@homepages/concrete 14.0.0 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @homepages/concrete
2
2
 
3
+ ## 14.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 92ffc26: `concrete build` now writes a font's or an image's address relative to the stylesheet or the island script that names it. A script works the address out from its own URL, so it matches the address the render writes into the section's HTML exactly. Every host now serves a build's stylesheets and scripts with their bytes unchanged. The build's static-assets binding lists the assets they name (`relative_assets`), which is how a host can tell this form from the earlier one. Nothing in a template's source changes: rebuild on this version to pick it up.
8
+
9
+ ### Patch Changes
10
+
11
+ - c671662: The section-asset address module it bundles drops two helpers nothing called. Nothing a consumer sees changed.
12
+ - 4b64e19: Source comments in two modules it bundles no longer name the retired renderers bucket. No code changed.
13
+ - cb45415: A render that waits for media still processing (a published site, a download) now also waits for an image's cut-out at a slot that declares `process.cutout()`. Until now it served the image with its background while the cut-out was still being made. A cut-out that can no longer land does not hold the render. Renders that serve straight away, like the playground's canvas, are unchanged.
14
+
3
15
  ## 14.0.0
4
16
 
5
17
  ### Major Changes
@@ -37,6 +37,10 @@
37
37
  "drop `CONCRETE_TOKEN` and `CONCRETE_API_URL` from the workspace's `.env` and every key file, and after `concrete publish` run `concrete release` to hand the version to HomePages; a script that ran `concrete publish --dry-run` runs `concrete release --dry-run` instead.",
38
38
  "set `CONCRETE_CONSOLE_KEY` to your team's console key (in the workspace's `.env`, the environment, or the file `--env-file` names); `concrete publish` refuses without it."
39
39
  ]
40
+ },
41
+ "14.1.0": {
42
+ "codemods": [],
43
+ "manual": []
40
44
  }
41
45
  }
42
46
  }
@@ -39,17 +39,56 @@ function bundledFrameworkPlugin() {
39
39
  }
40
40
  };
41
41
  }
