@pie-element/shared-i18n 0.1.1 → 0.1.2-next.20261019062545
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/index.d.ts +1 -0
- package/dist/index.js +129 -1
- package/dist/interface-locale.d.ts +21 -0
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { type Catalogs, type CatalogsOptions, defineCatalogs, isLocaleReady, loadLocale, registerMessages, } from './catalogs.js';
|
|
2
2
|
export { canonicalLanguageTag, elementLanguageAttributes, type LanguageAttributes, stampElementLanguage, } from './element-language.js';
|
|
3
|
+
export { type InterfaceLocaleContextValue, interfaceLocaleContext, subscribeInterfaceLocale, } from './interface-locale.js';
|
|
3
4
|
export { findBestLanguageMatch, languageTagLookupSequence, languageTagsEqual, normalizeLanguageTag, toLanguageTag, } from './language-tags.js';
|
|
4
5
|
export { DEFAULT_LOCALE, dynamicMessageKey, localeDirection, SimpleI18n } from './provider.js';
|
|
5
6
|
export type { CatalogLoader, DynamicMessageKey, I18nConfig, I18nServiceApi, InterpolationValues, MessageCatalog, MessageNode, NestedKeys, PluralOptions, PluralTranslation, TextDirection, Translator, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -319,4 +319,132 @@ function T(e, t) {
|
|
|
319
319
|
n ? (e.setAttribute("lang", n.lang), e.setAttribute("dir", n.dir)) : (e.removeAttribute("lang"), e.removeAttribute("dir"));
|
|
320
320
|
}
|
|
321
321
|
//#endregion
|
|
322
|
-
|
|
322
|
+
//#region ../../../node_modules/.bun/@pie-players+pie-context@1.0.0-beta.3/node_modules/@pie-players/pie-context/dist/events.js
|
|
323
|
+
function E(e, t, n) {
|
|
324
|
+
let r = t.ownerDocument?.defaultView?.Event ?? Event;
|
|
325
|
+
return Object.assign(new r(e, {
|
|
326
|
+
bubbles: !0,
|
|
327
|
+
composed: !0
|
|
328
|
+
}), n);
|
|
329
|
+
}
|
|
330
|
+
var D = /* @__PURE__ */ new WeakSet(), O = (e, t) => typeof t == "object" && !!t && e.has(t), k = class {
|
|
331
|
+
constructor(e, t, n, r) {
|
|
332
|
+
let i = E("context-request", t, {
|
|
333
|
+
context: e,
|
|
334
|
+
contextTarget: t,
|
|
335
|
+
callback: n,
|
|
336
|
+
subscribe: r ?? !1
|
|
337
|
+
});
|
|
338
|
+
return D.add(i), i;
|
|
339
|
+
}
|
|
340
|
+
static [Symbol.hasInstance](e) {
|
|
341
|
+
return O(D, e);
|
|
342
|
+
}
|
|
343
|
+
}, A = (e) => {
|
|
344
|
+
let t = [];
|
|
345
|
+
for (let n of e) n.requestorRef.deref() && n.callbackRef.deref() && t.push(n);
|
|
346
|
+
return t;
|
|
347
|
+
}, j = class {
|
|
348
|
+
host;
|
|
349
|
+
pendingByContext = /* @__PURE__ */ new Map();
|
|
350
|
+
attached = !1;
|
|
351
|
+
constructor(e) {
|
|
352
|
+
this.host = e;
|
|
353
|
+
}
|
|
354
|
+
attach() {
|
|
355
|
+
this.attached || (this.attached = !0, this.host.addEventListener("context-request", this.onContextRequest), this.host.addEventListener("context-provider", this.onContextProvider));
|
|
356
|
+
}
|
|
357
|
+
detach() {
|
|
358
|
+
this.attached && (this.attached = !1, this.host.removeEventListener("context-request", this.onContextRequest), this.host.removeEventListener("context-provider", this.onContextProvider), this.pendingByContext.clear());
|
|
359
|
+
}
|
|
360
|
+
onContextRequest = (e) => {
|
|
361
|
+
if (e.cancelBubble) return;
|
|
362
|
+
let t = e;
|
|
363
|
+
if (t.subscribe !== !0 || typeof t.callback != "function" || t.context === void 0) return;
|
|
364
|
+
let n = t.contextTarget ?? e.composedPath?.()[0];
|
|
365
|
+
if (!n) return;
|
|
366
|
+
let r = this.pendingByContext.get(t.context);
|
|
367
|
+
r || (r = {
|
|
368
|
+
callbacks: /* @__PURE__ */ new WeakMap(),
|
|
369
|
+
requests: []
|
|
370
|
+
}, this.pendingByContext.set(t.context, r));
|
|
371
|
+
let i = t.callback, a = r.callbacks.get(n);
|
|
372
|
+
a || (a = /* @__PURE__ */ new WeakSet(), r.callbacks.set(n, a)), !a.has(i) && (a.add(i), r.requests.push({
|
|
373
|
+
requestorRef: new WeakRef(n),
|
|
374
|
+
callbackRef: new WeakRef(i)
|
|
375
|
+
}), r.requests = A(r.requests));
|
|
376
|
+
};
|
|
377
|
+
onContextProvider = (e) => {
|
|
378
|
+
let t = e.context;
|
|
379
|
+
if (t === void 0) return;
|
|
380
|
+
let n = this.pendingByContext.get(t);
|
|
381
|
+
if (!(!n || n.requests.length === 0)) {
|
|
382
|
+
this.pendingByContext.delete(t);
|
|
383
|
+
for (let e of n.requests) {
|
|
384
|
+
let n = e.requestorRef.deref(), r = e.callbackRef.deref();
|
|
385
|
+
!n || !r || n.dispatchEvent(new k(t, n, r, !0));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
}, M = Symbol.for("pie.context.documentRoot");
|
|
390
|
+
function N(e) {
|
|
391
|
+
if (!e) return;
|
|
392
|
+
let t = e;
|
|
393
|
+
if (t[M]) return;
|
|
394
|
+
let n = e.documentElement;
|
|
395
|
+
if (!n) return;
|
|
396
|
+
let r = new j(n);
|
|
397
|
+
r.attach(), t[M] = r;
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region ../../../node_modules/.bun/@pie-players+pie-context@1.0.0-beta.3/node_modules/@pie-players/pie-context/dist/consumer.js
|
|
401
|
+
var P = class {
|
|
402
|
+
host;
|
|
403
|
+
context;
|
|
404
|
+
subscribe;
|
|
405
|
+
onValue;
|
|
406
|
+
isConnected = !1;
|
|
407
|
+
isDisconnected = !1;
|
|
408
|
+
unsubscribe;
|
|
409
|
+
currentValue;
|
|
410
|
+
constructor(e, t) {
|
|
411
|
+
this.host = e, this.context = t.context, this.subscribe = t.subscribe ?? !0, this.onValue = t.onValue;
|
|
412
|
+
}
|
|
413
|
+
connect() {
|
|
414
|
+
this.isConnected || (this.isConnected = !0, this.isDisconnected = !1, this.subscribe && N(this.host.ownerDocument), this.requestValue());
|
|
415
|
+
}
|
|
416
|
+
disconnect() {
|
|
417
|
+
this.isConnected && (this.isConnected = !1, this.isDisconnected = !0, this.unsubscribe?.(), this.unsubscribe = void 0);
|
|
418
|
+
}
|
|
419
|
+
get value() {
|
|
420
|
+
return this.currentValue;
|
|
421
|
+
}
|
|
422
|
+
handleValue = (e, t) => {
|
|
423
|
+
if (this.isDisconnected) {
|
|
424
|
+
t?.();
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
t !== this.unsubscribe && (this.unsubscribe?.(), this.unsubscribe = t), !this.subscribe && this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0), this.currentValue = e, this.onValue?.(e);
|
|
428
|
+
};
|
|
429
|
+
requestValue() {
|
|
430
|
+
this.host.dispatchEvent(new k(this.context, this.host, this.handleValue, this.subscribe));
|
|
431
|
+
}
|
|
432
|
+
}, F = (e, t, n) => {
|
|
433
|
+
let r = new P(e, {
|
|
434
|
+
context: t,
|
|
435
|
+
subscribe: !0,
|
|
436
|
+
onValue: n
|
|
437
|
+
});
|
|
438
|
+
r.connect();
|
|
439
|
+
let i = (e) => {
|
|
440
|
+
e.context === t && r.requestValue();
|
|
441
|
+
};
|
|
442
|
+
return e.addEventListener("context-provider", i), () => {
|
|
443
|
+
e.removeEventListener("context-provider", i), r.disconnect();
|
|
444
|
+
};
|
|
445
|
+
}, I = ((e) => e)(Symbol.for("pie.interfaceLocale"));
|
|
446
|
+
function L(e, t) {
|
|
447
|
+
return F(e, I, t);
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
450
|
+
export { a as DEFAULT_LOCALE, d as SimpleI18n, C as canonicalLanguageTag, y as defineCatalogs, o as dynamicMessageKey, w as elementLanguageAttributes, i as findBestLanguageMatch, I as interfaceLocaleContext, b as isLocaleReady, r as languageTagLookupSequence, n as languageTagsEqual, x as loadLocale, u as localeDirection, e as normalizeLanguageTag, S as registerMessages, T as stampElementLanguage, L as subscribeInterfaceLocale, t as toLanguageTag };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The value a player publishes: what the chrome should speak, and which way it flows. */
|
|
2
|
+
export interface InterfaceLocaleContextValue {
|
|
3
|
+
locale: string;
|
|
4
|
+
direction: 'ltr' | 'rtl';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Built with pie-context's own factory, exactly as the player half builds its
|
|
8
|
+
* `interfaceLocaleContext`: the `Symbol.for` registration makes the two the
|
|
9
|
+
* same key on the page, and this constant is what the package import replaces
|
|
10
|
+
* once the contract releases.
|
|
11
|
+
*/
|
|
12
|
+
export declare const interfaceLocaleContext: {
|
|
13
|
+
__context__: InterfaceLocaleContextValue;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Calls `onLocale` with the interface locale in effect for `host` whenever a
|
|
17
|
+
* player publishes it, including a change the host makes later. With no
|
|
18
|
+
* player it is never called. Call it from `connectedCallback`, where the
|
|
19
|
+
* request can reach the player; returns the cleanup for `disconnectedCallback`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function subscribeInterfaceLocale(host: Element, onLocale: (value: InterfaceLocaleContextValue) => void): () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/shared-i18n",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2-next.20261019062545",
|
|
4
4
|
"description": "Interface-string i18n engine for PIE elements: typed per-package catalogs, lazy locales, RFC 4647 resolution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"test": "vitest",
|
|
22
22
|
"clean": "rm -rf dist"
|
|
23
23
|
},
|
|
24
|
-
"dependencies": {
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@pie-players/pie-context": "1.0.0-beta.3"
|
|
26
|
+
},
|
|
25
27
|
"publishConfig": {
|
|
26
28
|
"access": "public"
|
|
27
29
|
},
|