@astroscope/i18n 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/babel-plugin-C8O9spUS.js +120 -0
  2. package/dist/babel-plugin-C8O9spUS.js.map +1 -0
  3. package/dist/client/directives/idle.d.ts +4 -9
  4. package/dist/client/directives/idle.d.ts.map +1 -0
  5. package/dist/client/directives/idle.js +13 -21
  6. package/dist/client/directives/idle.js.map +1 -0
  7. package/dist/client/directives/load.d.ts +4 -9
  8. package/dist/client/directives/load.d.ts.map +1 -0
  9. package/dist/client/directives/load.js +9 -14
  10. package/dist/client/directives/load.js.map +1 -0
  11. package/dist/client/directives/media.d.ts +4 -9
  12. package/dist/client/directives/media.d.ts.map +1 -0
  13. package/dist/client/directives/media.js +16 -24
  14. package/dist/client/directives/media.js.map +1 -0
  15. package/dist/client/directives/only.d.ts +4 -11
  16. package/dist/client/directives/only.d.ts.map +1 -0
  17. package/dist/client/directives/only.js +9 -14
  18. package/dist/client/directives/only.js.map +1 -0
  19. package/dist/client/directives/utils.d.ts +3 -4
  20. package/dist/client/directives/utils.d.ts.map +1 -0
  21. package/dist/client/directives/utils.js +32 -7
  22. package/dist/client/directives/utils.js.map +1 -0
  23. package/dist/client/directives/visible.d.ts +4 -9
  24. package/dist/client/directives/visible.d.ts.map +1 -0
  25. package/dist/client/directives/visible.js +22 -29
  26. package/dist/client/directives/visible.js.map +1 -0
  27. package/dist/client/translate.d.ts +5 -4
  28. package/dist/client/translate.d.ts.map +1 -0
  29. package/dist/client/translate.js +68 -41
  30. package/dist/client/translate.js.map +1 -0
  31. package/dist/compiler-CkOVGWU5.js +48 -0
  32. package/dist/compiler-CkOVGWU5.js.map +1 -0
  33. package/dist/context-DT91WgEO.js +247 -0
  34. package/dist/context-DT91WgEO.js.map +1 -0
  35. package/dist/extraction/index.d.ts +12 -17
  36. package/dist/extraction/index.d.ts.map +1 -0
  37. package/dist/extraction/index.js +3 -11
  38. package/dist/i18n-DzmH9JmE.d.ts +79 -0
  39. package/dist/i18n-DzmH9JmE.d.ts.map +1 -0
  40. package/dist/index.d.ts +37 -33
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +163 -148
  43. package/dist/index.js.map +1 -0
  44. package/dist/internal.d.ts +6 -6
  45. package/dist/internal.d.ts.map +1 -0
  46. package/dist/internal.js +2 -10
  47. package/dist/manifest-D883_BIS.js +43 -0
  48. package/dist/manifest-D883_BIS.js.map +1 -0
  49. package/dist/rich-CHisXE-A.js +87 -0
  50. package/dist/rich-CHisXE-A.js.map +1 -0
  51. package/dist/{rich-CQUhdwBc.d.ts → rich-CqNMP3tk.d.ts} +4 -2
  52. package/dist/rich-CqNMP3tk.d.ts.map +1 -0
  53. package/dist/server/translate.d.ts +5 -3
  54. package/dist/server/translate.d.ts.map +1 -0
  55. package/dist/server/translate.js +75 -64
  56. package/dist/server/translate.js.map +1 -0
  57. package/dist/state-DeudhdeT.js +20 -0
  58. package/dist/state-DeudhdeT.js.map +1 -0
  59. package/dist/{types-ChMT6Vbd.d.ts → types-BfyoJsoB.d.ts} +11 -10
  60. package/dist/types-BfyoJsoB.d.ts.map +1 -0
  61. package/dist/types-Bo4jMK8g.d.ts +20 -0
  62. package/dist/types-Bo4jMK8g.d.ts.map +1 -0
  63. package/dist/{types-DNRFj1XA.d.ts → types-C98CcjtN.d.ts} +13 -11
  64. package/dist/types-C98CcjtN.d.ts.map +1 -0
  65. package/dist/url-B8334XSD.js +36 -0
  66. package/dist/url-B8334XSD.js.map +1 -0
  67. package/dist/vite-plugin-DVUlcvEH.js +421 -0
  68. package/dist/vite-plugin-DVUlcvEH.js.map +1 -0
  69. package/package.json +13 -12
  70. package/dist/babel-plugin-GOB6FMZ2.js +0 -119
  71. package/dist/chunk-33JVAFGQ.js +0 -44
  72. package/dist/chunk-4A5BKHFN.js +0 -16
  73. package/dist/chunk-7MSGHEST.js +0 -31
  74. package/dist/chunk-FYKC3DAZ.js +0 -36
  75. package/dist/chunk-LXW5WYBS.js +0 -298
  76. package/dist/chunk-PACQPCSW.js +0 -479
  77. package/dist/chunk-VGPVG5JP.js +0 -73
  78. package/dist/i18n-B--L7OQk.d.ts +0 -76
  79. package/dist/types-B_8vAmvv.d.ts +0 -18
  80. package/dist/types-BeDFfFIL.d.ts +0 -7
