@zeyos/zx 5.6.0 → 5.7.1
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/CHANGELOG.md +188 -0
- package/README.md +73 -7
- package/bin/zx-css.js +328 -0
- package/dist/types/components/account-menu/account-menu.d.ts +4 -2
- package/dist/types/components/activity-list/activity-list.d.ts +14 -8
- package/dist/types/components/agent-thread/ag-ui.d.ts +340 -0
- package/dist/types/components/agent-thread/agent-thread.d.ts +142 -14
- package/dist/types/components/agent-thread/ui-message-stream.d.ts +401 -0
- package/dist/types/components/app-sidebar/app-sidebar.d.ts +14 -8
- package/dist/types/components/breadcrumb/breadcrumb.d.ts +3 -3
- package/dist/types/components/calendar/calendar-model.d.ts +9 -2
- package/dist/types/components/calendar/calendar.d.ts +12 -4
- package/dist/types/components/chart/chart.d.ts +25 -13
- package/dist/types/components/checklist/checklist.d.ts +29 -0
- package/dist/types/components/code-editor/code-editor.d.ts +7 -2
- package/dist/types/components/composer/composer.d.ts +206 -4
- package/dist/types/components/composer/queue.d.ts +76 -0
- package/dist/types/components/copy/copy-button.d.ts +6 -4
- package/dist/types/components/copy/copy-input.d.ts +10 -6
- package/dist/types/components/datebox/date-range-box.d.ts +33 -0
- package/dist/types/components/datebox/placeholder.d.ts +7 -0
- package/dist/types/components/dialog/dialog.d.ts +2 -2
- package/dist/types/components/dock/dock.d.ts +12 -3
- package/dist/types/components/entity-ref/entity-ref.d.ts +5 -3
- package/dist/types/components/field-upload/field-upload.d.ts +3 -2
- package/dist/types/components/file-item/file-item.d.ts +3 -2
- package/dist/types/components/file-list/file-list.d.ts +14 -8
- package/dist/types/components/filter/filter-model.d.ts +31 -1
- package/dist/types/components/filter/filter.d.ts +20 -2
- package/dist/types/components/finder/finder.d.ts +14 -6
- package/dist/types/components/flag/flag.d.ts +99 -0
- package/dist/types/components/grid/grid.d.ts +1 -1
- package/dist/types/components/kanban-view/kanban-view.d.ts +8 -66
- package/dist/types/components/launcher/launcher.d.ts +2 -0
- package/dist/types/components/modal/modal.d.ts +34 -8
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +3 -2
- package/dist/types/components/number-field/number-field.d.ts +41 -7
- package/dist/types/components/prompt-starters/prompt-starters.d.ts +107 -0
- package/dist/types/components/prose/prose.d.ts +9 -6
- package/dist/types/components/questionnaire/conditions.d.ts +270 -0
- package/dist/types/components/questionnaire/items.d.ts +52 -30
- package/dist/types/components/questionnaire/questionnaire.d.ts +44 -4
- package/dist/types/components/rating/rating.d.ts +5 -3
- package/dist/types/components/select/country.d.ts +106 -0
- package/dist/types/components/select/field-adapter.d.ts +2 -1
- package/dist/types/components/select/locale.d.ts +102 -0
- package/dist/types/components/select/select.d.ts +41 -2
- package/dist/types/components/sheet/sheet.d.ts +2 -2
- package/dist/types/components/slider/slider.d.ts +1 -0
- package/dist/types/components/sort-control/sort-control.d.ts +7 -3
- package/dist/types/components/source-list/source-list.d.ts +7 -5
- package/dist/types/components/split-view/split-view.d.ts +5 -3
- package/dist/types/components/surface/catalog.d.ts +260 -0
- package/dist/types/components/surface/elicit.d.ts +81 -0
- package/dist/types/components/surface/mcp.d.ts +165 -0
- package/dist/types/components/surface/schema.d.ts +314 -0
- package/dist/types/components/surface/stream.d.ts +118 -0
- package/dist/types/components/surface/surface.d.ts +718 -0
- package/dist/types/components/surface/text.d.ts +277 -0
- package/dist/types/components/surface/validate.d.ts +339 -0
- package/dist/types/components/table/table.d.ts +55 -3
- package/dist/types/components/table/window.d.ts +203 -0
- package/dist/types/components/toolbar/toolbar.d.ts +10 -6
- package/dist/types/components/tooltip/tooltip.d.ts +2 -2
- package/dist/types/components/tree/tree.d.ts +20 -13
- package/dist/types/core/component.d.ts +10 -0
- package/dist/types/core/date.d.ts +8 -1
- package/dist/types/core/dom.d.ts +15 -0
- package/dist/types/core/http.d.ts +10 -0
- package/dist/types/core/i18n.d.ts +38 -0
- package/dist/types/core/messages.d.ts +344 -1
- package/dist/types/core/storage.d.ts +7 -2
- package/dist/types/elements/define.d.ts +21 -46
- package/dist/types/elements/definitions.d.ts +147 -0
- package/dist/types/elements/kit.d.ts +7 -0
- package/dist/types/elements/reflect.d.ts +6 -3
- package/dist/types/index.d.ts +10 -1
- package/dist/types/internal/date-locale.d.ts +7 -0
- package/dist/types/internal/json-patch.d.ts +146 -0
- package/dist/types/locales/de.d.ts +13 -0
- package/dist/types/locales/en.d.ts +2 -0
- package/dist/types/locales/index.d.ts +823 -0
- package/dist/types/zeyos/view.d.ts +8 -1
- package/dist/zx-zeyos.esm.js +16852 -15131
- package/dist/zx-zeyos.esm.min.js +5 -5
- package/dist/zx.core.css +1276 -0
- package/dist/zx.core.min.css +1 -0
- package/dist/zx.css +520 -143
- package/dist/zx.esm.js +40940 -29684
- package/dist/zx.esm.min.js +36 -23
- package/dist/zx.global.js +40940 -29684
- package/dist/zx.global.min.js +36 -23
- package/dist/zx.layered.css +17315 -0
- package/dist/zx.layered.min.css +1 -0
- package/dist/zx.min.css +1 -1
- package/docs/agent-catalog.json +12501 -0
- package/docs/agent-surfaces.md +340 -0
- package/docs/api.json +909 -137
- package/docs/llms.md +1046 -80
- package/docs/llms.txt +30 -9
- package/package.json +29 -6
- package/src/components/account-menu/account-menu.js +6 -3
- package/src/components/activity-item/activity-item.js +2 -1
- package/src/components/activity-list/activity-list.js +16 -10
- package/src/components/agent-thread/ag-ui.js +1439 -0
- package/src/components/agent-thread/agent-thread.js +359 -54
- package/src/components/agent-thread/ui-message-stream.js +1281 -0
- package/src/components/app-sidebar/app-sidebar.js +18 -8
- package/src/components/approval-card/approval-card.js +3 -2
- package/src/components/block-view/block-view.js +7 -6
- package/src/components/breadcrumb/breadcrumb.js +8 -5
- package/src/components/button/button.css +24 -11
- package/src/components/calendar/calendar-model.js +8 -2
- package/src/components/calendar/calendar.js +53 -18
- package/src/components/chart/chart.js +54 -23
- package/src/components/checklist/checklist.css +9 -1
- package/src/components/checklist/checklist.js +59 -3
- package/src/components/checklist/field-adapter.js +2 -11
- package/src/components/code-editor/code-editor.js +45 -8
- package/src/components/code-editor/field-adapter.js +1 -1
- package/src/components/composer/composer.css +80 -1
- package/src/components/composer/composer.js +390 -16
- package/src/components/composer/queue.js +78 -0
- package/src/components/context-menu/context-menu.js +12 -1
- package/src/components/copy/copy-button.js +9 -7
- package/src/components/copy/copy-input.js +10 -6
- package/src/components/date-picker/date-picker.js +2 -1
- package/src/components/date-picker/date-range-picker.js +8 -7
- package/src/components/datebox/date-range-box.js +3 -9
- package/src/components/datebox/datebox.js +18 -21
- package/src/components/datebox/placeholder.js +18 -0
- package/src/components/dialog/dialog.js +4 -5
- package/src/components/dock/dock.js +34 -13
- package/src/components/entity-ref/entity-ref.js +16 -5
- package/src/components/field-upload/field-upload.js +81 -38
- package/src/components/file-item/file-item.js +70 -40
- package/src/components/file-list/file-list.js +15 -9
- package/src/components/filter/filter-model.js +46 -8
- package/src/components/filter/filter.css +3 -3
- package/src/components/filter/filter.js +29 -10
- package/src/components/filter-panel/filter-panel.js +13 -5
- package/src/components/finder/finder.js +50 -26
- package/src/components/flag/flag.css +40 -0
- package/src/components/flag/flag.js +177 -0
- package/src/components/form/form.js +1 -1
- package/src/components/grid/grid.js +22 -8
- package/src/components/kanban-view/kanban-view.js +51 -81
- package/src/components/launcher/launcher.js +17 -2
- package/src/components/list-toolbar/list-toolbar.js +2 -1
- package/src/components/master-panel/master-panel.js +1 -1
- package/src/components/menu-button/menu-button.js +4 -0
- package/src/components/message/message.js +3 -0
- package/src/components/modal/modal.js +62 -8
- package/src/components/multi-value-editor/multi-value-editor.js +10 -9
- package/src/components/navigation-bar/navigation-bar.js +3 -3
- package/src/components/number-field/number-field.js +98 -29
- package/src/components/prompt-starters/prompt-starters.css +91 -0
- package/src/components/prompt-starters/prompt-starters.js +206 -0
- package/src/components/prose/prose.js +14 -10
- package/src/components/questionnaire/conditions.js +666 -0
- package/src/components/questionnaire/items.js +150 -41
- package/src/components/questionnaire/questionnaire.js +126 -32
- package/src/components/rating/rating.js +5 -4
- package/src/components/run-status/run-status.js +2 -2
- package/src/components/select/country.js +136 -0
- package/src/components/select/field-adapter.js +7 -2
- package/src/components/select/locale.js +219 -0
- package/src/components/select/select.css +20 -22
- package/src/components/select/select.js +94 -12
- package/src/components/sheet/sheet-stack.js +10 -1
- package/src/components/sheet/sheet.js +12 -5
- package/src/components/slider/slider.js +7 -2
- package/src/components/sort-control/sort-control.js +15 -5
- package/src/components/source-list/source-list.js +7 -4
- package/src/components/split-view/split-view.js +5 -3
- package/src/components/surface/catalog.js +1334 -0
- package/src/components/surface/elicit.js +107 -0
- package/src/components/surface/mcp.js +243 -0
- package/src/components/surface/schema.js +644 -0
- package/src/components/surface/stream.js +245 -0
- package/src/components/surface/surface.css +308 -0
- package/src/components/surface/surface.js +2291 -0
- package/src/components/surface/text.js +513 -0
- package/src/components/surface/validate.js +2218 -0
- package/src/components/tabbox/tabbox.js +9 -0
- package/src/components/table/table.css +63 -3
- package/src/components/table/table.js +167 -28
- package/src/components/table/window.js +317 -0
- package/src/components/toolbar/toolbar.js +12 -7
- package/src/components/tooltip/tooltip.css +2 -3
- package/src/components/tooltip/tooltip.js +32 -5
- package/src/components/tree/tree.js +53 -23
- package/src/core/component.js +25 -1
- package/src/core/date.js +62 -16
- package/src/core/dom.js +67 -4
- package/src/core/format.js +15 -13
- package/src/core/http.js +29 -20
- package/src/core/i18n.js +83 -10
- package/src/core/icons.js +13 -2
- package/src/core/keyboard.js +79 -8
- package/src/core/messages.js +376 -2
- package/src/core/overlay-host.js +1 -0
- package/src/core/position.js +3 -2
- package/src/core/storage.js +59 -6
- package/src/elements/define.js +178 -130
- package/src/elements/definitions.js +229 -0
- package/src/elements/kit.js +444 -0
- package/src/elements/reflect.js +8 -3
- package/src/index.js +10 -1
- package/src/internal/date-locale.js +11 -0
- package/src/internal/json-patch.js +405 -0
- package/src/locales/de.js +911 -0
- package/src/locales/en.js +2 -0
- package/src/locales/index.js +7 -0
- package/src/zeyos/calendar.js +2 -1
- package/src/zeyos/form.js +2 -1
- package/src/zeyos/launcher.js +7 -6
- package/src/zeyos/module-bar.js +2 -1
- package/src/zeyos/schema.js +37 -23
- package/src/zeyos/select.js +4 -3
- package/src/zeyos/table.js +2 -13
- package/src/zeyos/view.js +57 -17
- package/styles/core.css +11 -0
- package/styles/tokens/semantic.css +1 -0
- package/styles/zeyos.css +2 -0
- package/styles/zx.css +4 -8
- package/styles/zx.layered.css +1 -0
package/src/core/component.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { h, resolveElement } from './dom.js';
|
|
3
|
-
import { defaultMessage, getLanguage, hostMessage, legacyMessageKey, printf } from './i18n.js';
|
|
3
|
+
import { defaultMessage, getLanguage, hostMessage, legacyMessageKey, pluralKeys, pluralMessage, printf } from './i18n.js';
|
|
4
4
|
import { deepMerge, isElement } from './util.js';
|
|
5
5
|
|
|
6
6
|
/** @typedef {Record<string, any>} ComponentOptions */
|
|
@@ -249,6 +249,30 @@ export class Component extends EventTarget {
|
|
|
249
249
|
return printf(text, args);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Resolves a cardinal plural message, keeping the numeric count separate from displayed values.
|
|
254
|
+
* Each source tries the selected category, `other`, and the unsuffixed/legacy key before moving
|
|
255
|
+
* from instance messages to the host, class defaults, and finally English plural rules.
|
|
256
|
+
* @param {string} key Unsuffixed message key.
|
|
257
|
+
* @param {number} count Finite numeric count.
|
|
258
|
+
* @param {...unknown} args Positional interpolation values.
|
|
259
|
+
* @returns {string}
|
|
260
|
+
*/
|
|
261
|
+
msgPlural(key, count, ...args) {
|
|
262
|
+
const lang = this.options?.lang ?? this.options?.language ?? getLanguage();
|
|
263
|
+
const keys = pluralKeys(key, count, lang);
|
|
264
|
+
const tables = messageTables.get(this) ?? {
|
|
265
|
+
own: isMessageTable(this.options?.msg) ? this.options.msg : null,
|
|
266
|
+
inherited: null
|
|
267
|
+
};
|
|
268
|
+
const text = pluralMessage(keys, (candidate) => pickMessage(tables.own, lang, candidate))
|
|
269
|
+
?? pluralMessage(keys, hostMessage)
|
|
270
|
+
?? pluralMessage(keys, (candidate) => pickMessage(tables.inherited, lang, candidate))
|
|
271
|
+
?? pluralMessage(pluralKeys(key, count, 'en'), defaultMessage)
|
|
272
|
+
?? key;
|
|
273
|
+
return printf(text, args);
|
|
274
|
+
}
|
|
275
|
+
|
|
252
276
|
/**
|
|
253
277
|
* Aborts listeners, unregisters the component, and removes roots created by the component.
|
|
254
278
|
* Safe to call repeatedly.
|
package/src/core/date.js
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import { getLanguage,
|
|
2
|
+
import { formattingLocale, getLanguage, hostMessage } from './i18n.js';
|
|
3
3
|
|
|
4
4
|
const MONTHS = [
|
|
5
5
|
'January', 'February', 'March', 'April', 'May', 'June',
|
|
6
6
|
'July', 'August', 'September', 'October', 'November', 'December'
|
|
7
7
|
];
|
|
8
8
|
const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
9
|
+
const ENGLISH_NAMES = { month: MONTHS, weekday: WEEKDAYS };
|
|
9
10
|
const TOKEN_PATTERN = /%[demYyHMSaAbBs]/g;
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* `Intl` formatters for month and weekday names, under their locale and style, because a calendar
|
|
14
|
+
* formats dozens of cells per render. A locale `Intl` cannot use is cached as null: one it refuses,
|
|
15
|
+
* and one it has no data for, which it would otherwise answer in the runtime's own language.
|
|
16
|
+
* @type {Map<string, Intl.DateTimeFormat|null>}
|
|
17
|
+
*/
|
|
18
|
+
const nameFormatters = new Map();
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* Formats a local Date using strftime-style kernel tokens.
|
|
22
|
+
*
|
|
23
|
+
* Month and weekday names come from the host translator's `date.month.*` and `date.weekday.*` keys
|
|
24
|
+
* when no explicit locale is given, and otherwise from `Intl` in the effective formatting locale.
|
|
25
|
+
* Explicit supported locales take precedence over host translations.
|
|
13
26
|
* @param {Date} date Date to format.
|
|
14
27
|
* @param {string} fmt Format containing `%d %e %m %Y %y %H %M %S %a %A %b %B %s` tokens.
|
|
28
|
+
* @param {{locale?: string|null}|null} [options] `locale` defaults to `getLanguage()`.
|
|
15
29
|
* @returns {string}
|
|
16
30
|
*/
|
|
17
|
-
export function formatDate(date, fmt) {
|
|
31
|
+
export function formatDate(date, fmt, options) {
|
|
32
|
+
const locale = formattingLocale(options?.locale, Intl.DateTimeFormat);
|
|
33
|
+
const useHost = options?.locale == null;
|
|
18
34
|
if (!(date instanceof Date) || Number.isNaN(date.getTime())) return '';
|
|
19
35
|
return String(fmt).replace(TOKEN_PATTERN, (token) => {
|
|
20
36
|
switch (token) {
|
|
@@ -26,10 +42,10 @@ export function formatDate(date, fmt) {
|
|
|
26
42
|
case '%H': return pad(date.getHours());
|
|
27
43
|
case '%M': return pad(date.getMinutes());
|
|
28
44
|
case '%S': return pad(date.getSeconds());
|
|
29
|
-
case '%a': return localizedShortName('weekday', date
|
|
30
|
-
case '%A': return localizedName('weekday', date
|
|
31
|
-
case '%b': return localizedShortName('month', date
|
|
32
|
-
case '%B': return localizedName('month', date
|
|
45
|
+
case '%a': return localizedShortName('weekday', date, locale, useHost);
|
|
46
|
+
case '%A': return localizedName('weekday', date, locale, useHost);
|
|
47
|
+
case '%b': return localizedShortName('month', date, locale, useHost);
|
|
48
|
+
case '%B': return localizedName('month', date, locale, useHost);
|
|
33
49
|
case '%s': return String(Math.floor(date.getTime() / 1000));
|
|
34
50
|
default: return token;
|
|
35
51
|
}
|
|
@@ -174,19 +190,49 @@ function pad(value) {
|
|
|
174
190
|
return String(value).padStart(2, '0');
|
|
175
191
|
}
|
|
176
192
|
|
|
177
|
-
/** @param {'month'|'weekday'} type @param {
|
|
178
|
-
function
|
|
193
|
+
/** @param {'month'|'weekday'} type @param {Date} date @returns {number} */
|
|
194
|
+
function nameIndex(type, date) {
|
|
195
|
+
return type === 'month' ? date.getMonth() : date.getDay();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @param {'month'|'weekday'} type @param {Date} date @param {string|string[]} locale @param {boolean} useHost @returns {string} */
|
|
199
|
+
function localizedName(type, date, locale, useHost) {
|
|
200
|
+
const index = nameIndex(type, date);
|
|
179
201
|
const key = `date.${type}.${index}`;
|
|
180
|
-
const value =
|
|
181
|
-
|
|
202
|
+
const value = useHost ? hostMessage(key) : null;
|
|
203
|
+
if (value !== null) return value;
|
|
204
|
+
return nameFormatter(type, 'long', locale)?.format(date) ?? ENGLISH_NAMES[type][index];
|
|
182
205
|
}
|
|
183
206
|
|
|
184
|
-
/** @param {'month'|'weekday'} type @param {
|
|
185
|
-
function localizedShortName(type,
|
|
186
|
-
const
|
|
187
|
-
const shortValue =
|
|
188
|
-
if (shortValue !==
|
|
189
|
-
return
|
|
207
|
+
/** @param {'month'|'weekday'} type @param {Date} date @param {string|string[]} locale @param {boolean} useHost @returns {string} */
|
|
208
|
+
function localizedShortName(type, date, locale, useHost) {
|
|
209
|
+
const index = nameIndex(type, date);
|
|
210
|
+
const shortValue = useHost ? hostMessage(`date.${type}.short.${index}`) : null;
|
|
211
|
+
if (shortValue !== null) return shortValue;
|
|
212
|
+
return nameFormatter(type, 'short', locale)?.format(date) ?? ENGLISH_NAMES[type][index].slice(0, 3);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The cached `Intl` formatter for one kind of name, or null when the English constants answer.
|
|
217
|
+
* The calendar is fixed because `%d`, `%m` and `%Y` are Gregorian in every locale.
|
|
218
|
+
* @param {'month'|'weekday'} type Kind of name.
|
|
219
|
+
* @param {'long'|'short'} style Length of the name.
|
|
220
|
+
* @param {string|string[]} locale BCP 47 language tag or locale list.
|
|
221
|
+
* @returns {Intl.DateTimeFormat|null}
|
|
222
|
+
*/
|
|
223
|
+
function nameFormatter(type, style, locale) {
|
|
224
|
+
const key = `${locale}\u0000${type}\u0000${style}`;
|
|
225
|
+
let formatter = nameFormatters.get(key);
|
|
226
|
+
if (formatter === undefined) {
|
|
227
|
+
try {
|
|
228
|
+
formatter = Intl.DateTimeFormat.supportedLocalesOf(locale).length > 0
|
|
229
|
+
? new Intl.DateTimeFormat(locale, { [type]: style, calendar: 'gregory' }) : null;
|
|
230
|
+
} catch {
|
|
231
|
+
formatter = null;
|
|
232
|
+
}
|
|
233
|
+
nameFormatters.set(key, formatter);
|
|
234
|
+
}
|
|
235
|
+
return formatter;
|
|
190
236
|
}
|
|
191
237
|
|
|
192
238
|
/** @param {string} token @returns {string|null} */
|
package/src/core/dom.js
CHANGED
|
@@ -20,6 +20,9 @@ const DOM_BUILDER_PROPERTIES = new Set([
|
|
|
20
20
|
'href', 'id', 'lang', 'name', 'rel', 'src', 'target', 'title', 'value'
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
|
+
/** HTML parsing belongs only to the explicit trusted `h.raw()` path. */
|
|
24
|
+
const HTML_SINK_PROPERTIES = new Set(['innerhtml', 'outerhtml', 'srcdoc']);
|
|
25
|
+
|
|
23
26
|
/** @type {WeakMap<EventTarget, Map<string, {handlers: Function[], listener: EventListener}>>} */
|
|
24
27
|
const compactEvents = new WeakMap();
|
|
25
28
|
|
|
@@ -208,16 +211,23 @@ export function fragment(...children) {
|
|
|
208
211
|
* @param {(HProps & Record<string, any>)|DomChild} [props] Properties and attributes, or the first child.
|
|
209
212
|
* @param {...DomChild} children Child values.
|
|
210
213
|
* @returns {HTMLElement}
|
|
214
|
+
* @throws {TypeError} When properties contain an HTML sink; use `h.raw()` for trusted HTML.
|
|
211
215
|
*/
|
|
212
216
|
export function h(tag, props, ...children) {
|
|
213
|
-
const element = document.createElement(tag);
|
|
214
217
|
let properties = props;
|
|
215
218
|
if (!isPropsObject(properties)) {
|
|
216
219
|
children.unshift(/** @type {DomChild} */ (properties));
|
|
217
220
|
properties = {};
|
|
218
221
|
}
|
|
219
222
|
|
|
220
|
-
|
|
223
|
+
const entries = Object.entries(properties);
|
|
224
|
+
for (const [key] of entries) {
|
|
225
|
+
if (HTML_SINK_PROPERTIES.has(key.toLowerCase())) {
|
|
226
|
+
throw new TypeError(`HTML property ${key} requires trusted h.raw() content`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const element = document.createElement(tag);
|
|
230
|
+
for (const [key, value] of entries) {
|
|
221
231
|
applyProperty(element, key, value);
|
|
222
232
|
}
|
|
223
233
|
appendChildren(element, children);
|
|
@@ -276,11 +286,54 @@ export function snapshotTarget(element) {
|
|
|
276
286
|
*/
|
|
277
287
|
export function restoreTarget(element, snapshot) {
|
|
278
288
|
if (!snapshot) return;
|
|
279
|
-
|
|
280
|
-
|
|
289
|
+
/*
|
|
290
|
+
* `style` goes back through the CSSOM (see `restoreInlineStyle`), so restoring a target never
|
|
291
|
+
* writes an inline style attribute that a strict Content Security Policy would block. While
|
|
292
|
+
* every captured attribute is still present they are corrected in place, which keeps their
|
|
293
|
+
* order and leaves an untouched `style` byte for byte as it was; only a target that lost one is
|
|
294
|
+
* rebuilt from nothing, in captured order.
|
|
295
|
+
*/
|
|
296
|
+
const styled = /** @type {Element & ElementCSSInlineStyle} */ (element);
|
|
297
|
+
const cssom = typeof styled.style?.cssText === 'string';
|
|
298
|
+
const saved = new Map(snapshot.attributes);
|
|
299
|
+
const intact = snapshot.attributes.every(([name]) => element.hasAttribute(name));
|
|
300
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
301
|
+
if (!intact || !saved.has(attribute.name)) {
|
|
302
|
+
if (attribute.name === 'style' && cssom) restoreInlineStyle(styled, null);
|
|
303
|
+
else element.removeAttribute(attribute.name);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
for (const [name, value] of snapshot.attributes) {
|
|
307
|
+
if (name === 'style' && cssom) restoreInlineStyle(styled, value);
|
|
308
|
+
else if (element.getAttribute(name) !== value) element.setAttribute(name, value);
|
|
309
|
+
}
|
|
281
310
|
element.replaceChildren(...snapshot.children);
|
|
282
311
|
}
|
|
283
312
|
|
|
313
|
+
/**
|
|
314
|
+
* Puts an element's inline style back to a captured attribute value.
|
|
315
|
+
*
|
|
316
|
+
* Written through the CSSOM, never the attribute: under a `style-src` policy without
|
|
317
|
+
* `'unsafe-inline'`, setting the `style` attribute is an inline style the browser blocks and
|
|
318
|
+
* reports, while `style.cssText` is not governed by it. A style that was absent (or empty) is
|
|
319
|
+
* cleared and its attribute removed — after a read, because Chrome reflects CSSOM changes into the
|
|
320
|
+
* attribute lazily, and a removal it has not reflected yet comes back as an empty `style=""`,
|
|
321
|
+
* which the next capture would then try to restore.
|
|
322
|
+
* @param {Element & ElementCSSInlineStyle} element Element whose inline style to restore.
|
|
323
|
+
* @param {string|null} value Attribute value captured earlier, or null when it was absent.
|
|
324
|
+
* @returns {void}
|
|
325
|
+
*/
|
|
326
|
+
export function restoreInlineStyle(element, value) {
|
|
327
|
+
// The read is also the flush: it makes the attribute current before anything compares or removes.
|
|
328
|
+
const current = element.getAttribute('style');
|
|
329
|
+
// Untouched styles keep their exact text; `cssText` would re-serialize `color:red` as `color: red;`.
|
|
330
|
+
if (current === value || (!value && current === null)) return;
|
|
331
|
+
element.style.cssText = value ?? '';
|
|
332
|
+
// Read either way: it places a restored attribute now, in order, and flushes before a removal.
|
|
333
|
+
element.getAttribute('style');
|
|
334
|
+
if (!value) element.removeAttribute('style');
|
|
335
|
+
}
|
|
336
|
+
|
|
284
337
|
/**
|
|
285
338
|
* Escapes text for safe insertion into an HTML string.
|
|
286
339
|
* @param {unknown} str Value to escape.
|
|
@@ -365,6 +418,16 @@ function isPropsObject(value) {
|
|
|
365
418
|
|
|
366
419
|
/** @param {HTMLElement} element @param {string} key @param {any} value @returns {void} */
|
|
367
420
|
function applyProperty(element, key, value) {
|
|
421
|
+
if (key.toLowerCase() === 'href') {
|
|
422
|
+
const href = safeHref(value);
|
|
423
|
+
if (href !== null) {
|
|
424
|
+
if ('href' in element) {
|
|
425
|
+
try { element.href = href; return; } catch { /* Attribute fallback for read-only properties. */ }
|
|
426
|
+
}
|
|
427
|
+
element.setAttribute('href', href);
|
|
428
|
+
}
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
368
431
|
if (key === 'ref') {
|
|
369
432
|
if (activeRefs && typeof value === 'string') activeRefs[value] = element;
|
|
370
433
|
return;
|
package/src/core/format.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import {
|
|
2
|
+
import { formattingLocale } from './i18n.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {Object} NumberFormatOptions
|
|
@@ -77,7 +77,7 @@ const relativeFormatters = new Map();
|
|
|
77
77
|
export function formatNumber(value, options = {}) {
|
|
78
78
|
const number = toFiniteNumber(value);
|
|
79
79
|
if (number === null) return '';
|
|
80
|
-
const { locale
|
|
80
|
+
const { locale, decimals, minDecimals, maxDecimals, group = true } = options;
|
|
81
81
|
return format(locale, digitOptions({ decimals, minDecimals, maxDecimals, group }), number);
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -92,7 +92,7 @@ export function formatNumber(value, options = {}) {
|
|
|
92
92
|
export function formatCurrency(value, currency, options = {}) {
|
|
93
93
|
const number = toFiniteNumber(value);
|
|
94
94
|
if (number === null) return '';
|
|
95
|
-
const { locale
|
|
95
|
+
const { locale, decimals } = options;
|
|
96
96
|
const code = currencyCode(currency);
|
|
97
97
|
if (code === null) return formatNumber(number, { locale, decimals });
|
|
98
98
|
|
|
@@ -109,7 +109,7 @@ export function formatCurrency(value, currency, options = {}) {
|
|
|
109
109
|
export function formatPercent(value, options = {}) {
|
|
110
110
|
const number = toFiniteNumber(value);
|
|
111
111
|
if (number === null) return '';
|
|
112
|
-
const { locale
|
|
112
|
+
const { locale, decimals = 0 } = options;
|
|
113
113
|
return format(locale, { ...digitOptions({ decimals, group: true }), style: 'percent' }, number);
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -122,7 +122,7 @@ export function formatPercent(value, options = {}) {
|
|
|
122
122
|
export function formatFileSize(bytes, options = {}) {
|
|
123
123
|
const number = toFiniteNumber(bytes);
|
|
124
124
|
if (number === null) return '';
|
|
125
|
-
const { locale
|
|
125
|
+
const { locale, decimals = 1, standard = 'iec' } = options;
|
|
126
126
|
if (number === 0) return `${formatNumber(0, { locale, decimals: 0 })} B`;
|
|
127
127
|
|
|
128
128
|
const units = standard === 'si' ? SI_UNITS : IEC_UNITS;
|
|
@@ -152,7 +152,7 @@ export function formatFileSize(bytes, options = {}) {
|
|
|
152
152
|
export function formatRelativeTime(date, options = {}) {
|
|
153
153
|
const target = toDate(date);
|
|
154
154
|
if (target === null) return '';
|
|
155
|
-
const { now = new Date(), locale
|
|
155
|
+
const { now = new Date(), locale, numeric = 'auto' } = options;
|
|
156
156
|
const reference = toDate(now);
|
|
157
157
|
if (reference === null) return '';
|
|
158
158
|
|
|
@@ -165,13 +165,14 @@ export function formatRelativeTime(date, options = {}) {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
|
-
* Returns a cached `Intl.NumberFormat`, falling back to the
|
|
169
|
-
* @param {string} locale BCP 47 language tag.
|
|
168
|
+
* Returns a cached `Intl.NumberFormat`, falling back to the active language for unusable locales.
|
|
169
|
+
* @param {string|string[]|undefined} locale BCP 47 language tag.
|
|
170
170
|
* @param {Intl.NumberFormatOptions} options Formatter options.
|
|
171
171
|
* @param {number} value Number to format.
|
|
172
172
|
* @returns {string}
|
|
173
173
|
*/
|
|
174
174
|
function format(locale, options, value) {
|
|
175
|
+
locale = formattingLocale(locale);
|
|
175
176
|
const key = `${locale}\u0000${JSON.stringify(options)}`;
|
|
176
177
|
let formatter = numberFormatters.get(key);
|
|
177
178
|
if (formatter === undefined) {
|
|
@@ -182,7 +183,7 @@ function format(locale, options, value) {
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
/**
|
|
185
|
-
* @param {string} locale BCP 47 language tag.
|
|
186
|
+
* @param {string|string[]|undefined} locale BCP 47 language tag.
|
|
186
187
|
* @param {Intl.NumberFormatOptions} options Formatter options.
|
|
187
188
|
* @returns {Intl.NumberFormat}
|
|
188
189
|
*/
|
|
@@ -191,27 +192,28 @@ function createNumberFormat(locale, options) {
|
|
|
191
192
|
return new Intl.NumberFormat(locale, options);
|
|
192
193
|
} catch {
|
|
193
194
|
try {
|
|
194
|
-
return new Intl.NumberFormat(
|
|
195
|
+
return new Intl.NumberFormat(formattingLocale(), options);
|
|
195
196
|
} catch {
|
|
196
197
|
// Unusable options (an unsupported currency style, say) still have to produce digits.
|
|
197
|
-
return new Intl.NumberFormat();
|
|
198
|
+
return new Intl.NumberFormat(formattingLocale());
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
/**
|
|
203
|
-
* @param {string} locale BCP 47 language tag.
|
|
204
|
+
* @param {string|string[]|undefined} locale BCP 47 language tag.
|
|
204
205
|
* @param {'auto'|'always'} numeric Numeric-phrasing mode.
|
|
205
206
|
* @returns {Intl.RelativeTimeFormat}
|
|
206
207
|
*/
|
|
207
208
|
function relativeFormatter(locale, numeric) {
|
|
209
|
+
locale = formattingLocale(locale, Intl.RelativeTimeFormat);
|
|
208
210
|
const key = `${locale}\u0000${numeric}`;
|
|
209
211
|
let formatter = relativeFormatters.get(key);
|
|
210
212
|
if (formatter === undefined) {
|
|
211
213
|
try {
|
|
212
214
|
formatter = new Intl.RelativeTimeFormat(locale, { numeric });
|
|
213
215
|
} catch {
|
|
214
|
-
formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
|
|
216
|
+
formatter = new Intl.RelativeTimeFormat(formattingLocale(undefined, Intl.RelativeTimeFormat), { numeric: 'auto' });
|
|
215
217
|
}
|
|
216
218
|
relativeFormatters.set(key, formatter);
|
|
217
219
|
}
|
package/src/core/http.js
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* @property {File|FileList|File[]} [files=null] Files that switch the body to FormData.
|
|
15
15
|
* @property {string|URLSearchParams|Record<string, unknown>} [query=null] Query parameters.
|
|
16
16
|
* @property {Record<string, string>} [headers={}] Per-request headers.
|
|
17
|
+
* @property {AbortSignal|null} [signal=null] Caller cancellation signal.
|
|
18
|
+
* @property {string} [paramName='files'] Multipart field name used for each file.
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
/** Dependency-free JSON fetch wrapper with legacy ZeyOS envelope handling. */
|
|
@@ -45,25 +47,29 @@ export class Http {
|
|
|
45
47
|
*/
|
|
46
48
|
async request(path, options = {}) {
|
|
47
49
|
const {
|
|
48
|
-
method = 'GET', data = null, files = null, query = null, headers = {}
|
|
50
|
+
method = 'GET', data = null, files = null, query = null, headers = {}, signal = null, paramName = 'files'
|
|
49
51
|
} = options;
|
|
50
52
|
const controller = new AbortController();
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (files !== null) {
|
|
58
|
-
body = createFormData(data, files);
|
|
59
|
-
requestHeaders.delete('Content-Type');
|
|
60
|
-
} else if (data !== null && method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'HEAD') {
|
|
61
|
-
body = JSON.stringify(data);
|
|
62
|
-
requestHeaders.set('Content-Type', requestHeaders.get('Content-Type') ?? 'application/json');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const url = appendQuery(this.base + path, query);
|
|
53
|
+
const abort = () => controller.abort(signal?.reason);
|
|
54
|
+
if (signal?.aborted) abort();
|
|
55
|
+
else signal?.addEventListener('abort', abort, { once: true });
|
|
56
|
+
const timeoutId = this.timeout > 0 ? setTimeout(() => {
|
|
57
|
+
controller.abort(new DOMException('Request timed out', 'TimeoutError'));
|
|
58
|
+
}, this.timeout) : null;
|
|
66
59
|
try {
|
|
60
|
+
controller.signal.throwIfAborted();
|
|
61
|
+
const requestHeaders = new Headers(this.headers);
|
|
62
|
+
for (const [name, value] of Object.entries(headers)) requestHeaders.set(name, value);
|
|
63
|
+
requestHeaders.set('Accept', requestHeaders.get('Accept') ?? 'application/json');
|
|
64
|
+
let body;
|
|
65
|
+
if (files !== null) {
|
|
66
|
+
body = createFormData(data, files, String(paramName));
|
|
67
|
+
requestHeaders.delete('Content-Type');
|
|
68
|
+
} else if (data !== null && method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'HEAD') {
|
|
69
|
+
body = JSON.stringify(data);
|
|
70
|
+
requestHeaders.set('Content-Type', requestHeaders.get('Content-Type') ?? 'application/json');
|
|
71
|
+
}
|
|
72
|
+
const url = appendQuery(this.base + path, query);
|
|
67
73
|
const response = await fetch(url, {
|
|
68
74
|
method: method.toUpperCase(),
|
|
69
75
|
headers: requestHeaders,
|
|
@@ -71,6 +77,7 @@ export class Http {
|
|
|
71
77
|
signal: controller.signal
|
|
72
78
|
});
|
|
73
79
|
const text = await response.text();
|
|
80
|
+
controller.signal.throwIfAborted();
|
|
74
81
|
let json = null;
|
|
75
82
|
if (text !== '') {
|
|
76
83
|
try {
|
|
@@ -110,6 +117,7 @@ export class Http {
|
|
|
110
117
|
throw error;
|
|
111
118
|
} finally {
|
|
112
119
|
if (timeoutId !== null) clearTimeout(timeoutId);
|
|
120
|
+
signal?.removeEventListener('abort', abort);
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
123
|
|
|
@@ -175,7 +183,8 @@ export function zeyosService(service, accesskey = '', options = {}) {
|
|
|
175
183
|
*/
|
|
176
184
|
export function parseResult(json) {
|
|
177
185
|
if (json && typeof json === 'object') {
|
|
178
|
-
if (Object.prototype.hasOwnProperty.call(json, 'error') && json.error != null
|
|
186
|
+
if (Object.prototype.hasOwnProperty.call(json, 'error') && json.error != null
|
|
187
|
+
&& json.error !== false && json.error !== 0) {
|
|
179
188
|
const message = typeof json.error === 'string' ? json.error : JSON.stringify(json.error);
|
|
180
189
|
throw new Error(message || 'Server error');
|
|
181
190
|
}
|
|
@@ -213,8 +222,8 @@ function appendParameter(parameters, key, value) {
|
|
|
213
222
|
}
|
|
214
223
|
}
|
|
215
224
|
|
|
216
|
-
/** @param {unknown} data @param {File|FileList|File[]} files @returns {FormData} */
|
|
217
|
-
function createFormData(data, files) {
|
|
225
|
+
/** @param {unknown} data @param {File|FileList|File[]} files @param {string} paramName @returns {FormData} */
|
|
226
|
+
function createFormData(data, files, paramName) {
|
|
218
227
|
const form = new FormData();
|
|
219
228
|
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
220
229
|
for (const [key, value] of Object.entries(data)) appendFormValue(form, key, value);
|
|
@@ -223,7 +232,7 @@ function createFormData(data, files) {
|
|
|
223
232
|
}
|
|
224
233
|
|
|
225
234
|
const list = isFileList(files) || Array.isArray(files) ? Array.from(files) : [files];
|
|
226
|
-
for (const file of list) form.append(
|
|
235
|
+
for (const file of list) form.append(paramName, file);
|
|
227
236
|
return form;
|
|
228
237
|
}
|
|
229
238
|
|
package/src/core/i18n.js
CHANGED
|
@@ -8,6 +8,8 @@ export { defaultMessages };
|
|
|
8
8
|
/** @type {Translator|null} */
|
|
9
9
|
let translator = null;
|
|
10
10
|
let language = 'en';
|
|
11
|
+
/** @type {Map<string, Intl.PluralRules>} */
|
|
12
|
+
const pluralRules = new Map();
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Installs the host application's translation function, or clears it with null. The function
|
|
@@ -88,6 +90,78 @@ export function translate(key, args) {
|
|
|
88
90
|
return printf(text, args);
|
|
89
91
|
}
|
|
90
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Selects a cardinal plural message before interpolation. The host's selected category, `other`,
|
|
95
|
+
* and unsuffixed message are tried before English, which uses its own plural rules.
|
|
96
|
+
* @param {string} key Unsuffixed translation key.
|
|
97
|
+
* @param {number} count Finite numeric count, independent of interpolation arguments.
|
|
98
|
+
* @param {unknown[]|Record<string, unknown>|string|number} [args] Interpolation arguments.
|
|
99
|
+
* @param {{locale?: string}} [options={}] Plural-rule locale; defaults to the active language.
|
|
100
|
+
* @returns {string}
|
|
101
|
+
*/
|
|
102
|
+
export function translatePlural(key, count, args, { locale } = {}) {
|
|
103
|
+
const text = pluralMessage(pluralKeys(key, count, locale), hostMessage)
|
|
104
|
+
?? pluralMessage(pluralKeys(key, count, 'en'), defaultMessage)
|
|
105
|
+
?? key;
|
|
106
|
+
return printf(text, args);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Resolves a supported explicit locale, then the active language, then English. Locale lists
|
|
111
|
+
* retain their preference order. Support is checked by the consuming Intl service, whose locale
|
|
112
|
+
* data may differ from NumberFormat's; internal formatting consumers share this precedence.
|
|
113
|
+
* @param {string|string[]|null} [option] Explicit locale or locale list.
|
|
114
|
+
* @param {{supportedLocalesOf: (locales: string|string[]) => string[]}} [service=Intl.NumberFormat] Consuming Intl service.
|
|
115
|
+
* @returns {string|string[]}
|
|
116
|
+
*/
|
|
117
|
+
export function formattingLocale(option, service = Intl.NumberFormat) {
|
|
118
|
+
for (const candidate of [option, getLanguage(), 'en']) {
|
|
119
|
+
if (candidate == null) continue;
|
|
120
|
+
try {
|
|
121
|
+
const locales = service.supportedLocalesOf(Intl.getCanonicalLocales(candidate));
|
|
122
|
+
if (locales.length) return Array.isArray(candidate) ? locales : locales[0];
|
|
123
|
+
} catch { /* An unusable explicit option falls through to the active language. */ }
|
|
124
|
+
}
|
|
125
|
+
return 'en';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Ordered keys within one message source. Internal helper shared with Component.msgPlural.
|
|
130
|
+
* @param {string} key Unsuffixed key.
|
|
131
|
+
* @param {number} count Finite numeric count.
|
|
132
|
+
* @param {string} [locale] Plural-rule locale.
|
|
133
|
+
* @returns {string[]}
|
|
134
|
+
*/
|
|
135
|
+
export function pluralKeys(key, count, locale) {
|
|
136
|
+
if (typeof count !== 'number' || !Number.isFinite(count)) {
|
|
137
|
+
throw new TypeError('Plural count must be a finite number');
|
|
138
|
+
}
|
|
139
|
+
const effective = formattingLocale(locale, Intl.PluralRules);
|
|
140
|
+
const cacheKey = String(effective);
|
|
141
|
+
let rules = pluralRules.get(cacheKey);
|
|
142
|
+
if (!rules) {
|
|
143
|
+
rules = new Intl.PluralRules(effective);
|
|
144
|
+
pluralRules.set(cacheKey, rules);
|
|
145
|
+
}
|
|
146
|
+
const category = rules.select(count);
|
|
147
|
+
const legacy = legacyMessageKey(key);
|
|
148
|
+
return [...new Set([`${key}.${category}`, `${key}.other`, key, ...(legacy ? [legacy] : [])])];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns the first available message without asking a translator for subsequent keys.
|
|
153
|
+
* @param {string[]} keys Candidate keys.
|
|
154
|
+
* @param {(key: string) => string|null} lookup One message source.
|
|
155
|
+
* @returns {string|null}
|
|
156
|
+
*/
|
|
157
|
+
export function pluralMessage(keys, lookup) {
|
|
158
|
+
for (const key of keys) {
|
|
159
|
+
const text = lookup(key);
|
|
160
|
+
if (text !== null) return text;
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
91
165
|
/**
|
|
92
166
|
* Replaces one-based numeric placeholders and legacy percent-delimited placeholders.
|
|
93
167
|
* Arrays replace `%1`, `%2`, and legacy placeholders in encounter order; objects replace
|
|
@@ -101,16 +175,16 @@ export function printf(str, args) {
|
|
|
101
175
|
|
|
102
176
|
const positional = Array.isArray(args) ? args :
|
|
103
177
|
(typeof args === 'object' ? null : [args]);
|
|
104
|
-
|
|
105
|
-
const index = Number(indexText) - 1;
|
|
106
|
-
let value;
|
|
107
|
-
if (positional) value = positional[index];
|
|
108
|
-
else if (Object.prototype.hasOwnProperty.call(args, indexText)) value = args[indexText];
|
|
109
|
-
return value == null ? placeholder : String(value);
|
|
110
|
-
});
|
|
111
|
-
|
|
178
|
+
// One pass: a value already written into the text is never read as a placeholder.
|
|
112
179
|
let legacyIndex = 0;
|
|
113
|
-
|
|
180
|
+
return String(str).replace(/%(\d+)|%([A-Za-z_][\w.-]*)%(?!\d)/g, (placeholder, indexText, key) => {
|
|
181
|
+
if (indexText !== undefined) {
|
|
182
|
+
const index = Number(indexText) - 1;
|
|
183
|
+
let value;
|
|
184
|
+
if (positional) value = positional[index];
|
|
185
|
+
else if (Object.prototype.hasOwnProperty.call(args, indexText)) value = args[indexText];
|
|
186
|
+
return value == null ? placeholder : String(value);
|
|
187
|
+
}
|
|
114
188
|
if (!positional && Object.prototype.hasOwnProperty.call(args, key)) {
|
|
115
189
|
const value = args[key];
|
|
116
190
|
return value == null ? placeholder : String(value);
|
|
@@ -122,5 +196,4 @@ export function printf(str, args) {
|
|
|
122
196
|
}
|
|
123
197
|
return placeholder;
|
|
124
198
|
});
|
|
125
|
-
return output;
|
|
126
199
|
}
|
package/src/core/icons.js
CHANGED
|
@@ -181,6 +181,10 @@ export const icons = Object.freeze({
|
|
|
181
181
|
error: outline('M2 12a10 10 0 1 0 20 0a10 10 0 1 0-20 0zM12 8V12M12 16H12.01'), // circle-alert
|
|
182
182
|
success: outline('M2 12a10 10 0 1 0 20 0a10 10 0 1 0-20 0zM16 9l-5.5 5.5L8 12'), // circle-check
|
|
183
183
|
upload: outline('M12 3v12M17 8l-5-5-5 5M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'),
|
|
184
|
+
download: outline('M12 15V3M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5'),
|
|
185
|
+
'box-archive': outline('M3 3h18a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1zM4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8M10 12h4'), // archive
|
|
186
|
+
pencil: outline('M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497zM15 5l4 4'),
|
|
187
|
+
'pen-to-square': outline('M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z'), // square-pen
|
|
184
188
|
drag: outline('M8 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM8 5a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM8 19a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM14 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM14 5a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM14 19a1 1 0 1 0 2 0a1 1 0 1 0-2 0z'), // grip-vertical
|
|
185
189
|
star: outline('M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z'),
|
|
186
190
|
heart: outline('M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5'),
|
|
@@ -204,8 +208,14 @@ export const icons = Object.freeze({
|
|
|
204
208
|
// </lucide-glyphs>
|
|
205
209
|
});
|
|
206
210
|
|
|
207
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* Other names for bundled glyphs: legacy gx Factory names, and the older Font Awesome names
|
|
213
|
+
* (`archive`, `edit`) that are still the ones most code reaches for. A glyph an application
|
|
214
|
+
* registered under the alias itself takes precedence (see `icon()`).
|
|
215
|
+
*/
|
|
208
216
|
const aliases = Object.freeze({
|
|
217
|
+
archive: 'box-archive',
|
|
218
|
+
edit: 'pen-to-square',
|
|
209
219
|
settings: 'gear',
|
|
210
220
|
clear: 'x',
|
|
211
221
|
checked: 'check',
|
|
@@ -352,7 +362,8 @@ export function icon(name, options = {}) {
|
|
|
352
362
|
const spec = parseIconSpec(name);
|
|
353
363
|
if (spec.classes) return faIcon(spec.classes, options);
|
|
354
364
|
|
|
355
|
-
|
|
365
|
+
// An application that registered a glyph under an alias name keeps its own glyph.
|
|
366
|
+
const resolved = Object.hasOwn(extraGlyphs, spec.name) ? spec.name : aliases[spec.name] ?? spec.name;
|
|
356
367
|
if (spec.provider === 'builtin') return builtinIcon(resolved, options);
|
|
357
368
|
if (spec.provider === 'fa') {
|
|
358
369
|
return faIcon(faIconClasses(resolved, {
|