@intlify/core 12.0.0-alpha.11 → 12.0.0-alpha.13
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/dist/core.esm-browser.js +174 -29
- package/dist/core.esm-browser.prod.js +383 -292
- package/dist/core.global.js +174 -29
- package/dist/core.global.prod.js +442 -351
- package/dist/core.js +1 -1
- package/dist/core.node.js +1 -1
- package/dist/core.runtime.esm-browser.js +174 -29
- package/dist/core.runtime.esm-browser.prod.js +373 -282
- package/dist/core.runtime.global.js +174 -29
- package/dist/core.runtime.global.prod.js +388 -297
- package/dist/core.runtime.js +1 -1
- package/dist/core.runtime.node.js +1 -1
- package/package.json +3 -3
package/dist/core.global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @intlify/core v12.0.0-alpha.
|
|
2
|
+
* @intlify/core v12.0.0-alpha.13
|
|
3
3
|
* (c) 2016-present kazuya kawaguchi and contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -223,6 +223,106 @@ var IntlifyCore = (function(exports) {
|
|
|
223
223
|
const valueQuote = quote || "";
|
|
224
224
|
return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
|
|
225
225
|
}
|
|
226
|
+
const HTML = 0;
|
|
227
|
+
const SVG = 1;
|
|
228
|
+
const MATHML = 2;
|
|
229
|
+
const notOpenedElementPattern = /^(?:area|base|basefont|bgsound|br|col|embed|frame|hr|image|img|input|keygen|link|meta|param|source|track|wbr|html|head|body|frameset)$/;
|
|
230
|
+
const breakoutElementPattern = /^(?:[bipsu]|big|blockquote|body|br|center|code|dd|div|dl|dt|em|embed|h[1-6]|head|hr|img|li|listing|menu|meta|nobr|ol|pre|ruby|small|span|strong|strike|sub|sup|table|tt|ul|var)$/;
|
|
231
|
+
const paragraphClosingElementPattern = /^(?:address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|header|hgroup|main|menu|nav|ol|p|search|section|summary|ul|h[1-6]|pre|listing|form|li|dd|dt|plaintext|table|hr|xmp)$/;
|
|
232
|
+
const buttonScopeElementPattern = /^(?:applet|caption|html|table|td|th|marquee|object|template|button)$/;
|
|
233
|
+
const svgIntegrationPattern = /^(?:foreignobject|desc|title)$/;
|
|
234
|
+
const integrationNamePattern = /^(?:foreignobject|desc|mi|mo|mn|ms|mtext|annotation-xml)$/;
|
|
235
|
+
const mathmlIntegrationPattern = /^(?:mi|mo|mn|ms|mtext)$/;
|
|
236
|
+
const htmlEncodingPattern = /^(?:text\/html|application\/xhtml\+xml)$/i;
|
|
237
|
+
function asciiLowercase(text) {
|
|
238
|
+
return text.replace(/[A-Z]+/g, (upper) => upper.toLowerCase());
|
|
239
|
+
}
|
|
240
|
+
function isForeignContext(top, name) {
|
|
241
|
+
return !!top && top.namespace !== HTML && (!top.integration || mathmlIntegrationPattern.test(top.name) && (name === "mglyph" || name === "malignmark")) && !(top.name === "annotation-xml" && name === "svg");
|
|
242
|
+
}
|
|
243
|
+
function isBreakout(name, attributes) {
|
|
244
|
+
return breakoutElementPattern.test(name) || name === "font" && (attributes.has("color") || attributes.has("face") || attributes.has("size"));
|
|
245
|
+
}
|
|
246
|
+
function closeDownTo(stack, length, parts) {
|
|
247
|
+
let endTags = "";
|
|
248
|
+
for (let index = stack.length - 1; index >= length; index--) {
|
|
249
|
+
const element = stack[index];
|
|
250
|
+
if (element.namespace === HTML && element.name === "form") parts[element.part] = escapeLessThan(parts[element.part]);
|
|
251
|
+
else endTags += `</${element.name}>`;
|
|
252
|
+
}
|
|
253
|
+
stack.length = length;
|
|
254
|
+
return endTags;
|
|
255
|
+
}
|
|
256
|
+
function closeForeign(stack, parts) {
|
|
257
|
+
let length = stack.length;
|
|
258
|
+
while (length > 0 && stack[length - 1].namespace !== HTML && !stack[length - 1].integration) length--;
|
|
259
|
+
return closeDownTo(stack, length, parts);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Open an element for a start tag, as the tree builder does
|
|
263
|
+
*
|
|
264
|
+
* @returns The end tags to write before the start tag: the SVG and MathML elements that it ends, and a `<p>`
|
|
265
|
+
* of the translation that it closes, with the elements in the `<p>` (so that no formatting element in it is
|
|
266
|
+
* made again after it), or `undefined` when the start tag becomes text
|
|
267
|
+
*/
|
|
268
|
+
function openElement(stack, parts, name, attributes, selfClosing) {
|
|
269
|
+
const part = parts.length + 1;
|
|
270
|
+
let endTags = "";
|
|
271
|
+
const top = stack[stack.length - 1];
|
|
272
|
+
if (isForeignContext(top, name)) {
|
|
273
|
+
if (!isBreakout(name, attributes)) {
|
|
274
|
+
if (!selfClosing) stack.push({
|
|
275
|
+
name,
|
|
276
|
+
namespace: top.namespace,
|
|
277
|
+
integration: top.namespace === SVG ? svgIntegrationPattern.test(name) : mathmlIntegrationPattern.test(name) || name === "annotation-xml" && htmlEncodingPattern.test((attributes.get("encoding") || "").replace(numericCharacterReferencePattern, decodeNumericCharacterReference)),
|
|
278
|
+
part
|
|
279
|
+
});
|
|
280
|
+
return endTags;
|
|
281
|
+
}
|
|
282
|
+
endTags = closeForeign(stack, parts);
|
|
283
|
+
}
|
|
284
|
+
if (paragraphClosingElementPattern.test(name)) for (let index = stack.length - 1; index >= 0; index--) {
|
|
285
|
+
const element = stack[index];
|
|
286
|
+
if (element.namespace === HTML ? buttonScopeElementPattern.test(element.name) : element.integration) break;
|
|
287
|
+
if (element.namespace === HTML && element.name === "p") {
|
|
288
|
+
endTags += closeDownTo(stack, index, parts);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (integrationNamePattern.test(name)) return;
|
|
293
|
+
if (name === "svg" || name === "math") {
|
|
294
|
+
if (!selfClosing) stack.push({
|
|
295
|
+
name,
|
|
296
|
+
namespace: name === "svg" ? SVG : MATHML,
|
|
297
|
+
integration: false,
|
|
298
|
+
part
|
|
299
|
+
});
|
|
300
|
+
} else if (!notOpenedElementPattern.test(name)) stack.push({
|
|
301
|
+
name,
|
|
302
|
+
namespace: HTML,
|
|
303
|
+
integration: false,
|
|
304
|
+
part
|
|
305
|
+
});
|
|
306
|
+
return endTags;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Close the element of an end tag: an SVG or MathML element with the same name above the innermost HTML
|
|
310
|
+
* element, or else an HTML element with the same name
|
|
311
|
+
*
|
|
312
|
+
* @returns The end tags to write before the end tag (of the elements in the closed element), or `undefined`
|
|
313
|
+
* when the end tag closes nothing in the translation, and is removed
|
|
314
|
+
*/
|
|
315
|
+
function closeElement(stack, parts, name) {
|
|
316
|
+
let endTags = "";
|
|
317
|
+
if (name === "p" || name === "br") endTags = closeForeign(stack, parts);
|
|
318
|
+
let index = stack.length - 1;
|
|
319
|
+
while (index >= 0 && stack[index].namespace !== HTML && stack[index].name !== name) index--;
|
|
320
|
+
if (index >= 0 && stack[index].namespace !== HTML) {} else while (index >= 0 && !(stack[index].namespace === HTML && stack[index].name === name)) index--;
|
|
321
|
+
if (index < 0) return name === "br" || name === "p" ? endTags : void 0;
|
|
322
|
+
endTags += closeDownTo(stack, index + 1, parts);
|
|
323
|
+
stack.length = index;
|
|
324
|
+
return endTags;
|
|
325
|
+
}
|
|
226
326
|
/**
|
|
227
327
|
* Read a tag with the rules of the HTML tokenizer.
|
|
228
328
|
* A start tag is written again with its attributes sanitized, and an end tag is kept as it is
|
|
@@ -230,7 +330,8 @@ var IntlifyCore = (function(exports) {
|
|
|
230
330
|
* @param html - The HTML
|
|
231
331
|
* @param start - The index of `<`
|
|
232
332
|
* @param neutralized - What has been neutralized
|
|
233
|
-
* @returns The tag, the tag name,
|
|
333
|
+
* @returns The tag, the tag name, the index after the tag (-1 when the tag is not closed),
|
|
334
|
+
* whether the start tag is self-closing (`/>`), and the attributes of the start tag,
|
|
234
335
|
* or `undefined` when `<` does not start a tag
|
|
235
336
|
*/
|
|
236
337
|
function readTag(html, start, neutralized) {
|
|
@@ -239,6 +340,7 @@ var IntlifyCore = (function(exports) {
|
|
|
239
340
|
if (!tagStart) return;
|
|
240
341
|
const [, slash, tagName] = tagStart;
|
|
241
342
|
let tag = tagStart[0];
|
|
343
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
242
344
|
let step;
|
|
243
345
|
tagStepPattern.lastIndex = tagStartPattern.lastIndex;
|
|
244
346
|
while (step = tagStepPattern.exec(html)) {
|
|
@@ -248,16 +350,25 @@ var IntlifyCore = (function(exports) {
|
|
|
248
350
|
return [
|
|
249
351
|
slash ? html.slice(start, end) : tag + raw,
|
|
250
352
|
tagName,
|
|
251
|
-
end
|
|
353
|
+
end,
|
|
354
|
+
!slash && separator.endsWith("/"),
|
|
355
|
+
attributes
|
|
252
356
|
];
|
|
253
357
|
}
|
|
254
358
|
if (quote && !closingQuote) break;
|
|
255
|
-
if (!slash)
|
|
359
|
+
if (!slash) {
|
|
360
|
+
const value = quote ? quotedValue : unquotedValue;
|
|
361
|
+
const name = asciiLowercase(attrName);
|
|
362
|
+
if (!attributes.has(name)) attributes.set(name, value || "");
|
|
363
|
+
tag += separator + serializeAttribute(attrName, value, quote, neutralized);
|
|
364
|
+
}
|
|
256
365
|
}
|
|
257
366
|
return [
|
|
258
367
|
tag,
|
|
259
368
|
tagName,
|
|
260
|
-
-1
|
|
369
|
+
-1,
|
|
370
|
+
false,
|
|
371
|
+
attributes
|
|
261
372
|
];
|
|
262
373
|
}
|
|
263
374
|
/**
|
|
@@ -281,60 +392,87 @@ var IntlifyCore = (function(exports) {
|
|
|
281
392
|
* where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
|
|
282
393
|
* What is still open at the end of the string (a tag, a comment, or an element whose content is text,
|
|
283
394
|
* like `<textarea>`) becomes text: on the server (SSR), the rest of the page follows the translation,
|
|
284
|
-
* and it would be read as a part of what is open
|
|
395
|
+
* and it would be read as a part of what is open.
|
|
396
|
+
* For the same reason, the elements are followed as the tree builder of browsers opens and closes them,
|
|
397
|
+
* including SVG and MathML: an end tag that closes no element of the translation is removed, the elements
|
|
398
|
+
* in the element that an end tag closes are closed before it, and the elements still open at the end are
|
|
399
|
+
* closed. A `<form>` that the translation does not close becomes text, because browsers ignore it in a form
|
|
400
|
+
* of the page, and `</form>` would close that form
|
|
285
401
|
*
|
|
286
402
|
* @param html - The translated HTML
|
|
287
403
|
* @returns The sanitized HTML
|
|
288
404
|
*/
|
|
289
405
|
function sanitizeTranslatedHtml(html) {
|
|
290
406
|
const neutralized = {};
|
|
291
|
-
|
|
407
|
+
const parts = [];
|
|
408
|
+
const stack = [];
|
|
292
409
|
let index = 0;
|
|
293
410
|
let lessThan;
|
|
294
411
|
while ((lessThan = html.indexOf("<", index)) !== -1) {
|
|
295
|
-
|
|
412
|
+
parts.push(html.slice(index, lessThan));
|
|
296
413
|
index = lessThan + 1;
|
|
297
414
|
const read = readTag(html, lessThan, neutralized);
|
|
298
415
|
if (read) {
|
|
299
|
-
const [tag, tagName, end] = read;
|
|
416
|
+
const [tag, tagName, end, selfClosing, attributes] = read;
|
|
300
417
|
if (end === -1) {
|
|
301
418
|
neutralized.unclosed = true;
|
|
302
|
-
|
|
419
|
+
parts.push(escapeLessThan(html.slice(lessThan)));
|
|
303
420
|
index = html.length;
|
|
304
421
|
break;
|
|
305
422
|
}
|
|
306
423
|
index = end;
|
|
307
|
-
if (tag[1] === "/")
|
|
308
|
-
|
|
424
|
+
if (tag[1] === "/") {
|
|
425
|
+
const endTags = closeElement(stack, parts, asciiLowercase(tagName));
|
|
426
|
+
if (endTags === void 0) neutralized.closed = true;
|
|
427
|
+
else {
|
|
428
|
+
if (endTags) neutralized.closed = true;
|
|
429
|
+
parts.push(endTags + tag);
|
|
430
|
+
}
|
|
431
|
+
} else if (dangerousElementPattern.test(tagName)) {
|
|
309
432
|
neutralized.element = true;
|
|
310
|
-
|
|
311
|
-
} else
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
433
|
+
parts.push(escapeLessThan(tag));
|
|
434
|
+
} else {
|
|
435
|
+
let content = "";
|
|
436
|
+
if (textContentElementPattern.test(tagName)) {
|
|
437
|
+
const contentEnd = findTextContentEnd(html, end, tagName);
|
|
438
|
+
if (contentEnd === -1) {
|
|
439
|
+
neutralized.unclosed = true;
|
|
440
|
+
parts.push(escapeLessThan(tag));
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
content = escapeLessThan(html.slice(end, contentEnd));
|
|
318
444
|
index = contentEnd;
|
|
319
445
|
}
|
|
320
|
-
|
|
446
|
+
const endTags = openElement(stack, parts, asciiLowercase(tagName), attributes, selfClosing);
|
|
447
|
+
if (endTags === void 0) {
|
|
448
|
+
neutralized.closed = true;
|
|
449
|
+
parts.push(escapeLessThan(tag) + content);
|
|
450
|
+
} else parts.push(endTags, tag + content);
|
|
451
|
+
}
|
|
321
452
|
continue;
|
|
322
453
|
}
|
|
323
454
|
commentPattern.lastIndex = lessThan;
|
|
324
455
|
if (commentPattern.test(html)) {
|
|
325
|
-
|
|
456
|
+
parts.push(html.slice(lessThan, commentPattern.lastIndex));
|
|
326
457
|
index = commentPattern.lastIndex;
|
|
327
458
|
continue;
|
|
328
459
|
}
|
|
329
460
|
if (html.startsWith("<!--", lessThan)) neutralized.unclosed = true;
|
|
330
|
-
|
|
461
|
+
parts.push("<");
|
|
462
|
+
}
|
|
463
|
+
parts.push(html.slice(index));
|
|
464
|
+
for (let open = stack.length - 1; open >= 0; open--) {
|
|
465
|
+
const element = stack[open];
|
|
466
|
+
neutralized.closed = true;
|
|
467
|
+
if (element.namespace === HTML && element.name === "form") parts[element.part] = escapeLessThan(parts[element.part]);
|
|
468
|
+
else parts.push(`</${element.name}>`);
|
|
331
469
|
}
|
|
332
|
-
result += html.slice(index);
|
|
333
470
|
if (neutralized.eventHandler) warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
|
|
334
471
|
if (neutralized.srcdoc) warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
|
|
335
472
|
if (neutralized.element) warn("Potentially dangerous element (<base>, <animate>, <set>, <script> or <plaintext>) detected in translation. Consider removing it from your translation messages.");
|
|
336
473
|
if (neutralized.unclosed) warn("Unclosed tag, comment or element (such as <textarea>) detected in translation. Consider closing it in your translation messages.");
|
|
337
|
-
|
|
474
|
+
if (neutralized.closed) warn("Unclosed or misnested elements detected in translation. Consider closing every element in the right order in your translation messages.");
|
|
475
|
+
return parts.join("");
|
|
338
476
|
}
|
|
339
477
|
// packages/shared/src/messages.ts
|
|
340
478
|
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
|
|
@@ -1898,7 +2036,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1898
2036
|
* Intlify core-base version
|
|
1899
2037
|
* @internal
|
|
1900
2038
|
*/
|
|
1901
|
-
const VERSION = "12.0.0-alpha.
|
|
2039
|
+
const VERSION = "12.0.0-alpha.13";
|
|
1902
2040
|
const NOT_RESOLVED = -1;
|
|
1903
2041
|
const DEFAULT_LOCALE = "en-US";
|
|
1904
2042
|
const MISSING_RESOLVE_VALUE = "";
|
|
@@ -2491,7 +2629,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2491
2629
|
};
|
|
2492
2630
|
const msg = !isMessageFunction(format) ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) : format;
|
|
2493
2631
|
if (occurred) return format;
|
|
2494
|
-
const msgContext = createMessageContext(getMessageContextOptions(context, targetLocale, message, options));
|
|
2632
|
+
const msgContext = createMessageContext(getMessageContextOptions(context, targetLocale, message, options, escapeParameter));
|
|
2495
2633
|
const timeline = startTimelineMeasure(context, "evaluation");
|
|
2496
2634
|
const messaged = msg(msgContext);
|
|
2497
2635
|
if (timeline) timeline.emitter.emit("message-evaluation", {
|
|
@@ -2516,6 +2654,13 @@ var IntlifyCore = (function(exports) {
|
|
|
2516
2654
|
options.named = named;
|
|
2517
2655
|
}
|
|
2518
2656
|
}
|
|
2657
|
+
function interpolateEscaped(value) {
|
|
2658
|
+
return isString(value) ? value : escapeHtml(toDisplayString(value));
|
|
2659
|
+
}
|
|
2660
|
+
function resolveProcessor(processor, escapeParameter) {
|
|
2661
|
+
if (!escapeParameter || isFunction(processor?.interpolate)) return processor ?? void 0;
|
|
2662
|
+
return assign({}, processor, { interpolate: interpolateEscaped });
|
|
2663
|
+
}
|
|
2519
2664
|
function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
|
|
2520
2665
|
const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
|
|
2521
2666
|
const locales = localeFallbacker(context, fallbackLocale, locale);
|
|
@@ -2660,7 +2805,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2660
2805
|
if (isString(source)) return source;
|
|
2661
2806
|
else if (source.loc?.source) return source.loc.source;
|
|
2662
2807
|
}
|
|
2663
|
-
function getMessageContextOptions(context, locale, message, options) {
|
|
2808
|
+
function getMessageContextOptions(context, locale, message, options, escapeParameter) {
|
|
2664
2809
|
const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
|
|
2665
2810
|
const resolveMessage = (key, useLinked) => {
|
|
2666
2811
|
let val = resolveValue(message, key);
|
|
@@ -2683,7 +2828,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2683
2828
|
modifiers,
|
|
2684
2829
|
pluralRules,
|
|
2685
2830
|
messages: resolveMessage,
|
|
2686
|
-
processor: context.processor
|
|
2831
|
+
processor: resolveProcessor(context.processor, escapeParameter),
|
|
2687
2832
|
list: options.list ?? void 0,
|
|
2688
2833
|
named: options.named ?? void 0,
|
|
2689
2834
|
pluralIndex: isNumber(options.plural) ? options.plural : void 0
|