zx-kit 0.20.0 → 0.21.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/i18n.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * i18n.ts — locale selection helper.
3
+ *
4
+ * A tiny, dependency-free utility for picking a string pack at runtime
5
+ * based on a language code. Designed so any zx-kit game can ship with
6
+ * multiple translations and switch them via a single config flag.
7
+ *
8
+ * USAGE
9
+ * ─────
10
+ * Each locale exports the same shape — usually as named string constants
11
+ * and template functions (e.g. `STR_DEPTH = (m) => \`D:${m}M\``).
12
+ * Import each locale module as a namespace and hand them to `pickLocale`:
13
+ *
14
+ * import * as en from './strings.ts' // default English
15
+ * import * as sk from './strings.sk.ts' // Slovak
16
+ * import * as ru from './strings.ru.ts' // Russian
17
+ * import { LANGUAGE_CODE } from './config.ts'
18
+ *
19
+ * export const L = pickLocale(en, { sk, ru }, LANGUAGE_CODE)
20
+ *
21
+ * Consumers then read `L.STR_DEPTH(120)` etc. — same name, swapped values.
22
+ *
23
+ * SELECTION RULES
24
+ * ───────────────
25
+ * - `code` null / undefined / empty → returns `defaultLocale`
26
+ * - `code` matches a key in `locales` → returns that locale
27
+ * (case-insensitive: 'SK' === 'sk')
28
+ * - `code` doesn't match anything → returns `defaultLocale`
29
+ *
30
+ * The default key (typically 'en') doesn't need to live in the `locales`
31
+ * map — passing 'en' simply falls through to `defaultLocale`. This keeps
32
+ * the English source-of-truth file at the conventional `strings.ts` path
33
+ * without forcing a `strings.en.ts` rename.
34
+ */
35
+ /**
36
+ * Pick a locale object from a map by code, with fallback to a default.
37
+ *
38
+ * Generic over `T` so every entry in `locales` is type-checked against the
39
+ * shape of `defaultLocale` — adding a new translation that misses a key
40
+ * (or has a wrong signature) becomes a compile error.
41
+ */
42
+ export declare function pickLocale<T>(defaultLocale: T, locales: Record<string, T>, code: string | null | undefined): T;
43
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,aAAa,EAAE,CAAC,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC9B,CAAC,CAIH"}
package/dist/i18n.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * i18n.ts — locale selection helper.
3
+ *
4
+ * A tiny, dependency-free utility for picking a string pack at runtime
5
+ * based on a language code. Designed so any zx-kit game can ship with
6
+ * multiple translations and switch them via a single config flag.
7
+ *
8
+ * USAGE
9
+ * ─────
10
+ * Each locale exports the same shape — usually as named string constants
11
+ * and template functions (e.g. `STR_DEPTH = (m) => \`D:${m}M\``).
12
+ * Import each locale module as a namespace and hand them to `pickLocale`:
13
+ *
14
+ * import * as en from './strings.ts' // default English
15
+ * import * as sk from './strings.sk.ts' // Slovak
16
+ * import * as ru from './strings.ru.ts' // Russian
17
+ * import { LANGUAGE_CODE } from './config.ts'
18
+ *
19
+ * export const L = pickLocale(en, { sk, ru }, LANGUAGE_CODE)
20
+ *
21
+ * Consumers then read `L.STR_DEPTH(120)` etc. — same name, swapped values.
22
+ *
23
+ * SELECTION RULES
24
+ * ───────────────
25
+ * - `code` null / undefined / empty → returns `defaultLocale`
26
+ * - `code` matches a key in `locales` → returns that locale
27
+ * (case-insensitive: 'SK' === 'sk')
28
+ * - `code` doesn't match anything → returns `defaultLocale`
29
+ *
30
+ * The default key (typically 'en') doesn't need to live in the `locales`
31
+ * map — passing 'en' simply falls through to `defaultLocale`. This keeps
32
+ * the English source-of-truth file at the conventional `strings.ts` path
33
+ * without forcing a `strings.en.ts` rename.
34
+ */
35
+ /**
36
+ * Pick a locale object from a map by code, with fallback to a default.
37
+ *
38
+ * Generic over `T` so every entry in `locales` is type-checked against the
39
+ * shape of `defaultLocale` — adding a new translation that misses a key
40
+ * (or has a wrong signature) becomes a compile error.
41
+ */
42
+ export function pickLocale(defaultLocale, locales, code) {
43
+ if (!code)
44
+ return defaultLocale;
45
+ const normalised = code.toLowerCase();
46
+ return locales[normalised] ?? defaultLocale;
47
+ }
48
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,aAAgB,EAChB,OAA0B,EAC1B,IAA+B;IAE/B,IAAI,CAAC,IAAI;QAAE,OAAO,aAAa,CAAA;IAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IACrC,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,aAAa,CAAA;AAC7C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -12,4 +12,5 @@ export * from './animation.js';
12
12
  export * from './camera.js';
13
13
  export * from './scene.js';
14
14
  export * from './save.js';
15
+ export * from './i18n.js';
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -12,4 +12,5 @@ export * from './animation.js';
12
12
  export * from './camera.js';
13
13
  export * from './scene.js';
14
14
  export * from './save.js';
15
+ export * from './i18n.js';
15
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zx-kit",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/zrebec/zx-kit.git"