targetj 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/AnimationManager.js +220 -152
- package/build/AnimationUtil.js +0 -1
- package/build/App.js +79 -39
- package/build/BaseModel.js +43 -11
- package/build/Easing.js +5 -0
- package/build/EventListener.js +29 -9
- package/build/HtmlToCanvas.js +411 -0
- package/build/LocationManager.js +44 -14
- package/build/PageManager.js +84 -33
- package/build/ParticleChild.js +12 -11
- package/build/ParticleExplode.js +360 -0
- package/build/ParticleRenderer.js +672 -192
- package/build/ParticleRuntime.js +844 -311
- package/build/ParticleTModel.js +370 -175
- package/build/ParticleUtil.js +9 -3
- package/build/RunScheduler.js +13 -8
- package/build/StateManager.js +125 -33
- package/build/StateUtil.js +142 -83
- package/build/TModel.js +179 -74
- package/build/TModelManager.js +127 -108
- package/build/TModelUtil.js +230 -143
- package/build/TUtil.js +4 -4
- package/build/TargetData.js +20 -12
- package/build/TargetExecutor.js +37 -14
- package/build/TargetManager.js +13 -18
- package/build/TargetParser.js +36 -2
- package/build/TargetUtil.js +189 -128
- package/build/VisibilityUtil.js +25 -14
- package/dist/targetjs.js +1 -1
- package/dist/targetjs.js.gz +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
6
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
7
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
8
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
9
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
10
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
var HtmlToCanvas = /*#__PURE__*/function () {
|
|
14
|
+
function HtmlToCanvas() {
|
|
15
|
+
_classCallCheck(this, HtmlToCanvas);
|
|
16
|
+
}
|
|
17
|
+
return _createClass(HtmlToCanvas, null, [{
|
|
18
|
+
key: "captureSource",
|
|
19
|
+
value: function () {
|
|
20
|
+
var _captureSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(element, width, height, excludeGpuLayer) {
|
|
21
|
+
var _document$fonts;
|
|
22
|
+
var pixelRatio, canvas, context, sourceRect;
|
|
23
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
24
|
+
while (1) switch (_context.prev = _context.next) {
|
|
25
|
+
case 0:
|
|
26
|
+
if (element) {
|
|
27
|
+
_context.next = 2;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
throw new Error("explodeChildren cannot capture a UI without a DOM element.");
|
|
31
|
+
case 2:
|
|
32
|
+
if (!(!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0)) {
|
|
33
|
+
_context.next = 4;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
throw new RangeError("explodeChildren requires positive dimensions before capturing.");
|
|
37
|
+
case 4:
|
|
38
|
+
if (!(element instanceof HTMLImageElement)) {
|
|
39
|
+
_context.next = 6;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
return _context.abrupt("return", HtmlToCanvas.captureImage(element, width, height));
|
|
43
|
+
case 6:
|
|
44
|
+
if (!((_document$fonts = document.fonts) !== null && _document$fonts !== void 0 && _document$fonts.ready)) {
|
|
45
|
+
_context.next = 9;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
_context.next = 9;
|
|
49
|
+
return document.fonts.ready;
|
|
50
|
+
case 9:
|
|
51
|
+
pixelRatio = window.devicePixelRatio || 1;
|
|
52
|
+
canvas = document.createElement("canvas");
|
|
53
|
+
canvas.width = Math.max(1, Math.round(width * pixelRatio));
|
|
54
|
+
canvas.height = Math.max(1, Math.round(height * pixelRatio));
|
|
55
|
+
canvas.style.width = "".concat(width, "px");
|
|
56
|
+
canvas.style.height = "".concat(height, "px");
|
|
57
|
+
context = canvas.getContext("2d");
|
|
58
|
+
if (context) {
|
|
59
|
+
_context.next = 18;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Could not create a 2D context for explodeChildren capture.");
|
|
63
|
+
case 18:
|
|
64
|
+
context.scale(pixelRatio, pixelRatio);
|
|
65
|
+
sourceRect = element.getBoundingClientRect();
|
|
66
|
+
_context.next = 22;
|
|
67
|
+
return HtmlToCanvas.drawElement(context, element, sourceRect, excludeGpuLayer);
|
|
68
|
+
case 22:
|
|
69
|
+
return _context.abrupt("return", {
|
|
70
|
+
canvas: canvas,
|
|
71
|
+
width: width,
|
|
72
|
+
height: height,
|
|
73
|
+
pixelRatio: pixelRatio
|
|
74
|
+
});
|
|
75
|
+
case 23:
|
|
76
|
+
case "end":
|
|
77
|
+
return _context.stop();
|
|
78
|
+
}
|
|
79
|
+
}, _callee);
|
|
80
|
+
}));
|
|
81
|
+
function captureSource(_x, _x2, _x3, _x4) {
|
|
82
|
+
return _captureSource.apply(this, arguments);
|
|
83
|
+
}
|
|
84
|
+
return captureSource;
|
|
85
|
+
}()
|
|
86
|
+
}, {
|
|
87
|
+
key: "drawElement",
|
|
88
|
+
value: function () {
|
|
89
|
+
var _drawElement = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(context, element, sourceRect, excludeGpuLayer) {
|
|
90
|
+
var rect, style, x, y, width, height, _iterator, _step, child;
|
|
91
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
92
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!(element === (excludeGpuLayer === null || excludeGpuLayer === void 0 ? void 0 : excludeGpuLayer()))) {
|
|
95
|
+
_context2.next = 2;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
return _context2.abrupt("return");
|
|
99
|
+
case 2:
|
|
100
|
+
rect = element.getBoundingClientRect();
|
|
101
|
+
style = getComputedStyle(element);
|
|
102
|
+
x = rect.left - sourceRect.left;
|
|
103
|
+
y = rect.top - sourceRect.top;
|
|
104
|
+
width = rect.width;
|
|
105
|
+
height = rect.height;
|
|
106
|
+
context.save();
|
|
107
|
+
HtmlToCanvas.clipBorderRadius(context, style, x, y, width, height);
|
|
108
|
+
if (style.backgroundColor !== "rgba(0, 0, 0, 0)") {
|
|
109
|
+
context.fillStyle = style.backgroundColor;
|
|
110
|
+
context.fillRect(x, y, width, height);
|
|
111
|
+
}
|
|
112
|
+
_context2.next = 13;
|
|
113
|
+
return HtmlToCanvas.drawBackgroundImage(context, style, x, y, width, height);
|
|
114
|
+
case 13:
|
|
115
|
+
if (!(element instanceof HTMLImageElement)) {
|
|
116
|
+
_context2.next = 20;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
if (element.complete) {
|
|
120
|
+
_context2.next = 17;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
_context2.next = 17;
|
|
124
|
+
return element.decode().catch(function () {});
|
|
125
|
+
case 17:
|
|
126
|
+
context.drawImage(element, x, y, width, height);
|
|
127
|
+
context.restore();
|
|
128
|
+
return _context2.abrupt("return");
|
|
129
|
+
case 20:
|
|
130
|
+
if (!(element instanceof HTMLCanvasElement)) {
|
|
131
|
+
_context2.next = 25;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
_context2.next = 23;
|
|
135
|
+
return HtmlToCanvas.drawCanvas(context, element, x, y, width, height);
|
|
136
|
+
case 23:
|
|
137
|
+
context.restore();
|
|
138
|
+
return _context2.abrupt("return");
|
|
139
|
+
case 25:
|
|
140
|
+
context.restore();
|
|
141
|
+
HtmlToCanvas.drawText(context, element, sourceRect);
|
|
142
|
+
_iterator = _createForOfIteratorHelper(element.children);
|
|
143
|
+
_context2.prev = 28;
|
|
144
|
+
_iterator.s();
|
|
145
|
+
case 30:
|
|
146
|
+
if ((_step = _iterator.n()).done) {
|
|
147
|
+
_context2.next = 36;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
child = _step.value;
|
|
151
|
+
_context2.next = 34;
|
|
152
|
+
return HtmlToCanvas.drawElement(context, child, sourceRect);
|
|
153
|
+
case 34:
|
|
154
|
+
_context2.next = 30;
|
|
155
|
+
break;
|
|
156
|
+
case 36:
|
|
157
|
+
_context2.next = 41;
|
|
158
|
+
break;
|
|
159
|
+
case 38:
|
|
160
|
+
_context2.prev = 38;
|
|
161
|
+
_context2.t0 = _context2["catch"](28);
|
|
162
|
+
_iterator.e(_context2.t0);
|
|
163
|
+
case 41:
|
|
164
|
+
_context2.prev = 41;
|
|
165
|
+
_iterator.f();
|
|
166
|
+
return _context2.finish(41);
|
|
167
|
+
case 44:
|
|
168
|
+
case "end":
|
|
169
|
+
return _context2.stop();
|
|
170
|
+
}
|
|
171
|
+
}, _callee2, null, [[28, 38, 41, 44]]);
|
|
172
|
+
}));
|
|
173
|
+
function drawElement(_x5, _x6, _x7, _x8) {
|
|
174
|
+
return _drawElement.apply(this, arguments);
|
|
175
|
+
}
|
|
176
|
+
return drawElement;
|
|
177
|
+
}()
|
|
178
|
+
}, {
|
|
179
|
+
key: "drawBackgroundImage",
|
|
180
|
+
value: function () {
|
|
181
|
+
var _drawBackgroundImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(context, style, x, y, width, height) {
|
|
182
|
+
var backgroundImage, match, image, imageWidth, imageHeight, drawWidth, drawHeight, scale, _scale, drawX, drawY;
|
|
183
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
184
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
185
|
+
case 0:
|
|
186
|
+
backgroundImage = style.backgroundImage;
|
|
187
|
+
if (!(!backgroundImage || backgroundImage === "none")) {
|
|
188
|
+
_context3.next = 3;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
return _context3.abrupt("return");
|
|
192
|
+
case 3:
|
|
193
|
+
match = backgroundImage.match(/url\((['"]?)(.*?)\1\)/);
|
|
194
|
+
if (match !== null && match !== void 0 && match[2]) {
|
|
195
|
+
_context3.next = 6;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
return _context3.abrupt("return");
|
|
199
|
+
case 6:
|
|
200
|
+
_context3.next = 8;
|
|
201
|
+
return HtmlToCanvas.loadBackgroundImage(match[2]);
|
|
202
|
+
case 8:
|
|
203
|
+
image = _context3.sent;
|
|
204
|
+
if (image) {
|
|
205
|
+
_context3.next = 11;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
return _context3.abrupt("return");
|
|
209
|
+
case 11:
|
|
210
|
+
imageWidth = image.naturalWidth;
|
|
211
|
+
imageHeight = image.naturalHeight;
|
|
212
|
+
if (!(!imageWidth || !imageHeight)) {
|
|
213
|
+
_context3.next = 15;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
return _context3.abrupt("return");
|
|
217
|
+
case 15:
|
|
218
|
+
drawWidth = width;
|
|
219
|
+
drawHeight = height;
|
|
220
|
+
if (style.backgroundSize === "cover") {
|
|
221
|
+
scale = Math.max(width / imageWidth, height / imageHeight);
|
|
222
|
+
drawWidth = imageWidth * scale;
|
|
223
|
+
drawHeight = imageHeight * scale;
|
|
224
|
+
} else if (style.backgroundSize === "contain") {
|
|
225
|
+
_scale = Math.min(width / imageWidth, height / imageHeight);
|
|
226
|
+
drawWidth = imageWidth * _scale;
|
|
227
|
+
drawHeight = imageHeight * _scale;
|
|
228
|
+
}
|
|
229
|
+
drawX = x + HtmlToCanvas.getBackgroundPosition(style.backgroundPositionX, width, drawWidth);
|
|
230
|
+
drawY = y + HtmlToCanvas.getBackgroundPosition(style.backgroundPositionY, height, drawHeight);
|
|
231
|
+
context.save();
|
|
232
|
+
context.beginPath();
|
|
233
|
+
context.rect(x, y, width, height);
|
|
234
|
+
context.clip();
|
|
235
|
+
context.drawImage(image, drawX, drawY, drawWidth, drawHeight);
|
|
236
|
+
context.restore();
|
|
237
|
+
case 26:
|
|
238
|
+
case "end":
|
|
239
|
+
return _context3.stop();
|
|
240
|
+
}
|
|
241
|
+
}, _callee3);
|
|
242
|
+
}));
|
|
243
|
+
function drawBackgroundImage(_x9, _x10, _x11, _x12, _x13, _x14) {
|
|
244
|
+
return _drawBackgroundImage.apply(this, arguments);
|
|
245
|
+
}
|
|
246
|
+
return drawBackgroundImage;
|
|
247
|
+
}()
|
|
248
|
+
}, {
|
|
249
|
+
key: "drawCanvas",
|
|
250
|
+
value: function () {
|
|
251
|
+
var _drawCanvas = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(context, canvas, x, y, width, height) {
|
|
252
|
+
var source, _source$close;
|
|
253
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
254
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
255
|
+
case 0:
|
|
256
|
+
if (!(typeof canvas.captureBitmap === "function")) {
|
|
257
|
+
_context4.next = 6;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
_context4.next = 3;
|
|
261
|
+
return canvas.captureBitmap();
|
|
262
|
+
case 3:
|
|
263
|
+
_context4.t0 = _context4.sent;
|
|
264
|
+
_context4.next = 7;
|
|
265
|
+
break;
|
|
266
|
+
case 6:
|
|
267
|
+
_context4.t0 = canvas;
|
|
268
|
+
case 7:
|
|
269
|
+
source = _context4.t0;
|
|
270
|
+
if (source) {
|
|
271
|
+
_context4.next = 10;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
return _context4.abrupt("return");
|
|
275
|
+
case 10:
|
|
276
|
+
try {
|
|
277
|
+
context.drawImage(source, x, y, width, height);
|
|
278
|
+
} finally {
|
|
279
|
+
if (source !== canvas) {
|
|
280
|
+
(_source$close = source.close) === null || _source$close === void 0 || _source$close.call(source);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
case 11:
|
|
284
|
+
case "end":
|
|
285
|
+
return _context4.stop();
|
|
286
|
+
}
|
|
287
|
+
}, _callee4);
|
|
288
|
+
}));
|
|
289
|
+
function drawCanvas(_x15, _x16, _x17, _x18, _x19, _x20) {
|
|
290
|
+
return _drawCanvas.apply(this, arguments);
|
|
291
|
+
}
|
|
292
|
+
return drawCanvas;
|
|
293
|
+
}()
|
|
294
|
+
}, {
|
|
295
|
+
key: "getBackgroundPosition",
|
|
296
|
+
value: function getBackgroundPosition(position, containerSize, imageSize) {
|
|
297
|
+
var remaining = containerSize - imageSize;
|
|
298
|
+
if (!position) {
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
position = position.trim();
|
|
302
|
+
if (position.endsWith("%")) {
|
|
303
|
+
var percent = parseFloat(position);
|
|
304
|
+
return Number.isFinite(percent) ? remaining * percent / 100 : 0;
|
|
305
|
+
}
|
|
306
|
+
if (position.endsWith("px")) {
|
|
307
|
+
var pixels = parseFloat(position);
|
|
308
|
+
return Number.isFinite(pixels) ? pixels : 0;
|
|
309
|
+
}
|
|
310
|
+
switch (position) {
|
|
311
|
+
case "center":
|
|
312
|
+
return remaining / 2;
|
|
313
|
+
case "right":
|
|
314
|
+
case "bottom":
|
|
315
|
+
return remaining;
|
|
316
|
+
default:
|
|
317
|
+
return 0;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
key: "loadBackgroundImage",
|
|
322
|
+
value: function loadBackgroundImage(src) {
|
|
323
|
+
return new Promise(function (resolve) {
|
|
324
|
+
var image = new Image();
|
|
325
|
+
try {
|
|
326
|
+
var url = new URL(src, document.baseURI);
|
|
327
|
+
if (url.origin !== window.location.origin) {
|
|
328
|
+
image.crossOrigin = "anonymous";
|
|
329
|
+
}
|
|
330
|
+
} catch (_unused) {}
|
|
331
|
+
image.onload = function () {
|
|
332
|
+
return resolve(image);
|
|
333
|
+
};
|
|
334
|
+
image.onerror = function () {
|
|
335
|
+
console.warn("Could not load explodeChildren background image: ".concat(src));
|
|
336
|
+
resolve(undefined);
|
|
337
|
+
};
|
|
338
|
+
image.src = src;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}, {
|
|
342
|
+
key: "clipBorderRadius",
|
|
343
|
+
value: function clipBorderRadius(context, style, x, y, width, height) {
|
|
344
|
+
var radii = [parseFloat(style.borderTopLeftRadius) || 0, parseFloat(style.borderTopRightRadius) || 0, parseFloat(style.borderBottomRightRadius) || 0, parseFloat(style.borderBottomLeftRadius) || 0];
|
|
345
|
+
if (!radii.some(function (radius) {
|
|
346
|
+
return radius > 0;
|
|
347
|
+
})) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
context.beginPath();
|
|
351
|
+
context.roundRect(x, y, width, height, radii);
|
|
352
|
+
context.clip();
|
|
353
|
+
}
|
|
354
|
+
}, {
|
|
355
|
+
key: "drawText",
|
|
356
|
+
value: function drawText(context, element, sourceRect) {
|
|
357
|
+
var style = getComputedStyle(element);
|
|
358
|
+
var _iterator2 = _createForOfIteratorHelper(element.childNodes),
|
|
359
|
+
_step2;
|
|
360
|
+
try {
|
|
361
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
362
|
+
var _node$textContent, _metrics$fontBounding, _metrics$fontBounding2;
|
|
363
|
+
var node = _step2.value;
|
|
364
|
+
if (node.nodeType !== Node.TEXT_NODE || !((_node$textContent = node.textContent) !== null && _node$textContent !== void 0 && _node$textContent.trim())) {
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
var range = document.createRange();
|
|
368
|
+
range.selectNodeContents(node);
|
|
369
|
+
var rect = range.getBoundingClientRect();
|
|
370
|
+
context.font = [style.fontStyle, style.fontWeight, style.fontSize, style.fontFamily].filter(Boolean).join(" ");
|
|
371
|
+
context.fillStyle = style.color;
|
|
372
|
+
context.textBaseline = "alphabetic";
|
|
373
|
+
var metrics = context.measureText(node.textContent);
|
|
374
|
+
var fontSize = parseFloat(style.fontSize);
|
|
375
|
+
var ascent = (_metrics$fontBounding = metrics.fontBoundingBoxAscent) !== null && _metrics$fontBounding !== void 0 ? _metrics$fontBounding : fontSize * 0.8;
|
|
376
|
+
var descent = (_metrics$fontBounding2 = metrics.fontBoundingBoxDescent) !== null && _metrics$fontBounding2 !== void 0 ? _metrics$fontBounding2 : fontSize * 0.2;
|
|
377
|
+
var x = rect.left - sourceRect.left;
|
|
378
|
+
var y = rect.top - sourceRect.top + (rect.height - ascent - descent) / 2 + ascent;
|
|
379
|
+
context.fillText(node.textContent, x, y);
|
|
380
|
+
}
|
|
381
|
+
} catch (err) {
|
|
382
|
+
_iterator2.e(err);
|
|
383
|
+
} finally {
|
|
384
|
+
_iterator2.f();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}, {
|
|
388
|
+
key: "captureImage",
|
|
389
|
+
value: function captureImage(image, width, height) {
|
|
390
|
+
var pixelRatio = window.devicePixelRatio || 1;
|
|
391
|
+
var canvas = document.createElement("canvas");
|
|
392
|
+
canvas.width = Math.max(1, Math.round(width * pixelRatio));
|
|
393
|
+
canvas.height = Math.max(1, Math.round(height * pixelRatio));
|
|
394
|
+
canvas.style.width = "".concat(width, "px");
|
|
395
|
+
canvas.style.height = "".concat(height, "px");
|
|
396
|
+
var context = canvas.getContext("2d");
|
|
397
|
+
if (!context) {
|
|
398
|
+
throw new Error("Could not create a 2D context for explodeChildren image capture.");
|
|
399
|
+
}
|
|
400
|
+
context.scale(pixelRatio, pixelRatio);
|
|
401
|
+
context.drawImage(image, 0, 0, width, height);
|
|
402
|
+
return {
|
|
403
|
+
canvas: canvas,
|
|
404
|
+
width: width,
|
|
405
|
+
height: height,
|
|
406
|
+
pixelRatio: pixelRatio
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}]);
|
|
410
|
+
}();
|
|
411
|
+
export { HtmlToCanvas };
|
package/build/LocationManager.js
CHANGED
|
@@ -28,7 +28,7 @@ import { TargetData } from "./TargetData.js";
|
|
|
28
28
|
import { TModelUtil } from "./TModelUtil.js";
|
|
29
29
|
import { ScheduleUtil } from "./ScheduleUtil.js";
|
|
30
30
|
import { TargetExecutor } from "./TargetExecutor.js";
|
|
31
|
-
import { getTargetManager, tRoot, getEvents, getAnimationManager, getManager } from "./App.js";
|
|
31
|
+
import { getTargetManager, getRunScheduler, tRoot, getEvents, getAnimationManager, getManager } from "./App.js";
|
|
32
32
|
|
|
33
33
|
/*
|
|
34
34
|
* It calculates the locations and dimensions of all objects and triggers the calculation of all targets.
|
|
@@ -132,13 +132,13 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
132
132
|
case 14:
|
|
133
133
|
this.processAfterStack();
|
|
134
134
|
this.calcBusy = false;
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
if (this.calcQueued) {
|
|
136
|
+
this.calcQueued = false;
|
|
137
|
+
getRunScheduler().schedule(1, "queuedLocationCalculation");
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
case
|
|
139
|
+
|
|
140
|
+
//console.log(this.locationListStats.length);
|
|
141
|
+
case 17:
|
|
142
142
|
case "end":
|
|
143
143
|
return _context.stop();
|
|
144
144
|
}
|
|
@@ -254,6 +254,9 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
254
254
|
var previousAbsX = child.absX;
|
|
255
255
|
var previousAbsY = child.absY;
|
|
256
256
|
_this.calcNextLocation(child, container, viewport);
|
|
257
|
+
if (child.isIncluded() && child.activateChangedPassiveTargets()) {
|
|
258
|
+
_this.calcQueued = true;
|
|
259
|
+
}
|
|
257
260
|
var positionChanged = child.absX !== previousAbsX || child.absY !== previousAbsY;
|
|
258
261
|
var needsRefresh = child.visibilityDirty || child.hasChildren() && child.isVisible() && positionChanged;
|
|
259
262
|
if (child.getDirtyLayout()) {
|
|
@@ -275,15 +278,20 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
275
278
|
if (child.isDomIsland()) {
|
|
276
279
|
_this.domIslandSet.add(child);
|
|
277
280
|
}
|
|
281
|
+
var previousLayoutX = child.x;
|
|
282
|
+
var previousLayoutY = child.y;
|
|
278
283
|
viewport.setLocation();
|
|
279
284
|
if (viewport.isOverflow()) {
|
|
280
285
|
viewport.overflow();
|
|
281
286
|
viewport.setLocation();
|
|
282
|
-
child.
|
|
287
|
+
if (child.x !== previousLayoutX || child.y !== previousLayoutY) {
|
|
288
|
+
child.markLayoutDirty('overflow');
|
|
289
|
+
}
|
|
283
290
|
}
|
|
284
291
|
var prevX = Math.floor(child.actualValues.x);
|
|
285
292
|
var prevY = Math.floor(child.actualValues.y);
|
|
286
293
|
if (child.isIncluded()) {
|
|
294
|
+
child.activateChangedPassiveTargets();
|
|
287
295
|
_this.calculateTargets(child);
|
|
288
296
|
}
|
|
289
297
|
if (child.isIncluded()) {
|
|
@@ -527,12 +535,14 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
527
535
|
if (visible && child.isInFlow()) {
|
|
528
536
|
container.visibleChildren.push(child);
|
|
529
537
|
}
|
|
530
|
-
if (
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
538
|
+
if (child.isInFlow()) {
|
|
539
|
+
if (TUtil.isNumber(child.val("appendNewLine"))) {
|
|
540
|
+
viewport.appendNewLine();
|
|
541
|
+
} else {
|
|
542
|
+
viewport.nextLocation();
|
|
543
|
+
}
|
|
544
|
+
container.calcContentWidthHeight();
|
|
534
545
|
}
|
|
535
|
-
container.calcContentWidthHeight();
|
|
536
546
|
}
|
|
537
547
|
}, {
|
|
538
548
|
key: "calculateVisibility",
|
|
@@ -562,8 +572,10 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
562
572
|
tmodel.actualValues.isVisible = nowVisible;
|
|
563
573
|
}
|
|
564
574
|
if (tmodel.isNowVisible || tmodel.isNowInvisible) {
|
|
575
|
+
var _tmodel$onVisibilityC;
|
|
565
576
|
tmodel.markLayoutDirty('isNowVisible');
|
|
566
577
|
this.addToLocationList(tmodel);
|
|
578
|
+
(_tmodel$onVisibilityC = tmodel.onVisibilityChange) === null || _tmodel$onVisibilityC === void 0 || _tmodel$onVisibilityC.call(tmodel, nowVisible);
|
|
567
579
|
}
|
|
568
580
|
if (tmodel.isNowVisible && tmodel.hasChildren()) {
|
|
569
581
|
tmodel.visibilityDirty = true;
|
|
@@ -576,6 +588,9 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
576
588
|
}, {
|
|
577
589
|
key: "calculateTargets",
|
|
578
590
|
value: function calculateTargets(tmodel) {
|
|
591
|
+
if (tmodel.hasDomNow) {
|
|
592
|
+
this.retryDomTargets(tmodel);
|
|
593
|
+
}
|
|
579
594
|
this.checkInternalEvents(tmodel);
|
|
580
595
|
var guard = 0;
|
|
581
596
|
while (tmodel.activatedTargets.length && guard++ < 50) {
|
|
@@ -595,7 +610,6 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
595
610
|
}
|
|
596
611
|
}
|
|
597
612
|
ScheduleUtil.pauseResumeSchedule(tmodel);
|
|
598
|
-
tmodel.activateChangedPassiveTargets();
|
|
599
613
|
getTargetManager().applyTargetValues(tmodel);
|
|
600
614
|
if (tmodel.updatingTargetList.length > 0) {
|
|
601
615
|
getTargetManager().setActualValues(tmodel, tmodel.updatingTargetList);
|
|
@@ -740,6 +754,22 @@ var LocationManager = /*#__PURE__*/function () {
|
|
|
740
754
|
}
|
|
741
755
|
});
|
|
742
756
|
}
|
|
757
|
+
}, {
|
|
758
|
+
key: "retryDomTargets",
|
|
759
|
+
value: function retryDomTargets(tmodel) {
|
|
760
|
+
var _onDomReady$value;
|
|
761
|
+
var onDomReady = tmodel.targets.onDomReady;
|
|
762
|
+
var value = (_onDomReady$value = onDomReady === null || onDomReady === void 0 ? void 0 : onDomReady.value) !== null && _onDomReady$value !== void 0 ? _onDomReady$value : onDomReady;
|
|
763
|
+
if (!value) {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
var targets = Array.isArray(value) ? value : [value];
|
|
767
|
+
targets.forEach(function (targetName) {
|
|
768
|
+
if (!targetName.endsWith("$")) {
|
|
769
|
+
TargetUtil.activateSingleTarget(tmodel, targetName);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
}
|
|
743
773
|
}, {
|
|
744
774
|
key: "addToLocationList",
|
|
745
775
|
value: function addToLocationList(tmodel) {
|