vanilla-intlayer 8.7.14 → 8.9.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.
Files changed (209) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/cjs/client/index.cjs +24 -1
  3. package/dist/cjs/client/installIntlayer.cjs +98 -1
  4. package/dist/cjs/client/installIntlayer.cjs.map +1 -0
  5. package/dist/cjs/client/useDictionary.cjs +59 -1
  6. package/dist/cjs/client/useDictionary.cjs.map +1 -0
  7. package/dist/cjs/client/useDictionaryDynamic.cjs +93 -1
  8. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
  9. package/dist/cjs/client/useIntlayer.cjs +65 -1
  10. package/dist/cjs/client/useIntlayer.cjs.map +1 -0
  11. package/dist/cjs/client/useLocale.cjs +58 -1
  12. package/dist/cjs/client/useLocale.cjs.map +1 -0
  13. package/dist/cjs/client/useLocaleStorage.cjs +51 -1
  14. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
  15. package/dist/cjs/client/useRewriteURL.cjs +46 -1
  16. package/dist/cjs/client/useRewriteURL.cjs.map +1 -0
  17. package/dist/cjs/editor/useEditor.cjs +49 -1
  18. package/dist/cjs/editor/useEditor.cjs.map +1 -0
  19. package/dist/cjs/format/index.cjs +20 -1
  20. package/dist/cjs/format/useCompact.cjs +17 -1
  21. package/dist/cjs/format/useCompact.cjs.map +1 -0
  22. package/dist/cjs/format/useCurrency.cjs +17 -1
  23. package/dist/cjs/format/useCurrency.cjs.map +1 -0
  24. package/dist/cjs/format/useDate.cjs +26 -1
  25. package/dist/cjs/format/useDate.cjs.map +1 -0
  26. package/dist/cjs/format/useIntl.cjs +44 -1
  27. package/dist/cjs/format/useIntl.cjs.map +1 -0
  28. package/dist/cjs/format/useList.cjs +17 -1
  29. package/dist/cjs/format/useList.cjs.map +1 -0
  30. package/dist/cjs/format/useNumber.cjs +20 -1
  31. package/dist/cjs/format/useNumber.cjs.map +1 -0
  32. package/dist/cjs/format/usePercentage.cjs +17 -1
  33. package/dist/cjs/format/usePercentage.cjs.map +1 -0
  34. package/dist/cjs/format/useRelativeTime.cjs +17 -1
  35. package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
  36. package/dist/cjs/format/useUnit.cjs +17 -1
  37. package/dist/cjs/format/useUnit.cjs.map +1 -0
  38. package/dist/cjs/getDictionary.cjs +11 -1
  39. package/dist/cjs/getDictionary.cjs.map +1 -0
  40. package/dist/cjs/getIntlayer.cjs +11 -1
  41. package/dist/cjs/getIntlayer.cjs.map +1 -0
  42. package/dist/cjs/html/HTMLRenderer.cjs +22 -1
  43. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -0
  44. package/dist/cjs/html/index.cjs +9 -1
  45. package/dist/cjs/html/installIntlayerHTML.cjs +91 -1
  46. package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -0
  47. package/dist/cjs/html/types.cjs +0 -1
  48. package/dist/cjs/index.cjs +37 -1
  49. package/dist/cjs/markdown/MarkdownRenderer.cjs +41 -1
  50. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
  51. package/dist/cjs/markdown/compiler.cjs +37 -1
  52. package/dist/cjs/markdown/compiler.cjs.map +1 -0
  53. package/dist/cjs/markdown/index.cjs +11 -1
  54. package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
  55. package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -0
  56. package/dist/cjs/markdown/runtime.cjs +87 -1
  57. package/dist/cjs/markdown/runtime.cjs.map +1 -0
  58. package/dist/cjs/plugins.cjs +240 -1
  59. package/dist/cjs/plugins.cjs.map +1 -0
  60. package/dist/cjs/renderIntlayerNode.cjs +44 -1
  61. package/dist/cjs/renderIntlayerNode.cjs.map +1 -0
  62. package/dist/esm/client/index.mjs +9 -8
  63. package/dist/esm/client/installIntlayer.mjs +93 -2
  64. package/dist/esm/client/installIntlayer.mjs.map +1 -0
  65. package/dist/esm/client/useDictionary.mjs +55 -8
  66. package/dist/esm/client/useDictionary.mjs.map +1 -0
  67. package/dist/esm/client/useDictionaryDynamic.mjs +82 -28
  68. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
  69. package/dist/esm/client/useIntlayer.mjs +61 -8
  70. package/dist/esm/client/useIntlayer.mjs.map +1 -0
  71. package/dist/esm/client/useLocale.mjs +51 -17
  72. package/dist/esm/client/useLocale.mjs.map +1 -0
  73. package/dist/esm/client/useLocaleStorage.mjs +39 -13
  74. package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
  75. package/dist/esm/client/useRewriteURL.mjs +40 -12
  76. package/dist/esm/client/useRewriteURL.mjs.map +1 -0
  77. package/dist/esm/editor/useEditor.mjs +47 -2
  78. package/dist/esm/editor/useEditor.mjs.map +1 -0
  79. package/dist/esm/format/index.mjs +11 -10
  80. package/dist/esm/format/useCompact.mjs +11 -8
  81. package/dist/esm/format/useCompact.mjs.map +1 -0
  82. package/dist/esm/format/useCurrency.mjs +11 -8
  83. package/dist/esm/format/useCurrency.mjs.map +1 -0
  84. package/dist/esm/format/useDate.mjs +18 -12
  85. package/dist/esm/format/useDate.mjs.map +1 -0
  86. package/dist/esm/format/useIntl.mjs +36 -8
  87. package/dist/esm/format/useIntl.mjs.map +1 -0
  88. package/dist/esm/format/useList.mjs +11 -8
  89. package/dist/esm/format/useList.mjs.map +1 -0
  90. package/dist/esm/format/useNumber.mjs +14 -8
  91. package/dist/esm/format/useNumber.mjs.map +1 -0
  92. package/dist/esm/format/usePercentage.mjs +11 -8
  93. package/dist/esm/format/usePercentage.mjs.map +1 -0
  94. package/dist/esm/format/useRelativeTime.mjs +11 -8
  95. package/dist/esm/format/useRelativeTime.mjs.map +1 -0
  96. package/dist/esm/format/useUnit.mjs +11 -8
  97. package/dist/esm/format/useUnit.mjs.map +1 -0
  98. package/dist/esm/getDictionary.mjs +7 -4
  99. package/dist/esm/getDictionary.mjs.map +1 -0
  100. package/dist/esm/getIntlayer.mjs +7 -4
  101. package/dist/esm/getIntlayer.mjs.map +1 -0
  102. package/dist/esm/html/HTMLRenderer.mjs +17 -5
  103. package/dist/esm/html/HTMLRenderer.mjs.map +1 -0
  104. package/dist/esm/html/index.mjs +4 -3
  105. package/dist/esm/html/installIntlayerHTML.mjs +81 -13
  106. package/dist/esm/html/installIntlayerHTML.mjs.map +1 -0
  107. package/dist/esm/index.mjs +13 -12
  108. package/dist/esm/markdown/MarkdownRenderer.mjs +36 -16
  109. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
  110. package/dist/esm/markdown/compiler.mjs +28 -4
  111. package/dist/esm/markdown/compiler.mjs.map +1 -0
  112. package/dist/esm/markdown/index.mjs +5 -4
  113. package/dist/esm/markdown/installIntlayerMarkdown.mjs +86 -23
  114. package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -0
  115. package/dist/esm/markdown/runtime.mjs +60 -28
  116. package/dist/esm/markdown/runtime.mjs.map +1 -0
  117. package/dist/esm/plugins.mjs +187 -133
  118. package/dist/esm/plugins.mjs.map +1 -0
  119. package/dist/esm/renderIntlayerNode.mjs +32 -15
  120. package/dist/esm/renderIntlayerNode.mjs.map +1 -0
  121. package/dist/types/client/index.d.ts +8 -0
  122. package/dist/{client → types/client}/installIntlayer.d.ts +27 -20
  123. package/dist/types/client/installIntlayer.d.ts.map +1 -0
  124. package/dist/{client → types/client}/useDictionary.d.ts +22 -17
  125. package/dist/types/client/useDictionary.d.ts.map +1 -0
  126. package/dist/{client → types/client}/useDictionaryDynamic.d.ts +10 -5
  127. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
  128. package/dist/{client → types/client}/useIntlayer.d.ts +9 -4
  129. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  130. package/dist/{client → types/client}/useLocale.d.ts +14 -10
  131. package/dist/types/client/useLocale.d.ts.map +1 -0
  132. package/dist/types/client/useLocaleStorage.d.ts +37 -0
  133. package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
  134. package/dist/{client → types/client}/useRewriteURL.d.ts +5 -1
  135. package/dist/types/client/useRewriteURL.d.ts.map +1 -0
  136. package/dist/{editor → types/editor}/useEditor.d.ts +5 -1
  137. package/dist/types/editor/useEditor.d.ts.map +1 -0
  138. package/dist/types/format/index.d.ts +10 -0
  139. package/dist/types/format/useCompact.d.ts +7 -0
  140. package/dist/types/format/useCompact.d.ts.map +1 -0
  141. package/dist/types/format/useCurrency.d.ts +7 -0
  142. package/dist/types/format/useCurrency.d.ts.map +1 -0
  143. package/dist/types/format/useDate.d.ts +10 -0
  144. package/dist/types/format/useDate.d.ts.map +1 -0
  145. package/dist/{format → types/format}/useIntl.d.ts +10 -5
  146. package/dist/types/format/useIntl.d.ts.map +1 -0
  147. package/dist/types/format/useList.d.ts +7 -0
  148. package/dist/types/format/useList.d.ts.map +1 -0
  149. package/dist/types/format/useNumber.d.ts +10 -0
  150. package/dist/types/format/useNumber.d.ts.map +1 -0
  151. package/dist/types/format/usePercentage.d.ts +7 -0
  152. package/dist/types/format/usePercentage.d.ts.map +1 -0
  153. package/dist/types/format/useRelativeTime.d.ts +7 -0
  154. package/dist/types/format/useRelativeTime.d.ts.map +1 -0
  155. package/dist/types/format/useUnit.d.ts +7 -0
  156. package/dist/types/format/useUnit.d.ts.map +1 -0
  157. package/dist/types/getDictionary.d.ts +9 -0
  158. package/dist/types/getDictionary.d.ts.map +1 -0
  159. package/dist/types/getIntlayer.d.ts +8 -0
  160. package/dist/types/getIntlayer.d.ts.map +1 -0
  161. package/dist/types/html/HTMLRenderer.d.ts +21 -0
  162. package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
  163. package/dist/types/html/index.d.ts +4 -0
  164. package/dist/{html → types/html}/installIntlayerHTML.d.ts +18 -13
  165. package/dist/types/html/installIntlayerHTML.d.ts.map +1 -0
  166. package/dist/{html → types/html}/types.d.ts +12 -14
  167. package/dist/types/html/types.d.ts.map +1 -0
  168. package/dist/types/index.d.ts +20 -0
  169. package/dist/types/index.d.ts.map +1 -0
  170. package/dist/types/markdown/MarkdownRenderer.d.ts +32 -0
  171. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
  172. package/dist/types/markdown/compiler.d.ts +23 -0
  173. package/dist/types/markdown/compiler.d.ts.map +1 -0
  174. package/dist/types/markdown/index.d.ts +4 -0
  175. package/dist/types/markdown/installIntlayerMarkdown.d.ts +71 -0
  176. package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -0
  177. package/dist/types/markdown/runtime.d.ts +16 -0
  178. package/dist/types/markdown/runtime.d.ts.map +1 -0
  179. package/dist/types/plugins.d.ts +80 -0
  180. package/dist/types/plugins.d.ts.map +1 -0
  181. package/dist/types/renderIntlayerNode.d.ts +31 -0
  182. package/dist/types/renderIntlayerNode.d.ts.map +1 -0
  183. package/package.json +10 -13
  184. package/dist/client/index.d.ts +0 -7
  185. package/dist/client/useLocaleStorage.d.ts +0 -31
  186. package/dist/format/index.d.ts +0 -9
  187. package/dist/format/useCompact.d.ts +0 -2
  188. package/dist/format/useCurrency.d.ts +0 -2
  189. package/dist/format/useDate.d.ts +0 -5
  190. package/dist/format/useList.d.ts +0 -2
  191. package/dist/format/useNumber.d.ts +0 -5
  192. package/dist/format/usePercentage.d.ts +0 -2
  193. package/dist/format/useRelativeTime.d.ts +0 -2
  194. package/dist/format/useUnit.d.ts +0 -2
  195. package/dist/getDictionary.d.ts +0 -4
  196. package/dist/getIntlayer.d.ts +0 -3
  197. package/dist/html/HTMLRenderer.d.ts +0 -14
  198. package/dist/html/index.d.ts +0 -3
  199. package/dist/index.d.ts +0 -11
  200. package/dist/installIntlayer-C99qMzFH.mjs +0 -47
  201. package/dist/installIntlayer-CxkE8IxM.js +0 -1
  202. package/dist/markdown/MarkdownRenderer.d.ts +0 -22
  203. package/dist/markdown/compiler.d.ts +0 -19
  204. package/dist/markdown/index.d.ts +0 -3
  205. package/dist/markdown/installIntlayerMarkdown.d.ts +0 -70
  206. package/dist/markdown/runtime.d.ts +0 -12
  207. package/dist/plugins-Bp8aaTny.js +0 -1
  208. package/dist/plugins.d.ts +0 -78
  209. package/dist/renderIntlayerNode.d.ts +0 -22
