revojs 0.0.68 → 0.0.70

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.
@@ -24,6 +24,6 @@ export type App = {
24
24
  config: Config;
25
25
  virtuals: Record<string, Virtual>;
26
26
  };
27
- export declare const createApp: (config?: NestedPartial<Config>) => App;
27
+ export declare function createApp(config?: NestedPartial<Config>): App;
28
28
  export declare const SERVER = "ssr";
29
29
  export declare const CLIENT = "client";
@@ -46,7 +46,6 @@ export interface ComponentOptions<TEvents extends Events, TAttributes extends At
46
46
  events?: TEvents;
47
47
  attributes?: TAttributes;
48
48
  shadowRoot?: ShadowRootInit;
49
- styles?: Array<string>;
50
49
  setup: (component: Component<TEvents, TAttributes>) => Slot;
51
50
  }
52
51
  export interface Component<TEvents extends Events, TAttributes extends Attributes> {
@@ -60,7 +59,6 @@ export interface ComponentConstructor<TEvents extends Events, TAttributes extend
60
59
  $name: string;
61
60
  $events: TEvents;
62
61
  $attributes: TAttributes;
63
- $styles: Array<string>;
64
62
  new (input?: Input<TEvents, TAttributes>, parentScope?: Scope): Component<TEvents, TAttributes>;
65
63
  }
