dothtml 6.0.0-beta.45 → 6.0.0-beta.46

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 (152) hide show
  1. package/build_module/constants.js +2 -0
  2. package/build_module/constants.js.map +1 -0
  3. package/build_module/css/css-props.js +77 -0
  4. package/build_module/css/css-props.js.map +1 -0
  5. package/{dist/build_module → build_module}/css/format-css-type.d.ts +4 -3
  6. package/build_module/css/format-css-type.js +80 -0
  7. package/build_module/css/format-css-type.js.map +1 -0
  8. package/build_module/decoration/component.d.ts +4 -0
  9. package/build_module/decoration/component.js +35 -0
  10. package/build_module/decoration/component.js.map +1 -0
  11. package/build_module/dot.js +404 -0
  12. package/build_module/dot.js.map +1 -0
  13. package/build_module/events/event-manager.d.ts +14 -0
  14. package/build_module/events/event-manager.js +98 -0
  15. package/build_module/events/event-manager.js.map +1 -0
  16. package/build_module/events/synthetic-event.d.ts +17 -0
  17. package/build_module/events/synthetic-event.js +33 -0
  18. package/build_module/events/synthetic-event.js.map +1 -0
  19. package/build_module/helpers/render-stylesheet.js +36 -0
  20. package/build_module/helpers/render-stylesheet.js.map +1 -0
  21. package/build_module/helpers/tools.js +50 -0
  22. package/build_module/helpers/tools.js.map +1 -0
  23. package/build_module/index.d.ts +9 -0
  24. package/build_module/index.js +19 -0
  25. package/build_module/index.js.map +1 -0
  26. package/{dist/build_module → build_module}/reactivity/binding.d.ts +3 -1
  27. package/build_module/reactivity/binding.js +26 -0
  28. package/build_module/reactivity/binding.js.map +1 -0
  29. package/build_module/reactivity/computed.d.ts +18 -0
  30. package/build_module/reactivity/computed.js +106 -0
  31. package/build_module/reactivity/computed.js.map +1 -0
  32. package/build_module/reactivity/priority.d.ts +6 -0
  33. package/build_module/reactivity/priority.js +8 -0
  34. package/build_module/reactivity/priority.js.map +1 -0
  35. package/build_module/reactivity/reactive-attr.js +7 -0
  36. package/build_module/reactivity/reactive-attr.js.map +1 -0
  37. package/build_module/reactivity/reactive-style.js +7 -0
  38. package/build_module/reactivity/reactive-style.js.map +1 -0
  39. package/build_module/reactivity/ref-collection.d.ts +8 -0
  40. package/build_module/reactivity/ref-collection.js +32 -0
  41. package/build_module/reactivity/ref-collection.js.map +1 -0
  42. package/build_module/reactivity/ref.d.ts +7 -0
  43. package/build_module/reactivity/ref.js +35 -0
  44. package/build_module/reactivity/ref.js.map +1 -0
  45. package/build_module/reactivity/scheduler.d.ts +22 -0
  46. package/build_module/reactivity/scheduler.js +124 -0
  47. package/build_module/reactivity/scheduler.js.map +1 -0
  48. package/build_module/reactivity/store.d.ts +14 -0
  49. package/build_module/reactivity/store.js +91 -0
  50. package/build_module/reactivity/store.js.map +1 -0
  51. package/{dist/build_module → build_module}/reactivity/subscription.d.ts +2 -1
  52. package/build_module/reactivity/subscription.js +40 -0
  53. package/build_module/reactivity/subscription.js.map +1 -0
  54. package/{dist/build_module → build_module}/reactivity/watcher.d.ts +6 -3
  55. package/build_module/reactivity/watcher.js +82 -0
  56. package/build_module/reactivity/watcher.js.map +1 -0
  57. package/build_module/routing/helpers.d.ts +2 -0
  58. package/build_module/routing/helpers.js +21 -0
  59. package/build_module/routing/helpers.js.map +1 -0
  60. package/build_module/routing/index.d.ts +5 -0
  61. package/build_module/routing/index.js +6 -0
  62. package/build_module/routing/index.js.map +1 -0
  63. package/build_module/routing/link.d.ts +2 -0
  64. package/build_module/routing/link.js +45 -0
  65. package/build_module/routing/link.js.map +1 -0
  66. package/build_module/routing/router.d.ts +23 -0
  67. package/build_module/routing/router.js +209 -0
  68. package/build_module/routing/router.js.map +1 -0
  69. package/build_module/routing/scroll-manager.d.ts +1 -0
  70. package/build_module/routing/scroll-manager.js +33 -0
  71. package/build_module/routing/scroll-manager.js.map +1 -0
  72. package/build_module/routing/state.d.ts +7 -0
  73. package/build_module/routing/state.js +45 -0
  74. package/build_module/routing/state.js.map +1 -0
  75. package/build_module/v-dom-node.d.ts +0 -0
  76. package/build_module/v-dom-node.js +1 -0
  77. package/build_module/v-dom-node.js.map +1 -0
  78. package/build_module/v-meta-nodes/attribute-v-node.js +53 -0
  79. package/build_module/v-meta-nodes/attribute-v-node.js.map +1 -0
  80. package/build_module/v-meta-nodes/style-v-node.d.ts +26 -0
  81. package/build_module/v-meta-nodes/style-v-node.js +231 -0
  82. package/build_module/v-meta-nodes/style-v-node.js.map +1 -0
  83. package/build_module/v-meta-nodes/v-meta-node.js +3 -0
  84. package/build_module/v-meta-nodes/v-meta-node.js.map +1 -0
  85. package/build_module/v-style-nodes/base-v-style.d.ts +13 -0
  86. package/build_module/v-style-nodes/base-v-style.js +41 -0
  87. package/build_module/v-style-nodes/base-v-style.js.map +1 -0
  88. package/{dist/build_module → build_module}/v-style-nodes/css-function-builder-v-style.d.ts +0 -3
  89. package/build_module/v-style-nodes/css-function-builder-v-style.js +33 -0
  90. package/build_module/v-style-nodes/css-function-builder-v-style.js.map +1 -0
  91. package/build_module/v-style-nodes/filter-v-style.js +35 -0
  92. package/build_module/v-style-nodes/filter-v-style.js.map +1 -0
  93. package/build_module/v-style-nodes/style-sheet-builder.d.ts +9 -0
  94. package/build_module/v-style-nodes/style-sheet-builder.js +51 -0
  95. package/build_module/v-style-nodes/style-sheet-builder.js.map +1 -0
  96. package/build_module/v-style-nodes/transform-v-style.js +76 -0
  97. package/build_module/v-style-nodes/transform-v-style.js.map +1 -0
  98. package/build_module/v-style-nodes/v-style.js +6 -0
  99. package/build_module/v-style-nodes/v-style.js.map +1 -0
  100. package/{dist/build_module → build_module}/vdom-nodes/collection-vdom.d.ts +3 -1
  101. package/build_module/vdom-nodes/collection-vdom.js +174 -0
  102. package/build_module/vdom-nodes/collection-vdom.js.map +1 -0
  103. package/build_module/vdom-nodes/component-context.d.ts +5 -0
  104. package/build_module/vdom-nodes/component-context.js +5 -0
  105. package/build_module/vdom-nodes/component-context.js.map +1 -0
  106. package/build_module/vdom-nodes/component-vdom.d.ts +35 -0
  107. package/build_module/vdom-nodes/component-vdom.js +338 -0
  108. package/build_module/vdom-nodes/component-vdom.js.map +1 -0
  109. package/{dist/build_module → build_module}/vdom-nodes/conditional-vdom.d.ts +1 -0
  110. package/build_module/vdom-nodes/conditional-vdom.js +112 -0
  111. package/build_module/vdom-nodes/conditional-vdom.js.map +1 -0
  112. package/{dist/build_module → build_module}/vdom-nodes/container-vdom.d.ts +6 -2
  113. package/build_module/vdom-nodes/container-vdom.js +163 -0
  114. package/build_module/vdom-nodes/container-vdom.js.map +1 -0
  115. package/{dist/build_module → build_module}/vdom-nodes/element-vdom.d.ts +2 -1
  116. package/build_module/vdom-nodes/element-vdom.js +218 -0
  117. package/build_module/vdom-nodes/element-vdom.js.map +1 -0
  118. package/{dist/build_module → build_module}/vdom-nodes/html-vdom.d.ts +1 -0
  119. package/build_module/vdom-nodes/html-vdom.js +65 -0
  120. package/build_module/vdom-nodes/html-vdom.js.map +1 -0
  121. package/{dist/build_module → build_module}/vdom-nodes/text-vdom.d.ts +1 -0
  122. package/build_module/vdom-nodes/text-vdom.js +40 -0
  123. package/build_module/vdom-nodes/text-vdom.js.map +1 -0
  124. package/{dist/build_module → build_module}/vdom-nodes/vdom.d.ts +2 -0
  125. package/build_module/vdom-nodes/vdom.js +58 -0
  126. package/build_module/vdom-nodes/vdom.js.map +1 -0
  127. package/build_module/window-wrapper.js +39 -0
  128. package/build_module/window-wrapper.js.map +1 -0
  129. package/package.json +58 -64
  130. package/readme.md +32 -26
  131. package/dist/build_module/index.d.ts +0 -7
  132. package/dist/build_module/reactivity/ref.d.ts +0 -5
  133. package/dist/build_module/v-meta-nodes/style-v-node.d.ts +0 -16
  134. package/dist/build_module/v-style-nodes/base-v-style.d.ts +0 -14
  135. package/dist/build_module/vdom-nodes/component-vdom.d.ts +0 -13
  136. package/dist/index.cjs.js +0 -2
  137. package/dist/index.cjs.js.map +0 -1
  138. package/dist/index.esm.js +0 -2
  139. package/dist/index.esm.js.map +0 -1
  140. /package/{dist/build_module → build_module}/constants.d.ts +0 -0
  141. /package/{dist/build_module → build_module}/css/css-props.d.ts +0 -0
  142. /package/{dist/build_module → build_module}/dot.d.ts +0 -0
  143. /package/{dist/build_module → build_module}/helpers/render-stylesheet.d.ts +0 -0
  144. /package/{dist/build_module → build_module}/helpers/tools.d.ts +0 -0
  145. /package/{dist/build_module → build_module}/reactivity/reactive-attr.d.ts +0 -0
  146. /package/{dist/build_module → build_module}/reactivity/reactive-style.d.ts +0 -0
  147. /package/{dist/build_module → build_module}/v-meta-nodes/attribute-v-node.d.ts +0 -0
  148. /package/{dist/build_module → build_module}/v-meta-nodes/v-meta-node.d.ts +0 -0
  149. /package/{dist/build_module → build_module}/v-style-nodes/filter-v-style.d.ts +0 -0
  150. /package/{dist/build_module → build_module}/v-style-nodes/transform-v-style.d.ts +0 -0
  151. /package/{dist/build_module → build_module}/v-style-nodes/v-style.d.ts +0 -0
  152. /package/{dist/build_module → build_module}/window-wrapper.d.ts +0 -0
