@nsnanocat/preference-panes 1.0.0 → 1.1.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/src/build.mjs CHANGED
@@ -11,10 +11,10 @@ import { normalizeBoxJs } from "./browser/boxjs.mjs";
11
11
  export async function build(boxjs, css = "") {
12
12
  if (typeof css !== "string") throw new TypeError("CSS must be a string");
13
13
  const module = normalizeBoxJs(boxjs).module;
14
- const [html, app] = await Promise.all([readFile(new URL("../dist/module/index.html", import.meta.url), "utf8"), readFile(new URL("../dist/module/app.mjs", import.meta.url), "utf8")]);
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
15
  return {
16
16
  [`settings/${module}/index.html`]: html,
17
- "settings/assets/app.mjs": app,
17
+ "settings/assets/index.mjs": index,
18
18
  [`settings/assets/${module}.css`]: css,
19
19
  };
20
20
  }
@@ -1,49 +0,0 @@
1
- import { pageInputs } from "../lib/page-inputs.mjs";
2
- import { statusView } from "./components.mjs";
3
- import { mount } from "./index.mjs";
4
- import { installDefaultStyles } from "./styles.mjs";
5
-
6
- installDefaultStyles(document);
7
- let view;
8
- /**
9
- * 从 URL 或代理传递的 Header 导入 JSON/CSS,支持独立文档与 srcdoc。
10
- * Import JSON/CSS from the URL or proxy-carried headers in standalone and srcdoc documents.
11
- * @returns {Promise<void>} 启动完成 / Startup completion.
12
- */
13
- async function start() {
14
- try {
15
- view?.destroy();
16
- view = undefined;
17
- document.querySelector("#preferences").replaceChildren(statusView("读取设置…"));
18
- const context = document.querySelector('meta[name="preference-panes-inputs"]');
19
- const embedded = window.frameElement?.dataset.preferencePanes;
20
- let inputs;
21
- switch (true) {
22
- case embedded !== undefined:
23
- inputs = JSON.parse(embedded);
24
- document.documentElement.dataset.preferencePanesEmbedded = "";
25
- break;
26
- case context !== null:
27
- inputs = JSON.parse(decodeURIComponent(context.content));
28
- break;
29
- default:
30
- inputs = pageInputs(new URL(location.href));
31
- }
32
- const apiURL = new URL(`/api/${encodeURIComponent(inputs.module)}`, inputs.url).href;
33
- const resources = [inputs.css].map(source => {
34
- if (!source) return null;
35
- const url = new URL(source, inputs.url);
36
- if (!["http:", "https:"].includes(url.protocol)) throw new TypeError("Resources must use HTTP(S) URLs");
37
- return url.href;
38
- });
39
- const [style, modelResponse] = await Promise.all([...resources.map(url => (url ? fetch(url, { cache: "no-store", credentials: "omit" }) : null)), fetch(apiURL, { cache: "no-store", credentials: "omit", headers: { Accept: "application/json", "X-PreferencePanes-JSON": inputs.json } })]);
40
- if ((style && style.status !== 200) || modelResponse.status !== 200) throw new Error(`HTTP ${modelResponse.status !== 200 ? modelResponse.status : style.status}`);
41
- view = mount(await modelResponse.json(), style ? await style.text() : "");
42
- } catch (error) {
43
- document.querySelector("#preferences").replaceChildren(statusView(`加载失败:${error.message}`, start));
44
- }
45
- }
46
- start();
47
- window.addEventListener("pageshow", event => {
48
- if (event.persisted) start();
49
- });