@nsnanocat/preference-panes 1.1.0 → 1.1.1

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/src/web.mjs CHANGED
@@ -2,7 +2,6 @@ import { URL } from "@nsnanocat/url";
2
2
  import { $app } from "@nsnanocat/util/lib/app.mjs";
3
3
  import { done } from "@nsnanocat/util/lib/done.mjs";
4
4
  import assets from "#assets";
5
- import { pageInputs } from "./lib/page-inputs.mjs";
6
5
 
7
6
  /**
8
7
  * 返回模块页面及其公共浏览器资源,不处理 API、网络或持久化。
@@ -16,10 +15,7 @@ function run() {
16
15
  const url = new URL(request.url);
17
16
  if (/^\/settings\/[a-zA-Z0-9_-]+\/?$/.test(url.pathname)) {
18
17
  if (!["GET", "HEAD"].includes(request.method)) result = response(request, 405, { error: "Method not allowed" });
19
- else {
20
- const inputs = encodeURIComponent(JSON.stringify(pageInputs(url, request.headers)));
21
- result = response(request, 200, assets.page.body.replace("</head>", `<meta name="preference-panes-inputs" content="${inputs}"></head>`), "text/html");
22
- }
18
+ else result = response(request, 200, assets.page.body, "text/html");
23
19
  } else {
24
20
  const asset = assets[url.pathname];
25
21
  if (asset) result = ["GET", "HEAD"].includes(request.method) ? response(request, 200, asset.body, asset.type) : response(request, 405, { error: "Method not allowed" });
package/src/build.mjs DELETED
@@ -1,20 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { normalizeBoxJs } from "./browser/boxjs.mjs";
3
-
4
- /**
5
- * 仅生成模块前端文件,不复制配置或生成绑定业务的读写脚本。
6
- * Build module frontend files without copying configuration or generating bound storage scripts.
7
- * @param {unknown} boxjs 仅包含一个模块的 BoxJS JSON / BoxJS JSON containing exactly one module.
8
- * @param {string} [css] 可选自定义 CSS 正文 / Optional custom CSS text.
9
- * @returns {Promise<Record<string, string>>} 相对路径到文件正文的映射 / Relative file paths mapped to file contents.
10
- */
11
- export async function build(boxjs, css = "") {
12
- if (typeof css !== "string") throw new TypeError("CSS must be a string");
13
- const module = normalizeBoxJs(boxjs).module;
14
- const [html, index] = await Promise.all([readFile(new URL("../dist/module/index.html", import.meta.url), "utf8"), readFile(new URL("../dist/module/index.mjs", import.meta.url), "utf8")]);
15
- return {
16
- [`settings/${module}/index.html`]: html,
17
- "settings/assets/index.mjs": index,
18
- [`settings/assets/${module}.css`]: css,
19
- };
20
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * 统一解析模块页的资源地址:Header 优先于查询参数,再使用模块约定。
3
- * Resolve module resource locations: headers override query parameters and module conventions.
4
- * @param {URL} url 已解析的页面请求地址 / Parsed page request URL.
5
- * @param {Record<string, string | undefined>} [headers] 请求头,名称不区分大小写 / Case-insensitive request headers.
6
- * @returns {{url: string, module: string, json: string, css: string}} 页面上下文与两个资源输入 / Page context and two resource inputs.
7
- */
8
- export function pageInputs(url, headers = {}) {
9
- const match = /^\/settings\/([a-zA-Z0-9_-]+)\/?$/.exec(url.pathname);
10
- if (!match) throw new TypeError("Open a concrete module URL");
11
- const module = match[1];
12
- const values = Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value]));
13
- const json = values["x-preferencepanes-json"] ?? url.searchParams.get("json") ?? `/configs/${module}`;
14
- const css = values["x-preferencepanes-css"] ?? url.searchParams.get("css") ?? "";
15
- if (!json.trim()) throw new TypeError("JSON resource URL is required");
16
- return { url: url.href, module, json, css };
17
- }