@intlayer/core 9.5.7 → 9.5.9-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/interpreter/getContent/index.cjs +2 -0
- package/dist/cjs/interpreter/getContent/plugins.cjs +65 -5
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/index.cjs +2 -0
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/interpreter/getContent/index.mjs +2 -2
- package/dist/esm/interpreter/getContent/plugins.mjs +64 -6
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/index.mjs +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/interpreter/getContent/index.d.ts +2 -2
- package/dist/types/interpreter/getContent/plugins.d.ts +25 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/index.d.ts +2 -2
- package/package.json +5 -5
- package/dist/cjs/dictionaryManipulator/qualifiedDictionary.test-d.cjs +0 -97
- package/dist/cjs/dictionaryManipulator/qualifiedDictionary.test-d.cjs.map +0 -1
- package/dist/cjs/interpreter/getIntlayer.test-d.cjs +0 -28
- package/dist/cjs/interpreter/getIntlayer.test-d.cjs.map +0 -1
- package/dist/cjs/localization/getCanonicalPath.test-d.cjs +0 -12
- package/dist/cjs/localization/getCanonicalPath.test-d.cjs.map +0 -1
- package/dist/cjs/localization/getLocalizedPath.test-d.cjs +0 -99
- package/dist/cjs/localization/getLocalizedPath.test-d.cjs.map +0 -1
- package/dist/cjs/localization/getLocalizedUrl.test-d.cjs +0 -78
- package/dist/cjs/localization/getLocalizedUrl.test-d.cjs.map +0 -1
- package/dist/cjs/localization/rewriteUtils.test-d.cjs +0 -43
- package/dist/cjs/localization/rewriteUtils.test-d.cjs.map +0 -1
- package/dist/esm/dictionaryManipulator/qualifiedDictionary.test-d.mjs +0 -97
- package/dist/esm/dictionaryManipulator/qualifiedDictionary.test-d.mjs.map +0 -1
- package/dist/esm/interpreter/getIntlayer.test-d.mjs +0 -28
- package/dist/esm/interpreter/getIntlayer.test-d.mjs.map +0 -1
- package/dist/esm/localization/getCanonicalPath.test-d.mjs +0 -12
- package/dist/esm/localization/getCanonicalPath.test-d.mjs.map +0 -1
- package/dist/esm/localization/getLocalizedPath.test-d.mjs +0 -99
- package/dist/esm/localization/getLocalizedPath.test-d.mjs.map +0 -1
- package/dist/esm/localization/getLocalizedUrl.test-d.mjs +0 -78
- package/dist/esm/localization/getLocalizedUrl.test-d.mjs.map +0 -1
- package/dist/esm/localization/rewriteUtils.test-d.mjs +0 -43
- package/dist/esm/localization/rewriteUtils.test-d.mjs.map +0 -1
- package/dist/types/dictionaryManipulator/qualifiedDictionary.test-d.d.ts +0 -1
- package/dist/types/interpreter/getIntlayer.test-d.d.ts +0 -1
- package/dist/types/localization/getCanonicalPath.test-d.d.ts +0 -1
- package/dist/types/localization/getLocalizedPath.test-d.d.ts +0 -1
- package/dist/types/localization/getLocalizedUrl.test-d.d.ts +0 -1
- package/dist/types/localization/rewriteUtils.test-d.d.ts +0 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -203,6 +203,7 @@ exports.VOID_HTML_ELEMENTS = require_transpiler_html_validateHTML.VOID_HTML_ELEM
|
|
|
203
203
|
exports.allowInline = require_markdown_utils.allowInline;
|
|
204
204
|
exports.anyScopeRegex = require_markdown_utils.anyScopeRegex;
|
|
205
205
|
exports.attributeValueToNodePropValue = require_markdown_utils.attributeValueToNodePropValue;
|
|
206
|
+
exports.bindInsertedValues = require_interpreter_getContent_plugins.bindInsertedValues;
|
|
206
207
|
exports.bindIntl = require_utils_intl.bindIntl;
|
|
207
208
|
exports.blockRegex = require_markdown_utils.blockRegex;
|
|
208
209
|
exports.buildMaskPlugin = require_deepTransformPlugins_getMaskContent.buildMaskPlugin;
|
|
@@ -390,6 +391,7 @@ exports.renderNothing = require_markdown_utils.renderNothing;
|
|
|
390
391
|
exports.resolveBrowserLocale = require_localization_resolveBrowserLocale.resolveBrowserLocale;
|
|
391
392
|
exports.resolveDictionaryArgument = require_dictionaryManipulator_qualifiedDictionary.resolveDictionaryArgument;
|
|
392
393
|
exports.resolveEffectiveVariantId = require_dictionaryManipulator_qualifiedDictionary.resolveEffectiveVariantId;
|
|
394
|
+
exports.resolveInsertedSelector = require_interpreter_getContent_plugins.resolveInsertedSelector;
|
|
393
395
|
exports.resolveLocalizedPath = require_localization_rewriteUtils.resolveLocalizedPath;
|
|
394
396
|
exports.resolveMessage = require_messageFormat_resolveMessage.resolveMessage;
|
|
395
397
|
exports.resolveMessageNode = require_messageFormat_resolveMessage.resolveMessageNode;
|
|
@@ -3,6 +3,7 @@ const require_interpreter_getContent_deepTransform = require('./deepTransform.cj
|
|
|
3
3
|
const require_interpreter_getContent_plugins = require('./plugins.cjs');
|
|
4
4
|
const require_interpreter_getContent_getContent = require('./getContent.cjs');
|
|
5
5
|
|
|
6
|
+
exports.bindInsertedValues = require_interpreter_getContent_plugins.bindInsertedValues;
|
|
6
7
|
exports.conditionPlugin = require_interpreter_getContent_plugins.conditionPlugin;
|
|
7
8
|
exports.deepTransformNode = require_interpreter_getContent_deepTransform.deepTransformNode;
|
|
8
9
|
exports.enumerationPlugin = require_interpreter_getContent_plugins.enumerationPlugin;
|
|
@@ -14,5 +15,6 @@ exports.getContent = require_interpreter_getContent_getContent.getContent;
|
|
|
14
15
|
exports.insertionPlugin = require_interpreter_getContent_plugins.insertionPlugin;
|
|
15
16
|
exports.nestedPlugin = require_interpreter_getContent_plugins.nestedPlugin;
|
|
16
17
|
exports.pluralPlugin = require_interpreter_getContent_plugins.pluralPlugin;
|
|
18
|
+
exports.resolveInsertedSelector = require_interpreter_getContent_plugins.resolveInsertedSelector;
|
|
17
19
|
exports.selectPlugin = require_interpreter_getContent_plugins.selectPlugin;
|
|
18
20
|
exports.translationPlugin = require_interpreter_getContent_plugins.translationPlugin;
|
|
@@ -82,22 +82,27 @@ const pluralPlugin = (locale) => process.env.INTLAYER_NODE_TYPE_PLURAL === "fals
|
|
|
82
82
|
transform: (node, props, deepTransformNode) => {
|
|
83
83
|
const original = node[_intlayer_types_nodeType.PLURAL];
|
|
84
84
|
const result = {};
|
|
85
|
+
const branchPlugins = (props.plugins ?? []).filter((plugin) => plugin.id !== "insertion-string-plugin");
|
|
85
86
|
/** String plugin for plural. Replaces string node with a component that renders the insertion. */
|
|
86
87
|
const pluralStringPlugin = {
|
|
87
88
|
id: "plural-string-plugin",
|
|
88
89
|
canHandle: (node) => typeof node === "string" || require_interpreter_interpolableNode.isInterpolableWrapperNode(node),
|
|
89
90
|
transform: (node, subProps, deepTransformNode) => {
|
|
90
|
-
if (
|
|
91
|
+
if (subProps.keyPath.slice(props.keyPath.length).some((keyPath) => keyPath.type === _intlayer_types_nodeType.INSERTION)) return deepTransformNode(node, {
|
|
92
|
+
...subProps,
|
|
93
|
+
plugins: subProps.plugins?.filter((plugin) => plugin.id !== "plural-string-plugin")
|
|
94
|
+
});
|
|
95
|
+
if (require_interpreter_interpolableNode.isInterpolableWrapperNode(node)) return (values) => require_interpreter_interpolableNode.transformInterpolableNode(node, values, subProps, branchPlugins, deepTransformNode);
|
|
91
96
|
const transformedResult = deepTransformNode(node, {
|
|
92
97
|
...subProps,
|
|
93
98
|
children: node,
|
|
94
|
-
plugins: [...
|
|
99
|
+
plugins: [...branchPlugins.filter((plugin) => plugin.id !== "intlayer-node-plugin")]
|
|
95
100
|
});
|
|
96
101
|
return (values) => {
|
|
97
102
|
const children = require_interpreter_getInsertion.getInsertion(transformedResult, values);
|
|
98
103
|
return deepTransformNode(children, {
|
|
99
104
|
...subProps,
|
|
100
|
-
plugins:
|
|
105
|
+
plugins: branchPlugins,
|
|
101
106
|
children
|
|
102
107
|
});
|
|
103
108
|
};
|
|
@@ -112,7 +117,7 @@ const pluralPlugin = (locale) => process.env.INTLAYER_NODE_TYPE_PLURAL === "fals
|
|
|
112
117
|
type: _intlayer_types_nodeType.PLURAL,
|
|
113
118
|
key
|
|
114
119
|
}],
|
|
115
|
-
plugins: [pluralStringPlugin, ...
|
|
120
|
+
plugins: [pluralStringPlugin, ...branchPlugins]
|
|
116
121
|
});
|
|
117
122
|
}
|
|
118
123
|
const effectiveLocale = String(locale ?? props.locale ?? "en");
|
|
@@ -179,14 +184,67 @@ const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? f
|
|
|
179
184
|
};
|
|
180
185
|
}
|
|
181
186
|
};
|
|
182
|
-
|
|
187
|
+
const result = deepTransformNode(children, {
|
|
183
188
|
...props,
|
|
184
189
|
children,
|
|
185
190
|
keyPath: newKeyPath,
|
|
186
191
|
plugins: [insertionStringPlugin, ...props.plugins ?? []]
|
|
187
192
|
});
|
|
193
|
+
return resolveInsertedSelector(children, result);
|
|
188
194
|
}
|
|
189
195
|
};
|
|
196
|
+
/** Container nodes resolved by a selector call: `enu(3)`, `cond(true)`, … */
|
|
197
|
+
const selectorNodeTypes = [
|
|
198
|
+
_intlayer_types_nodeType.ENUMERATION,
|
|
199
|
+
_intlayer_types_nodeType.CONDITION,
|
|
200
|
+
_intlayer_types_nodeType.PLURAL,
|
|
201
|
+
_intlayer_types_nodeType.GENDER,
|
|
202
|
+
_intlayer_types_nodeType.SELECT
|
|
203
|
+
];
|
|
204
|
+
/** Whether `insert()` wraps a selector node that resolved to a function. */
|
|
205
|
+
const isInsertedSelector = (children, result) => {
|
|
206
|
+
const nodeType = typeof children === "object" && children !== null ? children.nodeType : void 0;
|
|
207
|
+
return typeof result === "function" && typeof nodeType === "string" && selectorNodeTypes.includes(nodeType);
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Binds the values of an `insert()` to the selector node it wraps, returning
|
|
211
|
+
* `(selector) => content`. Any other child result is returned unchanged.
|
|
212
|
+
*
|
|
213
|
+
* `areBranchesInterpolated` is set by frameworks that interpolate the branch
|
|
214
|
+
* strings as soon as the values are known: the selected branch is then final
|
|
215
|
+
* content and is never called with the values.
|
|
216
|
+
*/
|
|
217
|
+
const bindInsertedValues = (children, result, values, areBranchesInterpolated = false) => {
|
|
218
|
+
if (!isInsertedSelector(children, result)) return result;
|
|
219
|
+
const isPlural = children.nodeType === _intlayer_types_nodeType.PLURAL;
|
|
220
|
+
const isEnumeration = children.nodeType === _intlayer_types_nodeType.ENUMERATION;
|
|
221
|
+
return (selector) => {
|
|
222
|
+
if (typeof selector === "object" && selector !== null) return result({
|
|
223
|
+
...values,
|
|
224
|
+
...selector
|
|
225
|
+
});
|
|
226
|
+
if (isPlural) return result({
|
|
227
|
+
...values,
|
|
228
|
+
count: selector
|
|
229
|
+
});
|
|
230
|
+
if (isEnumeration && typeof selector === "number") {
|
|
231
|
+
const mergedValues = {
|
|
232
|
+
count: selector,
|
|
233
|
+
...values
|
|
234
|
+
};
|
|
235
|
+
const selected = result(mergedValues);
|
|
236
|
+
return !areBranchesInterpolated && typeof selected === "function" ? selected(mergedValues) : selected;
|
|
237
|
+
}
|
|
238
|
+
const selected = result(selector);
|
|
239
|
+
return !areBranchesInterpolated && typeof selected === "function" ? selected(values) : selected;
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Shapes the result of `insert()` wrapping a selector node as
|
|
244
|
+
* `(values) => (selector) => content`, so the values reach the selected
|
|
245
|
+
* branch. Any other child result is returned unchanged.
|
|
246
|
+
*/
|
|
247
|
+
const resolveInsertedSelector = (children, result) => isInsertedSelector(children, result) ? (values) => bindInsertedValues(children, result, values) : result;
|
|
190
248
|
/** Gender plugin. Replaces node with a function that takes gender => string. */
|
|
191
249
|
const genderPlugin = process.env.INTLAYER_NODE_TYPE_GENDER === "false" ? fallbackPlugin : {
|
|
192
250
|
id: "gender-plugin",
|
|
@@ -264,6 +322,7 @@ const filePlugin = process.env.INTLAYER_NODE_TYPE_FILE === "false" ? fallbackPlu
|
|
|
264
322
|
};
|
|
265
323
|
|
|
266
324
|
//#endregion
|
|
325
|
+
exports.bindInsertedValues = bindInsertedValues;
|
|
267
326
|
exports.conditionPlugin = conditionPlugin;
|
|
268
327
|
exports.enumerationPlugin = enumerationPlugin;
|
|
269
328
|
exports.fallbackPlugin = fallbackPlugin;
|
|
@@ -272,6 +331,7 @@ exports.genderPlugin = genderPlugin;
|
|
|
272
331
|
exports.insertionPlugin = insertionPlugin;
|
|
273
332
|
exports.nestedPlugin = nestedPlugin;
|
|
274
333
|
exports.pluralPlugin = pluralPlugin;
|
|
334
|
+
exports.resolveInsertedSelector = resolveInsertedSelector;
|
|
275
335
|
exports.selectPlugin = selectPlugin;
|
|
276
336
|
exports.translationPlugin = translationPlugin;
|
|
277
337
|
//# sourceMappingURL=plugins.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["NodeTypes","getTranslation","getEnumeration","isInterpolableWrapperNode","transformInterpolableNode","getInsertion","getPlural","getCondition","getGender","getSelect","getNestingOptimized","getNesting"],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n PluralContent,\n PluralContentState,\n SelectContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getNesting as getNestingOptimized } from '../getNesting.optimized';\nimport { getPlural } from '../getPlural';\nimport { getSelect } from '../getSelect';\nimport { getTranslation } from '../getTranslation';\nimport {\n isInterpolableWrapperNode,\n transformInterpolableNode,\n} from '../interpolableNode';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * FALLBACK PLUGIN\n *\n * Used to fallback a tree-shaken plugin\n * --------------------------------------------- */\n\nexport const fallbackPlugin: Plugins = {\n id: 'fallback-plugin',\n canHandle: () => false,\n transform: (node) => node,\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins =>\n process.env.INTLAYER_NODE_TYPE_TRANSLATION === 'false'\n ? fallbackPlugin\n : {\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.TRANSLATION] ?? {};\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const childProps = {\n ...props,\n children: original[key as keyof typeof original],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n original[key as keyof typeof original],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n };\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_ENUMERATION === 'false'\n ? fallbackPlugin\n : {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.ENUMERATION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as unknown as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * PLURAL PLUGIN\n * --------------------------------------------- */\n\nexport type PluralCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.PLURAL]: object;\n}\n ? (\n arg: number | { count: number; [key: string]: unknown }\n ) => DeepTransformContent<\n T[typeof NodeTypes.PLURAL][keyof T[typeof NodeTypes.PLURAL]],\n S\n >\n : never;\n\ntype SubResultFunction = (values: Record<string, string | number>) => string;\n\n/**\n * Plural plugin. Replaces node with a function that takes a count (or\n * `{ count, ...values }`) => string, picking the matching CLDR plural form\n * for the active locale and interpolating `{{count}}` (and other values).\n */\nexport const pluralPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_PLURAL === 'false'\n ? fallbackPlugin\n : {\n id: 'plural-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.PLURAL,\n transform: (node: PluralContent, props, deepTransformNode) => {\n const original = node[NodeTypes.PLURAL];\n const result: Record<string, any> = {};\n\n /** String plugin for plural. Replaces string node with a component that renders the insertion. */\n const pluralStringPlugin: Plugins = {\n id: 'plural-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{count}}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (values: { [k: string]: string | number }) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: { [k: string]: string | number }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.PLURAL, key } as KeyPath,\n ],\n plugins: [pluralStringPlugin, ...(props.plugins ?? [])],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n const effectiveLocale = String(locale ?? props.locale ?? 'en');\n\n return (arg: number | { count: number; [key: string]: unknown }) => {\n const count = typeof arg === 'number' ? arg : arg.count;\n const values =\n typeof arg === 'number'\n ? { count: arg }\n : (arg as { count: number; [key: string]: unknown });\n\n const subResult: string | SubResultFunction = getPlural(\n result as PluralContent['plural'] as PluralContentState<string>,\n count,\n effectiveLocale\n );\n\n if (typeof subResult === 'function') {\n return (subResult as SubResultFunction)(values);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_CONDITION === 'false'\n ? fallbackPlugin\n : {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const original = node[NodeTypes.CONDITION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result as any, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => I extends string\n ? DeepTransformContent<string, S>\n : DeepTransformContent<I, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\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 {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_GENDER === 'false'\n ? fallbackPlugin\n : {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const original = node[NodeTypes.GENDER];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.GENDER, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result as any, value);\n },\n };\n\n/** ---------------------------------------------\n * SELECT PLUGIN\n * --------------------------------------------- */\n\n/**\n * Accepted selector for a select node.\n *\n * When the node declares a `fallback` case, any string is accepted (the\n * fallback covers the unmatched values) while the declared cases still\n * autocomplete. Without a `fallback`, only the declared cases are accepted.\n */\nexport type SelectSelector<States> = 'fallback' extends keyof States\n ? Exclude<keyof States & string, 'fallback'> | (string & {})\n : keyof States & string;\n\nexport type SelectCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.SELECT]: object;\n}\n ? (\n value:\n | SelectSelector<T[typeof NodeTypes.SELECT]>\n | { value: SelectSelector<T[typeof NodeTypes.SELECT]> }\n ) => DeepTransformContent<\n T[typeof NodeTypes.SELECT][keyof T[typeof NodeTypes.SELECT]],\n S\n >\n : never;\n\n/** Select plugin. Replaces node with a function that takes a string => content. */\nexport const selectPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_SELECT === 'false'\n ? fallbackPlugin\n : {\n id: 'select-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.SELECT,\n transform: (node: SelectContent, props, deepTransformNode) => {\n const original = node[NodeTypes.SELECT];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.SELECT, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: string | { value: string }) => {\n const value = typeof arg === 'string' ? arg : arg?.value;\n const subResult = getSelect(result, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/**\n * Resolver used to turn a nested node into content.\n *\n * Optimized builds set `INTLAYER_OPTIMIZED_NESTING` so bundlers fold this to\n * the local resolver and dead-code-eliminate the registry-based one — together\n * with its `getIntlayer` import, and therefore the whole\n * `@intlayer/dictionaries-entry` module. That is what allows the dictionaries\n * entry to be emptied while `nest()` keeps working.\n */\nconst resolveNesting =\n process.env.INTLAYER_OPTIMIZED_NESTING === 'true'\n ? getNestingOptimized\n : getNesting;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_NESTED === 'false'\n ? fallbackPlugin\n : {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n resolveNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n };\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? DeepTransformContent<string, S>\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_FILE === 'false'\n ? fallbackPlugin\n : {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n };\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n /**\n * Dictionaries referenced through `nest()`, attached to the consuming\n * dictionary by the build optimization and threaded down by\n * `deepTransformNode`.\n *\n * Present only in optimized builds, where the global dictionary registry is\n * stripped and `getNesting` resolves from this map instead. See\n * `getNesting.optimized.ts`.\n */\n nestedDictionaries?: Record<string, unknown>;\n /**\n * Forces eager traversal of plain objects in `deepTransformNode`. By default\n * traversal is lazy (property getters), so callers that discard the returned\n * value never trigger plugins on nested nodes. Set this when running plugins\n * for their side effects only (e.g. missing-locale detection).\n */\n eager?: boolean;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n plural: PluralCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n select: SelectCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T, S, L>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n plural: true;\n condition: true;\n insertion: true;\n gender: true;\n select: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAA0B;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AAQ,WAAW,MAAM,KAAK;GACnD,MAAM,YAAYS,wCAAU,QAAQ,KAAK;GAEzC,IAAI,OAAO,cAAc,cAAc,OAAO,QAAQ,UACpD,OAAO,UAAU,GAAG;GAGtB,OAAO;EACT;CACF;AACF;;;;;;;;;;AA2BN,MAAM,iBACJ,QAAQ,IAAI,+BAA+B,SACvCC,sDACAC;;AAGN,MAAa,gBAAgB,WAC3B,QAAQ,IAAI,8BAA8B,UACtC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,aACf,MAAM,aAAaX,yBAAU,UAAU,MAAM,aAAa;CAC7D,YAAY,MAAqB,UAC/B,eACE,KAAKA,yBAAU,OAAO,CAAC,eACvB,KAAKA,yBAAU,OAAO,CAAC,MACvB;EACE,GAAG;EACH,QAAS,UAAU,MAAM;CAC3B,CACF;AACJ;;AAeN,MAAa,aACX,QAAQ,IAAI,4BAA4B,UACpC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaA,yBAAU;CAC3D,YAAY,MAAmB,OAAO,kBACpC,cAAc,KAAK,SAAS;EAC1B,GAAG;EACH,UAAU,KAAK;CACjB,CAAC;AACL"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["NodeTypes","getTranslation","getEnumeration","isInterpolableWrapperNode","transformInterpolableNode","getInsertion","getPlural","getCondition","getGender","getSelect","getNestingOptimized","getNesting"],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n PluralContent,\n PluralContentState,\n SelectContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getNesting as getNestingOptimized } from '../getNesting.optimized';\nimport { getPlural } from '../getPlural';\nimport { getSelect } from '../getSelect';\nimport { getTranslation } from '../getTranslation';\nimport {\n isInterpolableWrapperNode,\n transformInterpolableNode,\n} from '../interpolableNode';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * FALLBACK PLUGIN\n *\n * Used to fallback a tree-shaken plugin\n * --------------------------------------------- */\n\nexport const fallbackPlugin: Plugins = {\n id: 'fallback-plugin',\n canHandle: () => false,\n transform: (node) => node,\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins =>\n process.env.INTLAYER_NODE_TYPE_TRANSLATION === 'false'\n ? fallbackPlugin\n : {\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.TRANSLATION] ?? {};\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const childProps = {\n ...props,\n children: original[key as keyof typeof original],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n original[key as keyof typeof original],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n };\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_ENUMERATION === 'false'\n ? fallbackPlugin\n : {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.ENUMERATION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as unknown as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * PLURAL PLUGIN\n * --------------------------------------------- */\n\n/**\n * A plural branch wrapped in an `insertion` node (auto-transformed\n * `{{count}}`) resolves to its inner content: the plural applies the values.\n */\ntype PluralBranch<Branch> = Branch extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer InsertionContent;\n fields: readonly string[];\n}\n ? InsertionContent\n : Branch;\n\nexport type PluralCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.PLURAL]: object;\n}\n ? (\n arg: number | { count: number; [key: string]: unknown }\n ) => DeepTransformContent<\n PluralBranch<\n T[typeof NodeTypes.PLURAL][keyof T[typeof NodeTypes.PLURAL]]\n >,\n S\n >\n : never;\n\ntype SubResultFunction = (values: Record<string, string | number>) => string;\n\n/**\n * Plural plugin. Replaces node with a function that takes a count (or\n * `{ count, ...values }`) => string, picking the matching CLDR plural form\n * for the active locale and interpolating `{{count}}` (and other values).\n */\nexport const pluralPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_PLURAL === 'false'\n ? fallbackPlugin\n : {\n id: 'plural-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.PLURAL,\n transform: (node: PluralContent, props, deepTransformNode) => {\n const original = node[NodeTypes.PLURAL];\n const result: Record<string, any> = {};\n // The plural interpolates its own branches. A string plugin from an\n // enclosing `insert()` would turn them into functions first.\n const branchPlugins = (props.plugins ?? []).filter(\n (plugin) => plugin.id !== 'insertion-string-plugin'\n );\n\n /** String plugin for plural. Replaces string node with a component that renders the insertion. */\n const pluralStringPlugin: Plugins = {\n id: 'plural-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // An `insertion` node below the plural (e.g. auto-transformed\n // `{{count}}` branches) already returns `(values) => …`. Leave its\n // strings untouched, or its template would become a function.\n const isInsideInsertion = subProps.keyPath\n .slice(props.keyPath.length)\n .some((keyPath) => keyPath.type === NodeTypes.INSERTION);\n\n if (isInsideInsertion) {\n return deepTransformNode(node, {\n ...subProps,\n plugins: subProps.plugins?.filter(\n (plugin) => plugin.id !== 'plural-string-plugin'\n ),\n });\n }\n\n // `html()`/`markdown()` nodes carry their `{{count}}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (values: { [k: string]: string | number }) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n branchPlugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...branchPlugins.filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: { [k: string]: string | number }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: branchPlugins,\n children,\n });\n };\n },\n };\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.PLURAL, key } as KeyPath,\n ],\n plugins: [pluralStringPlugin, ...branchPlugins],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n const effectiveLocale = String(locale ?? props.locale ?? 'en');\n\n return (arg: number | { count: number; [key: string]: unknown }) => {\n const count = typeof arg === 'number' ? arg : arg.count;\n const values =\n typeof arg === 'number'\n ? { count: arg }\n : (arg as { count: number; [key: string]: unknown });\n\n const subResult: string | SubResultFunction = getPlural(\n result as PluralContent['plural'] as PluralContentState<string>,\n count,\n effectiveLocale\n );\n\n if (typeof subResult === 'function') {\n return (subResult as SubResultFunction)(values);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_CONDITION === 'false'\n ? fallbackPlugin\n : {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const original = node[NodeTypes.CONDITION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result as any, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => I extends string\n ? DeepTransformContent<string, S>\n : DeepTransformContent<I, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\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 {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n return resolveInsertedSelector(children, result);\n },\n };\n\n/** Container nodes resolved by a selector call: `enu(3)`, `cond(true)`, … */\nconst selectorNodeTypes: string[] = [\n NodeTypes.ENUMERATION,\n NodeTypes.CONDITION,\n NodeTypes.PLURAL,\n NodeTypes.GENDER,\n NodeTypes.SELECT,\n];\n\n/** Whether `insert()` wraps a selector node that resolved to a function. */\nconst isInsertedSelector = (\n children: unknown,\n result: unknown\n): result is (selector: unknown) => unknown => {\n const nodeType =\n typeof children === 'object' && children !== null\n ? (children as { nodeType?: unknown }).nodeType\n : undefined;\n\n return (\n typeof result === 'function' &&\n typeof nodeType === 'string' &&\n selectorNodeTypes.includes(nodeType)\n );\n};\n\n/**\n * Binds the values of an `insert()` to the selector node it wraps, returning\n * `(selector) => content`. Any other child result is returned unchanged.\n *\n * `areBranchesInterpolated` is set by frameworks that interpolate the branch\n * strings as soon as the values are known: the selected branch is then final\n * content and is never called with the values.\n */\nexport const bindInsertedValues = (\n children: unknown,\n result: unknown,\n values: Record<string, unknown>,\n areBranchesInterpolated = false\n): unknown => {\n if (!isInsertedSelector(children, result)) {\n return result;\n }\n\n const isPlural =\n (children as { nodeType: string }).nodeType === NodeTypes.PLURAL;\n const isEnumeration =\n (children as { nodeType: string }).nodeType === NodeTypes.ENUMERATION;\n\n return (selector: unknown) => {\n // Object selectors (`{ count }`, `{ value }`) carry the values along.\n if (typeof selector === 'object' && selector !== null) {\n return result({ ...values, ...selector });\n }\n\n // Plural interpolates its own branches, `{{count}}` included.\n if (isPlural) {\n return result({ ...values, count: selector });\n }\n\n // Enumeration selector is a numeric count (or count range)\n if (isEnumeration && typeof selector === 'number') {\n const mergedValues = { count: selector, ...values };\n const selected = result(mergedValues);\n\n return !areBranchesInterpolated && typeof selected === 'function'\n ? selected(mergedValues)\n : selected;\n }\n\n const selected = result(selector);\n\n return !areBranchesInterpolated && typeof selected === 'function'\n ? selected(values)\n : selected;\n };\n};\n\n/**\n * Shapes the result of `insert()` wrapping a selector node as\n * `(values) => (selector) => content`, so the values reach the selected\n * branch. Any other child result is returned unchanged.\n */\nexport const resolveInsertedSelector = (\n children: unknown,\n result: unknown\n): unknown =>\n isInsertedSelector(children, result)\n ? (values: Record<string, unknown>) =>\n bindInsertedValues(children, result, values)\n : result;\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_GENDER === 'false'\n ? fallbackPlugin\n : {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const original = node[NodeTypes.GENDER];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.GENDER, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result as any, value);\n },\n };\n\n/** ---------------------------------------------\n * SELECT PLUGIN\n * --------------------------------------------- */\n\n/**\n * Accepted selector for a select node.\n *\n * When the node declares a `fallback` case, any string is accepted (the\n * fallback covers the unmatched values) while the declared cases still\n * autocomplete. Without a `fallback`, only the declared cases are accepted.\n */\nexport type SelectSelector<States> = 'fallback' extends keyof States\n ? Exclude<keyof States & string, 'fallback'> | (string & {})\n : keyof States & string;\n\nexport type SelectCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.SELECT]: object;\n}\n ? (\n value:\n | SelectSelector<T[typeof NodeTypes.SELECT]>\n | { value: SelectSelector<T[typeof NodeTypes.SELECT]> }\n ) => DeepTransformContent<\n T[typeof NodeTypes.SELECT][keyof T[typeof NodeTypes.SELECT]],\n S\n >\n : never;\n\n/** Select plugin. Replaces node with a function that takes a string => content. */\nexport const selectPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_SELECT === 'false'\n ? fallbackPlugin\n : {\n id: 'select-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.SELECT,\n transform: (node: SelectContent, props, deepTransformNode) => {\n const original = node[NodeTypes.SELECT];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.SELECT, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: string | { value: string }) => {\n const value = typeof arg === 'string' ? arg : arg?.value;\n const subResult = getSelect(result, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/**\n * Resolver used to turn a nested node into content.\n *\n * Optimized builds set `INTLAYER_OPTIMIZED_NESTING` so bundlers fold this to\n * the local resolver and dead-code-eliminate the registry-based one — together\n * with its `getIntlayer` import, and therefore the whole\n * `@intlayer/dictionaries-entry` module. That is what allows the dictionaries\n * entry to be emptied while `nest()` keeps working.\n */\nconst resolveNesting =\n process.env.INTLAYER_OPTIMIZED_NESTING === 'true'\n ? getNestingOptimized\n : getNesting;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_NESTED === 'false'\n ? fallbackPlugin\n : {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n resolveNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n };\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? DeepTransformContent<string, S>\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_FILE === 'false'\n ? fallbackPlugin\n : {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n };\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n /**\n * Dictionaries referenced through `nest()`, attached to the consuming\n * dictionary by the build optimization and threaded down by\n * `deepTransformNode`.\n *\n * Present only in optimized builds, where the global dictionary registry is\n * stripped and `getNesting` resolves from this map instead. See\n * `getNesting.optimized.ts`.\n */\n nestedDictionaries?: Record<string, unknown>;\n /**\n * Forces eager traversal of plain objects in `deepTransformNode`. By default\n * traversal is lazy (property getters), so callers that discard the returned\n * value never trigger plugins on nested nodes. Set this when running plugins\n * for their side effects only (e.g. missing-locale detection).\n */\n eager?: boolean;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n plural: PluralCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n select: SelectCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T, S, L>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n plural: true;\n condition: true;\n insertion: true;\n gender: true;\n select: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,iBAA0B;CACrC,IAAI;CACJ,iBAAiB;CACjB,YAAY,SAAS;AACvB;;AAmCA,MAAa,qBACX,QACA,aAEA,QAAQ,IAAI,mCAAmC,UAC3C,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaA,yBAAU;CAC3D,YAAY,MAA0B,OAAO,s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,OAAO;EACT;CACF;AACF;;;;;;;;;;AA2BN,MAAM,iBACJ,QAAQ,IAAI,+BAA+B,SACvCC,sDACAC;;AAGN,MAAa,gBAAgB,WAC3B,QAAQ,IAAI,8BAA8B,UACtC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,aACf,MAAM,aAAaX,yBAAU,UAAU,MAAM,aAAa;CAC7D,YAAY,MAAqB,UAC/B,eACE,KAAKA,yBAAU,OAAO,CAAC,eACvB,KAAKA,yBAAU,OAAO,CAAC,MACvB;EACE,GAAG;EACH,QAAS,UAAU,MAAM;CAC3B,CACF;AACJ;;AAeN,MAAa,aACX,QAAQ,IAAI,4BAA4B,UACpC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaA,yBAAU;CAC3D,YAAY,MAAmB,OAAO,kBACpC,cAAc,KAAK,SAAS;EAC1B,GAAG;EACH,UAAU,KAAK;CACjB,CAAC;AACL"}
|
|
@@ -19,6 +19,7 @@ const require_interpreter_getHTML = require('./getHTML.cjs');
|
|
|
19
19
|
const require_interpreter_getIntlayerAsync = require('./getIntlayerAsync.cjs');
|
|
20
20
|
const require_interpreter_splitAndJoinInsertion = require('./splitAndJoinInsertion.cjs');
|
|
21
21
|
|
|
22
|
+
exports.bindInsertedValues = require_interpreter_getContent_plugins.bindInsertedValues;
|
|
22
23
|
exports.conditionPlugin = require_interpreter_getContent_plugins.conditionPlugin;
|
|
23
24
|
exports.deepTransformNode = require_interpreter_getContent_deepTransform.deepTransformNode;
|
|
24
25
|
exports.enumerationPlugin = require_interpreter_getContent_plugins.enumerationPlugin;
|
|
@@ -50,6 +51,7 @@ exports.nestedPlugin = require_interpreter_getContent_plugins.nestedPlugin;
|
|
|
50
51
|
exports.pluralPlugin = require_interpreter_getContent_plugins.pluralPlugin;
|
|
51
52
|
exports.readTransformCache = require_interpreter_dictionaryTransformCache.readTransformCache;
|
|
52
53
|
exports.rebuildInterpolableContent = require_interpreter_interpolableNode.rebuildInterpolableContent;
|
|
54
|
+
exports.resolveInsertedSelector = require_interpreter_getContent_plugins.resolveInsertedSelector;
|
|
53
55
|
exports.selectPlugin = require_interpreter_getContent_plugins.selectPlugin;
|
|
54
56
|
exports.splitInsertionTemplate = require_interpreter_splitAndJoinInsertion.splitInsertionTemplate;
|
|
55
57
|
exports.transformInterpolableNode = require_interpreter_interpolableNode.transformInterpolableNode;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import { getPlural } from "./interpreter/getPlural.mjs";
|
|
|
22
22
|
import { getSelect } from "./interpreter/getSelect.mjs";
|
|
23
23
|
import { getTranslation } from "./interpreter/getTranslation.mjs";
|
|
24
24
|
import { getInterpolableContent, isInterpolableWrapperNode, rebuildInterpolableContent, transformInterpolableNode } from "./interpreter/interpolableNode.mjs";
|
|
25
|
-
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./interpreter/getContent/plugins.mjs";
|
|
25
|
+
import { bindInsertedValues, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, resolveInsertedSelector, selectPlugin, translationPlugin } from "./interpreter/getContent/plugins.mjs";
|
|
26
26
|
import { getBasePlugins, getContent } from "./interpreter/getContent/getContent.mjs";
|
|
27
27
|
import { PRELOADED_DYNAMIC_KEY, getPreloadedDictionary } from "./dictionaryManipulator/preloadedDynamicLoader.mjs";
|
|
28
28
|
import { QUALIFIER_DYNAMIC_TYPES_KEY, isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync } from "./dictionaryManipulator/qualifiedDynamicLoader.mjs";
|
|
@@ -114,4 +114,4 @@ import { createMessageResolver, interpolateMessage, parseTaggedMessage, resolveM
|
|
|
114
114
|
import { isSameKeyPath } from "./utils/isSameKeyPath.mjs";
|
|
115
115
|
import { stringifyYaml } from "./utils/stringifyYaml.mjs";
|
|
116
116
|
|
|
117
|
-
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CachedIntl, CachedIntl as Intl, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, FENCE_DELIMITER_R, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LOOKAHEAD, LocaleStorage, LocaleStorageClient, LocaleStorageServer, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, PRELOADED_DYNAMIC_KEY, Priority, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleScope, RuleType, SCOPE_BLOCK, SCOPE_BOTH, SCOPE_INLINE, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_HTML_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createMessageResolver, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, findPlainDynamicLoader, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryAsync, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDictionaryTransformCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getIntlayerAsync, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromRequest, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPluginsCacheKey, getPlural, getPrefix, getPreloadLocale, getPreloadedDictionary, getReplacedValuesContent, getRewritePath, getRewriteRules, getRuleSet, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isDeclaredLocale, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, readTransformCache, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveBrowserLocale, resolveDictionaryArgument, resolveEffectiveVariantId, resolveLocalizedPath, resolveMessage, resolveMessageNode, resolveMessageNodeToString, resolvePlainDynamicLoader, resolveProviderVariant, resolveProxyMode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, select, selectPlugin, serializeVariant, serializeVariantChain, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter, writeTransformCache };
|
|
117
|
+
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CachedIntl, CachedIntl as Intl, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, FENCE_DELIMITER_R, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LOOKAHEAD, LocaleStorage, LocaleStorageClient, LocaleStorageServer, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, PRELOADED_DYNAMIC_KEY, Priority, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleScope, RuleType, SCOPE_BLOCK, SCOPE_BOTH, SCOPE_INLINE, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_HTML_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindInsertedValues, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createMessageResolver, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, findPlainDynamicLoader, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryAsync, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDictionaryTransformCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getIntlayerAsync, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromRequest, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPluginsCacheKey, getPlural, getPrefix, getPreloadLocale, getPreloadedDictionary, getReplacedValuesContent, getRewritePath, getRewriteRules, getRuleSet, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isDeclaredLocale, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, readTransformCache, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveBrowserLocale, resolveDictionaryArgument, resolveEffectiveVariantId, resolveInsertedSelector, resolveLocalizedPath, resolveMessage, resolveMessageNode, resolveMessageNodeToString, resolvePlainDynamicLoader, resolveProviderVariant, resolveProxyMode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, select, selectPlugin, serializeVariant, serializeVariantChain, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter, writeTransformCache };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepTransformNode } from "./deepTransform.mjs";
|
|
2
|
-
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./plugins.mjs";
|
|
2
|
+
import { bindInsertedValues, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, resolveInsertedSelector, selectPlugin, translationPlugin } from "./plugins.mjs";
|
|
3
3
|
import { getBasePlugins, getContent } from "./getContent.mjs";
|
|
4
4
|
|
|
5
|
-
export { conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getBasePlugins, getContent, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin };
|
|
5
|
+
export { bindInsertedValues, conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getBasePlugins, getContent, insertionPlugin, nestedPlugin, pluralPlugin, resolveInsertedSelector, selectPlugin, translationPlugin };
|
|
@@ -79,22 +79,27 @@ const pluralPlugin = (locale) => process.env.INTLAYER_NODE_TYPE_PLURAL === "fals
|
|
|
79
79
|
transform: (node, props, deepTransformNode) => {
|
|
80
80
|
const original = node[NodeTypes.PLURAL];
|
|
81
81
|
const result = {};
|
|
82
|
+
const branchPlugins = (props.plugins ?? []).filter((plugin) => plugin.id !== "insertion-string-plugin");
|
|
82
83
|
/** String plugin for plural. Replaces string node with a component that renders the insertion. */
|
|
83
84
|
const pluralStringPlugin = {
|
|
84
85
|
id: "plural-string-plugin",
|
|
85
86
|
canHandle: (node) => typeof node === "string" || isInterpolableWrapperNode(node),
|
|
86
87
|
transform: (node, subProps, deepTransformNode) => {
|
|
87
|
-
if (
|
|
88
|
+
if (subProps.keyPath.slice(props.keyPath.length).some((keyPath) => keyPath.type === NodeTypes.INSERTION)) return deepTransformNode(node, {
|
|
89
|
+
...subProps,
|
|
90
|
+
plugins: subProps.plugins?.filter((plugin) => plugin.id !== "plural-string-plugin")
|
|
91
|
+
});
|
|
92
|
+
if (isInterpolableWrapperNode(node)) return (values) => transformInterpolableNode(node, values, subProps, branchPlugins, deepTransformNode);
|
|
88
93
|
const transformedResult = deepTransformNode(node, {
|
|
89
94
|
...subProps,
|
|
90
95
|
children: node,
|
|
91
|
-
plugins: [...
|
|
96
|
+
plugins: [...branchPlugins.filter((plugin) => plugin.id !== "intlayer-node-plugin")]
|
|
92
97
|
});
|
|
93
98
|
return (values) => {
|
|
94
99
|
const children = getInsertion(transformedResult, values);
|
|
95
100
|
return deepTransformNode(children, {
|
|
96
101
|
...subProps,
|
|
97
|
-
plugins:
|
|
102
|
+
plugins: branchPlugins,
|
|
98
103
|
children
|
|
99
104
|
});
|
|
100
105
|
};
|
|
@@ -109,7 +114,7 @@ const pluralPlugin = (locale) => process.env.INTLAYER_NODE_TYPE_PLURAL === "fals
|
|
|
109
114
|
type: NodeTypes.PLURAL,
|
|
110
115
|
key
|
|
111
116
|
}],
|
|
112
|
-
plugins: [pluralStringPlugin, ...
|
|
117
|
+
plugins: [pluralStringPlugin, ...branchPlugins]
|
|
113
118
|
});
|
|
114
119
|
}
|
|
115
120
|
const effectiveLocale = String(locale ?? props.locale ?? "en");
|
|
@@ -176,14 +181,67 @@ const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? f
|
|
|
176
181
|
};
|
|
177
182
|
}
|
|
178
183
|
};
|
|
179
|
-
|
|
184
|
+
const result = deepTransformNode(children, {
|
|
180
185
|
...props,
|
|
181
186
|
children,
|
|
182
187
|
keyPath: newKeyPath,
|
|
183
188
|
plugins: [insertionStringPlugin, ...props.plugins ?? []]
|
|
184
189
|
});
|
|
190
|
+
return resolveInsertedSelector(children, result);
|
|
185
191
|
}
|
|
186
192
|
};
|
|
193
|
+
/** Container nodes resolved by a selector call: `enu(3)`, `cond(true)`, … */
|
|
194
|
+
const selectorNodeTypes = [
|
|
195
|
+
NodeTypes.ENUMERATION,
|
|
196
|
+
NodeTypes.CONDITION,
|
|
197
|
+
NodeTypes.PLURAL,
|
|
198
|
+
NodeTypes.GENDER,
|
|
199
|
+
NodeTypes.SELECT
|
|
200
|
+
];
|
|
201
|
+
/** Whether `insert()` wraps a selector node that resolved to a function. */
|
|
202
|
+
const isInsertedSelector = (children, result) => {
|
|
203
|
+
const nodeType = typeof children === "object" && children !== null ? children.nodeType : void 0;
|
|
204
|
+
return typeof result === "function" && typeof nodeType === "string" && selectorNodeTypes.includes(nodeType);
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Binds the values of an `insert()` to the selector node it wraps, returning
|
|
208
|
+
* `(selector) => content`. Any other child result is returned unchanged.
|
|
209
|
+
*
|
|
210
|
+
* `areBranchesInterpolated` is set by frameworks that interpolate the branch
|
|
211
|
+
* strings as soon as the values are known: the selected branch is then final
|
|
212
|
+
* content and is never called with the values.
|
|
213
|
+
*/
|
|
214
|
+
const bindInsertedValues = (children, result, values, areBranchesInterpolated = false) => {
|
|
215
|
+
if (!isInsertedSelector(children, result)) return result;
|
|
216
|
+
const isPlural = children.nodeType === NodeTypes.PLURAL;
|
|
217
|
+
const isEnumeration = children.nodeType === NodeTypes.ENUMERATION;
|
|
218
|
+
return (selector) => {
|
|
219
|
+
if (typeof selector === "object" && selector !== null) return result({
|
|
220
|
+
...values,
|
|
221
|
+
...selector
|
|
222
|
+
});
|
|
223
|
+
if (isPlural) return result({
|
|
224
|
+
...values,
|
|
225
|
+
count: selector
|
|
226
|
+
});
|
|
227
|
+
if (isEnumeration && typeof selector === "number") {
|
|
228
|
+
const mergedValues = {
|
|
229
|
+
count: selector,
|
|
230
|
+
...values
|
|
231
|
+
};
|
|
232
|
+
const selected = result(mergedValues);
|
|
233
|
+
return !areBranchesInterpolated && typeof selected === "function" ? selected(mergedValues) : selected;
|
|
234
|
+
}
|
|
235
|
+
const selected = result(selector);
|
|
236
|
+
return !areBranchesInterpolated && typeof selected === "function" ? selected(values) : selected;
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Shapes the result of `insert()` wrapping a selector node as
|
|
241
|
+
* `(values) => (selector) => content`, so the values reach the selected
|
|
242
|
+
* branch. Any other child result is returned unchanged.
|
|
243
|
+
*/
|
|
244
|
+
const resolveInsertedSelector = (children, result) => isInsertedSelector(children, result) ? (values) => bindInsertedValues(children, result, values) : result;
|
|
187
245
|
/** Gender plugin. Replaces node with a function that takes gender => string. */
|
|
188
246
|
const genderPlugin = process.env.INTLAYER_NODE_TYPE_GENDER === "false" ? fallbackPlugin : {
|
|
189
247
|
id: "gender-plugin",
|
|
@@ -261,5 +319,5 @@ const filePlugin = process.env.INTLAYER_NODE_TYPE_FILE === "false" ? fallbackPlu
|
|
|
261
319
|
};
|
|
262
320
|
|
|
263
321
|
//#endregion
|
|
264
|
-
export { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin };
|
|
322
|
+
export { bindInsertedValues, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, resolveInsertedSelector, selectPlugin, translationPlugin };
|
|
265
323
|
//# sourceMappingURL=plugins.mjs.map
|