@fluentic/i18n-compiler 0.0.0-stage → 0.1.0-beta.2

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.
@@ -0,0 +1,419 @@
1
+ import * as generatorModule from "@babel/generator";
2
+ import * as b from "@babel/types";
3
+ import { COMPACT_VERSION, DEFAULT_HASH_LENGTH, messageHash, normalizeHashLength, normalizeMessage } from "@fluentic/i18n/compiler-support";
4
+ import { parse } from "@babel/parser";
5
+ import * as traverseModule from "@babel/traverse";
6
+ import { TYPE, parse as parse$1 } from "@formatjs/icu-messageformat-parser";
7
+ // src/analyze.ts
8
+ const traverse = traverseModule.default.default ?? traverseModule.default;
9
+ const importMap = {
10
+ "@fluentic/i18n": "@fluentic/i18n/compiled",
11
+ "@fluentic/i18n/core": "@fluentic/i18n/compiled"
12
+ };
13
+ function parseSource(code, filename) {
14
+ return parse(code, {
15
+ sourceFilename: filename,
16
+ sourceType: "unambiguous",
17
+ plugins: [
18
+ .../\.[cm]?tsx?$/.test(filename) ? ["typescript"] : [],
19
+ ...!/\.[cm]?ts$/.test(filename) ? ["jsx"] : [],
20
+ "decorators-legacy",
21
+ "importAttributes"
22
+ ]
23
+ });
24
+ }
25
+ function unwrap(path) {
26
+ while (path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() || path.isTypeCastExpression() || path.isParenthesizedExpression()) path = path.get("expression");
27
+ return path;
28
+ }
29
+ function literal(path, seen = /* @__PURE__ */ new Set()) {
30
+ path = unwrap(path);
31
+ if (path.isStringLiteral()) return normalizeMessage(path.node.value);
32
+ if (path.isTemplateLiteral() && !path.node.expressions.length) return normalizeMessage(path.node.quasis[0].value.cooked ?? "");
33
+ if (path.isIdentifier()) {
34
+ const binding = path.scope.getBinding(path.node.name);
35
+ if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {
36
+ seen.add(binding);
37
+ return literal(binding.path.get("init"), seen);
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+ function memberName(path) {
43
+ if (!path.isMemberExpression()) return null;
44
+ const property = path.get("property");
45
+ return !path.node.computed && property.isIdentifier() ? property.node.name : property.isStringLiteral() ? property.node.value : null;
46
+ }
47
+ function analyzer(imports = Object.keys(importMap)) {
48
+ const memo = /* @__PURE__ */ new Map();
49
+ const scopedBindings = /* @__PURE__ */ new Set();
50
+ const scopeCalls = /* @__PURE__ */ new Set();
51
+ const resolve = (path, visiting = /* @__PURE__ */ new Set()) => {
52
+ path = unwrap(path);
53
+ if (path.isIdentifier()) {
54
+ const binding = path.scope.getBinding(path.node.name);
55
+ if (!binding) return null;
56
+ if (memo.has(binding)) return memo.get(binding);
57
+ if (visiting.has(binding)) throw new Error("[i18n] circular translator alias");
58
+ if (binding.path.isImportSpecifier()) {
59
+ const declaration = binding.path.parentPath;
60
+ const imported = binding.path.node.imported;
61
+ return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) && (b.isIdentifier(imported) ? imported.name : imported.value) === "t" && declaration.node.importKind !== "type" ? {
62
+ context: null,
63
+ notes: []
64
+ } : null;
65
+ }
66
+ if (binding.path.isVariableDeclarator()) {
67
+ visiting.add(binding);
68
+ const scope = resolve(binding.path.get("init"), visiting);
69
+ visiting.delete(binding);
70
+ if (scope && !binding.constant) throw new Error("[i18n] translator aliases must not be reassigned: " + path.node.name);
71
+ memo.set(binding, scope);
72
+ if (scope) scopedBindings.add(binding);
73
+ return scope;
74
+ }
75
+ return null;
76
+ }
77
+ if (path.isMemberExpression() && memberName(path) === "t") {
78
+ const object = path.get("object");
79
+ if (!object.isIdentifier()) return null;
80
+ const binding = object.scope.getBinding(object.node.name);
81
+ const declaration = binding?.path.parentPath;
82
+ if (binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() && imports.includes(declaration.node.source.value)) return {
83
+ context: null,
84
+ notes: []
85
+ };
86
+ }
87
+ if (!path.isCallExpression()) return null;
88
+ const callee = path.get("callee");
89
+ const method = memberName(callee);
90
+ if (!method || ![
91
+ "context",
92
+ "note",
93
+ "meta"
94
+ ].includes(method)) return null;
95
+ const parent = resolve(callee.get("object"), visiting);
96
+ if (!parent) return null;
97
+ if (path.node.arguments.length !== 1) throw new Error("[i18n] scope methods require one static argument");
98
+ const argument = path.get("arguments.0");
99
+ scopeCalls.add(path);
100
+ if (method === "meta") {
101
+ const evaluated = argument.evaluate();
102
+ if (!evaluated.confident) throw new Error("[i18n] metadata must be statically known");
103
+ return {
104
+ ...parent,
105
+ meta: evaluated.value
106
+ };
107
+ }
108
+ const value = literal(argument);
109
+ if (value === null) throw new Error("[i18n] " + method + " must be a static string");
110
+ return method === "note" ? {
111
+ ...parent,
112
+ notes: [...parent.notes, value]
113
+ } : {
114
+ ...parent,
115
+ context: parent.context ? `${parent.context}.${value}` : value
116
+ };
117
+ };
118
+ return {
119
+ resolve,
120
+ scopedBindings,
121
+ scopeCalls
122
+ };
123
+ }
124
+ function collectMessages(code, filename, imports) {
125
+ const ast = parseSource(code, filename);
126
+ const { resolve } = analyzer(imports);
127
+ const messages = [];
128
+ traverse(ast, { CallExpression(path) {
129
+ const callee = path.get("callee");
130
+ const method = memberName(callee);
131
+ if (!method || ![
132
+ "msg",
133
+ "text",
134
+ "jsx"
135
+ ].includes(method)) return;
136
+ const scope = resolve(callee.get("object"));
137
+ if (!scope) return;
138
+ const source = literal(path.get("arguments.0"));
139
+ if (source === null) {
140
+ if (method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
141
+ return;
142
+ }
143
+ messages.push({
144
+ ...scope,
145
+ id: scope.context ? `${scope.context}\0${source}` : source,
146
+ source
147
+ });
148
+ } });
149
+ return [...new Map(messages.map((message) => [message.id, message])).values()];
150
+ }
151
+ // src/message.ts
152
+ function messageIdentity(context, source) {
153
+ source = normalizeMessage(source);
154
+ return context ? `${context}\0${source}` : source;
155
+ }
156
+ function messageId(context, source, hashLength = DEFAULT_HASH_LENGTH) {
157
+ return messageHash(messageIdentity(context, source), hashLength);
158
+ }
159
+ function compileMessage(source) {
160
+ source = normalizeMessage(source);
161
+ const compact = (elements) => {
162
+ const result = elements.map((element) => {
163
+ switch (element.type) {
164
+ case TYPE.literal: return element.value;
165
+ case TYPE.argument: return [0, element.value];
166
+ case TYPE.number:
167
+ case TYPE.date:
168
+ case TYPE.time: return [
169
+ element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,
170
+ element.value,
171
+ typeof element.style === "object" && element.style ? element.style.parsedOptions : element.style ?? null
172
+ ];
173
+ case TYPE.select: return [
174
+ 4,
175
+ element.value,
176
+ Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
177
+ ];
178
+ case TYPE.plural: return [
179
+ 5,
180
+ element.value,
181
+ element.offset,
182
+ element.pluralType === "ordinal" ? 1 : 0,
183
+ Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
184
+ ];
185
+ case TYPE.pound: return [6];
186
+ case TYPE.tag: return [
187
+ 7,
188
+ element.value,
189
+ compact(element.children)
190
+ ];
191
+ }
192
+ });
193
+ return result.every((part) => typeof part === "string") ? result.join("") : result;
194
+ };
195
+ return compact(parse$1(source, { captureLocation: false }));
196
+ }
197
+ function compileCatalog(records, options = {}) {
198
+ const seen = /* @__PURE__ */ new Map();
199
+ return records.flatMap((record) => {
200
+ const id = messageId(record.context, record.source, options.hashLength);
201
+ const identity = messageIdentity(record.context, record.source);
202
+ if (seen.has(id) && seen.get(id) !== identity) throw new Error("[i18n] message hash collision: " + id);
203
+ seen.set(id, identity);
204
+ return record.translation === "" ? [] : [[id, compileMessage(record.translation)]];
205
+ });
206
+ }
207
+ // src/index.ts
208
+ const generate = generatorModule.default.default ?? generatorModule.default;
209
+ function reactFunction(path) {
210
+ for (let current = path.findParent((parent) => parent.isFunction()); current; current = current.findParent((parent) => parent.isFunction())) {
211
+ const fn = current;
212
+ const parent = fn.parentPath;
213
+ const ownName = b.isFunctionDeclaration(fn.node) || b.isFunctionExpression(fn.node) ? fn.node.id?.name : null;
214
+ const variableId = parent?.isVariableDeclarator() ? parent.get("id") : null;
215
+ const name = ownName ?? (variableId?.isIdentifier() ? variableId.node.name : null);
216
+ if (parent?.isExportDefaultDeclaration() || name && (/^[A-Z]/.test(name) || /^use[A-Z]/.test(name))) return fn;
217
+ }
218
+ return null;
219
+ }
220
+ function hashLength(length) {
221
+ return normalizeHashLength(length ?? DEFAULT_HASH_LENGTH);
222
+ }
223
+ function resolveJsxCallback(path, seen = /* @__PURE__ */ new Set()) {
224
+ while (path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() || path.isTypeCastExpression() || path.isParenthesizedExpression()) path = path.get("expression");
225
+ if (path.isArrowFunctionExpression() || path.isFunctionExpression() || path.isFunctionDeclaration()) return path;
226
+ if (!path.isIdentifier()) return null;
227
+ const binding = path.scope.getBinding(path.node.name);
228
+ if (!binding?.constant || seen.has(binding)) return null;
229
+ seen.add(binding);
230
+ if (binding.path.isFunctionDeclaration()) return binding.path;
231
+ if (!binding.path.isVariableDeclarator()) return null;
232
+ return resolveJsxCallback(binding.path.get("init"), seen);
233
+ }
234
+ function compileProgram(code, filename, options = {}) {
235
+ const ast = parseSource(code, filename);
236
+ const messages = [];
237
+ const analysis = analyzer();
238
+ const plans = [];
239
+ const declarations = [];
240
+ const jsxCallbacks = /* @__PURE__ */ new Set();
241
+ traverse(ast, { CallExpression(path) {
242
+ const callee = path.get("callee");
243
+ if (memberName(callee) !== "jsx") return;
244
+ if (!analysis.resolve(callee.get("object"))) return;
245
+ const callback = resolveJsxCallback(path.get("arguments.0"));
246
+ if (callback) jsxCallbacks.add(callback.node);
247
+ } });
248
+ let program;
249
+ const clientModule = ast.program.directives.some((directive) => directive.value.value === "use client");
250
+ traverse(ast, {
251
+ Program(path) {
252
+ program = path;
253
+ },
254
+ ExportAllDeclaration(path) {
255
+ if (importMap[path.node.source.value]) throw new Error("[i18n] do not re-export the translator in compiled mode; import t directly at each use");
256
+ },
257
+ ExportNamedDeclaration(path) {
258
+ if (path.node.source && importMap[path.node.source.value] && path.node.specifiers.some((specifier) => b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : "") === "t")) throw new Error("[i18n] do not re-export the translator in compiled mode; export message descriptors instead");
259
+ },
260
+ ImportDeclaration(path) {
261
+ if (importMap[path.node.source.value] && path.node.importKind !== "type") declarations.push(path);
262
+ },
263
+ CallExpression(path) {
264
+ const callee = path.get("callee");
265
+ const method = memberName(callee);
266
+ if (!method || ![
267
+ "msg",
268
+ "jsx",
269
+ "text"
270
+ ].includes(method)) return;
271
+ const scope = analysis.resolve(callee.get("object"));
272
+ if (!scope) return;
273
+ if (method === "jsx" && resolveJsxCallback(path.get("arguments.0"))) return;
274
+ const source = literal(path.get("arguments.0"));
275
+ if (source === null && method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
276
+ const callbackOwned = method === "text" && Boolean(path.findParent((parent) => parent.isFunction() && jsxCallbacks.has(parent.node)));
277
+ const reactOwner = options.bindReactText && clientModule && method === "text" && !callbackOwned ? reactFunction(path) : void 0;
278
+ if (options.bindReactText && clientModule && method === "text" && !callbackOwned && !reactOwner) throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: client t.text must be rendered inside a component or hook`);
279
+ plans.push({
280
+ path,
281
+ source,
282
+ scope,
283
+ reactOwner: reactOwner ?? void 0
284
+ });
285
+ if (source !== null) messages.push({
286
+ ...scope,
287
+ source,
288
+ id: scope.context ? `${scope.context}\0${source}` : source
289
+ });
290
+ }
291
+ });
292
+ traverse(ast, {
293
+ VariableDeclarator(path) {
294
+ analysis.resolve(path.get("id"));
295
+ },
296
+ CallExpression(path) {
297
+ const name = memberName(path.get("callee"));
298
+ if (name && [
299
+ "context",
300
+ "note",
301
+ "meta"
302
+ ].includes(name)) analysis.resolve(path);
303
+ }
304
+ });
305
+ const expressionUse = (path) => {
306
+ while (path.parentPath && (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() || path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() || path.parentPath.isParenthesizedExpression())) path = path.parentPath;
307
+ return path;
308
+ };
309
+ for (const path of analysis.scopeCalls) {
310
+ const use = expressionUse(path);
311
+ const parent = use.parentPath;
312
+ if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;
313
+ if (parent?.isMemberExpression() && parent.get("object") === use && parent.parentPath?.isCallExpression()) continue;
314
+ throw new Error("[i18n] scoped translator escapes same-file message calls");
315
+ }
316
+ for (const binding of analysis.scopedBindings) {
317
+ if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) throw new Error("[i18n] scoped translators cannot be exported; repeat the context in the consuming file");
318
+ for (const reference of binding.referencePaths) {
319
+ if (reference.findParent((parent) => parent.isTSType())) continue;
320
+ const use = expressionUse(reference);
321
+ const parent = use.parentPath;
322
+ if (parent?.isVariableDeclarator() && parent.get("init") === use) continue;
323
+ if (parent?.isMemberExpression() && parent.get("object") === use) {
324
+ const method = memberName(parent);
325
+ if (method && [
326
+ "msg",
327
+ "text",
328
+ "jsx",
329
+ "context",
330
+ "note",
331
+ "meta"
332
+ ].includes(method) && parent.parentPath?.isCallExpression()) continue;
333
+ }
334
+ throw new Error("[i18n] scoped translator escapes same-file message calls: " + binding.identifier.name);
335
+ }
336
+ }
337
+ if (!declarations.length) return {
338
+ ast,
339
+ messages,
340
+ changed: false
341
+ };
342
+ const helper = program.scope.generateUidIdentifier("tc");
343
+ const rendererHook = program.scope.generateUidIdentifier("useI18nRenderer");
344
+ const rendererBindings = /* @__PURE__ */ new Map();
345
+ if (plans.length) program.unshiftContainer("body", b.importDeclaration([b.importSpecifier(helper, b.identifier("t"))], b.stringLiteral("@fluentic/i18n/compiled")));
346
+ if (plans.some((plan) => plan.reactOwner)) {
347
+ program.unshiftContainer("body", b.importDeclaration([b.importSpecifier(rendererHook, b.identifier("useI18nRenderer"))], b.stringLiteral("@fluentic/i18n/react")));
348
+ for (const owner of new Set(plans.map((plan) => plan.reactOwner).filter(Boolean))) {
349
+ const binding = owner.scope.generateUidIdentifier("text");
350
+ rendererBindings.set(owner, binding);
351
+ const body = owner.get("body");
352
+ if (!body.isBlockStatement()) {
353
+ const expression = body.node;
354
+ body.replaceWith(b.blockStatement([b.returnStatement(expression)]));
355
+ }
356
+ owner.get("body").unshiftContainer("body", b.variableDeclaration("const", [b.variableDeclarator(b.cloneNode(binding), b.callExpression(b.cloneNode(rendererHook), [b.memberExpression(b.cloneNode(helper), b.identifier("text"))]))]));
357
+ }
358
+ }
359
+ for (const { path, source, scope, reactOwner } of plans) {
360
+ const callee = path.get("callee");
361
+ const renderer = reactOwner && rendererBindings.get(reactOwner);
362
+ if (renderer) callee.replaceWith(b.cloneNode(renderer));
363
+ else callee.get("object").replaceWith(b.cloneNode(helper));
364
+ if (source !== null) {
365
+ const replacement = b.valueToNode([messageId(scope.context, source, hashLength(options.hashLength)), compileMessage(source)]);
366
+ b.inherits(replacement, path.node.arguments[0]);
367
+ path.node.arguments[0] = replacement;
368
+ }
369
+ }
370
+ let removed = true;
371
+ while (removed) {
372
+ removed = false;
373
+ program.scope.crawl();
374
+ for (const binding of analysis.scopedBindings) {
375
+ if (binding.path.removed) continue;
376
+ const current = binding.path.scope.getBinding(binding.identifier.name);
377
+ if (current && !current.referenced) {
378
+ binding.path.remove();
379
+ removed = true;
380
+ }
381
+ }
382
+ }
383
+ for (const path of analysis.scopeCalls) if (!path.removed) {
384
+ const use = expressionUse(path);
385
+ if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();
386
+ }
387
+ for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];
388
+ program.scope.crawl();
389
+ for (const declaration of declarations) {
390
+ declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {
391
+ if (!b.isImportSpecifier(specifier) || (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== "t") return true;
392
+ return Boolean(program.scope.getBinding(specifier.local.name)?.referenced);
393
+ });
394
+ if (!declaration.node.specifiers.length) declaration.remove();
395
+ }
396
+ return {
397
+ ast,
398
+ messages,
399
+ changed: true
400
+ };
401
+ }
402
+ function transform(code, options = {}) {
403
+ const filename = options.filename ?? "source.tsx";
404
+ const result = compileProgram(code, filename, options);
405
+ if (!result.changed) return null;
406
+ const output = generate(result.ast, {
407
+ sourceMaps: true,
408
+ sourceFileName: filename,
409
+ comments: true
410
+ }, code);
411
+ return {
412
+ code: output.code,
413
+ map: output.map,
414
+ messages: result.messages
415
+ };
416
+ }
417
+ export { compileMessage as a, collectMessages as c, compileCatalog as i, traverse as l, transform as n, messageId as o, COMPACT_VERSION as r, messageIdentity as s, compileProgram as t };
418
+
419
+ //# sourceMappingURL=src-ZYntx97W.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-ZYntx97W.mjs","names":["parse"],"sources":["../src/analyze.ts","../src/message.ts","../src/index.ts"],"sourcesContent":["import { parse } from '@babel/parser';\nimport * as traverseModule from '@babel/traverse';\nimport type { Binding, NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\nimport { normalizeMessage } from '@fluentic/i18n/compiler-support';\n\nconst traverse = ((traverseModule.default as unknown as { default?: typeof traverseModule.default; }).default ??\n traverseModule.default) as typeof traverseModule.default;\nexport { traverse };\n\nexport const importMap: Record<string, string> = {\n '@fluentic/i18n': '@fluentic/i18n/compiled',\n '@fluentic/i18n/core': '@fluentic/i18n/compiled',\n};\nexport type Scope = { context: string | null; notes: string[]; meta?: unknown; };\nexport type ExtractedMessage = Scope & { id: string; source: string; };\n\nexport function parseSource(code: string, filename: string) {\n return parse(code, {\n sourceFilename: filename,\n sourceType: 'unambiguous',\n plugins: [\n ...(/\\.[cm]?tsx?$/.test(filename) ? ['typescript' as const] : []),\n ...(!/\\.[cm]?ts$/.test(filename) ? ['jsx' as const] : []),\n 'decorators-legacy',\n 'importAttributes',\n ],\n });\n}\n\nexport function unwrap(path: NodePath): NodePath {\n while (\n path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() ||\n path.isTypeCastExpression() || path.isParenthesizedExpression()\n ) path = path.get('expression') as NodePath;\n\n return path;\n}\n\nexport function literal(path: NodePath, seen = new Set<Binding>()): string | null {\n path = unwrap(path);\n if (path.isStringLiteral()) return normalizeMessage(path.node.value);\n if (path.isTemplateLiteral() && !path.node.expressions.length) {\n return normalizeMessage(path.node.quasis[0].value.cooked ?? '');\n }\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {\n seen.add(binding);\n\n return literal(binding.path.get('init') as NodePath, seen);\n }\n }\n\n return null;\n}\n\nexport function memberName(path: NodePath): string | null {\n if (!path.isMemberExpression()) return null;\n\n const property = path.get('property');\n\n return !path.node.computed && property.isIdentifier()\n ? property.node.name\n : property.isStringLiteral()\n ? property.node.value\n : null;\n}\n\nexport function analyzer(imports = Object.keys(importMap)) {\n const memo = new Map<Binding, Scope | null>();\n const scopedBindings = new Set<Binding>();\n const scopeCalls = new Set<NodePath>();\n\n const resolve = (path: NodePath, visiting = new Set<Binding>()): Scope | null => {\n path = unwrap(path);\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (!binding) return null;\n if (memo.has(binding)) return memo.get(binding)!;\n if (visiting.has(binding)) throw new Error('[i18n] circular translator alias');\n if (binding.path.isImportSpecifier()) {\n const declaration = binding.path.parentPath;\n const imported = binding.path.node.imported;\n\n return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) &&\n (b.isIdentifier(imported) ? imported.name : imported.value) === 't' &&\n declaration.node.importKind !== 'type'\n ? { context: null, notes: [] }\n : null;\n }\n if (binding.path.isVariableDeclarator()) {\n visiting.add(binding);\n const scope = resolve(binding.path.get('init') as NodePath, visiting);\n visiting.delete(binding);\n if (scope && !binding.constant) {\n throw new Error('[i18n] translator aliases must not be reassigned: ' + path.node.name);\n }\n memo.set(binding, scope);\n if (scope) scopedBindings.add(binding);\n\n return scope;\n }\n\n return null;\n }\n if (path.isMemberExpression() && memberName(path) === 't') {\n const object = path.get('object');\n\n if (!object.isIdentifier()) return null;\n\n const binding = object.scope.getBinding(object.node.name);\n const declaration = binding?.path.parentPath;\n\n if (\n binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() &&\n imports.includes(declaration.node.source.value)\n ) return { context: null, notes: [] };\n }\n if (!path.isCallExpression()) return null;\n\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['context', 'note', 'meta'].includes(method)) return null;\n\n const parent = resolve((callee as NodePath<b.MemberExpression>).get('object'), visiting);\n\n if (!parent) return null;\n if (path.node.arguments.length !== 1) throw new Error('[i18n] scope methods require one static argument');\n\n const argument = path.get('arguments.0') as NodePath;\n scopeCalls.add(path);\n if (method === 'meta') {\n const evaluated = argument.evaluate();\n\n if (!evaluated.confident) throw new Error('[i18n] metadata must be statically known');\n\n return { ...parent, meta: evaluated.value };\n }\n\n const value = literal(argument);\n\n if (value === null) throw new Error('[i18n] ' + method + ' must be a static string');\n\n return method === 'note'\n ? { ...parent, notes: [...parent.notes, value] }\n : { ...parent, context: parent.context ? `${parent.context}.${value}` : value };\n };\n\n return { resolve, scopedBindings, scopeCalls };\n}\n\nexport function collectMessages(code: string, filename: string, imports?: string[]): ExtractedMessage[] {\n const ast = parseSource(code, filename);\n const { resolve } = analyzer(imports);\n const messages: ExtractedMessage[] = [];\n traverse(ast, {\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'text', 'jsx'].includes(method)) return;\n\n const scope = resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null) {\n if (method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n\n return;\n }\n messages.push({ ...scope, id: scope.context ? `${scope.context}\\0${source}` : source, source });\n },\n });\n\n return [...new Map(messages.map((message) => [message.id, message])).values()];\n}\n","import {\n type CompactMessage,\n type CompactPart,\n DEFAULT_HASH_LENGTH,\n messageHash,\n normalizeMessage,\n} from '@fluentic/i18n/compiler-support';\nimport { type MessageFormatElement, parse, TYPE } from '@formatjs/icu-messageformat-parser';\n\nexport { COMPACT_VERSION } from '@fluentic/i18n/compiler-support';\n\nexport function messageIdentity(context: string | null, source: string): string {\n source = normalizeMessage(source);\n return context ? `${context}\\0${source}` : source;\n}\n\nexport function messageId(context: string | null, source: string, hashLength = DEFAULT_HASH_LENGTH): string {\n return messageHash(messageIdentity(context, source), hashLength);\n}\n\nexport function compileMessage(source: string): CompactMessage {\n source = normalizeMessage(source);\n const compact = (elements: MessageFormatElement[]): CompactMessage => {\n const result: CompactPart[] = elements.map((element): CompactPart => {\n switch (element.type) {\n case TYPE.literal:\n return element.value;\n case TYPE.argument:\n return [0, element.value];\n case TYPE.number:\n case TYPE.date:\n case TYPE.time:\n return [\n element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,\n element.value,\n typeof element.style === 'object' && element.style\n ? element.style.parsedOptions as Record<string, unknown>\n : element.style ?? null,\n ];\n case TYPE.select:\n return [\n 4,\n element.value,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.plural:\n return [\n 5,\n element.value,\n element.offset,\n element.pluralType === 'ordinal' ? 1 : 0,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.pound:\n return [6];\n case TYPE.tag:\n return [7, element.value, compact(element.children)];\n }\n });\n\n return result.every((part) => typeof part === 'string') ? result.join('') : result;\n };\n\n return compact(parse(source, { captureLocation: false }));\n}\n\nexport function compileCatalog(\n records: Array<{ source: string; context: string | null; translation: string; }>,\n options: { hashLength?: number; } = {},\n): Array<[string, CompactMessage]> {\n const seen = new Map<string, string>();\n\n return records.flatMap((record) => {\n const id = messageId(record.context, record.source, options.hashLength);\n const identity = messageIdentity(record.context, record.source);\n\n if (seen.has(id) && seen.get(id) !== identity) throw new Error('[i18n] message hash collision: ' + id);\n seen.set(id, identity);\n\n return record.translation === '' ? [] : [[id, compileMessage(record.translation)] as [string, CompactMessage]];\n });\n}\n","import * as generatorModule from '@babel/generator';\nimport type { NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\nimport { DEFAULT_HASH_LENGTH, normalizeHashLength } from '@fluentic/i18n/compiler-support';\nimport {\n analyzer,\n collectMessages,\n type ExtractedMessage,\n importMap,\n literal,\n memberName,\n parseSource,\n traverse,\n} from './analyze';\nimport { compileMessage, messageId } from './message';\n\nexport { collectMessages } from './analyze';\nexport * from './message';\n\nconst generate = ((generatorModule.default as unknown as { default?: typeof generatorModule.default; }).default ??\n generatorModule.default) as typeof generatorModule.default;\nexport type CompiledOptions = { hashLength?: number; };\nexport type CompilerOptions = CompiledOptions & { filename?: string; bindReactText?: boolean; };\n\ntype FunctionPath = NodePath<\n b.ArrowFunctionExpression | b.FunctionDeclaration | b.FunctionExpression | b.ObjectMethod | b.ClassMethod\n>;\n\nfunction reactFunction(path: NodePath): FunctionPath | null {\n for (\n let current = path.findParent((parent) => parent.isFunction());\n current;\n current = current.findParent(\n (parent) => parent.isFunction(),\n )\n ) {\n const fn = current as FunctionPath;\n const parent = fn.parentPath;\n const ownName = (b.isFunctionDeclaration(fn.node) || b.isFunctionExpression(fn.node)) ? fn.node.id?.name : null;\n const variableId = parent?.isVariableDeclarator() ? parent.get('id') : null;\n const name = ownName ?? (variableId?.isIdentifier() ? variableId.node.name : null);\n const exported = parent?.isExportDefaultDeclaration();\n\n if (exported || (name && (/^[A-Z]/.test(name) || /^use[A-Z]/.test(name)))) return fn;\n }\n\n return null;\n}\n\nfunction hashLength(length: CompilerOptions['hashLength']): number {\n return normalizeHashLength(length ?? DEFAULT_HASH_LENGTH);\n}\n\nfunction resolveJsxCallback(path: NodePath, seen = new Set<unknown>()): FunctionPath | null {\n while (\n path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() ||\n path.isTypeCastExpression() || path.isParenthesizedExpression()\n ) path = path.get('expression') as NodePath;\n if (path.isArrowFunctionExpression() || path.isFunctionExpression() || path.isFunctionDeclaration()) {\n return path as FunctionPath;\n }\n if (!path.isIdentifier()) return null;\n const binding = path.scope.getBinding(path.node.name);\n if (!binding?.constant || seen.has(binding)) return null;\n seen.add(binding);\n if (binding.path.isFunctionDeclaration()) return binding.path as FunctionPath;\n if (!binding.path.isVariableDeclarator()) return null;\n return resolveJsxCallback(binding.path.get('init') as NodePath, seen);\n}\n\nexport function compileProgram(code: string, filename: string, options: CompilerOptions = {}) {\n const ast = parseSource(code, filename);\n const messages: ExtractedMessage[] = [];\n\n const analysis = analyzer();\n\n const plans: Array<\n {\n path: NodePath<b.CallExpression>;\n source: string | null;\n scope: NonNullable<ReturnType<typeof analysis.resolve>>;\n reactOwner?: FunctionPath;\n }\n > = [];\n const declarations: NodePath<b.ImportDeclaration>[] = [];\n const jsxCallbacks = new Set<b.Function>();\n\n traverse(ast, {\n CallExpression(path) {\n const callee = path.get('callee');\n if (memberName(callee) !== 'jsx') return;\n const scope = analysis.resolve((callee as NodePath<b.MemberExpression>).get('object'));\n if (!scope) return;\n const callback = resolveJsxCallback(path.get('arguments.0') as NodePath);\n if (callback) jsxCallbacks.add(callback.node);\n },\n });\n\n let program: NodePath<b.Program> | undefined;\n const clientModule = ast.program.directives.some((directive) => directive.value.value === 'use client');\n traverse(ast, {\n Program(path) {\n program = path;\n },\n ExportAllDeclaration(path) {\n if (importMap[path.node.source.value]) {\n throw new Error('[i18n] do not re-export the translator in compiled mode; import t directly at each use');\n }\n },\n ExportNamedDeclaration(path) {\n if (\n path.node.source && importMap[path.node.source.value] &&\n path.node.specifiers.some((specifier) =>\n b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : '') === 't'\n )\n ) throw new Error('[i18n] do not re-export the translator in compiled mode; export message descriptors instead');\n },\n ImportDeclaration(path) {\n if (importMap[path.node.source.value] && path.node.importKind !== 'type') declarations.push(path);\n },\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'jsx', 'text'].includes(method)) return;\n\n const scope = analysis.resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n if (method === 'jsx' && resolveJsxCallback(path.get('arguments.0') as NodePath)) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null && method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n const callbackOwned = method === 'text' && Boolean(\n path.findParent((parent) => parent.isFunction() && jsxCallbacks.has(parent.node as b.Function)),\n );\n const reactOwner = options.bindReactText && clientModule && method === 'text' && !callbackOwned\n ? reactFunction(path)\n : undefined;\n if (options.bindReactText && clientModule && method === 'text' && !callbackOwned && !reactOwner) {\n throw new Error(\n `[i18n] ${filename}:${path.node.loc?.start.line}: client t.text must be rendered inside a component or hook`,\n );\n }\n plans.push({ path, source, scope, reactOwner: reactOwner ?? undefined });\n if (source !== null) {\n messages.push({ ...scope, source, id: scope.context ? `${scope.context}\\0${source}` : source });\n }\n },\n });\n // Discover unused/escaping scopes as well as scopes reached by message calls.\n traverse(ast, {\n VariableDeclarator(path) {\n analysis.resolve(path.get('id') as NodePath);\n },\n CallExpression(path) {\n const name = memberName(path.get('callee'));\n\n if (name && ['context', 'note', 'meta'].includes(name)) analysis.resolve(path);\n },\n });\n const expressionUse = (path: NodePath): NodePath => {\n while (\n path.parentPath &&\n (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() ||\n path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() ||\n path.parentPath.isParenthesizedExpression())\n ) path = path.parentPath;\n\n return path;\n };\n\n for (const path of analysis.scopeCalls) {\n const use = expressionUse(path);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use && parent.parentPath?.isCallExpression()) continue;\n throw new Error('[i18n] scoped translator escapes same-file message calls');\n }\n for (const binding of analysis.scopedBindings) {\n if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) {\n throw new Error('[i18n] scoped translators cannot be exported; repeat the context in the consuming file');\n }\n\n for (const reference of binding.referencePaths) {\n if (reference.findParent((parent) => parent.isTSType())) continue;\n\n const use = expressionUse(reference);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() && parent.get('init') === use) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use) {\n const method = memberName(parent);\n\n if (\n method && ['msg', 'text', 'jsx', 'context', 'note', 'meta'].includes(method) &&\n parent.parentPath?.isCallExpression()\n ) continue;\n }\n throw new Error('[i18n] scoped translator escapes same-file message calls: ' + binding.identifier.name);\n }\n }\n if (!declarations.length) return { ast, messages, changed: false };\n\n const helper = program!.scope.generateUidIdentifier('tc');\n const rendererHook = program!.scope.generateUidIdentifier('useI18nRenderer');\n const rendererBindings = new Map<FunctionPath, b.Identifier>();\n\n if (plans.length) {\n program!.unshiftContainer(\n 'body',\n b.importDeclaration([b.importSpecifier(helper, b.identifier('t'))], b.stringLiteral('@fluentic/i18n/compiled')),\n );\n }\n if (plans.some((plan) => plan.reactOwner)) {\n program!.unshiftContainer(\n 'body',\n b.importDeclaration(\n [b.importSpecifier(rendererHook, b.identifier('useI18nRenderer'))],\n b.stringLiteral('@fluentic/i18n/react'),\n ),\n );\n for (const owner of new Set(plans.map((plan) => plan.reactOwner).filter(Boolean) as FunctionPath[])) {\n const binding = owner.scope.generateUidIdentifier('text');\n rendererBindings.set(owner, binding);\n const body = owner.get('body');\n if (!body.isBlockStatement()) {\n const expression = body.node as b.Expression;\n body.replaceWith(b.blockStatement([b.returnStatement(expression)]));\n }\n (owner.get('body') as NodePath<b.BlockStatement>).unshiftContainer(\n 'body',\n b.variableDeclaration('const', [\n b.variableDeclarator(\n b.cloneNode(binding),\n b.callExpression(b.cloneNode(rendererHook), [\n b.memberExpression(b.cloneNode(helper), b.identifier('text')),\n ]),\n ),\n ]),\n );\n }\n }\n\n for (const { path, source, scope, reactOwner } of plans) {\n const callee = path.get('callee') as NodePath<b.MemberExpression>;\n const renderer = reactOwner && rendererBindings.get(reactOwner);\n if (renderer) callee.replaceWith(b.cloneNode(renderer));\n else callee.get('object').replaceWith(b.cloneNode(helper));\n if (source !== null) {\n const replacement = b.valueToNode([\n messageId(scope.context, source, hashLength(options.hashLength)),\n compileMessage(source),\n ]);\n b.inherits(replacement, path.node.arguments[0]);\n path.node.arguments[0] = replacement;\n }\n }\n // All scope uses were checked before mutation. Remove aliases from leaves to roots.\n let removed = true;\n\n while (removed) {\n removed = false;\n program!.scope.crawl();\n\n for (const binding of analysis.scopedBindings) {\n if (binding.path.removed) continue;\n\n const current = binding.path.scope.getBinding(binding.identifier.name);\n\n if (current && !current.referenced) {\n binding.path.remove();\n removed = true;\n }\n }\n }\n\n for (const path of analysis.scopeCalls) {\n if (!path.removed) {\n const use = expressionUse(path);\n\n if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();\n }\n }\n for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];\n program!.scope.crawl();\n\n for (const declaration of declarations) {\n declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {\n if (\n !b.isImportSpecifier(specifier) ||\n (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== 't'\n ) return true;\n\n return Boolean(program!.scope.getBinding(specifier.local.name)?.referenced);\n });\n if (!declaration.node.specifiers.length) declaration.remove();\n }\n\n return { ast, messages, changed: true };\n}\n\nexport function transform(code: string, options: CompilerOptions = {}) {\n const filename = options.filename ?? 'source.tsx';\n const result = compileProgram(code, filename, options);\n\n if (!result.changed) return null;\n\n const output = generate(result.ast, { sourceMaps: true, sourceFileName: filename, comments: true }, code);\n\n return { code: output.code, map: output.map, messages: result.messages };\n}\n"],"mappings":";;;;;;;AAMA,MAAM,WAAa,eAAe,QAAoE,WACpG,eAAe;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,QAAS,MAAM,WAAW,UAAU,MAAM,IAAI,CAAC,EAAE,UAAU;EAC5E,CAAC;EACD,IAAI,CAAC,YAAY,KAAK,WAAW,QAAQ,YAAY,OAAO;CAC9D;CAEA,OAAO;EAAE;EAAK;EAAU,SAAS;CAAK;AACxC;AAEA,SAAgB,UAAU,MAAc,UAA2B,CAAC,GAAG;CACrE,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,SAAS,eAAe,MAAM,UAAU,OAAO;CAErD,IAAI,CAAC,OAAO,SAAS,OAAO;CAE5B,MAAM,SAAS,SAAS,OAAO,KAAK;EAAE,YAAY;EAAM,gBAAgB;EAAU,UAAU;CAAK,GAAG,IAAI;CAExG,OAAO;EAAE,MAAM,OAAO;EAAM,KAAK,OAAO;EAAK,UAAU,OAAO;CAAS;AACzE"}
package/dist/vite.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { PluginOptions } from './options';
2
+ export default function fluentic(options?: PluginOptions): {
3
+ name: string;
4
+ buildStart(this: {
5
+ addWatchFile(file: string): void;
6
+ }): void;
7
+ watchChange(id: string): void;
8
+ transform(code: string, id: string): {
9
+ code: string;
10
+ map: {
11
+ version: number;
12
+ sources: string[];
13
+ names: string[];
14
+ sourceRoot?: string | undefined;
15
+ sourcesContent?: string[] | undefined;
16
+ mappings: string;
17
+ file: string;
18
+ } | null;
19
+ messages: import("./analyze").ExtractedMessage[];
20
+ } | null;
21
+ enforce: 'pre';
22
+ };
package/dist/vite.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import fluentic$1 from "./rollup.mjs";
2
+ // src/vite.ts
3
+ function fluentic(options = {}) {
4
+ return {
5
+ ...fluentic$1(options),
6
+ enforce: "pre"
7
+ };
8
+ }
9
+ export { fluentic as default };
10
+
11
+ //# sourceMappingURL=vite.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.mjs","names":["rollup"],"sources":["../src/vite.ts"],"sourcesContent":["import type { PluginOptions } from './options';\nimport rollup from './rollup';\n\nexport default function fluentic(options: PluginOptions = {}) {\n // Vite uses the Rollup-compatible compiler adapter.\n return { ...rollup(options), enforce: 'pre' as const };\n}\n"],"mappings":";;AAGA,SAAwB,SAAS,UAAyB,CAAC,GAAG;CAE5D,OAAO;EAAE,GAAGA,WAAO,OAAO;EAAG,SAAS;CAAe;AACvD"}
@@ -0,0 +1 @@
1
+ export default function loader(this: any, code: string, inputMap: unknown): void;
@@ -0,0 +1,17 @@
1
+ import { n as transform } from "./src-ZYntx97W.mjs";
2
+ import { n as loadOptions } from "./options-WZfxnYkT.mjs";
3
+ import remapping from "@jridgewell/remapping";
4
+ // src/webpack-loader.ts
5
+ function loader(code, inputMap) {
6
+ this.cacheable?.();
7
+ const options = loadOptions(this.getOptions?.() ?? {}, this.rootContext);
8
+ if (options.configFile) this.addDependency(options.configFile);
9
+ const result = transform(code, {
10
+ filename: this.resourcePath,
11
+ ...options
12
+ });
13
+ this.callback(null, result?.code ?? code, result?.map && inputMap ? remapping([result.map, inputMap], () => null) : result?.map ?? inputMap);
14
+ }
15
+ export { loader as default };
16
+
17
+ //# sourceMappingURL=webpack-loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack-loader.mjs","names":[],"sources":["../src/webpack-loader.ts"],"sourcesContent":["import remapping from '@jridgewell/remapping';\nimport { transform } from './index';\nimport { loadOptions } from './options';\n\nexport default function loader(this: any, code: string, inputMap: unknown) {\n this.cacheable?.();\n const options = loadOptions(this.getOptions?.() ?? {}, this.rootContext);\n\n if (options.configFile) this.addDependency(options.configFile);\n\n const result = transform(code, { filename: this.resourcePath, ...options });\n this.callback(\n null,\n result?.code ?? code,\n result?.map && inputMap ? remapping([result.map as any, inputMap as any], () => null) : result?.map ?? inputMap,\n );\n}\n"],"mappings":";;;;AAIA,SAAwB,OAAkB,MAAc,UAAmB;CACzE,KAAK,YAAY;CACjB,MAAM,UAAU,YAAY,KAAK,aAAa,KAAK,CAAC,GAAG,KAAK,WAAW;CAEvE,IAAI,QAAQ,YAAY,KAAK,cAAc,QAAQ,UAAU;CAE7D,MAAM,SAAS,UAAU,MAAM;EAAE,UAAU,KAAK;EAAc,GAAG;CAAQ,CAAC;CAC1E,KAAK,SACH,MACA,QAAQ,QAAQ,MAChB,QAAQ,OAAO,WAAW,UAAU,CAAC,OAAO,KAAY,QAAe,SAAS,IAAI,IAAI,QAAQ,OAAO,QACzG;AACF"}
@@ -0,0 +1,6 @@
1
+ import type { PluginOptions } from './options';
2
+ export default class FluenticI18nPlugin {
3
+ private options;
4
+ constructor(options?: PluginOptions);
5
+ apply(compiler: any): void;
6
+ }
@@ -0,0 +1,22 @@
1
+ import { createRequire } from "node:module";
2
+ // src/webpack.ts
3
+ const require = createRequire(import.meta.url);
4
+ var FluenticI18nPlugin = class {
5
+ constructor(options = {}) {
6
+ this.options = options;
7
+ }
8
+ apply(compiler) {
9
+ compiler.options.module.rules.push({
10
+ test: /\.[cm]?[jt]sx?$/,
11
+ enforce: "pre",
12
+ ...this.options.includeDependencies ? {} : { exclude: /node_modules/ },
13
+ use: [{
14
+ loader: require.resolve("@fluentic/i18n-compiler/webpack-loader"),
15
+ options: this.options
16
+ }]
17
+ });
18
+ }
19
+ };
20
+ export { FluenticI18nPlugin as default };
21
+
22
+ //# sourceMappingURL=webpack.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.mjs","names":[],"sources":["../src/webpack.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type { PluginOptions } from './options';\n\nconst require = createRequire(import.meta.url);\nexport default class FluenticI18nPlugin {\n constructor(private options: PluginOptions = {}) {}\n apply(compiler: any) {\n compiler.options.module.rules.push({\n test: /\\.[cm]?[jt]sx?$/,\n enforce: 'pre',\n ...(this.options.includeDependencies ? {} : { exclude: /node_modules/ }),\n use: [{ loader: require.resolve('@fluentic/i18n-compiler/webpack-loader'), options: this.options }],\n });\n }\n}\n"],"mappings":";;AAGA,MAAM,UAAU,cAAc,YAAY,GAAG;AAC7C,IAAqB,qBAArB,MAAwC;CACtC,YAAY,UAAiC,CAAC,GAAG;EAA7B,KAAA,UAAA;CAA8B;CAClD,MAAM,UAAe;EACnB,SAAS,QAAQ,OAAO,MAAM,KAAK;GACjC,MAAM;GACN,SAAS;GACT,GAAI,KAAK,QAAQ,sBAAsB,CAAC,IAAI,EAAE,SAAS,eAAe;GACtE,KAAK,CAAC;IAAE,QAAQ,QAAQ,QAAQ,wCAAwC;IAAG,SAAS,KAAK;GAAQ,CAAC;EACpG,CAAC;CACH;AACF"}