lit-intlayer 9.9.3 → 9.9.4

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 (72) hide show
  1. package/dist/cjs/client/IntlayerBinding.cjs +93 -1
  2. package/dist/cjs/client/index.cjs +28 -1
  3. package/dist/cjs/client/installIntlayer.cjs +6 -1
  4. package/dist/cjs/client/useDictionary.cjs +24 -1
  5. package/dist/cjs/client/useDictionaryDynamic.cjs +47 -1
  6. package/dist/cjs/client/useIntlayer.cjs +30 -1
  7. package/dist/cjs/client/useLocale.cjs +90 -1
  8. package/dist/cjs/client/useLocaleStorage.cjs +56 -1
  9. package/dist/cjs/client/useRewriteURL.cjs +48 -1
  10. package/dist/cjs/editor/useEditor.cjs +3 -1
  11. package/dist/cjs/format/index.cjs +19 -1
  12. package/dist/cjs/format/useCompact.cjs +34 -1
  13. package/dist/cjs/format/useCurrency.cjs +34 -1
  14. package/dist/cjs/format/useDate.cjs +52 -1
  15. package/dist/cjs/format/useIntl.cjs +66 -1
  16. package/dist/cjs/format/useList.cjs +34 -1
  17. package/dist/cjs/format/useNumber.cjs +40 -1
  18. package/dist/cjs/format/usePercentage.cjs +34 -1
  19. package/dist/cjs/format/useRelativeTime.cjs +34 -1
  20. package/dist/cjs/format/useUnit.cjs +34 -1
  21. package/dist/cjs/getDictionary.cjs +14 -1
  22. package/dist/cjs/getIntlayer.cjs +14 -1
  23. package/dist/cjs/html/HTMLRenderer.cjs +53 -1
  24. package/dist/cjs/html/index.cjs +8 -1
  25. package/dist/cjs/html/installIntlayerHTML.cjs +90 -1
  26. package/dist/cjs/html/types.cjs +1 -1
  27. package/dist/cjs/index.cjs +41 -1
  28. package/dist/cjs/markdown/MarkdownRenderer.cjs +97 -1
  29. package/dist/cjs/markdown/compiler.cjs +72 -1
  30. package/dist/cjs/markdown/index.cjs +12 -1
  31. package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
  32. package/dist/cjs/markdown/runtime.cjs +86 -1
  33. package/dist/cjs/plugins.cjs +217 -3
  34. package/dist/cjs/renderIntlayerNode.cjs +29 -1
  35. package/dist/esm/client/IntlayerBinding.mjs +75 -33
  36. package/dist/esm/client/index.mjs +9 -9
  37. package/dist/esm/client/installIntlayer.mjs +1 -1
  38. package/dist/esm/client/useDictionary.mjs +22 -10
  39. package/dist/esm/client/useDictionaryDynamic.mjs +44 -11
  40. package/dist/esm/client/useIntlayer.mjs +28 -10
  41. package/dist/esm/client/useLocale.mjs +71 -19
  42. package/dist/esm/client/useLocaleStorage.mjs +45 -12
  43. package/dist/esm/client/useRewriteURL.mjs +36 -18
  44. package/dist/esm/editor/useEditor.mjs +1 -1
  45. package/dist/esm/format/index.mjs +10 -10
  46. package/dist/esm/format/useCompact.mjs +23 -19
  47. package/dist/esm/format/useCurrency.mjs +23 -19
  48. package/dist/esm/format/useDate.mjs +37 -27
  49. package/dist/esm/format/useIntl.mjs +54 -13
  50. package/dist/esm/format/useList.mjs +23 -19
  51. package/dist/esm/format/useNumber.mjs +29 -19
  52. package/dist/esm/format/usePercentage.mjs +23 -19
  53. package/dist/esm/format/useRelativeTime.mjs +23 -19
  54. package/dist/esm/format/useUnit.mjs +23 -19
  55. package/dist/esm/getDictionary.mjs +11 -6
  56. package/dist/esm/getIntlayer.mjs +11 -6
  57. package/dist/esm/html/HTMLRenderer.mjs +38 -13
  58. package/dist/esm/html/index.mjs +3 -3
  59. package/dist/esm/html/installIntlayerHTML.mjs +82 -13
  60. package/dist/esm/index.mjs +12 -12
  61. package/dist/esm/markdown/MarkdownRenderer.mjs +66 -26
  62. package/dist/esm/markdown/compiler.mjs +68 -22
  63. package/dist/esm/markdown/index.mjs +4 -4
  64. package/dist/esm/markdown/installIntlayerMarkdown.mjs +87 -23
  65. package/dist/esm/markdown/runtime.mjs +58 -28
  66. package/dist/esm/plugins.mjs +156 -106
  67. package/dist/esm/renderIntlayerNode.mjs +17 -17
  68. package/dist/installIntlayer-CCMOc1XT.mjs +174 -0
  69. package/dist/installIntlayer-HB8aIQ-i.js +203 -0
  70. package/package.json +7 -7
  71. package/dist/installIntlayer-CFvvijL7.js +0 -1
  72. package/dist/installIntlayer-CTpPd7yz.mjs +0 -82
