valyrian.js 7.1.1 → 7.2.0

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/dist/index.mjs CHANGED
@@ -263,11 +263,12 @@ function directive(name, directive2) {
263
263
  }
264
264
  function sharedSetAttribute(name, value, newVnode, oldVnode) {
265
265
  if (typeof value === "function") {
266
- if (name in eventListenerNames === false) {
267
- mainVnode.dom.addEventListener(name.slice(2), eventListener);
268
- eventListenerNames[name] = true;
266
+ let lowercaseName = name.toLowerCase();
267
+ if (lowercaseName in eventListenerNames === false) {
268
+ mainVnode.dom.addEventListener(lowercaseName.slice(2), eventListener);
269
+ eventListenerNames[lowercaseName] = true;
269
270
  }
270
- newVnode.dom[`v-${name}`] = value;
271
+ newVnode.dom[`v-${lowercaseName}`] = value;
271
272
  return;
272
273
  }
273
274
  if (name in newVnode.dom && newVnode.isSVG === false) {
@@ -366,41 +367,18 @@ function patch(newVnode, oldVnode) {
366
367
  for (let i = 0; i < newTree.length; i++) {
367
368
  let newChild = newTree[i];
368
369
  if (newChild instanceof Vnode && newChild.tag !== textTag) {
369
- if (typeof newChild.tag !== "string") {
370
- current.component = newChild.tag;
371
- newTree.splice(
372
- i--,
373
- 1,
374
- ("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
375
- newChild.props,
376
- ...newChild.children
377
- )
378
- );
370
+ if (typeof newChild.tag === "string") {
379
371
  continue;
380
372
  }
381
- newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
382
- if (i < oldTreeLength) {
383
- let oldChild = oldTree[i];
384
- if (newChild.tag === oldChild.tag) {
385
- newChild.dom = oldChild.dom;
386
- if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
387
- newChild.children = oldChild.children;
388
- continue;
389
- }
390
- updateAttributes(newChild, oldChild);
391
- patch(newChild, oldChild);
392
- continue;
393
- }
394
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
395
- updateAttributes(newChild);
396
- newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
397
- patch(newChild);
398
- continue;
399
- }
400
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
401
- updateAttributes(newChild);
402
- newVnode.dom.appendChild(newChild.dom);
403
- patch(newChild);
373
+ current.component = newChild.tag;
374
+ newTree.splice(
375
+ i--,
376
+ 1,
377
+ ("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
378
+ newChild.props,
379
+ ...newChild.children
380
+ )
381
+ );
404
382
  continue;
405
383
  }
406
384
  if (Array.isArray(newChild)) {
@@ -411,26 +389,55 @@ function patch(newVnode, oldVnode) {
411
389
  newTree.splice(i--, 1);
412
390
  continue;
413
391
  }
414
- newTree[i] = new Vnode(textTag, {}, []);
415
392
  if (newChild instanceof Vnode) {
416
- newTree[i].dom = newChild.dom;
417
- newChild = newChild.dom.textContent;
393
+ newChild.children[0] = newChild.dom.textContent;
394
+ continue;
418
395
  }
396
+ newChild = newTree[i] = new Vnode(textTag, {}, [newChild]);
397
+ }
398
+ for (let i = 0; i < newTree.length; i++) {
399
+ let newChild = newTree[i];
400
+ if (newChild.tag === textTag) {
401
+ if (i < oldTreeLength) {
402
+ let oldChild = oldTree[i];
403
+ if (oldChild.tag === textTag) {
404
+ newChild.dom = oldChild.dom;
405
+ if (newChild.children[0] != oldChild.dom.textContent) {
406
+ oldChild.dom.textContent = newChild.children[0];
407
+ }
408
+ continue;
409
+ }
410
+ newChild.dom = document.createTextNode(newChild.children[0]);
411
+ newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
412
+ continue;
413
+ }
414
+ newChild.dom = document.createTextNode(newChild.children[0]);
415
+ newVnode.dom.appendChild(newChild.dom);
416
+ continue;
417
+ }
418
+ newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
419
419
  if (i < oldTreeLength) {
420
420
  let oldChild = oldTree[i];
421
- if (oldChild.tag === textTag) {
422
- newTree[i].dom = oldChild.dom;
423
- if (newChild != oldChild.dom.textContent) {
424
- oldChild.dom.textContent = newChild;
421
+ if (newChild.tag === oldChild.tag) {
422
+ newChild.dom = oldChild.dom;
423
+ if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
424
+ newChild.children = oldChild.children;
425
+ continue;
425
426
  }
427
+ updateAttributes(newChild, oldChild);
428
+ patch(newChild, oldChild);
426
429
  continue;
427
430
  }
428
- newTree[i].dom = document.createTextNode(newChild);
429
- newVnode.dom.replaceChild(newTree[i].dom, oldChild.dom);
431
+ newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
432
+ updateAttributes(newChild);
433
+ newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
434
+ patch(newChild);
430
435
  continue;
431
436
  }
432
- newTree[i].dom = document.createTextNode(newChild);
433
- newVnode.dom.appendChild(newTree[i].dom);
437
+ newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
438
+ updateAttributes(newChild);
439
+ newVnode.dom.appendChild(newChild.dom);
440
+ patch(newChild);
434
441
  }
435
442
  for (let i = newTree.length; i < oldTreeLength; i++) {
436
443
  newVnode.dom.removeChild(oldTree[i].dom);
@@ -454,6 +461,21 @@ function update() {
454
461
  }
455
462
  }
456
463
  }
464
+ function updateVnode(vnode, oldVnode) {
465
+ callSet(onCleanupSet);
466
+ patch(vnode, oldVnode);
467
+ oldVnode.tag = vnode.tag;
468
+ oldVnode.props = { ...vnode.props };
469
+ oldVnode.children = [...vnode.children];
470
+ callSet(isMounted ? onUpdateSet : onMountSet);
471
+ isMounted = true;
472
+ current.vnode = null;
473
+ current.oldVnode = null;
474
+ current.component = null;
475
+ if (isNodeJs) {
476
+ return vnode.dom.innerHTML;
477
+ }
478
+ }
457
479
  function unmount() {
458
480
  if (mainVnode) {
459
481
  mainComponent = new Vnode(() => null, {}, []);
@@ -508,5 +530,6 @@ export {
508
530
  unmount,
509
531
  update,
510
532
  updateAttributes,
533
+ updateVnode,
511
534
  v
512
535
  };
@@ -86,6 +86,7 @@ declare module "valyrian.js" {
86
86
  function updateAttributes(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
87
87
  function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
88
88
  function update(): void | string;
89
+ function updateVnode(vnode: VnodeWithDom, oldVnode: VnodeWithDom): string | void;
89
90
  function unmount(): string | void;
90
91
  function mount(dom: any, component: any): string | void;
91
92
  const v: V;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../lib/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAiB,KAAK;QACpB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,QAAQ,CAAC,EAAE;YACT,CAAC,KAAK,EAAE,cAAc,GAAG,KAAK,CAAC;SAChC,CAAC;QACF,QAAQ,CAAC,EAAE;YACT,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,GAAG,KAAK,CAAC;SAC1D,CAAC;QACF,QAAQ,CAAC,EAAE;YACT,CAAC,QAAQ,EAAE,cAAc,GAAG,KAAK,CAAC;SACnC,CAAC;QACF,YAAY,CAAC,EAAE;YACb,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,GAAG,SAAS,GAAG,OAAO,CAAC;SACxE,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KACtC;IACD,UAAiB,UAAW,SAAQ,OAAO;QACzC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB;IACD,UAAiB,cAAc;QAC7B,KAAK,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC;QAChG,GAAG,EAAE,MAAM,GAAG,SAA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I,CAAC;IACzC,SAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,CAAC;CACnB"}
@@ -0,0 +1,23 @@
1
+ interface Cleanup {
2
+ (): void;
3
+ }
4
+ interface Subscription {
5
+ (value: ProxySignal["value"]): void | Cleanup;
6
+ }
7
+ interface Getter {
8
+ (value: ProxySignal["value"]): any;
9
+ }
10
+ interface ProxySignal {
11
+ (): ProxySignal["value"];
12
+ (value: Subscription): ProxySignal;
13
+ (path: string, handler: (valueAtPathPosition: any) => any): ProxySignal["value"];
14
+ (path: string, value: any): ProxySignal["value"];
15
+ (value: any): ProxySignal["value"];
16
+ value: any;
17
+ cleanup: () => void;
18
+ getter: (name: string, handler: Getter) => any;
19
+ [key: string | number | symbol]: any;
20
+ }
21
+ export declare function ProxySignal(value: any): ProxySignal;
22
+ export {};
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/proxy-signal/index.ts"],"names":[],"mappings":"AAGA,UAAU,OAAO;IACf,IAAI,IAAI,CAAC;CACV;AAED,UAAU,YAAY;IAEpB,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC;CAC/C;AAID,UAAU,MAAM;IAEd,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;CACpC;AAMD,UAAU,WAAW;IAEnB,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IAGzB,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAAC;IAGnC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,mBAAmB,EAAE,GAAG,KAAK,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAGjF,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAGjD,CAAC,KAAK,EAAE,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEnC,KAAK,EAAE,GAAG,CAAC;IAEX,OAAO,EAAE,MAAM,IAAI,CAAC;IAGpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,GAAG,CAAC;IAE/C,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CACtC;AAoCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,WAAW,CAuGnD"}
@@ -0,0 +1,136 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // lib/proxy-signal/index.ts
20
+ var proxy_signal_exports = {};
21
+ __export(proxy_signal_exports, {
22
+ ProxySignal: () => ProxySignal
23
+ });
24
+ module.exports = __toCommonJS(proxy_signal_exports);
25
+ var import_valyrian = require("valyrian.js");
26
+ function makeUnsubscribe(subscriptions, computed, handler, cleanup) {
27
+ if (typeof cleanup === "function") {
28
+ computed.cleanup = cleanup;
29
+ }
30
+ computed.unsubscribe = () => {
31
+ subscriptions.delete(handler);
32
+ computed?.cleanup();
33
+ };
34
+ }
35
+ function createSubscription(signal, subscriptions, handler) {
36
+ if (subscriptions.has(handler) === false) {
37
+ let computed = ProxySignal(() => handler(signal.value));
38
+ let cleanup = computed();
39
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
40
+ subscriptions.set(handler, computed);
41
+ }
42
+ return subscriptions.get(handler);
43
+ }
44
+ var updateTimeout;
45
+ function delayedUpdate() {
46
+ clearTimeout(updateTimeout);
47
+ updateTimeout = setTimeout(import_valyrian.update);
48
+ }
49
+ function ProxySignal(value) {
50
+ let subscriptions = /* @__PURE__ */ new Map();
51
+ let getters = {};
52
+ let forceUpdate = false;
53
+ let signal = new Proxy(
54
+ function(valOrPath, handler) {
55
+ if (typeof valOrPath === "undefined") {
56
+ return signal.value;
57
+ }
58
+ if (typeof valOrPath === "function") {
59
+ return createSubscription(signal, subscriptions, valOrPath);
60
+ }
61
+ if (typeof valOrPath === "string" && typeof handler !== "undefined") {
62
+ let parsed = valOrPath.split(".");
63
+ let result = signal.value;
64
+ let next;
65
+ while (parsed.length) {
66
+ next = parsed.shift();
67
+ if (parsed.length > 0) {
68
+ if (typeof result[next] !== "object") {
69
+ result[next] = {};
70
+ }
71
+ result = result[next];
72
+ } else {
73
+ result[next] = typeof handler === "function" ? handler(result[next]) : handler;
74
+ }
75
+ }
76
+ forceUpdate = true;
77
+ signal.value = signal.value;
78
+ return signal.value;
79
+ }
80
+ signal.value = valOrPath;
81
+ return signal.value;
82
+ },
83
+ {
84
+ set(state, prop, val) {
85
+ if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
86
+ let old = state[prop];
87
+ state[prop] = val;
88
+ if (prop === "value" && (forceUpdate || val !== old)) {
89
+ forceUpdate = false;
90
+ for (let [handler, computed] of subscriptions) {
91
+ computed.cleanup();
92
+ let cleanup = handler(val);
93
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
94
+ }
95
+ delayedUpdate();
96
+ }
97
+ return true;
98
+ }
99
+ return false;
100
+ },
101
+ get(state, prop) {
102
+ if (prop === "value") {
103
+ return typeof state.value === "function" ? state.value() : state.value;
104
+ }
105
+ if (prop === "cleanup" || prop === "unsubscribe" || prop === "getter") {
106
+ return state[prop];
107
+ }
108
+ if (prop in getters) {
109
+ return getters[prop](state.value);
110
+ }
111
+ }
112
+ }
113
+ );
114
+ Object.defineProperties(signal, {
115
+ value: { value, writable: true, enumerable: true },
116
+ cleanup: {
117
+ value() {
118
+ for (let [handler, computed] of subscriptions) {
119
+ computed.unsubscribe();
120
+ }
121
+ },
122
+ writable: true,
123
+ enumerable: true
124
+ },
125
+ getter: {
126
+ value(name, handler) {
127
+ if (name in getters) {
128
+ throw new Error("Named computed already exists.");
129
+ }
130
+ getters[name] = handler;
131
+ },
132
+ enumerable: true
133
+ }
134
+ });
135
+ return signal;
136
+ }
@@ -0,0 +1,116 @@
1
+ // lib/proxy-signal/index.ts
2
+ import { update } from "valyrian.js";
3
+ function makeUnsubscribe(subscriptions, computed, handler, cleanup) {
4
+ if (typeof cleanup === "function") {
5
+ computed.cleanup = cleanup;
6
+ }
7
+ computed.unsubscribe = () => {
8
+ subscriptions.delete(handler);
9
+ computed?.cleanup();
10
+ };
11
+ }
12
+ function createSubscription(signal, subscriptions, handler) {
13
+ if (subscriptions.has(handler) === false) {
14
+ let computed = ProxySignal(() => handler(signal.value));
15
+ let cleanup = computed();
16
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
17
+ subscriptions.set(handler, computed);
18
+ }
19
+ return subscriptions.get(handler);
20
+ }
21
+ var updateTimeout;
22
+ function delayedUpdate() {
23
+ clearTimeout(updateTimeout);
24
+ updateTimeout = setTimeout(update);
25
+ }
26
+ function ProxySignal(value) {
27
+ let subscriptions = /* @__PURE__ */ new Map();
28
+ let getters = {};
29
+ let forceUpdate = false;
30
+ let signal = new Proxy(
31
+ function(valOrPath, handler) {
32
+ if (typeof valOrPath === "undefined") {
33
+ return signal.value;
34
+ }
35
+ if (typeof valOrPath === "function") {
36
+ return createSubscription(signal, subscriptions, valOrPath);
37
+ }
38
+ if (typeof valOrPath === "string" && typeof handler !== "undefined") {
39
+ let parsed = valOrPath.split(".");
40
+ let result = signal.value;
41
+ let next;
42
+ while (parsed.length) {
43
+ next = parsed.shift();
44
+ if (parsed.length > 0) {
45
+ if (typeof result[next] !== "object") {
46
+ result[next] = {};
47
+ }
48
+ result = result[next];
49
+ } else {
50
+ result[next] = typeof handler === "function" ? handler(result[next]) : handler;
51
+ }
52
+ }
53
+ forceUpdate = true;
54
+ signal.value = signal.value;
55
+ return signal.value;
56
+ }
57
+ signal.value = valOrPath;
58
+ return signal.value;
59
+ },
60
+ {
61
+ set(state, prop, val) {
62
+ if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
63
+ let old = state[prop];
64
+ state[prop] = val;
65
+ if (prop === "value" && (forceUpdate || val !== old)) {
66
+ forceUpdate = false;
67
+ for (let [handler, computed] of subscriptions) {
68
+ computed.cleanup();
69
+ let cleanup = handler(val);
70
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
71
+ }
72
+ delayedUpdate();
73
+ }
74
+ return true;
75
+ }
76
+ return false;
77
+ },
78
+ get(state, prop) {
79
+ if (prop === "value") {
80
+ return typeof state.value === "function" ? state.value() : state.value;
81
+ }
82
+ if (prop === "cleanup" || prop === "unsubscribe" || prop === "getter") {
83
+ return state[prop];
84
+ }
85
+ if (prop in getters) {
86
+ return getters[prop](state.value);
87
+ }
88
+ }
89
+ }
90
+ );
91
+ Object.defineProperties(signal, {
92
+ value: { value, writable: true, enumerable: true },
93
+ cleanup: {
94
+ value() {
95
+ for (let [handler, computed] of subscriptions) {
96
+ computed.unsubscribe();
97
+ }
98
+ },
99
+ writable: true,
100
+ enumerable: true
101
+ },
102
+ getter: {
103
+ value(name, handler) {
104
+ if (name in getters) {
105
+ throw new Error("Named computed already exists.");
106
+ }
107
+ getters[name] = handler;
108
+ },
109
+ enumerable: true
110
+ }
111
+ });
112
+ return signal;
113
+ }
114
+ export {
115
+ ProxySignal
116
+ };
@@ -28,8 +28,9 @@ interface RouterInterface {
28
28
  path: string;
29
29
  params: Record<string, string | number | any>;
30
30
  matches: string[];
31
+ pathPrefix: string;
31
32
  add(method: string, ...args: Middlewares): Router;
32
- use(...args: string[] | Middlewares | Router[]): Router;
33
+ use(...args: (string | Middleware | Router)[]): Router;
33
34
  routes(): string[];
34
35
  go(path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface): Promise<string | void>;
35
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/router/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,aAAa,EACb,uBAAuB,EASxB,MAAM,aAAa,CAAC;AAErB,UAAU,OAAO;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,GAAG,aAAa,GAAG,uBAAuB,KAAK,KAAK,CAAC;CAC1G;AAED,UAAU,UAAU;IAElB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,GACpB,OAAO,CAAC,GAAG,GAAG,SAAS,GAAG,aAAa,GAAG,uBAAuB,CAAC,GAClE,GAAG,GACH,SAAS,GACT,aAAa,GACb,uBAAuB,CAAC;CAC7B;AAED,UAAU,WAAY,SAAQ,KAAK,CAAC,UAAU,CAAC;CAAG;AAElD,UAAU,IAAI;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;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e;IAC5C,KAAK,EAAE,IAAI,EAAE,CAAM;IACnB,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAAQ;IAC1C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAM;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAClC,GAAG,EAAE,MAAM,CAAM;IACjB,IAAI,EAAE,MAAM,CAAM;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,CAAM;IACnD,OAAO,EAAE,MAAM,EAAE,CAAM;IACvB,UAAU,EAAE,MAAM,CAAM;gBAEZ,UAAU,GAAE,MAAW;IAInC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,WAAW,GAAG,MAAM;IAMtD,GAAG,CAAC,GAAG,WAAW,EAAE,WAAW,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM;IA2B9D,MAAM,IAAI,MAAM,EAAE;IAIZ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,EAAE,gBAAgB,UAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAwCrG,iBAAiB,CAAC,GAAG,EAAE,MAAM,OAChB,UAAU;CAOxB;AAID,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,EAAE,gBAAgB,UAAQ,GAAG,MAAM,GAAG,IAAI,CAK1G;AAED,wBAAgB,WAAW,CAAC,gBAAgB,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAiBhF"}
@@ -28,6 +28,16 @@ var import_valyrian = require("valyrian.js");
28
28
  function flat(array) {
29
29
  return Array.isArray(array) ? array.flat(Infinity) : [array];
30
30
  }
31
+ function getPathWithoutPrefix(path, prefix) {
32
+ return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), ""));
33
+ }
34
+ function getPathWithoutLastSlash(path) {
35
+ let pathWithoutLastSlash = path.replace(/\/$/, "");
36
+ if (pathWithoutLastSlash === "") {
37
+ pathWithoutLastSlash = "/";
38
+ }
39
+ return pathWithoutLastSlash;
40
+ }
31
41
  var addPath = ({
32
42
  router,
33
43
  method,
@@ -71,7 +81,7 @@ function searchMiddlewares(router, path) {
71
81
  }
72
82
  matches.push(...match);
73
83
  if (item.method === "add") {
74
- router.path = item.path;
84
+ router.path = getPathWithoutPrefix(item.path, router.pathPrefix);
75
85
  break;
76
86
  }
77
87
  }
@@ -117,11 +127,14 @@ var Router = class {
117
127
  this.pathPrefix = pathPrefix;
118
128
  }
119
129
  add(path, ...middlewares) {
120
- addPath({ router: this, method: "add", path: `${this.pathPrefix}${path}`, middlewares });
130
+ let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
131
+ addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
121
132
  return this;
122
133
  }
123
134
  use(...middlewares) {
124
- let path = `${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`;
135
+ let path = getPathWithoutLastSlash(
136
+ `${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`
137
+ );
125
138
  for (const item of middlewares) {
126
139
  if (item instanceof Router) {
127
140
  const subrouter = item;
@@ -148,7 +161,7 @@ var Router = class {
148
161
  if (!path) {
149
162
  throw new Error("router.url.required");
150
163
  }
151
- const constructedPath = `${this.pathPrefix}${path}`;
164
+ let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
152
165
  const parts = constructedPath.split("?", 2);
153
166
  this.url = constructedPath;
154
167
  this.query = parseQuery(parts[1]);
@@ -197,7 +210,7 @@ function mountRouter(elementContainer, router) {
197
210
  localRedirect = router.go.bind(router);
198
211
  if (!import_valyrian.isNodeJs) {
199
212
  let onPopStateGoToRoute = function() {
200
- let pathWithoutPrefix = document.location.pathname.replace(router.pathPrefix, "");
213
+ let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
201
214
  router.go(pathWithoutPrefix, void 0, true);
202
215
  };
203
216
  window.addEventListener("popstate", onPopStateGoToRoute, false);
@@ -11,6 +11,16 @@ import {
11
11
  function flat(array) {
12
12
  return Array.isArray(array) ? array.flat(Infinity) : [array];
13
13
  }
14
+ function getPathWithoutPrefix(path, prefix) {
15
+ return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), ""));
16
+ }
17
+ function getPathWithoutLastSlash(path) {
18
+ let pathWithoutLastSlash = path.replace(/\/$/, "");
19
+ if (pathWithoutLastSlash === "") {
20
+ pathWithoutLastSlash = "/";
21
+ }
22
+ return pathWithoutLastSlash;
23
+ }
14
24
  var addPath = ({
15
25
  router,
16
26
  method,
@@ -54,7 +64,7 @@ function searchMiddlewares(router, path) {
54
64
  }
55
65
  matches.push(...match);
56
66
  if (item.method === "add") {
57
- router.path = item.path;
67
+ router.path = getPathWithoutPrefix(item.path, router.pathPrefix);
58
68
  break;
59
69
  }
60
70
  }
@@ -100,11 +110,14 @@ var Router = class {
100
110
  this.pathPrefix = pathPrefix;
101
111
  }
102
112
  add(path, ...middlewares) {
103
- addPath({ router: this, method: "add", path: `${this.pathPrefix}${path}`, middlewares });
113
+ let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
114
+ addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
104
115
  return this;
105
116
  }
106
117
  use(...middlewares) {
107
- let path = `${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`;
118
+ let path = getPathWithoutLastSlash(
119
+ `${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`
120
+ );
108
121
  for (const item of middlewares) {
109
122
  if (item instanceof Router) {
110
123
  const subrouter = item;
@@ -131,7 +144,7 @@ var Router = class {
131
144
  if (!path) {
132
145
  throw new Error("router.url.required");
133
146
  }
134
- const constructedPath = `${this.pathPrefix}${path}`;
147
+ let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
135
148
  const parts = constructedPath.split("?", 2);
136
149
  this.url = constructedPath;
137
150
  this.query = parseQuery(parts[1]);
@@ -180,7 +193,7 @@ function mountRouter(elementContainer, router) {
180
193
  localRedirect = router.go.bind(router);
181
194
  if (!isNodeJs) {
182
195
  let onPopStateGoToRoute = function() {
183
- let pathWithoutPrefix = document.location.pathname.replace(router.pathPrefix, "");
196
+ let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
184
197
  router.go(pathWithoutPrefix, void 0, true);
185
198
  };
186
199
  window.addEventListener("popstate", onPopStateGoToRoute, false);
@@ -1,23 +1,2 @@
1
- interface Cleanup {
2
- (): void;
3
- }
4
- interface Subscription {
5
- (value: Signal["value"]): void | Cleanup;
6
- }
7
- interface Getter {
8
- (value: Signal["value"]): any;
9
- }
10
- interface Signal {
11
- (): Signal["value"];
12
- (value: Subscription): Signal;
13
- (path: string, handler: (valueAtPathPosition: any) => any): Signal["value"];
14
- (path: string, value: any): Signal["value"];
15
- (value: any): Signal["value"];
16
- value: any;
17
- cleanup: () => void;
18
- getter: (name: string, handler: Getter) => any;
19
- [key: string | number | symbol]: any;
20
- }
21
- export declare function Signal(value: any): Signal;
22
- export {};
1
+ export declare function Signal(initialValue: any): any;
23
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAGA,UAAU,OAAO;IACf,IAAI,IAAI,CAAC;CACV;AAED,UAAU,YAAY;IAEpB,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC;CAC1C;AAID,UAAU,MAAM;IAEd,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;CAC/B;AAMD,UAAU,MAAM;IAEd,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAGpB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC;IAG9B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,mBAAmB,EAAE,GAAG,KAAK,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAG5E,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAG5C,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAE9B,KAAK,EAAE,GAAG,CAAC;IAEX,OAAO,EAAE,MAAM,IAAI,CAAC;IAGpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,GAAG,CAAC;IAE/C,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CACtC;AA+BD,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAuGzC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,YAAY,KAAA,OAmGlC"}