66
64
  export interface CustomElement<TEvents extends Events, TAttributes extends Attributes> extends HTMLElement {
@@ -72,30 +70,30 @@ export interface CustomElementConstructor<TEvents extends Events, TAttributes ex
72
70
  export declare class MountedEvent extends Event {
73
71
  constructor();
74
72
  }
75
- export declare const isTemplate: <T>(value?: T) => value is Template & T;
76
- export declare const isCustomElement: <T>(value?: T) => value is CustomElement<Events, Attributes> & T;
77
- export declare const isComponent: <T>(value?: T) => value is ComponentConstructor<Events, Attributes> & T;
78
- export declare const useHost: (scope: Scope) => HostContext;
79
- export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | ((attributes: AttributeInput<Attributes>) => Slot) | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
80
- export declare const toString: (slot: Slot) => string;
81
- export declare const toArray: (hydration: Hydration) => Array<Node>;
82
- export declare const toRange: (hydration: Hydration) => Range;
83
- export declare const toFragment: (hydration: Hydration) => DocumentFragment;
84
- export declare const hydrate: (scope: Scope, parentNode: Node, slot: Slot, index: number, previous?: Hydration) => Hydration;
85
- export declare const renderToString: (scope: Scope, slot: Slot) => Promise<string>;
86
- export declare const defineComponent: <TEvents extends Events, TAttributes extends Attributes>(options: ComponentOptions<TEvents, TAttributes>) => ComponentConstructor<TEvents, TAttributes>;
87
- export declare const toCustomElement: <TEvents extends Events, TAttributes extends Attributes>(Component: ComponentConstructor<TEvents, TAttributes>) => CustomElementConstructor<TEvents, TAttributes>;
88
- export declare const registerComponent: <TEvents extends Events, TAttributes extends Attributes>(component: ComponentConstructor<TEvents, TAttributes>) => ComponentConstructor<TEvents, TAttributes>;
73
+ export declare function isTemplate<T>(value?: T): value is Template & T;
74
+ export declare function isCustomElement<T>(value?: T): value is CustomElement<Events, Attributes> & T;
75
+ export declare function isComponent<T>(value?: T): value is ComponentConstructor<Events, Attributes> & T;
76
+ export declare function useHost(scope: Scope): HostContext;
77
+ export declare function createElement<TEvents extends Events, TAttributes extends Attributes>(input: string | ((attributes: AttributeInput<Attributes>) => Slot) | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>): Slot;
78
+ export declare function toString(slot: Slot): string;
79
+ export declare function toArray(hydration: Hydration): Array<Node>;
80
+ export declare function toRange(hydration: Hydration): Range;
81
+ export declare function toFragment(hydration: Hydration): DocumentFragment;
82
+ export declare function hydrate(scope: Scope, parentNode: Node, slot: Slot, index: number, previous?: Hydration): Hydration;
83
+ export declare function renderToString(scope: Scope, slot: Slot): Promise<string>;
84
+ export declare function defineComponent<TEvents extends Events, TAttributes extends Attributes>(options: ComponentOptions<TEvents, TAttributes>): ComponentConstructor<TEvents, TAttributes>;
85
+ export declare function toCustomElement<TEvents extends Events, TAttributes extends Attributes>(Component: ComponentConstructor<TEvents, TAttributes>): CustomElementConstructor<TEvents, TAttributes>;
86
+ export declare function registerComponent<TEvents extends Events, TAttributes extends Attributes>(component: ComponentConstructor<TEvents, TAttributes>): ComponentConstructor<TEvents, TAttributes>;
89
87
  export declare function useEvent<T extends keyof ElementEventMap>(scope: Scope, target: EventTarget | undefined | null, event: T, input: EventListener<ElementEventMap[T]>, options?: AddEventListenerOptions): void;
90
88
  export declare function useEvent<T extends keyof WindowEventMap>(scope: Scope, target: Window | undefined | null, event: T, input: EventListener<WindowEventMap[T]>, options?: AddEventListenerOptions): void;
91
89
  export declare function useEvent<T extends keyof HTMLElementEventMap>(scope: Scope, target: Document | HTMLElement | undefined | null, event: T, input: EventListener<HTMLElementEventMap[T]>, options?: AddEventListenerOptions): void;
92
- export declare const onMounted: (scope: Scope, event: EventListener<MountedEvent>) => void;
93
- export declare const startViewTransition: (invoke: ViewTransitionUpdateCallback) => Promise<void>;
94
- export declare const isClient: () => boolean;
95
- export declare const isServer: () => boolean;
96
- export declare const preventDefault: (event: Event) => void;
97
- export declare const stopPropagation: (event: Event) => void;
98
- export declare const stopImmediatePropagation: (event: Event) => void;
90
+ export declare function onMounted(scope: Scope, event: EventListener<MountedEvent>): void;
91
+ export declare function startViewTransition(invoke: ViewTransitionUpdateCallback): Promise<void>;
92
+ export declare function isClient(): boolean;
93
+ export declare function isServer(): boolean;
94
+ export declare function preventDefault(event: Event): void;
95
+ export declare function stopPropagation(event: Event): void;
96
+ export declare function stopImmediatePropagation(event: Event): void;
99
97
  export declare const components: Map<string, ComponentConstructor<Events, Attributes>>;
100
98
  export declare const HOST_CONTEXT: import("..").Descriptor<HostContext>;
101
99
  declare global {
@@ -20,14 +20,14 @@ export type ResponseOptions = {
20
20
  };
21
21
  export type Handle = (scope: Scope) => void | Response | Promise<void | Response>;
22
22
  export type Chain = (scope: Scope, next: Handle) => void | Response | Promise<void | Response>;
23
- export declare const sendText: (scope: Scope, text: string) => Response;
24
- export declare const sendHtml: (scope: Scope, text: string) => Response;
25
- export declare const sendJson: <T>(scope: Scope, value: T) => Response;
26
- export declare const sendRedirect: (scope: Scope, path: string) => Response;
27
- export declare const sendBadRequest: (scope: Scope, text: string) => Response;
28
- export declare const sendUnauthorized: (scope: Scope) => Response;
29
- export declare const useRequestUrl: (scope: Scope, base?: string) => URL;
30
- export declare const useCookies: (scope: Scope) => Record<string, string>;
31
- export declare const useSetCookies: (scope: Scope) => Record<string, string>;
32
- export declare const setCookie: (scope: Scope, name: string, value: string, options?: CookieOptions) => void;
33
- export declare const mimeType: (file: string) => MimeType;
23
+ export declare function sendText(scope: Scope, text: string): Response;
24
+ export declare function sendHtml(scope: Scope, text: string): Response;
25
+ export declare function sendJson<T>(scope: Scope, value: T): Response;
26
+ export declare function sendRedirect(scope: Scope, path: string): Response;
27
+ export declare function sendBadRequest(scope: Scope, text: string): Response;
28
+ export declare function sendUnauthorized(scope: Scope): Response;
29
+ export declare function useUrl(scope: Scope, base?: string): URL;
30
+ export declare function useCookies(scope: Scope): Record<string, string>;
31
+ export declare function useSetCookies(scope: Scope): Record<string, string>;
32
+ export declare function setCookie(scope: Scope, name: string, value: string, options?: CookieOptions): void;
33
+ export declare function mimeType(file: string): MimeType;
package/dist/index.js CHANGED
@@ -126,7 +126,7 @@ const targets = /* @__PURE__ */ new WeakMap();
126
126
 
127
127
  //#endregion
128
128
  //#region src/app/index.ts
129
- const createApp = (config) => {
129
+ function createApp(config) {
130
130
  return {
131
131
  config: mergeObjects(config, {
132
132
  client: { entry: "./index.html" },
@@ -135,7 +135,7 @@ const createApp = (config) => {
135
135
  }),
136
136
  virtuals: {}
137
137
  };
138
- };
138
+ }
139
139
  const SERVER = "ssr";
140
140
  const CLIENT = "client";
141
141
 
@@ -220,64 +220,64 @@ const svgElements = new Set([
220
220
  "view",
221
221
  "vkern"
222
222
  ]);
223
- const namespace = (tag) => {
223
+ function namespace(tag) {
224
224
  return svgElements.has(tag) ? "http://www.w3.org/2000/svg" : "http://www.w3.org/1999/xhtml";
225
- };
225
+ }
226
226
 
227
227
  //#endregion
228
228
  //#region src/http/index.ts
229
- const sendText = (scope, text) => {
229
+ function sendText(scope, text) {
230
230
  const { response } = useRuntime(scope);
231
231
  response.headers.set("Content-Type", "text/plain");
232
232
  return new Response(text, response);
233
- };
234
- const sendHtml = (scope, text) => {
233
+ }
234
+ function sendHtml(scope, text) {
235
235
  const { response } = useRuntime(scope);
236
236
  response.headers.set("Content-Type", "text/html");
237
237
  return new Response(text, response);
238
- };
239
- const sendJson = (scope, value) => {
238
+ }
239
+ function sendJson(scope, value) {
240
240
  const { response } = useRuntime(scope);
241
241
  response.headers.set("Content-Type", "application/json");
242
242
  return new Response(JSON.stringify(value), response);
243
- };
244
- const sendRedirect = (scope, path) => {
243
+ }
244
+ function sendRedirect(scope, path) {
245
245
  const { response } = useRuntime(scope);
246
246
  response.status = 302;
247
247
  response.headers.set("Location", path);
248
248
  return new Response(null, response);
249
- };
250
- const sendBadRequest = (scope, text) => {
249
+ }
250
+ function sendBadRequest(scope, text) {
251
251
  const { response } = useRuntime(scope);
252
252
  response.status = 400;
253
253
  return new Response(text, response);
254
- };
255
- const sendUnauthorized = (scope) => {
254
+ }
255
+ function sendUnauthorized(scope) {
256
256
  const { response } = useRuntime(scope);
257
257
  response.status = 401;
258
258
  return new Response(null, response);
259
- };
260
- const useRequestUrl = (scope, base) => {
259
+ }
260
+ function useUrl(scope, base) {
261
261
  const { request } = useRuntime(scope);
262
- return new URL(request.url, base);
263
- };
264
- const useCookies = (scope) => {
262
+ return new URL(request?.url ?? window?.location.href, base);
263
+ }
264
+ function useCookies(scope) {
265
265
  const { request } = useRuntime(scope);
266
266
  return (isClient() ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
267
267
  const [name, value] = cookie.split("=");
268
268
  if (name && value) result[name] = decodeURIComponent(value);
269
269
  return result;
270
270
  }, {});
271
- };
272
- const useSetCookies = (scope) => {
271
+ }
272
+ function useSetCookies(scope) {
273
273
  const { request } = useRuntime(scope);
274
274
  return request.headers.getSetCookie().reduce((result, cookie) => {
275
275
  const [name, value] = cookie.split("=");
276
276
  if (name && value) result[name] = decodeURIComponent(value);
277
277
  return result;
278
278
  }, {});
279
- };
280
- const setCookie = (scope, name, value, options) => {
279
+ }
280
+ function setCookie(scope, name, value, options) {
281
281
  const { response } = useRuntime(scope);
282
282
  let cookie = name + "=" + encodeURIComponent(value);
283
283
  if (options?.domain) cookie += `; Domain=${options.domain}`;
@@ -290,11 +290,11 @@ const setCookie = (scope, name, value, options) => {
290
290
  if (options?.secure) cookie += `; Secure`;
291
291
  if (isClient()) document.cookie = cookie;
292
292
  else response.headers.append("Set-Cookie", cookie);
293
- };
294
- const mimeType = (file) => {
293
+ }
294
+ function mimeType(file) {
295
295
  const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
296
296
  return mimeTypes[extension ?? ""] ?? "text/plain";
297
- };
297
+ }
298
298
  const mimeTypes = {
299
299
  txt: "text/plain",
300
300
  css: "text/css",
@@ -383,31 +383,31 @@ var Radix = class Radix {
383
383
 
384
384
  //#endregion
385
385
  //#region src/runtime/index.ts
386
- const isRoute = (value) => {
386
+ function isRoute(value) {
387
387
  return !!value && typeof value === "object" && "fetch" in value;
388
- };
389
- const useRuntime = (scope) => {
388
+ }
389
+ function useRuntime(scope) {
390
390
  return scope.getContext(RUNTIME_CONTEXT);
391
- };
392
- const useRoute = (scope) => {
391
+ }
392
+ function useRoute(scope) {
393
393
  return scope.getContext(ROUTE_CONTEXT);
394
- };
395
- const defineRoute = (route) => {
394
+ }
395
+ function defineRoute(route) {
396
396
  return route;
397
- };
398
- const defineMiddleware = (middleware) => {
397
+ }
398
+ function defineMiddleware(middleware) {
399
399
  return middleware;
400
- };
401
- const fileName = (path) => {
400
+ }
401
+ function fileName(path) {
402
402
  return path.split("/").pop()?.split(".").slice(0, -1).join(".");
403
- };
404
- const toPath = (value) => {
403
+ }
404
+ function toPath(value) {
405
405
  const path = (value.startsWith("/") ? value : "/" + value).replaceAll(/\/index/g, "").replaceAll(/\[(.*?)\]/g, (_, name) => ":" + name);
406
406
  const route = path.startsWith("/") ? path : "/" + path;
407
407
  const split = route.split(".");
408
408
  return split.length === 3 ? [split.at(0), split.at(1)] : [split.at(0)];
409
- };
410
- const $fetch = async (scope, input, options) => {
409
+ }
410
+ async function $fetch(scope, input, options) {
411
411
  const { request, variables } = useRuntime(scope);
412
412
  let response;
413
413
  if (request) {
@@ -429,8 +429,8 @@ const $fetch = async (scope, input, options) => {
429
429
  case "application/json": return response.json();
430
430
  default: return response;
431
431
  }
432
- };
433
- const useAsync = (scope, invoke, options) => {
432
+ }
433
+ function useAsync(scope, invoke, options) {
434
434
  const { tasks } = useRuntime(scope);
435
435
  const state = createState();
436
436
  const isLoading = createState(true);
@@ -449,11 +449,11 @@ const useAsync = (scope, invoke, options) => {
449
449
  isLoading,
450
450
  execute
451
451
  };
452
- };
453
- const useFetch = (scope, input, options) => {
452
+ }
453
+ function useFetch(scope, input, options) {
454
454
  return useAsync(scope, async () => await $fetch(scope, input, options), options);
455
- };
456
- const createRuntime = async () => {
455
+ }
456
+ async function createRuntime() {
457
457
  const radix = new Radix();
458
458
  const middlewares = new Array();
459
459
  const routes = await import("#virtual/routes").then((module) => module.default);
@@ -489,7 +489,7 @@ const createRuntime = async () => {
489
489
  middlewares,
490
490
  fetch: async (scope) => {
491
491
  const { request } = useRuntime(scope);
492
- const { pathname } = useRequestUrl(scope);
492
+ const { pathname } = useUrl(scope);
493
493
  const { value: route, inputs } = radix.match(request.method + pathname);
494
494
  try {
495
495
  scope.setContext(ROUTE_CONTEXT, { inputs: createState(inputs) });
@@ -504,7 +504,7 @@ const createRuntime = async () => {
504
504
  }
505
505
  }
506
506
  };
507
- };
507
+ }
508
508
  const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
509
509
  const ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
510
510
 
@@ -515,31 +515,24 @@ var MountedEvent = class extends Event {
515
515
  super("mounted");
516
516
  }
517
517
  };
518
- const isTemplate = (value) => {
518
+ function isTemplate(value) {
519
519
  return !!value && typeof value === "object" && "tag" in value && "attributes" in value && "children" in value;
520
- };
521
- const isCustomElement = (value) => {
520
+ }
521
+ function isCustomElement(value) {
522
522
  return !!value && typeof value === "object" && "component" in value;
523
- };
524
- const isComponent = (value) => {
523
+ }
524
+ function isComponent(value) {
525
525
  return !!value && typeof value === "function" && "$name" in value;
526
- };
527
- const useHost = (scope) => {
526
+ }
527
+ function useHost(scope) {
528
528
  return scope.getContext(HOST_CONTEXT);
529
- };
530
- const createElement = (input, attributes, ...children) => {
531
- if (isComponent(input)) {
532
- const template = {
533
- tag: input.$name,
534
- attributes: attributes ?? {},
535
- children
536
- };
537
- if (input.$styles.length) {
538
- const classes = template.attributes["class"];
539
- template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
540
- }
541
- return template;
542
- }
529
+ }
530
+ function createElement(input, attributes, ...children) {
531
+ if (isComponent(input)) return {
532
+ tag: input.$name,
533
+ attributes: attributes ?? {},
534
+ children
535
+ };
543
536
  if (typeof input === "string") return {
544
537
  tag: input,
545
538
  attributes: attributes ?? {},
@@ -549,8 +542,8 @@ const createElement = (input, attributes, ...children) => {
549
542
  ...attributes,
550
543
  children
551
544
  });
552
- };
553
- const toString = (slot) => {
545
+ }
546
+ function toString(slot) {
554
547
  switch (typeof slot) {
555
548
  case "string":
556
549
  case "number":
@@ -561,12 +554,12 @@ const toString = (slot) => {
561
554
  case "function": return toString(slot());
562
555
  default: return "";
563
556
  }
564
- };
565
- const toArray = (hydration) => {
557
+ }
558
+ function toArray(hydration) {
566
559
  if (Array.isArray(hydration)) return hydration.reduce((items, child) => items.concat(toArray(child)), new Array());
567
- else return [hydration];
568
- };
569
- const toRange = (hydration) => {
560
+ return [hydration];
561
+ }
562
+ function toRange(hydration) {
570
563
  const items = toArray(hydration);
571
564
  const range = document.createRange();
572
565
  const firstNode = items.at(0);
@@ -574,14 +567,14 @@ const toRange = (hydration) => {
574
567
  const lastNode = items.at(-1);
575
568
  if (lastNode) range.setEndAfter(lastNode);
576
569
  return range;
577
- };
578
- const toFragment = (hydration) => {
570
+ }
571
+ function toFragment(hydration) {
579
572
  return toArray(hydration).reduce((fragment, node) => {
580
573
  fragment.appendChild(node);
581
574
  return fragment;
582
575
  }, document.createDocumentFragment());
583
- };
584
- const hydrate = (scope, parentNode, slot, index, previous) => {
576
+ }
577
+ function hydrate(scope, parentNode, slot, index, previous) {
585
578
  let hydration = parentNode.childNodes.item(index);
586
579
  if (Array.isArray(slot)) {
587
580
  const items = new Array();
@@ -634,8 +627,8 @@ const hydrate = (scope, parentNode, slot, index, previous) => {
634
627
  hydration ??= document.createComment("");
635
628
  if (parentNode.childNodes.item(index) === null) parentNode.appendChild(toFragment(hydration));
636
629
  return hydration;
637
- };
638
- const renderToString = async (scope, slot) => {
630
+ }
631
+ async function renderToString(scope, slot) {
639
632
  const { tasks } = useRuntime(scope);
640
633
  if (typeof slot === "number" || typeof slot === "bigint" || typeof slot === "boolean" || typeof slot === "string" || typeof slot === "symbol") return slot.toString();
641
634
  if (typeof slot === "function") {
@@ -675,13 +668,12 @@ const renderToString = async (scope, slot) => {
675
668
  return content;
676
669
  }
677
670
  return "<!---->";
678
- };
679
- const defineComponent = (options) => {
671
+ }
672
+ function defineComponent(options) {
680
673
  class Instance {
681
674
  static $name = options.name;
682
675
  static $events = options.events ?? {};
683
676
  static $attributes = options.attributes ?? {};
684
- static $styles = options.styles ?? [];
685
677
  scope;
686
678
  events;
687
679
  attributes;
@@ -702,8 +694,8 @@ const defineComponent = (options) => {
702
694
  }
703
695
  components.set(options.name, Instance);
704
696
  return Instance;
705
- };
706
- const toCustomElement = (Component) => {
697
+ }
698
+ function toCustomElement(Component) {
707
699
  return class extends HTMLElement {
708
700
  static formAssociated = true;
709
701
  component;
@@ -765,14 +757,14 @@ const toCustomElement = (Component) => {
765
757
  return Object.keys(Component.$attributes ?? {});
766
758
  }
767
759
  };
768
- };
769
- const registerComponent = (component) => {
760
+ }
761
+ function registerComponent(component) {
770
762
  if (isClient()) {
771
763
  const previous = customElements.get(component.$name);
772
764
  if (previous === void 0) customElements.define(component.$name, toCustomElement(component));
773
765
  }
774
766
  return component;
775
- };
767
+ }
776
768
  function useEvent(scope, target, event, input, options) {
777
769
  const controller = new AbortController();
778
770
  target?.addEventListener(event, (event$1) => {
@@ -784,21 +776,31 @@ function useEvent(scope, target, event, input, options) {
784
776
  });
785
777
  scope.onStop(() => controller.abort());
786
778
  }
787
- const onMounted = (scope, event) => {
779
+ function onMounted(scope, event) {
788
780
  if (isClient()) {
789
781
  const { host } = useHost(scope);
790
782
  useEvent(scope, host, "mounted", event);
791
783
  }
792
- };
793
- const startViewTransition = (invoke) => {
784
+ }
785
+ function startViewTransition(invoke) {
794
786
  if (isClient() && document.startViewTransition !== void 0) return document.startViewTransition(invoke).updateCallbackDone;
795
787
  return invoke();
796
- };
797
- const isClient = () => typeof window !== "undefined";
798
- const isServer = () => typeof window === "undefined";
799
- const preventDefault = (event) => event.preventDefault();
800
- const stopPropagation = (event) => event.stopPropagation();
801
- const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
788
+ }
789
+ function isClient() {
790
+ return typeof window !== "undefined";
791
+ }
792
+ function isServer() {
793
+ return typeof window === "undefined";
794
+ }
795
+ function preventDefault(event) {
796
+ event.preventDefault();
797
+ }
798
+ function stopPropagation(event) {
799
+ event.stopPropagation();
800
+ }
801
+ function stopImmediatePropagation(event) {
802
+ event.stopImmediatePropagation();
803
+ }
802
804
  const components = /* @__PURE__ */ new Map();
803
805
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
804
806
 
@@ -814,7 +816,7 @@ var AfterNavigateEvent = class extends Event {
814
816
  super("afterNavigate");
815
817
  }
816
818
  };
817
- const provideRouterContext = (scope, options) => {
819
+ function provideRouterContext(scope, options) {
818
820
  const url = createState();
819
821
  const route = createState();
820
822
  const radix = new Radix();
@@ -827,15 +829,18 @@ const provideRouterContext = (scope, options) => {
827
829
  }
828
830
  }
829
831
  const fetch$1 = () => {
830
- const { inputs } = useRoute(scope);
831
832
  const { request } = useRuntime(scope);
832
- url.value = new URL(request?.url ?? window?.location.href);
833
- const match = radix.match(url.value.pathname);
834
- inputs.value = match.inputs;
835
- route.value = match.value;
836
- navigator.dispatchEvent(new AfterNavigateEvent());
833
+ const { inputs } = useRoute(scope);
834
+ var next = new URL(request?.url ?? window?.location.href);
835
+ if (next.toString() !== url.value?.toString()) {
836
+ const match = radix.match(next.pathname);
837
+ url.value = next;
838
+ inputs.value = match.inputs;
839
+ route.value = match.value;
840
+ navigator.dispatchEvent(new AfterNavigateEvent());
841
+ }
837
842
  };
838
- if (isClient()) useEvent(scope, window, "popstate", () => navigator.dispatchEvent(new NavigateEvent()));
843
+ if (isClient()) useEvent(scope, window, "popstate", fetch$1);
839
844
  scope.setContext(ROUTE_CONTEXT, { inputs: createState() });
840
845
  scope.setContext(ROUTER_CONTEXT, {
841
846
  options,
@@ -845,10 +850,10 @@ const provideRouterContext = (scope, options) => {
845
850
  route
846
851
  });
847
852
  fetch$1();
848
- useEvent(scope, navigator, "navigate", async () => await startViewTransition(fetch$1));
853
+ useEvent(scope, navigator, "navigate", () => startViewTransition(fetch$1));
849
854
  return useRouter(scope);
850
- };
851
- const useRouter = (scope, context) => {
855
+ }
856
+ function useRouter(scope, context) {
852
857
  const { url, route, navigator } = scope.getContext(context ?? ROUTER_CONTEXT);
853
858
  const navigate = (path) => {
854
859
  if (isClient()) {
@@ -867,7 +872,7 @@ const useRouter = (scope, context) => {
867
872
  navigate,
868
873
  anchorNavigate
869
874
  };
870
- };
875
+ }
871
876
  const Page = defineComponent({
872
877
  name: "x-page",
873
878
  setup: ({ scope }) => {
@@ -879,7 +884,7 @@ const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
879
884
 
880
885
  //#endregion
881
886
  //#region src/locale/index.ts
882
- const provideLocaleContext = (scope, options) => {
887
+ function provideLocaleContext(scope, options) {
883
888
  const { inputs } = useRoute(scope);
884
889
  const { navigator } = useRouter(scope);
885
890
  const locale = createState(options.defaultLocale);
@@ -902,8 +907,8 @@ const provideLocaleContext = (scope, options) => {
902
907
  options
903
908
  });
904
909
  return useLocale(scope);
905
- };
906
- const useLocale = (scope, context) => {
910
+ }
911
+ function useLocale(scope, context) {
907
912
  const { locale, messages } = scope.getContext(context ?? LOCALE_CONTEXT);
908
913
  const $ = (key) => {
909
914
  return () => messages.value?.[key] ?? key;
@@ -918,8 +923,8 @@ const useLocale = (scope, context) => {
918
923
  $,
919
924
  date
920
925
  };
921
- };
926
+ }
922
927
  const LOCALE_CONTEXT = defineContext("LOCALE_CONTEXT");
923
928
 
924
929
  //#endregion
925
- export { $fetch, AfterNavigateEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
930
+ export { $fetch, AfterNavigateEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useRoute, useRouter, useRuntime, useSetCookies, useUrl };
@@ -1,4 +1,4 @@
1
- import { type EventListener, type Slot } from "../html";
1
+ import { createElement, type EventListener, type Slot } from "../html";
2
2
  export type Fragment = {
3
3
  children: Array<Slot>;
4
4
  };
@@ -366,6 +366,6 @@ export declare namespace JSX {
366
366
  }
367
367
  }
368
368
  export declare const svgElements: Set<string>;
369
- export declare const namespace: (tag: string) => "http://www.w3.org/1999/xhtml" | "http://www.w3.org/2000/svg";
370
- export declare const h: <TEvents extends import("..").Events, TAttributes extends import("..").Attributes>(input: string | ((attributes: import("..").AttributeInput<import("..").Attributes>) => Slot) | import("..").ComponentConstructor<TEvents, TAttributes>, attributes?: import("..").AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
369
+ export declare function namespace(tag: string): "http://www.w3.org/1999/xhtml" | "http://www.w3.org/2000/svg";
370
+ export declare const h: typeof createElement;
371
371
  export declare const fragment: ({ children }: Fragment) => unknown[];
package/dist/jsx/index.js CHANGED
@@ -10,22 +10,15 @@ const ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
10
10
 
11
11
  //#endregion
12
12
  //#region src/html/index.ts
13
- const isComponent = (value) => {
13
+ function isComponent(value) {
14
14
  return !!value && typeof value === "function" && "$name" in value;
15
- };
16
- const createElement = (input, attributes, ...children) => {
17
- if (isComponent(input)) {
18
- const template = {
19
- tag: input.$name,
20
- attributes: attributes ?? {},
21
- children
22
- };
23
- if (input.$styles.length) {
24
- const classes = template.attributes["class"];
25
- template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
26
- }
27
- return template;
28
- }
15
+ }
16
+ function createElement(input, attributes, ...children) {
17
+ if (isComponent(input)) return {
18
+ tag: input.$name,
19
+ attributes: attributes ?? {},
20
+ children
21
+ };
29
22
  if (typeof input === "string") return {
30
23
  tag: input,
31
24
  attributes: attributes ?? {},
@@ -35,7 +28,7 @@ const createElement = (input, attributes, ...children) => {
35
28
  ...attributes,
36
29
  children
37
30
  });
38
- };
31
+ }
39
32
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
40
33
 
41
34
  //#endregion
@@ -119,9 +112,9 @@ const svgElements = new Set([
119
112
  "view",
120
113
  "vkern"
121
114
  ]);
122
- const namespace = (tag) => {
115
+ function namespace(tag) {
123
116
  return svgElements.has(tag) ? "http://www.w3.org/2000/svg" : "http://www.w3.org/1999/xhtml";
124
- };
117
+ }
125
118
  const h = createElement;
126
119
  const fragment = ({ children }) => children;
127
120
 
@@ -9,13 +9,13 @@ export type LocaleContext = {
9
9
  messages: State<Record<string, string> | undefined>;
10
10
  options: LocaleOptions;
11
11
  };
12
- export declare const provideLocaleContext: (scope: Scope, options: LocaleOptions) => {
12
+ export declare function provideLocaleContext(scope: Scope, options: LocaleOptions): {
13
13
  locale: State<string | undefined>;
14
14
  messages: State<Record<string, string> | undefined>;
15
15
  $: (key: string) => () => string | number | symbol;
16
16
  date: (date?: Date, options?: Intl.DateTimeFormatOptions) => string | undefined;
17
17
  };
18
- export declare const useLocale: <T extends LocaleContext>(scope: Scope, context?: Descriptor<T>) => {
18
+ export declare function useLocale<T extends LocaleContext>(scope: Scope, context?: Descriptor<T>): {
19
19
  locale: State<string | undefined>;
20
20
  messages: State<Record<string, string> | undefined>;
21
21
  $: (key: keyof T["options"]["locales"][keyof T["options"]["locales"]]) => () => string | number | symbol;
@@ -17,14 +17,14 @@ export declare class NavigateEvent extends Event {
17
17
  export declare class AfterNavigateEvent extends Event {
18
18
  constructor();
19
19
  }
20
- export declare const provideRouterContext: (scope: Scope, options: RouterOptions) => {
20
+ export declare function provideRouterContext(scope: Scope, options: RouterOptions): {
21
21
  url: State<URL | undefined>;
22
22
  route: State<unknown>;
23
23
  navigator: EventTarget;
24
24
  navigate: (path: string) => void;
25
25
  anchorNavigate: (event: Event) => void;
26
26
  };
27
- export declare const useRouter: <T extends RouterContext>(scope: Scope, context?: Descriptor<T>) => {
27
+ export declare function useRouter<T extends RouterContext>(scope: Scope, context?: Descriptor<T>): {
28
28
  url: State<URL | undefined>;
29
29
  route: State<unknown>;
30
30
  navigator: EventTarget;
@@ -24,24 +24,24 @@ export type RouteContext = {
24
24
  export type AsyncOptions = {
25
25
  catch?: (error: unknown) => void | Promise<void>;
26
26
  };
27
- export declare const isRoute: <T>(value?: T) => value is Route & T;
28
- export declare const useRuntime: <T = Record<string, unknown>>(scope: Scope) => RuntimeContext<T>;
29
- export declare const useRoute: (scope: Scope) => RouteContext;
30
- export declare const defineRoute: (route: Route) => Route;
31
- export declare const defineMiddleware: (middleware: Middleware) => Middleware;
32
- export declare const fileName: (path: string) => string | undefined;
33
- export declare const toPath: (value: string) => (string | undefined)[];
34
- export declare const $fetch: <T>(scope: Scope, input: string | URL, options?: RequestInit) => Promise<T>;
35
- export declare const useAsync: <T>(scope: Scope, invoke: () => Promise<T>, options?: AsyncOptions) => {
27
+ export declare function isRoute<T>(value?: T): value is Route & T;
28
+ export declare function useRuntime<T = Record<string, unknown>>(scope: Scope): RuntimeContext<T>;
29
+ export declare function useRoute(scope: Scope): RouteContext;
30
+ export declare function defineRoute(route: Route): Route;
31
+ export declare function defineMiddleware(middleware: Middleware): Middleware;
32
+ export declare function fileName(path: string): string | undefined;
33
+ export declare function toPath(value: string): (string | undefined)[];
34
+ export declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
35
+ export declare function useAsync<T>(scope: Scope, invoke: () => Promise<T>, options?: AsyncOptions): {
36
36
  state: State<T | undefined>;
37
37
  isLoading: State<boolean>;
38
38
  execute: () => Promise<T | undefined>;
39
39
  };
40
- export declare const useFetch: <T>(scope: Scope, input: string | URL, options?: RequestInit & AsyncOptions) => {
40
+ export declare function useFetch<T>(scope: Scope, input: string | URL, options?: RequestInit & AsyncOptions): {
41
41
  state: State<T | undefined>;
42
42
  isLoading: State<boolean>;
43
43
  execute: () => Promise<T | undefined>;
44
44
  };
45
- export declare const createRuntime: () => Promise<Runtime>;
45
+ export declare function createRuntime(): Promise<Runtime>;
46
46
  export declare const RUNTIME_CONTEXT: import("..").Descriptor<RuntimeContext<Record<string, unknown>>>;
47
47
  export declare const ROUTE_CONTEXT: import("..").Descriptor<RouteContext>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.68",
3
+ "version": "0.0.70",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",