targetj 1.0.206 → 1.0.208

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/Export.js CHANGED
@@ -14,6 +14,7 @@ export * from "./build/BracketGenerator.js";
14
14
  export * from "./build/ColorUtil.js";
15
15
  export * from "./build/Easing.js";
16
16
  export * from "./build/TargetExecutor.js";
17
+ export * from "./build/AnimationManager.js";
17
18
 
18
19
  import * as App from './build/App.js';
19
20
  import * as TModel from './build/TModel.js';
@@ -31,6 +32,7 @@ import * as BracketGenerator from './build/BracketGenerator.js';
31
32
  import * as ColorUtil from './build/ColorUtil.js';
32
33
  import * as Easing from './build/Easing.js';
33
34
  import * as TargetExecutor from './build/TargetExecutor.js';
35
+ import * as AnimationManager from './build/AnimationManager.js';
34
36
 
35
37
  const TargetJS = {
36
38
  ...App,
@@ -48,6 +50,7 @@ const TargetJS = {
48
50
  ...ColorUtil,
49
51
  ...Easing,
50
52
  ...TargetExecutor,
53
+ ...AnimationManager
51
54
  };
52
55
 
53
56
  if (typeof window !== 'undefined') {
package/README.md CHANGED
@@ -327,14 +327,26 @@ import { App } from "targetj";
327
327
 
328
328
  **Via CDN**
329
329
 
330
- Add the following `<script>` tag to your HTML to load TargetJS from a CDN (only 67KB):
330
+ Add the following `<script>` tag to your HTML to load TargetJS from a CDN (only 54KB):
331
331
 
332
332
  ```html
333
333
  <script src="https://unpkg.com/targetj@latest/dist/targetjs.js"></script>
334
334
  ```
335
335
 
336
- This will add `TargetJS` to the global `window` object, making it accessible throughout your JavaScript such as `TargetJS.App(YourApp)`.
337
- You can also use it directly in your HTML with `tg-` attributes:
336
+ This exposes `TargetJS` on `window`, so you can initialize your app with `TargetJS.App(...)`. Make sure your code runs after the TargetJS script loads (use `defer` or place your script below it).
337
+
338
+ You can also use it without `App` by mounting a `TModel` object to an HTML element, for example:
339
+
340
+ ```html
341
+ <script>
342
+ new TargetJS.TModel({
343
+ background: 'red',
344
+ width: [100, 50, 10],
345
+ height: [100, 50, 10]
346
+ }).mount(document.body);
347
+ </script>
348
+ ```
349
+ Or, directly in your HTML with `tg-` attributes:
338
350
 
339
351
  ```html
340
352
  <div
package/build/$Dom.js CHANGED
@@ -24,12 +24,37 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
24
24
  } else if (elemSelector) {
25
25
  this.element = elemSelector;
26
26
  }
27
- this.childrenCount = 0;
28
- this.$domParent = undefined;
27
+ this.hasRealChildren = false;
28
+ this.slotModeEnabled = false;
29
+ this.contentSlot = null;
29
30
  this.originalContent = undefined;
30
31
  this.textOnly = true;
32
+ this.transformProp = null;
33
+ this.initTransformProp();
31
34
  }
32
35
  return _createClass($Dom, [{
36
+ key: "create",
37
+ value: function create(tagName) {
38
+ this.element = document.createElement(tagName);
39
+ this.initTransformProp();
40
+ }
41
+ }, {
42
+ key: "initTransformProp",
43
+ value: function initTransformProp() {
44
+ if (!this.element || !this.element.style) {
45
+ this.transformProp = null;
46
+ return;
47
+ }
48
+ var s = this.element.style;
49
+ if ('transform' in s) {
50
+ this.transformProp = 'transform';
51
+ } else if ('webkitTransform' in s) {
52
+ this.transformProp = 'webkitTransform';
53
+ } else {
54
+ this.transformProp = null;
55
+ }
56
+ }
57
+ }, {
33
58
  key: "cloneTemplate",
34
59
  value: function cloneTemplate() {
35
60
  var _this$element$content;
@@ -43,21 +68,90 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
43
68
  }, {
44
69
  key: "exists",
45
70
  value: function exists() {
46
- if (this.selector) {
47
- this.element = $Dom.query(this.selector);
71
+ return this.selector ? !!$Dom.query(this.selector) : false;
72
+ }
73
+ }, {
74
+ key: "getElement",
75
+ value: function getElement() {
76
+ return this.element;
77
+ }
78
+ }, {
79
+ key: "supportsWAAPI",
80
+ value: function supportsWAAPI() {
81
+ return !!(this.element && typeof this.element.animate === 'function');
82
+ }
83
+ }, {
84
+ key: "findContentSlot",
85
+ value: function findContentSlot() {
86
+ if (this.contentSlot && this.contentSlot.parentNode === this.element) {
87
+ return this.contentSlot;
88
+ }
89
+ if (!this.element.firstElementChild) {
90
+ return null;
91
+ }
92
+ var slot = this.element.querySelector(':scope > [data-tj-slot="content"]');
93
+ if (slot) {
94
+ this.contentSlot = slot;
95
+ }
96
+ return slot;
97
+ }
98
+ }, {
99
+ key: "ensureContentSlotFirst",
100
+ value: function ensureContentSlotFirst() {
101
+ var slot = this.findContentSlot();
102
+ if (!slot) {
103
+ slot = document.createElement('div');
104
+ slot.setAttribute('data-tj-slot', 'content');
105
+ this.element.insertBefore(slot, this.element.firstChild);
106
+ this.contentSlot = slot;
107
+ } else if (this.element.firstChild !== slot) {
108
+ this.element.insertBefore(slot, this.element.firstChild);
109
+ }
110
+ return slot;
111
+ }
112
+ }, {
113
+ key: "enableSlotMode",
114
+ value: function enableSlotMode() {
115
+ var _this$element;
116
+ if (this.slotModeEnabled) {
117
+ return;
118
+ }
119
+ if (!((_this$element = this.element) !== null && _this$element !== void 0 && _this$element.firstChild)) {
120
+ this.slotModeEnabled = true;
121
+ return;
122
+ }
123
+ var slot = this.ensureContentSlotFirst();
124
+ var n = slot.nextSibling;
125
+ while (n) {
126
+ var next = n.nextSibling;
127
+ slot.appendChild(n);
128
+ n = next;
129
+ }
130
+ this.slotModeEnabled = true;
131
+ }
132
+ }, {
133
+ key: "ensureSlotMode",
134
+ value: function ensureSlotMode() {
135
+ this.enableSlotMode();
136
+ var slot = this.findContentSlot();
137
+ if (slot && this.element.firstChild !== slot) {
138
+ this.element.insertBefore(slot, this.element.firstChild);
48
139
  }
49
- return this.element ? !!this.element.parentElement : false;
140
+ }
141
+ }, {
142
+ key: "getComputedStyle",
143
+ value: function getComputedStyle(name) {
144
+ if (!this.element) {
145
+ return undefined;
146
+ }
147
+ var cs = window.getComputedStyle(this.element);
148
+ return name ? cs.getPropertyValue(name) || cs[name] : cs;
50
149
  }
51
150
  }, {
52
151
  key: "contains",
53
152
  value: function contains(element) {
54
153
  return element instanceof Node && this.element.contains(element);
55
154
  }
56
- }, {
57
- key: "create",
58
- value: function create(tagName) {
59
- this.element = document.createElement(tagName);
60
- }
61
155
  }, {
62
156
  key: "getTagName",
63
157
  value: function getTagName() {
@@ -192,30 +286,12 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
192
286
  key: "detach",
193
287
  value: function detach() {
194
288
  $Dom.detach(this.element);
195
- if (this.$domParent && this.$domParent.childrenCount > 0) {
196
- this.$domParent.childrenCount--;
197
- }
198
289
  }
199
290
  }, {
200
291
  key: "child",
201
292
  value: function child(index) {
202
293
  return this.element.children[index];
203
294
  }
204
- }, {
205
- key: "append$Dom",
206
- value: function append$Dom($dom) {
207
- this.element.appendChild($dom.element);
208
- }
209
- }, {
210
- key: "appendElement",
211
- value: function appendElement(element) {
212
- this.element.appendChild(element);
213
- }
214
- }, {
215
- key: "removeElement",
216
- value: function removeElement(element) {
217
- this.element.removeChild(element);
218
- }
219
295
  }, {
220
296
  key: "elementCount",
221
297
  value: function elementCount() {
@@ -233,79 +309,123 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
233
309
  }
234
310
  }
235
311
  }, {
236
- key: "insertFirst$Dom",
237
- value: function insertFirst$Dom($dom) {
238
- if (this.element.firstChild) {
239
- this.element.insertBefore($dom.element, this.element.firstChild);
312
+ key: "insertAfterContentSlot",
313
+ value: function insertAfterContentSlot(node) {
314
+ if (!this.element) {
315
+ return;
316
+ }
317
+ var slot = this.ensureContentSlotFirst();
318
+ var after = slot ? slot.nextSibling : this.element.firstChild;
319
+ if (after) {
320
+ this.element.insertBefore(node, after);
240
321
  } else {
241
- this.append$Dom($dom);
322
+ this.element.appendChild(node);
242
323
  }
243
324
  }
325
+ }, {
326
+ key: "insertFirst$Dom",
327
+ value: function insertFirst$Dom($dom) {
328
+ this.ensureSlotMode();
329
+ this.insertAfterContentSlot($dom.element);
330
+ this.hasRealChildren = true;
331
+ }
244
332
  }, {
245
333
  key: "relocate",
246
334
  value: function relocate(tmodel, orderIndex) {
247
- this.element.insertBefore(tmodel.$dom.element, this.element.children[orderIndex]);
335
+ this.ensureSlotMode();
336
+ var slot = this.findContentSlot();
337
+ var offset = slot ? 1 : 0;
338
+ var idx = orderIndex + offset;
339
+ this.element.insertBefore(tmodel.$dom.element, this.element.children[idx] || null);
248
340
  }
249
341
  }, {
250
342
  key: "appendTModel$Dom",
251
343
  value: function appendTModel$Dom(tmodel) {
252
- if (this.childrenCount === 0 && this.element.children.length > 1 && tmodel.getDomParent() && tmodel.getDomParent().getHtml() && tmodel.getDomParent().getHtml() === this.originalContent) {
253
- this.element.innerHTML = "<div>".concat(this.html(), "</div>");
254
- }
344
+ this.ensureSlotMode();
255
345
  this.element.appendChild(tmodel.$dom.element);
256
- tmodel.$dom.$domParent = this;
257
- this.childrenCount++;
346
+ this.hasRealChildren = true;
258
347
  }
259
348
  }, {
260
- key: "deleteAll",
261
- value: function deleteAll() {
262
- this.element.innerHTML = this.originalContent || '';
263
- this.childrenCount = 0;
349
+ key: "append$Dom",
350
+ value: function append$Dom($dom) {
351
+ this.ensureSlotMode();
352
+ this.element.appendChild($dom.element);
353
+ this.hasRealChildren = true;
354
+ }
355
+ }, {
356
+ key: "appendElement",
357
+ value: function appendElement(element) {
358
+ this.ensureSlotMode();
359
+ this.element.appendChild(element);
360
+ this.hasRealChildren = true;
361
+ }
362
+ }, {
363
+ key: "removeElement",
364
+ value: function removeElement(element) {
365
+ if (!element) {
366
+ return;
367
+ }
368
+ var parent = element.parentNode;
369
+ if (parent === this.element) {
370
+ this.element.removeChild(element);
371
+ return true;
372
+ }
373
+ if (parent) {
374
+ parent.removeChild(element);
375
+ return false;
376
+ }
264
377
  }
265
378
  }, {
266
379
  key: "html",
267
380
  value: function html(_html) {
268
381
  if (_TUtil.TUtil.isDefined(_html)) {
269
- if (this.childrenCount > 0) {
270
- var element = document.createElement('div');
271
- element.innerHTML = _html;
272
- if (_TUtil.TUtil.isDefined(this.originalContent)) {
273
- this.element.replaceChild(element, this.element.firstChild);
274
- } else {
275
- this.element.insertBefore(element, this.element.firstChild);
276
- }
277
- this.originalContent = _html;
278
- this.textOnly = false;
279
- } else {
382
+ if (!this.hasRealChildren) {
280
383
  this.element.innerHTML = _html;
281
- this.originalContent = _html;
282
- this.textOnly = false;
384
+ } else {
385
+ var slot = this.ensureContentSlotFirst();
386
+ slot.innerHTML = _html;
283
387
  }
284
- } else {
285
- return _TUtil.TUtil.isDefined(this.originalContent) ? this.originalContent : this.element.innerHTML;
388
+ this.originalContent = _html;
389
+ this.textOnly = false;
286
390
  }
287
391
  }
288
392
  }, {
289
393
  key: "text",
290
394
  value: function text(_text) {
291
395
  if (_TUtil.TUtil.isDefined(_text)) {
292
- if (this.childrenCount > 0) {
293
- var element = document.createTextNode(_text);
294
- if (_TUtil.TUtil.isDefined(this.originalContent)) {
295
- this.element.replaceChild(element, this.element.firstChild);
296
- } else {
297
- this.element.insertBefore(element, this.element.firstChild);
298
- }
299
- this.originalContent = _text;
300
- this.textOnly = true;
301
- } else {
396
+ if (!this.hasRealChildren) {
302
397
  this.element.textContent = _text;
303
- this.originalContent = _text;
304
- this.textOnly = true;
398
+ } else {
399
+ var slot = this.ensureContentSlotFirst();
400
+ slot.textContent = _text;
305
401
  }
306
- } else {
307
- return _TUtil.TUtil.isDefined(this.originalContent) ? this.originalContent : this.element.textContent;
402
+ this.originalContent = _text;
403
+ this.textOnly = true;
404
+ }
405
+ }
406
+ }, {
407
+ key: "clearContent",
408
+ value: function clearContent() {
409
+ if (!this.element) {
410
+ return;
411
+ }
412
+ if (!this.hasRealChildren) {
413
+ this.element.innerHTML = this.originalContent || '';
414
+ return;
415
+ }
416
+ var slot = this.ensureContentSlotFirst();
417
+ slot.innerHTML = this.originalContent || '';
418
+ }
419
+ }, {
420
+ key: "deleteAll",
421
+ value: function deleteAll() {
422
+ if (!this.element) {
423
+ return;
308
424
  }
425
+ this.element.innerHTML = this.originalContent || '';
426
+ this.hasRealChildren = false;
427
+ this.contentSlot = null;
428
+ this.slotModeEnabled = false;
309
429
  }
310
430
  }, {
311
431
  key: "outerHTML",
@@ -370,7 +490,7 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
370
490
  }, {
371
491
  key: "transform",
372
492
  value: function transform(transformString) {
373
- this.element.style[(0, _App.getBrowser)().style.transform] = transformString;
493
+ this.element.style[this.transformProp] = transformString;
374
494
  }
375
495
  }, {
376
496
  key: "animate",
@@ -406,14 +526,14 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
406
526
  }, {
407
527
  key: "getScrollTop",
408
528
  value: function getScrollTop() {
409
- var _this$element$scrollT, _this$element;
410
- return (_this$element$scrollT = (_this$element = this.element) === null || _this$element === void 0 ? void 0 : _this$element.scrollTop) !== null && _this$element$scrollT !== void 0 ? _this$element$scrollT : 0;
529
+ var _this$element$scrollT, _this$element2;
530
+ return (_this$element$scrollT = (_this$element2 = this.element) === null || _this$element2 === void 0 ? void 0 : _this$element2.scrollTop) !== null && _this$element$scrollT !== void 0 ? _this$element$scrollT : 0;
411
531
  }
412
532
  }, {
413
533
  key: "getScrollLeft",
414
534
  value: function getScrollLeft() {
415
- var _this$element$scrollL, _this$element2;
416
- return (_this$element$scrollL = (_this$element2 = this.element) === null || _this$element2 === void 0 ? void 0 : _this$element2.scrollLeft) !== null && _this$element$scrollL !== void 0 ? _this$element$scrollL : 0;
535
+ var _this$element$scrollL, _this$element3;
536
+ return (_this$element$scrollL = (_this$element3 = this.element) === null || _this$element3 === void 0 ? void 0 : _this$element3.scrollLeft) !== null && _this$element$scrollL !== void 0 ? _this$element$scrollL : 0;
417
537
  }
418
538
  }], [{
419
539
  key: "createTemplate",
@@ -423,6 +543,11 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
423
543
  $dom.innerHTML(html.trim());
424
544
  return $dom;
425
545
  }
546
+ }, {
547
+ key: "createDocumentFragment",
548
+ value: function createDocumentFragment() {
549
+ return document.createDocumentFragment();
550
+ }
426
551
  }, {
427
552
  key: "query",
428
553
  value: function query(selector) {
@@ -516,7 +641,7 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
516
641
  key: "ajax",
517
642
  value: function ajax(query) {
518
643
  var xhr = new XMLHttpRequest();
519
- var params = "";
644
+ var params = '';
520
645
  if (query.data) {
521
646
  params = Object.keys(query.data).map(function (key) {
522
647
  return "".concat(key, "=").concat(encodeURIComponent(query.data[key]));
@@ -537,7 +662,7 @@ var $Dom = exports.$Dom = /*#__PURE__*/function () {
537
662
  xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
538
663
  xhr.send(params);
539
664
  } else {
540
- query.url += !params ? "" : query.url > "" && query.url.indexOf("?") >= 0 ? "&".concat(params) : "?".concat(params);
665
+ query.url += !params ? '' : query.url > '' && query.url.indexOf('?') >= 0 ? "&".concat(params) : "?".concat(params);
541
666
  xhr.open(query.type, query.url, true);
542
667
  xhr.send();
543
668
  }