vanilla-intlayer 8.5.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/README.md +290 -0
- package/dist/chunk-C91j1N6u.js +1 -0
- package/dist/cjs/client/index.cjs +1 -0
- package/dist/cjs/client/installIntlayer.cjs +1 -0
- package/dist/cjs/client/useDictionary.cjs +1 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -0
- package/dist/cjs/client/useIntlayer.cjs +1 -0
- package/dist/cjs/client/useLocale.cjs +1 -0
- package/dist/cjs/client/useLocaleStorage.cjs +1 -0
- package/dist/cjs/client/useRewriteURL.cjs +1 -0
- package/dist/cjs/editor/useEditor.cjs +1 -0
- package/dist/cjs/format/index.cjs +1 -0
- package/dist/cjs/format/useIntl.cjs +1 -0
- package/dist/cjs/getDictionary.cjs +1 -0
- package/dist/cjs/getIntlayer.cjs +1 -0
- package/dist/cjs/html/HTMLRenderer.cjs +1 -0
- package/dist/cjs/html/index.cjs +1 -0
- package/dist/cjs/html/installIntlayerHTML.cjs +1 -0
- package/dist/cjs/html/types.cjs +1 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -0
- package/dist/cjs/markdown/compiler.cjs +1 -0
- package/dist/cjs/markdown/index.cjs +1 -0
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +1 -0
- package/dist/cjs/markdown/runtime.cjs +1 -0
- package/dist/cjs/plugins.cjs +1 -0
- package/dist/cjs/renderIntlayerNode.cjs +1 -0
- package/dist/esm/client/index.mjs +8 -0
- package/dist/esm/client/installIntlayer.mjs +2 -0
- package/dist/esm/client/useDictionary.mjs +11 -0
- package/dist/esm/client/useDictionaryDynamic.mjs +37 -0
- package/dist/esm/client/useIntlayer.mjs +11 -0
- package/dist/esm/client/useLocale.mjs +22 -0
- package/dist/esm/client/useLocaleStorage.mjs +24 -0
- package/dist/esm/client/useRewriteURL.mjs +17 -0
- package/dist/esm/editor/useEditor.mjs +2 -0
- package/dist/esm/format/index.mjs +2 -0
- package/dist/esm/format/useIntl.mjs +14 -0
- package/dist/esm/getDictionary.mjs +6 -0
- package/dist/esm/getIntlayer.mjs +6 -0
- package/dist/esm/html/HTMLRenderer.mjs +8 -0
- package/dist/esm/html/index.mjs +3 -0
- package/dist/esm/html/installIntlayerHTML.mjs +18 -0
- package/dist/esm/html/types.mjs +0 -0
- package/dist/esm/index.mjs +13 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs +19 -0
- package/dist/esm/markdown/compiler.mjs +6 -0
- package/dist/esm/markdown/index.mjs +4 -0
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +31 -0
- package/dist/esm/markdown/runtime.mjs +51 -0
- package/dist/esm/plugins.mjs +135 -0
- package/dist/esm/renderIntlayerNode.mjs +25 -0
- package/dist/installIntlayer-BRDzSdO3.mjs +46 -0
- package/dist/installIntlayer-CieE91lh.js +1 -0
- package/dist/types/client/index.d.ts +7 -0
- package/dist/types/client/installIntlayer.d.ts +58 -0
- package/dist/types/client/useDictionary.d.ts +57 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +35 -0
- package/dist/types/client/useIntlayer.d.ts +49 -0
- package/dist/types/client/useLocale.d.ts +40 -0
- package/dist/types/client/useLocaleStorage.d.ts +31 -0
- package/dist/types/client/useRewriteURL.d.ts +23 -0
- package/dist/types/editor/useEditor.d.ts +19 -0
- package/dist/types/format/index.d.ts +1 -0
- package/dist/types/format/useIntl.d.ts +31 -0
- package/dist/types/getDictionary.d.ts +4 -0
- package/dist/types/getIntlayer.d.ts +3 -0
- package/dist/types/html/HTMLRenderer.d.ts +14 -0
- package/dist/types/html/index.d.ts +3 -0
- package/dist/types/html/installIntlayerHTML.d.ts +62 -0
- package/dist/types/html/types.d.ts +42 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +22 -0
- package/dist/types/markdown/compiler.d.ts +19 -0
- package/dist/types/markdown/index.d.ts +3 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +70 -0
- package/dist/types/markdown/runtime.d.ts +12 -0
- package/dist/types/plugins.d.ts +71 -0
- package/dist/types/renderIntlayerNode.d.ts +22 -0
- package/package.json +137 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useHTML as e } from "./installIntlayerHTML.mjs";
|
|
2
|
+
//#region src/html/HTMLRenderer.ts
|
|
3
|
+
var t = (e, t = {}) => e, n = ({ components: t } = {}) => {
|
|
4
|
+
let n = e();
|
|
5
|
+
return (e) => n.renderHTML(e, { components: t });
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { t as renderHTML, n as useHTMLRenderer };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { installIntlayerHTML as e, installIntlayerHTMLDynamic as t, useHTML as n } from "./installIntlayerHTML.mjs";
|
|
2
|
+
import { renderHTML as r, useHTMLRenderer as i } from "./HTMLRenderer.mjs";
|
|
3
|
+
export { e as installIntlayerHTML, t as installIntlayerHTMLDynamic, r as renderHTML, n as useHTML, i as useHTMLRenderer };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/html/installIntlayerHTML.ts
|
|
2
|
+
var e = null, t = (t) => e || (e = { renderHTML: t }, e), n = (e) => {
|
|
3
|
+
let n;
|
|
4
|
+
if (typeof e == "function") n = e;
|
|
5
|
+
else {
|
|
6
|
+
let { components: t, renderHTML: r } = e ?? {};
|
|
7
|
+
n = r || ((e, n) => {
|
|
8
|
+
let r = n && typeof n == "object" && "components" in n ? n.components : n, i = {
|
|
9
|
+
...t ?? {},
|
|
10
|
+
...r ?? {}
|
|
11
|
+
};
|
|
12
|
+
return Object.keys(i).length, e;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return t(n);
|
|
16
|
+
}, r = () => e || { renderHTML: (e) => e }, i = async (t) => e || n(await t());
|
|
17
|
+
//#endregion
|
|
18
|
+
export { t as createIntlayerHTMLClient, n as installIntlayerHTML, i as installIntlayerHTMLDynamic, r as useHTML };
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getPlugins as e, htmlPlugin as t, insertionPlugin as n, intlayerNodePlugins as r, markdownPlugin as i, markdownStringPlugin as a } from "./plugins.mjs";
|
|
2
|
+
import { getDictionary as o } from "./getDictionary.mjs";
|
|
3
|
+
import { getIntlayer as s } from "./getIntlayer.mjs";
|
|
4
|
+
import { a as c, i as l, n as u, r as d, t as f } from "../installIntlayer-BRDzSdO3.mjs";
|
|
5
|
+
import { useDictionary as p } from "./client/useDictionary.mjs";
|
|
6
|
+
import { useDictionaryDynamic as m } from "./client/useDictionaryDynamic.mjs";
|
|
7
|
+
import { useIntlayer as h } from "./client/useIntlayer.mjs";
|
|
8
|
+
import { localeCookie as g, localeInStorage as _, setLocaleCookie as v, setLocaleInStorage as y, useLocaleCookie as b, useLocaleStorage as x } from "./client/useLocaleStorage.mjs";
|
|
9
|
+
import { useLocale as S } from "./client/useLocale.mjs";
|
|
10
|
+
import { useRewriteURL as C } from "./client/useRewriteURL.mjs";
|
|
11
|
+
import "./client/index.mjs";
|
|
12
|
+
import { useIntl as w } from "./format/useIntl.mjs";
|
|
13
|
+
export { f as IntlayerClient, u as createIntlayerClient, o as getDictionary, s as getIntlayer, d as getIntlayerClient, e as getPlugins, t as htmlPlugin, n as insertionPlugin, l as installIntlayer, r as intlayerNodePlugins, g as localeCookie, _ as localeInStorage, i as markdownPlugin, a as markdownStringPlugin, v as setLocaleCookie, y as setLocaleInStorage, p as useDictionary, m as useDictionaryDynamic, c as useEditor, w as useIntl, h as useIntlayer, S as useLocale, b as useLocaleCookie, x as useLocaleStorage, C as useRewriteURL };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { compileMarkdown as e } from "./compiler.mjs";
|
|
2
|
+
import { useMarkdown as t } from "./installIntlayerMarkdown.mjs";
|
|
3
|
+
//#region src/markdown/MarkdownRenderer.ts
|
|
4
|
+
var n = (t, { forceBlock: n, forceInline: r, preserveFrontmatter: i, tagfilter: a } = {}) => e(t, {
|
|
5
|
+
forceBlock: n,
|
|
6
|
+
forceInline: r,
|
|
7
|
+
preserveFrontmatter: i,
|
|
8
|
+
tagfilter: a
|
|
9
|
+
}), r = (e = {}) => {
|
|
10
|
+
let n = t();
|
|
11
|
+
return (t) => n.renderMarkdown(t, {
|
|
12
|
+
forceBlock: e.forceBlock,
|
|
13
|
+
forceInline: e.forceInline,
|
|
14
|
+
preserveFrontmatter: e.preserveFrontmatter,
|
|
15
|
+
tagfilter: e.tagfilter
|
|
16
|
+
}, e.components, e.wrapper);
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { n as renderMarkdown, r as useMarkdownRenderer };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import e from "./runtime.mjs";
|
|
2
|
+
import { RuleType as t, compileWithOptions as n, sanitizer as r, slugify as i } from "@intlayer/core/markdown";
|
|
3
|
+
//#region src/markdown/compiler.ts
|
|
4
|
+
var a = (t = "", r = {}) => n(t, e, r), o = a, s = a;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { t as RuleType, s as compile, a as compileMarkdown, o as compiler, r as sanitizer, i as slugify };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { compileMarkdown as e } from "./compiler.mjs";
|
|
2
|
+
import { installIntlayerMarkdown as t, installIntlayerMarkdownDynamic as n, useMarkdown as r } from "./installIntlayerMarkdown.mjs";
|
|
3
|
+
import { renderMarkdown as i, useMarkdownRenderer as a } from "./MarkdownRenderer.mjs";
|
|
4
|
+
export { e as compileMarkdown, t as installIntlayerMarkdown, n as installIntlayerMarkdownDynamic, i as renderMarkdown, r as useMarkdown, a as useMarkdownRenderer };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compileMarkdown as e } from "./compiler.mjs";
|
|
2
|
+
//#region src/markdown/installIntlayerMarkdown.ts
|
|
3
|
+
var t = null, n = (e, n) => t || (t = {
|
|
4
|
+
components: n,
|
|
5
|
+
renderMarkdown: e
|
|
6
|
+
}, t), r = (t) => {
|
|
7
|
+
let r, i;
|
|
8
|
+
if (typeof t == "function") r = t;
|
|
9
|
+
else {
|
|
10
|
+
let { components: n, wrapper: a, forceBlock: o, forceInline: s, preserveFrontmatter: c, tagfilter: l, renderMarkdown: u } = t ?? {};
|
|
11
|
+
if (i = n, u) r = u;
|
|
12
|
+
else {
|
|
13
|
+
let t = {
|
|
14
|
+
forceBlock: o,
|
|
15
|
+
forceInline: s,
|
|
16
|
+
preserveFrontmatter: c,
|
|
17
|
+
tagfilter: l
|
|
18
|
+
};
|
|
19
|
+
r = (n, r, i, a) => e(n, {
|
|
20
|
+
...t,
|
|
21
|
+
forceBlock: r?.forceBlock ?? t.forceBlock,
|
|
22
|
+
forceInline: r?.forceInline ?? t.forceInline,
|
|
23
|
+
preserveFrontmatter: r?.preserveFrontmatter ?? t.preserveFrontmatter,
|
|
24
|
+
tagfilter: r?.tagfilter ?? t.tagfilter
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return n(r, i);
|
|
29
|
+
}, i = () => t || { renderMarkdown: (t) => e(t) }, a = async (e) => t || r(await e());
|
|
30
|
+
//#endregion
|
|
31
|
+
export { n as createIntlayerMarkdownClient, r as installIntlayerMarkdown, a as installIntlayerMarkdownDynamic, i as useMarkdown };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/markdown/runtime.ts
|
|
2
|
+
var e = new Set([
|
|
3
|
+
"area",
|
|
4
|
+
"base",
|
|
5
|
+
"br",
|
|
6
|
+
"col",
|
|
7
|
+
"embed",
|
|
8
|
+
"hr",
|
|
9
|
+
"img",
|
|
10
|
+
"input",
|
|
11
|
+
"link",
|
|
12
|
+
"meta",
|
|
13
|
+
"param",
|
|
14
|
+
"source",
|
|
15
|
+
"track",
|
|
16
|
+
"wbr"
|
|
17
|
+
]), t = (e) => e ? Object.entries(e).filter(([, e]) => e != null).map(([e, t]) => typeof t == "boolean" ? t ? e : "" : e === "_innerHTML" ? "" : `${e}="${String(t).replace(/&/g, "&").replace(/"/g, """)}"`).filter(Boolean).join(" ") : "", n = "__vanilla_fragment__", r = {
|
|
18
|
+
createElement: (r, i, ...a) => {
|
|
19
|
+
let o = a.flat(Infinity).join("");
|
|
20
|
+
if (r === n) return o;
|
|
21
|
+
if (typeof r == "string") {
|
|
22
|
+
let n = t(i), a = n ? ` ${n}` : "", s = i?._innerHTML;
|
|
23
|
+
return e.has(r) ? `<${r}${a}>` : s === void 0 ? `<${r}${a}>${o}</${r}>` : `<${r}${a}>${s}</${r}>`;
|
|
24
|
+
}
|
|
25
|
+
if (typeof r == "function") try {
|
|
26
|
+
let e = r({
|
|
27
|
+
...i,
|
|
28
|
+
children: o
|
|
29
|
+
});
|
|
30
|
+
return typeof e == "string" ? e : o;
|
|
31
|
+
} catch {
|
|
32
|
+
return o;
|
|
33
|
+
}
|
|
34
|
+
return o;
|
|
35
|
+
},
|
|
36
|
+
cloneElement: (e, t, ...n) => typeof e == "string" ? e : String(e ?? ""),
|
|
37
|
+
Fragment: n,
|
|
38
|
+
normalizeProps: (e, t) => {
|
|
39
|
+
let n = {};
|
|
40
|
+
for (let [e, r] of Object.entries(t)) e === "className" ? n.class = r : e === "htmlFor" ? n.for = r : e === "dangerouslySetInnerHTML" && r?.__html ? n._innerHTML = r.__html : n[e] = r;
|
|
41
|
+
return n;
|
|
42
|
+
}
|
|
43
|
+
}, i = (e = {}) => {
|
|
44
|
+
let { onCreateElement: t } = e;
|
|
45
|
+
return t ? {
|
|
46
|
+
...r,
|
|
47
|
+
createElement: (e, n, ...r) => t(e, n, r)
|
|
48
|
+
} : r;
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { i as createVanillaRuntime, r as default, r as vanillaRuntime };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { renderIntlayerNode as e } from "./renderIntlayerNode.mjs";
|
|
2
|
+
import { conditionPlugin as t, enumerationPlugin as n, filePlugin as r, genderPlugin as i, nestedPlugin as a, splitInsertionTemplate as o, translationPlugin as s } from "@intlayer/core/interpreter";
|
|
3
|
+
import c from "@intlayer/config/built";
|
|
4
|
+
import { getMarkdownMetadata as l } from "@intlayer/core/markdown";
|
|
5
|
+
import { isEnabled as u } from "@intlayer/editor/isEnabled";
|
|
6
|
+
import * as d from "@intlayer/types/nodeType";
|
|
7
|
+
//#region src/plugins.ts
|
|
8
|
+
var f = (e) => e.replace(/&/g, "&").replace(/"/g, """), p = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), m = {
|
|
9
|
+
id: "intlayer-node-plugin",
|
|
10
|
+
canHandle: (e) => typeof e == "bigint" || typeof e == "string" || typeof e == "number",
|
|
11
|
+
transform: (t, { children: n, keyPath: r, dictionaryKey: i, ...a }) => {
|
|
12
|
+
if (u && typeof document < "u") {
|
|
13
|
+
let e = String(n ?? ""), t = JSON.stringify(r ?? []), a = String(i ?? ""), o = `<intlayer-content-selector-wrapper key-path="${f(t)}" dictionary-key="${f(a)}">${p(e)}</intlayer-content-selector-wrapper>`, s = {
|
|
14
|
+
toString: () => o,
|
|
15
|
+
valueOf: () => e,
|
|
16
|
+
[Symbol.toPrimitive]: (e) => o,
|
|
17
|
+
toJSON: () => e,
|
|
18
|
+
get raw() {
|
|
19
|
+
return e;
|
|
20
|
+
},
|
|
21
|
+
get value() {
|
|
22
|
+
return e;
|
|
23
|
+
},
|
|
24
|
+
__update(e) {},
|
|
25
|
+
toElement: () => {
|
|
26
|
+
let n = document.createElement("intlayer-content-selector-wrapper");
|
|
27
|
+
return n.setAttribute("key-path", t), n.setAttribute("dictionary-key", a), n.textContent = e, n;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return Object.setPrototypeOf(s, String.prototype), s;
|
|
31
|
+
}
|
|
32
|
+
return e({
|
|
33
|
+
...a,
|
|
34
|
+
value: n,
|
|
35
|
+
children: n
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, h = {
|
|
39
|
+
id: "insertion-plugin",
|
|
40
|
+
canHandle: (e) => typeof e == "object" && e?.nodeType === d.INSERTION,
|
|
41
|
+
transform: (e, t, n) => {
|
|
42
|
+
let r = [...t.keyPath, { type: d.INSERTION }], i = e[d.INSERTION], a = {
|
|
43
|
+
id: "insertion-string-plugin",
|
|
44
|
+
canHandle: (e) => typeof e == "string",
|
|
45
|
+
transform: (e, n, r) => {
|
|
46
|
+
let i = r(e, {
|
|
47
|
+
...n,
|
|
48
|
+
children: e,
|
|
49
|
+
plugins: (t.plugins ?? []).filter((e) => e.id !== "intlayer-node-plugin")
|
|
50
|
+
});
|
|
51
|
+
return (e) => {
|
|
52
|
+
let a = o(i, e), s = a.isSimple ? a.parts : a.parts.join("");
|
|
53
|
+
return r(s, {
|
|
54
|
+
...n,
|
|
55
|
+
plugins: t.plugins,
|
|
56
|
+
children: s
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}, s = n(i, {
|
|
61
|
+
...t,
|
|
62
|
+
children: i,
|
|
63
|
+
keyPath: r,
|
|
64
|
+
plugins: [a, ...t.plugins ?? []]
|
|
65
|
+
});
|
|
66
|
+
return typeof i == "object" && i && "nodeType" in i && [d.ENUMERATION, d.CONDITION].includes(i.nodeType) ? (e) => (t) => {
|
|
67
|
+
let n = s(t);
|
|
68
|
+
return typeof n == "function" ? n(e) : n;
|
|
69
|
+
} : s;
|
|
70
|
+
}
|
|
71
|
+
}, g = {
|
|
72
|
+
id: "markdown-string-plugin",
|
|
73
|
+
canHandle: (e) => typeof e == "string",
|
|
74
|
+
transform: (t, n, r) => {
|
|
75
|
+
let { plugins: i, ...a } = n, o = r(l(t) ?? {}, {
|
|
76
|
+
plugins: [{
|
|
77
|
+
id: "markdown-metadata-plugin",
|
|
78
|
+
canHandle: (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean" || !e,
|
|
79
|
+
transform: (n, r) => e({
|
|
80
|
+
...r,
|
|
81
|
+
value: n,
|
|
82
|
+
children: t
|
|
83
|
+
})
|
|
84
|
+
}],
|
|
85
|
+
dictionaryKey: a.dictionaryKey,
|
|
86
|
+
keyPath: []
|
|
87
|
+
});
|
|
88
|
+
return e({
|
|
89
|
+
...n,
|
|
90
|
+
value: t,
|
|
91
|
+
children: t,
|
|
92
|
+
additionalProps: {
|
|
93
|
+
metadata: o,
|
|
94
|
+
use: (e) => t
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, _ = {
|
|
99
|
+
id: "markdown-plugin",
|
|
100
|
+
canHandle: (e) => typeof e == "object" && e?.nodeType === d.MARKDOWN,
|
|
101
|
+
transform: (e, t, n) => {
|
|
102
|
+
let r = [...t.keyPath, { type: d.MARKDOWN }], i = e[d.MARKDOWN];
|
|
103
|
+
return n(i, {
|
|
104
|
+
...t,
|
|
105
|
+
children: i,
|
|
106
|
+
keyPath: r,
|
|
107
|
+
plugins: [g, ...t.plugins ?? []]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}, v = {
|
|
111
|
+
id: "html-plugin",
|
|
112
|
+
canHandle: (e) => typeof e == "object" && e?.nodeType === d.HTML,
|
|
113
|
+
transform: (t, n) => {
|
|
114
|
+
let r = t[d.HTML];
|
|
115
|
+
return e({
|
|
116
|
+
...n,
|
|
117
|
+
value: r,
|
|
118
|
+
children: r,
|
|
119
|
+
additionalProps: { use: (e) => r }
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}, y = (e, o = !0) => [
|
|
123
|
+
s(e ?? c.internationalization.defaultLocale, o ? c.internationalization.defaultLocale : void 0),
|
|
124
|
+
n,
|
|
125
|
+
t,
|
|
126
|
+
a(e ?? c.internationalization.defaultLocale),
|
|
127
|
+
r,
|
|
128
|
+
i,
|
|
129
|
+
m,
|
|
130
|
+
h,
|
|
131
|
+
_,
|
|
132
|
+
v
|
|
133
|
+
];
|
|
134
|
+
//#endregion
|
|
135
|
+
export { y as getPlugins, v as htmlPlugin, h as insertionPlugin, m as intlayerNodePlugins, _ as markdownPlugin, g as markdownStringPlugin };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/renderIntlayerNode.ts
|
|
2
|
+
var e = ({ value: e, additionalProps: t = {} }) => {
|
|
3
|
+
let n = e, r = {
|
|
4
|
+
toString: () => String(n ?? ""),
|
|
5
|
+
valueOf: () => n,
|
|
6
|
+
[Symbol.toPrimitive]: () => n,
|
|
7
|
+
toJSON: () => n,
|
|
8
|
+
get raw() {
|
|
9
|
+
return n;
|
|
10
|
+
},
|
|
11
|
+
set raw(e) {
|
|
12
|
+
n = e;
|
|
13
|
+
},
|
|
14
|
+
get value() {
|
|
15
|
+
return n;
|
|
16
|
+
},
|
|
17
|
+
__update(e) {
|
|
18
|
+
n = e?.raw ?? e?.value ?? e;
|
|
19
|
+
},
|
|
20
|
+
...t
|
|
21
|
+
};
|
|
22
|
+
return Object.setPrototypeOf(r, String.prototype), r;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { e as renderIntlayerNode };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import e from "@intlayer/config/built";
|
|
2
|
+
import { isEnabled as t } from "@intlayer/editor/isEnabled";
|
|
3
|
+
//#region src/editor/useEditor.ts
|
|
4
|
+
var n = () => {
|
|
5
|
+
if (!t) return () => {};
|
|
6
|
+
let e = null, n = !1;
|
|
7
|
+
return import("@intlayer/editor").then(({ initEditorClient: t }) => {
|
|
8
|
+
if (n) return;
|
|
9
|
+
let r = t(), i = o();
|
|
10
|
+
r.currentLocale.set(i.locale), e = i.subscribe((e) => {
|
|
11
|
+
r.currentLocale.set(e);
|
|
12
|
+
});
|
|
13
|
+
}), () => {
|
|
14
|
+
n = !0, e?.(), import("@intlayer/editor").then(({ stopEditorClient: e }) => {
|
|
15
|
+
e();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}, r = class {
|
|
19
|
+
_locale;
|
|
20
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
21
|
+
isCookieEnabled;
|
|
22
|
+
constructor(t, n = !0) {
|
|
23
|
+
let { defaultLocale: r } = e.internationalization ?? {};
|
|
24
|
+
this._locale = t ?? r, this.isCookieEnabled = n;
|
|
25
|
+
}
|
|
26
|
+
get locale() {
|
|
27
|
+
return this._locale;
|
|
28
|
+
}
|
|
29
|
+
setLocale(e) {
|
|
30
|
+
this._locale = e;
|
|
31
|
+
for (let t of this._listeners) t(e);
|
|
32
|
+
}
|
|
33
|
+
subscribe(e) {
|
|
34
|
+
return this._listeners.add(e), () => {
|
|
35
|
+
this._listeners.delete(e);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
notify() {
|
|
39
|
+
for (let e of this._listeners) e(this._locale);
|
|
40
|
+
}
|
|
41
|
+
}, i = null, a = (e, t = !0) => i || (i = new r(e, t), i), o = () => (i ||= new r(), i), s = ({ locale: e, isCookieEnabled: t } = {}) => {
|
|
42
|
+
let r = a(e, t);
|
|
43
|
+
return n(), r;
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { n as a, s as i, a as n, o as r, r as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./chunk-C91j1N6u.js`);let t=require(`@intlayer/config/built`);t=e.t(t);let n=require(`@intlayer/editor/isEnabled`);var r=()=>{if(!n.isEnabled)return()=>{};let e=null,t=!1;return import(`@intlayer/editor`).then(({initEditorClient:n})=>{if(t)return;let r=n(),i=s();r.currentLocale.set(i.locale),e=i.subscribe(e=>{r.currentLocale.set(e)})}),()=>{t=!0,e?.(),import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()})}},i=class{_locale;_listeners=new Set;isCookieEnabled;constructor(e,n=!0){let{defaultLocale:r}=t.default.internationalization??{};this._locale=e??r,this.isCookieEnabled=n}get locale(){return this._locale}setLocale(e){this._locale=e;for(let t of this._listeners)t(e)}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}notify(){for(let e of this._listeners)e(this._locale)}},a=null,o=(e,t=!0)=>a||(a=new i(e,t),a),s=()=>(a||=new i,a),c=({locale:e,isCookieEnabled:t}={})=>{let n=o(e,t);return r(),n};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
type LocaleListener = (locale: LocalesValues) => void;
|
|
3
|
+
export declare class IntlayerClient {
|
|
4
|
+
private _locale;
|
|
5
|
+
private _listeners;
|
|
6
|
+
isCookieEnabled: boolean;
|
|
7
|
+
constructor(locale?: LocalesValues, isCookieEnabled?: boolean);
|
|
8
|
+
get locale(): LocalesValues;
|
|
9
|
+
setLocale(newLocale: LocalesValues): void;
|
|
10
|
+
subscribe(listener: LocaleListener): () => void;
|
|
11
|
+
/**
|
|
12
|
+
* Fire all listeners with the current locale without changing it.
|
|
13
|
+
* Used to trigger re-renders after async data loads.
|
|
14
|
+
*/
|
|
15
|
+
notify(): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create and return a single IntlayerClient instance.
|
|
19
|
+
*/
|
|
20
|
+
export declare const createIntlayerClient: (locale?: LocalesValues, isCookieEnabled?: boolean) => IntlayerClient;
|
|
21
|
+
/**
|
|
22
|
+
* Get the current IntlayerClient instance, creating one with defaults if needed.
|
|
23
|
+
*/
|
|
24
|
+
export declare const getIntlayerClient: () => IntlayerClient;
|
|
25
|
+
/**
|
|
26
|
+
* Install Intlayer into your vanilla JS application.
|
|
27
|
+
*
|
|
28
|
+
* Call this once at application startup, before any Intlayer APIs are used.
|
|
29
|
+
*
|
|
30
|
+
* When called with a `config` argument, `window.INTLAYER_CONFIG` is set so
|
|
31
|
+
* that `@intlayer/config/built` resolves the correct values in the browser
|
|
32
|
+
* without requiring module aliasing in the bundler configuration.
|
|
33
|
+
*
|
|
34
|
+
* @param locale - Initial locale (defaults to config defaultLocale).
|
|
35
|
+
* @param isCookieEnabled - Whether to persist locale in cookies/localStorage.
|
|
36
|
+
* @param config - Optional Intlayer configuration. When provided, sets
|
|
37
|
+
* `window.INTLAYER_CONFIG` with the browser-safe subset of the config so
|
|
38
|
+
* the application works without a Vite/webpack plugin alias.
|
|
39
|
+
* @returns The IntlayerClient singleton.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { installIntlayer } from 'vanilla-intlayer';
|
|
44
|
+
*
|
|
45
|
+
* // With explicit config (no build plugin alias needed):
|
|
46
|
+
* installIntlayer('en', true, {
|
|
47
|
+
* internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // With build plugin (alias handles config automatically):
|
|
51
|
+
* installIntlayer('en');
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const installIntlayer: ({ locale, isCookieEnabled, }?: {
|
|
55
|
+
locale?: LocalesValues;
|
|
56
|
+
isCookieEnabled?: boolean;
|
|
57
|
+
}) => IntlayerClient;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
import { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import { DeepTransformContent } from '../plugins';
|
|
4
|
+
export type WithOnChange<T> = T & {
|
|
5
|
+
/**
|
|
6
|
+
* Subscribe to locale changes. The callback receives the fresh content
|
|
7
|
+
* whenever the active locale changes. Returns the content object itself
|
|
8
|
+
* for convenient one-liner patterns:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const content = useDictionary(myDict).onChange((c) => {
|
|
12
|
+
* document.querySelector('p')!.textContent = String(c.greeting);
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
onChange: (callback: <T extends Dictionary, L extends LocalesValues>(content: DeepTransformContent<T['content'], L>) => void) => WithOnChange<T>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get the translated content for a raw dictionary object and optionally
|
|
20
|
+
* subscribe to locale changes via the chainable `.onChange()` method —
|
|
21
|
+
* mirroring the API of `react-intlayer`.
|
|
22
|
+
*
|
|
23
|
+
* Unlike `useIntlayer` (which takes a registered key), this function accepts a
|
|
24
|
+
* dictionary object directly — useful for dictionaries loaded asynchronously
|
|
25
|
+
* or defined inline.
|
|
26
|
+
*
|
|
27
|
+
* The function returns the current content **directly** (same shape as
|
|
28
|
+
* `getDictionary(dict)`), plus the `.onChange()` helper:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // React
|
|
32
|
+
* const content = useDictionary(myDict);
|
|
33
|
+
*
|
|
34
|
+
* // Vanilla — identical surface API, opt-in reactivity via .onChange()
|
|
35
|
+
* const content = useDictionary(myDict);
|
|
36
|
+
* const content = useDictionary(myDict).onChange((c) => render(c));
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param dictionary - The raw dictionary object.
|
|
40
|
+
* @param locale - Optional locale override.
|
|
41
|
+
* @returns The current translated content with an `.onChange()` method.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import myDict from './myDictionary.content';
|
|
46
|
+
* import { installIntlayer, useDictionary } from 'vanilla-intlayer';
|
|
47
|
+
*
|
|
48
|
+
* installIntlayer();
|
|
49
|
+
*
|
|
50
|
+
* const content = useDictionary(myDict).onChange((c) => {
|
|
51
|
+
* document.querySelector('p').textContent = String(c.greeting);
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* document.querySelector('p').textContent = String(content.greeting);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const useDictionary: <T extends Dictionary, L extends LocalesValues = DeclaredLocales>(dictionary: T, locale?: L) => WithOnChange<DeepTransformContent<T["content"], L>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
import { DictionaryKeys, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import { DeepTransformContent } from '../plugins';
|
|
4
|
+
import { WithOnChange } from './useDictionary';
|
|
5
|
+
/**
|
|
6
|
+
* Dynamically load and transform a locale-keyed dictionary.
|
|
7
|
+
*
|
|
8
|
+
* Works like `useIntlayer` / `useDictionary` but accepts a locale-keyed map
|
|
9
|
+
* of lazy loaders instead of a pre-imported dictionary. Call it inside your
|
|
10
|
+
* render function — the first call triggers a background fetch and returns
|
|
11
|
+
* placeholder values; when the load completes the client notifies all
|
|
12
|
+
* subscribers (including your render loop) so the render runs again with real
|
|
13
|
+
* content. Subsequent calls for the same locale return immediately from cache.
|
|
14
|
+
*
|
|
15
|
+
* Locale switches follow the same two-phase pattern: placeholder on first
|
|
16
|
+
* render, real content after the locale bundle loads.
|
|
17
|
+
*
|
|
18
|
+
* @param dictionaryLoaders - Locale-keyed map of `() => Promise<Dictionary>`.
|
|
19
|
+
* @param key - Dictionary key (used for cache namespacing).
|
|
20
|
+
* @param locale - Optional locale override.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import dynDic from '../.intlayer/dynamic_dictionary/app.mjs';
|
|
25
|
+
*
|
|
26
|
+
* const render = () => {
|
|
27
|
+
* const content = useDictionaryDynamic(dynDic, 'app');
|
|
28
|
+
* document.querySelector('h1')!.textContent = String(content.title);
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* render();
|
|
32
|
+
* getIntlayerClient().subscribe(() => render());
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const useDictionaryDynamic: <T extends Dictionary, K extends DictionaryKeys, L extends LocalesValues = LocalesValues>(dictionaryLoaders: StrictModeLocaleMap<() => Promise<T>>, key: K, locale?: L) => WithOnChange<DeepTransformContent<T["content"], L>>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
import { DeepTransformContent } from '../plugins';
|
|
3
|
+
import { WithOnChange } from './useDictionary';
|
|
4
|
+
/**
|
|
5
|
+
* Get the translated content for the given key and optionally subscribe to
|
|
6
|
+
* locale changes via the chainable `.onChange()` method — mirroring the API
|
|
7
|
+
* of `react-intlayer`'s `useIntlayer`.
|
|
8
|
+
*
|
|
9
|
+
* Unlike React (where the hook system automatically re-runs on re-render),
|
|
10
|
+
* vanilla JS has no component lifecycle. The `.onChange()` callback is the
|
|
11
|
+
* explicit equivalent: it is called with fresh content whenever the active
|
|
12
|
+
* locale changes. Use it to patch your DOM or trigger a full re-render.
|
|
13
|
+
*
|
|
14
|
+
* The function returns the current content **directly** (same shape as
|
|
15
|
+
* `getIntlayer(key)`), plus the `.onChange()` helper:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* // React
|
|
19
|
+
* const content = useIntlayer('app');
|
|
20
|
+
*
|
|
21
|
+
* // Vanilla — identical surface API, opt-in reactivity via .onChange()
|
|
22
|
+
* const content = useIntlayer('app');
|
|
23
|
+
* const content = useIntlayer('app').onChange((c) => render(c));
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* For cleanup (e.g. Vite HMR), subscribe via `getIntlayerClient().subscribe()`
|
|
27
|
+
* and hold the returned unsubscribe function.
|
|
28
|
+
*
|
|
29
|
+
* @param key - Dictionary key registered in your intlayer content files.
|
|
30
|
+
* @param locale - Optional locale override (defaults to the current app locale).
|
|
31
|
+
* @returns The current translated content with an `.onChange()` method.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { installIntlayer, useIntlayer } from 'vanilla-intlayer';
|
|
36
|
+
*
|
|
37
|
+
* installIntlayer();
|
|
38
|
+
*
|
|
39
|
+
* // Static read (no subscription)
|
|
40
|
+
* const content = useIntlayer('homepage');
|
|
41
|
+
* document.querySelector('h1').textContent = String(content.title);
|
|
42
|
+
*
|
|
43
|
+
* // Reactive read — onChange is called on every locale change
|
|
44
|
+
* useIntlayer('homepage').onChange((c) => {
|
|
45
|
+
* document.querySelector('h1').textContent = String(c.title);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const useIntlayer: <T extends DictionaryKeys>(key: T, locale?: LocalesValues) => WithOnChange<DeepTransformContent<DictionaryRegistryContent<T>>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
type UseLocaleProps = {
|
|
3
|
+
isCookieEnabled?: boolean;
|
|
4
|
+
onLocaleChange?: (locale: LocalesValues) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Get the current locale state and locale management utilities.
|
|
8
|
+
*
|
|
9
|
+
* Returns a plain object with the current `locale`, `defaultLocale`,
|
|
10
|
+
* `availableLocales`, a `setLocale` function, and a `subscribe` function
|
|
11
|
+
* to react to locale changes.
|
|
12
|
+
*
|
|
13
|
+
* @param props - Optional configuration.
|
|
14
|
+
* @returns Locale state and management utilities.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { installIntlayer, useLocale } from 'vanilla-intlayer';
|
|
19
|
+
*
|
|
20
|
+
* installIntlayer('en');
|
|
21
|
+
*
|
|
22
|
+
* const { locale, availableLocales, setLocale, subscribe } = useLocale();
|
|
23
|
+
*
|
|
24
|
+
* const unsubscribe = subscribe((newLocale) => {
|
|
25
|
+
* console.log('Locale changed to', newLocale);
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* document.querySelector('#lang-switcher').addEventListener('change', (e) => {
|
|
29
|
+
* setLocale(e.target.value);
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const useLocale: (props?: UseLocaleProps) => {
|
|
34
|
+
locale: DeclaredLocales;
|
|
35
|
+
defaultLocale: DeclaredLocales;
|
|
36
|
+
availableLocales: DeclaredLocales[];
|
|
37
|
+
setLocale: (newLocale: LocalesValues) => void;
|
|
38
|
+
subscribe: (callback: (locale: LocalesValues) => void) => () => void;
|
|
39
|
+
};
|
|
40
|
+
export {};
|