@@ -1,139 +1,189 @@
1
- import { editor as e, internationalization as t } from "@intlayer/config/built";
2
- import { conditionPlugin as n, enumerationPlugin as r, fallbackPlugin as i, filePlugin as a, genderPlugin as o, getHTML as s, isInterpolableWrapperNode as c, nestedPlugin as l, pluralPlugin as u, resolveInsertedSelector as d, resolveInterpreterLocale as f, selectPlugin as p, splitInsertionTemplate as m, transformInterpolableNode as h, translationPlugin as g } from "@intlayer/core/interpreter";
3
- import { compileWithOptions as _, getMarkdownMetadata as v } from "@intlayer/core/markdown";
4
- import { getIntlayerNodePrototype as y } from "@intlayer/core/utils";
5
- import * as b from "@intlayer/types/nodeType";
6
- import { unsafeHTML as x } from "lit/directives/unsafe-html.js";
7
- import { html as S, unsafeStatic as C } from "lit/static-html.js";
8
- import { r as w } from "../installIntlayer-CTpPd7yz.mjs";
9
- import T from "./markdown/runtime.mjs";
10
- import { renderIntlayerNode as E } from "./renderIntlayerNode.mjs";
1
+ import { editor, internationalization } from "@intlayer/config/built";
2
+ import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getHTML, isInterpolableWrapperNode, nestedPlugin, pluralPlugin, resolveInsertedSelector, resolveInterpreterLocale, selectPlugin, splitInsertionTemplate, transformInterpolableNode, translationPlugin } from "@intlayer/core/interpreter";
3
+ import { compileWithOptions, getMarkdownMetadata } from "@intlayer/core/markdown";
4
+ import { getIntlayerNodePrototype } from "@intlayer/core/utils";
5
+ import * as NodeTypes from "@intlayer/types/nodeType";
6
+ import { unsafeHTML } from "lit/directives/unsafe-html.js";
7
+ import { html, unsafeStatic } from "lit/static-html.js";
8
+ import { r as getIntlayerClient } from "../installIntlayer-CCMOc1XT.mjs";
9
+ import litRuntime from "./markdown/runtime.mjs";
10
+ import { renderIntlayerNode } from "./renderIntlayerNode.mjs";
11
11
  // src/plugins.ts
