@intlayer/core 9.4.0-canary.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/cjs/dictionaryManipulator/index.cjs +5 -2
- package/dist/cjs/index.cjs +15 -3
- package/dist/cjs/interpreter/dictionaryTransformCache.cjs +111 -0
- package/dist/cjs/interpreter/dictionaryTransformCache.cjs.map +1 -0
- package/dist/cjs/interpreter/getDictionary.cjs +8 -8
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionaryAsync.cjs +79 -0
- package/dist/cjs/interpreter/getDictionaryAsync.cjs.map +1 -0
- package/dist/cjs/interpreter/getIntlayer.cjs +22 -15
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayerAsync.cjs +36 -0
- package/dist/cjs/interpreter/getIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/interpreter/index.cjs +10 -1
- package/dist/cjs/localization/generateSitemap.cjs +57 -27
- package/dist/cjs/localization/generateSitemap.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedPath.cjs +3 -0
- package/dist/cjs/localization/getLocalizedPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedPath.test-d.cjs +16 -0
- package/dist/cjs/localization/getLocalizedPath.test-d.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +8 -0
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.test-d.cjs +36 -0
- package/dist/cjs/localization/getLocalizedUrl.test-d.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/markdown/constants.cjs +24 -3
- package/dist/cjs/markdown/constants.cjs.map +1 -1
- package/dist/esm/dictionaryManipulator/index.mjs +4 -3
- package/dist/esm/index.mjs +7 -3
- package/dist/esm/interpreter/dictionaryTransformCache.mjs +107 -0
- package/dist/esm/interpreter/dictionaryTransformCache.mjs.map +1 -0
- package/dist/esm/interpreter/getDictionary.mjs +9 -9
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionaryAsync.mjs +78 -0
- package/dist/esm/interpreter/getDictionaryAsync.mjs.map +1 -0
- package/dist/esm/interpreter/getIntlayer.mjs +22 -15
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayerAsync.mjs +35 -0
- package/dist/esm/interpreter/getIntlayerAsync.mjs.map +1 -0
- package/dist/esm/interpreter/index.mjs +4 -1
- package/dist/esm/localization/generateSitemap.mjs +57 -27
- package/dist/esm/localization/generateSitemap.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedPath.mjs +3 -0
- package/dist/esm/localization/getLocalizedPath.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedPath.test-d.mjs +16 -0
- package/dist/esm/localization/getLocalizedPath.test-d.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +8 -0
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.test-d.mjs +36 -0
- package/dist/esm/localization/getLocalizedUrl.test-d.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/markdown/constants.mjs +24 -3
- package/dist/esm/markdown/constants.mjs.map +1 -1
- package/dist/types/dictionaryManipulator/index.d.ts +3 -2
- package/dist/types/index.d.ts +7 -3
- package/dist/types/interpreter/dictionaryTransformCache.d.ts +42 -0
- package/dist/types/interpreter/dictionaryTransformCache.d.ts.map +1 -0
- package/dist/types/interpreter/getContent/plugins.d.ts +2 -2
- package/dist/types/interpreter/getDictionary.d.ts +0 -5
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getDictionaryAsync.d.ts +34 -0
- package/dist/types/interpreter/getDictionaryAsync.d.ts.map +1 -0
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayerAsync.d.ts +36 -0
- package/dist/types/interpreter/getIntlayerAsync.d.ts.map +1 -0
- package/dist/types/interpreter/index.d.ts +5 -2
- package/dist/types/localization/generateSitemap.d.ts +34 -9
- package/dist/types/localization/generateSitemap.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedPath.d.ts +3 -0
- package/dist/types/localization/getLocalizedPath.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts +8 -0
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getPrefix.d.ts +9 -4
- package/dist/types/localization/getPrefix.d.ts.map +1 -1
- package/dist/types/markdown/constants.d.ts +0 -1
- package/dist/types/markdown/constants.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","names":[],"sources":["../../../src/markdown/constants.ts"],"sourcesContent":["// ============================================================================\n// RULE TYPES\n// ============================================================================\n\n/**\n * Analogous to `node.type`. Please note that the values here may change at any time,\n * so do not hard code against the value directly.\n */\nexport const RuleType = {\n blockQuote: '0',\n breakLine: '1',\n breakThematic: '2',\n codeBlock: '3',\n codeFenced: '4',\n codeInline: '5',\n footnote: '6',\n footnoteReference: '7',\n gfmTask: '8',\n heading: '9',\n headingSetext: '10',\n /** only available if not `disableHTMLParsing` */\n htmlBlock: '11',\n htmlComment: '12',\n /** only available if not `disableHTMLParsing` */\n htmlSelfClosing: '13',\n /** Custom components like <Tabs>, <TabItem> */\n customComponent: '34',\n image: '14',\n link: '15',\n /** emits a `link` 'node', does not render directly */\n linkAngleBraceStyleDetector: '16',\n /** emits a `link` 'node', does not render directly */\n linkBareUrlDetector: '17',\n newlineCoalescer: '19',\n orderedList: '20',\n paragraph: '21',\n ref: '22',\n refImage: '23',\n refLink: '24',\n table: '25',\n tableSeparator: '26',\n text: '27',\n textBolded: '28',\n textEmphasized: '29',\n textEscaped: '30',\n textMarked: '31',\n textStrikethroughed: '32',\n unorderedList: '33',\n} as const;\n\n// In test environment, use human-readable keys for easier debugging\nif (process.env.NODE_ENV === 'test') {\n Object.keys(RuleType).forEach((key) => {\n (RuleType as any)[key] = key;\n });\n}\n\nexport type RuleTypeValue = (typeof RuleType)[keyof typeof RuleType];\n\n// ============================================================================\n// PRIORITY LEVELS\n// ============================================================================\n\n/**\n * Priority levels for rule ordering.\n */\nexport const Priority = {\n /** anything that must scan the tree before everything else */\n MAX: 0,\n /** scans for block-level constructs */\n HIGH: 1,\n /** inline w/ more priority than other inline */\n MED: 2,\n /** inline elements */\n LOW: 3,\n /** bare text and stuff that is considered leftovers */\n MIN: 4,\n} as const;\n\nexport type PriorityValue = (typeof Priority)[keyof typeof Priority];\n\n// ============================================================================\n// PERFORMANCE CONSTANTS\n// ============================================================================\n\n/** Threshold for performance logging (in milliseconds) */\nexport const DURATION_DELAY_TRIGGER = 20;\n\n// ============================================================================\n// ATTRIBUTE MAPPING\n// ============================================================================\n\n/**\n * Map of HTML attributes to their JSX prop equivalents.\n * Some renderers use camelCase for certain attributes.\n */\nexport const ATTRIBUTE_TO_NODE_PROP_MAP: Record<string, string> = [\n 'allowFullScreen',\n 'allowTransparency',\n 'autoComplete',\n 'autoFocus',\n 'autoPlay',\n 'cellPadding',\n 'cellSpacing',\n 'charSet',\n 'classId',\n 'colSpan',\n 'contentEditable',\n 'contextMenu',\n 'crossOrigin',\n 'encType',\n 'formAction',\n 'formEncType',\n 'formMethod',\n 'formNoValidate',\n 'formTarget',\n 'frameBorder',\n 'hrefLang',\n 'inputMode',\n 'keyParams',\n 'keyType',\n 'marginHeight',\n 'marginWidth',\n 'maxLength',\n 'mediaGroup',\n 'minLength',\n 'noValidate',\n 'radioGroup',\n 'readOnly',\n 'rowSpan',\n 'spellCheck',\n 'srcDoc',\n 'srcLang',\n 'srcSet',\n 'tabIndex',\n 'useMap',\n].reduce(\n (obj: Record<string, string>, x) => {\n obj[x.toLowerCase()] = x;\n return obj;\n },\n { class: 'className', for: 'htmlFor' }\n);\n\n// ============================================================================\n// NAMED CODES TO UNICODE\n// ============================================================================\n\n/**\n * Default HTML entity to unicode mappings.\n */\nexport const NAMED_CODES_TO_UNICODE: Record<string, string> = {\n amp: '\\u0026',\n apos: '\\u0027',\n gt: '\\u003e',\n lt: '\\u003c',\n nbsp: '\\u00a0',\n quot: '\\u201c',\n};\n\n// ============================================================================\n// SPECIAL ELEMENTS\n// ============================================================================\n\n/** HTML elements that should not have their content processed */\nexport const DO_NOT_PROCESS_HTML_ELEMENTS = ['style', 'script', 'pre'];\n\n/** Attributes that require URL sanitization */\nexport const ATTRIBUTES_TO_SANITIZE = [\n 'src',\n 'href',\n 'data',\n 'formAction',\n 'srcDoc',\n 'action',\n];\n\n// ============================================================================\n// REGEX PATTERNS\n// ============================================================================\n\n/** Attribute extractor regex */\nexport const ATTR_EXTRACTOR_R =\n /([-A-Z0-9_:]+)(?:\\s*=\\s*(?:(?:\"((?:\\\\.|[^\"])*)\")|(?:'((?:\\\\.|[^'])*)')|(?:\\{((?:\\\\.|{[^}]*?}|[^}])*)\\})))?/gi;\n\n/** Block end detection */\nexport const BLOCK_END_R = /\\n{2,}$/;\n\n/** Blockquote patterns */\nexport const BLOCKQUOTE_R = /^(\\s*>[\\s\\S]*?)(?=\\n\\n|$)/;\nexport const BLOCKQUOTE_TRIM_LEFT_MULTILINE_R = /^ *> ?/gm;\nexport const BLOCKQUOTE_ALERT_R = /^(?:\\[!([^\\]]*)\\]\\n)?([\\s\\S]*)/;\n\n/** Line break patterns */\nexport const BREAK_LINE_R = /^ {2,}\\n/;\nexport const BREAK_THEMATIC_R = /^(?:([-*_])( *\\1){2,}) *(?:\\n *)+\\n/;\n\n/** Code block patterns */\nexport const CODE_BLOCK_FENCED_R =\n /^(?: {1,3})?(`{3,}|~{3,}) *(\\S+)? *([^\\n]*?)?\\n([\\s\\S]*?)(?:\\1\\n?|$)/;\nexport const CODE_BLOCK_R = /^(?: {4}[^\\n]+\\n*)+(?:\\n *)+\\n?/;\n/** A single line opening or closing a fenced code block, with its indentation. */\nexport const FENCE_DELIMITER_R = /^([ \\t]*)(`{3,}|~{3,})/;\nexport const CODE_INLINE_R = /^(`+)((?:\\\\`|(?!\\1)`|[^`])+)\\1/;\n\n/** Newline patterns */\nexport const CONSECUTIVE_NEWLINE_R = /^(?:\\n *)*\\n/;\nexport const CR_NEWLINE_R = /\\r\\n?/g;\n\n/** Footnote patterns */\nexport const FOOTNOTE_R = /^\\[\\^([^\\]]+)](:(.*)((\\n+ {4,}.*)|(\\n(?!\\[\\^).+))*)/;\nexport const FOOTNOTE_REFERENCE_R = /^\\[\\^([^\\]]+)]/;\n\n/** Form feed */\nexport const FORMFEED_R = /\\f/g;\n\n/** Front matter */\nexport const FRONT_MATTER_R = /^---[ \\t]*\\n(.|\\n)*?\\n---[ \\t]*\\n/;\n\n/** GFM task */\nexport const GFM_TASK_R = /^\\s*?\\[(x|\\s)\\]/;\n\n/** Heading patterns */\nexport const HEADING_R = /^ *(#{1,6}) *([^\\n]+?)(?: +#*)?(?:\\n *)*(?:\\n|$)/;\nexport const HEADING_ATX_COMPLIANT_R =\n /^ *(#{1,6}) +([^\\n]+?)(?: +#*)?(?:\\n *)*(?:\\n|$)/;\nexport const HEADING_SETEXT_R = /^([^\\n]+)\\n *(=|-)\\2{2,} *\\n/;\n\n/** HTML patterns */\nexport const HTML_BLOCK_ELEMENT_R =\n /^ *(?!<[a-zA-Z][^ >/]* ?\\/>)<([a-zA-Z][^ >/]*) ?((?:[^>]*[^/])?)>\\n?(\\s*(?:<\\1[^>]*?>[\\s\\S]*?<\\/\\1>|(?!<\\1\\b)[\\s\\S])*?)<\\/\\1>(?!<\\/\\1>)\\n*/i;\nexport const HTML_CHAR_CODE_R =\n /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi;\nexport const HTML_COMMENT_R = /^<!--[\\s\\S]*?(?:-->)/;\nexport const HTML_CUSTOM_ATTR_R = /^(data|aria|x)-[a-z_][a-z\\d_.-]*$/;\nexport const HTML_SELF_CLOSING_ELEMENT_R =\n /^ *<([a-zA-Z][a-zA-Z0-9:]*)(?:\\s+((?:<.*?>|[^>])*))?\\/?>(?!<\\/\\1>)(\\s*\\n)?/i;\n\n/** Custom component pattern */\nexport const CUSTOM_COMPONENT_R =\n /^ *<([A-Z][a-zA-Z0-9]*)(?:\\s+((?:<.*?>|[^>])*))?>\\n?(\\s*(?:<\\1[^>]*?>[\\s\\S]*?<\\/\\1>|(?!<\\1\\b)[\\s\\S])*?)<\\/\\1>(?!<\\/\\1>)\\n*/;\n\n/** Interpolation */\nexport const INTERPOLATION_R = /^\\{.*\\}$/;\n\n/** Link patterns */\nexport const LINK_AUTOLINK_BARE_URL_R = /^(https?:\\/\\/[^\\s<]+[^<.,:;\"')\\]\\s])/;\nexport const LINK_AUTOLINK_R = /^<([^ >]+[:@/][^ >]+)>/;\nexport const CAPTURE_LETTER_AFTER_HYPHEN = /-([a-z])?/gi;\n\n/** Table patterns */\nexport const NP_TABLE_R =\n /^(\\|.*)\\n(?: *(\\|? *[-:]+ *\\|[-| :]*)\\n((?:.*\\|.*\\n)*))?\\n?/;\nexport const TABLE_TRIM_PIPES = /(^ *\\||\\| *$)/g;\nexport const TABLE_CENTER_ALIGN = /^ *:-+: *$/;\nexport const TABLE_LEFT_ALIGN = /^ *:-+ *$/;\nexport const TABLE_RIGHT_ALIGN = /^ *-+: *$/;\n\n/** Paragraph */\nexport const PARAGRAPH_R = /^[^\\n]+(?: {2}\\n|\\n{2,})/;\n\n/** Reference patterns */\nexport const REFERENCE_IMAGE_OR_LINK =\n /^\\[([^\\]]*)\\]:\\s+<?([^\\s>]+)>?\\s*(\"([^\"]*)\")?/;\nexport const REFERENCE_IMAGE_R = /^!\\[([^\\]]*)\\] ?\\[([^\\]]*)\\]/;\nexport const REFERENCE_LINK_R = /^\\[([^\\]]*)\\] ?\\[([^\\]]*)\\]/;\n\n/** Block detection */\nexport const SHOULD_RENDER_AS_BLOCK_R = /(\\n|^[-*]\\s|^#|^ {2,}|^-{2,}|^>\\s)/;\n\n/** Tab and whitespace */\nexport const TAB_R = /\\t/g;\nexport const TRIM_STARTING_NEWLINES = /^\\n+/;\nexport const HTML_LEFT_TRIM_AMOUNT_R = /^\\n*([ \\t]*)/;\n\n/** List patterns */\nexport const LIST_LOOKBEHIND_R = /(?:^|\\n)( *)$/;\nexport const ORDERED_LIST_BULLET = '(?:\\\\d+\\\\.)';\nexport const UNORDERED_LIST_BULLET = '(?:[*+-])';\n\n/** Text formatting patterns */\nexport const TEXT_ESCAPED_R = /^\\\\([^0-9A-Za-z\\s])/;\nexport const UNESCAPE_R = /\\\\([^0-9A-Za-z\\s])/g;\nexport const TEXT_PLAIN_R =\n /^[\\s\\S](?:(?! {2}\\n|[0-9]\\.|http)[^=*_~\\-\\n:<`\\\\[!])*/;\n\n/** Shortcode pattern */\nexport const SHORTCODE_R = /^(:[a-zA-Z0-9-_]+:)/;\n\n// ============================================================================\n// LIST TYPE CONSTANTS\n// ============================================================================\n\nexport type ListType = 1 | 2;\nexport const ORDERED: ListType = 1;\nexport const UNORDERED: ListType = 2;\n\n// ============================================================================\n// INLINE PATTERN HELPERS\n// ============================================================================\n\n/**\n * Ensure there's at least one more instance of the delimiter later\n * in the current sequence.\n */\nexport const LOOKAHEAD = (double: number): string =>\n `(?=[\\\\s\\\\S]+?\\\\1${double ? '\\\\1' : ''})`;\n\n/**\n * For inline formatting, this partial attempts to ignore characters that\n * may appear in nested formatting.\n */\nexport const INLINE_SKIP_R =\n '((?:\\\\[.*?\\\\][([].*?[)\\\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|\\\\\\\\[^\\\\s]|[\\\\s\\\\S])+?)';\n\n/** Bold text pattern */\nexport const TEXT_BOLD_R = new RegExp(\n `^([*_])\\\\1${LOOKAHEAD(1)}${INLINE_SKIP_R}\\\\1\\\\1(?!\\\\1)`\n);\n\n/** Emphasized text pattern */\nexport const TEXT_EMPHASIZED_R = new RegExp(\n `^([*_])${LOOKAHEAD(0)}${INLINE_SKIP_R}\\\\1(?!\\\\1)`\n);\n\n/** Marked text pattern */\nexport const TEXT_MARKED_R = new RegExp(\n `^(==)${LOOKAHEAD(0)}${INLINE_SKIP_R}\\\\1`\n);\n\n/** Strikethrough text pattern */\nexport const TEXT_STRIKETHROUGHED_R = new RegExp(\n `^(~~)${LOOKAHEAD(0)}${INLINE_SKIP_R}\\\\1`\n);\n\n// ============================================================================\n// LIST REGEX GENERATORS\n// ============================================================================\n\nexport const generateListItemPrefix = (type: ListType): string => {\n return (\n '( *)(' +\n (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) +\n ') +'\n );\n};\n\nexport const ORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(ORDERED);\nexport const UNORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(UNORDERED);\n\nexport const generateListItemPrefixRegex = (type: ListType): RegExp => {\n return new RegExp(\n '^' +\n (type === ORDERED ? ORDERED_LIST_ITEM_PREFIX : UNORDERED_LIST_ITEM_PREFIX)\n );\n};\n\nexport const ORDERED_LIST_ITEM_PREFIX_R = generateListItemPrefixRegex(ORDERED);\nexport const UNORDERED_LIST_ITEM_PREFIX_R =\n generateListItemPrefixRegex(UNORDERED);\n\nexport const generateListItemRegex = (type: ListType): RegExp => {\n return new RegExp(\n '^' +\n (type === ORDERED\n ? ORDERED_LIST_ITEM_PREFIX\n : UNORDERED_LIST_ITEM_PREFIX) +\n '[^\\\\n]*(?:\\\\n' +\n '(?!\\\\1' +\n (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) +\n ' )[^\\\\n]*)*(\\\\n|$)',\n 'gm'\n );\n};\n\nexport const ORDERED_LIST_ITEM_R = generateListItemRegex(ORDERED);\nexport const UNORDERED_LIST_ITEM_R = generateListItemRegex(UNORDERED);\n\nexport const generateListRegex = (type: ListType): RegExp => {\n const bullet = type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET;\n\n return new RegExp(\n '^( *)(' +\n bullet +\n ') ' +\n '[\\\\s\\\\S]+?(?:\\\\n{2,}(?! )' +\n '(?!\\\\1' +\n bullet +\n ' (?!' +\n bullet +\n ' ))\\\\n*' +\n '|\\\\s*\\\\n*$)'\n );\n};\n\nexport const ORDERED_LIST_R = generateListRegex(ORDERED);\nexport const UNORDERED_LIST_R = generateListRegex(UNORDERED);\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"constants.cjs","names":[],"sources":["../../../src/markdown/constants.ts"],"sourcesContent":["// ============================================================================\n// RULE TYPES\n// ============================================================================\n\n/**\n * Analogous to `node.type`. Please note that the values here may change at any time,\n * so do not hard code against the value directly.\n */\nexport const RuleType = {\n blockQuote: '0',\n breakLine: '1',\n breakThematic: '2',\n codeBlock: '3',\n codeFenced: '4',\n codeInline: '5',\n footnote: '6',\n footnoteReference: '7',\n gfmTask: '8',\n heading: '9',\n headingSetext: '10',\n /** only available if not `disableHTMLParsing` */\n htmlBlock: '11',\n htmlComment: '12',\n /** only available if not `disableHTMLParsing` */\n htmlSelfClosing: '13',\n /** Custom components like <Tabs>, <TabItem> */\n customComponent: '34',\n image: '14',\n link: '15',\n /** emits a `link` 'node', does not render directly */\n linkAngleBraceStyleDetector: '16',\n /** emits a `link` 'node', does not render directly */\n linkBareUrlDetector: '17',\n newlineCoalescer: '19',\n orderedList: '20',\n paragraph: '21',\n ref: '22',\n refImage: '23',\n refLink: '24',\n table: '25',\n tableSeparator: '26',\n text: '27',\n textBolded: '28',\n textEmphasized: '29',\n textEscaped: '30',\n textMarked: '31',\n textStrikethroughed: '32',\n unorderedList: '33',\n} as const;\n\n// In test environment, use human-readable keys for easier debugging\nif (process.env.NODE_ENV === 'test') {\n Object.keys(RuleType).forEach((key) => {\n (RuleType as any)[key] = key;\n });\n}\n\nexport type RuleTypeValue = (typeof RuleType)[keyof typeof RuleType];\n\n// ============================================================================\n// PRIORITY LEVELS\n// ============================================================================\n\n/**\n * Priority levels for rule ordering.\n */\nexport const Priority = {\n /** anything that must scan the tree before everything else */\n MAX: 0,\n /** scans for block-level constructs */\n HIGH: 1,\n /** inline w/ more priority than other inline */\n MED: 2,\n /** inline elements */\n LOW: 3,\n /** bare text and stuff that is considered leftovers */\n MIN: 4,\n} as const;\n\nexport type PriorityValue = (typeof Priority)[keyof typeof Priority];\n\n// ============================================================================\n// PERFORMANCE CONSTANTS\n// ============================================================================\n\n/** Threshold for performance logging (in milliseconds) */\nexport const DURATION_DELAY_TRIGGER = 20;\n\n// ============================================================================\n// ATTRIBUTE MAPPING\n// ============================================================================\n\n/**\n * Map of HTML attributes to their JSX prop equivalents.\n * Some renderers use camelCase for certain attributes.\n */\nexport const ATTRIBUTE_TO_NODE_PROP_MAP: Record<string, string> = [\n 'allowFullScreen',\n 'allowTransparency',\n 'autoComplete',\n 'autoFocus',\n 'autoPlay',\n 'cellPadding',\n 'cellSpacing',\n 'charSet',\n 'classId',\n 'colSpan',\n 'contentEditable',\n 'contextMenu',\n 'crossOrigin',\n 'encType',\n 'formAction',\n 'formEncType',\n 'formMethod',\n 'formNoValidate',\n 'formTarget',\n 'frameBorder',\n 'hrefLang',\n 'inputMode',\n 'keyParams',\n 'keyType',\n 'marginHeight',\n 'marginWidth',\n 'maxLength',\n 'mediaGroup',\n 'minLength',\n 'noValidate',\n 'radioGroup',\n 'readOnly',\n 'rowSpan',\n 'spellCheck',\n 'srcDoc',\n 'srcLang',\n 'srcSet',\n 'tabIndex',\n 'useMap',\n].reduce(\n (obj: Record<string, string>, x) => {\n obj[x.toLowerCase()] = x;\n return obj;\n },\n { class: 'className', for: 'htmlFor' }\n);\n\n// ============================================================================\n// NAMED CODES TO UNICODE\n// ============================================================================\n\n/**\n * Default HTML entity to unicode mappings.\n */\nexport const NAMED_CODES_TO_UNICODE: Record<string, string> = {\n amp: '\\u0026',\n apos: '\\u0027',\n gt: '\\u003e',\n lt: '\\u003c',\n nbsp: '\\u00a0',\n quot: '\\u201c',\n};\n\n// ============================================================================\n// SPECIAL ELEMENTS\n// ============================================================================\n\n/** HTML elements that should not have their content processed */\nexport const DO_NOT_PROCESS_HTML_ELEMENTS = ['style', 'script', 'pre'];\n\n/** Attributes that require URL sanitization */\nexport const ATTRIBUTES_TO_SANITIZE = [\n 'src',\n 'href',\n 'data',\n 'formAction',\n 'srcDoc',\n 'action',\n];\n\n// ============================================================================\n// REGEX PATTERNS\n// ============================================================================\n\n/** Attribute extractor regex */\nexport const ATTR_EXTRACTOR_R =\n /([-A-Z0-9_:]+)(?:\\s*=\\s*(?:(?:\"((?:\\\\.|[^\"])*)\")|(?:'((?:\\\\.|[^'])*)')|(?:\\{((?:\\\\.|{[^}]*?}|[^}])*)\\})))?/gi;\n\n/** Block end detection */\nexport const BLOCK_END_R = /\\n{2,}$/;\n\n/** Blockquote patterns */\nexport const BLOCKQUOTE_R = /^(\\s*>[\\s\\S]*?)(?=\\n\\n|$)/;\nexport const BLOCKQUOTE_TRIM_LEFT_MULTILINE_R = /^ *> ?/gm;\nexport const BLOCKQUOTE_ALERT_R = /^(?:\\[!([^\\]]*)\\]\\n)?([\\s\\S]*)/;\n\n/** Line break patterns */\nexport const BREAK_LINE_R = /^ {2,}\\n/;\nexport const BREAK_THEMATIC_R = /^(?:([-*_])( *\\1){2,}) *(?:\\n *)+\\n/;\n\n/** Code block patterns */\nexport const CODE_BLOCK_FENCED_R =\n /^(?: {1,3})?(`{3,}|~{3,}) *(\\S+)? *([^\\n]*?)?\\n([\\s\\S]*?)(?:\\1\\n?|$)/;\nexport const CODE_BLOCK_R = /^(?: {4}[^\\n]+\\n*)+(?:\\n *)+\\n?/;\n/** A single line opening or closing a fenced code block, with its indentation. */\nexport const FENCE_DELIMITER_R = /^([ \\t]*)(`{3,}|~{3,})/;\nexport const CODE_INLINE_R = /^(`+)((?:\\\\`|(?!\\1)`|[^`])+)\\1/;\n\n/** Newline patterns */\nexport const CONSECUTIVE_NEWLINE_R = /^(?:\\n *)*\\n/;\nexport const CR_NEWLINE_R = /\\r\\n?/g;\n\n/** Footnote patterns */\nexport const FOOTNOTE_R = /^\\[\\^([^\\]]+)](:(.*)((\\n+ {4,}.*)|(\\n(?!\\[\\^).+))*)/;\nexport const FOOTNOTE_REFERENCE_R = /^\\[\\^([^\\]]+)]/;\n\n/** Form feed */\nexport const FORMFEED_R = /\\f/g;\n\n/** Front matter */\nexport const FRONT_MATTER_R = /^---[ \\t]*\\n(.|\\n)*?\\n---[ \\t]*\\n/;\n\n/** GFM task */\nexport const GFM_TASK_R = /^\\s*?\\[(x|\\s)\\]/;\n\n/** Heading patterns */\nexport const HEADING_R = /^ *(#{1,6}) *([^\\n]+?)(?: +#*)?(?:\\n *)*(?:\\n|$)/;\nexport const HEADING_ATX_COMPLIANT_R =\n /^ *(#{1,6}) +([^\\n]+?)(?: +#*)?(?:\\n *)*(?:\\n|$)/;\nexport const HEADING_SETEXT_R = /^([^\\n]+)\\n *(=|-)\\2{2,} *\\n/;\n\n/** HTML patterns */\n\n/**\n * Run of characters carrying no meaning inside an opening tag: neither a quote\n * opening a value nor an angle bracket delimiting a tag.\n */\nconst TAG_PLAIN_RUN = `[^>\"'<]*`;\n\n/**\n * Quoted attribute value. It may hold an angle bracket —\n * `<Tab label='Intlayer >=9.4'>` — but not a line break, which keeps a tag that\n * turns out not to match from trying every later quote of the document as its\n * closing one.\n */\nconst TAG_QUOTED_VALUE = `\"[^\"\\\\n]*\"|'[^'\\\\n]*'`;\n\n/**\n * Attribute list of an opening tag, written as a plain run followed by\n * quote-or-bracket-led segments so that each character has a single way to be\n * read. A lone quote is allowed last so a tag holding an unbalanced one still\n * parses, as it did before quoted values were recognised.\n */\nconst TAG_ATTRIBUTES = `${TAG_PLAIN_RUN}(?:(?:${TAG_QUOTED_VALUE}|<.*?>|[\"'])${TAG_PLAIN_RUN})*`;\n\n/** Rejects the opening tag of a self-closing element, `<div class=\"a\"/>`. */\nconst NOT_SELF_CLOSING = `(?![^>]*/>)`;\n\n/**\n * Opening tag of a nested element bearing the same name as the outer one. This\n * one stays a plain scan up to the first `>`: it is tried at every character of\n * the element's content, and a richer pattern here costs an order of magnitude\n * on documents whose tag never closes.\n */\nconst NESTED_SAME_TAG_OPENING = `<\\\\1[^>]*?>`;\n\nexport const HTML_BLOCK_ELEMENT_R = new RegExp(\n `^ *(?!<[a-zA-Z][^ >/]* ?/>)<([a-zA-Z][^ >/]*) ?(${NOT_SELF_CLOSING}${TAG_ATTRIBUTES})>\\\\n?(\\\\s*(?:${NESTED_SAME_TAG_OPENING}[\\\\s\\\\S]*?</\\\\1>|(?!<\\\\1\\\\b)[\\\\s\\\\S])*?)</\\\\1>(?!</\\\\1>)\\\\n*`,\n 'i'\n);\nexport const HTML_CHAR_CODE_R =\n /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi;\nexport const HTML_COMMENT_R = /^<!--[\\s\\S]*?(?:-->)/;\nexport const HTML_CUSTOM_ATTR_R = /^(data|aria|x)-[a-z_][a-z\\d_.-]*$/;\nexport const HTML_SELF_CLOSING_ELEMENT_R = new RegExp(\n `^ *<([a-zA-Z][a-zA-Z0-9:]*)(?:\\\\s+(${TAG_ATTRIBUTES}))?/?>(?!</\\\\1>)(\\\\s*\\\\n)?`,\n 'i'\n);\n\n/** Custom component pattern */\nexport const CUSTOM_COMPONENT_R = new RegExp(\n `^ *<([A-Z][a-zA-Z0-9]*)(?:\\\\s+(${TAG_ATTRIBUTES}))?>\\\\n?(\\\\s*(?:${NESTED_SAME_TAG_OPENING}[\\\\s\\\\S]*?</\\\\1>|(?!<\\\\1\\\\b)[\\\\s\\\\S])*?)</\\\\1>(?!</\\\\1>)\\\\n*`\n);\n\n/** Interpolation */\nexport const INTERPOLATION_R = /^\\{.*\\}$/;\n\n/** Link patterns */\nexport const LINK_AUTOLINK_BARE_URL_R = /^(https?:\\/\\/[^\\s<]+[^<.,:;\"')\\]\\s])/;\nexport const LINK_AUTOLINK_R = /^<([^ >]+[:@/][^ >]+)>/;\nexport const CAPTURE_LETTER_AFTER_HYPHEN = /-([a-z])?/gi;\n\n/** Table patterns */\nexport const NP_TABLE_R =\n /^(\\|.*)\\n(?: *(\\|? *[-:]+ *\\|[-| :]*)\\n((?:.*\\|.*\\n)*))?\\n?/;\nexport const TABLE_TRIM_PIPES = /(^ *\\||\\| *$)/g;\nexport const TABLE_CENTER_ALIGN = /^ *:-+: *$/;\nexport const TABLE_LEFT_ALIGN = /^ *:-+ *$/;\nexport const TABLE_RIGHT_ALIGN = /^ *-+: *$/;\n\n/** Paragraph */\nexport const PARAGRAPH_R = /^[^\\n]+(?: {2}\\n|\\n{2,})/;\n\n/** Reference patterns */\nexport const REFERENCE_IMAGE_OR_LINK =\n /^\\[([^\\]]*)\\]:\\s+<?([^\\s>]+)>?\\s*(\"([^\"]*)\")?/;\nexport const REFERENCE_IMAGE_R = /^!\\[([^\\]]*)\\] ?\\[([^\\]]*)\\]/;\nexport const REFERENCE_LINK_R = /^\\[([^\\]]*)\\] ?\\[([^\\]]*)\\]/;\n\n/** Block detection */\nexport const SHOULD_RENDER_AS_BLOCK_R = /(\\n|^[-*]\\s|^#|^ {2,}|^-{2,}|^>\\s)/;\n\n/** Tab and whitespace */\nexport const TAB_R = /\\t/g;\nexport const TRIM_STARTING_NEWLINES = /^\\n+/;\nexport const HTML_LEFT_TRIM_AMOUNT_R = /^\\n*([ \\t]*)/;\n\n/** List patterns */\nexport const LIST_LOOKBEHIND_R = /(?:^|\\n)( *)$/;\nexport const ORDERED_LIST_BULLET = '(?:\\\\d+\\\\.)';\nexport const UNORDERED_LIST_BULLET = '(?:[*+-])';\n\n/** Text formatting patterns */\nexport const TEXT_ESCAPED_R = /^\\\\([^0-9A-Za-z\\s])/;\nexport const UNESCAPE_R = /\\\\([^0-9A-Za-z\\s])/g;\nexport const TEXT_PLAIN_R =\n /^[\\s\\S](?:(?! {2}\\n|[0-9]\\.|http)[^=*_~\\-\\n:<`\\\\[!])*/;\n\n/** Shortcode pattern */\nexport const SHORTCODE_R = /^(:[a-zA-Z0-9-_]+:)/;\n\n// ============================================================================\n// LIST TYPE CONSTANTS\n// ============================================================================\n\nexport type ListType = 1 | 2;\nexport const ORDERED: ListType = 1;\nexport const UNORDERED: ListType = 2;\n\n// ============================================================================\n// INLINE PATTERN HELPERS\n// ============================================================================\n\n/**\n * Ensure there's at least one more instance of the delimiter later\n * in the current sequence.\n */\nexport const LOOKAHEAD = (double: number): string =>\n `(?=[\\\\s\\\\S]+?\\\\1${double ? '\\\\1' : ''})`;\n\n/**\n * For inline formatting, this partial attempts to ignore characters that\n * may appear in nested formatting.\n */\nexport const INLINE_SKIP_R =\n '((?:\\\\[.*?\\\\][([].*?[)\\\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|\\\\\\\\[^\\\\s]|[\\\\s\\\\S])+?)';\n\n/** Bold text pattern */\nexport const TEXT_BOLD_R = new RegExp(\n `^([*_])\\\\1${LOOKAHEAD(1)}${INLINE_SKIP_R}\\\\1\\\\1(?!\\\\1)`\n);\n\n/** Emphasized text pattern */\nexport const TEXT_EMPHASIZED_R = new RegExp(\n `^([*_])${LOOKAHEAD(0)}${INLINE_SKIP_R}\\\\1(?!\\\\1)`\n);\n\n/** Marked text pattern */\nexport const TEXT_MARKED_R = new RegExp(\n `^(==)${LOOKAHEAD(0)}${INLINE_SKIP_R}\\\\1`\n);\n\n/** Strikethrough text pattern */\nexport const TEXT_STRIKETHROUGHED_R = new RegExp(\n `^(~~)${LOOKAHEAD(0)}${INLINE_SKIP_R}\\\\1`\n);\n\n// ============================================================================\n// LIST REGEX GENERATORS\n// ============================================================================\n\nexport const generateListItemPrefix = (type: ListType): string => {\n return (\n '( *)(' +\n (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) +\n ') +'\n );\n};\n\nexport const ORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(ORDERED);\nexport const UNORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(UNORDERED);\n\nexport const generateListItemPrefixRegex = (type: ListType): RegExp => {\n return new RegExp(\n '^' +\n (type === ORDERED ? ORDERED_LIST_ITEM_PREFIX : UNORDERED_LIST_ITEM_PREFIX)\n );\n};\n\nexport const ORDERED_LIST_ITEM_PREFIX_R = generateListItemPrefixRegex(ORDERED);\nexport const UNORDERED_LIST_ITEM_PREFIX_R =\n generateListItemPrefixRegex(UNORDERED);\n\nexport const generateListItemRegex = (type: ListType): RegExp => {\n return new RegExp(\n '^' +\n (type === ORDERED\n ? ORDERED_LIST_ITEM_PREFIX\n : UNORDERED_LIST_ITEM_PREFIX) +\n '[^\\\\n]*(?:\\\\n' +\n '(?!\\\\1' +\n (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) +\n ' )[^\\\\n]*)*(\\\\n|$)',\n 'gm'\n );\n};\n\nexport const ORDERED_LIST_ITEM_R = generateListItemRegex(ORDERED);\nexport const UNORDERED_LIST_ITEM_R = generateListItemRegex(UNORDERED);\n\nexport const generateListRegex = (type: ListType): RegExp => {\n const bullet = type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET;\n\n return new RegExp(\n '^( *)(' +\n bullet +\n ') ' +\n '[\\\\s\\\\S]+?(?:\\\\n{2,}(?! )' +\n '(?!\\\\1' +\n bullet +\n ' (?!' +\n bullet +\n ' ))\\\\n*' +\n '|\\\\s*\\\\n*$)'\n );\n};\n\nexport const ORDERED_LIST_R = generateListRegex(ORDERED);\nexport const UNORDERED_LIST_R = generateListRegex(UNORDERED);\n"],"mappings":"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"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { COMPOSITE_ID_SEPARATOR, DEFAULT_VARIANT_ID, getDictionarySelectorCacheKey, isQualifiedDictionaryGroup, parseDictionarySelector, reconstructQualifiedEntry, resolveDictionaryArgument, resolveEffectiveVariantId, resolveProviderVariant, resolveQualifiedDictionary, serializeVariant, serializeVariantChain } from "./qualifiedDictionary.mjs";
|
|
2
|
+
import { PRELOADED_DYNAMIC_KEY, getPreloadedDictionary } from "./preloadedDynamicLoader.mjs";
|
|
3
|
+
import { QUALIFIER_DYNAMIC_TYPES_KEY, isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync } from "./qualifiedDynamicLoader.mjs";
|
|
4
|
+
import { findPlainDynamicLoader, resolvePlainDynamicLoader } from "./plainDynamicLoader.mjs";
|
|
2
5
|
import { editDictionaryByKeyPath } from "./editDictionaryByKeyPath.mjs";
|
|
3
6
|
import { getContentNodeByKeyPath } from "./getContentNodeByKeyPath.mjs";
|
|
4
7
|
import { getDefaultNode } from "./getDefaultNode.mjs";
|
|
@@ -11,10 +14,8 @@ import { QUALIFIER_ORDER, getDictionaryCompositeIds, getDictionaryQualifierIds,
|
|
|
11
14
|
import { mergeQualifiedDictionaries } from "./mergeQualifiedDictionaries.mjs";
|
|
12
15
|
import { orderDictionaries } from "./orderDictionaries.mjs";
|
|
13
16
|
import { normalizeDictionaries, normalizeDictionary } from "./normalizeDictionary.mjs";
|
|
14
|
-
import { PRELOADED_DYNAMIC_KEY, getPreloadedDictionary } from "./preloadedDynamicLoader.mjs";
|
|
15
|
-
import { QUALIFIER_DYNAMIC_TYPES_KEY, isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync } from "./qualifiedDynamicLoader.mjs";
|
|
16
17
|
import { removeContentNodeByKeyPath } from "./removeContentNodeByKeyPath.mjs";
|
|
17
18
|
import { renameContentNodeByKeyPath } from "./renameContentNodeByKeyPath.mjs";
|
|
18
19
|
import { updateNodeChildren } from "./updateNodeChildren.mjs";
|
|
19
20
|
|
|
20
|
-
export { COMPOSITE_ID_SEPARATOR, DEFAULT_VARIANT_ID, PRELOADED_DYNAMIC_KEY, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, editDictionaryByKeyPath, getContentNodeByKeyPath, getDefaultNode, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getEmptyNode, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNodeChildren, getNodeType, getPreloadedDictionary, getVariantIds, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, mergeDictionaries, mergeQualifiedDictionaries, normalizeDictionaries, normalizeDictionary, orderDictionaries, parseDictionarySelector, reconstructQualifiedEntry, removeContentNodeByKeyPath, renameContentNodeByKeyPath, resolveDictionaryArgument, resolveEffectiveVariantId, resolveProviderVariant, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, serializeVariant, serializeVariantChain, updateNodeChildren };
|
|
21
|
+
export { COMPOSITE_ID_SEPARATOR, DEFAULT_VARIANT_ID, PRELOADED_DYNAMIC_KEY, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, editDictionaryByKeyPath, findPlainDynamicLoader, getContentNodeByKeyPath, getDefaultNode, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getEmptyNode, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNodeChildren, getNodeType, getPreloadedDictionary, getVariantIds, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, mergeDictionaries, mergeQualifiedDictionaries, normalizeDictionaries, normalizeDictionary, orderDictionaries, parseDictionarySelector, reconstructQualifiedEntry, removeContentNodeByKeyPath, renameContentNodeByKeyPath, resolveDictionaryArgument, resolveEffectiveVariantId, resolvePlainDynamicLoader, resolveProviderVariant, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, serializeVariant, serializeVariantChain, updateNodeChildren };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getEditedContent, getEditedDictionary } from "./deepTransformPlugins/getEditedContent.mjs";
|
|
2
|
+
import { getDictionaryTransformCacheKey, getPluginsCacheKey, readTransformCache, writeTransformCache } from "./interpreter/dictionaryTransformCache.mjs";
|
|
2
3
|
import { getCondition } from "./interpreter/getCondition.mjs";
|
|
3
4
|
import { deepTransformNode } from "./interpreter/getContent/deepTransform.mjs";
|
|
4
5
|
import { findMatchingCondition, getEnumeration } from "./interpreter/getEnumeration.mjs";
|
|
@@ -23,7 +24,12 @@ import { getTranslation } from "./interpreter/getTranslation.mjs";
|
|
|
23
24
|
import { getInterpolableContent, isInterpolableWrapperNode, rebuildInterpolableContent, transformInterpolableNode } from "./interpreter/interpolableNode.mjs";
|
|
24
25
|
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./interpreter/getContent/plugins.mjs";
|
|
25
26
|
import { getBasePlugins, getContent } from "./interpreter/getContent/getContent.mjs";
|
|
27
|
+
import { PRELOADED_DYNAMIC_KEY, getPreloadedDictionary } from "./dictionaryManipulator/preloadedDynamicLoader.mjs";
|
|
28
|
+
import { QUALIFIER_DYNAMIC_TYPES_KEY, isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync } from "./dictionaryManipulator/qualifiedDynamicLoader.mjs";
|
|
29
|
+
import { findPlainDynamicLoader, resolvePlainDynamicLoader } from "./dictionaryManipulator/plainDynamicLoader.mjs";
|
|
30
|
+
import { getDictionaryAsync } from "./interpreter/getDictionaryAsync.mjs";
|
|
26
31
|
import { getHTML } from "./interpreter/getHTML.mjs";
|
|
32
|
+
import { getIntlayerAsync } from "./interpreter/getIntlayerAsync.mjs";
|
|
27
33
|
import { splitInsertionTemplate } from "./interpreter/splitAndJoinInsertion.mjs";
|
|
28
34
|
import { getFilteredLocalesContent, getFilteredLocalesDictionary } from "./deepTransformPlugins/getFilteredLocalesContent.mjs";
|
|
29
35
|
import { cond as condition } from "./transpiler/condition/condition.mjs";
|
|
@@ -64,8 +70,6 @@ import { QUALIFIER_ORDER, getDictionaryCompositeIds, getDictionaryQualifierIds,
|
|
|
64
70
|
import { mergeQualifiedDictionaries } from "./dictionaryManipulator/mergeQualifiedDictionaries.mjs";
|
|
65
71
|
import { orderDictionaries } from "./dictionaryManipulator/orderDictionaries.mjs";
|
|
66
72
|
import { normalizeDictionaries, normalizeDictionary } from "./dictionaryManipulator/normalizeDictionary.mjs";
|
|
67
|
-
import { PRELOADED_DYNAMIC_KEY, getPreloadedDictionary } from "./dictionaryManipulator/preloadedDynamicLoader.mjs";
|
|
68
|
-
import { QUALIFIER_DYNAMIC_TYPES_KEY, isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync } from "./dictionaryManipulator/qualifiedDynamicLoader.mjs";
|
|
69
73
|
import { removeContentNodeByKeyPath } from "./dictionaryManipulator/removeContentNodeByKeyPath.mjs";
|
|
70
74
|
import { renameContentNodeByKeyPath } from "./dictionaryManipulator/renameContentNodeByKeyPath.mjs";
|
|
71
75
|
import { updateNodeChildren } from "./dictionaryManipulator/updateNodeChildren.mjs";
|
|
@@ -107,4 +111,4 @@ import { interpolateMessage, parseTaggedMessage, resolveMessage, resolveMessageN
|
|
|
107
111
|
import { isSameKeyPath } from "./utils/isSameKeyPath.mjs";
|
|
108
112
|
import { stringifyYaml } from "./utils/stringifyYaml.mjs";
|
|
109
113
|
|
|
110
|
-
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, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, 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_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_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, RuleType, 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_PLAIN_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, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getPreloadLocale, getPreloadedDictionary, getReplacedValuesContent, getRewritePath, getRewriteRules, 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, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveBrowserLocale, resolveDictionaryArgument, resolveEffectiveVariantId, resolveLocalizedPath, resolveMessage, resolveMessageNode, 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 };
|
|
114
|
+
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, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, 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_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_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, RuleType, 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_PLAIN_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, 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, 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, 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, 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 };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//#region src/interpreter/dictionaryTransformCache.ts
|
|
2
|
+
/**
|
|
3
|
+
* Stable identity per plugin array, so a cache key can tell two custom plugin
|
|
4
|
+
* sets apart.
|
|
5
|
+
*
|
|
6
|
+
* A boolean `custom / default` discriminator is not enough: two callers passing
|
|
7
|
+
* *different* plugin arrays for the same dictionary and locale would collide,
|
|
8
|
+
* and the second one would be served the first one's transformed content.
|
|
9
|
+
*
|
|
10
|
+
* Every framework package memoizes `getPlugins(locale)` per locale, so the same
|
|
11
|
+
* locale always hands over the same array reference and reuses its identity —
|
|
12
|
+
* an array built fresh on every call only ever costs a cache miss, never a
|
|
13
|
+
* wrong hit.
|
|
14
|
+
*/
|
|
15
|
+
const pluginsIdentities = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
let nextPluginsIdentity = 0;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the cache-key fragment identifying a plugin array.
|
|
19
|
+
*
|
|
20
|
+
* @param plugins - The plugin array a transform runs with, or `undefined` when
|
|
21
|
+
* the interpreter's base plugins are used.
|
|
22
|
+
*/
|
|
23
|
+
const getPluginsCacheKey = (plugins) => {
|
|
24
|
+
if (!plugins) return "base";
|
|
25
|
+
const existingIdentity = pluginsIdentities.get(plugins);
|
|
26
|
+
if (existingIdentity) return existingIdentity;
|
|
27
|
+
nextPluginsIdentity += 1;
|
|
28
|
+
const identity = `p${nextPluginsIdentity}`;
|
|
29
|
+
pluginsIdentities.set(plugins, identity);
|
|
30
|
+
return identity;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Upper bound of transformed entries kept per dictionary. A dictionary is
|
|
34
|
+
* transformed once per `locale × selector × plugin set`, so the realistic count
|
|
35
|
+
* stays in the tens; the cap only guards pathological selector fan-out (a
|
|
36
|
+
* collection read by hundreds of item ids). Reaching it drops the dictionary's
|
|
37
|
+
* entries rather than evicting one by one — the next reads simply re-transform.
|
|
38
|
+
*/
|
|
39
|
+
const MAX_ENTRIES_PER_DICTIONARY = 256;
|
|
40
|
+
/**
|
|
41
|
+
* Transformed content, keyed first by the dictionary object it came from, then
|
|
42
|
+
* by `locale × selector × plugin set`.
|
|
43
|
+
*
|
|
44
|
+
* Keying on the object rather than on the dictionary key is what makes this
|
|
45
|
+
* safe for the paths the build optimization produces: `useDictionary` and
|
|
46
|
+
* `useDictionaryDynamic` receive the dictionary itself, never its key, and a
|
|
47
|
+
* dictionary replaced at runtime — a hot reload, a freshly loaded locale chunk
|
|
48
|
+
* — is a new object, so it can never be served stale content. Being weak also
|
|
49
|
+
* means a dictionary that goes out of scope takes its entries with it.
|
|
50
|
+
*/
|
|
51
|
+
const transformCache = /* @__PURE__ */ new WeakMap();
|
|
52
|
+
/**
|
|
53
|
+
* Whether a value is a settled dictionary worth memoizing.
|
|
54
|
+
*
|
|
55
|
+
* Two kinds of argument are deliberately excluded, and both are callable:
|
|
56
|
+
* - a callable stand-in proxy — `solid-intlayer`'s `useLoadDynamic` hands
|
|
57
|
+
* `getDictionary` a placeholder that reads a Solid resource on every property
|
|
58
|
+
* access, so its content changes the moment the chunk lands. Memoizing it
|
|
59
|
+
* would freeze the pending, empty state for the rest of the session.
|
|
60
|
+
* - anything a non-typed caller passes that a `WeakMap` cannot hold as a key,
|
|
61
|
+
* which would otherwise throw instead of simply running uncached.
|
|
62
|
+
*/
|
|
63
|
+
const isMemoizableDictionary = (value) => value !== null && typeof value === "object";
|
|
64
|
+
/**
|
|
65
|
+
* Builds the cache key for one transformed entry.
|
|
66
|
+
*
|
|
67
|
+
* @param locale - The resolved locale, already defaulted by the caller.
|
|
68
|
+
* @param selectorCacheKey - Serialized selector, empty for a plain dictionary.
|
|
69
|
+
* @param plugins - The plugin array the transform runs with.
|
|
70
|
+
*/
|
|
71
|
+
const getDictionaryTransformCacheKey = (locale, selectorCacheKey, plugins) => `${locale}_${selectorCacheKey}_${getPluginsCacheKey(plugins)}`;
|
|
72
|
+
/**
|
|
73
|
+
* Looks up the transformed content cached for `dictionary` under `cacheKey`.
|
|
74
|
+
*
|
|
75
|
+
* The hit is reported through a discriminated result rather than through the
|
|
76
|
+
* value: `null` is a legitimate cached content — an unresolvable qualified
|
|
77
|
+
* coordinate — so a miss can never be inferred from the value alone.
|
|
78
|
+
*/
|
|
79
|
+
const readTransformCache = (dictionary, cacheKey) => {
|
|
80
|
+
if (!isMemoizableDictionary(dictionary)) return { hit: false };
|
|
81
|
+
const entries = transformCache.get(dictionary);
|
|
82
|
+
if (!entries?.has(cacheKey)) return { hit: false };
|
|
83
|
+
return {
|
|
84
|
+
hit: true,
|
|
85
|
+
content: entries.get(cacheKey)
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Stores transformed content for `dictionary` under `cacheKey`.
|
|
90
|
+
*
|
|
91
|
+
* @returns The stored content, so callers can `return writeTransformCache(...)`.
|
|
92
|
+
*/
|
|
93
|
+
const writeTransformCache = (dictionary, cacheKey, content) => {
|
|
94
|
+
if (!isMemoizableDictionary(dictionary)) return content;
|
|
95
|
+
let entries = transformCache.get(dictionary);
|
|
96
|
+
if (!entries) {
|
|
97
|
+
entries = /* @__PURE__ */ new Map();
|
|
98
|
+
transformCache.set(dictionary, entries);
|
|
99
|
+
}
|
|
100
|
+
if (entries.size >= MAX_ENTRIES_PER_DICTIONARY) entries.clear();
|
|
101
|
+
entries.set(cacheKey, content);
|
|
102
|
+
return content;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { getDictionaryTransformCacheKey, getPluginsCacheKey, readTransformCache, writeTransformCache };
|
|
107
|
+
//# sourceMappingURL=dictionaryTransformCache.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionaryTransformCache.mjs","names":[],"sources":["../../../src/interpreter/dictionaryTransformCache.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { Plugins } from './getContent';\n\n/**\n * Stable identity per plugin array, so a cache key can tell two custom plugin\n * sets apart.\n *\n * A boolean `custom / default` discriminator is not enough: two callers passing\n * *different* plugin arrays for the same dictionary and locale would collide,\n * and the second one would be served the first one's transformed content.\n *\n * Every framework package memoizes `getPlugins(locale)` per locale, so the same\n * locale always hands over the same array reference and reuses its identity —\n * an array built fresh on every call only ever costs a cache miss, never a\n * wrong hit.\n */\nconst pluginsIdentities = new WeakMap<Plugins[], string>();\n\nlet nextPluginsIdentity = 0;\n\n/**\n * Returns the cache-key fragment identifying a plugin array.\n *\n * @param plugins - The plugin array a transform runs with, or `undefined` when\n * the interpreter's base plugins are used.\n */\nexport const getPluginsCacheKey = (plugins?: Plugins[]): string => {\n if (!plugins) return 'base';\n\n const existingIdentity = pluginsIdentities.get(plugins);\n if (existingIdentity) return existingIdentity;\n\n nextPluginsIdentity += 1;\n const identity = `p${nextPluginsIdentity}`;\n pluginsIdentities.set(plugins, identity);\n\n return identity;\n};\n\n/**\n * Upper bound of transformed entries kept per dictionary. A dictionary is\n * transformed once per `locale × selector × plugin set`, so the realistic count\n * stays in the tens; the cap only guards pathological selector fan-out (a\n * collection read by hundreds of item ids). Reaching it drops the dictionary's\n * entries rather than evicting one by one — the next reads simply re-transform.\n */\nconst MAX_ENTRIES_PER_DICTIONARY = 256;\n\n/**\n * Transformed content, keyed first by the dictionary object it came from, then\n * by `locale × selector × plugin set`.\n *\n * Keying on the object rather than on the dictionary key is what makes this\n * safe for the paths the build optimization produces: `useDictionary` and\n * `useDictionaryDynamic` receive the dictionary itself, never its key, and a\n * dictionary replaced at runtime — a hot reload, a freshly loaded locale chunk\n * — is a new object, so it can never be served stale content. Being weak also\n * means a dictionary that goes out of scope takes its entries with it.\n */\nconst transformCache = new WeakMap<object, Map<string, unknown>>();\n\n/**\n * Whether a value is a settled dictionary worth memoizing.\n *\n * Two kinds of argument are deliberately excluded, and both are callable:\n * - a callable stand-in proxy — `solid-intlayer`'s `useLoadDynamic` hands\n * `getDictionary` a placeholder that reads a Solid resource on every property\n * access, so its content changes the moment the chunk lands. Memoizing it\n * would freeze the pending, empty state for the rest of the session.\n * - anything a non-typed caller passes that a `WeakMap` cannot hold as a key,\n * which would otherwise throw instead of simply running uncached.\n */\nconst isMemoizableDictionary = (value: unknown): value is object =>\n value !== null && typeof value === 'object';\n\n/**\n * Builds the cache key for one transformed entry.\n *\n * @param locale - The resolved locale, already defaulted by the caller.\n * @param selectorCacheKey - Serialized selector, empty for a plain dictionary.\n * @param plugins - The plugin array the transform runs with.\n */\nexport const getDictionaryTransformCacheKey = (\n locale: LocalesValues,\n selectorCacheKey: string,\n plugins?: Plugins[]\n): string => `${locale}_${selectorCacheKey}_${getPluginsCacheKey(plugins)}`;\n\n/**\n * Looks up the transformed content cached for `dictionary` under `cacheKey`.\n *\n * The hit is reported through a discriminated result rather than through the\n * value: `null` is a legitimate cached content — an unresolvable qualified\n * coordinate — so a miss can never be inferred from the value alone.\n */\nexport const readTransformCache = <Content>(\n dictionary: Dictionary | object,\n cacheKey: string\n): { hit: true; content: Content } | { hit: false } => {\n if (!isMemoizableDictionary(dictionary)) return { hit: false };\n\n const entries = transformCache.get(dictionary);\n\n if (!entries?.has(cacheKey)) return { hit: false };\n\n return { hit: true, content: entries.get(cacheKey) as Content };\n};\n\n/**\n * Stores transformed content for `dictionary` under `cacheKey`.\n *\n * @returns The stored content, so callers can `return writeTransformCache(...)`.\n */\nexport const writeTransformCache = <Content>(\n dictionary: Dictionary | object,\n cacheKey: string,\n content: Content\n): Content => {\n if (!isMemoizableDictionary(dictionary)) return content;\n\n let entries = transformCache.get(dictionary);\n\n if (!entries) {\n entries = new Map<string, unknown>();\n transformCache.set(dictionary, entries);\n }\n\n if (entries.size >= MAX_ENTRIES_PER_DICTIONARY) entries.clear();\n\n entries.set(cacheKey, content);\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,oCAAoB,IAAI,QAA2B;AAEzD,IAAI,sBAAsB;;;;;;;AAQ1B,MAAa,sBAAsB,YAAgC;CACjE,IAAI,CAAC,SAAS,OAAO;CAErB,MAAM,mBAAmB,kBAAkB,IAAI,OAAO;CACtD,IAAI,kBAAkB,OAAO;CAE7B,uBAAuB;CACvB,MAAM,WAAW,IAAI;CACrB,kBAAkB,IAAI,SAAS,QAAQ;CAEvC,OAAO;AACT;;;;;;;;AASA,MAAM,6BAA6B;;;;;;;;;;;;AAanC,MAAM,iCAAiB,IAAI,QAAsC;;;;;;;;;;;;AAajE,MAAM,0BAA0B,UAC9B,UAAU,QAAQ,OAAO,UAAU;;;;;;;;AASrC,MAAa,kCACX,QACA,kBACA,YACW,GAAG,OAAO,GAAG,iBAAiB,GAAG,mBAAmB,OAAO;;;;;;;;AASxE,MAAa,sBACX,YACA,aACqD;CACrD,IAAI,CAAC,uBAAuB,UAAU,GAAG,OAAO,EAAE,KAAK,MAAM;CAE7D,MAAM,UAAU,eAAe,IAAI,UAAU;CAE7C,IAAI,CAAC,SAAS,IAAI,QAAQ,GAAG,OAAO,EAAE,KAAK,MAAM;CAEjD,OAAO;EAAE,KAAK;EAAM,SAAS,QAAQ,IAAI,QAAQ;CAAa;AAChE;;;;;;AAOA,MAAa,uBACX,YACA,UACA,YACY;CACZ,IAAI,CAAC,uBAAuB,UAAU,GAAG,OAAO;CAEhD,IAAI,UAAU,eAAe,IAAI,UAAU;CAE3C,IAAI,CAAC,SAAS;EACZ,0BAAU,IAAI,IAAqB;EACnC,eAAe,IAAI,YAAY,OAAO;CACxC;CAEA,IAAI,QAAQ,QAAQ,4BAA4B,QAAQ,MAAM;CAE9D,QAAQ,IAAI,UAAU,OAAO;CAE7B,OAAO;AACT"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDictionaryTransformCacheKey, readTransformCache, writeTransformCache } from "./dictionaryTransformCache.mjs";
|
|
2
|
+
import { getDictionarySelectorCacheKey, parseDictionarySelector, resolveQualifiedDictionary } from "../dictionaryManipulator/qualifiedDictionary.mjs";
|
|
2
3
|
import { getBasePlugins, getContent } from "./getContent/getContent.mjs";
|
|
4
|
+
import { internationalization } from "@intlayer/config/built";
|
|
3
5
|
|
|
4
6
|
//#region src/interpreter/getDictionary.ts
|
|
5
7
|
/**
|
|
6
8
|
* Transforms a dictionary in a single pass, applying each plugin as needed.
|
|
7
9
|
*
|
|
8
|
-
* Also accepts a `QualifiedDictionaryGroup` (collections, variants) together
|
|
9
|
-
* with a selector as second argument — the group is resolved to a single entry
|
|
10
|
-
* (or an ordered array of entries for collections without an `item` selector)
|
|
11
|
-
* before transformation.
|
|
12
|
-
*
|
|
13
10
|
* @param dictionary The dictionary (or qualified dictionary group) to transform.
|
|
14
11
|
* @param localeOrSelector The locale, or a selector object (`{ item }`,
|
|
15
12
|
* `{ variant }`, optionally with `locale`).
|
|
@@ -18,6 +15,9 @@ import { getBasePlugins, getContent } from "./getContent/getContent.mjs";
|
|
|
18
15
|
*/
|
|
19
16
|
const getDictionary = (dictionary, localeOrSelector, plugins) => {
|
|
20
17
|
const { locale, selector } = parseDictionarySelector(localeOrSelector);
|
|
18
|
+
const cacheKey = getDictionaryTransformCacheKey(locale ?? internationalization.defaultLocale, getDictionarySelectorCacheKey(selector), plugins);
|
|
19
|
+
const cached = readTransformCache(dictionary, cacheKey);
|
|
20
|
+
if (cached.hit) return cached.content;
|
|
21
21
|
const appliedPlugins = plugins ?? getBasePlugins(locale);
|
|
22
22
|
const resolved = resolveQualifiedDictionary(dictionary, selector);
|
|
23
23
|
const transformDictionary = (resolvedDictionary) => {
|
|
@@ -30,9 +30,9 @@ const getDictionary = (dictionary, localeOrSelector, plugins) => {
|
|
|
30
30
|
};
|
|
31
31
|
return getContent(resolvedDictionary.content, props, appliedPlugins);
|
|
32
32
|
};
|
|
33
|
-
if (resolved === null) return null;
|
|
34
|
-
if (Array.isArray(resolved)) return resolved.map(transformDictionary);
|
|
35
|
-
return transformDictionary(resolved);
|
|
33
|
+
if (resolved === null) return writeTransformCache(dictionary, cacheKey, null);
|
|
34
|
+
if (Array.isArray(resolved)) return writeTransformCache(dictionary, cacheKey, resolved.map(transformDictionary));
|
|
35
|
+
return writeTransformCache(dictionary, cacheKey, transformDictionary(resolved));
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.mjs","names":[],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n parseDictionarySelector,\n resolveQualifiedDictionary,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n Plugins,\n} from './getContent';\nimport { getBasePlugins, getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n *
|
|
1
|
+
{"version":3,"file":"getDictionary.mjs","names":[],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n Dictionary,\n DictionarySelector,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n resolveQualifiedDictionary,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport {\n getDictionaryTransformCacheKey,\n readTransformCache,\n writeTransformCache,\n} from './dictionaryTransformCache';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n Plugins,\n} from './getContent';\nimport { getBasePlugins, getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n * @param dictionary The dictionary (or qualified dictionary group) to transform.\n * @param localeOrSelector The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins An array of NodeTransformer that define how to transform recognized nodes.\n * If omitted, we’ll use a default set of plugins.\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const { locale, selector } = parseDictionarySelector(localeOrSelector);\n\n // The base plugins are rebuilt on every call, so they cannot identify\n // themselves — but they are fully determined by the locale, which the key\n // already carries. Only an explicitly passed array needs its own identity.\n const cacheKey = getDictionaryTransformCacheKey(\n locale ?? internationalization.defaultLocale,\n getDictionarySelectorCacheKey(selector),\n plugins\n );\n\n const cached = readTransformCache<any>(dictionary, cacheKey);\n if (cached.hit) return cached.content;\n\n const appliedPlugins = plugins ?? getBasePlugins(locale);\n\n const resolved = resolveQualifiedDictionary(dictionary, selector);\n\n const transformDictionary = (resolvedDictionary: Dictionary) => {\n const props: NodeProps = {\n dictionaryKey: resolvedDictionary.key,\n dictionaryPath: resolvedDictionary.filePath,\n keyPath: [],\n plugins: appliedPlugins,\n // Attached by the build optimization so `nest()` resolves without the\n // global registry. Undefined in unoptimized builds, where the\n // registry-based resolver is used instead.\n nestedDictionaries: resolvedDictionary.nestedDictionaries,\n };\n\n return getContent(resolvedDictionary.content, props, appliedPlugins);\n };\n\n if (resolved === null) return writeTransformCache(dictionary, cacheKey, null);\n\n if (Array.isArray(resolved)) {\n return writeTransformCache(\n dictionary,\n cacheKey,\n resolved.map(transformDictionary)\n ) as any;\n }\n\n return writeTransformCache(\n dictionary,\n cacheKey,\n transformDictionary(resolved)\n ) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,MAAa,iBAIX,YACA,kBACA,YAKG;CACH,MAAM,EAAE,QAAQ,aAAa,wBAAwB,gBAAgB;CAKrE,MAAM,WAAW,+BACf,UAAU,qBAAqB,eAC/B,8BAA8B,QAAQ,GACtC,OACF;CAEA,MAAM,SAAS,mBAAwB,YAAY,QAAQ;CAC3D,IAAI,OAAO,KAAK,OAAO,OAAO;CAE9B,MAAM,iBAAiB,WAAW,eAAe,MAAM;CAEvD,MAAM,WAAW,2BAA2B,YAAY,QAAQ;CAEhE,MAAM,uBAAuB,uBAAmC;EAC9D,MAAM,QAAmB;GACvB,eAAe,mBAAmB;GAClC,gBAAgB,mBAAmB;GACnC,SAAS,CAAC;GACV,SAAS;GAIT,oBAAoB,mBAAmB;EACzC;EAEA,OAAO,WAAW,mBAAmB,SAAS,OAAO,cAAc;CACrE;CAEA,IAAI,aAAa,MAAM,OAAO,oBAAoB,YAAY,UAAU,IAAI;CAE5E,IAAI,MAAM,QAAQ,QAAQ,GACxB,OAAO,oBACL,YACA,UACA,SAAS,IAAI,mBAAmB,CAClC;CAGF,OAAO,oBACL,YACA,UACA,oBAAoB,QAAQ,CAC9B;AACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getPluginsCacheKey } from "./dictionaryTransformCache.mjs";
|
|
2
|
+
import { getDictionarySelectorCacheKey, parseDictionarySelector } from "../dictionaryManipulator/qualifiedDictionary.mjs";
|
|
3
|
+
import { getDictionary } from "./getDictionary.mjs";
|
|
4
|
+
import { isQualifiedDynamicLoaderMap, resolveQualifiedDynamicContentAsync } from "../dictionaryManipulator/qualifiedDynamicLoader.mjs";
|
|
5
|
+
import { findPlainDynamicLoader } from "../dictionaryManipulator/plainDynamicLoader.mjs";
|
|
6
|
+
import { internationalization } from "@intlayer/config/built";
|
|
7
|
+
|
|
8
|
+
//#region src/interpreter/getDictionaryAsync.ts
|
|
9
|
+
/**
|
|
10
|
+
* Content already resolved for a `key + locale + selector` triple, or the
|
|
11
|
+
* in-flight promise resolving it. Storing the promise itself makes the cache
|
|
12
|
+
* double as an in-flight deduplication table: concurrent calls for the same
|
|
13
|
+
* chunk await one single load.
|
|
14
|
+
*/
|
|
15
|
+
const contentPromiseCache = /* @__PURE__ */ new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Awaits the chunk a plain loader map holds for `locale` — walking the same
|
|
18
|
+
* fallback chain as static mode — and transforms it.
|
|
19
|
+
*
|
|
20
|
+
* Returns `null` when the map emitted no chunk for the locale nor for any of
|
|
21
|
+
* its fallbacks, mirroring how a missing qualified coordinate resolves.
|
|
22
|
+
*/
|
|
23
|
+
const loadPlainChunk = async (dictionaryLoaders, locale, transform) => {
|
|
24
|
+
const resolved = findPlainDynamicLoader(dictionaryLoaders, locale);
|
|
25
|
+
if (!resolved) return null;
|
|
26
|
+
return transform(await resolved.loader());
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Loads a single locale chunk of a dictionary and returns its transformed
|
|
30
|
+
* content.
|
|
31
|
+
*
|
|
32
|
+
* Counterpart of {@link getDictionary} for the per-locale loader maps emitted
|
|
33
|
+
* in `.intlayer/dynamic_dictionaries/`: instead of receiving a dictionary
|
|
34
|
+
* holding every locale, it receives the loader map and awaits only the chunk
|
|
35
|
+
* the requested locale needs.
|
|
36
|
+
*
|
|
37
|
+
* The loader map is either plain (`locale → loader`) or qualified
|
|
38
|
+
* (`locale → qualifierId → loader`, for collections and variants). For a
|
|
39
|
+
* qualified map, only the chunk(s) the selector targets are loaded.
|
|
40
|
+
*
|
|
41
|
+
* Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a
|
|
42
|
+
* `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call
|
|
43
|
+
* {@link getIntlayerAsync} and never this function directly.
|
|
44
|
+
*
|
|
45
|
+
* @param dictionaryLoaders - Plain or qualified per-locale loader map.
|
|
46
|
+
* @param key - Dictionary key, used to namespace the chunk cache.
|
|
47
|
+
* @param localeOrSelector - The locale, or a selector object (`{ item }`,
|
|
48
|
+
* `{ variant }`, optionally with `locale`).
|
|
49
|
+
* @param plugins - Node transformers. Defaults to the base interpreter set.
|
|
50
|
+
*/
|
|
51
|
+
const getDictionaryAsync = async (dictionaryLoaders, key, localeOrSelector, plugins) => {
|
|
52
|
+
let locale;
|
|
53
|
+
let selector;
|
|
54
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") {
|
|
55
|
+
const parsed = parseDictionarySelector(localeOrSelector);
|
|
56
|
+
locale = parsed.locale;
|
|
57
|
+
selector = parsed.selector;
|
|
58
|
+
} else locale = localeOrSelector;
|
|
59
|
+
const localeTarget = locale ?? internationalization.defaultLocale;
|
|
60
|
+
const cacheKey = `${key}_${localeTarget}_${getDictionarySelectorCacheKey(selector)}_${getPluginsCacheKey(plugins)}`;
|
|
61
|
+
const cachedContent = contentPromiseCache.get(cacheKey);
|
|
62
|
+
if (cachedContent) return cachedContent;
|
|
63
|
+
const transform = (dictionary) => getDictionary(dictionary, localeTarget, plugins);
|
|
64
|
+
const contentPromise = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(dictionaryLoaders) ? resolveQualifiedDynamicContentAsync({
|
|
65
|
+
loaderMap: dictionaryLoaders,
|
|
66
|
+
key,
|
|
67
|
+
locale: localeTarget,
|
|
68
|
+
selector,
|
|
69
|
+
transform
|
|
70
|
+
}) : loadPlainChunk(dictionaryLoaders, localeTarget, transform);
|
|
71
|
+
contentPromiseCache.set(cacheKey, contentPromise);
|
|
72
|
+
contentPromise.catch(() => contentPromiseCache.delete(cacheKey));
|
|
73
|
+
return contentPromise;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { getDictionaryAsync };
|
|
78
|
+
//# sourceMappingURL=getDictionaryAsync.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionaryAsync.mjs","names":[],"sources":["../../../src/interpreter/getDictionaryAsync.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n findPlainDynamicLoader,\n type PlainDynamicLoaderMap,\n} from '../dictionaryManipulator/plainDynamicLoader';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport {\n isQualifiedDynamicLoaderMap,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '../dictionaryManipulator/qualifiedDynamicLoader';\nimport { getPluginsCacheKey } from './dictionaryTransformCache';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\n\n/**\n * Content already resolved for a `key + locale + selector` triple, or the\n * in-flight promise resolving it. Storing the promise itself makes the cache\n * double as an in-flight deduplication table: concurrent calls for the same\n * chunk await one single load.\n */\nconst contentPromiseCache = new Map<string, Promise<unknown>>();\n\n/**\n * Awaits the chunk a plain loader map holds for `locale` — walking the same\n * fallback chain as static mode — and transforms it.\n *\n * Returns `null` when the map emitted no chunk for the locale nor for any of\n * its fallbacks, mirroring how a missing qualified coordinate resolves.\n */\nconst loadPlainChunk = async <T extends Dictionary, Content>(\n dictionaryLoaders: PlainDynamicLoaderMap<T>,\n locale: LocalesValues,\n transform: (dictionary: Dictionary) => Content\n): Promise<Content | null> => {\n const resolved = findPlainDynamicLoader<T>(dictionaryLoaders, locale);\n\n if (!resolved) return null;\n\n return transform(await resolved.loader());\n};\n\n/**\n * Loads a single locale chunk of a dictionary and returns its transformed\n * content.\n *\n * Counterpart of {@link getDictionary} for the per-locale loader maps emitted\n * in `.intlayer/dynamic_dictionaries/`: instead of receiving a dictionary\n * holding every locale, it receives the loader map and awaits only the chunk\n * the requested locale needs.\n *\n * The loader map is either plain (`locale → loader`) or qualified\n * (`locale → qualifierId → loader`, for collections and variants). For a\n * qualified map, only the chunk(s) the selector targets are loaded.\n *\n * Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a\n * `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call\n * {@link getIntlayerAsync} and never this function directly.\n *\n * @param dictionaryLoaders - Plain or qualified per-locale loader map.\n * @param key - Dictionary key, used to namespace the chunk cache.\n * @param localeOrSelector - The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins - Node transformers. Defaults to the base interpreter set.\n */\nexport const getDictionaryAsync = async <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryLoaders: PlainDynamicLoaderMap<T> | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n T['content'],\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n let locale: LocalesValues | undefined;\n let selector: DictionarySelector | undefined;\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n const parsed = parseDictionarySelector<LocalesValues>(localeOrSelector);\n locale = parsed.locale;\n selector = parsed.selector;\n } else {\n // Selectors are unused in this project (build-time flag): the argument can\n // only be a locale, so the selector parsing is dead code.\n locale = localeOrSelector as LocalesValues | undefined;\n }\n\n const localeTarget = locale ?? internationalization.defaultLocale;\n\n const cacheKey = `${key}_${localeTarget}_${getDictionarySelectorCacheKey(\n selector\n )}_${getPluginsCacheKey(plugins)}`;\n\n const cachedContent = contentPromiseCache.get(cacheKey);\n if (cachedContent) return cachedContent as Promise<any>;\n\n const transform = (dictionary: Dictionary) =>\n getDictionary(dictionary, localeTarget, plugins);\n\n const contentPromise =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryLoaders)\n ? resolveQualifiedDynamicContentAsync({\n loaderMap: dictionaryLoaders,\n key,\n locale: localeTarget,\n selector,\n transform,\n })\n : loadPlainChunk(\n dictionaryLoaders as PlainDynamicLoaderMap<T>,\n localeTarget,\n transform\n );\n\n contentPromiseCache.set(cacheKey, contentPromise);\n\n // A rejected load must not stay cached, or every later call replays the\n // same failure without ever retrying the chunk.\n contentPromise.catch(() => contentPromiseCache.delete(cacheKey));\n\n return contentPromise as Promise<any>;\n};\n"],"mappings":";;;;;;;;;;;;;;AAqCA,MAAM,sCAAsB,IAAI,IAA8B;;;;;;;;AAS9D,MAAM,iBAAiB,OACrB,mBACA,QACA,cAC4B;CAC5B,MAAM,WAAW,uBAA0B,mBAAmB,MAAM;CAEpE,IAAI,CAAC,UAAU,OAAO;CAEtB,OAAO,UAAU,MAAM,SAAS,OAAO,CAAC;AAC1C;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,qBAAqB,OAIhC,mBACA,KACA,kBACA,YAOG;CACH,IAAI;CACJ,IAAI;CAEJ,IAAI,QAAQ,IAAI,iCAAiC,SAAS;EACxD,MAAM,SAAS,wBAAuC,gBAAgB;EACtE,SAAS,OAAO;EAChB,WAAW,OAAO;CACpB,OAGE,SAAS;CAGX,MAAM,eAAe,UAAU,qBAAqB;CAEpD,MAAM,WAAW,GAAG,IAAI,GAAG,aAAa,GAAG,8BACzC,QACF,EAAE,GAAG,mBAAmB,OAAO;CAE/B,MAAM,gBAAgB,oBAAoB,IAAI,QAAQ;CACtD,IAAI,eAAe,OAAO;CAE1B,MAAM,aAAa,eACjB,cAAc,YAAY,cAAc,OAAO;CAEjD,MAAM,iBACJ,QAAQ,IAAI,iCAAiC,WAC7C,4BAA4B,iBAAiB,IACzC,oCAAoC;EAClC,WAAW;EACX;EACA,QAAQ;EACR;EACA;CACF,CAAC,IACD,eACE,mBACA,cACA,SACF;CAEN,oBAAoB,IAAI,UAAU,cAAc;CAIhD,eAAe,YAAY,oBAAoB,OAAO,QAAQ,CAAC;CAE/D,OAAO;AACT"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getDictionarySelectorCacheKey, parseDictionarySelector } from "../dictionaryManipulator/qualifiedDictionary.mjs";
|
|
2
1
|
import { getDictionary } from "./getDictionary.mjs";
|
|
3
2
|
import { log } from "@intlayer/config/built";
|
|
4
3
|
import { colorizeKey, getAppLogger } from "@intlayer/config/logger";
|
|
@@ -6,13 +5,33 @@ import { getDictionaries } from "@intlayer/dictionaries-entry";
|
|
|
6
5
|
|
|
7
6
|
//#region src/interpreter/getIntlayer.ts
|
|
8
7
|
/**
|
|
8
|
+
* Object.prototype methods libraries call on arbitrary values while inspecting
|
|
9
|
+
* them — TanStack Router's `isPlainObject` reaches for `hasOwnProperty` on
|
|
10
|
+
* every value it deep-compares. Answering them with another path proxy turns
|
|
11
|
+
* a missing dictionary into `hasOwnProperty is not a function`, thrown deep
|
|
12
|
+
* inside the consumer, so they are forwarded to the real implementations.
|
|
13
|
+
*/
|
|
14
|
+
const PROTOTYPE_METHOD_NAMES = /* @__PURE__ */ new Set([
|
|
15
|
+
"hasOwnProperty",
|
|
16
|
+
"isPrototypeOf",
|
|
17
|
+
"propertyIsEnumerable",
|
|
18
|
+
"toLocaleString"
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
9
21
|
* Creates a Recursive Proxy that returns the path of the accessed key
|
|
10
22
|
* stringified. This prevents the app from crashing on undefined access.
|
|
23
|
+
*
|
|
24
|
+
* The proxy wraps a function so that calling any leaf — `keywords.join(', ')`,
|
|
25
|
+
* `title.trim()` — resolves to the path too, instead of throwing
|
|
26
|
+
* `join is not a function`. Being callable also keeps structural checks
|
|
27
|
+
* (`Object.prototype.toString`) from mistaking it for a plain object worth
|
|
28
|
+
* walking.
|
|
11
29
|
*/
|
|
12
30
|
const createSafeFallback = (path = "") => {
|
|
13
|
-
return new Proxy(
|
|
31
|
+
return new Proxy((() => path), { get: (target, prop) => {
|
|
14
32
|
if (prop === "toJSON" || prop === Symbol.toPrimitive || prop === "toString" || prop === "valueOf") return () => path;
|
|
15
33
|
if (prop === "then") return;
|
|
34
|
+
if (PROTOTYPE_METHOD_NAMES.has(prop)) return Object.prototype[prop].bind(target);
|
|
16
35
|
if (prop === Symbol.iterator) return function* () {
|
|
17
36
|
yield path;
|
|
18
37
|
};
|
|
@@ -20,7 +39,6 @@ const createSafeFallback = (path = "") => {
|
|
|
20
39
|
return createSafeFallback(nextPath);
|
|
21
40
|
} });
|
|
22
41
|
};
|
|
23
|
-
const dictionaryCache = /* @__PURE__ */ new Map();
|
|
24
42
|
const warnedMissingDictionaries = /* @__PURE__ */ new Set();
|
|
25
43
|
/**
|
|
26
44
|
* Picks one dictionary by its key and returns its content for the given
|
|
@@ -41,18 +59,7 @@ const getIntlayer = (key, localeOrSelector, plugins) => {
|
|
|
41
59
|
}
|
|
42
60
|
return createSafeFallback(key);
|
|
43
61
|
}
|
|
44
|
-
|
|
45
|
-
let selectorCacheKey = "";
|
|
46
|
-
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") {
|
|
47
|
-
const parsed = parseDictionarySelector(localeOrSelector);
|
|
48
|
-
locale = parsed.locale;
|
|
49
|
-
selectorCacheKey = getDictionarySelectorCacheKey(parsed.selector);
|
|
50
|
-
} else locale = localeOrSelector;
|
|
51
|
-
const cacheKey = `${key}_${locale ?? "default"}_${selectorCacheKey}_${plugins ? "custom_plugins" : "default_plugins"}`;
|
|
52
|
-
if (dictionaryCache.has(cacheKey)) return dictionaryCache.get(cacheKey);
|
|
53
|
-
const result = getDictionary(dictionary, localeOrSelector, plugins);
|
|
54
|
-
dictionaryCache.set(cacheKey, result);
|
|
55
|
-
return result;
|
|
62
|
+
return getDictionary(dictionary, localeOrSelector, plugins);
|
|
56
63
|
};
|
|
57
64
|
|
|
58
65
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.mjs","names":[],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport
|
|
1
|
+
{"version":3,"file":"getIntlayer.mjs","names":[],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\n\n/**\n * Object.prototype methods libraries call on arbitrary values while inspecting\n * them — TanStack Router's `isPlainObject` reaches for `hasOwnProperty` on\n * every value it deep-compares. Answering them with another path proxy turns\n * a missing dictionary into `hasOwnProperty is not a function`, thrown deep\n * inside the consumer, so they are forwarded to the real implementations.\n */\nconst PROTOTYPE_METHOD_NAMES = new Set<string | symbol>([\n 'hasOwnProperty',\n 'isPrototypeOf',\n 'propertyIsEnumerable',\n 'toLocaleString',\n]);\n\n/**\n * Creates a Recursive Proxy that returns the path of the accessed key\n * stringified. This prevents the app from crashing on undefined access.\n *\n * The proxy wraps a function so that calling any leaf — `keywords.join(', ')`,\n * `title.trim()` — resolves to the path too, instead of throwing\n * `join is not a function`. Being callable also keeps structural checks\n * (`Object.prototype.toString`) from mistaking it for a plain object worth\n * walking.\n */\nconst createSafeFallback = (path = ''): any => {\n return new Proxy((() => path) as Record<string | symbol, any>, {\n get: (target, prop) => {\n if (\n prop === 'toJSON' ||\n prop === Symbol.toPrimitive ||\n prop === 'toString' ||\n prop === 'valueOf'\n ) {\n return () => path;\n }\n if (prop === 'then') {\n return undefined; // Prevent it from being treated as a Promise\n }\n if (PROTOTYPE_METHOD_NAMES.has(prop)) {\n return (Object.prototype as Record<string | symbol, any>)[prop].bind(\n target\n );\n }\n if (prop === Symbol.iterator) {\n return function* () {\n yield path;\n };\n }\n\n // Recursively build the path (e.g., \"myDictionary.home.title\")\n const nextPath = path ? `${path}.${String(prop)}` : String(prop);\n return createSafeFallback(nextPath);\n },\n });\n};\n\nconst warnedMissingDictionaries = new Set<string>();\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const dictionaries = getDictionaries();\n const dictionary = dictionaries[key as T]!;\n\n if (!dictionary && process.env.NODE_ENV === 'development') {\n if (!warnedMissingDictionaries.has(key as string)) {\n // Log a warning instead of throwing (so developers know it's missing)\n const logger = getAppLogger({ log });\n logger(\n typeof window === 'undefined'\n ? `Dictionary ${colorizeKey(key)} was not found. Using fallback proxy.`\n : `Dictionary ${key} was not found. Using fallback proxy.`,\n {\n level: 'warn',\n }\n );\n warnedMissingDictionaries.add(key as string);\n }\n\n return createSafeFallback(key as string);\n }\n\n return getDictionary(dictionary, localeOrSelector, plugins) as any;\n};\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAM,yCAAyB,IAAI,IAAqB;CACtD;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;;AAYD,MAAM,sBAAsB,OAAO,OAAY;CAC7C,OAAO,IAAI,aAAa,OAAuC,EAC7D,MAAM,QAAQ,SAAS;EACrB,IACE,SAAS,YACT,SAAS,OAAO,eAChB,SAAS,cACT,SAAS,WAET,aAAa;EAEf,IAAI,SAAS,QACX;EAEF,IAAI,uBAAuB,IAAI,IAAI,GACjC,OAAQ,OAAO,UAA2C,KAAK,CAAC,KAC9D,MACF;EAEF,IAAI,SAAS,OAAO,UAClB,OAAO,aAAa;GAClB,MAAM;EACR;EAIF,MAAM,WAAW,OAAO,GAAG,KAAK,GAAG,OAAO,IAAI,MAAM,OAAO,IAAI;EAC/D,OAAO,mBAAmB,QAAQ;CACpC,EACF,CAAC;AACH;AAEA,MAAM,4CAA4B,IAAI,IAAY;;;;;;;;;;;AAYlD,MAAa,eAIX,KACA,kBACA,YAKG;CAEH,MAAM,aADe,gBACS,CAAC,CAAC;CAEhC,IAAI,CAAC,cAAc,MAAwC;EACzD,IAAI,CAAC,0BAA0B,IAAI,GAAa,GAAG;GAGjD,AADe,aAAa,EAAE,IAAI,CAC7B,CAAC,CACJ,OAAO,WAAW,cACd,cAAc,YAAY,GAAG,EAAE,yCAC/B,cAAc,IAAI,wCACtB,EACE,OAAO,OACT,CACF;GACA,0BAA0B,IAAI,GAAa;EAC7C;EAEA,OAAO,mBAAmB,GAAa;CACzC;CAEA,OAAO,cAAc,YAAY,kBAAkB,OAAO;AAC5D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getIntlayer } from "./getIntlayer.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/interpreter/getIntlayerAsync.ts
|
|
4
|
+
/**
|
|
5
|
+
* Picks one dictionary by its key and resolves its content for the given
|
|
6
|
+
* locale or selector, loading that locale alone.
|
|
7
|
+
*
|
|
8
|
+
* Async counterpart of {@link getIntlayer}, meant for the places a dictionary
|
|
9
|
+
* is read outside of rendering — route `head` / metadata builders, loaders,
|
|
10
|
+
* server functions. Where `getIntlayer` pulls in the merged dictionary holding
|
|
11
|
+
* every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite
|
|
12
|
+
* this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at
|
|
13
|
+
* the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle
|
|
14
|
+
* only ever carries the locale actually requested.
|
|
15
|
+
*
|
|
16
|
+
* Without those plugins — an unoptimized build — the call resolves through the
|
|
17
|
+
* synchronous dictionary registry instead: the same content, without the
|
|
18
|
+
* per-locale split.
|
|
19
|
+
*
|
|
20
|
+
* The second argument is either a locale (`'fr'`) or a selector object:
|
|
21
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
22
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
23
|
+
* - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant
|
|
24
|
+
* - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const { title } = await getIntlayerAsync('home-metadata', locale);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const getIntlayerAsync = async (key, localeOrSelector, plugins) => getIntlayer(key, localeOrSelector, plugins);
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { getIntlayerAsync };
|
|
35
|
+
//# sourceMappingURL=getIntlayerAsync.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntlayerAsync.mjs","names":[],"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"sourcesContent":["import type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\n\n/**\n * Picks one dictionary by its key and resolves its content for the given\n * locale or selector, loading that locale alone.\n *\n * Async counterpart of {@link getIntlayer}, meant for the places a dictionary\n * is read outside of rendering — route `head` / metadata builders, loaders,\n * server functions. Where `getIntlayer` pulls in the merged dictionary holding\n * every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite\n * this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at\n * the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle\n * only ever carries the locale actually requested.\n *\n * Without those plugins — an unoptimized build — the call resolves through the\n * synchronous dictionary registry instead: the same content, without the\n * per-locale split.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n *\n * @example\n * ```ts\n * const { title } = await getIntlayerAsync('home-metadata', locale);\n * ```\n */\nexport const getIntlayerAsync = async <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => getIntlayer<T, A>(key, localeOrSelector, plugins);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,mBAAmB,OAI9B,KACA,kBACA,YAOG,YAAkB,KAAK,kBAAkB,OAAO"}
|