42
- function workspaceLoaders(root) {
42
+ function workspaceLoaders(root, addresses) {
43
43
  return {
44
44
  loader: {
45
45
  ".css": "empty",
46
46
  ...MEDIA_LOADERS
47
47
  },
48
- publicPath: ASSET_PUBLIC_PATH,
48
+ publicPath: addresses === "fixed" ? ASSET_PUBLIC_PATH : "",
49
49
  assetNames: ASSET_NAMES,
50
50
  outdir: join(root, ".concrete", "cache", "build")
51
51
  };
52
52
  }
53
+ const RELATIVE_ASSET_NAMESPACE = "concrete-relative-asset";
54
+ const RELATIVE_ASSET_INNER = Symbol("concrete-relative-asset:inner");
55
+ const ASSET_IMPORT_KINDS = /* @__PURE__ */ new Set([
56
+ "import-statement",
57
+ "require-call",
58
+ "dynamic-import"
59
+ ]);
60
+ const MEDIA_FILTER = new RegExp(`\\.(?:${Object.keys(MEDIA_LOADERS).map((ext) => [...ext.slice(1)].map((c) => `[${c.toLowerCase()}${c.toUpperCase()}]`).join("")).join("|")})$`);
61
+ function relativeAssetPlugin() {
62
+ return {
63
+ name: RELATIVE_ASSET_NAMESPACE,
64
+ setup(build) {
65
+ build.onResolve({ filter: MEDIA_FILTER }, async (args) => {
66
+ if (args.pluginData === RELATIVE_ASSET_INNER || !ASSET_IMPORT_KINDS.has(args.kind)) return null;
67
+ const resolved = await build.resolve(args.path, {
68
+ importer: args.importer,
69
+ namespace: args.namespace,
70
+ resolveDir: args.resolveDir,
71
+ kind: args.kind,
72
+ pluginData: RELATIVE_ASSET_INNER
73
+ });
74
+ if (resolved.errors.length > 0 || resolved.path === "" || resolved.external === true) return null;
75
+ return {
76
+ path: resolved.path,
77
+ namespace: RELATIVE_ASSET_NAMESPACE
78
+ };
79
+ });
80
+ build.onLoad({
81
+ filter: /.*/,
82
+ namespace: RELATIVE_ASSET_NAMESPACE
83
+ }, (args) => ({
84
+ contents: `import file from ${JSON.stringify(args.path)};\nexport default new URL(file, import.meta.url).pathname;`,
85
+ loader: "js",
86
+ resolveDir: dirname(args.path),
87
+ pluginData: RELATIVE_ASSET_INNER
88
+ }));
89
+ }
90
+ };
91
+ }
53
92
  function emittedAssets(outputs) {
54
93
  const byName = /* @__PURE__ */ new Map();
55
94
  for (const file of outputs) {
@@ -83,4 +122,4 @@ async function runPass(what, pass) {
83
122
  }
84
123
 
85
124
  //#endregion
86
- export { ASSET_NAMES, ASSET_PUBLIC_PATH, assetContentType, bundledFrameworkPlugin, emittedAssets, javascriptOutput, runPass, workspaceLoaders };
125
+ export { ASSET_NAMES, ASSET_PUBLIC_PATH, RELATIVE_ASSET_NAMESPACE, assetContentType, bundledFrameworkPlugin, emittedAssets, javascriptOutput, relativeAssetPlugin, runPass, workspaceLoaders };
@@ -10,13 +10,14 @@ const LEGACY_BUILD_RECORD_FILE = "build.json";
10
10
  function buildRecordPath(out) {
11
11
  return join(dirname(out), `${basename(out)}.json`);
12
12
  }
13
- const BUILD_RECORD_SCHEMA = 2;
13
+ const BUILD_RECORD_SCHEMA = 3;
14
14
  const IslandRecord = z.object({
15
15
  island_key: z.string(),
16
16
  filename: z.string(),
17
17
  content_hash: z.string(),
18
18
  file: z.string(),
19
- frameless: z.boolean()
19
+ frameless: z.boolean(),
20
+ assets: z.array(z.string())
20
21
  });
21
22
  const SourceRecord = z.object({
22
23
  file: z.string(),
@@ -37,7 +38,7 @@ const SectionRecord = z.object({
37
38
  files: z.array(z.string())
38
39
  });
39
40
  const BuildRecord = z.object({
40
- build_schema: z.literal(2),
41
+ build_schema: z.literal(3),
41
42
  framework_version: z.string(),
42
43
  key: z.string(),
43
44
  template: z.object({ content_hash: z.string() }),
@@ -1,5 +1,5 @@
1
1
  import { isWorkspaceFile, toPosix, workspacePath } from "../../platform/paths.js";
2
- import { bundledFrameworkPlugin, emittedAssets, javascriptOutput, runPass, workspaceLoaders } from "./esbuild.js";
2
+ import { bundledFrameworkPlugin, emittedAssets, javascriptOutput, relativeAssetPlugin, runPass, workspaceLoaders } from "./esbuild.js";
3
3
  import { ISLAND_REACT_EXTERNALS } from "../../packages/internal/static-assets-binding/dist/index.js";
4
4
  import { declaresNoServerFrame, stubClientModule, wrapClientModule } from "../../islands/wrap.js";
5
5
  import { mediaCacheDir } from "../media/cache.js";
@@ -95,7 +95,7 @@ async function rendererPass(input, deriver, found, stubFrameless) {
95
95
  "react/jsx-runtime"
96
96
  ],
97
97
  absWorkingDir: root,
98
- ...workspaceLoaders(root),
98
+ ...workspaceLoaders(root, "fixed"),
99
99
  plugins: [
100
100
  bundledFrameworkPlugin(),
101
101
  serverIslandsPlugin(root, key, found, stubFrameless),
@@ -166,7 +166,11 @@ async function buildSection(input) {
166
166
  collect(rendererDeriver, rendered.outputFiles, rendered.metafile);
167
167
  const islands = [];
168
168
  for (const [islandKey, file] of [...found].sort(([a], [b]) => a < b ? -1 : 1)) {
169
- const deriver = createMediaDeriver(deriverOptions);
169
+ const deriver = createMediaDeriver({
170
+ ...deriverOptions,
171
+ addresses: "relative"
172
+ });
173
+ let named = [];
170
174
  const bytes = await runPass(`The island chunk ${islandKey}`, async () => {
171
175
  const result = await build({
172
176
  entryPoints: [file],
@@ -179,16 +183,18 @@ async function buildSection(input) {
179
183
  jsx: "automatic",
180
184
  external: [...ISLAND_REACT_EXTERNALS],
181
185
  absWorkingDir: root,
182
- ...workspaceLoaders(root),
186
+ ...workspaceLoaders(root, "relative"),
183
187
  plugins: [
184
188
  bundledFrameworkPlugin(),
185
189
  nestedIslandsPlugin(root, key, file),
186
- deriver.plugin
190
+ deriver.plugin,
191
+ relativeAssetPlugin()
187
192
  ],
188
193
  metafile: true,
189
194
  logLevel: "silent"
190
195
  });
191
196
  collect(deriver, result.outputFiles, result.metafile);
197
+ named = [.../* @__PURE__ */ new Set([...emittedAssets(result.outputFiles).map((asset) => asset.filename), ...deriver.named])].sort();
192
198
  return javascriptOutput(result.outputFiles, `island ${islandKey}`);
193
199
  });
194
200
  const contentHash = sha256(bytes);
@@ -199,7 +205,8 @@ async function buildSection(input) {
199
205
  contentHash,
200
206
  bytes,
201
207
  file,
202
- frameless
208
+ frameless,
209
+ assets: named
203
210
  });
204
211
  }
205
212
  return {
@@ -120,7 +120,8 @@ async function produceSection(root, out, task, site, context) {
120
120
  contentHash: island.content_hash,
121
121
  bytes: islandBytes[index],
122
122
  file: island.file,
123
- frameless: island.frameless
123
+ frameless: island.frameless,
124
+ assets: island.assets
124
125
  }));
125
126
  return {
126
127
  logic: {
@@ -194,7 +195,8 @@ async function produceSection(root, out, task, site, context) {
194
195
  filename: island.filename,
195
196
  content_hash: island.contentHash,
196
197
  file: island.file,
197
- frameless: island.frameless
198
+ frameless: island.frameless,
199
+ assets: [...island.assets]
198
200
  })),
199
201
  sources: [...built.sources],
200
202
  masters: Object.fromEntries(byKey(built.masters)),
@@ -447,6 +449,7 @@ async function assemble(root, out, workspace, composition, css, results, shared)
447
449
  const sectionRecords = [];
448
450
  const islands = {};
449
451
  const masters = [];
452
+ const relativeAssets = /* @__PURE__ */ new Set();
450
453
  for (const result of [...results].sort((a, b) => a.build.key < b.build.key ? -1 : a.build.key > b.build.key ? 1 : 0)) {
451
454
  const { build, record } = result;
452
455
  if (!isSectionKey(build.key)) throw new LayoutRefusal({
@@ -479,10 +482,13 @@ async function assemble(root, out, workspace, composition, css, results, shared)
479
482
  output.keep(path, sha);
480
483
  }
481
484
  }
482
- for (const island of bundles.islands) islands[island.islandKey] = {
483
- filename: island.filename,
484
- content_hash: island.contentHash
485
- };
485
+ for (const island of bundles.islands) {
486
+ islands[island.islandKey] = {
487
+ filename: island.filename,
488
+ content_hash: island.contentHash
489
+ };
490
+ for (const asset of island.assets) relativeAssets.add(asset);
491
+ }
486
492
  masters.push(...bundles.masters);
487
493
  const contentHash = output.digestUnder(sectionDir(build.key));
488
494
  sectionRecords.push({
@@ -512,7 +518,10 @@ async function assemble(root, out, workspace, composition, css, results, shared)
512
518
  output.put(templatePath(TEMPLATE_FILES.composition), json(compositionColumn));
513
519
  output.put(templatePath(TEMPLATE_FILES.preview), json(manifest.preview ?? null));
514
520
  output.put(templatePath(TEMPLATE_FILES.stylesheet), css.bytes);
515
- for (const asset of css.assets) output.asset(asset);
521
+ for (const asset of css.assets) {
522
+ output.asset(asset);
523
+ relativeAssets.add(asset.filename);
524
+ }
516
525
  const { icons } = shared;
517
526
  if (icons === null) throw new LayoutRefusal({
518
527
  rule: "workspace/template-invalid",
@@ -541,7 +550,8 @@ async function assemble(root, out, workspace, composition, css, results, shared)
541
550
  react_vendor_core: vendor === null ? null : putStatic(vendor.core),
542
551
  analytics: shared.analytics === null ? null : putStatic(shared.analytics),
543
552
  masters: Object.fromEntries(byKey(masters)),
544
- icons: icons.icons
553
+ icons: icons.icons,
554
+ relative_assets: [...relativeAssets].sort()
545
555
  };
546
556
  output.put(templatePath(TEMPLATE_FILES.staticAssets), json(binding));
547
557
  const clashes = browserFileClashes(binding, output.hashes.keys());
@@ -574,7 +584,7 @@ async function assemble(root, out, workspace, composition, css, results, shared)
574
584
  message: `The build would not write the same files on Windows and macOS:\n` + unportable.map((found) => ` ${found.paths.join(" and ")}: ${found.reason}`).join("\n") + "\nRename the source files these names come from."
575
585
  });
576
586
  const record = {
577
- build_schema: 2,
587
+ build_schema: 3,
578
588
  framework_version: CONCRETE_CLI_VERSION,
579
589
  key: template.key,
580
590
  template: { content_hash: templateHash },
@@ -1,4 +1,5 @@
1
1
  import { isFileSpecifier } from "../../platform/paths.js";
2
+ import { ASSET_PUBLIC_PATH, RELATIVE_ASSET_NAMESPACE } from "../build/esbuild.js";
2
3
  import { DERIVABLE_EXTENSIONS, cachedAuthorImage, deriveAuthorImage, masterOnlyDerivation } from "./derive.js";
3
4
  import { existsSync } from "node:fs";
4
5
  import { extname, resolve } from "node:path";
@@ -14,13 +15,14 @@ function createMediaDeriver(opts = {}) {
14
15
  const passthrough = /* @__PURE__ */ new Set();
15
16
  const pending = /* @__PURE__ */ new Set();
16
17
  const sources = /* @__PURE__ */ new Map();
18
+ const named = /* @__PURE__ */ new Set();
17
19
  return {
18
20
  plugin: {
19
21
  name: NAMESPACE,
20
22
  setup(build) {
21
23
  build.onResolve({ filter: RASTER_FILTER }, async (args) => {
22
24
  if (args.pluginData === RESOLVING) return null;
23
- if (args.kind !== "import-statement") return null;
25
+ if (args.kind !== "import-statement" || args.namespace === "concrete-relative-asset") return null;
24
26
  if (!DERIVABLE_EXTENSIONS.has(extname(args.path).toLowerCase())) return null;
25
27
  if (isFileSpecifier(args.path)) {
26
28
  const written = resolve(args.resolveDir, args.path);
@@ -73,8 +75,9 @@ function createMediaDeriver(opts = {}) {
73
75
  masterBytes: masterBytes.byteLength,
74
76
  derivatives: derivation.derivatives
75
77
  });
78
+ for (const address of imageAddresses(derivation.image)) named.add(address.slice(FIXED_PREFIX.length));
76
79
  return {
77
- contents: `export default ${JSON.stringify(derivation.image)};`,
80
+ contents: authorImageModule(derivation.image, opts.addresses ?? "fixed"),
78
81
  loader: "js",
79
82
  watchFiles: [args.path]
80
83
  };
@@ -85,9 +88,28 @@ function createMediaDeriver(opts = {}) {
85
88
  masters,
86
89
  passthrough,
87
90
  pending,
88
- sources
91
+ sources,
92
+ named
89
93
  };
90
94
  }
95
+ const FIXED_PREFIX = `${ASSET_PUBLIC_PATH}/`;
96
+ function imageAddresses(image) {
97
+ const candidates = (image.responsive?.sources ?? []).flatMap((source) => source.srcset.split(", ").map((candidate) => candidate.split(" ")[0]));
98
+ return [image.url, ...candidates];
99
+ }
100
+ function relativeAddress(address) {
101
+ if (!address.startsWith(FIXED_PREFIX)) throw new Error(`derive: an image address outside ${FIXED_PREFIX}: ${address}`);
102
+ return `d+${JSON.stringify(address.slice(FIXED_PREFIX.length))}`;
103
+ }
104
+ function authorImageModule(image, addresses) {
105
+ if (addresses === "fixed") return `export default ${JSON.stringify(image)};`;
106
+ const srcset = (list) => list.split(", ").map((candidate) => {
107
+ const space = candidate.indexOf(" ");
108
+ return space < 0 ? relativeAddress(candidate) : `${relativeAddress(candidate.slice(0, space))}+${JSON.stringify(candidate.slice(space))}`;
109
+ }).join(`+", "+`);
110
+ const responsive = image.responsive === null ? "null" : `{sources:[${image.responsive.sources.map((source) => `{type:${JSON.stringify(source.type)},srcset:${srcset(source.srcset)}}`).join(",")}],width:${String(image.responsive.width)},height:${String(image.responsive.height)}}`;
111
+ return [`const d = new URL("./", import.meta.url).pathname;`, `export default {url:${relativeAddress(image.url)},responsive:${responsive},width:${String(image.width)},height:${String(image.height)}};`].join("\n");
112
+ }
91
113
 
92
114
  //#endregion
93
- export { createMediaDeriver };
115
+ export { authorImageModule, createMediaDeriver };
@@ -4,7 +4,6 @@ import { basename, extname, join } from "node:path";
4
4
  import { build } from "esbuild";
5
5
 
6
6
  //#region src/css/inline.ts
7
- const ASSET_PUBLIC_PATH = "/section-assets";
8
7
  const ASSET_NAMES = "[name]-[hash]";
9
8
  function importRulePlugin() {
10
9
  return {
@@ -66,7 +65,7 @@ async function inlineCssGraph(root, files) {
66
65
  metafile: true,
67
66
  outdir: "out",
68
67
  loader: Object.fromEntries(Object.keys(ASSET_MIME).map((ext) => [ext, "file"])),
69
- publicPath: ASSET_PUBLIC_PATH,
68
+ publicPath: "",
70
69
  assetNames: ASSET_NAMES,
71
70
  legalComments: "none",
72
71
  plugins: [importRulePlugin()],
@@ -95,4 +94,4 @@ async function inlineCssGraph(root, files) {
95
94
  }
96
95
 
97
96
  //#endregion
98
- export { ASSET_PUBLIC_PATH, inlineCssGraph };
97
+ export { inlineCssGraph };
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "14.0.0";
2
+ var version = "14.1.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -74,15 +74,15 @@ async function serveRequest(input, documents, req, res) {
74
74
  const contentType = route.contentType ?? stored.contentType ?? DEFAULT_CONTENT_TYPE;
75
75
  const disposition = route.from === "media" && route.contentDisposition !== void 0 ? { "content-disposition": route.contentDisposition } : {};
76
76
  if (isFilledText(route) && route.from === "build") {
77
- let text;
77
+ let raw;
78
78
  try {
79
- text = await readText(stored.body);
79
+ raw = await readBytes(stored.body);
80
80
  } catch (err) {
81
81
  input.onError?.(`capture origin could not read ${route.path}`, err);
82
82
  res.writeHead(404).end();
83
83
  return;
84
84
  }
85
- const body = Buffer.from(fillBuildFile(route.filename, text, input.bases.build), "utf8");
85
+ const body = fillBuildFile(route.filename, raw, input.bases.build).bytes;
86
86
  res.writeHead(200, {
87
87
  "content-type": contentType,
88
88
  "content-length": body.byteLength
@@ -107,10 +107,10 @@ async function serveRequest(input, documents, req, res) {
107
107
  res.destroy();
108
108
  }
109
109
  }
110
- async function readText(body) {
110
+ async function readBytes(body) {
111
111
  const chunks = [];
112
112
  for await (const chunk of body) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
113
- return Buffer.concat(chunks).toString("utf8");
113
+ return Buffer.concat(chunks);
114
114
  }
115
115
  function closeServer(server) {
116
116
  return new Promise((resolve, reject) => {
@@ -1,3 +1,4 @@
1
+ import { processBindingsOf, processOf } from "../../template-contracts/dist/slot-catalog.js";
1
2
  import { contentMediaIdOf, cropsPart } from "../../template-contracts/dist/registry-facts.js";
2
3
  import { cropKeyOwner } from "./crop-key.js";
3
4
  import { readLadder } from "./store.js";
@@ -82,13 +83,27 @@ function sameCrop(a, b) {
82
83
  if (a === null || b === null) return a === b;
83
84
  return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
84
85
  }
85
- function carriesCutAt(framing, photoId, crop) {
86
- const cut = (framing.renditions && typeof framing.renditions === "object" ? framing.renditions : {}).crop;
87
- const key = renditionKey(cut);
88
- if (key === null || cropKeyOwner(key) !== photoId) return false;
89
- const over = cut.over;
86
+ function madeAt(rendition, crop) {
87
+ const over = rendition !== null && typeof rendition === "object" ? rendition.over : void 0;
90
88
  return over !== null && typeof over === "object" && sameCrop(storedCrop(over.crop), crop);
91
89
  }
90
+ function carriesCutAt(framing, photoId, crop) {
91
+ const renditions = framing.renditions && typeof framing.renditions === "object" ? framing.renditions : {};
92
+ const key = renditionKey(renditions.crop);
93
+ return key !== null && cropKeyOwner(key) === photoId && madeAt(renditions.crop, crop);
94
+ }
95
+ function declaresCutout(declaration) {
96
+ return processOf(processBindingsOf(declaration?.process), "cutout") !== void 0;
97
+ }
98
+ function noteOwedCutout(v, photoId, record, at, store) {
99
+ if (store.notePending === void 0 || record?.kind !== "image" || record.key === null) return;
100
+ const renditions = v.renditions && typeof v.renditions === "object" ? v.renditions : {};
101
+ const key = renditionKey(renditions.cutout);
102
+ if (!(key !== null && key.startsWith(`processed/cutout/${photoId}/`) && madeAt(renditions.cutout, framingCrop(v, at)))) store.notePending({
103
+ kind: "cutout",
104
+ id: photoId
105
+ });
106
+ }
92
107
  function noteOwedCuts(v, photoId, record, at, mask, store) {
93
108
  if (store.notePending === void 0 || mask !== null || record?.kind !== "image") return;
94
109
  const owes = (framing, crop) => cropsPart(crop) && !carriesCutAt(framing, photoId, crop);
@@ -103,7 +118,7 @@ function noteOwedCuts(v, photoId, record, at, mask, store) {
103
118
  function readMediaId(v) {
104
119
  return contentMediaIdOf(v) ?? "";
105
120
  }
106
- async function resolveImageValue(value, records, store, aspects) {
121
+ async function resolveImageValue(value, records, store, aspects, cutsOut = false) {
107
122
  if (value === null) return {
108
123
  value: null,
109
124
  desktopKey: null,
@@ -124,6 +139,7 @@ async function resolveImageValue(value, records, store, aspects) {
124
139
  imageAspect: imageAspectOf(record, ar)
125
140
  };
126
141
  if (photoId) noteOwedCuts(v, photoId, record, at, mask, store);
142
+ if (photoId && cutsOut) noteOwedCutout(v, photoId, record, at, store);
127
143
  const mobileKey = photoId ? mobileCutKey(v, at) : null;
128
144
  const mobile = mobileKey ? await mobileCropUrl(mobileKey, store) : null;
129
145
  const alt = typeof v.alt === "string" ? v.alt : "";
@@ -185,11 +201,11 @@ async function attachResponsive(entries, store) {
185
201
  }
186
202
  }
187
203
  }
188
- async function resolveImageSlot(value, records, store, aspects) {
189
- const entry = await resolveImageValue(value, records, store, aspects);
204
+ async function resolveImageSlot(value, records, store, aspects, cutsOut = false) {
205
+ const entry = await resolveImageValue(value, records, store, aspects, cutsOut);
190
206
  await attachResponsive([entry], store);
191
207
  return entry.value;
192
208
  }
193
209
 
194
210
  //#endregion
195
- export { attachResponsive, emptyImage, mobileCutKey, resolveImageMedia, resolveImageSlot, resolveImageValue, servedKeyOf, slotCutKey };
211
+ export { attachResponsive, declaresCutout, emptyImage, mobileCutKey, resolveImageMedia, resolveImageSlot, resolveImageValue, servedKeyOf, slotCutKey };
@@ -1,6 +1,6 @@
1
1
  import { resolveDocumentSlot } from "./document.js";
2
2
  import { slotCropAspects } from "../../template-contracts/dist/content-pick.js";
3
- import { attachResponsive, emptyImage, resolveImageValue } from "./image.js";
3
+ import { attachResponsive, declaresCutout, emptyImage, resolveImageValue } from "./image.js";
4
4
  import { resolveTourSlot } from "./tour.js";
5
5
  import { resolveVideoSlot } from "./video.js";
6
6
  import { resolveMediaSlot } from "./media.js";
@@ -36,7 +36,7 @@ async function resolvePrimitiveItems(members, primitive, ctx, element) {
36
36
  switch (primitive) {
37
37
  case "image": {
38
38
  const entries = [];
39
- for (const member of members) entries.push(await resolveImageValue(member, ctx.records, ctx.store, slotCropAspects(element?.crop)));
39
+ for (const member of members) entries.push(await resolveImageValue(member, ctx.records, ctx.store, slotCropAspects(element?.crop), declaresCutout(element)));
40
40
  await attachResponsive(entries, ctx.store);
41
41
  return entries.map((entry) => entry.value ?? emptyImage());
42
42
  }
@@ -84,7 +84,7 @@ async function resolveField(value, field, ctx, batch) {
84
84
  if (itemContentOf(field) !== null) return resolveNestedList(value, field, ctx, batch);
85
85
  switch (primitiveOf(field.type)) {
86
86
  case "image": {
87
- const entry = await resolveImageValue(value, ctx.records, ctx.store, slotCropAspects(field.crop));
87
+ const entry = await resolveImageValue(value, ctx.records, ctx.store, slotCropAspects(field.crop), declaresCutout(field));
88
88
  batch.push(entry);
89
89
  return entry.value;
90
90
  }
@@ -103,7 +103,7 @@ async function resolveNestedList(value, field, ctx, batch) {
103
103
  if (content.kind === "record") return resolveRecordRows(value, content.fields, ctx, batch);
104
104
  if (content.primitive !== "image") return resolvePrimitiveItems(value, content.primitive, ctx, field.element);
105
105
  const entries = [];
106
- for (const member of value) entries.push(await resolveImageValue(member, ctx.records, ctx.store, slotCropAspects(field.element?.crop)));
106
+ for (const member of value) entries.push(await resolveImageValue(member, ctx.records, ctx.store, slotCropAspects(field.element?.crop), declaresCutout(field.element)));
107
107
  batch.push(...entries);
108
108
  return entries.map((entry) => entry.value ?? emptyImage());
109
109
  }
@@ -2,7 +2,7 @@ import { declaredKinds } from "../../template-contracts/dist/slot-catalog.js";
2
2
  import { contentMediaIdOf } from "../../template-contracts/dist/registry-facts.js";
3
3
  import { resolveDocumentSlot } from "./document.js";
4
4
  import { slotCropAspects } from "../../template-contracts/dist/content-pick.js";
5
- import { resolveImageSlot } from "./image.js";
5
+ import { declaresCutout, resolveImageSlot } from "./image.js";
6
6
  import { resolveTourSlot } from "./tour.js";
7
7
  import { resolveVideoSlot } from "./video.js";
8
8
 
@@ -26,7 +26,7 @@ async function resolveMediaSlot(value, declaration, records, store) {
26
26
  const reference = { media: mediaId };
27
27
  switch (record.kind) {
28
28
  case "image": {
29
- const image = await resolveImageSlot(value, records, store, slotCropAspects(declaration.crop));
29
+ const image = await resolveImageSlot(value, records, store, slotCropAspects(declaration.crop), declaresCutout(declaration));
30
30
  return image === null ? null : {
31
31
  ...image,
32
32
  kind: "image"
@@ -1,6 +1,6 @@
1
1
  import { resolveDocumentSlot } from "./document.js";
2
2
  import { slotCropAspects } from "../../template-contracts/dist/content-pick.js";
3
- import { resolveImageSlot } from "./image.js";
3
+ import { declaresCutout, resolveImageSlot } from "./image.js";
4
4
  import { resolveTourSlot } from "./tour.js";
5
5
  import { resolveVideoSlot } from "./video.js";
6
6
  import { resolveMediaSlot } from "./media.js";
@@ -11,7 +11,7 @@ async function resolveSlotValue(value, slot, ctx) {
11
11
  if (slot === void 0) return value;
12
12
  if (itemContentOf(slot) !== null) return resolveListSlot(value, slot, ctx);
13
13
  switch (slot.type) {
14
- case "image": return resolveImageSlot(value, ctx.records, ctx.store, slotCropAspects(slot.crop));
14
+ case "image": return resolveImageSlot(value, ctx.records, ctx.store, slotCropAspects(slot.crop), declaresCutout(slot));
15
15
  case "video": return resolveVideoSlot(value, ctx.records, ctx.store);
16
16
  case "tour": return resolveTourSlot(value, ctx.records, ctx.store);
17
17
  case "document": return resolveDocumentSlot(value, ctx.records, ctx.store);
@@ -1,5 +1,5 @@
1
1
  import { TEMPLATE_FILES, browserFiles, builtTreePath, templatePath } from "../../../template-artifact/dist/layout.js";
2
- import { carriesFixedAddresses, fillBuildFile } from "../../../static-assets-binding/dist/section-asset-url.js";
2
+ import { fillBuildFile } from "../../../static-assets-binding/dist/section-asset-url.js";
3
3
  import { playgroundClientDir } from "../layout.js";
4
4
  import { parseDownloadPath } from "../host/download.js";
5
5
  import { OUTPUT_FOLDERS, ROUTES, parseOutputPath } from "../wire.js";
@@ -320,8 +320,7 @@ async function sendBuiltFile(ctx, filename, res, buildBase = `${ctx.base}${BUILD
320
320
  return;
321
321
  }
322
322
  res.setHeader("cache-control", "no-cache");
323
- const bytes = carriesFixedAddresses(filename) ? new TextEncoder().encode(fillBuildFile(filename, new TextDecoder().decode(read.bytes), buildBase)) : read.bytes;
324
- sendBytes(res, contentTypeFor(at), bytes);
323
+ sendBytes(res, contentTypeFor(at), fillBuildFile(filename, read.bytes, buildBase).bytes);
325
324
  }
326
325
  async function sendFixtureMedia(ctx, req, url, res) {
327
326
  if (req.method !== "GET" && req.method !== "HEAD") {
@@ -1,6 +1,6 @@
1
1
  import { assetContentType } from "../../template-artifact/dist/asset-mime.js";
2
2
  import { assetPath, boundFiles } from "../../template-artifact/dist/layout.js";
3
- import { carriesFixedAddresses, fillBuildFileText } from "../../static-assets-binding/dist/section-asset-url.js";
3
+ import { fillBuildFile } from "../../static-assets-binding/dist/section-asset-url.js";
4
4
  import { pageTitle, siteHead } from "./head.js";
5
5
  import { renderPage } from "../../page-shell/dist/index.js";
6
6
 
@@ -94,7 +94,7 @@ async function buildCopy(input, buildBase, buildDir) {
94
94
  if (binding.analytics === null) throw new Error("The binding is an image or a document template's (it names no visit beacon): a site is made from a website's build.");
95
95
  if (Object.keys(binding.islands).length > 0 && (binding.island_runtime === null || binding.react_vendor === null || binding.react_vendor_core === null)) throw new Error("The binding has islands but names no island runtime, React vendor or vendor core.");
96
96
  const pathOf = new Map(boundFiles(binding).map((file) => [file.filename, file.path]));
97
- const named = new Set(input.pages.flatMap((page) => page.buildFiles));
97
+ const named = /* @__PURE__ */ new Set([...input.pages.flatMap((page) => page.buildFiles), ...binding.relative_assets ?? []]);
98
98
  const bound = await Promise.all(siteBoundEntries(binding, input.analytics).map(async ({ ref, contentType }) => {
99
99
  const raw = await input.readBuildFile(pathOf.get(ref.filename));
100
100
  return {
@@ -118,11 +118,9 @@ async function buildCopy(input, buildBase, buildDir) {
118
118
  };
119
119
  }
120
120
  function fillBuildBytes(filename, raw, buildBase, named) {
121
- if (!carriesFixedAddresses(filename)) return raw;
122
- const filled = fillBuildFileText(filename, new TextDecoder().decode(raw), buildBase);
123
- if (filled.files.length === 0) return raw;
121
+ const filled = fillBuildFile(filename, raw, buildBase);
124
122
  for (const file of filled.files) named.add(file);
125
- return new TextEncoder().encode(filled.text);
123
+ return filled.bytes;
126
124
  }
127
125
  async function shareImage(input, cover) {
128
126
  const bytes = await input.cutShareImage(await cover.read(), {
@@ -25,7 +25,8 @@ const StaticAssetsBindingSchema = z.object({
25
25
  svg: StaticAssetRefSchema.nullable(),
26
26
  png: z.record(z.string(), StaticAssetRefSchema),
27
27
  apple_touch: StaticAssetRefSchema
28
- })
28
+ }),
29
+ relative_assets: z.array(z.string().min(1)).optional()
29
30
  }).strict();
30
31
 
31
32
  //#endregion
@@ -30,9 +30,6 @@ const SCRIPT_RE = /\.(mjs|js)$/i;
30
30
  function carriesFixedAddresses(filename) {
31
31
  return STYLESHEET_RE.test(filename) || SCRIPT_RE.test(filename);
32
32
  }
33
- function fillBuildFile(filename, text, buildBase) {
34
- return fillBuildFileText(filename, text, buildBase).text;
35
- }
36
33
  function fillBuildFileText(filename, text, buildBase) {
37
34
  if (STYLESHEET_RE.test(filename)) return fillSectionAssetRefs(text, { kind: "stylesheet" });
38
35
  if (SCRIPT_RE.test(filename)) return fillSectionAssetRefs(text, {
@@ -44,6 +41,21 @@ function fillBuildFileText(filename, text, buildBase) {
44
41
  files: []
45
42
  };
46
43
  }
44
+ function fillBuildFile(filename, bytes, buildBase) {
45
+ if (!carriesFixedAddresses(filename)) return {
46
+ bytes,
47
+ files: []
48
+ };
49
+ const filled = fillBuildFileText(filename, new TextDecoder().decode(bytes), buildBase);
50
+ if (filled.files.length === 0) return {
51
+ bytes,
52
+ files: []
53
+ };
54
+ return {
55
+ bytes: new TextEncoder().encode(filled.text),
56
+ files: filled.files
57
+ };
58
+ }
47
59
 
48
60
  //#endregion
49
- export { SECTION_ASSET_PREFIX, carriesFixedAddresses, fillBuildFile, fillBuildFileText, fillSectionAssetRefs, sectionAssetPrefix };
61
+ export { SECTION_ASSET_PREFIX, carriesFixedAddresses, fillBuildFile, fillSectionAssetRefs, sectionAssetPrefix };
@@ -1,4 +1,4 @@
1
- import { ASSETS_DIR, FIXTURES_DIR, FIXTURE_DOCUMENT_EXTENSION, MANIFEST_FILE, SECTIONS_DIR, SECTION_FILES, SECTION_ISLANDS_DIR, STATIC_DIR, TEMPLATE_DIR, TEMPLATE_FILES, assetPath, boundFiles, browserFileClashes, isFixtureDocument, isFixtureFilePath, isSectionKey, isStoredPath, isTemplateKey, islandPath, publishedSectionKey, sectionDir, sectionOfIslandKey, sectionPath, staticPath, templatePath } from "./layout.js";
1
+ import { ASSETS_DIR, ASSET_URL_PREFIX, FIXTURES_DIR, FIXTURE_DOCUMENT_EXTENSION, MANIFEST_FILE, SECTIONS_DIR, SECTION_FILES, SECTION_ISLANDS_DIR, STATIC_DIR, TEMPLATE_DIR, TEMPLATE_FILES, assetPath, boundFiles, browserFileClashes, isFixtureDocument, isFixtureFilePath, isSectionKey, isStoredPath, isTemplateKey, islandPath, publishedSectionKey, sectionDir, sectionOfIslandKey, sectionPath, staticPath, templatePath } from "./layout.js";
2
2
  import { sha256Hex } from "./sha256.js";
3
3
  import { listingDigest, sectionContentHash, sourceDigest, templateContentHash } from "./hash.js";
4
4
  import { ArtifactManifest, ArtifactScope, ArtifactSection, readArtifactSchema } from "./manifest.js";
@@ -23,6 +23,7 @@ function isFixtureDocument(path) {
23
23
  function isStoredPath(path) {
24
24
  return path.startsWith(`${ASSETS_DIR}/`);
25
25
  }
26
+ const ASSET_URL_PREFIX = "/section-assets/";
26
27
  const SECTION_FILES = {
27
28
  schema: "schema.json",
28
29
  fillSpec: "fill-spec.json",
@@ -92,6 +93,10 @@ function boundFiles(binding) {
92
93
  path: assetPath(filename),
93
94
  filename
94
95
  });
96
+ for (const filename of binding.relative_assets ?? []) out.push({
97
+ path: assetPath(filename),
98
+ filename
99
+ });
95
100
  const { ico, svg, png, apple_touch } = binding.icons;
96
101
  ref(assetPath(ico.filename), ico);
97
102
  if (svg !== null) ref(assetPath(svg.filename), svg);
@@ -123,4 +128,4 @@ function browserFileClashes(binding, paths) {
123
128
  }
124
129
 
125
130
  //#endregion
126
- export { ASSETS_DIR, BUILD_DIR, FIXTURES_DIR, FIXTURE_DOCUMENT_EXTENSION, MANIFEST_FILE, SECTIONS_DIR, SECTION_FILES, SECTION_ISLANDS_DIR, STATIC_DIR, TEMPLATE_DIR, TEMPLATE_FILES, assetPath, boundFiles, browserFileClashes, browserFiles, builtPathOf, builtTreePath, isBuiltTreePath, isFixtureDocument, isFixtureFilePath, isSectionKey, isStoredPath, isTemplateKey, islandPath, publishedSectionKey, sectionDir, sectionOfIslandKey, sectionPath, staticPath, templatePath };
131
+ export { ASSETS_DIR, ASSET_URL_PREFIX, BUILD_DIR, FIXTURES_DIR, FIXTURE_DOCUMENT_EXTENSION, MANIFEST_FILE, SECTIONS_DIR, SECTION_FILES, SECTION_ISLANDS_DIR, STATIC_DIR, TEMPLATE_DIR, TEMPLATE_FILES, assetPath, boundFiles, browserFileClashes, browserFiles, builtPathOf, builtTreePath, isBuiltTreePath, isFixtureDocument, isFixtureFilePath, isSectionKey, isStoredPath, isTemplateKey, islandPath, publishedSectionKey, sectionDir, sectionOfIslandKey, sectionPath, staticPath, templatePath };
@@ -1,4 +1,4 @@
1
- import { ASSETS_DIR, MANIFEST_FILE, SECTIONS_DIR, SECTION_FILES, SECTION_ISLANDS_DIR, STATIC_DIR, TEMPLATE_DIR, TEMPLATE_FILES, boundFiles, browserFileClashes, isStoredPath, sectionPath, templatePath } from "./layout.js";
1
+ import { ASSETS_DIR, ASSET_URL_PREFIX, MANIFEST_FILE, SECTIONS_DIR, SECTION_FILES, SECTION_ISLANDS_DIR, STATIC_DIR, TEMPLATE_DIR, TEMPLATE_FILES, boundFiles, browserFileClashes, isStoredPath, sectionPath, templatePath } from "./layout.js";
2
2
  import { sha256Hex } from "./sha256.js";
3
3
  import { sectionContentHash, templateContentHash } from "./hash.js";
4
4
  import { ArtifactManifest, readArtifactSchema } from "./manifest.js";
@@ -9,6 +9,7 @@ const SECTION_FILE_NAMES = new Set(Object.values(SECTION_FILES));
9
9
  const TEMPLATE_FILE_NAMES = new Set(Object.values(TEMPLATE_FILES));
10
10
  const ISLAND_CHUNK = new RegExp(`^${SECTION_ISLANDS_DIR}/[A-Za-z0-9._-]+\\.mjs$`);
11
11
  const FLAT_FILE = /^[A-Za-z0-9._-]+$/;
12
+ const BUILD_TEXT = /\.(?:css|mjs|js)$/;
12
13
  function readJson(files, path, problems) {
13
14
  const bytes = files.get(path);
14
15
  if (bytes === void 0) {
@@ -208,6 +209,13 @@ function verifyBuild(files, stored = /* @__PURE__ */ new Map()) {
208
209
  path: clash.paths[1],
209
210
  message: `is a browser file named ${clash.filename}, as ${clash.paths.filter((p) => p !== clash.paths[1]).join(" and ")} is: a build's browser files have one name each`
210
211
  });
212
+ if (binding.value.relative_assets !== void 0) for (const file of bound) {
213
+ const bytes = files.get(file.path);
214
+ if (bytes !== void 0 && BUILD_TEXT.test(file.path) && new TextDecoder().decode(bytes).includes("/section-assets/")) problems.push({
215
+ path: file.path,
216
+ message: `names an asset by the fixed address ${ASSET_URL_PREFIX}, which a build whose binding lists relative_assets never writes`
217
+ });
218
+ }
211
219
  for (const path of files.keys()) {
212
220
  const parts = path.split("/");
213
221
  const isChunk = parts.length === 5 && parts[0] === "sections" && parts[3] === "islands";
@@ -152,6 +152,13 @@ function processBindingOf(entry) {
152
152
  const { kind, verb } = entry;
153
153
  return kind === "process" && isProcessVerb(verb) ? entry : null;
154
154
  }
155
+ function processBindingsOf(process) {
156
+ if (!Array.isArray(process)) return [];
157
+ return process.map(processBindingOf).filter((binding) => binding !== null);
158
+ }
159
+ function processOf(bindings, verb) {
160
+ return bindings.find((binding) => binding.kind === "process" && binding.verb === verb);
161
+ }
155
162
  function processOptionsProblem(binding) {
156
163
  const entry = PROCESS_CATALOG[binding.verb];
157
164
  const takes = Object.keys(entry.options);
@@ -408,4 +415,4 @@ const PASSTHROUGH_TOUR_PROVIDERS = /* @__PURE__ */ new Set([
408
415
  ]);
409
416
 
410
417
  //#endregion
411
- export { CONTENT_SLOT_TYPES, DISPLAY_ENTRIES, HOLDER_PROCESS_VERBS, LINK_KINDS, LINK_PROVIDERS, LIST_SLOT_TYPES, MEDIA_KINDS, OBJECT_BINDING_OWN_KEYS, PROCESS_CATALOG, PROCESS_VERBS, REF_SLOT_TYPES, SLOT_TYPES, VISIBILITY_CASES, acceptsLink, declaredKinds, isEmailValue, isIsoDateValue, isLinkAccepts, isListSlotType, isMediaKind, isMediaType, isPhoneValue, isProcessVerb, kindOfLink, kindOfMime, matchLinkProvider, mediaDeclarationProblem, processBindingOf, processOptionsProblem, tourEmbedUrl, videoEmbedUrl };
418
+ export { CONTENT_SLOT_TYPES, DISPLAY_ENTRIES, HOLDER_PROCESS_VERBS, LINK_KINDS, LINK_PROVIDERS, LIST_SLOT_TYPES, MEDIA_KINDS, OBJECT_BINDING_OWN_KEYS, PROCESS_CATALOG, PROCESS_VERBS, REF_SLOT_TYPES, SLOT_TYPES, VISIBILITY_CASES, acceptsLink, declaredKinds, isEmailValue, isIsoDateValue, isLinkAccepts, isListSlotType, isMediaKind, isMediaType, isPhoneValue, isProcessVerb, kindOfLink, kindOfMime, matchLinkProvider, mediaDeclarationProblem, processBindingOf, processBindingsOf, processOf, processOptionsProblem, tourEmbedUrl, videoEmbedUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homepages/concrete",
3
- "version": "14.0.0",
3
+ "version": "14.1.0",
4
4
  "description": "Concrete, the HomePages template framework: the authoring API, the contract primitives, the styles, the lint preset and the `concrete` command in one package that owns its whole toolchain.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",