12
- var D = (e = "", t = {}) => _(e, T, t), O = (e, t, n = {}) => {
13
- let r = typeof e == "string" ? x(e) : e, i = Array.isArray(r), a = Object.assign(i ? [...r] : { ...r }, n, {
14
- value: t,
15
- raw: t,
12
+ /**
13
+ * Compile markdown to an HTML string using the Lit runtime.
14
+ * Inline here to avoid a cross-entry circular import with markdown/compiler.
15
+ */
16
+ var compileMarkdown = (markdown = "", options = {}) => compileWithOptions(markdown, litRuntime, options);
17
+ /**
18
+ * Creates a Lit-renderable node for raw HTML/compiled markdown.
19
+ *
20
+ * The returned object is a copy of an `unsafeHTML` DirectiveResult or TemplateResult
21
+ * so that Lit's template engine renders it as HTML, while string
22
+ * coercion (`.toString()`, `String(node)`) still returns the raw source string
23
+ * for editor tooling and serialization.
24
+ */
25
+ var createLitHTMLNode = (content, rawStr, additionalProps = {}) => {
26
+ const result = typeof content === "string" ? unsafeHTML(content) : Array.isArray(content) ? content : content;
27
+ const isArrayResult = Array.isArray(result);
28
+ const node = Object.assign(isArrayResult ? [...result] : { ...result }, additionalProps, {
29
+ value: rawStr,
30
+ raw: rawStr,
16
31
  [Symbol.iterator]: void 0,
17
32
  __update: () => {},
18
- isJSX: !0
33
+ isJSX: true
19
34
  });
20
- return Object.setPrototypeOf(a, y(t, i ? Array.prototype : Object.prototype));
21
- }, k = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;"), A = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), j = {
35
+ return Object.setPrototypeOf(node, getIntlayerNodePrototype(rawStr, isArrayResult ? Array.prototype : Object.prototype));
36
+ };
37
+ var escapeHtmlAttr = (str) => str.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
38
+ var escapeHtmlText = (str) => str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
39
+ /**
40
+ * Wraps string/number leaf values in an IntlayerNode so they carry
41
+ * `.value`, `.raw`, `toString()`, and `__update()`.
42
+ * When the editor is enabled, wraps the content with
43
+ * `<intlayer-content-selector-wrapper>` so the visual editor can highlight it.
44
+ */
45
+ var intlayerNodePlugins = {
22
46
  id: "intlayer-node-plugin",
23
- canHandle: (e) => typeof e == "bigint" || typeof e == "string" || typeof e == "number",
24
- transform: (t, { children: n, keyPath: r, dictionaryKey: i }) => {
25
- if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && e.enabled) {
26
- let e = String(n ?? "");
27
- return O(`<intlayer-content-selector-wrapper key-path="${k(JSON.stringify(r ?? []))}" dictionary-key="${k(String(i ?? ""))}">${A(e)}</intlayer-content-selector-wrapper>`, e);
47
+ canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
48
+ transform: (_node, { children, keyPath, dictionaryKey }) => {
49
+ if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && editor.enabled) {
50
+ const rawStr = String(children ?? "");
51
+ return createLitHTMLNode(`<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(JSON.stringify(keyPath ?? []))}" dictionary-key="${escapeHtmlAttr(String(dictionaryKey ?? ""))}">${escapeHtmlText(rawStr)}</intlayer-content-selector-wrapper>`, rawStr);
28
52
  }
29
- return E({
30
- value: n,
31
- children: n
53
+ return renderIntlayerNode({
54
+ value: children,
55
+ children
32
56
  });
33
57
  }
34
- }, M = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? i : {
58
+ };
59
+ var insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? fallbackPlugin : {
35
60
  id: "insertion-plugin",
36
- canHandle: (e) => typeof e == "object" && e?.nodeType === b.INSERTION,
37
- transform: (e, t, n) => {
38
- let r = [...t.keyPath, { type: b.INSERTION }], i = e[b.INSERTION], a = {
61
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.INSERTION,
62
+ transform: (node, props, deepTransformNode) => {
63
+ const newKeyPath = [...props.keyPath, { type: NodeTypes.INSERTION }];
64
+ const children = node[NodeTypes.INSERTION];
65
+ const insertionStringPlugin = {
39
66
  id: "insertion-string-plugin",
40
- canHandle: (e) => typeof e == "string" || c(e),
41
- transform: (e, n, r) => {
42
- if (c(e)) return (i) => h(e, i, n, t.plugins, r);
43
- let i = r(e, {
44
- ...n,
45
- children: e,
46
- plugins: (t.plugins ?? []).filter((e) => e.id !== "intlayer-node-plugin")
67
+ canHandle: (node) => typeof node === "string" || isInterpolableWrapperNode(node),
68
+ transform: (node, subProps, deepTransformNode) => {
69
+ if (isInterpolableWrapperNode(node)) return (values) => transformInterpolableNode(node, values, subProps, props.plugins, deepTransformNode);
70
+ const transformedResult = deepTransformNode(node, {
71
+ ...subProps,
72
+ children: node,
73
+ plugins: (props.plugins ?? []).filter((plugin) => plugin.id !== "intlayer-node-plugin")
47
74
  });
48
- return (e) => {
49
- let a = m(i, e), o = a.isSimple ? a.parts : a.parts.join("");
50
- return r(o, {
51
- ...n,
52
- plugins: t.plugins,
53
- children: o
75
+ return (values) => {
76
+ const result = splitInsertionTemplate(transformedResult, values);
77
+ const resultStr = result.isSimple ? result.parts : result.parts.join("");
78
+ return deepTransformNode(resultStr, {
79
+ ...subProps,
80
+ plugins: props.plugins,
81
+ children: resultStr
54
82
  });
55
83
  };
56
84
  }
57
- }, o = n(i, {
58
- ...t,
59
- children: i,
60
- keyPath: r,
61
- plugins: [a, ...t.plugins ?? []]
85
+ };
86
+ const transformed = deepTransformNode(children, {
87
+ ...props,
88
+ children,
89
+ keyPath: newKeyPath,
90
+ plugins: [insertionStringPlugin, ...props.plugins ?? []]
62
91
  });
63
- return d(i, o);
92
+ return resolveInsertedSelector(children, transformed);
64
93
  }
65
- }, N = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? i : {
94
+ };
95
+ /** Markdown string plugin. Replaces string node with a component that render the markdown. */
96
+ var markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? fallbackPlugin : {
66
97
  id: "markdown-string-plugin",
67
- canHandle: (e) => typeof e == "string",
68
- transform: (t, n, r) => {
69
- let { plugins: i, ...a } = n, { keyPath: o, dictionaryKey: s } = a, c = r(v(t) ?? {}, {
98
+ canHandle: (node) => typeof node === "string",
99
+ transform: (node, props, deepTransformNode) => {
100
+ const { plugins: _plugins, ...rest } = props;
101
+ const { keyPath, dictionaryKey } = rest;
102
+ const metadataNodes = deepTransformNode(getMarkdownMetadata(node) ?? {}, {
70
103
  plugins: [{
71
104
  id: "markdown-metadata-plugin",
72
- canHandle: (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean" || !e,
73
- transform: (e, n) => E({
74
- ...n,
75
- value: e,
76
- children: t
105
+ canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
106
+ transform: (metadataNode, subProps) => renderIntlayerNode({
107
+ ...subProps,
108
+ value: metadataNode,
109
+ children: node
77
110
  })
78
111
  }],
79
- dictionaryKey: a.dictionaryKey,
112
+ dictionaryKey: rest.dictionaryKey,
80
113
  keyPath: []
81
- }), l = D(t), u = (n) => {
82
- let r = D(t, { components: n });
83
- return process.env.INTLAYER_EDITOR_ENABLED !== "false" && e.enabled ? O(`<intlayer-content-selector-wrapper key-path="${k(JSON.stringify(o ?? []))}" dictionary-key="${k(String(s ?? ""))}">${r}</intlayer-content-selector-wrapper>`, t) : O(r, t);
114
+ });
115
+ const compiled = compileMarkdown(node);
116
+ const use = (components) => {
117
+ const rendered = compileMarkdown(node, { components });
118
+ if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && editor.enabled) return createLitHTMLNode(`<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(JSON.stringify(keyPath ?? []))}" dictionary-key="${escapeHtmlAttr(String(dictionaryKey ?? ""))}">${rendered}</intlayer-content-selector-wrapper>`, node);
119
+ return createLitHTMLNode(rendered, node);
84
120
  };
85
- return process.env.INTLAYER_EDITOR_ENABLED !== "false" && e.enabled ? O(`<intlayer-content-selector-wrapper key-path="${k(JSON.stringify(o ?? []))}" dictionary-key="${k(String(s ?? ""))}">${l}</intlayer-content-selector-wrapper>`, t, {
86
- metadata: c,
87
- use: u
88
- }) : O(l, t, {
89
- metadata: c,
90
- use: u
121
+ if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && editor.enabled) return createLitHTMLNode(`<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(JSON.stringify(keyPath ?? []))}" dictionary-key="${escapeHtmlAttr(String(dictionaryKey ?? ""))}">${compiled}</intlayer-content-selector-wrapper>`, node, {
122
+ metadata: metadataNodes,
123
+ use
124
+ });
125
+ return createLitHTMLNode(compiled, node, {
126
+ metadata: metadataNodes,
127
+ use
91
128
  });
92
129
  }
93
- }, P = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? i : {
130
+ };
131
+ var markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? fallbackPlugin : {
94
132
  id: "markdown-plugin",
95
- canHandle: (e) => typeof e == "object" && e?.nodeType === b.MARKDOWN,
96
- transform: (e, t, n) => {
97
- let r = [...t.keyPath, { type: b.MARKDOWN }], i = e[b.MARKDOWN];
98
- return n(i, {
99
- ...t,
100
- children: i,
101
- keyPath: r,
102
- plugins: [N, ...t.plugins ?? []]
133
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.MARKDOWN,
134
+ transform: (node, props, deepTransformNode) => {
135
+ const newKeyPath = [...props.keyPath, { type: NodeTypes.MARKDOWN }];
136
+ const children = node[NodeTypes.MARKDOWN];
137
+ return deepTransformNode(children, {
138
+ ...props,
139
+ children,
140
+ keyPath: newKeyPath,
141
+ plugins: [markdownStringPlugin, ...props.plugins ?? []]
103
142
  });
104
143
  }
105
- }, F = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? i : {
144
+ };
145
+ var htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? fallbackPlugin : {
106
146
  id: "html-plugin",
107
- canHandle: (e) => typeof e == "object" && e?.nodeType === b.HTML,
108
- transform: (t, n) => {
109
- let r = t[b.HTML], { keyPath: i, dictionaryKey: a } = n, o = (t = {}) => {
110
- let n = Object.fromEntries(Object.entries(t).filter(([, e]) => e).map(([e, t]) => [e, (e) => t(e)])), o = new Proxy(n, { get(e, t) {
111
- if (typeof t == "string" && t in e) return e[t];
112
- if (typeof t == "string" && /^[a-z][a-z0-9]*$/.test(t)) return (e) => S`<${C(t)} ...${e}
113
- >${e.children}</${C(t)}
147
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.HTML,
148
+ transform: (node, props) => {
149
+ const htmlStr = node[NodeTypes.HTML];
150
+ const { keyPath, dictionaryKey } = props;
151
+ const use = (components = {}) => {
152
+ const userComponents = Object.fromEntries(Object.entries(components).filter(([, Component]) => Component).map(([key, Component]) => [key, (props) => Component(props)]));
153
+ const wrappedComponents = new Proxy(userComponents, { get(target, prop) {
154
+ if (typeof prop === "string" && prop in target) return target[prop];
155
+ if (typeof prop === "string" && /^[a-z][a-z0-9]*$/.test(prop)) return (props) => html`<${unsafeStatic(prop)} ...${props}
156
+ >${props.children}</${unsafeStatic(prop)}
114
157
  >`;
115
- } }), c = s(r, o);
116
- return process.env.INTLAYER_EDITOR_ENABLED !== "false" && e.enabled ? O(`<intlayer-content-selector-wrapper key-path="${k(JSON.stringify(i ?? []))}" dictionary-key="${k(String(a ?? ""))}">${c}</intlayer-content-selector-wrapper>`, r) : O(c, r);
158
+ } });
159
+ const rendered = getHTML(htmlStr, wrappedComponents);
160
+ if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && editor.enabled) return createLitHTMLNode(`<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(JSON.stringify(keyPath ?? []))}" dictionary-key="${escapeHtmlAttr(String(dictionaryKey ?? ""))}">${rendered}</intlayer-content-selector-wrapper>`, htmlStr);
161
+ return createLitHTMLNode(rendered, htmlStr);
117
162
  };
118
- return process.env.INTLAYER_EDITOR_ENABLED !== "false" && e.enabled ? O(`<intlayer-content-selector-wrapper key-path="${k(JSON.stringify(i ?? []))}" dictionary-key="${k(String(a ?? ""))}">${r}</intlayer-content-selector-wrapper>`, r, { use: o }) : O(r, r, { use: o });
163
+ if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && editor.enabled) return createLitHTMLNode(`<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(JSON.stringify(keyPath ?? []))}" dictionary-key="${escapeHtmlAttr(String(dictionaryKey ?? ""))}">${htmlStr}</intlayer-content-selector-wrapper>`, htmlStr, { use });
164
+ return createLitHTMLNode(htmlStr, htmlStr, { use });
119
165
  }
120
- }, I = /* @__PURE__ */ new Map(), L = (e, s = !0) => {
121
- let c = e ?? (typeof window < "u" && w()?.locale) ?? f(), d = `${c}_${s}`;
122
- if (I.has(d)) return I.get(d);
123
- let m = [
124
- j,
125
- g(c, s ? t.defaultLocale : void 0),
126
- r,
127
- u(c),
128
- n,
129
- l(c),
130
- a,
131
- o,
132
- p,
133
- M,
134
- P,
135
- F
136
- ].filter((e) => e !== i);
137
- return I.set(d, m), m;
138
166
  };
139
- export { L as getPlugins, F as htmlPlugin, M as insertionPlugin, j as intlayerNodePlugins, P as markdownPlugin, N as markdownStringPlugin };
167
+ var pluginsCache = /* @__PURE__ */ new Map();
168
+ var getPlugins = (locale, fallback = true) => {
169
+ const currentLocale = locale ?? (typeof window !== "undefined" && getIntlayerClient()?.locale) ?? resolveInterpreterLocale();
170
+ const cacheKey = `${currentLocale}_${fallback}`;
171
+ if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
172
+ const enabledPlugins = [
173
+ intlayerNodePlugins,
174
+ translationPlugin(currentLocale, fallback ? internationalization.defaultLocale : void 0),
175
+ enumerationPlugin,
176
+ pluralPlugin(currentLocale),
177
+ conditionPlugin,
178
+ nestedPlugin(currentLocale),
179
+ filePlugin,
180
+ genderPlugin,
181
+ selectPlugin,
182
+ insertionPlugin,
183
+ markdownPlugin,
184
+ htmlPlugin
185
+ ].filter((plugin) => plugin !== fallbackPlugin);
186
+ pluginsCache.set(cacheKey, enabledPlugins);
187
+ return enabledPlugins;
188
+ };
189
+ export { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin };
@@ -1,28 +1,28 @@
1
- import { getIntlayerNodePrototype as e } from "@intlayer/core/utils";
1
+ import { getIntlayerNodePrototype } from "@intlayer/core/utils";
2
2
  // src/renderIntlayerNode.ts
3
- var t = ({ value: t, additionalProps: n = {} }) => {
4
- let r = t;
3
+ var renderIntlayerNode = ({ value, additionalProps = {} }) => {
4
+ let _value = value;
5
5
  return {
6
- __proto__: e(t),
7
- toString: () => String(r ?? ""),
8
- valueOf: () => r,
9
- [Symbol.toPrimitive]: () => r,
6
+ __proto__: getIntlayerNodePrototype(value),
7
+ toString: () => String(_value ?? ""),
8
+ valueOf: () => _value,
9
+ [Symbol.toPrimitive]: () => _value,
10
10
  [Symbol.iterator]: void 0,
11
- toJSON: () => r,
11
+ toJSON: () => _value,
12
12
  get raw() {
13
- return r;
13
+ return _value;
14
14
  },
15
- set raw(e) {
16
- r = e;
15
+ set raw(value) {
16
+ _value = value;
17
17
  },
18
18
  get value() {
19
- return r;
19
+ return _value;
20
20
  },
21
- __update(e) {
22
- r = e?.raw ?? e?.value ?? e;
21
+ __update(next) {
22
+ _value = next?.raw ?? next?.value ?? next;
23
23
  },
24
- isJSX: !0,
25
- ...n
24
+ isJSX: true,
25
+ ...additionalProps
26
26
  };
27
27
  };
28
- export { t as renderIntlayerNode };
28
+ export { renderIntlayerNode };
@@ -0,0 +1,174 @@
1
+ import { internationalization } from "@intlayer/config/built";
2
+ import { setIntlayerIdentifier } from "@intlayer/config/client";
3
+ import { isEnabled } from "@intlayer/editor/isEnabled";
4
+ import { getLocaleInStorage, setLocaleInStorage } from "./esm/client/useLocaleStorage.mjs";
5
+ // src/editor/useEditor.ts
6
+ /**
7
+ * Syncs the client locale into the editor manager and applies the locales
8
+ * requested by the editor. Returns a function stopping both subscriptions.
9
+ */
10
+ var syncEditorLocale = (manager) => {
11
+ const client = getIntlayerClient();
12
+ manager.currentLocale.set(client.locale);
13
+ const unsubscribeLocale = client.subscribe((newLocale) => {
14
+ manager.currentLocale.set(newLocale);
15
+ });
16
+ const unsubscribeLocaleRequest = manager.onLocaleChangeRequested((requestedLocale) => {
17
+ client.setLocale(requestedLocale);
18
+ setLocaleInStorage(requestedLocale, client.isCookieEnabled);
19
+ });
20
+ return () => {
21
+ unsubscribeLocale();
22
+ unsubscribeLocaleRequest();
23
+ };
24
+ };
25
+ /**
26
+ * ReactiveController that initialises the Intlayer visual editor when enabled.
27
+ * Syncs the current locale into the editor manager so it always reflects the
28
+ * locale the app is displaying.
29
+ *
30
+ * @internal
31
+ */
32
+ var EditorController = class {
33
+ host;
34
+ _stopped = false;
35
+ _unsubscribeLocale = null;
36
+ constructor(host) {
37
+ this.host = host;
38
+ host.addController(this);
39
+ }
40
+ hostConnected() {
41
+ this._stopped = false;
42
+ if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return;
43
+ import("@intlayer/editor").then(({ initEditorClient }) => {
44
+ if (this._stopped) return;
45
+ this._unsubscribeLocale = syncEditorLocale(initEditorClient());
46
+ }).catch(() => {});
47
+ }
48
+ hostDisconnected() {
49
+ this._stopped = true;
50
+ this._unsubscribeLocale?.();
51
+ this._unsubscribeLocale = null;
52
+ import("@intlayer/editor").then(({ stopEditorClient }) => {
53
+ stopEditorClient();
54
+ }).catch(() => {});
55
+ }
56
+ };
57
+ function useEditor(host) {
58
+ if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return host ? void 0 : () => {};
59
+ if (!host) {
60
+ let stopped = false;
61
+ let unsubscribeLocale = null;
62
+ import("@intlayer/editor").then(({ initEditorClient }) => {
63
+ if (stopped) return;
64
+ unsubscribeLocale = syncEditorLocale(initEditorClient());
65
+ }).catch(() => {});
66
+ return () => {
67
+ stopped = true;
68
+ unsubscribeLocale?.();
69
+ import("@intlayer/editor").then(({ stopEditorClient }) => {
70
+ stopEditorClient();
71
+ }).catch(() => {});
72
+ };
73
+ }
74
+ new EditorController(host);
75
+ }
76
+ // src/client/installIntlayer.ts
77
+ var IntlayerClient = class {
78
+ _locale;
79
+ _variant;
80
+ _listeners = /* @__PURE__ */ new Set();
81
+ isCookieEnabled;
82
+ constructor(locale, isCookieEnabled = true, variant) {
83
+ const { defaultLocale } = internationalization ?? {};
84
+ setIntlayerIdentifier();
85
+ this._locale = locale ?? getLocaleInStorage() ?? defaultLocale;
86
+ this._variant = variant;
87
+ this.isCookieEnabled = isCookieEnabled;
88
+ }
89
+ get locale() {
90
+ return this._locale;
91
+ }
92
+ /**
93
+ * Ambient variant applied to every dictionary read, the same way `locale` is.
94
+ * Overridden per call by an explicit selector.
95
+ */
96
+ get variant() {
97
+ return this._variant;
98
+ }
99
+ setLocale(newLocale) {
100
+ this._locale = newLocale;
101
+ for (const listener of this._listeners) listener(newLocale);
102
+ }
103
+ setVariant(newVariant) {
104
+ this._variant = newVariant;
105
+ for (const listener of this._listeners) listener(this._locale);
106
+ }
107
+ subscribe(listener) {
108
+ this._listeners.add(listener);
109
+ return () => {
110
+ this._listeners.delete(listener);
111
+ };
112
+ }
113
+ };
114
+ /**
115
+ * Singleton instance
116
+ */
117
+ var instance = null;
118
+ /**
119
+ * Create and return a single IntlayerClient instance.
120
+ */
121
+ var createIntlayerClient = (locale, isCookieEnabled = true, variant) => {
122
+ if (instance) return instance;
123
+ instance = new IntlayerClient(locale, isCookieEnabled, variant);
124
+ return instance;
125
+ };
126
+ /**
127
+ * Get the current IntlayerClient instance, creating one with defaults if needed.
128
+ */
129
+ var getIntlayerClient = () => {
130
+ if (!instance) instance = new IntlayerClient();
131
+ return instance;
132
+ };
133
+ /**
134
+ * Install Intlayer into your Lit application.
135
+ *
136
+ * Call this once at application startup before any Lit elements are rendered.
137
+ *
138
+ * When called with a `config` argument, `window.INTLAYER_CONFIG` is set so
139
+ * that `@intlayer/config/built` resolves the correct values in the browser
140
+ * without requiring module aliasing in the bundler configuration.
141
+ *
142
+ * @param locale - Initial locale (defaults to config defaultLocale).
143
+ * @param isCookieEnabled - Whether to persist locale in cookies/localStorage.
144
+ * @param variant - Ambient variant applied to every dictionary read — for a
145
+ * dimension fixed for the whole session (tenant, school type, plan tier…)
146
+ * that no call site should have to pass by hand. Accepts a name
147
+ * (`'school1'`), an ordered preference chain (`['school1', 'default']`), or a
148
+ * per-key map (`{ key1: 'school1', default: 'base' }`). A plain object is
149
+ * always the per-key map; nest a structured variant as
150
+ * `{ default: { id: 'prod_abc' } }`. A call-site selector always wins.
151
+ * @param config - Optional Intlayer configuration. When provided, sets
152
+ * `window.INTLAYER_CONFIG` with the browser-safe subset of the config so
153
+ * the application works without a Vite/webpack plugin alias.
154
+ * @returns The IntlayerClient singleton.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { installIntlayer } from 'lit-intlayer';
159
+ *
160
+ * // With explicit config (no build plugin alias needed):
161
+ * installIntlayer('en', true, {
162
+ * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },
163
+ * });
164
+ *
165
+ * // With build plugin (alias handles config automatically):
166
+ * installIntlayer('en');
167
+ * ```
168
+ */
169
+ var installIntlayer = ({ locale, isCookieEnabled, variant } = {}) => {
170
+ const client = createIntlayerClient(locale, isCookieEnabled, variant);
171
+ useEditor();
172
+ return client;
173
+ };
174
+ export { useEditor as a, installIntlayer as i, createIntlayerClient as n, getIntlayerClient as r, IntlayerClient as t };