@yozora-tech/qfluent 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -20,17 +20,7 @@ const t_search_empty = useT("search-the-web");
20
20
  - npm: https://www.npmjs.com/package/@yozora-tech/qfluent
21
21
  - jsr: https://jsr.io/@yozora-tech/qfluent
22
22
 
23
- ## AI (LLM) Usage
24
-
25
- ### By Human
26
-
27
- - `src/qfluent/*`
28
- - `site/src/routes/*`
29
-
30
- ### By LLM
31
-
32
- - `src/tests/*`
33
- - `site/src/*.css`
23
+ See also [Dev Notes](./dev.md).
34
24
 
35
25
  ## Legal
36
26
 
@@ -0,0 +1 @@
1
+ ["..\\index.qwik.mjs",4,5,"..\\qfluent\\context.qwik.mjs","..\\qfluent\\tools.qwik.mjs","..\\qfluent\\translate.qwik.mjs",3]
@@ -0,0 +1 @@
1
+ ["..\\index.qwik.cjs",4,5,"..\\qfluent\\context.qwik.cjs","..\\qfluent\\tools.qwik.cjs","..\\qfluent\\translate.qwik.cjs",3]
@@ -1,13 +1,12 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const context = require("./qfluent/context.qwik.cjs");
4
- const translate = require("./qfluent/translate.qwik.cjs");
5
- const tools = require("./qfluent/tools.qwik.cjs");
6
- exports.FluentProvider = context.FluentProvider;
7
- exports.useFluentErrors = context.useFluentErrors;
8
- exports.useFluentLocales = context.useFluentLocales;
9
- exports.useFluentResources = context.useFluentResources;
10
- exports.T = translate.T;
11
- exports.useLocalizedTitle = translate.useLocalizedTitle;
12
- exports.useT = translate.useT;
13
- exports.parseAcceptLanguage = tools.parseAcceptLanguage;
2
+ const require_context = require("./qfluent/context.qwik.cjs");
3
+ const require_translate = require("./qfluent/translate.qwik.cjs");
4
+ const require_tools = require("./qfluent/tools.qwik.cjs");
5
+ exports.FluentProvider = require_context.FluentProvider;
6
+ exports.T = require_translate.T;
7
+ exports.parseAcceptLanguage = require_tools.parseAcceptLanguage;
8
+ exports.useFluentErrors = require_context.useFluentErrors;
9
+ exports.useFluentLocales = require_context.useFluentLocales;
10
+ exports.useFluentResources = require_context.useFluentResources;
11
+ exports.useLocalizedTitle = require_translate.useLocalizedTitle;
12
+ exports.useT = require_translate.useT;
@@ -1,13 +1,4 @@
1
1
  import { FluentProvider, useFluentErrors, useFluentLocales, useFluentResources } from "./qfluent/context.qwik.mjs";
2
2
  import { T, useLocalizedTitle, useT } from "./qfluent/translate.qwik.mjs";
3
3
  import { parseAcceptLanguage } from "./qfluent/tools.qwik.mjs";
4
- export {
5
- FluentProvider,
6
- T,
7
- parseAcceptLanguage,
8
- useFluentErrors,
9
- useFluentLocales,
10
- useFluentResources,
11
- useLocalizedTitle,
12
- useT
13
- };
4
+ export { FluentProvider, T, parseAcceptLanguage, useFluentErrors, useFluentLocales, useFluentResources, useLocalizedTitle, useT };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "1",
3
- "manifestHash": "m6gwie",
3
+ "manifestHash": "h4ylak",
4
4
  "options": {
5
5
  "target": "lib",
6
6
  "buildMode": "development",
@@ -8,53 +8,53 @@
8
8
  "type": "inline"
9
9
  }
10
10
  },
11
- "bundleGraphAsset": "assets/DVjQdr_6-bundle-graph.json",
11
+ "bundleGraphAsset": "assets/DLXuL6n7-bundle-graph.json",
12
12
  "injections": [],
