targetj 1.0.256 → 1.0.258

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.
@@ -0,0 +1,600 @@
1
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
4
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
5
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
+ 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; } } }; }
11
+ 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; } }
12
+ 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; }
13
+ 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); }
14
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
15
+ 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); } }
16
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
18
+ 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); }
19
+ import { TUtil } from "./TUtil.js";
20
+ var TMODEL_REF_KEY = "__targetjsTModelRef";
21
+
22
+ /*
23
+ * These fields are reconstructed separately or must be connected to the
24
+ * current DOM rather than copied from the old tree.
25
+ */
26
+ var EXCLUDED_RUNTIME_FIELDS = new Set(["_state", "targets", "targetDefinitions", "restoringRuntime", "restoredUsesExistingDom", "type", "oid", "oidNum", "originalId", "parent", "allChildrenList", "allChildrenMap", "$dom", "viewport", "visibilityStatus", "currentStatus", "dirtyLayout", "originWindowEpoch", "hasDomNow", "isNowVisible", "domHeightTimestamp", "domWidthTimestamp", "lastBatch", "waapiBatch", "finalKeyframe", "finalRawFrame"]);
27
+ var CHILD_OPERATION_FIELDS = ["addedChildren", "deletedChildren", "movedChildren"];
28
+ var RUNTIME_TIMESTAMP_FIELDS = new Set(["lastUpdate", "scheduleTimeStamp", "completeTime", "creationTime", "activationTime", "catchupAt", "startTime", "lastResizeHandledTime"]);
29
+ var TARGET_RUNTIME_FIELDS = ["originalTargetName", "originalTModel", "invokerTargetName", "invokerTModel", "fetchAction", "childAction", "addChildAction"];
30
+
31
+ /**
32
+ * Creates and restores in-memory TargetJS runtime snapshots.
33
+ *
34
+ * The snapshot is not JSON serialization. Functions and non-plain class
35
+ * instances remain shared references.
36
+ */
37
+ var StateUtil = /*#__PURE__*/function () {
38
+ function StateUtil() {
39
+ _classCallCheck(this, StateUtil);
40
+ }
41
+ return _createClass(StateUtil, null, [{
42
+ key: "rebaseRuntimeTimes",
43
+ value: function rebaseRuntimeTimes(value, offset) {
44
+ var seen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
45
+ if (!value || _typeof(value) !== "object" || offset === 0 || StateUtil.isTModel(value) || seen.has(value)) {
46
+ return;
47
+ }
48
+ seen.add(value);
49
+ if (value instanceof Map) {
50
+ var _iterator = _createForOfIteratorHelper(value.values()),
51
+ _step;
52
+ try {
53
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
54
+ var mapValue = _step.value;
55
+ StateUtil.rebaseRuntimeTimes(mapValue, offset, seen);
56
+ }
57
+ } catch (err) {
58
+ _iterator.e(err);
59
+ } finally {
60
+ _iterator.f();
61
+ }
62
+ return;
63
+ }
64
+ if (value instanceof Set) {
65
+ var _iterator2 = _createForOfIteratorHelper(value),
66
+ _step2;
67
+ try {
68
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
69
+ var item = _step2.value;
70
+ StateUtil.rebaseRuntimeTimes(item, offset, seen);
71
+ }
72
+ } catch (err) {
73
+ _iterator2.e(err);
74
+ } finally {
75
+ _iterator2.f();
76
+ }
77
+ return;
78
+ }
79
+ for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
80
+ var key = _Object$keys[_i];
81
+ var propertyValue = value[key];
82
+ if (RUNTIME_TIMESTAMP_FIELDS.has(key) && Number.isFinite(propertyValue) && propertyValue > 0) {
83
+ value[key] = propertyValue + offset;
84
+ continue;
85
+ }
86
+ StateUtil.rebaseRuntimeTimes(propertyValue, offset, seen);
87
+ }
88
+ }
89
+ }, {
90
+ key: "isPlainObject",
91
+ value: function isPlainObject(value) {
92
+ if (!value || _typeof(value) !== "object") {
93
+ return false;
94
+ }
95
+ var prototype = Object.getPrototypeOf(value);
96
+ return prototype === Object.prototype || prototype === null;
97
+ }
98
+ }, {
99
+ key: "cloneUnboundTargets",
100
+ value: function cloneUnboundTargets(targets) {
101
+ var cloned = TUtil.cloneTargetDefinition(targets);
102
+ for (var _i2 = 0, _Object$values = Object.values(cloned); _i2 < _Object$values.length; _i2++) {
103
+ var target = _Object$values[_i2];
104
+ if (!StateUtil.isPlainObject(target)) {
105
+ continue;
106
+ }
107
+ for (var _i3 = 0, _Object$keys2 = Object.keys(target); _i3 < _Object$keys2.length; _i3++) {
108
+ var key = _Object$keys2[_i3];
109
+ var value = target[key];
110
+ if (typeof value === "function" && value.__isBoundTargetMethod) {
111
+ target[key] = value.__targetjsSource || value;
112
+ }
113
+ }
114
+ }
115
+ return cloned;
116
+ }
117
+ }, {
118
+ key: "isTModel",
119
+ value: function isTModel(value) {
120
+ return Boolean(value && _typeof(value) === "object" && typeof value.oid === "string" && value.targets && typeof value.state === "function" && typeof value.getChildren === "function");
121
+ }
122
+ }, {
123
+ key: "isTModelReference",
124
+ value: function isTModelReference(value) {
125
+ return Boolean(StateUtil.isPlainObject(value) && Object.prototype.hasOwnProperty.call(value, TMODEL_REF_KEY));
126
+ }
127
+ }, {
128
+ key: "createTModelReference",
129
+ value: function createTModelReference(tmodel) {
130
+ return _defineProperty({}, TMODEL_REF_KEY, tmodel.oid);
131
+ }
132
+ }, {
133
+ key: "encodeValue",
134
+ value: function encodeValue(value) {
135
+ var seen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakMap();
136
+ if (value === null || value === undefined || _typeof(value) !== "object") {
137
+ return value;
138
+ }
139
+ if (StateUtil.isTModel(value)) {
140
+ return StateUtil.createTModelReference(value);
141
+ }
142
+ if (seen.has(value)) {
143
+ return seen.get(value);
144
+ }
145
+ if (value instanceof Date) {
146
+ return new Date(value.getTime());
147
+ }
148
+ if (value instanceof Map) {
149
+ var _copy = new Map();
150
+ seen.set(value, _copy);
151
+ var _iterator3 = _createForOfIteratorHelper(value),
152
+ _step3;
153
+ try {
154
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
155
+ var _step3$value = _slicedToArray(_step3.value, 2),
156
+ key = _step3$value[0],
157
+ mapValue = _step3$value[1];
158
+ _copy.set(StateUtil.encodeValue(key, seen), StateUtil.encodeValue(mapValue, seen));
159
+ }
160
+ } catch (err) {
161
+ _iterator3.e(err);
162
+ } finally {
163
+ _iterator3.f();
164
+ }
165
+ return _copy;
166
+ }
167
+ if (value instanceof Set) {
168
+ var _copy2 = new Set();
169
+ seen.set(value, _copy2);
170
+ var _iterator4 = _createForOfIteratorHelper(value),
171
+ _step4;
172
+ try {
173
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
174
+ var item = _step4.value;
175
+ _copy2.add(StateUtil.encodeValue(item, seen));
176
+ }
177
+ } catch (err) {
178
+ _iterator4.e(err);
179
+ } finally {
180
+ _iterator4.f();
181
+ }
182
+ return _copy2;
183
+ }
184
+ if (Array.isArray(value)) {
185
+ var _copy3 = [];
186
+ seen.set(value, _copy3);
187
+ var _iterator5 = _createForOfIteratorHelper(value),
188
+ _step5;
189
+ try {
190
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
191
+ var _item = _step5.value;
192
+ _copy3.push(StateUtil.encodeValue(_item, seen));
193
+ }
194
+ } catch (err) {
195
+ _iterator5.e(err);
196
+ } finally {
197
+ _iterator5.f();
198
+ }
199
+ return _copy3;
200
+ }
201
+ if (!StateUtil.isPlainObject(value)) {
202
+ return value;
203
+ }
204
+ var copy = {};
205
+ seen.set(value, copy);
206
+ for (var _i4 = 0, _Object$entries = Object.entries(value); _i4 < _Object$entries.length; _i4++) {
207
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i4], 2),
208
+ _key = _Object$entries$_i[0],
209
+ propertyValue = _Object$entries$_i[1];
210
+ copy[_key] = StateUtil.encodeValue(propertyValue, seen);
211
+ }
212
+ return copy;
213
+ }
214
+ }, {
215
+ key: "decodeValue",
216
+ value: function decodeValue(value, tmodelIdMap) {
217
+ var seen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakMap();
218
+ if (value === null || value === undefined || _typeof(value) !== "object") {
219
+ return value;
220
+ }
221
+ if (StateUtil.isTModelReference(value)) {
222
+ return tmodelIdMap[value[TMODEL_REF_KEY]];
223
+ }
224
+ if (seen.has(value)) {
225
+ return seen.get(value);
226
+ }
227
+ if (value instanceof Date) {
228
+ return new Date(value.getTime());
229
+ }
230
+ if (value instanceof Map) {
231
+ var _copy4 = new Map();
232
+ seen.set(value, _copy4);
233
+ var _iterator6 = _createForOfIteratorHelper(value),
234
+ _step6;
235
+ try {
236
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
237
+ var _step6$value = _slicedToArray(_step6.value, 2),
238
+ key = _step6$value[0],
239
+ mapValue = _step6$value[1];
240
+ _copy4.set(StateUtil.decodeValue(key, tmodelIdMap, seen), StateUtil.decodeValue(mapValue, tmodelIdMap, seen));
241
+ }
242
+ } catch (err) {
243
+ _iterator6.e(err);
244
+ } finally {
245
+ _iterator6.f();
246
+ }
247
+ return _copy4;
248
+ }
249
+ if (value instanceof Set) {
250
+ var _copy5 = new Set();
251
+ seen.set(value, _copy5);
252
+ var _iterator7 = _createForOfIteratorHelper(value),
253
+ _step7;
254
+ try {
255
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
256
+ var item = _step7.value;
257
+ _copy5.add(StateUtil.decodeValue(item, tmodelIdMap, seen));
258
+ }
259
+ } catch (err) {
260
+ _iterator7.e(err);
261
+ } finally {
262
+ _iterator7.f();
263
+ }
264
+ return _copy5;
265
+ }
266
+ if (Array.isArray(value)) {
267
+ var _copy6 = [];
268
+ seen.set(value, _copy6);
269
+ var _iterator8 = _createForOfIteratorHelper(value),
270
+ _step8;
271
+ try {
272
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
273
+ var _item2 = _step8.value;
274
+ _copy6.push(StateUtil.decodeValue(_item2, tmodelIdMap, seen));
275
+ }
276
+ } catch (err) {
277
+ _iterator8.e(err);
278
+ } finally {
279
+ _iterator8.f();
280
+ }
281
+ return _copy6;
282
+ }
283
+ if (!StateUtil.isPlainObject(value)) {
284
+ return value;
285
+ }
286
+ var copy = {};
287
+ seen.set(value, copy);
288
+ for (var _i5 = 0, _Object$entries2 = Object.entries(value); _i5 < _Object$entries2.length; _i5++) {
289
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i5], 2),
290
+ _key2 = _Object$entries2$_i[0],
291
+ propertyValue = _Object$entries2$_i[1];
292
+ copy[_key2] = StateUtil.decodeValue(propertyValue, tmodelIdMap, seen);
293
+ }
294
+ return copy;
295
+ }
296
+ }, {
297
+ key: "resolveTModelReferencesInPlace",
298
+ value: function resolveTModelReferencesInPlace(value, tmodelIdMap) {
299
+ var seen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
300
+ if (value === null || value === undefined || _typeof(value) !== "object") {
301
+ return value;
302
+ }
303
+ if (StateUtil.isTModelReference(value)) {
304
+ return tmodelIdMap[value[TMODEL_REF_KEY]];
305
+ }
306
+ if (seen.has(value)) {
307
+ return value;
308
+ }
309
+ seen.add(value);
310
+ if (value instanceof Date) {
311
+ return value;
312
+ }
313
+ if (value instanceof Map) {
314
+ var entries = _toConsumableArray(value.entries());
315
+ value.clear();
316
+ var _iterator9 = _createForOfIteratorHelper(entries),
317
+ _step9;
318
+ try {
319
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
320
+ var _step9$value = _slicedToArray(_step9.value, 2),
321
+ key = _step9$value[0],
322
+ mapValue = _step9$value[1];
323
+ value.set(StateUtil.resolveTModelReferencesInPlace(key, tmodelIdMap, seen), StateUtil.resolveTModelReferencesInPlace(mapValue, tmodelIdMap, seen));
324
+ }
325
+ } catch (err) {
326
+ _iterator9.e(err);
327
+ } finally {
328
+ _iterator9.f();
329
+ }
330
+ return value;
331
+ }
332
+ if (value instanceof Set) {
333
+ var _entries = _toConsumableArray(value);
334
+ value.clear();
335
+ var _iterator10 = _createForOfIteratorHelper(_entries),
336
+ _step10;
337
+ try {
338
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
339
+ var item = _step10.value;
340
+ value.add(StateUtil.resolveTModelReferencesInPlace(item, tmodelIdMap, seen));
341
+ }
342
+ } catch (err) {
343
+ _iterator10.e(err);
344
+ } finally {
345
+ _iterator10.f();
346
+ }
347
+ return value;
348
+ }
349
+ if (Array.isArray(value)) {
350
+ for (var index = 0; index < value.length; index++) {
351
+ value[index] = StateUtil.resolveTModelReferencesInPlace(value[index], tmodelIdMap, seen);
352
+ }
353
+ return value;
354
+ }
355
+ if (!StateUtil.isPlainObject(value)) {
356
+ return value;
357
+ }
358
+ for (var _i6 = 0, _Object$keys3 = Object.keys(value); _i6 < _Object$keys3.length; _i6++) {
359
+ var _key3 = _Object$keys3[_i6];
360
+ value[_key3] = StateUtil.resolveTModelReferencesInPlace(value[_key3], tmodelIdMap, seen);
361
+ }
362
+ return value;
363
+ }
364
+ }, {
365
+ key: "clearMaterializedChildOperations",
366
+ value: function clearMaterializedChildOperations(state) {
367
+ if (!state) {
368
+ return;
369
+ }
370
+ for (var _i7 = 0, _CHILD_OPERATION_FIEL = CHILD_OPERATION_FIELDS; _i7 < _CHILD_OPERATION_FIEL.length; _i7++) {
371
+ var key = _CHILD_OPERATION_FIEL[_i7];
372
+ if (Array.isArray(state[key])) {
373
+ state[key].length = 0;
374
+ } else {
375
+ state[key] = [];
376
+ }
377
+ }
378
+ if (!state.lastChildrenUpdate) {
379
+ state.lastChildrenUpdate = {
380
+ additions: [],
381
+ deletions: []
382
+ };
383
+ return;
384
+ }
385
+ state.lastChildrenUpdate.additions = [];
386
+ state.lastChildrenUpdate.deletions = [];
387
+ }
388
+ }, {
389
+ key: "exportRuntimeState",
390
+ value: function exportRuntimeState(tmodel) {
391
+ var fields = {};
392
+ for (var _i8 = 0, _Object$keys4 = Object.keys(tmodel); _i8 < _Object$keys4.length; _i8++) {
393
+ var key = _Object$keys4[_i8];
394
+ if (EXCLUDED_RUNTIME_FIELDS.has(key)) {
395
+ continue;
396
+ }
397
+ fields[key] = tmodel[key];
398
+ }
399
+ var runtime = StateUtil.encodeValue({
400
+ state: tmodel.state(),
401
+ fields: fields
402
+ });
403
+ StateUtil.clearMaterializedChildOperations(runtime.state);
404
+ return runtime;
405
+ }
406
+ }, {
407
+ key: "importRuntimeState",
408
+ value: function importRuntimeState(tmodel, runtime, tmodelIdMap) {
409
+ var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
410
+ _ref2$timeOffset = _ref2.timeOffset,
411
+ timeOffset = _ref2$timeOffset === void 0 ? 0 : _ref2$timeOffset;
412
+ var restored = StateUtil.decodeValue(runtime, tmodelIdMap);
413
+ StateUtil.rebaseRuntimeTimes(restored, timeOffset);
414
+ tmodel._state = restored.state || {};
415
+ for (var _i9 = 0, _Object$entries3 = Object.entries(restored.fields || {}); _i9 < _Object$entries3.length; _i9++) {
416
+ var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i9], 2),
417
+ key = _Object$entries3$_i[0],
418
+ value = _Object$entries3$_i[1];
419
+ if (EXCLUDED_RUNTIME_FIELDS.has(key)) {
420
+ continue;
421
+ }
422
+ tmodel[key] = value;
423
+ }
424
+ StateUtil.clearMaterializedChildOperations(tmodel._state);
425
+
426
+ /*
427
+ * The child tree has already been reconstructed directly.
428
+ */
429
+ tmodel.childrenUpdateFlag = false;
430
+
431
+ /*
432
+ * DOM and Web Animation objects belong to the old runtime.
433
+ */
434
+ tmodel.$dom = null;
435
+ tmodel.viewport = undefined;
436
+ tmodel.hasDomNow = false;
437
+ tmodel.lastBatch = undefined;
438
+ tmodel.waapiBatch = undefined;
439
+ tmodel.finalKeyframe = undefined;
440
+ tmodel.finalRawFrame = undefined;
441
+ return tmodel;
442
+ }
443
+ }, {
444
+ key: "createRuntimeSnapshot",
445
+ value: function createRuntimeSnapshot(tmodel) {
446
+ var _tmodel$oidNum, _tmodel$targets, _tmodel$targets2, _tmodel$originalTarge;
447
+ var children = _toConsumableArray(tmodel.getChildren());
448
+ var targetDefinitions = TUtil.cloneTargetDefinition(tmodel.targetDefinitions);
449
+ return {
450
+ oid: tmodel.oid,
451
+ oidNum: (_tmodel$oidNum = tmodel.oidNum) !== null && _tmodel$oidNum !== void 0 ? _tmodel$oidNum : 0,
452
+ originalId: tmodel.originalId,
453
+ type: tmodel.type,
454
+ usesExistingDom: ((_tmodel$targets = tmodel.targets) === null || _tmodel$targets === void 0 ? void 0 : _tmodel$targets.domIsland) === true || ((_tmodel$targets2 = tmodel.targets) === null || _tmodel$targets2 === void 0 ? void 0 : _tmodel$targets2.reuseDomDefinition) === true || ((_tmodel$originalTarge = tmodel.originalTargetNames) === null || _tmodel$originalTarge === void 0 ? void 0 : _tmodel$originalTarge.includes('$dom')),
455
+ targets: StateUtil.encodeValue(targetDefinitions),
456
+ targetRuntime: StateUtil.exportTargetRuntime(tmodel),
457
+ runtime: StateUtil.exportRuntimeState(tmodel),
458
+ children: children.map(function (child) {
459
+ return StateUtil.createRuntimeSnapshot(child);
460
+ })
461
+ };
462
+ }
463
+ }, {
464
+ key: "createWithIdentity",
465
+ value: function createWithIdentity(snapshot, TModelClass) {
466
+ var _snapshot$oidNum;
467
+ if (typeof TModelClass !== "function") {
468
+ throw new TypeError("A TModel constructor is required.");
469
+ }
470
+ var targets = StateUtil.encodeValue(snapshot.targets);
471
+ var tmodel = new TModelClass(snapshot.type, targets, snapshot.oid, {
472
+ restoringRuntime: true,
473
+ usesExistingDom: snapshot.usesExistingDom === true
474
+ });
475
+ tmodel.type = snapshot.type;
476
+ tmodel.oid = snapshot.oid;
477
+ tmodel.oidNum = (_snapshot$oidNum = snapshot.oidNum) !== null && _snapshot$oidNum !== void 0 ? _snapshot$oidNum : 0;
478
+ if (snapshot.originalId !== undefined) {
479
+ tmodel.originalId = snapshot.originalId;
480
+ } else {
481
+ delete tmodel.originalId;
482
+ }
483
+
484
+ /*
485
+ * Tree relationships are restored without using addChild().
486
+ */
487
+ tmodel.parent = undefined;
488
+ tmodel.allChildrenList = [];
489
+ tmodel.allChildrenMap = {};
490
+ return tmodel;
491
+ }
492
+ }, {
493
+ key: "attachRestoredChild",
494
+ value: function attachRestoredChild(parent, child) {
495
+ child.parent = parent;
496
+ parent.allChildrenList.push(child);
497
+ parent.allChildrenMap[child.oid] = child;
498
+ return child;
499
+ }
500
+ }, {
501
+ key: "fromRuntimeSnapshot",
502
+ value: function fromRuntimeSnapshot(snapshot, TModelClass) {
503
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
504
+ if (!snapshot) {
505
+ throw new TypeError("A runtime snapshot is required.");
506
+ }
507
+ var tmodelIdMap = {};
508
+ var models = [];
509
+ var imports = [];
510
+ var _buildTree = function buildTree(modelSnapshot, parent) {
511
+ var tmodel = StateUtil.createWithIdentity(modelSnapshot, TModelClass);
512
+ tmodelIdMap[tmodel.oid] = tmodel;
513
+ models.push(tmodel);
514
+ if (parent) {
515
+ StateUtil.attachRestoredChild(parent, tmodel);
516
+ }
517
+ imports.push({
518
+ tmodel: tmodel,
519
+ runtime: modelSnapshot.runtime,
520
+ targetRuntime: modelSnapshot.targetRuntime
521
+ });
522
+ var _iterator11 = _createForOfIteratorHelper(modelSnapshot.children || []),
523
+ _step11;
524
+ try {
525
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
526
+ var childSnapshot = _step11.value;
527
+ _buildTree(childSnapshot, tmodel);
528
+ }
529
+ } catch (err) {
530
+ _iterator11.e(err);
531
+ } finally {
532
+ _iterator11.f();
533
+ }
534
+ return tmodel;
535
+ };
536
+ var root = _buildTree(snapshot, undefined);
537
+ for (var _i10 = 0, _models = models; _i10 < _models.length; _i10++) {
538
+ var tmodel = _models[_i10];
539
+ StateUtil.resolveTModelReferencesInPlace(tmodel.targets, tmodelIdMap);
540
+ }
541
+ for (var _i11 = 0, _imports = imports; _i11 < _imports.length; _i11++) {
542
+ var _imports$_i = _imports[_i11],
543
+ _tmodel = _imports$_i.tmodel,
544
+ targetRuntime = _imports$_i.targetRuntime;
545
+ StateUtil.applyTargetRuntime(_tmodel, targetRuntime, tmodelIdMap);
546
+ }
547
+ for (var _i12 = 0, _imports2 = imports; _i12 < _imports2.length; _i12++) {
548
+ var _imports2$_i = _imports2[_i12],
549
+ _tmodel2 = _imports2$_i.tmodel,
550
+ runtime = _imports2$_i.runtime;
551
+ StateUtil.importRuntimeState(_tmodel2, runtime, tmodelIdMap, options);
552
+ }
553
+ return {
554
+ root: root,
555
+ tmodelIdMap: tmodelIdMap,
556
+ models: models
557
+ };
558
+ }
559
+ }, {
560
+ key: "exportTargetRuntime",
561
+ value: function exportTargetRuntime(tmodel) {
562
+ var result = {};
563
+ for (var _i13 = 0, _Object$entries4 = Object.entries(tmodel.targets); _i13 < _Object$entries4.length; _i13++) {
564
+ var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i13], 2),
565
+ targetName = _Object$entries4$_i[0],
566
+ target = _Object$entries4$_i[1];
567
+ if (!StateUtil.isPlainObject(target)) {
568
+ continue;
569
+ }
570
+ var runtime = {};
571
+ for (var _i14 = 0, _TARGET_RUNTIME_FIELD = TARGET_RUNTIME_FIELDS; _i14 < _TARGET_RUNTIME_FIELD.length; _i14++) {
572
+ var field = _TARGET_RUNTIME_FIELD[_i14];
573
+ if (Object.prototype.hasOwnProperty.call(target, field)) {
574
+ runtime[field] = target[field];
575
+ }
576
+ }
577
+ if (Object.keys(runtime).length) {
578
+ result[targetName] = StateUtil.encodeValue(runtime);
579
+ }
580
+ }
581
+ return result;
582
+ }
583
+ }, {
584
+ key: "applyTargetRuntime",
585
+ value: function applyTargetRuntime(tmodel, encodedTargetRuntime, tmodelIdMap) {
586
+ for (var _i15 = 0, _Object$entries5 = Object.entries(encodedTargetRuntime || {}); _i15 < _Object$entries5.length; _i15++) {
587
+ var _Object$entries5$_i = _slicedToArray(_Object$entries5[_i15], 2),
588
+ targetName = _Object$entries5$_i[0],
589
+ encodedRuntime = _Object$entries5$_i[1];
590
+ var target = tmodel.targets[targetName];
591
+ if (!target) {
592
+ continue;
593
+ }
594
+ var runtime = StateUtil.decodeValue(encodedRuntime, tmodelIdMap);
595
+ Object.assign(target, runtime);
596
+ }
597
+ }
598
+ }]);
599
+ }();
600
+ export { StateUtil };
package/build/TModel.js CHANGED
@@ -28,6 +28,7 @@ import { SearchUtil } from "./SearchUtil.js";
28
28
  import { TargetUtil } from "./TargetUtil.js";
