@acryldev/blends-frame 0.2.2 → 0.2.4

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The app's own icon, chosen in Settings > App: one PNG at `<app>/assets/icon.png`, the file the page serves as the tab's icon and the desktop window
3
+ * shows (its Dock icon on macOS from the window's next start). The page sends a PNG it drew at 512 px; anything else is refused.
4
+ */
5
+ export declare const APP_ICON_FILE: string;
6
+ export declare const APP_ICON_MAX_BYTES: number;
7
+ export declare class AppIconRefused extends Error {
8
+ }
9
+ /** The PNG's bytes from the page's base64, or a refusal in words for the person. */
10
+ export declare function iconBytes(base64: unknown): Uint8Array;
11
+ /** Write the icon into the app, replacing any earlier one in one step (a half-written icon is never served). */
12
+ export declare function saveAppIcon(root: string, bytes: Uint8Array): Promise<void>;
package/lib/client.js CHANGED
@@ -172,6 +172,8 @@ window.__ModuleLoader__.load({
172
172
  const FRAME_APP_SHARE_PLAN_PATH = `${FRAME_API_PREFIX}/app/share-plan`;
173
173
  /** POST `{ owner?, visibility?, confirm }`: share the app exactly as the confirmed plan says, or nothing. */
174
174
  const FRAME_APP_SHARE_PATH = `${FRAME_API_PREFIX}/app/share`;
175
+ /** POST `{ png: base64 }`: the app's own icon (assets/icon.png), drawn by the page at 512 px. */
176
+ const FRAME_APP_ICON_PATH = `${FRAME_API_PREFIX}/app/icon`;
175
177
  function parseAppSharePlan(value) {
176
178
  if (!isRecord$5(value)) throw new Error("app share plan: not a plan");
177
179
  const { repository, create, visibility, changes } = value;
@@ -48280,6 +48282,108 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
48280
48282
  }
48281
48283
  };
48282
48284
  }
48285
+ // src/client/AppIconRow.tsx
48286
+ /**
48287
+ * Settings > App > Icon: the app's own icon. The picked image (PNG, JPEG, SVG, WebP...) is drawn on a 512 px square in the page and sent as a PNG to
48288
+ * the frame's host, which keeps it as assets/icon.png: the browser tab shows it at once, the desktop window too, and the Dock on macOS from the
48289
+ * window's next start.
48290
+ */
48291
+ const SIZE = 512;
48292
+ /** The image as a 512 px PNG, centred and kept whole, as base64. */
48293
+ async function asPng(file) {
48294
+ const url = URL.createObjectURL(file);
48295
+ try {
48296
+ const image = new Image();
48297
+ image.src = url;
48298
+ await image.decode();
48299
+ const canvas = document.createElement("canvas");
48300
+ canvas.width = SIZE;
48301
+ canvas.height = SIZE;
48302
+ const context = canvas.getContext("2d");
48303
+ if (context === null) throw new Error("this browser cannot draw the image");
48304
+ const scale = Math.min(SIZE / (image.naturalWidth || SIZE), SIZE / (image.naturalHeight || SIZE));
48305
+ const width = (image.naturalWidth || SIZE) * scale;
48306
+ const height = (image.naturalHeight || SIZE) * scale;
48307
+ context.drawImage(image, (SIZE - width) / 2, (SIZE - height) / 2, width, height);
48308
+ return canvas.toDataURL("image/png").slice(22);
48309
+ } finally {
48310
+ URL.revokeObjectURL(url);
48311
+ }
48312
+ }
48313
+ /** Point the tab's icon at the new file (browsers keep the old one otherwise). */
48314
+ function refreshTabIcon(version) {
48315
+ for (const link of document.querySelectorAll("link[rel~=\"icon\"]")) link.href = `/favicon.svg?v=${String(version)}`;
48316
+ }
48317
+ function AppIconRow() {
48318
+ const [version, setVersion] = (0, react.useState)(() => Date.now());
48319
+ const [note, setNote] = (0, react.useState)(void 0);
48320
+ const [busy, setBusy] = (0, react.useState)(false);
48321
+ const pick = (event) => {
48322
+ const file = event.target.files?.[0];
48323
+ event.target.value = "";
48324
+ if (file === void 0) return;
48325
+ setBusy(true);
48326
+ setNote(void 0);
48327
+ (async () => {
48328
+ try {
48329
+ const response = await fetch(FRAME_APP_ICON_PATH, {
48330
+ method: "POST",
48331
+ credentials: "same-origin",
48332
+ headers: { "Content-Type": "application/json" },
48333
+ body: JSON.stringify({ png: await asPng(file) })
48334
+ });
48335
+ if (!response.ok) {
48336
+ const said = await response.json().then((body) => body.error, () => void 0);
48337
+ throw new Error(typeof said === "string" && said !== "" ? said : `the icon was not saved (HTTP ${String(response.status)})`);
48338
+ }
48339
+ const next = Date.now();
48340
+ setVersion(next);
48341
+ refreshTabIcon(next);
48342
+ setNote({
48343
+ text: "Saved. The window shows it now; the Dock on a Mac from the next start.",
48344
+ error: false
48345
+ });
48346
+ } catch (cause) {
48347
+ setNote({
48348
+ text: cause instanceof Error ? cause.message : String(cause),
48349
+ error: true
48350
+ });
48351
+ } finally {
48352
+ setBusy(false);
48353
+ }
48354
+ })();
48355
+ };
48356
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48357
+ className: "acrylBlendsAppRow",
48358
+ children: [
48359
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Icon" }),
48360
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
48361
+ className: "acrylBlendsAppControls",
48362
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
48363
+ className: "acrylBlendsAppIcon",
48364
+ src: `/favicon.svg?v=${String(version)}`,
48365
+ alt: "This app's icon",
48366
+ width: 28,
48367
+ height: 28
48368
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
48369
+ className: "acrylBlendsAppButton",
48370
+ children: [busy ? "Saving…" : "Choose an image…", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
48371
+ type: "file",
48372
+ accept: "image/*",
48373
+ hidden: true,
48374
+ disabled: busy,
48375
+ onChange: pick
48376
+ })]
48377
+ })]
48378
+ }),
48379
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: note === void 0 ? "The icon of this app: its window, its browser tab, and its Dock icon on a Mac. Saved in the app as assets/icon.png." : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
48380
+ role: note.error ? "alert" : "status",
48381
+ ...note.error ? { "data-error": "" } : {},
48382
+ children: note.text
48383
+ }) })
48384
+ ]
48385
+ });
48386
+ }
48283
48387
  // src/client/desktop-app.ts
