flowpilot 0.0.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.
- package/README.md +203 -0
- package/dist/cli.js +32174 -0
- package/dist/client/chunks/client-Bb-xh-5_.js +356 -0
- package/dist/client/chunks/client-DSXtnba0.js +1399 -0
- package/dist/client/chunks/client-oAYP8wOx.js +1574 -0
- package/dist/client/chunks/jsx-dev-runtime-DGBfem3G.js +3704 -0
- package/dist/client/chunks/search-cPm8k8mK.js +20 -0
- package/dist/client/client.js +36 -0
- package/dist/public/android-chrome-192x192.png +0 -0
- package/dist/public/android-chrome-512x512.png +0 -0
- package/dist/public/apple-touch-icon.png +0 -0
- package/dist/public/favicon-16x16.png +0 -0
- package/dist/public/favicon-32x32.png +0 -0
- package/dist/public/favicon.ico +0 -0
- package/dist/public/site.webmanifest +19 -0
- package/dist/serve.js +19545 -0
- package/dist/server.js +19580 -0
- package/favicon/android-chrome-192x192.png +0 -0
- package/favicon/android-chrome-512x512.png +0 -0
- package/favicon/apple-touch-icon.png +0 -0
- package/favicon/favicon-16x16.png +0 -0
- package/favicon/favicon-32x32.png +0 -0
- package/favicon/favicon.ico +0 -0
- package/favicon/site.webmanifest +19 -0
- package/package.json +62 -0
|
@@ -0,0 +1,3704 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/utils/html.js
|
|
14
|
+
var HtmlEscapedCallbackPhase = {
|
|
15
|
+
Stringify: 1,
|
|
16
|
+
BeforeStream: 2,
|
|
17
|
+
Stream: 3
|
|
18
|
+
};
|
|
19
|
+
var raw = (value, callbacks) => {
|
|
20
|
+
const escapedString = new String(value);
|
|
21
|
+
escapedString.isEscaped = true;
|
|
22
|
+
escapedString.callbacks = callbacks;
|
|
23
|
+
return escapedString;
|
|
24
|
+
};
|
|
25
|
+
var escapeRe = /[&<>'"]/;
|
|
26
|
+
var stringBufferToString = async (buffer, callbacks) => {
|
|
27
|
+
let str = "";
|
|
28
|
+
callbacks ||= [];
|
|
29
|
+
const resolvedBuffer = await Promise.all(buffer);
|
|
30
|
+
for (let i = resolvedBuffer.length - 1;; i--) {
|
|
31
|
+
str += resolvedBuffer[i];
|
|
32
|
+
i--;
|
|
33
|
+
if (i < 0) break;
|
|
34
|
+
let r = resolvedBuffer[i];
|
|
35
|
+
if (typeof r === "object") callbacks.push(...r.callbacks || []);
|
|
36
|
+
const isEscaped = r.isEscaped;
|
|
37
|
+
r = await (typeof r === "object" ? r.toString() : r);
|
|
38
|
+
if (typeof r === "object") callbacks.push(...r.callbacks || []);
|
|
39
|
+
if (r.isEscaped ?? isEscaped) str += r;
|
|
40
|
+
else {
|
|
41
|
+
const buf = [str];
|
|
42
|
+
escapeToBuffer(r, buf);
|
|
43
|
+
str = buf[0];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return raw(str, callbacks);
|
|
47
|
+
};
|
|
48
|
+
var escapeToBuffer = (str, buffer) => {
|
|
49
|
+
const match = str.search(escapeRe);
|
|
50
|
+
if (match === -1) {
|
|
51
|
+
buffer[0] += str;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let escape;
|
|
55
|
+
let index;
|
|
56
|
+
let lastIndex = 0;
|
|
57
|
+
for (index = match; index < str.length; index++) {
|
|
58
|
+
switch (str.charCodeAt(index)) {
|
|
59
|
+
case 34:
|
|
60
|
+
escape = """;
|
|
61
|
+
break;
|
|
62
|
+
case 39:
|
|
63
|
+
escape = "'";
|
|
64
|
+
break;
|
|
65
|
+
case 38:
|
|
66
|
+
escape = "&";
|
|
67
|
+
break;
|
|
68
|
+
case 60:
|
|
69
|
+
escape = "<";
|
|
70
|
+
break;
|
|
71
|
+
case 62:
|
|
72
|
+
escape = ">";
|
|
73
|
+
break;
|
|
74
|
+
default: continue;
|
|
75
|
+
}
|
|
76
|
+
buffer[0] += str.substring(lastIndex, index) + escape;
|
|
77
|
+
lastIndex = index + 1;
|
|
78
|
+
}
|
|
79
|
+
buffer[0] += str.substring(lastIndex, index);
|
|
80
|
+
};
|
|
81
|
+
var resolveCallbackSync = (str) => {
|
|
82
|
+
const callbacks = str.callbacks;
|
|
83
|
+
if (!callbacks?.length) return str;
|
|
84
|
+
const buffer = [str];
|
|
85
|
+
const context = {};
|
|
86
|
+
callbacks.forEach((c) => c({
|
|
87
|
+
phase: HtmlEscapedCallbackPhase.Stringify,
|
|
88
|
+
buffer,
|
|
89
|
+
context
|
|
90
|
+
}));
|
|
91
|
+
return buffer[0];
|
|
92
|
+
};
|
|
93
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
94
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
95
|
+
if (!(str instanceof Promise)) str = str.toString();
|
|
96
|
+
if (str instanceof Promise) str = await str;
|
|
97
|
+
}
|
|
98
|
+
const callbacks = str.callbacks;
|
|
99
|
+
if (!callbacks?.length) return Promise.resolve(str);
|
|
100
|
+
if (buffer) buffer[0] += str;
|
|
101
|
+
else buffer = [str];
|
|
102
|
+
const resStr = Promise.all(callbacks.map((c) => c({
|
|
103
|
+
phase,
|
|
104
|
+
buffer,
|
|
105
|
+
context
|
|
106
|
+
}))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
|
|
107
|
+
if (preserveCallbacks) return raw(await resStr, callbacks);
|
|
108
|
+
else return resStr;
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/constants.js
|
|
112
|
+
var DOM_RENDERER = /* @__PURE__ */ Symbol("RENDERER");
|
|
113
|
+
var DOM_ERROR_HANDLER = /* @__PURE__ */ Symbol("ERROR_HANDLER");
|
|
114
|
+
var DOM_STASH = /* @__PURE__ */ Symbol("STASH");
|
|
115
|
+
var DOM_INTERNAL_TAG = /* @__PURE__ */ Symbol("INTERNAL");
|
|
116
|
+
var DOM_MEMO = /* @__PURE__ */ Symbol("MEMO");
|
|
117
|
+
var PERMALINK = /* @__PURE__ */ Symbol("PERMALINK");
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/dom/utils.js
|
|
120
|
+
var setInternalTagFlag = (fn) => {
|
|
121
|
+
fn[DOM_INTERNAL_TAG] = true;
|
|
122
|
+
return fn;
|
|
123
|
+
};
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/dom/context.js
|
|
126
|
+
var createContextProviderFunction = (values) => ({ value, children }) => {
|
|
127
|
+
if (!children) return;
|
|
128
|
+
const props = { children: [{
|
|
129
|
+
tag: setInternalTagFlag(() => {
|
|
130
|
+
values.push(value);
|
|
131
|
+
}),
|
|
132
|
+
props: {}
|
|
133
|
+
}] };
|
|
134
|
+
if (Array.isArray(children)) props.children.push(...children.flat());
|
|
135
|
+
else props.children.push(children);
|
|
136
|
+
props.children.push({
|
|
137
|
+
tag: setInternalTagFlag(() => {
|
|
138
|
+
values.pop();
|
|
139
|
+
}),
|
|
140
|
+
props: {}
|
|
141
|
+
});
|
|
142
|
+
const res = {
|
|
143
|
+
tag: "",
|
|
144
|
+
props,
|
|
145
|
+
type: ""
|
|
146
|
+
};
|
|
147
|
+
res[DOM_ERROR_HANDLER] = (err) => {
|
|
148
|
+
values.pop();
|
|
149
|
+
throw err;
|
|
150
|
+
};
|
|
151
|
+
return res;
|
|
152
|
+
};
|
|
153
|
+
var createContext$1 = (defaultValue) => {
|
|
154
|
+
const values = [defaultValue];
|
|
155
|
+
const context = createContextProviderFunction(values);
|
|
156
|
+
context.values = values;
|
|
157
|
+
context.Provider = context;
|
|
158
|
+
globalContexts.push(context);
|
|
159
|
+
return context;
|
|
160
|
+
};
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/context.js
|
|
163
|
+
var globalContexts = [];
|
|
164
|
+
var createContext = (defaultValue) => {
|
|
165
|
+
const values = [defaultValue];
|
|
166
|
+
const context = ((props) => {
|
|
167
|
+
values.push(props.value);
|
|
168
|
+
let string;
|
|
169
|
+
try {
|
|
170
|
+
string = props.children ? (Array.isArray(props.children) ? new JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
|
|
171
|
+
} catch (e) {
|
|
172
|
+
values.pop();
|
|
173
|
+
throw e;
|
|
174
|
+
}
|
|
175
|
+
if (string instanceof Promise) return string.finally(() => values.pop()).then((resString) => raw(resString, resString.callbacks));
|
|
176
|
+
else {
|
|
177
|
+
values.pop();
|
|
178
|
+
return raw(string);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
context.values = values;
|
|
182
|
+
context.Provider = context;
|
|
183
|
+
context[DOM_RENDERER] = createContextProviderFunction(values);
|
|
184
|
+
globalContexts.push(context);
|
|
185
|
+
return context;
|
|
186
|
+
};
|
|
187
|
+
var useContext = (context) => {
|
|
188
|
+
return context.values.at(-1);
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/intrinsic-element/common.js
|
|
192
|
+
var deDupeKeyMap = {
|
|
193
|
+
title: [],
|
|
194
|
+
script: ["src"],
|
|
195
|
+
style: ["data-href"],
|
|
196
|
+
link: ["href"],
|
|
197
|
+
meta: [
|
|
198
|
+
"name",
|
|
199
|
+
"httpEquiv",
|
|
200
|
+
"charset",
|
|
201
|
+
"itemProp"
|
|
202
|
+
]
|
|
203
|
+
};
|
|
204
|
+
var domRenderers = {};
|
|
205
|
+
var dataPrecedenceAttr = "data-precedence";
|
|
206
|
+
var isStylesheetLinkWithPrecedence = (props) => props.rel === "stylesheet" && "precedence" in props;
|
|
207
|
+
var shouldDeDupeByKey = (tagName, supportSort) => {
|
|
208
|
+
if (tagName === "link") return supportSort;
|
|
209
|
+
return deDupeKeyMap[tagName].length > 0;
|
|
210
|
+
};
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/children.js
|
|
213
|
+
var toArray = (children) => Array.isArray(children) ? children : [children];
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/intrinsic-element/components.js
|
|
216
|
+
var components_exports$1 = /* @__PURE__ */ __exportAll({
|
|
217
|
+
button: () => button$1,
|
|
218
|
+
form: () => form$1,
|
|
219
|
+
input: () => input$1,
|
|
220
|
+
link: () => link$1,
|
|
221
|
+
meta: () => meta$1,
|
|
222
|
+
script: () => script$1,
|
|
223
|
+
style: () => style$1,
|
|
224
|
+
title: () => title$1
|
|
225
|
+
});
|
|
226
|
+
var metaTagMap = /* @__PURE__ */ new WeakMap();
|
|
227
|
+
var insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }) => {
|
|
228
|
+
if (!buffer) return;
|
|
229
|
+
const map = metaTagMap.get(context) || {};
|
|
230
|
+
metaTagMap.set(context, map);
|
|
231
|
+
const tags = map[tagName] ||= [];
|
|
232
|
+
let duped = false;
|
|
233
|
+
const deDupeKeys = deDupeKeyMap[tagName];
|
|
234
|
+
const deDupeByKey = shouldDeDupeByKey(tagName, precedence !== void 0);
|
|
235
|
+
if (deDupeByKey) LOOP: for (const [, tagProps] of tags) {
|
|
236
|
+
if (tagName === "link" && !(tagProps.rel === "stylesheet" && tagProps["data-precedence"] !== void 0)) continue;
|
|
237
|
+
for (const key of deDupeKeys) if ((tagProps?.[key] ?? null) === props?.[key]) {
|
|
238
|
+
duped = true;
|
|
239
|
+
break LOOP;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (duped) buffer[0] = buffer[0].replaceAll(tag, "");
|
|
243
|
+
else if (deDupeByKey || tagName === "link") tags.push([
|
|
244
|
+
tag,
|
|
245
|
+
props,
|
|
246
|
+
precedence
|
|
247
|
+
]);
|
|
248
|
+
else tags.unshift([
|
|
249
|
+
tag,
|
|
250
|
+
props,
|
|
251
|
+
precedence
|
|
252
|
+
]);
|
|
253
|
+
if (buffer[0].indexOf("</head>") !== -1) {
|
|
254
|
+
let insertTags;
|
|
255
|
+
if (tagName === "link" || precedence !== void 0) {
|
|
256
|
+
const precedences = [];
|
|
257
|
+
insertTags = tags.map(([tag2, , tagPrecedence], index) => {
|
|
258
|
+
if (tagPrecedence === void 0) return [
|
|
259
|
+
tag2,
|
|
260
|
+
Number.MAX_SAFE_INTEGER,
|
|
261
|
+
index
|
|
262
|
+
];
|
|
263
|
+
let order = precedences.indexOf(tagPrecedence);
|
|
264
|
+
if (order === -1) {
|
|
265
|
+
precedences.push(tagPrecedence);
|
|
266
|
+
order = precedences.length - 1;
|
|
267
|
+
}
|
|
268
|
+
return [
|
|
269
|
+
tag2,
|
|
270
|
+
order,
|
|
271
|
+
index
|
|
272
|
+
];
|
|
273
|
+
}).sort((a, b) => a[1] - b[1] || a[2] - b[2]).map(([tag2]) => tag2);
|
|
274
|
+
} else insertTags = tags.map(([tag2]) => tag2);
|
|
275
|
+
insertTags.forEach((tag2) => {
|
|
276
|
+
buffer[0] = buffer[0].replaceAll(tag2, "");
|
|
277
|
+
});
|
|
278
|
+
buffer[0] = buffer[0].replace(/(?=<\/head>)/, insertTags.join(""));
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
var returnWithoutSpecialBehavior = (tag, children, props) => raw(new JSXNode(tag, props, toArray(children ?? [])).toString());
|
|
282
|
+
var documentMetadataTag$1 = (tag, children, props, sort) => {
|
|
283
|
+
if ("itemProp" in props) return returnWithoutSpecialBehavior(tag, children, props);
|
|
284
|
+
let { precedence, blocking, ...restProps } = props;
|
|
285
|
+
precedence = sort ? precedence ?? "" : void 0;
|
|
286
|
+
if (sort) restProps[dataPrecedenceAttr] = precedence;
|
|
287
|
+
const string = new JSXNode(tag, restProps, toArray(children || [])).toString();
|
|
288
|
+
if (string instanceof Promise) return string.then((resString) => raw(string, [...resString.callbacks || [], insertIntoHead(tag, resString, restProps, precedence)]));
|
|
289
|
+
else return raw(string, [insertIntoHead(tag, string, restProps, precedence)]);
|
|
290
|
+
};
|
|
291
|
+
var title$1 = ({ children, ...props }) => {
|
|
292
|
+
const nameSpaceContext = getNameSpaceContext$1();
|
|
293
|
+
if (nameSpaceContext) {
|
|
294
|
+
const context = useContext(nameSpaceContext);
|
|
295
|
+
if (context === "svg" || context === "head") return new JSXNode("title", props, toArray(children ?? []));
|
|
296
|
+
}
|
|
297
|
+
return documentMetadataTag$1("title", children, props, false);
|
|
298
|
+
};
|
|
299
|
+
var script$1 = ({ children, ...props }) => {
|
|
300
|
+
const nameSpaceContext = getNameSpaceContext$1();
|
|
301
|
+
if (["src", "async"].some((k) => !props[k]) || nameSpaceContext && useContext(nameSpaceContext) === "head") return returnWithoutSpecialBehavior("script", children, props);
|
|
302
|
+
return documentMetadataTag$1("script", children, props, false);
|
|
303
|
+
};
|
|
304
|
+
var style$1 = ({ children, ...props }) => {
|
|
305
|
+
if (!["href", "precedence"].every((k) => k in props)) return returnWithoutSpecialBehavior("style", children, props);
|
|
306
|
+
props["data-href"] = props.href;
|
|
307
|
+
delete props.href;
|
|
308
|
+
return documentMetadataTag$1("style", children, props, true);
|
|
309
|
+
};
|
|
310
|
+
var link$1 = ({ children, ...props }) => {
|
|
311
|
+
if (["onLoad", "onError"].some((k) => k in props) || props.rel === "stylesheet" && (!("precedence" in props) || "disabled" in props)) return returnWithoutSpecialBehavior("link", children, props);
|
|
312
|
+
return documentMetadataTag$1("link", children, props, isStylesheetLinkWithPrecedence(props));
|
|
313
|
+
};
|
|
314
|
+
var meta$1 = ({ children, ...props }) => {
|
|
315
|
+
const nameSpaceContext = getNameSpaceContext$1();
|
|
316
|
+
if (nameSpaceContext && useContext(nameSpaceContext) === "head") return returnWithoutSpecialBehavior("meta", children, props);
|
|
317
|
+
return documentMetadataTag$1("meta", children, props, false);
|
|
318
|
+
};
|
|
319
|
+
var newJSXNode = (tag, { children, ...props }) => new JSXNode(tag, props, toArray(children ?? []));
|
|
320
|
+
var form$1 = (props) => {
|
|
321
|
+
if (typeof props.action === "function") props.action = PERMALINK in props.action ? props.action[PERMALINK] : void 0;
|
|
322
|
+
return newJSXNode("form", props);
|
|
323
|
+
};
|
|
324
|
+
var formActionableElement$1 = (tag, props) => {
|
|
325
|
+
if (typeof props.formAction === "function") props.formAction = PERMALINK in props.formAction ? props.formAction[PERMALINK] : void 0;
|
|
326
|
+
return newJSXNode(tag, props);
|
|
327
|
+
};
|
|
328
|
+
var input$1 = (props) => formActionableElement$1("input", props);
|
|
329
|
+
var button$1 = (props) => formActionableElement$1("button", props);
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/utils.js
|
|
332
|
+
var normalizeElementKeyMap = /* @__PURE__ */ new Map([
|
|
333
|
+
["className", "class"],
|
|
334
|
+
["htmlFor", "for"],
|
|
335
|
+
["crossOrigin", "crossorigin"],
|
|
336
|
+
["httpEquiv", "http-equiv"],
|
|
337
|
+
["itemProp", "itemprop"],
|
|
338
|
+
["fetchPriority", "fetchpriority"],
|
|
339
|
+
["noModule", "nomodule"],
|
|
340
|
+
["formAction", "formaction"]
|
|
341
|
+
]);
|
|
342
|
+
var normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
|
|
343
|
+
var invalidAttributeNameCharRe = /[\s"'<>/=`\\\x00-\x1f\x7f-\x9f]/;
|
|
344
|
+
var validAttributeNameCache = /* @__PURE__ */ new Set();
|
|
345
|
+
var validAttributeNameCacheMax = 1024;
|
|
346
|
+
var invalidTagNameCharRe = /^[!?]|[\s"'<>/=`\\\x00-\x1f\x7f-\x9f]/;
|
|
347
|
+
var validTagNameCache = /* @__PURE__ */ new Set();
|
|
348
|
+
var validTagNameCacheMax = 256;
|
|
349
|
+
var cacheValidName = (cache, max, name) => {
|
|
350
|
+
if (cache.size >= max) cache.clear();
|
|
351
|
+
cache.add(name);
|
|
352
|
+
};
|
|
353
|
+
var isValidTagName = (name) => {
|
|
354
|
+
if (validTagNameCache.has(name)) return true;
|
|
355
|
+
if (typeof name !== "string") return false;
|
|
356
|
+
if (name.length === 0) return true;
|
|
357
|
+
if (invalidTagNameCharRe.test(name)) return false;
|
|
358
|
+
cacheValidName(validTagNameCache, validTagNameCacheMax, name);
|
|
359
|
+
return true;
|
|
360
|
+
};
|
|
361
|
+
var isValidAttributeName = (name) => {
|
|
362
|
+
if (validAttributeNameCache.has(name)) return true;
|
|
363
|
+
const len = name.length;
|
|
364
|
+
if (len === 0) return false;
|
|
365
|
+
for (let i = 0; i < len; i++) {
|
|
366
|
+
const c = name.charCodeAt(i);
|
|
367
|
+
if (!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 45 || c === 95 || c === 46 || c === 58)) if (!invalidAttributeNameCharRe.test(name)) {
|
|
368
|
+
cacheValidName(validAttributeNameCache, validAttributeNameCacheMax, name);
|
|
369
|
+
return true;
|
|
370
|
+
} else return false;
|
|
371
|
+
}
|
|
372
|
+
cacheValidName(validAttributeNameCache, validAttributeNameCacheMax, name);
|
|
373
|
+
return true;
|
|
374
|
+
};
|
|
375
|
+
var invalidStylePropertyNameCharRe = /[\s"'():;\\/\[\]{}\x00-\x1f\x7f-\x9f]/;
|
|
376
|
+
var validStylePropertyNameCache = /* @__PURE__ */ new Set();
|
|
377
|
+
var validStylePropertyNameCacheMax = 1024;
|
|
378
|
+
var isValidStylePropertyName = (name) => {
|
|
379
|
+
if (validStylePropertyNameCache.has(name)) return true;
|
|
380
|
+
const len = name.length;
|
|
381
|
+
if (len === 0) return false;
|
|
382
|
+
for (let i = 0; i < len; i++) {
|
|
383
|
+
const c = name.charCodeAt(i);
|
|
384
|
+
if (!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 45 || c === 95)) if (!invalidStylePropertyNameCharRe.test(name)) {
|
|
385
|
+
cacheValidName(validStylePropertyNameCache, validStylePropertyNameCacheMax, name);
|
|
386
|
+
return true;
|
|
387
|
+
} else return false;
|
|
388
|
+
}
|
|
389
|
+
cacheValidName(validStylePropertyNameCache, validStylePropertyNameCacheMax, name);
|
|
390
|
+
return true;
|
|
391
|
+
};
|
|
392
|
+
var unsafeStyleValueCharRe = /[;"'\\/\[\](){}]/;
|
|
393
|
+
var hasUnsafeStyleValue = (value) => {
|
|
394
|
+
if (!unsafeStyleValueCharRe.test(value)) return false;
|
|
395
|
+
let quote = 0;
|
|
396
|
+
const blockStack = [];
|
|
397
|
+
for (let i = 0, len = value.length; i < len; i++) {
|
|
398
|
+
const c = value.charCodeAt(i);
|
|
399
|
+
if (c === 92) {
|
|
400
|
+
if (i === len - 1) return true;
|
|
401
|
+
i++;
|
|
402
|
+
} else if (quote !== 0) {
|
|
403
|
+
if (c === 10 || c === 12 || c === 13) return true;
|
|
404
|
+
if (c === quote) quote = 0;
|
|
405
|
+
} else if (c === 47 && value.charCodeAt(i + 1) === 42) {
|
|
406
|
+
const end = value.indexOf("*/", i + 2);
|
|
407
|
+
if (end === -1) return true;
|
|
408
|
+
i = end + 1;
|
|
409
|
+
} else if (c === 34 || c === 39) quote = c;
|
|
410
|
+
else if (c === 40) blockStack.push(41);
|
|
411
|
+
else if (c === 91) blockStack.push(93);
|
|
412
|
+
else if (c === 123 || c === 125) return true;
|
|
413
|
+
else if (c === 41 || c === 93) {
|
|
414
|
+
if (blockStack[blockStack.length - 1] !== c) return true;
|
|
415
|
+
blockStack.pop();
|
|
416
|
+
} else if (c === 59 && blockStack.length === 0) return true;
|
|
417
|
+
}
|
|
418
|
+
return quote !== 0 || blockStack.length !== 0;
|
|
419
|
+
};
|
|
420
|
+
var styleObjectForEach = (style, fn) => {
|
|
421
|
+
for (const [k, v] of Object.entries(style)) {
|
|
422
|
+
const key = k[0] === "-" || !/[A-Z]/.test(k) ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
423
|
+
if (!isValidStylePropertyName(key)) continue;
|
|
424
|
+
if (v == null) {
|
|
425
|
+
fn(key, null);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
let value;
|
|
429
|
+
if (typeof v === "number") value = !key.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/) ? `${v}px` : `${v}`;
|
|
430
|
+
else if (typeof v === "string") {
|
|
431
|
+
if (hasUnsafeStyleValue(v)) continue;
|
|
432
|
+
value = v;
|
|
433
|
+
} else continue;
|
|
434
|
+
fn(key, value);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/base.js
|
|
439
|
+
var nameSpaceContext$1 = void 0;
|
|
440
|
+
var getNameSpaceContext$1 = () => nameSpaceContext$1;
|
|
441
|
+
var toSVGAttributeName = (key) => /[A-Z]/.test(key) && key.match(/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
|
442
|
+
var emptyTags = [
|
|
443
|
+
"area",
|
|
444
|
+
"base",
|
|
445
|
+
"br",
|
|
446
|
+
"col",
|
|
447
|
+
"embed",
|
|
448
|
+
"hr",
|
|
449
|
+
"img",
|
|
450
|
+
"input",
|
|
451
|
+
"keygen",
|
|
452
|
+
"link",
|
|
453
|
+
"meta",
|
|
454
|
+
"param",
|
|
455
|
+
"source",
|
|
456
|
+
"track",
|
|
457
|
+
"wbr"
|
|
458
|
+
];
|
|
459
|
+
var booleanAttributes = [
|
|
460
|
+
"allowfullscreen",
|
|
461
|
+
"async",
|
|
462
|
+
"autofocus",
|
|
463
|
+
"autoplay",
|
|
464
|
+
"checked",
|
|
465
|
+
"controls",
|
|
466
|
+
"default",
|
|
467
|
+
"defer",
|
|
468
|
+
"disabled",
|
|
469
|
+
"download",
|
|
470
|
+
"formnovalidate",
|
|
471
|
+
"hidden",
|
|
472
|
+
"inert",
|
|
473
|
+
"ismap",
|
|
474
|
+
"itemscope",
|
|
475
|
+
"loop",
|
|
476
|
+
"multiple",
|
|
477
|
+
"muted",
|
|
478
|
+
"nomodule",
|
|
479
|
+
"novalidate",
|
|
480
|
+
"open",
|
|
481
|
+
"playsinline",
|
|
482
|
+
"readonly",
|
|
483
|
+
"required",
|
|
484
|
+
"reversed",
|
|
485
|
+
"selected"
|
|
486
|
+
];
|
|
487
|
+
var childrenToStringToBuffer = (children, buffer) => {
|
|
488
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
489
|
+
const child = children[i];
|
|
490
|
+
if (typeof child === "string") escapeToBuffer(child, buffer);
|
|
491
|
+
else if (typeof child === "boolean" || child === null || child === void 0) continue;
|
|
492
|
+
else if (child instanceof JSXNode) child.toStringToBuffer(buffer);
|
|
493
|
+
else if (typeof child === "number" || child.isEscaped) buffer[0] += child;
|
|
494
|
+
else if (child instanceof Promise) buffer.unshift("", child);
|
|
495
|
+
else childrenToStringToBuffer(child, buffer);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
var JSXNode = class {
|
|
499
|
+
tag;
|
|
500
|
+
props;
|
|
501
|
+
key;
|
|
502
|
+
children;
|
|
503
|
+
isEscaped = true;
|
|
504
|
+
localContexts;
|
|
505
|
+
constructor(tag, props, children) {
|
|
506
|
+
if (typeof tag !== "function" && !isValidTagName(tag)) throw new Error(`Invalid JSX tag name: ${tag}`);
|
|
507
|
+
this.tag = tag;
|
|
508
|
+
this.props = props;
|
|
509
|
+
this.children = children;
|
|
510
|
+
}
|
|
511
|
+
get type() {
|
|
512
|
+
return this.tag;
|
|
513
|
+
}
|
|
514
|
+
get ref() {
|
|
515
|
+
return this.props.ref || null;
|
|
516
|
+
}
|
|
517
|
+
toString() {
|
|
518
|
+
const buffer = [""];
|
|
519
|
+
this.localContexts?.forEach(([context, value]) => {
|
|
520
|
+
context.values.push(value);
|
|
521
|
+
});
|
|
522
|
+
try {
|
|
523
|
+
this.toStringToBuffer(buffer);
|
|
524
|
+
} finally {
|
|
525
|
+
this.localContexts?.forEach(([context]) => {
|
|
526
|
+
context.values.pop();
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
|
|
530
|
+
}
|
|
531
|
+
toStringToBuffer(buffer) {
|
|
532
|
+
const tag = this.tag;
|
|
533
|
+
const props = this.props;
|
|
534
|
+
let { children } = this;
|
|
535
|
+
buffer[0] += `<${tag}`;
|
|
536
|
+
const normalizeKey = tag === "svg" || nameSpaceContext$1 && useContext(nameSpaceContext$1) === "svg" ? (key) => toSVGAttributeName(normalizeIntrinsicElementKey(key)) : (key) => normalizeIntrinsicElementKey(key);
|
|
537
|
+
for (let [key, v] of Object.entries(props)) {
|
|
538
|
+
key = normalizeKey(key);
|
|
539
|
+
if (!isValidAttributeName(key)) continue;
|
|
540
|
+
if (key === "children") {} else if (key === "style" && typeof v === "object") {
|
|
541
|
+
let styleStr = "";
|
|
542
|
+
styleObjectForEach(v, (property, value) => {
|
|
543
|
+
if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
544
|
+
});
|
|
545
|
+
buffer[0] += " style=\"";
|
|
546
|
+
escapeToBuffer(styleStr, buffer);
|
|
547
|
+
buffer[0] += "\"";
|
|
548
|
+
} else if (typeof v === "string") {
|
|
549
|
+
buffer[0] += ` ${key}="`;
|
|
550
|
+
escapeToBuffer(v, buffer);
|
|
551
|
+
buffer[0] += "\"";
|
|
552
|
+
} else if (v === null || v === void 0) {} else if (typeof v === "number" || v.isEscaped) buffer[0] += ` ${key}="${v}"`;
|
|
553
|
+
else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
|
|
554
|
+
if (v) buffer[0] += ` ${key}=""`;
|
|
555
|
+
} else if (key === "dangerouslySetInnerHTML") {
|
|
556
|
+
if (children.length > 0) throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");
|
|
557
|
+
children = [raw(v.__html)];
|
|
558
|
+
} else if (v instanceof Promise) {
|
|
559
|
+
buffer[0] += ` ${key}="`;
|
|
560
|
+
buffer.unshift("\"", v);
|
|
561
|
+
} else if (typeof v === "function") {
|
|
562
|
+
if (!key.startsWith("on") && key !== "ref") throw new Error(`Invalid prop '${key}' of type 'function' supplied to '${tag}'.`);
|
|
563
|
+
} else {
|
|
564
|
+
buffer[0] += ` ${key}="`;
|
|
565
|
+
escapeToBuffer(v.toString(), buffer);
|
|
566
|
+
buffer[0] += "\"";
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (emptyTags.includes(tag) && children.length === 0) {
|
|
570
|
+
buffer[0] += "/>";
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
buffer[0] += ">";
|
|
574
|
+
childrenToStringToBuffer(children, buffer);
|
|
575
|
+
buffer[0] += `</${tag}>`;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
var JSXFunctionNode = class extends JSXNode {
|
|
579
|
+
toStringToBuffer(buffer) {
|
|
580
|
+
const { children } = this;
|
|
581
|
+
const props = { ...this.props };
|
|
582
|
+
if (children.length) props.children = children.length === 1 ? children[0] : children;
|
|
583
|
+
const res = this.tag.call(null, props);
|
|
584
|
+
if (typeof res === "boolean" || res == null) return;
|
|
585
|
+
else if (res instanceof Promise) if (globalContexts.length === 0) buffer.unshift("", res);
|
|
586
|
+
else {
|
|
587
|
+
const currentContexts = globalContexts.map((c) => [c, c.values.at(-1)]);
|
|
588
|
+
buffer.unshift("", res.then((childRes) => {
|
|
589
|
+
if (childRes instanceof JSXNode) childRes.localContexts = currentContexts;
|
|
590
|
+
return childRes;
|
|
591
|
+
}));
|
|
592
|
+
}
|
|
593
|
+
else if (res instanceof JSXNode) res.toStringToBuffer(buffer);
|
|
594
|
+
else if (typeof res === "number" || res.isEscaped) {
|
|
595
|
+
buffer[0] += res;
|
|
596
|
+
if (res.callbacks) {
|
|
597
|
+
buffer.callbacks ||= [];
|
|
598
|
+
buffer.callbacks.push(...res.callbacks);
|
|
599
|
+
}
|
|
600
|
+
} else escapeToBuffer(res, buffer);
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
var JSXFragmentNode = class extends JSXNode {
|
|
604
|
+
toStringToBuffer(buffer) {
|
|
605
|
+
childrenToStringToBuffer(this.children, buffer);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
var jsx = (tag, props, ...children) => {
|
|
609
|
+
props ??= {};
|
|
610
|
+
if (children.length) props.children = children.length === 1 ? children[0] : children;
|
|
611
|
+
const key = props.key;
|
|
612
|
+
delete props["key"];
|
|
613
|
+
const node = jsxFn(tag, props, children);
|
|
614
|
+
node.key = key;
|
|
615
|
+
return node;
|
|
616
|
+
};
|
|
617
|
+
var initDomRenderer = false;
|
|
618
|
+
var jsxFn = (tag, props, children) => {
|
|
619
|
+
if (!initDomRenderer) {
|
|
620
|
+
for (const k in domRenderers) components_exports$1[k][DOM_RENDERER] = domRenderers[k];
|
|
621
|
+
initDomRenderer = true;
|
|
622
|
+
}
|
|
623
|
+
if (typeof tag === "function") return new JSXFunctionNode(tag, props, children);
|
|
624
|
+
else if (components_exports$1[tag]) return new JSXFunctionNode(components_exports$1[tag], props, children);
|
|
625
|
+
else if (tag === "svg" || tag === "head") {
|
|
626
|
+
nameSpaceContext$1 ||= createContext("");
|
|
627
|
+
return new JSXNode(tag, props, [new JSXFunctionNode(nameSpaceContext$1, { value: tag }, children)]);
|
|
628
|
+
} else return new JSXNode(tag, props, children);
|
|
629
|
+
};
|
|
630
|
+
var Fragment$1 = ({ children }) => {
|
|
631
|
+
return new JSXFragmentNode("", { children }, Array.isArray(children) ? children : children ? [children] : []);
|
|
632
|
+
};
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/dom/render.js
|
|
635
|
+
var HONO_PORTAL_ELEMENT = "_hp";
|
|
636
|
+
var eventAliasMap = {
|
|
637
|
+
Change: "Input",
|
|
638
|
+
DoubleClick: "DblClick"
|
|
639
|
+
};
|
|
640
|
+
var nameSpaceMap = {
|
|
641
|
+
svg: "2000/svg",
|
|
642
|
+
math: "1998/Math/MathML"
|
|
643
|
+
};
|
|
644
|
+
var buildDataStack = [];
|
|
645
|
+
var refCleanupMap = /* @__PURE__ */ new WeakMap();
|
|
646
|
+
var nameSpaceContext = void 0;
|
|
647
|
+
var getNameSpaceContext = () => nameSpaceContext;
|
|
648
|
+
var isNodeString = (node) => "t" in node;
|
|
649
|
+
var eventCache = { onClick: ["click", false] };
|
|
650
|
+
var getEventSpec = (key) => {
|
|
651
|
+
if (!key.startsWith("on")) return;
|
|
652
|
+
if (eventCache[key]) return eventCache[key];
|
|
653
|
+
const match = key.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);
|
|
654
|
+
if (match) {
|
|
655
|
+
const [, eventName, capture] = match;
|
|
656
|
+
return eventCache[key] = [(eventAliasMap[eventName] || eventName).toLowerCase(), !!capture];
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
var toAttributeName = (element, key) => nameSpaceContext && element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
|
660
|
+
var normalizeFormValue = (value) => value === null || value === void 0 || value === false ? null : value;
|
|
661
|
+
var applySelectValue = (select, props) => {
|
|
662
|
+
if (!("value" in props)) return;
|
|
663
|
+
select.value = normalizeFormValue(props["value"]);
|
|
664
|
+
if (!select.multiple && select.selectedIndex === -1) select.selectedIndex = 0;
|
|
665
|
+
};
|
|
666
|
+
var isIgnorableAttributeError = (error) => error instanceof DOMException && error.name === "InvalidCharacterError";
|
|
667
|
+
var applyProps = (container, attributes, oldAttributes) => {
|
|
668
|
+
attributes ||= {};
|
|
669
|
+
for (let key in attributes) {
|
|
670
|
+
const value = attributes[key];
|
|
671
|
+
if (key !== "children" && (!oldAttributes || oldAttributes[key] !== value)) {
|
|
672
|
+
key = normalizeIntrinsicElementKey(key);
|
|
673
|
+
const eventSpec = getEventSpec(key);
|
|
674
|
+
if (eventSpec) {
|
|
675
|
+
if (oldAttributes?.[key] !== value) {
|
|
676
|
+
if (oldAttributes) container.removeEventListener(eventSpec[0], oldAttributes[key], eventSpec[1]);
|
|
677
|
+
if (value != null) {
|
|
678
|
+
if (typeof value !== "function") throw new Error(`Event handler for "${key}" is not a function`);
|
|
679
|
+
container.addEventListener(eventSpec[0], value, eventSpec[1]);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
} else if (key === "dangerouslySetInnerHTML" && value) container.innerHTML = value.__html;
|
|
683
|
+
else if (key === "ref") {
|
|
684
|
+
let cleanup;
|
|
685
|
+
if (typeof value === "function") cleanup = value(container) || (() => value(null));
|
|
686
|
+
else if (value && "current" in value) {
|
|
687
|
+
value.current = container;
|
|
688
|
+
cleanup = () => value.current = null;
|
|
689
|
+
}
|
|
690
|
+
refCleanupMap.set(container, cleanup);
|
|
691
|
+
} else if (key === "style") {
|
|
692
|
+
const style = container.style;
|
|
693
|
+
if (typeof value === "string") style.cssText = value;
|
|
694
|
+
else {
|
|
695
|
+
style.cssText = "";
|
|
696
|
+
if (value != null) styleObjectForEach(value, style.setProperty.bind(style));
|
|
697
|
+
}
|
|
698
|
+
} else {
|
|
699
|
+
if (key === "value") {
|
|
700
|
+
const nodeName = container.nodeName;
|
|
701
|
+
if (nodeName === "SELECT") continue;
|
|
702
|
+
else if (nodeName === "INPUT" || nodeName === "TEXTAREA") {
|
|
703
|
+
container.value = normalizeFormValue(value);
|
|
704
|
+
if (nodeName === "TEXTAREA") {
|
|
705
|
+
container.textContent = value;
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
} else if (key === "checked" && container.nodeName === "INPUT" || key === "selected" && container.nodeName === "OPTION") container[key] = value;
|
|
710
|
+
const k = toAttributeName(container, key);
|
|
711
|
+
try {
|
|
712
|
+
if (value === null || value === void 0 || value === false) container.removeAttribute(k);
|
|
713
|
+
else if (value === true) container.setAttribute(k, "");
|
|
714
|
+
else if (typeof value === "string" || typeof value === "number") container.setAttribute(k, value);
|
|
715
|
+
else container.setAttribute(k, value.toString());
|
|
716
|
+
} catch (e) {
|
|
717
|
+
if (!isIgnorableAttributeError(e)) throw e;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (oldAttributes) for (let key in oldAttributes) {
|
|
723
|
+
const value = oldAttributes[key];
|
|
724
|
+
if (key !== "children" && !(key in attributes)) {
|
|
725
|
+
key = normalizeIntrinsicElementKey(key);
|
|
726
|
+
const eventSpec = getEventSpec(key);
|
|
727
|
+
if (eventSpec) container.removeEventListener(eventSpec[0], value, eventSpec[1]);
|
|
728
|
+
else if (key === "ref") refCleanupMap.get(container)?.();
|
|
729
|
+
else try {
|
|
730
|
+
container.removeAttribute(toAttributeName(container, key));
|
|
731
|
+
} catch (e) {
|
|
732
|
+
if (!isIgnorableAttributeError(e)) throw e;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
var invokeTag = (context, node) => {
|
|
738
|
+
node[DOM_STASH][0] = 0;
|
|
739
|
+
buildDataStack.push([context, node]);
|
|
740
|
+
const func = node.tag[DOM_RENDERER] || node.tag;
|
|
741
|
+
const props = func.defaultProps ? {
|
|
742
|
+
...func.defaultProps,
|
|
743
|
+
...node.props
|
|
744
|
+
} : node.props;
|
|
745
|
+
try {
|
|
746
|
+
return [func.call(null, props)];
|
|
747
|
+
} finally {
|
|
748
|
+
buildDataStack.pop();
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
var getNextChildren = (node, container, nextChildren, childrenToRemove, callbacks) => {
|
|
752
|
+
if (node.vR?.length) {
|
|
753
|
+
childrenToRemove.push(...node.vR);
|
|
754
|
+
delete node.vR;
|
|
755
|
+
}
|
|
756
|
+
if (typeof node.tag === "function") node[DOM_STASH][1][1]?.forEach((data) => callbacks.push(data));
|
|
757
|
+
node.vC.forEach((child) => {
|
|
758
|
+
if (isNodeString(child)) nextChildren.push(child);
|
|
759
|
+
else if (typeof child.tag === "function" || child.tag === "") {
|
|
760
|
+
child.c = container;
|
|
761
|
+
const currentNextChildrenIndex = nextChildren.length;
|
|
762
|
+
getNextChildren(child, container, nextChildren, childrenToRemove, callbacks);
|
|
763
|
+
if (child.s) {
|
|
764
|
+
for (let i = currentNextChildrenIndex; i < nextChildren.length; i++) nextChildren[i].s = true;
|
|
765
|
+
child.s = false;
|
|
766
|
+
}
|
|
767
|
+
} else {
|
|
768
|
+
nextChildren.push(child);
|
|
769
|
+
if (child.vR?.length) {
|
|
770
|
+
childrenToRemove.push(...child.vR);
|
|
771
|
+
delete child.vR;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
};
|
|
776
|
+
var findInsertBefore = (node) => {
|
|
777
|
+
while (node && (node.tag === HONO_PORTAL_ELEMENT || !node.e)) node = node.tag === HONO_PORTAL_ELEMENT || !node.vC?.[0] ? node.nN : node.vC[0];
|
|
778
|
+
return node?.e;
|
|
779
|
+
};
|
|
780
|
+
var removeNode = (node) => {
|
|
781
|
+
if (!isNodeString(node)) {
|
|
782
|
+
node[DOM_STASH]?.[1][1]?.forEach((data) => data[2]?.());
|
|
783
|
+
refCleanupMap.get(node.e)?.();
|
|
784
|
+
if (node.p === 2) node.vC?.forEach((n) => n.p = 2);
|
|
785
|
+
node.vC?.forEach(removeNode);
|
|
786
|
+
}
|
|
787
|
+
if (!node.p) {
|
|
788
|
+
node.e?.remove();
|
|
789
|
+
delete node.e;
|
|
790
|
+
}
|
|
791
|
+
if (typeof node.tag === "function") {
|
|
792
|
+
updateMap.delete(node);
|
|
793
|
+
fallbackUpdateFnArrayMap.delete(node);
|
|
794
|
+
delete node[DOM_STASH][3];
|
|
795
|
+
node.a = true;
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
var apply = (node, container, isNew) => {
|
|
799
|
+
node.c = container;
|
|
800
|
+
applyNodeObject(node, container, isNew);
|
|
801
|
+
};
|
|
802
|
+
var findChildNodeIndex = (childNodes, child) => {
|
|
803
|
+
if (!child) return;
|
|
804
|
+
for (let i = 0, len = childNodes.length; i < len; i++) if (childNodes[i] === child) return i;
|
|
805
|
+
};
|
|
806
|
+
var cancelBuild = /* @__PURE__ */ Symbol();
|
|
807
|
+
var applyNodeObject = (node, container, isNew) => {
|
|
808
|
+
const next = [];
|
|
809
|
+
const remove = [];
|
|
810
|
+
const callbacks = [];
|
|
811
|
+
getNextChildren(node, container, next, remove, callbacks);
|
|
812
|
+
remove.forEach(removeNode);
|
|
813
|
+
const childNodes = isNew ? void 0 : container.childNodes;
|
|
814
|
+
let offset;
|
|
815
|
+
let insertBeforeNode = null;
|
|
816
|
+
if (isNew) offset = -1;
|
|
817
|
+
else if (!childNodes.length) offset = 0;
|
|
818
|
+
else {
|
|
819
|
+
const offsetByNextNode = findChildNodeIndex(childNodes, findInsertBefore(node.nN));
|
|
820
|
+
if (offsetByNextNode !== void 0) {
|
|
821
|
+
insertBeforeNode = childNodes[offsetByNextNode];
|
|
822
|
+
offset = offsetByNextNode;
|
|
823
|
+
} else offset = findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ?? -1;
|
|
824
|
+
if (offset === -1) isNew = true;
|
|
825
|
+
}
|
|
826
|
+
for (let i = 0, len = next.length; i < len; i++, offset++) {
|
|
827
|
+
const child = next[i];
|
|
828
|
+
let el;
|
|
829
|
+
if (child.s && child.e) {
|
|
830
|
+
el = child.e;
|
|
831
|
+
child.s = false;
|
|
832
|
+
} else {
|
|
833
|
+
const isNewLocal = isNew || !child.e;
|
|
834
|
+
if (isNodeString(child)) {
|
|
835
|
+
if (child.e && child.d) child.e.textContent = child.t;
|
|
836
|
+
child.d = false;
|
|
837
|
+
el = child.e ||= document.createTextNode(child.t);
|
|
838
|
+
} else {
|
|
839
|
+
el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
|
|
840
|
+
applyProps(el, child.props, child.pP);
|
|
841
|
+
applyNodeObject(child, el, isNewLocal);
|
|
842
|
+
if (child.tag === "select") applySelectValue(el, child.props);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (child.tag === HONO_PORTAL_ELEMENT) offset--;
|
|
846
|
+
else if (isNew) {
|
|
847
|
+
if (!el.parentNode) container.appendChild(el);
|
|
848
|
+
} else if (childNodes[offset] !== el && childNodes[offset - 1] !== el) if (childNodes[offset + 1] === el) container.appendChild(childNodes[offset]);
|
|
849
|
+
else container.insertBefore(el, insertBeforeNode || childNodes[offset] || null);
|
|
850
|
+
}
|
|
851
|
+
if (node.pP) node.pP = void 0;
|
|
852
|
+
if (callbacks.length) {
|
|
853
|
+
const useLayoutEffectCbs = [];
|
|
854
|
+
const useEffectCbs = [];
|
|
855
|
+
callbacks.forEach(([, useLayoutEffectCb, , useEffectCb, useInsertionEffectCb]) => {
|
|
856
|
+
if (useLayoutEffectCb) useLayoutEffectCbs.push(useLayoutEffectCb);
|
|
857
|
+
if (useEffectCb) useEffectCbs.push(useEffectCb);
|
|
858
|
+
useInsertionEffectCb?.();
|
|
859
|
+
});
|
|
860
|
+
useLayoutEffectCbs.forEach((cb) => cb());
|
|
861
|
+
if (useEffectCbs.length) requestAnimationFrame(() => {
|
|
862
|
+
useEffectCbs.forEach((cb) => cb());
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
var isSameContext = (oldContexts, newContexts) => !!(oldContexts && oldContexts.length === newContexts.length && oldContexts.every((ctx, i) => ctx[1] === newContexts[i][1]));
|
|
867
|
+
var fallbackUpdateFnArrayMap = /* @__PURE__ */ new WeakMap();
|
|
868
|
+
var build = (context, node, children) => {
|
|
869
|
+
const buildWithPreviousChildren = !children && node.pC;
|
|
870
|
+
if (children) node.pC ||= node.vC;
|
|
871
|
+
let foundErrorHandler;
|
|
872
|
+
try {
|
|
873
|
+
children ||= typeof node.tag == "function" ? invokeTag(context, node) : toArray(node.props.children);
|
|
874
|
+
if (children[0]?.tag === "" && children[0][DOM_ERROR_HANDLER]) {
|
|
875
|
+
foundErrorHandler = children[0][DOM_ERROR_HANDLER];
|
|
876
|
+
context[5].push([
|
|
877
|
+
context,
|
|
878
|
+
foundErrorHandler,
|
|
879
|
+
node
|
|
880
|
+
]);
|
|
881
|
+
}
|
|
882
|
+
const oldVChildren = buildWithPreviousChildren ? [...node.pC] : node.vC ? [...node.vC] : void 0;
|
|
883
|
+
const vChildren = [];
|
|
884
|
+
let prevNode;
|
|
885
|
+
for (let i = 0; i < children.length; i++) {
|
|
886
|
+
if (Array.isArray(children[i])) {
|
|
887
|
+
children.splice(i, 1, ...children[i].flat(Infinity));
|
|
888
|
+
i--;
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
let child = buildNode(children[i]);
|
|
892
|
+
if (child) {
|
|
893
|
+
if (typeof child.tag === "function" && !child.tag[DOM_INTERNAL_TAG]) {
|
|
894
|
+
if (globalContexts.length > 0) child[DOM_STASH][2] = globalContexts.map((c) => [c, c.values.at(-1)]);
|
|
895
|
+
if (context[5]?.length) child[DOM_STASH][3] = context[5].at(-1);
|
|
896
|
+
}
|
|
897
|
+
let oldChild;
|
|
898
|
+
if (oldVChildren && oldVChildren.length) {
|
|
899
|
+
const i2 = oldVChildren.findIndex(isNodeString(child) ? (c) => isNodeString(c) : child.key !== void 0 ? (c) => c.key === child.key && c.tag === child.tag : (c) => c.tag === child.tag);
|
|
900
|
+
if (i2 !== -1) {
|
|
901
|
+
oldChild = oldVChildren[i2];
|
|
902
|
+
oldVChildren.splice(i2, 1);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
if (oldChild) if (isNodeString(child)) {
|
|
906
|
+
if (oldChild.t !== child.t) {
|
|
907
|
+
oldChild.t = child.t;
|
|
908
|
+
oldChild.d = true;
|
|
909
|
+
}
|
|
910
|
+
child = oldChild;
|
|
911
|
+
} else {
|
|
912
|
+
const pP = oldChild.pP = oldChild.props;
|
|
913
|
+
oldChild.props = child.props;
|
|
914
|
+
oldChild.f ||= child.f || node.f;
|
|
915
|
+
if (typeof child.tag === "function") {
|
|
916
|
+
const oldContexts = oldChild[DOM_STASH][2];
|
|
917
|
+
oldChild[DOM_STASH][2] = child[DOM_STASH][2] || [];
|
|
918
|
+
oldChild[DOM_STASH][3] = child[DOM_STASH][3];
|
|
919
|
+
if (!oldChild.f && ((oldChild.o || oldChild) === child.o || oldChild.tag[DOM_MEMO]?.(pP, oldChild.props)) && isSameContext(oldContexts, oldChild[DOM_STASH][2])) oldChild.s = true;
|
|
920
|
+
}
|
|
921
|
+
child = oldChild;
|
|
922
|
+
}
|
|
923
|
+
else if (!isNodeString(child) && nameSpaceContext) {
|
|
924
|
+
const ns = useContext(nameSpaceContext);
|
|
925
|
+
if (ns) child.n = ns;
|
|
926
|
+
}
|
|
927
|
+
if (!isNodeString(child) && !child.s) {
|
|
928
|
+
build(context, child);
|
|
929
|
+
delete child.f;
|
|
930
|
+
}
|
|
931
|
+
vChildren.push(child);
|
|
932
|
+
if (prevNode && !prevNode.s && !child.s) for (let p = prevNode; p && !isNodeString(p); p = p.vC?.at(-1)) p.nN = child;
|
|
933
|
+
prevNode = child;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
node.vR = buildWithPreviousChildren ? [...node.vC, ...oldVChildren || []] : oldVChildren || [];
|
|
937
|
+
node.vC = vChildren;
|
|
938
|
+
if (buildWithPreviousChildren) delete node.pC;
|
|
939
|
+
} catch (e) {
|
|
940
|
+
node.f = true;
|
|
941
|
+
if (e === cancelBuild) if (foundErrorHandler) return;
|
|
942
|
+
else throw e;
|
|
943
|
+
const [errorHandlerContext, errorHandler, errorHandlerNode] = node[DOM_STASH]?.[3] || [];
|
|
944
|
+
if (errorHandler) {
|
|
945
|
+
const fallbackUpdateFn = () => update([
|
|
946
|
+
0,
|
|
947
|
+
false,
|
|
948
|
+
context[2]
|
|
949
|
+
], errorHandlerNode);
|
|
950
|
+
const fallbackUpdateFnArray = fallbackUpdateFnArrayMap.get(errorHandlerNode) || [];
|
|
951
|
+
fallbackUpdateFnArray.push(fallbackUpdateFn);
|
|
952
|
+
fallbackUpdateFnArrayMap.set(errorHandlerNode, fallbackUpdateFnArray);
|
|
953
|
+
const fallback = errorHandler(e, () => {
|
|
954
|
+
const fnArray = fallbackUpdateFnArrayMap.get(errorHandlerNode);
|
|
955
|
+
if (fnArray) {
|
|
956
|
+
const i = fnArray.indexOf(fallbackUpdateFn);
|
|
957
|
+
if (i !== -1) {
|
|
958
|
+
fnArray.splice(i, 1);
|
|
959
|
+
return fallbackUpdateFn();
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
if (fallback) {
|
|
964
|
+
if (context[0] === 1) context[1] = true;
|
|
965
|
+
else {
|
|
966
|
+
build(context, errorHandlerNode, [fallback]);
|
|
967
|
+
if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c) {
|
|
968
|
+
apply(errorHandlerNode, errorHandlerNode.c, false);
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
throw cancelBuild;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
throw e;
|
|
976
|
+
} finally {
|
|
977
|
+
if (foundErrorHandler) context[5].pop();
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
var buildNode = (node) => {
|
|
981
|
+
if (node === void 0 || node === null || typeof node === "boolean") return;
|
|
982
|
+
else if (typeof node === "string" || typeof node === "number") return {
|
|
983
|
+
t: node.toString(),
|
|
984
|
+
d: true
|
|
985
|
+
};
|
|
986
|
+
else {
|
|
987
|
+
if ("vR" in node) node = {
|
|
988
|
+
tag: node.tag,
|
|
989
|
+
props: node.props,
|
|
990
|
+
key: node.key,
|
|
991
|
+
f: node.f,
|
|
992
|
+
type: node.tag,
|
|
993
|
+
ref: node.props.ref,
|
|
994
|
+
o: node.o || node
|
|
995
|
+
};
|
|
996
|
+
if (typeof node.tag === "function") node[DOM_STASH] = [0, []];
|
|
997
|
+
else {
|
|
998
|
+
const ns = nameSpaceMap[node.tag];
|
|
999
|
+
if (ns) {
|
|
1000
|
+
nameSpaceContext ||= createContext$1("");
|
|
1001
|
+
node.props.children = [{
|
|
1002
|
+
tag: nameSpaceContext,
|
|
1003
|
+
props: {
|
|
1004
|
+
value: node.n = `http://www.w3.org/${ns}`,
|
|
1005
|
+
children: node.props.children
|
|
1006
|
+
}
|
|
1007
|
+
}];
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return node;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
var replaceContainer = (node, from, to) => {
|
|
1014
|
+
if (node.c === from) {
|
|
1015
|
+
node.c = to;
|
|
1016
|
+
node.vC.forEach((child) => replaceContainer(child, from, to));
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
var updateSync = (context, node) => {
|
|
1020
|
+
node[DOM_STASH][2]?.forEach(([c, v]) => {
|
|
1021
|
+
c.values.push(v);
|
|
1022
|
+
});
|
|
1023
|
+
try {
|
|
1024
|
+
build(context, node, void 0);
|
|
1025
|
+
} catch {
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (node.a) {
|
|
1029
|
+
delete node.a;
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
node[DOM_STASH][2]?.forEach(([c]) => {
|
|
1033
|
+
c.values.pop();
|
|
1034
|
+
});
|
|
1035
|
+
if (context[0] !== 1 || !context[1]) apply(node, node.c, false);
|
|
1036
|
+
};
|
|
1037
|
+
var updateMap = /* @__PURE__ */ new WeakMap();
|
|
1038
|
+
var currentUpdateSets = [];
|
|
1039
|
+
var update = async (context, node) => {
|
|
1040
|
+
context[5] ||= [];
|
|
1041
|
+
const existing = updateMap.get(node);
|
|
1042
|
+
if (existing) existing[0](void 0);
|
|
1043
|
+
let resolve;
|
|
1044
|
+
const promise = new Promise((r) => resolve = r);
|
|
1045
|
+
updateMap.set(node, [resolve, () => {
|
|
1046
|
+
if (context[2]) context[2](context, node, (context2) => {
|
|
1047
|
+
updateSync(context2, node);
|
|
1048
|
+
}).then(() => resolve(node));
|
|
1049
|
+
else {
|
|
1050
|
+
updateSync(context, node);
|
|
1051
|
+
resolve(node);
|
|
1052
|
+
}
|
|
1053
|
+
}]);
|
|
1054
|
+
if (currentUpdateSets.length) currentUpdateSets.at(-1).add(node);
|
|
1055
|
+
else {
|
|
1056
|
+
await Promise.resolve();
|
|
1057
|
+
const latest = updateMap.get(node);
|
|
1058
|
+
if (latest) {
|
|
1059
|
+
updateMap.delete(node);
|
|
1060
|
+
latest[1]();
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return promise;
|
|
1064
|
+
};
|
|
1065
|
+
var renderNode = (node, container) => {
|
|
1066
|
+
const context = [];
|
|
1067
|
+
context[5] = [];
|
|
1068
|
+
context[4] = true;
|
|
1069
|
+
build(context, node, void 0);
|
|
1070
|
+
context[4] = false;
|
|
1071
|
+
const fragment = document.createDocumentFragment();
|
|
1072
|
+
apply(node, fragment, true);
|
|
1073
|
+
replaceContainer(node, fragment, container);
|
|
1074
|
+
container.replaceChildren(fragment);
|
|
1075
|
+
};
|
|
1076
|
+
var render = (jsxNode, container) => {
|
|
1077
|
+
renderNode(buildNode({
|
|
1078
|
+
tag: "",
|
|
1079
|
+
props: { children: jsxNode }
|
|
1080
|
+
}), container);
|
|
1081
|
+
};
|
|
1082
|
+
var createPortal = (children, container, key) => ({
|
|
1083
|
+
tag: HONO_PORTAL_ELEMENT,
|
|
1084
|
+
props: { children },
|
|
1085
|
+
key,
|
|
1086
|
+
e: container,
|
|
1087
|
+
p: 1
|
|
1088
|
+
});
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/hooks/index.js
|
|
1091
|
+
var STASH_SATE = 0;
|
|
1092
|
+
var STASH_CALLBACK = 2;
|
|
1093
|
+
var STASH_MEMO = 3;
|
|
1094
|
+
var STASH_REF = 4;
|
|
1095
|
+
var resolvedPromiseValueMap = /* @__PURE__ */ new WeakMap();
|
|
1096
|
+
var isDepsChanged = (prevDeps, deps) => !prevDeps || !deps || prevDeps.length !== deps.length || deps.some((dep, i) => dep !== prevDeps[i]);
|
|
1097
|
+
var updateHook = void 0;
|
|
1098
|
+
var pendingStack = [];
|
|
1099
|
+
var useState = (initialState) => {
|
|
1100
|
+
const resolveInitialState = () => typeof initialState === "function" ? initialState() : initialState;
|
|
1101
|
+
const buildData = buildDataStack.at(-1);
|
|
1102
|
+
if (!buildData) return [resolveInitialState(), () => {}];
|
|
1103
|
+
const [, node] = buildData;
|
|
1104
|
+
const stateArray = node[DOM_STASH][1][STASH_SATE] ||= [];
|
|
1105
|
+
const hookIndex = node[DOM_STASH][0]++;
|
|
1106
|
+
return stateArray[hookIndex] ||= [resolveInitialState(), (newState) => {
|
|
1107
|
+
const localUpdateHook = updateHook;
|
|
1108
|
+
const stateData = stateArray[hookIndex];
|
|
1109
|
+
if (typeof newState === "function") newState = newState(stateData[0]);
|
|
1110
|
+
if (!Object.is(newState, stateData[0])) {
|
|
1111
|
+
stateData[0] = newState;
|
|
1112
|
+
if (pendingStack.length) {
|
|
1113
|
+
const [pendingType, pendingPromise] = pendingStack.at(-1);
|
|
1114
|
+
Promise.all([pendingType === 3 ? node : update([
|
|
1115
|
+
pendingType,
|
|
1116
|
+
false,
|
|
1117
|
+
localUpdateHook
|
|
1118
|
+
], node), pendingPromise]).then(([node2]) => {
|
|
1119
|
+
if (!node2 || !(pendingType === 2 || pendingType === 3)) return;
|
|
1120
|
+
const lastVC = node2.vC;
|
|
1121
|
+
const addUpdateTask = () => {
|
|
1122
|
+
setTimeout(() => {
|
|
1123
|
+
if (lastVC !== node2.vC) return;
|
|
1124
|
+
update([
|
|
1125
|
+
pendingType === 3 ? 1 : 0,
|
|
1126
|
+
false,
|
|
1127
|
+
localUpdateHook
|
|
1128
|
+
], node2);
|
|
1129
|
+
});
|
|
1130
|
+
};
|
|
1131
|
+
requestAnimationFrame(addUpdateTask);
|
|
1132
|
+
});
|
|
1133
|
+
} else update([
|
|
1134
|
+
0,
|
|
1135
|
+
false,
|
|
1136
|
+
localUpdateHook
|
|
1137
|
+
], node);
|
|
1138
|
+
}
|
|
1139
|
+
}];
|
|
1140
|
+
};
|
|
1141
|
+
var useReducer = (reducer, initialArg, init) => {
|
|
1142
|
+
const handler = useCallback((action) => {
|
|
1143
|
+
setState((state2) => reducer(state2, action));
|
|
1144
|
+
}, [reducer]);
|
|
1145
|
+
const [state, setState] = useState(() => init ? init(initialArg) : initialArg);
|
|
1146
|
+
return [state, handler];
|
|
1147
|
+
};
|
|
1148
|
+
var useEffectCommon = (index, effect, deps) => {
|
|
1149
|
+
const buildData = buildDataStack.at(-1);
|
|
1150
|
+
if (!buildData) return;
|
|
1151
|
+
const [, node] = buildData;
|
|
1152
|
+
const effectDepsArray = node[DOM_STASH][1][1] ||= [];
|
|
1153
|
+
const hookIndex = node[DOM_STASH][0]++;
|
|
1154
|
+
const [prevDeps, , prevCleanup] = effectDepsArray[hookIndex] ||= [];
|
|
1155
|
+
if (isDepsChanged(prevDeps, deps)) {
|
|
1156
|
+
if (prevCleanup) prevCleanup();
|
|
1157
|
+
const runner = () => {
|
|
1158
|
+
data[index] = void 0;
|
|
1159
|
+
data[2] = effect();
|
|
1160
|
+
};
|
|
1161
|
+
const data = [
|
|
1162
|
+
deps,
|
|
1163
|
+
void 0,
|
|
1164
|
+
void 0,
|
|
1165
|
+
void 0,
|
|
1166
|
+
void 0
|
|
1167
|
+
];
|
|
1168
|
+
data[index] = runner;
|
|
1169
|
+
effectDepsArray[hookIndex] = data;
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
var useEffect = (effect, deps) => useEffectCommon(3, effect, deps);
|
|
1173
|
+
var useCallback = (callback, deps) => {
|
|
1174
|
+
const buildData = buildDataStack.at(-1);
|
|
1175
|
+
if (!buildData) return callback;
|
|
1176
|
+
const [, node] = buildData;
|
|
1177
|
+
const callbackArray = node[DOM_STASH][1][STASH_CALLBACK] ||= [];
|
|
1178
|
+
const hookIndex = node[DOM_STASH][0]++;
|
|
1179
|
+
const prevDeps = callbackArray[hookIndex];
|
|
1180
|
+
if (isDepsChanged(prevDeps?.[1], deps)) callbackArray[hookIndex] = [callback, deps];
|
|
1181
|
+
else callback = callbackArray[hookIndex][0];
|
|
1182
|
+
return callback;
|
|
1183
|
+
};
|
|
1184
|
+
var useRef = (initialValue) => {
|
|
1185
|
+
const buildData = buildDataStack.at(-1);
|
|
1186
|
+
if (!buildData) return { current: initialValue };
|
|
1187
|
+
const [, node] = buildData;
|
|
1188
|
+
const refArray = node[DOM_STASH][1][STASH_REF] ||= [];
|
|
1189
|
+
const hookIndex = node[DOM_STASH][0]++;
|
|
1190
|
+
return refArray[hookIndex] ||= { current: initialValue };
|
|
1191
|
+
};
|
|
1192
|
+
var use$1 = (promise) => {
|
|
1193
|
+
const cachedRes = resolvedPromiseValueMap.get(promise);
|
|
1194
|
+
if (cachedRes) {
|
|
1195
|
+
if (cachedRes.length === 2) throw cachedRes[1];
|
|
1196
|
+
return cachedRes[0];
|
|
1197
|
+
}
|
|
1198
|
+
promise.then((res) => resolvedPromiseValueMap.set(promise, [res]), (e) => resolvedPromiseValueMap.set(promise, [void 0, e]));
|
|
1199
|
+
throw promise;
|
|
1200
|
+
};
|
|
1201
|
+
var useMemo = (factory, deps) => {
|
|
1202
|
+
const buildData = buildDataStack.at(-1);
|
|
1203
|
+
if (!buildData) return factory();
|
|
1204
|
+
const [, node] = buildData;
|
|
1205
|
+
const memoArray = node[DOM_STASH][1][STASH_MEMO] ||= [];
|
|
1206
|
+
const hookIndex = node[DOM_STASH][0]++;
|
|
1207
|
+
const prevDeps = memoArray[hookIndex];
|
|
1208
|
+
if (isDepsChanged(prevDeps?.[1], deps)) memoArray[hookIndex] = [factory(), deps];
|
|
1209
|
+
return memoArray[hookIndex][0];
|
|
1210
|
+
};
|
|
1211
|
+
//#endregion
|
|
1212
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/dom/hooks/index.js
|
|
1213
|
+
var FormContext = createContext$1({
|
|
1214
|
+
pending: false,
|
|
1215
|
+
data: null,
|
|
1216
|
+
method: null,
|
|
1217
|
+
action: null
|
|
1218
|
+
});
|
|
1219
|
+
var actions = /* @__PURE__ */ new Set();
|
|
1220
|
+
var registerAction = (action) => {
|
|
1221
|
+
actions.add(action);
|
|
1222
|
+
action.finally(() => actions.delete(action));
|
|
1223
|
+
};
|
|
1224
|
+
//#endregion
|
|
1225
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js
|
|
1226
|
+
var components_exports = /* @__PURE__ */ __exportAll({
|
|
1227
|
+
button: () => button,
|
|
1228
|
+
clearCache: () => clearCache,
|
|
1229
|
+
composeRef: () => composeRef,
|
|
1230
|
+
form: () => form,
|
|
1231
|
+
input: () => input,
|
|
1232
|
+
link: () => link,
|
|
1233
|
+
meta: () => meta,
|
|
1234
|
+
script: () => script,
|
|
1235
|
+
style: () => style,
|
|
1236
|
+
title: () => title
|
|
1237
|
+
});
|
|
1238
|
+
var clearCache = () => {
|
|
1239
|
+
blockingPromiseMap = /* @__PURE__ */ Object.create(null);
|
|
1240
|
+
createdElements = /* @__PURE__ */ Object.create(null);
|
|
1241
|
+
};
|
|
1242
|
+
var composeRef = (ref, cb) => {
|
|
1243
|
+
return useMemo(() => (e) => {
|
|
1244
|
+
let refCleanup;
|
|
1245
|
+
if (ref) {
|
|
1246
|
+
if (typeof ref === "function") refCleanup = ref(e) || (() => {
|
|
1247
|
+
ref(null);
|
|
1248
|
+
});
|
|
1249
|
+
else if (ref && "current" in ref) {
|
|
1250
|
+
ref.current = e;
|
|
1251
|
+
refCleanup = () => {
|
|
1252
|
+
ref.current = null;
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
const cbCleanup = cb(e);
|
|
1257
|
+
return () => {
|
|
1258
|
+
cbCleanup?.();
|
|
1259
|
+
refCleanup?.();
|
|
1260
|
+
};
|
|
1261
|
+
}, [ref]);
|
|
1262
|
+
};
|
|
1263
|
+
var blockingPromiseMap = /* @__PURE__ */ Object.create(null);
|
|
1264
|
+
var createdElements = /* @__PURE__ */ Object.create(null);
|
|
1265
|
+
var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlocking) => {
|
|
1266
|
+
if (props?.itemProp) return {
|
|
1267
|
+
tag,
|
|
1268
|
+
props,
|
|
1269
|
+
type: tag,
|
|
1270
|
+
ref: props.ref
|
|
1271
|
+
};
|
|
1272
|
+
const head = document.head;
|
|
1273
|
+
let { onLoad, onError, precedence, blocking, ...restProps } = props;
|
|
1274
|
+
let element = null;
|
|
1275
|
+
let created = false;
|
|
1276
|
+
const deDupeKeys = deDupeKeyMap[tag];
|
|
1277
|
+
const deDupeByKey = shouldDeDupeByKey(tag, supportSort);
|
|
1278
|
+
const isDeDupeCandidateLink = (e) => e.getAttribute("rel") === "stylesheet" && e.getAttribute("data-precedence") !== null;
|
|
1279
|
+
let existingElements = void 0;
|
|
1280
|
+
if (deDupeByKey) {
|
|
1281
|
+
const tags = head.querySelectorAll(tag);
|
|
1282
|
+
LOOP: for (const e of tags) {
|
|
1283
|
+
if (tag === "link" && !isDeDupeCandidateLink(e)) continue;
|
|
1284
|
+
for (const key of deDupeKeys) if (e.getAttribute(key) === props[key]) {
|
|
1285
|
+
element = e;
|
|
1286
|
+
break LOOP;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (!element) {
|
|
1290
|
+
const cacheKey = deDupeKeys.reduce((acc, key) => props[key] === void 0 ? acc : `${acc}-${key}-${props[key]}`, tag);
|
|
1291
|
+
created = !createdElements[cacheKey];
|
|
1292
|
+
element = createdElements[cacheKey] ||= (() => {
|
|
1293
|
+
const e = document.createElement(tag);
|
|
1294
|
+
for (const key of deDupeKeys) if (props[key] !== void 0) e.setAttribute(key, props[key]);
|
|
1295
|
+
if (props.rel) e.setAttribute("rel", props.rel);
|
|
1296
|
+
return e;
|
|
1297
|
+
})();
|
|
1298
|
+
}
|
|
1299
|
+
} else existingElements = head.querySelectorAll(tag);
|
|
1300
|
+
precedence = supportSort ? precedence ?? "" : void 0;
|
|
1301
|
+
if (supportSort) restProps[dataPrecedenceAttr] = precedence;
|
|
1302
|
+
const insert = useCallback((e) => {
|
|
1303
|
+
if (deDupeByKey) {
|
|
1304
|
+
if (tag === "link" && precedence !== void 0) {
|
|
1305
|
+
let found2 = false;
|
|
1306
|
+
for (const existingElement of head.querySelectorAll(tag)) {
|
|
1307
|
+
const existingPrecedence = existingElement.getAttribute(dataPrecedenceAttr);
|
|
1308
|
+
if (existingPrecedence === null) {
|
|
1309
|
+
head.insertBefore(e, existingElement);
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
if (found2 && existingPrecedence !== precedence) {
|
|
1313
|
+
head.insertBefore(e, existingElement);
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
if (existingPrecedence === precedence) found2 = true;
|
|
1317
|
+
}
|
|
1318
|
+
head.appendChild(e);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
let found = false;
|
|
1322
|
+
for (const existingElement of head.querySelectorAll(tag)) {
|
|
1323
|
+
if (found && existingElement.getAttribute("data-precedence") !== precedence) {
|
|
1324
|
+
head.insertBefore(e, existingElement);
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
if (existingElement.getAttribute("data-precedence") === precedence) found = true;
|
|
1328
|
+
}
|
|
1329
|
+
head.appendChild(e);
|
|
1330
|
+
} else if (tag === "link") {
|
|
1331
|
+
if (!head.contains(e)) head.appendChild(e);
|
|
1332
|
+
} else if (existingElements) {
|
|
1333
|
+
let found = false;
|
|
1334
|
+
for (const existingElement of existingElements) if (existingElement === e) {
|
|
1335
|
+
found = true;
|
|
1336
|
+
break;
|
|
1337
|
+
}
|
|
1338
|
+
if (!found) head.insertBefore(e, head.contains(existingElements[0]) ? existingElements[0] : head.querySelector(tag));
|
|
1339
|
+
existingElements = void 0;
|
|
1340
|
+
}
|
|
1341
|
+
}, [
|
|
1342
|
+
deDupeByKey,
|
|
1343
|
+
precedence,
|
|
1344
|
+
tag
|
|
1345
|
+
]);
|
|
1346
|
+
const ref = composeRef(props.ref, (e) => {
|
|
1347
|
+
const key = deDupeKeys[0];
|
|
1348
|
+
if (preserveNodeType === 2) e.innerHTML = "";
|
|
1349
|
+
if (created || existingElements) insert(e);
|
|
1350
|
+
if (!onError && !onLoad) return;
|
|
1351
|
+
if (!key) return;
|
|
1352
|
+
let promise = blockingPromiseMap[e.getAttribute(key)] ||= new Promise((resolve, reject) => {
|
|
1353
|
+
e.addEventListener("load", resolve);
|
|
1354
|
+
e.addEventListener("error", reject);
|
|
1355
|
+
});
|
|
1356
|
+
if (onLoad) promise = promise.then(onLoad);
|
|
1357
|
+
if (onError) promise = promise.catch(onError);
|
|
1358
|
+
promise.catch(() => {});
|
|
1359
|
+
});
|
|
1360
|
+
if (supportBlocking && blocking === "render") {
|
|
1361
|
+
const key = deDupeKeyMap[tag][0];
|
|
1362
|
+
if (key && props[key]) {
|
|
1363
|
+
const value = props[key];
|
|
1364
|
+
use$1(blockingPromiseMap[value] ||= new Promise((resolve, reject) => {
|
|
1365
|
+
insert(element);
|
|
1366
|
+
element.addEventListener("load", resolve);
|
|
1367
|
+
element.addEventListener("error", reject);
|
|
1368
|
+
}));
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
const jsxNode = {
|
|
1372
|
+
tag,
|
|
1373
|
+
type: tag,
|
|
1374
|
+
props: {
|
|
1375
|
+
...restProps,
|
|
1376
|
+
ref
|
|
1377
|
+
},
|
|
1378
|
+
ref
|
|
1379
|
+
};
|
|
1380
|
+
jsxNode.p = preserveNodeType;
|
|
1381
|
+
if (element) jsxNode.e = element;
|
|
1382
|
+
return createPortal(jsxNode, head);
|
|
1383
|
+
};
|
|
1384
|
+
var title = (props) => {
|
|
1385
|
+
const nameSpaceContext = getNameSpaceContext();
|
|
1386
|
+
if ((nameSpaceContext && useContext(nameSpaceContext))?.endsWith("svg")) return {
|
|
1387
|
+
tag: "title",
|
|
1388
|
+
props,
|
|
1389
|
+
type: "title",
|
|
1390
|
+
ref: props.ref
|
|
1391
|
+
};
|
|
1392
|
+
return documentMetadataTag("title", props, void 0, false, false);
|
|
1393
|
+
};
|
|
1394
|
+
var script = (props) => {
|
|
1395
|
+
if (!props || ["src", "async"].some((k) => !props[k])) return {
|
|
1396
|
+
tag: "script",
|
|
1397
|
+
props,
|
|
1398
|
+
type: "script",
|
|
1399
|
+
ref: props.ref
|
|
1400
|
+
};
|
|
1401
|
+
return documentMetadataTag("script", props, 1, false, true);
|
|
1402
|
+
};
|
|
1403
|
+
var style = (props) => {
|
|
1404
|
+
if (!props || !["href", "precedence"].every((k) => k in props)) return {
|
|
1405
|
+
tag: "style",
|
|
1406
|
+
props,
|
|
1407
|
+
type: "style",
|
|
1408
|
+
ref: props.ref
|
|
1409
|
+
};
|
|
1410
|
+
props["data-href"] = props.href;
|
|
1411
|
+
delete props.href;
|
|
1412
|
+
return documentMetadataTag("style", props, 2, true, true);
|
|
1413
|
+
};
|
|
1414
|
+
var link = (props) => {
|
|
1415
|
+
if (!props || ["onLoad", "onError"].some((k) => k in props) || props.rel === "stylesheet" && (!("precedence" in props) || "disabled" in props)) return {
|
|
1416
|
+
tag: "link",
|
|
1417
|
+
props,
|
|
1418
|
+
type: "link",
|
|
1419
|
+
ref: props.ref
|
|
1420
|
+
};
|
|
1421
|
+
return documentMetadataTag("link", props, 1, isStylesheetLinkWithPrecedence(props), true);
|
|
1422
|
+
};
|
|
1423
|
+
var meta = (props) => {
|
|
1424
|
+
return documentMetadataTag("meta", props, void 0, false, false);
|
|
1425
|
+
};
|
|
1426
|
+
var customEventFormAction = /* @__PURE__ */ Symbol();
|
|
1427
|
+
var form = (props) => {
|
|
1428
|
+
const { action, ...restProps } = props;
|
|
1429
|
+
if (typeof action !== "function") restProps.action = action;
|
|
1430
|
+
const [state, setState] = useState([null, false]);
|
|
1431
|
+
const onSubmit = useCallback(async (ev) => {
|
|
1432
|
+
const currentAction = ev.isTrusted ? action : ev.detail[customEventFormAction];
|
|
1433
|
+
if (typeof currentAction !== "function") return;
|
|
1434
|
+
ev.preventDefault();
|
|
1435
|
+
const formData = new FormData(ev.target);
|
|
1436
|
+
setState([formData, true]);
|
|
1437
|
+
const actionRes = currentAction(formData);
|
|
1438
|
+
if (actionRes instanceof Promise) {
|
|
1439
|
+
registerAction(actionRes);
|
|
1440
|
+
await actionRes;
|
|
1441
|
+
}
|
|
1442
|
+
setState([null, true]);
|
|
1443
|
+
}, []);
|
|
1444
|
+
const ref = composeRef(props.ref, (el) => {
|
|
1445
|
+
el.addEventListener("submit", onSubmit);
|
|
1446
|
+
return () => {
|
|
1447
|
+
el.removeEventListener("submit", onSubmit);
|
|
1448
|
+
};
|
|
1449
|
+
});
|
|
1450
|
+
const [data, isDirty] = state;
|
|
1451
|
+
state[1] = false;
|
|
1452
|
+
return {
|
|
1453
|
+
tag: FormContext,
|
|
1454
|
+
props: {
|
|
1455
|
+
value: {
|
|
1456
|
+
pending: data !== null,
|
|
1457
|
+
data,
|
|
1458
|
+
method: data ? "post" : null,
|
|
1459
|
+
action: data ? action : null
|
|
1460
|
+
},
|
|
1461
|
+
children: {
|
|
1462
|
+
tag: "form",
|
|
1463
|
+
props: {
|
|
1464
|
+
...restProps,
|
|
1465
|
+
ref
|
|
1466
|
+
},
|
|
1467
|
+
type: "form",
|
|
1468
|
+
ref
|
|
1469
|
+
}
|
|
1470
|
+
},
|
|
1471
|
+
f: isDirty
|
|
1472
|
+
};
|
|
1473
|
+
};
|
|
1474
|
+
var formActionableElement = (tag, { formAction, ...props }) => {
|
|
1475
|
+
if (typeof formAction === "function") {
|
|
1476
|
+
const onClick = useCallback((ev) => {
|
|
1477
|
+
ev.preventDefault();
|
|
1478
|
+
ev.currentTarget.form.dispatchEvent(new CustomEvent("submit", { detail: { [customEventFormAction]: formAction } }));
|
|
1479
|
+
}, []);
|
|
1480
|
+
props.ref = composeRef(props.ref, (el) => {
|
|
1481
|
+
el.addEventListener("click", onClick);
|
|
1482
|
+
return () => {
|
|
1483
|
+
el.removeEventListener("click", onClick);
|
|
1484
|
+
};
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
return {
|
|
1488
|
+
tag,
|
|
1489
|
+
props,
|
|
1490
|
+
type: tag,
|
|
1491
|
+
ref: props.ref
|
|
1492
|
+
};
|
|
1493
|
+
};
|
|
1494
|
+
var input = (props) => formActionableElement("input", props);
|
|
1495
|
+
var button = (props) => formActionableElement("button", props);
|
|
1496
|
+
Object.assign(domRenderers, {
|
|
1497
|
+
title,
|
|
1498
|
+
script,
|
|
1499
|
+
style,
|
|
1500
|
+
link,
|
|
1501
|
+
meta,
|
|
1502
|
+
form,
|
|
1503
|
+
input,
|
|
1504
|
+
button
|
|
1505
|
+
});
|
|
1506
|
+
//#endregion
|
|
1507
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/dom/jsx-dev-runtime.js
|
|
1508
|
+
var jsxDEV$1 = (tag, props, key) => {
|
|
1509
|
+
if (typeof tag === "string" && components_exports[tag]) tag = components_exports[tag];
|
|
1510
|
+
return {
|
|
1511
|
+
tag,
|
|
1512
|
+
type: tag,
|
|
1513
|
+
props,
|
|
1514
|
+
key,
|
|
1515
|
+
ref: props.ref
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1518
|
+
var Fragment = (props) => jsxDEV$1("", props, void 0);
|
|
1519
|
+
//#endregion
|
|
1520
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/dom/components.js
|
|
1521
|
+
var ErrorBoundary$1 = (({ children, fallback, fallbackRender, onError }) => {
|
|
1522
|
+
const res = Fragment({ children });
|
|
1523
|
+
res[DOM_ERROR_HANDLER] = (err) => {
|
|
1524
|
+
if (err instanceof Promise) throw err;
|
|
1525
|
+
onError?.(err);
|
|
1526
|
+
return fallbackRender?.(err) || fallback;
|
|
1527
|
+
};
|
|
1528
|
+
return res;
|
|
1529
|
+
});
|
|
1530
|
+
var Suspense$1 = (({ children, fallback }) => {
|
|
1531
|
+
const res = Fragment({ children });
|
|
1532
|
+
res[DOM_ERROR_HANDLER] = (err, retry) => {
|
|
1533
|
+
if (!(err instanceof Promise)) throw err;
|
|
1534
|
+
err.finally(retry);
|
|
1535
|
+
return fallback;
|
|
1536
|
+
};
|
|
1537
|
+
return res;
|
|
1538
|
+
});
|
|
1539
|
+
//#endregion
|
|
1540
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/streaming.js
|
|
1541
|
+
var StreamingContext = createContext(null);
|
|
1542
|
+
var suspenseCounter = 0;
|
|
1543
|
+
var Suspense = async ({ children, fallback }) => {
|
|
1544
|
+
if (!Array.isArray(children)) children = [children];
|
|
1545
|
+
const nonce = useContext(StreamingContext)?.scriptNonce;
|
|
1546
|
+
let resArray = [];
|
|
1547
|
+
const stackNode = { [DOM_STASH]: [0, []] };
|
|
1548
|
+
const popNodeStack = (value) => {
|
|
1549
|
+
buildDataStack.pop();
|
|
1550
|
+
return value;
|
|
1551
|
+
};
|
|
1552
|
+
try {
|
|
1553
|
+
stackNode[DOM_STASH][0] = 0;
|
|
1554
|
+
buildDataStack.push([[], stackNode]);
|
|
1555
|
+
resArray = children.map((c) => c == null || typeof c === "boolean" ? "" : c.toString());
|
|
1556
|
+
} catch (e) {
|
|
1557
|
+
if (e instanceof Promise) resArray = [e.then(() => {
|
|
1558
|
+
stackNode[DOM_STASH][0] = 0;
|
|
1559
|
+
buildDataStack.push([[], stackNode]);
|
|
1560
|
+
return childrenToString(children).then(popNodeStack);
|
|
1561
|
+
})];
|
|
1562
|
+
else throw e;
|
|
1563
|
+
} finally {
|
|
1564
|
+
popNodeStack();
|
|
1565
|
+
}
|
|
1566
|
+
if (resArray.some((res) => res instanceof Promise)) {
|
|
1567
|
+
const index = suspenseCounter++;
|
|
1568
|
+
const fallbackStr = await fallback.toString();
|
|
1569
|
+
return raw(`<template id="H:${index}"></template>${fallbackStr}<!--/$-->`, [...fallbackStr.callbacks || [], ({ phase, buffer, context }) => {
|
|
1570
|
+
if (phase === HtmlEscapedCallbackPhase.BeforeStream) return;
|
|
1571
|
+
return Promise.all(resArray).then(async (htmlArray) => {
|
|
1572
|
+
htmlArray = htmlArray.flat();
|
|
1573
|
+
const content = htmlArray.join("");
|
|
1574
|
+
if (buffer) buffer[0] = buffer[0].replace(new RegExp(`<template id="H:${index}"></template>.*?<!--/\\$-->`), content);
|
|
1575
|
+
let html = buffer ? "" : `<template data-hono-target="H:${index}">${content}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
1576
|
+
((d,c,n) => {
|
|
1577
|
+
c=d.currentScript.previousSibling
|
|
1578
|
+
d=d.getElementById('H:${index}')
|
|
1579
|
+
if(!d)return
|
|
1580
|
+
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='/$')
|
|
1581
|
+
d.replaceWith(c.content)
|
|
1582
|
+
})(document)
|
|
1583
|
+
<\/script>`;
|
|
1584
|
+
const callbacks = htmlArray.map((html2) => html2.callbacks || []).flat();
|
|
1585
|
+
if (!callbacks.length) return html;
|
|
1586
|
+
if (phase === HtmlEscapedCallbackPhase.Stream) html = await resolveCallback(html, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
1587
|
+
return raw(html, callbacks);
|
|
1588
|
+
});
|
|
1589
|
+
}]);
|
|
1590
|
+
} else return raw(resArray.join(""));
|
|
1591
|
+
};
|
|
1592
|
+
Suspense[DOM_RENDERER] = Suspense$1;
|
|
1593
|
+
new TextEncoder();
|
|
1594
|
+
//#endregion
|
|
1595
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/components.js
|
|
1596
|
+
var errorBoundaryCounter = 0;
|
|
1597
|
+
var childrenToString = async (children) => {
|
|
1598
|
+
try {
|
|
1599
|
+
return children.flat().map((c) => c == null || typeof c === "boolean" ? "" : c.toString());
|
|
1600
|
+
} catch (e) {
|
|
1601
|
+
if (e instanceof Promise) {
|
|
1602
|
+
await e;
|
|
1603
|
+
return childrenToString(children);
|
|
1604
|
+
} else throw e;
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
var resolveChildEarly = (c) => {
|
|
1608
|
+
if (c == null || typeof c === "boolean") return "";
|
|
1609
|
+
else if (typeof c === "string") return c;
|
|
1610
|
+
else {
|
|
1611
|
+
const str = c.toString();
|
|
1612
|
+
if (!(str instanceof Promise)) return raw(str);
|
|
1613
|
+
else return str;
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
|
|
1617
|
+
if (!children) return raw("");
|
|
1618
|
+
if (!Array.isArray(children)) children = [children];
|
|
1619
|
+
const nonce = useContext(StreamingContext)?.scriptNonce;
|
|
1620
|
+
let fallbackStr;
|
|
1621
|
+
const resolveFallbackStr = async () => {
|
|
1622
|
+
const awaitedFallback = await fallback;
|
|
1623
|
+
if (typeof awaitedFallback === "string") fallbackStr = awaitedFallback;
|
|
1624
|
+
else {
|
|
1625
|
+
fallbackStr = await awaitedFallback?.toString();
|
|
1626
|
+
if (typeof fallbackStr === "string") fallbackStr = raw(fallbackStr);
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
const fallbackRes = (error) => {
|
|
1630
|
+
onError?.(error);
|
|
1631
|
+
return fallbackStr || fallbackRender && jsx(Fragment$1, {}, fallbackRender(error)) || "";
|
|
1632
|
+
};
|
|
1633
|
+
let resArray = [];
|
|
1634
|
+
try {
|
|
1635
|
+
resArray = children.map(resolveChildEarly);
|
|
1636
|
+
} catch (e) {
|
|
1637
|
+
await resolveFallbackStr();
|
|
1638
|
+
if (e instanceof Promise) resArray = [e.then(() => childrenToString(children)).catch((e2) => fallbackRes(e2))];
|
|
1639
|
+
else resArray = [fallbackRes(e)];
|
|
1640
|
+
}
|
|
1641
|
+
if (resArray.some((res) => res instanceof Promise)) {
|
|
1642
|
+
await resolveFallbackStr();
|
|
1643
|
+
const index = errorBoundaryCounter++;
|
|
1644
|
+
const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
|
|
1645
|
+
const catchCallback = async ({ error: error2, buffer }) => {
|
|
1646
|
+
const fallbackResString = await Fragment$1({ children: fallbackRes(error2) }).toString();
|
|
1647
|
+
if (buffer) buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
|
|
1648
|
+
return buffer ? "" : `<template data-hono-target="E:${index}">${fallbackResString}</template><script>
|
|
1649
|
+
((d,c,n) => {
|
|
1650
|
+
c=d.currentScript.previousSibling
|
|
1651
|
+
d=d.getElementById('E:${index}')
|
|
1652
|
+
if(!d)return
|
|
1653
|
+
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
|
|
1654
|
+
d.replaceWith(c.content)
|
|
1655
|
+
})(document)
|
|
1656
|
+
<\/script>`;
|
|
1657
|
+
};
|
|
1658
|
+
let error;
|
|
1659
|
+
const promiseAll = Promise.all(resArray).catch((e) => error = e);
|
|
1660
|
+
return raw(`<template id="E:${index}"></template><!--E:${index}-->`, [({ phase, buffer, context }) => {
|
|
1661
|
+
if (phase === HtmlEscapedCallbackPhase.BeforeStream) return;
|
|
1662
|
+
return promiseAll.then(async (htmlArray) => {
|
|
1663
|
+
if (error) throw error;
|
|
1664
|
+
htmlArray = htmlArray.flat();
|
|
1665
|
+
const content = htmlArray.join("");
|
|
1666
|
+
let html = buffer ? "" : `<template data-hono-target="E:${index}">${content}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
1667
|
+
((d,c) => {
|
|
1668
|
+
c=d.currentScript.previousSibling
|
|
1669
|
+
d=d.getElementById('E:${index}')
|
|
1670
|
+
if(!d)return
|
|
1671
|
+
d.parentElement.insertBefore(c.content,d.nextSibling)
|
|
1672
|
+
})(document)
|
|
1673
|
+
<\/script>`;
|
|
1674
|
+
if (htmlArray.every((html2) => !html2.callbacks?.length)) {
|
|
1675
|
+
if (buffer) buffer[0] = buffer[0].replace(replaceRe, content);
|
|
1676
|
+
return html;
|
|
1677
|
+
}
|
|
1678
|
+
if (buffer) buffer[0] = buffer[0].replace(replaceRe, (_all, pre, _, post) => `${pre}${content}${post}`);
|
|
1679
|
+
const callbacks = htmlArray.map((html2) => html2.callbacks || []).flat();
|
|
1680
|
+
if (phase === HtmlEscapedCallbackPhase.Stream) html = await resolveCallback(html, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
1681
|
+
let resolvedCount = 0;
|
|
1682
|
+
const promises = callbacks.map((c) => (...args) => c(...args)?.then((content2) => {
|
|
1683
|
+
resolvedCount++;
|
|
1684
|
+
if (buffer) {
|
|
1685
|
+
if (resolvedCount === callbacks.length) buffer[0] = buffer[0].replace(replaceRe, (_all, _pre, content3) => content3);
|
|
1686
|
+
buffer[0] += content2;
|
|
1687
|
+
return raw("", content2.callbacks);
|
|
1688
|
+
}
|
|
1689
|
+
return raw(content2 + (resolvedCount !== callbacks.length ? "" : `<script>
|
|
1690
|
+
((d,c,n) => {
|
|
1691
|
+
d=d.getElementById('E:${index}')
|
|
1692
|
+
if(!d)return
|
|
1693
|
+
n=d.nextSibling
|
|
1694
|
+
while(n.nodeType!=8||n.nodeValue!='E:${index}'){n=n.nextSibling}
|
|
1695
|
+
n.remove()
|
|
1696
|
+
d.remove()
|
|
1697
|
+
})(document)
|
|
1698
|
+
<\/script>`), content2.callbacks);
|
|
1699
|
+
}).catch((error2) => catchCallback({
|
|
1700
|
+
error: error2,
|
|
1701
|
+
buffer
|
|
1702
|
+
})));
|
|
1703
|
+
return raw(html, promises);
|
|
1704
|
+
}).catch((error2) => catchCallback({
|
|
1705
|
+
error: error2,
|
|
1706
|
+
buffer
|
|
1707
|
+
}));
|
|
1708
|
+
}]);
|
|
1709
|
+
} else return Fragment$1({ children: resArray });
|
|
1710
|
+
};
|
|
1711
|
+
ErrorBoundary[DOM_RENDERER] = ErrorBoundary$1;
|
|
1712
|
+
//#endregion
|
|
1713
|
+
//#region node_modules/.pnpm/i18next@26.1.0_typescript@6.0.3/node_modules/i18next/dist/esm/i18next.js
|
|
1714
|
+
const isString = (obj) => typeof obj === "string";
|
|
1715
|
+
const defer = () => {
|
|
1716
|
+
let res;
|
|
1717
|
+
let rej;
|
|
1718
|
+
const promise = new Promise((resolve, reject) => {
|
|
1719
|
+
res = resolve;
|
|
1720
|
+
rej = reject;
|
|
1721
|
+
});
|
|
1722
|
+
promise.resolve = res;
|
|
1723
|
+
promise.reject = rej;
|
|
1724
|
+
return promise;
|
|
1725
|
+
};
|
|
1726
|
+
const makeString = (object) => {
|
|
1727
|
+
if (object == null) return "";
|
|
1728
|
+
return String(object);
|
|
1729
|
+
};
|
|
1730
|
+
const copy = (a, s, t) => {
|
|
1731
|
+
a.forEach((m) => {
|
|
1732
|
+
if (s[m]) t[m] = s[m];
|
|
1733
|
+
});
|
|
1734
|
+
};
|
|
1735
|
+
const lastOfPathSeparatorRegExp = /###/g;
|
|
1736
|
+
const cleanKey = (key) => key && key.includes("###") ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
1737
|
+
const canNotTraverseDeeper = (object) => !object || isString(object);
|
|
1738
|
+
const getLastOfPath = (object, path, Empty) => {
|
|
1739
|
+
const stack = !isString(path) ? path : path.split(".");
|
|
1740
|
+
let stackIndex = 0;
|
|
1741
|
+
while (stackIndex < stack.length - 1) {
|
|
1742
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
1743
|
+
const key = cleanKey(stack[stackIndex]);
|
|
1744
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
1745
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) object = object[key];
|
|
1746
|
+
else object = {};
|
|
1747
|
+
++stackIndex;
|
|
1748
|
+
}
|
|
1749
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
1750
|
+
return {
|
|
1751
|
+
obj: object,
|
|
1752
|
+
k: cleanKey(stack[stackIndex])
|
|
1753
|
+
};
|
|
1754
|
+
};
|
|
1755
|
+
const setPath = (object, path, newValue) => {
|
|
1756
|
+
const { obj, k } = getLastOfPath(object, path, Object);
|
|
1757
|
+
if (obj !== void 0 || path.length === 1) {
|
|
1758
|
+
obj[k] = newValue;
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
let e = path[path.length - 1];
|
|
1762
|
+
let p = path.slice(0, path.length - 1);
|
|
1763
|
+
let last = getLastOfPath(object, p, Object);
|
|
1764
|
+
while (last.obj === void 0 && p.length) {
|
|
1765
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
1766
|
+
p = p.slice(0, p.length - 1);
|
|
1767
|
+
last = getLastOfPath(object, p, Object);
|
|
1768
|
+
if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") last.obj = void 0;
|
|
1769
|
+
}
|
|
1770
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
1771
|
+
};
|
|
1772
|
+
const pushPath = (object, path, newValue, concat) => {
|
|
1773
|
+
const { obj, k } = getLastOfPath(object, path, Object);
|
|
1774
|
+
obj[k] = obj[k] || [];
|
|
1775
|
+
obj[k].push(newValue);
|
|
1776
|
+
};
|
|
1777
|
+
const getPath = (object, path) => {
|
|
1778
|
+
const { obj, k } = getLastOfPath(object, path);
|
|
1779
|
+
if (!obj) return void 0;
|
|
1780
|
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
|
|
1781
|
+
return obj[k];
|
|
1782
|
+
};
|
|
1783
|
+
const getPathWithDefaults = (data, defaultData, key) => {
|
|
1784
|
+
const value = getPath(data, key);
|
|
1785
|
+
if (value !== void 0) return value;
|
|
1786
|
+
return getPath(defaultData, key);
|
|
1787
|
+
};
|
|
1788
|
+
const deepExtend = (target, source, overwrite) => {
|
|
1789
|
+
for (const prop in source) if (prop !== "__proto__" && prop !== "constructor") if (prop in target) if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
1790
|
+
if (overwrite) target[prop] = source[prop];
|
|
1791
|
+
} else deepExtend(target[prop], source[prop], overwrite);
|
|
1792
|
+
else target[prop] = source[prop];
|
|
1793
|
+
return target;
|
|
1794
|
+
};
|
|
1795
|
+
const regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
1796
|
+
const _entityMap = {
|
|
1797
|
+
"&": "&",
|
|
1798
|
+
"<": "<",
|
|
1799
|
+
">": ">",
|
|
1800
|
+
"\"": """,
|
|
1801
|
+
"'": "'",
|
|
1802
|
+
"/": "/"
|
|
1803
|
+
};
|
|
1804
|
+
const escape = (data) => {
|
|
1805
|
+
if (isString(data)) return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
1806
|
+
return data;
|
|
1807
|
+
};
|
|
1808
|
+
var RegExpCache = class {
|
|
1809
|
+
constructor(capacity) {
|
|
1810
|
+
this.capacity = capacity;
|
|
1811
|
+
this.regExpMap = /* @__PURE__ */ new Map();
|
|
1812
|
+
this.regExpQueue = [];
|
|
1813
|
+
}
|
|
1814
|
+
getRegExp(pattern) {
|
|
1815
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
1816
|
+
if (regExpFromCache !== void 0) return regExpFromCache;
|
|
1817
|
+
const regExpNew = new RegExp(pattern);
|
|
1818
|
+
if (this.regExpQueue.length === this.capacity) this.regExpMap.delete(this.regExpQueue.shift());
|
|
1819
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
1820
|
+
this.regExpQueue.push(pattern);
|
|
1821
|
+
return regExpNew;
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
const chars = [
|
|
1825
|
+
" ",
|
|
1826
|
+
",",
|
|
1827
|
+
"?",
|
|
1828
|
+
"!",
|
|
1829
|
+
";"
|
|
1830
|
+
];
|
|
1831
|
+
const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
1832
|
+
const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
1833
|
+
nsSeparator = nsSeparator || "";
|
|
1834
|
+
keySeparator = keySeparator || "";
|
|
1835
|
+
const possibleChars = chars.filter((c) => !nsSeparator.includes(c) && !keySeparator.includes(c));
|
|
1836
|
+
if (possibleChars.length === 0) return true;
|
|
1837
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
1838
|
+
let matched = !r.test(key);
|
|
1839
|
+
if (!matched) {
|
|
1840
|
+
const ki = key.indexOf(keySeparator);
|
|
1841
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) matched = true;
|
|
1842
|
+
}
|
|
1843
|
+
return matched;
|
|
1844
|
+
};
|
|
1845
|
+
const deepFind = (obj, path, keySeparator = ".") => {
|
|
1846
|
+
if (!obj) return void 0;
|
|
1847
|
+
if (obj[path]) {
|
|
1848
|
+
if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
|
|
1849
|
+
return obj[path];
|
|
1850
|
+
}
|
|
1851
|
+
const tokens = path.split(keySeparator);
|
|
1852
|
+
let current = obj;
|
|
1853
|
+
for (let i = 0; i < tokens.length;) {
|
|
1854
|
+
if (!current || typeof current !== "object") return;
|
|
1855
|
+
let next;
|
|
1856
|
+
let nextPath = "";
|
|
1857
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
1858
|
+
if (j !== i) nextPath += keySeparator;
|
|
1859
|
+
nextPath += tokens[j];
|
|
1860
|
+
next = current[nextPath];
|
|
1861
|
+
if (next !== void 0) {
|
|
1862
|
+
if ([
|
|
1863
|
+
"string",
|
|
1864
|
+
"number",
|
|
1865
|
+
"boolean"
|
|
1866
|
+
].includes(typeof next) && j < tokens.length - 1) continue;
|
|
1867
|
+
i += j - i + 1;
|
|
1868
|
+
break;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
current = next;
|
|
1872
|
+
}
|
|
1873
|
+
return current;
|
|
1874
|
+
};
|
|
1875
|
+
const getCleanedCode = (code) => code?.replace(/_/g, "-");
|
|
1876
|
+
const consoleLogger = {
|
|
1877
|
+
type: "logger",
|
|
1878
|
+
log(args) {
|
|
1879
|
+
this.output("log", args);
|
|
1880
|
+
},
|
|
1881
|
+
warn(args) {
|
|
1882
|
+
this.output("warn", args);
|
|
1883
|
+
},
|
|
1884
|
+
error(args) {
|
|
1885
|
+
this.output("error", args);
|
|
1886
|
+
},
|
|
1887
|
+
output(type, args) {
|
|
1888
|
+
console?.[type]?.apply?.(console, args);
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
var baseLogger = new class Logger {
|
|
1892
|
+
constructor(concreteLogger, options = {}) {
|
|
1893
|
+
this.init(concreteLogger, options);
|
|
1894
|
+
}
|
|
1895
|
+
init(concreteLogger, options = {}) {
|
|
1896
|
+
this.prefix = options.prefix || "i18next:";
|
|
1897
|
+
this.logger = concreteLogger || consoleLogger;
|
|
1898
|
+
this.options = options;
|
|
1899
|
+
this.debug = options.debug;
|
|
1900
|
+
}
|
|
1901
|
+
log(...args) {
|
|
1902
|
+
return this.forward(args, "log", "", true);
|
|
1903
|
+
}
|
|
1904
|
+
warn(...args) {
|
|
1905
|
+
return this.forward(args, "warn", "", true);
|
|
1906
|
+
}
|
|
1907
|
+
error(...args) {
|
|
1908
|
+
return this.forward(args, "error", "");
|
|
1909
|
+
}
|
|
1910
|
+
deprecate(...args) {
|
|
1911
|
+
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
1912
|
+
}
|
|
1913
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
1914
|
+
if (debugOnly && !this.debug) return null;
|
|
1915
|
+
args = args.map((a) => isString(a) ? a.replace(/[\r\n\x00-\x1F\x7F]/g, " ") : a);
|
|
1916
|
+
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
1917
|
+
return this.logger[lvl](args);
|
|
1918
|
+
}
|
|
1919
|
+
create(moduleName) {
|
|
1920
|
+
return new Logger(this.logger, {
|
|
1921
|
+
prefix: `${this.prefix}:${moduleName}:`,
|
|
1922
|
+
...this.options
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
clone(options) {
|
|
1926
|
+
options = options || this.options;
|
|
1927
|
+
options.prefix = options.prefix || this.prefix;
|
|
1928
|
+
return new Logger(this.logger, options);
|
|
1929
|
+
}
|
|
1930
|
+
}();
|
|
1931
|
+
var EventEmitter = class {
|
|
1932
|
+
constructor() {
|
|
1933
|
+
this.observers = {};
|
|
1934
|
+
}
|
|
1935
|
+
on(events, listener) {
|
|
1936
|
+
events.split(" ").forEach((event) => {
|
|
1937
|
+
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
1938
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
1939
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
1940
|
+
});
|
|
1941
|
+
return this;
|
|
1942
|
+
}
|
|
1943
|
+
off(event, listener) {
|
|
1944
|
+
if (!this.observers[event]) return;
|
|
1945
|
+
if (!listener) {
|
|
1946
|
+
delete this.observers[event];
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
this.observers[event].delete(listener);
|
|
1950
|
+
}
|
|
1951
|
+
once(event, listener) {
|
|
1952
|
+
const wrapper = (...args) => {
|
|
1953
|
+
listener(...args);
|
|
1954
|
+
this.off(event, wrapper);
|
|
1955
|
+
};
|
|
1956
|
+
this.on(event, wrapper);
|
|
1957
|
+
return this;
|
|
1958
|
+
}
|
|
1959
|
+
emit(event, ...args) {
|
|
1960
|
+
if (this.observers[event]) Array.from(this.observers[event].entries()).forEach(([observer, numTimesAdded]) => {
|
|
1961
|
+
for (let i = 0; i < numTimesAdded; i++) observer(...args);
|
|
1962
|
+
});
|
|
1963
|
+
if (this.observers["*"]) Array.from(this.observers["*"].entries()).forEach(([observer, numTimesAdded]) => {
|
|
1964
|
+
for (let i = 0; i < numTimesAdded; i++) observer(event, ...args);
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
var ResourceStore = class extends EventEmitter {
|
|
1969
|
+
constructor(data, options = {
|
|
1970
|
+
ns: ["translation"],
|
|
1971
|
+
defaultNS: "translation"
|
|
1972
|
+
}) {
|
|
1973
|
+
super();
|
|
1974
|
+
this.data = data || {};
|
|
1975
|
+
this.options = options;
|
|
1976
|
+
if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
|
|
1977
|
+
if (this.options.ignoreJSONStructure === void 0) this.options.ignoreJSONStructure = true;
|
|
1978
|
+
}
|
|
1979
|
+
addNamespaces(ns) {
|
|
1980
|
+
if (!this.options.ns.includes(ns)) this.options.ns.push(ns);
|
|
1981
|
+
}
|
|
1982
|
+
removeNamespaces(ns) {
|
|
1983
|
+
const index = this.options.ns.indexOf(ns);
|
|
1984
|
+
if (index > -1) this.options.ns.splice(index, 1);
|
|
1985
|
+
}
|
|
1986
|
+
getResource(lng, ns, key, options = {}) {
|
|
1987
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
1988
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
1989
|
+
let path;
|
|
1990
|
+
if (lng.includes(".")) path = lng.split(".");
|
|
1991
|
+
else {
|
|
1992
|
+
path = [lng, ns];
|
|
1993
|
+
if (key) if (Array.isArray(key)) path.push(...key);
|
|
1994
|
+
else if (isString(key) && keySeparator) path.push(...key.split(keySeparator));
|
|
1995
|
+
else path.push(key);
|
|
1996
|
+
}
|
|
1997
|
+
const result = getPath(this.data, path);
|
|
1998
|
+
if (!result && !ns && !key && lng.includes(".")) {
|
|
1999
|
+
lng = path[0];
|
|
2000
|
+
ns = path[1];
|
|
2001
|
+
key = path.slice(2).join(".");
|
|
2002
|
+
}
|
|
2003
|
+
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
2004
|
+
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
2005
|
+
}
|
|
2006
|
+
addResource(lng, ns, key, value, options = { silent: false }) {
|
|
2007
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
2008
|
+
let path = [lng, ns];
|
|
2009
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
2010
|
+
if (lng.includes(".")) {
|
|
2011
|
+
path = lng.split(".");
|
|
2012
|
+
value = ns;
|
|
2013
|
+
ns = path[1];
|
|
2014
|
+
}
|
|
2015
|
+
this.addNamespaces(ns);
|
|
2016
|
+
setPath(this.data, path, value);
|
|
2017
|
+
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
2018
|
+
}
|
|
2019
|
+
addResources(lng, ns, resources, options = { silent: false }) {
|
|
2020
|
+
for (const m in resources) if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], { silent: true });
|
|
2021
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
2022
|
+
}
|
|
2023
|
+
addResourceBundle(lng, ns, resources, deep, overwrite, options = {
|
|
2024
|
+
silent: false,
|
|
2025
|
+
skipCopy: false
|
|
2026
|
+
}) {
|
|
2027
|
+
let path = [lng, ns];
|
|
2028
|
+
if (lng.includes(".")) {
|
|
2029
|
+
path = lng.split(".");
|
|
2030
|
+
deep = resources;
|
|
2031
|
+
resources = ns;
|
|
2032
|
+
ns = path[1];
|
|
2033
|
+
}
|
|
2034
|
+
this.addNamespaces(ns);
|
|
2035
|
+
let pack = getPath(this.data, path) || {};
|
|
2036
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
2037
|
+
if (deep) deepExtend(pack, resources, overwrite);
|
|
2038
|
+
else pack = {
|
|
2039
|
+
...pack,
|
|
2040
|
+
...resources
|
|
2041
|
+
};
|
|
2042
|
+
setPath(this.data, path, pack);
|
|
2043
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
2044
|
+
}
|
|
2045
|
+
removeResourceBundle(lng, ns) {
|
|
2046
|
+
if (this.hasResourceBundle(lng, ns)) delete this.data[lng][ns];
|
|
2047
|
+
this.removeNamespaces(ns);
|
|
2048
|
+
this.emit("removed", lng, ns);
|
|
2049
|
+
}
|
|
2050
|
+
hasResourceBundle(lng, ns) {
|
|
2051
|
+
return this.getResource(lng, ns) !== void 0;
|
|
2052
|
+
}
|
|
2053
|
+
getResourceBundle(lng, ns) {
|
|
2054
|
+
if (!ns) ns = this.options.defaultNS;
|
|
2055
|
+
return this.getResource(lng, ns);
|
|
2056
|
+
}
|
|
2057
|
+
getDataByLanguage(lng) {
|
|
2058
|
+
return this.data[lng];
|
|
2059
|
+
}
|
|
2060
|
+
hasLanguageSomeTranslations(lng) {
|
|
2061
|
+
const data = this.getDataByLanguage(lng);
|
|
2062
|
+
return !!(data && Object.keys(data) || []).find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
2063
|
+
}
|
|
2064
|
+
toJSON() {
|
|
2065
|
+
return this.data;
|
|
2066
|
+
}
|
|
2067
|
+
};
|
|
2068
|
+
var postProcessor = {
|
|
2069
|
+
processors: {},
|
|
2070
|
+
addPostProcessor(module) {
|
|
2071
|
+
this.processors[module.name] = module;
|
|
2072
|
+
},
|
|
2073
|
+
handle(processors, value, key, options, translator) {
|
|
2074
|
+
processors.forEach((processor) => {
|
|
2075
|
+
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
2076
|
+
});
|
|
2077
|
+
return value;
|
|
2078
|
+
}
|
|
2079
|
+
};
|
|
2080
|
+
const PATH_KEY = Symbol("i18next/PATH_KEY");
|
|
2081
|
+
function createProxy() {
|
|
2082
|
+
const state = [];
|
|
2083
|
+
const handler = Object.create(null);
|
|
2084
|
+
let proxy;
|
|
2085
|
+
handler.get = (target, key) => {
|
|
2086
|
+
proxy?.revoke?.();
|
|
2087
|
+
if (key === PATH_KEY) return state;
|
|
2088
|
+
state.push(key);
|
|
2089
|
+
proxy = Proxy.revocable(target, handler);
|
|
2090
|
+
return proxy.proxy;
|
|
2091
|
+
};
|
|
2092
|
+
return Proxy.revocable(Object.create(null), handler).proxy;
|
|
2093
|
+
}
|
|
2094
|
+
function keysFromSelector(selector, opts) {
|
|
2095
|
+
const { [PATH_KEY]: path } = selector(createProxy());
|
|
2096
|
+
const keySeparator = opts?.keySeparator ?? ".";
|
|
2097
|
+
const nsSeparator = opts?.nsSeparator ?? ":";
|
|
2098
|
+
const strict = opts?.enableSelector === "strict";
|
|
2099
|
+
if (path.length > 1 && nsSeparator) {
|
|
2100
|
+
const ns = opts?.ns;
|
|
2101
|
+
const nsList = strict ? Array.isArray(ns) ? ns : ns ? [ns] : null : Array.isArray(ns) ? ns : null;
|
|
2102
|
+
if (nsList) {
|
|
2103
|
+
if ((strict ? nsList : nsList.length > 1 ? nsList.slice(1) : []).includes(path[0])) return `${path[0]}${nsSeparator}${path.slice(1).join(keySeparator)}`;
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
return path.join(keySeparator);
|
|
2107
|
+
}
|
|
2108
|
+
const shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
2109
|
+
var Translator = class Translator extends EventEmitter {
|
|
2110
|
+
constructor(services, options = {}) {
|
|
2111
|
+
super();
|
|
2112
|
+
copy([
|
|
2113
|
+
"resourceStore",
|
|
2114
|
+
"languageUtils",
|
|
2115
|
+
"pluralResolver",
|
|
2116
|
+
"interpolator",
|
|
2117
|
+
"backendConnector",
|
|
2118
|
+
"i18nFormat",
|
|
2119
|
+
"utils"
|
|
2120
|
+
], services, this);
|
|
2121
|
+
this.options = options;
|
|
2122
|
+
if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
|
|
2123
|
+
this.logger = baseLogger.create("translator");
|
|
2124
|
+
this.checkedLoadedFor = {};
|
|
2125
|
+
}
|
|
2126
|
+
changeLanguage(lng) {
|
|
2127
|
+
if (lng) this.language = lng;
|
|
2128
|
+
}
|
|
2129
|
+
exists(key, o = { interpolation: {} }) {
|
|
2130
|
+
const opt = { ...o };
|
|
2131
|
+
if (key == null) return false;
|
|
2132
|
+
const resolved = this.resolve(key, opt);
|
|
2133
|
+
if (resolved?.res === void 0) return false;
|
|
2134
|
+
const isObject = shouldHandleAsObject(resolved.res);
|
|
2135
|
+
if (opt.returnObjects === false && isObject) return false;
|
|
2136
|
+
return true;
|
|
2137
|
+
}
|
|
2138
|
+
extractFromKey(key, opt) {
|
|
2139
|
+
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
2140
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
2141
|
+
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
2142
|
+
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
2143
|
+
const wouldCheckForNsInKey = nsSeparator && key.includes(nsSeparator);
|
|
2144
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
2145
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
2146
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
2147
|
+
if (m && m.length > 0) return {
|
|
2148
|
+
key,
|
|
2149
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
2150
|
+
};
|
|
2151
|
+
const parts = key.split(nsSeparator);
|
|
2152
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.includes(parts[0])) namespaces = parts.shift();
|
|
2153
|
+
key = parts.join(keySeparator);
|
|
2154
|
+
}
|
|
2155
|
+
return {
|
|
2156
|
+
key,
|
|
2157
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
translate(keys, o, lastKey) {
|
|
2161
|
+
let opt = typeof o === "object" ? { ...o } : o;
|
|
2162
|
+
if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
2163
|
+
if (typeof opt === "object") opt = { ...opt };
|
|
2164
|
+
if (!opt) opt = {};
|
|
2165
|
+
if (keys == null) return "";
|
|
2166
|
+
if (typeof keys === "function") keys = keysFromSelector(keys, {
|
|
2167
|
+
...this.options,
|
|
2168
|
+
...opt
|
|
2169
|
+
});
|
|
2170
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
2171
|
+
keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
2172
|
+
...this.options,
|
|
2173
|
+
...opt
|
|
2174
|
+
}) : String(k));
|
|
2175
|
+
const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
|
|
2176
|
+
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
2177
|
+
const { key, namespaces } = this.extractFromKey(keys[keys.length - 1], opt);
|
|
2178
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
2179
|
+
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
2180
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
2181
|
+
const lng = opt.lng || this.language;
|
|
2182
|
+
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
2183
|
+
if (lng?.toLowerCase() === "cimode") {
|
|
2184
|
+
if (appendNamespaceToCIMode) {
|
|
2185
|
+
if (returnDetails) return {
|
|
2186
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
2187
|
+
usedKey: key,
|
|
2188
|
+
exactUsedKey: key,
|
|
2189
|
+
usedLng: lng,
|
|
2190
|
+
usedNS: namespace,
|
|
2191
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
2192
|
+
};
|
|
2193
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
2194
|
+
}
|
|
2195
|
+
if (returnDetails) return {
|
|
2196
|
+
res: key,
|
|
2197
|
+
usedKey: key,
|
|
2198
|
+
exactUsedKey: key,
|
|
2199
|
+
usedLng: lng,
|
|
2200
|
+
usedNS: namespace,
|
|
2201
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
2202
|
+
};
|
|
2203
|
+
return key;
|
|
2204
|
+
}
|
|
2205
|
+
const resolved = this.resolve(keys, opt);
|
|
2206
|
+
let res = resolved?.res;
|
|
2207
|
+
const resUsedKey = resolved?.usedKey || key;
|
|
2208
|
+
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
2209
|
+
const noObject = [
|
|
2210
|
+
"[object Number]",
|
|
2211
|
+
"[object Function]",
|
|
2212
|
+
"[object RegExp]"
|
|
2213
|
+
];
|
|
2214
|
+
const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
|
|
2215
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
2216
|
+
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
2217
|
+
const hasDefaultValue = Translator.hasDefaultValue(opt);
|
|
2218
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
|
|
2219
|
+
const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, { ordinal: false }) : "";
|
|
2220
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
2221
|
+
const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
|
|
2222
|
+
let resForObjHndl = res;
|
|
2223
|
+
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) resForObjHndl = defaultValue;
|
|
2224
|
+
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
2225
|
+
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
2226
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && !noObject.includes(resType) && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
2227
|
+
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
2228
|
+
if (!this.options.returnedObjectHandler) this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
2229
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
2230
|
+
...opt,
|
|
2231
|
+
ns: namespaces
|
|
2232
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
2233
|
+
if (returnDetails) {
|
|
2234
|
+
resolved.res = r;
|
|
2235
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
2236
|
+
return resolved;
|
|
2237
|
+
}
|
|
2238
|
+
return r;
|
|
2239
|
+
}
|
|
2240
|
+
if (keySeparator) {
|
|
2241
|
+
const resTypeIsArray = Array.isArray(resForObjHndl);
|
|
2242
|
+
const copy = resTypeIsArray ? [] : {};
|
|
2243
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
2244
|
+
for (const m in resForObjHndl) if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
2245
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
2246
|
+
if (hasDefaultValue && !res) copy[m] = this.translate(deepKey, {
|
|
2247
|
+
...opt,
|
|
2248
|
+
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
|
|
2249
|
+
joinArrays: false,
|
|
2250
|
+
ns: namespaces
|
|
2251
|
+
});
|
|
2252
|
+
else copy[m] = this.translate(deepKey, {
|
|
2253
|
+
...opt,
|
|
2254
|
+
joinArrays: false,
|
|
2255
|
+
ns: namespaces
|
|
2256
|
+
});
|
|
2257
|
+
if (copy[m] === deepKey) copy[m] = resForObjHndl[m];
|
|
2258
|
+
}
|
|
2259
|
+
res = copy;
|
|
2260
|
+
}
|
|
2261
|
+
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
2262
|
+
res = res.join(joinArrays);
|
|
2263
|
+
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
2264
|
+
} else {
|
|
2265
|
+
let usedDefault = false;
|
|
2266
|
+
let usedKey = false;
|
|
2267
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
2268
|
+
usedDefault = true;
|
|
2269
|
+
res = defaultValue;
|
|
2270
|
+
}
|
|
2271
|
+
if (!this.isValidLookup(res)) {
|
|
2272
|
+
usedKey = true;
|
|
2273
|
+
res = key;
|
|
2274
|
+
}
|
|
2275
|
+
const resForMissing = (opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && usedKey ? void 0 : res;
|
|
2276
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
2277
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
2278
|
+
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, needsPluralHandling && !updateMissing ? `${key}${this.pluralResolver.getSuffix(lng, opt.count, opt)}` : key, updateMissing ? defaultValue : res);
|
|
2279
|
+
if (keySeparator) {
|
|
2280
|
+
const fk = this.resolve(key, {
|
|
2281
|
+
...opt,
|
|
2282
|
+
keySeparator: false
|
|
2283
|
+
});
|
|
2284
|
+
if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
|
|
2285
|
+
}
|
|
2286
|
+
let lngs = [];
|
|
2287
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
2288
|
+
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) for (let i = 0; i < fallbackLngs.length; i++) lngs.push(fallbackLngs[i]);
|
|
2289
|
+
else if (this.options.saveMissingTo === "all") lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
2290
|
+
else lngs.push(opt.lng || this.language);
|
|
2291
|
+
const send = (l, k, specificDefaultValue) => {
|
|
2292
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
2293
|
+
if (this.options.missingKeyHandler) this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
2294
|
+
else if (this.backendConnector?.saveMissing) this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
2295
|
+
this.emit("missingKey", l, namespace, k, res);
|
|
2296
|
+
};
|
|
2297
|
+
if (this.options.saveMissing) if (this.options.saveMissingPlurals && needsPluralHandling) lngs.forEach((language) => {
|
|
2298
|
+
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
2299
|
+
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && !suffixes.includes(`${this.options.pluralSeparator}zero`)) suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
2300
|
+
suffixes.forEach((suffix) => {
|
|
2301
|
+
send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
|
|
2302
|
+
});
|
|
2303
|
+
});
|
|
2304
|
+
else send(lngs, key, defaultValue);
|
|
2305
|
+
}
|
|
2306
|
+
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
2307
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}${nsSeparator}${key}`;
|
|
2308
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
|
|
2309
|
+
}
|
|
2310
|
+
if (returnDetails) {
|
|
2311
|
+
resolved.res = res;
|
|
2312
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
2313
|
+
return resolved;
|
|
2314
|
+
}
|
|
2315
|
+
return res;
|
|
2316
|
+
}
|
|
2317
|
+
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
2318
|
+
if (this.i18nFormat?.parse) res = this.i18nFormat.parse(res, {
|
|
2319
|
+
...this.options.interpolation.defaultVariables,
|
|
2320
|
+
...opt
|
|
2321
|
+
}, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, { resolved });
|
|
2322
|
+
else if (!opt.skipInterpolation) {
|
|
2323
|
+
if (opt.interpolation) this.interpolator.init({
|
|
2324
|
+
...opt,
|
|
2325
|
+
interpolation: {
|
|
2326
|
+
...this.options.interpolation,
|
|
2327
|
+
...opt.interpolation
|
|
2328
|
+
}
|
|
2329
|
+
});
|
|
2330
|
+
const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
2331
|
+
let nestBef;
|
|
2332
|
+
if (skipOnVariables) {
|
|
2333
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
2334
|
+
nestBef = nb && nb.length;
|
|
2335
|
+
}
|
|
2336
|
+
let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
|
|
2337
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
2338
|
+
...this.options.interpolation.defaultVariables,
|
|
2339
|
+
...data
|
|
2340
|
+
};
|
|
2341
|
+
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
2342
|
+
if (skipOnVariables) {
|
|
2343
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
2344
|
+
const nestAft = na && na.length;
|
|
2345
|
+
if (nestBef < nestAft) opt.nest = false;
|
|
2346
|
+
}
|
|
2347
|
+
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
2348
|
+
if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
|
|
2349
|
+
if (lastKey?.[0] === args[0] && !opt.context) {
|
|
2350
|
+
this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
2351
|
+
return null;
|
|
2352
|
+
}
|
|
2353
|
+
return this.translate(...args, key);
|
|
2354
|
+
}, opt);
|
|
2355
|
+
if (opt.interpolation) this.interpolator.reset();
|
|
2356
|
+
}
|
|
2357
|
+
const postProcess = opt.postProcess || this.options.postProcess;
|
|
2358
|
+
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
2359
|
+
if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
2360
|
+
i18nResolved: {
|
|
2361
|
+
...resolved,
|
|
2362
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
2363
|
+
},
|
|
2364
|
+
...opt
|
|
2365
|
+
} : opt, this);
|
|
2366
|
+
return res;
|
|
2367
|
+
}
|
|
2368
|
+
resolve(keys, opt = {}) {
|
|
2369
|
+
let found;
|
|
2370
|
+
let usedKey;
|
|
2371
|
+
let exactUsedKey;
|
|
2372
|
+
let usedLng;
|
|
2373
|
+
let usedNS;
|
|
2374
|
+
if (isString(keys)) keys = [keys];
|
|
2375
|
+
if (Array.isArray(keys)) keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
2376
|
+
...this.options,
|
|
2377
|
+
...opt
|
|
2378
|
+
}) : k);
|
|
2379
|
+
keys.forEach((k) => {
|
|
2380
|
+
if (this.isValidLookup(found)) return;
|
|
2381
|
+
const extracted = this.extractFromKey(k, opt);
|
|
2382
|
+
const key = extracted.key;
|
|
2383
|
+
usedKey = key;
|
|
2384
|
+
let namespaces = extracted.namespaces;
|
|
2385
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
2386
|
+
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
2387
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
2388
|
+
const needsContextHandling = opt.context !== void 0 && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
|
|
2389
|
+
const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
2390
|
+
namespaces.forEach((ns) => {
|
|
2391
|
+
if (this.isValidLookup(found)) return;
|
|
2392
|
+
usedNS = ns;
|
|
2393
|
+
if (!this.checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
2394
|
+
this.checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
2395
|
+
this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
2396
|
+
}
|
|
2397
|
+
codes.forEach((code) => {
|
|
2398
|
+
if (this.isValidLookup(found)) return;
|
|
2399
|
+
usedLng = code;
|
|
2400
|
+
const finalKeys = [key];
|
|
2401
|
+
if (this.i18nFormat?.addLookupKeys) this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
2402
|
+
else {
|
|
2403
|
+
let pluralSuffix;
|
|
2404
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
2405
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
2406
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
2407
|
+
if (needsPluralHandling) {
|
|
2408
|
+
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
2409
|
+
finalKeys.push(key + pluralSuffix);
|
|
2410
|
+
if (needsZeroSuffixLookup) finalKeys.push(key + zeroSuffix);
|
|
2411
|
+
}
|
|
2412
|
+
if (needsContextHandling) {
|
|
2413
|
+
const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
|
|
2414
|
+
finalKeys.push(contextKey);
|
|
2415
|
+
if (needsPluralHandling) {
|
|
2416
|
+
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
2417
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
2418
|
+
if (needsZeroSuffixLookup) finalKeys.push(contextKey + zeroSuffix);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
let possibleKey;
|
|
2423
|
+
while (possibleKey = finalKeys.pop()) if (!this.isValidLookup(found)) {
|
|
2424
|
+
exactUsedKey = possibleKey;
|
|
2425
|
+
found = this.getResource(code, ns, possibleKey, opt);
|
|
2426
|
+
}
|
|
2427
|
+
});
|
|
2428
|
+
});
|
|
2429
|
+
});
|
|
2430
|
+
return {
|
|
2431
|
+
res: found,
|
|
2432
|
+
usedKey,
|
|
2433
|
+
exactUsedKey,
|
|
2434
|
+
usedLng,
|
|
2435
|
+
usedNS
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
isValidLookup(res) {
|
|
2439
|
+
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
2440
|
+
}
|
|
2441
|
+
getResource(code, ns, key, options = {}) {
|
|
2442
|
+
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
2443
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
2444
|
+
}
|
|
2445
|
+
getUsedParamsDetails(options = {}) {
|
|
2446
|
+
const optionsKeys = [
|
|
2447
|
+
"defaultValue",
|
|
2448
|
+
"ordinal",
|
|
2449
|
+
"context",
|
|
2450
|
+
"replace",
|
|
2451
|
+
"lng",
|
|
2452
|
+
"lngs",
|
|
2453
|
+
"fallbackLng",
|
|
2454
|
+
"ns",
|
|
2455
|
+
"keySeparator",
|
|
2456
|
+
"nsSeparator",
|
|
2457
|
+
"returnObjects",
|
|
2458
|
+
"returnDetails",
|
|
2459
|
+
"joinArrays",
|
|
2460
|
+
"postProcess",
|
|
2461
|
+
"interpolation"
|
|
2462
|
+
];
|
|
2463
|
+
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
2464
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
2465
|
+
if (useOptionsReplaceForData && typeof options.count !== "undefined") data.count = options.count;
|
|
2466
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
2467
|
+
...this.options.interpolation.defaultVariables,
|
|
2468
|
+
...data
|
|
2469
|
+
};
|
|
2470
|
+
if (!useOptionsReplaceForData) {
|
|
2471
|
+
data = { ...data };
|
|
2472
|
+
for (const key of optionsKeys) delete data[key];
|
|
2473
|
+
}
|
|
2474
|
+
return data;
|
|
2475
|
+
}
|
|
2476
|
+
static hasDefaultValue(options) {
|
|
2477
|
+
const prefix = "defaultValue";
|
|
2478
|
+
for (const option in options) if (Object.prototype.hasOwnProperty.call(options, option) && option.startsWith(prefix) && void 0 !== options[option]) return true;
|
|
2479
|
+
return false;
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
var LanguageUtil = class {
|
|
2483
|
+
constructor(options) {
|
|
2484
|
+
this.options = options;
|
|
2485
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
2486
|
+
this.logger = baseLogger.create("languageUtils");
|
|
2487
|
+
}
|
|
2488
|
+
getScriptPartFromCode(code) {
|
|
2489
|
+
code = getCleanedCode(code);
|
|
2490
|
+
if (!code || !code.includes("-")) return null;
|
|
2491
|
+
const p = code.split("-");
|
|
2492
|
+
if (p.length === 2) return null;
|
|
2493
|
+
p.pop();
|
|
2494
|
+
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
2495
|
+
return this.formatLanguageCode(p.join("-"));
|
|
2496
|
+
}
|
|
2497
|
+
getLanguagePartFromCode(code) {
|
|
2498
|
+
code = getCleanedCode(code);
|
|
2499
|
+
if (!code || !code.includes("-")) return code;
|
|
2500
|
+
const p = code.split("-");
|
|
2501
|
+
return this.formatLanguageCode(p[0]);
|
|
2502
|
+
}
|
|
2503
|
+
formatLanguageCode(code) {
|
|
2504
|
+
if (isString(code) && code.includes("-")) {
|
|
2505
|
+
let formattedCode;
|
|
2506
|
+
try {
|
|
2507
|
+
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
2508
|
+
} catch (e) {}
|
|
2509
|
+
if (formattedCode && this.options.lowerCaseLng) formattedCode = formattedCode.toLowerCase();
|
|
2510
|
+
if (formattedCode) return formattedCode;
|
|
2511
|
+
if (this.options.lowerCaseLng) return code.toLowerCase();
|
|
2512
|
+
return code;
|
|
2513
|
+
}
|
|
2514
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
2515
|
+
}
|
|
2516
|
+
isSupportedCode(code) {
|
|
2517
|
+
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) code = this.getLanguagePartFromCode(code);
|
|
2518
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.includes(code);
|
|
2519
|
+
}
|
|
2520
|
+
getBestMatchFromCodes(codes) {
|
|
2521
|
+
if (!codes) return null;
|
|
2522
|
+
let found;
|
|
2523
|
+
codes.forEach((code) => {
|
|
2524
|
+
if (found) return;
|
|
2525
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
2526
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
2527
|
+
});
|
|
2528
|
+
if (!found && this.options.supportedLngs) codes.forEach((code) => {
|
|
2529
|
+
if (found) return;
|
|
2530
|
+
const lngScOnly = this.getScriptPartFromCode(code);
|
|
2531
|
+
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
2532
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
2533
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
2534
|
+
found = this.options.supportedLngs.find((supportedLng) => {
|
|
2535
|
+
if (supportedLng === lngOnly) return true;
|
|
2536
|
+
if (!supportedLng.includes("-") && !lngOnly.includes("-")) return false;
|
|
2537
|
+
if (supportedLng.includes("-") && !lngOnly.includes("-") && supportedLng.slice(0, supportedLng.indexOf("-")) === lngOnly) return true;
|
|
2538
|
+
if (supportedLng.startsWith(lngOnly) && lngOnly.length > 1) return true;
|
|
2539
|
+
return false;
|
|
2540
|
+
});
|
|
2541
|
+
});
|
|
2542
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
2543
|
+
return found;
|
|
2544
|
+
}
|
|
2545
|
+
getFallbackCodes(fallbacks, code) {
|
|
2546
|
+
if (!fallbacks) return [];
|
|
2547
|
+
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
2548
|
+
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
2549
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
2550
|
+
if (!code) return fallbacks.default || [];
|
|
2551
|
+
let found = fallbacks[code];
|
|
2552
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
2553
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
2554
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
2555
|
+
if (!found) found = fallbacks.default;
|
|
2556
|
+
return found || [];
|
|
2557
|
+
}
|
|
2558
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
2559
|
+
const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
|
|
2560
|
+
const codes = [];
|
|
2561
|
+
const addCode = (c) => {
|
|
2562
|
+
if (!c) return;
|
|
2563
|
+
if (this.isSupportedCode(c)) codes.push(c);
|
|
2564
|
+
else this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
2565
|
+
};
|
|
2566
|
+
if (isString(code) && (code.includes("-") || code.includes("_"))) {
|
|
2567
|
+
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
2568
|
+
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
2569
|
+
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
2570
|
+
} else if (isString(code)) addCode(this.formatLanguageCode(code));
|
|
2571
|
+
fallbackCodes.forEach((fc) => {
|
|
2572
|
+
if (!codes.includes(fc)) addCode(this.formatLanguageCode(fc));
|
|
2573
|
+
});
|
|
2574
|
+
return codes;
|
|
2575
|
+
}
|
|
2576
|
+
};
|
|
2577
|
+
const suffixesOrder = {
|
|
2578
|
+
zero: 0,
|
|
2579
|
+
one: 1,
|
|
2580
|
+
two: 2,
|
|
2581
|
+
few: 3,
|
|
2582
|
+
many: 4,
|
|
2583
|
+
other: 5
|
|
2584
|
+
};
|
|
2585
|
+
const dummyRule = {
|
|
2586
|
+
select: (count) => count === 1 ? "one" : "other",
|
|
2587
|
+
resolvedOptions: () => ({ pluralCategories: ["one", "other"] })
|
|
2588
|
+
};
|
|
2589
|
+
var PluralResolver = class {
|
|
2590
|
+
constructor(languageUtils, options = {}) {
|
|
2591
|
+
this.languageUtils = languageUtils;
|
|
2592
|
+
this.options = options;
|
|
2593
|
+
this.logger = baseLogger.create("pluralResolver");
|
|
2594
|
+
this.pluralRulesCache = {};
|
|
2595
|
+
}
|
|
2596
|
+
clearCache() {
|
|
2597
|
+
this.pluralRulesCache = {};
|
|
2598
|
+
}
|
|
2599
|
+
getRule(code, options = {}) {
|
|
2600
|
+
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
2601
|
+
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
2602
|
+
const cacheKey = JSON.stringify({
|
|
2603
|
+
cleanedCode,
|
|
2604
|
+
type
|
|
2605
|
+
});
|
|
2606
|
+
if (cacheKey in this.pluralRulesCache) return this.pluralRulesCache[cacheKey];
|
|
2607
|
+
let rule;
|
|
2608
|
+
try {
|
|
2609
|
+
rule = new Intl.PluralRules(cleanedCode, { type });
|
|
2610
|
+
} catch (err) {
|
|
2611
|
+
if (typeof Intl === "undefined") {
|
|
2612
|
+
this.logger.error("No Intl support, please use an Intl polyfill!");
|
|
2613
|
+
return dummyRule;
|
|
2614
|
+
}
|
|
2615
|
+
if (!code.match(/-|_/)) return dummyRule;
|
|
2616
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
2617
|
+
rule = this.getRule(lngPart, options);
|
|
2618
|
+
}
|
|
2619
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
2620
|
+
return rule;
|
|
2621
|
+
}
|
|
2622
|
+
needsPlural(code, options = {}) {
|
|
2623
|
+
let rule = this.getRule(code, options);
|
|
2624
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
2625
|
+
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
2626
|
+
}
|
|
2627
|
+
getPluralFormsOfKey(code, key, options = {}) {
|
|
2628
|
+
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
2629
|
+
}
|
|
2630
|
+
getSuffixes(code, options = {}) {
|
|
2631
|
+
let rule = this.getRule(code, options);
|
|
2632
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
2633
|
+
if (!rule) return [];
|
|
2634
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
2635
|
+
}
|
|
2636
|
+
getSuffix(code, count, options = {}) {
|
|
2637
|
+
const rule = this.getRule(code, options);
|
|
2638
|
+
if (rule) return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
2639
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
2640
|
+
return this.getSuffix("dev", count, options);
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
const deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
|
|
2644
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
2645
|
+
if (!path && ignoreJSONStructure && isString(key)) {
|
|
2646
|
+
path = deepFind(data, key, keySeparator);
|
|
2647
|
+
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
2648
|
+
}
|
|
2649
|
+
return path;
|
|
2650
|
+
};
|
|
2651
|
+
const regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
2652
|
+
var Interpolator = class {
|
|
2653
|
+
constructor(options = {}) {
|
|
2654
|
+
this.logger = baseLogger.create("interpolator");
|
|
2655
|
+
this.options = options;
|
|
2656
|
+
this.format = options?.interpolation?.format || ((value) => value);
|
|
2657
|
+
this.init(options);
|
|
2658
|
+
}
|
|
2659
|
+
init(options = {}) {
|
|
2660
|
+
if (!options.interpolation) options.interpolation = { escapeValue: true };
|
|
2661
|
+
const { escape: escape$1, escapeValue, useRawValueToEscape, prefix, prefixEscaped, suffix, suffixEscaped, formatSeparator, unescapeSuffix, unescapePrefix, nestingPrefix, nestingPrefixEscaped, nestingSuffix, nestingSuffixEscaped, nestingOptionsSeparator, maxReplaces, alwaysFormat } = options.interpolation;
|
|
2662
|
+
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
2663
|
+
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
2664
|
+
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
2665
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
2666
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
2667
|
+
this.formatSeparator = formatSeparator || ",";
|
|
2668
|
+
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix ? regexEscape(unescapePrefix) : "-";
|
|
2669
|
+
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix ? regexEscape(unescapeSuffix) : "";
|
|
2670
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
2671
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
2672
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
2673
|
+
this.maxReplaces = maxReplaces || 1e3;
|
|
2674
|
+
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
2675
|
+
this.resetRegExp();
|
|
2676
|
+
}
|
|
2677
|
+
reset() {
|
|
2678
|
+
if (this.options) this.init(this.options);
|
|
2679
|
+
}
|
|
2680
|
+
resetRegExp() {
|
|
2681
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
2682
|
+
if (existingRegExp?.source === pattern) {
|
|
2683
|
+
existingRegExp.lastIndex = 0;
|
|
2684
|
+
return existingRegExp;
|
|
2685
|
+
}
|
|
2686
|
+
return new RegExp(pattern, "g");
|
|
2687
|
+
};
|
|
2688
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
2689
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
2690
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
|
|
2691
|
+
}
|
|
2692
|
+
interpolate(str, data, lng, options) {
|
|
2693
|
+
let match;
|
|
2694
|
+
let value;
|
|
2695
|
+
let replaces;
|
|
2696
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
2697
|
+
const handleFormat = (key) => {
|
|
2698
|
+
if (!key.includes(this.formatSeparator)) {
|
|
2699
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
2700
|
+
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
2701
|
+
...options,
|
|
2702
|
+
...data,
|
|
2703
|
+
interpolationkey: key
|
|
2704
|
+
}) : path;
|
|
2705
|
+
}
|
|
2706
|
+
const p = key.split(this.formatSeparator);
|
|
2707
|
+
const k = p.shift().trim();
|
|
2708
|
+
const f = p.join(this.formatSeparator).trim();
|
|
2709
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
2710
|
+
...options,
|
|
2711
|
+
...data,
|
|
2712
|
+
interpolationkey: k
|
|
2713
|
+
});
|
|
2714
|
+
};
|
|
2715
|
+
this.resetRegExp();
|
|
2716
|
+
if (!this.escapeValue && typeof str === "string" && /\$t\([^)]*\{[^}]*\{\{/.test(str)) this.logger.warn("nesting options string contains interpolated variables with escapeValue: false — if any of those values are attacker-controlled they can inject additional nesting options (e.g. redirect lng/ns). Sanitise untrusted input before passing it to t(), or keep escapeValue: true.");
|
|
2717
|
+
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
2718
|
+
const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
2719
|
+
[{
|
|
2720
|
+
regex: this.regexpUnescape,
|
|
2721
|
+
safeValue: (val) => regexSafe(val)
|
|
2722
|
+
}, {
|
|
2723
|
+
regex: this.regexp,
|
|
2724
|
+
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
2725
|
+
}].forEach((todo) => {
|
|
2726
|
+
replaces = 0;
|
|
2727
|
+
while (match = todo.regex.exec(str)) {
|
|
2728
|
+
const matchedVar = match[1].trim();
|
|
2729
|
+
value = handleFormat(matchedVar);
|
|
2730
|
+
if (value === void 0) if (typeof missingInterpolationHandler === "function") {
|
|
2731
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
2732
|
+
value = isString(temp) ? temp : "";
|
|
2733
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) value = "";
|
|
2734
|
+
else if (skipOnVariables) {
|
|
2735
|
+
value = match[0];
|
|
2736
|
+
continue;
|
|
2737
|
+
} else {
|
|
2738
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
2739
|
+
value = "";
|
|
2740
|
+
}
|
|
2741
|
+
else if (!isString(value) && !this.useRawValueToEscape) value = makeString(value);
|
|
2742
|
+
const safeValue = todo.safeValue(value);
|
|
2743
|
+
str = str.replace(match[0], safeValue);
|
|
2744
|
+
if (skipOnVariables) {
|
|
2745
|
+
todo.regex.lastIndex += value.length;
|
|
2746
|
+
todo.regex.lastIndex -= match[0].length;
|
|
2747
|
+
} else todo.regex.lastIndex = 0;
|
|
2748
|
+
replaces++;
|
|
2749
|
+
if (replaces >= this.maxReplaces) break;
|
|
2750
|
+
}
|
|
2751
|
+
});
|
|
2752
|
+
return str;
|
|
2753
|
+
}
|
|
2754
|
+
nest(str, fc, options = {}) {
|
|
2755
|
+
let match;
|
|
2756
|
+
let value;
|
|
2757
|
+
let clonedOptions;
|
|
2758
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
2759
|
+
const sep = this.nestingOptionsSeparator;
|
|
2760
|
+
if (!key.includes(sep)) return key;
|
|
2761
|
+
const c = key.split(new RegExp(`${regexEscape(sep)}[ ]*{`));
|
|
2762
|
+
let optionsString = `{${c[1]}`;
|
|
2763
|
+
key = c[0];
|
|
2764
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
2765
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
2766
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
2767
|
+
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || (matchedDoubleQuotes?.length ?? 0) % 2 !== 0) optionsString = optionsString.replace(/'/g, "\"");
|
|
2768
|
+
try {
|
|
2769
|
+
clonedOptions = JSON.parse(optionsString);
|
|
2770
|
+
if (inheritedOptions) clonedOptions = {
|
|
2771
|
+
...inheritedOptions,
|
|
2772
|
+
...clonedOptions
|
|
2773
|
+
};
|
|
2774
|
+
} catch (e) {
|
|
2775
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
2776
|
+
return `${key}${sep}${optionsString}`;
|
|
2777
|
+
}
|
|
2778
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.includes(this.prefix)) delete clonedOptions.defaultValue;
|
|
2779
|
+
return key;
|
|
2780
|
+
};
|
|
2781
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
2782
|
+
let formatters = [];
|
|
2783
|
+
clonedOptions = { ...options };
|
|
2784
|
+
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
2785
|
+
clonedOptions.applyPostProcessor = false;
|
|
2786
|
+
delete clonedOptions.defaultValue;
|
|
2787
|
+
const keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf("}") + 1 : match[1].indexOf(this.formatSeparator);
|
|
2788
|
+
if (keyEndIndex !== -1) {
|
|
2789
|
+
formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
|
|
2790
|
+
match[1] = match[1].slice(0, keyEndIndex);
|
|
2791
|
+
}
|
|
2792
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
2793
|
+
if (value && match[0] === str && !isString(value)) return value;
|
|
2794
|
+
if (!isString(value)) value = makeString(value);
|
|
2795
|
+
if (!value) {
|
|
2796
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
2797
|
+
value = "";
|
|
2798
|
+
}
|
|
2799
|
+
if (formatters.length) value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
2800
|
+
...options,
|
|
2801
|
+
interpolationkey: match[1].trim()
|
|
2802
|
+
}), value.trim());
|
|
2803
|
+
str = str.replace(match[0], value);
|
|
2804
|
+
this.regexp.lastIndex = 0;
|
|
2805
|
+
}
|
|
2806
|
+
return str;
|
|
2807
|
+
}
|
|
2808
|
+
};
|
|
2809
|
+
const parseFormatStr = (formatStr) => {
|
|
2810
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
2811
|
+
const formatOptions = {};
|
|
2812
|
+
if (formatStr.includes("(")) {
|
|
2813
|
+
const p = formatStr.split("(");
|
|
2814
|
+
formatName = p[0].toLowerCase().trim();
|
|
2815
|
+
const optStr = p[1].slice(0, -1);
|
|
2816
|
+
if (formatName === "currency" && !optStr.includes(":")) {
|
|
2817
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
2818
|
+
} else if (formatName === "relativetime" && !optStr.includes(":")) {
|
|
2819
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
2820
|
+
} else optStr.split(";").forEach((opt) => {
|
|
2821
|
+
if (opt) {
|
|
2822
|
+
const [key, ...rest] = opt.split(":");
|
|
2823
|
+
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
2824
|
+
const trimmedKey = key.trim();
|
|
2825
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
2826
|
+
if (val === "false") formatOptions[trimmedKey] = false;
|
|
2827
|
+
if (val === "true") formatOptions[trimmedKey] = true;
|
|
2828
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
2829
|
+
}
|
|
2830
|
+
});
|
|
2831
|
+
}
|
|
2832
|
+
return {
|
|
2833
|
+
formatName,
|
|
2834
|
+
formatOptions
|
|
2835
|
+
};
|
|
2836
|
+
};
|
|
2837
|
+
const createCachedFormatter = (fn) => {
|
|
2838
|
+
const cache = {};
|
|
2839
|
+
return (v, l, o) => {
|
|
2840
|
+
let optForCache = o;
|
|
2841
|
+
if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) optForCache = {
|
|
2842
|
+
...optForCache,
|
|
2843
|
+
[o.interpolationkey]: void 0
|
|
2844
|
+
};
|
|
2845
|
+
const key = l + JSON.stringify(optForCache);
|
|
2846
|
+
let frm = cache[key];
|
|
2847
|
+
if (!frm) {
|
|
2848
|
+
frm = fn(getCleanedCode(l), o);
|
|
2849
|
+
cache[key] = frm;
|
|
2850
|
+
}
|
|
2851
|
+
return frm(v);
|
|
2852
|
+
};
|
|
2853
|
+
};
|
|
2854
|
+
const createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
|
|
2855
|
+
var Formatter = class {
|
|
2856
|
+
constructor(options = {}) {
|
|
2857
|
+
this.logger = baseLogger.create("formatter");
|
|
2858
|
+
this.options = options;
|
|
2859
|
+
this.init(options);
|
|
2860
|
+
}
|
|
2861
|
+
init(services, options = { interpolation: {} }) {
|
|
2862
|
+
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
2863
|
+
const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
|
|
2864
|
+
this.formats = {
|
|
2865
|
+
number: cf((lng, opt) => {
|
|
2866
|
+
const formatter = new Intl.NumberFormat(lng, { ...opt });
|
|
2867
|
+
return (val) => formatter.format(val);
|
|
2868
|
+
}),
|
|
2869
|
+
currency: cf((lng, opt) => {
|
|
2870
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
2871
|
+
...opt,
|
|
2872
|
+
style: "currency"
|
|
2873
|
+
});
|
|
2874
|
+
return (val) => formatter.format(val);
|
|
2875
|
+
}),
|
|
2876
|
+
datetime: cf((lng, opt) => {
|
|
2877
|
+
const formatter = new Intl.DateTimeFormat(lng, { ...opt });
|
|
2878
|
+
return (val) => formatter.format(val);
|
|
2879
|
+
}),
|
|
2880
|
+
relativetime: cf((lng, opt) => {
|
|
2881
|
+
const formatter = new Intl.RelativeTimeFormat(lng, { ...opt });
|
|
2882
|
+
return (val) => formatter.format(val, opt.range || "day");
|
|
2883
|
+
}),
|
|
2884
|
+
list: cf((lng, opt) => {
|
|
2885
|
+
const formatter = new Intl.ListFormat(lng, { ...opt });
|
|
2886
|
+
return (val) => formatter.format(val);
|
|
2887
|
+
})
|
|
2888
|
+
};
|
|
2889
|
+
}
|
|
2890
|
+
add(name, fc) {
|
|
2891
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
2892
|
+
}
|
|
2893
|
+
addCached(name, fc) {
|
|
2894
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
2895
|
+
}
|
|
2896
|
+
format(value, format, lng, options = {}) {
|
|
2897
|
+
if (!format) return value;
|
|
2898
|
+
if (value == null) return value;
|
|
2899
|
+
const formats = format.split(this.formatSeparator);
|
|
2900
|
+
if (formats.length > 1 && formats[0].indexOf("(") > 1 && !formats[0].includes(")") && formats.find((f) => f.includes(")"))) {
|
|
2901
|
+
const lastIndex = formats.findIndex((f) => f.includes(")"));
|
|
2902
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
2903
|
+
}
|
|
2904
|
+
return formats.reduce((mem, f) => {
|
|
2905
|
+
const { formatName, formatOptions } = parseFormatStr(f);
|
|
2906
|
+
if (this.formats[formatName]) {
|
|
2907
|
+
let formatted = mem;
|
|
2908
|
+
try {
|
|
2909
|
+
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
2910
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
2911
|
+
formatted = this.formats[formatName](mem, l, {
|
|
2912
|
+
...formatOptions,
|
|
2913
|
+
...options,
|
|
2914
|
+
...valOptions
|
|
2915
|
+
});
|
|
2916
|
+
} catch (error) {
|
|
2917
|
+
this.logger.warn(error);
|
|
2918
|
+
}
|
|
2919
|
+
return formatted;
|
|
2920
|
+
} else this.logger.warn(`there was no format function for ${formatName}`);
|
|
2921
|
+
return mem;
|
|
2922
|
+
}, value);
|
|
2923
|
+
}
|
|
2924
|
+
};
|
|
2925
|
+
const removePending = (q, name) => {
|
|
2926
|
+
if (q.pending[name] !== void 0) {
|
|
2927
|
+
delete q.pending[name];
|
|
2928
|
+
q.pendingCount--;
|
|
2929
|
+
}
|
|
2930
|
+
};
|
|
2931
|
+
var Connector = class extends EventEmitter {
|
|
2932
|
+
constructor(backend, store, services, options = {}) {
|
|
2933
|
+
super();
|
|
2934
|
+
this.backend = backend;
|
|
2935
|
+
this.store = store;
|
|
2936
|
+
this.services = services;
|
|
2937
|
+
this.languageUtils = services.languageUtils;
|
|
2938
|
+
this.options = options;
|
|
2939
|
+
this.logger = baseLogger.create("backendConnector");
|
|
2940
|
+
this.waitingReads = [];
|
|
2941
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
2942
|
+
this.readingCalls = 0;
|
|
2943
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
2944
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
2945
|
+
this.state = {};
|
|
2946
|
+
this.queue = [];
|
|
2947
|
+
this.backend?.init?.(services, options.backend, options);
|
|
2948
|
+
}
|
|
2949
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
2950
|
+
const toLoad = {};
|
|
2951
|
+
const pending = {};
|
|
2952
|
+
const toLoadLanguages = {};
|
|
2953
|
+
const toLoadNamespaces = {};
|
|
2954
|
+
languages.forEach((lng) => {
|
|
2955
|
+
let hasAllNamespaces = true;
|
|
2956
|
+
namespaces.forEach((ns) => {
|
|
2957
|
+
const name = `${lng}|${ns}`;
|
|
2958
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) this.state[name] = 2;
|
|
2959
|
+
else if (this.state[name] < 0);
|
|
2960
|
+
else if (this.state[name] === 1) {
|
|
2961
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
2962
|
+
} else {
|
|
2963
|
+
this.state[name] = 1;
|
|
2964
|
+
hasAllNamespaces = false;
|
|
2965
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
2966
|
+
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
2967
|
+
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
2968
|
+
}
|
|
2969
|
+
});
|
|
2970
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
2971
|
+
});
|
|
2972
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) this.queue.push({
|
|
2973
|
+
pending,
|
|
2974
|
+
pendingCount: Object.keys(pending).length,
|
|
2975
|
+
loaded: {},
|
|
2976
|
+
errors: [],
|
|
2977
|
+
callback
|
|
2978
|
+
});
|
|
2979
|
+
return {
|
|
2980
|
+
toLoad: Object.keys(toLoad),
|
|
2981
|
+
pending: Object.keys(pending),
|
|
2982
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
2983
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
2984
|
+
};
|
|
2985
|
+
}
|
|
2986
|
+
loaded(name, err, data) {
|
|
2987
|
+
const s = name.split("|");
|
|
2988
|
+
const lng = s[0];
|
|
2989
|
+
const ns = s[1];
|
|
2990
|
+
if (err) this.emit("failedLoading", lng, ns, err);
|
|
2991
|
+
if (!err && data) this.store.addResourceBundle(lng, ns, data, void 0, void 0, { skipCopy: true });
|
|
2992
|
+
this.state[name] = err ? -1 : 2;
|
|
2993
|
+
if (err && data) this.state[name] = 0;
|
|
2994
|
+
const loaded = {};
|
|
2995
|
+
this.queue.forEach((q) => {
|
|
2996
|
+
pushPath(q.loaded, [lng], ns);
|
|
2997
|
+
removePending(q, name);
|
|
2998
|
+
if (err) q.errors.push(err);
|
|
2999
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
3000
|
+
Object.keys(q.loaded).forEach((l) => {
|
|
3001
|
+
if (!loaded[l]) loaded[l] = {};
|
|
3002
|
+
const loadedKeys = q.loaded[l];
|
|
3003
|
+
if (loadedKeys.length) loadedKeys.forEach((n) => {
|
|
3004
|
+
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
3005
|
+
});
|
|
3006
|
+
});
|
|
3007
|
+
q.done = true;
|
|
3008
|
+
if (q.errors.length) q.callback(q.errors);
|
|
3009
|
+
else q.callback();
|
|
3010
|
+
}
|
|
3011
|
+
});
|
|
3012
|
+
this.emit("loaded", loaded);
|
|
3013
|
+
this.queue = this.queue.filter((q) => !q.done);
|
|
3014
|
+
}
|
|
3015
|
+
read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
|
|
3016
|
+
if (!lng.length) return callback(null, {});
|
|
3017
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
3018
|
+
this.waitingReads.push({
|
|
3019
|
+
lng,
|
|
3020
|
+
ns,
|
|
3021
|
+
fcName,
|
|
3022
|
+
tried,
|
|
3023
|
+
wait,
|
|
3024
|
+
callback
|
|
3025
|
+
});
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
this.readingCalls++;
|
|
3029
|
+
const resolver = (err, data) => {
|
|
3030
|
+
this.readingCalls--;
|
|
3031
|
+
if (this.waitingReads.length > 0) {
|
|
3032
|
+
const next = this.waitingReads.shift();
|
|
3033
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
3034
|
+
}
|
|
3035
|
+
if (err && data && tried < this.maxRetries) {
|
|
3036
|
+
setTimeout(() => {
|
|
3037
|
+
this.read(lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
3038
|
+
}, wait);
|
|
3039
|
+
return;
|
|
3040
|
+
}
|
|
3041
|
+
callback(err, data);
|
|
3042
|
+
};
|
|
3043
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
3044
|
+
if (fc.length === 2) {
|
|
3045
|
+
try {
|
|
3046
|
+
const r = fc(lng, ns);
|
|
3047
|
+
if (r && typeof r.then === "function") r.then((data) => resolver(null, data)).catch(resolver);
|
|
3048
|
+
else resolver(null, r);
|
|
3049
|
+
} catch (err) {
|
|
3050
|
+
resolver(err);
|
|
3051
|
+
}
|
|
3052
|
+
return;
|
|
3053
|
+
}
|
|
3054
|
+
return fc(lng, ns, resolver);
|
|
3055
|
+
}
|
|
3056
|
+
prepareLoading(languages, namespaces, options = {}, callback) {
|
|
3057
|
+
if (!this.backend) {
|
|
3058
|
+
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
3059
|
+
return callback && callback();
|
|
3060
|
+
}
|
|
3061
|
+
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
3062
|
+
if (isString(namespaces)) namespaces = [namespaces];
|
|
3063
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
3064
|
+
if (!toLoad.toLoad.length) {
|
|
3065
|
+
if (!toLoad.pending.length) callback();
|
|
3066
|
+
return null;
|
|
3067
|
+
}
|
|
3068
|
+
toLoad.toLoad.forEach((name) => {
|
|
3069
|
+
this.loadOne(name);
|
|
3070
|
+
});
|
|
3071
|
+
}
|
|
3072
|
+
load(languages, namespaces, callback) {
|
|
3073
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
3074
|
+
}
|
|
3075
|
+
reload(languages, namespaces, callback) {
|
|
3076
|
+
this.prepareLoading(languages, namespaces, { reload: true }, callback);
|
|
3077
|
+
}
|
|
3078
|
+
loadOne(name, prefix = "") {
|
|
3079
|
+
const s = name.split("|");
|
|
3080
|
+
const lng = s[0];
|
|
3081
|
+
const ns = s[1];
|
|
3082
|
+
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
3083
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
3084
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
3085
|
+
this.loaded(name, err, data);
|
|
3086
|
+
});
|
|
3087
|
+
}
|
|
3088
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
|
|
3089
|
+
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
3090
|
+
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
3091
|
+
return;
|
|
3092
|
+
}
|
|
3093
|
+
if (key === void 0 || key === null || key === "") return;
|
|
3094
|
+
if (this.backend?.create) {
|
|
3095
|
+
const opts = {
|
|
3096
|
+
...options,
|
|
3097
|
+
isUpdate
|
|
3098
|
+
};
|
|
3099
|
+
const fc = this.backend.create.bind(this.backend);
|
|
3100
|
+
if (fc.length < 6) try {
|
|
3101
|
+
let r;
|
|
3102
|
+
if (fc.length === 5) r = fc(languages, namespace, key, fallbackValue, opts);
|
|
3103
|
+
else r = fc(languages, namespace, key, fallbackValue);
|
|
3104
|
+
if (r && typeof r.then === "function") r.then((data) => clb(null, data)).catch(clb);
|
|
3105
|
+
else clb(null, r);
|
|
3106
|
+
} catch (err) {
|
|
3107
|
+
clb(err);
|
|
3108
|
+
}
|
|
3109
|
+
else fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
3110
|
+
}
|
|
3111
|
+
if (!languages || !languages[0]) return;
|
|
3112
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
3113
|
+
}
|
|
3114
|
+
};
|
|
3115
|
+
const get = () => ({
|
|
3116
|
+
debug: false,
|
|
3117
|
+
initAsync: true,
|
|
3118
|
+
ns: ["translation"],
|
|
3119
|
+
defaultNS: ["translation"],
|
|
3120
|
+
fallbackLng: ["dev"],
|
|
3121
|
+
fallbackNS: false,
|
|
3122
|
+
supportedLngs: false,
|
|
3123
|
+
nonExplicitSupportedLngs: false,
|
|
3124
|
+
load: "all",
|
|
3125
|
+
preload: false,
|
|
3126
|
+
keySeparator: ".",
|
|
3127
|
+
nsSeparator: ":",
|
|
3128
|
+
pluralSeparator: "_",
|
|
3129
|
+
contextSeparator: "_",
|
|
3130
|
+
enableSelector: false,
|
|
3131
|
+
partialBundledLanguages: false,
|
|
3132
|
+
saveMissing: false,
|
|
3133
|
+
updateMissing: false,
|
|
3134
|
+
saveMissingTo: "fallback",
|
|
3135
|
+
saveMissingPlurals: true,
|
|
3136
|
+
missingKeyHandler: false,
|
|
3137
|
+
missingInterpolationHandler: false,
|
|
3138
|
+
postProcess: false,
|
|
3139
|
+
postProcessPassResolved: false,
|
|
3140
|
+
returnNull: false,
|
|
3141
|
+
returnEmptyString: true,
|
|
3142
|
+
returnObjects: false,
|
|
3143
|
+
joinArrays: false,
|
|
3144
|
+
returnedObjectHandler: false,
|
|
3145
|
+
parseMissingKeyHandler: false,
|
|
3146
|
+
appendNamespaceToMissingKey: false,
|
|
3147
|
+
appendNamespaceToCIMode: false,
|
|
3148
|
+
overloadTranslationOptionHandler: (args) => {
|
|
3149
|
+
let ret = {};
|
|
3150
|
+
if (typeof args[1] === "object") ret = args[1];
|
|
3151
|
+
if (isString(args[1])) ret.defaultValue = args[1];
|
|
3152
|
+
if (isString(args[2])) ret.tDescription = args[2];
|
|
3153
|
+
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
3154
|
+
const options = args[3] || args[2];
|
|
3155
|
+
Object.keys(options).forEach((key) => {
|
|
3156
|
+
ret[key] = options[key];
|
|
3157
|
+
});
|
|
3158
|
+
}
|
|
3159
|
+
return ret;
|
|
3160
|
+
},
|
|
3161
|
+
interpolation: {
|
|
3162
|
+
escapeValue: true,
|
|
3163
|
+
prefix: "{{",
|
|
3164
|
+
suffix: "}}",
|
|
3165
|
+
formatSeparator: ",",
|
|
3166
|
+
unescapePrefix: "-",
|
|
3167
|
+
nestingPrefix: "$t(",
|
|
3168
|
+
nestingSuffix: ")",
|
|
3169
|
+
nestingOptionsSeparator: ",",
|
|
3170
|
+
maxReplaces: 1e3,
|
|
3171
|
+
skipOnVariables: true
|
|
3172
|
+
},
|
|
3173
|
+
cacheInBuiltFormats: true
|
|
3174
|
+
});
|
|
3175
|
+
const transformOptions = (options) => {
|
|
3176
|
+
if (isString(options.ns)) options.ns = [options.ns];
|
|
3177
|
+
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
3178
|
+
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
3179
|
+
if (options.supportedLngs && !options.supportedLngs.includes("cimode")) options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
3180
|
+
return options;
|
|
3181
|
+
};
|
|
3182
|
+
const noop = () => {};
|
|
3183
|
+
const bindMemberFunctions = (inst) => {
|
|
3184
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(inst)).forEach((mem) => {
|
|
3185
|
+
if (typeof inst[mem] === "function") inst[mem] = inst[mem].bind(inst);
|
|
3186
|
+
});
|
|
3187
|
+
};
|
|
3188
|
+
const instance = class I18n extends EventEmitter {
|
|
3189
|
+
constructor(options = {}, callback) {
|
|
3190
|
+
super();
|
|
3191
|
+
this.options = transformOptions(options);
|
|
3192
|
+
this.services = {};
|
|
3193
|
+
this.logger = baseLogger;
|
|
3194
|
+
this.modules = { external: [] };
|
|
3195
|
+
bindMemberFunctions(this);
|
|
3196
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
3197
|
+
if (!this.options.initAsync) {
|
|
3198
|
+
this.init(options, callback);
|
|
3199
|
+
return this;
|
|
3200
|
+
}
|
|
3201
|
+
setTimeout(() => {
|
|
3202
|
+
this.init(options, callback);
|
|
3203
|
+
}, 0);
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
init(options = {}, callback) {
|
|
3207
|
+
this.isInitializing = true;
|
|
3208
|
+
if (typeof options === "function") {
|
|
3209
|
+
callback = options;
|
|
3210
|
+
options = {};
|
|
3211
|
+
}
|
|
3212
|
+
if (options.defaultNS == null && options.ns) {
|
|
3213
|
+
if (isString(options.ns)) options.defaultNS = options.ns;
|
|
3214
|
+
else if (!options.ns.includes("translation")) options.defaultNS = options.ns[0];
|
|
3215
|
+
}
|
|
3216
|
+
const defOpts = get();
|
|
3217
|
+
this.options = {
|
|
3218
|
+
...defOpts,
|
|
3219
|
+
...this.options,
|
|
3220
|
+
...transformOptions(options)
|
|
3221
|
+
};
|
|
3222
|
+
this.options.interpolation = {
|
|
3223
|
+
...defOpts.interpolation,
|
|
3224
|
+
...this.options.interpolation
|
|
3225
|
+
};
|
|
3226
|
+
if (options.keySeparator !== void 0) this.options.userDefinedKeySeparator = options.keySeparator;
|
|
3227
|
+
if (options.nsSeparator !== void 0) this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
3228
|
+
if (typeof this.options.overloadTranslationOptionHandler !== "function") this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
|
|
3229
|
+
const createClassOnDemand = (ClassOrObject) => {
|
|
3230
|
+
if (!ClassOrObject) return null;
|
|
3231
|
+
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
3232
|
+
return ClassOrObject;
|
|
3233
|
+
};
|
|
3234
|
+
if (!this.options.isClone) {
|
|
3235
|
+
if (this.modules.logger) baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
3236
|
+
else baseLogger.init(null, this.options);
|
|
3237
|
+
let formatter;
|
|
3238
|
+
if (this.modules.formatter) formatter = this.modules.formatter;
|
|
3239
|
+
else formatter = Formatter;
|
|
3240
|
+
const lu = new LanguageUtil(this.options);
|
|
3241
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
3242
|
+
const s = this.services;
|
|
3243
|
+
s.logger = baseLogger;
|
|
3244
|
+
s.resourceStore = this.store;
|
|
3245
|
+
s.languageUtils = lu;
|
|
3246
|
+
s.pluralResolver = new PluralResolver(lu, { prepend: this.options.pluralSeparator });
|
|
3247
|
+
if (formatter) {
|
|
3248
|
+
s.formatter = createClassOnDemand(formatter);
|
|
3249
|
+
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
3250
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
3251
|
+
}
|
|
3252
|
+
s.interpolator = new Interpolator(this.options);
|
|
3253
|
+
s.utils = { hasLoadedNamespace: this.hasLoadedNamespace.bind(this) };
|
|
3254
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
3255
|
+
s.backendConnector.on("*", (event, ...args) => {
|
|
3256
|
+
this.emit(event, ...args);
|
|
3257
|
+
});
|
|
3258
|
+
if (this.modules.languageDetector) {
|
|
3259
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
3260
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
3261
|
+
}
|
|
3262
|
+
if (this.modules.i18nFormat) {
|
|
3263
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
3264
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
3265
|
+
}
|
|
3266
|
+
this.translator = new Translator(this.services, this.options);
|
|
3267
|
+
this.translator.on("*", (event, ...args) => {
|
|
3268
|
+
this.emit(event, ...args);
|
|
3269
|
+
});
|
|
3270
|
+
this.modules.external.forEach((m) => {
|
|
3271
|
+
if (m.init) m.init(this);
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
this.format = this.options.interpolation.format;
|
|
3275
|
+
if (!callback) callback = noop;
|
|
3276
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
3277
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
3278
|
+
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
3279
|
+
}
|
|
3280
|
+
if (!this.services.languageDetector && !this.options.lng) this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
3281
|
+
[
|
|
3282
|
+
"getResource",
|
|
3283
|
+
"hasResourceBundle",
|
|
3284
|
+
"getResourceBundle",
|
|
3285
|
+
"getDataByLanguage"
|
|
3286
|
+
].forEach((fcName) => {
|
|
3287
|
+
this[fcName] = (...args) => this.store[fcName](...args);
|
|
3288
|
+
});
|
|
3289
|
+
[
|
|
3290
|
+
"addResource",
|
|
3291
|
+
"addResources",
|
|
3292
|
+
"addResourceBundle",
|
|
3293
|
+
"removeResourceBundle"
|
|
3294
|
+
].forEach((fcName) => {
|
|
3295
|
+
this[fcName] = (...args) => {
|
|
3296
|
+
this.store[fcName](...args);
|
|
3297
|
+
return this;
|
|
3298
|
+
};
|
|
3299
|
+
});
|
|
3300
|
+
const deferred = defer();
|
|
3301
|
+
const load = () => {
|
|
3302
|
+
const finish = (err, t) => {
|
|
3303
|
+
this.isInitializing = false;
|
|
3304
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
3305
|
+
this.isInitialized = true;
|
|
3306
|
+
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
3307
|
+
this.emit("initialized", this.options);
|
|
3308
|
+
deferred.resolve(t);
|
|
3309
|
+
callback(err, t);
|
|
3310
|
+
};
|
|
3311
|
+
if ((this.languages || this.isLanguageChangingTo) && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
3312
|
+
this.changeLanguage(this.options.lng, finish);
|
|
3313
|
+
};
|
|
3314
|
+
if (this.options.resources || !this.options.initAsync) load();
|
|
3315
|
+
else setTimeout(load, 0);
|
|
3316
|
+
return deferred;
|
|
3317
|
+
}
|
|
3318
|
+
loadResources(language, callback = noop) {
|
|
3319
|
+
let usedCallback = callback;
|
|
3320
|
+
const usedLng = isString(language) ? language : this.language;
|
|
3321
|
+
if (typeof language === "function") usedCallback = language;
|
|
3322
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
3323
|
+
if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
3324
|
+
const toLoad = [];
|
|
3325
|
+
const append = (lng) => {
|
|
3326
|
+
if (!lng) return;
|
|
3327
|
+
if (lng === "cimode") return;
|
|
3328
|
+
this.services.languageUtils.toResolveHierarchy(lng).forEach((l) => {
|
|
3329
|
+
if (l === "cimode") return;
|
|
3330
|
+
if (!toLoad.includes(l)) toLoad.push(l);
|
|
3331
|
+
});
|
|
3332
|
+
};
|
|
3333
|
+
if (!usedLng) this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach((l) => append(l));
|
|
3334
|
+
else append(usedLng);
|
|
3335
|
+
this.options.preload?.forEach?.((l) => append(l));
|
|
3336
|
+
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
3337
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
3338
|
+
usedCallback(e);
|
|
3339
|
+
});
|
|
3340
|
+
} else usedCallback(null);
|
|
3341
|
+
}
|
|
3342
|
+
reloadResources(lngs, ns, callback) {
|
|
3343
|
+
const deferred = defer();
|
|
3344
|
+
if (typeof lngs === "function") {
|
|
3345
|
+
callback = lngs;
|
|
3346
|
+
lngs = void 0;
|
|
3347
|
+
}
|
|
3348
|
+
if (typeof ns === "function") {
|
|
3349
|
+
callback = ns;
|
|
3350
|
+
ns = void 0;
|
|
3351
|
+
}
|
|
3352
|
+
if (!lngs) lngs = this.languages;
|
|
3353
|
+
if (!ns) ns = this.options.ns;
|
|
3354
|
+
if (!callback) callback = noop;
|
|
3355
|
+
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
3356
|
+
deferred.resolve();
|
|
3357
|
+
callback(err);
|
|
3358
|
+
});
|
|
3359
|
+
return deferred;
|
|
3360
|
+
}
|
|
3361
|
+
use(module) {
|
|
3362
|
+
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
3363
|
+
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
3364
|
+
if (module.type === "backend") this.modules.backend = module;
|
|
3365
|
+
if (module.type === "logger" || module.log && module.warn && module.error) this.modules.logger = module;
|
|
3366
|
+
if (module.type === "languageDetector") this.modules.languageDetector = module;
|
|
3367
|
+
if (module.type === "i18nFormat") this.modules.i18nFormat = module;
|
|
3368
|
+
if (module.type === "postProcessor") postProcessor.addPostProcessor(module);
|
|
3369
|
+
if (module.type === "formatter") this.modules.formatter = module;
|
|
3370
|
+
if (module.type === "3rdParty") this.modules.external.push(module);
|
|
3371
|
+
return this;
|
|
3372
|
+
}
|
|
3373
|
+
setResolvedLanguage(l) {
|
|
3374
|
+
if (!l || !this.languages) return;
|
|
3375
|
+
if (["cimode", "dev"].includes(l)) return;
|
|
3376
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
3377
|
+
const lngInLngs = this.languages[li];
|
|
3378
|
+
if (["cimode", "dev"].includes(lngInLngs)) continue;
|
|
3379
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
3380
|
+
this.resolvedLanguage = lngInLngs;
|
|
3381
|
+
break;
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
if (!this.resolvedLanguage && !this.languages.includes(l) && this.store.hasLanguageSomeTranslations(l)) {
|
|
3385
|
+
this.resolvedLanguage = l;
|
|
3386
|
+
this.languages.unshift(l);
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
changeLanguage(lng, callback) {
|
|
3390
|
+
this.isLanguageChangingTo = lng;
|
|
3391
|
+
const deferred = defer();
|
|
3392
|
+
this.emit("languageChanging", lng);
|
|
3393
|
+
const setLngProps = (l) => {
|
|
3394
|
+
this.language = l;
|
|
3395
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
3396
|
+
this.resolvedLanguage = void 0;
|
|
3397
|
+
this.setResolvedLanguage(l);
|
|
3398
|
+
};
|
|
3399
|
+
const done = (err, l) => {
|
|
3400
|
+
if (l) {
|
|
3401
|
+
if (this.isLanguageChangingTo === lng) {
|
|
3402
|
+
setLngProps(l);
|
|
3403
|
+
this.translator.changeLanguage(l);
|
|
3404
|
+
this.isLanguageChangingTo = void 0;
|
|
3405
|
+
this.emit("languageChanged", l);
|
|
3406
|
+
this.logger.log("languageChanged", l);
|
|
3407
|
+
}
|
|
3408
|
+
} else this.isLanguageChangingTo = void 0;
|
|
3409
|
+
deferred.resolve((...args) => this.t(...args));
|
|
3410
|
+
if (callback) callback(err, (...args) => this.t(...args));
|
|
3411
|
+
};
|
|
3412
|
+
const setLng = (lngs) => {
|
|
3413
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
3414
|
+
const fl = isString(lngs) ? lngs : lngs && lngs[0];
|
|
3415
|
+
const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
3416
|
+
if (l) {
|
|
3417
|
+
if (!this.language) setLngProps(l);
|
|
3418
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
3419
|
+
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
3420
|
+
}
|
|
3421
|
+
this.loadResources(l, (err) => {
|
|
3422
|
+
done(err, l);
|
|
3423
|
+
});
|
|
3424
|
+
};
|
|
3425
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) setLng(this.services.languageDetector.detect());
|
|
3426
|
+
else if (!lng && this.services.languageDetector && this.services.languageDetector.async) if (this.services.languageDetector.detect.length === 0) this.services.languageDetector.detect().then(setLng);
|
|
3427
|
+
else this.services.languageDetector.detect(setLng);
|
|
3428
|
+
else setLng(lng);
|
|
3429
|
+
return deferred;
|
|
3430
|
+
}
|
|
3431
|
+
getFixedT(lng, ns, keyPrefix, fixedOpts) {
|
|
3432
|
+
const scopeNs = fixedOpts?.scopeNs;
|
|
3433
|
+
const fixedT = (key, opts, ...rest) => {
|
|
3434
|
+
let o;
|
|
3435
|
+
if (typeof opts !== "object") o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
3436
|
+
else o = { ...opts };
|
|
3437
|
+
o.lng = o.lng || fixedT.lng;
|
|
3438
|
+
o.lngs = o.lngs || fixedT.lngs;
|
|
3439
|
+
const explicitCallNs = o.ns !== void 0 && o.ns !== null;
|
|
3440
|
+
o.ns = o.ns || fixedT.ns;
|
|
3441
|
+
if (o.keyPrefix !== "") o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
3442
|
+
const selectorOpts = {
|
|
3443
|
+
...this.options,
|
|
3444
|
+
...o
|
|
3445
|
+
};
|
|
3446
|
+
if (Array.isArray(scopeNs) && !explicitCallNs) selectorOpts.ns = scopeNs;
|
|
3447
|
+
if (typeof o.keyPrefix === "function") o.keyPrefix = keysFromSelector(o.keyPrefix, selectorOpts);
|
|
3448
|
+
const keySeparator = this.options.keySeparator || ".";
|
|
3449
|
+
let resultKey;
|
|
3450
|
+
if (o.keyPrefix && Array.isArray(key)) resultKey = key.map((k) => {
|
|
3451
|
+
if (typeof k === "function") k = keysFromSelector(k, selectorOpts);
|
|
3452
|
+
return `${o.keyPrefix}${keySeparator}${k}`;
|
|
3453
|
+
});
|
|
3454
|
+
else {
|
|
3455
|
+
if (typeof key === "function") key = keysFromSelector(key, selectorOpts);
|
|
3456
|
+
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
|
|
3457
|
+
}
|
|
3458
|
+
return this.t(resultKey, o);
|
|
3459
|
+
};
|
|
3460
|
+
if (isString(lng)) fixedT.lng = lng;
|
|
3461
|
+
else fixedT.lngs = lng;
|
|
3462
|
+
fixedT.ns = ns;
|
|
3463
|
+
fixedT.keyPrefix = keyPrefix;
|
|
3464
|
+
return fixedT;
|
|
3465
|
+
}
|
|
3466
|
+
t(...args) {
|
|
3467
|
+
return this.translator?.translate(...args);
|
|
3468
|
+
}
|
|
3469
|
+
exists(...args) {
|
|
3470
|
+
return this.translator?.exists(...args);
|
|
3471
|
+
}
|
|
3472
|
+
setDefaultNamespace(ns) {
|
|
3473
|
+
this.options.defaultNS = ns;
|
|
3474
|
+
}
|
|
3475
|
+
hasLoadedNamespace(ns, options = {}) {
|
|
3476
|
+
if (!this.isInitialized) {
|
|
3477
|
+
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
3478
|
+
return false;
|
|
3479
|
+
}
|
|
3480
|
+
if (!this.languages || !this.languages.length) {
|
|
3481
|
+
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
3482
|
+
return false;
|
|
3483
|
+
}
|
|
3484
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
3485
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
3486
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
3487
|
+
if (lng.toLowerCase() === "cimode") return true;
|
|
3488
|
+
const loadNotPending = (l, n) => {
|
|
3489
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
3490
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
3491
|
+
};
|
|
3492
|
+
if (options.precheck) {
|
|
3493
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
3494
|
+
if (preResult !== void 0) return preResult;
|
|
3495
|
+
}
|
|
3496
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
3497
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
3498
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
3499
|
+
return false;
|
|
3500
|
+
}
|
|
3501
|
+
loadNamespaces(ns, callback) {
|
|
3502
|
+
const deferred = defer();
|
|
3503
|
+
if (!this.options.ns) {
|
|
3504
|
+
if (callback) callback();
|
|
3505
|
+
return Promise.resolve();
|
|
3506
|
+
}
|
|
3507
|
+
if (isString(ns)) ns = [ns];
|
|
3508
|
+
ns.forEach((n) => {
|
|
3509
|
+
if (!this.options.ns.includes(n)) this.options.ns.push(n);
|
|
3510
|
+
});
|
|
3511
|
+
this.loadResources((err) => {
|
|
3512
|
+
deferred.resolve();
|
|
3513
|
+
if (callback) callback(err);
|
|
3514
|
+
});
|
|
3515
|
+
return deferred;
|
|
3516
|
+
}
|
|
3517
|
+
loadLanguages(lngs, callback) {
|
|
3518
|
+
const deferred = defer();
|
|
3519
|
+
if (isString(lngs)) lngs = [lngs];
|
|
3520
|
+
const preloaded = this.options.preload || [];
|
|
3521
|
+
const newLngs = lngs.filter((lng) => !preloaded.includes(lng) && this.services.languageUtils.isSupportedCode(lng));
|
|
3522
|
+
if (!newLngs.length) {
|
|
3523
|
+
if (callback) callback();
|
|
3524
|
+
return Promise.resolve();
|
|
3525
|
+
}
|
|
3526
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
3527
|
+
this.loadResources((err) => {
|
|
3528
|
+
deferred.resolve();
|
|
3529
|
+
if (callback) callback(err);
|
|
3530
|
+
});
|
|
3531
|
+
return deferred;
|
|
3532
|
+
}
|
|
3533
|
+
dir(lng) {
|
|
3534
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
3535
|
+
if (!lng) return "rtl";
|
|
3536
|
+
try {
|
|
3537
|
+
const l = new Intl.Locale(lng);
|
|
3538
|
+
if (l && l.getTextInfo) {
|
|
3539
|
+
const ti = l.getTextInfo();
|
|
3540
|
+
if (ti && ti.direction) return ti.direction;
|
|
3541
|
+
}
|
|
3542
|
+
} catch (e) {}
|
|
3543
|
+
const rtlLngs = [
|
|
3544
|
+
"ar",
|
|
3545
|
+
"shu",
|
|
3546
|
+
"sqr",
|
|
3547
|
+
"ssh",
|
|
3548
|
+
"xaa",
|
|
3549
|
+
"yhd",
|
|
3550
|
+
"yud",
|
|
3551
|
+
"aao",
|
|
3552
|
+
"abh",
|
|
3553
|
+
"abv",
|
|
3554
|
+
"acm",
|
|
3555
|
+
"acq",
|
|
3556
|
+
"acw",
|
|
3557
|
+
"acx",
|
|
3558
|
+
"acy",
|
|
3559
|
+
"adf",
|
|
3560
|
+
"ads",
|
|
3561
|
+
"aeb",
|
|
3562
|
+
"aec",
|
|
3563
|
+
"afb",
|
|
3564
|
+
"ajp",
|
|
3565
|
+
"apc",
|
|
3566
|
+
"apd",
|
|
3567
|
+
"arb",
|
|
3568
|
+
"arq",
|
|
3569
|
+
"ars",
|
|
3570
|
+
"ary",
|
|
3571
|
+
"arz",
|
|
3572
|
+
"auz",
|
|
3573
|
+
"avl",
|
|
3574
|
+
"ayh",
|
|
3575
|
+
"ayl",
|
|
3576
|
+
"ayn",
|
|
3577
|
+
"ayp",
|
|
3578
|
+
"bbz",
|
|
3579
|
+
"pga",
|
|
3580
|
+
"he",
|
|
3581
|
+
"iw",
|
|
3582
|
+
"ps",
|
|
3583
|
+
"pbt",
|
|
3584
|
+
"pbu",
|
|
3585
|
+
"pst",
|
|
3586
|
+
"prp",
|
|
3587
|
+
"prd",
|
|
3588
|
+
"ug",
|
|
3589
|
+
"ur",
|
|
3590
|
+
"ydd",
|
|
3591
|
+
"yds",
|
|
3592
|
+
"yih",
|
|
3593
|
+
"ji",
|
|
3594
|
+
"yi",
|
|
3595
|
+
"hbo",
|
|
3596
|
+
"men",
|
|
3597
|
+
"xmn",
|
|
3598
|
+
"fa",
|
|
3599
|
+
"jpr",
|
|
3600
|
+
"peo",
|
|
3601
|
+
"pes",
|
|
3602
|
+
"prs",
|
|
3603
|
+
"dv",
|
|
3604
|
+
"sam",
|
|
3605
|
+
"ckb"
|
|
3606
|
+
];
|
|
3607
|
+
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
3608
|
+
if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
|
|
3609
|
+
return rtlLngs.includes(languageUtils.getLanguagePartFromCode(lng)) || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
3610
|
+
}
|
|
3611
|
+
static createInstance(options = {}, callback) {
|
|
3612
|
+
const instance = new I18n(options, callback);
|
|
3613
|
+
instance.createInstance = I18n.createInstance;
|
|
3614
|
+
return instance;
|
|
3615
|
+
}
|
|
3616
|
+
cloneInstance(options = {}, callback = noop) {
|
|
3617
|
+
const forkResourceStore = options.forkResourceStore;
|
|
3618
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
3619
|
+
const mergedOptions = {
|
|
3620
|
+
...this.options,
|
|
3621
|
+
...options,
|
|
3622
|
+
isClone: true
|
|
3623
|
+
};
|
|
3624
|
+
const clone = new I18n(mergedOptions);
|
|
3625
|
+
if (options.debug !== void 0 || options.prefix !== void 0) clone.logger = clone.logger.clone(options);
|
|
3626
|
+
[
|
|
3627
|
+
"store",
|
|
3628
|
+
"services",
|
|
3629
|
+
"language"
|
|
3630
|
+
].forEach((m) => {
|
|
3631
|
+
clone[m] = this[m];
|
|
3632
|
+
});
|
|
3633
|
+
clone.services = { ...this.services };
|
|
3634
|
+
clone.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
|
|
3635
|
+
if (forkResourceStore) {
|
|
3636
|
+
clone.store = new ResourceStore(Object.keys(this.store.data).reduce((prev, l) => {
|
|
3637
|
+
prev[l] = { ...this.store.data[l] };
|
|
3638
|
+
prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
|
|
3639
|
+
acc[n] = { ...prev[l][n] };
|
|
3640
|
+
return acc;
|
|
3641
|
+
}, prev[l]);
|
|
3642
|
+
return prev;
|
|
3643
|
+
}, {}), mergedOptions);
|
|
3644
|
+
clone.services.resourceStore = clone.store;
|
|
3645
|
+
}
|
|
3646
|
+
if (options.interpolation) {
|
|
3647
|
+
const mergedInterpolation = {
|
|
3648
|
+
...get().interpolation,
|
|
3649
|
+
...this.options.interpolation,
|
|
3650
|
+
...options.interpolation
|
|
3651
|
+
};
|
|
3652
|
+
const mergedForInterpolator = {
|
|
3653
|
+
...mergedOptions,
|
|
3654
|
+
interpolation: mergedInterpolation
|
|
3655
|
+
};
|
|
3656
|
+
clone.services.interpolator = new Interpolator(mergedForInterpolator);
|
|
3657
|
+
}
|
|
3658
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
3659
|
+
clone.translator.on("*", (event, ...args) => {
|
|
3660
|
+
clone.emit(event, ...args);
|
|
3661
|
+
});
|
|
3662
|
+
clone.init(mergedOptions, callback);
|
|
3663
|
+
clone.translator.options = mergedOptions;
|
|
3664
|
+
clone.translator.backendConnector.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
|
|
3665
|
+
return clone;
|
|
3666
|
+
}
|
|
3667
|
+
toJSON() {
|
|
3668
|
+
return {
|
|
3669
|
+
options: this.options,
|
|
3670
|
+
store: this.store,
|
|
3671
|
+
language: this.language,
|
|
3672
|
+
languages: this.languages,
|
|
3673
|
+
resolvedLanguage: this.resolvedLanguage
|
|
3674
|
+
};
|
|
3675
|
+
}
|
|
3676
|
+
}.createInstance();
|
|
3677
|
+
instance.createInstance;
|
|
3678
|
+
instance.dir;
|
|
3679
|
+
instance.init;
|
|
3680
|
+
instance.loadResources;
|
|
3681
|
+
instance.reloadResources;
|
|
3682
|
+
instance.use;
|
|
3683
|
+
instance.changeLanguage;
|
|
3684
|
+
instance.getFixedT;
|
|
3685
|
+
instance.t;
|
|
3686
|
+
instance.exists;
|
|
3687
|
+
instance.setDefaultNamespace;
|
|
3688
|
+
instance.hasLoadedNamespace;
|
|
3689
|
+
instance.loadNamespaces;
|
|
3690
|
+
instance.loadLanguages;
|
|
3691
|
+
//#endregion
|
|
3692
|
+
//#region node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/jsx/jsx-dev-runtime.js
|
|
3693
|
+
function jsxDEV(tag, props, key) {
|
|
3694
|
+
let node;
|
|
3695
|
+
if (!props || !("children" in props)) node = jsxFn(tag, props, []);
|
|
3696
|
+
else {
|
|
3697
|
+
const children = props.children;
|
|
3698
|
+
node = Array.isArray(children) ? jsxFn(tag, props, children) : jsxFn(tag, props, [children]);
|
|
3699
|
+
}
|
|
3700
|
+
node.key = key;
|
|
3701
|
+
return node;
|
|
3702
|
+
}
|
|
3703
|
+
//#endregion
|
|
3704
|
+
export { useRef as a, useReducer as i, instance as n, useState as o, useEffect as r, render as s, jsxDEV as t };
|