29
29
  import { TModelUtil } from "./TModelUtil.js";
30
30
  import { DomInit } from "./DomInit.js";
31
+ import { StateUtil } from "./StateUtil.js";
31
32
 
32
33
  /**
33
34
  * It provides the base class for all objects in an app where targets are defined.
@@ -36,8 +37,9 @@ import { DomInit } from "./DomInit.js";
36
37
  var TModel = /*#__PURE__*/function (_BaseModel) {
37
38
  function TModel(type, targets, oid) {
38
39
  var _this;
40
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
39
41
  _classCallCheck(this, TModel);
40
- _this = _callSuper(this, TModel, [type, targets, oid]);
42
+ _this = _callSuper(this, TModel, [type, targets, oid, options]);
41
43
  _this.allChildrenList = [];
42
44
  _this.allChildrenMap = {};
43
45
  _this.childrenUpdateFlag = false;
@@ -61,6 +63,7 @@ var TModel = /*#__PURE__*/function (_BaseModel) {
61
63
  _this.dirtyLayout = false;
62
64
  _this.originWindowEpoch = -1;
63
65
  _this.initTargets();
66
+ _this.restoringRuntime = false;
64
67
  return _this;
65
68
  }
66
69
  _inherits(TModel, _BaseModel);
@@ -127,8 +130,8 @@ var TModel = /*#__PURE__*/function (_BaseModel) {
127
130
  this.removeFromActiveChildren(child);
128
131
  this.removeFromAnimatingChildren(child);
129
132
  this.childrenUpdateFlag = true;
130
- getLocationManager().calcChildren(this);
131
133
  this.markLayoutDirty('removeChild');
134
+ getLocationManager().calcChildren(this);
132
135
  getRunScheduler().schedule(1, 'removeChild-' + child.oid);
133
136
  return this;
134
137
  }
@@ -1157,6 +1160,11 @@ var TModel = /*#__PURE__*/function (_BaseModel) {
1157
1160
  value: function reuseDomDefinition() {
1158
1161
  return this.val('reuseDomDefinition');
1159
1162
  }
1163
+ }, {
1164
+ key: "createRuntimeSnapshot",
1165
+ value: function createRuntimeSnapshot() {
1166
+ return StateUtil.createRuntimeSnapshot(this);
1167
+ }
1160
1168
  }]);
1161
1169
  }(BaseModel);
1162
1170
  export { TModel };