angular-intlayer 9.5.9 → 9.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/intlayerToken.cjs +3 -1
- package/dist/cjs/client/intlayerToken.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +10 -2
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/esbuild/plugin.cjs +3 -3
- package/dist/cjs/plugins.cjs +63 -69
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/renderIntlayerNode.cjs +17 -36
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
- package/dist/cjs/webpack/mergeConfig.cjs +1 -1
- package/dist/esm/client/intlayerToken.mjs +3 -1
- package/dist/esm/client/intlayerToken.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +11 -4
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/plugins.mjs +63 -69
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs +17 -36
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/types/client/intlayerToken.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +12 -6
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/format/useCompact.d.ts +1 -2
- package/dist/types/format/useCompact.d.ts.map +1 -1
- package/dist/types/format/useCurrency.d.ts +1 -2
- package/dist/types/format/useCurrency.d.ts.map +1 -1
- package/dist/types/format/useDate.d.ts +1 -2
- package/dist/types/format/useDate.d.ts.map +1 -1
- package/dist/types/format/useList.d.ts +1 -2
- package/dist/types/format/useList.d.ts.map +1 -1
- package/dist/types/format/useNumber.d.ts +1 -2
- package/dist/types/format/useNumber.d.ts.map +1 -1
- package/dist/types/format/usePercentage.d.ts +1 -2
- package/dist/types/format/usePercentage.d.ts.map +1 -1
- package/dist/types/format/useRelativeTime.d.ts +1 -2
- package/dist/types/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/format/useUnit.d.ts +1 -2
- package/dist/types/format/useUnit.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +2 -5
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/renderIntlayerNode.d.ts +22 -2
- package/dist/types/renderIntlayerNode.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/types/intlayer/dist/types/index.d.ts +0 -14
package/dist/esm/plugins.mjs
CHANGED
|
@@ -60,21 +60,21 @@ const compileToHtml = (source, components) => {
|
|
|
60
60
|
const intlayerNodePlugins = {
|
|
61
61
|
id: "intlayer-node-plugin",
|
|
62
62
|
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
63
|
-
transform: (_node,
|
|
63
|
+
transform: (_node, props) => {
|
|
64
|
+
const { children, dictionaryKey, keyPath } = props;
|
|
64
65
|
if (process.env.INTLAYER_ANALYTICS_ENABLED !== "false") reportExposure({
|
|
65
|
-
dictionaryKey
|
|
66
|
-
keyPath
|
|
67
|
-
locale:
|
|
66
|
+
dictionaryKey,
|
|
67
|
+
keyPath,
|
|
68
|
+
locale: props.locale,
|
|
68
69
|
nodeType: "text"
|
|
69
70
|
});
|
|
70
71
|
return renderIntlayerNode({
|
|
71
|
-
...rest,
|
|
72
72
|
value: children,
|
|
73
73
|
children: () => ({
|
|
74
74
|
component: process.env.INTLAYER_EDITOR_ENABLED === "false" || !editor.enabled ? children : ContentSelectorWrapperComponent,
|
|
75
75
|
props: {
|
|
76
|
-
dictionaryKey
|
|
77
|
-
keyPath
|
|
76
|
+
dictionaryKey,
|
|
77
|
+
keyPath
|
|
78
78
|
},
|
|
79
79
|
children
|
|
80
80
|
})
|
|
@@ -101,34 +101,32 @@ const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false"
|
|
|
101
101
|
keyPath: []
|
|
102
102
|
});
|
|
103
103
|
const renderMarkdown = (components) => untracked(markdownRendererModule)?.useMarkdown().renderMarkdown(node, components) ?? node;
|
|
104
|
-
const render = (components) =>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
} });
|
|
131
|
-
return createProxy(render());
|
|
104
|
+
const render = (components) => {
|
|
105
|
+
const toHtml = () => compileToHtml(node, components);
|
|
106
|
+
return renderIntlayerNode({
|
|
107
|
+
...rest,
|
|
108
|
+
value: node,
|
|
109
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !editor.enabled ? () => renderMarkdown(components) : () => ({
|
|
110
|
+
component: ContentSelectorWrapperComponent,
|
|
111
|
+
props: {
|
|
112
|
+
dictionaryKey: rest.dictionaryKey,
|
|
113
|
+
keyPath: rest.keyPath,
|
|
114
|
+
...components
|
|
115
|
+
},
|
|
116
|
+
children: () => renderMarkdown(components)
|
|
117
|
+
}),
|
|
118
|
+
additionalProps: {
|
|
119
|
+
metadata: metadataNodes,
|
|
120
|
+
toString: toHtml,
|
|
121
|
+
[Symbol.toPrimitive]: toHtml,
|
|
122
|
+
use: (newComponents) => render({
|
|
123
|
+
...components,
|
|
124
|
+
...newComponents
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
return render();
|
|
132
130
|
}
|
|
133
131
|
};
|
|
134
132
|
const markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? fallbackPlugin : {
|
|
@@ -152,35 +150,31 @@ const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? fallbackPlu
|
|
|
152
150
|
transform: (node, props) => {
|
|
153
151
|
const html = node[NodeTypes.HTML];
|
|
154
152
|
const { plugins, ...rest } = props;
|
|
155
|
-
const render = (userComponents) =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
};
|
|
181
|
-
return Reflect.get(target, prop, receiver);
|
|
182
|
-
} });
|
|
183
|
-
return createProxy(render());
|
|
153
|
+
const render = (userComponents) => {
|
|
154
|
+
const toHtml = () => !userComponents || Object.keys(userComponents).length === 0 ? String(html) : compileToHtml(String(html), userComponents);
|
|
155
|
+
return renderIntlayerNode({
|
|
156
|
+
...rest,
|
|
157
|
+
value: html,
|
|
158
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !editor.enabled ? html : () => ({
|
|
159
|
+
component: ContentSelectorWrapperComponent,
|
|
160
|
+
props: {
|
|
161
|
+
dictionaryKey: rest.dictionaryKey,
|
|
162
|
+
keyPath: rest.keyPath,
|
|
163
|
+
...userComponents
|
|
164
|
+
},
|
|
165
|
+
children: html
|
|
166
|
+
}),
|
|
167
|
+
additionalProps: {
|
|
168
|
+
toString: toHtml,
|
|
169
|
+
[Symbol.toPrimitive]: toHtml,
|
|
170
|
+
use: (newComponents) => render({
|
|
171
|
+
...userComponents,
|
|
172
|
+
...newComponents
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
return render();
|
|
184
178
|
}
|
|
185
179
|
};
|
|
186
180
|
const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? fallbackPlugin : {
|
|
@@ -238,7 +232,8 @@ const pluginsCache = /* @__PURE__ */ new Map();
|
|
|
238
232
|
const getPlugins = (locale, fallback = true) => {
|
|
239
233
|
const cacheKey = `${locale ?? internationalization.defaultLocale}_${fallback}_${markdownRendererModule() !== null}`;
|
|
240
234
|
if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
|
|
241
|
-
const
|
|
235
|
+
const enabledPlugins = [
|
|
236
|
+
intlayerNodePlugins,
|
|
242
237
|
translationPlugin(locale ?? internationalization.defaultLocale, fallback ? internationalization.defaultLocale : void 0),
|
|
243
238
|
enumerationPlugin,
|
|
244
239
|
pluralPlugin(locale ?? internationalization.defaultLocale),
|
|
@@ -247,13 +242,12 @@ const getPlugins = (locale, fallback = true) => {
|
|
|
247
242
|
filePlugin,
|
|
248
243
|
genderPlugin,
|
|
249
244
|
selectPlugin,
|
|
250
|
-
intlayerNodePlugins,
|
|
251
245
|
markdownPlugin,
|
|
252
246
|
htmlPlugin,
|
|
253
247
|
insertionPlugin
|
|
254
|
-
];
|
|
255
|
-
pluginsCache.set(cacheKey,
|
|
256
|
-
return
|
|
248
|
+
].filter((plugin) => plugin !== fallbackPlugin);
|
|
249
|
+
pluginsCache.set(cacheKey, enabledPlugins);
|
|
250
|
+
return enabledPlugins;
|
|
257
251
|
};
|
|
258
252
|
|
|
259
253
|
//#endregion
|
package/dist/esm/plugins.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.ts"],"sourcesContent":["import { signal, untracked } from '@angular/core';\nimport { editor, internationalization } from '@intlayer/config/built';\nimport {\n bindInsertedValues,\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getInsertion,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n selectPlugin,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport type { MarkdownContent } from '@intlayer/core/markdown';\nimport { compile, getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { HTMLContent, InsertionContent } 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 { reportExposure } from './analytics/exposureSink';\nimport { ContentSelectorWrapperComponent } from './editor/ContentSelector.component';\nimport { renderIntlayerNode } from './renderIntlayerNode';\n\ntype MarkdownRendererModule = Pick<\n typeof import('./markdown/installIntlayerMarkdown'),\n 'htmlRuntime' | 'useMarkdown'\n>;\n\n/**\n * Code-split markdown renderer, held in a signal.\n *\n * The chunk loads asynchronously, so the first dictionary evaluation may run\n * before it lands. `getPlugins` reads this signal inside the `computed` of\n * `useIntlayer`/`useDictionary`, which makes that computed depend on it: nodes\n * stringify to their raw source until the module resolves, then the signal\n * flip re-evaluates the dictionary and every binding re-renders with compiled\n * HTML. This is the Angular counterpart of the `Suspense` boundary the React\n * and Solid packages wrap their markdown renderer in.\n */\nconst markdownRendererModule = signal<MarkdownRendererModule | null>(null);\n\nif (\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false' ||\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown')\n .then((module) => markdownRendererModule.set(module))\n .catch(() => {});\n}\n\n/** ---------------------------------------------\n * UTILS\n * --------------------------------------------- */\n\nconst createRuntimeWithOverides = (baseRuntime: any, overrides: any) => ({\n ...baseRuntime,\n createElement: (tag: string, props: any, ...children: any[]) => {\n const override = overrides?.[tag];\n\n if (override) {\n const newProps = { ...props, ...override };\n\n // Merge class attributes intelligently\n const originalClass = props?.class || props?.className;\n const overrideClass = override.class || override.className;\n\n if (originalClass && overrideClass) {\n newProps.class = `${originalClass} ${overrideClass}`;\n newProps.className = undefined;\n }\n\n return baseRuntime.createElement(tag, newProps, ...children);\n }\n\n return baseRuntime.createElement(tag, props, ...children);\n },\n});\n\n/**\n * Compiles a markdown/HTML source to an HTML string with the code-split\n * runtime, or returns the raw source while the renderer chunk is still\n * loading. Runs at stringify time, so a node kept outside any reactive\n * context still picks the renderer up once it has landed.\n */\nconst compileToHtml = (\n source: string,\n components?: Record<string, unknown>\n): string => {\n const rendererModule = untracked(markdownRendererModule);\n\n if (!rendererModule) return source;\n\n const runtime = components\n ? createRuntimeWithOverides(rendererModule.htmlRuntime, components)\n : rendererModule.htmlRuntime;\n\n return compile(source, { runtime }) as string;\n};\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport interface IntlayerNode<T, P = {}> {\n value: T;\n children?: any;\n additionalProps?: P;\n}\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\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, ...rest }) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'text',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: children,\n children: () => ({\n component:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' || !editor.enabled\n ? children\n : ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n },\n children: children,\n }),\n });\n },\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\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 {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\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, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: node,\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const renderMarkdown = (components?: any) =>\n untracked(markdownRendererModule)\n ?.useMarkdown()\n .renderMarkdown(node, components) ?? node;\n\n const render = (components?: any) =>\n renderIntlayerNode({\n ...rest,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? () => renderMarkdown(components)\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => renderMarkdown(components),\n }),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'toString' || prop === Symbol.toPrimitive) {\n return () => compileToHtml(node, components);\n }\n\n if (prop === 'use') {\n return (newComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...newComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\nexport type MarkdownCond<T, _S, _L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: Record<keyof U, any>) => any;\n metadata: DeepTransformContent<V>;\n }\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 {\n type: NodeTypes.MARKDOWN,\n },\n ];\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\n/**\n * HTML conditional type.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T, _S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: Record<keyof U, any>) => any;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */\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\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: any) =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? html\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n }),\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return html;\n }\n\n if (prop === 'toString' || prop === Symbol.toPrimitive) {\n return () => {\n // Without component overrides the source is already HTML.\n if (!components || Object.keys(components).length === 0) {\n return String(html);\n }\n\n return compileToHtml(String(html), components);\n };\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return (userComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...userComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\n/**\n * Insertion conditional type.\n */\nexport type InsertionPluginCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer Content;\n}\n ? (\n args: Record<string, string | number>\n ) => Content extends string\n ? string\n : DeepTransformContentCore<Content, S, 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 { plugins, ...rest } = props;\n const content = node[NodeTypes.INSERTION];\n\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run the\n // transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(content)) {\n return (args: Record<string, string | number> = {}) =>\n transformInterpolableNode(\n content,\n args,\n { ...props, keyPath: newKeyPath },\n props.plugins,\n deepTransformNode\n );\n }\n\n // Container content (`insert(enu(…))`, `insert(plural(…))`, …):\n // interpolate every branch string, then bind the values to the\n // selector so the call reads `(values) => (selector) => content`.\n if (typeof content === 'object' && content !== null) {\n return (args: Record<string, string | number> = {}) => {\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (branch) =>\n typeof branch === 'string' ||\n isInterpolableWrapperNode(branch),\n transform: (branch, subProps, deepTransformBranch) => {\n if (isInterpolableWrapperNode(branch)) {\n return transformInterpolableNode(\n branch,\n args,\n subProps,\n plugins,\n deepTransformBranch\n );\n }\n\n const interpolated = getInsertion(branch, args);\n\n return deepTransformBranch(interpolated, {\n ...subProps,\n children: interpolated,\n plugins,\n });\n },\n };\n\n const result = deepTransformNode(content, {\n ...props,\n children: content,\n keyPath: [...props.keyPath, { type: NodeTypes.INSERTION }],\n plugins: [insertionStringPlugin, ...(plugins ?? [])],\n });\n\n return bindInsertedValues(content, result, args, true);\n };\n }\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = content as string;\n if (args) {\n Object.entries(args).forEach(([key, value]) => {\n text = text.replace(\n new RegExp(`{{\\\\s*${key}\\\\s*}}`, 'g'),\n String(value)\n );\n });\n }\n return text;\n };\n\n return renderIntlayerNode({\n ...rest,\n value: render as any,\n children: render,\n });\n },\n };\n\nexport interface IInterpreterPluginAngular<T, S, L extends LocalesValues> {\n angularIntlayerNode: IntlayerNodeCond<T>;\n angularMarkdown: MarkdownCond<T, S, L>;\n angularHtml: HTMLPluginCond<T, S, L>;\n angularInsertion: InsertionPluginCond<T, S, L>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `angular-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n angularIntlayerNode: true;\n angularMarkdown: true;\n angularHtml: true;\n angularInsertion: 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 Angular 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: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n // Tracked read: called inside the dictionary `computed` of the hooks, so the\n // computed re-evaluates once the renderer chunk lands. The core interpreter\n // memoizes transformed content per plugin-array identity, and the transform\n // itself is lazy (property getters resolved from the template), so handing\n // out a fresh array is what discards the proxies built while pending and\n // gives every binding a new value to re-render.\n const isRendererLoaded = markdownRendererModule() !== null;\n const cacheKey = `${currentLocale}_${fallback}_${isRendererLoaded}`;\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 selectPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,yBAAyB,OAAsC,IAAI;AAEzE,IACE,QAAQ,IAAI,gCAAgC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S,QAAQ,MAAM,IAAI;EACvD;EAIF,MAAM,UAAU,OAAwC,CAAC,MAAM;GAC7D,IAAI,OAAO;GACX,IAAI,MACF,OAAO,QAAQ,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;IAC7C,OAAO,KAAK,QACV,IAAI,OAAO,SAAS,IAAI,SAAS,GAAG,GACpC,OAAO,KAAK,CACd;GACF,CAAC;GAEH,OAAO;EACT;EAEA,OAAO,mBAAmB;GACxB,GAAG;GACH,OAAO;GACP,UAAU;EACZ,CAAC;CACH;AACF;AA6BN,MAAM,+BAAe,IAAI,IAAuB;;;;;AAMhD,MAAa,cACX,QACA,WAAoB,SACN;CASd,MAAM,WAAW,GARK,UAAU,qBAAqB,cAQnB,GAAG,SAAS,GADrB,uBAAuB,MAAM;CAGtD,IAAI,aAAa,IAAI,QAAQ,GAC3B,OAAO,aAAa,IAAI,QAAQ;CAGlC,MAAM,UAAU;EACd,kBACE,UAAU,qBAAqB,eAC/B,WAAW,qBAAqB,gBAAgB,MAClD;EACA;EACA,aAAa,UAAU,qBAAqB,aAAa;EACzD;EACA,aAAa,UAAU,qBAAqB,aAAa;EACzD;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,aAAa,IAAI,UAAU,OAAO;CAElC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.ts"],"sourcesContent":["import { signal, untracked } from '@angular/core';\nimport { editor, internationalization } from '@intlayer/config/built';\nimport {\n bindInsertedValues,\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getInsertion,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n selectPlugin,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport type { MarkdownContent } from '@intlayer/core/markdown';\nimport { compile, getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { HTMLContent, InsertionContent } 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 { reportExposure } from './analytics/exposureSink';\nimport { ContentSelectorWrapperComponent } from './editor/ContentSelector.component';\nimport { type IntlayerNode, renderIntlayerNode } from './renderIntlayerNode';\n\ntype MarkdownRendererModule = Pick<\n typeof import('./markdown/installIntlayerMarkdown'),\n 'htmlRuntime' | 'useMarkdown'\n>;\n\n/**\n * Code-split markdown renderer, held in a signal.\n *\n * The chunk loads asynchronously, so the first dictionary evaluation may run\n * before it lands. `getPlugins` reads this signal inside the `computed` of\n * `useIntlayer`/`useDictionary`, which makes that computed depend on it: nodes\n * stringify to their raw source until the module resolves, then the signal\n * flip re-evaluates the dictionary and every binding re-renders with compiled\n * HTML. This is the Angular counterpart of the `Suspense` boundary the React\n * and Solid packages wrap their markdown renderer in.\n */\nconst markdownRendererModule = signal<MarkdownRendererModule | null>(null);\n\nif (\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false' ||\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown')\n .then((module) => markdownRendererModule.set(module))\n .catch(() => {});\n}\n\n/** ---------------------------------------------\n * UTILS\n * --------------------------------------------- */\n\nconst createRuntimeWithOverides = (baseRuntime: any, overrides: any) => ({\n ...baseRuntime,\n createElement: (tag: string, props: any, ...children: any[]) => {\n const override = overrides?.[tag];\n\n if (override) {\n const newProps = { ...props, ...override };\n\n // Merge class attributes intelligently\n const originalClass = props?.class || props?.className;\n const overrideClass = override.class || override.className;\n\n if (originalClass && overrideClass) {\n newProps.class = `${originalClass} ${overrideClass}`;\n newProps.className = undefined;\n }\n\n return baseRuntime.createElement(tag, newProps, ...children);\n }\n\n return baseRuntime.createElement(tag, props, ...children);\n },\n});\n\n/**\n * Compiles a markdown/HTML source to an HTML string with the code-split\n * runtime, or returns the raw source while the renderer chunk is still\n * loading. Runs at stringify time, so a node kept outside any reactive\n * context still picks the renderer up once it has landed.\n */\nconst compileToHtml = (\n source: string,\n components?: Record<string, unknown>\n): string => {\n const rendererModule = untracked(markdownRendererModule);\n\n if (!rendererModule) return source;\n\n const runtime = components\n ? createRuntimeWithOverides(rendererModule.htmlRuntime, components)\n : rendererModule.htmlRuntime;\n\n return compile(source, { runtime }) as string;\n};\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 };\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\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, props) => {\n const { children, dictionaryKey, keyPath } = props;\n\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey,\n keyPath,\n locale: props.locale,\n nodeType: 'text',\n });\n }\n\n return renderIntlayerNode({\n value: children,\n children: () => ({\n component:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' || !editor.enabled\n ? children\n : ContentSelectorWrapperComponent,\n props: { dictionaryKey, keyPath },\n children: children,\n }),\n });\n },\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\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 {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\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, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: node,\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const renderMarkdown = (components?: any) =>\n untracked(markdownRendererModule)\n ?.useMarkdown()\n .renderMarkdown(node, components) ?? node;\n\n const render = (components?: any): any => {\n const toHtml = () => compileToHtml(node, components);\n\n return renderIntlayerNode({\n ...rest,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? () => renderMarkdown(components)\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => renderMarkdown(components),\n }),\n additionalProps: {\n metadata: metadataNodes,\n toString: toHtml,\n [Symbol.toPrimitive]: toHtml,\n use: (newComponents?: any) =>\n render({ ...components, ...newComponents }),\n },\n });\n };\n\n return render();\n },\n };\n\nexport type MarkdownCond<T, _S, _L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: Record<keyof U, any>) => any;\n metadata: DeepTransformContent<V>;\n }\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 {\n type: NodeTypes.MARKDOWN,\n },\n ];\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\n/**\n * HTML conditional type.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T, _S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: Record<keyof U, any>) => any;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */\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\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: any): any => {\n // Without component overrides the source is already HTML\n const toHtml = () =>\n !userComponents || Object.keys(userComponents).length === 0\n ? String(html)\n : compileToHtml(String(html), userComponents);\n\n return renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? html\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n }),\n additionalProps: {\n toString: toHtml,\n [Symbol.toPrimitive]: toHtml,\n use: (newComponents?: any) =>\n render({ ...userComponents, ...newComponents }),\n },\n });\n };\n\n return render();\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\n/**\n * Insertion conditional type.\n */\nexport type InsertionPluginCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer Content;\n}\n ? (\n args: Record<string, string | number>\n ) => Content extends string\n ? string\n : DeepTransformContentCore<Content, S, 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 { plugins, ...rest } = props;\n const content = node[NodeTypes.INSERTION];\n\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run the\n // transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(content)) {\n return (args: Record<string, string | number> = {}) =>\n transformInterpolableNode(\n content,\n args,\n { ...props, keyPath: newKeyPath },\n props.plugins,\n deepTransformNode\n );\n }\n\n // Container content (`insert(enu(…))`, `insert(plural(…))`, …):\n // interpolate every branch string, then bind the values to the\n // selector so the call reads `(values) => (selector) => content`.\n if (typeof content === 'object' && content !== null) {\n return (args: Record<string, string | number> = {}) => {\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (branch) =>\n typeof branch === 'string' ||\n isInterpolableWrapperNode(branch),\n transform: (branch, subProps, deepTransformBranch) => {\n if (isInterpolableWrapperNode(branch)) {\n return transformInterpolableNode(\n branch,\n args,\n subProps,\n plugins,\n deepTransformBranch\n );\n }\n\n const interpolated = getInsertion(branch, args);\n\n return deepTransformBranch(interpolated, {\n ...subProps,\n children: interpolated,\n plugins,\n });\n },\n };\n\n const result = deepTransformNode(content, {\n ...props,\n children: content,\n keyPath: [...props.keyPath, { type: NodeTypes.INSERTION }],\n plugins: [insertionStringPlugin, ...(plugins ?? [])],\n });\n\n return bindInsertedValues(content, result, args, true);\n };\n }\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = content as string;\n if (args) {\n Object.entries(args).forEach(([key, value]) => {\n text = text.replace(\n new RegExp(`{{\\\\s*${key}\\\\s*}}`, 'g'),\n String(value)\n );\n });\n }\n return text;\n };\n\n return renderIntlayerNode({\n ...rest,\n value: render as any,\n children: render,\n });\n },\n };\n\nexport interface IInterpreterPluginAngular<T, S, L extends LocalesValues> {\n angularIntlayerNode: IntlayerNodeCond<T>;\n angularMarkdown: MarkdownCond<T, S, L>;\n angularHtml: HTMLPluginCond<T, S, L>;\n angularInsertion: InsertionPluginCond<T, S, L>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `angular-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n angularIntlayerNode: true;\n angularMarkdown: true;\n angularHtml: true;\n angularInsertion: 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 Angular 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: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n // Tracked read: called inside the dictionary `computed` of the hooks, so the\n // computed re-evaluates once the renderer chunk lands. The core interpreter\n // memoizes transformed content per plugin-array identity, and the transform\n // itself is lazy (property getters resolved from the template), so handing\n // out a fresh array is what discards the proxies built while pending and\n // gives every binding a new value to re-render.\n const isRendererLoaded = markdownRendererModule() !== null;\n const cacheKey = `${currentLocale}_${fallback}_${isRendererLoaded}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // First: most nodes are plain strings, which every other plugin rejects\n intlayerNodePlugins,\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 selectPlugin,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n // Plugins disabled at build time never match: skip them on every node\n const enabledPlugins = plugins.filter((plugin) => plugin !== fallbackPlugin);\n\n pluginsCache.set(cacheKey, enabledPlugins);\n\n return enabledPlugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,yBAAyB,OAAsC,IAAI;AAEzE,IACE,QAAQ,IAAI,gCAAgC,WAC5C,QAAQ,IAAI,4BAA4B,SAExC,AAAK,OAAO,yCAAqC,CAC9C,MAAM,WAAW,uBAAuB,IAAI,MAAM,CAAC,CAAC,CACpD,YAAY,CAAC,CAAC;;;;AAOnB,MAAM,6BAA6B,aAAkB,eAAoB;CACvE,GAAG;CACH,gBAAgB,KAAa,OAAY,GAAG,aAAoB;EAC9D,MAAM,WAAW,YAAY;EAE7B,IAAI,UAAU;GACZ,MAAM,WAAW;IAAE,GAAG;IAAO,GAAG;GAAS;GAGzC,MAAM,gBAAgB,OAAO,SAAS,OAAO;GAC7C,MAAM,gBAAgB,SAAS,SAAS,SAAS;GAEjD,IAAI,iBAAiB,eAAe;IAClC,SAAS,QAAQ,GAAG,cAAc,GAAG;IACrC,SAAS,YAAY;GACvB;GAEA,OAAO,YAAY,cAAc,KAAK,UAAU,GAAG,QAAQ;EAC7D;EAEA,OAAO,YAA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EAAE,MAAM,UAAU,UAAU,CAAC;IACzD,SAAS,CAAC,uBAAuB,GAAI,WAAW,CAAC,CAAE;GACrD,CAAC;GAED,OAAO,mBAAmB,SAAS,QAAQ,MAAM,IAAI;EACvD;EAIF,MAAM,UAAU,OAAwC,CAAC,MAAM;GAC7D,IAAI,OAAO;GACX,IAAI,MACF,OAAO,QAAQ,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;IAC7C,OAAO,KAAK,QACV,IAAI,OAAO,SAAS,IAAI,SAAS,GAAG,GACpC,OAAO,KAAK,CACd;GACF,CAAC;GAEH,OAAO;EACT;EAEA,OAAO,mBAAmB;GACxB,GAAG;GACH,OAAO;GACP,UAAU;EACZ,CAAC;CACH;AACF;AA6BN,MAAM,+BAAe,IAAI,IAAuB;;;;;AAMhD,MAAa,cACX,QACA,WAAoB,SACN;CASd,MAAM,WAAW,GARK,UAAU,qBAAqB,cAQnB,GAAG,SAAS,GADrB,uBAAuB,MAAM;CAGtD,IAAI,aAAa,IAAI,QAAQ,GAC3B,OAAO,aAAa,IAAI,QAAQ;CAuBlC,MAAM,iBAAiB;EAlBrB;EACA,kBACE,UAAU,qBAAqB,eAC/B,WAAW,qBAAqB,gBAAgB,MAClD;EACA;EACA,aAAa,UAAU,qBAAqB,aAAa;EACzD;EACA,aAAa,UAAU,qBAAqB,aAAa;EACzD;EACA;EACA;EACA;EACA;EACA;CAI2B,CAAC,CAAC,QAAQ,WAAW,WAAW,cAAc;CAE3E,aAAa,IAAI,UAAU,cAAc;CAEzC,OAAO;AACT"}
|
|
@@ -1,41 +1,22 @@
|
|
|
1
|
+
import { getIntlayerNodePrototype } from "@intlayer/core/utils";
|
|
2
|
+
|
|
1
3
|
//#region src/renderIntlayerNode.ts
|
|
4
|
+
/**
|
|
5
|
+
* Builds a node that renders its content and also behaves like its value
|
|
6
|
+
* (`node.value`, `${node}`, `node.toUpperCase()`), through a shared prototype
|
|
7
|
+
* rather than a Proxy.
|
|
8
|
+
*
|
|
9
|
+
* @param props - The value, the rendered content and extra node members.
|
|
10
|
+
* @returns The node.
|
|
11
|
+
*/
|
|
2
12
|
const renderIntlayerNode = ({ children, value, additionalProps = {} }) => {
|
|
3
|
-
if (children
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const valObj = Object(value);
|
|
11
|
-
if (prop in valObj) {
|
|
12
|
-
const valProp = valObj[prop];
|
|
13
|
-
return typeof valProp === "function" ? valProp.bind(value) : valProp;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return Reflect.get(target, prop, receiver);
|
|
17
|
-
} });
|
|
18
|
-
return new Proxy(typeof children === "object" || typeof children === "function" ? children : {}, {
|
|
19
|
-
apply(target, thisArg, argumentsList) {
|
|
20
|
-
if (typeof value === "function") return Reflect.apply(value, thisArg, argumentsList);
|
|
21
|
-
return Reflect.apply(target, thisArg, argumentsList);
|
|
22
|
-
},
|
|
23
|
-
get(target, prop, receiver) {
|
|
24
|
-
if (prop === "value") return value;
|
|
25
|
-
if (prop === Symbol.toPrimitive) return () => value ?? "";
|
|
26
|
-
if (prop === "toString") return () => String(value ?? "");
|
|
27
|
-
if (prop === "valueOf") return () => value;
|
|
28
|
-
if (additionalProps && prop in additionalProps) return additionalProps[prop];
|
|
29
|
-
if (value !== null && value !== void 0 && typeof prop === "string" && prop !== "constructor" && !(prop in target)) {
|
|
30
|
-
const valObj = Object(value);
|
|
31
|
-
if (prop in valObj) {
|
|
32
|
-
const valProp = valObj[prop];
|
|
33
|
-
return typeof valProp === "function" ? valProp.bind(value) : valProp;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return Reflect.get(target, prop, receiver);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
13
|
+
if (typeof children !== "function") return Object.setPrototypeOf({
|
|
14
|
+
...typeof children === "object" ? children : {},
|
|
15
|
+
...additionalProps,
|
|
16
|
+
value
|
|
17
|
+
}, getIntlayerNodePrototype(value));
|
|
18
|
+
Object.assign(children, additionalProps, { value });
|
|
19
|
+
return Object.setPrototypeOf(children, getIntlayerNodePrototype(value, Function.prototype));
|
|
39
20
|
};
|
|
40
21
|
|
|
41
22
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderIntlayerNode.mjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\
|
|
1
|
+
{"version":3,"file":"renderIntlayerNode.mjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import { getIntlayerNodePrototype } from '@intlayer/core/utils';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\n/**\n * Content node returned by `useIntlayer`.\n *\n * Without the editor it is typed as its value (`\"Hello\" & { value: \"Hello\" }`)\n * so it can be bound straight to string inputs and attributes. With the\n * editor, it must be rendered through `<intlayer-node>`, so string bindings\n * must use `.value`.\n */\nexport type IntlayerNode<\n T = string,\n AdditionalProps = unknown,\n> = ResolvedEditor<\n T & { value: T } & AdditionalProps,\n IntlayerNodeRenderer & { value: T } & AdditionalProps\n>;\n\n/** Renderer the node is built on, consumed by `<intlayer-node>`. */\ntype IntlayerNodeRenderer = () => unknown;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: any;\n additionalProps?: { [key: string]: any };\n};\n\n/**\n * Builds a node that renders its content and also behaves like its value\n * (`node.value`, `${node}`, `node.toUpperCase()`), through a shared prototype\n * rather than a Proxy.\n *\n * @param props - The value, the rendered content and extra node members.\n * @returns The node.\n */\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n children,\n value,\n additionalProps = {},\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // Callable content (renderers built by the plugins) stays callable; any other\n // content becomes a plain object node\n if (typeof children !== 'function') {\n return Object.setPrototypeOf(\n {\n ...(typeof children === 'object' ? children : {}),\n ...additionalProps,\n value,\n },\n getIntlayerNodePrototype(value)\n );\n }\n\n Object.assign(children, additionalProps, { value });\n\n // Serves the value's members, after the assignments above so they never\n // walk a Proxy in the prototype chain\n return Object.setPrototypeOf(\n children,\n getIntlayerNodePrototype(value, Function.prototype)\n );\n};\n"],"mappings":";;;;;;;;;;;AAoCA,MAAa,sBAEX,EACA,UACA,OACA,kBAAkB,CAAC,QAC8B;CAGjD,IAAI,OAAO,aAAa,YACtB,OAAO,OAAO,eACZ;EACE,GAAI,OAAO,aAAa,WAAW,WAAW,CAAC;EAC/C,GAAG;EACH;CACF,GACA,yBAAyB,KAAK,CAChC;CAGF,OAAO,OAAO,UAAU,iBAAiB,EAAE,MAAM,CAAC;CAIlD,OAAO,OAAO,eACZ,UACA,yBAAyB,OAAO,SAAS,SAAS,CACpD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerToken.d.ts","names":[],"sources":["../../../src/client/intlayerToken.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"intlayerToken.d.ts","names":[],"sources":["../../../src/client/intlayerToken.ts"],"mappings":";;;qBASa;EACX,yCAAe;UACP;UAIA;WAEC,QAAQ,OAAO;;;;;WAMf,SAAS,OAAO;EAGzB;EAIA,YAAS,QAAY;EAIrB,aAAU,SAAa;;qBAKZ,gBAAc,eAAA;;;;qBAUd,uBAAoB,SACtB,eAAa,2BAAA,UAEZ,oBACT"}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import { Locale } from "../intlayer/dist/types/index.js";
|
|
2
1
|
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
2
|
//#region src/client/useLocaleStorage.d.ts
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Reads the locale persisted in the browser storage (cookie, localStorage…).
|
|
5
|
+
*
|
|
6
|
+
* Unlike `localeInStorage`, read on first call rather than at import, then
|
|
7
|
+
* cached until the next `setLocaleInStorage`. Never cached on the server.
|
|
6
8
|
*/
|
|
9
|
+
export declare const getLocaleInStorage: () => import("@intlayer/types").Locale | undefined;
|
|
7
10
|
/**
|
|
8
11
|
* Get the locale cookie
|
|
12
|
+
*
|
|
13
|
+
* Read once at import time; marked pure so bundlers drop the read when nothing
|
|
14
|
+
* imports it.
|
|
9
15
|
*/
|
|
10
|
-
export declare const localeInStorage: Locale;
|
|
16
|
+
export declare const localeInStorage: import("@intlayer/types").Locale;
|
|
11
17
|
/**
|
|
12
18
|
* @deprecated Use localeInStorage instead
|
|
13
19
|
*
|
|
14
20
|
* Get the locale cookie
|
|
15
21
|
*/
|
|
16
|
-
export declare const localeCookie: Locale;
|
|
22
|
+
export declare const localeCookie: import("@intlayer/types").Locale;
|
|
17
23
|
/**
|
|
18
24
|
* Set the locale cookie
|
|
19
25
|
*/
|
|
@@ -28,7 +34,7 @@ export declare const setLocaleCookie: typeof setLocaleInStorage;
|
|
|
28
34
|
* Hook that provides the locale storage and a function to set it
|
|
29
35
|
*/
|
|
30
36
|
export declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
31
|
-
getLocale: () => Locale;
|
|
37
|
+
getLocale: () => import("@intlayer/types").Locale;
|
|
32
38
|
setLocale: (locale: LocalesValues) => void;
|
|
33
39
|
};
|
|
34
40
|
/**
|
|
@@ -39,7 +45,7 @@ export declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
|
39
45
|
* Hook that provides the locale cookie and a function to set it
|
|
40
46
|
*/
|
|
41
47
|
export declare const useLocaleCookie: (isCookieEnabled?: boolean) => {
|
|
42
|
-
localeCookie: Locale;
|
|
48
|
+
localeCookie: import("@intlayer/types").Locale;
|
|
43
49
|
setLocaleCookie: (locale: LocalesValues) => void;
|
|
44
50
|
};
|
|
45
51
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":";;;;;;;;qBAea,oDAAkB;;;;;;;qBAQlB,2CAAe;;;;;;qBAOf,wCAAY;;;;qBAKZ,qBAAkB,QACrB,eAAa;;;;;;qBAaV,wBAAe;;;;qBAKf,mBAAgB;;sBAAhB;;;;;;;;;qBAaA,kBAAe;EAIxB,wCAAY;EACZ,kBAAe,QAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/useCompact.d.ts
|
|
3
2
|
export declare const useCompact: () => import("@angular/core").Signal<(value: string | number, options?: Intl.NumberFormatOptions & {
|
|
4
|
-
locale?: LocalesValues;
|
|
3
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
5
4
|
}) => string>;
|
|
6
5
|
//#endregion
|
|
7
6
|
//# sourceMappingURL=useCompact.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../src/format/useCompact.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../src/format/useCompact.ts"],"mappings":";qBAIa,0CAAU,QAAA,wBAAA,UAAA,KAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/useCurrency.d.ts
|
|
3
2
|
export declare const useCurrency: () => import("@angular/core").Signal<(value: string | number, options?: Intl.NumberFormatOptions & {
|
|
4
|
-
locale?: LocalesValues;
|
|
3
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
5
4
|
}) => string>;
|
|
6
5
|
//#endregion
|
|
7
6
|
//# sourceMappingURL=useCurrency.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../src/format/useCurrency.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../src/format/useCurrency.ts"],"mappings":";qBAIa,2CAAW,QAAA,wBAAA,UAAA,KAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/useDate.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Angular client hook that provides a localized date/time formatter.
|
|
5
4
|
*/
|
|
6
5
|
export declare const useDate: () => import("@angular/core").Signal<(date: string | number | Date, options?: import("@intlayer/core/formatters").DateTimePreset | (Intl.DateTimeFormatOptions & {
|
|
7
|
-
locale?: LocalesValues;
|
|
6
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
8
7
|
})) => string>;
|
|
9
8
|
//#endregion
|
|
10
9
|
//# sourceMappingURL=useDate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDate.d.ts","names":[],"sources":["../../../src/format/useDate.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDate.d.ts","names":[],"sources":["../../../src/format/useDate.ts"],"mappings":";;;;qBAOa,uCAAO,QAAA,wBAAA,MAAA,8CAAA,kBAAA,KAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/useList.d.ts
|
|
3
2
|
export declare const useList: () => import("@angular/core").Signal<(values: (string | number)[], options?: import("@intlayer/core/formatters").ListFormatOptions & {
|
|
4
|
-
locale?: LocalesValues;
|
|
3
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
5
4
|
}) => string>;
|
|
6
5
|
//#endregion
|
|
7
6
|
//# sourceMappingURL=useList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.d.ts","names":[],"sources":["../../../src/format/useList.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useList.d.ts","names":[],"sources":["../../../src/format/useList.ts"],"mappings":";qBAIa,uCAAO,QAAA,6BAAA,8CAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/useNumber.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Angular client hook that provides a localized number formatter.
|
|
5
4
|
*/
|
|
6
5
|
export declare const useNumber: () => import("@angular/core").Signal<(value: string | number, args_1?: Intl.NumberFormatOptions & {
|
|
7
|
-
locale?: LocalesValues;
|
|
6
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
8
7
|
}) => string>;
|
|
9
8
|
//#endregion
|
|
10
9
|
//# sourceMappingURL=useNumber.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../src/format/useNumber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../src/format/useNumber.ts"],"mappings":";;;;qBAOa,yCAAS,QAAA,wBAAA,SAAA,KAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/usePercentage.d.ts
|
|
3
2
|
export declare const usePercentage: () => import("@angular/core").Signal<(value: string | number, args_1?: Intl.NumberFormatOptions & {
|
|
4
|
-
locale?: LocalesValues;
|
|
3
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
5
4
|
}) => string>;
|
|
6
5
|
//#endregion
|
|
7
6
|
//# sourceMappingURL=usePercentage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../src/format/usePercentage.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../src/format/usePercentage.ts"],"mappings":";qBAIa,6CAAa,QAAA,wBAAA,SAAA,KAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/useRelativeTime.d.ts
|
|
3
2
|
export declare const useRelativeTime: () => import("@angular/core").Signal<(from: string | number | Date, to?: string | number | Date, options?: Intl.RelativeTimeFormatOptions & {
|
|
4
|
-
locale?: LocalesValues;
|
|
3
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
5
4
|
unit?: Intl.RelativeTimeFormatUnit;
|
|
6
5
|
}) => string>;
|
|
7
6
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"mappings":";qBAIa,+CAAe,QAAA,wBAAA,MAAA,uBAAA,MAAA,UAAA,KAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
2
1
|
//#region src/format/useUnit.d.ts
|
|
3
2
|
export declare const useUnit: () => import("@angular/core").Signal<(value: string | number, options?: Intl.NumberFormatOptions & {
|
|
4
|
-
locale?: LocalesValues;
|
|
3
|
+
locale?: import("@intlayer/types").LocalesValues;
|
|
5
4
|
}) => string>;
|
|
6
5
|
//#endregion
|
|
7
6
|
//# sourceMappingURL=useUnit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../src/format/useUnit.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../src/format/useUnit.ts"],"mappings":";qBAIa,uCAAO,QAAA,wBAAA,UAAA,KAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { ConversionParams, useConversion } from "./analytics/useConversion.js";
|
|
|
6
6
|
import { ExperimentState, useExperiment } from "./analytics/useExperiment.js";
|
|
7
7
|
import "./analytics/index.js";
|
|
8
8
|
import { installIntlayer, provideIntlayer } from "./client/installIntlayer.js";
|
|
9
|
-
import {
|
|
9
|
+
import { IntlayerNode } from "./renderIntlayerNode.js";
|
|
10
|
+
import { DeepTransformContent, HTMLPluginCond, IInterpreterPluginAngular, IInterpreterPluginState, InsertionPluginCond, IntlayerNodeCond, MarkdownCond, MarkdownStringCond, getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin } from "./plugins.js";
|
|
10
11
|
import { useDictionary } from "./client/useDictionary.js";
|
|
11
12
|
import { useDictionaryAsync } from "./client/useDictionaryAsync.js";
|
|
12
13
|
import { useDictionaryDynamic } from "./client/useDictionaryDynamic.js";
|
|
@@ -23,5 +24,5 @@ declare module '@intlayer/core/interpreter' {
|
|
|
23
24
|
interface IInterpreterPlugin<T, S, L extends LocalesValues> extends IInterpreterPluginAngular<T, S, L> {}
|
|
24
25
|
}
|
|
25
26
|
//#endregion
|
|
26
|
-
export { ConversionParams, DeepTransformContent, ExperimentState, HTMLPluginCond, IInterpreterPluginAngular, IInterpreterPluginState, INTLAYER_TOKEN, InsertionPluginCond, IntlayerNode, IntlayerNodeComponent, IntlayerNodeCond, IntlayerProvider, MarkdownCond, MarkdownStringCond, UseLocaleProps, UseLocaleResult, createIntlayerClient, getDictionary, getIntlayer, getPlugins, htmlPlugin, insertionPlugin, installIntlayer, intlayerNodePlugins, isUpdatableNode, markdownPlugin, markdownStringPlugin, provideIntlayer, provideIntlayerAnalytics, useAnalytics, useConversion, useDictionary, useDictionaryAsync, useDictionaryDynamic, useExperiment, useIntlayer, useLoadDynamic, useLocale, usePathname };
|
|
27
|
+
export { ConversionParams, DeepTransformContent, ExperimentState, HTMLPluginCond, IInterpreterPluginAngular, IInterpreterPluginState, INTLAYER_TOKEN, InsertionPluginCond, type IntlayerNode, IntlayerNodeComponent, IntlayerNodeCond, IntlayerProvider, MarkdownCond, MarkdownStringCond, UseLocaleProps, UseLocaleResult, createIntlayerClient, getDictionary, getIntlayer, getPlugins, htmlPlugin, insertionPlugin, installIntlayer, intlayerNodePlugins, isUpdatableNode, markdownPlugin, markdownStringPlugin, provideIntlayer, provideIntlayerAnalytics, useAnalytics, useConversion, useDictionary, useDictionaryAsync, useDictionaryDynamic, useExperiment, useIntlayer, useLoadDynamic, useLocale, usePathname };
|
|
27
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;YAIY,mBAAmB,GAAG,GAAG,UAAU,uBACnC,0BAA0B,GAAG,GAAG"}
|