revojs 0.0.27 → 0.0.29
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.d.ts +1 -0
- package/dist/index.js +141 -105
- package/dist/locale/index.d.ts +15 -0
- package/dist/router/index.d.ts +4 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -260,9 +260,9 @@ const renderToString = async (scope, slot) => {
|
|
|
260
260
|
const children = await renderToString(scope, slot.children);
|
|
261
261
|
if (customElement) {
|
|
262
262
|
const element = new customElement(slot.attributes, scope);
|
|
263
|
-
const template = await renderToString(scope, await element.setup());
|
|
263
|
+
const template = await renderToString(element.scope, await element.setup());
|
|
264
264
|
if (element.shadowRoot) {
|
|
265
|
-
const shadow = await renderToString(scope, {
|
|
265
|
+
const shadow = await renderToString(element.scope, {
|
|
266
266
|
tag: "template",
|
|
267
267
|
attributes: { shadowRootMode: element.shadowRoot.mode },
|
|
268
268
|
children: [template]
|
|
@@ -548,99 +548,6 @@ const mimeTypes = {
|
|
|
548
548
|
txt: "text/plain"
|
|
549
549
|
};
|
|
550
550
|
|
|
551
|
-
//#endregion
|
|
552
|
-
//#region src/markdown/index.ts
|
|
553
|
-
const charWhile = (buffer, start, ...chars) => {
|
|
554
|
-
let depth = 0;
|
|
555
|
-
let current = buffer.at(start + depth);
|
|
556
|
-
while (current && chars.includes(current)) {
|
|
557
|
-
depth += 1;
|
|
558
|
-
current = buffer.at(start + depth);
|
|
559
|
-
}
|
|
560
|
-
return depth;
|
|
561
|
-
};
|
|
562
|
-
const charUntil = (buffer, start, ...chars) => {
|
|
563
|
-
let depth = 0;
|
|
564
|
-
let current = buffer.at(start + depth);
|
|
565
|
-
while (current && !chars.includes(current)) {
|
|
566
|
-
depth += 1;
|
|
567
|
-
current = buffer.at(start + depth);
|
|
568
|
-
}
|
|
569
|
-
return depth;
|
|
570
|
-
};
|
|
571
|
-
const inlineText = (buffer, options) => {
|
|
572
|
-
const nodes = new Array();
|
|
573
|
-
let index = 0;
|
|
574
|
-
while (index < buffer.length) {
|
|
575
|
-
const char = buffer.charAt(index);
|
|
576
|
-
const text = charUntil(buffer, index, "*", "_", "\n");
|
|
577
|
-
if (text > 0) {
|
|
578
|
-
nodes.push(buffer.slice(index, index + text));
|
|
579
|
-
index += text;
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
if (char === "*" || char === "_") {
|
|
583
|
-
const start = charWhile(buffer, index, char);
|
|
584
|
-
const between = charUntil(buffer, index + start, char);
|
|
585
|
-
const end = charWhile(buffer, index + start + between, char);
|
|
586
|
-
const min = Math.min(start, end, 2);
|
|
587
|
-
const leading = start - min;
|
|
588
|
-
const trailing = end - min;
|
|
589
|
-
const slice = buffer.slice(index + leading + min, index + start + between + end - trailing - min);
|
|
590
|
-
if (slice.length > 0) {
|
|
591
|
-
const inline = inlineText(char.repeat(leading) + slice + char.repeat(trailing), options);
|
|
592
|
-
const tag = min === 2 ? "strong" : "em";
|
|
593
|
-
nodes.push(defu(options?.[tag], {
|
|
594
|
-
tag,
|
|
595
|
-
attributes: {},
|
|
596
|
-
children: inline
|
|
597
|
-
}));
|
|
598
|
-
}
|
|
599
|
-
index += start + between + end;
|
|
600
|
-
continue;
|
|
601
|
-
}
|
|
602
|
-
if (char === "\n") {
|
|
603
|
-
nodes.push(defu(options?.["br"], {
|
|
604
|
-
tag: "br",
|
|
605
|
-
attributes: {},
|
|
606
|
-
children: []
|
|
607
|
-
}));
|
|
608
|
-
index += 1;
|
|
609
|
-
continue;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
return nodes;
|
|
613
|
-
};
|
|
614
|
-
const markdownToSlot = (input, options) => {
|
|
615
|
-
const nodes = new Array();
|
|
616
|
-
const buffer = input.replace(/[\r]+/g, "").trim();
|
|
617
|
-
let index = 0;
|
|
618
|
-
while (index < buffer.length) {
|
|
619
|
-
const start = index;
|
|
620
|
-
let lines = charWhile(buffer, index, "\n");
|
|
621
|
-
while (lines < 2 && index < buffer.length) {
|
|
622
|
-
index += lines + charUntil(buffer, index + lines, "\n");
|
|
623
|
-
lines = charWhile(buffer, index, "\n");
|
|
624
|
-
}
|
|
625
|
-
const block = buffer.slice(start, index);
|
|
626
|
-
if (block.startsWith("#")) {
|
|
627
|
-
const depth = charWhile(block, 0, "#");
|
|
628
|
-
const tag = "h" + depth;
|
|
629
|
-
nodes.push(defu(options?.[tag], {
|
|
630
|
-
tag,
|
|
631
|
-
attributes: {},
|
|
632
|
-
children: inlineText(block.slice(depth))
|
|
633
|
-
}));
|
|
634
|
-
} else nodes.push(defu(options?.["p"], {
|
|
635
|
-
tag: "p",
|
|
636
|
-
attributes: {},
|
|
637
|
-
children: inlineText(block)
|
|
638
|
-
}));
|
|
639
|
-
index += lines;
|
|
640
|
-
}
|
|
641
|
-
return nodes;
|
|
642
|
-
};
|
|
643
|
-
|
|
644
551
|
//#endregion
|
|
645
552
|
//#region src/radix/index.ts
|
|
646
553
|
var Radix = class Radix {
|
|
@@ -762,6 +669,18 @@ const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
|
|
|
762
669
|
|
|
763
670
|
//#endregion
|
|
764
671
|
//#region src/router/index.tsx
|
|
672
|
+
const ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
|
|
673
|
+
const navigate = (url) => {
|
|
674
|
+
if (isClient()) {
|
|
675
|
+
const state = window.history.state;
|
|
676
|
+
window.history.pushState(state, "", url);
|
|
677
|
+
window.dispatchEvent(new PopStateEvent("popstate", { state }));
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
const anchorNavigate = (event) => {
|
|
681
|
+
event.preventDefault();
|
|
682
|
+
navigate(event.currentTarget?.getAttribute("href") ?? "/");
|
|
683
|
+
};
|
|
765
684
|
const Outlet = defineComponent({
|
|
766
685
|
name: "x-outlet",
|
|
767
686
|
shadowRoot: false,
|
|
@@ -778,21 +697,138 @@ const Outlet = defineComponent({
|
|
|
778
697
|
return async () => {
|
|
779
698
|
const { value, inputs } = radix.match(url.value.pathname);
|
|
780
699
|
const Page = await value?.();
|
|
781
|
-
if (Page)
|
|
700
|
+
if (Page) {
|
|
701
|
+
scope.setContext(ROUTE_CONTEXT, { inputs });
|
|
702
|
+
return /* @__PURE__ */ h(Page, inputs);
|
|
703
|
+
}
|
|
782
704
|
};
|
|
783
705
|
}
|
|
784
706
|
});
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
707
|
+
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/locale/index.ts
|
|
710
|
+
const createLocaleContext = (options) => {
|
|
711
|
+
const LOCALE_CONTEXT = defineContext("LOCALE_CONTEXT");
|
|
712
|
+
const registerLocaleContext = (scope) => {
|
|
713
|
+
scope.setContext(LOCALE_CONTEXT, options);
|
|
714
|
+
};
|
|
715
|
+
return {
|
|
716
|
+
LOCALE_CONTEXT,
|
|
717
|
+
registerLocaleContext
|
|
718
|
+
};
|
|
719
|
+
};
|
|
720
|
+
const useLocaleContext = async (scope, context) => {
|
|
721
|
+
const { event } = scope.getContext(RUNTIME_CONTEXT);
|
|
722
|
+
const { inputs } = scope.getContext(ROUTE_CONTEXT);
|
|
723
|
+
const { locales, defaultLocale, cookie, input } = scope.getContext(context);
|
|
724
|
+
const entries = await import("#virtual/locales").then((module) => module.index);
|
|
725
|
+
let locale;
|
|
726
|
+
if (cookie) {
|
|
727
|
+
if (event) locale = getCookies(event)[cookie];
|
|
790
728
|
}
|
|
729
|
+
if (input) if (event) locale = event.context.inputs[input];
|
|
730
|
+
else locale = inputs[input];
|
|
731
|
+
locale ??= defaultLocale;
|
|
732
|
+
if (locale) locales[locale] = await entries[locale]?.() ?? {};
|
|
733
|
+
const $ = (key) => {
|
|
734
|
+
if (locale) return locales[locale]?.[key] ?? key;
|
|
735
|
+
return key;
|
|
736
|
+
};
|
|
737
|
+
return { $ };
|
|
791
738
|
};
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
739
|
+
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/markdown/index.ts
|
|
742
|
+
const charWhile = (buffer, start, ...chars) => {
|
|
743
|
+
let depth = 0;
|
|
744
|
+
let current = buffer.at(start + depth);
|
|
745
|
+
while (current && chars.includes(current)) {
|
|
746
|
+
depth += 1;
|
|
747
|
+
current = buffer.at(start + depth);
|
|
748
|
+
}
|
|
749
|
+
return depth;
|
|
750
|
+
};
|
|
751
|
+
const charUntil = (buffer, start, ...chars) => {
|
|
752
|
+
let depth = 0;
|
|
753
|
+
let current = buffer.at(start + depth);
|
|
754
|
+
while (current && !chars.includes(current)) {
|
|
755
|
+
depth += 1;
|
|
756
|
+
current = buffer.at(start + depth);
|
|
757
|
+
}
|
|
758
|
+
return depth;
|
|
759
|
+
};
|
|
760
|
+
const inlineText = (buffer, options) => {
|
|
761
|
+
const nodes = new Array();
|
|
762
|
+
let index = 0;
|
|
763
|
+
while (index < buffer.length) {
|
|
764
|
+
const char = buffer.charAt(index);
|
|
765
|
+
const text = charUntil(buffer, index, "*", "_", "\n");
|
|
766
|
+
if (text > 0) {
|
|
767
|
+
nodes.push(buffer.slice(index, index + text));
|
|
768
|
+
index += text;
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
if (char === "*" || char === "_") {
|
|
772
|
+
const start = charWhile(buffer, index, char);
|
|
773
|
+
const between = charUntil(buffer, index + start, char);
|
|
774
|
+
const end = charWhile(buffer, index + start + between, char);
|
|
775
|
+
const min = Math.min(start, end, 2);
|
|
776
|
+
const leading = start - min;
|
|
777
|
+
const trailing = end - min;
|
|
778
|
+
const slice = buffer.slice(index + leading + min, index + start + between + end - trailing - min);
|
|
779
|
+
if (slice.length > 0) {
|
|
780
|
+
const inline = inlineText(char.repeat(leading) + slice + char.repeat(trailing), options);
|
|
781
|
+
const tag = min === 2 ? "strong" : "em";
|
|
782
|
+
nodes.push(defu(options?.[tag], {
|
|
783
|
+
tag,
|
|
784
|
+
attributes: {},
|
|
785
|
+
children: inline
|
|
786
|
+
}));
|
|
787
|
+
}
|
|
788
|
+
index += start + between + end;
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
if (char === "\n") {
|
|
792
|
+
nodes.push(defu(options?.["br"], {
|
|
793
|
+
tag: "br",
|
|
794
|
+
attributes: {},
|
|
795
|
+
children: []
|
|
796
|
+
}));
|
|
797
|
+
index += 1;
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return nodes;
|
|
802
|
+
};
|
|
803
|
+
const markdownToSlot = (input, options) => {
|
|
804
|
+
const nodes = new Array();
|
|
805
|
+
const buffer = input.replace(/[\r]+/g, "").trim();
|
|
806
|
+
let index = 0;
|
|
807
|
+
while (index < buffer.length) {
|
|
808
|
+
const start = index;
|
|
809
|
+
let lines = charWhile(buffer, index, "\n");
|
|
810
|
+
while (lines < 2 && index < buffer.length) {
|
|
811
|
+
index += lines + charUntil(buffer, index + lines, "\n");
|
|
812
|
+
lines = charWhile(buffer, index, "\n");
|
|
813
|
+
}
|
|
814
|
+
const block = buffer.slice(start, index);
|
|
815
|
+
if (block.startsWith("#")) {
|
|
816
|
+
const depth = charWhile(block, 0, "#");
|
|
817
|
+
const tag = "h" + depth;
|
|
818
|
+
nodes.push(defu(options?.[tag], {
|
|
819
|
+
tag,
|
|
820
|
+
attributes: {},
|
|
821
|
+
children: inlineText(block.slice(depth))
|
|
822
|
+
}));
|
|
823
|
+
} else nodes.push(defu(options?.["p"], {
|
|
824
|
+
tag: "p",
|
|
825
|
+
attributes: {},
|
|
826
|
+
children: inlineText(block)
|
|
827
|
+
}));
|
|
828
|
+
index += lines;
|
|
829
|
+
}
|
|
830
|
+
return nodes;
|
|
795
831
|
};
|
|
796
832
|
|
|
797
833
|
//#endregion
|
|
798
|
-
export { $fetch, Compute, Handler, MountedEvent, Outlet, RUNTIME_CONTEXT, Radix, Scope, StopEvent, activeCompute, anchorNavigate, components, createApp, createCompute, createElement, createEvent, createMemo, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getGlobalStyles, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, isClient, isServer, isTemplate, markdownToSlot, navigate, preventDefault, registerComponent, renderToNode, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toCustomElement, toFragment, toPath, toString, useEvent };
|
|
834
|
+
export { $fetch, Compute, Handler, MountedEvent, Outlet, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, Scope, StopEvent, activeCompute, anchorNavigate, components, createApp, createCompute, createElement, createEvent, createLocaleContext, createMemo, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getGlobalStyles, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, isClient, isServer, isTemplate, markdownToSlot, navigate, preventDefault, registerComponent, renderToNode, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toCustomElement, toFragment, toPath, toString, useEvent, useLocaleContext };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Descriptor, Scope } from "../signals";
|
|
2
|
+
export type Locales = Record<string, Record<string, string>>;
|
|
3
|
+
export type LocaleOptions<T extends Locales> = {
|
|
4
|
+
locales: T;
|
|
5
|
+
defaultLocale?: keyof T;
|
|
6
|
+
cookie?: string;
|
|
7
|
+
input?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const createLocaleContext: <T extends LocaleOptions<Locales>>(options: T) => {
|
|
10
|
+
LOCALE_CONTEXT: Descriptor<T>;
|
|
11
|
+
registerLocaleContext: (scope: Scope) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const useLocaleContext: <T extends LocaleOptions<Locales>>(scope: Scope, context: Descriptor<T>) => Promise<{
|
|
14
|
+
$: (key: keyof T["locales"][keyof T["locales"]]) => string | number | symbol | keyof T["locales"][keyof T["locales"]];
|
|
15
|
+
}>;
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { type ComponentConstructor } from "../html";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const ROUTE_CONTEXT: import("..").Descriptor<{
|
|
3
|
+
inputs: Record<string, string>;
|
|
4
|
+
}>;
|
|
3
5
|
export declare const navigate: (url: string) => void;
|
|
4
6
|
export declare const anchorNavigate: (event: Event) => void;
|
|
7
|
+
export declare const Outlet: ComponentConstructor<{}, {}>;
|