@phis/ui 0.5.7 → 0.6.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.
Files changed (116) hide show
  1. package/components/controls/phi-amount-list-control.d.ts +69 -0
  2. package/components/controls/phi-amount-list-control.js +15 -0
  3. package/components/controls/phi-button-control.js +16 -2
  4. package/components/controls/phi-form-control.d.ts +6 -0
  5. package/components/controls/phi-form-control.js +23 -7
  6. package/components/controls/phi-media-picker-control.d.ts +3 -1
  7. package/components/controls/phi-media-picker-control.js +2 -2
  8. package/components/forms/form-descriptor-runtime-client.d.ts +3 -1
  9. package/components/forms/form-descriptor-runtime-client.js +2 -2
  10. package/components/forms/form-field-provider-modules.d.ts +23 -0
  11. package/components/forms/form-field-provider-modules.js +28 -0
  12. package/components/forms/form-provider-contract.d.ts +7 -0
  13. package/components/forms/form-provider-contract.js +7 -0
  14. package/components/forms/lazy-form-field-control.d.ts +14 -0
  15. package/components/forms/lazy-form-field-control.js +35 -0
  16. package/components/forms/phi-form-widget.d.ts +3 -2
  17. package/components/forms/phi-form-widget.js +21 -3
  18. package/components/forms/shared-form-provider-registry.js +1 -33
  19. package/components/media/phi-area-upload-widget.js +6 -58
  20. package/components/media/phi-media-picker-binding.d.ts +16 -1
  21. package/components/media/phi-media-picker-binding.js +3 -2
  22. package/components/media/phi-media-upload.d.ts +12 -0
  23. package/components/media/phi-media-upload.js +22 -0
  24. package/components/media/phi-upload-drop-area.d.ts +22 -0
  25. package/components/media/phi-upload-drop-area.js +49 -0
  26. package/components/root/phi-root-layout.d.ts +1 -0
  27. package/components/root/phi-root-layout.js +1 -0
  28. package/components/widgets/helpers/semantic-html-translation.d.ts +4 -1
  29. package/components/widgets/helpers/semantic-html-translation.js +4 -2
  30. package/components/widgets/label-sets/admin-users.d.ts +9 -1
  31. package/components/widgets/label-sets/admin-users.js +14 -2
  32. package/components/widgets/label-sets/slot-upload.js +6 -3
  33. package/components/widgets/label-types/slot-upload.d.ts +7 -1
  34. package/components/widgets/label-types/slot-upload.js +2 -1
  35. package/components/widgets/shared/markdown-render.js +6 -6
  36. package/constants/media-library-provider-keys.d.ts +9 -0
  37. package/constants/media-library-provider-keys.js +9 -0
  38. package/constants/media.d.ts +2 -0
  39. package/constants/media.js +2 -0
  40. package/constants/runtime-module-ownership.js +2 -0
  41. package/controls.d.ts +4 -0
  42. package/controls.js +2 -0
  43. package/gateway/signet-route.d.ts +24 -0
  44. package/gateway/signet-route.js +107 -0
  45. package/gateway/site-proxy.js +14 -7
  46. package/helpers/phi-metadata.d.ts +8 -6
  47. package/helpers/phi-metadata.js +9 -2
  48. package/helpers/phi-signet-head.d.ts +26 -0
  49. package/helpers/phi-signet-head.js +53 -0
  50. package/helpers/phi-signet-paths.d.ts +16 -0
  51. package/helpers/phi-signet-paths.js +19 -0
  52. package/helpers/phi-signet.d.ts +40 -0
  53. package/helpers/phi-signet.js +70 -0
  54. package/net/phi-next-proxy.d.ts +10 -8
  55. package/net/phi-next-proxy.js +27 -84
  56. package/next/proxy-runtime.js +15 -0
  57. package/next/root-route.js +7 -4
  58. package/next/site-proxy.js +21 -0
  59. package/package.json +3 -3
  60. package/plugins/runtime-modules/area-definitions.d.ts +24 -3
  61. package/plugins/runtime-modules/area-definitions.js +11 -3
  62. package/plugins/runtime-modules/asset/definition.d.ts +44 -2
  63. package/plugins/runtime-modules/asset/definition.js +5 -2
  64. package/plugins/runtime-modules/asset/form-providers.d.ts +63 -0
  65. package/plugins/runtime-modules/asset/form-providers.js +54 -0
  66. package/plugins/runtime-modules/asset/form-ui-provider.js +13 -3
  67. package/plugins/runtime-modules/asset/media-asset-field.d.ts +20 -0
  68. package/plugins/runtime-modules/asset/media-asset-field.js +33 -0
  69. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +21 -0
  70. package/plugins/runtime-modules/asset/media-asset-form-control.js +74 -0
  71. package/plugins/runtime-modules/core/widgets/html/server.js +1 -1
  72. package/plugins/runtime-modules/core/widgets/slot-upload/client.js +28 -23
  73. package/plugins/runtime-modules/core/widgets/slot-upload/slot.d.ts +19 -0
  74. package/plugins/runtime-modules/core/widgets/slot-upload/slot.js +16 -0
  75. package/plugins/runtime-modules/public/presets.d.ts +12 -0
  76. package/plugins/runtime-modules/public/presets.js +10 -0
  77. package/plugins/runtime-modules/public/server.js +1 -1
  78. package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.d.ts +4 -0
  79. package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.js +66 -0
  80. package/plugins/runtime-modules/public-base-page-references.d.ts +2 -1
  81. package/plugins/runtime-modules/public-base-page-references.js +2 -1
  82. package/plugins/runtime-modules/resolver.js +38 -4
  83. package/plugins/runtime-modules/theme/controller/runtime.js +7 -2
  84. package/plugins/runtime-modules/theme/materialize-images.d.ts +16 -0
  85. package/plugins/runtime-modules/theme/materialize-images.js +37 -0
  86. package/plugins/runtime-modules/user-management/addon-roles.d.ts +35 -0
  87. package/plugins/runtime-modules/user-management/addon-roles.js +76 -0
  88. package/plugins/runtime-modules/user-management/cards.js +1 -1
  89. package/plugins/runtime-modules/user-management/client-data-providers.js +6 -0
  90. package/plugins/runtime-modules/user-management/data-providers.d.ts +11 -2
  91. package/plugins/runtime-modules/user-management/data-providers.js +12 -1
  92. package/plugins/runtime-modules/user-management/definition.d.ts +11 -2
  93. package/plugins/runtime-modules/user-management/ids.d.ts +1 -0
  94. package/plugins/runtime-modules/user-management/ids.js +1 -0
  95. package/plugins/runtime-modules/user-management/services/options.d.ts +8 -0
  96. package/plugins/runtime-modules/user-management/services/options.js +25 -0
  97. package/plugins/runtime-modules/user-management/services/table.js +9 -1
  98. package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +20 -2
  99. package/server-helpers/cms-widget-texts.js +1 -1
  100. package/server-helpers/search-index.js +22 -13
  101. package/server-helpers/search-text.d.ts +3 -2
  102. package/server-helpers/search-text.js +6 -5
  103. package/server-helpers/translate.d.ts +13 -2
  104. package/server-helpers/translate.js +10 -6
  105. package/styles/amount-list.css +142 -0
  106. package/styles/controls.css +156 -7
  107. package/styles/gradients.css +21 -20
  108. package/theme/phi-theme-blocks.d.ts +7 -6
  109. package/theme/phi-theme-composition.d.ts +19 -1
  110. package/theme/phi-theme-composition.js +15 -0
  111. package/theme/phi-theme-signet.d.ts +31 -0
  112. package/theme/phi-theme-signet.js +53 -0
  113. package/theme/phi-tokens.d.ts +1 -1
  114. package/theme/phi-tokens.js +5 -1
  115. package/types/cms-plugins.d.ts +10 -1
  116. package/types/site-theme.d.ts +29 -0
