@poe-platform/safe-js 0.1.469 → 0.1.471
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/safe-js/chunks/{chunk-J72Q6BW5.js → chunk-D26DLMQR.js} +382 -13
- package/dist/safe-js/chunks/{chunk-J72Q6BW5.js.map → chunk-D26DLMQR.js.map} +4 -4
- package/dist/safe-js/chunks/{chunk-566GCASZ.js → chunk-QMJGHTCP.js} +2 -2
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/dist/safe-js/interp/intl-duration-options.d.ts +17 -0
- package/dist/safe-js/interp/intl-durationformat.d.ts +11 -0
- package/dist/safe-js/snapshot/guest-heap.d.ts +5 -0
- package/package.json +3 -2
- /package/dist/safe-js/chunks/{chunk-566GCASZ.js.map → chunk-QMJGHTCP.js.map} +0 -0
|
@@ -19873,8 +19873,37 @@ async function compareStringLocale(value, args, budget, context) {
|
|
|
19873
19873
|
}
|
|
19874
19874
|
}
|
|
19875
19875
|
|
|
19876
|
+
// packages/safe-js/src/interp/methods/string-html.ts
|
|
19877
|
+
var stringHtmlMethods = {
|
|
19878
|
+
anchor: ["a", "name"],
|
|
19879
|
+
big: ["big", ""],
|
|
19880
|
+
blink: ["blink", ""],
|
|
19881
|
+
bold: ["b", ""],
|
|
19882
|
+
fixed: ["tt", ""],
|
|
19883
|
+
fontcolor: ["font", "color"],
|
|
19884
|
+
fontsize: ["font", "size"],
|
|
19885
|
+
italics: ["i", ""],
|
|
19886
|
+
link: ["a", "href"],
|
|
19887
|
+
small: ["small", ""],
|
|
19888
|
+
strike: ["strike", ""],
|
|
19889
|
+
sub: ["sub", ""],
|
|
19890
|
+
sup: ["sup", ""]
|
|
19891
|
+
};
|
|
19892
|
+
async function createStringHtml(value, [tag, attribute], argument, budget, context) {
|
|
19893
|
+
const release = retainValues(budget, () => [value, argument]);
|
|
19894
|
+
try {
|
|
19895
|
+
const text = attribute === "" ? "" : await sandboxString(argument, budget, context);
|
|
19896
|
+
budget.visitNode(value.length + text.length);
|
|
19897
|
+
const opening = attribute === "" ? `<${tag}>` : `<${tag} ${attribute}="${text.replaceAll('"', """)}">`;
|
|
19898
|
+
return budget.allocateString(`${opening}${value}</${tag}>`);
|
|
19899
|
+
} finally {
|
|
19900
|
+
release();
|
|
19901
|
+
}
|
|
19902
|
+
}
|
|
19903
|
+
|
|
19876
19904
|
// packages/safe-js/src/interp/methods/string.ts
|
|
19877
19905
|
var stringMethodLengths = {
|
|
19906
|
+
...Object.fromEntries(Object.entries(stringHtmlMethods).map(([name, [, attribute]]) => [name, attribute === "" ? 0 : 1])),
|
|
19878
19907
|
at: 1,
|
|
19879
19908
|
charAt: 1,
|
|
19880
19909
|
charCodeAt: 1,
|
|
@@ -20012,6 +20041,9 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
|
|
|
20012
20041
|
return dispatch();
|
|
20013
20042
|
}
|
|
20014
20043
|
function callStringMethodBody(value, methodName, args, budget, parent, context) {
|
|
20044
|
+
if (Object.hasOwn(stringHtmlMethods, methodName)) {
|
|
20045
|
+
return createStringHtml(value, stringHtmlMethods[methodName], args[0], budget, context);
|
|
20046
|
+
}
|
|
20015
20047
|
if (methodName === "concat" && args.some((argument) => argument !== null && typeof argument === "object")) {
|
|
20016
20048
|
return callConcat(value, args, budget, context);
|
|
20017
20049
|
}
|
|
@@ -28756,20 +28788,41 @@ function selectPlural2(value, inputs) {
|
|
|
28756
28788
|
return Reflect.apply(inputs.length === 1 ? select : selectRange, pluralRulesState(value).native, inputs);
|
|
28757
28789
|
}
|
|
28758
28790
|
|
|
28759
|
-
// packages/safe-js/src/interp/intl-
|
|
28791
|
+
// packages/safe-js/src/interp/intl-durationformat.ts
|
|
28760
28792
|
var states10 = /* @__PURE__ */ new WeakMap();
|
|
28793
|
+
function createSandboxDurationFormat(settings) {
|
|
28794
|
+
const value = /* @__PURE__ */ Object.create(null);
|
|
28795
|
+
const options = { locale: settings.locale, numberingSystem: settings.numberingSystem, style: settings.style };
|
|
28796
|
+
for (const [unit, { style, display }] of Object.entries(settings.units)) {
|
|
28797
|
+
options[unit] = style === "fractional" ? "numeric" : style;
|
|
28798
|
+
options[`${unit}Display`] = display;
|
|
28799
|
+
}
|
|
28800
|
+
options.fractionalDigits = settings.fractionalDigits;
|
|
28801
|
+
states10.set(value, { settings, options });
|
|
28802
|
+
return value;
|
|
28803
|
+
}
|
|
28804
|
+
function isSandboxDurationFormat(value) {
|
|
28805
|
+
return typeof value === "object" && value !== null && states10.has(value);
|
|
28806
|
+
}
|
|
28807
|
+
function durationFormatState(value) {
|
|
28808
|
+
if (!isSandboxDurationFormat(value)) throw new TypeError("Intl.DurationFormat requires a DurationFormat receiver.");
|
|
28809
|
+
return states10.get(value);
|
|
28810
|
+
}
|
|
28811
|
+
|
|
28812
|
+
// packages/safe-js/src/interp/intl-numberformat.ts
|
|
28813
|
+
var states11 = /* @__PURE__ */ new WeakMap();
|
|
28761
28814
|
function createSandboxNumberFormat(locales2, options) {
|
|
28762
28815
|
const native = createNumberFormatter(locales2, options);
|
|
28763
28816
|
const value = /* @__PURE__ */ Object.create(null);
|
|
28764
|
-
|
|
28817
|
+
states11.set(value, { native, options: numberFormatterOptions2(native) });
|
|
28765
28818
|
return value;
|
|
28766
28819
|
}
|
|
28767
28820
|
function isSandboxNumberFormat(value) {
|
|
28768
|
-
return typeof value === "object" && value !== null &&
|
|
28821
|
+
return typeof value === "object" && value !== null && states11.has(value);
|
|
28769
28822
|
}
|
|
28770
28823
|
function numberFormatState(value) {
|
|
28771
28824
|
if (!isSandboxNumberFormat(value)) throw new TypeError("Intl.NumberFormat requires a NumberFormat receiver.");
|
|
28772
|
-
return
|
|
28825
|
+
return states11.get(value);
|
|
28773
28826
|
}
|
|
28774
28827
|
async function numberFormatValue(value, budget, context) {
|
|
28775
28828
|
const primitive = typeof value === "object" && value !== null ? await objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number") : value;
|
|
@@ -28793,21 +28846,21 @@ var methods = {
|
|
|
28793
28846
|
formatRange: NativeDateTimeFormat.prototype.formatRange,
|
|
28794
28847
|
formatRangeToParts: NativeDateTimeFormat.prototype.formatRangeToParts
|
|
28795
28848
|
};
|
|
28796
|
-
var
|
|
28849
|
+
var states12 = /* @__PURE__ */ new WeakMap();
|
|
28797
28850
|
function createSandboxDateTimeFormat(locales2, options, restoring = false) {
|
|
28798
28851
|
const input = { ...options };
|
|
28799
28852
|
if (restoring) delete input.hour12;
|
|
28800
28853
|
const native = new NativeDateTimeFormat(locales2, input);
|
|
28801
28854
|
const value = /* @__PURE__ */ Object.create(null);
|
|
28802
|
-
|
|
28855
|
+
states12.set(value, { native, options: { ...Reflect.apply(resolvedOptions6, native, []) } });
|
|
28803
28856
|
return value;
|
|
28804
28857
|
}
|
|
28805
28858
|
function isSandboxDateTimeFormat(value) {
|
|
28806
|
-
return typeof value === "object" && value !== null &&
|
|
28859
|
+
return typeof value === "object" && value !== null && states12.has(value);
|
|
28807
28860
|
}
|
|
28808
28861
|
function dateTimeFormatState(value) {
|
|
28809
28862
|
if (!isSandboxDateTimeFormat(value)) throw new TypeError("Intl.DateTimeFormat requires a DateTimeFormat receiver.");
|
|
28810
|
-
return
|
|
28863
|
+
return states12.get(value);
|
|
28811
28864
|
}
|
|
28812
28865
|
function formatDateTimeValue(receiver, method, values) {
|
|
28813
28866
|
const { native } = dateTimeFormatState(receiver);
|
|
@@ -29171,6 +29224,14 @@ function captureGuestHeapNode(value, encode) {
|
|
|
29171
29224
|
const options = pluralRulesState(value).options;
|
|
29172
29225
|
return { kind: "guest-pluralrules", options: { ...options, pluralCategories: [...options.pluralCategories] }, state: captureObjectState(value, encode) };
|
|
29173
29226
|
}
|
|
29227
|
+
if (isSandboxDurationFormat(value)) {
|
|
29228
|
+
const { fractionalDigits, ...settings } = durationFormatState(value).settings;
|
|
29229
|
+
return { kind: "guest-durationformat", settings: {
|
|
29230
|
+
...settings,
|
|
29231
|
+
...fractionalDigits === void 0 ? {} : { fractionalDigits },
|
|
29232
|
+
units: Object.fromEntries(Object.entries(settings.units).map(([unit, options]) => [unit, { ...options }]))
|
|
29233
|
+
}, state: captureObjectState(value, encode) };
|
|
29234
|
+
}
|
|
29174
29235
|
if (isSandboxDateTimeFormat(value)) {
|
|
29175
29236
|
const { options, format: format4 } = dateTimeFormatState(value);
|
|
29176
29237
|
return { kind: "guest-datetimeformat", options: { ...options }, ...format4 === void 0 ? {} : { format: encode(format4) }, state: captureObjectState(value, encode) };
|
|
@@ -30140,6 +30201,27 @@ function getEnumerableDataValues(value) {
|
|
|
30140
30201
|
return getEnumerableDataEntries(value).map(([, entry]) => entry);
|
|
30141
30202
|
}
|
|
30142
30203
|
|
|
30204
|
+
// packages/safe-js/src/interp/intl-duration-locale.ts
|
|
30205
|
+
import { DurationFormat } from "@formatjs/intl-durationformat";
|
|
30206
|
+
var NativeNumberFormat4 = Intl.NumberFormat;
|
|
30207
|
+
var NativeLocale2 = Intl.Locale;
|
|
30208
|
+
var patterns = new Map(Object.entries(DurationFormat.localeData).map(([locale, data]) => {
|
|
30209
|
+
if (data === void 0) throw new TypeError(`Missing duration data for ${locale}.`);
|
|
30210
|
+
return [locale, Object.freeze({ ...data.digitalFormat })];
|
|
30211
|
+
}));
|
|
30212
|
+
function resolveDurationLocale(locales2, options) {
|
|
30213
|
+
const { locale, numberingSystem } = new NativeNumberFormat4(locales2, options).resolvedOptions();
|
|
30214
|
+
const tag = new NativeLocale2(locale);
|
|
30215
|
+
let selected = tag.baseName;
|
|
30216
|
+
if (!patterns.has(selected)) selected = tag.minimize().baseName;
|
|
30217
|
+
while (!patterns.has(selected) && selected.includes("-")) selected = selected.slice(0, selected.lastIndexOf("-"));
|
|
30218
|
+
const pattern = patterns.get(selected);
|
|
30219
|
+
if (pattern === void 0) throw new RangeError(`Missing DurationFormat locale data for ${locale}.`);
|
|
30220
|
+
const separator = pattern[numberingSystem] ?? pattern.default;
|
|
30221
|
+
if (separator === void 0) throw new TypeError("Missing duration separator.");
|
|
30222
|
+
return { locale, numberingSystem, separator };
|
|
30223
|
+
}
|
|
30224
|
+
|
|
30143
30225
|
// packages/safe-js/src/interp/globals/json-parse.ts
|
|
30144
30226
|
async function parseJsonWithReviver(text, reviver, budget, context) {
|
|
30145
30227
|
budget.visitNode(text.length);
|
|
@@ -32004,7 +32086,7 @@ function createMiscGlobals(options) {
|
|
|
32004
32086
|
}
|
|
32005
32087
|
|
|
32006
32088
|
// packages/safe-js/src/interp/globals/uri.ts
|
|
32007
|
-
var conversions = { encodeURI, encodeURIComponent, decodeURI, decodeURIComponent };
|
|
32089
|
+
var conversions = { encodeURI, encodeURIComponent, decodeURI, decodeURIComponent, escape, unescape };
|
|
32008
32090
|
function createUriGlobals(budget) {
|
|
32009
32091
|
return Object.fromEntries(Object.entries(conversions).map(([name, conversion]) => {
|
|
32010
32092
|
const closure = createSandboxClosure({
|
|
@@ -34376,6 +34458,262 @@ function createSegmenterConstructor(budget) {
|
|
|
34376
34458
|
return constructor;
|
|
34377
34459
|
}
|
|
34378
34460
|
|
|
34461
|
+
// packages/safe-js/src/interp/intl-duration-options.ts
|
|
34462
|
+
async function readDurationOptions(value, locales2, budget, context) {
|
|
34463
|
+
if (value !== void 0 && (value === null || typeof value !== "object")) throw new TypeError("DurationFormat options must be an object.");
|
|
34464
|
+
const input = intlOptionsObject(value, budget);
|
|
34465
|
+
const converted = {};
|
|
34466
|
+
const units = {};
|
|
34467
|
+
let raw;
|
|
34468
|
+
const release = retainValues(budget, () => [input, locales2, converted, units, raw]);
|
|
34469
|
+
try {
|
|
34470
|
+
for (const [key, type] of [["localeMatcher", ["lookup", "best fit"]], ["numberingSystem", "unicodeType"]]) {
|
|
34471
|
+
raw = await readIntlProperty(input, key, budget, context);
|
|
34472
|
+
if (raw !== void 0) converted[key] = await convertIntlOption(raw, key, type, budget, context);
|
|
34473
|
+
}
|
|
34474
|
+
const locale = resolveDurationLocale(locales2, { localeMatcher: converted.localeMatcher, numberingSystem: converted.numberingSystem });
|
|
34475
|
+
raw = await readIntlProperty(input, "style", budget, context);
|
|
34476
|
+
const style = raw === void 0 ? "short" : await convertIntlOption(raw, "style", ["long", "short", "narrow", "digital"], budget, context);
|
|
34477
|
+
let previous = "";
|
|
34478
|
+
for (const unit of ["years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]) {
|
|
34479
|
+
units[unit] = await readDurationUnitOptions(input, unit, style, previous, budget, context);
|
|
34480
|
+
if (["hours", "minutes", "seconds", "milliseconds", "microseconds"].includes(unit)) previous = units[unit].style;
|
|
34481
|
+
}
|
|
34482
|
+
raw = await readIntlProperty(input, "fractionalDigits", budget, context);
|
|
34483
|
+
let fractionalDigits;
|
|
34484
|
+
if (raw !== void 0) {
|
|
34485
|
+
const number = await sandboxNumber(raw, budget, context);
|
|
34486
|
+
if (Number.isNaN(number) || number < 0 || number > 9) throw new RangeError("Invalid duration fractionalDigits.");
|
|
34487
|
+
fractionalDigits = Math.floor(number);
|
|
34488
|
+
}
|
|
34489
|
+
return { ...locale, style, units, fractionalDigits };
|
|
34490
|
+
} finally {
|
|
34491
|
+
release();
|
|
34492
|
+
}
|
|
34493
|
+
}
|
|
34494
|
+
async function readDurationUnitOptions(input, unit, base, previous, budget, context) {
|
|
34495
|
+
const subsecond = ["milliseconds", "microseconds", "nanoseconds"].includes(unit);
|
|
34496
|
+
const clock = ["hours", "minutes", "seconds"].includes(unit);
|
|
34497
|
+
const styles = ["long", "short", "narrow", ...clock || subsecond ? ["numeric"] : [], ...clock ? ["2-digit"] : []];
|
|
34498
|
+
let raw;
|
|
34499
|
+
let style;
|
|
34500
|
+
const release = retainValues(budget, () => [input, raw, style]);
|
|
34501
|
+
try {
|
|
34502
|
+
raw = await readIntlProperty(input, unit, budget, context);
|
|
34503
|
+
style = raw === void 0 ? void 0 : await convertIntlOption(raw, unit, styles, budget, context);
|
|
34504
|
+
let defaultDisplay = "always";
|
|
34505
|
+
if (style === void 0) {
|
|
34506
|
+
if (base === "digital") {
|
|
34507
|
+
style = clock || subsecond ? "numeric" : "short";
|
|
34508
|
+
if (!clock) defaultDisplay = "auto";
|
|
34509
|
+
} else if (["numeric", "2-digit", "fractional"].includes(previous)) {
|
|
34510
|
+
style = "numeric";
|
|
34511
|
+
if (unit !== "minutes" && unit !== "seconds") defaultDisplay = "auto";
|
|
34512
|
+
} else {
|
|
34513
|
+
style = base;
|
|
34514
|
+
defaultDisplay = "auto";
|
|
34515
|
+
}
|
|
34516
|
+
}
|
|
34517
|
+
if (style === "numeric" && subsecond) {
|
|
34518
|
+
style = "fractional";
|
|
34519
|
+
defaultDisplay = "auto";
|
|
34520
|
+
}
|
|
34521
|
+
raw = await readIntlProperty(input, `${unit}Display`, budget, context);
|
|
34522
|
+
const display = raw === void 0 ? defaultDisplay : await convertIntlOption(raw, `${unit}Display`, ["always", "auto"], budget, context);
|
|
34523
|
+
if (display === "always" && style === "fractional" || previous === "fractional" && style !== "fractional" || ["numeric", "2-digit"].includes(previous) && !["numeric", "2-digit", "fractional"].includes(style))
|
|
34524
|
+
throw new RangeError("Incompatible duration unit style or display.");
|
|
34525
|
+
if (["minutes", "seconds"].includes(unit) && ["numeric", "2-digit"].includes(previous)) style = "2-digit";
|
|
34526
|
+
return { style, display };
|
|
34527
|
+
} finally {
|
|
34528
|
+
release();
|
|
34529
|
+
}
|
|
34530
|
+
}
|
|
34531
|
+
|
|
34532
|
+
// packages/safe-js/src/interp/intl-duration-record.ts
|
|
34533
|
+
async function readDurationRecord(input, budget, context) {
|
|
34534
|
+
if (typeof input === "string") throw new RangeError("Duration strings are not supported.");
|
|
34535
|
+
if (typeof input !== "object" || input === null) throw new TypeError("Expected a duration object.");
|
|
34536
|
+
const record4 = { years: 0, months: 0, weeks: 0, days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 0, microseconds: 0, nanoseconds: 0 };
|
|
34537
|
+
let raw;
|
|
34538
|
+
let present = false;
|
|
34539
|
+
const release = retainValues(budget, () => [input, record4, raw]);
|
|
34540
|
+
try {
|
|
34541
|
+
for (const key of ["days", "hours", "microseconds", "milliseconds", "minutes", "months", "nanoseconds", "seconds", "weeks", "years"]) {
|
|
34542
|
+
raw = await readIntlProperty(input, key, budget, context);
|
|
34543
|
+
if (raw === void 0) continue;
|
|
34544
|
+
present = true;
|
|
34545
|
+
const value = await sandboxNumber(raw, budget, context);
|
|
34546
|
+
if (!Number.isInteger(value)) throw new RangeError("Duration fields must be finite integers.");
|
|
34547
|
+
record4[key] = value === 0 ? 0 : value;
|
|
34548
|
+
}
|
|
34549
|
+
if (!present) throw new TypeError("Expected at least one duration field.");
|
|
34550
|
+
let sign = 0;
|
|
34551
|
+
for (const value of Object.values(record4)) {
|
|
34552
|
+
const current = Math.sign(value);
|
|
34553
|
+
if (current !== 0) {
|
|
34554
|
+
if (sign !== 0 && sign !== current) throw new RangeError("Duration fields must have the same sign.");
|
|
34555
|
+
sign = current;
|
|
34556
|
+
}
|
|
34557
|
+
}
|
|
34558
|
+
if ([record4.years, record4.months, record4.weeks].some((value) => Math.abs(value) >= 2 ** 32))
|
|
34559
|
+
throw new RangeError("Duration calendar fields exceed their limit.");
|
|
34560
|
+
const nanoseconds = BigInt(record4.days) * 86400000000000n + BigInt(record4.hours) * 3600000000000n + BigInt(record4.minutes) * 60000000000n + BigInt(record4.seconds) * 1000000000n + BigInt(record4.milliseconds) * 1000000n + BigInt(record4.microseconds) * 1000n + BigInt(record4.nanoseconds);
|
|
34561
|
+
const limit = 2n ** 53n * 1000000000n;
|
|
34562
|
+
if (nanoseconds <= -limit || nanoseconds >= limit) throw new RangeError("Duration time fields exceed their limit.");
|
|
34563
|
+
return record4;
|
|
34564
|
+
} finally {
|
|
34565
|
+
release();
|
|
34566
|
+
}
|
|
34567
|
+
}
|
|
34568
|
+
|
|
34569
|
+
// packages/safe-js/src/interp/intl-duration-parts.ts
|
|
34570
|
+
import { BigDecimal as BigDecimal2 } from "@formatjs/bigdecimal";
|
|
34571
|
+
var NativeListFormat2 = Intl.ListFormat;
|
|
34572
|
+
function formatDurationParts(settings, duration, separator) {
|
|
34573
|
+
const units = Object.keys(duration);
|
|
34574
|
+
const lists = [];
|
|
34575
|
+
const negative = Object.values(duration).some((value) => value < 0);
|
|
34576
|
+
let first = true;
|
|
34577
|
+
const amount = (index2) => {
|
|
34578
|
+
let value = new BigDecimal2(BigInt(duration[units[index2]]).toString());
|
|
34579
|
+
for (let next = index2 + 1; next < units.length && settings.units[units[next]].style === "fractional"; next++)
|
|
34580
|
+
value = value.plus(new BigDecimal2(BigInt(duration[units[next]]).toString()).div(new BigDecimal2(1e3).pow(next - index2)));
|
|
34581
|
+
return value;
|
|
34582
|
+
};
|
|
34583
|
+
const numberParts = (index2, value, numeric) => {
|
|
34584
|
+
const unit = units[index2];
|
|
34585
|
+
const style = settings.units[unit].style;
|
|
34586
|
+
const options = { numberingSystem: settings.numberingSystem, signDisplay: first ? "auto" : "never" };
|
|
34587
|
+
if (numeric) {
|
|
34588
|
+
options.useGrouping = false;
|
|
34589
|
+
if (style === "2-digit") options.minimumIntegerDigits = 2;
|
|
34590
|
+
} else {
|
|
34591
|
+
options.style = "unit";
|
|
34592
|
+
options.unit = unit.slice(0, -1);
|
|
34593
|
+
options.unitDisplay = style;
|
|
34594
|
+
}
|
|
34595
|
+
if (settings.units[units[index2 + 1] ?? ""]?.style === "fractional") {
|
|
34596
|
+
options.minimumFractionDigits = settings.fractionalDigits ?? 0;
|
|
34597
|
+
options.maximumFractionDigits = settings.fractionalDigits ?? 9;
|
|
34598
|
+
options.roundingMode = "trunc";
|
|
34599
|
+
}
|
|
34600
|
+
const input = first && negative && value.isZero() ? -0 : value.toString();
|
|
34601
|
+
first = false;
|
|
34602
|
+
const formatter = createPortableNumberFormatter(settings.locale, options);
|
|
34603
|
+
const parts = numberFormatterResult(formatter, "formatToParts", [input]);
|
|
34604
|
+
return parts.map((part) => ({ ...part, unit: unit.slice(0, -1) }));
|
|
34605
|
+
};
|
|
34606
|
+
for (let index2 = 0; index2 < units.length; index2++) {
|
|
34607
|
+
const unit = units[index2];
|
|
34608
|
+
const option = settings.units[unit];
|
|
34609
|
+
if (option.style === "fractional") break;
|
|
34610
|
+
if (["numeric", "2-digit"].includes(option.style)) {
|
|
34611
|
+
const hours = index2 <= 4 && (duration.hours !== 0 || settings.units.hours.display === "always");
|
|
34612
|
+
const secondsValue = amount(6);
|
|
34613
|
+
const seconds = !secondsValue.isZero() || settings.units.seconds.display === "always";
|
|
34614
|
+
const minutes = index2 <= 5 && (duration.minutes !== 0 || settings.units.minutes.display === "always" || hours && seconds);
|
|
34615
|
+
const parts = [];
|
|
34616
|
+
for (const [clockIndex, displayed] of [[4, hours], [5, minutes], [6, seconds]]) {
|
|
34617
|
+
if (!displayed) continue;
|
|
34618
|
+
if (parts.length) parts.push({ type: "literal", value: separator });
|
|
34619
|
+
parts.push(...numberParts(clockIndex, clockIndex === 6 ? secondsValue : amount(clockIndex), true));
|
|
34620
|
+
}
|
|
34621
|
+
if (parts.length) lists.push(parts);
|
|
34622
|
+
break;
|
|
34623
|
+
}
|
|
34624
|
+
const value = amount(index2);
|
|
34625
|
+
if (!value.isZero() || option.display === "always") lists.push(numberParts(index2, value, false));
|
|
34626
|
+
if (settings.units[units[index2 + 1] ?? ""]?.style === "fractional") break;
|
|
34627
|
+
}
|
|
34628
|
+
const list2 = new NativeListFormat2(settings.locale, { type: "unit", style: settings.style === "digital" ? "short" : settings.style });
|
|
34629
|
+
let index = 0;
|
|
34630
|
+
return list2.formatToParts(lists.map((parts) => parts.map((part) => part.value).join(""))).flatMap((part) => part.type === "element" ? lists[index++] : [{ type: "literal", value: part.value }]);
|
|
34631
|
+
}
|
|
34632
|
+
|
|
34633
|
+
// packages/safe-js/src/interp/globals/intl-durationformat.ts
|
|
34634
|
+
var supportedLocalesOf10 = Intl.NumberFormat.supportedLocalesOf;
|
|
34635
|
+
function createDurationFormatConstructor(budget) {
|
|
34636
|
+
const prototype = createIntrinsicObject();
|
|
34637
|
+
const constructor = createSandboxClosure({
|
|
34638
|
+
guest: true,
|
|
34639
|
+
sandbox: true,
|
|
34640
|
+
name: "DurationFormat",
|
|
34641
|
+
length: 0,
|
|
34642
|
+
call: () => {
|
|
34643
|
+
throw new TypeError("Constructor DurationFormat requires 'new'.");
|
|
34644
|
+
},
|
|
34645
|
+
construct: async ([input, options], context) => {
|
|
34646
|
+
const target = context?.newTarget;
|
|
34647
|
+
const selected = target === void 0 || target === constructor ? prototype : context?.getProperty !== void 0 ? await context.getProperty(target, "prototype") : await readPropertyDescriptor(getSandboxPropertyDescriptor(target, "prototype", budget) ?? { value: void 0 }, target, context);
|
|
34648
|
+
let locales2 = [];
|
|
34649
|
+
let settings;
|
|
34650
|
+
const release = retainValues(budget, () => [selected, locales2, settings]);
|
|
34651
|
+
try {
|
|
34652
|
+
locales2 = await canonicalizeGuestLocales(input, budget, context);
|
|
34653
|
+
settings = await readDurationOptions(options, locales2, budget, context);
|
|
34654
|
+
const value = createSandboxDurationFormat(settings);
|
|
34655
|
+
setSandboxPrototype(value, typeof selected === "object" && selected !== null ? selected : prototype, budget);
|
|
34656
|
+
return allocateProducedSandboxValue(value, budget);
|
|
34657
|
+
} finally {
|
|
34658
|
+
release();
|
|
34659
|
+
}
|
|
34660
|
+
}
|
|
34661
|
+
});
|
|
34662
|
+
const properties = materializeFunctionProperties(constructor);
|
|
34663
|
+
Object.defineProperty(properties, "prototype", { value: prototype, writable: false, configurable: false });
|
|
34664
|
+
Object.defineProperty(properties, "supportedLocalesOf", { value: createSandboxClosure({
|
|
34665
|
+
guest: true,
|
|
34666
|
+
sandbox: true,
|
|
34667
|
+
name: "supportedLocalesOf",
|
|
34668
|
+
length: 1,
|
|
34669
|
+
call: async ([input, options], context) => {
|
|
34670
|
+
const locales2 = await canonicalizeGuestLocales(input, budget, context);
|
|
34671
|
+
const release = retainValues(budget, () => [locales2]);
|
|
34672
|
+
try {
|
|
34673
|
+
const source = intlOptionsObject(options, budget);
|
|
34674
|
+
const raw = await readIntlProperty(source, "localeMatcher", budget, context);
|
|
34675
|
+
const matcher = raw === void 0 ? void 0 : await convertIntlOption(raw, "localeMatcher", ["lookup", "best fit"], budget, context);
|
|
34676
|
+
return allocateProducedSandboxValue(supportedLocalesOf10(locales2, { localeMatcher: matcher }), budget);
|
|
34677
|
+
} finally {
|
|
34678
|
+
release();
|
|
34679
|
+
}
|
|
34680
|
+
}
|
|
34681
|
+
}), writable: true, configurable: true });
|
|
34682
|
+
Object.defineProperties(prototype, {
|
|
34683
|
+
constructor: { value: constructor, writable: true, configurable: true },
|
|
34684
|
+
[Symbol.toStringTag]: { value: "Intl.DurationFormat", configurable: true },
|
|
34685
|
+
resolvedOptions: { value: createSandboxClosure({
|
|
34686
|
+
guest: true,
|
|
34687
|
+
sandbox: true,
|
|
34688
|
+
name: "resolvedOptions",
|
|
34689
|
+
length: 0,
|
|
34690
|
+
call: (_args, context) => allocateProducedSandboxValue({ ...durationFormatState(context?.thisValue).options }, budget)
|
|
34691
|
+
}), writable: true, configurable: true }
|
|
34692
|
+
});
|
|
34693
|
+
for (const method of ["format", "formatToParts"]) {
|
|
34694
|
+
Object.defineProperty(prototype, method, { value: createSandboxClosure({
|
|
34695
|
+
guest: true,
|
|
34696
|
+
sandbox: true,
|
|
34697
|
+
name: method,
|
|
34698
|
+
length: 1,
|
|
34699
|
+
call: async ([input], context) => {
|
|
34700
|
+
const receiver = context?.thisValue;
|
|
34701
|
+
const { settings } = durationFormatState(receiver);
|
|
34702
|
+
const release = retainValues(budget, () => [receiver, input]);
|
|
34703
|
+
try {
|
|
34704
|
+
const record4 = await readDurationRecord(input, budget, context);
|
|
34705
|
+
budget.visitNode(100);
|
|
34706
|
+
const parts = formatDurationParts(settings, record4, settings.separator);
|
|
34707
|
+
return allocateProducedSandboxValue(method === "format" ? parts.map((part) => part.value).join("") : parts, budget);
|
|
34708
|
+
} finally {
|
|
34709
|
+
release();
|
|
34710
|
+
}
|
|
34711
|
+
}
|
|
34712
|
+
}), writable: true, configurable: true });
|
|
34713
|
+
}
|
|
34714
|
+
return constructor;
|
|
34715
|
+
}
|
|
34716
|
+
|
|
34379
34717
|
// packages/safe-js/src/interp/globals/intl.ts
|
|
34380
34718
|
var supportedValuesOf = Intl.supportedValuesOf;
|
|
34381
34719
|
function createIntlGlobal(budget, now) {
|
|
@@ -34398,6 +34736,7 @@ function createIntlGlobal(budget, now) {
|
|
|
34398
34736
|
const dateTimeFormat = createDateTimeFormatConstructor(budget, now);
|
|
34399
34737
|
const pluralRules = createPluralRulesConstructor(budget);
|
|
34400
34738
|
const segmenter = createSegmenterConstructor(budget);
|
|
34739
|
+
const durationFormat = createDurationFormatConstructor(budget);
|
|
34401
34740
|
Object.defineProperty(intl, "Locale", { value: locale, writable: true, configurable: true });
|
|
34402
34741
|
Object.defineProperty(intl, "Collator", { value: collator, writable: true, configurable: true });
|
|
34403
34742
|
Object.defineProperty(intl, "NumberFormat", { value: numberFormat, writable: true, configurable: true });
|
|
@@ -34407,13 +34746,14 @@ function createIntlGlobal(budget, now) {
|
|
|
34407
34746
|
Object.defineProperty(intl, "DateTimeFormat", { value: dateTimeFormat, writable: true, configurable: true });
|
|
34408
34747
|
Object.defineProperty(intl, "PluralRules", { value: pluralRules, writable: true, configurable: true });
|
|
34409
34748
|
Object.defineProperty(intl, "Segmenter", { value: segmenter, writable: true, configurable: true });
|
|
34749
|
+
Object.defineProperty(intl, "DurationFormat", { value: durationFormat, writable: true, configurable: true });
|
|
34410
34750
|
for (const [name, call] of Object.entries(methods3)) {
|
|
34411
34751
|
const closure = createSandboxClosure({ guest: true, sandbox: true, name, length: 1, call });
|
|
34412
34752
|
Object.defineProperty(intl, name, { value: closure, writable: true, configurable: true });
|
|
34413
34753
|
}
|
|
34414
34754
|
Object.defineProperty(intl, Symbol.toStringTag, { value: "Intl", configurable: true });
|
|
34415
34755
|
registerBuiltinIdentities(budget, { Intl: intl });
|
|
34416
|
-
for (const constructor of [locale, collator, numberFormat, listFormat, relativeTimeFormat, displayNames, dateTimeFormat, pluralRules, segmenter]) {
|
|
34756
|
+
for (const constructor of [locale, collator, numberFormat, listFormat, relativeTimeFormat, displayNames, dateTimeFormat, pluralRules, segmenter, durationFormat]) {
|
|
34417
34757
|
const prototype = constructor.properties.prototype;
|
|
34418
34758
|
for (const owner of [prototype, constructor.properties])
|
|
34419
34759
|
for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(owner)))
|
|
@@ -34531,7 +34871,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
34531
34871
|
createRawJson(node.text);
|
|
34532
34872
|
return true;
|
|
34533
34873
|
}
|
|
34534
|
-
if (!["guest-segmenter", "guest-segments", "module-function", "async-generator-driver", "async-generator-handler", "async-function-driver", "async-function-handler", "thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-locale", "guest-listformat", "guest-pluralrules", "guest-displaynames", "guest-relativetimeformat", "guest-datetimeformat", "guest-numberformat", "guest-collator", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
34874
|
+
if (!["guest-durationformat", "guest-segmenter", "guest-segments", "module-function", "async-generator-driver", "async-generator-handler", "async-function-driver", "async-function-handler", "thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-locale", "guest-listformat", "guest-pluralrules", "guest-displaynames", "guest-relativetimeformat", "guest-datetimeformat", "guest-numberformat", "guest-collator", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
34535
34875
|
const reference = (value, kinds) => {
|
|
34536
34876
|
const ref = record2(value);
|
|
34537
34877
|
fields(ref, ["kind", "id"]);
|
|
@@ -34861,6 +35201,30 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
34861
35201
|
throw new TypeError("Invalid segment iterator boundary.");
|
|
34862
35202
|
}
|
|
34863
35203
|
state(node.state);
|
|
35204
|
+
} else if (node.kind === "guest-durationformat") {
|
|
35205
|
+
fields(node, ["kind", "settings", "state"]);
|
|
35206
|
+
const settings = record2(node.settings);
|
|
35207
|
+
fields(settings, ["locale", "numberingSystem", "separator", "style", "units"], ["fractionalDigits"]);
|
|
35208
|
+
if (typeof settings.locale !== "string" || typeof settings.numberingSystem !== "string" || !["long", "short", "narrow", "digital"].includes(settings.style) || settings.fractionalDigits !== void 0 && (!Number.isInteger(settings.fractionalDigits) || settings.fractionalDigits < 0 || settings.fractionalDigits > 9))
|
|
35209
|
+
throw new TypeError("Invalid duration settings.");
|
|
35210
|
+
const locale = resolveDurationLocale([settings.locale], { numberingSystem: settings.numberingSystem });
|
|
35211
|
+
if (locale.locale !== settings.locale || locale.numberingSystem !== settings.numberingSystem || locale.separator !== settings.separator)
|
|
35212
|
+
throw new TypeError("Invalid resolved duration locale.");
|
|
35213
|
+
const units = record2(settings.units);
|
|
35214
|
+
const names = ["years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"];
|
|
35215
|
+
fields(units, names);
|
|
35216
|
+
let previous = "";
|
|
35217
|
+
for (const name of names) {
|
|
35218
|
+
const unit = record2(units[name]);
|
|
35219
|
+
fields(unit, ["style", "display"]);
|
|
35220
|
+
const clock = ["hours", "minutes", "seconds"].includes(name);
|
|
35221
|
+
const subsecond = ["milliseconds", "microseconds", "nanoseconds"].includes(name);
|
|
35222
|
+
const allowed = ["long", "short", "narrow", ...clock ? ["numeric", "2-digit"] : [], ...subsecond ? ["fractional"] : []];
|
|
35223
|
+
if (typeof unit.style !== "string" || !allowed.includes(unit.style) || !["always", "auto"].includes(unit.display) || unit.style === "fractional" && unit.display !== "auto" || previous === "fractional" && unit.style !== "fractional" || ["numeric", "2-digit"].includes(previous) && !["numeric", "2-digit", "fractional"].includes(unit.style) || ["minutes", "seconds"].includes(name) && ["numeric", "2-digit"].includes(previous) && unit.style !== "2-digit")
|
|
35224
|
+
throw new TypeError("Invalid duration unit options.");
|
|
35225
|
+
if (clock || name === "milliseconds" || name === "microseconds") previous = unit.style;
|
|
35226
|
+
}
|
|
35227
|
+
state(node.state);
|
|
34864
35228
|
} else if (node.kind === "guest-pluralrules") {
|
|
34865
35229
|
fields(node, ["kind", "options", "state"]);
|
|
34866
35230
|
const options = record2(node.options);
|
|
@@ -38446,7 +38810,7 @@ var structuredCloneErrorNames = ["Error", "EvalError", "RangeError", "ReferenceE
|
|
|
38446
38810
|
function* cloneStructuredGraph(value, state, budget, depth = 0) {
|
|
38447
38811
|
assertSandboxDataDepth(depth);
|
|
38448
38812
|
budget.visitNode();
|
|
38449
|
-
if (typeof value === "symbol" || isSandboxModuleNamespace(value) || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxStringIterator(value) || isSandboxArguments(value) || isSandboxSegmenter(value) || isSandboxSegments(value) || isSandboxLocale(value) || isSandboxCollator(value) || isSandboxDateTimeFormat(value) || isSandboxDisplayNames(value) || isSandboxListFormat(value) || isSandboxNumberFormat(value) || isSandboxPluralRules(value) || isSandboxRelativeTimeFormat(value))
|
|
38813
|
+
if (typeof value === "symbol" || isSandboxModuleNamespace(value) || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxStringIterator(value) || isSandboxArguments(value) || isSandboxSegmenter(value) || isSandboxSegments(value) || isSandboxLocale(value) || isSandboxCollator(value) || isSandboxDateTimeFormat(value) || isSandboxDisplayNames(value) || isSandboxDurationFormat(value) || isSandboxListFormat(value) || isSandboxNumberFormat(value) || isSandboxPluralRules(value) || isSandboxRelativeTimeFormat(value))
|
|
38450
38814
|
throw new DOMException("Value cannot be structured cloned.", "DataCloneError");
|
|
38451
38815
|
if (typeof value !== "object" || value === null) return allocateProducedSandboxValue(value, budget);
|
|
38452
38816
|
if (iteratorHelperStates.has(value) || iteratorWrapperStates.has(value))
|
|
@@ -38654,6 +39018,11 @@ function measureSandboxData(values, options = {}) {
|
|
|
38654
39018
|
if (isSandboxRelativeTimeFormat(value)) visit(relativeTimeFormatState(value).options, depth + 1);
|
|
38655
39019
|
if (isSandboxDisplayNames(value)) visit(displayNamesState(value).options, depth + 1);
|
|
38656
39020
|
if (isSandboxPluralRules(value)) visit(pluralRulesState(value).options, depth + 1);
|
|
39021
|
+
if (isSandboxDurationFormat(value)) {
|
|
39022
|
+
const state = durationFormatState(value);
|
|
39023
|
+
visit(state.settings, depth + 1);
|
|
39024
|
+
visit(state.options, depth + 1);
|
|
39025
|
+
}
|
|
38657
39026
|
if (isSandboxNumberFormat(value)) {
|
|
38658
39027
|
const state = numberFormatState(value);
|
|
38659
39028
|
visit(state.options, depth + 1);
|
|
@@ -56706,4 +57075,4 @@ authorization of the copyright holder.
|
|
|
56706
57075
|
SPDX-License-Identifier: Unicode-3.0
|
|
56707
57076
|
|
|
56708
57077
|
*/
|
|
56709
|
-
//# sourceMappingURL=chunk-
|
|
57078
|
+
//# sourceMappingURL=chunk-D26DLMQR.js.map
|