native-document 1.0.93 → 1.0.95

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.
Files changed (37) hide show
  1. package/dist/native-document.components.min.js +667 -62
  2. package/dist/native-document.dev.js +878 -111
  3. package/dist/native-document.dev.js.map +1 -1
  4. package/dist/native-document.devtools.min.js +1 -1
  5. package/dist/native-document.min.js +1 -1
  6. package/elements.js +1 -0
  7. package/index.def.js +1086 -0
  8. package/package.json +1 -1
  9. package/src/core/elements/anchor.js +28 -20
  10. package/src/core/elements/content-formatter.js +138 -1
  11. package/src/core/elements/control/for-each-array.js +1 -1
  12. package/src/core/elements/control/for-each.js +2 -2
  13. package/src/core/elements/control/show-if.js +3 -3
  14. package/src/core/elements/control/show-when.js +2 -2
  15. package/src/core/elements/control/switch.js +1 -1
  16. package/src/core/elements/description-list.js +14 -0
  17. package/src/core/elements/form.js +188 -4
  18. package/src/core/elements/html5-semantics.js +44 -1
  19. package/src/core/elements/img.js +22 -10
  20. package/src/core/elements/index.js +5 -0
  21. package/src/core/elements/interactive.js +19 -1
  22. package/src/core/elements/list.js +28 -1
  23. package/src/core/elements/medias.js +29 -0
  24. package/src/core/elements/meta-data.js +34 -0
  25. package/src/core/elements/table.js +59 -0
  26. package/src/core/utils/helpers.js +7 -2
  27. package/src/core/utils/memoize.js +1 -1
  28. package/src/core/wrappers/DocumentObserver.js +102 -31
  29. package/src/core/wrappers/ElementCreator.js +5 -0
  30. package/src/core/wrappers/HtmlElementWrapper.js +2 -2
  31. package/src/core/wrappers/NDElement.js +33 -2
  32. package/src/core/wrappers/TemplateCloner.js +1 -1
  33. package/src/core/wrappers/prototypes/nd-element.transition.extensions.js +83 -0
  34. package/types/elements.d.ts +1073 -113
  35. package/types/forms.d.ts +85 -48
  36. package/types/images.d.ts +16 -9
  37. package/types/nd-element.d.ts +6 -0
@@ -0,0 +1,83 @@
1
+ import {NDElement} from "../NDElement";
2
+
3
+ /**
4
+ * @param {HTMLElement} el
5
+ * @param {number} timeout
6
+ */
7
+ const waitForVisualEnd = (el, timeout = 1000) => {
8
+ return new Promise((resolve) => {
9
+ let isResolved = false;
10
+
11
+ const cleanupAndResolve = (e) => {
12
+ if (e && e.target !== el) return;
13
+ if (isResolved) return;
14
+
15
+ isResolved = true;
16
+ el.removeEventListener('transitionend', cleanupAndResolve);
17
+ el.removeEventListener('animationend', cleanupAndResolve);
18
+ clearTimeout(timer);
19
+ resolve();
20
+ };
21
+
22
+ el.addEventListener('transitionend', cleanupAndResolve);
23
+ el.addEventListener('animationend', cleanupAndResolve);
24
+
25
+ const timer = setTimeout(cleanupAndResolve, timeout);
26
+
27
+ const style = window.getComputedStyle(el);
28
+ const hasTransition = style.transitionDuration !== '0s';
29
+ const hasAnimation = style.animationDuration !== '0s';
30
+
31
+ if (!hasTransition && !hasAnimation) {
32
+ cleanupAndResolve();
33
+ }
34
+ });
35
+ };
36
+
37
+ NDElement.prototype.transitionOut = function(transitionName) {
38
+ const exitClass = transitionName + '-exit';
39
+ this.beforeUnmount('transition-exit', async function() {
40
+ this.$element.classes.add(exitClass);
41
+ await waitForVisualEnd(this.$element);
42
+ this.$element.classes.remove(exitClass);
43
+ });
44
+ return this;
45
+ };
46
+
47
+ NDElement.prototype.transitionIn = function(transitionName) {
48
+ const startClass = transitionName + '-enter-from';
49
+ const endClass = transitionName + '-enter-to';
50
+
51
+ this.$element.classes.add(startClass);
52
+
53
+ this.mounted(() => {
54
+ requestAnimationFrame(() => {
55
+ requestAnimationFrame(() => {
56
+ this.$element.classes.remove(startClass);
57
+ this.$element.classes.add(endClass);
58
+
59
+ waitForVisualEnd(this.$element).then(() => {
60
+ this.$element.classes.remove(endClass);
61
+ });
62
+ });
63
+ });
64
+ });
65
+ return this;
66
+ };
67
+
68
+
69
+ NDElement.prototype.transition = function (transitionName) {
70
+ this.transitionIn(transitionName);
71
+ this.transitionOut(transitionName);
72
+ return this;
73
+ };
74
+
75
+ NDElement.prototype.animate = function(animationName) {
76
+ this.$element.classes.add(animationName);
77
+
78
+ waitForVisualEnd(this.$element).then(() => {
79
+ this.$element.classes.remove(animationName);
80
+ });
81
+
82
+ return this;
83
+ };