package/controls.d.ts CHANGED
@@ -9,6 +9,10 @@ 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";
14
+ export { PhiFileDropControl } from "./components/controls/phi-file-drop-control";
15
+ export type { PhiFileDropControlProps } from "./components/controls/phi-file-drop-control";
12
16
  export { PhiPlacementMatrixControl } from "./components/controls/phi-placement-matrix-control";
13
17
  export type { PhiPlacementMatrixControlProps } from "./components/controls/phi-placement-matrix-control";
14
18
  export { PhiNumberControl } from "./components/controls/phi-number-control";
package/controls.js CHANGED
@@ -4,6 +4,8 @@ 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";
8
+ export { PhiFileDropControl } from "./components/controls/phi-file-drop-control";
7
9
  export { PhiPlacementMatrixControl } from "./components/controls/phi-placement-matrix-control";
8
10
  export { PhiNumberControl } from "./components/controls/phi-number-control";
9
11
  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,107 @@
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 { buildPhiSignetAssetIdentity, buildPhiSignetVersion, decodePhiSignetDataUrl, readPhiPngSize, } from "../helpers/phi-signet";
6
+ import { getResolvedSiteConfig } from "./site-config";
7
+ /**
8
+ * An address that names the picture's own content never changes what it answers: a year, immutable. For a
9
+ * library picture that is the identifier built from the Asset's revision, which moves with the bytes.
10
+ */
11
+ const PHI_SIGNET_CACHE_IDENTIFIED = "public, max-age=31536000, immutable";
12
+ /**
13
+ * Everything else: the browser's own `/favicon.ico` and Apple paths, an address whose identifier is not
14
+ * the current one, and a library picture whose Core states no revision (an older Core), whose identifier
15
+ * cannot see the bytes. Short, so a changed Signet reaches the tab within the hour.
16
+ */
17
+ const PHI_SIGNET_CACHE_SHORT = "public, max-age=3600";
18
+ const PHI_SIGNET_CACHE_MISSING = "public, max-age=300";
19
+ /**
20
+ * The picture is only ever shown by an `<img>` or the tab, but its address can be opened as a document,
21
+ * and an SVG is a document. The sandbox and the empty policy keep a script in one from running on the
22
+ * Site's origin.
23
+ */
24
+ const PHI_SIGNET_SECURITY_HEADERS = {
25
+ "content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox",
26
+ "x-content-type-options": "nosniff",
27
+ };
28
+ function missing() {
29
+ return new Response(null, { status: 404, headers: { "cache-control": PHI_SIGNET_CACHE_MISSING } });
30
+ }
31
+ /**
32
+ * A library picture, read through the same door every Asset is delivered by.
33
+ *
34
+ * Not redirected: the Apple path has to know whether the bytes are a PNG of 180 px, and the tab should
35
+ * not depend on a second request that follows a first. Anything that is not an image answers null.
36
+ */
37
+ async function readPhiSignetAsset(assetId, request, proxied) {
38
+ 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"] }) });
39
+ const contentType = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() ?? "";
40
+ if (!upstream.ok || !contentType.startsWith("image/"))
41
+ return null;
42
+ return { contentType, bytes: new Uint8Array(await upstream.arrayBuffer()) };
43
+ }
44
+ /**
45
+ * `GET /api/site/signet`: the Signet the Site owns, as a picture at a real address.
46
+ *
47
+ * Only the Site's own, `theme.brand.signet` of the published record, which a Theme save writes
48
+ * (`materializePhiThemeBrandSignet`). A Theme Set's Signet is not resolved here: that needs the Theme
49
+ * blocks of the installed Modules, a graph this door does not carry, and the head names a followed Set's
50
+ * Signet as the data URL it is instead. An Asset is read through the media door; an inline `data:image/`
51
+ * picture is decoded. An address on another server is answered 404 and not redirected: a redirect from
52
+ * the favicon path would send every visitor's request to a third party, the head cannot name it, and
53
+ * nothing writes one -- the save uploads what it finds.
54
+ *
55
+ * Three ways in, one picture. The head names `?v=<identifier>`; the proxy rewrites the browser's own
56
+ * `/favicon.ico`, `/apple-touch-icon.png` and `/apple-touch-icon-precomposed.png` to `?as=favicon|apple`.
57
+ * An Apple path answers only for a PNG of 180 px or more -- anything else would be scaled into a blur.
58
+ * No Site Signet, or one that cannot be delivered, answers 404.
59
+ */
60
+ export function buildPhiSignetRouteHandler({ loadAreaBridge, proxied, }) {
61
+ return async function GET(request) {
62
+ // Any Bridge knows the Site's key and its Core; the Public one is the one every Site has.
63
+ const runtime = (await loadAreaBridge("public"))?.runtime;
64
+ if (!runtime)
65
+ return missing();
66
+ const site = await getResolvedSiteConfig({
67
+ apiBaseUrl: runtime.apiBaseUrl,
68
+ internalToken: runtime.internalToken,
69
+ siteKey: runtime.siteKey,
70
+ });
71
+ const signet = readPhiThemeSiteSignet(site.theme?.brand?.signet);
72
+ if (!signet)
73
+ return missing();
74
+ let image;
75
+ let identity;
76
+ if (signet.kind === "data") {
77
+ image = decodePhiSignetDataUrl(signet.source);
78
+ identity = image?.bytes ?? "";
79
+ }
80
+ else {
81
+ image = await readPhiSignetAsset(signet.assetId, request, proxied);
82
+ identity = buildPhiSignetAssetIdentity(signet);
83
+ }
84
+ if (!image)
85
+ return missing();
86
+ const alias = request.nextUrl.searchParams.get(PHI_SIGNET_ALIAS_PARAM);
87
+ if (alias === "apple") {
88
+ const dimensions = image.contentType === "image/png" ? readPhiPngSize(image.bytes) : null;
89
+ if (!dimensions || dimensions.width < PHI_SIGNET_APPLE_MIN_SIZE || dimensions.height < PHI_SIGNET_APPLE_MIN_SIZE) {
90
+ return missing();
91
+ }
92
+ }
93
+ const asked = request.nextUrl.searchParams.get(PHI_SIGNET_VERSION_PARAM);
94
+ const identified = alias === null && asked === buildPhiSignetVersion(identity);
95
+ return new Response(Buffer.from(image.bytes), {
96
+ status: 200,
97
+ headers: {
98
+ "content-type": image.contentType,
99
+ "content-length": String(image.bytes.length),
100
+ "cache-control": identified && (signet.kind === "data" || signet.revision != null)
101
+ ? PHI_SIGNET_CACHE_IDENTIFIED
102
+ : PHI_SIGNET_CACHE_SHORT,
103
+ ...PHI_SIGNET_SECURITY_HEADERS,
104
+ },
105
+ });
106
+ };
107
+ }
@@ -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; and `page-references` lists the Pages of an Area a link may point at. All five read the
11
- * Site's own Module catalogs, which phi-server deliberately knows nothing about.
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 handlers = await pending;
140
- const local = handlers[method] ?? (method === "HEAD" ? handlers.GET : undefined);
146
+ const answeredHandlers = await pending;
147
+ const local = answeredHandlers[method] ?? (method === "HEAD" ? answeredHandlers.GET : undefined);
141
148
  if (!local) {
142
- const allow = Object.keys(handlers).join(", ");
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's address, as the Theme Set that is followed states it -- a data URL for the Sets that
21
- * draw their own mark.
21
+ * The Signet as the head names it (`describePhiSignetHead`).
22
22
  *
23
- * Only `icon`, not `apple`: an Apple touch icon has to be a raster of a stated size, and pointing the
24
- * home screen at a drawing it cannot read would be worse than saying nothing. A Site that has no
25
- * Signet says nothing at all here, which leaves the browser the `/favicon.ico` it asks for anyway.
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?: string | null;
29
+ signet?: PhiSignetHead | null;
28
30
  };