@@ -0,0 +1,120 @@
1
+ //#region src/extraction/babel-plugin.ts
2
+ /**
3
+ * Extract string value from AST node
4
+ */
5
+ function getStringValue(t, node) {
6
+ if (t.isStringLiteral(node)) return node.value;
7
+ if (t.isTemplateLiteral(node) && node.quasis.length === 1 && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? null;
8
+ return null;
9
+ }
10
+ /**
11
+ * Extract TranslationMeta from the second argument of t()
12
+ */
13
+ function extractMeta(t, node, warn) {
14
+ const stringValue = getStringValue(t, node);
15
+ if (stringValue !== null) return { fallback: stringValue };
16
+ if (t.isTemplateLiteral(node) && node.expressions.length > 0) {
17
+ warn("t() meta contains template literal with expressions - cannot extract statically");
18
+ return { fallback: "" };
19
+ }
20
+ if (t.isObjectExpression(node)) {
21
+ const meta = { fallback: "" };
22
+ for (const prop of node.properties) {
23
+ if (t.isSpreadElement(prop)) {
24
+ warn("t() meta contains spread element - cannot extract statically");
25
+ continue;
26
+ }
27
+ if (!t.isObjectProperty(prop)) continue;
28
+ if (!t.isIdentifier(prop.key)) continue;
29
+ const name = prop.key.name;
30
+ if (name === "fallback") {
31
+ const value = getStringValue(t, prop.value);
32
+ if (value !== null) meta.fallback = value;
33
+ else warn("t() fallback is not a static string - cannot extract");
34
+ } else if (name === "description") {
35
+ const value = getStringValue(t, prop.value);
36
+ if (value !== null) meta.description = value;
37
+ else warn("t() description is not a static string - cannot extract");
38
+ } else if (name === "variables" && t.isObjectExpression(prop.value)) meta.variables = extractVariables(t, prop.value, warn);
39
+ }
40
+ return meta;
41
+ }
42
+ warn("t() meta is not a static string or object - cannot extract");
43
+ return { fallback: "" };
44
+ }
45
+ /**
46
+ * Extract variables definition from object expression
47
+ */
48
+ function extractVariables(t, obj, warn) {
49
+ const result = {};
50
+ for (const prop of obj.properties) {
51
+ if (t.isSpreadElement(prop)) {
52
+ warn("t() variables contains spread element - cannot extract statically");
53
+ continue;
54
+ }
55
+ if (!t.isObjectProperty(prop)) continue;
56
+ if (!t.isIdentifier(prop.key)) continue;
57
+ const varName = prop.key.name;
58
+ if (t.isObjectExpression(prop.value)) {
59
+ const varDef = {};
60
+ for (const varProp of prop.value.properties) {
61
+ if (t.isSpreadElement(varProp)) {
62
+ warn(`t() variable "${varName}" contains spread element - cannot extract statically`);
63
+ continue;
64
+ }
65
+ if (!t.isObjectProperty(varProp)) continue;
66
+ if (!t.isIdentifier(varProp.key)) continue;
67
+ const varPropName = varProp.key.name;
68
+ const value = getStringValue(t, varProp.value);
69
+ if (value !== null) {
70
+ if (varPropName === "fallback") varDef.fallback = value;
71
+ else if (varPropName === "description") varDef.description = value;
72
+ } else if (varPropName === "fallback" || varPropName === "description") warn(`t() variable "${varName}.${varPropName}" is not a static string - cannot extract`);
73
+ }
74
+ result[varName] = varDef;
75
+ }
76
+ }
77
+ return Object.keys(result).length > 0 ? result : void 0;
78
+ }
79
+ /**
80
+ * Babel plugin for i18n extraction and transformation
81
+ *
82
+ * - Extracts t() calls with key and metadata
83
+ * - Strips fallback argument in production builds
84
+ */
85
+ function i18nExtractPlugin({ types: t }) {
86
+ return {
87
+ name: "@astroscope/i18n/extract",
88
+ visitor: { CallExpression(path, state) {
89
+ if (!path.get("callee").isIdentifier({ name: "t" })) return;
90
+ const args = path.node.arguments;
91
+ const keyArg = args[0];
92
+ if (!t.isExpression(keyArg)) return;
93
+ const key = getStringValue(t, keyArg);
94
+ if (key === null) return;
95
+ const file = state.filename ?? "";
96
+ const line = path.node.loc?.start.line ?? 0;
97
+ const warn = (message) => state.opts.logger.warn(`${message} at ${file}:${line}`);
98
+ const meta = args.length >= 2 && t.isExpression(args[1]) ? extractMeta(t, args[1], warn) : { fallback: "" };
99
+ state.opts.onKeyExtracted({
100
+ key,
101
+ meta,
102
+ file,
103
+ line
104
+ });
105
+ if (state.opts.stripFallbacks && args.length >= 2) {
106
+ const firstArg = args[0];
107
+ if (args.length === 2) path.node.arguments = [firstArg];
108
+ else path.node.arguments = [
109
+ firstArg,
110
+ t.identifier("undefined"),
111
+ args[2]
112
+ ];
113
+ }
114
+ } }
115
+ };
116
+ }
117
+ //#endregion
118
+ export { i18nExtractPlugin };
119
+
120
+ //# sourceMappingURL=babel-plugin-C8O9spUS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-C8O9spUS.js","names":[],"sources":["../src/extraction/babel-plugin.ts"],"sourcesContent":["import type { NodePath, PluginObject, PluginPass } from '@babel/core';\nimport type * as BabelTypes from '@babel/types';\nimport type { Expression, Node, ObjectExpression } from '@babel/types';\nimport type { AstroIntegrationLogger } from 'astro';\nimport type { TranslationMeta, VariableDef } from '../shared/types.js';\nimport type { ExtractedKeyOccurrence } from './types.js';\n\nexport type I18nExtractPluginOpts = {\n onKeyExtracted: (key: ExtractedKeyOccurrence) => void;\n logger: AstroIntegrationLogger;\n stripFallbacks: boolean;\n};\n\ntype PluginState = PluginPass & { opts: I18nExtractPluginOpts };\n\ntype WarnFn = (message: string) => void;\n\n/**\n * Extract string value from AST node\n */\nfunction getStringValue(t: typeof BabelTypes, node: Node): string | null {\n if (t.isStringLiteral(node)) {\n return node.value;\n }\n\n if (t.isTemplateLiteral(node) && node.quasis.length === 1 && node.expressions.length === 0) {\n return node.quasis[0]?.value.cooked ?? null;\n }\n\n return null;\n}\n\n/**\n * Extract TranslationMeta from the second argument of t()\n */\nfunction extractMeta(t: typeof BabelTypes, node: Expression, warn: WarnFn): TranslationMeta {\n // string shorthand: t('key', 'fallback')\n const stringValue = getStringValue(t, node);\n\n if (stringValue !== null) {\n return { fallback: stringValue };\n }\n\n // dynamic template literal: t('key', `Hello ${name}`)\n if (t.isTemplateLiteral(node) && node.expressions.length > 0) {\n warn('t() meta contains template literal with expressions - cannot extract statically');\n\n return { fallback: '' };\n }\n\n // object form: t('key', { fallback: '...', description: '...', variables: {...} })\n if (t.isObjectExpression(node)) {\n const meta: TranslationMeta = { fallback: '' };\n\n for (const prop of node.properties) {\n // spread elements cannot be extracted statically\n if (t.isSpreadElement(prop)) {\n warn('t() meta contains spread element - cannot extract statically');\n\n continue;\n }\n\n if (!t.isObjectProperty(prop)) continue;\n if (!t.isIdentifier(prop.key)) continue;\n\n const name = prop.key.name;\n\n if (name === 'fallback') {\n const value = getStringValue(t, prop.value as Node);\n\n if (value !== null) {\n meta.fallback = value;\n } else {\n warn('t() fallback is not a static string - cannot extract');\n }\n } else if (name === 'description') {\n const value = getStringValue(t, prop.value as Node);\n\n if (value !== null) {\n meta.description = value;\n } else {\n warn('t() description is not a static string - cannot extract');\n }\n } else if (name === 'variables' && t.isObjectExpression(prop.value)) {\n meta.variables = extractVariables(t, prop.value, warn);\n }\n }\n\n return meta;\n }\n\n // dynamic meta (e.g. variable reference)\n warn('t() meta is not a static string or object - cannot extract');\n\n return { fallback: '' };\n}\n\n/**\n * Extract variables definition from object expression\n */\nfunction extractVariables(\n t: typeof BabelTypes,\n obj: ObjectExpression,\n warn: WarnFn,\n): Record<string, VariableDef> | undefined {\n const result: Record<string, VariableDef> = {};\n\n for (const prop of obj.properties) {\n if (t.isSpreadElement(prop)) {\n warn('t() variables contains spread element - cannot extract statically');\n continue;\n }\n\n if (!t.isObjectProperty(prop)) continue;\n if (!t.isIdentifier(prop.key)) continue;\n\n const varName = prop.key.name;\n\n if (t.isObjectExpression(prop.value)) {\n const varDef: VariableDef = {};\n\n for (const varProp of prop.value.properties) {\n if (t.isSpreadElement(varProp)) {\n warn(`t() variable \"${varName}\" contains spread element - cannot extract statically`);\n continue;\n }\n\n if (!t.isObjectProperty(varProp)) continue;\n if (!t.isIdentifier(varProp.key)) continue;\n\n const varPropName = varProp.key.name;\n const value = getStringValue(t, varProp.value as Node);\n\n if (value !== null) {\n if (varPropName === 'fallback') {\n varDef.fallback = value;\n } else if (varPropName === 'description') {\n varDef.description = value;\n }\n } else if (varPropName === 'fallback' || varPropName === 'description') {\n warn(`t() variable \"${varName}.${varPropName}\" is not a static string - cannot extract`);\n }\n }\n\n result[varName] = varDef;\n }\n }\n\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\n/**\n * Babel plugin for i18n extraction and transformation\n *\n * - Extracts t() calls with key and metadata\n * - Strips fallback argument in production builds\n */\nexport function i18nExtractPlugin({ types: t }: { types: typeof BabelTypes }): PluginObject<PluginState> {\n return {\n name: '@astroscope/i18n/extract',\n visitor: {\n CallExpression(path: NodePath<BabelTypes.CallExpression>, state: PluginState) {\n // check if callee is 't' identifier\n // we assume that it was not aliased / reassigned\n if (!path.get('callee').isIdentifier({ name: 't' })) return;\n\n const args = path.node.arguments;\n const keyArg = args[0];\n\n // check first arg\n if (!t.isExpression(keyArg)) return;\n\n const key = getStringValue(t, keyArg);\n\n if (key === null) return; // first arg must be string\n // end check first arg\n\n const file = state.filename ?? '';\n const line = path.node.loc?.start.line ?? 0;\n const warn: WarnFn = (message) => state.opts.logger.warn(`${message} at ${file}:${line}`);\n\n // second arg is always meta (fallback string or object)\n // may not exist if we're processing already-transformed code\n const meta = args.length >= 2 && t.isExpression(args[1]) ? extractMeta(t, args[1], warn) : { fallback: '' };\n\n // report extracted key\n state.opts.onKeyExtracted({ key, meta, file, line });\n\n // strip fallback in production\n // t('key', 'fallback') → t('key')\n // t('key', 'fallback', values) → t('key', undefined, values)\n if (state.opts.stripFallbacks && args.length >= 2) {\n const firstArg = args[0]!;\n\n if (args.length === 2) {\n path.node.arguments = [firstArg];\n } else {\n path.node.arguments = [firstArg, t.identifier('undefined'), args[2]!];\n }\n }\n },\n },\n };\n}\n"],"mappings":";;;;AAoBA,SAAS,eAAe,GAAsB,MAA2B;CACvE,IAAI,EAAE,gBAAgB,IAAI,GACxB,OAAO,KAAK;CAGd,IAAI,EAAE,kBAAkB,IAAI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YAAY;GAC/B,MAAM,OAAO,KAAK,KAAK,KAAK,MAAM,QAAQ;GAC1C,MAAM,QAAgB,YAAY,MAAM,KAAK,OAAO,KAAK,GAAG,QAAQ,MAAM,KAAK,GAAG,MAAM;GAIxF,MAAM,OAAO,KAAK,UAAU,KAAK,EAAE,aAAa,KAAK,EAAE,IAAI,YAAY,GAAG,KAAK,IAAI,IAAI,IAAI,EAAE,UAAU,GAAG;GAG1G,MAAM,KAAK,eAAe;IAAE;IAAK;IAAM;IAAM;GAAK,CAAC;GAKnD,IAAI,MAAM,KAAK,kBAAkB,KAAK,UAAU,GAAG;IACjD,MAAM,WAAW,KAAK;IAEtB,IAAI,KAAK,WAAW,GAClB,KAAK,KAAK,YAAY,CAAC,QAAQ;SAE/B,KAAK,KAAK,YAAY;KAAC;KAAU,EAAE,WAAW,WAAW;KAAG,KAAK;IAAG;GAExE;EACF,EACF;CACF;AACF"}
@@ -1,12 +1,7 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:idle directive
5
- *
6
- * Based on Astro's idle directive (MIT License)
7
- * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/idle.ts
8
- */
1
+ import { ClientDirective } from "astro";
9
2
 
3
+ //#region src/client/directives/idle.d.ts
10
4
  declare const idleDirective: ClientDirective;
11
-
5
+ //#endregion
12
6
  export { idleDirective as default };
7
+ //# sourceMappingURL=idle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle.d.ts","names":[],"sources":["../../../src/client/directives/idle.ts"],"mappings":";;;cASM,aAAA,EAAe,eAYpB"}
@@ -1,22 +1,14 @@
1
- import {
2
- warmUpI18nForChunk
3
- } from "../../chunk-7MSGHEST.js";
4
- import "../../chunk-4A5BKHFN.js";
5
-
6
- // src/client/directives/idle.ts
7
- var idleDirective = (load, _options, el) => {
8
- const cb = async () => {
9
- warmUpI18nForChunk(el);
10
- const hydrate = await load();
11
- await hydrate();
12
- };
13
- if ("requestIdleCallback" in window) {
14
- window.requestIdleCallback(cb);
15
- } else {
16
- setTimeout(cb, 200);
17
- }
18
- };
19
- var idle_default = idleDirective;
20
- export {
21
- idle_default as default
1
+ import { warmUpI18nForChunk } from "./utils.js";
2
+ //#region src/client/directives/idle.ts
3
+ const idleDirective = (load, _options, el) => {
4
+ const cb = async () => {
5
+ warmUpI18nForChunk(el);
6
+ await (await load())();
7
+ };
8
+ if ("requestIdleCallback" in window) window.requestIdleCallback(cb);
9
+ else setTimeout(cb, 200);
22
10
  };
11
+ //#endregion
12
+ export { idleDirective as default };
13
+
14
+ //# sourceMappingURL=idle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle.js","names":[],"sources":["../../../src/client/directives/idle.ts"],"sourcesContent":["/**\n * i18n-aware client:idle directive\n *\n * Based on Astro's idle directive (MIT License)\n * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/idle.ts\n */\nimport type { ClientDirective } from 'astro';\nimport { warmUpI18nForChunk } from './utils.js';\n\nconst idleDirective: ClientDirective = (load, _options, el) => {\n const cb = async () => {\n warmUpI18nForChunk(el);\n const hydrate = await load();\n await hydrate();\n };\n\n if ('requestIdleCallback' in window) {\n (window as unknown as { requestIdleCallback: (cb: () => void) => void }).requestIdleCallback(cb);\n } else {\n setTimeout(cb, 200);\n }\n};\n\nexport default idleDirective;\n"],"mappings":";;AASA,MAAM,iBAAkC,MAAM,UAAU,OAAO;CAC7D,MAAM,KAAK,YAAY;EACrB,mBAAmB,EAAE;EAErB,OAAM,MADgB,KAAK,EAAA,CACb;CAChB;CAEA,IAAI,yBAAyB,QAC3B,OAAyE,oBAAoB,EAAE;MAE/F,WAAW,IAAI,GAAG;AAEtB"}
@@ -1,12 +1,7 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:load directive
5
- *
6
- * Based on Astro's load directive (MIT License)
7
- * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/load.ts
8
- */
1
+ import { ClientDirective } from "astro";
9
2
 
3
+ //#region src/client/directives/load.d.ts
10
4
  declare const loadDirective: ClientDirective;
11
-
5
+ //#endregion
12
6
  export { loadDirective as default };
7
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","names":[],"sources":["../../../src/client/directives/load.ts"],"mappings":";;;cASM,aAAA,EAAe,eAIpB"}
@@ -1,15 +1,10 @@
1
- import {
2
- warmUpI18nForChunk
3
- } from "../../chunk-7MSGHEST.js";
4
- import "../../chunk-4A5BKHFN.js";
5
-
6
- // src/client/directives/load.ts
7
- var loadDirective = async (load, _options, el) => {
8
- warmUpI18nForChunk(el);
9
- const hydrate = await load();
10
- await hydrate();
11
- };
12
- var load_default = loadDirective;
13
- export {
14
- load_default as default
1
+ import { warmUpI18nForChunk } from "./utils.js";
2
+ //#region src/client/directives/load.ts
3
+ const loadDirective = async (load, _options, el) => {
4
+ warmUpI18nForChunk(el);
5
+ await (await load())();
15
6
  };
7
+ //#endregion
8
+ export { loadDirective as default };
9
+
10
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","names":[],"sources":["../../../src/client/directives/load.ts"],"sourcesContent":["/**\n * i18n-aware client:load directive\n *\n * Based on Astro's load directive (MIT License)\n * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/load.ts\n */\nimport type { ClientDirective } from 'astro';\nimport { warmUpI18nForChunk } from './utils.js';\n\nconst loadDirective: ClientDirective = async (load, _options, el) => {\n warmUpI18nForChunk(el);\n const hydrate = await load();\n await hydrate();\n};\n\nexport default loadDirective;\n"],"mappings":";;AASA,MAAM,gBAAiC,OAAO,MAAM,UAAU,OAAO;CACnE,mBAAmB,EAAE;CAErB,OAAM,MADgB,KAAK,EAAA,CACb;AAChB"}
@@ -1,12 +1,7 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:media directive
5
- *
6
- * Based on Astro's media directive (MIT License)
7
- * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/media.ts
8
- */
1
+ import { ClientDirective } from "astro";
9
2
 
3
+ //#region src/client/directives/media.d.ts
10
4
  declare const mediaDirective: ClientDirective;
11
-
5
+ //#endregion
12
6
  export { mediaDirective as default };
7
+ //# sourceMappingURL=media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","names":[],"sources":["../../../src/client/directives/media.ts"],"mappings":";;;cASM,cAAA,EAAgB,eAerB"}
@@ -1,25 +1,17 @@
1
- import {
2
- warmUpI18nForChunk
3
- } from "../../chunk-7MSGHEST.js";
4
- import "../../chunk-4A5BKHFN.js";
5
-
6
- // src/client/directives/media.ts
7
- var mediaDirective = (load, options, el) => {
8
- const cb = async () => {
9
- warmUpI18nForChunk(el);
10
- const hydrate = await load();
11
- await hydrate();
12
- };
13
- if (options.value) {
14
- const mql = matchMedia(options.value);
15
- if (mql.matches) {
16
- cb();
17
- } else {
18
- mql.addEventListener("change", cb, { once: true });
19
- }
20
- }
21
- };
22
- var media_default = mediaDirective;
23
- export {
24
- media_default as default
1
+ import { warmUpI18nForChunk } from "./utils.js";
2
+ //#region src/client/directives/media.ts
3
+ const mediaDirective = (load, options, el) => {
4
+ const cb = async () => {
5
+ warmUpI18nForChunk(el);
6
+ await (await load())();
7
+ };
8
+ if (options.value) {
9
+ const mql = matchMedia(options.value);
10
+ if (mql.matches) cb();
11
+ else mql.addEventListener("change", cb, { once: true });
12
+ }
25
13
  };
14
+ //#endregion
15
+ export { mediaDirective as default };
16
+
17
+ //# sourceMappingURL=media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.js","names":[],"sources":["../../../src/client/directives/media.ts"],"sourcesContent":["/**\n * i18n-aware client:media directive\n *\n * Based on Astro's media directive (MIT License)\n * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/media.ts\n */\nimport type { ClientDirective } from 'astro';\nimport { warmUpI18nForChunk } from './utils.js';\n\nconst mediaDirective: ClientDirective = (load, options, el) => {\n const cb = async () => {\n warmUpI18nForChunk(el);\n const hydrate = await load();\n await hydrate();\n };\n\n if (options.value) {\n const mql = matchMedia(options.value);\n if (mql.matches) {\n cb();\n } else {\n mql.addEventListener('change', cb, { once: true });\n }\n }\n};\n\nexport default mediaDirective;\n"],"mappings":";;AASA,MAAM,kBAAmC,MAAM,SAAS,OAAO;CAC7D,MAAM,KAAK,YAAY;EACrB,mBAAmB,EAAE;EAErB,OAAM,MADgB,KAAK,EAAA,CACb;CAChB;CAEA,IAAI,QAAQ,OAAO;EACjB,MAAM,MAAM,WAAW,QAAQ,KAAK;EACpC,IAAI,IAAI,SACN,GAAG;OAEH,IAAI,iBAAiB,UAAU,IAAI,EAAE,MAAM,KAAK,CAAC;CAErD;AACF"}
@@ -1,14 +1,7 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:only directive
5
- *
6
- * Based on Astro's load directive (MIT License)
7
- * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/load.ts
8
- *
9
- * client:only works the same as client:load - immediate hydration
10
- */
1
+ import { ClientDirective } from "astro";
11
2
 
3
+ //#region src/client/directives/only.d.ts
12
4
  declare const onlyDirective: ClientDirective;
13
-
5
+ //#endregion
14
6
  export { onlyDirective as default };
7
+ //# sourceMappingURL=only.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"only.d.ts","names":[],"sources":["../../../src/client/directives/only.ts"],"mappings":";;;cAWM,aAAA,EAAe,eAIpB"}
@@ -1,15 +1,10 @@
1
- import {
2
- warmUpI18nForChunk
3
- } from "../../chunk-7MSGHEST.js";
4
- import "../../chunk-4A5BKHFN.js";
5
-
6
- // src/client/directives/only.ts
7
- var onlyDirective = async (load, _options, el) => {
8
- warmUpI18nForChunk(el);
9
- const hydrate = await load();
10
- await hydrate();
11
- };
12
- var only_default = onlyDirective;
13
- export {
14
- only_default as default
1
+ import { warmUpI18nForChunk } from "./utils.js";
2
+ //#region src/client/directives/only.ts
3
+ const onlyDirective = async (load, _options, el) => {
4
+ warmUpI18nForChunk(el);
5
+ await (await load())();
15
6
  };
7
+ //#endregion
8
+ export { onlyDirective as default };
9
+
10
+ //# sourceMappingURL=only.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"only.js","names":[],"sources":["../../../src/client/directives/only.ts"],"sourcesContent":["/**\n * i18n-aware client:only directive\n *\n * Based on Astro's load directive (MIT License)\n * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/load.ts\n *\n * client:only works the same as client:load - immediate hydration\n */\nimport type { ClientDirective } from 'astro';\nimport { warmUpI18nForChunk } from './utils.js';\n\nconst onlyDirective: ClientDirective = async (load, _options, el) => {\n warmUpI18nForChunk(el);\n const hydrate = await load();\n await hydrate();\n};\n\nexport default onlyDirective;\n"],"mappings":";;AAWA,MAAM,gBAAiC,OAAO,MAAM,UAAU,OAAO;CACnE,mBAAmB,EAAE;CAErB,OAAM,MADgB,KAAK,EAAA,CACb;AAChB"}
@@ -1,11 +1,10 @@
1
- import '../../types-BeDFfFIL.js';
2
- import '../../types-DNRFj1XA.js';
3
-
1
+ //#region src/client/directives/utils.d.ts
4
2
  /**
5
3
  * Warm up translation cache for a chunk and all its descendants (fire and forget)
6
4
  * Extracts chunk name from astro-island's component-url attribute
7
5
  * Uses flattened imports map from window.__i18n__ to prefetch all nested translations
8
6
  */
9
7
  declare function warmUpI18nForChunk(el: HTMLElement): void;
10
-
8
+ //#endregion
11
9
  export { warmUpI18nForChunk };
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","names":[],"sources":["../../../src/client/directives/utils.ts"],"mappings":";;AAqBA;;;;iBAAgB,kBAAA,CAAmB,EAAe,EAAX,WAAW"}
@@ -1,7 +1,32 @@
1
- import {
2
- warmUpI18nForChunk
3
- } from "../../chunk-7MSGHEST.js";
4
- import "../../chunk-4A5BKHFN.js";
5
- export {
6
- warmUpI18nForChunk
7
- };
1
+ import { r as componentUrlToChunkName, t as buildI18nChunkUrl } from "../../url-B8334XSD.js";
2
+ import { t as getI18nState } from "../../state-DeudhdeT.js";
3
+ //#region src/client/directives/utils.ts
4
+ /**
5
+ * Prefetch translation chunk (fire and forget)
6
+ */
7
+ function prefetchTranslation(chunkName, i18n) {
8
+ const hash = i18n.hashes[chunkName];
9
+ if (hash) import(
10
+ /* @vite-ignore */
11
+ buildI18nChunkUrl(i18n.locale, chunkName, hash)
12
+ );
13
+ }
14
+ /**
15
+ * Warm up translation cache for a chunk and all its descendants (fire and forget)
16
+ * Extracts chunk name from astro-island's component-url attribute
17
+ * Uses flattened imports map from window.__i18n__ to prefetch all nested translations
18
+ */
19
+ function warmUpI18nForChunk(el) {
20
+ const componentUrl = el.getAttribute("component-url");
21
+ if (!componentUrl) return;
22
+ const i18n = getI18nState();
23
+ if (!i18n) return;
24
+ const chunkName = componentUrlToChunkName(componentUrl);
25
+ prefetchTranslation(chunkName, i18n);
26
+ const deps = i18n.imports[chunkName] ?? [];
27
+ for (const dep of deps) prefetchTranslation(dep, i18n);
28
+ }
29
+ //#endregion
30
+ export { warmUpI18nForChunk };
31
+
32
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../src/client/directives/utils.ts"],"sourcesContent":["import type { I18nClientState } from '../../shared/types.js';\nimport { buildI18nChunkUrl, componentUrlToChunkName } from '../../shared/url.js';\nimport { getI18nState } from '../state.js';\n\n/**\n * Prefetch translation chunk (fire and forget)\n */\nfunction prefetchTranslation(chunkName: string, i18n: I18nClientState): void {\n const hash = i18n.hashes[chunkName];\n\n if (hash) {\n const url = buildI18nChunkUrl(i18n.locale, chunkName, hash);\n import(/* @vite-ignore */ url);\n }\n}\n\n/**\n * Warm up translation cache for a chunk and all its descendants (fire and forget)\n * Extracts chunk name from astro-island's component-url attribute\n * Uses flattened imports map from window.__i18n__ to prefetch all nested translations\n */\nexport function warmUpI18nForChunk(el: HTMLElement): void {\n const componentUrl = el.getAttribute('component-url');\n\n if (!componentUrl) return;\n\n const i18n = getI18nState();\n\n if (!i18n) return;\n\n const chunkName = componentUrlToChunkName(componentUrl);\n\n // prefetch this chunk's translations\n prefetchTranslation(chunkName, i18n);\n\n // prefetch all descendant translations (flattened in imports map)\n const deps = i18n.imports[chunkName] ?? [];\n\n for (const dep of deps) {\n prefetchTranslation(dep, i18n);\n }\n}\n"],"mappings":";;;;;;AAOA,SAAS,oBAAoB,WAAmB,MAA6B;CAC3E,MAAM,OAAO,KAAK,OAAO;CAEzB,IAAI,MAEF;;EADY,kBAAkB,KAAK,QAAQ,WAAW,IAC1B;;AAEhC;;;;;;AAOA,SAAgB,mBAAmB,IAAuB;CACxD,MAAM,eAAe,GAAG,aAAa,eAAe;CAEpD,IAAI,CAAC,cAAc;CAEnB,MAAM,OAAO,aAAa;CAE1B,IAAI,CAAC,MAAM;CAEX,MAAM,YAAY,wBAAwB,YAAY;CAGtD,oBAAoB,WAAW,IAAI;CAGnC,MAAM,OAAO,KAAK,QAAQ,cAAc,CAAC;CAEzC,KAAK,MAAM,OAAO,MAChB,oBAAoB,KAAK,IAAI;AAEjC"}
@@ -1,12 +1,7 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:visible directive
5
- *
6
- * Based on Astro's visible directive (MIT License)
7
- * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/visible.ts
8
- */
1
+ import { ClientDirective } from "astro";
9
2
 
3
+ //#region src/client/directives/visible.d.ts
10
4
  declare const visibleDirective: ClientDirective;
11
-
5
+ //#endregion
12
6
  export { visibleDirective as default };
7
+ //# sourceMappingURL=visible.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visible.d.ts","names":[],"sources":["../../../src/client/directives/visible.ts"],"mappings":";;;cASM,gBAAA,EAAkB,eAuBvB"}
@@ -1,30 +1,23 @@
1
- import {
2
- warmUpI18nForChunk
3
- } from "../../chunk-7MSGHEST.js";
4
- import "../../chunk-4A5BKHFN.js";
5
-
6
- // src/client/directives/visible.ts
7
- var visibleDirective = (load, options, el) => {
8
- const cb = async () => {
9
- warmUpI18nForChunk(el);
10
- const hydrate = await load();
11
- await hydrate();
12
- };
13
- const rawOptions = typeof options.value === "object" ? options.value : void 0;
14
- const ioOptions = rawOptions?.rootMargin ? { rootMargin: rawOptions.rootMargin } : {};
15
- const io = new IntersectionObserver((entries) => {
16
- for (const entry of entries) {
17
- if (!entry.isIntersecting) continue;
18
- io.disconnect();
19
- cb();
20
- break;
21
- }
22
- }, ioOptions);
23
- for (const child of el.children) {
24
- io.observe(child);
25
- }
26
- };
27
- var visible_default = visibleDirective;
28
- export {
29
- visible_default as default
1
+ import { warmUpI18nForChunk } from "./utils.js";
2
+ //#region src/client/directives/visible.ts
3
+ const visibleDirective = (load, options, el) => {
4
+ const cb = async () => {
5
+ warmUpI18nForChunk(el);
6
+ await (await load())();
7
+ };
8
+ const rawOptions = typeof options.value === "object" ? options.value : void 0;
9
+ const ioOptions = rawOptions?.rootMargin ? { rootMargin: rawOptions.rootMargin } : {};
10
+ const io = new IntersectionObserver((entries) => {
11
+ for (const entry of entries) {
12
+ if (!entry.isIntersecting) continue;
13
+ io.disconnect();
14
+ cb();
15
+ break;
16
+ }
17
+ }, ioOptions);
18
+ for (const child of el.children) io.observe(child);
30
19
  };
20
+ //#endregion
21
+ export { visibleDirective as default };
22
+
23
+ //# sourceMappingURL=visible.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visible.js","names":[],"sources":["../../../src/client/directives/visible.ts"],"sourcesContent":["/**\n * i18n-aware client:visible directive\n *\n * Based on Astro's visible directive (MIT License)\n * https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/visible.ts\n */\nimport type { ClientDirective, ClientVisibleOptions } from 'astro';\nimport { warmUpI18nForChunk } from './utils.js';\n\nconst visibleDirective: ClientDirective = (load, options, el) => {\n const cb = async () => {\n warmUpI18nForChunk(el);\n const hydrate = await load();\n await hydrate();\n };\n\n const rawOptions = typeof options.value === 'object' ? (options.value as ClientVisibleOptions) : undefined;\n\n const ioOptions: IntersectionObserverInit = rawOptions?.rootMargin ? { rootMargin: rawOptions.rootMargin } : {};\n\n const io = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n if (!entry.isIntersecting) continue;\n io.disconnect();\n cb();\n break;\n }\n }, ioOptions);\n\n for (const child of el.children) {\n io.observe(child);\n }\n};\n\nexport default visibleDirective;\n"],"mappings":";;AASA,MAAM,oBAAqC,MAAM,SAAS,OAAO;CAC/D,MAAM,KAAK,YAAY;EACrB,mBAAmB,EAAE;EAErB,OAAM,MADgB,KAAK,EAAA,CACb;CAChB;CAEA,MAAM,aAAa,OAAO,QAAQ,UAAU,WAAY,QAAQ,QAAiC,KAAA;CAEjG,MAAM,YAAsC,YAAY,aAAa,EAAE,YAAY,WAAW,WAAW,IAAI,CAAC;CAE9G,MAAM,KAAK,IAAI,sBAAsB,YAAY;EAC/C,KAAK,MAAM,SAAS,SAAS;GAC3B,IAAI,CAAC,MAAM,gBAAgB;GAC3B,GAAG,WAAW;GACd,GAAG;GACH;EACF;CACF,GAAG,SAAS;CAEZ,KAAK,MAAM,SAAS,GAAG,UACrB,GAAG,QAAQ,KAAK;AAEpB"}
@@ -1,7 +1,7 @@
1
- import { R as RichComponents } from '../rich-CQUhdwBc.js';
2
- import { T as TranslationMeta, a as TranslateFunction } from '../types-DNRFj1XA.js';
3
- import '../types-BeDFfFIL.js';
1
+ import { t as RichComponents } from "../rich-CqNMP3tk.js";
2
+ import { a as TranslationMeta, i as TranslateFunction } from "../types-C98CcjtN.js";
4
3
 
4
+ //#region src/client/translate.d.ts
5
5
  declare function getLocale(): string;
6
6
  /**
7
7
  * Client-side translate function
@@ -37,5 +37,6 @@ declare const t: TranslateFunction;
37
37
  * ```
38
38
  */
39
39
  declare function rich<T = unknown>(key: string, meta?: TranslationMeta | string | undefined, components?: RichComponents<T> | undefined, values?: Record<string, unknown> | undefined): (string | T)[];
40
-
40
+ //#endregion
41
41
  export { getLocale, rich, t };
42
+ //# sourceMappingURL=translate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.d.ts","names":[],"sources":["../../src/client/translate.ts"],"mappings":";;;;iBAQgB,SAAA;;AAAhB;;;;AAAyB;AAiBzB;;;;AAuCuB;AAqBvB;;cA5Da,CAAA,EAAG,iBAuCO;;;;;;;;;;;;;;;;;;;AA0BT;iBALE,IAAA,cACd,GAAA,UACA,IAAA,GAAO,eAAA,uBACP,UAAA,GAAa,cAAA,CAAe,CAAA,eAC5B,MAAA,GAAS,MAAA,0CACE,CAAA"}