prosebook 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +595 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +508 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-CF7HziDa.d.ts +498 -0
- package/dist/config-CF7HziDa.d.ts.map +1 -0
- package/dist/config-CxVMn19f.js +1146 -0
- package/dist/config-CxVMn19f.js.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/dist/copy-DXnzXsJa.d.ts +162 -0
- package/dist/copy-DXnzXsJa.d.ts.map +1 -0
- package/dist/helpers-BPuPGjQP.js +61 -0
- package/dist/helpers-BPuPGjQP.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +188 -0
- package/dist/index.js.map +1 -0
- package/dist/inspector.d.ts +37 -0
- package/dist/inspector.d.ts.map +1 -0
- package/dist/inspector.js +572 -0
- package/dist/inspector.js.map +1 -0
- package/dist/react/index.d.ts +37 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +86 -0
- package/dist/react/index.js.map +1 -0
- package/dist/sarif-PkPvsB07.js +1033 -0
- package/dist/sarif-PkPvsB07.js.map +1 -0
- package/dist/scan-B0tZ7y-D.js +2447 -0
- package/dist/scan-B0tZ7y-D.js.map +1 -0
- package/dist/tools.d.ts +351 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +4 -0
- package/dist/vite.d.ts +15 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +238 -0
- package/dist/vite.js.map +1 -0
- package/package.json +148 -15
- package/src/cli.ts +528 -0
- package/src/index.ts +31 -0
- package/src/inspector-dialog.ts +450 -0
- package/src/inspector.ts +228 -0
- package/src/react/index.tsx +112 -0
- package/src/runtime/copy.ts +221 -0
- package/src/runtime/helpers.ts +66 -0
- package/src/runtime/locale.ts +49 -0
- package/src/runtime/types.ts +106 -0
- package/src/tools/catalog.ts +449 -0
- package/src/tools/compile.ts +110 -0
- package/src/tools/config.ts +195 -0
- package/src/tools/diff.ts +84 -0
- package/src/tools/entry.ts +325 -0
- package/src/tools/extract.ts +694 -0
- package/src/tools/generate.ts +259 -0
- package/src/tools/icu.ts +182 -0
- package/src/tools/index.ts +78 -0
- package/src/tools/lint.ts +828 -0
- package/src/tools/lock.ts +95 -0
- package/src/tools/mf1.ts +246 -0
- package/src/tools/mf2.ts +752 -0
- package/src/tools/migrate.ts +138 -0
- package/src/tools/presets.ts +159 -0
- package/src/tools/pseudo.ts +40 -0
- package/src/tools/sarif.ts +80 -0
- package/src/tools/scan.ts +173 -0
- package/src/tools/syntax.ts +24 -0
- package/src/tools/types.ts +137 -0
- package/src/vite.ts +252 -0
- package/index.js +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { n as flatten, t as createHelpers } from "./helpers-BPuPGjQP.js";
|
|
2
|
+
// src/runtime/locale.ts
|
|
3
|
+
/**
|
|
4
|
+
* Picks the best available locale for what was asked, in the order it was asked.
|
|
5
|
+
*
|
|
6
|
+
* Each requested tag tries an exact match, then its parents (`pt-BR` finds `pt`), then any locale
|
|
7
|
+
* of the same language (`pt` finds `pt-BR`). Matching ignores case, as BCP 47 does.
|
|
8
|
+
*/
|
|
9
|
+
function negotiate(requested, available, fallback) {
|
|
10
|
+
const find = (tag) => available.find((a) => a.toLowerCase() === tag.toLowerCase());
|
|
11
|
+
for (const want of typeof requested === "string" ? [requested] : requested) {
|
|
12
|
+
let tag = want;
|
|
13
|
+
for (;;) {
|
|
14
|
+
const found = find(tag);
|
|
15
|
+
if (found !== void 0) return found;
|
|
16
|
+
const cut = tag.lastIndexOf("-");
|
|
17
|
+
if (cut < 0) break;
|
|
18
|
+
tag = tag.slice(0, cut);
|
|
19
|
+
}
|
|
20
|
+
const language = languageOf(want);
|
|
21
|
+
const sibling = available.find((a) => languageOf(a) === language);
|
|
22
|
+
if (sibling !== void 0) return sibling;
|
|
23
|
+
}
|
|
24
|
+
return fallback;
|
|
25
|
+
}
|
|
26
|
+
/** The locales a message is looked up in, in order: the locale, its available parents, then the source. */
|
|
27
|
+
function chainOf(locale, available, source) {
|
|
28
|
+
const chain = [locale];
|
|
29
|
+
let tag = locale;
|
|
30
|
+
while (tag.includes("-")) {
|
|
31
|
+
tag = tag.slice(0, tag.lastIndexOf("-"));
|
|
32
|
+
const parent = available.find((a) => a.toLowerCase() === tag.toLowerCase());
|
|
33
|
+
if (parent !== void 0 && !chain.includes(parent)) chain.push(parent);
|
|
34
|
+
}
|
|
35
|
+
if (!chain.includes(source)) chain.push(source);
|
|
36
|
+
return chain;
|
|
37
|
+
}
|
|
38
|
+
/** The locales the browser or the environment asks for, most preferred first. */
|
|
39
|
+
function preferredLocales() {
|
|
40
|
+
const nav = globalThis.navigator;
|
|
41
|
+
if (nav?.languages && nav.languages.length > 0) return [...nav.languages];
|
|
42
|
+
if (nav?.language) return [nav.language];
|
|
43
|
+
const resolved = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
44
|
+
return resolved ? [resolved] : [];
|
|
45
|
+
}
|
|
46
|
+
function languageOf(tag) {
|
|
47
|
+
return tag.split("-", 1)[0].toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
// src/runtime/copy.ts
|
|
50
|
+
/** Ties a generated catalog to its message shapes. Called by generated code. */
|
|
51
|
+
function defineCatalog(catalog) {
|
|
52
|
+
return catalog;
|
|
53
|
+
}
|
|
54
|
+
/** A message as the text it puts on screen: rendered again with its tags left as their text. */
|
|
55
|
+
function textOf(message, values, h) {
|
|
56
|
+
if (typeof message === "string") return message;
|
|
57
|
+
const plain = Object.fromEntries(Object.entries(values).filter(([, v]) => typeof v !== "function"));
|
|
58
|
+
return flatten(message(plain, h)).join("");
|
|
59
|
+
}
|
|
60
|
+
/** A catalog reader with a current locale. Create one per app, or one per request on a server. */
|
|
61
|
+
function createCopy(catalog, options = {}) {
|
|
62
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
63
|
+
const pending = /* @__PURE__ */ new Map();
|
|
64
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
65
|
+
const defaultTags = options.tags ?? {};
|
|
66
|
+
const formatters = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const [locale, messages] of Object.entries(catalog.messages)) loaded.set(locale, {
|
|
68
|
+
messages,
|
|
69
|
+
h: createHelpers(locale)
|
|
70
|
+
});
|
|
71
|
+
let locale = catalog.source;
|
|
72
|
+
let chain = layers(chainOf(locale, catalog.locales, catalog.source));
|
|
73
|
+
let latest = 0;
|
|
74
|
+
let version = 0;
|
|
75
|
+
function changed() {
|
|
76
|
+
version++;
|
|
77
|
+
for (const listener of listeners) listener();
|
|
78
|
+
}
|
|
79
|
+
globalThis.__PROSEBOOK_HOT__?.add((l, messages) => {
|
|
80
|
+
const layer = loaded.get(l);
|
|
81
|
+
if (layer === void 0) return;
|
|
82
|
+
layer.messages = messages;
|
|
83
|
+
changed();
|
|
84
|
+
});
|
|
85
|
+
function layers(locales) {
|
|
86
|
+
return locales.flatMap((l) => loaded.get(l) ?? []);
|
|
87
|
+
}
|
|
88
|
+
function load(l) {
|
|
89
|
+
const done = loaded.get(l);
|
|
90
|
+
if (done) return Promise.resolve(done);
|
|
91
|
+
let p = pending.get(l);
|
|
92
|
+
if (p === void 0) {
|
|
93
|
+
const loader = catalog.loaders[l];
|
|
94
|
+
if (loader === void 0) return Promise.reject(/* @__PURE__ */ new Error(`prosebook: no messages for locale "${l}"`));
|
|
95
|
+
p = loader().then((mod) => {
|
|
96
|
+
const layer = {
|
|
97
|
+
messages: mod.default,
|
|
98
|
+
h: createHelpers(l)
|
|
99
|
+
};
|
|
100
|
+
loaded.set(l, layer);
|
|
101
|
+
pending.delete(l);
|
|
102
|
+
return layer;
|
|
103
|
+
});
|
|
104
|
+
p.catch(() => pending.delete(l));
|
|
105
|
+
pending.set(l, p);
|
|
106
|
+
}
|
|
107
|
+
return p;
|
|
108
|
+
}
|
|
109
|
+
async function setLocale(next) {
|
|
110
|
+
const target = negotiate(next, catalog.locales, catalog.source);
|
|
111
|
+
const ticket = ++latest;
|
|
112
|
+
const locales = chainOf(target, catalog.locales, catalog.source);
|
|
113
|
+
await Promise.all(locales.map(load));
|
|
114
|
+
if (ticket !== latest || target === locale) return;
|
|
115
|
+
locale = target;
|
|
116
|
+
chain = layers(locales);
|
|
117
|
+
formatters.clear();
|
|
118
|
+
changed();
|
|
119
|
+
}
|
|
120
|
+
function find(key) {
|
|
121
|
+
for (const layer of chain) {
|
|
122
|
+
const message = layer.messages[key];
|
|
123
|
+
if (message !== void 0) return [message, layer.h];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function render(key, values) {
|
|
127
|
+
const found = find(key);
|
|
128
|
+
if (found === void 0) return options.onMissing ? options.onMissing(key, locale) : key;
|
|
129
|
+
const [message, h] = found;
|
|
130
|
+
const out = typeof message === "string" ? message : message(values, h);
|
|
131
|
+
const read = globalThis.__PROSEBOOK_READ__;
|
|
132
|
+
if (read !== void 0) read(key, typeof out === "string" ? out : textOf(message, values, h), h.locale);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function formatter(kind, options, make) {
|
|
136
|
+
const id = `${kind}${JSON.stringify(options ?? {})}`;
|
|
137
|
+
let made = formatters.get(id);
|
|
138
|
+
if (made === void 0) formatters.set(id, made = make());
|
|
139
|
+
return made;
|
|
140
|
+
}
|
|
141
|
+
const ready = options.locale === void 0 ? Promise.resolve() : setLocale(options.locale);
|
|
142
|
+
return {
|
|
143
|
+
get locale() {
|
|
144
|
+
return locale;
|
|
145
|
+
},
|
|
146
|
+
get version() {
|
|
147
|
+
return version;
|
|
148
|
+
},
|
|
149
|
+
locales: catalog.locales,
|
|
150
|
+
source: catalog.source,
|
|
151
|
+
tags: defaultTags,
|
|
152
|
+
ready,
|
|
153
|
+
t(key, ...args) {
|
|
154
|
+
const out = render(key, args[0] ?? {});
|
|
155
|
+
return typeof out === "string" ? out : flatten(out).join("");
|
|
156
|
+
},
|
|
157
|
+
rich(key, ...values) {
|
|
158
|
+
const out = render(key, {
|
|
159
|
+
...defaultTags,
|
|
160
|
+
...values[0]
|
|
161
|
+
});
|
|
162
|
+
return flatten(out);
|
|
163
|
+
},
|
|
164
|
+
has(key) {
|
|
165
|
+
return find(key) !== void 0;
|
|
166
|
+
},
|
|
167
|
+
setLocale,
|
|
168
|
+
subscribe(listener) {
|
|
169
|
+
listeners.add(listener);
|
|
170
|
+
return () => listeners.delete(listener);
|
|
171
|
+
},
|
|
172
|
+
number(value, opts) {
|
|
173
|
+
return formatter("n", opts, () => new Intl.NumberFormat(locale, opts)).format(value);
|
|
174
|
+
},
|
|
175
|
+
date(value, opts) {
|
|
176
|
+
return formatter("d", opts, () => new Intl.DateTimeFormat(locale, opts)).format(value);
|
|
177
|
+
},
|
|
178
|
+
list(items, opts) {
|
|
179
|
+
return formatter("l", opts, () => new Intl.ListFormat(locale, opts)).format(items);
|
|
180
|
+
},
|
|
181
|
+
relative(value, unit, opts) {
|
|
182
|
+
return formatter("r", opts, () => new Intl.RelativeTimeFormat(locale, opts)).format(value, unit);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
export { chainOf, createCopy, createHelpers, defineCatalog, flatten, negotiate, preferredLocales };
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/runtime/locale.ts","../src/runtime/copy.ts"],"sourcesContent":["/**\n * Picks the best available locale for what was asked, in the order it was asked.\n *\n * Each requested tag tries an exact match, then its parents (`pt-BR` finds `pt`), then any locale\n * of the same language (`pt` finds `pt-BR`). Matching ignores case, as BCP 47 does.\n */\nexport function negotiate<L extends string>(requested: string | readonly string[], available: readonly L[], fallback: L): L {\n const find = (tag: string) => available.find((a) => a.toLowerCase() === tag.toLowerCase());\n for (const want of typeof requested === 'string' ? [requested] : requested) {\n let tag = want;\n for (;;) {\n const found = find(tag);\n if (found !== undefined) return found;\n const cut = tag.lastIndexOf('-');\n if (cut < 0) break;\n tag = tag.slice(0, cut);\n }\n const language = languageOf(want);\n const sibling = available.find((a) => languageOf(a) === language);\n if (sibling !== undefined) return sibling;\n }\n return fallback;\n}\n\n/** The locales a message is looked up in, in order: the locale, its available parents, then the source. */\nexport function chainOf<L extends string>(locale: L, available: readonly L[], source: L): L[] {\n const chain: L[] = [locale];\n let tag: string = locale;\n while (tag.includes('-')) {\n tag = tag.slice(0, tag.lastIndexOf('-'));\n const parent = available.find((a) => a.toLowerCase() === tag.toLowerCase());\n if (parent !== undefined && !chain.includes(parent)) chain.push(parent);\n }\n if (!chain.includes(source)) chain.push(source);\n return chain;\n}\n\n/** The locales the browser or the environment asks for, most preferred first. */\nexport function preferredLocales(): string[] {\n const nav = (globalThis as { navigator?: { languages?: readonly string[]; language?: string } }).navigator;\n if (nav?.languages && nav.languages.length > 0) return [...nav.languages];\n if (nav?.language) return [nav.language];\n const resolved = Intl.DateTimeFormat().resolvedOptions().locale;\n return resolved ? [resolved] : [];\n}\n\nfunction languageOf(tag: string): string {\n return tag.split('-', 1)[0]!.toLowerCase();\n}\n","import { createHelpers, flatten } from './helpers.ts';\nimport { chainOf, negotiate } from './locale.ts';\nimport type {\n AnyTagFn,\n ArgsParam,\n Chunks,\n Compiled,\n CompiledMessages,\n Helpers,\n DevHooks,\n MessageShapes,\n RichKey,\n RichParam,\n Values,\n} from './types.ts';\n\ntype Loader = () => Promise<{ default: CompiledMessages }>;\n\n/** A generated catalog: which locales exist, which ship in the bundle and how to fetch the rest. */\nexport interface Catalog<M extends MessageShapes = MessageShapes, L extends string = string> {\n /** The locale the catalog is written in, which every other falls back to. */\n readonly source: L;\n readonly locales: readonly L[];\n /** Locales whose messages ship in the bundle. Always holds the source. */\n readonly messages: { readonly [locale in L]?: CompiledMessages };\n /** Locales fetched when first asked for. */\n readonly loaders: { readonly [locale in L]?: Loader };\n /** Type-only: carries the message shapes from the generated module to `createCopy`. */\n readonly '~messages'?: M;\n}\n\n/** Ties a generated catalog to its message shapes. Called by generated code. */\nexport function defineCatalog<M extends MessageShapes, L extends string = string>(\n catalog: Omit<Catalog<M, L>, '~messages'>,\n): Catalog<M, L> {\n return catalog;\n}\n\nexport interface CopyOptions<L extends string> {\n /** The locale to start in, or the locales a reader prefers, most preferred first. Defaults to the source. */\n locale?: L | (string & {}) | readonly string[];\n /** Tag renderers every rich read gets unless it supplies its own, such as `b` or `link`. */\n tags?: { [tag: string]: AnyTagFn };\n /** What a key the catalog lacks reads as. Defaults to the key itself. */\n onMissing?: (key: string, locale: L) => string;\n}\n\n/** Its methods don't use `this`, so they can be passed around and destructured: `const { t } = copy`. */\nexport interface Copy<M extends MessageShapes = MessageShapes, L extends string = string> {\n /** The locale messages are coming back in. */\n readonly locale: L;\n readonly locales: readonly L[];\n readonly source: L;\n /** The tag renderers rich reads fall back to, from `CopyOptions.tags`. */\n readonly tags: { readonly [tag: string]: AnyTagFn };\n /** Settles once the starting locale's messages are loaded. */\n readonly ready: Promise<void>;\n /** A message as plain text. Tags render as the text they wrap. */\n t<K extends keyof M & string>(this: void, key: K, ...args: ArgsParam<M[K]>): string;\n /** A message with elements inside it: each tag's function turns what it wraps into a node. */\n rich<K extends RichKey<M>, N = unknown>(this: void, key: K, ...values: RichParam<M[K], N>): Chunks<N>;\n has(this: void, key: string): key is keyof M & string;\n /** Switches locale once its messages (and its fallbacks') are loaded. */\n setLocale(this: void, next: L | (string & {}) | readonly string[]): Promise<void>;\n /** Counts changes to what messages read as: each locale switch, and each catalog edit in dev. */\n readonly version: number;\n /** Called after each locale switch, and in dev after each catalog edit. Returns the unsubscribe. */\n subscribe(this: void, listener: () => void): () => void;\n /** Formats a number in the current locale. */\n number(this: void, value: number | bigint, options?: Intl.NumberFormatOptions): string;\n /** Formats a date in the current locale. */\n date(this: void, value: Date | number, options?: Intl.DateTimeFormatOptions): string;\n /** Joins items as a list in the current locale: `a, b and c`. */\n list(this: void, items: Iterable<string>, options?: Intl.ListFormatOptions): string;\n /** `in 3 days`, `2 hours ago`, in the current locale. */\n relative(this: void, value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string;\n}\n\ntype Layer = { messages: CompiledMessages; h: Helpers };\n\n/** A message as the text it puts on screen: rendered again with its tags left as their text. */\nfunction textOf(message: Compiled, values: Values, h: Helpers): string {\n if (typeof message === 'string') return message;\n const plain = Object.fromEntries(Object.entries(values).filter(([, v]) => typeof v !== 'function'));\n return flatten(message(plain, h)).join('');\n}\n\n/** A catalog reader with a current locale. Create one per app, or one per request on a server. */\nexport function createCopy<M extends MessageShapes, L extends string>(catalog: Catalog<M, L>, options: CopyOptions<L> = {}): Copy<M, L> {\n const loaded = new Map<L, Layer>();\n const pending = new Map<L, Promise<Layer>>();\n const listeners = new Set<() => void>();\n const defaultTags = options.tags ?? {};\n const formatters = new Map<string, Intl.NumberFormat | Intl.DateTimeFormat | Intl.ListFormat | Intl.RelativeTimeFormat>();\n\n for (const [locale, messages] of Object.entries(catalog.messages) as [L, CompiledMessages][])\n loaded.set(locale, { messages, h: createHelpers(locale) });\n\n let locale = catalog.source;\n let chain: Layer[] = layers(chainOf(locale, catalog.locales, catalog.source));\n let latest = 0;\n let version = 0;\n\n function changed() {\n version++;\n for (const listener of listeners) listener();\n }\n\n // A layer's messages are swapped in place, so the chain that holds it reads the new ones.\n (globalThis as DevHooks).__PROSEBOOK_HOT__?.add((l, messages) => {\n const layer = loaded.get(l as L);\n if (layer === undefined) return;\n layer.messages = messages;\n changed();\n });\n\n function layers(locales: L[]): Layer[] {\n return locales.flatMap((l) => loaded.get(l) ?? []);\n }\n\n function load(l: L): Promise<Layer> {\n const done = loaded.get(l);\n if (done) return Promise.resolve(done);\n let p = pending.get(l);\n if (p === undefined) {\n // oxlint-disable-next-line typescript/no-unsafe-enum-assignment -- `L` is a string union, not an enum; the rule misreads the mapped type\n const loader = catalog.loaders[l];\n if (loader === undefined) return Promise.reject(new Error(`prosebook: no messages for locale \"${l}\"`));\n p = loader().then((mod) => {\n const layer = { messages: mod.default, h: createHelpers(l) };\n loaded.set(l, layer);\n pending.delete(l);\n return layer;\n });\n p.catch(() => pending.delete(l));\n pending.set(l, p);\n }\n return p;\n }\n\n async function setLocale(next: L | (string & {}) | readonly string[]): Promise<void> {\n const target = negotiate(next, catalog.locales, catalog.source);\n const ticket = ++latest;\n const locales = chainOf(target, catalog.locales, catalog.source);\n await Promise.all(locales.map(load));\n // A slower load must not undo a later switch.\n if (ticket !== latest || target === locale) return;\n locale = target;\n chain = layers(locales);\n formatters.clear();\n changed();\n }\n\n function find(key: string): [Compiled, Helpers] | undefined {\n for (const layer of chain) {\n const message = layer.messages[key];\n if (message !== undefined) return [message, layer.h];\n }\n return undefined;\n }\n\n function render(key: string, values: Values): unknown {\n const found = find(key);\n if (found === undefined) return options.onMissing ? options.onMissing(key, locale) : key;\n const [message, h] = found;\n const out = typeof message === 'string' ? message : message(values, h);\n const read = (globalThis as DevHooks).__PROSEBOOK_READ__;\n if (read !== undefined) read(key, typeof out === 'string' ? out : textOf(message, values, h), h.locale);\n return out;\n }\n\n function formatter<F>(kind: string, options: object | undefined, make: () => F): F {\n const id = `${kind}${JSON.stringify(options ?? {})}`;\n let made = formatters.get(id) as F | undefined;\n if (made === undefined) formatters.set(id, (made = make()) as never);\n return made;\n }\n\n const ready = options.locale === undefined ? Promise.resolve() : setLocale(options.locale);\n\n return {\n get locale() {\n return locale;\n },\n get version() {\n return version;\n },\n locales: catalog.locales,\n source: catalog.source,\n tags: defaultTags,\n ready,\n t(key, ...args) {\n const out = render(key, (args[0] as Values | undefined) ?? {});\n return typeof out === 'string' ? out : flatten(out).join('');\n },\n rich(key, ...values) {\n const out = render(key, { ...defaultTags, ...(values[0] as Values | undefined) });\n return flatten(out) as Chunks<never>;\n },\n has(key): key is keyof M & string {\n return find(key) !== undefined;\n },\n setLocale,\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n number(value, opts) {\n return formatter('n', opts, () => new Intl.NumberFormat(locale, opts)).format(value);\n },\n date(value, opts) {\n return formatter('d', opts, () => new Intl.DateTimeFormat(locale, opts)).format(value);\n },\n list(items, opts) {\n return formatter('l', opts, () => new Intl.ListFormat(locale, opts)).format(items);\n },\n relative(value, unit, opts) {\n return formatter('r', opts, () => new Intl.RelativeTimeFormat(locale, opts)).format(value, unit);\n },\n };\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,UAA4B,WAAuC,WAAyB,UAAgB;CAC1H,MAAM,QAAQ,QAAgB,UAAU,MAAM,MAAM,EAAE,YAAY,MAAM,IAAI,YAAY,CAAC;CACzF,KAAK,MAAM,QAAQ,OAAO,cAAc,WAAW,CAAC,SAAS,IAAI,WAAW;EAC1E,IAAI,MAAM;EACV,SAAS;GACP,MAAM,QAAQ,KAAK,GAAG;GACtB,IAAI,UAAU,KAAA,GAAW,OAAO;GAChC,MAAM,MAAM,IAAI,YAAY,GAAG;GAC/B,IAAI,MAAM,GAAG;GACb,MAAM,IAAI,MAAM,GAAG,GAAG;EACxB;EACA,MAAM,WAAW,WAAW,IAAI;EAChC,MAAM,UAAU,UAAU,MAAM,MAAM,WAAW,CAAC,MAAM,QAAQ;EAChE,IAAI,YAAY,KAAA,GAAW,OAAO;CACpC;CACA,OAAO;AACT;;AAGA,SAAgB,QAA0B,QAAW,WAAyB,QAAgB;CAC5F,MAAM,QAAa,CAAC,MAAM;CAC1B,IAAI,MAAc;CAClB,OAAO,IAAI,SAAS,GAAG,GAAG;EACxB,MAAM,IAAI,MAAM,GAAG,IAAI,YAAY,GAAG,CAAC;EACvC,MAAM,SAAS,UAAU,MAAM,MAAM,EAAE,YAAY,MAAM,IAAI,YAAY,CAAC;EAC1E,IAAI,WAAW,KAAA,KAAa,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,KAAK,MAAM;CACxE;CACA,IAAI,CAAC,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AI,OAAO;GAA0B,CAAC;GAChF,OAAO,QAAQ,GAAG;EACpB;EACA,IAAI,KAA8B;GAChC,OAAO,KAAK,GAAG,MAAM,KAAA;EACvB;EACA;EACA,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa,UAAU,OAAO,QAAQ;EACxC;EACA,OAAO,OAAO,MAAM;GAClB,OAAO,UAAU,KAAK,YAAY,IAAI,KAAK,aAAa,QAAQ,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK;EACrF;EACA,KAAK,OAAO,MAAM;GAChB,OAAO,UAAU,KAAK,YAAY,IAAI,KAAK,eAAe,QAAQ,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK;EACvF;EACA,KAAK,OAAO,MAAM;GAChB,OAAO,UAAU,KAAK,YAAY,IAAI,KAAK,WAAW,QAAQ,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK;EACnF;EACA,SAAS,OAAO,MAAM,MAAM;GAC1B,OAAO,UAAU,KAAK,YAAY,IAAI,KAAK,mBAAmB,QAAQ,IAAI,CAAC,CAAC,CAAC,OAAO,OAAO,IAAI;EACjG;CACF;AACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface Read {
|
|
2
|
+
key: string;
|
|
3
|
+
/** The locale the message was found in. */
|
|
4
|
+
locale: string;
|
|
5
|
+
}
|
|
6
|
+
/** Recent reads by the text they came to, least recent text first; each text's keys most recent first. */
|
|
7
|
+
export type Reads = Map<string, Read[]>;
|
|
8
|
+
/** The character under the pointer: a text node and its index there. */
|
|
9
|
+
export interface Caret {
|
|
10
|
+
node: Node;
|
|
11
|
+
offset: number;
|
|
12
|
+
}
|
|
13
|
+
export interface Hit {
|
|
14
|
+
text: string;
|
|
15
|
+
read: Read;
|
|
16
|
+
/** How many other keys came to the same text. */
|
|
17
|
+
others: number;
|
|
18
|
+
/** The innermost element holding all of the text. */
|
|
19
|
+
element: Element;
|
|
20
|
+
}
|
|
21
|
+
export declare function record(reads: Reads, key: string, text: string, locale: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* The read under the caret: the longest text that covers it, in the innermost element holding all of
|
|
24
|
+
* it. A rich message runs across its elements, so it wins over a shorter text inside one of them.
|
|
25
|
+
* Without a caret (over an input, or padding) an element's whole text, or the target's readable
|
|
26
|
+
* attribute, must equal a read.
|
|
27
|
+
*/
|
|
28
|
+
export declare function keyAt(target: Element, caret: Caret | undefined, reads: Reads): Hit | undefined;
|
|
29
|
+
/** The character under a point on screen, where the browser can say. */
|
|
30
|
+
export declare function caretAt(x: number, y: number): Caret | undefined;
|
|
31
|
+
export interface InspectorOptions {
|
|
32
|
+
/** The dev server's base URL, ending in `/`. */
|
|
33
|
+
base: string;
|
|
34
|
+
}
|
|
35
|
+
/** Starts listening for reads and for Alt on the page. Called by the module the Vite plugin serves. */
|
|
36
|
+
export declare function install({ base }: InspectorOptions): void;
|
|
37
|
+
//# sourceMappingURL=inspector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspector.d.ts","names":[],"sources":["../src/inspector.ts"],"mappings":"A,iBAaiB;EACf;;EAEA;;;YAIU,QAAQ,YAAY;;iBAGf;EACf,MAAM;EACN;;iBAGe;EACf;EACA,MAAM;;EAEN;;EAEA,SAAS;;wBAOK,OAAO,OAAO,OAAO,aAAa,cAAc;;;;;;;wBAchD,MAAM,QAAQ,SAAS,OAAO,mBAAmB,OAAO,QAAQ;;wBAuChE,QAAQ,WAAW,YAAY;iBAgB9B;;EAEf;;;wBAIc,UAAU,QAAQ"}
|