Commit efed272f authored by rockyl's avatar rockyl

更新tiny-image库

parent c1a8fe24
......@@ -2,10 +2,10 @@ var __extends;var __assign;var __rest;var __decorate;var __param;var __metadata;
}};__exportStar=function(m,exports){for(var p in m){if(!exports.hasOwnProperty(p)){exports[p]=m[p]}}};__values=function(o){var m=typeof Symbol==="function"&&o[Symbol.iterator],i=0;if(m){return m.call(o)}return{next:function(){if(o&&i>=o.length){o=void 0}return{value:o&&o[i++],done:!o}}}};__read=function(o,n){var m=typeof Symbol==="function"&&o[Symbol.iterator];if(!m){return o}var i=m.call(o),r,ar=[],e;try{while((n===void 0||n-->0)&&!(r=i.next()).done){ar.push(r.value)}}catch(error){e={error:error}}finally{try{if(r&&!r.done&&(m=i["return"])){m.call(i)}}finally{if(e){throw e.error}}}return ar};__spread=function(){for(var ar=[],i=0;i<arguments.length;i++){ar=ar.concat(__read(arguments[i]))}return ar};__spreadArrays=function(){for(var s=0,i=0,il=arguments.length;i<il;i++){s+=arguments[i].length}for(var r=Array(s),k=0,i=0;i<il;i++){for(var a=arguments[i],j=0,jl=a.length;j<jl;j++,k++){r[k]=a[j]}}return r};__await=function(v){return this instanceof __await?(this.v=v,this):new __await(v)};__asyncGenerator=function(thisArg,_arguments,generator){if(!Symbol.asyncIterator){throw new TypeError("Symbol.asyncIterator is not defined.")}var g=generator.apply(thisArg,_arguments||[]),i,q=[];return i={},verb("next"),verb("throw"),verb("return"),i[Symbol.asyncIterator]=function(){return this},i;function verb(n){if(g[n]){i[n]=function(v){return new Promise(function(a,b){q.push([n,v,a,b])>1||resume(n,v)})}}}function resume(n,v){try{step(g[n](v))}catch(e){settle(q[0][3],e)}}function step(r){r.value instanceof __await?Promise.resolve(r.value.v).then(fulfill,reject):settle(q[0][2],r)}function fulfill(value){resume("next",value)}function reject(value){resume("throw",value)}function settle(f,v){if(f(v),q.shift(),q.length){resume(q[0][0],q[0][1])}}};__asyncDelegator=function(o){var i,p;return i={},verb("next"),verb("throw",function(e){throw e}),verb("return"),i[Symbol.iterator]=function(){return this},i;function verb(n,f){i[n]=o[n]?function(v){return(p=!p)?{value:__await(o[n](v)),done:n==="return"}:f?f(v):v}:f}};__asyncValues=function(o){if(!Symbol.asyncIterator){throw new TypeError("Symbol.asyncIterator is not defined.")}var m=o[Symbol.asyncIterator],i;return m?m.call(o):(o=typeof __values==="function"?__values(o):o[Symbol.iterator](),i={},verb("next"),verb("throw"),verb("return"),i[Symbol.asyncIterator]=function(){return this},i);function verb(n){i[n]=o[n]&&function(v){return new Promise(function(resolve,reject){v=o[n](v),settle(resolve,reject,v.done,v.value)})}}function settle(resolve,reject,d,v){Promise.resolve(v).then(function(v){resolve({value:v,done:d})},reject)}};__makeTemplateObject=function(cooked,raw){if(Object.defineProperty){Object.defineProperty(cooked,"raw",{value:raw})}else{cooked.raw=raw}return cooked};__importStar=function(mod){if(mod&&mod.__esModule){return mod}var result={};if(mod!=null){for(var k in mod){if(Object.hasOwnProperty.call(mod,k)){result[k]=mod[k]}}}result["default"]=mod;return result};__importDefault=function(mod){return(mod&&mod.__esModule)?mod:{"default":mod}};exporter("__extends",__extends);exporter("__assign",__assign);exporter("__rest",__rest);exporter("__decorate",__decorate);exporter("__param",__param);exporter("__metadata",__metadata);exporter("__awaiter",__awaiter);exporter("__generator",__generator);exporter("__exportStar",__exportStar);exporter("__values",__values);exporter("__read",__read);exporter("__spread",__spread);exporter("__spreadArrays",__spreadArrays);exporter("__await",__await);exporter("__asyncGenerator",__asyncGenerator);exporter("__asyncDelegator",__asyncDelegator);exporter("__asyncValues",__asyncValues);exporter("__makeTemplateObject",__makeTemplateObject);exporter("__importStar",__importStar);exporter("__importDefault",__importDefault)});
var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: __decorate,__param: __param,__metadata: __metadata,__awaiter: __awaiter,__generator: __generator,__exportStar: __exportStar,__values: __values,__read: __read,__spread: __spread,__spreadArrays: __spreadArrays,__await: __await,__asyncGenerator: __asyncGenerator,__asyncDelegator: __asyncDelegator,__asyncValues: __asyncValues,__makeTemplateObject: __makeTemplateObject,__importStar: __importStar,__importDefault: __importDefault};
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib')) :
typeof define === 'function' && define.amd ? define(['exports', 'tslib'], factory) :
(global = global || self, factory(global.engine = {}, global.tslib));
}(this, function (exports, tslib_1) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('props-compute')) :
typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'props-compute'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.engine = {}, global.tslib, global.propsCompute));
}(this, (function (exports, tslib_1, propsCompute) { 'use strict';
var HashObject = (function () {
function HashObject() {
......@@ -1413,6 +1413,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
});
Object.defineProperty(DisplayObject.prototype, "scale", {
get: function () {
if (this.destroyed) {
return 1;
}
return this.transform.scale;
},
set: function (value) {
......@@ -1934,13 +1937,20 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var _this = this;
var list = this.alignList;
list.forEach(function (v) {
if (v.destroyed) {
return;
}
_this.autoSize(v);
_this.align(v);
});
list.forEach(function (v) {
if (v.destroyed) {
return;
}
if (v.alignMode === ALIGN_MODE.ONCE) {
v.alignEnabled = false;
}
v.onLayoutComplete && v.onLayoutComplete();
});
list.length = 0;
};
......@@ -3257,11 +3267,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
Container.prototype.attachVisibility = function () {
return;
this.dispatchEvent(this.worldVisible ? Event.VISIBLE : Event.HIDDEN);
for (var i = 0, li = this.children.length; i < li; i++) {
var child = this.children[i];
child.attachVisibility();
}
};
Container.prototype.addChild = function (child) {
this.addChildAt(child, this.children.length);
......@@ -3831,11 +3836,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._transformID = -1;
return _this;
}
FloatDisplay.prototype.addHtmlElement = function () {
FloatDisplay.prototype.addHtmlElement = function (el) {
var s = this;
if (!s.stage) {
return;
}
if (!container) {
container = document.createElement('div');
container.style.position = "absolute";
......@@ -3846,16 +3848,24 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
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);
try {
container.removeChild(s._htmlElement);
}
else {
if (s._htmlElement && s.visible) {
style.display = "block";
}
catch (e) {
}
}
if (el) {
s._htmlElement = el;
}
container.appendChild(s._htmlElement);
if (!s._isAdded) {
s._isAdded = true;
s.stage["_floatDisplayList"].push(s);
}
else {
if (s._htmlElement && s.visible) {
var style = s._htmlElement.style;
style.display = "block";
}
}
};
......@@ -3864,6 +3874,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return this._htmlElement;
},
set: function (v) {
this._shouldUpdateStyle = true;
this.init(v);
this.updateStyle();
},
......@@ -3904,8 +3915,11 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
s._localBoundsSelf.width = w;
s._localBoundsSelf.height = h;
s._htmlElement = she;
this.addHtmlElement();
if (!s.stage) {
s._htmlElement = she;
return;
}
this.addHtmlElement(she);
};
FloatDisplay.prototype.getStyle = function (elem, cssName) {
if (elem.style[cssName]) {
......@@ -3943,7 +3957,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
style.display = show;
}
if (visible) {
if (this._transformID != this.transform._worldID) {
if (this._shouldUpdateStyle || this._transformID != this.transform._worldID) {
this._shouldUpdateStyle = false;
this._transformID = this.transform._worldID;
var mtx = s.transform.worldMatrix;
var d = devicePixelRatio;
......@@ -4870,7 +4885,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
function determineCrossOrigin(url, loc) {
if (loc === void 0) { loc = window.location; }
if (url.indexOf('data:') === 0) {
return '';
}
......@@ -5600,7 +5614,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return color;
}
function inputFeildIosEnable() {
var u = navigator.userAgent, app = navigator.appVersion;
var u = navigator.userAgent;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if (isIOS) {
setTimeout(function () {
......@@ -16011,1052 +16025,1060 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return EditableText;
}(TextField));
var ScrollViewBase = (function (_super) {
tslib_1.__extends(ScrollViewBase, _super);
function ScrollViewBase(maxDistance, isFull) {
if (isFull === void 0) { isFull = false; }
var _this = _super.call(this) || this;
_this.distance = 0;
_this.minDis = 0;
_this.maskObj = new Graphics();
_this.viewPort = new Container();
_this.lastValue = 0;
_this.speed = 0;
_this.addSpeed = 0;
_this.isStop = true;
_this.maxSpeed = 100;
_this.fSpeed = 20;
_this.paramXY = "y";
_this.paramSize = "height";
_this.stopTimes = -1;
_this.isMouseDownState = 0;
_this.autoScroll = false;
_this.isSpringBack = true;
var s = _this;
s._instanceType = "ScrollContainer";
_super.prototype.addChild.call(_this, s.maskObj);
_super.prototype.addChild.call(_this, s.viewPort);
if (!isFull) {
s.viewPort.mask = s.maskObj;
s.maskObj.isUsedToMask = false;
var Tween = (function () {
function Tween(target, props, pluginData) {
this._target = null;
this._useTicks = false;
this.ignoreGlobalPause = false;
this.loop = false;
this.pluginData = null;
this._steps = null;
this.paused = false;
this.duration = 0;
this._prevPos = -1;
this.position = null;
this._prevPosition = 0;
this._stepPosition = 0;
this.passive = false;
this.initialize(target, props, pluginData);
}
Tween.get = function (target, props, pluginData, override) {
if (pluginData === void 0) { pluginData = null; }
if (override === void 0) { override = false; }
if (override) {
Tween.removeTweens(target);
}
s.maskObj.alpha = 0;
s.updateViewRect();
s.direction = exports.SCROLL_DIRECTION.VERTICAL;
s.addEventListener(Event.ADDED_TO_STAGE, function (e) {
s.stage.addEventListener(MouseEvent.MOUSE_UP, s.onMouseEvent, s);
s.stage.addEventListener(MouseEvent.MOUSE_MOVE, s.onMouseEvent, s);
});
s.addEventListener(Event.REMOVED_FROM_STAGE, function (e) {
s.stage.removeEventListener(MouseEvent.MOUSE_UP, s.onMouseEvent, s);
s.stage.removeEventListener(MouseEvent.MOUSE_MOVE, s.onMouseEvent, s);
});
s.addEventListener(MouseEvent.MOUSE_DOWN, s.onMouseEvent, s, false);
s.addEventListener(Event.ENTER_FRAME, function () {
var view = s.viewPort;
if (s.autoScroll)
return;
if (!s.isSpringBack) {
if (view[s.paramXY] > 0) {
s.addSpeed = 0;
s.speed = 0;
s.isStop = true;
view[s.paramXY] = 0;
return;
}
else if (view[s.paramXY] < s.distance - s.maxDistance) {
s.addSpeed = 0;
s.speed = 0;
s.isStop = true;
view[s.paramXY] = Math.min(0, s.distance - s.maxDistance);
return;
}
}
if (!s.isStop) {
if (Math.abs(s.speed) > 0) {
view[s.paramXY] += s.speed;
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
s.speed += s.addSpeed * s.fSpeed;
}
else {
s.speed += s.addSpeed;
}
if (s.speed * s.addSpeed > 0) {
s.dispatchEvent(Event.ON_SCROLL_STOP);
s.speed = 0;
}
}
else {
if (s.addSpeed != 0) {
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
var tarP = 0;
if (view[s.paramXY] < s.distance - s.maxDistance) {
if (s.distance < s.maxDistance) {
tarP = s.distance - s.maxDistance;
}
}
view[s.paramXY] += 0.4 * (tarP - view[s.paramXY]);
if (Math.abs(tarP - view[s.paramXY]) < 0.1) {
s.isStop = true;
if (s.addSpeed > 0) {
s.dispatchEvent(Event.ON_SCROLL_TO_END);
}
else {
s.dispatchEvent(Event.ON_SCROLL_TO_HEAD);
}
}
}
}
else {
s.isStop = true;
}
}
return new Tween(target, props, pluginData);
};
Tween.removeTweens = function (target) {
if (!target.tween_count) {
return;
}
var tweens = Tween._tweens;
for (var i = tweens.length - 1; i >= 0; i--) {
if (tweens[i]._target == target) {
tweens[i].paused = true;
tweens.splice(i, 1);
}
else {
if (s.stopTimes >= 0) {
if (s.stopTimes >= 15) {
s.speed = 0;
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
s.isStop = false;
s.stopTimes = -1;
}
}
}
}
target.tween_count = 0;
};
Tween.pauseTweens = function (target) {
if (!target.tween_count) {
return;
}
var tweens = Tween._tweens;
for (var i = tweens.length - 1; i >= 0; i--) {
if (tweens[i]._target == target) {
tweens[i].paused = true;
}
});
s.addEventListener(Event.RESIZE, _this.updateViewRect, s);
return _this;
}
Object.defineProperty(ScrollViewBase.prototype, "maxDistance", {
get: function () {
return this.calMaxDistance();
},
enumerable: true,
configurable: true
});
ScrollViewBase.prototype.calMaxDistance = function () {
return this.viewPort[this.paramSize] + this.viewPort.getLocalBounds()[this.paramXY];
}
};
Object.defineProperty(ScrollViewBase.prototype, "direction", {
get: function () {
return this._direction;
},
set: function (value) {
this._direction = value;
this.updateDirection();
},
enumerable: true,
configurable: true
});
ScrollViewBase.prototype.updateDirection = function () {
var s = this;
if (this._direction === exports.SCROLL_DIRECTION.VERTICAL) {
s.distance = s.height;
s.paramXY = "y";
s.paramSize = 'height';
Tween.resumeTweens = function (target) {
if (!target.tween_count) {
return;
}
else {
s.distance = s.width;
s.paramXY = "x";
s.paramSize = 'width';
var tweens = Tween._tweens;
for (var i = tweens.length - 1; i >= 0; i--) {
if (tweens[i]._target == target) {
tweens[i].paused = false;
}
}
};
ScrollViewBase.prototype.updateViewRect = function () {
var s = this;
s.maskObj.clear();
s.maskObj.beginFill("#000000");
s.maskObj.drawRect(0, 0, s.width, s.height);
s.maskObj.endFill();
this.updateDirection();
Tween.tick = function (timeStamp, paused) {
if (paused === void 0) { paused = false; }
var delta = timeStamp - Tween._lastTime;
Tween._lastTime = timeStamp;
var tweens = Tween._tweens.concat();
for (var i = tweens.length - 1; i >= 0; i--) {
var tween = tweens[i];
if ((paused && !tween.ignoreGlobalPause) || tween.paused) {
continue;
}
tween.$tick(tween._useTicks ? 1 : delta);
}
return false;
};
ScrollViewBase.prototype.cancelScroll = function () {
this.isMouseDownState = 0;
Tween.flush = function () {
var timeStamp = Date.now();
var delta = Tween._lastTime ? (timeStamp - Tween._lastTime) : 16.67;
Tween._lastTime = timeStamp;
var tweens = Tween._tweens.concat();
for (var i = tweens.length - 1; i >= 0; i--) {
var tween = tweens[i];
if (tween.paused) {
continue;
}
tween.$tick(tween._useTicks ? 1 : delta);
}
};
ScrollViewBase.prototype.onMouseEvent = function (e) {
var s = this;
var view = s.viewPort;
if (e.type == MouseEvent.MOUSE_DOWN) {
e.stopPropagation();
if (!s.isStop) {
s.isStop = true;
Tween._register = function (tween, value) {
var target = tween._target;
var tweens = Tween._tweens;
if (value) {
if (target) {
target.tween_count = target.tween_count > 0 ? target.tween_count + 1 : 1;
}
if (s.autoScroll) {
s.autoScroll = false;
tweens.push(tween);
if (!Tween._inited) {
Tween._inited = true;
}
if (s._direction === exports.SCROLL_DIRECTION.VERTICAL) {
s.lastValue = e.stageY;
}
else {
if (target) {
target.tween_count--;
}
else {
s.lastValue = e.stageX;
var i = tweens.length;
while (i--) {
if (tweens[i] == tween) {
tweens.splice(i, 1);
return;
}
}
s.speed = 0;
s.isMouseDownState = 1;
}
else if (e.type == MouseEvent.MOUSE_MOVE) {
if (s.isMouseDownState == 0)
return;
if (s.isMouseDownState == 1) {
s.dispatchEvent(Event.ON_SCROLL_START);
}
s.isMouseDownState = 2;
var currentValue = void 0;
if (s._direction === exports.SCROLL_DIRECTION.VERTICAL) {
currentValue = e.stageY;
};
Tween.removeAllTweens = function () {
var tweens = Tween._tweens;
for (var i = 0, l = tweens.length; i < l; i++) {
var tween = tweens[i];
tween.paused = true;
tween._target.tween_count = 0;
}
tweens.length = 0;
};
Tween.prototype.initialize = function (target, props, pluginData) {
this._target = target;
if (props) {
this._useTicks = props.useTicks;
this.ignoreGlobalPause = props.ignoreGlobalPause;
this.loop = props.loop;
if (props.onChange) {
this.onChange = props.onChange.bind(props.onChangeObj);
}
else {
currentValue = e.stageX;
this.onChange = null;
}
s.speed = currentValue - s.lastValue;
if (s.speed > s.minDis) {
s.addSpeed = -2;
if (s.speed > s.maxSpeed) {
s.speed = s.maxSpeed;
}
if (props.override) {
Tween.removeTweens(target);
}
else if (s.speed < -s.minDis) {
if (s.speed < -s.maxSpeed) {
s.speed = -s.maxSpeed;
}
this.pluginData = pluginData || {};
this._curQueueProps = {};
this._initQueueProps = {};
this._steps = [];
if (props && props.paused) {
this.paused = true;
}
else {
Tween._register(this, true);
}
if (props && props.position != null) {
this.setPosition(props.position, Tween.NONE);
}
};
Tween.prototype.setPosition = function (value, actionsMode) {
if (actionsMode === void 0) { actionsMode = 1; }
if (value < 0) {
value = 0;
}
var t = value;
var end = false;
if (t >= this.duration) {
if (this.loop) {
var newTime = t % this.duration;
if (t > 0 && newTime === 0) {
t = this.duration;
}
else {
t = newTime;
}
s.addSpeed = 2;
}
else {
s.speed = 0;
t = this.duration;
end = true;
}
if (s.speed != 0) {
var speedPer = 1;
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
speedPer = 0.2;
}
if (t == this._prevPos) {
return end;
}
if (end) {
this.setPaused(true);
}
var prevPos = this._prevPos;
this.position = this._prevPos = t;
this._prevPosition = value;
if (this._target) {
if (this._steps.length > 0) {
var l = this._steps.length;
var stepIndex = -1;
for (var i = 0; i < l; i++) {
if (this._steps[i].type == "step") {
stepIndex = i;
if (this._steps[i].t <= t && this._steps[i].t + this._steps[i].d >= t) {
break;
}
}
}
for (var i = 0; i < l; i++) {
if (this._steps[i].type == "action") {
if (actionsMode != 0) {
if (this._useTicks) {
this._runAction(this._steps[i], t, t);
}
else if (actionsMode == 1 && t < prevPos) {
if (prevPos != this.duration) {
this._runAction(this._steps[i], prevPos, this.duration);
}
this._runAction(this._steps[i], 0, t, true);
}
else {
this._runAction(this._steps[i], prevPos, t);
}
}
}
else if (this._steps[i].type == "step") {
if (stepIndex == i) {
var step = this._steps[stepIndex];
this._updateTargetProps(step, Math.min((this._stepPosition = t - step.t) / step.d, 1));
}
}
}
view[s.paramXY] += (currentValue - s.lastValue) * speedPer;
}
s.lastValue = currentValue;
s.stopTimes = 0;
}
this.onChange && this.onChange();
return end;
};
Tween.prototype._runAction = function (action, startPos, endPos, includeStart) {
if (includeStart === void 0) { includeStart = false; }
var sPos = startPos;
var ePos = endPos;
if (startPos > endPos) {
sPos = endPos;
ePos = startPos;
}
var pos = action.t;
if (pos == ePos || (pos > sPos && pos < ePos) || (includeStart && pos == startPos)) {
action.f.apply(action.o, action.p);
}
};
Tween.prototype._updateTargetProps = function (step, ratio) {
var p0, p1, v, v0, v1, arr;
if (!step && ratio == 1) {
this.passive = false;
p0 = p1 = this._curQueueProps;
}
else {
s.isStop = false;
s.stopTimes = -1;
if (s.speed == 0 && s.isMouseDownState == 2) {
s.dispatchEvent(Event.ON_SCROLL_STOP);
this.passive = !!step.v;
if (this.passive) {
return;
}
if (step.e) {
ratio = step.e(ratio, 0, 1, 1);
}
p0 = step.p0;
p1 = step.p1;
}
for (var n in this._initQueueProps) {
if ((v0 = p0[n]) == null) {
p0[n] = v0 = this._initQueueProps[n];
}
if ((v1 = p1[n]) == null) {
p1[n] = v1 = v0;
}
if (v0 == v1 || ratio == 0 || ratio == 1 || (typeof (v0) != "number")) {
v = ratio == 1 ? v1 : v0;
}
else {
v = v0 + (v1 - v0) * ratio;
}
var ignore = false;
if (arr = Tween._plugins[n]) {
for (var i = 0, l = arr.length; i < l; i++) {
var v2 = arr[i].tween(this, n, v, p0, p1, ratio, !!step && p0 == p1, !step);
if (v2 == Tween.IGNORE) {
ignore = true;
}
else {
v = v2;
}
}
}
if (!ignore) {
this._target[n] = v;
}
s.isMouseDownState = 0;
}
};
ScrollViewBase.prototype.scrollTo = function (dis, time) {
var s = this;
var newDis = s.paramXY == "x" ? s.width : s.height;
if (dis < 0) {
dis = 0;
Tween.prototype.setPaused = function (value) {
if (this.paused == value) {
return this;
}
else if (dis > s.maxDistance - newDis) {
dis = s.maxDistance - newDis;
this.paused = value;
Tween._register(this, !value);
return this;
};
Tween.prototype._cloneProps = function (props) {
var o = {};
for (var n in props) {
o[n] = props[n];
}
if (Math.abs(s.viewPort[s.paramXY] + dis) > 2) {
s.isStop = true;
s.isMouseDownState = 0;
s.viewPort[s.paramXY] = -dis;
return o;
};
Tween.prototype._addStep = function (o) {
if (o.d > 0) {
o.type = "step";
this._steps.push(o);
o.t = this.duration;
this.duration += o.d;
}
return this;
};
ScrollViewBase.prototype.destroy = function () {
var s = this;
s.maskObj.destroy();
s.viewPort.destroy();
s.maskObj = null;
s.viewPort = null;
_super.prototype.destroy.call(this);
};
return ScrollViewBase;
}(Container));
function fieldChanged(onModify) {
return function (target, key) {
var privateKey = '_' + key;
Object.defineProperty(target, key, {
enumerable: true,
get: function () {
return this[privateKey];
},
set: function (v) {
var oldValue = this[privateKey];
if (oldValue !== v) {
this[privateKey] = v;
onModify.apply(this, [v, key, oldValue]);
Tween.prototype._appendQueueProps = function (o) {
var arr, oldValue, i, l, injectProps;
for (var n in o) {
if (this._initQueueProps[n] === undefined) {
oldValue = this._target[n];
if (arr = Tween._plugins[n]) {
for (i = 0, l = arr.length; i < l; i++) {
oldValue = arr[i].init(this, n, oldValue);
}
}
this._initQueueProps[n] = this._curQueueProps[n] = (oldValue === undefined) ? null : oldValue;
}
});
else {
oldValue = this._curQueueProps[n];
}
}
for (var n in o) {
oldValue = this._curQueueProps[n];
if (arr = Tween._plugins[n]) {
injectProps = injectProps || {};
for (i = 0, l = arr.length; i < l; i++) {
if (arr[i].step) {
arr[i].step(this, n, oldValue, o[n], injectProps);
}
}
}
this._curQueueProps[n] = o[n];
}
if (injectProps) {
this._appendQueueProps(injectProps);
}
return this._curQueueProps;
};
}
var dirtyFieldDetector = fieldChanged(function (value, key, oldValue) {
this['__fieldDirty'] = true;
});
var deepDirtyFieldDetector = fieldChanged(function (value, key, oldValue) {
var scope = this;
scope['__fieldDirty'] = true;
if (typeof value === 'object') {
value['onModify'] = function () {
scope['__fieldDirty'] = true;
};
}
});
var dirtyFieldTrigger = fieldChanged(function (value, key, oldValue) {
this['onModify'] && this['onModify'](value, key, oldValue);
});
var deepDirtyFieldTrigger = fieldChanged(function (value, key, oldValue) {
if (this['onModify']) {
this['onModify'](value, key, oldValue);
if (typeof value === 'object') {
value['onModify'] = this['onModify'];
Tween.prototype._addAction = function (o) {
o.t = this.duration;
o.type = "action";
this._steps.push(o);
return this;
};
Tween.prototype._set = function (props, o) {
for (var n in props) {
o[n] = props[n];
}
}
});
var ScrollListItemBase = (function (_super) {
tslib_1.__extends(ScrollListItemBase, _super);
function ScrollListItemBase() {
return _super !== null && _super.apply(this, arguments) || this;
}
ScrollListItemBase.prototype._initData = function (id, data) {
this.id = id;
this.data = data;
if (id >= 0) {
this.updateData(data);
};
Tween.prototype.wait = function (duration, passive) {
if (duration == null || duration <= 0) {
return this;
}
var o = this._cloneProps(this._curQueueProps);
return this._addStep({ d: duration, p0: o, p1: o, v: passive });
};
return ScrollListItemBase;
}(Container));
var ScrollListBase = (function (_super) {
tslib_1.__extends(ScrollListBase, _super);
function ScrollListBase() {
var _this = _super.call(this) || this;
_this._items = null;
_this._isInit = 0;
_this.data = [];
_this.downL = null;
_this._lastFirstId = -1;
_this._updateId = -1;
_this.itemWidth = 0;
_this.itemHeight = 0;
_this.cols = 1;
var s = _this;
s._instanceType = "ScrollList";
s._items = [];
s._itemCount = 0;
s.once(Event.ENTER_FRAME, s.onNextFrame, s);
s.addEventListener(Event.ENTER_FRAME, s.flushData.bind(s));
return _this;
}
Object.defineProperty(ScrollListBase.prototype, "loadingView", {
get: function () {
return this.downL;
},
enumerable: true,
configurable: true
});
ScrollListBase.prototype.onNextFrame = function (event) {
this.updateViewRect();
Tween.prototype.to = function (props, duration, ease) {
if (ease === void 0) { ease = undefined; }
if (isNaN(duration) || duration < 0) {
duration = 0;
}
this._addStep({ d: duration || 0, p0: this._cloneProps(this._curQueueProps), e: ease, p1: this._cloneProps(this._appendQueueProps(props)) });
return this.set(props);
};
ScrollListBase.prototype.onModify = function (value, key) {
Tween.prototype.call = function (callback, thisObj, params) {
if (thisObj === void 0) { thisObj = undefined; }
if (params === void 0) { params = undefined; }
return this._addAction({ f: callback, p: params ? params : [], o: thisObj ? thisObj : this._target });
};
ScrollListBase.prototype.calMaxDistance = function () {
var key = 'item' + this.paramSize.substr(0, 1).toUpperCase() + this.paramSize.substr(1);
return this[key] * Math.ceil(this.data.length / this.cols);
Tween.prototype.set = function (props, target) {
if (target === void 0) { target = null; }
this._appendQueueProps(props);
return this._addAction({ f: this._set, o: this, p: [props, target ? target : this._target] });
};
ScrollListBase.prototype.updateData = function (data, isReset) {
if (isReset === void 0) { isReset = true; }
var s = this;
if (!s._isInit || isReset) {
s.data = data;
Tween.prototype.play = function (tween) {
if (!tween) {
tween = this;
}
else {
s.data = s.data.concat(data);
return this.call(tween.setPaused, tween, [false]);
};
Tween.prototype.pause = function (tween) {
if (!tween) {
tween = this;
}
s._isInit = 1;
s._lastFirstId = -1;
return this.call(tween.setPaused, tween, [true]);
};
ScrollListBase.prototype.flushData = function () {
var s = this;
var items = s._items;
if (items.length <= 0) {
Tween.prototype.$tick = function (delta) {
if (this.paused) {
return;
}
if (s._isInit > 0) {
if (s._updateId != s.viewPort.transform._localID) {
var id = s.viewPort[s.paramXY] > 0 ? 0 : (Math.abs(Math.floor(s.viewPort[s.paramXY] / s._itemRow)) - 1) * s.cols;
id = id < 0 ? 0 : id;
if (id != s._lastFirstId) {
s._lastFirstId = id;
if (id != items[0].id) {
for (var r = 0; r < s.cols; r++) {
if (s.speed > 0) {
items.unshift(items.pop());
}
else {
items.push(items.shift());
}
}
}
}
for (var i = 0; i < s._itemCount; i++) {
var item = items[i];
if (s._isInit == 1) {
item.sli_id = -1;
}
if (item.sli_id != id) {
if (s.data[id]) {
item._initData(s.data[id] ? id : -1, s.data[id]);
}
item[s.paramXY] = Math.floor(id / s.cols) * s._itemRow;
item[s._disParam] = (id % s.cols) * s._itemCol;
if (s.data[id]) {
item.sli_id = id;
item.visible = true;
}
else {
item.sli_id = -1;
item.visible = false;
}
}
id++;
}
s._isInit = 2;
}
}
this.setPosition(this._prevPosition + delta);
};
ScrollListBase.prototype.updateViewRect = function () {
_super.prototype.updateViewRect.call(this);
var s = this;
if (s.itemWidth && s.itemHeight) {
s._updateViewRect();
Tween.NONE = 0;
Tween.LOOP = 1;
Tween.REVERSE = 2;
Tween._tweens = [];
Tween.IGNORE = {};
Tween._plugins = {};
Tween._inited = false;
Tween._lastTime = 0;
return Tween;
}());
var Ease = (function () {
function Ease() {
}
Ease.get = function (amount) {
if (amount < -1) {
amount = -1;
}
};
ScrollListBase.prototype._updateViewRect = function () {
var s = this;
if (s._direction === exports.SCROLL_DIRECTION.VERTICAL) {
if (s.itemHeight <= 0) {
return;
}
s._disParam = "x";
s._itemRow = s.itemHeight;
s._itemCol = s.itemWidth;
if (amount > 1) {
amount = 1;
}
else {
if (s.itemWidth <= 0) {
return;
}
s._disParam = "y";
s._itemRow = s.itemWidth;
s._itemCol = s.itemHeight;
}
var newCount = (Math.ceil(s.distance / s._itemRow) + 1) * s.cols;
if (newCount != s._itemCount) {
if (newCount > s._itemCount) {
for (var i = s._itemCount; i < newCount; i++) {
var item = s.createItem();
item.id = -1;
item.data = null;
s._items.push(item);
s.viewPort.addChild(item);
}
return function (t) {
if (amount == 0) {
return t;
}
else {
for (var i = 0; i < s._itemCount - newCount; i++) {
s.viewPort.removeChild(s._items.pop());
}
if (amount < 0) {
return t * (t * -amount + 1 + amount);
}
s._itemCount = newCount;
s._lastFirstId = -1;
}
return t * ((2 - t) * amount + (1 - amount));
};
};
ScrollListBase.prototype.createItem = function () {
return new this.itemClass();
Ease.getPowIn = function (pow) {
return function (t) {
return Math.pow(t, pow);
};
};
ScrollListBase.prototype.setLoading = function (downLoading) {
var s = this;
if (s.downL) {
s.viewPort.removeChild(s.downL);
s.downL = null;
}
if (downLoading) {
s.downL = downLoading;
s.viewPort.addChild(downLoading);
s.downL[s.paramXY] = Math.max(s.distance, s.maxDistance);
}
else {
s.isStop = false;
}
Ease.getPowOut = function (pow) {
return function (t) {
return 1 - Math.pow(1 - t, pow);
};
};
ScrollListBase.prototype.destroy = function () {
var s = this;
s._items = null;
s.itemClass = null;
s.data = null;
s.downL = null;
_super.prototype.destroy.call(this);
Ease.getPowInOut = function (pow) {
return function (t) {
if ((t *= 2) < 1)
return 0.5 * Math.pow(t, pow);
return 1 - 0.5 * Math.abs(Math.pow(2 - t, pow));
};
};
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "itemWidth", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "itemHeight", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "cols", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "itemClass", void 0);
return ScrollListBase;
}(ScrollViewBase));
var Tween = (function () {
function Tween(target, props, pluginData) {
this._target = null;
this._useTicks = false;
this.ignoreGlobalPause = false;
this.loop = false;
this.pluginData = null;
this._steps = null;
this.paused = false;
this.duration = 0;
this._prevPos = -1;
this.position = null;
this._prevPosition = 0;
this._stepPosition = 0;
this.passive = false;
this.initialize(target, props, pluginData);
}
Tween.get = function (target, props, pluginData, override) {
if (pluginData === void 0) { pluginData = null; }
if (override === void 0) { override = false; }
if (override) {
Tween.removeTweens(target);
}
return new Tween(target, props, pluginData);
Ease.sineIn = function (t) {
return 1 - Math.cos(t * Math.PI / 2);
};
Tween.removeTweens = function (target) {
if (!target.tween_count) {
return;
}
var tweens = Tween._tweens;
for (var i = tweens.length - 1; i >= 0; i--) {
if (tweens[i]._target == target) {
tweens[i].paused = true;
tweens.splice(i, 1);
}
}
target.tween_count = 0;
Ease.sineOut = function (t) {
return Math.sin(t * Math.PI / 2);
};
Tween.pauseTweens = function (target) {
if (!target.tween_count) {
return;
}
var tweens = Tween._tweens;
for (var i = tweens.length - 1; i >= 0; i--) {
if (tweens[i]._target == target) {
tweens[i].paused = true;
}
}
Ease.sineInOut = function (t) {
return -0.5 * (Math.cos(Math.PI * t) - 1);
};
Tween.resumeTweens = function (target) {
if (!target.tween_count) {
return;
}
var tweens = Tween._tweens;
for (var i = tweens.length - 1; i >= 0; i--) {
if (tweens[i]._target == target) {
tweens[i].paused = false;
}
}
Ease.getBackIn = function (amount) {
return function (t) {
return t * t * ((amount + 1) * t - amount);
};
};
Tween.tick = function (timeStamp, paused) {
if (paused === void 0) { paused = false; }
var delta = timeStamp - Tween._lastTime;
Tween._lastTime = timeStamp;
var tweens = Tween._tweens.concat();
for (var i = tweens.length - 1; i >= 0; i--) {
var tween = tweens[i];
if ((paused && !tween.ignoreGlobalPause) || tween.paused) {
continue;
}
tween.$tick(tween._useTicks ? 1 : delta);
}
return false;
Ease.getBackOut = function (amount) {
return function (t) {
return (--t * t * ((amount + 1) * t + amount) + 1);
};
};
Tween.flush = function () {
var timeStamp = Date.now();
var delta = Tween._lastTime ? (timeStamp - Tween._lastTime) : 16.67;
Tween._lastTime = timeStamp;
var tweens = Tween._tweens.concat();
for (var i = tweens.length - 1; i >= 0; i--) {
var tween = tweens[i];
if (tween.paused) {
continue;
}
tween.$tick(tween._useTicks ? 1 : delta);
}
Ease.getBackInOut = function (amount) {
amount *= 1.525;
return function (t) {
if ((t *= 2) < 1)
return 0.5 * (t * t * ((amount + 1) * t - amount));
return 0.5 * ((t -= 2) * t * ((amount + 1) * t + amount) + 2);
};
};
Tween._register = function (tween, value) {
var target = tween._target;
var tweens = Tween._tweens;
if (value) {
if (target) {
target.tween_count = target.tween_count > 0 ? target.tween_count + 1 : 1;
}
tweens.push(tween);
if (!Tween._inited) {
Tween._inited = true;
}
}
else {
if (target) {
target.tween_count--;
}
var i = tweens.length;
while (i--) {
if (tweens[i] == tween) {
tweens.splice(i, 1);
return;
}
}
}
Ease.circIn = function (t) {
return -(Math.sqrt(1 - t * t) - 1);
};
Tween.removeAllTweens = function () {
var tweens = Tween._tweens;
for (var i = 0, l = tweens.length; i < l; i++) {
var tween = tweens[i];
tween.paused = true;
tween._target.tween_count = 0;
Ease.circOut = function (t) {
return Math.sqrt(1 - (--t) * t);
};
Ease.circInOut = function (t) {
if ((t *= 2) < 1) {
return -0.5 * (Math.sqrt(1 - t * t) - 1);
}
tweens.length = 0;
return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
};
Tween.prototype.initialize = function (target, props, pluginData) {
this._target = target;
if (props) {
this._useTicks = props.useTicks;
this.ignoreGlobalPause = props.ignoreGlobalPause;
this.loop = props.loop;
if (props.onChange) {
this.onChange = props.onChange.bind(props.onChangeObj);
}
else {
this.onChange = null;
}
if (props.override) {
Tween.removeTweens(target);
}
Ease.bounceIn = function (t) {
return 1 - Ease.bounceOut(1 - t);
};
Ease.bounceOut = function (t) {
if (t < 1 / 2.75) {
return (7.5625 * t * t);
}
this.pluginData = pluginData || {};
this._curQueueProps = {};
this._initQueueProps = {};
this._steps = [];
if (props && props.paused) {
this.paused = true;
else if (t < 2 / 2.75) {
return (7.5625 * (t -= 1.5 / 2.75) * t + 0.75);
}
else {
Tween._register(this, true);
else if (t < 2.5 / 2.75) {
return (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375);
}
if (props && props.position != null) {
this.setPosition(props.position, Tween.NONE);
else {
return (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375);
}
};
Tween.prototype.setPosition = function (value, actionsMode) {
if (actionsMode === void 0) { actionsMode = 1; }
if (value < 0) {
value = 0;
Ease.bounceInOut = function (t) {
if (t < 0.5)
return Ease.bounceIn(t * 2) * .5;
return Ease.bounceOut(t * 2 - 1) * 0.5 + 0.5;
};
Ease.getElasticIn = function (amplitude, period) {
var pi2 = Math.PI * 2;
return function (t) {
if (t == 0 || t == 1)
return t;
var s = period / pi2 * Math.asin(1 / amplitude);
return -(amplitude * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * pi2 / period));
};
};
Ease.getElasticOut = function (amplitude, period) {
var pi2 = Math.PI * 2;
return function (t) {
if (t == 0 || t == 1)
return t;
var s = period / pi2 * Math.asin(1 / amplitude);
return (amplitude * Math.pow(2, -10 * t) * Math.sin((t - s) * pi2 / period) + 1);
};
};
Ease.getElasticInOut = function (amplitude, period) {
var pi2 = Math.PI * 2;
return function (t) {
var s = period / pi2 * Math.asin(1 / amplitude);
if ((t *= 2) < 1)
return -0.5 * (amplitude * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * pi2 / period));
return amplitude * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * pi2 / period) * 0.5 + 1;
};
};
Ease.quadIn = Ease.getPowIn(2);
Ease.quadOut = Ease.getPowOut(2);
Ease.quadInOut = Ease.getPowInOut(2);
Ease.cubicIn = Ease.getPowIn(3);
Ease.cubicOut = Ease.getPowOut(3);
Ease.cubicInOut = Ease.getPowInOut(3);
Ease.quartIn = Ease.getPowIn(4);
Ease.quartOut = Ease.getPowOut(4);
Ease.quartInOut = Ease.getPowInOut(4);
Ease.quintIn = Ease.getPowIn(5);
Ease.quintOut = Ease.getPowOut(5);
Ease.quintInOut = Ease.getPowInOut(5);
Ease.backIn = Ease.getBackIn(1.7);
Ease.backOut = Ease.getBackOut(1.7);
Ease.backInOut = Ease.getBackInOut(1.7);
Ease.elasticIn = Ease.getElasticIn(1, 0.3);
Ease.elasticOut = Ease.getElasticOut(1, 0.3);
Ease.elasticInOut = Ease.getElasticInOut(1, 0.3 * 1.5);
return Ease;
}());
var ScrollViewBase = (function (_super) {
tslib_1.__extends(ScrollViewBase, _super);
function ScrollViewBase(maxDistance, isFull) {
if (isFull === void 0) { isFull = false; }
var _this = _super.call(this) || this;
_this.distance = 0;
_this.minDis = 0;
_this.maskObj = new Graphics();
_this.viewPort = new Container();
_this.lastValue = 0;
_this.speed = 0;
_this.addSpeed = 0;
_this.isStop = true;
_this.maxSpeed = 100;
_this.fSpeed = 20;
_this.paramXY = "y";
_this.paramSize = "height";
_this.stopTimes = -1;
_this.isMouseDownState = 0;
_this.autoScroll = false;
_this.isSpringBack = true;
var s = _this;
s._instanceType = "ScrollContainer";
_super.prototype.addChild.call(_this, s.maskObj);
_super.prototype.addChild.call(_this, s.viewPort);
if (!isFull) {
s.viewPort.mask = s.maskObj;
s.maskObj.isUsedToMask = false;
}
var t = value;
var end = false;
if (t >= this.duration) {
if (this.loop) {
var newTime = t % this.duration;
if (t > 0 && newTime === 0) {
t = this.duration;
s.maskObj.alpha = 0;
s.updateViewRect();
s.direction = exports.SCROLL_DIRECTION.VERTICAL;
s.addEventListener(Event.ADDED_TO_STAGE, function (e) {
s.stage.addEventListener(MouseEvent.MOUSE_UP, s.onMouseEvent, s);
s.stage.addEventListener(MouseEvent.MOUSE_MOVE, s.onMouseEvent, s);
});
s.addEventListener(Event.REMOVED_FROM_STAGE, function (e) {
s.stage.removeEventListener(MouseEvent.MOUSE_UP, s.onMouseEvent, s);
s.stage.removeEventListener(MouseEvent.MOUSE_MOVE, s.onMouseEvent, s);
});
s.addEventListener(MouseEvent.MOUSE_DOWN, s.onMouseEvent, s, false);
s.addEventListener(Event.ENTER_FRAME, function () {
var view = s.viewPort;
if (s.autoScroll)
return;
if (!s.isSpringBack) {
if (view[s.paramXY] > 0) {
s.addSpeed = 0;
s.speed = 0;
s.isStop = true;
view[s.paramXY] = 0;
return;
}
else {
t = newTime;
else if (view[s.paramXY] < s.distance - s.maxDistance) {
s.addSpeed = 0;
s.speed = 0;
s.isStop = true;
view[s.paramXY] = Math.min(0, s.distance - s.maxDistance);
return;
}
}
else {
t = this.duration;
end = true;
}
}
if (t == this._prevPos) {
return end;
}
if (end) {
this.setPaused(true);
}
var prevPos = this._prevPos;
this.position = this._prevPos = t;
this._prevPosition = value;
if (this._target) {
if (this._steps.length > 0) {
var l = this._steps.length;
var stepIndex = -1;
for (var i = 0; i < l; i++) {
if (this._steps[i].type == "step") {
stepIndex = i;
if (this._steps[i].t <= t && this._steps[i].t + this._steps[i].d >= t) {
break;
}
if (!s.isStop) {
if (Math.abs(s.speed) > 0) {
view[s.paramXY] += s.speed;
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
s.speed += s.addSpeed * s.fSpeed;
}
else {
s.speed += s.addSpeed;
}
if (s.speed * s.addSpeed > 0) {
s.dispatchEvent(Event.ON_SCROLL_STOP);
s.speed = 0;
}
}
for (var i = 0; i < l; i++) {
if (this._steps[i].type == "action") {
if (actionsMode != 0) {
if (this._useTicks) {
this._runAction(this._steps[i], t, t);
}
else if (actionsMode == 1 && t < prevPos) {
if (prevPos != this.duration) {
this._runAction(this._steps[i], prevPos, this.duration);
else {
if (s.addSpeed != 0) {
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
var tarP = 0;
if (view[s.paramXY] < s.distance - s.maxDistance) {
if (s.distance < s.maxDistance) {
tarP = s.distance - s.maxDistance;
}
this._runAction(this._steps[i], 0, t, true);
}
else {
this._runAction(this._steps[i], prevPos, t);
view[s.paramXY] += 0.4 * (tarP - view[s.paramXY]);
if (Math.abs(tarP - view[s.paramXY]) < 0.1) {
s.isStop = true;
if (s.addSpeed > 0) {
s.dispatchEvent(Event.ON_SCROLL_TO_END);
}
else {
s.dispatchEvent(Event.ON_SCROLL_TO_HEAD);
}
}
}
}
else if (this._steps[i].type == "step") {
if (stepIndex == i) {
var step = this._steps[stepIndex];
this._updateTargetProps(step, Math.min((this._stepPosition = t - step.t) / step.d, 1));
else {
s.isStop = true;
}
}
}
else {
if (s.stopTimes >= 0) {
if (s.stopTimes >= 15) {
s.speed = 0;
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
s.isStop = false;
s.stopTimes = -1;
}
}
}
}
}
this.onChange && this.onChange();
return end;
});
s.addEventListener(Event.RESIZE, _this.updateViewRect, s);
return _this;
}
Object.defineProperty(ScrollViewBase.prototype, "maxDistance", {
get: function () {
return this.calMaxDistance();
},
enumerable: true,
configurable: true
});
ScrollViewBase.prototype.calMaxDistance = function () {
return this.viewPort[this.paramSize] + this.viewPort.getLocalBounds()[this.paramXY];
};
Tween.prototype._runAction = function (action, startPos, endPos, includeStart) {
if (includeStart === void 0) { includeStart = false; }
var sPos = startPos;
var ePos = endPos;
if (startPos > endPos) {
sPos = endPos;
ePos = startPos;
Object.defineProperty(ScrollViewBase.prototype, "direction", {
get: function () {
return this._direction;
},
set: function (value) {
this._direction = value;
this.updateDirection();
},
enumerable: true,
configurable: true
});
ScrollViewBase.prototype.updateDirection = function () {
var s = this;
if (this._direction === exports.SCROLL_DIRECTION.VERTICAL) {
s.distance = s.height;
s.paramXY = "y";
s.paramSize = 'height';
}
var pos = action.t;
if (pos == ePos || (pos > sPos && pos < ePos) || (includeStart && pos == startPos)) {
action.f.apply(action.o, action.p);
else {
s.distance = s.width;
s.paramXY = "x";
s.paramSize = 'width';
}
};
Tween.prototype._updateTargetProps = function (step, ratio) {
var p0, p1, v, v0, v1, arr;
if (!step && ratio == 1) {
this.passive = false;
p0 = p1 = this._curQueueProps;
ScrollViewBase.prototype.updateViewRect = function () {
var s = this;
s.maskObj.clear();
s.maskObj.beginFill("#000000");
s.maskObj.drawRect(0, 0, s.width, s.height);
s.maskObj.endFill();
this.updateDirection();
};
ScrollViewBase.prototype.cancelScroll = function () {
this.isMouseDownState = 0;
};
ScrollViewBase.prototype.onMouseEvent = function (e) {
var s = this;
var view = s.viewPort;
if (e.type == MouseEvent.MOUSE_DOWN) {
e.stopPropagation();
if (!s.isStop) {
s.isStop = true;
}
if (s.autoScroll) {
s.autoScroll = false;
}
if (s._direction === exports.SCROLL_DIRECTION.VERTICAL) {
s.lastValue = e.stageY;
}
else {
s.lastValue = e.stageX;
}
s.speed = 0;
s.isMouseDownState = 1;
}
else {
this.passive = !!step.v;
if (this.passive) {
else if (e.type == MouseEvent.MOUSE_MOVE) {
if (s.isMouseDownState == 0)
return;
if (s.isMouseDownState == 1) {
s.dispatchEvent(Event.ON_SCROLL_START);
}
if (step.e) {
ratio = step.e(ratio, 0, 1, 1);
s.isMouseDownState = 2;
var currentValue = void 0;
if (s._direction === exports.SCROLL_DIRECTION.VERTICAL) {
currentValue = e.stageY;
}
p0 = step.p0;
p1 = step.p1;
}
for (var n in this._initQueueProps) {
if ((v0 = p0[n]) == null) {
p0[n] = v0 = this._initQueueProps[n];
else {
currentValue = e.stageX;
}
if ((v1 = p1[n]) == null) {
p1[n] = v1 = v0;
s.speed = currentValue - s.lastValue;
if (s.speed > s.minDis) {
s.addSpeed = -2;
if (s.speed > s.maxSpeed) {
s.speed = s.maxSpeed;
}
}
if (v0 == v1 || ratio == 0 || ratio == 1 || (typeof (v0) != "number")) {
v = ratio == 1 ? v1 : v0;
else if (s.speed < -s.minDis) {
if (s.speed < -s.maxSpeed) {
s.speed = -s.maxSpeed;
}
s.addSpeed = 2;
}
else {
v = v0 + (v1 - v0) * ratio;
s.speed = 0;
}
var ignore = false;
if (arr = Tween._plugins[n]) {
for (var i = 0, l = arr.length; i < l; i++) {
var v2 = arr[i].tween(this, n, v, p0, p1, ratio, !!step && p0 == p1, !step);
if (v2 == Tween.IGNORE) {
ignore = true;
}
else {
v = v2;
}
if (s.speed != 0) {
var speedPer = 1;
if (view[s.paramXY] > 0 || view[s.paramXY] < s.distance - s.maxDistance) {
speedPer = 0.2;
}
view[s.paramXY] += (currentValue - s.lastValue) * speedPer;
}
if (!ignore) {
this._target[n] = v;
}
s.lastValue = currentValue;
s.stopTimes = 0;
}
};
Tween.prototype.setPaused = function (value) {
if (this.paused == value) {
return this;
else {
s.isStop = false;
s.stopTimes = -1;
if (s.speed == 0 && s.isMouseDownState == 2) {
s.dispatchEvent(Event.ON_SCROLL_STOP);
}
s.isMouseDownState = 0;
}
this.paused = value;
Tween._register(this, !value);
return this;
};
Tween.prototype._cloneProps = function (props) {
var o = {};
for (var n in props) {
o[n] = props[n];
ScrollViewBase.prototype.scrollTo = function (dis, time) {
if (time === void 0) { time = 0; }
var _a;
var s = this;
var newDis = s.paramXY == "x" ? s.width : s.height;
if (dis < 0) {
dis = 0;
}
return o;
};
Tween.prototype._addStep = function (o) {
if (o.d > 0) {
o.type = "step";
this._steps.push(o);
o.t = this.duration;
this.duration += o.d;
else if (dis > s.maxDistance - newDis) {
dis = s.maxDistance - newDis;
}
return this;
};
Tween.prototype._appendQueueProps = function (o) {
var arr, oldValue, i, l, injectProps;
for (var n in o) {
if (this._initQueueProps[n] === undefined) {
oldValue = this._target[n];
if (arr = Tween._plugins[n]) {
for (i = 0, l = arr.length; i < l; i++) {
oldValue = arr[i].init(this, n, oldValue);
}
}
this._initQueueProps[n] = this._curQueueProps[n] = (oldValue === undefined) ? null : oldValue;
if (Math.abs(s.viewPort[s.paramXY] + dis) > 2) {
s.isStop = true;
s.isMouseDownState = 0;
if (time > 0) {
Tween.get(s.viewPort, null, null, true)
.to((_a = {}, _a[s.paramXY] = -dis, _a), time, Ease.cubicInOut);
}
else {
oldValue = this._curQueueProps[n];
s.viewPort[s.paramXY] = -dis;
}
}
for (var n in o) {
oldValue = this._curQueueProps[n];
if (arr = Tween._plugins[n]) {
injectProps = injectProps || {};
for (i = 0, l = arr.length; i < l; i++) {
if (arr[i].step) {
arr[i].step(this, n, oldValue, o[n], injectProps);
}
};
ScrollViewBase.prototype.destroy = function () {
var s = this;
s.maskObj.destroy();
s.viewPort.destroy();
s.maskObj = null;
s.viewPort = null;
_super.prototype.destroy.call(this);
};
return ScrollViewBase;
}(Container));
function fieldChanged(onModify) {
return function (target, key) {
var privateKey = '_' + key;
Object.defineProperty(target, key, {
enumerable: true,
get: function () {
return this[privateKey];
},
set: function (v) {
var oldValue = this[privateKey];
if (oldValue !== v) {
this[privateKey] = v;
onModify.apply(this, [v, key, oldValue]);
}
}
this._curQueueProps[n] = o[n];
}
if (injectProps) {
this._appendQueueProps(injectProps);
}
return this._curQueueProps;
};
Tween.prototype._addAction = function (o) {
o.t = this.duration;
o.type = "action";
this._steps.push(o);
return this;
});
};
Tween.prototype._set = function (props, o) {
for (var n in props) {
o[n] = props[n];
}
var dirtyFieldDetector = fieldChanged(function (value, key, oldValue) {
this['__fieldDirty'] = true;
});
var deepDirtyFieldDetector = fieldChanged(function (value, key, oldValue) {
var scope = this;
scope['__fieldDirty'] = true;
if (typeof value === 'object') {
value['onModify'] = function () {
scope['__fieldDirty'] = true;
};
}
});
var dirtyFieldTrigger = fieldChanged(function (value, key, oldValue) {
this['onModify'] && this['onModify'](value, key, oldValue);
});
var deepDirtyFieldTrigger = fieldChanged(function (value, key, oldValue) {
if (this['onModify']) {
this['onModify'](value, key, oldValue);
if (typeof value === 'object') {
value['onModify'] = this['onModify'];
}
};
Tween.prototype.wait = function (duration, passive) {
if (duration == null || duration <= 0) {
return this;
}
});
var ScrollListItemBase = (function (_super) {
tslib_1.__extends(ScrollListItemBase, _super);
function ScrollListItemBase() {
return _super !== null && _super.apply(this, arguments) || this;
}
ScrollListItemBase.prototype._initData = function (id, data) {
this.id = id;
this.data = data;
if (id >= 0) {
this.updateData(data);
}
var o = this._cloneProps(this._curQueueProps);
return this._addStep({ d: duration, p0: o, p1: o, v: passive });
};
Tween.prototype.to = function (props, duration, ease) {
if (ease === void 0) { ease = undefined; }
if (isNaN(duration) || duration < 0) {
duration = 0;
}
this._addStep({ d: duration || 0, p0: this._cloneProps(this._curQueueProps), e: ease, p1: this._cloneProps(this._appendQueueProps(props)) });
return this.set(props);
return ScrollListItemBase;
}(Container));
var ScrollListBase = (function (_super) {
tslib_1.__extends(ScrollListBase, _super);
function ScrollListBase() {
var _this = _super.call(this) || this;
_this._items = null;
_this._isInit = 0;
_this.data = [];
_this.downL = null;
_this._lastFirstId = -1;
_this._updateId = -1;
_this.itemWidth = 0;
_this.itemHeight = 0;
_this.cols = 1;
var s = _this;
s._instanceType = "ScrollList";
s._items = [];
s._itemCount = 0;
s.once(Event.ENTER_FRAME, s.onNextFrame, s);
s.addEventListener(Event.ENTER_FRAME, s.flushData.bind(s));
return _this;
}
Object.defineProperty(ScrollListBase.prototype, "loadingView", {
get: function () {
return this.downL;
},
enumerable: true,
configurable: true
});
ScrollListBase.prototype.onNextFrame = function (event) {
this.updateViewRect();
};
Tween.prototype.call = function (callback, thisObj, params) {
if (thisObj === void 0) { thisObj = undefined; }
if (params === void 0) { params = undefined; }
return this._addAction({ f: callback, p: params ? params : [], o: thisObj ? thisObj : this._target });
ScrollListBase.prototype.onModify = function (value, key) {
};
Tween.prototype.set = function (props, target) {
if (target === void 0) { target = null; }
this._appendQueueProps(props);
return this._addAction({ f: this._set, o: this, p: [props, target ? target : this._target] });
ScrollListBase.prototype.calMaxDistance = function () {
var key = 'item' + this.paramSize.substr(0, 1).toUpperCase() + this.paramSize.substr(1);
return this[key] * Math.ceil(this.data.length / this.cols);
};
Tween.prototype.play = function (tween) {
if (!tween) {
tween = this;
ScrollListBase.prototype.updateData = function (data, isReset) {
if (isReset === void 0) { isReset = true; }
var s = this;
if (!s._isInit || isReset) {
s.data = data;
}
return this.call(tween.setPaused, tween, [false]);
else {
s.data = s.data.concat(data);
}
s._isInit = 1;
s._lastFirstId = -1;
};
Tween.prototype.pause = function (tween) {
if (!tween) {
tween = this;
ScrollListBase.prototype.flushData = function () {
var s = this;
var items = s._items;
if (items.length <= 0) {
return;
}
if (s._isInit > 0) {
if (s._updateId != s.viewPort.transform._localID) {
var id = s.viewPort[s.paramXY] > 0 ? 0 : (Math.abs(Math.floor(s.viewPort[s.paramXY] / s._itemRow)) - 1) * s.cols;
id = id < 0 ? 0 : id;
if (id != s._lastFirstId) {
s._lastFirstId = id;
if (id != items[0].id) {
for (var r = 0; r < s.cols; r++) {
if (s.speed > 0) {
items.unshift(items.pop());
}
else {
items.push(items.shift());
}
}
}
}
for (var i = 0; i < s._itemCount; i++) {
var item = items[i];
if (s._isInit == 1) {
item.sli_id = -1;
}
if (item.sli_id != id) {
if (s.data[id]) {
item._initData(s.data[id] ? id : -1, s.data[id]);
}
item[s.paramXY] = Math.floor(id / s.cols) * s._itemRow;
item[s._disParam] = (id % s.cols) * s._itemCol;
if (s.data[id]) {
item.sli_id = id;
item.visible = true;
}
else {
item.sli_id = -1;
item.visible = false;
}
}
id++;
}
s._isInit = 2;
}
}
return this.call(tween.setPaused, tween, [true]);
};
Tween.prototype.$tick = function (delta) {
if (this.paused) {
return;
ScrollListBase.prototype.updateViewRect = function () {
_super.prototype.updateViewRect.call(this);
var s = this;
if (s.itemWidth && s.itemHeight) {
s._updateViewRect();
}
this.setPosition(this._prevPosition + delta);
};
Tween.NONE = 0;
Tween.LOOP = 1;
Tween.REVERSE = 2;
Tween._tweens = [];
Tween.IGNORE = {};
Tween._plugins = {};
Tween._inited = false;
Tween._lastTime = 0;
return Tween;
}());
var Ease = (function () {
function Ease() {
}
Ease.get = function (amount) {
if (amount < -1) {
amount = -1;
ScrollListBase.prototype._updateViewRect = function () {
var s = this;
if (s._direction === exports.SCROLL_DIRECTION.VERTICAL) {
if (s.itemHeight <= 0) {
return;
}
s._disParam = "x";
s._itemRow = s.itemHeight;
s._itemCol = s.itemWidth;
}
if (amount > 1) {
amount = 1;
else {
if (s.itemWidth <= 0) {
return;
}
s._disParam = "y";
s._itemRow = s.itemWidth;
s._itemCol = s.itemHeight;
}
return function (t) {
if (amount == 0) {
return t;
var newCount = (Math.ceil(s.distance / s._itemRow) + 1) * s.cols;
if (newCount != s._itemCount) {
if (newCount > s._itemCount) {
for (var i = s._itemCount; i < newCount; i++) {
var item = s.createItem();
item.id = -1;
item.data = null;
s._items.push(item);
s.viewPort.addChild(item);
}
}
if (amount < 0) {
return t * (t * -amount + 1 + amount);
else {
for (var i = 0; i < s._itemCount - newCount; i++) {
s.viewPort.removeChild(s._items.pop());
}
}
return t * ((2 - t) * amount + (1 - amount));
};
};
Ease.getPowIn = function (pow) {
return function (t) {
return Math.pow(t, pow);
};
};
Ease.getPowOut = function (pow) {
return function (t) {
return 1 - Math.pow(1 - t, pow);
};
};
Ease.getPowInOut = function (pow) {
return function (t) {
if ((t *= 2) < 1)
return 0.5 * Math.pow(t, pow);
return 1 - 0.5 * Math.abs(Math.pow(2 - t, pow));
};
};
Ease.sineIn = function (t) {
return 1 - Math.cos(t * Math.PI / 2);
};
Ease.sineOut = function (t) {
return Math.sin(t * Math.PI / 2);
};
Ease.sineInOut = function (t) {
return -0.5 * (Math.cos(Math.PI * t) - 1);
};
Ease.getBackIn = function (amount) {
return function (t) {
return t * t * ((amount + 1) * t - amount);
};
};
Ease.getBackOut = function (amount) {
return function (t) {
return (--t * t * ((amount + 1) * t + amount) + 1);
};
};
Ease.getBackInOut = function (amount) {
amount *= 1.525;
return function (t) {
if ((t *= 2) < 1)
return 0.5 * (t * t * ((amount + 1) * t - amount));
return 0.5 * ((t -= 2) * t * ((amount + 1) * t + amount) + 2);
};
};
Ease.circIn = function (t) {
return -(Math.sqrt(1 - t * t) - 1);
};
Ease.circOut = function (t) {
return Math.sqrt(1 - (--t) * t);
};
Ease.circInOut = function (t) {
if ((t *= 2) < 1) {
return -0.5 * (Math.sqrt(1 - t * t) - 1);
s._itemCount = newCount;
s._lastFirstId = -1;
}
return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
};
Ease.bounceIn = function (t) {
return 1 - Ease.bounceOut(1 - t);
ScrollListBase.prototype.createItem = function () {
return new this.itemClass();
};
Ease.bounceOut = function (t) {
if (t < 1 / 2.75) {
return (7.5625 * t * t);
}
else if (t < 2 / 2.75) {
return (7.5625 * (t -= 1.5 / 2.75) * t + 0.75);
ScrollListBase.prototype.setLoading = function (downLoading) {
var s = this;
if (s.downL) {
s.viewPort.removeChild(s.downL);
s.downL = null;
}
else if (t < 2.5 / 2.75) {
return (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375);
if (downLoading) {
s.downL = downLoading;
s.viewPort.addChild(downLoading);
s.downL[s.paramXY] = Math.max(s.distance, s.maxDistance);
}
else {
return (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375);
s.isStop = false;
}
};
Ease.bounceInOut = function (t) {
if (t < 0.5)
return Ease.bounceIn(t * 2) * .5;
return Ease.bounceOut(t * 2 - 1) * 0.5 + 0.5;
};
Ease.getElasticIn = function (amplitude, period) {
var pi2 = Math.PI * 2;
return function (t) {
if (t == 0 || t == 1)
return t;
var s = period / pi2 * Math.asin(1 / amplitude);
return -(amplitude * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * pi2 / period));
};
};
Ease.getElasticOut = function (amplitude, period) {
var pi2 = Math.PI * 2;
return function (t) {
if (t == 0 || t == 1)
return t;
var s = period / pi2 * Math.asin(1 / amplitude);
return (amplitude * Math.pow(2, -10 * t) * Math.sin((t - s) * pi2 / period) + 1);
};
};
Ease.getElasticInOut = function (amplitude, period) {
var pi2 = Math.PI * 2;
return function (t) {
var s = period / pi2 * Math.asin(1 / amplitude);
if ((t *= 2) < 1)
return -0.5 * (amplitude * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * pi2 / period));
return amplitude * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * pi2 / period) * 0.5 + 1;
};
ScrollListBase.prototype.destroy = function () {
var s = this;
s._items = null;
s.itemClass = null;
s.data = null;
s.downL = null;
_super.prototype.destroy.call(this);
};
Ease.quadIn = Ease.getPowIn(2);
Ease.quadOut = Ease.getPowOut(2);
Ease.quadInOut = Ease.getPowInOut(2);
Ease.cubicIn = Ease.getPowIn(3);
Ease.cubicOut = Ease.getPowOut(3);
Ease.cubicInOut = Ease.getPowInOut(3);
Ease.quartIn = Ease.getPowIn(4);
Ease.quartOut = Ease.getPowOut(4);
Ease.quartInOut = Ease.getPowInOut(4);
Ease.quintIn = Ease.getPowIn(5);
Ease.quintOut = Ease.getPowOut(5);
Ease.quintInOut = Ease.getPowInOut(5);
Ease.backIn = Ease.getBackIn(1.7);
Ease.backOut = Ease.getBackOut(1.7);
Ease.backInOut = Ease.getBackInOut(1.7);
Ease.elasticIn = Ease.getElasticIn(1, 0.3);
Ease.elasticOut = Ease.getElasticOut(1, 0.3);
Ease.elasticInOut = Ease.getElasticInOut(1, 0.3 * 1.5);
return Ease;
}());
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "itemWidth", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "itemHeight", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "cols", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], ScrollListBase.prototype, "itemClass", void 0);
return ScrollListBase;
}(ScrollViewBase));
var Node$1 = (function (_super) {
tslib_1.__extends(Node, _super);
......@@ -21747,101 +21769,14 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
};
/**
* Created by rockyl on 2020-01-27.
*/
var genericRegexp = /(\w+)(<(\w+)>)?/;
function compute(props, options) {
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) {
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) {
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) {
var value;
if (props.hasOwnProperty(key)) {
value = props[key];
}
else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
}
var emojiRegexp = emojiRegex();
Object.defineProperty(exports, 'computeProps', {
enumerable: true,
get: function () {
return propsCompute.compute;
}
});
exports.BaseTexture = BaseTexture;
exports.BaseTextureCache = BaseTextureCache;
exports.BitmapText = BitmapText;
......@@ -21917,7 +21852,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.clearTextureCache = clearTextureCache;
exports.cmdOldPrefix = cmdOldPrefix;
exports.cmdPrefix = cmdPrefix;
exports.computeProps = compute;
exports.copyProp = copyProp;
exports.cos = cos;
exports.countTrailingZeros = countTrailingZeros;
......@@ -22033,5 +21967,5 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Object.defineProperty(exports, '__esModule', { value: true });
}));
})));
//# sourceMappingURL=engine.js.map
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -33,7 +33,7 @@ function getPxToken(callback) {
};
xhr.send();
} else {
callback('need login');
callback('need reload');
}
function failedCallback() {
......
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
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 reload");function t(){n("net error")}}
import { DisplayObject } from './DisplayObject';
import { Rectangle } from "../math/Rectangle";
import { Point } from '../math/index';
import {DisplayObject} from './DisplayObject';
import {Rectangle} from "../math/Rectangle";
import {Point} from '../math/index';
import CanvasRenderer from '../renderers/CanvasRenderer';
import { Event } from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer';
import { applyAutoAdjust } from "../../zeroing/decorators/auto-adjust";
import { applyScript } from "../../zeroing/decorators/scripts";
import { applyEvents } from "../../zeroing/decorators/events";
import { afterConstructor } from "../../zeroing/decorators/after-constructor";
import { injectProperties, instantiateScript, toBoolean } from "../../zeroing/utils/index";
import { isUI } from "../../zeroing/game-warpper/nodes/IUIComponent";
import {Event} from "../events/Event"
import {WebglRenderer} from '../renderers/WebglRenderer';
import {applyAutoAdjust} from "../../zeroing/decorators/auto-adjust";
import {applyScript} from "../../zeroing/decorators/scripts";
import {applyEvents} from "../../zeroing/decorators/events";
import {afterConstructor} from "../../zeroing/decorators/after-constructor";
import {injectProperties, instantiateScript, toBoolean} from "../../zeroing/utils/index";
import {isUI} from "../../zeroing/game-warpper/nodes/IUIComponent";
import Transform from "../math/Transform";
/**
......@@ -24,869 +24,869 @@ import Transform from "../math/Transform";
@applyEvents
export default class Container extends DisplayObject {
percentWidth: number;
percentHeight: number;
left: number;
top: number;
right: number;
bottom: number;
horizonCenter: number;
verticalCenter: number;
private _transform: Transform;
private _lastLocalID;
/**
* 为false鼠标事件不再向下传递
*/
_mouseChildren: boolean = true;
/**
* 孩子们
* @member {DisplayObject[]}
* @readonly
*/
children: any[];
/**
* 特殊用处
* 缓存的Container的updateTransform
*/
containerUpdateTransform;
constructor() {
super();
this._instanceType = "Container";
this.children = [];
this._transform = this.transform;
this.afterConstructor();
}
get mouseChildren() {
return this._mouseChildren;
}
set mouseChildren(v) {
this._mouseChildren = v;
}
afterConstructor() {
}
/**
* children改变时
* @private
*/
onChildrenChange(index) {
/* empty */
//子类需要时重写
this.dispatchEvent(Event.MAYBE_ALIGN);
}
attachVisibility() {
return;
this.dispatchEvent(this.worldVisible ? Event.VISIBLE : Event.HIDDEN);
for (let i = 0, li = this.children.length; i < li; i++) {
const child = <Container>this.children[i];
child.attachVisibility();
}
}
/**
* 添加child
* @param {DisplayObject} child
* @return {DisplayObject}
*/
addChild(child: DisplayObject): DisplayObject {
//默认添加在最顶层
this.addChildAt(child, this.children.length);
return child;
}
/**
* 在相应index处添加child
* @param {DisplayObject} child - The child to add
* @param {number} index - The index to place the child in
* @return {DisplayObject} The child that was added.
*/
addChildAt(child: DisplayObject, index: number): DisplayObject {
if (!child) return;
let s = this;
let sameParent = (s == child.parent);
let len: number;
if (child.parent) {
if (!sameParent) {
child.parent.removeChild(child);
} else {
len = s.children.length;
for (let i = 0; i < len; i++) {
if (s.children[i] == child) {
s.children.splice(i, 1);
break;
}
}
}
}
child.parent = s;
//保证child的transform会被更新
child.transform._parentID = -1;
//确保包围盒重新计算
this._boundsID++;
len = s.children.length;
if (index >= len) {
s.children[s.children.length] = child;
index = len;
} else if (index == 0 || index < 0) {
s.children.unshift(child);
index = 0;
} else {
s.children.splice(index, 0, child);
}
if (s.stage && !sameParent) {
// child["_cp"] = true;
child._onDispatchBubbledEvent(Event.ADDED_TO_STAGE);
}
this.onChildrenChange(index);
return child;
}
/**
* 只用于交换索引
* @param {DisplayObject} child - First display object to swap
* @param {DisplayObject} child2 - Second display object to swap
*/
swapChildren(child1: DisplayObject, child2: DisplayObject) {
if (child1 === child2) {
return;
}
let s = this;
let id1 = -1;
let id2 = -1;
let childCount = s.children.length;
if (typeof (child1) == "number") {
id1 = child1;
} else {
id1 = s.getChildIndex(child1);
}
if (typeof (child2) == "number") {
id2 = child2;
} else {
id2 = s.getChildIndex(child2);
}
if (id1 == id2 || id1 < 0 || id1 >= childCount || id2 < 0 || id2 >= childCount) {
return false;
} else {
let temp: any = s.children[id1];
s.children[id1] = s.children[id2];
s.children[id2] = temp;
this.onChildrenChange(id1 < id2 ? id1 : id2);
return true;
}
}
/**
* 获取child的层级索引index
* @param {DisplayObject} child - The DisplayObject instance to identify
* @return {number} The index position of the child display object to identify
*/
getChildIndex(child: DisplayObject): number {
const index = this.children.indexOf(child);
if (index === -1) {
return null
}
return index;
}
/**
* 是否含有child
* @param child
*/
contains(child: DisplayObject): boolean {
return !!this.getChildIndex(child);
}
/**
* 设置child的层级
* @param {DisplayObject} child
* @param {number} index
*/
setChildIndex(child: DisplayObject, index: number) {
this.addChildAt(child, index);
}
/**
* Returns the child at the specified index
* @param {number} index - The index to get the child at
* @return {DisplayObject} The child at the given index, if any.
*/
getChildAt(index: number): DisplayObject {
if (index < 0 || index >= this.children.length) {
return null
}
return this.children[index];
}
/**
* 根据路径获取子节点
* @param path
* @param method
*/
getChildByPath(path: any, method: string): DisplayObject {
if (!path) {
return null;
}
let p = this;
while (path.length > 0) {
let segment = path.shift();
p = p[method](segment);
if (!p) {
break;
}
}
return p;
}
/**
* 根据名称路径获取子节点
* @param path
*/
getChildByNamePath(path: string): DisplayObject {
const pathArr = path.split('/');
return this.getChildByPath(pathArr, 'getChildByName');
}
/**
* 根据索引路径获取子节点
* @param path
*/
getChildByIndexPath(path: string): DisplayObject {
const pathArr = path.split('/').map(seg => parseInt(seg));
return this.getChildByPath(pathArr, 'getChildAt');
}
/**
* 根据uuid搜索子节点
* @param uuid
*/
findChildByUUID(uuid: string) {
if (this['uuid'] === uuid) {
return this;
}
if (this.children && this.children.length > 0) {
for (let child of this.children) {
if (child.findChildByUUID) {
let target = child.findChildByUUID(uuid);
if (target) {
return target;
}
}
}
}
}
/**
* 通过名字获取子级
* @param name
* @param isOnlyOne
* @param isRecursive
*/
public getChildByName(name: string | RegExp, isOnlyOne: boolean = true, isRecursive: boolean = false): any {
if (!name) return null;
let s = this;
let rex: any;
if (typeof (name) == "string") {
rex = new RegExp("^" + name + "$");
} else {
rex = name;
}
let elements: Array<DisplayObject> = [];
Container._getElementsByName(rex, s, isOnlyOne, isRecursive, elements);
let len = elements.length;
if (len == 0) {
return null;
} else if (len == 1) {
return elements[0];
} else {
return elements;
}
}
/**
* 移除child
* @param {DisplayObject} child
* @return {DisplayObject}
*/
removeChild(child: DisplayObject): DisplayObject {
const index = this.children.indexOf(child);
if (index === -1) return null;
this.removeChildAt(index);
return child;
}
/**
* 在index处移除child
* @param {number} index - The index to get the child from
* @return {DisplayObject} The child that was removed.
*/
removeChildAt(index: number): DisplayObject {
let s = this;
let child: any;
let len = s.children.length - 1;
if (len < 0) return;
if (index == len) {
child = s.children.pop();
} else if (index == 0) {
child = s.children.shift();
} else {
child = s.children.splice(index, 1)[0];
}
child._onDispatchBubbledEvent(Event.REMOVED_FROM_STAGE);
//保证子级会被更新
child.parent = null;
child.transform._parentID = -1;
//保证包围盒重新计算
this._boundsID++;
this.onChildrenChange(index);
return child;
}
/**
* 通过索引批量移除child
* @param {number} [beginIndex=0]
* @param {number} [endIndex=this.children.length]
* @returns {DisplayObject[]} List of removed children
*/
removeChildren(beginIndex: number = 0, endIndex: number = this.children.length): DisplayObject[] {
const begin = beginIndex;
const end = typeof endIndex === 'number' ? endIndex : this.children.length;
const range = end - begin;
let removed;
if (range > 0 && range <= end) {
removed = this.children.splice(begin, range);
for (let i = 0; i < removed.length; ++i) {
removed[i].parent = null;
if (removed[i].transform) {
removed[i].transform._parentID = -1;
}
}
this._boundsID++;
this.onChildrenChange(beginIndex);
for (let i = 0; i < removed.length; ++i) {
removed[i]._onDispatchBubbledEvent(Event.REMOVED_FROM_STAGE);
}
return removed;
} else if (range === 0 && this.children.length === 0) {
return [];
}
throw new RangeError('removeChildren: numeric values are outside the acceptable range.');
}
/**
* 更新矩阵
*/
updateTransform() {
//自己先算
super.updateTransform();
//考虑是否要加,
this._boundsID++;
//children遍历计算
for (let i = 0, j = this.children.length; i < j; ++i) {
const child = this.children[i];
if (child.visible) {
child.updateTransform();
}
}
/*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;
}*/
}
/**
* 父类重写
* 都是全局的
*/
calculateBounds() {
if (this._lastBoundsID == this._boundsID) return
this._lastBoundsID = this._boundsID
this._bounds.clear();
//算自己的
this._calculateBounds();
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
if (!child.visible || !child.renderable) {
continue;
}
child.calculateBounds();
if (child.$mask) {
child.$mask.calculateBounds();
//取交集矩形
if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
}
if (child._bounds.width > child.$mask._bounds.width) {
child._bounds.width = child.$mask._bounds.width;
}
if (child._bounds.height > child.$mask._bounds.height) {
child._bounds.height = child.$mask._bounds.height;
}
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
}
}
}
/**
* 加"_"的方法基本是为了自己特殊处理
*/
protected _calculateBounds(): boolean {
//子类自己重写
//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);
return true;
}
return false;
}
/**
* 检测点是否在任何child上
* 重写父类方法
*/
hitTestPoint(globalPoint: Point, isMouseEvent: boolean = false) {
//如果不可见
if (!this.visible) return null
//如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren) {
return this.hitTestSelf(globalPoint);
}
var children = this.children;
var length = children.length;
let child, hitDisplayObject;
//后序遍历,后添加的在上层
for (var i = length - 1; i >= 0; i--) {
child = children[i];
//当作遮罩的不作为检测,跳过
if (child.isUsedToMask) continue;
//有遮罩,但是不在遮罩内,跳过
if (child.mask && !child.mask.hitTestPoint(globalPoint, isMouseEvent)) continue;
//检测
hitDisplayObject = child.hitTestPoint(globalPoint, isMouseEvent);
//存在直接返回
if (hitDisplayObject) return hitDisplayObject;
}
return this.displayObjectHitTestPoint(globalPoint, isMouseEvent);
}
hitTestSelf(globalPoint) {
if (this.mouseEnabled) {
return this.hitTestSelfBounds(globalPoint);
}
return null;
}
hitTestSelfBounds(globalPoint) {
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
}
/**
* webgl渲染
* @param {WebglRenderer} renderer - The renderer
*/
renderWebGL(renderer: WebglRenderer) {
//不可见,全局透明度为0,或者 不渲染,直接return
if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
return;
}
//是否有遮罩。到时如果有滤镜,
if (this.mask) {
this.renderAdvancedWebGL(renderer);
} else {
//自身先渲染
this._renderWebGL(renderer);
//遍历children
for (let i = 0, j = this.children.length; i < j; ++i) {
this.children[i].renderWebGL(renderer);
}
}
}
/**
* 高级渲染方法
*
* @private
* @param {WebGLRenderer} renderer - The renderer
*/
private renderAdvancedWebGL(renderer: WebglRenderer) {
//之前的批处理刷掉先
renderer.batchManager.flush();
//有滤镜再说
const mask = this.mask;
if (mask) {
//先画遮罩
renderer.maskManager.pushMask(this, this.mask);
}
//渲染自身
this._renderWebGL(renderer);
//遍历children
for (let i = 0, j = this.children.length; i < j; i++) {
this.children[i].renderWebGL(renderer);
}
//刷掉批处理
renderer.batchManager.flush();
if (mask) {
//移除遮罩,支持多重遮罩
renderer.maskManager.popMask(this, this.mask);
}
}
/**
* 自身渲染方式
* @private
* @param {WebglRenderer} renderer - The renderer
*/
protected _renderWebGL(renderer: WebglRenderer) {
//自身绘制方法
}
/**
* canvas渲染方式
* @param {CanvasRenderer} renderer - The renderer
*/
renderCanvas(renderer: CanvasRenderer) {
if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
return;
}
if (this.mask) {
renderer.maskManager.pushMask(this.mask);
}
this._renderCanvas(renderer);
for (let i = 0, j = this.children.length; i < j; ++i) {
this.children[i].renderCanvas(renderer);
}
if (this.mask) {
renderer.maskManager.popMask(renderer);
}
}
/**
* 自身渲染方法
*
* @private
* @param {CanvasRenderer} renderer - The renderer
*/
protected _renderCanvas(renderer: CanvasRenderer) {
//自身绘制方法
}
/**
* 更新方法
*/
update(deltaTime: number) {
/*if (!this.visible) return;*/
//更新自己的
super.update(deltaTime)
//更新儿子们的
let len = this.children.length;
for (let i = len - 1; i >= 0; i--) {
const child = this.children[i];
/*if (child.visible)*/
child.update(deltaTime);
}
}
/**
* 调用此方法对自己及其child触发一次指定事件
* @method _onDispatchBubbledEvent
* @public
* @param {string} type
* @since 1.0.0
*/
public _onDispatchBubbledEvent(type: string): void {
let s = this;
let len = s.children.length;
if (type == Event.REMOVED_FROM_STAGE && !s.stage) return;
super._onDispatchBubbledEvent(type);
for (let i = 0; i < len; i++) {
s.children[i]._onDispatchBubbledEvent(type);
}
}
/**
*
*/
destroy() {
let s = this;
//让子级也destroy
for (let i = s.children.length - 1; i >= 0; i--) {
s.children[i].destroy();
}
super.destroy();
this.mouseChildren = false;
}
/**
* 一般用于获取宽高并设置
* 包括子级的,容器的尽量少用,子类可重写
* @member {number}
*/
get width(): number {
let value = this._width;
return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value;
}
set width(value: number) {
// const width = this.getLocalBounds().width;
// if (width !== 0) {
// this.scale.x = value / width;
// } else {
// this.scale.x = 1;
// }
if (this._width !== value) {
if (!value && value != 0) {
this._width = undefined;
} else {
//子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentWidth 或同时设置了 left 和 right 则表示他的宽度是相对的,则对于父级来说它的宽度永远是 0
this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
? 0
: value;
}
}
/**
* 高度同width
* @member {number}
*/
get height(): number {
let value = this._height;
return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value;
}
set height(value: number) {
// const height = this.getLocalBounds().height;
// if (height !== 0) {
// this.scale.y = value / height;
// } else {
// this.scale.y = 1;
// }
if (!value && value != 0) {
this._height = undefined;
} else {
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentHeight 或同时设置了 top 和 bottom 则表示他的高度是相对的,则对于父级来说它的高度永远是 0
this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
? 0
: value;
}
}
protected __width = 0; // 忽略 相对宽度 的 宽度,在父级计算自动宽度的时候用到
protected __height = 0; // 忽略 相对高度 的 高度,在父级计算自动高度的时候用到
get x(): number {
return this.position.x;
}
set x(value: number) {
if(this.destroyed){
return;
}
if (value == this.transform.position.x) return;
this.transform.position.x = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
}
get y(): number {
return this.position.y;
}
set y(value: number) {
if(this.destroyed){
return;
}
if (value == this.transform.position.y) return;
this.transform.position.y = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
}
clone(withEvents = false, withScripts = false) {
let target = this.constructor.apply(Object.create(this.constructor.prototype));
const originConfig = this['__originConfig'];
const {name, properties, events, scripts} = originConfig;
target.name = name;
target['__originConfig'] = originConfig;
injectProperties(target, properties);
if (withScripts) {
if (scripts && scripts.length > 0) {
for (let scriptConfig of scripts) {
instantiateScript(target, scriptConfig);
}
}
}
if (withEvents) {
if (events) {
target.eventsProxy.start(events);
}
}
for (let child of this.children) {
let childCopy = child.clone(withEvents, withScripts);
target.addChild(childCopy);
}
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
* @param {RegExp} rex
* @param {Container} root
* @param {boolean} isOnlyOne
* @param {boolean} isRecursive
* @param {Array<DisplayObject>} resultList
* @private
* @static
*/
private static _getElementsByName(rex: RegExp, root: Container, isOnlyOne: boolean, isRecursive: boolean, resultList: Array<DisplayObject>): void {
let len = root.children.length;
if (len > 0) {
let name: string;
let child: any;
for (let i = 0; i < len; i++) {
child = root.children[i];
name = child.name;
if (name && name != "") {
if (rex.test(name)) {
resultList[resultList.length] = child;
if (isOnlyOne) {
return;
}
}
}
if (isRecursive) {
if (child["children"] != null) {
Container._getElementsByName(rex, child, isOnlyOne, isRecursive, resultList);
}
}
}
}
}
percentWidth: number;
percentHeight: number;
left: number;
top: number;
right: number;
bottom: number;
horizonCenter: number;
verticalCenter: number;
private _transform: Transform;
private _lastLocalID;
/**
* 为false鼠标事件不再向下传递
*/
_mouseChildren: boolean = true;
/**
* 孩子们
* @member {DisplayObject[]}
* @readonly
*/
children: any[];
/**
* 特殊用处
* 缓存的Container的updateTransform
*/
containerUpdateTransform;
constructor() {
super();
this._instanceType = "Container";
this.children = [];
this._transform = this.transform;
this.afterConstructor();
}
get mouseChildren() {
return this._mouseChildren;
}
set mouseChildren(v) {
this._mouseChildren = v;
}
afterConstructor() {
}
/**
* children改变时
* @private
*/
onChildrenChange(index) {
/* empty */
//子类需要时重写
this.dispatchEvent(Event.MAYBE_ALIGN);
}
attachVisibility() {
return;
this.dispatchEvent(this.worldVisible ? Event.VISIBLE : Event.HIDDEN);
for (let i = 0, li = this.children.length; i < li; i++) {
const child = <Container>this.children[i];
child.attachVisibility();
}
}
/**
* 添加child
* @param {DisplayObject} child
* @return {DisplayObject}
*/
addChild(child: DisplayObject): DisplayObject {
//默认添加在最顶层
this.addChildAt(child, this.children.length);
return child;
}
/**
* 在相应index处添加child
* @param {DisplayObject} child - The child to add
* @param {number} index - The index to place the child in
* @return {DisplayObject} The child that was added.
*/
addChildAt(child: DisplayObject, index: number): DisplayObject {
if (!child) return;
let s = this;
let sameParent = (s == child.parent);
let len: number;
if (child.parent) {
if (!sameParent) {
child.parent.removeChild(child);
} else {
len = s.children.length;
for (let i = 0; i < len; i++) {
if (s.children[i] == child) {
s.children.splice(i, 1);
break;
}
}
}
}
child.parent = s;
//保证child的transform会被更新
child.transform._parentID = -1;
//确保包围盒重新计算
this._boundsID++;
len = s.children.length;
if (index >= len) {
s.children[s.children.length] = child;
index = len;
} else if (index == 0 || index < 0) {
s.children.unshift(child);
index = 0;
} else {
s.children.splice(index, 0, child);
}
if (s.stage && !sameParent) {
// child["_cp"] = true;
child._onDispatchBubbledEvent(Event.ADDED_TO_STAGE);
}
this.onChildrenChange(index);
return child;
}
/**
* 只用于交换索引
* @param {DisplayObject} child - First display object to swap
* @param {DisplayObject} child2 - Second display object to swap
*/
swapChildren(child1: DisplayObject, child2: DisplayObject) {
if (child1 === child2) {
return;
}
let s = this;
let id1 = -1;
let id2 = -1;
let childCount = s.children.length;
if (typeof (child1) == "number") {
id1 = child1;
} else {
id1 = s.getChildIndex(child1);
}
if (typeof (child2) == "number") {
id2 = child2;
} else {
id2 = s.getChildIndex(child2);
}
if (id1 == id2 || id1 < 0 || id1 >= childCount || id2 < 0 || id2 >= childCount) {
return false;
} else {
let temp: any = s.children[id1];
s.children[id1] = s.children[id2];
s.children[id2] = temp;
this.onChildrenChange(id1 < id2 ? id1 : id2);
return true;
}
}
/**
* 获取child的层级索引index
* @param {DisplayObject} child - The DisplayObject instance to identify
* @return {number} The index position of the child display object to identify
*/
getChildIndex(child: DisplayObject): number {
const index = this.children.indexOf(child);
if (index === -1) {
return null
}
return index;
}
/**
* 是否含有child
* @param child
*/
contains(child: DisplayObject): boolean {
return !!this.getChildIndex(child);
}
/**
* 设置child的层级
* @param {DisplayObject} child
* @param {number} index
*/
setChildIndex(child: DisplayObject, index: number) {
this.addChildAt(child, index);
}
/**
* Returns the child at the specified index
* @param {number} index - The index to get the child at
* @return {DisplayObject} The child at the given index, if any.
*/
getChildAt(index: number): DisplayObject {
if (index < 0 || index >= this.children.length) {
return null
}
return this.children[index];
}
/**
* 根据路径获取子节点
* @param path
* @param method
*/
getChildByPath(path: any, method: string): DisplayObject {
if (!path) {
return null;
}
let p = this;
while (path.length > 0) {
let segment = path.shift();
p = p[method](segment);
if (!p) {
break;
}
}
return p;
}
/**
* 根据名称路径获取子节点
* @param path
*/
getChildByNamePath(path: string): DisplayObject {
const pathArr = path.split('/');
return this.getChildByPath(pathArr, 'getChildByName');
}
/**
* 根据索引路径获取子节点
* @param path
*/
getChildByIndexPath(path: string): DisplayObject {
const pathArr = path.split('/').map(seg => parseInt(seg));
return this.getChildByPath(pathArr, 'getChildAt');
}
/**
* 根据uuid搜索子节点
* @param uuid
*/
findChildByUUID(uuid: string) {
if (this['uuid'] === uuid) {
return this;
}
if (this.children && this.children.length > 0) {
for (let child of this.children) {
if (child.findChildByUUID) {
let target = child.findChildByUUID(uuid);
if (target) {
return target;
}
}
}
}
}
/**
* 通过名字获取子级
* @param name
* @param isOnlyOne
* @param isRecursive
*/
public getChildByName(name: string | RegExp, isOnlyOne: boolean = true, isRecursive: boolean = false): any {
if (!name) return null;
let s = this;
let rex: any;
if (typeof (name) == "string") {
rex = new RegExp("^" + name + "$");
} else {
rex = name;
}
let elements: Array<DisplayObject> = [];
Container._getElementsByName(rex, s, isOnlyOne, isRecursive, elements);
let len = elements.length;
if (len == 0) {
return null;
} else if (len == 1) {
return elements[0];
} else {
return elements;
}
}
/**
* 移除child
* @param {DisplayObject} child
* @return {DisplayObject}
*/
removeChild(child: DisplayObject): DisplayObject {
const index = this.children.indexOf(child);
if (index === -1) return null;
this.removeChildAt(index);
return child;
}
/**
* 在index处移除child
* @param {number} index - The index to get the child from
* @return {DisplayObject} The child that was removed.
*/
removeChildAt(index: number): DisplayObject {
let s = this;
let child: any;
let len = s.children.length - 1;
if (len < 0) return;
if (index == len) {
child = s.children.pop();
} else if (index == 0) {
child = s.children.shift();
} else {
child = s.children.splice(index, 1)[0];
}
child._onDispatchBubbledEvent(Event.REMOVED_FROM_STAGE);
//保证子级会被更新
child.parent = null;
child.transform._parentID = -1;
//保证包围盒重新计算
this._boundsID++;
this.onChildrenChange(index);
return child;
}
/**
* 通过索引批量移除child
* @param {number} [beginIndex=0]
* @param {number} [endIndex=this.children.length]
* @returns {DisplayObject[]} List of removed children
*/
removeChildren(beginIndex: number = 0, endIndex: number = this.children.length): DisplayObject[] {
const begin = beginIndex;
const end = typeof endIndex === 'number' ? endIndex : this.children.length;
const range = end - begin;
let removed;
if (range > 0 && range <= end) {
removed = this.children.splice(begin, range);
for (let i = 0; i < removed.length; ++i) {
removed[i].parent = null;
if (removed[i].transform) {
removed[i].transform._parentID = -1;
}
}
this._boundsID++;
this.onChildrenChange(beginIndex);
for (let i = 0; i < removed.length; ++i) {
removed[i]._onDispatchBubbledEvent(Event.REMOVED_FROM_STAGE);
}
return removed;
} else if (range === 0 && this.children.length === 0) {
return [];
}
throw new RangeError('removeChildren: numeric values are outside the acceptable range.');
}
/**
* 更新矩阵
*/
updateTransform() {
//自己先算
super.updateTransform();
//考虑是否要加,
this._boundsID++;
//children遍历计算
for (let i = 0, j = this.children.length; i < j; ++i) {
const child = this.children[i];
if (child.visible) {
child.updateTransform();
}
}
/*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;
}*/
}
/**
* 父类重写
* 都是全局的
*/
calculateBounds() {
if (this._lastBoundsID == this._boundsID) return
this._lastBoundsID = this._boundsID
this._bounds.clear();
//算自己的
this._calculateBounds();
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
if (!child.visible || !child.renderable) {
continue;
}
child.calculateBounds();
if (child.$mask) {
child.$mask.calculateBounds();
//取交集矩形
if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
}
if (child._bounds.width > child.$mask._bounds.width) {
child._bounds.width = child.$mask._bounds.width;
}
if (child._bounds.height > child.$mask._bounds.height) {
child._bounds.height = child.$mask._bounds.height;
}
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
}
}
}
/**
* 加"_"的方法基本是为了自己特殊处理
*/
protected _calculateBounds(): boolean {
//子类自己重写
//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);
return true;
}
return false;
}
/**
* 检测点是否在任何child上
* 重写父类方法
*/
hitTestPoint(globalPoint: Point, isMouseEvent: boolean = false) {
//如果不可见
if (!this.visible) return null
//如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren) {
return this.hitTestSelf(globalPoint);
}
var children = this.children;
var length = children.length;
let child, hitDisplayObject;
//后序遍历,后添加的在上层
for (var i = length - 1; i >= 0; i--) {
child = children[i];
//当作遮罩的不作为检测,跳过
if (child.isUsedToMask) continue;
//有遮罩,但是不在遮罩内,跳过
if (child.mask && !child.mask.hitTestPoint(globalPoint, isMouseEvent)) continue;
//检测
hitDisplayObject = child.hitTestPoint(globalPoint, isMouseEvent);
//存在直接返回
if (hitDisplayObject) return hitDisplayObject;
}
return this.displayObjectHitTestPoint(globalPoint, isMouseEvent);
}
hitTestSelf(globalPoint) {
if (this.mouseEnabled) {
return this.hitTestSelfBounds(globalPoint);
}
return null;
}
hitTestSelfBounds(globalPoint) {
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
}
/**
* webgl渲染
* @param {WebglRenderer} renderer - The renderer
*/
renderWebGL(renderer: WebglRenderer) {
//不可见,全局透明度为0,或者 不渲染,直接return
if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
return;
}
//是否有遮罩。到时如果有滤镜,
if (this.mask) {
this.renderAdvancedWebGL(renderer);
} else {
//自身先渲染
this._renderWebGL(renderer);
//遍历children
for (let i = 0, j = this.children.length; i < j; ++i) {
this.children[i].renderWebGL(renderer);
}
}
}
/**
* 高级渲染方法
*
* @private
* @param {WebGLRenderer} renderer - The renderer
*/
private renderAdvancedWebGL(renderer: WebglRenderer) {
//之前的批处理刷掉先
renderer.batchManager.flush();
//有滤镜再说
const mask = this.mask;
if (mask) {
//先画遮罩
renderer.maskManager.pushMask(this, this.mask);
}
//渲染自身
this._renderWebGL(renderer);
//遍历children
for (let i = 0, j = this.children.length; i < j; i++) {
this.children[i].renderWebGL(renderer);
}
//刷掉批处理
renderer.batchManager.flush();
if (mask) {
//移除遮罩,支持多重遮罩
renderer.maskManager.popMask(this, this.mask);
}
}
/**
* 自身渲染方式
* @private
* @param {WebglRenderer} renderer - The renderer
*/
protected _renderWebGL(renderer: WebglRenderer) {
//自身绘制方法
}
/**
* canvas渲染方式
* @param {CanvasRenderer} renderer - The renderer
*/
renderCanvas(renderer: CanvasRenderer) {
if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
return;
}
if (this.mask) {
renderer.maskManager.pushMask(this.mask);
}
this._renderCanvas(renderer);
for (let i = 0, j = this.children.length; i < j; ++i) {
this.children[i].renderCanvas(renderer);
}
if (this.mask) {
renderer.maskManager.popMask(renderer);
}
}
/**
* 自身渲染方法
*
* @private
* @param {CanvasRenderer} renderer - The renderer
*/
protected _renderCanvas(renderer: CanvasRenderer) {
//自身绘制方法
}
/**
* 更新方法
*/
update(deltaTime: number) {
/*if (!this.visible) return;*/
//更新自己的
super.update(deltaTime)
//更新儿子们的
let len = this.children.length;
for (let i = len - 1; i >= 0; i--) {
const child = this.children[i];
/*if (child.visible)*/
child.update(deltaTime);
}
}
/**
* 调用此方法对自己及其child触发一次指定事件
* @method _onDispatchBubbledEvent
* @public
* @param {string} type
* @since 1.0.0
*/
public _onDispatchBubbledEvent(type: string): void {
let s = this;
let len = s.children.length;
if (type == Event.REMOVED_FROM_STAGE && !s.stage) return;
super._onDispatchBubbledEvent(type);
for (let i = 0; i < len; i++) {
s.children[i]._onDispatchBubbledEvent(type);
}
}
/**
*
*/
destroy() {
let s = this;
//让子级也destroy
for (let i = s.children.length - 1; i >= 0; i--) {
s.children[i].destroy();
}
super.destroy();
this.mouseChildren = false;
}
/**
* 一般用于获取宽高并设置
* 包括子级的,容器的尽量少用,子类可重写
* @member {number}
*/
get width(): number {
let value = this._width;
return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value;
}
set width(value: number) {
// const width = this.getLocalBounds().width;
// if (width !== 0) {
// this.scale.x = value / width;
// } else {
// this.scale.x = 1;
// }
if (this._width !== value) {
if (!value && value != 0) {
this._width = undefined;
} else {
//子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentWidth 或同时设置了 left 和 right 则表示他的宽度是相对的,则对于父级来说它的宽度永远是 0
this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
? 0
: value;
}
}
/**
* 高度同width
* @member {number}
*/
get height(): number {
let value = this._height;
return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value;
}
set height(value: number) {
// const height = this.getLocalBounds().height;
// if (height !== 0) {
// this.scale.y = value / height;
// } else {
// this.scale.y = 1;
// }
if (!value && value != 0) {
this._height = undefined;
} else {
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentHeight 或同时设置了 top 和 bottom 则表示他的高度是相对的,则对于父级来说它的高度永远是 0
this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
? 0
: value;
}
}
protected __width = 0; // 忽略 相对宽度 的 宽度,在父级计算自动宽度的时候用到
protected __height = 0; // 忽略 相对高度 的 高度,在父级计算自动高度的时候用到
get x(): number {
return this.position.x;
}
set x(value: number) {
if (this.destroyed) {
return;
}
if (value == this.transform.position.x) return;
this.transform.position.x = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
}
get y(): number {
return this.position.y;
}
set y(value: number) {
if (this.destroyed) {
return;
}
if (value == this.transform.position.y) return;
this.transform.position.y = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
}
clone(withEvents = false, withScripts = false) {
let target = this.constructor.apply(Object.create(this.constructor.prototype));
const originConfig = this['__originConfig'];
const {name, properties, events, scripts} = originConfig;
target.name = name;
target['__originConfig'] = originConfig;
injectProperties(target, properties);
if (withScripts) {
if (scripts && scripts.length > 0) {
for (let scriptConfig of scripts) {
instantiateScript(target, scriptConfig);
}
}
}
if (withEvents) {
if (events) {
target.eventsProxy.start(events);
}
}
for (let child of this.children) {
let childCopy = child.clone(withEvents, withScripts);
target.addChild(childCopy);
}
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
* @param {RegExp} rex
* @param {Container} root
* @param {boolean} isOnlyOne
* @param {boolean} isRecursive
* @param {Array<DisplayObject>} resultList
* @private
* @static
*/
private static _getElementsByName(rex: RegExp, root: Container, isOnlyOne: boolean, isRecursive: boolean, resultList: Array<DisplayObject>): void {
let len = root.children.length;
if (len > 0) {
let name: string;
let child: any;
for (let i = 0; i < len; i++) {
child = root.children[i];
name = child.name;
if (name && name != "") {
if (rex.test(name)) {
resultList[resultList.length] = child;
if (isOnlyOne) {
return;
}
}
}
if (isRecursive) {
if (child["children"] != null) {
Container._getElementsByName(rex, child, isOnlyOne, isRecursive, resultList);
}
}
}
}
}
}
Container.prototype.containerUpdateTransform = Container.prototype.updateTransform;
......@@ -40,6 +40,11 @@ export class FloatDisplay extends DisplayObject {
*/
private _transformID: number;
/**
* 记录是否需要修改位置矩阵
*/
private _shouldUpdateStyle: boolean;
/**
* 构造函数
* @method FloatDisplay
......@@ -89,13 +94,9 @@ export class FloatDisplay extends DisplayObject {
this._transformID = -1;
}
addHtmlElement() {
addHtmlElement(el?) {
let s = this;
if(!s.stage){
return;
}
if (!container) {
container = document.createElement('div');
container.style.position = "absolute";
......@@ -105,16 +106,26 @@ export class FloatDisplay extends DisplayObject {
container.style.lineHeight = 'normal';
s.stage.rootDiv.appendChild(container);//, s.stage.rootDiv.childNodes[0]
}
if (s._htmlElement) {
let 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";
}
try {
container.removeChild(s._htmlElement);
}catch (e){
}
}
if(el){
s._htmlElement = el;
}
container.appendChild(s._htmlElement);
if (!s._isAdded) {
s._isAdded = true;
s.stage["_floatDisplayList"].push(s);
} else {
if (s._htmlElement && s.visible) {
let style = s._htmlElement.style;
style.display = "block";
}
}
}
......@@ -124,6 +135,7 @@ export class FloatDisplay extends DisplayObject {
}
set htmlElement(v) {
this._shouldUpdateStyle = true;
this.init(v);
this.updateStyle();
}
......@@ -169,9 +181,13 @@ export class FloatDisplay extends DisplayObject {
// s._bounds.height = h;
s._localBoundsSelf.width = w;
s._localBoundsSelf.height = h;
s._htmlElement = she;
this.addHtmlElement();
if (!s.stage) {
s._htmlElement = she;
return;
}
this.addHtmlElement(she);
}
/**
......@@ -227,7 +243,8 @@ export class FloatDisplay extends DisplayObject {
style.display = show;
}
if (visible) {
if (this._transformID != this.transform._worldID) {
if (this._shouldUpdateStyle || this._transformID != this.transform._worldID) {
this._shouldUpdateStyle = false;
this._transformID = this.transform._worldID
let mtx = s.transform.worldMatrix;
let d = devicePixelRatio;
......
......@@ -19,7 +19,6 @@ class AlignManager {
* flash (渲染前)
*/
public flush() {
const list = this.alignList;
list.forEach((v: Container) => {
......
......@@ -134,11 +134,11 @@ export class GameStage extends Node {
await this.loadPreloadAssets(onPreloadAssetsProgress, onPreloadAssetsComplete);
this.start();
dealPxEnv();
dealPageRemainTime();
this.start();
onStart && onStart();
setTimeout(this.lazyLoadAllAssets,
......
......@@ -224,8 +224,6 @@ export class TextInput extends Label implements IUIComponent {
this.fillColor = this._oldFillColor;
this.strokeColor = this._oldStrokeColor;
this.dispatchEvent(Event.BLUR);
}
private onFocus = (e) => {
......@@ -235,6 +233,8 @@ export class TextInput extends Label implements IUIComponent {
private onBlur = (e) => {
this.setBlur();
this.dispatchEvent(Event.BLUR);
delayScrollTop();
};
......
......@@ -4,20 +4,21 @@
const storeKey = 'zlog-switch';
export enum Logs{
export enum Logs {
PROCESS = 'process',
}
let store;
try {
store = JSON.parse(localStorage.getItem(storeKey));
let t = localStorage.getItem(storeKey);
store = t ? JSON.parse(t) : null;
store = store === null ? false : store;
} catch (e) {
store = false;
localStorage.setItem(storeKey, JSON.stringify(store));
}
export function getLogSwitch(id):boolean | Array {
export function getLogSwitch(id): boolean | Array {
return typeof store === 'object' ? store[id] : !!store;
}
......@@ -2,9 +2,8 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/dist" />
</content>
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
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