@@ -0,0 +1,209 @@
1
+ import dot from "../dot";
2
+ import { currentPath, previousPath, navigate } from "./state";
3
+ import { Vdom } from "../vdom-nodes/vdom";
4
+ const beforeHooks = [];
5
+ const afterHooks = [];
6
+ const globalRoutes = dot.watch([]);
7
+ export function setGlobalRoutes(routes) {
8
+ globalRoutes.value = routes;
9
+ }
10
+ export function getGlobalRoutes() {
11
+ return globalRoutes.value;
12
+ }
13
+ export function matchRoute(routes, path, basePath = "") {
14
+ const relativePath = path.startsWith(basePath) ? path.slice(basePath.length) : path;
15
+ const pathSegments = relativePath.split("/").filter(s => s !== "");
16
+ for (const route of routes) {
17
+ const routeSegments = route.path.split("/").filter(s => s !== "");
18
+ const params = {};
19
+ let match = true;
20
+ const hasMultiWildcard = routeSegments.indexOf("*") !== -1;
21
+ const isPrefixMatchAllowed = !!(route.children && route.children.length > 0);
22
+ if (!hasMultiWildcard && !isPrefixMatchAllowed && routeSegments.length !== pathSegments.length) {
23
+ continue;
24
+ }
25
+ if (routeSegments.length > pathSegments.length) {
26
+ continue;
27
+ }
28
+ for (let i = 0; i < routeSegments.length; i++) {
29
+ const rSeg = routeSegments[i];
30
+ const pSeg = pathSegments[i];
31
+ if (rSeg === "*") {
32
+ match = true;
33
+ break;
34
+ }
35
+ if (pSeg === undefined) {
36
+ match = false;
37
+ break;
38
+ }
39
+ if (rSeg === "+") {
40
+ continue;
41
+ }
42
+ if (rSeg.startsWith("{") && rSeg.endsWith("}")) {
43
+ const paramName = rSeg.slice(1, -1);
44
+ params[paramName] = pSeg;
45
+ continue;
46
+ }
47
+ if (rSeg.startsWith(":")) {
48
+ const paramName = rSeg.slice(1);
49
+ params[paramName] = pSeg;
50
+ continue;
51
+ }
52
+ if (rSeg !== pSeg) {
53
+ match = false;
54
+ break;
55
+ }
56
+ }
57
+ if (match) {
58
+ const matchedSegments = pathSegments.slice(0, routeSegments.length);
59
+ const matchedPath = (basePath.endsWith("/") ? basePath.slice(0, -1) : basePath) + "/" + matchedSegments.join("/");
60
+ return { route, params, matchedPath };
61
+ }
62
+ }
63
+ return null;
64
+ }
65
+ export const Router = dot.component(class {
66
+ constructor() {
67
+ this.resolvedComponent = dot.watch(null);
68
+ this.currentMatch = null;
69
+ this.lastPath = "";
70
+ this.subId = -1;
71
+ this.loaderCache = new Map();
72
+ }
73
+ static { this.props = {
74
+ routes: { type: Array, required: true },
75
+ notFound: { type: Object, default: null },
76
+ loading: { type: Object, default: null },
77
+ basePath: { type: String, default: "" }
78
+ }; }
79
+ mounting() {
80
+ this.subId = currentPath.subscribe(() => {
81
+ this._?.cvdom.requestUpdate();
82
+ });
83
+ }
84
+ unmounting() {
85
+ currentPath._detachBinding(this.subId);
86
+ }
87
+ build(dot) {
88
+ setGlobalRoutes(this.props.routes);
89
+ const path = currentPath.value;
90
+ const match = matchRoute(this.props.routes, path, this.props.basePath);
91
+ this.currentMatch = match;
92
+ const proceed = (comp) => {
93
+ if (!match)
94
+ return;
95
+ let title = match.route.title;
96
+ if (typeof title === "function") {
97
+ title = title(match.params);
98
+ }
99
+ if (title) {
100
+ document.title = title;
101
+ }
102
+ if (typeof comp === "function" && !comp.prototype?.build) {
103
+ if (this.loaderCache.has(comp)) {
104
+ this.resolvedComponent.value = this.loaderCache.get(comp);
105
+ afterHooks.forEach(h => h(path, previousPath.value));
106
+ return;
107
+ }
108
+ const result = comp();
109
+ if (result instanceof Promise) {
110
+ result.then(m => {
111
+ const resolved = m.default || m;
112
+ this.loaderCache.set(comp, resolved);
113
+ this.resolvedComponent.value = resolved;
114
+ this._?.cvdom.requestUpdate();
115
+ afterHooks.forEach(h => h(path, previousPath.value));
116
+ });
117
+ this.resolvedComponent.value = this.props.loading || dot.div("Loading...");
118
+ return;
119
+ }
120
+ }
121
+ this.resolvedComponent.value = comp;
122
+ afterHooks.forEach(h => h(path, previousPath.value));
123
+ };
124
+ if (!match) {
125
+ this.resolvedComponent.value = this.props.notFound || dot.div("404 - Not Found");
126
+ }
127
+ else if (match.route.redirect) {
128
+ const target = typeof match.route.redirect === "function"
129
+ ? match.route.redirect(match.params)
130
+ : match.route.redirect;
131
+ navigate(target, true);
132
+ return dot.div();
133
+ }
134
+ else {
135
+ const guards = [...beforeHooks];
136
+ if (match.route.beforeEnter) {
137
+ guards.push(match.route.beforeEnter);
138
+ }
139
+ const runGuards = async (index) => {
140
+ if (index >= guards.length) {
141
+ proceed(match.route.component);
142
+ return;
143
+ }
144
+ const guard = guards[index];
145
+ let nextCalled = false;
146
+ const handleNext = (nextVal) => {
147
+ if (nextCalled)
148
+ return;
149
+ nextCalled = true;
150
+ if (nextVal === false) {
151
+ navigate(previousPath.value, true);
152
+ }
153
+ else if (typeof nextVal === "string") {
154
+ navigate(nextVal, true);
155
+ }
156
+ else {
157
+ runGuards(index + 1);
158
+ }
159
+ };
160
+ const result = guard(path, previousPath.value, handleNext);
161
+ if (result instanceof Promise) {
162
+ const asyncResult = await result;
163
+ if (!nextCalled) {
164
+ if (asyncResult === false || typeof asyncResult === "string") {
165
+ handleNext(asyncResult);
166
+ }
167
+ else {
168
+ handleNext();
169
+ }
170
+ }
171
+ }
172
+ else if (result !== undefined && !nextCalled) {
173
+ handleNext(result);
174
+ }
175
+ };
176
+ runGuards(0);
177
+ }
178
+ const C = this.resolvedComponent.value;
179
+ if (!C)
180
+ return dot.div();
181
+ const currentMatch = this.currentMatch;
182
+ if (typeof C === "function" && C.prototype?.build) {
183
+ return dot.mount(new C(), {
184
+ routeParams: currentMatch?.params,
185
+ basePath: currentMatch?.matchedPath
186
+ });
187
+ }
188
+ if (typeof C === "object" && C.build) {
189
+ return dot.mount(C, {
190
+ routeParams: currentMatch?.params,
191
+ basePath: currentMatch?.matchedPath
192
+ });
193
+ }
194
+ if (C instanceof Vdom)
195
+ return C;
196
+ return dot.div(C);
197
+ }
198
+ });
199
+ Router.beforeEach = (guard) => {
200
+ beforeHooks.push(guard);
201
+ };
202
+ Router.afterEach = (hook) => {
203
+ afterHooks.push(hook);
204
+ };
205
+ Router.clearHooks = () => {
206
+ beforeHooks.length = 0;
207
+ afterHooks.length = 0;
208
+ };
209
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/routing/router.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAsB1C,MAAM,WAAW,GAAsB,EAAE,CAAC;AAC1C,MAAM,UAAU,GAA0B,EAAE,CAAC;AAC7C,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAoB,EAAE,CAAC,CAAC;AAEtD,MAAM,UAAU,eAAe,CAAC,MAAyB;IACxD,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,eAAe;IAC9B,OAAO,YAAY,CAAC,KAAK,CAAC;AAC3B,CAAC;AAUD,MAAM,UAAU,UAAU,CAAC,MAAyB,EAAE,IAAY,EA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E,YAAY,EAAE,MAAM;gBACjC,QAAQ,EAAE,YAAY,EAAE,WAAW;aACnC,CAAC,CAAC;SACH;QAED,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,EAAE;YACrC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;gBACnB,WAAW,EAAE,YAAY,EAAE,MAAM;gBACjC,QAAQ,EAAE,YAAY,EAAE,WAAW;aACnC,CAAC,CAAC;SACH;QAED,IAAI,CAAC,YAAY,IAAI;YAAE,OAAO,CAAC,CAAC;QAChC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;CACD,CACD,CAAC;AAED,MAAc,CAAC,UAAU,GAAG,CAAC,KAAsB,EAAE,EAAE;IACvD,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC,CAAC;AAED,MAAc,CAAC,SAAS,GAAG,CAAC,IAAyB,EAAE,EAAE;IACzD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC,CAAC;AAED,MAAc,CAAC,UAAU,GAAG,GAAG,EAAE;IACjC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;IACvB,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function initScrollManager(): void;
@@ -0,0 +1,33 @@
1
+ import { currentPath, currentHash } from "./state";
2
+ const scrollPositions = new Map();
3
+ export function initScrollManager() {
4
+ if (typeof window === "undefined")
5
+ return;
6
+ window.addEventListener("scroll", () => {
7
+ scrollPositions.set(window.location.pathname, {
8
+ x: window.pageXOffset,
9
+ y: window.pageYOffset
10
+ });
11
+ }, { passive: true });
12
+ currentPath.subscribe((newPath) => {
13
+ setTimeout(() => {
14
+ const hash = currentHash.value;
15
+ if (hash && hash.startsWith("#")) {
16
+ const id = hash.substring(1);
17
+ const element = document.getElementById(id);
18
+ if (element) {
19
+ element.scrollIntoView();
20
+ return;
21
+ }
22
+ }
23
+ const savedPosition = scrollPositions.get(newPath);
24
+ if (savedPosition) {
25
+ window.scrollTo(savedPosition.x, savedPosition.y);
26
+ }
27
+ else {
28
+ window.scrollTo(0, 0);
29
+ }
30
+ }, 0);
31
+ });
32
+ }
33
+ //# sourceMappingURL=scroll-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-manager.js","sourceRoot":"","sources":["../../src/routing/scroll-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAoC,CAAC;AAMpE,MAAM,UAAU,iBAAiB;IAChC,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAM1C,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE;YAC7C,CAAC,EAAE,MAAM,CAAC,WAAW;YACrB,CAAC,EAAE,MAAM,CAAC,WAAW;SACrB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtB,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE;QAEjC,UAAU,CAAC,GAAG,EAAE;YACf,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC;YAC/B,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBACjC,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC7B,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;gBAC5C,IAAI,OAAO,EAAE;oBACZ,OAAO,CAAC,cAAc,EAAE,CAAC;oBACzB,OAAO;iBACP;aACD;YAED,MAAM,aAAa,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACnD,IAAI,aAAa,EAAE;gBAClB,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;aAClD;iBAAM;gBACN,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;QACF,CAAC,EAAE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const currentPath: import("dothtml-interfaces").IWatcher<string>;
2
+ export declare const previousPath: import("dothtml-interfaces").IWatcher<string>;
3
+ export declare const currentSearch: import("dothtml-interfaces").IWatcher<string>;
4
+ export declare const currentHash: import("dothtml-interfaces").IWatcher<string>;
5
+ export declare function navigate(path: string, replace?: boolean): void;
6
+ export declare function useQueryParams(): import("dothtml-interfaces").IWatcher<Record<string, string>>;
7
+ export declare function useHash(): import("dothtml-interfaces").IWatcher<string>;
@@ -0,0 +1,45 @@
1
+ import dot from "../dot";
2
+ export const currentPath = dot.watch(typeof window !== "undefined" ? window.location.pathname : "/");
3
+ export const previousPath = dot.watch(typeof window !== "undefined" ? window.location.pathname : "/");
4
+ export const currentSearch = dot.watch(typeof window !== "undefined" ? window.location.search : "");
5
+ export const currentHash = dot.watch(typeof window !== "undefined" ? window.location.hash : "");
6
+ export function navigate(path, replace = false) {
7
+ if (typeof window === "undefined")
8
+ return;
9
+ previousPath.value = window.location.pathname;
10
+ if (replace) {
11
+ window.history.replaceState({}, "", path);
12
+ }
13
+ else {
14
+ window.history.pushState({}, "", path);
15
+ }
16
+ currentPath.value = window.location.pathname;
17
+ currentSearch.value = window.location.search;
18
+ currentHash.value = window.location.hash;
19
+ }
20
+ export function useQueryParams() {
21
+ return dot.computed(() => {
22
+ const search = currentSearch.value;
23
+ const params = new URLSearchParams(search);
24
+ const result = {};
25
+ params.forEach((value, key) => {
26
+ result[key] = value;
27
+ });
28
+ return result;
29
+ });
30
+ }
31
+ export function useHash() {
32
+ return dot.computed(() => {
33
+ const hash = currentHash.value;
34
+ return hash.startsWith("#") ? hash.substring(1) : hash;
35
+ });
36
+ }
37
+ if (typeof window !== "undefined") {
38
+ window.addEventListener("popstate", () => {
39
+ previousPath.value = currentPath.value;
40
+ currentPath.value = window.location.pathname;
41
+ currentSearch.value = window.location.search;
42
+ currentHash.value = window.location.hash;
43
+ });
44
+ }
45
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/routing/state.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAC;AAEzB,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACrG,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACtG,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACpG,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAOhG,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,UAAmB,KAAK;IAC9D,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAE1C,YAAY,CAAC,KAAK,GAAG,MAA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AC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE;QACxC,YAAY,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC;QACvC,WAAW,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC7C,aAAa,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC7C,WAAW,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC1C,CAAC,CAAC,CAAC;CACH"}
File without changes
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=v-dom-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v-dom-node.js","sourceRoot":"","sources":["../src/v-dom-node.ts"],"names":[],"mappings":""}
@@ -0,0 +1,53 @@
1
+ import Binding from "../reactivity/binding";
2
+ import Watcher from "../reactivity/watcher";
3
+ import VMetaNode from "./v-meta-node";
4
+ export default class AttributeVNode extends VMetaNode {
5
+ constructor(attrName, attrValue) {
6
+ super();
7
+ this.observables = {};
8
+ this.attr = attrName;
9
+ this.value = attrValue;
10
+ }
11
+ render(target) {
12
+ this.target = target;
13
+ {
14
+ for (let k in this.value) {
15
+ let v = this.value[k];
16
+ if (v instanceof Watcher)
17
+ v = v.bind();
18
+ if (v && v instanceof Binding) {
19
+ let id = v._subscribe(this);
20
+ this.observables[id] = v;
21
+ }
22
+ }
23
+ }
24
+ {
25
+ this.update();
26
+ }
27
+ }
28
+ update() {
29
+ if (!this.target)
30
+ return;
31
+ let tokens = [];
32
+ for (let k in this.value) {
33
+ let v = this.value[k];
34
+ if (v) {
35
+ if (v instanceof Watcher)
36
+ v = v.bind();
37
+ if (!(v instanceof Binding) || v._get()) {
38
+ tokens.push(k);
39
+ }
40
+ }
41
+ }
42
+ this.target.setAttribute(this.attr, tokens.join(" "));
43
+ }
44
+ unrender() {
45
+ this.target = null;
46
+ for (let o in this.observables) {
47
+ let v = this.observables[o];
48
+ v._unsubscribe(Number(o));
49
+ }
50
+ this.observables = {};
51
+ }
52
+ }
53
+ //# sourceMappingURL=attribute-v-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute-v-node.js","sourceRoot":"","sources":["../../src/v-meta-nodes/attribute-v-node.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,SAAS,MAAM,eAAe,CAAC;AAMtC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,SAAS;IAQpD,YAAY,QAAQ,EAAE,SAAS;QAC9B,KAAK,EAAE,CAAC;QAHT,gBAAW,GAA4B,EAAE,CAAC;QAIzC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,MAAmB;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB;YACC,KAAI,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,EAAC;gBACvB,IAAI,CAAC,GAAI,IAAI,CAAC,KAAa,CAAC,CAAC,CAAC,CAAC;gBAE/B,IAAG,CAAC,YAAY,OAAO;oBAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;gBAEtC,IAAG,CAAC,IAAI,CAAC,YAAY,OAAO,EAAC;oBAC5B,IAAI,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBAC5B,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;iBACzB;aACD;SACD;QAED;YACC,IAAI,CAAC,MAAM,EAAE,CAAC;SACd;IACF,CAAC;IAED,MAAM;QACL,IAAG,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QAExB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAI,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,EAAC;YACvB,IAAI,CAAC,GAAI,IAAI,CAAC,KAAa,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAG,CAAC,EAAC;gBACJ,IAAG,CAAC,YAAY,OAAO;oBAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;gBACtC,IAAG,CAAC,CAAC,CAAC,YAAY,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAC;oBACtC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBACf;aACD;SACD;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,QAAQ;QACP,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,KAAI,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,EAAC;YAC7B,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC5B,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1B;QAED,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACvB,CAAC;CACD"}
@@ -0,0 +1,26 @@
1
+ import { IDotCss } from "dothtml-interfaces";
2
+ import VMetaNode from "./v-meta-node";
3
+ import BaseVStyle from "../v-style-nodes/base-v-style";
4
+ export default class StyleVNode extends VMetaNode {
5
+ target: HTMLElement | string;
6
+ document: Document;
7
+ shadowRoot: ShadowRoot;
8
+ styleSource: IDotCss | BaseVStyle;
9
+ private styleElement;
10
+ private observables;
11
+ private observableIds;
12
+ private isQueued;
13
+ private updateSubscription;
14
+ constructor(styleSource: IDotCss | BaseVStyle);
15
+ private extractObservables;
16
+ private processValue;
17
+ private tryExtractObservable;
18
+ render(target: HTMLElement | string, document?: Document, shadowRoot?: ShadowRoot): void;
19
+ update(): void;
20
+ private applyStyles;
21
+ private applySingleStyle;
22
+ private getStyleString;
23
+ private formatSingleStyle;
24
+ unrender(): void;
25
+ toString(): string;
26
+ }
@@ -0,0 +1,231 @@
1
+ import cssProps from "../css/css-props";
2
+ import VMetaNode from "./v-meta-node";
3
+ import CssFunctionBuilderVStyle from "../v-style-nodes/css-function-builder-v-style";
4
+ import FilterVStyle from "../v-style-nodes/filter-v-style";
5
+ import TransformVStyle from "../v-style-nodes/transform-v-style";
6
+ import { formatCssLength } from "../css/format-css-type";
7
+ import Binding from "../reactivity/binding";
8
+ import BaseVStyle from "../v-style-nodes/base-v-style";
9
+ import { scheduler } from "../reactivity/scheduler";
10
+ import { Priority } from "../reactivity/priority";
11
+ import Watcher from "../reactivity/watcher";
12
+ export default class StyleVNode extends VMetaNode {
13
+ constructor(styleSource) {
14
+ super();
15
+ this.observables = [];
16
+ this.observableIds = [];
17
+ this.isQueued = false;
18
+ this.updateSubscription = {
19
+ active: true,
20
+ update: () => {
21
+ this.isQueued = false;
22
+ this.applyStyles();
23
+ }
24
+ };
25
+ this.styleSource = styleSource;
26
+ if (this.styleSource instanceof BaseVStyle) {
27
+ this.styleSource._setOnUpdate(() => this.update());
28
+ }
29
+ this.extractObservables();
30
+ }
31
+ extractObservables() {
32
+ const source = this.styleSource instanceof BaseVStyle ? this.styleSource.getProps() : this.styleSource;
33
+ if (Array.isArray(source)) {
34
+ for (let i = 0; i < source.length; i++) {
35
+ let p = source[i];
36
+ this.processValue(p.prop, p.value, (newVal) => p.value = newVal);
37
+ }
38
+ }
39
+ else {
40
+ for (let prop in source) {
41
+ this.processValue(prop, source[prop], (newVal) => source[prop] = newVal);
42
+ }
43
+ }
44
+ }
45
+ processValue(prop, value, setter) {
46
+ if (!this.tryExtractObservable(value)) {
47
+ if (typeof value === "object" && value !== null && !(value instanceof CssFunctionBuilderVStyle)) {
48
+ let builder;
49
+ switch (prop) {
50
+ case "filter": {
51
+ builder = new FilterVStyle(prop);
52
+ break;
53
+ }
54
+ case "transform": {
55
+ builder = new TransformVStyle(prop);
56
+ break;
57
+ }
58
+ }
59
+ if (builder) {
60
+ let funcArray = Array.isArray(value) ? value : [value];
61
+ for (let funcValue of funcArray) {
62
+ for (let k in funcValue) {
63
+ let v = funcValue[k];
64
+ this.tryExtractObservable(v);
65
+ if (Array.isArray(v)) {
66
+ for (let w of v) {
67
+ this.tryExtractObservable(w);
68
+ }
69
+ }
70
+ if (typeof builder[k] === "function") {
71
+ if (Array.isArray(v)) {
72
+ builder[k](...v);
73
+ }
74
+ else {
75
+ builder[k](v);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ setter(builder);
81
+ }
82
+ }
83
+ }
84
+ }
85
+ tryExtractObservable(value) {
86
+ if (value instanceof Binding || value instanceof Watcher) {
87
+ if (this.observables.indexOf(value) === -1) {
88
+ this.observables.push(value);
89
+ if (this.target) {
90
+ let id = value.subscribe(() => this.update());
91
+ this.observableIds.push(id);
92
+ }
93
+ }
94
+ return true;
95
+ }
96
+ return false;
97
+ }
98
+ render(target, document = window.document, shadowRoot) {
99
+ this.target = target;
100
+ this.document = document;
101
+ this.shadowRoot = shadowRoot;
102
+ for (let observable of this.observables) {
103
+ let id = observable.subscribe(() => this.update());
104
+ this.observableIds.push(id);
105
+ }
106
+ if (typeof target === "string") {
107
+ this.styleElement = this.document.createElement("style");
108
+ if (this.shadowRoot) {
109
+ this.shadowRoot.appendChild(this.styleElement);
110
+ }
111
+ else {
112
+ this.document.head.appendChild(this.styleElement);
113
+ }
114
+ }
115
+ this.applyStyles();
116
+ }
117
+ update() {
118
+ if (!this.isQueued) {
119
+ this.isQueued = true;
120
+ scheduler.enqueue(this.updateSubscription, Priority.Normal);
121
+ }
122
+ }
123
+ applyStyles() {
124
+ if (!this.target)
125
+ return;
126
+ if (typeof this.target === "string") {
127
+ if (this.styleElement) {
128
+ this.styleElement.textContent = `${this.target} { ${this.getStyleString()} }`;
129
+ }
130
+ }
131
+ else {
132
+ this.extractObservables();
133
+ const source = this.styleSource instanceof BaseVStyle ? this.styleSource.getProps() : this.styleSource;
134
+ if (Array.isArray(source)) {
135
+ for (const p of source) {
136
+ const value = p.value instanceof Binding ? p.value._get() : (p.value instanceof Watcher ? p.value.value : p.value);
137
+ this.applySingleStyle(p.prop, value);
138
+ }
139
+ }
140
+ else {
141
+ for (let prop in source) {
142
+ const value = source[prop] instanceof Binding ? source[prop]._get() : (source[prop] instanceof Watcher ? source[prop].value : source[prop]);
143
+ this.applySingleStyle(prop, value);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ applySingleStyle(prop, value) {
149
+ let cssValue;
150
+ if (value instanceof CssFunctionBuilderVStyle) {
151
+ cssValue = value.toString();
152
+ }
153
+ else {
154
+ cssValue = value;
155
+ }
156
+ let cssProp = prop;
157
+ let cssUnit = undefined;
158
+ const registeredProp = cssProps[prop];
159
+ if (registeredProp) {
160
+ cssProp = registeredProp.cssName;
161
+ cssUnit = registeredProp.unit;
162
+ if (registeredProp.type === "length" && typeof cssValue === "number") {
163
+ cssValue = formatCssLength(cssValue, cssUnit);
164
+ }
165
+ }
166
+ if (this.target instanceof HTMLElement) {
167
+ this.target.style.setProperty(cssProp, `${cssValue}`);
168
+ }
169
+ }
170
+ getStyleString() {
171
+ let styles = "";
172
+ const source = this.styleSource instanceof BaseVStyle ? this.styleSource.getProps() : this.styleSource;
173
+ if (Array.isArray(source)) {
174
+ for (const p of source) {
175
+ styles += this.formatSingleStyle(p.prop, p.value);
176
+ }
177
+ }
178
+ else {
179
+ for (let prop in source) {
180
+ styles += this.formatSingleStyle(prop, source[prop]);
181
+ }
182
+ }
183
+ return styles;
184
+ }
185
+ formatSingleStyle(prop, value) {
186
+ let cssValue = value instanceof Binding ? value._get() : (value instanceof Watcher ? value.value : value);
187
+ if (cssValue instanceof CssFunctionBuilderVStyle) {
188
+ cssValue = cssValue.toString();
189
+ }
190
+ let cssProp = prop;
191
+ let cssUnit = undefined;
192
+ const registeredProp = cssProps[prop];
193
+ if (registeredProp) {
194
+ cssProp = registeredProp.cssName;
195
+ cssUnit = registeredProp.unit;
196
+ if (registeredProp.type === "length" && typeof cssValue === "number") {
197
+ cssValue = formatCssLength(cssValue, cssUnit);
198
+ }
199
+ }
200
+ return `${cssProp}: ${cssValue}; `;
201
+ }
202
+ unrender() {
203
+ for (let i = 0; i < this.observableIds.length; i++) {
204
+ let id = this.observableIds[i];
205
+ let observable = this.observables[i];
206
+ if (observable instanceof Binding) {
207
+ observable._unsubscribe(id);
208
+ }
209
+ else {
210
+ observable._detachBinding(id);
211
+ }
212
+ }
213
+ this.observableIds = [];
214
+ this.observables = [];
215
+ if (this.styleElement) {
216
+ this.styleElement.remove();
217
+ this.styleElement = null;
218
+ }
219
+ this.target = null;
220
+ this.updateSubscription.active = false;
221
+ }
222
+ toString() {
223
+ if (typeof this.target === "string") {
224
+ return `${this.target} { ${this.getStyleString()} }`;
225
+ }
226
+ else {
227
+ return this.getStyleString();
228
+ }
229
+ }
230
+ }
231
+ //# sourceMappingURL=style-v-node.js.map