Commit bd7b8e7c authored by rockyl's avatar rockyl

Merge branch 'mvvm'

# Conflicts:
#	manifest.json
parents d82d3f53 07abf962
......@@ -295,6 +295,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
return EE;
}());
//# sourceMappingURL=EventDispatcher.js.map
var ObservablePoint = (function (_super) {
tslib_1.__extends(ObservablePoint, _super);
......@@ -1269,6 +1270,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var bounds = this.getBounds(false, rect);
this.parent = parentRef;
this.transform = transformRef;
if (this.parent && this.stage) {
this.updateTransform();
}
return bounds;
};
DisplayObject.prototype.calculateBounds = function () {
......@@ -1507,12 +1511,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return this.$mask;
},
set: function (value) {
if (value === this) {
return;
}
if (this.$mask) {
this.$mask.renderable = true;
this.$mask.isUsedToMask = false;
if (this.$mask.parent) {
this.$mask.parent.removeChild(this.$mask);
}
}
this.$mask = value;
if (this.$mask) {
......@@ -1815,6 +1819,18 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
}
function safeEval(code, throwException) {
if (throwException === void 0) { throwException = false; }
var func = new Function(code);
try {
return func();
}
catch (e) {
if (throwException) {
throw e;
}
}
}
function injectProp(target, data, callback, ignoreMethod, ignoreNull) {
if (ignoreMethod === void 0) { ignoreMethod = true; }
if (ignoreNull === void 0) { ignoreNull = true; }
......@@ -1990,9 +2006,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var scriptName = ScriptConfig.script, props = ScriptConfig.props, disabled = ScriptConfig.disabled;
var script = node.scripts.add(scriptName, props, disabled);
}
var cmdPrefix = 'z-';
var cmdOldPrefix = '//z-';
function injectProperties(target, source) {
for (var key in source) {
propertyParse(key, target, source);
if (key.indexOf('//') !== 0 && !source.hasOwnProperty(cmdPrefix + key)) {
propertyParse(key, target, source);
}
}
return target;
}
......@@ -2464,7 +2484,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var name = args[0];
var dataMapping = this.getDataMapping(name);
try {
var data = this.getDataByPath(dataMapping.path, undefined, true);
var data = this.getDataByPath(dataMapping.path, undefined, false);
if (args[1] !== undefined) {
data = data[args[1]];
}
......@@ -2842,7 +2862,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
props[key] = nameValue !== undefined ? nameValue : dataCenter.getDataByPath(name);
break;
case 'env':
props[key] = env[name];
props[key] = getDataByPath(env, name);
break;
case 'map':
this.updateProps(props[key] = {}, args, name, name);
......@@ -3093,11 +3113,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
//# sourceMappingURL=after-constructor.js.map
function isUI(obj) {
return obj.isUI;
}
//# sourceMappingURL=IUIComponent.js.map
var Container = (function (_super) {
tslib_1.__extends(Container, _super);
function Container() {
......@@ -3356,10 +3371,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
child.updateTransform();
}
}
if (this._transform === this.transform && isUI(this) && this._lastLocalID !== this.transform.localID) {
this._lastLocalID = this.transform.localID;
this.stage.layoutInvalid = true;
}
};
Container.prototype.calculateBounds = function () {
if (this._lastBoundsID == this._boundsID)
......@@ -3393,23 +3404,27 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Rectangle.createFromRects(this._bounds, child._bounds);
}
}
};
Container.prototype._calculateBounds = function () {
var widthSetted = !!this._width && this._width !== 0;
var heightSetted = !!this._height && this._height !== 0;
if (widthSetted) {
this._bounds.width = this._width;
}
if (heightSetted) {
this._bounds.height = this._height;
if (widthSetted || heightSetted) {
var rect = this._localBoundsSelf;
var matrix = this.transform.worldMatrix;
matrix.transformPoint(rect.x, rect.y, DisplayObject._p1);
matrix.transformPoint(rect.x + rect.width, rect.y, DisplayObject._p2);
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
}
};
Container.prototype._calculateBounds = function () {
};
Container.prototype.hitTestPoint = function (globalPoint, isMouseEvent) {
if (isMouseEvent === void 0) { isMouseEvent = false; }
if (!this.visible)
return null;
if (isMouseEvent && !this.mouseChildren)
if (isMouseEvent && !this.mouseChildren) {
return this.hitTestSelf(globalPoint);
}
var children = this.children;
var length = children.length;
var child, hitDisplayObject;
......@@ -3423,7 +3438,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (hitDisplayObject)
return hitDisplayObject;
}
return this.hitTestSelf(globalPoint);
return this.displayObjectHitTestPoint(globalPoint, isMouseEvent);
};
Container.prototype.hitTestSelf = function (globalPoint) {
if (this.mouseEnabled) {
......@@ -3432,12 +3447,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return null;
};
Container.prototype.hitTestSelfBounds = function (globalPoint) {
if (this.width && this.height) {
var lp = this.globalToLocal(globalPoint, DisplayObject._bp);
if (lp.x > 0 &&
lp.x < this.width &&
lp.y > 0 &&
lp.y < this.height)
if (this._width && this._height) {
var _a = this.worldMatrix, tx = _a.tx, ty = _a.ty;
var x = globalPoint.x, y = globalPoint.y;
if (x > tx &&
x < tx + this.width &&
y > ty &&
y < ty + this.height)
return this;
}
return null;
......@@ -3523,8 +3539,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
set: function (value) {
if (this._width !== value) {
this._width = value;
if (this.stage)
this.stage.layoutInvalid = true;
this._localBoundsSelf.width = value;
this.dispatchEvent(Event.RESIZE);
}
},
......@@ -3538,8 +3553,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
set: function (value) {
if (this._height !== value) {
this._height = value;
if (this.stage)
this.stage.layoutInvalid = true;
this._localBoundsSelf.height = value;
this.dispatchEvent(Event.RESIZE);
}
},
......@@ -3550,8 +3564,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (withEvents === void 0) { withEvents = false; }
if (withScripts === void 0) { withScripts = false; }
var target = this.constructor.apply(Object.create(this.constructor.prototype));
var _a = this['__originConfig'], name = _a.name, properties = _a.properties, events = _a.events, scripts = _a.scripts;
var originConfig = this['__originConfig'];
var name = originConfig.name, properties = originConfig.properties, events = originConfig.events, scripts = originConfig.scripts;
target.name = name;
target['__originConfig'] = originConfig;
injectProperties(target, properties);
if (withScripts) {
if (scripts && scripts.length > 0) {
......@@ -3566,13 +3582,29 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
target.eventsProxy.start(events);
}
}
for (var _b = 0, _c = this.children; _b < _c.length; _b++) {
var child = _c[_b];
for (var _a = 0, _b = this.children; _a < _b.length; _a++) {
var child = _b[_a];
var childCopy = child.clone(withEvents, withScripts);
target.addChild(childCopy);
}
return target;
};
Object.defineProperty(Container.prototype, "$store", {
get: function () {
var p = this;
do {
if (p['$isViewRoot']) {
break;
}
p = p.parent;
} while (p.parent);
if (p) {
return p['$_store'];
}
},
enumerable: true,
configurable: true
});
Container._getElementsByName = function (rex, root, isOnlyOne, isRecursive, resultList) {
var len = root.children.length;
if (len > 0) {
......@@ -3625,32 +3657,39 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
});
s.addEventListener(Event.ADDED_TO_STAGE, function (e) {
if (!container) {
container = document.createElement('div');
container.style.position = "absolute";
container.style.left = "0";
container.style.top = "0";
container.style.fontSize = '30px';
container.style.lineHeight = 'normal';
s.stage.rootDiv.appendChild(container);
}
if (s._htmlElement) {
var style = s._htmlElement.style;
if (!s._isAdded) {
s._isAdded = true;
container.appendChild(s._htmlElement);
s.stage["_floatDisplayList"].push(s);
}
else {
if (s._htmlElement && s.visible) {
style.display = "block";
}
}
}
});
this.addHtmlElement();
}, s);
_this._transformID = -1;
return _this;
}
FloatDisplay.prototype.addHtmlElement = function () {
var s = this;
if (!s.stage) {
return;
}
if (!container) {
container = document.createElement('div');
container.style.position = "absolute";
container.style.left = "0";
container.style.top = "0";
container.style.fontSize = '30px';
container.style.lineHeight = 'normal';
s.stage.rootDiv.appendChild(container);
}
if (s._htmlElement) {
var style = s._htmlElement.style;
if (!s._isAdded) {
s._isAdded = true;
container.appendChild(s._htmlElement);
s.stage["_floatDisplayList"].push(s);
}
else {
if (s._htmlElement && s.visible) {
style.display = "block";
}
}
}
};
Object.defineProperty(FloatDisplay.prototype, "htmlElement", {
get: function () {
return this._htmlElement;
......@@ -3697,6 +3736,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
s._localBoundsSelf.width = w;
s._localBoundsSelf.height = h;
s._htmlElement = she;
this.addHtmlElement();
};
FloatDisplay.prototype.getStyle = function (elem, cssName) {
if (elem.style[cssName]) {
......@@ -4580,7 +4620,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
displayObject.parent = this._tempDisplayObjectParent;
displayObject.updateTransform();
displayObject.parent = cacheParent;
displayObject.stage && displayObject.stage.afterUpdateTransform();
context.save();
context.setTransform(1, 0, 0, 1, 0, 0);
context.globalAlpha = 1;
......@@ -5609,6 +5648,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this._localBoundsSelf.y = -height * this.anchorTexture.y;
this._localBoundsSelf.width = width;
this._localBoundsSelf.height = height;
this.dispatchEvent(Event.COMPLETE);
this.dispatchEvent(Event.RESIZE);
};
Sprite.prototype._onAnchorUpdate = function () {
......@@ -7678,7 +7718,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
displayObject.parent = this._tempDisplayObjectParent;
displayObject.updateTransform();
displayObject.parent = cacheParent;
displayObject.stage && displayObject.stage.afterUpdateTransform();
this.bindRenderTexture(renderTexture, transform);
this.batchManager.currentRenderer.start();
this._activeRenderTarget.clear();
......@@ -7856,6 +7895,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
return requestAnimationFrame;
}());
var skipTagNames = ['INPUT'];
var Stage = (function (_super) {
tslib_1.__extends(Stage, _super);
function Stage(rootDivId, desW, desH, frameRate, scaleMode, renderType, transparent, bgColor) {
......@@ -7873,7 +7913,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this.rootDiv = HTMLElement;
_this.renderObj = null;
_this.renderType = exports.RENDERER_TYPE.UNKNOWN;
_this.layoutInvalid = false;
_this.viewRect = new Rectangle();
_this.autoSteering = false;
_this.autoResize = false;
......@@ -7960,7 +7999,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Stage.addUpdateObj(s);
s.dispatchEvent(Event.ON_INIT_STAGE);
}, 100);
var rc = canvas;
var rc = s.rootDiv;
var mouseEvent = s.onMouseEvent.bind(s);
if (osType != "pc") {
rc.addEventListener("touchstart", mouseEvent, false);
......@@ -8090,6 +8129,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
Stage.prototype.onMouseEvent = function (e) {
var s = this;
if (skipTagNames.indexOf(e.target.tagName) >= 0) {
return;
}
if (EventDispatcher._totalMEC > 0) {
var points = void 0;
var item = s._mouseEventTypes[e.type];
......@@ -8117,8 +8159,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
else {
cp = new Point();
}
var rootDiv = s.rootDiv;
var doc = document.documentElement;
var box = points[o].target.getBoundingClientRect();
var box = rootDiv.getBoundingClientRect();
var left = box.left + window.pageXOffset - doc.clientLeft;
var top = box.top + window.pageYOffset - doc.clientTop;
cp.x = (points[o].pageX - left) * devicePixelRatio;
......@@ -8407,8 +8450,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
};
Stage.prototype.afterUpdateTransform = function () {
};
Stage.prototype.destroy = function () {
var s = this;
Stage.removeUpdateObj(s);
......@@ -11054,6 +11095,24 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var arr = item.split('=');
queryParams[arr[0]] = arr.length === 1 ? true : arr[1];
}
function appendScript(script, parent) {
if (parent === void 0) { parent = document.body; }
if (!script) {
return;
}
var scriptContent;
if (script.indexOf('<script') === 0) {
var temp = document.createElement('div');
temp.innerHTML = script;
scriptContent = temp.children[0].innerHTML;
}
else {
scriptContent = script;
}
var scriptEl = document.createElement('script');
scriptEl.innerHTML = scriptContent;
parent.appendChild(scriptEl);
}
//# sourceMappingURL=web.js.map
function httpRequest(url, method, params, type, headers) {
......@@ -14683,6 +14742,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
//# sourceMappingURL=Loader.js.map
var padding$1 = 10;
var styleFields = {
color: 'fillStyle',
stroke: 'lineWidth',
strokeColor: 'strokeStyle',
font: 'font',
};
var TextField = (function (_super) {
tslib_1.__extends(TextField, _super);
function TextField() {
......@@ -14690,10 +14755,11 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._textAlpha = 1;
_this._textAlign = exports.TEXT_ALIGN.LEFT;
_this._verticalAlign = exports.VERTICAL_ALIGN.UP;
_this._lineSpacing = 14;
_this._lineSpacing = 0;
_this._lineType = exports.TEXT_lINETYPE.SINGLE;
_this._text = "";
_this._pureText = '';
_this._styleCache = [];
_this._font = "Arial";
_this._size = 12;
_this._fillColor = "#000";
......@@ -14839,6 +14905,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
set: function (value) {
this._textFlow = value;
this.dirty = true;
this._styleCache.splice(0);
var text = '';
for (var _i = 0, _a = this._textFlow; _i < _a.length; _i++) {
var item = _a[_i];
......@@ -14867,6 +14934,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (!this.textFlow) {
return null;
}
if (this._styleCache[index]) {
return this._styleCache[index];
}
var targetItem;
var count = 0;
for (var _i = 0, _a = this._textFlow; _i < _a.length; _i++) {
......@@ -14877,6 +14947,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
break;
}
}
if (targetItem && targetItem.style) {
this._styleCache[index] = targetItem.style;
}
return targetItem.style;
};
Object.defineProperty(TextField.prototype, "font", {
......@@ -14983,20 +15056,23 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true,
configurable: true
});
TextField.prototype._setupFont = function (font, size, bold, italic) {
var fontStyle = size;
fontStyle += "px ";
fontStyle += font;
if (bold) {
fontStyle = "bold " + fontStyle;
}
if (italic) {
fontStyle = "italic " + fontStyle;
}
return fontStyle;
};
TextField.prototype._prepContext = function (ctx) {
var s = this;
var font = s.size || 12;
font += "px ";
font += s.font;
if (s._bold) {
font = "bold " + font;
}
if (s._italic) {
font = "italic " + font;
}
ctx.font = font;
ctx.textAlign = s._textAlign || exports.TEXT_ALIGN.LEFT;
ctx.textBaseline = "top";
ctx.font = this._setupFont(s._font, s._size, s._bold, s._italic);
ctx.textAlign = s.isPureText ? (s._textAlign || exports.TEXT_ALIGN.LEFT) : exports.TEXT_ALIGN.LEFT;
ctx.textBaseline = s.isPureText ? 'top' : 'bottom';
if (typeof (s._fillColor) == "number")
s._fillColor = hex2string(s._fillColor);
ctx.fillStyle = s._textAlpha === 1 ? s._fillColor : getRGBA(s._fillColor, s._textAlpha);
......@@ -15016,18 +15092,30 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true,
configurable: true
});
TextField.prototype._getMeasuredWidth = function (text) {
TextField.prototype._getMeasuredWidth = function (text, style) {
var ctx = this.context;
ctx.save();
if (style && style.font) {
ctx.font = style.font;
}
var w = ctx.measureText(text).width;
ctx.restore();
return w;
};
TextField.prototype._getFontSize = function (style) {
if (style && style.font) {
return parseInt(style.font);
}
};
TextField.prototype.updateText = function () {
var s = this;
var text = s.pureText;
if (!text) {
s.canvas.width = 0;
s.canvas.height = 0;
s._localBoundsSelf.clear();
if (!this._width && !this._height) {
s._localBoundsSelf.clear();
}
this.anchorTexture = { x: 0, y: 0 };
this.updateTexture();
return;
......@@ -15036,15 +15124,18 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (!s.dirty)
return;
s.dirty = false;
var isPureText = s.isPureText;
text += "";
var can = s.canvas;
var ctx = s.context;
var hardLines = text.toString().split(/(?:\r\n|\r|\n)/);
var realLines = [];
var lineWidths = [];
var lineHeights = [];
s.realLines = realLines;
s._prepContext(ctx);
var textWidth = s._width;
if (text.indexOf("\n") < 0 && s.lineType == exports.TEXT_lINETYPE.SINGLE) {
if (isPureText && text.indexOf("\n") < 0 && s.lineType == exports.TEXT_lINETYPE.SINGLE) {
realLines[realLines.length] = hardLines[0];
var str = hardLines[0];
var lineW = s._getMeasuredWidth(str);
......@@ -15069,6 +15160,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
else {
var shouldMeasureTextWidth = !textWidth;
var index_1 = 0;
for (var i = 0, l = hardLines.length; i < l; i++) {
var str = hardLines[i];
if (!str)
......@@ -15076,49 +15168,71 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var lineWidth = 0;
for (var _i = 0, str_1 = str; _i < str_1.length; _i++) {
var char = str_1[_i];
var charWidth = measureChar(char);
var charWidth = measureChar(char, index_1);
lineWidth += charWidth;
index_1++;
}
if (shouldMeasureTextWidth) {
textWidth = Math.max(lineWidth, textWidth);
}
}
index_1 = 0;
for (var i = 0, l = hardLines.length; i < l; i++) {
var str = hardLines[i];
if (!str)
continue;
var w = measureCache[str[0]];
var w = measureChar(str[0], index_1++);
var lineStr = str[0];
var wordW = 0;
var strLen = str.length;
var lineHeight = 0;
for (var j = 1; j < strLen; j++) {
wordW = measureCache[str[j]];
wordW = measureChar(str[j], index_1);
w += wordW;
if (w > textWidth) {
realLines[realLines.length] = lineStr;
lineWidths.push(w - wordW);
lineHeights.push(lineHeight || s.size);
lineStr = str[j];
w = wordW;
lineHeight = 0;
}
else {
lineStr += str[j];
}
var style = this.getStyle(index_1);
var size = this._getFontSize(style);
if (size) {
if (size > lineHeight) {
lineHeight = size;
}
}
index_1++;
}
realLines[realLines.length] = lineStr;
lineWidths.push(w);
lineHeights.push(lineHeight || s.size);
}
}
var trueHeight = s.size * realLines.length + s._lineSpacing * (realLines.length - 1);
var maxH = s._height || trueHeight;
var maxW = textWidth;
var tx = 0;
if (s._textAlign == exports.TEXT_ALIGN.CENTER) {
tx = maxW * 0.5;
var maxH, trueHeight;
if (isPureText) {
trueHeight = s.size * realLines.length + s._lineSpacing * (realLines.length - 1);
}
else {
trueHeight = lineHeights.reduce(function (a, b) {
return a + b;
}, 0) + s._lineSpacing * (realLines.length - 1);
}
if (s._height) {
maxH = s._height;
}
else if (s._textAlign == exports.TEXT_ALIGN.RIGHT) {
tx = maxW;
else {
maxH = trueHeight;
}
var maxW = textWidth;
can.width = maxW + padding$1 * 2;
can.height = maxH + padding$1 * 2;
ctx.clearRect(0, 0, can.width, can.width);
ctx.clearRect(0, 0, can.width, can.height);
if (s.border) {
ctx.beginPath();
ctx.strokeStyle = "#000";
......@@ -15126,6 +15240,15 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
ctx.strokeRect(padding$1 + 0.5, padding$1 + 0.5, maxW, maxH);
ctx.closePath();
}
var tx = 0;
if (isPureText) {
if (s._textAlign == exports.TEXT_ALIGN.CENTER) {
tx = maxW * 0.5;
}
else if (s._textAlign == exports.TEXT_ALIGN.RIGHT) {
tx = maxW;
}
}
ctx.setTransform(1, 0, 0, 1, tx + padding$1, padding$1);
s._prepContext(ctx);
var lineH = s._lineSpacing + s.size;
......@@ -15139,9 +15262,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
var index = 0;
var lineY = upY;
for (var i = 0; i < realLines.length; i++) {
var line = realLines[i];
if (s.isPureText) {
if (isPureText) {
var y = upY + i * lineH;
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
......@@ -15151,38 +15275,37 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
ctx.fillText(line, 0, y, maxW);
}
else {
var lineWidth = 0;
for (var _a = 0, line_1 = line; _a < line_1.length; _a++) {
var char = line_1[_a];
var charWidth = measureChar(char);
lineWidth += charWidth;
var lineWidth = lineWidths[i];
var lineHeight = lineHeights[i];
lineY += s._lineSpacing + lineHeight;
var x = 0;
if (s._textAlign == exports.TEXT_ALIGN.CENTER) {
x = (maxW - lineWidth) * 0.5;
}
else if (s._textAlign == exports.TEXT_ALIGN.RIGHT) {
x = maxW - lineWidth;
}
var x = -lineWidth / 2;
for (var j = 0, lj = line.length; j < lj; j++) {
var char = line[j];
var style = s.getStyle(index);
if (style) {
if (style.hasOwnProperty('color')) {
ctx.fillStyle = style.color;
}
if (style.hasOwnProperty('stroke')) {
ctx.lineWidth = style.stroke * 2;
}
if (style.hasOwnProperty('strokeColor')) {
ctx.strokeStyle = style.strokeColor;
ctx.save();
for (var field in styleFields) {
if (style.hasOwnProperty(field)) {
ctx[styleFields[field]] = style[field];
}
}
}
else {
ctx.fillStyle = s.fillColor;
ctx.lineWidth = s.stroke;
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2;
ctx.strokeText(char, x, lineY);
}
var y = upY + i * lineH;
if (ctx.lineWidth > 0) {
ctx.strokeText(char, x, y);
ctx.fillText(char, x, lineY);
if (style) {
ctx.restore();
}
ctx.fillText(char, x, y);
x += measureChar(char);
x += measureChar(char, index);
index++;
}
}
......@@ -15193,10 +15316,18 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
s._localBoundsSelf.width = maxW;
s._localBoundsSelf.height = maxH;
s.updateTexture();
function measureChar(char) {
var w = measureCache[char];
function measureChar(char, index) {
var key = char + ':';
var style;
if (!isPureText && index !== undefined) {
style = s.getStyle(index);
if (style && style.font) {
key += style.font;
}
}
var w = measureCache[key];
if (w === undefined) {
w = measureCache[char] = s._getMeasuredWidth(char);
w = measureCache[char] = s._getMeasuredWidth(char, style);
}
return w;
}
......@@ -15654,7 +15785,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
configurable: true
});
ScrollViewBase.prototype.calMaxDistance = function () {
return this.viewPort[this.paramSize];
return this.viewPort[this.paramSize] + this.viewPort.getLocalBounds()[this.paramXY];
};
Object.defineProperty(ScrollViewBase.prototype, "direction", {
get: function () {
......@@ -16624,7 +16755,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
StackContainer.prototype.pop = function (dispatch) {
if (dispatch === void 0) { dispatch = true; }
var len = this.children.length;
if (len == 0) {
if (len <= 0) {
return false;
}
this.removeChildAt(len - 1);
......@@ -18851,6 +18982,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
function Image() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.isUI = true;
_this.crossOrigin = true;
_this._escapes = [];
_this._registeredEvents = [];
return _this;
......@@ -18881,7 +19013,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
url = assetConfig.uuid;
}
}
this.texture = Texture.fromImage(url);
this.texture = Texture.fromImage(url, this.crossOrigin);
}
else {
this.texture = null;
......@@ -19201,7 +19333,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
TextInput.prototype.onClickStatic = function () {
this.setFocus();
this.stage.once(MouseEvent.CLICK, this.onClickStage, this);
this.stage.once(MouseEvent.MOUSE_DOWN, this.onClickStage, this);
};
TextInput.prototype.onResize = function () {
var pl = this._placeholderLabel;
......@@ -19426,6 +19558,27 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
HtmlView.prototype.afterConstructor = function () {
};
Object.defineProperty(HtmlView.prototype, "$store", {
get: function () {
var p = this;
do {
if (p['$isViewRoot']) {
break;
}
p = p.parent;
} while (p.parent);
if (p) {
return p['$_store'];
}
},
enumerable: true,
configurable: true
});
HtmlView.prototype.findChildByUUID = function (uuid) {
if (this['uuid'] === uuid) {
return this;
}
};
HtmlView = tslib_1.__decorate([
afterConstructor,
applyAutoAdjust,
......@@ -19434,7 +19587,11 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
], HtmlView);
return HtmlView;
}(FloatDisplay));
//# sourceMappingURL=HtmlView.js.map
function isUI(obj) {
return obj.isUI;
}
//# sourceMappingURL=IUIComponent.js.map
var nodeTypeMapping = {
node: Node$1,
......@@ -19583,6 +19740,759 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}(Node$1));
//# sourceMappingURL=Toast.js.map
function createEvalFunc(exp) {
var func;
try {
func = Function("scope", "with(scope){return " + exp + "}");
}
catch (err) {
var sepStr = (exp.indexOf('"') < 0 ? '"' : "'");
var reg = /([^\\]?)`/g;
exp = exp.replace(reg, "$1" + sepStr);
reg = /\$\{(.*?)\}/g;
exp = exp.replace(reg, sepStr + "+($1)+" + sepStr);
try {
func = Function("scope", "with(scope){return " + exp + "}");
}
catch (e) {
console.error('非法的表达式:', exp);
}
}
return func;
}
function evalExp(exp, scope) {
return createEvalFunc(exp)(scope);
}
function createRunFunc(exp) {
return createEvalFunc("(function(){" + exp + "})()");
}
function runExp(exp, scope) {
createRunFunc(exp)(scope);
}
//# sourceMappingURL=Utils.js.map
var Watcher = (function () {
function Watcher(entity, target, exp, scope, callback) {
this._disposed = false;
this._entity = entity;
this._uid = Watcher._uid++;
this._target = target;
this._exp = exp;
this._scope = scope;
this._expFunc = createEvalFunc(exp);
this._callback = callback;
this.update();
}
Object.defineProperty(Watcher.prototype, "uid", {
get: function () {
return this._uid;
},
enumerable: true,
configurable: true
});
Watcher.prototype.getValue = function () {
if (this._disposed)
return null;
var value = null;
Watcher.updating = this;
Object.defineProperty(this._scope, "$root", {
configurable: true,
enumerable: false,
value: this._entity.compiler.root,
writable: false
});
Object.defineProperty(this._scope, "$target", {
configurable: true,
enumerable: false,
value: this._target,
writable: false
});
try {
value = this._expFunc.call(this._scope, this._scope);
}
catch (err) {
console.warn("表达式求值错误\nerr: " + err.toString() + "\nexp:" + this._exp + ",scope:" + JSON.stringify(this._scope));
}
delete this._scope["$root"];
delete this._scope["$target"];
Watcher.updating = null;
return value;
};
Watcher.prototype.update = function (extra) {
if (this._disposed)
return;
var value = this.getValue();
if (!Watcher.isEqual(value, this._value)) {
this._callback && this._callback(value, this._value, extra);
this._value = Watcher.deepCopy(value);
}
};
Watcher.prototype.dispose = function () {
if (this._disposed)
return;
this._value = null;
this._target = null;
this._exp = null;
this._scope = null;
this._expFunc = null;
this._callback = null;
this._disposed = true;
};
Watcher.isEqual = function (a, b) {
return (a == b || (Watcher.isObject(a) && Watcher.isObject(b)
? JSON.stringify(a) == JSON.stringify(b)
: false));
};
Watcher.isObject = function (obj) {
return (obj && typeof obj == "object");
};
Watcher.deepCopy = function (from) {
if (Watcher.isObject(from)) {
return JSON.parse(JSON.stringify(from));
}
else {
return from;
}
};
Watcher.updating = null;
Watcher._uid = 0;
return Watcher;
}());
//# sourceMappingURL=Watcher.js.map
var Dep = (function () {
function Dep() {
this._map = {};
}
Dep.prototype.watch = function (watcher) {
if (!this._map[watcher.uid]) {
this._map[watcher.uid] = watcher;
}
};
Dep.prototype.notify = function (extra) {
for (var uid in this._map) {
var watcher = this._map[uid];
watcher.update(extra);
}
};
return Dep;
}());
//# sourceMappingURL=Dep.js.map
var Mutator = (function () {
function Mutator() {
}
Mutator.mutate = function (data) {
if (!data || typeof data != "object")
return;
if (!data.__ares_mutated__) {
for (var key in data) {
Mutator.mutateProp(data, key, data[key]);
}
Object.defineProperty(data, "__ares_mutated__", {
value: true,
writable: false,
enumerable: false,
configurable: false
});
}
return data;
};
Mutator.mutateProp = function (data, key, value) {
var dep = new Dep();
Object.defineProperty(data, key, {
enumerable: true,
configurable: false,
get: function () {
var watcher = Watcher.updating;
if (watcher)
dep.watch(watcher);
return value;
},
set: function (v) {
if (v == value)
return;
value = v;
if (Array.isArray(v))
Mutator.mutateArray(v, dep);
else
Mutator.mutate(v);
dep.notify();
}
});
if (Array.isArray(value)) {
Mutator.mutateArray(value, dep);
}
else {
Mutator.mutate(value);
}
};
Mutator.mutateArray = function (arr, dep) {
arr["__proto__"] = Mutator.defineReactiveArray(dep);
for (var i = 0, len = arr.length; i < len; i++) {
Mutator.mutate(arr[i]);
}
};
Mutator.defineReactiveArray = function (dep) {
var proto = Array.prototype;
var result = Object.create(proto);
Mutator._arrMethods.forEach(function (method) {
var oriMethod = proto[method];
Object.defineProperty(result, method, {
value: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var result = oriMethod.apply(this, args);
var inserted;
switch (method) {
case "push":
case "unshift":
inserted = args;
break;
case "splice":
inserted = args.slice(2);
break;
}
if (inserted && inserted.length) {
Mutator.mutateArray(inserted, dep);
}
dep.notify({ method: args });
return result;
}
});
});
Object.defineProperty(result, "$set", {
value: function (index, value) {
if (index >= this.length)
index = this.length;
return this.splice(index, 1, value)[0];
}
});
Object.defineProperty(result, "$remove", {
value: function (item) {
var index = this.indexOf(item);
if (index > -1)
return this.splice(index, 1);
return null;
}
});
return result;
};
Mutator._arrMethods = [
"push",
"pop",
"unshift",
"shift",
"splice",
"sort",
"reverse"
];
return Mutator;
}());
//# sourceMappingURL=Mutator.js.map
var commands = {
set: function (context) {
runExp(context.data.subCmd + "=" + context.data.exp, context.scope);
return context.target;
},
bind: function (context) {
context.entity.createWatcher(context.target, context.data.exp, context.scope, function (value) {
if (context.data.subCmd)
runExp(context.data.subCmd + "=" + context.data.exp, context.scope);
});
return context.target;
}
};
//# sourceMappingURL=Commands.js.map
var defaultCmdRegExp = /^(data\-)?z[\-_](\w+)([:\$](.+))?$/;
var Zri = (function () {
function Zri(data, compiler, options) {
this._data = Mutator.mutate(data);
this._compiler = compiler;
this._options = options;
this._compiler.init(this);
if (this._options && this._options.inited) {
this._options.inited.call(this._data, this);
}
}
Object.defineProperty(Zri.prototype, "data", {
get: function () {
return this._data;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Zri.prototype, "compiler", {
get: function () {
return this._compiler;
},
enumerable: true,
configurable: true
});
Zri.prototype.createWatcher = function (target, exp, scope, callback) {
return new Watcher(this, target, exp, scope, callback);
};
Zri.prototype.parseCommand = function (key, value, cmdRegExp) {
var result = (cmdRegExp || defaultCmdRegExp).exec(key);
if (!result)
return null;
var key = result[0];
var cmdName = result[2];
var exp = value;
var subCmd = result[4] || "";
return {
cmdName: cmdName,
subCmd: subCmd,
propName: key,
exp: exp
};
};
Zri.prototype.testCommand = function (data) {
if (!data)
return false;
var cmd = commands[data.cmdName];
return (cmd != null);
};
Zri.prototype.execCommand = function (data, target, scope) {
if (!data || !scope)
return false;
var cmd = commands[data.cmdName];
if (!cmd)
return false;
cmd({
target: target,
scope: scope,
entity: this,
data: data
});
return true;
};
return Zri;
}());
//# sourceMappingURL=Zri.js.map
var commands$1 = {
prop: function (context) {
var cmdData = context.cmdData;
var target = context.target;
context.entity.createWatcher(target, cmdData.exp, context.scope, function (value) {
if (cmdData.subCmd != "") {
target[cmdData.subCmd] = value;
}
else {
for (var name in value) {
target[name] = value[name];
}
}
});
return target;
},
on: function (context) {
var cmdData = context.cmdData;
if (cmdData.subCmd != "") {
var handler_1 = context.scope[cmdData.exp] || window[context.cmdData.exp];
if (typeof handler_1 == "function") {
context.target.addEventListener(cmdData.subCmd, function () {
handler_1.apply(this, arguments);
}, context.scope);
}
else {
context.target.addEventListener(cmdData.subCmd, function (evt) {
var scope = Object.create(context.scope);
scope.$event = evt;
scope.$target = context.target;
runExp(cmdData.exp, scope);
});
}
}
return context.target;
},
if: function (context) {
var cmdData = context.cmdData;
var compiled = false;
var refNode = new Container();
refNode.mouseChildren = refNode.mouseEnabled = false;
var parent = context.target.parent;
var index = parent.getChildIndex(context.target);
parent.removeChildAt(index);
parent.addChildAt(refNode, index);
var watcher = context.entity.createWatcher(context.target, cmdData.exp, context.scope, function (value) {
if (!refNode.parent && !context.target.parent) {
watcher.dispose();
return;
}
if (value == true) {
if (!context.target.parent) {
var parent_1 = refNode.parent;
var index_1 = parent_1.getChildIndex(refNode);
parent_1.removeChild(refNode);
parent_1.addChildAt(context.target, index_1);
}
if (!compiled) {
context.compiler.compile(context.target, context.scope);
compiled = true;
}
}
else {
if (context.target.parent) {
var parent_2 = context.target.parent;
var index_2 = parent_2.getChildIndex(context.target);
parent_2.removeChild(context.target);
parent_2.addChildAt(refNode, index_2);
}
}
});
return context.target;
},
for: function (context) {
var cmdData = context.cmdData;
var options = evalExp(cmdData.subCmd, context.scope) || {};
var page = (options.page || Number.MAX_VALUE);
var reg = /^\s*(\S+)\s+in\s+([\s\S]+?)\s*$/;
var res = reg.exec(cmdData.exp);
if (!res) {
console.error("for命令表达式错误:" + cmdData.exp);
return;
}
var itemName = res[1];
var arrName = res[2];
var index = context.target.parent.getChildIndex(context.target);
var parent = new Container();
context.target.parent.addChildAt(parent, index);
context.target.parent.removeChild(context.target);
var forScope = Object.create(context.scope);
Object.defineProperty(forScope, "$forTarget", {
configurable: true,
enumerable: false,
value: context.target,
writable: false
});
context.compiler.compile(parent, forScope);
var isArray;
var curList;
var curIndex;
var lastNode;
var watcher = context.entity.createWatcher(context.target, arrName, forScope, function (value) {
if (!parent.parent) {
watcher.dispose();
return;
}
for (var i = parent.children.length - 1; i >= 0; i--) {
parent.removeChildAt(i).destroy();
}
if (typeof value == "number") {
var temp = [];
for (var i = 0; i < value; i++) {
temp.push(i);
}
value = temp;
}
isArray = (value instanceof Array);
var list;
if (isArray) {
list = value;
}
else {
list = [];
for (var key in value) {
list.push({
key: key,
value: value[key]
});
}
}
curList = list;
curIndex = 0;
lastNode = null;
for (var li = curList.length; curIndex < li; curIndex++) {
var newNode = context.target.clone(true, true);
parent.addChild(newNode);
var newScope = Object.create(forScope);
Object.defineProperty(newScope, "$index", {
configurable: true,
enumerable: false,
value: curIndex,
writable: false
});
if (!isArray) {
Object.defineProperty(newScope, "$key", {
configurable: true,
enumerable: true,
value: curList[curIndex].key,
writable: false
});
}
Object.defineProperty(newScope, "$last", {
configurable: true,
enumerable: false,
value: lastNode,
writable: false
});
Object.defineProperty(newScope, "$length", {
configurable: true,
enumerable: false,
value: curList.length,
writable: false
});
Object.defineProperty(newScope, itemName, {
configurable: true,
enumerable: true,
value: (isArray ? curList[curIndex] : curList[curIndex].value),
writable: false
});
Object.defineProperty(newNode, "$data", {
configurable: true,
enumerable: false,
value: (isArray ? curList[curIndex] : curList[curIndex].value),
writable: false
});
context.compiler.compile(newNode, newScope);
lastNode = newNode;
}
});
return context.target;
}
};
//# sourceMappingURL=ZriCommands.js.map
var interruptCmds = ['for', 'if'];
var ZriCompiler = (function () {
function ZriCompiler(root) {
this._root = root;
}
Object.defineProperty(ZriCompiler.prototype, "root", {
get: function () {
return this._root;
},
enumerable: true,
configurable: true
});
ZriCompiler.prototype.init = function (entity) {
this._entity = entity;
this.compile(this._root, entity.data);
};
ZriCompiler.prototype.compile = function (target, scope) {
var cmdDatas = [];
var needInterrupt = false;
var originConfig = target['__originConfig'];
if (originConfig && originConfig.properties) {
var properties = originConfig.properties;
for (var key in properties) {
if (key.indexOf(cmdPrefix) != 0) {
continue;
}
var cmdData = this._entity.parseCommand(key, target[key]);
if (cmdData) {
cmdDatas.push(cmdData);
if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
needInterrupt = true;
cmdDatas.splice(0, cmdDatas.length - 1);
break;
}
}
}
for (var _i = 0, cmdDatas_1 = cmdDatas; _i < cmdDatas_1.length; _i++) {
var cmdData = cmdDatas_1[_i];
delete target[cmdData.propName];
if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
delete properties[cmdData.propName];
}
var cmd = commands$1[cmdData.cmdName];
if (!cmd) {
cmdData.subCmd = cmdData.cmdName || "";
cmdData.cmdName = "prop";
cmd = commands$1[cmdData.cmdName];
}
cmd({
scope: scope,
target: target,
entity: this._entity,
cmdData: cmdData,
compiler: this,
});
}
}
if (!needInterrupt && target.children && target.children.length > 0) {
for (var _a = 0, _b = target.children; _a < _b.length; _a++) {
var child = _b[_a];
this.compile(child, scope);
}
}
};
ZriCompiler.prototype.debug = function () {
};
return ZriCompiler;
}());
//# sourceMappingURL=ZriCompiler.js.map
function bind(store, view, options) {
var compiler = new ZriCompiler(view);
var zri = new Zri(store, compiler, options);
compiler.debug();
return zri;
}
function createStore(exp, computed) {
var store = safeEval(exp) || {};
for (var _i = 0, computed_1 = computed; _i < computed_1.length; _i++) {
var _a = computed_1[_i], name = _a.name, script = _a.script;
if (name && !store.hasOwnProperty(name)) {
var getterCode = "return function(){\n\t\t\t" + script + "\n\t\t}";
Object.defineProperty(store, name, {
get: safeEval(getterCode),
});
}
}
return store;
}
//# sourceMappingURL=index.js.map
var customMap = {};
function registerCustomModules(customs) {
if (!customs) {
return;
}
for (var _i = 0, customs_1 = customs; _i < customs_1.length; _i++) {
var custom = customs_1[_i];
if (custom.assets) {
customMap[custom.id].assets = custom.assets;
}
if (custom.props) {
customMap[custom.id].props = custom.props;
}
}
}
function registerCustomModule(id, def) {
customMap[id] = {
def: def,
};
}
function registerCustomCodeModule(config) {
var id = config.id, code = config.code;
registerCustomModule(id, importCJSCode(code, true));
}
function registerCustomModuleFromConfig(config) {
if (config) {
for (var _i = 0, config_1 = config; _i < config_1.length; _i++) {
var item = config_1[_i];
registerCustomCodeModule(item);
}
}
}
function addCustomModule(id, container, options) {
var creator = customMap[id].def;
if (creator) {
var instance = creator(options);
if (instance) {
container.addChild(instance);
return instance;
}
}
}
function resolveCustomAsset(id, uuid) {
var module = customMap[id];
if (module) {
var config = arrayFind(module.assets, function (item) { return item.uuid === uuid; });
if (config) {
if (config.url.indexOf(linkScheme) === 0) {
var linkUUID = config.url.replace(linkScheme, '');
var linkConfig = getAssetByUUID(linkUUID);
if (linkConfig) {
config = linkConfig;
}
}
}
return config;
}
}
function getProps(id) {
return customMap[id].props || {};
}
//# sourceMappingURL=custom-module.js.map
function dealPxEnv() {
if (queryParams.appID) {
env.appID = queryParams.appID;
}
if (queryParams.channelType) {
env.channelType = queryParams.channelType;
}
if (queryParams.projectID) {
env.projectID = queryParams.projectID;
}
else {
var result = window.location.pathname.match(/\/projectx\/(.*?)\/.*?/);
if (result) {
env.projectID = result[1];
}
}
if (queryParams.is_from_share) {
env.fromShare = true;
}
var newUser = true;
var key = 'nu_' + env.appID + '_' + env.projectID;
var v = localStorage.getItem(key);
if (v) {
newUser = false;
}
else {
localStorage.setItem(key, '1');
}
env.newUser = newUser;
if (window['isSharePage']) {
accessLog(506);
}
}
function cleanNewUser() {
var key = 'nu_' + env.appID + '_' + env.projectID;
localStorage.removeItem(key);
}
function dealPageRemainTime() {
var startTimer = new Date().getTime();
var endTimer;
var visibilityChange;
if (typeof document.hidden !== 'undefined') {
visibilityChange = 'visibilitychange';
}
else if (typeof document['msHidden'] !== 'undefined') {
visibilityChange = 'msvisibilitychange';
}
else if (typeof document['webkitHidden'] !== 'undefined') {
visibilityChange = 'webkitvisibilitychange';
}
var handleVisibilityChange = function (e) {
if (document.visibilityState == "visible") {
startTimer = new Date().getTime();
}
if (document.visibilityState == "hidden") {
endTimer = new Date().getTime();
sendData();
}
};
var sendData = function () {
var t0 = endTimer - startTimer;
accessLog(156, {
remain: t0,
});
};
document.addEventListener(visibilityChange, handleVisibilityChange, false);
document.body['onbeforeunload'] = function () {
endTimer = new Date().getTime();
return sendData();
};
}
function accessLog(pagebizid, params) {
var p = {
pagebizid: pagebizid,
};
injectProp(p, params);
return httpRequest('buriedPoint', 'get', p);
}
//# sourceMappingURL=px-logics.js.map
var GameStage = (function (_super) {
tslib_1.__extends(GameStage, _super);
function GameStage(stage) {
......@@ -19688,6 +20598,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return [3, 2];
case 5:
this.start();
dealPxEnv();
dealPageRemainTime();
onStart && onStart();
return [2];
}
......@@ -19721,6 +20633,16 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var viewConfig = this.getViewConfigByName(name);
if (viewConfig) {
view = instantiate(viewConfig);
var store = {};
if (viewConfig.store) {
var _a = viewConfig.store, exp = _a.exp, computed = _a.computed;
store = createStore(exp, computed);
}
view['$isViewRoot'] = true;
view['$_store'] = store;
console.time('bind');
bind(store, view);
console.timeEnd('bind');
if (cache) {
this._viewCache[name] = view;
}
......@@ -19755,69 +20677,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}(Node$1));
//# sourceMappingURL=GameStage.js.map
var customMap = {};
function registerCustomModules(customs) {
if (!customs) {
return;
}
for (var _i = 0, customs_1 = customs; _i < customs_1.length; _i++) {
var custom = customs_1[_i];
if (custom.assets) {
customMap[custom.id].assets = custom.assets;
}
if (custom.props) {
customMap[custom.id].props = custom.props;
}
}
}
function registerCustomModule(id, def) {
customMap[id] = {
def: def,
};
}
function registerCustomCodeModule(config) {
var id = config.id, code = config.code;
registerCustomModule(id, importCJSCode(code, true));
}
function registerCustomModuleFromConfig(config) {
if (config) {
for (var _i = 0, config_1 = config; _i < config_1.length; _i++) {
var item = config_1[_i];
registerCustomCodeModule(item);
}
}
}
function addCustomModule(id, container, options) {
var creator = customMap[id].def;
if (creator) {
var instance = creator(options);
if (instance) {
container.addChild(instance);
return instance;
}
}
}
function resolveCustomAsset(id, uuid) {
var module = customMap[id];
if (module) {
var config = arrayFind(module.assets, function (item) { return item.uuid === uuid; });
if (config) {
if (config.url.indexOf(linkScheme) === 0) {
var linkUUID = config.url.replace(linkScheme, '');
var linkConfig = getAssetByUUID(linkUUID);
if (linkConfig) {
config = linkConfig;
}
}
}
return config;
}
}
function getProps(id) {
return customMap[id].props || {};
}
//# sourceMappingURL=custom-module.js.map
var template = "\n<div class=\"zeroing-loading-wrapper\">\n\t<div class=\"zeroing-loading-content\">\n\t</div>\n</div>\n";
var style = "\n.zeroing-loading-wrapper{\n\tposition: absolute;\n\ttop:0;\n\tleft: 0;\n\tright: 0;\n\tbottom: 0;\n\tdisplay: flex;\n\tdisplay: -webkit-flex;\n\tjustify-content: center;\n\t-webkit-justify-content: center;\n\talign-items: center;\n\t-webkit-align-items: center;\n}\n@keyframes part-body\n{\n\t0%,40% {transform: scale(1);}\n\t20% {transform: scale(1.5);}\n}\n.zeroing-loading-part {\n\ttransform-origin: 2px 12px;\n\tposition: absolute;\n}\n.zeroing-loading-part-body{\n\tbackground-color: dimgray;\n\twidth: 4px;\n\theight: 6px;\n\tborder-radius: 2px;\n\ttransform-origin: 2px 6px;\n\tanimation: part-body 1500ms linear infinite;\n}\n";
var inited = false;
......@@ -19973,95 +20832,94 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
/**
* Created by rockyl on 2020-01-27.
*/
const genericRegexp = /(\w+)(<(\w+)>)?/;
var genericRegexp = /(\w+)(<(\w+)>)?/;
function compute(props, options) {
let result = props || {};
for (let key in options) {
let sourceValue = getValue(result, options, key);
let value = sourceValue;
if (options) {
let option = options[key];
if (option && option.type) {
let {type, generic} = parseType(option.type);
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
let seps = sourceValue.split(',');
seps = seps.map(sep => {
let item;
if (generic) {
switch (generic) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
} else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
}
return result;
var result = props || {};
var _loop_1 = function (key) {
var sourceValue = getValue(result, options, key);
var value = sourceValue;
if (options) {
var option = options[key];
if (option && option.type) {
var _a = parseType(option.type), type = _a.type, generic_1 = _a.generic;
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
var seps = sourceValue.split(',');
seps = seps.map(function (sep) {
var item;
if (generic_1) {
switch (generic_1) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
}
else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
};
for (var key in options) {
_loop_1(key);
}
return result;
}
function parseType(typeStr) {
let type = typeStr, generic;
let regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type, generic,
}
var type = typeStr, generic;
var regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type: type, generic: generic,
};
}
function parseVector2(sourceValue) {
let value = sourceValue;
if (!sourceValue) {
value = {x: undefined, y: undefined};
}
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
var value = sourceValue;
if (!sourceValue) {
value = { x: undefined, y: undefined };
}
if (typeof sourceValue === 'string') {
var arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
}
else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
}
function getValue(props, options, key) {
let value;
if (props.hasOwnProperty(key)) {
value = props[key];
} else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
var value;
if (props.hasOwnProperty(key)) {
value = props[key];
}
else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
}
//# sourceMappingURL=index.es.js.map
......@@ -20077,6 +20935,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.DATA_CENTER_EVENT = DATA_CENTER_EVENT;
exports.DATA_URI = DATA_URI;
exports.DEG_TO_RAD = DEG_TO_RAD;
exports.DataCenter = DataCenter;
exports.DisplayObject = DisplayObject;
exports.DrawAllToCanvas = DrawAllToCanvas;
exports.ESCAPE_REG_EXP = ESCAPE_REG_EXP;
......@@ -20129,17 +20988,23 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.URL_FILE_EXTENSION = URL_FILE_EXTENSION;
exports.VERSION = VERSION;
exports.abs = abs;
exports.accessLog = accessLog;
exports.addCustomModule = addCustomModule;
exports.appendScript = appendScript;
exports.applyEvents = applyEvents;
exports.applyScript = applyScript;
exports.arrayFind = arrayFind;
exports.backupCanvas = backupCanvas;
exports.cleanNewUser = cleanNewUser;
exports.clearTextureCache = clearTextureCache;
exports.cmdOldPrefix = cmdOldPrefix;
exports.cmdPrefix = cmdPrefix;
exports.computeProps = compute;
exports.copyProp = copyProp;
exports.cos = cos;
exports.countTrailingZeros = countTrailingZeros;
exports.createTextureSheet = createTextureSheet;
exports.dataCenter = dataCenter;
exports.decomposeDataUri = decomposeDataUri;
exports.deepDirtyFieldDetector = deepDirtyFieldDetector;
exports.deepDirtyFieldTrigger = deepDirtyFieldTrigger;
......@@ -20228,6 +21093,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.resolveCustomAsset = resolveCustomAsset;
exports.reverse = reverse;
exports.rgb2hex = rgb2hex;
exports.safeEval = safeEval;
exports.setGlobalContext = setGlobalContext;
exports.setProcessMetaLibs = setProcessMetaLibs;
exports.setScriptMap = setScriptMap;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
module.exports = {
region: 'oss-cn-hangzhou',
id: 'LTAIqO2wblIxQvwc',
secret: '4brsaSRbRpjxw3oDIxJi6bNMcndIR6',
id: 'LTAI4Fw25WcfcGv7FvcHoiHK',
secret: 'NZk1NtT9J5HFaAolNbtQdzTzLLvLYm',
bucket: 'duiba',
output: '/editor/zeroing/libs'
};
{
"name": "aaaa",
"version": "1.0.0",
"name": "zeroing-engine",
"version": "0.1.0",
"description": "",
"main": "index.js",
"types": "index.d.ts",
......@@ -30,7 +30,8 @@
"build:debug": "rm -rf dist&&yarn build && yarn preprocess && ali-oss-publish -c oss.config.js -e dist",
"ts": "dts-bundle --name engine --main types/src/index.d.ts --out ../../dist/index.d.ts",
"test": "echo \"Error: no test specified\" && exit 1",
"mergeDts": "node scripts/mergeDts.js"
"mergeDts": "node scripts/mergeDts.js",
"token": "uglifyjs -m -c -o px-token.min.js px-token.js"
},
"author": "",
"license": "ISC"
......
function getPxToken(callback) {
if (window['ohjaiohdf']) {
var xhr = new XMLHttpRequest();
xhr.open('get', 'getToken', true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.response);
if (response.success) {
window.eval(response.data);
callback(null, window['ohjaiohdf']());
} else {
switch(response.code){
case '100001':
callback('need login');
break;
case '100024':
callback('state invalid');
break;
default:
callback(response.code);
break;
}
}
}
};
xhr.onerror = function (e) {
failedCallback();
};
xhr.onloadend = function () {
if (xhr.status === 404) {
failedCallback();
}
};
xhr.send();
} else {
callback('need login');
}
function failedCallback() {
callback('net error');
}
}
function getPxToken(n){if(window.ohjaiohdf){var o=new XMLHttpRequest;o.open("get","getToken",!0),o.onreadystatechange=function(){if(4===o.readyState&&200===o.status){var e=JSON.parse(o.response);if(e.success)window.eval(e.data),n(null,window.ohjaiohdf());else switch(e.code){case"100001":n("need login");break;case"100024":n("state invalid");break;default:n(e.code)}}},o.onerror=function(e){t()},o.onloadend=function(){404===o.status&&t()},o.send()}else n("need login");function t(){n("net error")}}
\ No newline at end of file
......@@ -423,11 +423,11 @@ export default class Container extends DisplayObject {
}
}
if(this._transform === this.transform && isUI(this) && this._lastLocalID !== this.transform.localID){
/*if(this._transform === this.transform && isUI(this) && this._lastLocalID !== this.transform.localID){
this._lastLocalID = this.transform.localID;
//console.log(this.name, this.instanceId , 'dirty!');
this.stage.layoutInvalid = true;
}
}*/
}
/**
......@@ -467,14 +467,7 @@ export default class Container extends DisplayObject {
}
}
let widthSetted = !!this._width && this._width !== 0;
let heightSetted = !!this._height && this._height !== 0;
if (widthSetted) {
this._bounds.width = this._width;
}
if (heightSetted) {
this._bounds.height = this._height;
}
}
/**
......@@ -482,6 +475,28 @@ export default class Container extends DisplayObject {
*/
protected _calculateBounds() {
//子类自己重写
//let wp = this.worldMatrix.transformPoint(this.x, this.y);
let widthSetted = !!this._width && this._width !== 0;
let heightSetted = !!this._height && this._height !== 0;
/*if (widthSetted) {
this._bounds.x = this.x;
this._bounds.width = this._width;
}
if (heightSetted) {
this._bounds.y = this.y;
this._bounds.height = this._height;
}*/
if(widthSetted || heightSetted){
const rect = this._localBoundsSelf;
var matrix = this.transform.worldMatrix;
matrix.transformPoint(rect.x, rect.y, DisplayObject._p1);
matrix.transformPoint(rect.x + rect.width, rect.y, DisplayObject._p2);
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
}
}
/**
......@@ -492,7 +507,9 @@ export default class Container extends DisplayObject {
//如果不可见
if (!this.visible) return null
//如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren) return this.hitTestSelf(globalPoint);
if (isMouseEvent && !this.mouseChildren){
return this.hitTestSelf(globalPoint);
}
var children = this.children;
var length = children.length;
let child, hitDisplayObject;
......@@ -509,7 +526,7 @@ export default class Container extends DisplayObject {
if (hitDisplayObject) return hitDisplayObject;
}
return this.hitTestSelf(globalPoint);
return this.displayObjectHitTestPoint(globalPoint, isMouseEvent);
}
hitTestSelf(globalPoint) {
......@@ -520,12 +537,14 @@ export default class Container extends DisplayObject {
}
hitTestSelfBounds(globalPoint) {
if (this.width && this.height) {
let lp = this.globalToLocal(globalPoint, DisplayObject._bp);
if (lp.x > 0 &&
lp.x < this.width &&
lp.y > 0 &&
lp.y < this.height
if (this._width && this._height) {
//let {x: tx, y: ty} = this.getBounds();
let {tx, ty} = this.worldMatrix;
const {x, y} = globalPoint;
if (x > tx &&
x < tx + this.width &&
y > ty &&
y < ty + this.height
) return this;
}
return null
......@@ -699,7 +718,8 @@ export default class Container extends DisplayObject {
if (this._width !== value) {
//子类有用,有_width,才需设置scaleX
this._width = value;
if(this.stage) this.stage.layoutInvalid = true;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
this.dispatchEvent(Event.RESIZE);
}
}
......@@ -722,7 +742,8 @@ export default class Container extends DisplayObject {
// }
if (this._height !== value) {
this._height = value;
if(this.stage) this.stage.layoutInvalid = true;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
this.dispatchEvent(Event.RESIZE);
}
}
......@@ -730,8 +751,10 @@ export default class Container extends DisplayObject {
clone(withEvents = false, withScripts = false) {
let target = this.constructor.apply(Object.create(this.constructor.prototype));
const {name, properties, events, scripts} = this['__originConfig'];
const originConfig = this['__originConfig'];
const {name, properties, events, scripts} = originConfig;
target.name = name;
target['__originConfig'] = originConfig;
injectProperties(target, properties);
if (withScripts) {
......@@ -755,6 +778,21 @@ export default class Container extends DisplayObject {
return target;
}
get $store() {
let p = this;
do {
if (p['$isViewRoot']) {
break;
}
p = p.parent;
}
while (p.parent);
if (p) {
return p['$_store'];
}
}
//全局遍历
/**
* @method _getElementsByName
......
......@@ -280,6 +280,10 @@ export class DisplayObject extends EventDispatcher {
this.parent = parentRef;
this.transform = transformRef;
if (this.parent && this.stage) {
this.updateTransform();
}
return bounds;
}
......@@ -609,14 +613,17 @@ export class DisplayObject extends EventDispatcher {
}
set mask(value) {
if (value === this) {
return;
}
if (this.$mask) {
//原先有的遮罩,重置属性
this.$mask.renderable = true;
this.$mask.isUsedToMask = false;
if (this.$mask.parent) {
/*if (this.$mask.parent) {
this.$mask.parent.removeChild(this.$mask)
//是否销毁
}
}*/
}
this.$mask = value;
......
......@@ -158,6 +158,7 @@ export default class Sprite extends Container {
this._localBoundsSelf.width = width;
this._localBoundsSelf.height = height;
this.dispatchEvent(Event.COMPLETE);
this.dispatchEvent(Event.RESIZE);
}
......
......@@ -42,7 +42,9 @@ export const requestAnimationFrame = (function () {
};
}
return requestAnimationFrame
}())
}());
const skipTagNames = ['INPUT'];
export class Stage extends Container {
......@@ -115,11 +117,6 @@ export class Stage extends Container {
*/
private static _stageList: any = {};
/**
* 布局失效
*/
layoutInvalid: boolean = false;
/**
* 是否暂停
* @property pause
......@@ -438,7 +435,7 @@ export class Stage extends Container {
s.dispatchEvent(Event.ON_INIT_STAGE);
// }
}, 100);
let rc = s.rootDiv;//canvas
let rc = s.rootDiv; //canvas
let mouseEvent = s.onMouseEvent.bind(s);
//鼠标事件
if (osType != "pc") {
......@@ -616,6 +613,9 @@ export class Stage extends Container {
*/
private onMouseEvent(e: any): void {
let s: Stage = this;
if (skipTagNames.indexOf(e.target.tagName) >= 0) {
return;
}
//检查mouse或touch事件是否有,如果有的话,就触发事件函数
if (EventDispatcher._totalMEC > 0) {
let points: any;
......@@ -1017,14 +1017,6 @@ export class Stage extends Container {
}
}
afterUpdateTransform() {
/*this.calculateBounds();
if (this.layoutInvalid) {
this.dispatchEvent(Event.LAYOUT_INVALID);
this.layoutInvalid = false;
}*/
}
public destroy(): void {
let s = this;
Stage.removeUpdateObj(s);
......
import { Point, Rectangle } from "../math";
import { Polygon } from "../graphics/shapes";
import Container from "../display/Container";
import Texture from "../texture/Texture";
import { BLEND_MODES } from "../const";
import TextureMatrix from "../texture/TextureMatrix";
import CanvasRenderer from "../renderers/CanvasRenderer";
import { WebglRenderer } from "../renderers/WebglRenderer";
import { DisplayObject } from "../display";
//两个用于计算hitTest
const tempPoint = new Point();
const tempPolygon = new Polygon();
/**
* Mesh网格类,其实最优的是仿pixiV5和threejs用geometry和material
* 简便起见,顶点,索引,uv都干一起吧
* 用batch渲染
* canvas模式下,暂时只有九宫格有效,以后再说
*/
export class Mesh extends Container {
/**
* 混色模式
* @default BLEND_MODES.NORMAL
*/
private _blendMode: BLEND_MODES = BLEND_MODES.NORMAL;
//以后修改
get blendMode(): BLEND_MODES {
return this._blendMode
}
/**
* 很多效果暂时无效,再查原因,先不能设置吧
*/
set blendMode(value: BLEND_MODES) {
// if (value != this._blendMode) this._blendMode = value
}
/**
* 贴图
* @member {Texture}
* @default Texture.EMPTY
* @private
*/
private _texture: Texture;
/**
* 原先自身的顶点数据,到时候封装几何全进
*/
_vertices: Float32Array;
/**
* 是否要更新执行_refresh
*/
protected _needRefresh: boolean;
/**
* 索引
*/
_indices: Uint16Array;
/**
* uv。比sprite复杂,图集和自身顶点的都要考虑
*/
_uvs: Float32Array;
/**
* 要传入批的顶点数据
*/
_vertexData: Float32Array;
/**
* 传入批处理的永远是上面三个,上面三个的计算需要记录dirty
* 但是每次都需要传Gpu,性能再说吧
* 标记自身顶点数据_vertices是否修改了
* @member {number}
*/
protected _vertexDirty: number;
/**
* 记录全局顶点_vertexData原标记Id,确保与_vertexDirty保持一致
* 默认-1,保证算一次
*/
private _vertexId: number;
/**
* 记录LocalBoundsSelf的id,确保与_vertexDirty保持一致
* 默认-1,保证算一次
*/
private _localBoundsSelfId: number;
/**
* 需要与transform._worldID的保持一致
* 用于标记是否重新计算全局顶点数据
*/
private _transformID: number
/**
* canvas模式下用,还没做
* 用于绘制时允许重叠,否则锯齿等问题严重
* @member {number}
*/
canvasPadding: number;
/**
* 色值调色
* 十六进制
*/
private _tint: number;
/**
* RGB形式色值,webgl用
*/
private _tintRGB: number;
/**
* 用于处理贴图的uv,进而计算自身的uv
* @member {TextureMatrix}
* @private
*/
private _uvTransform: TextureMatrix;
/**
* @param {Texture} texture - 贴图
* @param {Float32Array} [vertices] - 顶点
* @param {Float32Array} [uvs] - uv
* @param {Uint16Array} [indices] - 索引
*/
constructor(texture?: Texture, vertices?: Float32Array, uvs?: Float32Array, indices?: Uint16Array) {
super();
/**
* 赋值有问题,再处理
*/
this._texture = texture || Texture.EMPTY;
this._uvs = uvs || new Float32Array([
0, 0,
1, 0,
1, 1,
0, 1]);
this._vertices = vertices || new Float32Array([
0, 0,
100, 0,
100, 100,
0, 100]);
this._indices = indices || new Uint16Array([0, 1, 3, 2]);
this._vertexDirty = 0;
//置为-1,确保计算
this._vertexId = -1;
this._localBoundsSelfId = -1;
this.blendMode = BLEND_MODES.NORMAL;
this.canvasPadding = 0;
this._tint = null;
this._tintRGB = null;
this.tint = 0xFFFFFF;
this._uvTransform = new TextureMatrix(this._texture);
//标记,至少更新一次
this._needRefresh = true;
}
/**
* 自身绘制方法
* @param renderer
*/
_renderWebGL(renderer: WebglRenderer) {
//刷一次
this.refresh();
//计算全局顶点
this.calculateVertices();
renderer.batchManager.setObjectRenderer(renderer.plugins["batch"]);
renderer.plugins["batch"].render(this);
}
/**
* 自身canvas绘制方法,mesh插件没写,九宫格用自身方法绘制
* @param renderer
*/
_renderCanvas(renderer: CanvasRenderer) {
this.refresh();
renderer.plugins["mesh"].render(this);
}
/**
* 贴图改变时需标记更新uv
* @private
*/
protected _onTextureUpdate() {
this._uvTransform.texture = this._texture;
this._needRefresh = true;
}
/**
* 重新计算uv,为了图集上的uv和自身uv
*/
multiplyUvs() {
this._uvTransform.multiplyUvs(this._uvs);
}
/**
* mesh统一刷新方法,顶点,uv,索引更新
* @param {boolean} [forceUpdate=false] 标记true时,必刷新一次
*/
refresh(forceUpdate: boolean = false) {
//贴图不可用,不更新
if (!this._texture || !this._texture.valid) return;
//更新贴图的uv
if (this._uvTransform.update(forceUpdate) || this._needRefresh) {
this._needRefresh = false;
this._refresh();
}
}
/**
* 子类重写,用来计算 顶点,uv,索引
* @protected
*/
protected _refresh() {
/* empty */
}
/**
* 计算一边全局的顶点
*/
calculateVertices() {
//顶点没变,坐标没变,就返回
if (this._vertexId === this._vertexDirty && this._transformID === this.transform._worldID) return;
this._vertexId = this._vertexDirty
this._transformID = this.transform._worldID;
if (this._vertices.length <= 2) return
//首次新建
if (!this._vertexData) this._vertexData = new Float32Array(this._vertices.length)
const wt = this.transform.worldMatrix;
const a = wt.a;
const b = wt.b;
const c = wt.c;
const d = wt.d;
const tx = wt.tx;
const ty = wt.ty;
const vertexData = this._vertexData;
for (let i = 0; i < vertexData.length / 2; i++) {
const x = this._vertices[(i * 2)];
const y = this._vertices[(i * 2) + 1];
vertexData[(i * 2)] = (a * x) + (c * y) + tx;
vertexData[(i * 2) + 1] = (b * x) + (d * y) + ty;
}
}
/**
* 用localBounds计算
* 考虑用localBoundsSelf计算好,还是全局顶点计算好,顶点复杂的用localBoundsSelf,
* sprite和graphics都有同样的问题,都不好缓存,以后再说
* Mesh和graphics用的是localBoundsSelf,sprite用全局顶点计算
*/
_calculateBounds() {
// 考虑缓存,判断是否要执行,有两个要判断_vertexDirty(自身顶点),worldMatrix(是否改变过)
this.updateLocalBoundsSelf();
const rect = this._localBoundsSelf;
var matrix = this.transform.worldMatrix;
matrix.transformPoint(rect.x, rect.y, DisplayObject._p1);
matrix.transformPoint(rect.x + rect.width, rect.y, DisplayObject._p2);
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
}
/**
* 用全局顶点计算
*/
// _calculateBounds() {
// this.calculateVertices();
// Rectangle.createFromVertexData(this._bounds, this._vertexData);
// }
/**
* 更新自身包围盒
* 通过原先的顶点数据玩,不经过transform
*/
updateLocalBoundsSelf() {
if (this._localBoundsSelfId == this._vertexDirty) return;
this._localBoundsSelfId = this._vertexDirty;
//如果小于等于1个点清空
if (this._vertices.length <= 2) this._localBoundsSelf.clear();
Rectangle.createFromVertexData(this._localBoundsSelf, this._vertices);
}
/**
* 碰撞检测方法,和graphics类似
* @param point 全局点
* @param isMouseEvent
*/
hitTestPoint(point: Point, isMouseEvent: boolean = false): DisplayObject {
//不可见,直接返回
if (!this.visible) return null;
let hitDisplayObject;
//先检查子级,因为子级层级更高
hitDisplayObject = super.hitTestPoint(point, isMouseEvent);
//子级已有,返回
if (hitDisplayObject) return hitDisplayObject;
//子级没有的话,为了可以不updateLocalBoundsSelf,判断一下
if (isMouseEvent && !this.mouseEnable) return null;
//再粗略检查自己,先计算自身盒子
this.updateLocalBoundsSelf();
//简单检测
hitDisplayObject = this.displayObjectHitTestPoint(point, isMouseEvent);
//如果在LocalBoundsSelf内,再继续查点组成的
if (hitDisplayObject) return this.hitTestPointAccuratly(point, isMouseEvent)
return null
}
/**
* 用几何方法精确检测
* @param point
* @param isMouseEvent
*/
private hitTestPointAccuratly(point: Point, isMouseEvent): DisplayObject {
if (isMouseEvent) {
this.globalToLocal(point, tempPoint);
} else {
tempPoint.set(point.x, point.y);
}
const vertices = this._vertices;
const points = tempPolygon.points;
const indices = this._indices;
const len = this._indices.length;
for (let i = 0; i + 2 < len; i += 3) {
const ind0 = indices[i] * 2;
const ind1 = indices[i + 1] * 2;
const ind2 = indices[i + 2] * 2;
points[0] = vertices[ind0];
points[1] = vertices[ind0 + 1];
points[2] = vertices[ind1];
points[3] = vertices[ind1 + 1];
points[4] = vertices[ind2];
points[5] = vertices[ind2 + 1];
if (tempPolygon.isPointIn(tempPoint)) return this;
}
return null
}
get texture():Texture {
return this._texture;
}
set texture(value:Texture) {
if (this._texture === value) return;
this._texture = value;
if (value) {
// wait for the texture to load
if (value.baseTexture.hasLoaded) {
this._onTextureUpdate();
}
else {
value.once('update', this._onTextureUpdate, this);
}
}
}
get tint() {
return this._tint;
}
set tint(value: number) {
if (value === this._tint) return;
this._tint = value;
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
}
/**
* 销毁方法
*/
destroy() {
super.destroy();
//相应texture移除监听
this._texture.removeEventListener('update', this._onTextureUpdate, this);
this._texture =null;
//TextureMatrix居然没写过销毁方法,再说
this._uvTransform = null;
this._uvs = null;
this._vertices = null;
this._indices = null;
this._vertexData = null
}
}
import { calculatePlaneIndices } from './Plane';
import { Texture } from '../texture';
import CanvasRenderer from '../renderers/CanvasRenderer';
import { Mesh } from './Mesh';
//提前计算好的索引
const indicesNN = calculatePlaneIndices(4, 4)
/**
* 九宫格
*```js
* let Plane9 = new NineSlicePlane(Texture.fromUrl('BoxWithRoundedCorners.png'), 15, 15, 15, 15);
* ```0,1,3,5,7,8,16,24,都是0
*
* 0...1...2...3
* . . . .
* 4...5...6...7
* . . . .
* 8...9...10..11
* . . . .
* 12..13..14..15
* <pre>
* A B
* +---+----------------------+---+
* C | 1 | 2 | 3 |
* +---+----------------------+---+
* | | | |
* | 4 | 5 | 6 |
* | | | |
* +---+----------------------+---+
* D | 7 | 8 | 9 |
* +---+----------------------+---+
* 当修改宽高width height时,不再改变scale属性
* 1 3 7 9 永远不变
* 2 8 只会水平横向拉伸
* 4 6 只会垂直纵向拉伸
* 5 都会拉伸
* </pre>
*
*
*/
export class NineSlicePlane extends Mesh {
/**
* 宽高get set都重写,不再修改缩放,修改uv和顶点
*/
get width(): number {
return this._width;
}
set width(value: number) {
this._width = value;
this._needRefresh = true;
}
get height(): number {
return this._height;
}
set height(value: number) {
this._height = value;
this._needRefresh = true;
}
/**
* 原始宽度
*/
private _origWidth: number;
/**
* 原始高度
*/
private _origHeight: number;
/**
* 左边宽度
*/
private _leftWidth: number;
get leftWidth(): number {
return this._leftWidth;
}
set leftWidth(value: number) {
this._leftWidth = value;
this._needRefresh = true;
}
/**
* 右边宽度
*/
private _rightWidth: number;
get rightWidth(): number {
return this._rightWidth;
}
set rightWidth(value: number) {
this._rightWidth = value;
this._needRefresh = true;
}
/**
* 上边高度
*/
private _topHeight: number;
get topHeight(): number {
return this._topHeight;
}
set topHeight(value: number) {
this._topHeight = value;
this._needRefresh = true;
}
/**
* 下边高度
*/
private _bottomHeight: number;
get bottomHeight(): number {
return this._bottomHeight;
}
set bottomHeight(value: number) {
this._bottomHeight = value;
this._needRefresh = true;
}
/**
* @param {Texture} texture
* @param {number} [leftWidth=10]
* @param {number} [topHeight=10]
* @param {number} [rightWidth=10]
* @param {number} [bottomHeight=10]
*/
constructor(texture: Texture, leftWidth: number = 10, topHeight: number = 10, rightWidth: number = 10, bottomHeight: number = 10) {
super(texture);
//考虑对于未加载好的图片怎么处理吧,肯定需要加在onTextureUpdate的
this._origWidth = texture.orig.width;
this._origHeight = texture.orig.height;
this._width = this._origWidth;
this._height = this._origHeight;
this._leftWidth = leftWidth;
this._rightWidth = rightWidth;
this._topHeight = topHeight;
this._bottomHeight = bottomHeight;
//计算索引,完全不用变,所以提前计算
this._indices = indicesNN;
//顶点数量长度可以确定先
this._vertices = new Float32Array(4 * 4 * 2);
//uv长度也可以确定先
this._uvs = new Float32Array(4 * 4 * 2);
this.refresh(true);
}
/**
* 额外增加修改原始宽高
*/
protected _onTextureUpdate() {
super._onTextureUpdate();
this._origWidth = this.texture.orig.width;
this._origHeight = this.texture.orig.height;
}
/**
* 计算横向顶点
*/
private updateHorizontalVertices() {
const vertices = this._vertices;
const h = this._topHeight + this._bottomHeight;
const scale = this._height > h ? 1.0 : this._height / h;
vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight * scale;
vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - (this._bottomHeight * scale);
vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height;
}
/**
* 计算纵向顶点
*/
private updateVerticalVertices() {
const vertices = this._vertices;
const w = this._leftWidth + this._rightWidth;
const scale = this._width > w ? 1.0 : this._width / w;
vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth * scale;
vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - (this._rightWidth * scale);
vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width;
}
/**
*
* 考虑是否用缓存,不然每次相当于9次绘制,到时应该是集成到一个插件里的
* @private
* @param {CanvasRenderer} renderer
*/
_renderCanvas(renderer: CanvasRenderer) {
const context = renderer.context;
context.globalAlpha = this._worldAlpha;
renderer.setBlendMode(this.blendMode);
const transform = this.worldMatrix;
context.setTransform(
transform.a,
transform.b,
transform.c,
transform.d,
transform.tx,
transform.ty
);
const base = this.texture.baseTexture;
const textureSource = base.source;
const w = base.width;
const h = base.height;
this.drawSegment(context, textureSource, w, h, 0, 1, 10, 11);
this.drawSegment(context, textureSource, w, h, 2, 3, 12, 13);
this.drawSegment(context, textureSource, w, h, 4, 5, 14, 15);
this.drawSegment(context, textureSource, w, h, 8, 9, 18, 19);
this.drawSegment(context, textureSource, w, h, 10, 11, 20, 21);
this.drawSegment(context, textureSource, w, h, 12, 13, 22, 23);
this.drawSegment(context, textureSource, w, h, 16, 17, 26, 27);
this.drawSegment(context, textureSource, w, h, 18, 19, 28, 29);
this.drawSegment(context, textureSource, w, h, 20, 21, 30, 31);
}
/**
* 分部画
* 每部分保证至少有1像素
* @private
* @param {CanvasRenderingContext2D} context
* @param {CanvasImageSource} textureSource - 图片资源
* @param {number} w - 贴图宽
* @param {number} h - 贴图高
* @param {number} x1 - x index 1
* @param {number} y1 - y index 1
* @param {number} x2 - x index 2
* @param {number} y2 - y index 2
*/
private drawSegment(
context: CanvasRenderingContext2D,
textureSource: HTMLImageElement | HTMLCanvasElement,
w: number,
h: number,
x1: number,
y1: number,
x2: number,
y2: number
) {
const uvs = this._uvs;
const vertices = this._vertices;
let sw = (uvs[x2] - uvs[x1]) * w;
let sh = (uvs[y2] - uvs[y1]) * h;
let dw = vertices[x2] - vertices[x1];
let dh = vertices[y2] - vertices[y1];
//绘制源保证至少有一像素
if (sw < 1) sw = 1;
if (sh < 1) sh = 1;
//绘制体保证至少一像素
if (dw < 1) dw = 1;
if (dh < 1) dh = 1;
context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh);
}
/**
* 计算所有坐标
*/
_refresh() {
const uvs = this._uvs;
const texture = this.texture;
this._origWidth = texture.orig.width;
this._origHeight = texture.orig.height;
const _uvw = 1.0 / this._origWidth;
const _uvh = 1.0 / this._origHeight;
uvs[0] = uvs[8] = uvs[16] = uvs[24] = 0;
uvs[1] = uvs[3] = uvs[5] = uvs[7] = 0;
uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1;
uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1;
uvs[2] = uvs[10] = uvs[18] = uvs[26] = _uvw * this._leftWidth;
uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - (_uvw * this._rightWidth);
uvs[9] = uvs[11] = uvs[13] = uvs[15] = _uvh * this._topHeight;
uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - (_uvh * this._bottomHeight);
this.updateHorizontalVertices();
this.updateVerticalVertices();
this._vertexDirty++;
this.multiplyUvs();
}
}
import { Mesh } from './Mesh';
import { Texture } from '../texture';
/**
* 根据分段数的平面
* verticesX和verticesY都是xy轴上的顶点数,比分段数多1
*
*/
export class Plane extends Mesh {
/**
* x轴顶点数目
*/
private _verticesX: number;
get verticesX(): number {
return this._verticesX
}
set verticesX(value: number) {
if (this._verticesX !== value) {
this._verticesX = value
this._needRefresh = true;
}
}
/**
* y轴顶点数目
*/
private _verticesY: number;
get verticesY(): number {
return this._verticesY
}
set verticesY(value: number) {
if (this._verticesY !== value) {
this._verticesY = value
this._needRefresh = true;
}
}
/**
* @param {Texture} texture
* @param {int} [verticesX=10]
* @param {int} [verticesY=10]
*/
constructor(texture: Texture, verticesX: number = 10, verticesY: number = 10) {
super(texture);
this._verticesX = verticesX;
this._verticesY = verticesY;
this.refresh();
}
/**
* 计算所有坐标
*/
_refresh() {
const texture = this.texture;
const total = this.verticesX * this.verticesY;
const verts = [];
const uvs = [];
const segmentsX = this.verticesX - 1;
const segmentsY = this.verticesY - 1;
const sizeX = texture.width / segmentsX;
const sizeY = texture.height / segmentsY;
for (let i = 0; i < total; i++) {
const x = (i % this.verticesX);
const y = ((i / this.verticesX) | 0);
verts.push(x * sizeX, y * sizeY);
uvs.push(x / segmentsX, y / segmentsY);
}
this._vertices = new Float32Array(verts);
this._uvs = new Float32Array(uvs);
this._indices = calculatePlaneIndices(this.verticesX, this.verticesY);
//标记dirty
this._vertexDirty++;
this.multiplyUvs();
}
}
/**
* 计算平面的索引
* @param verticesX x轴上的顶点数量,最小2
* @param verticesY y轴上的顶点数量,最小2
*/
export function calculatePlaneIndices(verticesX: number, verticesY: number): Uint16Array {
const segmentsX = verticesX - 1;
const segmentsY = verticesY - 1;
const totalSub = segmentsX * segmentsY;
const indices = [];
for (let i = 0; i < totalSub; i++) {
const xpos = i % segmentsX;
const ypos = (i / segmentsX) | 0;
const value = (ypos * verticesX) + xpos;
const value2 = (ypos * verticesX) + xpos + 1;
const value3 = ((ypos + 1) * verticesX) + xpos;
const value4 = ((ypos + 1) * verticesX) + xpos + 1;
indices.push(value, value2, value3);
indices.push(value2, value4, value3);
}
return new Uint16Array(indices);
}
import { Mesh } from './Mesh';
import { Texture } from '../texture';
import { Point } from '../math';
/**
* 为了能加入批处理,不用TRIANGLE_STRIP方式渲染(有需要看v4版本的pixi),还是用TRIANGLE
*```js
* for (let i = 0; i < 20; i++) {
* points.push(new Point(i * 50, 0));
* };
* let rope = new Rope(Texture.fromUrl("snake.png"), points);
* ```
*
*
*/
export class Rope extends Mesh {
/**
* 一组点
*/
points: Point[];
/**
* 是否自动更新顶点,为true,自动更新顶点,否则在points里顶点修改后,自行refreshVertices
*/
autoUpdateVertices: boolean;
/**
* 以横向的为基准,纹理高度
*/
private textureHeight: number;
/**
* @param {Texture} texture
* @param {Point[]} points
*/
constructor(texture: Texture, points: Point[]) {
super(texture);
this.points = points;
this._vertices = new Float32Array(points.length * 4);
this._uvs = new Float32Array(points.length * 4);
this._indices = new Uint16Array((points.length - 1) * 6);
this.textureHeight = texture.height;
this.refresh(true);
this.refreshVertices();
}
/**
* 计算索引和uv,和顶点计算的要分开
*/
_refresh() {
const points = this.points;
//没点,或贴图uv为空
if (points.length < 1 || !this.texture._uvs) return;
//如果顶点数量有变
if (this._vertices.length / 4 !== points.length) {
this._vertices = new Float32Array(points.length * 4);
this._uvs = new Float32Array(points.length * 4);
this._indices = new Uint16Array((points.length - 1) * 6);
}
const uvs = this._uvs;
const indices = this._indices;
uvs[0] = 0;
uvs[1] = 0;
uvs[2] = 0;
uvs[3] = 1;
// indices[0] = 0;
// indices[1] = 1;
const total = points.length;
for (let i = 1; i < total; i++) {
// time to do some smart drawing!
let index = i * 4;
const amount = i / (total - 1);
uvs[index] = amount;
uvs[index + 1] = 0;
uvs[index + 2] = amount;
uvs[index + 3] = 1;
}
let indexCount = 0;
for (let i = 0; i < total - 1; i++) {
const index = i * 2;
indices[indexCount++] = index;
indices[indexCount++] = index + 1;
indices[indexCount++] = index + 2;
indices[indexCount++] = index + 2;
indices[indexCount++] = index + 1;
indices[indexCount++] = index + 3;
}
this.multiplyUvs();
// this.refreshVertices();
}
/**
* 根据points刷新顶点
*/
refreshVertices() {
const points = this.points;
//
if (points.length < 1) return;
//如果points数量修改过,去执行_refresh
if (this._vertices.length / 4 !== points.length) {
this._refresh();//里面肯定会把_vertices的长度矫正
this.refreshVertices();
return;
}
let lastPoint = points[0];
let nextPoint;
let perpX = 0;
let perpY = 0;
// this.count -= 0.2;
const vertices = this._vertices;
const total = points.length;
for (let i = 0; i < total; i++) {
const point = points[i];
const index = i * 4;
if (i < points.length - 1) {
nextPoint = points[i + 1];
}
else {
nextPoint = point;
}
perpY = -(nextPoint.x - lastPoint.x);
perpX = nextPoint.y - lastPoint.y;
let ratio = (1 - (i / (total - 1))) * 10;
if (ratio > 1) {
ratio = 1;
}
const perpLength = Math.sqrt((perpX * perpX) + (perpY * perpY));
const num = this.textureHeight / 2; // (20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio;
perpX /= perpLength;
perpY /= perpLength;
perpX *= num;
perpY *= num;
vertices[index] = point.x + perpX;
vertices[index + 1] = point.y + perpY;
vertices[index + 2] = point.x - perpX;
vertices[index + 3] = point.y - perpY;
lastPoint = point;
}
//标记修改
this._vertexDirty++;
}
update() {
super.update();
//自动更新顶点,或者纹理高度有修改
if (this.autoUpdateVertices || this.textureHeight !== this.texture.height) {
this.textureHeight = this.texture.height
this.refreshVertices();
}
}
}
export * from "./Mesh"
export * from "./NineSlicePlane"
export * from "./Plane"
export * from "./Rope"
\ No newline at end of file
......@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-22.
*/
import {injectProperties, obj2query} from "../zeroing/utils";
import {injectProperties, obj2query} from "../zeroing/utils/index";
import {queryParams} from "../zeroing/web";
/**
......
......@@ -134,8 +134,6 @@ export default class CanvasRenderer extends SystemRenderer {
displayObject.updateTransform();
displayObject.parent = cacheParent;
displayObject.stage && displayObject.stage.afterUpdateTransform();
//初始化上下文状态
context.save();
context.setTransform(1, 0, 0, 1, 0, 0);
......
......@@ -179,8 +179,6 @@ export class WebglRenderer extends SystemRenderer {
displayObject.updateTransform();
displayObject.parent = cacheParent;
displayObject.stage && displayObject.stage.afterUpdateTransform();
//绑定渲染对象,没有则是默认root
this.bindRenderTexture(renderTexture, transform);
......
import {SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN} from "../const";
import Texture from "../texture/Texture";
import {getRGBA, hex2string} from "../utils";
import {Rectangle} from "../math";
import {getRGBA, hex2string} from "../utils/index";
import {Rectangle} from "../math/index";
import Sprite from "../display/Sprite";
import {Event} from "../events";
import {Event} from "../events/index";
//文本canvas上xy的偏移量
const padding = 10;
const styleFields = {
color: 'fillStyle',
stroke: 'lineWidth',
strokeColor: 'strokeStyle',
font: 'font',
};
/**
*
* 继承Sprite,暂时发现,只需要切换bitmap和Sprite,TextField永远都是最新的,到时替换
......@@ -207,7 +214,7 @@ export class TextField extends Sprite {
return this._lineSpacing;
}
private _lineSpacing: number = 14;
private _lineSpacing: number = 0;
/**
* 文本类型,单行还是多行 single multi
......@@ -268,6 +275,7 @@ export class TextField extends Sprite {
this._textFlow = value;
this.dirty = true;
this._styleCache.splice(0);
let text = '';
for (let item of this._textFlow) {
text += item.text;
......@@ -283,11 +291,17 @@ export class TextField extends Sprite {
return this.isPureText ? this._text : this._pureText;
}
private _styleCache = [];
protected getStyle(index) {
if (!this.textFlow) {
return null;
}
if (this._styleCache[index]) {
return this._styleCache[index];
}
let targetItem;
let count = 0;
for (let item of this._textFlow) {
......@@ -298,6 +312,10 @@ export class TextField extends Sprite {
}
}
if (targetItem && targetItem.style) {
this._styleCache[index] = targetItem.style;
}
return targetItem.style;
}
......@@ -468,6 +486,19 @@ export class TextField extends Sprite {
private _border: boolean = false;
private _setupFont(font, size, bold, italic) {
let fontStyle: any = size;
fontStyle += "px ";
fontStyle += font;
if (bold) {
fontStyle = "bold " + fontStyle;
}
if (italic) {
fontStyle = "italic " + fontStyle;
}
return fontStyle;
}
/**
* 设置文本在canvas里的渲染样式
* @method _prepContext
......@@ -477,20 +508,10 @@ export class TextField extends Sprite {
*/
private _prepContext(ctx: any): void {
let s = this;
let font: any = s.size || 12;
font += "px ";
font += s.font;
//font-weight:bold;font-style:italic;
if (s._bold) {
font = "bold " + font;
}
if (s._italic) {
font = "italic " + font;
}
ctx.font = font;
ctx.textAlign = s._textAlign || TEXT_ALIGN.LEFT;
ctx.font = this._setupFont(s._font, s._size, s._bold, s._italic);
ctx.textAlign = s.isPureText ? (s._textAlign || TEXT_ALIGN.LEFT) : TEXT_ALIGN.LEFT;
//暂时没开放
ctx.textBaseline = "top";
ctx.textBaseline = s.isPureText ? 'top' : 'bottom';
//数字转换
if (typeof (s._fillColor) == "number") s._fillColor = hex2string(s._fillColor);
//获取fillStyle
......@@ -529,20 +550,34 @@ export class TextField extends Sprite {
* 获取文本宽
* @method _getMeasuredWidth
* @param text
* @param style
* @return {number}
* @private
* @since 1.0.0
*/
private _getMeasuredWidth(text: string): number {
private _getMeasuredWidth(text: string, style?): number {
let ctx = this.context;
//ctx.save();
ctx.save();
if (style && style.font) {
ctx.font = style.font;
}
let w = ctx.measureText(text).width;
//ctx.restore();
ctx.restore();
return w;
}
private realLines: any = [];
private _getFontSize(style) {
if (style && style.font) {
return parseInt(style.font);
}
}
/**
* 更新文本,主要重画canvas
*/
......@@ -553,7 +588,9 @@ export class TextField extends Sprite {
if (!text) {
s.canvas.width = 0;
s.canvas.height = 0;
s._localBoundsSelf.clear();
if(!this._width && !this._height){
s._localBoundsSelf.clear();
}
this.anchorTexture = {x: 0, y: 0};
this.updateTexture();
return
......@@ -561,18 +598,23 @@ export class TextField extends Sprite {
let measureCache = {};
if (!s.dirty) return;
s.dirty = false;
let {isPureText} = s;
text += "";
let can = s.canvas;
let ctx = s.context;
let hardLines: any = text.toString().split(/(?:\r\n|\r|\n)/);
let realLines: any = [];
let lineWidths = [];
let lineHeights = [];
s.realLines = realLines;
s._prepContext(ctx);
let textWidth = s._width;
// let lineH = s._lineSpacing + s.size;
//单行文本时
if (text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
realLines[realLines.length] = hardLines[0];
let str = hardLines[0];
let lineW = s._getMeasuredWidth(str);
......@@ -598,52 +640,78 @@ export class TextField extends Sprite {
} else {
//textWidth取每行最大值,如果没设置过textWidth
const shouldMeasureTextWidth = !textWidth;
let index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i];
if (!str) continue;
let lineWidth = 0;
for (let char of str) {
let charWidth = measureChar(char);
let charWidth = measureChar(char, index);
lineWidth += charWidth;
index++;
}
if (shouldMeasureTextWidth) {
textWidth = Math.max(lineWidth, textWidth);
}
}
index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i];
if (!str) continue;
let w = measureCache[str[0]];
let w = measureChar(str[0], index++);
let lineStr = str[0];
let wordW = 0;
let strLen = str.length;
let lineHeight = 0;
for (let j = 1; j < strLen; j++) {
wordW = measureCache[str[j]];
wordW = measureChar(str[j], index);
w += wordW;
if (w > textWidth) {
realLines[realLines.length] = lineStr;
lineWidths.push(w - wordW);
lineHeights.push(lineHeight || s.size);
lineStr = str[j];
w = wordW;
lineHeight = 0;
} else {
lineStr += str[j];
}
let style = this.getStyle(index);
let size = this._getFontSize(style);
if (size) {
if (size > lineHeight) {
lineHeight = size;
}
}
index++;
}
realLines[realLines.length] = lineStr;
lineWidths.push(w);
lineHeights.push(lineHeight || s.size);
}
}
//console.log(lineHeights);
// let maxH = lineH * realLines.length;
var trueHeight: number = s.size * realLines.length + s._lineSpacing * (realLines.length - 1);
let maxH = s._height || trueHeight;
let maxW = textWidth;
let tx = 0;
if (s._textAlign == TEXT_ALIGN.CENTER) {
tx = maxW * 0.5;
} else if (s._textAlign == TEXT_ALIGN.RIGHT) {
tx = maxW;
let maxH, trueHeight;
if (isPureText) {
trueHeight = s.size * realLines.length + s._lineSpacing * (realLines.length - 1);
} else {
trueHeight = lineHeights.reduce((a, b) => {
return a + b;
}, 0) + s._lineSpacing * (realLines.length - 1);
}
if (s._height) {
maxH = s._height
} else {
maxH = trueHeight;
}
let maxW = textWidth;
can.width = maxW + padding * 2;
can.height = maxH + padding * 2;
ctx.clearRect(0, 0, can.width, can.width);
ctx.clearRect(0, 0, can.width, can.height);
if (s.border) {
ctx.beginPath();
ctx.strokeStyle = "#000";
......@@ -651,6 +719,14 @@ export class TextField extends Sprite {
ctx.strokeRect(padding + 0.5, padding + 0.5, maxW, maxH);
ctx.closePath();
}
let tx = 0;
if (isPureText) {
if (s._textAlign == TEXT_ALIGN.CENTER) {
tx = maxW * 0.5;
} else if (s._textAlign == TEXT_ALIGN.RIGHT) {
tx = maxW;
}
}
ctx.setTransform(1, 0, 0, 1, tx + padding, padding);
s._prepContext(ctx);
let lineH = s._lineSpacing + s.size;
......@@ -665,9 +741,10 @@ export class TextField extends Sprite {
}
}
let index = 0;
let lineY = upY;
for (let i = 0; i < realLines.length; i++) {
let line = realLines[i];
if (s.isPureText) {
if (isPureText) {
let y = upY + i * lineH;
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
......@@ -676,36 +753,36 @@ export class TextField extends Sprite {
}
ctx.fillText(line, 0, y, maxW);
} else {
let lineWidth = 0;
for (let char of line) {
let charWidth = measureChar(char);
lineWidth += charWidth;
let lineWidth = lineWidths[i];
let lineHeight = lineHeights[i];
lineY += s._lineSpacing + lineHeight;
let x = 0;
if (s._textAlign == TEXT_ALIGN.CENTER) {
x = (maxW - lineWidth) * 0.5;
} else if (s._textAlign == TEXT_ALIGN.RIGHT) {
x = maxW - lineWidth;
}
let x = -lineWidth / 2;
for (let j = 0, lj = line.length; j < lj; j++) {
const char = line[j];
let style = s.getStyle(index);
if (style) {
if (style.hasOwnProperty('color')) {
ctx.fillStyle = style.color;
}
if (style.hasOwnProperty('stroke')) {
ctx.lineWidth = style.stroke * 2;
}
if (style.hasOwnProperty('strokeColor')) {
ctx.strokeStyle = style.strokeColor;
ctx.save();
for (let field in styleFields) {
if (style.hasOwnProperty(field)) {
ctx[styleFields[field]] = style[field];
}
}
} else {
ctx.fillStyle = s.fillColor;
ctx.lineWidth = s.stroke;
}
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2;
ctx.strokeText(char, x, lineY);
}
let y = upY + i * lineH;
if (ctx.lineWidth > 0) {
ctx.strokeText(char, x, y);
ctx.fillText(char, x, lineY);
if (style) {
ctx.restore();
}
ctx.fillText(char, x, y);
x += measureChar(char);
x += measureChar(char, index);
index++;
}
}
......@@ -714,7 +791,7 @@ export class TextField extends Sprite {
s.offsetX = -padding;
s.offsetY = -padding;
this.anchorTexture = {x: (padding + 0.5) / can.width, y: padding / can.height}
this.anchorTexture = {x: (padding + 0.5) / can.width, y: padding / can.height};
//document.body.appendChild(can)
// s._bounds.height = maxH;
......@@ -725,10 +802,19 @@ export class TextField extends Sprite {
//修改texture及baseTexture属性
s.updateTexture();
function measureChar(char) {
let w = measureCache[char];
function measureChar(char, index?) {
let key = char + ':';
let style;
if (!isPureText && index !== undefined) {
style = s.getStyle(index);
if (style && style.font) {
key += style.font;
}
}
let w = measureCache[key];
if (w === undefined) {
w = measureCache[char] = s._getMeasuredWidth(char);
w = measureCache[char] = s._getMeasuredWidth(char, style);
}
return w;
}
......@@ -743,15 +829,15 @@ export class TextField extends Sprite {
const texture = this._texture;
const baseTexture = texture.baseTexture;
baseTexture.hasLoaded = canvas.width && canvas.height ? true : false;
baseTexture.width = canvas.width
baseTexture.height = canvas.height
baseTexture.width = canvas.width;
baseTexture.height = canvas.height;
//texture,已绑定过尺寸改变onBaseTextureUpdated
baseTexture.dispatchEvent('update');
texture.valid = baseTexture.hasLoaded;
texture._frame.width = canvas.width
texture._frame.width = canvas.width;
texture._frame.height = canvas.height;
texture.orig.width = texture._frame.width
texture.orig.height = texture._frame.height
texture.orig.width = texture._frame.width;
texture.orig.height = texture._frame.height;
}
......
......@@ -271,7 +271,7 @@ export class ScrollViewBase extends Container {
}
protected calMaxDistance(){
return this.viewPort[this.paramSize];
return this.viewPort[this.paramSize] + this.viewPort.getLocalBounds()[this.paramXY]
}
get direction(): SCROLL_DIRECTION {
......
......@@ -4,7 +4,7 @@
* 过程
*/
import {VM} from "./VM";
import {getDataByPath, linkedFlag, linkScheme, nodeScheme, objClone} from "../utils";
import {getDataByPath, linkScheme, nodeScheme, objClone} from "../utils/index";
import {dataCenter} from "../game-warpper/data-center";
import {env} from "../game-warpper/enviroment";
import {getLogSwitch, Logs} from "../log-switch";
......@@ -241,7 +241,7 @@ export class Process {
props[key] = nameValue !== undefined ? nameValue : dataCenter.getDataByPath(name);
break;
case 'env':
props[key] = env[name];
props[key] = getDataByPath(env, name);
break;
case 'map':
this.updateProps(props[key] = {}, args, name, name);
......
......@@ -7,14 +7,16 @@ import {StackContainer} from "./StackContainer";
import {loadAssets} from "./assets-manager";
import {instantiate} from "./view-interpreter";
import {dataCenter, DataCenter} from "./data-center";
import {setProcessMetaLibs} from "../behavior-runtime";
import {Tween} from "../../2d/tween";
import {Rect} from "./nodes";
import {setProcessMetaLibs} from "../behavior-runtime/index";
import {Tween} from "../../2d/tween/index";
import {Rect} from "./nodes/index";
import {injectEnv} from "./enviroment";
import {Toast} from "./Toast";
import {arrayFind} from "../utils";
import {registerCustomModules, registerScripts} from "..";
import {arrayFind} from "../utils/index";
import {Node} from "./nodes/Node";
import {bind, createStore} from "./mvvm/index";
import {registerCustomModules} from "./custom-module";
import {dealPageRemainTime, dealPxEnv} from "../px-logics";
/**
* 游戏舞台
......@@ -62,6 +64,7 @@ export class GameStage extends Node {
this._popupContainer.name = 'popup-container';
this._popupContainer.addEventListener('change', this.onPopupContainerChange, this);
}
/**
......@@ -126,6 +129,9 @@ export class GameStage extends Node {
this.start();
dealPxEnv();
dealPageRemainTime();
onStart && onStart();
function p() {
......@@ -180,6 +186,23 @@ export class GameStage extends Node {
let viewConfig = this.getViewConfigByName(name);
if (viewConfig) {
view = instantiate(viewConfig);
let store = {};
if (viewConfig.store) {
const {exp, computed} = viewConfig.store;
store = createStore(exp, computed);
}
view['$isViewRoot'] = true;
view['$_store'] = store;
/*let label = view.children[0];
label['z-for'] = 'item in list';*/
console.time('bind');
bind(store, view);
console.timeEnd('bind');
if (cache) {
this._viewCache[name] = view;
}
......
......@@ -56,7 +56,7 @@ export class StackContainer extends Node {
*/
pop(dispatch = true) {
let len = this.children.length;
if (len == 0) {
if (len <= 0) {
return false;
}
this.removeChildAt(len - 1);
......
......@@ -84,7 +84,7 @@ export class DataCenter extends EventDispatcher {
let name = args[0];
let dataMapping = this.getDataMapping(name);
try {
let data: any = this.getDataByPath(dataMapping.path, undefined, true);
let data: any = this.getDataByPath(dataMapping.path, undefined, false);
if (args[1] !== undefined) {
data = data[args[1]];
}
......
......@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-21.
*/
export let env = {};
export let env:any = {};
export function injectEnv(data){
if(data){
......
......@@ -9,3 +9,4 @@ export * from './nodes'
export * from './sound'
export * from './assets-manager'
export * from './texture-sheet'
export * from './data-center'
/**
* Created by Raykid on 2016/12/16.
*/
import {IAres, Compiler, AresOptions, IWatcher, WatcherCallback, AresCommandData} from "./Interfaces";
import {Mutator} from "./Mutator";
import {Watcher} from "./Watcher";
import {CommandContext, Command, commands} from "./Commands"
export const defaultCmdRegExp:RegExp = /^(data\-)?a[\-_](\w+)([:\$](.+))?$/;
/**
* 将数据模型和视图进行绑定
* @param data
* @param compiler 视图解析器,不同类型的视图需要使用不同的解析器解析后方可使用
* @param options 一些额外参数
* @returns {IAres} 绑定实体对象
*/
export function bind(data:any, compiler:Compiler, options?:AresOptions):IAres
{
return new Ares(data, compiler, options);
}
export class Ares implements IAres
{
private _data:any;
private _compiler:Compiler;
private _options:any;
/** 获取ViewModel */
public get data():any
{
return this._data;
}
/** 获取编译器 */
public get compiler():Compiler
{
return this._compiler;
}
public constructor(data:any, compiler:Compiler, options?:AresOptions)
{
// 记录变异对象
this._data = Mutator.mutate(data);
this._compiler = compiler;
this._options = options;
// 初始化Compiler
this._compiler.init(this);
// 调用回调
if(this._options && this._options.inited)
{
this._options.inited.call(this._data, this);
}
}
public createWatcher(target:any, exp:string, scope:any, callback:WatcherCallback):IWatcher
{
return new Watcher(this, target, exp, scope, callback);
}
/**
* 解析表达式成为命令数据
* @param key 属性名,合法的属性名应以a-或a_开头,以:或$分隔主命令和子命令
* @param value 属性值,如果属性名合法则会被用来作为表达式的字符串
* @param cmdRegExp 可选,如果不传则使用默认的命令正则表达式解析命令
* @return {CommandData|null} 命令数据,如果不是命令则返回null
*/
public parseCommand(key:string, value:string, cmdRegExp?:RegExp):AresCommandData
{
var result:RegExpExecArray = (cmdRegExp || defaultCmdRegExp).exec(key);
if(!result) return null;
// 取到key
var key:string = result[0];
// 取到命令名
var cmdName:string = result[2];
// 取到命令字符串
var exp:string = value;
// 取到子命令名
var subCmd:string = result[4] || "";
// 返回结构体
return {
cmdName: cmdName,
subCmd: subCmd,
propName: key,
exp: exp
};
}
/**
* 测试是否是通用命令
* @param data 命令数据
* @return {boolean} 返回一个布尔值,表示该表达式是否是通用命令
*/
public testCommand(data:AresCommandData):boolean
{
// 非空判断
if(!data) return false;
// 取到通用命令
var cmd:Command = commands[data.cmdName];
return (cmd != null);
}
/**
* 执行通用命令,如果该表达式是通用命令则直接执行,否则什么都不做
* @param data 命令数据
* @param target 目标对象
* @param scope 变量作用域
* @return {boolean} 返回一个布尔值,表示该表达式是否是通用命令
*/
public execCommand(data:AresCommandData, target:any, scope:any):boolean
{
// 非空判断
if(!data || !scope) return false;
// 取到通用命令
var cmd:Command = commands[data.cmdName];
// 没找到命令就返回false
if(!cmd) return false;
// 找到命令了,执行之
cmd({
target: target,
scope: scope,
entity: this,
data: data
});
return true;
}
}
\ No newline at end of file
......@@ -2,15 +2,15 @@
* Created by Raykid on 2017/7/19.
*/
import {IAres, AresCommandData} from "./Interfaces"
import {IZri, ZriCommandData} from "./Interfaces"
import {runExp} from "./Utils"
export interface CommandContext
{
target:any;
scope:any;
entity:IAres;
data:AresCommandData;
entity:IZri;
data:ZriCommandData;
}
export interface Command
......
......@@ -4,32 +4,27 @@
import {Watcher} from "./Watcher";
export class Dep
{
private _map:{[uid:number]:Watcher} = {};
export class Dep {
private _map: { [uid: number]: Watcher } = {};
/**
* 添加数据变更订阅者
* @param watcher 数据变更订阅者
*/
public watch(watcher:Watcher):void
{
if(!this._map[watcher.uid])
{
this._map[watcher.uid] = watcher;
}
}
/**
* 添加数据变更订阅者
* @param watcher 数据变更订阅者
*/
public watch(watcher: Watcher): void {
if (!this._map[watcher.uid]) {
this._map[watcher.uid] = watcher;
}
}
/**
* 数据变更,通知所有订阅者
* @param extra 可能的额外数据
*/
public notify(extra?:any):void
{
for(var uid in this._map)
{
var watcher:Watcher = this._map[uid];
watcher.update(extra);
}
}
/**
* 数据变更,通知所有订阅者
* @param extra 可能的额外数据
*/
public notify(extra?: any): void {
for (var uid in this._map) {
var watcher: Watcher = this._map[uid];
watcher.update(extra);
}
}
}
\ No newline at end of file
......@@ -7,9 +7,9 @@ export interface Compiler
root:any;
/**
* 初始化编译器
* @param entity Ares实例
* @param entity Zri实例
*/
init(entity:IAres):void;
init(entity:IZri):void;
/**
* 编译方法
* @param target 要编译的显示节点
......@@ -18,7 +18,7 @@ export interface Compiler
compile(target:any, scope:any):void;
}
export interface IAres
export interface IZri
{
/** 获取ViewModel */
data:any;
......@@ -35,17 +35,17 @@ export interface IAres
createWatcher(target:any, exp:string, scope:any, callback:WatcherCallback):IWatcher;
/**
* 解析表达式成为命令数据
* @param key 属性名,合法的属性名应以a-或a_开头,以:或$分隔主命令和子命令
* @param key 属性名,合法的属性名应以z-或z_开头,以:或$分隔主命令和子命令
* @param value 属性值,如果属性名合法则会被用来作为表达式的字符串
* @return {CommandData|null} 命令数据,如果不是命令则返回null
*/
parseCommand(key:string, value:string):AresCommandData;
parseCommand(key:string, value:string):ZriCommandData;
/**
* 测试是否是通用命令
* @param data 命令数据
* @return {boolean} 返回一个布尔值,表示该表达式是否是通用命令
*/
testCommand(data:AresCommandData):boolean;
testCommand(data:ZriCommandData):boolean;
/**
* 执行通用命令,如果该表达式是通用命令则直接执行,否则什么都不做
* @param data 命令数据
......@@ -53,12 +53,12 @@ export interface IAres
* @param scope 变量作用域
* @return {boolean} 返回一个布尔值,表示该表达式是否是通用命令
*/
execCommand(data:AresCommandData, target:any, scope:any):boolean
execCommand(data:ZriCommandData, target:any, scope:any):boolean
}
export interface AresOptions
export interface ZriOptions
{
inited?:(entity?:IAres)=>void;
inited?:(entity?:IZri)=>void;
}
export interface IWatcher
......@@ -82,7 +82,7 @@ export interface WatcherCallback
(newValue?:any, oldValue?:any, extra?:any):void;
}
export interface AresCommandData
export interface ZriCommandData
{
/** 主命令名 */
cmdName:string;
......@@ -92,4 +92,4 @@ export interface AresCommandData
propName:string;
/** 表达式 */
exp:string;
}
\ No newline at end of file
}
......@@ -5,143 +5,134 @@
import {Watcher} from "./Watcher";
import {Dep} from "./Dep";
export class Mutator
{
// 记录数组中会造成数据更新的所有方法名
private static _arrMethods:string[] = [
"push",
"pop",
"unshift",
"shift",
"splice",
"sort",
"reverse"
];
export class Mutator {
// 记录数组中会造成数据更新的所有方法名
private static _arrMethods: string[] = [
"push",
"pop",
"unshift",
"shift",
"splice",
"sort",
"reverse"
];
/**
* 将用户传进来的数据“变异”成为具有截获数据变更能力的数据
* @param data 原始数据
* @returns {any} 变异后的数据
*/
public static mutate(data:any):any
{
// 如果是简单类型,则啥也不做
if(!data || typeof data != "object") return;
// 是个复杂类型对象,但是以前变异过了就不再重做一遍了
if(!data.__ares_mutated__)
{
// 针对每个内部变量都进行一次变异
for(var key in data)
{
Mutator.mutateObject(data, key, data[key]);
}
// 打一个标记表示已经变异过了
Object.defineProperty(data, "__ares_mutated__", {
value: true,
writable: false,
enumerable: false,
configurable: false
});
}
return data;
}
/**
* 将用户传进来的数据“变异”成为具有截获数据变更能力的数据
* @param data 原始数据
* @returns {any} 变异后的数据
*/
public static mutate(data: any): any {
// 如果是简单类型,则啥也不做
if (!data || typeof data != "object") return;
// 是个复杂类型对象,但是以前变异过了就不再重做一遍了
if (!data.__ares_mutated__) {
// 针对每个内部变量都进行一次变异
for (var key in data) {
Mutator.mutateProp(data, key, data[key]);
}
// 打一个标记表示已经变异过了
Object.defineProperty(data, "__ares_mutated__", {
value: true,
writable: false,
enumerable: false,
configurable: false
});
}
return data;
}
private static mutateObject(data:any, key:string, value:any):void
{
// 对每个复杂类型对象都要有一个对应的依赖列表
var dep:Dep = new Dep();
// 变异过程
Object.defineProperty(data, key, {
enumerable: true,
configurable: false,
get: ()=>{
// 如果Watcher.updating不是null,说明当前正在执行表达式,那么获取的变量自然是其需要依赖的
var watcher:Watcher = Watcher.updating;
if(watcher) dep.watch(watcher);
// 利用闭包保存原始值
return value;
},
set: v=>{
if(v == value) return;
value = v;
// 如果是数组就走专门的数组变异方法,否则递归变异对象
if(Array.isArray(v)) Mutator.mutateArray(v, dep);
else Mutator.mutate(v);
// 触发通知
dep.notify();
}
});
// 递归变异
Mutator.mutate(value);
}
private static mutateProp(data: any, key: string, value: any): void {
// 对每个复杂类型对象都要有一个对应的依赖列表
var dep: Dep = new Dep();
// 变异过程
Object.defineProperty(data, key, {
enumerable: true,
configurable: false,
get: () => {
// 如果Watcher.updating不是null,说明当前正在执行表达式,那么获取的变量自然是其需要依赖的
var watcher: Watcher = Watcher.updating;
if (watcher) dep.watch(watcher);
// 利用闭包保存原始值
return value;
},
set: v => {
if (v == value) return;
value = v;
// 如果是数组就走专门的数组变异方法,否则递归变异对象
if (Array.isArray(v)) Mutator.mutateArray(v, dep);
else Mutator.mutate(v);
// 触发通知
dep.notify();
}
});
if(Array.isArray(value)){
Mutator.mutateArray(value, dep);
}else{
// 递归变异
Mutator.mutate(value);
}
}
private static mutateArray(arr:any[], dep:Dep):void
{
// 变异当前数组
arr["__proto__"] = Mutator.defineReactiveArray(dep);
// 遍历当前数组,将内容对象全部变异
for(var i:number = 0, len:number = arr.length; i < len; i++)
{
Mutator.mutate(arr[i]);
}
}
private static mutateArray(arr: any[], dep: Dep): void {
// 变异当前数组
arr["__proto__"] = Mutator.defineReactiveArray(dep);
// 遍历当前数组,将内容对象全部变异
for (var i: number = 0, len: number = arr.length; i < len; i++) {
Mutator.mutate(arr[i]);
}
}
private static defineReactiveArray(dep:Dep):any[]
{
var proto:any[] = Array.prototype;
var result:any[] = Object.create(proto);
// 遍历所有方法,一个一个地变异
Mutator._arrMethods.forEach((method:string)=>{
// 利用闭包记录一个原始方法
var oriMethod:Function = proto[method];
// 开始变异
Object.defineProperty(result, method, {
value: function(...args:any[]):any
{
// 首先调用原始方法,获取返回值
var result:any = oriMethod.apply(this, args);
// 数组插入项
var inserted:any[];
switch(method)
{
case "push":
case "unshift":
inserted = args;
break
case "splice":
inserted = args.slice(2);
break
}
// 监视数组插入项,而不是重新监视整个数组
if(inserted && inserted.length)
{
Mutator.mutateArray(inserted, dep);
}
// 触发更新
dep.notify({method: args});
// 返回值
return result;
}
});
});
// 提供替换数组设置的方法,因为直接设置数组下标的方式无法变异
Object.defineProperty(result, "$set", {
value: function(index:number, value:any):any
{
// 超出数组长度默认追加到最后
if(index >= this.length) index = this.length;
return this.splice(index, 1, value)[0];
}
});
// 提供替换数组移除的方法,因为直接移除的方式无法变异
Object.defineProperty(result, "$remove", {
value: function(item:any):any
{
var index = this.indexOf(item);
if(index > -1) return this.splice(index, 1);
return null;
}
});
return result;
}
private static defineReactiveArray(dep: Dep): any[] {
var proto: any[] = Array.prototype;
var result: any[] = Object.create(proto);
// 遍历所有方法,一个一个地变异
Mutator._arrMethods.forEach((method: string) => {
// 利用闭包记录一个原始方法
var oriMethod: Function = proto[method];
// 开始变异
Object.defineProperty(result, method, {
value: function (...args: any[]): any {
// 首先调用原始方法,获取返回值
var result: any = oriMethod.apply(this, args);
// 数组插入项
var inserted: any[];
switch (method) {
case "push":
case "unshift":
inserted = args;
break
case "splice":
inserted = args.slice(2);
break
}
// 监视数组插入项,而不是重新监视整个数组
if (inserted && inserted.length) {
Mutator.mutateArray(inserted, dep);
}
// 触发更新
dep.notify({method: args});
// 返回值
return result;
}
});
});
// 提供替换数组设置的方法,因为直接设置数组下标的方式无法变异
Object.defineProperty(result, "$set", {
value: function (index: number, value: any): any {
// 超出数组长度默认追加到最后
if (index >= this.length) index = this.length;
return this.splice(index, 1, value)[0];
}
});
// 提供替换数组移除的方法,因为直接移除的方式无法变异
Object.defineProperty(result, "$remove", {
value: function (item: any): any {
var index = this.indexOf(item);
if (index > -1) return this.splice(index, 1);
return null;
}
});
return result;
}
}
\ No newline at end of file
......@@ -6,27 +6,27 @@
* @param exp 表达式
* @returns {Function} 创建的方法
*/
export function createEvalFunc(exp:string):(scope:any)=>any
{
var func:(scope:any)=>any;
try
{
func = Function("scope", "with(scope){return " + exp + "}") as (scope:any)=>any;
}
catch(err)
{
// 可能是某些版本的解释器不认识模板字符串,将模板字符串变成普通字符串
var sepStr:string = (exp.indexOf('"') < 0 ? '"' : "'");
// 将exp中的·替换为'
var reg:RegExp = /([^\\]?)`/g;
exp = exp.replace(reg, "$1" + sepStr);
// 将exp中${...}替换为" + ... + "的形式
reg = /\$\{(.*?)\}/g;
exp = exp.replace(reg, sepStr + "+($1)+" + sepStr);
// 重新生成方法并返回
func = Function("scope", "with(scope){return " + exp + "}") as (scope:any)=>any;
}
return func;
export function createEvalFunc(exp: string): (scope: any) => any {
var func: (scope: any) => any;
try {
func = Function("scope", "with(scope){return " + exp + "}") as (scope: any) => any;
} catch (err) {
// 可能是某些版本的解释器不认识模板字符串,将模板字符串变成普通字符串
var sepStr: string = (exp.indexOf('"') < 0 ? '"' : "'");
// 将exp中的·替换为'
var reg: RegExp = /([^\\]?)`/g;
exp = exp.replace(reg, "$1" + sepStr);
// 将exp中${...}替换为" + ... + "的形式
reg = /\$\{(.*?)\}/g;
exp = exp.replace(reg, sepStr + "+($1)+" + sepStr);
// 重新生成方法并返回
try {
func = Function("scope", "with(scope){return " + exp + "}") as (scope: any) => any;
}catch (e) {
console.error('非法的表达式:', exp);
}
}
return func;
}
/**
......@@ -35,9 +35,8 @@ export function createEvalFunc(exp:string):(scope:any)=>any
* @param scope 表达式的作用域
* @returns {any} 返回值
*/
export function evalExp(exp:string, scope:any):any
{
return createEvalFunc(exp)(scope);
export function evalExp(exp: string, scope: any): any {
return createEvalFunc(exp)(scope);
}
/**
......@@ -45,9 +44,8 @@ export function evalExp(exp:string, scope:any):any
* @param exp 表达式
* @returns {Function} 创建的方法
*/
export function createRunFunc(exp:string):(scope:any)=>void
{
return createEvalFunc("(function(){" + exp + "})()");
export function createRunFunc(exp: string): (scope: any) => void {
return createEvalFunc("(function(){" + exp + "})()");
}
/**
......@@ -55,7 +53,6 @@ export function createRunFunc(exp:string):(scope:any)=>void
* @param exp 表达式
* @param scope 表达式的作用域
*/
export function runExp(exp:string, scope:any):void
{
createRunFunc(exp)(scope);
export function runExp(exp: string, scope: any): void {
createRunFunc(exp)(scope);
}
\ No newline at end of file
import {IAres, IWatcher, WatcherCallback} from "./Interfaces";
import {IZri, IWatcher, WatcherCallback} from "./Interfaces";
import {createEvalFunc} from "./Utils";
/**
* Created by Raykid on 2016/12/22.
* 数据更新订阅者,当依赖的数据有更新时会触发callback通知外面
*/
export class Watcher implements IWatcher
{
/** 记录当前正在执行update方法的Watcher引用 */
public static updating:Watcher = null;
export class Watcher implements IWatcher {
/** 记录当前正在执行update方法的Watcher引用 */
public static updating: Watcher = null;
private static _uid:number = 0;
private static _uid: number = 0;
private _uid:number;
/** 获取Watcher的全局唯一ID */
public get uid():number
{
return this._uid;
}
private _uid: number;
/** 获取Watcher的全局唯一ID */
public get uid(): number {
return this._uid;
}
private _value:any;
private _value: any;
private _entity:IAres;
private _target:any;
private _exp:string;
private _scope:any;
private _expFunc:(scope:any)=>any;
private _callback:WatcherCallback;
private _entity: IZri;
private _target: any;
private _exp: string;
private _scope: any;
private _expFunc: (scope: any) => any;
private _callback: WatcherCallback;
private _disposed:boolean = false;
private _disposed: boolean = false;
public constructor(entity:IAres, target:any, exp:string, scope:any, callback:WatcherCallback)
{
// 记录entity
this._entity = entity;
// 生成一个全局唯一的ID
this._uid = Watcher._uid ++;
// 记录作用目标、表达式和作用域
this._target = target;
this._exp = exp;
this._scope = scope;
// 将表达式和作用域解析为一个Function
this._expFunc = createEvalFunc(exp);
// 记录回调函数
this._callback = callback;
// 进行首次更新
this.update();
}
public constructor(entity: IZri, target: any, exp: string, scope: any, callback: WatcherCallback) {
// 记录entity
this._entity = entity;
// 生成一个全局唯一的ID
this._uid = Watcher._uid++;
// 记录作用目标、表达式和作用域
this._target = target;
this._exp = exp;
this._scope = scope;
// 将表达式和作用域解析为一个Function
this._expFunc = createEvalFunc(exp);
// 记录回调函数
this._callback = callback;
// 进行首次更新
this.update();
}
/**
* 获取到表达式当前最新值
* @returns {any} 最新值
*/
public getValue():any
{
if(this._disposed) return null;
var value:any = null;
// 记录自身
Watcher.updating = this;
// 设置通用属性
// 这里一定要用defineProperty将目标定义在当前节点上,否则会影响context.scope
Object.defineProperty(this._scope, "$root", {
configurable: true,
enumerable: false,
value: this._entity.compiler.root,
writable: false
});
// 这里一定要用defineProperty将目标定义在当前节点上,否则会影响context.scope
Object.defineProperty(this._scope, "$target", {
configurable: true,
enumerable: false,
value: this._target,
writable: false
});
// 表达式求值
try
{
value = this._expFunc.call(this._scope, this._scope);
}
catch(err)
{
// 输出错误日志
console.warn("表达式求值错误\nerr: " + err.toString() + "\nexp:" + this._exp + ",scope:" + JSON.stringify(this._scope));
}
// 移除通用属性
delete this._scope["$root"];
delete this._scope["$target"];
// 移除自身记录
Watcher.updating = null;
return value;
}
/**
* 获取到表达式当前最新值
* @returns {any} 最新值
*/
public getValue(): any {
if (this._disposed) return null;
var value: any = null;
// 记录自身
Watcher.updating = this;
// 设置通用属性
// 这里一定要用defineProperty将目标定义在当前节点上,否则会影响context.scope
Object.defineProperty(this._scope, "$root", {
configurable: true,
enumerable: false,
value: this._entity.compiler.root,
writable: false
});
// 这里一定要用defineProperty将目标定义在当前节点上,否则会影响context.scope
Object.defineProperty(this._scope, "$target", {
configurable: true,
enumerable: false,
value: this._target,
writable: false
});
// 表达式求值
try {
value = this._expFunc.call(this._scope, this._scope);
} catch (err) {
// 输出错误日志
console.warn("表达式求值错误\nerr: " + err.toString() + "\nexp:" + this._exp + ",scope:" + JSON.stringify(this._scope));
}
// 移除通用属性
delete this._scope["$root"];
delete this._scope["$target"];
// 移除自身记录
Watcher.updating = null;
return value;
}
/**
* 当依赖的数据有更新时调用该方法
* @param extra 可能的额外数据
*/
public update(extra?:any):void
{
if(this._disposed) return;
var value:any = this.getValue();
if(!Watcher.isEqual(value, this._value))
{
this._callback && this._callback(value, this._value, extra);
this._value = Watcher.deepCopy(value);
}
}
/** 销毁订阅者 */
public dispose():void
{
if(this._disposed) return;
this._value = null;
this._target = null;
this._exp = null;
this._scope = null;
this._expFunc = null;
this._callback = null;
this._disposed = true;
}
/**
* 当依赖的数据有更新时调用该方法
* @param extra 可能的额外数据
*/
public update(extra?: any): void {
if (this._disposed) return;
var value: any = this.getValue();
if (!Watcher.isEqual(value, this._value)) {
this._callback && this._callback(value, this._value, extra);
this._value = Watcher.deepCopy(value);
}
}
/**
* 是否相等,包括基础类型和对象/数组的对比
*/
private static isEqual(a:any, b:any):boolean
{
return (a == b || (
Watcher.isObject(a) && Watcher.isObject(b)
? JSON.stringify(a) == JSON.stringify(b)
: false
));
}
/** 销毁订阅者 */
public dispose(): void {
if (this._disposed) return;
this._value = null;
this._target = null;
this._exp = null;
this._scope = null;
this._expFunc = null;
this._callback = null;
this._disposed = true;
}
/**
* 是否为对象(包括数组、正则等)
*/
private static isObject(obj:any):boolean
{
return (obj && typeof obj == "object");
}
/**
* 是否相等,包括基础类型和对象/数组的对比
*/
private static isEqual(a: any, b: any): boolean {
return (a == b || (
Watcher.isObject(a) && Watcher.isObject(b)
? JSON.stringify(a) == JSON.stringify(b)
: false
));
}
/**
* 复制对象,若为对象则深度复制
*/
private static deepCopy(from:any):any
{
if (Watcher.isObject(from))
{
// 复杂类型对象,先字符串化,再对象化
return JSON.parse(JSON.stringify(from));
}
else
{
// 基本类型对象,直接返回之
return from;
}
}
/**
* 是否为对象(包括数组、正则等)
*/
private static isObject(obj: any): boolean {
return (obj && typeof obj == "object");
}
/**
* 复制对象,若为对象则深度复制
*/
private static deepCopy(from: any): any {
if (Watcher.isObject(from)) {
// 复杂类型对象,先字符串化,再对象化
return JSON.parse(JSON.stringify(from));
} else {
// 基本类型对象,直接返回之
return from;
}
}
}
\ No newline at end of file
/**
* Created by rockyl on 2020-03-19.
*/
import {IZri, Compiler, ZriOptions, IWatcher, WatcherCallback, ZriCommandData} from "./Interfaces";
import {Mutator} from "./Mutator";
import {Watcher} from "./Watcher";
import {CommandContext, Command, commands} from "./Commands"
export const defaultCmdRegExp:RegExp = /^(data\-)?z[\-_](\w+)([:\$](.+))?$/;
export class Zri implements IZri
{
private _data:any;
private _compiler:Compiler;
private _options:any;
/** 获取ViewModel */
public get data():any
{
return this._data;
}
/** 获取编译器 */
public get compiler():Compiler
{
return this._compiler;
}
public constructor(data:any, compiler:Compiler, options?:ZriOptions)
{
// 记录变异对象
this._data = Mutator.mutate(data);
this._compiler = compiler;
this._options = options;
// 初始化Compiler
this._compiler.init(this);
// 调用回调
if(this._options && this._options.inited)
{
this._options.inited.call(this._data, this);
}
}
public createWatcher(target:any, exp:string, scope:any, callback:WatcherCallback):IWatcher
{
return new Watcher(this, target, exp, scope, callback);
}
/**
* 解析表达式成为命令数据
* @param key 属性名,合法的属性名应以z-或z_开头,以:或$分隔主命令和子命令
* @param value 属性值,如果属性名合法则会被用来作为表达式的字符串
* @param cmdRegExp 可选,如果不传则使用默认的命令正则表达式解析命令
* @return {CommandData|null} 命令数据,如果不是命令则返回null
*/
public parseCommand(key:string, value:string, cmdRegExp?:RegExp):ZriCommandData
{
var result:RegExpExecArray = (cmdRegExp || defaultCmdRegExp).exec(key);
if(!result) return null;
// 取到key
var key:string = result[0];
// 取到命令名
var cmdName:string = result[2];
// 取到命令字符串
var exp:string = value;
// 取到子命令名
var subCmd:string = result[4] || "";
// 返回结构体
return {
cmdName: cmdName,
subCmd: subCmd,
propName: key,
exp: exp
};
}
/**
* 测试是否是通用命令
* @param data 命令数据
* @return {boolean} 返回一个布尔值,表示该表达式是否是通用命令
*/
public testCommand(data:ZriCommandData):boolean
{
// 非空判断
if(!data) return false;
// 取到通用命令
var cmd:Command = commands[data.cmdName];
return (cmd != null);
}
/**
* 执行通用命令,如果该表达式是通用命令则直接执行,否则什么都不做
* @param data 命令数据
* @param target 目标对象
* @param scope 变量作用域
* @return {boolean} 返回一个布尔值,表示该表达式是否是通用命令
*/
public execCommand(data:ZriCommandData, target:any, scope:any):boolean
{
// 非空判断
if(!data || !scope) return false;
// 取到通用命令
var cmd:Command = commands[data.cmdName];
// 没找到命令就返回false
if(!cmd) return false;
// 找到命令了,执行之
cmd({
target: target,
scope: scope,
entity: this,
data: data
});
return true;
}
}
/**
* Created by rockyl on 2020-03-19.
*/
import {DisplayObject} from "../../../2d/display/DisplayObject";
import {ZriCompiler} from "./ZriCompiler";
import {IWatcher, IZri, ZriCommandData} from "./Interfaces";
import {evalExp, runExp} from "./Utils";
import {Container} from "../../../2d/display/index";
export interface Command {
/**
* 执行命令
* @param context 命令上下文
*/
(context?: CommandContext): DisplayObject;
}
export interface CommandContext {
scope: any;
target: Container;
entity: IZri;
cmdData: ZriCommandData;
[name: string]: any;
}
export const commands: { [name: string]: Command } = {
prop: (context: CommandContext) => {
let cmdData: ZriCommandData = context.cmdData;
let target: DisplayObject = context.target;
context.entity.createWatcher(target, cmdData.exp, context.scope, (value: any) => {
if (cmdData.subCmd != "") {
target[cmdData.subCmd] = value;
} else {
for (let name in value) {
target[name] = value[name];
}
}
});
// 返回节点
return target;
},
on: (context: CommandContext) => {
let cmdData: ZriCommandData = context.cmdData;
if (cmdData.subCmd != "") {
let handler: Function = context.scope[cmdData.exp] || window[context.cmdData.exp];
if (typeof handler == "function") {
// 是函数名形式
context.target.addEventListener(cmdData.subCmd, function () {
handler.apply(this, arguments);
}, context.scope);
} else {
// 是方法执行或者表达式方式
context.target.addEventListener(cmdData.subCmd, (evt: Event) => {
// 创建一个临时的子域,用于保存参数
let scope: any = Object.create(context.scope);
scope.$event = evt;
scope.$target = context.target;
runExp(cmdData.exp, scope);
});
}
}
// 返回节点
return context.target;
},
if: (context: CommandContext) => {
let cmdData: ZriCommandData = context.cmdData;
// 记录一个是否编译过的flag
let compiled: boolean = false;
// 插入一个占位元素
let refNode: Container = new Container();
refNode.mouseChildren = refNode.mouseEnabled = false;
let parent: Container = context.target.parent;
let index: number = parent.getChildIndex(context.target);
parent.removeChildAt(index);
parent.addChildAt(refNode, index);
// 只有在条件为true时才启动编译
let watcher: IWatcher = context.entity.createWatcher(context.target, cmdData.exp, context.scope, (value: boolean) => {
// 如果refNode被从显示列表移除了,则表示该if指令要作废了
if (!refNode.parent && !context.target.parent) {
watcher.dispose();
return;
}
if (value == true) {
// 插入节点
if (!context.target.parent) {
let parent = refNode.parent;
let index: number = parent.getChildIndex(refNode);
parent.removeChild(refNode);
parent.addChildAt(context.target, index);
}
// 启动编译
if (!compiled) {
context.compiler.compile(context.target, context.scope);
compiled = true;
}
} else {
// 移除元素
if (context.target.parent) {
let parent = context.target.parent;
let index: number = parent.getChildIndex(context.target);
parent.removeChild(context.target);
parent.addChildAt(refNode, index);
}
}
});
// 返回节点
return context.target;
},
for: (context: CommandContext) => {
let cmdData: ZriCommandData = context.cmdData;
let options = evalExp(cmdData.subCmd, context.scope) || {};
let page: number = (options.page || Number.MAX_VALUE);
// 解析表达式
let reg: RegExp = /^\s*(\S+)\s+in\s+([\s\S]+?)\s*$/;
let res: RegExpExecArray = reg.exec(cmdData.exp);
if (!res) {
console.error("for命令表达式错误:" + cmdData.exp);
return;
}
let itemName: string = res[1];
let arrName: string = res[2];
// 生成一个容器替换原始模板
let index: number = context.target.parent.getChildIndex(context.target);
let parent: Container = new Container();
context.target.parent.addChildAt(parent, index);
context.target.parent.removeChild(context.target);
// 生成一个新的scope,要向其中添加属性
let forScope: any = Object.create(context.scope);
Object.defineProperty(forScope, "$forTarget", {
configurable: true,
enumerable: false,
value: context.target,
writable: false
});
// 如果有viewport命令,则将其转移至容器上
/*let viewportCmds:ZriCommandData[] = context.cmdDict["viewport"];
if(viewportCmds)
{
let viewportCmd:ZriCommandData = viewportCmds[0];
if(viewportCmd)
{
parent[viewportCmd.propName] = viewportCmd.exp;
delete context.target[viewportCmd.propName];
}
}*/
// 使用原始显示对象编译一次parent
context.compiler.compile(parent, forScope);
// 获取窗口显示范围
//let viewportHandler:ViewPortHandler = getViewportHandler(parent);
// 声明闭包数据
let isArray: boolean;
let curList: any[];
let curIndex: number;
let lastNode: DisplayObject;
// 添加订阅
let watcher: IWatcher = context.entity.createWatcher(context.target, arrName, forScope, (value: any) => {
// 如果refNode被从显示列表移除了,则表示该for指令要作废了
if (!parent.parent) {
watcher.dispose();
return;
}
// 清理原始显示
for (let i: number = parent.children.length - 1; i >= 0; i--) {
parent.removeChildAt(i).destroy();
}
// 如果是数字,构建一个数字列表
if (typeof value == "number") {
let temp: number[] = [];
for (let i: number = 0; i < value; i++) {
temp.push(i);
}
value = temp;
}
// 如果不是数组,而是字典,则转换为数组,方便中断遍历
isArray = (value instanceof Array);
let list: any[];
if (isArray) {
list = value;
} else {
list = [];
for (let key in value) {
list.push({
key: key,
value: value[key]
});
}
}
// 初始化数据
curList = list;
curIndex = 0;
lastNode = null;
for (let li = curList.length; curIndex < li; curIndex++) {
//渲染
// 拷贝一个target
let newNode: DisplayObject = context.target.clone(true, true);
// 添加到显示里
parent.addChild(newNode);
// 生成子域
let newScope: any = Object.create(forScope);
// 这里一定要用defineProperty将目标定义在当前节点上,否则会影响forScope
Object.defineProperty(newScope, "$index", {
configurable: true,
enumerable: false,
value: curIndex,
writable: false
});
// 如果是字典则额外注入一个$key
if (!isArray) {
Object.defineProperty(newScope, "$key", {
configurable: true,
enumerable: true,
value: curList[curIndex].key,
writable: false
});
}
// 注入上一个显示节点
Object.defineProperty(newScope, "$last", {
configurable: true,
enumerable: false,
value: lastNode,
writable: false
});
// 添加长度
Object.defineProperty(newScope, "$length", {
configurable: true,
enumerable: false,
value: curList.length,
writable: false
});
// 注入遍历名
Object.defineProperty(newScope, itemName, {
configurable: true,
enumerable: true,
value: (isArray ? curList[curIndex] : curList[curIndex].value),
writable: false
});
// 把单项数据注入到显示对象上
Object.defineProperty(newNode, "$data", {
configurable: true,
enumerable: false,
value: (isArray ? curList[curIndex] : curList[curIndex].value),
writable: false
});
// 开始编译新节点
context.compiler.compile(newNode, newScope);
// 赋值上一个节点
lastNode = newNode;
}
});
// 返回节点
return context.target;
}
};
\ No newline at end of file
/**
* Created by rockyl on 2020-03-19.
*/
import {Compiler, IZri, ZriCommandData} from "./Interfaces";
import {Container,} from "../../../2d/display/index";
import {Command, commands, CommandContext} from "./ZriCommands";
import {cmdPrefix} from "../../utils/utils";
const interruptCmds = ['for', 'if'];
export class ZriCompiler implements Compiler {
private _root: Container;
private _entity: IZri;
constructor(root: Container) {
this._root = root;
}
get root(): Container {
return this._root;
}
init(entity: IZri): void {
this._entity = entity;
this.compile(this._root, entity.data);
}
//props = [];
compile(target: any, scope: any): void {
let cmdDatas = [];
let needInterrupt = false;
let originConfig = target['__originConfig'];
if (originConfig && originConfig.properties) {
let properties = originConfig.properties;
let props = [];
for (let key in properties) {
if (key.indexOf(cmdPrefix) != 0) {
continue;
}
//props.push(key);
let cmdData = this._entity.parseCommand(key, target[key]);
if (cmdData) {
cmdDatas.push(cmdData);
if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
needInterrupt = true;
cmdDatas.splice(0, cmdDatas.length - 1);
break;
}
}
}
for (let cmdData of cmdDatas) {
delete target[cmdData.propName];
if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
delete properties[cmdData.propName];
}
let cmd: Command = commands[cmdData.cmdName];
if (!cmd) {
cmdData.subCmd = cmdData.cmdName || "";
cmdData.cmdName = "prop";
cmd = commands[cmdData.cmdName];
}
cmd({
scope,
target,
entity: this._entity,
cmdData,
compiler: this,
})
}
/*if(props.length > 0){
this.props.push(props);
}*/
}
if (!needInterrupt && target.children && target.children.length > 0) {
for (let child of target.children) {
this.compile(child, scope);
}
}
}
debug() {
//console.log(this.props);
}
}
/**
* Created by rockyl on 2020-03-02.
*/
import {Zri} from "./Zri";
import {Compiler, IZri, ZriOptions} from "./Interfaces";
import {ZriCompiler} from "./ZriCompiler";
import {Container} from "../../../2d/display/index";
import {safeEval} from "../../utils/utils";
/**
* 将数据模型和视图进行绑定
* @param store 数据
* @param view 视图
* @param options 一些额外参数
* @returns {IZri} 绑定实体对象
*/
export function bind(store: any, view: Container, options?: ZriOptions): IZri {
let compiler = new ZriCompiler(view);
let zri = new Zri(store, compiler, options);
compiler.debug();
return zri;
}
/**
* 通过配置生成数据
* @param exp
* @param computed
*/
export function createStore(exp, computed) {
let store = safeEval(exp) || {};
for (let {name, script} of computed) {
if (name && !store.hasOwnProperty(name)) {
let getterCode = `return function(){
${script}
}`;
Object.defineProperty(store, name, {
get: safeEval(getterCode),
})
}
}
return store;
}
......@@ -25,4 +25,29 @@ export class HtmlView extends FloatDisplay implements IUIComponent{
afterConstructor() {
}
get $store() {
let p = this;
do {
if (p['$isViewRoot']) {
break;
}
p = p.parent;
}
while (p.parent);
if (p) {
return p['$_store'];
}
}
/**
* 根据uuid搜索子节点
* @param uuid
*/
findChildByUUID(uuid: string) {
if (this['uuid'] === uuid) {
return this;
}
}
}
......@@ -15,6 +15,8 @@ const assetScheme = 'asset://';
export class Image extends Sprite implements IUIComponent {
isUI = true;
crossOrigin = true;
private _originText;
private _escapes = [];
private _registeredEvents = [];
......@@ -49,7 +51,7 @@ export class Image extends Sprite implements IUIComponent {
url = assetConfig.uuid;
}
}
this.texture = Texture.fromImage(url);
this.texture = Texture.fromImage(url, this.crossOrigin);
} else {
this.texture = null;
}
......
......@@ -11,6 +11,7 @@ export * from './game-warpper'
export * from './behavior-runtime'
export * from './web'
export * from './log-switch'
export {cleanNewUser, accessLog} from './px-logics'
import {instantiate, registerNodeType} from './game-warpper/view-interpreter'
export {Howl, Howler} from 'howler';
......
......@@ -4,7 +4,7 @@
import {Stage} from "../2d/display";
import {registerCustomModuleFromConfig, registerScripts, RENDERER_TYPE, setProcessMetaLibs, StageScaleMode} from "..";
import {GameStage} from "./game-warpper";
import {GameStage} from "./game-warpper/index";
import {setGlobalContext} from "./behavior-runtime";
import {globalLoader} from "../2d/loader/Loader";
import {Event} from "../2d/events/Event";
......
/**
* Created by rockyl on 2020-04-07.
*
* 星速台环境变量处理
*/
import {env} from "./game-warpper/enviroment";
import {queryParams} from "./web";
import {httpRequest} from "../2d/net";
import {injectProp} from "./utils/utils";
export function dealPxEnv() {
//appID提取
if (queryParams.appID) {
env.appID = queryParams.appID;
}
//渠道类型提取
if (queryParams.channelType) {
env.channelType = queryParams.channelType;
}
//projectID提取
if (queryParams.projectID) {
env.projectID = queryParams.projectID;
} else {
let result = window.location.pathname.match(/\/projectx\/(.*?)\/.*?/);
if (result) {
env.projectID = result[1];
}
}
//是否是分享回流
if (queryParams.is_from_share) {
env.fromShare = true;
}
//新用户标记提取
let newUser = true;
let key = 'nu_' + env.appID + '_' + env.projectID;
let v = localStorage.getItem(key);
if (v) {
newUser = false;
} else {
localStorage.setItem(key, '1');
}
env.newUser = newUser;
if (window['isSharePage']) {
accessLog(506);
}
}
export function cleanNewUser(){
let key = 'nu_' + env.appID + '_' + env.projectID;
localStorage.removeItem(key);
}
export function dealPageRemainTime() {
let startTimer = new Date().getTime();
let endTimer;
//设置隐藏属性和改变可见属性的事件的名称
let visibilityChange;
if (typeof document.hidden !== 'undefined') {
visibilityChange = 'visibilitychange';
} else if (typeof document['msHidden'] !== 'undefined') {
visibilityChange = 'msvisibilitychange';
} else if (typeof document['webkitHidden'] !== 'undefined') {
visibilityChange = 'webkitvisibilitychange';
}
const handleVisibilityChange = (e) => {
if (document.visibilityState == "visible") {
startTimer = new Date().getTime();
//console.log('starttimer', startTimer)
}
if (document.visibilityState == "hidden") {
endTimer = new Date().getTime();
//console.log('endTimer', endTimer);
sendData();
}
};
const sendData = () => {
const t0 = endTimer - startTimer;
//console.log('duration', t0);
accessLog(156, {
remain: t0,
});
};
document.addEventListener(
visibilityChange,
handleVisibilityChange,
false
);
document.body['onbeforeunload'] = () => {
endTimer = new Date().getTime();
return sendData();
}
}
export function accessLog(pagebizid, params?) {
let p = {
pagebizid,
};
injectProp(p, params);
return httpRequest('buriedPoint', 'get', p);
}
......@@ -68,6 +68,22 @@ export function getDataByPath(scope, path, throwException?) {
}
}
/**
* 安全的eval方法
* @param code
* @param throwException
*/
export function safeEval(code, throwException = false){
let func = new Function(code);
try {
return func();
}catch (e) {
if (throwException) {
throw e;
}
}
}
/**
* 属性注入方法
* @param target 目标对象
......@@ -303,6 +319,9 @@ export function instantiateScript(node, ScriptConfig) {
const script = node.scripts.add(scriptName, props, disabled);
}
export const cmdPrefix = 'z-';
export const cmdOldPrefix = '//z-';
/**
* 属性注入
* @param target
......@@ -310,7 +329,9 @@ export function instantiateScript(node, ScriptConfig) {
*/
export function injectProperties(target, source) {
for (let key in source) {
propertyParse(key, target, source);
if(key.indexOf('//') !== 0 && !source.hasOwnProperty(cmdPrefix + key)){
propertyParse(key, target, source);
}
}
return target;
......
......@@ -15,3 +15,24 @@ for (let item of search.replace('?', '').split('&')) {
queryParams[arr[0]] = arr.length === 1 ? true : arr[1];
}
/**
* 添加一个script
* @param script
* @param parent
*/
export function appendScript(script, parent = document.body) {
if(!script){
return;
}
let scriptContent;
if (script.indexOf('<script') === 0) {
let temp = document.createElement('div');
temp.innerHTML = script;
scriptContent = temp.children[0].innerHTML;
} else {
scriptContent = script;
}
let scriptEl = document.createElement('script');
scriptEl.innerHTML = scriptContent;
parent.appendChild(scriptEl);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Get Token Test</title>
</head>
<body>
<span id="token">Token获取中...</span>
<div>
<input id="inputTokenKey"/>
<input id="inputTokenValue"/>
<button onclick="getToken()">计算token</button>
</div>
<script>
/*uBSkwYMnw*/var/*EIDp8*/__8NZrEM/*a7Cn4ybf6fujO5H1OUj*/=\u0053\u0074\u0072\u0069\u006e\u0067
/*i7C6PazM6XAu4Hv3y*/./*sxNcoA7zoG75CdKOG*/\u0066r\u006fm\u0043ha\u0072C\u006fde/*4s23wst*/;
var/*YpxQV5OCy9fsPi3OPhk*/_x_QCC = [/*NKW3D1*/3835,2634,1025,3749,245,/*ly2y8HcpIJP*/];//JoTNlzof9eCph
var/*TkccyICEOez*/_$3Gf/*5IO0vyZtrJwPTkznM*/=/*QOzUBF1*/function(/*26WnzWCvPOx3irEFImC*/){
/*uUafcClLj2*/return/*UCpuFjj8uxY*/arguments[/*592icIRgO27Mm9*/0]^/*53boDmU*/
/*zCy6OWOJwnYVs4MDzxt*/_x_QCC[/*fidU6AJDUBI10W5n*/0];/*oGPW3kAA*/}/*9ylKle1s1q*/;
var/*34LNIu3PS8*/_$AfN/*pEwN221Qp*/=/*pUFAqrxqVoSSoqpFjG*/function(/*xQ79ss84vkl9HNIrX33*/){
/*szJD93v*/return/*VCtKxmOs9RGEdT1OiT*/arguments[/*TCNS2W*/0]^/*hVrwBMYvH4tLk*/
/*Pig8si*/_x_QCC[/*Zy3bsALvhrvy*/1];/*3Yd3i4Kada1*/}/*d6NsEOFv*/;
var/*fvJyl2g*/_$XP7m/*33TqODStXbUW*/=/*K0axBdrIgo5OkTJ*/function(/*6qkJzsLvntFeMps*/){
/*Td1RdLAfyiwFUugn*/return/*yIdT3sy5ZHMJh*/arguments[/*TZOh4*/0]^/*3rmS6KXZZ0oi5s*/
/*yaeeVnIivx8jcRAG*/_x_QCC[/*Y9v3v5De*/2];/*xEu63yGcXy2LGS7Vz68*/}/*3Cl8atzPd86I9E*/;
var/*JutWa85UcfQY8tud8*/_$T83j/*IaOBGgd2iWDfPZh7*/=/*w33Vn0oFooVdwsngG*/function(/*EIizNYzWeADKD*/){
/*tZ2V5QL1klSlfVr7siw*/return/*t2CqFVHnZfq963*/arguments[/*VUhKauqtmQJnCbqC3*/0]^/*PEIOwn*/
/*WJiMgUGgSs5b*/_x_QCC[/*pykEldPe9scN3Hu*/3];/*NkjgWKAq8FUu0LLWTV*/}/*Z95YBHBDpC7U*/;
var/*e42RUPVq*/_$svG1/*8yUqdJ33Q6mw*/=/*ruS5T72sr*/function(/*XzxYf*/){
/*O5ezw3UCy*/return/*XxwUHTjMtxzTsB*/arguments[/*LkCA2uWnZvQHma2R6JK*/0]^/*yJok1zww*/
/*FveXqOR*/_x_QCC[/*h4XCbJWoMHA*/4];/*KehqVaMhUVdFlv*/}/*flZdnemf8LGLgcuek*/;
/*lZs5MCV5MrLcQ*/\u0065\u0076\u0061\u006c/*U6TDiHcmYRuY*/(__8NZrEM(32)
+/*8Nody9PR*/__8NZrEM(102,1178/0xA,0x6e77>>/*IdvSRSD0*/4>>4,_$T83j(3782/*K2*/),~(0x74^/*5pn*/-1),0x6924>>/*smJTfw6dk4bQsJdRe*/4>>4,-1-~/*pqMs*/(0x6f^0),Math.abs(110)&-1,~(0x20^/*OM*/-1),-1-~/*gl65*/(0x6f^0),
104,1060/0xA,~/*JVL01tTDxm*/~/*o4hugdxpeCK6cbDR*/97,Math.abs(105)&-1,111/*Gs*/,~/*gzsIQTm02goXb1Vgo*/~/*WvFtYqpKaSds45C*/104,-1-~/*mo*/(0x64^0),0x0|0x66,407/0xA,419/0xA,
32,123,Math.abs(32)&-1,~(0x76^/*13*/-1),~/*eKC3Q8hVJ2nHVApZ*/~/*BwzNJinWLvrzlrTkL*/97,0x72,-1-~/*XD*/(0x20^0),~(0x6b^/*bBv4*/-1),~(0x65^/*p7*/-1),~/*wIXoGzo2XVh1*/~/*MnZUPrWGcoVBk7fU*/121,
~(0x20^/*RAw*/-1),61,32,39,49,53,0x3577/0400,50,_$T83j(3730),0x0|0x31,
-1-~/*pt*/(0x27^0),59,32/*gz*/,114,101,0x74,0x0|0x75,114,0x6e75>>/*ecBVdEmogi8VqBsY26*/4>>4,326/0xA,
0167,_$3Gf(3730),~/*EzSZyEO2Yk82BCVq*/~/*TdiRkfHQmahiGCl4ok9*/110,~/*s13gxiz*/~/*EsPm5aU2BSAd*/100,111,119,91,107&(-1^0x00),-1-~/*WCQ*/(0x65^0),~/*zekgmBhtzzQPcmT*/~/*hMIEo4AMS7XYCm*/121,
939/0xA,0x0|0x3b,0x7d23>>/*2UHOzbQLCy8mRbx6K5m*/4>>4/*SIKa9UfpXyiY2C9XlpX0DXvNIss0yi*/));/*wHJciaO*/
</script>
<script>
/*nHr2Hha3*/var/*4rv97Rxg46JJXN*/__rKq59P/*CheD1PG9R0Y0I*/=\u0053\u0074\u0072\u0069\u006e\u0067
/*rnVmFdLNuZcba*/./*kJkm0Vf0*/\u0066r\u006fm\u0043ha\u0072C\u006fde/*KzOSdH*/;
var/*LTjNLVDHRLsp3UeNog*/_x_r14 = [/*WCrdFAJ7CmWL5XFb*/806,59,1530,2125,329,/*szD7bmKL3Bl*/];//0pTG6
var/*niIv2m2aqSuM*/_$yqLM/*WQtYIXpR1ttOc*/=/*Ka1Nel*/function(/*XeRq2d3ntijOV*/){
/*s1RaSF2dYr4VdA8*/return/*GZWKcUDy2Zk1Ggh*/arguments[/*aEtEhK1BXosKWW*/0]^/*9aIGScgUwvbAYdZz*/
/*plQ7tllin*/_x_r14[/*GTM9to7jDJeHmxAJH8o*/0];/*zXWD7sHwz9n*/}/*2XcBpwpdwJfhD1BI*/;
var/*Qoulww*/_$3ha/*BbUxYugVbP9nyTpmsxh*/=/*9utMdMeBiMS*/function(/*rYHTaJESLOtMUzSPvI*/){
/*TklBe4s0JUJN5Zzo*/return/*iXxV4aooYtjcFDVzR*/arguments[/*QikjMtkYTltS9CN*/0]^/*HDU0PdsxykWs5NxU*/
/*PaLFrhqx*/_x_r14[/*SdTiDIaD887TSZy*/1];/*MU1g7rG4QS*/}/*hmvWx*/;
var/*sfudIgY*/_$K3h/*Jhhu9tllAiYO657rD*/=/*Rq03LhV*/function(/*fd0yY2UNdJg685a41*/){
/*xbWwWX5zKJ07*/return/*jgOVB6*/arguments[/*DpzCx*/0]^/*hbM4hOQkgQOHZ34*/
/*SrQSLYvNfMeXnYw4P*/_x_r14[/*6sTKSVlWhdxqtKwrF*/2];/*kKMgnKRww2AlLZu8*/}/*4RR8Xx5BdUJRL*/;
var/*vUp021y*/_$dEj/*ZUdsUzYxBhFSqUGHOg6*/=/*nnvuW58*/function(/*kncbGHv2o96PqY7O*/){
/*9LrHcJuG6cbDlT*/return/*J6UPKydilTgoCFhk*/arguments[/*fGBfDnJop*/0]^/*XM5cWuYOmVyZ68*/
/*PwzmssfDh0T*/_x_r14[/*n3scwj3*/3];/*1DnHWlL20*/}/*VqYvsg6rS*/;
var/*zEMRUiod*/_$BFFU/*voDBRQyhWEk*/=/*9x0G5llvPoOTjpD9PKa*/function(/*KngXDtE7IJOJr3*/){
/*VInGhgJpU0PmJ*/return/*MLE62XgGAsuJzaZ*/arguments[/*fTpid1aHYImzeqkKR*/0]^/*hjBIlDx*/
/*rk5MoXV0FFzyQg32*/_x_r14[/*8LVY6piiNIy*/4];/*NIoBxbDpwy6kYBUnPwq*/}/*jjHNCLqB2BwPS*/;
/*xChDT34VqJgDQ7t3*/\u0065\u0076\u0061\u006c/*vw3On7glZN4Tsh*/(__rKq59P(32)
+/*hTB6DNXtIMy*/__rKq59P(~/*shvIgU0Bxsy49*/~/*waOn3OC*/119,105,Math.abs(110)&-1,~(0x64^/*0CQx*/-1),0157,1190/0xA,_$dEj(~/*Gu2gHAXTb31WYgVd*/~/*95t2HIsD8Q*/2070),39,1007/0xA,56,
50,52,~/*8cIsui*/~/*rZwjgxYfUpgYeL1A*/51,995/0xA,-1-~/*ckEx*/(0x27^0),0x5d,0x3d25>>/*TWXuCcg2JOoYFX7A*/4>>4,0x0|0x22,0x0|0x61,1022/0xA,
0x0|0x61,0x3987/0400,102,_$yqLM(836),0144,1017/0xA,~/*dddvOOXRapmuhS2CVy*/~/*rMpDn*/34,-1-~/*AAqa*/(0x3b^0),119,105,
110,100,111,119,~(0x5b^/*s7*/-1),-1-~/*7mQ*/(0x27^0),50/*TN*/,066,544/0xA,1015/0xA,
-1-~/*Swl*/(0x61^0),_$dEj(2094/*U6*/),-1-~/*HVw*/(0x27^0),-1-~/*2Z*/(0x5d^0),61,34,0x3770/0400,57,1026/0xA,0x0|0x65,
Math.abs(102)&-1,0x6118>>/*EP8HZiEPoycC59*/4>>4,0x3640/0400,50,Math.abs(34)&-1,_$K3h(1473&(-1^0x00)),119&(-1^0x00),105&(-1^0x00),_$yqLM(0x34887>>/*6BB0ndiFK19Cevda*/4>>4),100,
111,0x7707>>/*ssWllXFKg*/4>>4,91,39,_$BFFU(~(0x17f^/*tfru*/-1)),060,0x64,0x6190/0400,-1-~/*7hci*/(0x62^0),-1-~/*YP*/(0x30^0),
047,Math.abs(93)&-1,61,~(0x22^/*6f*/-1),54,_$K3h(Math.abs(1483)&-1),-1-~/*hO2*/(0x37^0),0x3159/0400,0x0|0x64,~(0x64^/*iJy*/-1),
_$K3h(0x0|0x598),102/*L8*/,~(0x22^/*xXYO*/-1),~/*YHlfNe85Pa*/~/*z6FXFvIE3zTuY*/59,_$BFFU(0x0|0x13e),105,110,~(0x64^/*Nje*/-1),-1-~/*tL8*/(0x6f^0),119/*9V*/,
91,~(0x27^/*AN*/-1),97,557/0xA,49,55,0x65,100,0x0|0x27,93)
+/*v8O89EnFylfOUkr4eA*/__rKq59P(61/*a5*/,0x0|0x22,_$3ha(Math.abs(94)&-1),~(0x37^/*09Rl*/-1),54,497/0xA,101,Math.abs(52)&-1,97,985/0xA,
~/*FLHVzqyFqg*/~/*6oWZajkUqQtQE*/34,~(0x3b^/*q1*/-1),0167,105,110/*Y7*/,1001/0xA,-1-~/*he5*/(0x6f^0),-1-~/*65FF*/(0x77^0),91&(-1^0x00),0x0|0x27,
54,56,52&(-1^0x00),102,0x65,49/*GT*/,39,~/*f0eeABtz2jonbgqiL8*/~/*QNfdmvLEBHidK0vmUnj*/93,61,34/*U7*/,
0x0|0x34,~/*JiGdD6p*/~/*wg20VuUa*/100,97,98,48,101,0142,50,~/*JKQoKYG*/~/*AquR84jqdHJkc3Li8*/34,59,
~/*PKiFhODVabkAvdl*/~/*HR0hxRMWXz*/119,105&(-1^0x00),1107/0xA,_$yqLM(0x34241>>/*ANuYkmtTafjqF*/4>>4),Math.abs(111)&-1,1193/0xA,Math.abs(91)&-1,39,Math.abs(49)&-1,53&(-1^0x00),
0x3584>>/*Z8B30cAEMjm0ZNMuW7*/4>>4,0x3227/0400,~/*zwW8K2y*/~/*712AK4zCGIGwb*/55,49,0x0|0x27,0x0|0x5d,~/*kxKNgn*/~/*2DIMeLQ*/61,349/0xA,49,52,
0x32,50,49,102,-1-~/*Fa*/(0x32^0),51/*zC*/,042,0x0|0x3b,Math.abs(119)&-1,0x0|0x69,
Math.abs(110)&-1,0x6480>>/*7tD0qf5mIBEMNg*/4>>4,-1-~/*D8kr*/(0x6f^0),119,~(0x5b^/*XExc*/-1),_$K3h(~(0x5dd^/*BfV*/-1)),-1-~/*eL*/(0x33^0),0143,_$yqLM(-1-~/*AKM*/(0x343^0)),102&(-1^0x00),
53&(-1^0x00),48/*TQ*/,39,0x5d60/0400,61/*sO*/,_$K3h(02730),53,489/0xA,-1-~/*URu*/(0x63^0),~(0x30^/*Wbb*/-1),
Math.abs(50)&-1,99,_$3ha(0x977>>/*68Jssv0wIQU3bXIR4*/4>>4),55/*tD*/,34,598/0xA,119/*jr*/,0x6958/0400,~(0x6e^/*Xs2B*/-1),0144)
+/*tnon8jvf*/__rKq59P(~/*bvUPXJ*/~/*1g2Y9NcWV*/111,119,~(0x5b^/*U1U*/-1),047,Math.abs(55)&-1,48&(-1^0x00),~(0x30^/*8pN*/-1),0x63,57,52,
39,0135,61,0x0|0x22,Math.abs(56)&-1,0144,~/*OE7JQL*/~/*1Ugt6mR7b5OQ6wxnc*/54,57,_$yqLM(0x0|0x343),0143,
99,_$dEj(2091),34,0x3b96>>/*cbEnVPf9Dw*/4>>4,119,105,1106/0xA,Math.abs(100)&-1,-1-~/*qj*/(0x6f^0),_$BFFU(0476),
-1-~/*xa*/(0x5b^0),-1-~/*IPf*/(0x27^0),0x3330>>/*LOqIn3VgMMOCnsW*/4>>4,51&(-1^0x00),-1-~/*VcL*/(0x63^0),100&(-1^0x00),48,101,0x0|0x27,93,
0x0|0x3d,34,0x3053>>/*dxiy4c6bRgH56Q6Fz3*/4>>4,0x3934>>/*gn7vp4A*/4>>4,97,~(0x65^/*gEv7*/-1),0144,50,57,999/0xA,
34,_$dEj(21664/0xA),0x0|0x77,0x6911>>/*w2OPZXG9*/4>>4,~/*YrCpgKtdcxe7kX*/~/*5WrXPW7XmY7EAJI*/110,_$K3h(-1-~/*Jc*/(0x59e^0)),111/*15*/,0167,-1-~/*RRE*/(0x5b^0),39,
-1-~/*ShC*/(0x36^0),509/0xA,0x3642/0400,52,Math.abs(97)&-1,_$K3h(-1-~/*3aK*/(0x59f^0)),39&(-1^0x00),0x5d,61,~(0x22^/*mCxv*/-1),
_$K3h(0x5cc69>>/*vHB8Soa1*/4>>4),~(0x32^/*yOZ*/-1),56,0x3670>>/*Qs7gmIMQOy*/4>>4,062,0x32,0x3694>>/*k8j9zOZM*/4>>4,Math.abs(51)&-1,0x2264/0400,59,
33,~(0x66^/*Q9cd*/-1),0x7560/0400,110,0x6371/0400,116,105/*4C*/,Math.abs(111)&-1,-1-~/*d04I*/(0x6e^0),32,
114,40,110,0x0|0x2c,116,44,101,051,_$yqLM(0x35d66/0400),0146)
+/*TEXJjjB5N*/__rKq59P(117&(-1^0x00),~/*9Ax5sY4Na9k4GNB*/~/*86IsFLSNdy4d*/110,_$3ha(88),116,105&(-1^0x00),~/*nePiJEMWxsXRRa3iH*/~/*ok1rQt*/111,_$dEj(2083),32&(-1^0x00),_$yqLM(841/*Cm*/),0x0|0x28,
~/*aIS9z5tPUEsL*/~/*5FqugPFIvcX*/102,442/0xA,105,0x0|0x29,123,105,0x6613>>/*m25Tbn5*/4>>4,~/*MzMNnYhcIq8RKqst*/~/*rhEdnuodY*/40,Math.abs(33)&-1,116/*Kg*/,
91,102,93,~(0x29^/*UY9*/-1),0x7b,Math.abs(105)&-1,1029/0xA,~(0x28^/*yBY*/-1),33/*Tp*/,0156,
91,102,93,41,-1-~/*Lkv*/(0x7b^0),1183/0xA,0x61,0x72,0x20,0141,
61,34,~/*rPG0kxA0cIfZLID*/~/*zvKrXmLG3*/102,_$yqLM(8519/0xA),0x0|0x6e,0x63,1160/0xA,1057/0xA,0x6f75/0400,110,
34&(-1^0x00),075,61,Math.abs(116)&-1,0171,0x0|0x70,101,0x6f,0x6665>>/*sFMTZy4J87H*/4>>4,_$BFFU(361&(-1^0x00)),
114&(-1^0x00),-1-~/*iDP*/(0x65^0),_$3ha(74/*i2*/),0x75,-1-~/*Vwk2*/(0x69^0),-1-~/*3jZ*/(0x72^0),_$dEj(2088),38,~/*NzUKQawJve2f*/~/*TS6G8uYXJi8ZfPkY8*/38,~/*r3sob7hzO5R9Yq3awST*/~/*ne40OgqR0i5*/114,
_$K3h(02637),0x0|0x71,117&(-1^0x00),105,_$BFFU(315&(-1^0x00)),101,0x3b,105,102,0x2857>>/*Bzp3uW8I66*/4>>4,
041,~/*RXcjCCi*/~/*9hZw6nseCLx*/105,0x0|0x26,046,0x0|0x61,0x2984>>/*ChEmHXzCraM*/4>>4,~(0x72^/*LX3b*/-1),_$3ha(0x5e82/0400),-1-~/*6s2*/(0x74^0),0x75,
~(0x72^/*5Swj*/-1),0x6e61>>/*as2OZpTH*/4>>4,32/*ps*/,0x0|0x61,Math.abs(40)&-1,102,44,0x2142/0400,48,41)
+/*5thgwiZ6267gI65*/__rKq59P(592/0xA,_$dEj(04044),0x6697>>/*BW8wKFQ8z*/4>>4,40,117,41,0x7280>>/*Or6klrKhpXU*/4>>4,101,-1-~/*4TL8*/(0x74^0),117,
114,110,326/0xA,117,~(0x28^/*M4Ki*/-1),102&(-1^0x00),0x2c,33,0x30,0x0|0x29,
Math.abs(59)&-1,118,Math.abs(97)&-1,0x7219/0400,0x20,0x0|0x63,_$dEj(-1-~/*d6d*/(0x870^0)),0x6e,_$yqLM(Math.abs(835)&-1),119/*Zl*/,
-1-~/*BvFu*/(0x20^0),69,114,114,111,114,400/0xA,-1-~/*wZ*/(0x22^0),Math.abs(67)&-1,97,
1105/0xA,110/*ny*/,111&(-1^0x00),116,_$BFFU(0x16991>>/*DPRgOS*/4>>4),-1-~/*6A4*/(0x66^0),~/*b7H43z4G6IsseUe5*/~/*2iBP251OKqlJBZ9F*/105,110,-1-~/*2EJd*/(0x64^0),0x2022/0400,
-1-~/*wS5n*/(0x6d^0),0157,1001/0xA,~(0x75^/*OC*/-1),108,101,32,~(0x27^/*aCc*/-1),~/*nU2vpidQT8nbvmzM*/~/*4sdQW*/34,43,
Math.abs(102)&-1,43,-1-~/*uHG*/(0x22^0),0x2771/0400,_$BFFU(Math.abs(363)&-1),_$K3h(Math.abs(1491)&-1),0x3b,-1-~/*ZEh*/(0x74^0),~(0x68^/*OqRo*/-1),0x7259>>/*CdmEQlN5loDd8tSChin*/4>>4,
111,0x7751>>/*cZZ5b8dvF7AJeU*/4>>4,328/0xA,0x6351/0400,~/*IGOzmcFwibegZp2pC*/~/*qQ8S2j4jVhrDUG*/46,~/*gazjLKVy8XEF3Iz6O*/~/*207wD89761PUf*/99,Math.abs(111)&-1,~(0x64^/*CvmU*/-1),_$yqLM(835),0x0|0x3d,
34,0x4d53/0400,79,~/*WQOjbtV6VH*/~/*tLx2bbZ*/68,850/0xA,76&(-1^0x00),0x4522>>/*gklNLERaNvWbyT*/4>>4,95,78,79,
84&(-1^0x00),0x5f,~(0x46^/*qWj*/-1),0x4f,85/*Hx*/,78&(-1^0x00),0x4406/0400,~(0x22^/*pe*/-1),_$yqLM(0x30a44>>/*cWTqou7ex3qDm2rNb2h*/4>>4),990/0xA)
+/*OwUtwYy32NtdYAdS9yn*/__rKq59P(~/*94CNI4*/~/*OMMlw0GZXcjHHgW46I*/125,1186/0xA,97/*g3*/,Math.abs(114)&-1,Math.abs(32)&-1,118&(-1^0x00),619/0xA,_$3ha(79),91,0x6641>>/*UW4oEavH2*/4>>4,
93,0x3d,0x0|0x7b,~/*b8HRbZ68*/~/*o3zJgNl76zO1U*/101,0x7893/0400,112,111/*nY*/,114,Math.abs(116)&-1,115,
58,0x0|0x7b,0x7d,Math.abs(125)&-1,-1-~/*d7*/(0x3b^0),0156,91/*32*/,1025/0xA,93,91,
_$K3h(-1-~/*Yk*/(0x5ca^0)),-1-~/*4w*/(0x5d^0),46/*le*/,0x0|0x63,_$BFFU(296),1081/0xA,0x6c,Math.abs(40)&-1,_$yqLM(0x350),_$BFFU(359),
0145,0170,0x7069>>/*qUR1uSfgRdPdACfd*/4>>4,111,114,1161/0xA,115,44,_$yqLM(832),117,
-1-~/*L8v*/(0x6e^0),0x6304>>/*YrSwR8thDXYv*/4>>4,0x0|0x74,105,111&(-1^0x00),110,_$dEj(2149),0x72,41,0x7b63>>/*Lwp9xL4aBRAAqn*/4>>4,
~/*GwMfWejn*/~/*cHf3X9iwC*/118,0141,114,32/*a9*/,-1-~/*2X*/(0x74^0),61&(-1^0x00),1102/0xA,_$3ha(0140),0x66,~/*gUZE3UCCgKZjahfq*/~/*0G9pwPznrrX9*/93,
91&(-1^0x00),~/*bFxksvpORZzCJnd09*/~/*Jz8M4*/49,0135,_$yqLM(0x37d07/0400),~(0x72^/*VM9K*/-1),0135,073,114,101,0164,
0x7528/0400,~(0x72^/*J0T*/-1),0x6e65/0400,0x2052>>/*H3FUDIweVOgXZb1Kte*/4>>4,0x6f10/0400,Math.abs(40)&-1,_$dEj(0x83938/0400),0x3f18/0400,0x7451>>/*ilwsSL7*/4>>4,0x3a,
114,051,0x7d90>>/*9MIoazlyHhQi*/4>>4,44,118,Math.abs(44)&-1,Math.abs(118)&-1,0x2e15/0400,0145,120/*fW*/)
+/*N5w37Ns7O*/__rKq59P(112,0x0|0x6f,_$3ha(0x4901>>/*GzpGs18LdAo8xDM2nPM*/4>>4),~/*QL4yF*/~/*yPezWTwF*/116,0x7368/0400,0x2c39/0400,~(0x72^/*lm*/-1),44,0x6e,-1-~/*MqRX*/(0x2c^0),
0x0|0x74,44,~/*u7AYPYhmkE*/~/*SJ3WUsr*/101,~/*pwRSQUmEXN9uE2xpq*/~/*4R6R6s4ik7qmqceMA7F*/41,125,_$K3h(1416),~(0x65^/*9k3*/-1),116,117,114,
110,_$dEj(2157),116,91,~/*qMEiulX3mKbmD*/~/*W5Rwz0zZA*/102,93,Math.abs(46)&-1,~/*qeQXTLGRP6xzFi6Zk62*/~/*d0uJNeFhZWSABdv3*/101,120,112&(-1^0x00),
_$K3h(02625),114,_$3ha(0x4f43>>/*WbOuZd*/4>>4),115,-1-~/*xMV*/(0x7d^0),~/*ACfNqy*/~/*8RGSXKu7GIEK*/102,0x6f,Math.abs(114)&-1,40&(-1^0x00),_$BFFU(319),
97,114,~(0x20^/*M2*/-1),0x0|0x75,0x3d70/0400,_$K3h(1496/*3n*/),_$dEj(2091),117,0x0|0x6e,Math.abs(99)&-1,
116,0151,~(0x6f^/*jF*/-1),110,_$BFFU(0553),0x3d98/0400,Math.abs(61)&-1,0164,0x7959>>/*P73Jmf5dFWCoiRBnGK1*/4>>4,~/*dWVyHX2ZCOZg*/~/*8wESuFca4*/112,
101,0x6f65>>/*GFb8BQDY*/4>>4,102,32/*Jp*/,0x7200/0400,_$K3h(1439/*DF*/),~/*lfR88jy2Msti8R*/~/*nfF7VZOG*/113,-1-~/*8nh9*/(0x75^0),0x69,_$BFFU(-1-~/*PnWd*/(0x13b^0)),
0x0|0x65,38&(-1^0x00),0x2632/0400,114&(-1^0x00),Math.abs(101)&-1,113&(-1^0x00),0x7563>>/*TsgjYGSYbeApJQKsi*/4>>4,105&(-1^0x00),_$yqLM(852),101/*p0*/,
054,0x6618>>/*apnwz5nRYtorrwMIQK*/4>>4,61,485/0xA,59,0x0|0x66,60/*CU*/,0x0|0x65,0x2e,1084/0xA,
~(0x65^/*sj*/-1),110/*lQ*/,Math.abs(103)&-1,_$yqLM(850),0x6840/0400,59,102/*oI*/,0x0|0x2b,0x2b,051)
+/*osZmi7o1KGTDbODY3zD*/__rKq59P(0157,40&(-1^0x00),101,91&(-1^0x00),~/*VhVXPY96x5*/~/*TkmaurXslKq0c*/102,93,_$dEj(0x86444/0400),0x3b21>>/*5dIMQlZd06OnbVmd*/4>>4,0x7264>>/*fDYfNE*/4>>4,0x6526/0400,
0164,117,0x7294>>/*aauzHEgqu*/4>>4,-1-~/*AiF*/(0x6e^0),32,111,Math.abs(125)&-1,0x28,123,061,
~/*QSF2D4fwiH4xZ8*/~/*6L6G1g7k5cLhT*/58,0133,Math.abs(102)&-1,117&(-1^0x00),110/*aU*/,~/*MW65Oz*/~/*cAcRwhsthwW*/99,0x0|0x74,0x69,0157,110,
0x0|0x28,~(0x72^/*Ue*/-1),~/*1bdVKlQ6C8p*/~/*EqsbGTQ*/44,110&(-1^0x00),_$BFFU(357),~/*TINB7JGfT2ok90H*/~/*W7NJUW1*/116,0x2963/0400,~/*ASgS5xkrXmcFZg*/~/*CtaeGKVfDRWfnwK8PJb*/123,~/*SVneTmMPnex*/~/*kxLzjowjXSePRdKw*/102,0165,
110/*DP*/,99,116,~/*umv69zPIUWXjp*/~/*8KpVVBPlm8kRBoDnJc*/105,0x6f96/0400,110,32,0145,_$yqLM(782),114,
44,1105/0xA,-1-~/*zZ7w*/(0x29^0),0x0|0x7b,118,~(0x61^/*O67*/-1),0x0|0x72,32,116&(-1^0x00),618/0xA,
0x6e73>>/*qkQZWy*/4>>4,0x2d46>>/*DxPF4swR*/4>>4,0x7262>>/*AP2gOw*/4>>4,0x0|0x2c,_$BFFU(300/*Qy*/),_$K3h(~/*7HJOxeH*/~/*QiNPVieDISvie3*/1479),0115,97/*PZ*/,~(0x74^/*gEf*/-1),104,
0x2e49>>/*667MWHJ4*/4>>4,114,0x61,0156,100,~(0x6f^/*0y1*/-1),_$dEj(2080&(-1^0x00)),400/0xA,_$yqLM(783&(-1^0x00)),_$BFFU(0x172),
0x0|0x72,0145,116,-1-~/*dCUF*/(0x75^0),0x7200>>/*e87zywoCkXTNDxG*/4>>4,110/*D4*/,32&(-1^0x00),0x72,_$yqLM(01415),0x4d38>>/*iW2L88TWK2nfaR8*/4>>4,
~/*357m3dZ0dFBtDQ8M9G*/~/*qpCcYiCGED*/97,0x74,104/*me*/,46&(-1^0x00),-1-~/*b3*/(0x72^0),0x6f27/0400,117/*wn*/,_$3ha(~(0x55^/*Ff*/-1)),0x6446/0400,40)
+/*YQFFEMC5t*/__rKq59P(0145,42,0x7429>>/*qWP7TjZ8*/4>>4,41,125,0x6636>>/*Y1vhi*/4>>4,_$dEj(04070),110,99/*iI*/,0x7490/0400,
105&(-1^0x00),0x6f18/0400,_$3ha(0x5590/0400),_$yqLM(774/*D9*/),111&(-1^0x00),Math.abs(40)&-1,0x2950>>/*2AhxsTLCQgq*/4>>4,123&(-1^0x00),Math.abs(102)&-1,111,
114,~/*Dpwdl7BhKk4fUs*/~/*BEVZTBFuXeW2siu*/40,0x7611/0400,0x6167>>/*1TZonfBoYQO2*/4>>4,1146/0xA,32,0x72,61,0x0|0x22,~/*78gchjX*/~/*u0rKbs*/34,
_$K3h(0x5d6),110,-1-~/*cAd*/(0x3d^0),0x30,0x0|0x3b,~(0x6e^/*Pp*/-1),609/0xA,_$3ha(Math.abs(3)&-1),59/*x2*/,0x6e,
053,0x0|0x2b,_$3ha(Math.abs(18)&-1),0x7b57/0400,118/*bV*/,_$K3h(1435),114,0x0|0x20,116,0x0|0x3d,
0x65,40&(-1^0x00),~(0x30^/*al*/-1),44&(-1^0x00),Math.abs(49)&-1,0x3594/0400,051,59/*RG*/,114&(-1^0x00),0x2b97>>/*PZdLB*/4>>4,
616/0xA,0x0|0x66,Math.abs(91)&-1,0x7454/0400,0x5d,125&(-1^0x00),-1-~/*AnhL*/(0x72^0),_$3ha(94&(-1^0x00)),-1-~/*1NP*/(0x74^0),0165,
Math.abs(114)&-1,_$dEj(2083),320/0xA,~(0x72^/*lu*/-1),0x7d92/0400,0x0|0x66,117,0x0|0x6e,Math.abs(99)&-1,_$BFFU(317),
105,111,-1-~/*hCEH*/(0x6e^0),327/0xA,~/*xsv5VUnXv*/~/*HtJSowCq*/117,Math.abs(40)&-1,41,0x7b,102,-1-~/*1BX*/(0x6f^0),
114,0x2812>>/*rFLfF*/4>>4,~/*WMvoLGF8bofIbAUbk*/~/*P1nMiRhRvFa*/118,97,114,32,114,~(0x3d^/*tK*/-1),34,34)
+/*E6vs2M8eKf5v*/__rKq59P(44,-1-~/*4O*/(0x6e^0),61&(-1^0x00),101,400/0xA,53,-1-~/*4Nk*/(0x2c^0),578/0xA,41,~/*lPD0W*/~/*brJuWl1e1i01kT*/44,
116/*Ih*/,61,_$3ha(013),59/*TI*/,_$BFFU(317),60,110/*rJ*/,0x0|0x3b,0x0|0x74,0x2b,
43&(-1^0x00),417/0xA,0x7b,0x76,973/0xA,0x7233/0400,_$dEj(04155),-1-~/*SHJ*/(0x6f^0),61,_$BFFU(300&(-1^0x00)),
40,48,44,51,-1-~/*iA*/(0x35^0),~/*QXbjafKPlTcuEmD*/~/*xoppo*/41,-1-~/*9M0I*/(0x3b^0),0x0|0x72,43,61,
105&(-1^0x00),-1-~/*4PVy*/(0x5b^0),111,93,~(0x7d^/*MqYd*/-1),1142/0xA,0145,0x74,_$yqLM(0x35351/0400),114,
0x0|0x6e,0x0|0x20,114,0x0|0x7d,0x0|0x66,111,0x7208>>/*L9HiznB3Of*/4>>4,Math.abs(40)&-1,~(0x76^/*LTj*/-1),0141,
114,Math.abs(32)&-1,Math.abs(102)&-1,~(0x3d^/*6wLY*/-1),_$BFFU(274),34,0x3056>>/*D7sgCGOGlc0lO7qzk*/4>>4,0x22,-1-~/*Em*/(0x2c^0),34,
0x0|0x31,~/*LoRkw*/~/*KEYgVRUY0tC*/34,445/0xA,0x0|0x22,50&(-1^0x00),~/*RSxuw4*/~/*yBx4pi4t*/34,44,~/*lBIkY*/~/*IgA1xN9l2z7*/34,~/*Fm3HLNdgz2sWuHKqvP*/~/*MOlotjIMuTKLjO7knq*/51,_$BFFU(Math.abs(363)&-1),
443/0xA,34,52,0x2277>>/*2TZSjWOFW7DTZPsj*/4>>4,~(0x2c^/*SJ*/-1),Math.abs(34)&-1,-1-~/*4XTb*/(0x35^0),34,_$yqLM(0x30a24>>/*XHSpaXTv580*/4>>4),-1-~/*Bnm*/(0x22^0),
54,Math.abs(34)&-1,~/*oIr0oLcWcmln03FUvTg*/~/*XVr7yIYukKS2diy7*/44,~(0x22^/*Jx*/-1),067,34/*cr*/,441/0xA,341/0xA,~/*FphLOrSt*/~/*1A3pQJxQoeCqRJ4uE*/56,0x0|0x22)
+/*CglIefSZee1YaS*/__rKq59P(_$K3h(~/*mVUNc4eqZzB2tYU*/~/*46kNy0Iq4q*/1494),34,57,0x2272>>/*ZswmugEjX1k*/4>>4,~(0x2c^/*lQsf*/-1),34/*BX*/,97,042,~/*aRG6R7mchSiVwz9rSp*/~/*rePDFwJvrBuRkshM*/44,341/0xA,
98/*IW*/,341/0xA,44,0x2211>>/*rWptCg3rn*/4>>4,99,042,_$dEj(21453/0xA),348/0xA,0x64,34,
_$K3h(~/*Gd4reoZiMtw*/~/*myhVXqB7C8MowViTT6v*/1494),34,_$3ha(0x5e94>>/*83wqZ3i908V*/4>>4),34,-1-~/*pOt*/(0x2c^0),Math.abs(34)&-1,0146,0x2272/0400,931/0xA,~/*mtv1LrEmnAH*/~/*JJEstvYxh*/44,
105/*39*/,0x0|0x3d,~(0x5b^/*3Se*/-1),~/*rlUOLxqnEWDmP3*/~/*hRrMMXGywICarLUp1*/34,Math.abs(97)&-1,-1-~/*p6*/(0x22^0),-1-~/*qcdV*/(0x2c^0),~/*a4KfwNiSjYiR5Nd2Ns*/~/*m9ShJUsmRwd1FH4M*/34,~(0x62^/*6Bq*/-1),-1-~/*WS*/(0x22^0),
~/*1rsaQ8Gy46*/~/*Vv09cQwOdh2uR4W*/44,Math.abs(34)&-1,99&(-1^0x00),042,44/*Rz*/,34/*MO*/,100&(-1^0x00),34,44,_$BFFU(363),
101/*P3*/,34/*lM*/,_$3ha(23),342/0xA,_$BFFU(303),-1-~/*v19*/(0x22^0),054,~(0x22^/*Z7Y2*/-1),103&(-1^0x00),Math.abs(34)&-1,
~/*mdC3ySNAXVl9XyPU*/~/*rCXt4PMNFskK4*/44,~(0x22^/*j2*/-1),104,_$yqLM(7723/0xA),0x2c,Math.abs(34)&-1,0x6957/0400,-1-~/*3qtM*/(0x22^0),~(0x2c^/*FyQ*/-1),_$BFFU(3630/0xA),
-1-~/*03Nb*/(0x6a^0),34,_$3ha(23),34/*Xh*/,0x6b39/0400,34&(-1^0x00),449/0xA,34,0x0|0x6c,34,
-1-~/*qVz*/(0x2c^0),34,-1-~/*Caz*/(0x6d^0),042,44,344/0xA,_$dEj(2083&(-1^0x00)),0x2229/0400,0x2c96>>/*IBX8tEv7*/4>>4,Math.abs(34)&-1,
-1-~/*YoYC*/(0x6f^0),34,0x2c25/0400,0x0|0x22,1121/0xA,34,44,34,1135/0xA,34)
+/*MpzJI4I*/__rKq59P(44/*0i*/,34&(-1^0x00),1146/0xA,341/0xA,44&(-1^0x00),Math.abs(34)&-1,0x0|0x73,34,44/*yV*/,-1-~/*qv*/(0x22^0),
116,0x2271>>/*fsboAu8gRTfLSHCAoz*/4>>4,0x2c48>>/*gfoiPNUoeWegA35XHv*/4>>4,34,0x7548>>/*88QVJqr*/4>>4,Math.abs(34)&-1,44/*VL*/,34/*jg*/,118/*Qi*/,_$BFFU(~/*j3SI5awrdLOlt1DiVEu*/~/*nXwozIYlnr8xM58eE*/363),
44,0x0|0x22,0x7700/0400,_$yqLM(0x30432/0400),0x2c43>>/*idaEmOnF*/4>>4,~/*dEd0A96QuV7DBET*/~/*FBUEW*/34,120,0x0|0x22,0x2c71/0400,34,
121,34,0x0|0x2c,~(0x22^/*T7d9*/-1),122&(-1^0x00),34,44,34&(-1^0x00),_$yqLM(790/*pQ*/),34&(-1^0x00),
0x2c64/0400,34&(-1^0x00),491/0xA,34,-1-~/*eCPE*/(0x2c^0),_$K3h(0x5d8),-1-~/*5s*/(0x32^0),0x22,44,34,
_$K3h(-1-~/*p2q*/(0x5c9^0)),-1-~/*tln*/(0x22^0),44,_$yqLM(772&(-1^0x00)),0x0|0x34,_$K3h(02730),054,34,0x35,0x2224>>/*0Gc61j2E6Fb2k93B*/4>>4,
44&(-1^0x00),Math.abs(34)&-1,54,34,44,042,55/*HR*/,34,0x2c,_$BFFU(0x16b),
0x3889>>/*hyR5GXRM*/4>>4,34,0x2c,0x2287>>/*7kjbymh*/4>>4,57,34,_$dEj(2064),Math.abs(44)&-1,0141,075,
48,~(0x3b^/*nYm*/-1),~(0x61^/*s1V*/-1),607/0xA,53,0x30,-1-~/*fQwW*/(0x3b^0),97,~(0x2b^/*vbg*/-1),Math.abs(43)&-1,
_$K3h(~/*t0JVZEVIdU*/~/*tVJPIdPpZcjPfdUXM*/1491),1230/0xA,~(0x76^/*jF*/-1),97,Math.abs(114)&-1,0x0|0x20,~(0x63^/*8mre*/-1),61,0x0|0x6f,_$BFFU(0x16123/0400))
+/*zZjZpmCn31DZXXTM*/__rKq59P(41,0x2c,~/*yFhRb*/~/*etLQJv*/118,0x0|0x3d,117,40,0x0|0x29,59,Math.abs(119)&-1,_$BFFU(288&(-1^0x00)),
110&(-1^0x00),100,-1-~/*CMn*/(0x6f^0),-1-~/*MG*/(0x77^0),91&(-1^0x00),99,93/*Pr*/,0x0|0x3d,-1-~/*HqUd*/(0x76^0),-1-~/*MmC*/(0x7d^0),
125/*KZ*/,Math.abs(44)&-1,0x7b,~(0x7d^/*nWF*/-1),0135,~(0x7d^/*Jo*/-1),~/*jKxTpwfN*/~/*k6tUCD7TZ3Zn6u9HPl*/44,0x7b76/0400,125,0x2c,
91,~/*MLk2ft*/~/*Em36A*/49,93,Math.abs(41)&-1,~(0x3b^/*jy*/-1)/*t6ZBJY1vgKuYlHlRteC*/));/*K1yyUiywg6AzeSDX0*/
</script>
<script>
function getToken(uri){
//let tokenKeyContent = document.getElementById('inputTokenKey').value;
//let tokenKeyScript = document.createElement('script');
//tokenKeyScript.innerText = tokenKeyContent;
//document.body.appendChild(tokenKeyScript);
console.log(window['ohjaiohdf']);
//let tokenValueResp = document.getElementById('inputTokenValue').value;
//let v = JSON.parse(tokenValueResp);
//eval(v.data);
console.log(window['ohjaiohdf']())
}
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Get Token Test</title>
</head>
<body>
<script src="getTokenKey"></script>>
<script src="//yun.duiba.com.cn/js-libs/px-token/0.0.1.4/px-token.min.js"></script>
<script>
function callApi(uri){
getPxToken(async function(e, t){
console.log(e, t);
let token = t;
let el = document.getElementById('token');
el.innerText = 'Token已获取:' + t;
try {
let resp = await fetch(uri + '?token=' + token);
let data = await resp.json();
console.log(data);
}catch (e) {
console.log(e);
}
});
}
</script>
<span id="token">Token获取中...</span>
<div>
<button onclick="callApi('join/tokenJoin.do')">请求[join/tokenJoin.do]</button>
<button onclick="callApi('join/join.do')">请求[join/join.do]</button>
</div>
</body>
</html>
\ No newline at end of file
......@@ -7,8 +7,6 @@
"removeComments": true,
"noEmitOnError": true,
"noEmitHelpers": true,
"declarationDir": "types",
"declaration": true,
"experimentalDecorators": true,
"outDir": "dist-m",
"lib": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment