willa 0.0.1-alpha.8d8fe96 → 0.0.3

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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * willa.js v0.0.1-alpha.8d8fe96
2
+ * willa.js v0.0.3
3
3
  * (c) 2026 chentao.arthur
4
4
  */
5
5
  var _willa_ui_content = require("@willa-ui/content");
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * willa.js v0.0.1-alpha.8d8fe96
2
+ * willa.js v0.0.3
3
3
  * (c) 2026 chentao.arthur
4
4
  */
5
5
  export * from "@willa-ui/content";
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * willa.js v0.0.1-alpha.8d8fe96
2
+ * willa.js v0.0.3
3
3
  * (c) 2026 chentao.arthur
4
4
  */
5
5
  var Willa = (function (exports, react, react_dom) {
@@ -52585,7 +52585,7 @@ var Willa = (function (exports, react, react_dom) {
52585
52585
  className:
52586
52586
  "willa-english-card-line willa-english-card-line--empty",
52587
52587
  children:
52588
- "正在尝试从有道词典获取中文释义;需要固定展示时,可以在 items 里手动补充。",
52588
+ "Fetching Chinese definitions from Youdao Dictionary.",
52589
52589
  }),
52590
52590
  ],
52591
52591
  }),
@@ -52665,8 +52665,8 @@ var Willa = (function (exports, react, react_dom) {
52665
52665
  if (state.status === "success") return null;
52666
52666
  const copy =
52667
52667
  state.status === "loading"
52668
- ? "正在从有道词典获取"
52669
- : (state.message ?? "词典 API 暂未配置");
52668
+ ? "Fetching from Youdao Dictionary."
52669
+ : (state.message ?? "Dictionary API is not available.");
52670
52670
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
52671
52671
  className: (0, import_classnames.default)(
52672
52672
  "willa-english-card-openapi",
@@ -53006,49 +53006,43 @@ var Willa = (function (exports, react, react_dom) {
53006
53006
  //#region ../willa-widgets/src/components/EnglishCards/data.ts
53007
53007
  const DICTIONARY_CACHE_TTL = 1e3 * 60 * 60 * 24 * 30;
53008
53008
  const DICTIONARY_CACHE_PREFIX = "willa:english-card:dictionary:v1";
53009
- const LOCAL_DICTIONARY_ENDPOINT = "/api/dictionary/youdao/jsonapi";
53010
- const REMOTE_DICTIONARY_ENDPOINT = "https://dict.youdao.com/jsonapi";
53009
+ const DEFAULT_DICTIONARY_ENDPOINT = "https://dict.youdao.com/jsonapi";
53011
53010
  function normalizeWordKey(word) {
53012
53011
  return word.trim().toLowerCase();
53013
53012
  }
53014
53013
  function normalizeOpenApiConfig(openApi) {
53015
53014
  if (typeof openApi !== "object" || openApi === null)
53016
53015
  return {
53017
- enabled: openApi !== false,
53016
+ enabled: openApi === true,
53018
53017
  language: "en",
53019
- endpoint: getDefaultDictionaryEndpoint(),
53020
53018
  };
53021
53019
  return {
53022
53020
  enabled: openApi.enabled ?? true,
53023
53021
  language: openApi.language ?? "en",
53024
- endpoint: trimTrailingSlash(
53025
- openApi.endpoint ?? getDefaultDictionaryEndpoint(),
53026
- ),
53027
53022
  };
53028
53023
  }
53029
53024
  async function fetchDictionaryWord(word, config, requestInit) {
53030
53025
  const cachedItem = readCache(word, config);
53031
53026
  if (cachedItem) return cachedItem;
53032
53027
  const item = parseDictionaryResponse(
53033
- await fetchDictionaryJson(word, config, requestInit),
53028
+ await fetchDictionaryJson(word, requestInit),
53034
53029
  word,
53035
53030
  );
53036
53031
  if (!item.translation && !item.explanation && !item.example)
53037
- throw new Error("词典接口未返回可展示数据");
53032
+ throw new Error(
53033
+ "Dictionary response did not include displayable content.",
53034
+ );
53038
53035
  writeCache(word, config, item);
53039
53036
  return item;
53040
53037
  }
53041
- const fetchDictionaryJson = async (word, config, requestInit) => {
53042
- const response = await fetch(
53043
- createDictionaryUrl(word, config),
53044
- requestInit,
53045
- );
53038
+ const fetchDictionaryJson = async (word, requestInit) => {
53039
+ const response = await fetch(createDictionaryUrl(word), requestInit);
53046
53040
  if (!response.ok) throw new Error(await readDictionaryError(response));
53047
53041
  return response.json();
53048
53042
  };
53049
- const createDictionaryUrl = (word, config) => {
53043
+ const createDictionaryUrl = (word) => {
53050
53044
  const url = new URL(
53051
- config.endpoint,
53045
+ DEFAULT_DICTIONARY_ENDPOINT,
53052
53046
  typeof window === "undefined" ? void 0 : window.location.origin,
53053
53047
  );
53054
53048
  url.searchParams.set("jsonversion", "2");
@@ -53286,14 +53280,16 @@ var Willa = (function (exports, react, react_dom) {
53286
53280
  ].join(":");
53287
53281
  };
53288
53282
  const readDictionaryError = async (response) => {
53289
- const fallbackMessage = `词典接口返回 ${response.status}`;
53283
+ const fallbackMessage = `Dictionary request failed with ${response.status}.`;
53290
53284
  try {
53291
53285
  const message = readString(record(await response.clone().json()) ?? {}, [
53292
53286
  "message",
53293
53287
  "title",
53294
53288
  "resolution",
53295
53289
  ]);
53296
- return message ? `词典接口:${message}` : fallbackMessage;
53290
+ return message
53291
+ ? `Dictionary request failed: ${message}`
53292
+ : fallbackMessage;
53297
53293
  } catch {
53298
53294
  return (await response.text()).trim() || fallbackMessage;
53299
53295
  }
@@ -53315,11 +53311,6 @@ var Willa = (function (exports, react, react_dom) {
53315
53311
  url.searchParams.set("audio", word);
53316
53312
  return url.toString();
53317
53313
  };
53318
- const getDefaultDictionaryEndpoint = () => {
53319
- return isLocalBrowser()
53320
- ? LOCAL_DICTIONARY_ENDPOINT
53321
- : REMOTE_DICTIONARY_ENDPOINT;
53322
- };
53323
53314
  const isLocalBrowser = () => {
53324
53315
  if (typeof window === "undefined") return false;
53325
53316
  return ["localhost", "127.0.0.1", "::1"].includes(window.location.hostname);
@@ -53354,9 +53345,6 @@ var Willa = (function (exports, react, react_dom) {
53354
53345
  return fieldValue.trim();
53355
53346
  }
53356
53347
  };
53357
- const trimTrailingSlash = (value) => {
53358
- return value.replace(/\/+$/, "");
53359
- };
53360
53348
  const record = (value) => {
53361
53349
  return isRecord(value) ? value : void 0;
53362
53350
  };
@@ -53414,8 +53402,10 @@ var Willa = (function (exports, react, react_dom) {
53414
53402
  };
53415
53403
  };
53416
53404
  const getErrorMessage = (error) => {
53417
- if (isAbortError(error)) return "词典请求已取消";
53418
- return error instanceof Error ? error.message : "词典请求失败";
53405
+ if (isAbortError(error)) return "Dictionary request was cancelled.";
53406
+ return error instanceof Error
53407
+ ? error.message
53408
+ : "Dictionary request failed.";
53419
53409
  };
53420
53410
  const isAbortError = (error) => {
53421
53411
  return error instanceof DOMException && error.name === "AbortError";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * willa.js v0.0.1-alpha.8d8fe96
2
+ * willa.js v0.0.3
3
3
  * (c) 2026 chentao.arthur
4
4
  */
5
5
  export * from "@willa-ui/content";
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * willa.js v0.0.1-alpha.8d8fe96
2
+ * willa.js v0.0.3
3
3
  * (c) 2026 chentao.arthur
4
4
  */
5
5
  export * from "@willa-ui/content";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "willa",
3
- "version": "0.0.1-alpha.8d8fe96",
3
+ "version": "0.0.3",
4
4
  "description": "Willa UI component library.",
5
5
  "author": "chentao.arthur",
6
6
  "license": "MIT",
@@ -57,8 +57,8 @@
57
57
  "**/*.css"
58
58
  ],
59
59
  "dependencies": {
60
- "@willa-ui/content": "0.0.1-alpha.8d8fe96",
61
- "@willa-ui/widgets": "0.0.1-alpha.8d8fe96"
60
+ "@willa-ui/content": "0.0.3",
61
+ "@willa-ui/widgets": "0.0.3"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "react": "19.2.6",
@@ -68,7 +68,7 @@
68
68
  "@types/react": "19.2.14",
69
69
  "@types/react-dom": "19.2.3",
70
70
  "@vitest/coverage-v8": "1.6.0",
71
- "auklet": "0.0.29",
71
+ "auklet": "0.1.1",
72
72
  "vitest": "1.6.0",
73
73
  "typescript": "6.0.3"
74
74
  },