13
13
  "mapping": {},
14
14
  "bundles": {
15
- "../index.qwik.cjs": {
16
- "size": 632,
17
- "total": 17193,
15
+ "..\\index.qwik.cjs": {
16
+ "size": 706,
17
+ "total": 18257,
18
18
  "imports": [
19
- "../qfluent/context.qwik.cjs",
20
- "../qfluent/tools.qwik.cjs",
21
- "../qfluent/translate.qwik.cjs"
19
+ "..\\qfluent\\context.qwik.cjs",
20
+ "..\\qfluent\\tools.qwik.cjs",
21
+ "..\\qfluent\\translate.qwik.cjs"
22
22
  ],
23
23
  "origins": [
24
- "src/index.ts"
24
+ "src\\index.ts"
25
25
  ],
26
26
  "interactivity": 0
27
27
  },
28
- "../qfluent/context.qwik.cjs": {
29
- "size": 6830,
30
- "total": 6830,
28
+ "..\\qfluent\\context.qwik.cjs": {
29
+ "size": 7046,
30
+ "total": 7046,
31
31
  "origins": [
32
- "src/qfluent/context.tsx"
32
+ "src\\qfluent\\context.tsx"
33
33
  ],
34
34
  "interactivity": 0
35
35
  },
36
- "../qfluent/tools.qwik.cjs": {
37
- "size": 505,
38
- "total": 505,
36
+ "..\\qfluent\\tools.qwik.cjs": {
37
+ "size": 609,
38
+ "total": 609,
39
39
  "origins": [
40
- "src/qfluent/tools.ts"
40
+ "src\\qfluent\\tools.ts"
41
41
  ],
42
42
  "interactivity": 0
43
43
  },
44
- "../qfluent/translate.qwik.cjs": {
45
- "size": 2396,
46
- "total": 9226,
44
+ "..\\qfluent\\translate.qwik.cjs": {
45
+ "size": 2850,
46
+ "total": 9896,
47
47
  "imports": [
48
- "../qfluent/context.qwik.cjs"
48
+ "..\\qfluent\\context.qwik.cjs"
49
49
  ],
50
50
  "origins": [
51
- "src/qfluent/translate.tsx"
51
+ "src\\qfluent\\translate.tsx"
52
52
  ],
53
53
  "interactivity": 0
54
54
  }
55
55
  },
56
56
  "assets": {
57
- "assets/DVjQdr_6-bundle-graph.json": {
57
+ "assets/DLXuL6n7-bundle-graph.json": {
58
58
  "name": "bundle-graph.json",
59
59
  "size": 7
60
60
  }
@@ -62,8 +62,8 @@
62
62
  "symbols": {},
63
63
  "platform": {
64
64
  "vite": "",
65
- "rollup": "4.62.2",
65
+ "rollup": "4.23.0",
66
66
  "env": "deno",
67
- "os": "linux"
67
+ "os": "win32"
68
68
  }
69
69
  }
@@ -1,4 +1,4 @@
1
- import { NoSerialize, Signal } from "@qwik.dev/core";
1
+ import { type Component, type NoSerialize, type Signal } from "@qwik.dev/core";
2
2
  import type { FluentProviderProps, QwikFluentBundleMap, QwikFluentError, QwikFluentResourceMap } from "./types";
3
3
  /** @internal */
4
4
  export declare const FluentLocalesId: import("@qwik.dev/core").ContextId<Signal<string[]>>;
@@ -51,4 +51,4 @@ export declare function useFluentErrors(): Signal<QwikFluentError[]>;
51
51
  * </body>
52
52
  * ```
53
53
  */
54
- export declare const FluentProvider: import("@qwik.dev/core").Component<FluentProviderProps>;
54
+ export declare const FluentProvider: Component<FluentProviderProps>;
@@ -1,189 +1,178 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
- const core = require("@qwik.dev/core");
26
- const bundle = require("@fluent/bundle");
27
- const FluentLocalesId = core.createContextId("QwikFluentLocales");
28
- const FluentResourcesId = core.createContextId("QwikFluentResources");
29
- const FluentBundlesId = core.createContextId("QwikFluentBundles");
30
- const FluentErrorsId = core.createContextId("QwikFluentErrors");
31
- function useFluentLocales() {
32
- return core.useContext(FluentLocalesId);
1
+ let _qwik_dev_core = require("@qwik.dev/core");
2
+ let _fluent_bundle = require("@fluent/bundle");
3
+ /** @internal */ var FluentLocalesId = (0, _qwik_dev_core.createContextId)("QwikFluentLocales");
4
+ /** @internal */ var FluentResourcesId = (0, _qwik_dev_core.createContextId)("QwikFluentResources");
5
+ /** @internal */ var FluentBundlesId = (0, _qwik_dev_core.createContextId)("QwikFluentBundles");
6
+ /** @internal */ var FluentErrorsId = (0, _qwik_dev_core.createContextId)("QwikFluentErrors");
7
+ /**
8
+ * Signal to list of preferred locales. Translations are picked from these languages, with fallbacks as needed.
9
+ *
10
+ * Normally you want to set this to `preferred_languages.concat(navigator.languages)`.
11
+ *
12
+ * ```tsx
13
+ * const locales = useFluentLocales();
14
+ * return (
15
+ * <select onChange$={(event, select) => {
16
+ * locales.value = [select.value].concat(navigator.languages);
17
+ * }}>
18
+ * <option value="ar">Arabic</option>
19
+ * <option value="en">English</option>
20
+ * <option value="ja">Japanese</option>
21
+ * ...
22
+ * </select>
23
+ * );
24
+ * ```
25
+ */ function useFluentLocales() {
26
+ return (0, _qwik_dev_core.useContext)(FluentLocalesId);
33
27
  }
34
- function useFluentResources() {
35
- return core.useContext(FluentResourcesId);
28
+ /**
29
+ * Includes your resources and compiled FluentBundles by locales.
30
+ *
31
+ * You can make use of your custom resource properties with this.
32
+ */ function useFluentResources() {
33
+ return (0, _qwik_dev_core.useContext)(FluentResourcesId);
36
34
  }
37
- function useFluentErrors() {
38
- return core.useContext(FluentErrorsId);
35
+ /**
36
+ * Useful for debugging errors in resources.
37
+ *
38
+ * You can clear the errors after use.
39
+ */ function useFluentErrors() {
40
+ return (0, _qwik_dev_core.useContext)(FluentErrorsId);
39
41
  }
40
42
  function ataToUtf8(pathname) {
41
- const label = ";base64,";
42
- const a = pathname.indexOf(label);
43
- if (a === -1) {
44
- throw new Error("Invalid ata url pathname: " + pathname);
45
- }
46
- const binaryString = atob(pathname.slice(a + label.length));
47
- const bytes = new Uint8Array(binaryString.length);
48
- for (let i = 0; i < binaryString.length; i++) {
49
- bytes[i] = binaryString.charCodeAt(i);
50
- }
51
- return new TextDecoder().decode(bytes);
43
+ const a = pathname.indexOf(";base64,");
44
+ if (a === -1) throw new Error("Invalid ata url pathname: " + pathname);
45
+ const binaryString = atob(pathname.slice(a + 8));
46
+ const bytes = new Uint8Array(binaryString.length);
47
+ for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
48
+ return new TextDecoder().decode(bytes);
52
49
  }
53
- const FluentProvider = /* @__PURE__ */ core.componentQrl(/* @__PURE__ */ core.inlinedQrl((_rawProps) => {
54
- const locales = core.useSignal(_rawProps.acceptLanguage ?? [
55
- "en"
56
- ]);
57
- const bunmap = core.useSignal({});
58
- const resmap = core.useSignal({});
59
- const errors = core.useSignal([]);
60
- core.useContextProvider(FluentLocalesId, locales);
61
- core.useContextProvider(FluentBundlesId, bunmap);
62
- core.useContextProvider(FluentResourcesId, resmap);
63
- core.useContextProvider(FluentErrorsId, errors);
64
- const ssr = core.useSignal(true);
65
- core.useOnDocument("load", /* @__PURE__ */ core.inlinedQrl(() => {
66
- const locales2 = core._captures[0], ssr2 = core._captures[1];
67
- if (!ssr2.value) return;
68
- ssr2.value = false;
69
- locales2.value = navigator.languages.concat();
70
- }, "FluentProvider_component_useOnDocument_9BL0L0WgLlY", [
71
- locales,
72
- ssr
73
- ]));
74
- core.useTaskQrl(/* @__PURE__ */ core.inlinedQrl((_rawProps1) => {
75
- const _rawProps2 = core._captures[0], bunmap2 = core._captures[1], errors2 = core._captures[2], locales2 = core._captures[3], resmap2 = core._captures[4], ssr2 = core._captures[5];
76
- _rawProps1.track(locales2);
77
- _rawProps1.track(ssr2);
78
- if (!bunmap2.value) {
79
- bunmap2.value = {};
80
- }
81
- if (!resmap2.value) {
82
- resmap2.value = {};
83
- }
84
- if (!errors2.value) {
85
- errors2.value = [];
86
- }
87
- const res = core.noSerialize(resmap2.value);
88
- const bun = core.noSerialize(bunmap2.value);
89
- const promises = [];
90
- const whitelist = locales2.value;
91
- let has_errors = false;
92
- for (const r of _rawProps2.resources) {
93
- let ok = false;
94
- for (const x of r.locales) {
95
- if (res[x]) {
96
- break;
97
- }
98
- if (whitelist.includes(x)) {
99
- ok = true;
100
- break;
101
- }
102
- }
103
- if (!ok) {
104
- continue;
105
- }
106
- const b = new bundle.FluentBundle(r.locales);
107
- for (const x of r.locales) {
108
- res[x] = r;
109
- bun[x] = b;
110
- }
111
- for (const url of r.resources) {
112
- let promise;
113
- if (core.isServer) {
114
- let path = url.toString().slice(1);
115
- {
116
- path = new URL(path, new URL("../dist/", _rawProps2.origin));
117
- }
118
- if (path.protocol === "ata:") {
119
- promise = new Promise((resolve, reject) => {
120
- try {
121
- resolve(ataToUtf8(path.pathname));
122
- } catch (err) {
123
- reject(err);
124
- }
125
- });
126
- } else {
127
- promise = import("node:fs/promises").then((fs) => fs.readFile(path.pathname)).then((buf) => new TextDecoder().decode(buf));
128
- }
129
- } else {
130
- promise = fetch(url).then((resp) => resp.text());
131
- }
132
- promises.push(promise.then((s) => {
133
- const errset = b.addResource(new bundle.FluentResource(s));
134
- if (errset.length) {
135
- errors2.value.push({
136
- resource: r,
137
- errors: errset
138
- });
139
- has_errors = true;
140
- console.error(`[qfluent] Errors in resource ${url}:`, errset);
141
- }
142
- }));
143
- }
144
- }
145
- return Promise.all(promises).then(() => {
146
- bunmap2.trigger();
147
- resmap2.trigger();
148
- if (has_errors) {
149
- errors2.trigger();
150
- }
151
- });
152
- }, "FluentProvider_component_useTask_0r0LUJYLJnU", [
153
- _rawProps,
154
- bunmap,
155
- errors,
156
- locales,
157
- resmap,
158
- ssr
159
- ]));
160
- core.useTaskQrl(/* @__PURE__ */ core.inlinedQrl(({ track }) => {
161
- const locales2 = core._captures[0], resmap2 = core._captures[1], ssr2 = core._captures[2];
162
- if (track(ssr2)) return;
163
- if (!track(resmap2)) return;
164
- track(locales2);
165
- const root = document.querySelector("html");
166
- if (!root) return;
167
- for (const l of locales2.value) {
168
- const b = resmap2.value[l];
169
- if (!b) {
170
- continue;
171
- }
172
- root.lang = l;
173
- const dir = b.dir;
174
- if (dir) {
175
- root.dir = dir;
176
- } else {
177
- root.dir = "";
178
- }
179
- break;
180
- }
181
- }, "FluentProvider_component_useTask_1_GdWGQNUVI4g", [
182
- locales,
183
- resmap,
184
- ssr
185
- ]));
186
- return /* @__PURE__ */ core._jsxSorted(core.Slot, null, null, null, 3, "76_0");
50
+ /**
51
+ * Use this in `src/root.tsx`.
52
+ *
53
+ * ```tsx
54
+ * <body>
55
+ * <FluentProvider resources={...}>
56
+ * <RouterOutlet />
57
+ * </FluentProvider>
58
+ * </body>
59
+ * ```
60
+ */ var FluentProvider = /*#__PURE__*/ (0, _qwik_dev_core.componentQrl)(/*#__PURE__*/ (0, _qwik_dev_core.inlinedQrl)((_rawProps) => {
61
+ const locales = (0, _qwik_dev_core.useSignal)(_rawProps.acceptLanguage ?? ["en"]);
62
+ const bunmap = (0, _qwik_dev_core.useSignal)((0, _qwik_dev_core.noSerialize)({}));
63
+ const resmap = (0, _qwik_dev_core.useSignal)((0, _qwik_dev_core.noSerialize)({}));
64
+ const errors = (0, _qwik_dev_core.useSignal)((0, _qwik_dev_core.noSerialize)([]));
65
+ (0, _qwik_dev_core.useContextProvider)(FluentLocalesId, locales);
66
+ (0, _qwik_dev_core.useContextProvider)(FluentBundlesId, bunmap);
67
+ (0, _qwik_dev_core.useContextProvider)(FluentResourcesId, resmap);
68
+ (0, _qwik_dev_core.useContextProvider)(FluentErrorsId, errors);
69
+ const ssr = (0, _qwik_dev_core.useSignal)(true);
70
+ (0, _qwik_dev_core.useOnDocument)("load", /*#__PURE__*/ (0, _qwik_dev_core.inlinedQrl)(() => {
71
+ const locales = _qwik_dev_core._captures[0], ssr = _qwik_dev_core._captures[1];
72
+ if (!ssr.value) return;
73
+ ssr.value = false;
74
+ locales.value = navigator.languages.concat();
75
+ }, "FluentProvider_component_useOnDocument_9BL0L0WgLlY", [locales, ssr]));
76
+ (0, _qwik_dev_core.useTaskQrl)(/*#__PURE__*/ (0, _qwik_dev_core.inlinedQrl)((_rawProps1) => {
77
+ const _rawProps = _qwik_dev_core._captures[0], bunmap = _qwik_dev_core._captures[1], errors = _qwik_dev_core._captures[2], locales = _qwik_dev_core._captures[3], resmap = _qwik_dev_core._captures[4], ssr = _qwik_dev_core._captures[5];
78
+ _rawProps1.track(locales);
79
+ _rawProps1.track(ssr);
80
+ if (!bunmap.value) bunmap.value = (0, _qwik_dev_core.noSerialize)({});
81
+ if (!resmap.value) resmap.value = (0, _qwik_dev_core.noSerialize)({});
82
+ if (!errors.value) errors.value = (0, _qwik_dev_core.noSerialize)([]);
83
+ const res = (0, _qwik_dev_core.noSerialize)(resmap.value);
84
+ const bun = (0, _qwik_dev_core.noSerialize)(bunmap.value);
85
+ const promises = [];
86
+ const whitelist = locales.value;
87
+ let has_errors = false;
88
+ for (const r of _rawProps.resources) {
89
+ let ok = false;
90
+ for (const x of r.locales) {
91
+ if (res[x]) break;
92
+ if (whitelist.includes(x)) {
93
+ ok = true;
94
+ break;
95
+ }
96
+ }
97
+ if (!ok) continue;
98
+ const b = new _fluent_bundle.FluentBundle(r.locales);
99
+ for (const x of r.locales) {
100
+ res[x] = r;
101
+ bun[x] = b;
102
+ }
103
+ for (const url of r.resources) {
104
+ let promise;
105
+ if (_qwik_dev_core.isServer) {
106
+ const rel = url.toString().slice(1);
107
+ const candidates = [new URL("../dist/", _rawProps.origin), _rawProps.origin].map((base) => new URL(rel, base));
108
+ const ata = candidates.find((c) => c.protocol === "ata:");
109
+ if (ata) promise = new Promise((resolve, reject) => {
110
+ try {
111
+ resolve(ataToUtf8(ata.pathname));
112
+ } catch (err) {
113
+ reject(err);
114
+ }
115
+ });
116
+ else promise = import("node:fs/promises").then(async (fs) => {
117
+ const { fileURLToPath } = await import("node:url");
118
+ let firstError;
119
+ for (const c of candidates) try {
120
+ const buf = await fs.readFile(c.protocol === "file:" ? fileURLToPath(c) : c.pathname);
121
+ return new TextDecoder().decode(buf);
122
+ } catch (err) {
123
+ if (firstError === void 0) firstError = err;
124
+ }
125
+ throw firstError;
126
+ });
127
+ } else promise = fetch(url).then((resp) => resp.text());
128
+ promises.push(promise.then((s) => {
129
+ const errset = b.addResource(new _fluent_bundle.FluentResource(s));
130
+ if (errset.length) {
131
+ errors.value.push({
132
+ resource: r,
133
+ errors: errset
134
+ });
135
+ has_errors = true;
136
+ console.error(`[qfluent] Errors in resource ${url}:`, errset);
137
+ }
138
+ }));
139
+ }
140
+ }
141
+ return Promise.all(promises).then(() => {
142
+ bunmap.trigger();
143
+ resmap.trigger();
144
+ if (has_errors) errors.trigger();
145
+ });
146
+ }, "FluentProvider_component_useTask_0r0LUJYLJnU", [
147
+ _rawProps,
148
+ bunmap,
149
+ errors,
150
+ locales,
151
+ resmap,
152
+ ssr
153
+ ]));
154
+ (0, _qwik_dev_core.useTaskQrl)(/*#__PURE__*/ (0, _qwik_dev_core.inlinedQrl)(({ track }) => {
155
+ const locales = _qwik_dev_core._captures[0], resmap = _qwik_dev_core._captures[1], ssr = _qwik_dev_core._captures[2];
156
+ if (track(ssr)) return;
157
+ if (!track(resmap)) return;
158
+ track(locales);
159
+ const root = document.querySelector("html");
160
+ if (!root) return;
161
+ for (const l of locales.value) {
162
+ const b = resmap.value[l];
163
+ if (!b) continue;
164
+ root.lang = l;
165
+ const dir = b.dir;
166
+ if (dir) root.dir = dir;
167
+ else root.dir = "";
168
+ break;
169
+ }
170
+ }, "FluentProvider_component_useTask_1_GdWGQNUVI4g", [
171
+ locales,
172
+ resmap,
173
+ ssr
174
+ ]));
175
+ return /*#__PURE__*/ (0, _qwik_dev_core._jsxSorted)(_qwik_dev_core.Slot, null, null, null, 3, "76_0");
187
176
  }, "FluentProvider_component_LWfKAJ3jVqM"));
188
177
  exports.FluentBundlesId = FluentBundlesId;
189
178
  exports.FluentErrorsId = FluentErrorsId;