@phis/ui 0.5.7 → 0.6.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/components/controls/phi-amount-list-control.d.ts +69 -0
- package/components/controls/phi-amount-list-control.js +15 -0
- package/components/controls/phi-button-control.js +16 -2
- package/components/root/phi-root-layout.d.ts +1 -0
- package/components/root/phi-root-layout.js +1 -0
- package/constants/media.d.ts +2 -0
- package/constants/media.js +2 -0
- package/controls.d.ts +2 -0
- package/controls.js +1 -0
- package/gateway/signet-route.d.ts +24 -0
- package/gateway/signet-route.js +102 -0
- package/gateway/site-proxy.js +14 -7
- package/helpers/phi-metadata.d.ts +8 -6
- package/helpers/phi-metadata.js +9 -2
- package/helpers/phi-signet-head.d.ts +25 -0
- package/helpers/phi-signet-head.js +41 -0
- package/helpers/phi-signet-paths.d.ts +16 -0
- package/helpers/phi-signet-paths.js +19 -0
- package/helpers/phi-signet.d.ts +28 -0
- package/helpers/phi-signet.js +59 -0
- package/next/root-route.js +7 -4
- package/next/site-proxy.js +16 -0
- package/package.json +3 -3
- package/plugins/runtime-modules/area-definitions.d.ts +24 -3
- package/plugins/runtime-modules/area-definitions.js +11 -3
- package/plugins/runtime-modules/public/presets.d.ts +12 -0
- package/plugins/runtime-modules/public/presets.js +10 -0
- package/plugins/runtime-modules/public/server.js +1 -1
- package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.d.ts +4 -0
- package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.js +66 -0
- package/plugins/runtime-modules/public-base-page-references.d.ts +2 -1
- package/plugins/runtime-modules/public-base-page-references.js +2 -1
- package/plugins/runtime-modules/theme/controller/runtime.js +7 -2
- package/plugins/runtime-modules/theme/materialize-images.d.ts +16 -0
- package/plugins/runtime-modules/theme/materialize-images.js +37 -0
- package/styles/amount-list.css +142 -0
- package/styles/controls.css +156 -7
- package/styles/gradients.css +21 -20
- package/theme/phi-theme-blocks.d.ts +7 -6
- package/theme/phi-theme-composition.d.ts +19 -1
- package/theme/phi-theme-composition.js +15 -0
- package/theme/phi-theme-signet.d.ts +25 -0
- package/theme/phi-theme-signet.js +17 -0
- package/types/site-theme.d.ts +17 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { PhiControlSize } from "../../types/control";
|
|
3
|
+
/**
|
|
4
|
+
* Lines and sums whose amounts stand in one column: a cart, a checkout, an order, a subscription's
|
|
5
|
+
* sign-up, a receipt.
|
|
6
|
+
*
|
|
7
|
+
* **It knows nothing about money.** An amount is text somebody else has already formatted, in whatever
|
|
8
|
+
* currency and locale the surface speaks. What this Control owns is the one thing a stack of rows cannot
|
|
9
|
+
* give it: every amount -- the items' and the totals' -- is in the same grid column, so their right edges
|
|
10
|
+
* are the same line and, with tabular digits, the figures stand digit under digit. Separate flex rows
|
|
11
|
+
* cannot do that; each one sizes its amount to itself.
|
|
12
|
+
*
|
|
13
|
+
* **One grid, rows through `subgrid`.** The list is a four-column grid -- media, text, controls, amount --
|
|
14
|
+
* and an item row and a total row are subgrids of it, so the amount column is sized by the widest amount
|
|
15
|
+
* of the whole list. `display: contents` would also share the columns, but it drops the row's box: no
|
|
16
|
+
* divider on a total, no role on a flattened element in some browsers. Rows are boxes, so `subgrid`.
|
|
17
|
+
*
|
|
18
|
+
* **Narrow is decided by the list's own width**, not the viewport's (`@container`, below 30rem): the item
|
|
19
|
+
* becomes two lines -- media and text, then controls and amount -- and the amount stays in the same
|
|
20
|
+
* column. Totals keep label left and amount right at every width. The container query needs
|
|
21
|
+
* `container-type: inline-size`, so the list takes the width its parent gives it (`width: 100%`) and has
|
|
22
|
+
* none of its own: in a shrink-to-fit parent -- an `inline-flex` or `fit-content` box -- it collapses to 0.
|
|
23
|
+
*
|
|
24
|
+
* **A list, with the sums as a description list.** The items are a `ul`: each is one thing with a name,
|
|
25
|
+
* free controls and an amount, and a table would need column headers that nothing here has (the
|
|
26
|
+
* controls cell has no name, the text cell is a title and a line). The sums are label/amount pairs, which
|
|
27
|
+
* is what `dl` says. The `ul` carries `role="list"` because list-style resets drop the role in Safari.
|
|
28
|
+
*
|
|
29
|
+
* **It is display, with no data source.** It sorts nothing, pages nothing and edits nothing; the
|
|
30
|
+
* quantity field or the remove button is whatever the surface passes as `controls`. It is not the Table
|
|
31
|
+
* Widget ([TABLES.md](../../TABLES.md)). It renders on the server: no state, no Ant Design, no theme hook;
|
|
32
|
+
* the rules are `styles/amount-list.css`.
|
|
33
|
+
*/
|
|
34
|
+
export type PhiAmountListItem = {
|
|
35
|
+
key: string;
|
|
36
|
+
/** The name of the line. It wraps; it is never cut off. */
|
|
37
|
+
title: ReactNode;
|
|
38
|
+
/** A second, quieter line under the title: "2 x 12,00 CHF", "per month". */
|
|
39
|
+
description?: ReactNode;
|
|
40
|
+
/** A small picture or icon before the title. */
|
|
41
|
+
media?: ReactNode;
|
|
42
|
+
/** Whatever the line can be operated with: a quantity field, a remove button. */
|
|
43
|
+
controls?: ReactNode;
|
|
44
|
+
/** The amount, already formatted. */
|
|
45
|
+
amount: ReactNode;
|
|
46
|
+
/** Quiet, under the amount: "incl. VAT". */
|
|
47
|
+
amountNote?: ReactNode;
|
|
48
|
+
};
|
|
49
|
+
export type PhiAmountListTotal = {
|
|
50
|
+
key: string;
|
|
51
|
+
label: ReactNode;
|
|
52
|
+
/** The amount, already formatted. */
|
|
53
|
+
amount: ReactNode;
|
|
54
|
+
/** Quiet, under the label. */
|
|
55
|
+
note?: ReactNode;
|
|
56
|
+
/** `strong` is for the line that is the answer: the grand total. */
|
|
57
|
+
emphasis?: "normal" | "strong";
|
|
58
|
+
/** A rule above this line, in the Theme's line colour. */
|
|
59
|
+
divided?: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type PhiAmountListControlProps = {
|
|
62
|
+
items: readonly PhiAmountListItem[];
|
|
63
|
+
totals?: readonly PhiAmountListTotal[];
|
|
64
|
+
size?: PhiControlSize;
|
|
65
|
+
/** Stands in place of the list when there are no items and no totals. */
|
|
66
|
+
emptyText?: ReactNode;
|
|
67
|
+
ariaLabel?: string;
|
|
68
|
+
};
|
|
69
|
+
export declare function PhiAmountListControl({ items, totals, size, emptyText, ariaLabel, }: PhiAmountListControlProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function PhiAmountListControl({ items, totals, size = "medium", emptyText, ariaLabel, }) {
|
|
3
|
+
const hasTotals = totals != null && totals.length > 0;
|
|
4
|
+
if (items.length === 0 && !hasTotals) {
|
|
5
|
+
return emptyText != null ? _jsx("div", { className: "phi-amount-list__empty", children: emptyText }) : null;
|
|
6
|
+
}
|
|
7
|
+
return (_jsxs("div", { className: `phi-amount-list phi-amount-list--${size}`, role: ariaLabel ? "group" : undefined, "aria-label": ariaLabel, children: [items.length > 0 ? (_jsx("ul", { className: "phi-amount-list__items", role: "list", children: items.map((item) => (_jsxs("li", { className: "phi-amount-list__item", role: "listitem", children: [item.media != null ? _jsx("div", { className: "phi-amount-list__media", children: item.media }) : null, _jsxs("div", { className: "phi-amount-list__text", children: [_jsx("div", { className: "phi-amount-list__title", children: item.title }), item.description != null ? (_jsx("div", { className: "phi-amount-list__description", children: item.description })) : null] }), item.controls != null ? _jsx("div", { className: "phi-amount-list__controls", children: item.controls }) : null, _jsxs("div", { className: "phi-amount-list__amount", children: [_jsx("div", { children: item.amount }), item.amountNote != null ? _jsx("div", { className: "phi-amount-list__note", children: item.amountNote }) : null] })] }, item.key))) })) : null, hasTotals ? (_jsx("dl", { className: "phi-amount-list__totals", children: totals.map((total) => {
|
|
8
|
+
const className = [
|
|
9
|
+
"phi-amount-list__total",
|
|
10
|
+
total.emphasis === "strong" ? "phi-amount-list__total--strong" : null,
|
|
11
|
+
total.divided ? "phi-amount-list__total--divided" : null,
|
|
12
|
+
].filter(Boolean).join(" ");
|
|
13
|
+
return (_jsxs("div", { className: className, children: [_jsxs("dt", { className: "phi-amount-list__label", children: [_jsx("span", { children: total.label }), total.note != null ? _jsx("span", { className: "phi-amount-list__note", children: total.note }) : null] }), _jsx("dd", { className: "phi-amount-list__amount", children: total.amount })] }, total.key));
|
|
14
|
+
}) })) : null] }));
|
|
15
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { lazy, Suspense } from "react";
|
|
4
|
-
import { Button } from "antd";
|
|
4
|
+
import { Button, theme } from "antd";
|
|
5
5
|
import { PHI_THEME_GRADIENT_CSS_VARS, } from "../../theme/phi-theme-gradients";
|
|
6
6
|
import { PhiLink } from "../navigation/phi-link";
|
|
7
7
|
import { PhiHoverText } from "./phi-hover-text";
|
|
@@ -12,7 +12,10 @@ import { PhiHoverText } from "./phi-hover-text";
|
|
|
12
12
|
*/
|
|
13
13
|
const PhiLazyBadge = lazy(() => import("antd/es/badge"));
|
|
14
14
|
const PHI_GLASS_BUTTON_FILTER = "blur(12px) saturate(140%)";
|
|
15
|
+
/* How far the badge centre sits outside the icon's top-right corner, in px. */
|
|
16
|
+
const PHI_ICON_ONLY_BADGE_OUTSET = 2;
|
|
15
17
|
export function PhiButtonControl({ label, ariaLabel, ariaPressed, ariaExpanded, href, newTab, external, tooltip, icon, type = "default", shape, danger, ghost, gradient, glass, disabled, readOnly, loading, htmlType, block, size, style, badge, className, ref, onClick, }) {
|
|
18
|
+
const { token } = theme.useToken();
|
|
16
19
|
const visibleTooltip = typeof label === "string" && typeof tooltip === "string" && label === tooltip
|
|
17
20
|
? null
|
|
18
21
|
: tooltip;
|
|
@@ -50,11 +53,22 @@ export function PhiButtonControl({ label, ariaLabel, ariaPressed, ariaExpanded,
|
|
|
50
53
|
* The colour is the Button's. A link states one, and here the Button beneath it already has.
|
|
51
54
|
*/
|
|
52
55
|
const linked = href && !disabled && !readOnly ? (_jsx(PhiLink, { href: href, ...(external === undefined ? {} : { external }), newTab: newTab, prefetch: false, style: { display: "inline-flex", color: "inherit" }, children: button })) : button;
|
|
56
|
+
/*
|
|
57
|
+
* Ant Design centres the badge on the corner of what it wraps. Around a button with a label that is the
|
|
58
|
+
* button's corner, but around an icon-only button the box is far larger than the icon and the count
|
|
59
|
+
* floats beside it. So the count is moved in by the padding between box and icon, leaving it a little
|
|
60
|
+
* outside the icon's corner. Box and icon follow the Button's own size tokens: the height is
|
|
61
|
+
* `controlHeight*`, the icon inherits the content font size (`fontSize`, `fontSizeLG` for large).
|
|
62
|
+
*/
|
|
63
|
+
const iconOnly = icon != null && (label == null || label === false || label === "");
|
|
64
|
+
const iconOnlyHeight = size === "small" ? token.controlHeightSM : size === "large" ? token.controlHeightLG : token.controlHeight;
|
|
65
|
+
const iconOnlySize = size === "large" ? token.fontSizeLG : token.fontSize;
|
|
66
|
+
const iconOnlyInset = Math.max(0, Math.round((iconOnlyHeight - iconOnlySize) / 2 - PHI_ICON_ONLY_BADGE_OUTSET));
|
|
53
67
|
/*
|
|
54
68
|
* Rendered on the Server it is complete, and hydration waits for the chunk. Mounted in the browser before
|
|
55
69
|
* the chunk is there, the Button stands without its count until it arrives.
|
|
56
70
|
*/
|
|
57
|
-
const badged = badge?.enabled ? (_jsx(Suspense, { fallback: linked, children: _jsx(PhiLazyBadge, { color: badge.color, count: badge.value ?? 0, overflowCount: badge.overflowCount, showZero: badge.showZero, size: "small", children: linked }) })) : linked;
|
|
71
|
+
const badged = badge?.enabled ? (_jsx(Suspense, { fallback: linked, children: _jsx(PhiLazyBadge, { color: badge.color, count: badge.value ?? 0, overflowCount: badge.overflowCount, showZero: badge.showZero, size: "small", offset: iconOnly && iconOnlyInset > 0 ? [-iconOnlyInset, iconOnlyInset] : undefined, children: linked }) })) : linked;
|
|
58
72
|
if (!visibleTooltip)
|
|
59
73
|
return badged;
|
|
60
74
|
/*
|
|
@@ -5,6 +5,7 @@ import "../../styles/root.css";
|
|
|
5
5
|
import "../../styles/layout.css";
|
|
6
6
|
import "../../styles/control-shape.css";
|
|
7
7
|
import "../../styles/controls.css";
|
|
8
|
+
import "../../styles/amount-list.css";
|
|
8
9
|
import "../../styles/gradients.css";
|
|
9
10
|
import type { PhiSiteConfig } from "../../types/site-config";
|
|
10
11
|
import type { PhiResolvedLocale } from "../../helpers/site-locale-config";
|
|
@@ -13,6 +13,7 @@ import "../../styles/root.css";
|
|
|
13
13
|
import "../../styles/layout.css";
|
|
14
14
|
import "../../styles/control-shape.css";
|
|
15
15
|
import "../../styles/controls.css";
|
|
16
|
+
import "../../styles/amount-list.css";
|
|
16
17
|
import "../../styles/gradients.css";
|
|
17
18
|
import { getResolvedSiteConfig } from "../../gateway/site-config";
|
|
18
19
|
import { loadPhiAntdLocale } from "../../helpers/antd-locale";
|
package/constants/media.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export declare const PhiMediaAssetSource: {
|
|
|
21
21
|
readonly ThemeGround: "theme-ground";
|
|
22
22
|
/** A Logo a Theme Set offered, taken over when the Theme was saved. */
|
|
23
23
|
readonly ThemeBrandLogo: "theme-brand-logo";
|
|
24
|
+
/** A Signet a Theme Set offered, taken over when the Theme was saved. */
|
|
25
|
+
readonly ThemeBrandSignet: "theme-brand-signet";
|
|
24
26
|
/** Fetched from the Iconify catalogue by the Mask picker. */
|
|
25
27
|
readonly Iconify: "iconify";
|
|
26
28
|
};
|
package/constants/media.js
CHANGED
|
@@ -24,6 +24,8 @@ export const PhiMediaAssetSource = {
|
|
|
24
24
|
ThemeGround: "theme-ground",
|
|
25
25
|
/** A Logo a Theme Set offered, taken over when the Theme was saved. */
|
|
26
26
|
ThemeBrandLogo: "theme-brand-logo",
|
|
27
|
+
/** A Signet a Theme Set offered, taken over when the Theme was saved. */
|
|
28
|
+
ThemeBrandSignet: "theme-brand-signet",
|
|
27
29
|
/** Fetched from the Iconify catalogue by the Mask picker. */
|
|
28
30
|
Iconify: "iconify",
|
|
29
31
|
};
|
package/controls.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type { PhiCompactGroupControlProps } from "./components/controls/phi-comp
|
|
|
9
9
|
export { PhiViewportVisibilityControl } from "./components/controls/phi-viewport-visibility-control";
|
|
10
10
|
export { PhiEntryListControl } from "./components/controls/phi-entry-list-control";
|
|
11
11
|
export type { PhiEntryListControlProps, PhiEntryListEntry } from "./components/controls/phi-entry-list-control";
|
|
12
|
+
export { PhiAmountListControl } from "./components/controls/phi-amount-list-control";
|
|
13
|
+
export type { PhiAmountListControlProps, PhiAmountListItem, PhiAmountListTotal, } from "./components/controls/phi-amount-list-control";
|
|
12
14
|
export { PhiPlacementMatrixControl } from "./components/controls/phi-placement-matrix-control";
|
|
13
15
|
export type { PhiPlacementMatrixControlProps } from "./components/controls/phi-placement-matrix-control";
|
|
14
16
|
export { PhiNumberControl } from "./components/controls/phi-number-control";
|
package/controls.js
CHANGED
|
@@ -4,6 +4,7 @@ export { PHI_CONTROL_SIZES, PHI_FEEDBACK_LEVELS, readPhiControlSize, } from "./t
|
|
|
4
4
|
export { PhiCompactGroupControl } from "./components/controls/phi-compact-group-control";
|
|
5
5
|
export { PhiViewportVisibilityControl } from "./components/controls/phi-viewport-visibility-control";
|
|
6
6
|
export { PhiEntryListControl } from "./components/controls/phi-entry-list-control";
|
|
7
|
+
export { PhiAmountListControl } from "./components/controls/phi-amount-list-control";
|
|
7
8
|
export { PhiPlacementMatrixControl } from "./components/controls/phi-placement-matrix-control";
|
|
8
9
|
export { PhiNumberControl } from "./components/controls/phi-number-control";
|
|
9
10
|
export { PhiPopoverControl } from "./components/controls/phi-popover-control";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { NextRequest } from "next/server";
|
|
3
|
+
import type { PhiNextProxyHandler } from "../net/phi-next-proxy";
|
|
4
|
+
import type { PhiSiteAreaBridgeLoader } from "./site-area-bridges";
|
|
5
|
+
/**
|
|
6
|
+
* `GET /api/site/signet`: the Signet the Site owns, as a picture at a real address.
|
|
7
|
+
*
|
|
8
|
+
* Only the Site's own, `theme.brand.signet` of the published record, which a Theme save writes
|
|
9
|
+
* (`materializePhiThemeBrandSignet`). A Theme Set's Signet is not resolved here: that needs the Theme
|
|
10
|
+
* blocks of the installed Modules, a graph this door does not carry, and the head names a followed Set's
|
|
11
|
+
* Signet as the data URL it is instead. An Asset is read through the media door; an inline `data:image/`
|
|
12
|
+
* picture is decoded. An address on another server is answered 404 and not redirected: a redirect from
|
|
13
|
+
* the favicon path would send every visitor's request to a third party, the head cannot name it, and
|
|
14
|
+
* nothing writes one -- the save uploads what it finds.
|
|
15
|
+
*
|
|
16
|
+
* Three ways in, one picture. The head names `?v=<identifier>`; the proxy rewrites the browser's own
|
|
17
|
+
* `/favicon.ico`, `/apple-touch-icon.png` and `/apple-touch-icon-precomposed.png` to `?as=favicon|apple`.
|
|
18
|
+
* An Apple path answers only for a PNG of 180 px or more -- anything else would be scaled into a blur.
|
|
19
|
+
* No Site Signet, or one that cannot be delivered, answers 404.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildPhiSignetRouteHandler({ loadAreaBridge, proxied, }: {
|
|
22
|
+
loadAreaBridge: PhiSiteAreaBridgeLoader;
|
|
23
|
+
proxied: PhiNextProxyHandler;
|
|
24
|
+
}): (request: NextRequest) => Promise<Response>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { NextRequest } from "next/server";
|
|
3
|
+
import { readPhiThemeSiteSignet } from "../theme/phi-theme-signet";
|
|
4
|
+
import { PHI_SIGNET_ALIAS_PARAM, PHI_SIGNET_APPLE_MIN_SIZE, PHI_SIGNET_VERSION_PARAM } from "../helpers/phi-signet-paths";
|
|
5
|
+
import { buildPhiSignetVersion, decodePhiSignetDataUrl, readPhiPngSize, } from "../helpers/phi-signet";
|
|
6
|
+
import { getResolvedSiteConfig } from "./site-config";
|
|
7
|
+
/** An address that names the picture's own content never changes what it answers: a year, immutable. */
|
|
8
|
+
const PHI_SIGNET_CACHE_IDENTIFIED = "public, max-age=31536000, immutable";
|
|
9
|
+
/**
|
|
10
|
+
* Everything else: the browser's own `/favicon.ico` and Apple paths, an address whose identifier is not
|
|
11
|
+
* the current one, and a library picture, whose identifier cannot see the bytes. Short, so a changed
|
|
12
|
+
* Signet reaches the tab within the hour.
|
|
13
|
+
*/
|
|
14
|
+
const PHI_SIGNET_CACHE_SHORT = "public, max-age=3600";
|
|
15
|
+
const PHI_SIGNET_CACHE_MISSING = "public, max-age=300";
|
|
16
|
+
/**
|
|
17
|
+
* The picture is only ever shown by an `<img>` or the tab, but its address can be opened as a document,
|
|
18
|
+
* and an SVG is a document. The sandbox and the empty policy keep a script in one from running on the
|
|
19
|
+
* Site's origin.
|
|
20
|
+
*/
|
|
21
|
+
const PHI_SIGNET_SECURITY_HEADERS = {
|
|
22
|
+
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox",
|
|
23
|
+
"x-content-type-options": "nosniff",
|
|
24
|
+
};
|
|
25
|
+
function missing() {
|
|
26
|
+
return new Response(null, { status: 404, headers: { "cache-control": PHI_SIGNET_CACHE_MISSING } });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A library picture, read through the same door every Asset is delivered by.
|
|
30
|
+
*
|
|
31
|
+
* Not redirected: the Apple path has to know whether the bytes are a PNG of 180 px, and the tab should
|
|
32
|
+
* not depend on a second request that follows a first. Anything that is not an image answers null.
|
|
33
|
+
*/
|
|
34
|
+
async function readPhiSignetAsset(assetId, request, proxied) {
|
|
35
|
+
const upstream = await proxied(new NextRequest(new URL(`/api/site/media/${assetId}/content`, request.url), { headers: request.headers }), { params: Promise.resolve({ path: ["media", String(assetId), "content"] }) });
|
|
36
|
+
const contentType = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
37
|
+
if (!upstream.ok || !contentType.startsWith("image/"))
|
|
38
|
+
return null;
|
|
39
|
+
return { contentType, bytes: new Uint8Array(await upstream.arrayBuffer()) };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* `GET /api/site/signet`: the Signet the Site owns, as a picture at a real address.
|
|
43
|
+
*
|
|
44
|
+
* Only the Site's own, `theme.brand.signet` of the published record, which a Theme save writes
|
|
45
|
+
* (`materializePhiThemeBrandSignet`). A Theme Set's Signet is not resolved here: that needs the Theme
|
|
46
|
+
* blocks of the installed Modules, a graph this door does not carry, and the head names a followed Set's
|
|
47
|
+
* Signet as the data URL it is instead. An Asset is read through the media door; an inline `data:image/`
|
|
48
|
+
* picture is decoded. An address on another server is answered 404 and not redirected: a redirect from
|
|
49
|
+
* the favicon path would send every visitor's request to a third party, the head cannot name it, and
|
|
50
|
+
* nothing writes one -- the save uploads what it finds.
|
|
51
|
+
*
|
|
52
|
+
* Three ways in, one picture. The head names `?v=<identifier>`; the proxy rewrites the browser's own
|
|
53
|
+
* `/favicon.ico`, `/apple-touch-icon.png` and `/apple-touch-icon-precomposed.png` to `?as=favicon|apple`.
|
|
54
|
+
* An Apple path answers only for a PNG of 180 px or more -- anything else would be scaled into a blur.
|
|
55
|
+
* No Site Signet, or one that cannot be delivered, answers 404.
|
|
56
|
+
*/
|
|
57
|
+
export function buildPhiSignetRouteHandler({ loadAreaBridge, proxied, }) {
|
|
58
|
+
return async function GET(request) {
|
|
59
|
+
// Any Bridge knows the Site's key and its Core; the Public one is the one every Site has.
|
|
60
|
+
const runtime = (await loadAreaBridge("public"))?.runtime;
|
|
61
|
+
if (!runtime)
|
|
62
|
+
return missing();
|
|
63
|
+
const site = await getResolvedSiteConfig({
|
|
64
|
+
apiBaseUrl: runtime.apiBaseUrl,
|
|
65
|
+
internalToken: runtime.internalToken,
|
|
66
|
+
siteKey: runtime.siteKey,
|
|
67
|
+
});
|
|
68
|
+
const signet = readPhiThemeSiteSignet(site.theme?.brand?.signet);
|
|
69
|
+
if (!signet)
|
|
70
|
+
return missing();
|
|
71
|
+
let image;
|
|
72
|
+
let identity;
|
|
73
|
+
if (signet.kind === "data") {
|
|
74
|
+
image = decodePhiSignetDataUrl(signet.source);
|
|
75
|
+
identity = image?.bytes ?? "";
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
image = await readPhiSignetAsset(signet.assetId, request, proxied);
|
|
79
|
+
identity = `asset:${signet.assetId}`;
|
|
80
|
+
}
|
|
81
|
+
if (!image)
|
|
82
|
+
return missing();
|
|
83
|
+
const alias = request.nextUrl.searchParams.get(PHI_SIGNET_ALIAS_PARAM);
|
|
84
|
+
if (alias === "apple") {
|
|
85
|
+
const dimensions = image.contentType === "image/png" ? readPhiPngSize(image.bytes) : null;
|
|
86
|
+
if (!dimensions || dimensions.width < PHI_SIGNET_APPLE_MIN_SIZE || dimensions.height < PHI_SIGNET_APPLE_MIN_SIZE) {
|
|
87
|
+
return missing();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const asked = request.nextUrl.searchParams.get(PHI_SIGNET_VERSION_PARAM);
|
|
91
|
+
const identified = alias === null && asked === buildPhiSignetVersion(identity);
|
|
92
|
+
return new Response(Buffer.from(image.bytes), {
|
|
93
|
+
status: 200,
|
|
94
|
+
headers: {
|
|
95
|
+
"content-type": image.contentType,
|
|
96
|
+
"content-length": String(image.bytes.length),
|
|
97
|
+
"cache-control": identified && signet.kind === "data" ? PHI_SIGNET_CACHE_IDENTIFIED : PHI_SIGNET_CACHE_SHORT,
|
|
98
|
+
...PHI_SIGNET_SECURITY_HEADERS,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
}
|
package/gateway/site-proxy.js
CHANGED
|
@@ -7,8 +7,10 @@ import { clearPhiSiteReadCache } from "./site-read-cache";
|
|
|
7
7
|
* `module-diagnostics` compares what this Site's Modules require against what its server offers;
|
|
8
8
|
* `navigation-target` resolves where a forwarding Area root would send this viewer; and
|
|
9
9
|
* `dashboard-cards` fans the Area's active Modules in to one list of cards, then answers each card's
|
|
10
|
-
* payload;
|
|
11
|
-
*
|
|
10
|
+
* payload; `page-references` lists the Pages of an Area a link may point at; and `signet` delivers the
|
|
11
|
+
* Theme's Signet as a picture, the address the document head and `/favicon.ico` lead to
|
|
12
|
+
* (`gateway/signet-route.ts`). All six read the Site's own Module catalogs, which phi-server
|
|
13
|
+
* deliberately knows nothing about.
|
|
12
14
|
*
|
|
13
15
|
* They are one segment each and matched exactly, so nothing deeper is captured by accident: an Asset
|
|
14
16
|
* under `/api/site/media/...` goes upstream as it always did. It is also why `dashboard-cards` names
|
|
@@ -20,6 +22,7 @@ const LOCALLY_ANSWERED = [
|
|
|
20
22
|
"navigation-target",
|
|
21
23
|
"dashboard-cards",
|
|
22
24
|
"page-references",
|
|
25
|
+
"signet",
|
|
23
26
|
];
|
|
24
27
|
function locallyAnswered(path) {
|
|
25
28
|
const first = path?.length === 1 ? path[0] : null;
|
|
@@ -32,7 +35,7 @@ function locallyAnswered(path) {
|
|
|
32
35
|
* package. Importing that at module scope would put it in the graph of a route that for nearly every
|
|
33
36
|
* request only copies bytes to Core and back.
|
|
34
37
|
*/
|
|
35
|
-
async function buildLocallyAnsweredHandlers(answered, { upstreamBaseUrl, timeoutMs, buildHeaders, loadAreaBridge }) {
|
|
38
|
+
async function buildLocallyAnsweredHandlers(answered, { upstreamBaseUrl, timeoutMs, buildHeaders, loadAreaBridge }, proxied) {
|
|
36
39
|
if (answered === "forms") {
|
|
37
40
|
const { buildPhiSiteFormRouteHandlers } = await import("./site-form-route");
|
|
38
41
|
const handlers = buildPhiSiteFormRouteHandlers({
|
|
@@ -56,6 +59,10 @@ async function buildLocallyAnsweredHandlers(answered, { upstreamBaseUrl, timeout
|
|
|
56
59
|
const { buildPhiPageReferencesRouteHandler } = await import("./page-references-route");
|
|
57
60
|
return { GET: buildPhiPageReferencesRouteHandler({ loadAreaBridge }) };
|
|
58
61
|
}
|
|
62
|
+
if (answered === "signet") {
|
|
63
|
+
const { buildPhiSignetRouteHandler } = await import("./signet-route");
|
|
64
|
+
return { GET: buildPhiSignetRouteHandler({ loadAreaBridge, proxied }) };
|
|
65
|
+
}
|
|
59
66
|
const { buildPhiNavigationTargetRouteHandler } = await import("./navigation-target-route");
|
|
60
67
|
return { GET: buildPhiNavigationTargetRouteHandler({ loadAreaBridge }) };
|
|
61
68
|
}
|
|
@@ -133,13 +140,13 @@ export function buildPhiSiteProxyHandlers(options) {
|
|
|
133
140
|
}
|
|
134
141
|
let pending = built.get(answered);
|
|
135
142
|
if (!pending) {
|
|
136
|
-
pending = buildLocallyAnsweredHandlers(answered, options);
|
|
143
|
+
pending = buildLocallyAnsweredHandlers(answered, options, handlers.GET);
|
|
137
144
|
built.set(answered, pending);
|
|
138
145
|
}
|
|
139
|
-
const
|
|
140
|
-
const local =
|
|
146
|
+
const answeredHandlers = await pending;
|
|
147
|
+
const local = answeredHandlers[method] ?? (method === "HEAD" ? answeredHandlers.GET : undefined);
|
|
141
148
|
if (!local) {
|
|
142
|
-
const allow = Object.keys(
|
|
149
|
+
const allow = Object.keys(answeredHandlers).join(", ");
|
|
143
150
|
return new Response(null, { status: 405, headers: { allow } });
|
|
144
151
|
}
|
|
145
152
|
return local(request, context);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Metadata } from "next";
|
|
2
2
|
import type { PhiCmsAreaKey } from "../constants/cms-areas";
|
|
3
3
|
import { type PhiAreaMeta } from "./cms-area-config";
|
|
4
|
+
import type { PhiSignetHead } from "./phi-signet-head";
|
|
4
5
|
import { type PhiPublicPageAddress } from "./phi-seo";
|
|
5
6
|
export type PhiMetadataScope = {
|
|
6
7
|
title?: string | null;
|
|
@@ -17,14 +18,15 @@ export type PhiRootMetadataInput = {
|
|
|
17
18
|
area?: PhiMetadataScope | null;
|
|
18
19
|
page?: PhiMetadataScope | null;
|
|
19
20
|
/**
|
|
20
|
-
* The Signet
|
|
21
|
-
* draw their own mark.
|
|
21
|
+
* The Signet as the head names it (`describePhiSignetHead`).
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* The Site's own is the address it delivers it at, with its media type and size where they are known;
|
|
24
|
+
* `apple` is present only where the picture is a PNG of at least 180 px, because an Apple touch icon
|
|
25
|
+
* has to be a raster of a stated size. A followed Set's Signet is its data URL and nothing else:
|
|
26
|
+
* Chrome and Firefox show it, Safari does not, and a Theme save is what gives the Site a real address.
|
|
27
|
+
* A Site that has no Signet says nothing at all here, and `/favicon.ico` answers 404 for it.
|
|
26
28
|
*/
|
|
27
|
-
signet?:
|
|
29
|
+
signet?: PhiSignetHead | null;
|
|
28
30
|
};
|
|
29
31
|
export declare function buildPhiRootMetadata(options?: PhiRootMetadataInput): Metadata;
|
|
30
32
|
/**
|
package/helpers/phi-metadata.js
CHANGED
|
@@ -36,7 +36,7 @@ export function buildPhiRootMetadata(options = {}) {
|
|
|
36
36
|
const resolvedDescription = resolveFirstText(options.page?.description, options.area?.description, options.site?.description, options.defaultDescription);
|
|
37
37
|
const resolvedApplicationName = resolveFirstText(options.applicationName, resolvedSiteTitle, resolvedAreaTitle);
|
|
38
38
|
const resolvedMetadataBase = resolveMetadataBase(options.metadataBase);
|
|
39
|
-
const
|
|
39
|
+
const signet = options.signet?.href?.trim() ? options.signet : null;
|
|
40
40
|
const shouldNoIndex = options.page?.noindex === true ||
|
|
41
41
|
options.area?.noindex === true ||
|
|
42
42
|
options.site?.noindex === true;
|
|
@@ -44,7 +44,14 @@ export function buildPhiRootMetadata(options = {}) {
|
|
|
44
44
|
...(resolvedMetadataBase ? { metadataBase: resolvedMetadataBase } : {}),
|
|
45
45
|
...(resolvedApplicationName ? { applicationName: resolvedApplicationName } : {}),
|
|
46
46
|
...(resolvedDescription ? { description: resolvedDescription } : {}),
|
|
47
|
-
...(
|
|
47
|
+
...(signet
|
|
48
|
+
? {
|
|
49
|
+
icons: {
|
|
50
|
+
icon: { url: signet.href, ...(signet.type ? { type: signet.type } : {}), ...(signet.sizes ? { sizes: signet.sizes } : {}) },
|
|
51
|
+
...(signet.apple ? { apple: { url: signet.apple.href, type: signet.apple.type, sizes: signet.apple.sizes } } : {}),
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
: {}),
|
|
48
55
|
...(shouldNoIndex
|
|
49
56
|
? {
|
|
50
57
|
robots: {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PhiThemeSignet } from "../theme/phi-theme-signet";
|
|
2
|
+
/** What the document head needs to say about the Signet; `appleHref` only where a raster of 180 px or more is known. */
|
|
3
|
+
export type PhiSignetHead = {
|
|
4
|
+
href: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
sizes?: string;
|
|
7
|
+
apple?: {
|
|
8
|
+
href: string;
|
|
9
|
+
type: string;
|
|
10
|
+
sizes: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The head entries for a Signet, or null where it cannot be delivered and the head says nothing.
|
|
15
|
+
*
|
|
16
|
+
* Only the Site's own Signet has an address of its own. A Set's -- the Site follows, nothing saved --
|
|
17
|
+
* is named as the data URL it is: Chrome and Firefox show it, Safari does not, and the save that takes it
|
|
18
|
+
* into the Media library is what gives that Site an icon there.
|
|
19
|
+
*
|
|
20
|
+
* A data URL that does not decode is not named: pointing the tab at an address that answers 404 would
|
|
21
|
+
* be worse than leaving the browser its own `/favicon.ico` request. An Asset is named without a type or
|
|
22
|
+
* a size, because the picture is not at hand here -- the response carries its type, and the Apple path
|
|
23
|
+
* answers for itself from the bytes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function describePhiSignetHead(signet: PhiThemeSignet | null | undefined): PhiSignetHead | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PHI_SIGNET_APPLE_MIN_SIZE, PHI_SIGNET_PATH, PHI_SIGNET_VERSION_PARAM } from "./phi-signet-paths";
|
|
2
|
+
import { buildPhiSignetVersion, decodePhiSignetDataUrl, readPhiPngSize } from "./phi-signet";
|
|
3
|
+
function buildPhiSignetHref(version) {
|
|
4
|
+
return `${PHI_SIGNET_PATH}?${PHI_SIGNET_VERSION_PARAM}=${version}`;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The head entries for a Signet, or null where it cannot be delivered and the head says nothing.
|
|
8
|
+
*
|
|
9
|
+
* Only the Site's own Signet has an address of its own. A Set's -- the Site follows, nothing saved --
|
|
10
|
+
* is named as the data URL it is: Chrome and Firefox show it, Safari does not, and the save that takes it
|
|
11
|
+
* into the Media library is what gives that Site an icon there.
|
|
12
|
+
*
|
|
13
|
+
* A data URL that does not decode is not named: pointing the tab at an address that answers 404 would
|
|
14
|
+
* be worse than leaving the browser its own `/favicon.ico` request. An Asset is named without a type or
|
|
15
|
+
* a size, because the picture is not at hand here -- the response carries its type, and the Apple path
|
|
16
|
+
* answers for itself from the bytes.
|
|
17
|
+
*/
|
|
18
|
+
export function describePhiSignetHead(signet) {
|
|
19
|
+
if (!signet)
|
|
20
|
+
return null;
|
|
21
|
+
if (signet.from === "set")
|
|
22
|
+
return signet.kind === "data" ? { href: signet.source } : null;
|
|
23
|
+
if (signet.kind === "asset") {
|
|
24
|
+
return { href: buildPhiSignetHref(buildPhiSignetVersion(`asset:${signet.assetId}`)) };
|
|
25
|
+
}
|
|
26
|
+
const image = decodePhiSignetDataUrl(signet.source);
|
|
27
|
+
if (!image)
|
|
28
|
+
return null;
|
|
29
|
+
const href = buildPhiSignetHref(buildPhiSignetVersion(image.bytes));
|
|
30
|
+
const dimensions = image.contentType === "image/png" ? readPhiPngSize(image.bytes) : null;
|
|
31
|
+
const sizes = dimensions ? `${dimensions.width}x${dimensions.height}` : undefined;
|
|
32
|
+
const apple = dimensions && dimensions.width >= PHI_SIGNET_APPLE_MIN_SIZE && dimensions.height >= PHI_SIGNET_APPLE_MIN_SIZE
|
|
33
|
+
? { href, type: image.contentType, sizes: sizes }
|
|
34
|
+
: undefined;
|
|
35
|
+
return {
|
|
36
|
+
href,
|
|
37
|
+
type: image.contentType,
|
|
38
|
+
...(sizes ? { sizes } : {}),
|
|
39
|
+
...(apple ? { apple } : {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a Site's Signet is delivered, and how the browser's own guesses reach it.
|
|
3
|
+
*
|
|
4
|
+
* One address under `/api/site`, the door every Site already mounts, so no Site file names it. The
|
|
5
|
+
* proxy rewrites `/favicon.ico` and the two Apple touch icon paths to it (`next/site-proxy.ts`), which
|
|
6
|
+
* is how a browser that never read the document head -- Safari asks for these on its own -- still gets
|
|
7
|
+
* the mark. `as` says which of those it was.
|
|
8
|
+
*/
|
|
9
|
+
export declare const PHI_SIGNET_PATH = "/api/site/signet";
|
|
10
|
+
export declare const PHI_SIGNET_VERSION_PARAM = "v";
|
|
11
|
+
export declare const PHI_SIGNET_ALIAS_PARAM = "as";
|
|
12
|
+
export type PhiSignetAlias = "favicon" | "apple";
|
|
13
|
+
/** The paths a browser asks for unprompted, and which answer each one stands for. */
|
|
14
|
+
export declare const PHI_SIGNET_ALIAS_PATHS: Readonly<Record<string, PhiSignetAlias>>;
|
|
15
|
+
/** The smallest square an Apple touch icon may be; a smaller one is scaled up and looks it. */
|
|
16
|
+
export declare const PHI_SIGNET_APPLE_MIN_SIZE = 180;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a Site's Signet is delivered, and how the browser's own guesses reach it.
|
|
3
|
+
*
|
|
4
|
+
* One address under `/api/site`, the door every Site already mounts, so no Site file names it. The
|
|
5
|
+
* proxy rewrites `/favicon.ico` and the two Apple touch icon paths to it (`next/site-proxy.ts`), which
|
|
6
|
+
* is how a browser that never read the document head -- Safari asks for these on its own -- still gets
|
|
7
|
+
* the mark. `as` says which of those it was.
|
|
8
|
+
*/
|
|
9
|
+
export const PHI_SIGNET_PATH = "/api/site/signet";
|
|
10
|
+
export const PHI_SIGNET_VERSION_PARAM = "v";
|
|
11
|
+
export const PHI_SIGNET_ALIAS_PARAM = "as";
|
|
12
|
+
/** The paths a browser asks for unprompted, and which answer each one stands for. */
|
|
13
|
+
export const PHI_SIGNET_ALIAS_PATHS = {
|
|
14
|
+
"/favicon.ico": "favicon",
|
|
15
|
+
"/apple-touch-icon.png": "apple",
|
|
16
|
+
"/apple-touch-icon-precomposed.png": "apple",
|
|
17
|
+
};
|
|
18
|
+
/** The smallest square an Apple touch icon may be; a smaller one is scaled up and looks it. */
|
|
19
|
+
export const PHI_SIGNET_APPLE_MIN_SIZE = 180;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type PhiSignetImage = {
|
|
2
|
+
contentType: string;
|
|
3
|
+
bytes: Uint8Array;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The picture a data URL carries, or null for anything the route does not deliver.
|
|
7
|
+
*
|
|
8
|
+
* Only PNG, SVG, ICO and WebP, and only as `;base64` -- or, for SVG alone, as text (`;utf8` or none),
|
|
9
|
+
* percent-decoded, which is how a drawing is written inline. A raster as text is not a thing, and any
|
|
10
|
+
* other media type is somebody's mistake or somebody's attempt; both answer null, which the route
|
|
11
|
+
* turns into a 404.
|
|
12
|
+
*/
|
|
13
|
+
export declare function decodePhiSignetDataUrl(source: string): PhiSignetImage | null;
|
|
14
|
+
/** The pixel size a PNG's header states, or null for bytes that are not a PNG with a header. */
|
|
15
|
+
export declare function readPhiPngSize(bytes: Uint8Array): {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
} | null;
|
|
19
|
+
/**
|
|
20
|
+
* A short identifier of what a Signet shows, for the address the head names.
|
|
21
|
+
*
|
|
22
|
+
* Of the picture's own bytes where the Signet is inline, so the same picture is the same address
|
|
23
|
+
* whichever Set or record carries it and a changed one is a new address -- which is what lets that
|
|
24
|
+
* address be cached for a year. Of the Asset's id where it is a library picture: the bytes are not
|
|
25
|
+
* known where the head is written, so a picture replaced in place under the same id keeps its address
|
|
26
|
+
* (and is therefore delivered with a short cache, see the route).
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildPhiSignetVersion(identity: Uint8Array | string): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
const PHI_SIGNET_DATA_URL = /^data:(image\/(?:png|svg\+xml|x-icon|webp))((?:;(?:utf8|charset=[A-Za-z0-9-]+))*)(;base64)?,(.*)$/su;
|
|
3
|
+
const PHI_BASE64 = /^[A-Za-z0-9+/]+={0,2}$/u;
|
|
4
|
+
const PHI_PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
5
|
+
/**
|
|
6
|
+
* The picture a data URL carries, or null for anything the route does not deliver.
|
|
7
|
+
*
|
|
8
|
+
* Only PNG, SVG, ICO and WebP, and only as `;base64` -- or, for SVG alone, as text (`;utf8` or none),
|
|
9
|
+
* percent-decoded, which is how a drawing is written inline. A raster as text is not a thing, and any
|
|
10
|
+
* other media type is somebody's mistake or somebody's attempt; both answer null, which the route
|
|
11
|
+
* turns into a 404.
|
|
12
|
+
*/
|
|
13
|
+
export function decodePhiSignetDataUrl(source) {
|
|
14
|
+
const match = PHI_SIGNET_DATA_URL.exec(source.trim());
|
|
15
|
+
if (!match)
|
|
16
|
+
return null;
|
|
17
|
+
const [, contentType, , base64, payload] = match;
|
|
18
|
+
if (base64) {
|
|
19
|
+
const compact = payload.replace(/\s+/gu, "");
|
|
20
|
+
if (!compact || compact.length % 4 === 1 || !PHI_BASE64.test(compact))
|
|
21
|
+
return null;
|
|
22
|
+
const bytes = Buffer.from(compact, "base64");
|
|
23
|
+
return bytes.length > 0 ? { contentType, bytes: new Uint8Array(bytes) } : null;
|
|
24
|
+
}
|
|
25
|
+
if (contentType !== "image/svg+xml" || !payload)
|
|
26
|
+
return null;
|
|
27
|
+
try {
|
|
28
|
+
return { contentType, bytes: new TextEncoder().encode(decodeURIComponent(payload)) };
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** The pixel size a PNG's header states, or null for bytes that are not a PNG with a header. */
|
|
35
|
+
export function readPhiPngSize(bytes) {
|
|
36
|
+
if (bytes.length < 24)
|
|
37
|
+
return null;
|
|
38
|
+
if (PHI_PNG_SIGNATURE.some((value, index) => bytes[index] !== value))
|
|
39
|
+
return null;
|
|
40
|
+
// The first chunk is always IHDR: length (4), the name (4), then width and height, big endian.
|
|
41
|
+
if (String.fromCharCode(bytes[12], bytes[13], bytes[14], bytes[15]) !== "IHDR")
|
|
42
|
+
return null;
|
|
43
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
44
|
+
const width = view.getUint32(16);
|
|
45
|
+
const height = view.getUint32(20);
|
|
46
|
+
return width > 0 && height > 0 ? { width, height } : null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A short identifier of what a Signet shows, for the address the head names.
|
|
50
|
+
*
|
|
51
|
+
* Of the picture's own bytes where the Signet is inline, so the same picture is the same address
|
|
52
|
+
* whichever Set or record carries it and a changed one is a new address -- which is what lets that
|
|
53
|
+
* address be cached for a year. Of the Asset's id where it is a library picture: the bytes are not
|
|
54
|
+
* known where the head is written, so a picture replaced in place under the same id keeps its address
|
|
55
|
+
* (and is therefore delivered with a short cache, see the route).
|
|
56
|
+
*/
|
|
57
|
+
export function buildPhiSignetVersion(identity) {
|
|
58
|
+
return createHash("sha256").update(identity).digest("hex").slice(0, 10);
|
|
59
|
+
}
|