48284
48388
  /** The product's app, read through the bridge: a store of its state (the bar's name and the first start's question follow it) and its operations. */
48285
48389
  var DesktopApp = class {
@@ -48469,6 +48573,7 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
48469
48573
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "A label only: renaming never moves the app's folder." })
48470
48574
  ]
48471
48575
  }),
48576
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppIconRow, {}),
48472
48577
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48473
48578
  className: "acrylBlendsAppRow",
48474
48579
  children: [
@@ -48683,6 +48788,18 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
48683
48788
  target.removeEventListener("unhandledrejection", listener);
48684
48789
  };
48685
48790
  }
48791
+ const INSTALLED = Symbol.for("acrylBlends.recovery");
48792
+ /**
48793
+ * Install the recovery once for the page, never removed. Not owned by the plugin's lifecycle on purpose: the race that blanks the page is DSH
48794
+ * replacing the slots service, which unloads the frame's client plugin (it injects `slots`), and an effect-owned listener was gone at exactly the
48795
+ * moment the error fired (seen on Windows with 0.2.2). A second call (the plugin applied again) finds the first listener and adds nothing.
48796
+ */
48797
+ function installRecoveryOnce(target, now = Date.now) {
48798
+ const marked = target;
48799
+ if (marked[INSTALLED]) return;
48800
+ marked[INSTALLED] = true;
48801
+ installRecovery(target, now);
48802
+ }
48686
48803
  // src/client/ShareAppSection.tsx
48687
48804
  /**
48688
48805
  * Settings > Share, in every app (window or browser tab): send the whole app, as it is now, to a GitHub repository of the person's own. The plan
@@ -49599,6 +49716,7 @@ button.acrylBlendsFrow:hover { background: var(--bf-surface-2); }
49599
49716
  .acrylBlendsAppRow small { grid-column: 1 / -1; color: var(--bf-dim); font-size: 11.5px; }
49600
49717
  .acrylBlendsAppControls { grid-row: 1; grid-column: 2; display: inline-flex; align-items: center; gap: 8px; }
49601
49718
  .acrylBlendsAppRow .acrylBlendsAppName { width: 220px; }
49719
+ .acrylBlendsAppIcon { width: 28px; height: 28px; border-radius: 6px; object-fit: contain; border: 1px solid var(--bf-border); }
49602
49720
  .acrylBlendsAppRow[data-wide] .acrylBlendsAppControls { grid-row: 2; grid-column: 1 / -1; flex-wrap: wrap; }
49603
49721
  .acrylBlendsAppButton { padding: 4px 10px; border: 1px solid #34343a; border-radius: 6px; background: var(--bf-surface-2); color: #e8e8ea; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
49604
49722
  .acrylBlendsAppButton:hover:not(:disabled) { border-color: #4a4a52; color: #fff; }
@@ -50192,7 +50310,7 @@ body[data-bf-settings-full] [data-shortcut-modal="settings"] { width: calc(100vw
50192
50310
  }
50193
50311
  }
50194
50312
  function apply(ctx) {
50195
- ctx.effect(() => installRecovery(window), "@acryldev/blends-frame: recover a blank page");
50313
+ installRecoveryOnce(window);
50196
50314
  const layout = new _acryldev_app_shell_client.DesktopLayoutState();
50197
50315
  const canvas = new AppCanvasState();
50198
50316
  const selection = new SelectionStore();