stage-js
Version:
2D HTML5 Rendering and Layout
1 lines • 214 kB
Source Map (JSON)
{"version":3,"file":"stage.umd.cjs","sources":["../src/common/math.ts","../src/common/matrix.ts","../node_modules/tslib/tslib.es6.js","../src/common/is.ts","../src/common/stats.ts","../src/common/uid.ts","../src/texture/texture.ts","../src/texture/image.ts","../src/texture/pipe.ts","../src/texture/atlas.ts","../src/texture/selection.ts","../src/texture/resizable.ts","../src/common/browser.ts","../src/core/pin.ts","../src/core/easing.ts","../src/core/transition.ts","../src/core/component.ts","../src/core/sprite.ts","../src/texture/canvas.ts","../src/core/pointer.ts","../src/core/root.ts","../src/core/anim.ts","../src/core/monotype.ts"],"sourcesContent":["/** @internal */ const math_random = Math.random;\n/** @internal */ const math_sqrt = Math.sqrt;\n\n/** @internal */\nexport function random(min?: number, max?: number): number {\n if (typeof min === \"undefined\") {\n max = 1;\n min = 0;\n } else if (typeof max === \"undefined\") {\n max = min;\n min = 0;\n }\n return min == max ? min : math_random() * (max - min) + min;\n}\n\n/** @internal */\nexport function wrap(num: number, min?: number, max?: number): number {\n if (typeof min === \"undefined\") {\n max = 1;\n min = 0;\n } else if (typeof max === \"undefined\") {\n max = min;\n min = 0;\n }\n if (max > min) {\n num = (num - min) % (max - min);\n return num + (num < 0 ? max : min);\n } else {\n num = (num - max) % (min - max);\n return num + (num <= 0 ? min : max);\n }\n}\n\n/** @internal */\nexport function clamp(num: number, min: number, max: number): number {\n if (num < min) {\n return min;\n } else if (num > max) {\n return max;\n } else {\n return num;\n }\n}\n\n/** @internal */\nexport function length(x: number, y: number): number {\n return math_sqrt(x * x + y * y);\n}\n\nexport const math = Object.create(Math);\n\nmath.random = random;\nmath.wrap = wrap;\nmath.clamp = clamp;\nmath.length = length;\n\n/** @hidden @deprecated @internal */\nmath.rotate = wrap;\n/** @hidden @deprecated @internal */\nmath.limit = clamp;\n","export interface MatrixValue {\n a: number;\n b: number;\n c: number;\n d: number;\n e: number;\n f: number;\n}\n\nexport interface Vec2Value {\n x: number;\n y: number;\n}\n\nexport class Matrix {\n /** x-scale */\n a = 1;\n b = 0;\n c = 0;\n /** y-scale */\n d = 1;\n /** x-translate */\n e = 0;\n /** y-translate */\n f = 0;\n\n /** @internal */ private _dirty: boolean;\n /** @internal */ private inverted?: Matrix;\n\n constructor(a: number, b: number, c: number, d: number, e: number, f: number);\n constructor(m: MatrixValue);\n constructor();\n constructor(\n a?: number | MatrixValue,\n b?: number,\n c?: number,\n d?: number,\n e?: number,\n f?: number,\n ) {\n if (typeof a === \"object\") {\n this.reset(a);\n } else {\n this.reset(a, b, c, d, e, f);\n }\n }\n\n toString() {\n return (\n \"[\" +\n this.a +\n \", \" +\n this.b +\n \", \" +\n this.c +\n \", \" +\n this.d +\n \", \" +\n this.e +\n \", \" +\n this.f +\n \"]\"\n );\n }\n\n clone() {\n return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);\n }\n\n reset(a: number, b: number, c: number, d: number, e: number, f: number): this;\n reset(m: MatrixValue): this;\n reset(\n a?: number | MatrixValue,\n b?: number,\n c?: number,\n d?: number,\n e?: number,\n f?: number,\n ): this {\n this._dirty = true;\n if (typeof a === \"object\") {\n this.a = a.a;\n this.d = a.d;\n this.b = a.b;\n this.c = a.c;\n this.e = a.e;\n this.f = a.f;\n } else {\n this.a = typeof a === \"number\" ? a : 1;\n this.b = typeof b === \"number\" ? b : 0;\n this.c = typeof c === \"number\" ? c : 0;\n this.d = typeof d === \"number\" ? d : 1;\n this.e = typeof e === \"number\" ? e : 0;\n this.f = typeof f === \"number\" ? f : 0;\n }\n return this;\n }\n\n identity() {\n this._dirty = true;\n this.a = 1;\n this.b = 0;\n this.c = 0;\n this.d = 1;\n this.e = 0;\n this.f = 0;\n return this;\n }\n\n rotate(angle: number) {\n if (!angle) {\n return this;\n }\n\n this._dirty = true;\n\n const u = angle ? Math.cos(angle) : 1;\n // android bug may give bad 0 values\n const v = angle ? Math.sin(angle) : 0;\n\n const a = u * this.a - v * this.b;\n const b = u * this.b + v * this.a;\n const c = u * this.c - v * this.d;\n const d = u * this.d + v * this.c;\n const e = u * this.e - v * this.f;\n const f = u * this.f + v * this.e;\n\n this.a = a;\n this.b = b;\n this.c = c;\n this.d = d;\n this.e = e;\n this.f = f;\n\n return this;\n }\n\n translate(x: number, y: number) {\n if (!x && !y) {\n return this;\n }\n this._dirty = true;\n this.e += x;\n this.f += y;\n return this;\n }\n\n scale(x: number, y: number) {\n if (!(x - 1) && !(y - 1)) {\n return this;\n }\n this._dirty = true;\n this.a *= x;\n this.b *= y;\n this.c *= x;\n this.d *= y;\n this.e *= x;\n this.f *= y;\n return this;\n }\n\n skew(x: number, y: number) {\n if (!x && !y) {\n return this;\n }\n this._dirty = true;\n\n const a = this.a + this.b * x;\n const b = this.b + this.a * y;\n const c = this.c + this.d * x;\n const d = this.d + this.c * y;\n const e = this.e + this.f * x;\n const f = this.f + this.e * y;\n\n this.a = a;\n this.b = b;\n this.c = c;\n this.d = d;\n this.e = e;\n this.f = f;\n return this;\n }\n\n concat(m: MatrixValue) {\n this._dirty = true;\n\n const a = this.a * m.a + this.b * m.c;\n const b = this.b * m.d + this.a * m.b;\n const c = this.c * m.a + this.d * m.c;\n const d = this.d * m.d + this.c * m.b;\n const e = this.e * m.a + m.e + this.f * m.c;\n const f = this.f * m.d + m.f + this.e * m.b;\n\n this.a = a;\n this.b = b;\n this.c = c;\n this.d = d;\n this.e = e;\n this.f = f;\n\n return this;\n }\n\n inverse() {\n if (this._dirty) {\n this._dirty = false;\n if (!this.inverted) {\n this.inverted = new Matrix();\n // todo: link-back the inverted matrix\n // todo: should the inverted be editable or readonly?\n }\n const z = this.a * this.d - this.b * this.c;\n this.inverted.a = this.d / z;\n this.inverted.b = -this.b / z;\n this.inverted.c = -this.c / z;\n this.inverted.d = this.a / z;\n this.inverted.e = (this.c * this.f - this.e * this.d) / z;\n this.inverted.f = (this.e * this.b - this.a * this.f) / z;\n }\n return this.inverted;\n }\n\n map(p: Vec2Value, q?: Vec2Value) {\n q = q || { x: 0, y: 0 };\n q.x = this.a * p.x + this.c * p.y + this.e;\n q.y = this.b * p.x + this.d * p.y + this.f;\n return q;\n }\n\n mapX(x: number | Vec2Value, y?: number) {\n if (typeof x === \"object\") {\n y = x.y;\n x = x.x;\n }\n return this.a * x + this.c * y + this.e;\n }\n\n mapY(x: number | Vec2Value, y?: number) {\n if (typeof x === \"object\") {\n y = x.y;\n x = x.x;\n }\n return this.b * x + this.d * y + this.f;\n }\n}\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __createBinding(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n 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); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n 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; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n 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);\r\n 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); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","/** @internal */\nconst objectToString = Object.prototype.toString;\n\n/** @internal */\nexport function isFn(value: any) {\n const str = objectToString.call(value);\n return (\n str === \"[object Function]\" ||\n str === \"[object GeneratorFunction]\" ||\n str === \"[object AsyncFunction]\"\n );\n}\n\n/** @internal */\nexport function isHash(value: any) {\n return objectToString.call(value) === \"[object Object]\" && value.constructor === Object;\n // return value && typeof value === 'object' && !Array.isArray(value) && !isFn(value);\n}\n","/** @hidden */\nexport default {\n create: 0,\n tick: 0,\n component: 0,\n draw: 0,\n fps: 0,\n};\n","/** @internal */\nexport const uid = function () {\n return Date.now().toString(36) + Math.random().toString(36).slice(2);\n};\n","import { uid } from \"../common/uid\";\n\n/** @internal */\nexport interface TexturePrerenderContext {\n pixelRatio: number;\n}\n\n// todo: unify 9-patch and padding?\n// todo: prerender is used to get texture width and height, replace it with a function to only get width and height\n\n// todo: add reusable shape textures\n\n/**\n * Textures are used to clip and resize image objects.\n */\nexport abstract class Texture {\n /** @internal */ uid = \"texture:\" + uid();\n\n /** @hidden */ sx = 0;\n /** @hidden */ sy = 0;\n /** @hidden */ sw: number;\n /** @hidden */ sh: number;\n /** @hidden */ dx = 0;\n /** @hidden */ dy = 0;\n /** @hidden */ dw: number;\n /** @hidden */ dh: number;\n\n // 9-patch resizing specification\n // todo: rename to something more descriptive\n /** @internal */ top: number;\n /** @internal */ bottom: number;\n /** @internal */ left: number;\n /** @internal */ right: number;\n\n // Geometrical values\n setSourceCoordinate(x: number, y: number) {\n this.sx = x;\n this.sy = y;\n }\n\n // Geometrical values\n setSourceDimension(w: number, h: number) {\n this.sw = w;\n this.sh = h;\n }\n\n // Geometrical values\n setDestinationCoordinate(x: number, y: number) {\n this.dx = x;\n this.dy = y;\n }\n\n // Geometrical values\n setDestinationDimension(w: number, h: number) {\n this.dw = w;\n this.dh = h;\n }\n\n abstract getWidth(): number;\n\n abstract getHeight(): number;\n\n /**\n * @internal\n * This is used by subclasses, such as CanvasTexture, to rerender offscreen texture if needed.\n */\n abstract prerender(context: TexturePrerenderContext): boolean;\n\n /**\n * Defer draw spec to texture config. This is used when a sprite draws its textures.\n */\n draw(context: CanvasRenderingContext2D): void;\n /**\n * This is probably unused.\n * Note: dx, dy are added to this.dx, this.dy.\n */\n draw(context: CanvasRenderingContext2D, dx: number, dy: number, dw: number, dh: number): void;\n /**\n * This is used when a piped texture passes drawing to it backend.\n * Note: sx, sy, dx, dy are added to this.sx, this.sy, this.dx, this.dy.\n */\n draw(\n context: CanvasRenderingContext2D,\n sx: number,\n sy: number,\n sw: number,\n sh: number,\n dx: number,\n dy: number,\n dw: number,\n dh: number,\n ): void;\n draw(\n context: CanvasRenderingContext2D,\n x1?: number,\n y1?: number,\n w1?: number,\n h1?: number,\n x2?: number,\n y2?: number,\n w2?: number,\n h2?: number,\n ): void {\n let sx: number, sy: number, sw: number, sh: number;\n let dx: number, dy: number, dw: number, dh: number;\n\n if (arguments.length > 5) {\n // two sets of [x, y, w, h] arguments\n sx = this.sx + x1;\n sy = this.sy + y1;\n sw = w1 ?? this.sw;\n sh = h1 ?? this.sh;\n\n dx = this.dx + x2;\n dy = this.dy + y2;\n dw = w2 ?? this.dw;\n dh = h2 ?? this.dh;\n } else if(arguments.length > 1) {\n // one set of [x, y, w, h] arguments\n sx = this.sx;\n sy = this.sy;\n sw = this.sw;\n sh = this.sh;\n\n dx = this.dx + x1;\n dy = this.dy + y1;\n dw = w1 ?? this.dw;\n dh = h1 ?? this.dh;\n } else {\n // no additional arguments\n sx = this.sx;\n sy = this.sy;\n sw = this.sw;\n sh = this.sh;\n\n dx = this.dx;\n dy = this.dy;\n dw = this.dw;\n dh = this.dh;\n }\n\n this.drawWithNormalizedArgs(context, sx, sy, sw, sh, dx, dy, dw, dh);\n }\n\n /** @internal */\n abstract drawWithNormalizedArgs(\n context: CanvasRenderingContext2D,\n sx: number,\n sy: number,\n sw: number,\n sh: number,\n dx: number,\n dy: number,\n dw: number,\n dh: number,\n ): void;\n}\n","import stats from \"../common/stats\";\nimport { clamp } from \"../common/math\";\n\nimport { Texture, TexturePrerenderContext } from \"./texture\";\n\ntype TextureImageSource =\n | HTMLImageElement\n | HTMLVideoElement\n | HTMLCanvasElement\n | ImageBitmap\n | OffscreenCanvas;\n\nexport class ImageTexture extends Texture {\n /** @internal */ _source: TextureImageSource;\n\n /** @internal */ _pixelRatio = 1;\n\n /** @internal */ _draw_failed: boolean;\n\n /** @internal */\n private padding = 0;\n\n constructor(source?: TextureImageSource, pixelRatio?: number) {\n super();\n if (typeof source === \"object\") {\n this.setSourceImage(source, pixelRatio);\n }\n }\n\n setSourceImage(image: TextureImageSource, pixelRatio = 1) {\n this._source = image;\n this._pixelRatio = pixelRatio;\n }\n\n /**\n * Add padding to the image texture. Padding can be negative.\n */\n setPadding(padding: number): void {\n this.padding = padding;\n }\n\n getWidth(): number {\n return this._source.width / this._pixelRatio + (this.padding + this.padding);\n }\n\n getHeight(): number {\n return this._source.height / this._pixelRatio + (this.padding + this.padding);\n }\n\n /** @internal */\n prerender(context: TexturePrerenderContext): boolean {\n return false;\n }\n\n /** @internal */\n drawWithNormalizedArgs(\n context: CanvasRenderingContext2D,\n sx: number,\n sy: number,\n sw: number,\n sh: number,\n dx: number,\n dy: number,\n dw: number,\n dh: number,\n ): void {\n const image = this._source;\n if (image === null || typeof image !== \"object\") {\n return;\n }\n\n sw = sw ?? this._source.width / this._pixelRatio;\n sh = sh ?? this._source.height / this._pixelRatio;\n\n dw = dw ?? sw;\n dh = dh ?? sh;\n\n dx += this.padding;\n dy += this.padding;\n\n const ix = sx * this._pixelRatio;\n const iy = sy * this._pixelRatio;\n const iw = sw * this._pixelRatio;\n const ih = sh * this._pixelRatio;\n\n try {\n stats.draw++;\n\n // sx = clamp(sx, 0, this._source.width);\n // sy = clamp(sx, 0, this._source.height);\n // sw = clamp(sw, 0, this._source.width - sw);\n // sh = clamp(sh, 0, this._source.height - sh);\n\n context.drawImage(image, ix, iy, iw, ih, dx, dy, dw, dh);\n } catch (ex) {\n if (!this._draw_failed) {\n console.log(\"Unable to draw: \", image);\n console.log(ex);\n this._draw_failed = true;\n }\n }\n }\n}\n","import { Texture, TexturePrerenderContext } from \"./texture\";\n\nexport class PipeTexture extends Texture {\n /** @internal */ _source: Texture;\n\n constructor(source: Texture) {\n super();\n this._source = source;\n }\n\n setSourceTexture(texture: Texture) {\n this._source = texture;\n }\n\n getWidth(): number {\n return this.dw ?? this.sw ?? this._source.getWidth();\n }\n\n getHeight(): number {\n return this.dh ?? this.sh ?? this._source.getHeight();\n }\n\n /** @internal */\n prerender(context: TexturePrerenderContext): boolean {\n return this._source.prerender(context);\n }\n\n /** @internal */\n drawWithNormalizedArgs(\n context: CanvasRenderingContext2D,\n sx: number,\n sy: number,\n sw: number,\n sh: number,\n dx: number,\n dy: number,\n dw: number,\n dh: number,\n ): void {\n const texture = this._source;\n if (texture === null || typeof texture !== \"object\") {\n return;\n }\n\n texture.draw(context, sx, sy, sw, sh, dx, dy, dw, dh);\n }\n}\n","import { isFn, isHash } from \"../common/is\";\n\nimport { Texture } from \"./texture\";\nimport { TextureSelection } from \"./selection\";\nimport { ImageTexture } from \"./image\";\nimport { PipeTexture } from \"./pipe\";\n\nexport interface AtlasTextureDefinition {\n x: number;\n y: number;\n width: number;\n height: number;\n\n left?: number;\n top?: number;\n right?: number;\n bottom?: number;\n}\n\ntype MonotypeAtlasTextureDefinition = Record<string, AtlasTextureDefinition | Texture | string>;\ntype AnimAtlasTextureDefinition = (AtlasTextureDefinition | Texture | string)[];\n\nexport interface AtlasDefinition {\n name?: string;\n image?:\n | {\n src: string;\n ratio?: number;\n }\n | {\n /** @deprecated Use src instead of url */\n url: string;\n ratio?: number;\n };\n\n ppu?: number;\n textures?: Record<\n string,\n AtlasTextureDefinition | Texture | MonotypeAtlasTextureDefinition | AnimAtlasTextureDefinition\n >;\n\n map?: (texture: AtlasTextureDefinition) => AtlasTextureDefinition;\n\n /** @deprecated Use map */\n filter?: (texture: AtlasTextureDefinition) => AtlasTextureDefinition;\n\n /** @deprecated */\n trim?: number;\n /** @deprecated Use ppu */\n ratio?: number;\n\n /** @deprecated Use map */\n imagePath?: string;\n /** @deprecated Use map */\n imageRatio?: number;\n}\n\nexport class Atlas extends ImageTexture {\n /** @internal */ name: any;\n\n /** @internal */ _ppu: any;\n /** @internal */ _trim: any;\n /** @internal */ _map: any;\n /** @internal */ _textures: any;\n /** @internal */ _imageSrc: string;\n\n constructor(def: AtlasDefinition = {}) {\n super();\n\n this.name = def.name;\n this._ppu = def.ppu || def.ratio || 1;\n this._trim = def.trim || 0;\n\n this._map = def.map || def.filter;\n this._textures = def.textures;\n\n if (typeof def.image === \"object\" && isHash(def.image)) {\n if (\"src\" in def.image) {\n this._imageSrc = def.image.src;\n } else if (\"url\" in def.image) {\n this._imageSrc = def.image.url;\n }\n if (typeof def.image.ratio === \"number\") {\n this._pixelRatio = def.image.ratio;\n }\n } else {\n if (typeof def.imagePath === \"string\") {\n this._imageSrc = def.imagePath;\n } else if (typeof def.image === \"string\") {\n this._imageSrc = def.image;\n }\n if (typeof def.imageRatio === \"number\") {\n this._pixelRatio = def.imageRatio;\n }\n }\n\n deprecatedWarning(def);\n }\n\n async load() {\n if (this._imageSrc) {\n const image = await asyncLoadImage(this._imageSrc);\n this.setSourceImage(image, this._pixelRatio);\n }\n }\n\n /**\n * @internal\n * Uses the definition to create a texture object from this atlas.\n */\n pipeSpriteTexture = (def: AtlasTextureDefinition): Texture => {\n const map = this._map;\n const ppu = this._ppu;\n const trim = this._trim;\n\n if (!def) {\n return undefined;\n }\n\n def = Object.assign({}, def);\n\n if (isFn(map)) {\n def = map(def);\n }\n\n if (ppu != 1) {\n def.x *= ppu;\n def.y *= ppu;\n def.width *= ppu;\n def.height *= ppu;\n def.top *= ppu;\n def.bottom *= ppu;\n def.left *= ppu;\n def.right *= ppu;\n }\n\n if (trim != 0) {\n def.x += trim;\n def.y += trim;\n def.width -= 2 * trim;\n def.height -= 2 * trim;\n def.top -= trim;\n def.bottom -= trim;\n def.left -= trim;\n def.right -= trim;\n }\n\n const texture = new PipeTexture(this);\n texture.top = def.top;\n texture.bottom = def.bottom;\n texture.left = def.left;\n texture.right = def.right;\n texture.setSourceCoordinate(def.x, def.y);\n texture.setSourceDimension(def.width, def.height);\n return texture;\n };\n\n /**\n * @internal\n * Looks up and returns texture definition.\n */\n findSpriteDefinition = (query: string) => {\n const textures = this._textures;\n\n if (textures) {\n if (isFn(textures)) {\n return textures(query);\n } else if (isHash(textures)) {\n return textures[query];\n }\n }\n };\n\n // returns Selection, and then selection.one/array returns actual texture/textures\n select = (query?: string) => {\n if (!query) {\n // TODO: if `textures` is texture def, map or fn?\n return new TextureSelection(new PipeTexture(this));\n }\n const textureDefinition = this.findSpriteDefinition(query);\n if (textureDefinition) {\n return new TextureSelection(textureDefinition, this);\n }\n };\n}\n\n/** @internal */\nfunction asyncLoadImage(src: string) {\n console.debug && console.debug(\"Loading image: \" + src);\n return new Promise<HTMLImageElement>(function (resolve, reject) {\n const img = new Image();\n img.onload = function () {\n console.debug && console.debug(\"Image loaded: \" + src);\n resolve(img);\n };\n img.onerror = function (error) {\n console.error(\"Loading failed: \" + src);\n reject(error);\n };\n img.src = src;\n });\n}\n\n/** @internal */\nfunction deprecatedWarning(def: AtlasDefinition) {\n if (\"filter\" in def) console.warn(\"'filter' field of atlas definition is deprecated\");\n\n // todo: throw error here?\n if (\"cutouts\" in def) console.warn(\"'cutouts' field of atlas definition is deprecated\");\n\n // todo: throw error here?\n if (\"sprites\" in def) console.warn(\"'sprites' field of atlas definition is deprecated\");\n\n // todo: throw error here?\n if (\"factory\" in def) console.warn(\"'factory' field of atlas definition is deprecated\");\n\n if (\"ratio\" in def) console.warn(\"'ratio' field of atlas definition is deprecated\");\n\n if (\"imagePath\" in def) console.warn(\"'imagePath' field of atlas definition is deprecated\");\n\n if (\"imageRatio\" in def) console.warn(\"'imageRatio' field of atlas definition is deprecated\");\n\n if (typeof def.image === \"object\" && \"url\" in def.image)\n console.warn(\"'image.url' field of atlas definition is deprecated\");\n}\n","import { isFn, isHash } from \"../common/is\";\n\nimport { Atlas, AtlasDefinition, AtlasTextureDefinition } from \"./atlas\";\nimport { Texture, TexturePrerenderContext } from \"./texture\";\n\nexport type TextureSelectionInputOne = Texture | AtlasTextureDefinition | string;\nexport type TextureSelectionInputMap = Record<string, TextureSelectionInputOne>;\nexport type TextureSelectionInputArray = TextureSelectionInputOne[];\nexport type TextureSelectionInputFactory = (subquery: string) => TextureSelectionInputOne;\n\n/**\n * Texture selection input could be one:\n * - texture\n * - sprite definition (and an atlas): atlas sprite texture\n * - string (with an atlas): string used as key to find sprite in the atlas, re-resolve\n * - hash object: use subquery as key, then re-resolve value\n * - array: re-resolve first item\n * - function: call function with subquery, then re-resolve\n */\nexport type TextureSelectionInput =\n | TextureSelectionInputOne\n | TextureSelectionInputMap\n | TextureSelectionInputArray\n | TextureSelectionInputFactory;\n\n/** @internal */\nfunction isAtlasSpriteDefinition(selection: any) {\n return (\n typeof selection === \"object\" &&\n isHash(selection) &&\n \"number\" === typeof selection.width &&\n \"number\" === typeof selection.height\n );\n}\n\n/**\n * TextureSelection holds reference to one or many textures or something that\n * can be resolved to one or many textures. This is used to decouple resolving\n * references to textures from rendering them in various ways.\n */\nexport class TextureSelection {\n selection: TextureSelectionInput;\n atlas: Atlas;\n constructor(selection: TextureSelectionInput, atlas?: Atlas) {\n this.selection = selection;\n this.atlas = atlas;\n }\n\n /**\n * @internal\n * Resolves the selection to a texture.\n */\n resolve(selection: TextureSelectionInput, subquery?: string): Texture {\n if (!selection) {\n return NO_TEXTURE;\n } else if (Array.isArray(selection)) {\n return this.resolve(selection[0]);\n } else if (selection instanceof Texture) {\n return selection;\n } else if (isAtlasSpriteDefinition(selection)) {\n if (!this.atlas) {\n return NO_TEXTURE;\n }\n return this.atlas.pipeSpriteTexture(selection as AtlasTextureDefinition);\n } else if (\n typeof selection === \"object\" &&\n isHash(selection) &&\n typeof subquery !== \"undefined\"\n ) {\n return this.resolve(selection[subquery]);\n } else if (typeof selection === \"function\" && isFn(selection)) {\n return this.resolve(selection(subquery));\n } else if (typeof selection === \"string\") {\n if (!this.atlas) {\n return NO_TEXTURE;\n }\n return this.resolve(this.atlas.findSpriteDefinition(selection));\n }\n }\n\n one(subquery?: string): Texture {\n return this.resolve(this.selection, subquery);\n }\n\n array(arr?: Texture[]): Texture[] {\n const array = Array.isArray(arr) ? arr : [];\n if (Array.isArray(this.selection)) {\n for (let i = 0; i < this.selection.length; i++) {\n array[i] = this.resolve(this.selection[i]);\n }\n } else {\n array[0] = this.resolve(this.selection);\n }\n return array;\n }\n}\n\n/** @internal */\nconst NO_TEXTURE = new (class extends Texture {\n getWidth(): number {\n return 0;\n }\n getHeight(): number {\n return 0;\n }\n prerender(context: TexturePrerenderContext): boolean {\n return false;\n }\n drawWithNormalizedArgs(\n context: CanvasRenderingContext2D,\n sx: number,\n sy: number,\n sw: number,\n sh: number,\n dx: number,\n dy: number,\n dw: number,\n dh: number,\n ): void {}\n constructor() {\n super();\n this.setSourceDimension(0, 0);\n }\n setSourceCoordinate(x: any, y: any): void {}\n setSourceDimension(w: any, h: any): void {}\n setDestinationCoordinate(x: number, y: number): void {}\n setDestinationDimension(w: number, h: number): void {}\n draw(): void {}\n})();\n\n/** @internal */\nconst NO_SELECTION = new TextureSelection(NO_TEXTURE);\n\n/** @internal */\nconst ATLAS_MEMO_BY_NAME: Record<string, Atlas> = {};\n\n/** @internal */\nconst ATLAS_ARRAY: Atlas[] = [];\n\n// TODO: print subquery not found error\n// TODO: index textures\n\nexport async function atlas(def: AtlasDefinition | Atlas): Promise<Atlas> {\n // todo: where is this used?\n let atlas: Atlas;\n if (def instanceof Atlas) {\n atlas = def;\n } else {\n atlas = new Atlas(def);\n }\n\n if (atlas.name) {\n ATLAS_MEMO_BY_NAME[atlas.name] = atlas;\n }\n ATLAS_ARRAY.push(atlas);\n\n await atlas.load();\n\n return atlas;\n}\n\n/**\n * When query argument is string, this function parses the query; looks up registered atlases; and returns a texture selection object.\n *\n * When query argument is an object, the object is used to create a new selection.\n */\nexport function texture(query: string | TextureSelectionInput): TextureSelection {\n if (\"string\" !== typeof query) {\n return new TextureSelection(query);\n }\n\n let result: TextureSelection | undefined | null = null;\n\n // parse query as atlas-name:texture-name\n const colonIndex = query.indexOf(\":\");\n if (colonIndex > 0 && query.length > colonIndex + 1) {\n const atlas = ATLAS_MEMO_BY_NAME[query.slice(0, colonIndex)];\n result = atlas && atlas.select(query.slice(colonIndex + 1));\n }\n\n if (!result) {\n // use query as \"atlas-name\", return entire atlas\n const atlas = ATLAS_MEMO_BY_NAME[query];\n result = atlas && atlas.select();\n }\n\n if (!result) {\n // use query as \"texture-name\", search over all atlases\n for (let i = 0; i < ATLAS_ARRAY.length; i++) {\n result = ATLAS_ARRAY[i].select(query);\n if (result) {\n break;\n }\n }\n }\n\n if (!result) {\n console.error(\"Texture not found: \" + query);\n result = NO_SELECTION;\n }\n\n return result;\n}\n","import { Texture, TexturePrerenderContext } from \"./texture\";\n\nexport type ResizableTextureMode = \"stretch\" | \"tile\";\n\nexport class ResizableTexture extends Texture {\n /** @internal */ _source: Texture;\n\n /** @internal */ _resizeMode: ResizableTextureMode;\n /** @internal */ _innerSize: boolean;\n\n constructor(source: Texture, mode: ResizableTextureMode) {\n super();\n this._source = source;\n this._resizeMode = mode;\n }\n\n getWidth(): number {\n // this is the last known width\n return this.dw ?? this._source.getWidth();\n }\n\n getHeight(): number {\n // this is the last known height\n return this.dh ?? this._source.getHeight();\n }\n\n /** @internal */\n prerender(context: TexturePrerenderContext): boolean {\n return false;\n }\n\n drawWithNormalizedArgs(\n context: CanvasRenderingContext2D,\n sx: number,\n sy: number,\n sw: number,\n sh: number,\n dx: number,\n dy: number,\n dw: number,\n dh: number,\n ): void {\n const texture = this._source;\n if (texture === null || typeof texture !== \"object\") {\n return;\n }\n\n let outWidth = dw;\n let outHeight = dh;\n\n const left = Number.isFinite(texture.left) ? texture.left : 0;\n const right = Number.isFinite(texture.right) ? texture.right : 0;\n const top = Number.isFinite(texture.top) ? texture.top : 0;\n const bottom = Number.isFinite(texture.bottom) ? texture.bottom : 0;\n\n const width = texture.getWidth() - left - right;\n const height = texture.getHeight() - top - bottom;\n\n if (!this._innerSize) {\n outWidth = Math.max(outWidth - left - right, 0);\n outHeight = Math.max(outHeight - top - bottom, 0);\n }\n\n // corners\n if (top > 0 && left > 0) {\n texture.draw(context, 0, 0, left, top, 0, 0, left, top);\n }\n if (bottom > 0 && left > 0) {\n texture.draw(context, 0, height + top, left, bottom, 0, outHeight + top, left, bottom);\n }\n if (top > 0 && right > 0) {\n texture.draw(context, width + left, 0, right, top, outWidth + left, 0, right, top);\n }\n if (bottom > 0 && right > 0) {\n texture.draw(\n context,\n width + left,\n height + top,\n right,\n bottom,\n outWidth + left,\n outHeight + top,\n right,\n bottom,\n );\n }\n\n if (this._resizeMode === \"stretch\") {\n // sides\n if (top > 0) {\n texture.draw(context, left, 0, width, top, left, 0, outWidth, top);\n }\n if (bottom > 0) {\n texture.draw(\n context,\n left,\n height + top,\n width,\n bottom,\n left,\n outHeight + top,\n outWidth,\n bottom,\n );\n }\n if (left > 0) {\n texture.draw(context, 0, top, left, height, 0, top, left, outHeight);\n }\n if (right > 0) {\n texture.draw(\n context,\n width + left,\n top,\n right,\n height,\n outWidth + left,\n top,\n right,\n outHeight,\n );\n }\n // center\n texture.draw(context, left, top, width, height, left, top, outWidth, outHeight);\n } else if (this._resizeMode === \"tile\") {\n // tile\n let l = left;\n let r = outWidth;\n let w: number;\n while (r > 0) {\n w = Math.min(width, r);\n r -= width;\n let t = top;\n let b = outHeight;\n let h: number;\n while (b > 0) {\n h = Math.min(height, b);\n b -= height;\n texture.draw(context, left, top, w, h, l, t, w, h);\n if (r <= 0) {\n if (left) {\n texture.draw(context, 0, top, left, h, 0, t, left, h);\n }\n if (right) {\n texture.draw(context, width + left, top, right, h, l + w, t, right, h);\n }\n }\n t += h;\n }\n if (top) {\n texture.draw(context, left, 0, w, top, l, 0, w, top);\n }\n if (bottom) {\n texture.draw(context, left, height + top, w, bottom, l, t, w, bottom);\n }\n l += w;\n }\n }\n }\n}\n","/** @internal */\nexport function getDevicePixelRatio() {\n // todo: do we need to divide by backingStoreRatio?\n return typeof window !== \"undefined\" ? window.devicePixelRatio || 1 : 1;\n}\n","import { Matrix, Vec2Value } from \"../common/matrix\";\nimport { uid } from \"../common/uid\";\n\nimport type { Component } from \"./component\";\n\n/**\n * @hidden @deprecated\n * - 'in-pad': same as 'contain'\n * - 'in': similar to 'contain' without centering\n * - 'out-crop': same as 'cover'\n * - 'out': similar to 'cover' without centering\n */\nexport type LegacyFitMode = \"in\" | \"out\" | \"out-crop\" | \"in-pad\";\n\n/**\n * - 'contain': contain within the provided space, maintain aspect ratio\n * - 'cover': cover the provided space, maintain aspect ratio\n * - 'fill': fill provided space without maintaining aspect ratio\n */\nexport type FitMode = \"contain\" | \"cover\" | \"fill\" | LegacyFitMode;\n\n/** @internal */\nexport function isValidFitMode(value: string) {\n return (\n value &&\n (value === \"cover\" ||\n value === \"contain\" ||\n value === \"fill\" ||\n value === \"in\" ||\n value === \"in-pad\" ||\n value === \"out\" ||\n value === \"out-crop\")\n );\n}\n\n/** @internal */ let iid = 0;\n\n/** @hidden */\nexport interface Pinned {\n pin(pin: object): this;\n pin(key: string, value: any): this;\n pin(key: string): any;\n\n size(w: number, h: number): this;\n\n width(): number;\n width(w: number): this;\n\n height(): number;\n height(h: number): this;\n\n offset(a: Vec2Value): this;\n offset(a: number, b: number): this;\n\n rotate(a: number): this;\n\n skew(a: Vec2Value): this;\n skew(a: number, b: number): this;\n\n scale(a: Vec2Value): this;\n scale(a: number, b: number): this;\n\n alpha(a: number, ta?: number): this;\n}\n\nexport class Pin {\n /** @internal */ uid = \"pin:\" + uid();\n\n /** @internal */ _owner: Component;\n\n // todo: maybe this should be a getter instead?\n /** @internal */ _parent: Pin | null;\n\n /** @internal */ _relativeMatrix: Matrix;\n /** @internal */ _absoluteMatrix: Matrix;\n\n /** @internal */ _x: number;\n /** @internal */ _y: number;\n\n /** @internal */ _unscaled_width: number;\n /** @internal */ _unscaled_height: number;\n\n /** @internal */ _width: number;\n /** @internal */ _height: number;\n\n /** @internal */ _textureAlpha: number;\n /** @internal */ _alpha: number;\n\n /** @internal */ _scaleX: number;\n /** @internal */ _scaleY: number;\n\n /** @internal */ _skewX: number;\n /** @internal */ _skewY: number;\n /** @internal */ _rotation: number;\n\n /** @internal */ _pivoted: boolean;\n /** @internal */ _pivotX: number;\n /** @internal */ _pivotY: number;\n\n /** @internal */ _handled: boolean;\n /** @internal */ _handleX: number;\n /** @internal */ _handleY: number;\n\n /** @internal */ _aligned: boolean;\n /** @internal */ _alignX: number;\n /** @internal */ _alignY: number;\n\n /** @internal */ _offsetX: number;\n /** @internal */ _offsetY: number;\n\n /** @internal */ _boxX: number;\n /** @internal */ _boxY: number;\n /** @internal */ _boxWidth: number;\n /** @internal */ _boxHeight: number;\n\n /** @internal */ _ts_transform: number;\n /** @internal */ _ts_translate: number;\n /** @internal */ _ts_matrix: number;\n\n /** @internal */ _mo_handle: number;\n /** @internal */ _mo_align: number;\n /** @internal */ _mo_abs: number;\n /** @internal */ _mo_rel: number;\n\n /** @internal */ _directionX = 1;\n /** @internal */ _directionY = 1;\n\n /** @internal */\n constructor(owner: Component) {\n this._owner = owner;\n this._parent = null;\n\n // relative to parent\n this._relativeMatrix = new Matrix();\n\n // relative to stage\n this._absoluteMatrix = new Matrix();\n\n this.reset();\n }\n\n reset() {\n this._textureAlpha = 1;\n this._alpha = 1;\n\n this._width = 0;\n this._height = 0;\n\n this._scaleX = 1;\n this._scaleY = 1;\n this._skewX = 0;\n this._skewY = 0;\n this._rotation = 0;\n\n // scale/skew/rotate center\n this._pivoted = false;\n // todo: this used to be null\n this._pivotX = 0;\n this._pivotY = 0;\n\n // self pin point\n this._handled = false;\n this._handleX = 0;\n this._handleY = 0;\n\n // parent pin point\n this._aligned = false;\n this._alignX = 0;\n this._alignY = 0;\n\n // as seen by parent px\n this._offsetX = 0;\n this._offsetY = 0;\n\n this._boxX = 0;\n this._boxY = 0;\n this._boxWidth = this._width;\n this._boxHeight = this._height;\n\n // TODO: also set for owner\n this._ts_translate = ++iid;\n this._ts_transform = ++iid;\n this._ts_matrix = ++iid;\n }\n\n /** @internal */\n _update() {\n this._parent = this._owner._parent && this._owner._parent._pin;\n\n // if handled and transformed then be translated\n if (this._handled && this._mo_handle != this._ts_transform) {\n this._mo_handle = this._ts_transform;\n this._ts_translate = ++iid;\n }\n\n if (this._aligned && this._parent && this._mo_align != this._parent._ts_transform) {\n this._mo_align = this._parent._ts_transform;\n this._ts_translate = ++iid;\n }\n\n return this;\n }\n\n toString() {\n return this._owner + \" (\" + (this._parent ? this._parent._owner : null) + \")\";\n }\n\n // TODO: ts fields require refactoring\n absoluteMatrix() {\n this._update();\n const ts = Math.max(\n this._ts_transform,\n this._ts_translate,\n this._parent ? this._parent._ts_matrix : 0,\n );\n if (this._mo_abs == ts) {\n return this._absoluteMatrix;\n }\n this._mo_abs = ts;\n\n const abs = this._absoluteMatrix;\n abs.reset(this.relativeMatrix());\n\n this._parent && abs.concat(this._parent._absoluteMatrix);\n\n this._ts_matrix = ++iid;\n\n return abs;\n }\n\n relativeMatrix() {\n this._update();\n const ts = Math.max(\n this._ts_transform,\n this._ts_translate,\n this._parent ? this._parent._ts_transform : 0,\n );\n if (this._mo_rel == ts) {\n return this._relativeMatrix;\n }\n this._mo_rel = ts;\n\n const rel = this._relativeMatrix;\n\n rel.identity();\n if (this._pivoted) {\n rel.translate(-this._pivotX * this._width, -this._pivotY * this._height);\n }\n rel.scale(this._scaleX * this._directionX, this._scaleY * this._directionY);\n rel.skew(this._skewX, this._skewY);\n rel.rotate(this._rotation);\n if (this._pivoted) {\n rel.translate(this._pivotX * this._width, this._pivotY * this._height);\n }\n\n // calculate effective box\n if (this._pivoted) {\n // origin\n this._boxX = 0;\n this._boxY = 0;\n this._boxWidth = this._width;\n this._boxHeight = this._height;\n } else {\n // aabb\n let p;\n let q;\n if ((rel.a > 0 && rel.c > 0) || (rel.a < 0 && rel.c < 0)) {\n p = 0;\n q = rel.a * this._width + rel.c * this._height;\n } else {\n p = rel.a * this._width;\n q = rel.c * this._height;\n }\n if (p > q) {\n this._boxX = q;\n this._boxWidth = p - q;\n } else {\n this._boxX = p;\n this._boxWidth = q - p;\n }\n if ((rel.b > 0 &