docs-i18n 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/assemble-IOHQYYHI.js +74 -0
- package/dist/build-4EQEL4NI.js +12 -0
- package/dist/build2-3W5WMFHZ.js +4901 -0
- package/dist/chunk-3YNFMSJH.js +30 -0
- package/dist/chunk-55MBYBVK.js +368 -0
- package/dist/chunk-7HWWVRNS.js +104 -0
- package/dist/chunk-AKLW2MUS.js +54 -0
- package/dist/chunk-FYDB7MZX.js +38944 -0
- package/dist/chunk-O35QHRY6.js +6 -0
- package/dist/chunk-PTIH4GGE.js +44 -0
- package/dist/chunk-QSVWLTGQ.js +60 -0
- package/dist/chunk-SUIDX6IZ.js +122 -0
- package/dist/chunk-VKKNQBDN.js +6487 -0
- package/dist/chunk-XEOYZUHS.js +396 -0
- package/dist/cli.js +104 -0
- package/dist/dist-6C32URTL.js +19 -0
- package/dist/dist-HOWMMQFV.js +6677 -0
- package/dist/false-JGP4AGWN.js +7 -0
- package/dist/index.d.ts +258 -0
- package/dist/index.js +545 -0
- package/dist/main-QVE5TVA3.js +2505 -0
- package/dist/node-4GLCLDJ6.js +875 -0
- package/dist/node-NUDVMOF2.js +129 -0
- package/dist/postcss-3SK7VUC2.js +5886 -0
- package/dist/postcss-import-JD46KA2Z.js +458 -0
- package/dist/prompt-BYQIwEjg-TG7DLENB.js +915 -0
- package/dist/rescan-VB2PILB2.js +74 -0
- package/dist/serve.d.ts +37 -0
- package/dist/serve.js +38 -0
- package/dist/server-ER56DGPR.js +548 -0
- package/dist/status-EWQEACVF.js +43 -0
- package/dist/translate-F3AQFN6X.js +707 -0
- package/package.json +55 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
async function loadConfig(path) {
|
|
3
|
+
const configPath = path ?? "docs-i18n.config.ts";
|
|
4
|
+
try {
|
|
5
|
+
const mod = await import(
|
|
6
|
+
/* @vite-ignore */
|
|
7
|
+
`${process.cwd()}/${configPath}`
|
|
8
|
+
);
|
|
9
|
+
return mod.default ?? mod;
|
|
10
|
+
} catch {
|
|
11
|
+
throw new Error(`Cannot load config from ${configPath}. Create a docs-i18n.config.ts file.`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function flattenSources(config) {
|
|
15
|
+
const projects = Object.entries(config.projects);
|
|
16
|
+
const singleProject = projects.length === 1;
|
|
17
|
+
return projects.flatMap(
|
|
18
|
+
([projectId, project]) => Object.entries(project.sources).map(([version, sourcePath]) => ({
|
|
19
|
+
project: projectId,
|
|
20
|
+
version,
|
|
21
|
+
sourcePath,
|
|
22
|
+
versionKey: singleProject ? version : `${projectId}/${version}`
|
|
23
|
+
}))
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
loadConfig,
|
|
29
|
+
flattenSources
|
|
30
|
+
};
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJSMin
|
|
3
|
+
} from "./chunk-PTIH4GGE.js";
|
|
4
|
+
|
|
5
|
+
// node_modules/vite/dist/node/chunks/lib.js
|
|
6
|
+
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7
|
+
var openParentheses = "(".charCodeAt(0);
|
|
8
|
+
var closeParentheses = ")".charCodeAt(0);
|
|
9
|
+
var singleQuote = "'".charCodeAt(0);
|
|
10
|
+
var doubleQuote = '"'.charCodeAt(0);
|
|
11
|
+
var backslash = "\\".charCodeAt(0);
|
|
12
|
+
var slash = "/".charCodeAt(0);
|
|
13
|
+
var comma = ",".charCodeAt(0);
|
|
14
|
+
var colon = ":".charCodeAt(0);
|
|
15
|
+
var star = "*".charCodeAt(0);
|
|
16
|
+
var uLower = "u".charCodeAt(0);
|
|
17
|
+
var uUpper = "U".charCodeAt(0);
|
|
18
|
+
var plus = "+".charCodeAt(0);
|
|
19
|
+
var isUnicodeRange = /^[a-f0-9?-]+$/i;
|
|
20
|
+
module.exports = function(input) {
|
|
21
|
+
var tokens = [];
|
|
22
|
+
var value = input;
|
|
23
|
+
var next, quote, prev, token, escape, escapePos, whitespacePos, parenthesesOpenPos;
|
|
24
|
+
var pos = 0;
|
|
25
|
+
var code = value.charCodeAt(pos);
|
|
26
|
+
var max = value.length;
|
|
27
|
+
var stack = [{ nodes: tokens }];
|
|
28
|
+
var balanced = 0;
|
|
29
|
+
var parent;
|
|
30
|
+
var name = "";
|
|
31
|
+
var before = "";
|
|
32
|
+
var after = "";
|
|
33
|
+
while (pos < max) if (code <= 32) {
|
|
34
|
+
next = pos;
|
|
35
|
+
do {
|
|
36
|
+
next += 1;
|
|
37
|
+
code = value.charCodeAt(next);
|
|
38
|
+
} while (code <= 32);
|
|
39
|
+
token = value.slice(pos, next);
|
|
40
|
+
prev = tokens[tokens.length - 1];
|
|
41
|
+
if (code === closeParentheses && balanced) after = token;
|
|
42
|
+
else if (prev && prev.type === "div") {
|
|
43
|
+
prev.after = token;
|
|
44
|
+
prev.sourceEndIndex += token.length;
|
|
45
|
+
} else if (code === comma || code === colon || code === slash && value.charCodeAt(next + 1) !== star && (!parent || parent && parent.type === "function" && parent.value !== "calc")) before = token;
|
|
46
|
+
else tokens.push({
|
|
47
|
+
type: "space",
|
|
48
|
+
sourceIndex: pos,
|
|
49
|
+
sourceEndIndex: next,
|
|
50
|
+
value: token
|
|
51
|
+
});
|
|
52
|
+
pos = next;
|
|
53
|
+
} else if (code === singleQuote || code === doubleQuote) {
|
|
54
|
+
next = pos;
|
|
55
|
+
quote = code === singleQuote ? "'" : '"';
|
|
56
|
+
token = {
|
|
57
|
+
type: "string",
|
|
58
|
+
sourceIndex: pos,
|
|
59
|
+
quote
|
|
60
|
+
};
|
|
61
|
+
do {
|
|
62
|
+
escape = false;
|
|
63
|
+
next = value.indexOf(quote, next + 1);
|
|
64
|
+
if (~next) {
|
|
65
|
+
escapePos = next;
|
|
66
|
+
while (value.charCodeAt(escapePos - 1) === backslash) {
|
|
67
|
+
escapePos -= 1;
|
|
68
|
+
escape = !escape;
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
value += quote;
|
|
72
|
+
next = value.length - 1;
|
|
73
|
+
token.unclosed = true;
|
|
74
|
+
}
|
|
75
|
+
} while (escape);
|
|
76
|
+
token.value = value.slice(pos + 1, next);
|
|
77
|
+
token.sourceEndIndex = token.unclosed ? next : next + 1;
|
|
78
|
+
tokens.push(token);
|
|
79
|
+
pos = next + 1;
|
|
80
|
+
code = value.charCodeAt(pos);
|
|
81
|
+
} else if (code === slash && value.charCodeAt(pos + 1) === star) {
|
|
82
|
+
next = value.indexOf("*/", pos);
|
|
83
|
+
token = {
|
|
84
|
+
type: "comment",
|
|
85
|
+
sourceIndex: pos,
|
|
86
|
+
sourceEndIndex: next + 2
|
|
87
|
+
};
|
|
88
|
+
if (next === -1) {
|
|
89
|
+
token.unclosed = true;
|
|
90
|
+
next = value.length;
|
|
91
|
+
token.sourceEndIndex = next;
|
|
92
|
+
}
|
|
93
|
+
token.value = value.slice(pos + 2, next);
|
|
94
|
+
tokens.push(token);
|
|
95
|
+
pos = next + 2;
|
|
96
|
+
code = value.charCodeAt(pos);
|
|
97
|
+
} else if ((code === slash || code === star) && parent && parent.type === "function" && parent.value === "calc") {
|
|
98
|
+
token = value[pos];
|
|
99
|
+
tokens.push({
|
|
100
|
+
type: "word",
|
|
101
|
+
sourceIndex: pos - before.length,
|
|
102
|
+
sourceEndIndex: pos + token.length,
|
|
103
|
+
value: token
|
|
104
|
+
});
|
|
105
|
+
pos += 1;
|
|
106
|
+
code = value.charCodeAt(pos);
|
|
107
|
+
} else if (code === slash || code === comma || code === colon) {
|
|
108
|
+
token = value[pos];
|
|
109
|
+
tokens.push({
|
|
110
|
+
type: "div",
|
|
111
|
+
sourceIndex: pos - before.length,
|
|
112
|
+
sourceEndIndex: pos + token.length,
|
|
113
|
+
value: token,
|
|
114
|
+
before,
|
|
115
|
+
after: ""
|
|
116
|
+
});
|
|
117
|
+
before = "";
|
|
118
|
+
pos += 1;
|
|
119
|
+
code = value.charCodeAt(pos);
|
|
120
|
+
} else if (openParentheses === code) {
|
|
121
|
+
next = pos;
|
|
122
|
+
do {
|
|
123
|
+
next += 1;
|
|
124
|
+
code = value.charCodeAt(next);
|
|
125
|
+
} while (code <= 32);
|
|
126
|
+
parenthesesOpenPos = pos;
|
|
127
|
+
token = {
|
|
128
|
+
type: "function",
|
|
129
|
+
sourceIndex: pos - name.length,
|
|
130
|
+
value: name,
|
|
131
|
+
before: value.slice(parenthesesOpenPos + 1, next)
|
|
132
|
+
};
|
|
133
|
+
pos = next;
|
|
134
|
+
if (name === "url" && code !== singleQuote && code !== doubleQuote) {
|
|
135
|
+
next -= 1;
|
|
136
|
+
do {
|
|
137
|
+
escape = false;
|
|
138
|
+
next = value.indexOf(")", next + 1);
|
|
139
|
+
if (~next) {
|
|
140
|
+
escapePos = next;
|
|
141
|
+
while (value.charCodeAt(escapePos - 1) === backslash) {
|
|
142
|
+
escapePos -= 1;
|
|
143
|
+
escape = !escape;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
value += ")";
|
|
147
|
+
next = value.length - 1;
|
|
148
|
+
token.unclosed = true;
|
|
149
|
+
}
|
|
150
|
+
} while (escape);
|
|
151
|
+
whitespacePos = next;
|
|
152
|
+
do {
|
|
153
|
+
whitespacePos -= 1;
|
|
154
|
+
code = value.charCodeAt(whitespacePos);
|
|
155
|
+
} while (code <= 32);
|
|
156
|
+
if (parenthesesOpenPos < whitespacePos) {
|
|
157
|
+
if (pos !== whitespacePos + 1) token.nodes = [{
|
|
158
|
+
type: "word",
|
|
159
|
+
sourceIndex: pos,
|
|
160
|
+
sourceEndIndex: whitespacePos + 1,
|
|
161
|
+
value: value.slice(pos, whitespacePos + 1)
|
|
162
|
+
}];
|
|
163
|
+
else token.nodes = [];
|
|
164
|
+
if (token.unclosed && whitespacePos + 1 !== next) {
|
|
165
|
+
token.after = "";
|
|
166
|
+
token.nodes.push({
|
|
167
|
+
type: "space",
|
|
168
|
+
sourceIndex: whitespacePos + 1,
|
|
169
|
+
sourceEndIndex: next,
|
|
170
|
+
value: value.slice(whitespacePos + 1, next)
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
token.after = value.slice(whitespacePos + 1, next);
|
|
174
|
+
token.sourceEndIndex = next;
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
token.after = "";
|
|
178
|
+
token.nodes = [];
|
|
179
|
+
}
|
|
180
|
+
pos = next + 1;
|
|
181
|
+
token.sourceEndIndex = token.unclosed ? next : pos;
|
|
182
|
+
code = value.charCodeAt(pos);
|
|
183
|
+
tokens.push(token);
|
|
184
|
+
} else {
|
|
185
|
+
balanced += 1;
|
|
186
|
+
token.after = "";
|
|
187
|
+
token.sourceEndIndex = pos + 1;
|
|
188
|
+
tokens.push(token);
|
|
189
|
+
stack.push(token);
|
|
190
|
+
tokens = token.nodes = [];
|
|
191
|
+
parent = token;
|
|
192
|
+
}
|
|
193
|
+
name = "";
|
|
194
|
+
} else if (closeParentheses === code && balanced) {
|
|
195
|
+
pos += 1;
|
|
196
|
+
code = value.charCodeAt(pos);
|
|
197
|
+
parent.after = after;
|
|
198
|
+
parent.sourceEndIndex += after.length;
|
|
199
|
+
after = "";
|
|
200
|
+
balanced -= 1;
|
|
201
|
+
stack[stack.length - 1].sourceEndIndex = pos;
|
|
202
|
+
stack.pop();
|
|
203
|
+
parent = stack[balanced];
|
|
204
|
+
tokens = parent.nodes;
|
|
205
|
+
} else {
|
|
206
|
+
next = pos;
|
|
207
|
+
do {
|
|
208
|
+
if (code === backslash) next += 1;
|
|
209
|
+
next += 1;
|
|
210
|
+
code = value.charCodeAt(next);
|
|
211
|
+
} while (next < max && !(code <= 32 || code === singleQuote || code === doubleQuote || code === comma || code === colon || code === slash || code === openParentheses || code === star && parent && parent.type === "function" && parent.value === "calc" || code === slash && parent.type === "function" && parent.value === "calc" || code === closeParentheses && balanced));
|
|
212
|
+
token = value.slice(pos, next);
|
|
213
|
+
if (openParentheses === code) name = token;
|
|
214
|
+
else if ((uLower === token.charCodeAt(0) || uUpper === token.charCodeAt(0)) && plus === token.charCodeAt(1) && isUnicodeRange.test(token.slice(2))) tokens.push({
|
|
215
|
+
type: "unicode-range",
|
|
216
|
+
sourceIndex: pos,
|
|
217
|
+
sourceEndIndex: next,
|
|
218
|
+
value: token
|
|
219
|
+
});
|
|
220
|
+
else tokens.push({
|
|
221
|
+
type: "word",
|
|
222
|
+
sourceIndex: pos,
|
|
223
|
+
sourceEndIndex: next,
|
|
224
|
+
value: token
|
|
225
|
+
});
|
|
226
|
+
pos = next;
|
|
227
|
+
}
|
|
228
|
+
for (pos = stack.length - 1; pos; pos -= 1) {
|
|
229
|
+
stack[pos].unclosed = true;
|
|
230
|
+
stack[pos].sourceEndIndex = value.length;
|
|
231
|
+
}
|
|
232
|
+
return stack[0].nodes;
|
|
233
|
+
};
|
|
234
|
+
}));
|
|
235
|
+
var require_walk = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
236
|
+
module.exports = function walk(nodes, cb, bubble) {
|
|
237
|
+
var i, max, node, result;
|
|
238
|
+
for (i = 0, max = nodes.length; i < max; i += 1) {
|
|
239
|
+
node = nodes[i];
|
|
240
|
+
if (!bubble) result = cb(node, i, nodes);
|
|
241
|
+
if (result !== false && node.type === "function" && Array.isArray(node.nodes)) walk(node.nodes, cb, bubble);
|
|
242
|
+
if (bubble) cb(node, i, nodes);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}));
|
|
246
|
+
var require_stringify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
247
|
+
function stringifyNode(node, custom) {
|
|
248
|
+
var type = node.type;
|
|
249
|
+
var value = node.value;
|
|
250
|
+
var buf;
|
|
251
|
+
var customResult;
|
|
252
|
+
if (custom && (customResult = custom(node)) !== void 0) return customResult;
|
|
253
|
+
else if (type === "word" || type === "space") return value;
|
|
254
|
+
else if (type === "string") {
|
|
255
|
+
buf = node.quote || "";
|
|
256
|
+
return buf + value + (node.unclosed ? "" : buf);
|
|
257
|
+
} else if (type === "comment") return "/*" + value + (node.unclosed ? "" : "*/");
|
|
258
|
+
else if (type === "div") return (node.before || "") + value + (node.after || "");
|
|
259
|
+
else if (Array.isArray(node.nodes)) {
|
|
260
|
+
buf = stringify(node.nodes, custom);
|
|
261
|
+
if (type !== "function") return buf;
|
|
262
|
+
return value + "(" + (node.before || "") + buf + (node.after || "") + (node.unclosed ? "" : ")");
|
|
263
|
+
}
|
|
264
|
+
return value;
|
|
265
|
+
}
|
|
266
|
+
function stringify(nodes, custom) {
|
|
267
|
+
var result, i;
|
|
268
|
+
if (Array.isArray(nodes)) {
|
|
269
|
+
result = "";
|
|
270
|
+
for (i = nodes.length - 1; ~i; i -= 1) result = stringifyNode(nodes[i], custom) + result;
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
return stringifyNode(nodes, custom);
|
|
274
|
+
}
|
|
275
|
+
module.exports = stringify;
|
|
276
|
+
}));
|
|
277
|
+
var require_unit = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
278
|
+
var minus = "-".charCodeAt(0);
|
|
279
|
+
var plus = "+".charCodeAt(0);
|
|
280
|
+
var dot = ".".charCodeAt(0);
|
|
281
|
+
var exp = "e".charCodeAt(0);
|
|
282
|
+
var EXP = "E".charCodeAt(0);
|
|
283
|
+
function likeNumber(value) {
|
|
284
|
+
var code = value.charCodeAt(0);
|
|
285
|
+
var nextCode;
|
|
286
|
+
if (code === plus || code === minus) {
|
|
287
|
+
nextCode = value.charCodeAt(1);
|
|
288
|
+
if (nextCode >= 48 && nextCode <= 57) return true;
|
|
289
|
+
var nextNextCode = value.charCodeAt(2);
|
|
290
|
+
if (nextCode === dot && nextNextCode >= 48 && nextNextCode <= 57) return true;
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
if (code === dot) {
|
|
294
|
+
nextCode = value.charCodeAt(1);
|
|
295
|
+
if (nextCode >= 48 && nextCode <= 57) return true;
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
if (code >= 48 && code <= 57) return true;
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
module.exports = function(value) {
|
|
302
|
+
var pos = 0;
|
|
303
|
+
var length = value.length;
|
|
304
|
+
var code;
|
|
305
|
+
var nextCode;
|
|
306
|
+
var nextNextCode;
|
|
307
|
+
if (length === 0 || !likeNumber(value)) return false;
|
|
308
|
+
code = value.charCodeAt(pos);
|
|
309
|
+
if (code === plus || code === minus) pos++;
|
|
310
|
+
while (pos < length) {
|
|
311
|
+
code = value.charCodeAt(pos);
|
|
312
|
+
if (code < 48 || code > 57) break;
|
|
313
|
+
pos += 1;
|
|
314
|
+
}
|
|
315
|
+
code = value.charCodeAt(pos);
|
|
316
|
+
nextCode = value.charCodeAt(pos + 1);
|
|
317
|
+
if (code === dot && nextCode >= 48 && nextCode <= 57) {
|
|
318
|
+
pos += 2;
|
|
319
|
+
while (pos < length) {
|
|
320
|
+
code = value.charCodeAt(pos);
|
|
321
|
+
if (code < 48 || code > 57) break;
|
|
322
|
+
pos += 1;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
code = value.charCodeAt(pos);
|
|
326
|
+
nextCode = value.charCodeAt(pos + 1);
|
|
327
|
+
nextNextCode = value.charCodeAt(pos + 2);
|
|
328
|
+
if ((code === exp || code === EXP) && (nextCode >= 48 && nextCode <= 57 || (nextCode === plus || nextCode === minus) && nextNextCode >= 48 && nextNextCode <= 57)) {
|
|
329
|
+
pos += nextCode === plus || nextCode === minus ? 3 : 2;
|
|
330
|
+
while (pos < length) {
|
|
331
|
+
code = value.charCodeAt(pos);
|
|
332
|
+
if (code < 48 || code > 57) break;
|
|
333
|
+
pos += 1;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
number: value.slice(0, pos),
|
|
338
|
+
unit: value.slice(pos)
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
}));
|
|
342
|
+
var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
343
|
+
var parse = require_parse();
|
|
344
|
+
var walk = require_walk();
|
|
345
|
+
var stringify = require_stringify();
|
|
346
|
+
function ValueParser(value) {
|
|
347
|
+
if (this instanceof ValueParser) {
|
|
348
|
+
this.nodes = parse(value);
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
return new ValueParser(value);
|
|
352
|
+
}
|
|
353
|
+
ValueParser.prototype.toString = function() {
|
|
354
|
+
return Array.isArray(this.nodes) ? stringify(this.nodes) : "";
|
|
355
|
+
};
|
|
356
|
+
ValueParser.prototype.walk = function(cb, bubble) {
|
|
357
|
+
walk(this.nodes, cb, bubble);
|
|
358
|
+
return this;
|
|
359
|
+
};
|
|
360
|
+
ValueParser.unit = require_unit();
|
|
361
|
+
ValueParser.walk = walk;
|
|
362
|
+
ValueParser.stringify = stringify;
|
|
363
|
+
module.exports = ValueParser;
|
|
364
|
+
}));
|
|
365
|
+
|
|
366
|
+
export {
|
|
367
|
+
require_lib
|
|
368
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/core/normalize.ts
|
|
2
|
+
function normalize(content) {
|
|
3
|
+
let result = content;
|
|
4
|
+
result = result.replace(
|
|
5
|
+
/^(<(?:AppOnly|PagesOnly|details[^>]*|div[^>]*)>)\n(?!\n)/gm,
|
|
6
|
+
"$1\n\n"
|
|
7
|
+
);
|
|
8
|
+
result = result.replace(
|
|
9
|
+
/(?<!\n)\n(<\/(?:AppOnly|PagesOnly|details|div)>)/gm,
|
|
10
|
+
"\n\n$1"
|
|
11
|
+
);
|
|
12
|
+
result = result.replace(
|
|
13
|
+
/^(<\/(?:AppOnly|PagesOnly|details|div)>)\n(?!\n)/gm,
|
|
14
|
+
"$1\n\n"
|
|
15
|
+
);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/core/parser.ts
|
|
20
|
+
import crypto from "crypto";
|
|
21
|
+
import { remark } from "remark";
|
|
22
|
+
var TRANSLATABLE_TYPES = /* @__PURE__ */ new Set([
|
|
23
|
+
"paragraph",
|
|
24
|
+
"heading",
|
|
25
|
+
"list",
|
|
26
|
+
"blockquote"
|
|
27
|
+
]);
|
|
28
|
+
function isHtmlPureTag(text) {
|
|
29
|
+
const lines = text.trim().split("\n");
|
|
30
|
+
return lines.every((line) => {
|
|
31
|
+
const trimmed = line.trim();
|
|
32
|
+
if (trimmed === "") return true;
|
|
33
|
+
if (/^<\w[^>]*\/>$/.test(trimmed)) return true;
|
|
34
|
+
if (/^<\/?\w[\w-]*[^>]*>$/.test(trimmed)) return true;
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function computeHash(text) {
|
|
39
|
+
return crypto.createHash("md5").update(text).digest("hex");
|
|
40
|
+
}
|
|
41
|
+
var FRONTMATTER_TRANSLATABLE_FIELDS = [
|
|
42
|
+
"title",
|
|
43
|
+
"description",
|
|
44
|
+
"nav_title",
|
|
45
|
+
"related.title",
|
|
46
|
+
"related.description"
|
|
47
|
+
];
|
|
48
|
+
function parseMdx(rawContent) {
|
|
49
|
+
const content = normalize(rawContent);
|
|
50
|
+
const tree = remark().parse(content);
|
|
51
|
+
const nodes = [];
|
|
52
|
+
let frontmatterHandled = false;
|
|
53
|
+
if (content.startsWith("---") && tree.children.length >= 2 && tree.children[0].type === "thematicBreak") {
|
|
54
|
+
const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
|
55
|
+
if (fmMatch) {
|
|
56
|
+
const fmEnd = fmMatch[0].length;
|
|
57
|
+
const fmText = fmMatch[0];
|
|
58
|
+
nodes.push({
|
|
59
|
+
type: "frontmatter",
|
|
60
|
+
rawText: fmText,
|
|
61
|
+
needsTranslation: true,
|
|
62
|
+
md5: computeHash(fmText),
|
|
63
|
+
startOffset: 0,
|
|
64
|
+
endOffset: fmEnd
|
|
65
|
+
});
|
|
66
|
+
frontmatterHandled = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const child of tree.children) {
|
|
70
|
+
const startOffset = child.position?.start.offset ?? 0;
|
|
71
|
+
const endOffset = child.position?.end.offset ?? 0;
|
|
72
|
+
if (frontmatterHandled && startOffset < nodes[0].endOffset) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const rawText = content.substring(startOffset, endOffset);
|
|
76
|
+
const type = child.type;
|
|
77
|
+
let needsTranslation;
|
|
78
|
+
if (TRANSLATABLE_TYPES.has(type)) {
|
|
79
|
+
needsTranslation = true;
|
|
80
|
+
} else if (type === "html") {
|
|
81
|
+
needsTranslation = !isHtmlPureTag(rawText);
|
|
82
|
+
} else {
|
|
83
|
+
needsTranslation = false;
|
|
84
|
+
}
|
|
85
|
+
const node = {
|
|
86
|
+
type,
|
|
87
|
+
rawText,
|
|
88
|
+
needsTranslation,
|
|
89
|
+
startOffset,
|
|
90
|
+
endOffset
|
|
91
|
+
};
|
|
92
|
+
if (needsTranslation) {
|
|
93
|
+
node.md5 = computeHash(rawText);
|
|
94
|
+
}
|
|
95
|
+
nodes.push(node);
|
|
96
|
+
}
|
|
97
|
+
return nodes;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
normalize,
|
|
102
|
+
FRONTMATTER_TRANSLATABLE_FIELDS,
|
|
103
|
+
parseMdx
|
|
104
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __glob = (map) => (path) => {
|
|
14
|
+
var fn = map[path];
|
|
15
|
+
if (fn) return fn();
|
|
16
|
+
throw new Error("Module not found in bundle: " + path);
|
|
17
|
+
};
|
|
18
|
+
var __esm = (fn, res) => function __init() {
|
|
19
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
20
|
+
};
|
|
21
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
22
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
23
|
+
};
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
+
mod
|
|
43
|
+
));
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
__require,
|
|
48
|
+
__glob,
|
|
49
|
+
__esm,
|
|
50
|
+
__commonJS,
|
|
51
|
+
__export,
|
|
52
|
+
__toESM,
|
|
53
|
+
__toCommonJS
|
|
54
|
+
};
|