@@ -1,178 +1,232 @@
1
- import { renderIntlayerNode as e } from "./renderIntlayerNode.mjs";
2
- import { conditionPlugin as t, enumerationPlugin as n, fallbackPlugin as r, filePlugin as i, genderPlugin as a, getHTML as o, nestedPlugin as s, splitInsertionTemplate as c, translationPlugin as l } from "@intlayer/core/interpreter";
3
- import { editor as u, internationalization as d } from "@intlayer/config/built";
4
- import { compileWithOptions as f, getMarkdownMetadata as p } from "@intlayer/core/markdown";
5
- import * as m from "@intlayer/types/nodeType";
1
+ import { renderIntlayerNode } from "./renderIntlayerNode.mjs";
2
+ import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getHTML, nestedPlugin, pluralPlugin, splitInsertionTemplate, translationPlugin } from "@intlayer/core/interpreter";
3
+ import { editor, internationalization } from "@intlayer/config/built";
4
+ import { compileWithOptions, getMarkdownMetadata } from "@intlayer/core/markdown";
5
+ import * as NodeTypes from "@intlayer/types/nodeType";
6
+
6
7
  //#region src/plugins.ts
7
- var h = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;"), g = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), _ = {
8
+ const escapeHtmlAttr = (str) => str.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
9
+ const escapeHtmlText = (str) => str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
10
+ const intlayerNodePlugins = {
8
11
  id: "intlayer-node-plugin",
9
- canHandle: (e) => typeof e == "bigint" || typeof e == "string" || typeof e == "number",
10
- transform: (t, { children: n, keyPath: r, dictionaryKey: i, ...a }) => {
11
- if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && u.enabled) {
12
- let t = String(n ?? ""), o = JSON.stringify(r ?? []), s = String(i ?? ""), c = `<intlayer-content-selector-wrapper key-path="${h(o)}" dictionary-key="${h(s)}">${g(t)}</intlayer-content-selector-wrapper>`;
13
- return e({
14
- ...a,
15
- value: n,
16
- children: c,
17
- keyPath: r,
18
- dictionaryKey: i,
12
+ canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
13
+ transform: (_node, { children, keyPath, dictionaryKey, ...rest }) => {
14
+ if (process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && editor.enabled) {
15
+ const rawStr = String(children ?? "");
16
+ const keyPathJson = JSON.stringify(keyPath ?? []);
17
+ const dictKey = String(dictionaryKey ?? "");
18
+ /**
19
+ * In editor mode, string coercion returns the wrapper HTML so that
20
+ * `element.innerHTML = content.title` automatically inserts the
21
+ * `<intlayer-content-selector-wrapper>` into the DOM.
22
+ */
23
+ const htmlStr = `<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(keyPathJson)}" dictionary-key="${escapeHtmlAttr(dictKey)}">${escapeHtmlText(rawStr)}</intlayer-content-selector-wrapper>`;
24
+ return renderIntlayerNode({
25
+ ...rest,
26
+ value: children,
27
+ children: htmlStr,
28
+ keyPath,
29
+ dictionaryKey,
19
30
  additionalProps: { toElement: () => {
20
- let e = document.createElement("intlayer-content-selector-wrapper");
21
- return e.setAttribute("key-path", o), e.setAttribute("dictionary-key", s), e.textContent = t, e;
31
+ const wrapper = document.createElement("intlayer-content-selector-wrapper");
32
+ wrapper.setAttribute("key-path", keyPathJson);
33
+ wrapper.setAttribute("dictionary-key", dictKey);
34
+ wrapper.textContent = rawStr;
35
+ return wrapper;
22
36
  } }
23
37
  });
24
38
  }
25
- return e({
26
- ...a,
27
- value: n,
28
- children: n
39
+ return renderIntlayerNode({
40
+ ...rest,
41
+ value: children,
42
+ children
29
43
  });
30
44
  }
31
- }, v = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? r : {
45
+ };
46
+ const insertionPlugin = process.env["INTLAYER_NODE_TYPE_INSERTION"] === "false" ? fallbackPlugin : {
32
47
  id: "insertion-plugin",
33
- canHandle: (e) => typeof e == "object" && e?.nodeType === m.INSERTION,
34
- transform: (e, t, n) => {
35
- let r = [...t.keyPath, { type: m.INSERTION }], i = e[m.INSERTION], a = {
48
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.INSERTION,
49
+ transform: (node, props, deepTransformNode) => {
50
+ const newKeyPath = [...props.keyPath, { type: NodeTypes.INSERTION }];
51
+ const children = node[NodeTypes.INSERTION];
52
+ const insertionStringPlugin = {
36
53
  id: "insertion-string-plugin",
37
- canHandle: (e) => typeof e == "string",
38
- transform: (e, n, r) => {
39
- let i = r(e, {
40
- ...n,
41
- children: e,
42
- plugins: (t.plugins ?? []).filter((e) => e.id !== "intlayer-node-plugin")
54
+ canHandle: (node) => typeof node === "string",
55
+ transform: (node, subProps, deepTransformNode) => {
56
+ const transformedResult = deepTransformNode(node, {
57
+ ...subProps,
58
+ children: node,
59
+ plugins: (props.plugins ?? []).filter((plugin) => plugin.id !== "intlayer-node-plugin")
43
60
  });
44
- return (e) => {
45
- let a = c(i, e), o = a.isSimple ? a.parts : a.parts.join("");
46
- return r(o, {
47
- ...n,
48
- plugins: t.plugins,
49
- children: o
61
+ return (values) => {
62
+ const result = splitInsertionTemplate(transformedResult, values);
63
+ const resultStr = result.isSimple ? result.parts : result.parts.join("");
64
+ return deepTransformNode(resultStr, {
65
+ ...subProps,
66
+ plugins: props.plugins,
67
+ children: resultStr
50
68
  });
51
69
  };
52
70
  }
53
- }, o = n(i, {
54
- ...t,
55
- children: i,
56
- keyPath: r,
57
- plugins: [a, ...t.plugins ?? []]
71
+ };
72
+ const transformed = deepTransformNode(children, {
73
+ ...props,
74
+ children,
75
+ keyPath: newKeyPath,
76
+ plugins: [insertionStringPlugin, ...props.plugins ?? []]
58
77
  });
59
- return typeof i == "object" && i && "nodeType" in i && [m.ENUMERATION, m.CONDITION].includes(i.nodeType) ? (e) => (t) => {
60
- let n = o(t);
61
- return typeof n == "function" ? n(e) : n;
62
- } : o;
78
+ if (typeof children === "object" && children !== null && "nodeType" in children && [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(children.nodeType)) return (values) => (arg) => {
79
+ const inner = transformed(arg);
80
+ return typeof inner === "function" ? inner(values) : inner;
81
+ };
82
+ return transformed;
63
83
  }
64
- }, y = {
65
- createElement: (e, t, ...n) => {
66
- let r = Object.entries(t || {}).filter(([e]) => e !== "children" && e !== "key" && e !== "_innerHTML").map(([e, t]) => `${e}="${t}"`).join(" "), i = t?._innerHTML, a = i === void 0 ? n.flat(Infinity).join("") : i;
67
- return `<${e}${r ? ` ${r}` : ""}>${a}</${e}>`;
84
+ };
85
+ /** ---------------------------------------------
86
+ * MARKDOWN PLUGIN
87
+ * --------------------------------------------- */
88
+ const vanillaRuntime = {
89
+ createElement: (tag, props, ...children) => {
90
+ const attrs = Object.entries(props || {}).filter(([key]) => key !== "children" && key !== "key" && key !== "_innerHTML").map(([key, value]) => `${key}="${value}"`).join(" ");
91
+ const innerHTML = props?._innerHTML;
92
+ const childrenStr = innerHTML !== void 0 ? innerHTML : children.flat(Infinity).join("");
93
+ return `<${tag}${attrs ? ` ${attrs}` : ""}>${childrenStr}</${tag}>`;
68
94
  },
69
- normalizeProps: (e, t) => {
70
- let n = {};
71
- 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;
72
- return n;
95
+ normalizeProps: (_tag, props) => {
96
+ const normalized = {};
97
+ for (const [key, value] of Object.entries(props)) if (key === "className") normalized.class = value;
98
+ else if (key === "htmlFor") normalized.for = value;
99
+ else if (key === "dangerouslySetInnerHTML" && value?.__html) normalized._innerHTML = value.__html;
100
+ else normalized[key] = value;
101
+ return normalized;
73
102
  }
74
- }, b = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? r : {
103
+ };
104
+ const markdownStringPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "false" ? fallbackPlugin : {
75
105
  id: "markdown-string-plugin",
76
- canHandle: (e) => typeof e == "string",
77
- transform: (t, n, r) => {
78
- let { plugins: i, ...a } = n, o = r(p(t) ?? {}, {
106
+ canHandle: (node) => typeof node === "string",
107
+ transform: (node, props, deepTransformNode) => {
108
+ const { plugins: _plugins, ...rest } = props;
109
+ const metadataNodes = deepTransformNode(getMarkdownMetadata(node) ?? {}, {
79
110
  plugins: [{
80
111
  id: "markdown-metadata-plugin",
81
- canHandle: (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean" || !e,
82
- transform: (n, r) => e({
83
- ...r,
84
- value: n,
85
- children: t
112
+ canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
113
+ transform: (metadataNode, subProps) => renderIntlayerNode({
114
+ ...subProps,
115
+ value: metadataNode,
116
+ children: node
86
117
  })
87
118
  }],
88
- dictionaryKey: a.dictionaryKey,
119
+ dictionaryKey: rest.dictionaryKey,
89
120
  keyPath: []
90
- }), s = (e = {}) => f(t, {
91
- ...y,
92
- createElement: (t, n, ...r) => {
93
- let i = e[t];
94
- return typeof i == "function" ? i({
95
- ...n,
96
- children: r.join("")
97
- }) : y.createElement(t, n, ...r);
121
+ });
122
+ const compile = (components = {}) => compileWithOptions(node, {
123
+ ...vanillaRuntime,
124
+ createElement: (tag, props, ...children) => {
125
+ const override = components[tag];
126
+ if (typeof override === "function") return override({
127
+ ...props,
128
+ children: children.join("")
129
+ });
130
+ return vanillaRuntime.createElement(tag, props, ...children);
98
131
  }
99
- }, {}), c = s(), l = t;
100
- if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && u.enabled) {
101
- let e = JSON.stringify(n.keyPath ?? []), t = String(n.dictionaryKey ?? "");
102
- l = `<intlayer-content-selector-wrapper key-path="${h(e)}" dictionary-key="${h(t)}">${g(c)}</intlayer-content-selector-wrapper>`;
132
+ }, {});
133
+ const value = compile();
134
+ let children = node;
135
+ if (process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && editor.enabled) {
136
+ const keyPathJson = JSON.stringify(props.keyPath ?? []);
137
+ const dictKey = String(props.dictionaryKey ?? "");
138
+ children = `<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(keyPathJson)}" dictionary-key="${escapeHtmlAttr(dictKey)}">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;
103
139
  }
104
- return e({
105
- ...n,
106
- value: c,
107
- children: l,
140
+ return renderIntlayerNode({
141
+ ...props,
142
+ value,
143
+ children,
108
144
  additionalProps: {
109
- metadata: o,
110
- use: (e) => s(e)
145
+ metadata: metadataNodes,
146
+ use: (components) => compile(components)
111
147
  }
112
148
  });
113
149
  }
114
- }, x = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? r : {
150
+ };
151
+ const markdownPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "false" ? fallbackPlugin : {
115
152
  id: "markdown-plugin",
116
- canHandle: (e) => typeof e == "object" && e?.nodeType === m.MARKDOWN,
117
- transform: (e, t, n) => {
118
- let r = [...t.keyPath, { type: m.MARKDOWN }], i = e[m.MARKDOWN];
119
- return n(i, {
120
- ...t,
121
- children: i,
122
- keyPath: r,
123
- plugins: [b, ...t.plugins ?? []]
153
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.MARKDOWN,
154
+ transform: (node, props, deepTransformNode) => {
155
+ const newKeyPath = [...props.keyPath, { type: NodeTypes.MARKDOWN }];
156
+ const children = node[NodeTypes.MARKDOWN];
157
+ return deepTransformNode(children, {
158
+ ...props,
159
+ children,
160
+ keyPath: newKeyPath,
161
+ plugins: [markdownStringPlugin, ...props.plugins ?? []]
124
162
  });
125
163
  }
126
- }, S = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? r : {
164
+ };
165
+ const htmlPlugin = process.env["INTLAYER_NODE_TYPE_HTML"] === "false" ? fallbackPlugin : {
127
166
  id: "html-plugin",
128
- canHandle: (e) => typeof e == "object" && e?.nodeType === m.HTML,
129
- transform: (t, n) => {
130
- let r = t[m.HTML], i = (e = {}) => {
131
- let t = o(r, new Proxy(e, { get(e, t) {
132
- if (typeof t == "string" && t in e) {
133
- let n = e[t];
134
- return (e) => {
135
- let t = Array.isArray(e.children) ? e.children.join("") : e.children;
136
- return n({
137
- ...e,
138
- children: t
167
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.HTML,
168
+ transform: (node, props) => {
169
+ const htmlStr = node[NodeTypes.HTML];
170
+ const use = (components = {}) => {
171
+ const result = getHTML(htmlStr, new Proxy(components, { get(target, prop) {
172
+ if (typeof prop === "string" && prop in target) {
173
+ const Component = target[prop];
174
+ return (props) => {
175
+ const children = Array.isArray(props.children) ? props.children.join("") : props.children;
176
+ return Component({
177
+ ...props,
178
+ children
139
179
  });
140
180
  };
141
181
  }
142
- if (typeof t == "string" && /^[a-z][a-z0-9]*$/.test(t)) return (e) => {
143
- let n = Object.entries(e).filter(([e]) => e !== "children" && e !== "key").map(([e, t]) => `${e}="${t}"`).join(" "), r = Array.isArray(e.children) ? e.children.join("") : e.children;
144
- return `<${t}${n ? ` ${n}` : ""}>${r}</${t}>`;
182
+ if (typeof prop === "string" && /^[a-z][a-z0-9]*$/.test(prop)) return (props) => {
183
+ const attrs = Object.entries(props).filter(([key]) => key !== "children" && key !== "key").map(([key, value]) => `${key}="${value}"`).join(" ");
184
+ const children = Array.isArray(props.children) ? props.children.join("") : props.children;
185
+ return `<${prop}${attrs ? ` ${attrs}` : ""}>${children}</${prop}>`;
145
186
  };
146
187
  } }));
147
- return Array.isArray(t) ? t.join("") : t;
148
- }, a = i(), s = r;
149
- if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && u.enabled) {
150
- let e = JSON.stringify(n.keyPath ?? []), t = String(n.dictionaryKey ?? "");
151
- s = `<intlayer-content-selector-wrapper key-path="${h(e)}" dictionary-key="${h(t)}">${g(a)}</intlayer-content-selector-wrapper>`;
188
+ return Array.isArray(result) ? result.join("") : result;
189
+ };
190
+ const value = use();
191
+ let children = htmlStr;
192
+ if (process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && editor.enabled) {
193
+ const keyPathJson = JSON.stringify(props.keyPath ?? []);
194
+ const dictKey = String(props.dictionaryKey ?? "");
195
+ children = `<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(keyPathJson)}" dictionary-key="${escapeHtmlAttr(dictKey)}">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;
152
196
  }
153
- return e({
154
- ...n,
155
- value: a,
156
- children: s,
157
- additionalProps: { use: (e) => i(e) }
197
+ return renderIntlayerNode({
198
+ ...props,
199
+ value,
200
+ children,
201
+ additionalProps: { use: (components) => use(components) }
158
202
  });
159
203
  }
160
- }, C = /* @__PURE__ */ new Map(), w = (e, r = !0) => {
161
- let o = `${e ?? d.defaultLocale}_${r}`;
162
- if (C.has(o)) return C.get(o);
163
- let c = [
164
- l(e ?? d.defaultLocale, r ? d.defaultLocale : void 0),
165
- n,
166
- t,
167
- s(e ?? d.defaultLocale),
168
- i,
169
- a,
170
- _,
171
- v,
172
- x,
173
- S
204
+ };
205
+ const pluginsCache = /* @__PURE__ */ new Map();
206
+ /**
207
+ * Get the plugins array for Vanilla content transformation.
208
+ * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
209
+ */
210
+ const getPlugins = (locale, fallback = true) => {
211
+ const cacheKey = `${locale ?? internationalization.defaultLocale}_${fallback}`;
212
+ if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
213
+ const plugins = [
214
+ translationPlugin(locale ?? internationalization.defaultLocale, fallback ? internationalization.defaultLocale : void 0),
215
+ enumerationPlugin,
216
+ pluralPlugin(locale ?? internationalization.defaultLocale),
217
+ conditionPlugin,
218
+ nestedPlugin(locale ?? internationalization.defaultLocale),
219
+ filePlugin,
220
+ genderPlugin,
221
+ intlayerNodePlugins,
222
+ insertionPlugin,
223
+ markdownPlugin,
224
+ htmlPlugin
174
225
  ];
175
- return C.set(o, c), c;
226
+ pluginsCache.set(cacheKey, plugins);
227
+ return plugins;
176
228
  };
229
+
177
230
  //#endregion
178
- export { w as getPlugins, S as htmlPlugin, v as insertionPlugin, _ as intlayerNodePlugins, x as markdownPlugin, b as markdownStringPlugin };
231
+ export { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin };
232
+ //# sourceMappingURL=plugins.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.ts"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getHTML,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport {\n compileWithOptions,\n getMarkdownMetadata,\n} from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { HTMLComponents } from './html/types';\nimport {\n type IntlayerNode as IntlayerNodeCore,\n renderIntlayerNode,\n} from './renderIntlayerNode';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport type IntlayerNode<T, P = {}> = IntlayerNodeCore<T> & P;\n\nconst escapeHtmlAttr = (str: string): string =>\n str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;');\n\nconst escapeHtmlText = (str: string): string =>\n str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, keyPath, dictionaryKey, ...rest }) => {\n if (process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' && editor.enabled) {\n const rawStr = String(children ?? '');\n const keyPathJson = JSON.stringify(keyPath ?? []);\n const dictKey = String(dictionaryKey ?? '');\n\n /**\n * In editor mode, string coercion returns the wrapper HTML so that\n * `element.innerHTML = content.title` automatically inserts the\n * `<intlayer-content-selector-wrapper>` into the DOM.\n */\n const htmlStr = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(rawStr)}</intlayer-content-selector-wrapper>`;\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children: htmlStr,\n keyPath,\n dictionaryKey,\n additionalProps: {\n toElement: (): HTMLElement => {\n const wrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n wrapper.setAttribute('key-path', keyPathJson);\n wrapper.setAttribute('dictionary-key', dictKey);\n wrapper.textContent = rawStr;\n return wrapper;\n },\n },\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children,\n });\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, _S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly (infer F)[];\n}\n ? <V extends { [K in Extract<F, string>]: string | number }>(\n values: V\n ) => I extends string ? IntlayerNode<string> : DeepTransformContent<I, L>\n : never;\n\nexport const insertionPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_INSERTION'] === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.INSERTION },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: (props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const result = splitInsertionTemplate(\n transformedResult,\n values\n );\n const resultStr = result.isSimple\n ? (result.parts as string)\n : (result.parts as string[]).join('');\n\n return deepTransformNode(resultStr, {\n ...subProps,\n plugins: props.plugins,\n children: resultStr,\n });\n };\n },\n };\n\n const transformed = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n (\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION] as NodeType[]\n ).includes(children.nodeType as NodeType)\n ) {\n return (values: any) => (arg: any) => {\n const inner = (transformed as (a: any) => any)(arg);\n return typeof inner === 'function' ? inner(values) : inner;\n };\n }\n\n return transformed;\n },\n };\n\n/** ---------------------------------------------\n * MARKDOWN PLUGIN\n * --------------------------------------------- */\n\nconst vanillaRuntime = {\n createElement: (tag: string, props: any, ...children: any[]) => {\n const attrs = Object.entries(props || {})\n .filter(\n ([key]) => key !== 'children' && key !== 'key' && key !== '_innerHTML'\n )\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const innerHTML = props?._innerHTML;\n const childrenStr =\n innerHTML !== undefined ? innerHTML : children.flat(Infinity).join('');\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n normalizeProps: (_tag: string, props: Record<string, any>) => {\n const normalized: Record<string, any> = {};\n for (const [key, value] of Object.entries(props)) {\n if (key === 'className') {\n normalized.class = value;\n } else if (key === 'htmlFor') {\n normalized.for = value;\n } else if (key === 'dangerouslySetInnerHTML' && (value as any)?.__html) {\n normalized._innerHTML = (value as any).__html;\n } else {\n normalized[key] = value;\n }\n }\n return normalized;\n },\n};\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n /** Returns the rendered markdown; render with .use(). */\n use: (components?: HTMLComponents<'permissive', {}>) => string;\n }\n >\n : never;\n\nexport const markdownStringPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const { plugins: _plugins, ...rest } = props;\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, subProps) =>\n renderIntlayerNode({\n ...subProps,\n value: metadataNode,\n children: node,\n }),\n };\n\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const compile = (components: any = {}) =>\n compileWithOptions(\n node,\n {\n ...vanillaRuntime,\n createElement: (tag: any, props: any, ...children: any[]) => {\n const override = components[tag];\n if (typeof override === 'function') {\n return override({ ...props, children: children.join('') });\n }\n return vanillaRuntime.createElement(tag, props, ...children);\n },\n },\n {}\n ) as any;\n\n const value = compile();\n let children = node;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n metadata: metadataNodes,\n use: (components?: any) => compile(components),\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n metadata?: infer U;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<M>;\n metadata: DeepTransformContent<U>;\n }\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.MARKDOWN },\n ];\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<I>;\n }\n : never;\n\nexport const htmlPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_HTML'] === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n transform: (node: HTMLContent<string>, props) => {\n const htmlStr = node[NodeTypes.HTML];\n\n const use = (components: Record<string, any> = {}) => {\n const wrappedComponents = new Proxy(components, {\n get(target, prop) {\n if (typeof prop === 'string' && prop in target) {\n const Component = target[prop];\n return (props: any) => {\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return Component({ ...props, children });\n };\n }\n if (typeof prop === 'string' && /^[a-z][a-z0-9]*$/.test(prop)) {\n return (props: any) => {\n const attrs = Object.entries(props)\n .filter(([key]) => key !== 'children' && key !== 'key')\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return `<${prop}${attrs ? ` ${attrs}` : ''}>${children}</${prop}>`;\n };\n }\n return undefined;\n },\n });\n\n const result = getHTML(htmlStr, wrappedComponents as any);\n return Array.isArray(result) ? result.join('') : result;\n };\n\n const value = use();\n let children = htmlStr;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n use: (components?: any) => use(components),\n },\n });\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginVanilla<T, S, L extends LocalesValues> {\n vanillaIntlayerNode: IntlayerNodeCond<T>;\n vanillaInsertion: InsertionCond<T, S, L>;\n vanillaMarkdown: MarkdownCond<T>;\n vanillaHtml: HTMLPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the `vanilla-intlayer` plugins will override the types of `intlayer` functions.\n * Use `getIntlayer` from `vanilla-intlayer` (not from `intlayer`) to get properly typed\n * `IntlayerNode` wrappers with `.value` access on string/number content.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion'\n> & {\n vanillaIntlayerNode: true;\n vanillaInsertion: true;\n vanillaMarkdown: true;\n vanillaHtml: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for Vanilla content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;AAgDA,MAAM,kBAAkB,QACtB,IAAI,QAAQ,MAAM,QAAQ,CAAC,QAAQ,MAAM,SAAS;AAEpD,MAAM,kBAAkB,QACtB,IAAI,QAAQ,MAAM,QAAQ,CAAC,QAAQ,MAAM,OAAO,CAAC,QAAQ,MAAM,OAAO;AAExE,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,EAAE,UAAU,SAAS,eAAe,GAAG,WAAW;AACnE,MAAI,QAAQ,IAAI,+BAA+B,WAAW,OAAO,SAAS;GACxE,MAAM,SAAS,OAAO,YAAY,GAAG;GACrC,MAAM,cAAc,KAAK,UAAU,WAAW,EAAE,CAAC;GACjD,MAAM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C;GACvD,MAAM,UAAU,OAAO,MAAM,iBAAiB,GAAG;AACjD,cAAW,gDAAgD,eAAe,YAAY,CAAC,oBAAoB,eAAe,QAAQ,CAAC,IAAI,eAAe,MAAM,CAAC;;AAG/J,SAAO,mBAAmB;GACxB,GAAG;GACH;GACA;GACA,iBAAiB,EACf,MAAM,eAAqB,IAAI,WAAW,EAC3C;GACF,CAAC;;CAEL;AAmCP,MAAM,+BAAe,IAAI,KAAwB;;;;;AAMjD,MAAa,cACX,QACA,WAAW,SACG;CAEd,MAAM,WAAW,GADK,UAAU,qBAAqB,cACnB,GAAG;AAErC,KAAI,aAAa,IAAI,SAAS,CAC5B,QAAO,aAAa,IAAI,SAAS;CAGnC,MAAM,UAAU;EACd,kBACE,UAAU,qBAAqB,eAC/B,WAAW,qBAAqB,gBAAgB,OACjD;EACD;EACA,aAAa,UAAU,qBAAqB,cAAc;EAC1D;EACA,aAAa,UAAU,qBAAqB,cAAc;EAC1D;EACA;EACA;EACA;EACA;EACA;EACD;AAED,cAAa,IAAI,UAAU,QAAQ;AAEnC,QAAO"}
@@ -1,25 +1,42 @@
1
1
  //#region src/renderIntlayerNode.ts
2
- var e = ({ value: e, children: t, additionalProps: n = {} }) => {
3
- let r = e, i = typeof t == "string" && t !== String(e ?? "") ? t : null, a = {
4
- toString: () => i ?? String(r ?? ""),
5
- valueOf: () => r,
6
- [Symbol.toPrimitive]: () => i ?? r,
7
- toJSON: () => r,
2
+ const renderIntlayerNode = ({ value, children, additionalProps = {} }) => {
3
+ let _value = value;
4
+ const displayOverride = typeof children === "string" && children !== String(value ?? "") ? children : null;
5
+ const node = {
6
+ toString: () => displayOverride ?? String(_value ?? ""),
7
+ valueOf: () => _value,
8
+ [Symbol.toPrimitive]: () => displayOverride ?? _value,
9
+ toJSON: () => _value,
8
10
  get raw() {
9
- return r;
11
+ return _value;
10
12
  },
11
- set raw(e) {
12
- r = e;
13
+ set raw(value) {
14
+ _value = value;
13
15
  },
14
16
  get value() {
15
- return r;
17
+ return _value;
16
18
  },
17
- __update(e) {
18
- r = e?.raw ?? e?.value ?? e;
19
+ __update(next) {
20
+ _value = next?.raw ?? next?.value ?? next;
19
21
  },
20
- ...n
22
+ ...additionalProps
21
23
  };
22
- return Object.setPrototypeOf(a, String.prototype), a;
24
+ if (_value !== null && _value !== void 0) {
25
+ const valObj = Object(_value);
26
+ const proto = Object.getPrototypeOf(valObj);
27
+ for (const prop of Object.getOwnPropertyNames(proto)) {
28
+ if (prop === "constructor" || prop in node) continue;
29
+ const valProp = valObj[prop];
30
+ if (typeof valProp === "function") Object.defineProperty(node, prop, {
31
+ value: valProp.bind(_value),
32
+ writable: true,
33
+ configurable: true
34
+ });
35
+ }
36
+ }
37
+ return node;
23
38
  };
39
+
24
40
  //#endregion
25
- export { e as renderIntlayerNode };
41
+ export { renderIntlayerNode };
42
+ //# sourceMappingURL=renderIntlayerNode.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderIntlayerNode.mjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\nexport type IntlayerNode<T = string> = ResolvedEditor<\n T & {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n },\n {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n }\n> &\n T;\n\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n value,\n children,\n additionalProps = {},\n}: {\n value: T;\n children?: any;\n additionalProps?: Record<string, unknown>;\n [key: string]: unknown;\n}): IntlayerNode<T> => {\n let _value = value;\n\n // When children is a string that differs from value, it acts as a display\n // override (e.g. editor HTML wrapper). Otherwise toString/toPrimitive reflect\n // the live _value so that __update propagates.\n const displayOverride =\n typeof children === 'string' && children !== String(value ?? '')\n ? children\n : null;\n\n const node = {\n toString: () => displayOverride ?? String(_value ?? ''),\n valueOf: () => _value,\n [Symbol.toPrimitive]: () => displayOverride ?? _value,\n toJSON: () => _value,\n\n get raw() {\n return _value;\n },\n set raw(value: T) {\n _value = value;\n },\n\n get value() {\n return _value;\n },\n\n __update(next: any) {\n _value = next?.raw ?? next?.value ?? next;\n },\n\n ...additionalProps,\n };\n\n // Delegate native methods from the underlying value (any type) to node.\n if (_value !== null && _value !== undefined) {\n const valObj = Object(_value); // Safely boxes primitives (e.g., 50 -> Number object)\n const proto = Object.getPrototypeOf(valObj);\n for (const prop of Object.getOwnPropertyNames(proto)) {\n if (prop === 'constructor' || prop in node) continue;\n const valProp = valObj[prop]; // read from instance so length/index values are correct\n if (typeof valProp === 'function') {\n Object.defineProperty(node, prop, {\n value: valProp.bind(_value),\n writable: true,\n configurable: true,\n });\n }\n }\n }\n\n return node as unknown as IntlayerNode<T>;\n};\n"],"mappings":";AAsBA,MAAa,sBAEX,EACA,OACA,UACA,kBAAkB,EAAE,OAMC;CACrB,IAAI,SAAS;CAKb,MAAM,kBACJ,OAAO,aAAa,YAAY,aAAa,OAAO,SAAS,GAAG,GAC5D,WACA;CAEN,MAAM,OAAO;EACX,gBAAgB,mBAAmB,OAAO,UAAU,GAAG;EACvD,eAAe;GACd,OAAO,oBAAoB,mBAAmB;EAC/C,cAAc;EAEd,IAAI,MAAM;AACR,UAAO;;EAET,IAAI,IAAI,OAAU;AAChB,YAAS;;EAGX,IAAI,QAAQ;AACV,UAAO;;EAGT,SAAS,MAAW;AAClB,YAAS,MAAM,OAAO,MAAM,SAAS;;EAGvC,GAAG;EACJ;AAGD,KAAI,WAAW,QAAQ,WAAW,QAAW;EAC3C,MAAM,SAAS,OAAO,OAAO;EAC7B,MAAM,QAAQ,OAAO,eAAe,OAAO;AAC3C,OAAK,MAAM,QAAQ,OAAO,oBAAoB,MAAM,EAAE;AACpD,OAAI,SAAS,iBAAiB,QAAQ,KAAM;GAC5C,MAAM,UAAU,OAAO;AACvB,OAAI,OAAO,YAAY,WACrB,QAAO,eAAe,MAAM,MAAM;IAChC,OAAO,QAAQ,KAAK,OAAO;IAC3B,UAAU;IACV,cAAc;IACf,CAAC;;;AAKR,QAAO"}
@@ -0,0 +1,8 @@
1
+ import { IntlayerClient, createIntlayerClient, getIntlayerClient, installIntlayer } from "./installIntlayer.js";
2
+ import { WithOnChange, useDictionary } from "./useDictionary.js";
3
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
4
+ import { useIntlayer } from "./useIntlayer.js";
5
+ import { useLocale } from "./useLocale.js";
6
+ import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.js";
7
+ import { useRewriteURL } from "./useRewriteURL.js";
8
+ export { IntlayerClient, WithOnChange, createIntlayerClient, getIntlayerClient, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
@@ -1,27 +1,29 @@
1
- import { LocalesValues } from '@intlayer/types/module_augmentation';
1
+ import { LocalesValues } from "@intlayer/types/module_augmentation";
2
+
3
+ //#region src/client/installIntlayer.d.ts
2
4
  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;
5
+ declare class IntlayerClient {
6
+ private _locale;
7
+ private _listeners;
8
+ isCookieEnabled: boolean;
9
+ constructor(locale?: LocalesValues, isCookieEnabled?: boolean);
10
+ get locale(): LocalesValues;
11
+ setLocale(newLocale: LocalesValues): void;
12
+ subscribe(listener: LocaleListener): () => void;
13
+ /**
14
+ * Fire all listeners with the current locale without changing it.
15
+ * Used to trigger re-renders after async data loads.
16
+ */
17
+ notify(): void;
16
18
  }
17
19
  /**
18
20
  * Create and return a single IntlayerClient instance.
19
21
  */
20
- export declare const createIntlayerClient: (locale?: LocalesValues, isCookieEnabled?: boolean) => IntlayerClient;
22
+ declare const createIntlayerClient: (locale?: LocalesValues, isCookieEnabled?: boolean) => IntlayerClient;
21
23
  /**
22
24
  * Get the current IntlayerClient instance, creating one with defaults if needed.
23
25
  */
24
- export declare const getIntlayerClient: () => IntlayerClient;
26
+ declare const getIntlayerClient: () => IntlayerClient;
25
27
  /**
26
28
  * Install Intlayer into your vanilla JS application.
27
29
  *
@@ -51,8 +53,13 @@ export declare const getIntlayerClient: () => IntlayerClient;
51
53
  * installIntlayer('en');
52
54
  * ```
53
55
  */
54
- export declare const installIntlayer: ({ locale, isCookieEnabled, }?: {
55
- locale?: LocalesValues;
56
- isCookieEnabled?: boolean;
56
+ declare const installIntlayer: ({
57
+ locale,
58
+ isCookieEnabled
59
+ }?: {
60
+ locale?: LocalesValues;
61
+ isCookieEnabled?: boolean;
57
62
  }) => IntlayerClient;
58
- export {};
63
+ //#endregion
64
+ export { IntlayerClient, createIntlayerClient, getIntlayerClient, installIntlayer };
65
+ //# sourceMappingURL=installIntlayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installIntlayer.d.ts","names":[],"sources":["../../../src/client/installIntlayer.ts"],"mappings":";;;KAKK,cAAA,IAAkB,MAAA,EAAQ,aAAA;AAAA,cAElB,cAAA;EAAA,QACH,OAAA;EAAA,QACA,UAAA;EACR,eAAA;cAEY,MAAA,GAAS,aAAA,EAAe,eAAA;EAAA,IAUhC,MAAA,CAAA,GAAU,aAAA;EAId,SAAA,CAAU,SAAA,EAAW,aAAA;EAOrB,SAAA,CAAU,QAAA,EAAU,cAAA;;;;;EAWpB,MAAA,CAAA;AAAA;;;;cAeW,oBAAA,GACX,MAAA,GAAS,aAAA,EACT,eAAA,eACC,cAAA;;;;cAUU,iBAAA,QAAwB,cAAA;;;;;;;;;;;;AAbrC;;;;;;;;;;AAaA;;;;;AAoCA;;;cAAa,eAAA;EAAmB,MAAA;EAAA;AAAA;EAI9B,MAAA,GAAS,aAAA;EACT,eAAA;AAAA,MACO,cAAA"}
@@ -1,19 +1,21 @@
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>;
1
+ import { DeepTransformContent } from "../plugins.js";
2
+ import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentation";
3
+ import { Dictionary } from "@intlayer/types/dictionary";
4
+
5
+ //#region src/client/useDictionary.d.ts
6
+ type WithOnChange<T> = T & {
7
+ /**
8
+ * Subscribe to locale changes. The callback receives the fresh content
9
+ * whenever the active locale changes. Returns the content object itself
10
+ * for convenient one-liner patterns:
11
+ *
12
+ * ```ts
13
+ * const content = useDictionary(myDict).onChange((c) => {
14
+ * document.querySelector('p')!.textContent = String(c.greeting);
15
+ * });
16
+ * ```
17
+ */
18
+ onChange: (callback: <T extends Dictionary, L extends LocalesValues>(content: DeepTransformContent<T['content'], L>) => void) => WithOnChange<T>;
17
19
  };
18
20
  /**
19
21
  * Get the translated content for a raw dictionary object and optionally
@@ -54,4 +56,7 @@ export type WithOnChange<T> = T & {
54
56
  * document.querySelector('p').textContent = String(content.greeting);
55
57
  * ```
56
58
  */
57
- export declare const useDictionary: <T extends Dictionary, L extends LocalesValues = DeclaredLocales>(dictionary: T, locale?: L) => WithOnChange<DeepTransformContent<T["content"], L>>;
59
+ declare const useDictionary: <T extends Dictionary, L extends LocalesValues = DeclaredLocales>(dictionary: T, locale?: L) => WithOnChange<DeepTransformContent<T["content"], L>>;
60
+ //#endregion
61
+ export { WithOnChange, useDictionary };
62
+ //# sourceMappingURL=useDictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../../src/client/useDictionary.ts"],"mappings":";;;;;KASY,YAAA,MAAkB,CAAA;;AAA9B;;;;;;;;;;EAYE,QAAA,GACE,QAAA,aAAqB,UAAA,YAAsB,aAAA,EACzC,OAAA,EAAS,oBAAA,CAAqB,CAAA,aAAc,CAAA,eAE3C,YAAA,CAAa,CAAA;AAAA;;;;;;;;;;;;;;;;;;AA0CpB;;;;;;;;;;;;;;;;;;;;;;cAAa,aAAA,aACD,UAAA,YACA,aAAA,GAAgB,eAAA,EAE1B,UAAA,EAAY,CAAA,EACZ,MAAA,GAAS,CAAA,KACR,YAAA,CAAa,oBAAA,CAAqB,CAAA,aAAc,CAAA"}