29
31
  export declare function buildPhiRootMetadata(options?: PhiRootMetadataInput): Metadata;
30
32
  /**
@@ -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 resolvedSignet = resolveFirstText(options.signet);
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
- ...(resolvedSignet ? { icons: { icon: resolvedSignet } } : {}),
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,26 @@
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 by its id and, where
22
+ * the Core states it (0.4.1), its revision, type and size -- the bytes are not at hand here. Without those
23
+ * fields (an older Core, a draft) it is named by the id alone and without a type or a size, and the
24
+ * response carries its type; the Apple path answers for itself from the bytes.
25
+ */
26
+ export declare function describePhiSignetHead(signet: PhiThemeSignet | null | undefined): PhiSignetHead | null;
@@ -0,0 +1,53 @@
1
+ import { PHI_SIGNET_APPLE_MIN_SIZE, PHI_SIGNET_PATH, PHI_SIGNET_VERSION_PARAM } from "./phi-signet-paths";
2
+ import { buildPhiSignetAssetIdentity, 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 by its id and, where
15
+ * the Core states it (0.4.1), its revision, type and size -- the bytes are not at hand here. Without those
16
+ * fields (an older Core, a draft) it is named by the id alone and without a type or a size, and the
17
+ * response carries its type; the Apple path answers for itself from the bytes.
18
+ */
19
+ export function describePhiSignetHead(signet) {
20
+ if (!signet)
21
+ return null;
22
+ if (signet.from === "set")
23
+ return signet.kind === "data" ? { href: signet.source } : null;
24
+ if (signet.kind === "asset") {
25
+ const href = buildPhiSignetHref(buildPhiSignetVersion(buildPhiSignetAssetIdentity(signet)));
26
+ const sizes = signet.width != null && signet.height != null ? `${signet.width}x${signet.height}` : undefined;
27
+ const apple = signet.contentType === "image/png" && signet.width != null && signet.height != null &&
28
+ signet.width >= PHI_SIGNET_APPLE_MIN_SIZE && signet.height >= PHI_SIGNET_APPLE_MIN_SIZE
29
+ ? { href, type: signet.contentType, sizes: sizes }
30
+ : undefined;
31
+ return {
32
+ href,
33
+ ...(signet.contentType ? { type: signet.contentType } : {}),
34
+ ...(sizes ? { sizes } : {}),
35
+ ...(apple ? { apple } : {}),
36
+ };
37
+ }
38
+ const image = decodePhiSignetDataUrl(signet.source);
39
+ if (!image)
40
+ return null;
41
+ const href = buildPhiSignetHref(buildPhiSignetVersion(image.bytes));
42
+ const dimensions = image.contentType === "image/png" ? readPhiPngSize(image.bytes) : null;
43
+ const sizes = dimensions ? `${dimensions.width}x${dimensions.height}` : undefined;
44
+ const apple = dimensions && dimensions.width >= PHI_SIGNET_APPLE_MIN_SIZE && dimensions.height >= PHI_SIGNET_APPLE_MIN_SIZE
45
+ ? { href, type: image.contentType, sizes: sizes }
46
+ : undefined;
47
+ return {
48
+ href,
49
+ type: image.contentType,
50
+ ...(sizes ? { sizes } : {}),
51
+ ...(apple ? { apple } : {}),
52
+ };
53
+ }
@@ -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,40 @@
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;
29
+ /**
30
+ * What identifies a library picture in the address the head names, and in the route that answers it.
31
+ *
32
+ * With the Asset's revision where the Core states one (Core 0.4.1), so a picture that is replaced gets a
33
+ * new address at once and the address can be cached for a year. Without it, the id alone: the bytes are
34
+ * not known where the head is written, a replaced picture keeps its address, and the route answers it
35
+ * with a short cache.
36
+ */
37
+ export declare function buildPhiSignetAssetIdentity(asset: {
38
+ assetId: number;
39
+ revision?: number;
40
+ }): string;
@@ -0,0 +1,70 @@
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
+ }
60
+ /**
61
+ * What identifies a library picture in the address the head names, and in the route that answers it.
62
+ *
63
+ * With the Asset's revision where the Core states one (Core 0.4.1), so a picture that is replaced gets a
64
+ * new address at once and the address can be cached for a year. Without it, the id alone: the bytes are
65
+ * not known where the head is written, a replaced picture keeps its address, and the route answers it
66
+ * with a short cache.
67
+ */
68
+ export function buildPhiSignetAssetIdentity(asset) {
69
+ return asset.revision != null ? `asset:${asset.assetId}:r${asset.revision}` : `asset:${asset.assetId}`;
70
+ }
@@ -46,14 +46,16 @@ export declare class PhiProxyPathError extends Error {
46
46
  /**
47
47
  * The upstream response's headers as the browser may see them.
48
48
  *
49
- * `fetch` hands over a body it has already decoded: undici asks for gzip, deflate and br on its own and
50
- * undoes whatever the Server applied. Passing the Server's `content-encoding` on then tells the browser
51
- * to decode plain bytes a second time (`ERR_CONTENT_DECODING_FAILED`), and its `content-length` counts
52
- * the compressed bytes. Both go for a decoded body; the runtime frames the body it actually sends.
53
- * Asking upstream for `identity` instead would rest on the Server honouring it -- this holds either way.
49
+ * Encoding is each hop's own business. This hop to the Server negotiates for itself -- `fetch` asks for
50
+ * gzip, deflate and br on its own and hands over a body it has already decoded
51
+ * (`buildPhiNextProxyHeaders` does not pass the browser's `accept-encoding` on). Passing the Server's
52
+ * `content-encoding` on then tells the browser to decode plain bytes a second time
53
+ * (`ERR_CONTENT_DECODING_FAILED`), and a runtime that compresses route handler responses itself (Next
54
+ * from 16.4.6) would stack a second layer on a body that still claims the first -- or, from 16.4.5, drop
55
+ * the claim and leave a compressed body unlabelled. The `content-length` counts the compressed bytes.
56
+ * Both go for a decoded body; the runtime frames the body it actually sends and compresses towards the
57
+ * browser itself, as nginx does in front of it.
54
58
  */
55
- export declare function buildPhiProxyResponseHeaders(upstream: Headers, options: {
56
- bodyDecoded: boolean;
57
- }): Headers;
59
+ export declare function buildPhiProxyResponseHeaders(upstream: Headers): Headers;
58
60
  export declare function PhiNextProxy(config: PhiNextProxyConfig): PhiNextProxyHandlers;
59
61
  export {};