@acryldev/blends-frame 0.2.3 → 0.2.5

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,122 @@ 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, and so do the desktop window and the Dock (the desktop
48289
+ * shell watches the file).
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 tab and the window show it now.",
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
+ }
48387
+ /** Settings > App in an app without the product's desktop bridge (every app people make): its icon. */
48388
+ function AppIconSection() {
48389
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48390
+ className: "acrylBlendsApp",
48391
+ children: [
48392
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: "App" }),
48393
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
48394
+ className: "acrylBlendsPluginsSub",
48395
+ children: "This app's own look."
48396
+ }),
48397
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppIconRow, {})
48398
+ ]
48399
+ });
48400
+ }
48283
48401
  // src/client/desktop-app.ts
48284
48402
  /** 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
48403
  var DesktopApp = class {
@@ -48469,6 +48587,7 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
48469
48587
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "A label only: renaming never moves the app's folder." })
48470
48588
  ]
48471
48589
  }),
48590
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppIconRow, {}),
48472
48591
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48473
48592
  className: "acrylBlendsAppRow",
48474
48593
  children: [
@@ -49611,6 +49730,7 @@ button.acrylBlendsFrow:hover { background: var(--bf-surface-2); }
49611
49730
  .acrylBlendsAppRow small { grid-column: 1 / -1; color: var(--bf-dim); font-size: 11.5px; }
49612
49731
  .acrylBlendsAppControls { grid-row: 1; grid-column: 2; display: inline-flex; align-items: center; gap: 8px; }
49613
49732
  .acrylBlendsAppRow .acrylBlendsAppName { width: 220px; }
49733
+ .acrylBlendsAppIcon { width: 28px; height: 28px; border-radius: 6px; object-fit: contain; border: 1px solid var(--bf-border); }
49614
49734
  .acrylBlendsAppRow[data-wide] .acrylBlendsAppControls { grid-row: 2; grid-column: 1 / -1; flex-wrap: wrap; }
49615
49735
  .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; }
49616
49736
  .acrylBlendsAppButton:hover:not(:disabled) { border-color: #4a4a52; color: #fff; }
@@ -50542,6 +50662,14 @@ body[data-bf-settings-full] [data-shortcut-modal="settings"] { width: calc(100vw
50542
50662
  locale: LOCALE_NAMESPACE,
50543
50663
  inject: () => ({ app: desktop })
50544
50664
  }, AppSection));
50665
+ else child.slots.inject("settings.section", () => child.slots.register({
50666
+ name: "settings.section",
50667
+ id: "acryl-blends-app",
50668
+ order: 5,
50669
+ label: () => t("app"),
50670
+ locale: LOCALE_NAMESPACE,
50671
+ inject: () => ({})
50672
+ }, AppIconSection));
50545
50673
  const shareApp = createShareAppApi();
50546
50674
  child.slots.inject("settings.section", () => child.slots.register({
50547
50675
  name: "settings.section",