verbaly 0.49.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/devtools.d.cts +3 -4
- package/dist/devtools.d.ts +3 -4
- package/dist/index.cjs +44 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -26
- package/dist/index.d.ts +28 -26
- package/dist/index.js +43 -16
- package/dist/index.js.map +1 -1
- package/dist/{types-DvDwMDB-.d.ts → types-BFlL6yDe.d.cts} +7 -3
- package/dist/{types-DvDwMDB-.d.cts → types-BFlL6yDe.d.ts} +7 -3
- package/package.json +5 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { S as parse, _ as Verbaly, a as Formatter, b as MessageNode, c as MessageAt, d as ParamNames, f as Params, g as TFunction, h as TArgs, i as FormatInfo, l as MessageTree, m as ResolveStatus, n as DictionaryInput, o as KeysOf, p as ResolveInfo, r as FlatKeys, s as LocaleLoader, t as AddMessagesOptions, u as MessageValue, v as VerbalyOptions, x as ParamNode, y as IcuParser } from "./types-BFlL6yDe.cjs";
|
|
2
2
|
//#region src/instance.d.ts
|
|
3
|
-
declare function createVerbaly<const D extends DictionaryInput = DictionaryInput>(options?: VerbalyOptions<D>): Verbaly<D>;
|
|
3
|
+
export declare function createVerbaly<const D extends DictionaryInput = DictionaryInput>(options?: VerbalyOptions<D>): Verbaly<D>;
|
|
4
4
|
//#endregion
|
|
5
5
|
//#region src/dom.d.ts
|
|
6
6
|
type RichLink = string | {
|
|
@@ -14,16 +14,18 @@ interface BindDomOptions {
|
|
|
14
14
|
richTags?: string[];
|
|
15
15
|
richLinks?: Record<string, RichLink>;
|
|
16
16
|
}
|
|
17
|
-
declare function safeHref(href: string): string | undefined;
|
|
18
|
-
declare function normalizeLink(link: RichLink): {
|
|
17
|
+
export declare function safeHref(href: string): string | undefined;
|
|
18
|
+
export declare function normalizeLink(link: RichLink): {
|
|
19
19
|
href?: string;
|
|
20
20
|
target?: string;
|
|
21
21
|
rel?: string;
|
|
22
22
|
};
|
|
23
|
-
declare function safeAttribute(name: string, value: string): string | undefined;
|
|
24
|
-
declare const VOID_TAGS: string[];
|
|
25
|
-
declare const RICH_TAGS: string[];
|
|
26
|
-
declare
|
|
23
|
+
export declare function safeAttribute(name: string, value: string): string | undefined;
|
|
24
|
+
export declare const VOID_TAGS: string[];
|
|
25
|
+
export declare const RICH_TAGS: string[];
|
|
26
|
+
export declare const CATALOG_SCRIPT = "data-verbaly-catalog";
|
|
27
|
+
export declare function inlineMessages(root?: ParentNode): Record<string, string> | undefined;
|
|
28
|
+
export declare function bindDom<D extends DictionaryInput>(instance: Verbaly<D>, options?: BindDomOptions): () => void;
|
|
27
29
|
//#endregion
|
|
28
30
|
//#region src/locale.d.ts
|
|
29
31
|
interface ResolveLocaleOptions {
|
|
@@ -38,9 +40,9 @@ interface LocaleFromPathOptions {
|
|
|
38
40
|
path?: string;
|
|
39
41
|
base?: string;
|
|
40
42
|
}
|
|
41
|
-
declare const LOCALE_STORAGE_KEY = "verbaly-locale";
|
|
42
|
-
declare function localeDirection(locale: string): 'ltr' | 'rtl';
|
|
43
|
-
declare function localeName(locale: string, displayIn?: string): string;
|
|
43
|
+
export declare const LOCALE_STORAGE_KEY = "verbaly-locale";
|
|
44
|
+
export declare function localeDirection(locale: string): 'ltr' | 'rtl';
|
|
45
|
+
export declare function localeName(locale: string, displayIn?: string): string;
|
|
44
46
|
type Routing = 'prefix-except-source' | 'no-prefix' | 'prefix-all';
|
|
45
47
|
interface LocalePathBase {
|
|
46
48
|
supported: string[];
|
|
@@ -54,14 +56,14 @@ type LocalePathOptions = LocalePathBase & ({
|
|
|
54
56
|
routing: 'no-prefix' | 'prefix-all';
|
|
55
57
|
sourceLocale?: string;
|
|
56
58
|
});
|
|
57
|
-
declare function localePath(locale: string, options: LocalePathOptions): string;
|
|
58
|
-
declare function localeFromPath(options: LocaleFromPathOptions): string | undefined;
|
|
59
|
+
export declare function localePath(locale: string, options: LocalePathOptions): string;
|
|
60
|
+
export declare function localeFromPath(options: LocaleFromPathOptions): string | undefined;
|
|
59
61
|
interface StripLocalePathOptions {
|
|
60
62
|
supported: string[];
|
|
61
63
|
path?: string;
|
|
62
64
|
base?: string;
|
|
63
65
|
}
|
|
64
|
-
declare function stripLocalePath(options: StripLocalePathOptions): string;
|
|
66
|
+
export declare function stripLocalePath(options: StripLocalePathOptions): string;
|
|
65
67
|
interface AlternateLink {
|
|
66
68
|
hreflang: string;
|
|
67
69
|
href: string;
|
|
@@ -74,9 +76,9 @@ interface AlternateLinksOptions {
|
|
|
74
76
|
base?: string;
|
|
75
77
|
baseUrl?: string;
|
|
76
78
|
}
|
|
77
|
-
declare function alternateLinks(options: AlternateLinksOptions): AlternateLink[];
|
|
78
|
-
declare function resolveLocale(options: ResolveLocaleOptions): string;
|
|
79
|
-
declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
|
|
79
|
+
export declare function alternateLinks(options: AlternateLinksOptions): AlternateLink[];
|
|
80
|
+
export declare function resolveLocale(options: ResolveLocaleOptions): string;
|
|
81
|
+
export declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
|
|
80
82
|
interface RequestLocaleOptions {
|
|
81
83
|
supported: string[];
|
|
82
84
|
path?: string | null;
|
|
@@ -86,7 +88,7 @@ interface RequestLocaleOptions {
|
|
|
86
88
|
header?: string | null;
|
|
87
89
|
fallback?: string;
|
|
88
90
|
}
|
|
89
|
-
declare function resolveRequestLocale(options: RequestLocaleOptions): string;
|
|
91
|
+
export declare function resolveRequestLocale(options: RequestLocaleOptions): string;
|
|
90
92
|
interface SwitchLocaleOptions {
|
|
91
93
|
cookie?: string | false;
|
|
92
94
|
storageKey?: string | false;
|
|
@@ -97,27 +99,27 @@ interface SwitchLocaleOptions {
|
|
|
97
99
|
base?: string;
|
|
98
100
|
navigate?: (path: string) => void | Promise<void>;
|
|
99
101
|
}
|
|
100
|
-
declare function switchLocale(instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>, locale: string, options?: SwitchLocaleOptions): Promise<void>;
|
|
101
|
-
declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
102
|
+
export declare function switchLocale(instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>, locale: string, options?: SwitchLocaleOptions): Promise<void>;
|
|
103
|
+
export declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
102
104
|
//#endregion
|
|
103
105
|
//#region src/icu.d.ts
|
|
104
|
-
declare function parseIcu(message: string): MessageNode[];
|
|
106
|
+
export declare function parseIcu(message: string): MessageNode[];
|
|
105
107
|
//#endregion
|
|
106
108
|
//#region src/relative.d.ts
|
|
107
|
-
declare const relativeFormatter: Formatter;
|
|
109
|
+
export declare const relativeFormatter: Formatter;
|
|
108
110
|
//#endregion
|
|
109
111
|
//#region src/flatten.d.ts
|
|
110
|
-
declare function flatten(tree: MessageTree, prefix?: string, out?: Record<string, string>): Record<string, string>;
|
|
112
|
+
export declare function flatten(tree: MessageTree, prefix?: string, out?: Record<string, string>): Record<string, string>;
|
|
111
113
|
//#endregion
|
|
112
114
|
//#region src/tags.d.ts
|
|
113
115
|
type TagNode = string | {
|
|
114
116
|
name: string;
|
|
115
117
|
children: TagNode[];
|
|
116
118
|
};
|
|
117
|
-
declare function parseTags(text: string): TagNode[];
|
|
119
|
+
export declare function parseTags(text: string): TagNode[];
|
|
118
120
|
//#endregion
|
|
119
121
|
//#region src/warn.d.ts
|
|
120
|
-
declare function warnOnce(message: string): void;
|
|
122
|
+
export declare function warnOnce(message: string): void;
|
|
121
123
|
//#endregion
|
|
122
|
-
export { type AlternateLink, type AlternateLinksOptions, type BindDomOptions, type DictionaryInput, type FlatKeys, type FormatInfo, type Formatter, type IcuParser, type KeysOf,
|
|
124
|
+
export { type AddMessagesOptions, type AlternateLink, type AlternateLinksOptions, type BindDomOptions, type DictionaryInput, type FlatKeys, type FormatInfo, type Formatter, type IcuParser, type KeysOf, type LocaleFromPathOptions, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type Routing, type StripLocalePathOptions, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, type Verbaly, type VerbalyOptions, parse };
|
|
123
125
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { S as parse, _ as Verbaly, a as Formatter, b as MessageNode, c as MessageAt, d as ParamNames, f as Params, g as TFunction, h as TArgs, i as FormatInfo, l as MessageTree, m as ResolveStatus, n as DictionaryInput, o as KeysOf, p as ResolveInfo, r as FlatKeys, s as LocaleLoader, t as AddMessagesOptions, u as MessageValue, v as VerbalyOptions, x as ParamNode, y as IcuParser } from "./types-BFlL6yDe.js";
|
|
2
2
|
//#region src/instance.d.ts
|
|
3
|
-
declare function createVerbaly<const D extends DictionaryInput = DictionaryInput>(options?: VerbalyOptions<D>): Verbaly<D>;
|
|
3
|
+
export declare function createVerbaly<const D extends DictionaryInput = DictionaryInput>(options?: VerbalyOptions<D>): Verbaly<D>;
|
|
4
4
|
//#endregion
|
|
5
5
|
//#region src/dom.d.ts
|
|
6
6
|
type RichLink = string | {
|
|
@@ -14,16 +14,18 @@ interface BindDomOptions {
|
|
|
14
14
|
richTags?: string[];
|
|
15
15
|
richLinks?: Record<string, RichLink>;
|
|
16
16
|
}
|
|
17
|
-
declare function safeHref(href: string): string | undefined;
|
|
18
|
-
declare function normalizeLink(link: RichLink): {
|
|
17
|
+
export declare function safeHref(href: string): string | undefined;
|
|
18
|
+
export declare function normalizeLink(link: RichLink): {
|
|
19
19
|
href?: string;
|
|
20
20
|
target?: string;
|
|
21
21
|
rel?: string;
|
|
22
22
|
};
|
|
23
|
-
declare function safeAttribute(name: string, value: string): string | undefined;
|
|
24
|
-
declare const VOID_TAGS: string[];
|
|
25
|
-
declare const RICH_TAGS: string[];
|
|
26
|
-
declare
|
|
23
|
+
export declare function safeAttribute(name: string, value: string): string | undefined;
|
|
24
|
+
export declare const VOID_TAGS: string[];
|
|
25
|
+
export declare const RICH_TAGS: string[];
|
|
26
|
+
export declare const CATALOG_SCRIPT = "data-verbaly-catalog";
|
|
27
|
+
export declare function inlineMessages(root?: ParentNode): Record<string, string> | undefined;
|
|
28
|
+
export declare function bindDom<D extends DictionaryInput>(instance: Verbaly<D>, options?: BindDomOptions): () => void;
|
|
27
29
|
//#endregion
|
|
28
30
|
//#region src/locale.d.ts
|
|
29
31
|
interface ResolveLocaleOptions {
|
|
@@ -38,9 +40,9 @@ interface LocaleFromPathOptions {
|
|
|
38
40
|
path?: string;
|
|
39
41
|
base?: string;
|
|
40
42
|
}
|
|
41
|
-
declare const LOCALE_STORAGE_KEY = "verbaly-locale";
|
|
42
|
-
declare function localeDirection(locale: string): 'ltr' | 'rtl';
|
|
43
|
-
declare function localeName(locale: string, displayIn?: string): string;
|
|
43
|
+
export declare const LOCALE_STORAGE_KEY = "verbaly-locale";
|
|
44
|
+
export declare function localeDirection(locale: string): 'ltr' | 'rtl';
|
|
45
|
+
export declare function localeName(locale: string, displayIn?: string): string;
|
|
44
46
|
type Routing = 'prefix-except-source' | 'no-prefix' | 'prefix-all';
|
|
45
47
|
interface LocalePathBase {
|
|
46
48
|
supported: string[];
|
|
@@ -54,14 +56,14 @@ type LocalePathOptions = LocalePathBase & ({
|
|
|
54
56
|
routing: 'no-prefix' | 'prefix-all';
|
|
55
57
|
sourceLocale?: string;
|
|
56
58
|
});
|
|
57
|
-
declare function localePath(locale: string, options: LocalePathOptions): string;
|
|
58
|
-
declare function localeFromPath(options: LocaleFromPathOptions): string | undefined;
|
|
59
|
+
export declare function localePath(locale: string, options: LocalePathOptions): string;
|
|
60
|
+
export declare function localeFromPath(options: LocaleFromPathOptions): string | undefined;
|
|
59
61
|
interface StripLocalePathOptions {
|
|
60
62
|
supported: string[];
|
|
61
63
|
path?: string;
|
|
62
64
|
base?: string;
|
|
63
65
|
}
|
|
64
|
-
declare function stripLocalePath(options: StripLocalePathOptions): string;
|
|
66
|
+
export declare function stripLocalePath(options: StripLocalePathOptions): string;
|
|
65
67
|
interface AlternateLink {
|
|
66
68
|
hreflang: string;
|
|
67
69
|
href: string;
|
|
@@ -74,9 +76,9 @@ interface AlternateLinksOptions {
|
|
|
74
76
|
base?: string;
|
|
75
77
|
baseUrl?: string;
|
|
76
78
|
}
|
|
77
|
-
declare function alternateLinks(options: AlternateLinksOptions): AlternateLink[];
|
|
78
|
-
declare function resolveLocale(options: ResolveLocaleOptions): string;
|
|
79
|
-
declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
|
|
79
|
+
export declare function alternateLinks(options: AlternateLinksOptions): AlternateLink[];
|
|
80
|
+
export declare function resolveLocale(options: ResolveLocaleOptions): string;
|
|
81
|
+
export declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
|
|
80
82
|
interface RequestLocaleOptions {
|
|
81
83
|
supported: string[];
|
|
82
84
|
path?: string | null;
|
|
@@ -86,7 +88,7 @@ interface RequestLocaleOptions {
|
|
|
86
88
|
header?: string | null;
|
|
87
89
|
fallback?: string;
|
|
88
90
|
}
|
|
89
|
-
declare function resolveRequestLocale(options: RequestLocaleOptions): string;
|
|
91
|
+
export declare function resolveRequestLocale(options: RequestLocaleOptions): string;
|
|
90
92
|
interface SwitchLocaleOptions {
|
|
91
93
|
cookie?: string | false;
|
|
92
94
|
storageKey?: string | false;
|
|
@@ -97,27 +99,27 @@ interface SwitchLocaleOptions {
|
|
|
97
99
|
base?: string;
|
|
98
100
|
navigate?: (path: string) => void | Promise<void>;
|
|
99
101
|
}
|
|
100
|
-
declare function switchLocale(instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>, locale: string, options?: SwitchLocaleOptions): Promise<void>;
|
|
101
|
-
declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
102
|
+
export declare function switchLocale(instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>, locale: string, options?: SwitchLocaleOptions): Promise<void>;
|
|
103
|
+
export declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
102
104
|
//#endregion
|
|
103
105
|
//#region src/icu.d.ts
|
|
104
|
-
declare function parseIcu(message: string): MessageNode[];
|
|
106
|
+
export declare function parseIcu(message: string): MessageNode[];
|
|
105
107
|
//#endregion
|
|
106
108
|
//#region src/relative.d.ts
|
|
107
|
-
declare const relativeFormatter: Formatter;
|
|
109
|
+
export declare const relativeFormatter: Formatter;
|
|
108
110
|
//#endregion
|
|
109
111
|
//#region src/flatten.d.ts
|
|
110
|
-
declare function flatten(tree: MessageTree, prefix?: string, out?: Record<string, string>): Record<string, string>;
|
|
112
|
+
export declare function flatten(tree: MessageTree, prefix?: string, out?: Record<string, string>): Record<string, string>;
|
|
111
113
|
//#endregion
|
|
112
114
|
//#region src/tags.d.ts
|
|
113
115
|
type TagNode = string | {
|
|
114
116
|
name: string;
|
|
115
117
|
children: TagNode[];
|
|
116
118
|
};
|
|
117
|
-
declare function parseTags(text: string): TagNode[];
|
|
119
|
+
export declare function parseTags(text: string): TagNode[];
|
|
118
120
|
//#endregion
|
|
119
121
|
//#region src/warn.d.ts
|
|
120
|
-
declare function warnOnce(message: string): void;
|
|
122
|
+
export declare function warnOnce(message: string): void;
|
|
121
123
|
//#endregion
|
|
122
|
-
export { type AlternateLink, type AlternateLinksOptions, type BindDomOptions, type DictionaryInput, type FlatKeys, type FormatInfo, type Formatter, type IcuParser, type KeysOf,
|
|
124
|
+
export { type AddMessagesOptions, type AlternateLink, type AlternateLinksOptions, type BindDomOptions, type DictionaryInput, type FlatKeys, type FormatInfo, type Formatter, type IcuParser, type KeysOf, type LocaleFromPathOptions, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type Routing, type StripLocalePathOptions, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, type Verbaly, type VerbalyOptions, parse };
|
|
123
125
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -738,6 +738,8 @@ function createVerbaly(options = {}) {
|
|
|
738
738
|
let version = 0;
|
|
739
739
|
let chainCache = null;
|
|
740
740
|
if (options.messages) for (const [loc, tree] of Object.entries(options.messages)) dict[loc] = flatten(tree);
|
|
741
|
+
const partial = new Set(options.partial ?? []);
|
|
742
|
+
for (const loc of partial) loaded.add(loc);
|
|
741
743
|
function chain() {
|
|
742
744
|
if (chainCache) return chainCache;
|
|
743
745
|
const result = narrowLocales(locale);
|
|
@@ -756,6 +758,7 @@ function createVerbaly(options = {}) {
|
|
|
756
758
|
}
|
|
757
759
|
function translate(key, params) {
|
|
758
760
|
const hit = lookup(key);
|
|
761
|
+
if (partial.size > 0 && (hit === void 0 || !partial.has(hit.from))) completePartial(key);
|
|
759
762
|
if (hit === void 0) {
|
|
760
763
|
const replacement = options.onMissing?.(key, locale);
|
|
761
764
|
const value = typeof replacement === "string" ? replacement : key;
|
|
@@ -803,6 +806,16 @@ function createVerbaly(options = {}) {
|
|
|
803
806
|
warnOnce(`failed to load catalog for "${target}"`);
|
|
804
807
|
});
|
|
805
808
|
}
|
|
809
|
+
function completePartial(key) {
|
|
810
|
+
for (const candidate of chain()) {
|
|
811
|
+
if (!partial.has(candidate)) continue;
|
|
812
|
+
if (dict[candidate]?.[key] !== void 0) return;
|
|
813
|
+
partial.delete(candidate);
|
|
814
|
+
loaded.delete(candidate);
|
|
815
|
+
autoLoad(candidate);
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
806
819
|
function pendingLoader(target) {
|
|
807
820
|
for (const candidate of narrowLocales(target)) if (loaders[candidate]) return loaded.has(candidate) ? void 0 : candidate;
|
|
808
821
|
}
|
|
@@ -822,7 +835,11 @@ function createVerbaly(options = {}) {
|
|
|
822
835
|
inFlight.set(pending, load);
|
|
823
836
|
return load;
|
|
824
837
|
}
|
|
825
|
-
function addMessages(loc, messages) {
|
|
838
|
+
function addMessages(loc, messages, opts) {
|
|
839
|
+
if (opts?.partial && !loaded.has(loc) && !inFlight.has(loc)) {
|
|
840
|
+
partial.add(loc);
|
|
841
|
+
loaded.add(loc);
|
|
842
|
+
}
|
|
826
843
|
dict[loc] = {
|
|
827
844
|
...dict[loc],
|
|
828
845
|
...flatten(messages)
|
|
@@ -982,6 +999,18 @@ const RICH_TAGS = [
|
|
|
982
999
|
"br",
|
|
983
1000
|
"wbr"
|
|
984
1001
|
];
|
|
1002
|
+
const CATALOG_SCRIPT = "data-verbaly-catalog";
|
|
1003
|
+
function inlineMessages(root) {
|
|
1004
|
+
const scope = root ?? (typeof document === "undefined" ? void 0 : document);
|
|
1005
|
+
if (!scope) return void 0;
|
|
1006
|
+
const node = scope.querySelector(`script[${CATALOG_SCRIPT}]`);
|
|
1007
|
+
if (!node?.textContent) return void 0;
|
|
1008
|
+
try {
|
|
1009
|
+
const parsed = JSON.parse(node.textContent);
|
|
1010
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return parsed;
|
|
1011
|
+
} catch {}
|
|
1012
|
+
warnOnce("inline catalog is not a usable object, so the page loads its locale instead");
|
|
1013
|
+
}
|
|
985
1014
|
function bindDom(instance, options = {}) {
|
|
986
1015
|
if (typeof document === "undefined") throw new Error("[verbaly] bindDom requires a DOM");
|
|
987
1016
|
const t = instance.t;
|
|
@@ -1043,9 +1072,8 @@ function bindDom(instance, options = {}) {
|
|
|
1043
1072
|
} else renderRich(el, node.children, links);
|
|
1044
1073
|
}
|
|
1045
1074
|
}
|
|
1046
|
-
let trustServerHtml = true;
|
|
1047
1075
|
let reportedKept = false;
|
|
1048
|
-
function holdBack(key, current) {
|
|
1076
|
+
function holdBack(key, current, trusted) {
|
|
1049
1077
|
if (!current?.trim()) return false;
|
|
1050
1078
|
const hit = instance.inspect(key);
|
|
1051
1079
|
if (!hit) {
|
|
@@ -1055,12 +1083,12 @@ function bindDom(instance, options = {}) {
|
|
|
1055
1083
|
}
|
|
1056
1084
|
return true;
|
|
1057
1085
|
}
|
|
1058
|
-
return
|
|
1086
|
+
return trusted && hit.from !== instance.locale;
|
|
1059
1087
|
}
|
|
1060
|
-
function render(el) {
|
|
1088
|
+
function render(el, trusted) {
|
|
1061
1089
|
const args = cachedArgs(el);
|
|
1062
1090
|
const key = el.getAttribute(attr);
|
|
1063
|
-
if (key && !holdBack(key, el.textContent)) {
|
|
1091
|
+
if (key && !holdBack(key, el.textContent, trusted)) {
|
|
1064
1092
|
const text = t(key, args);
|
|
1065
1093
|
if (el.hasAttribute(richAttr)) {
|
|
1066
1094
|
el.textContent = "";
|
|
@@ -1071,25 +1099,24 @@ function bindDom(instance, options = {}) {
|
|
|
1071
1099
|
const attrMap = fromCache(attrsCache, el, rawAttrs, () => parseArgs(rawAttrs));
|
|
1072
1100
|
if (attrMap) for (const [name, attrKey] of Object.entries(attrMap)) {
|
|
1073
1101
|
if (typeof attrKey !== "string") continue;
|
|
1074
|
-
if (holdBack(attrKey, el.getAttribute(name))) continue;
|
|
1102
|
+
if (holdBack(attrKey, el.getAttribute(name), trusted)) continue;
|
|
1075
1103
|
const value = safeAttribute(name, t(attrKey, args));
|
|
1076
1104
|
if (value !== void 0) el.setAttribute(name, value);
|
|
1077
1105
|
}
|
|
1078
1106
|
}
|
|
1079
1107
|
const selector = `[${attr}], [${attrsAttr}]`;
|
|
1080
|
-
function renderAll(scope) {
|
|
1081
|
-
if (scope instanceof Element && scope.matches(selector)) render(scope);
|
|
1082
|
-
for (const el of scope.querySelectorAll(selector)) render(el);
|
|
1108
|
+
function renderAll(scope, trusted) {
|
|
1109
|
+
if (scope instanceof Element && scope.matches(selector)) render(scope, trusted);
|
|
1110
|
+
for (const el of scope.querySelectorAll(selector)) render(el, trusted);
|
|
1083
1111
|
}
|
|
1084
1112
|
warnOnLangMismatch(instance.locale);
|
|
1085
1113
|
warnOnUnboundHead(root, selector);
|
|
1086
|
-
renderAll(root);
|
|
1087
|
-
|
|
1088
|
-
const unsubscribe = instance.subscribe(() => renderAll(root));
|
|
1114
|
+
renderAll(root, true);
|
|
1115
|
+
const unsubscribe = instance.subscribe(() => renderAll(root, false));
|
|
1089
1116
|
const observer = new MutationObserver((records) => {
|
|
1090
|
-
for (const record of records) if (record.type === "attributes" && record.target instanceof Element) render(record.target);
|
|
1117
|
+
for (const record of records) if (record.type === "attributes" && record.target instanceof Element) render(record.target, false);
|
|
1091
1118
|
else if (record.type === "childList") {
|
|
1092
|
-
for (const node of record.addedNodes) if (node instanceof Element) renderAll(node);
|
|
1119
|
+
for (const node of record.addedNodes) if (node instanceof Element) renderAll(node, true);
|
|
1093
1120
|
}
|
|
1094
1121
|
});
|
|
1095
1122
|
observer.observe(root instanceof Document ? root.documentElement : root, {
|
|
@@ -1167,6 +1194,6 @@ const relativeFormatter = (value, locale, arg, info) => {
|
|
|
1167
1194
|
}
|
|
1168
1195
|
};
|
|
1169
1196
|
//#endregion
|
|
1170
|
-
export { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, bindDom, createVerbaly, flatten, localeDirection, localeFromPath, localeName, localePath, negotiateLocale, normalizeLink, parse, parseIcu, parseTags, persistLocale, relativeFormatter, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, stripLocalePath, switchLocale, warnOnce };
|
|
1197
|
+
export { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, bindDom, createVerbaly, flatten, inlineMessages, localeDirection, localeFromPath, localeName, localePath, negotiateLocale, normalizeLink, parse, parseIcu, parseTags, persistLocale, relativeFormatter, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, stripLocalePath, switchLocale, warnOnce };
|
|
1171
1198
|
|
|
1172
1199
|
//# sourceMappingURL=index.js.map
|