@homepages/concrete 1.0.2 → 2.0.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/codemods/manifest.json +12 -0
  3. package/codemods/unlayer-author-css.mjs +194 -0
  4. package/dist/artifact/playground/client/assets/index-CW7co-u9.js +1101 -0
  5. package/dist/artifact/playground/client/assets/index-CckS2ONm.css +1 -0
  6. package/dist/artifact/playground/client/index.html +2 -2
  7. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
  8. package/dist/artifact/playground/host.mjs +24 -24
  9. package/dist/base.css +15 -2
  10. package/dist/cli/build/artifact.js +5 -2
  11. package/dist/cli/build/captures.js +15 -18
  12. package/dist/cli/build/fixtures.js +11 -3
  13. package/dist/cli/build/sections.js +13 -4
  14. package/dist/cli/build/static.js +1 -1
  15. package/dist/cli/check/load-workspace.js +6 -1
  16. package/dist/cli/check/stages/bundles.js +3 -1
  17. package/dist/cli/commands.js +1 -1
  18. package/dist/cli/dev/load-template.js +32 -25
  19. package/dist/cli/dev/server.js +11 -3
  20. package/dist/cli/dev/vite.js +78 -22
  21. package/dist/cli/dev/workspace-reader.js +2 -6
  22. package/dist/cli/media/derive.js +30 -3
  23. package/dist/cli/media/deriver-plugin.js +6 -2
  24. package/dist/cli/media/frame-rung-floor.js +18 -0
  25. package/dist/css/compile.js +26 -4
  26. package/dist/css/graph.js +2 -1
  27. package/dist/css/rules.js +72 -1
  28. package/dist/eslint/authoring.js +2 -0
  29. package/dist/eslint/rules/island-ids.js +39 -0
  30. package/dist/fixtures/load.js +6 -1
  31. package/dist/fixtures/media-plugin.js +32 -17
  32. package/dist/fixtures/media.js +41 -8
  33. package/dist/fixtures/package-stylesheets.js +59 -0
  34. package/dist/fixtures/property.js +40 -9
  35. package/dist/fixtures/resolve.js +58 -5
  36. package/dist/fixtures/rows.js +6 -1
  37. package/dist/fixtures.d.ts +80 -12
  38. package/dist/fixtures.js +7 -3
  39. package/dist/index.d.ts +2 -1
  40. package/dist/index.js +2 -1
  41. package/dist/islands/island-id.js +8 -0
  42. package/dist/islands/marker.d.ts +14 -4
  43. package/dist/islands/marker.js +18 -6
  44. package/dist/packages/external/concrete/package.js +1 -1
  45. package/dist/packages/internal/island-runtime/dist/index.js +4 -2
  46. package/dist/packages/internal/island-runtime/dist/island-id-context.js +15 -0
  47. package/dist/packages/internal/island-runtime/dist/use-island-id.d.ts +24 -0
  48. package/dist/packages/internal/island-runtime/dist/use-island-id.js +44 -0
  49. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1 -1
  50. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +44 -2
  51. package/dist/primitives/slot-bindings.d.ts +19 -13
  52. package/dist/primitives/slot-bindings.js +7 -3
  53. package/dist/rules/registry.js +19 -0
  54. package/dist/section/section.d.ts +6 -1
  55. package/dist/template/logic-shim.d.ts +2 -1
  56. package/dist/template/logic-shim.js +2 -1
  57. package/guide/reference/cli/INDEX.md +2 -2
  58. package/guide/reference/cli/build.md +2 -2
  59. package/guide/reference/cli/check.md +1 -1
  60. package/guide/reference/cli/dev.md +1 -1
  61. package/guide/reference/cli/property-add.md +1 -1
  62. package/guide/reference/cli/property-list.md +1 -1
  63. package/guide/reference/cli/publish.md +1 -1
  64. package/guide/reference/cli/upgrade.md +1 -1
  65. package/guide/reference/rules/INDEX.md +4 -1
  66. package/package.json +1 -1
  67. package/dist/artifact/playground/client/assets/index-BSA1yutg.css +0 -1
  68. package/dist/artifact/playground/client/assets/index-JloQyj8h.js +0 -1101
package/dist/css/rules.js CHANGED
@@ -24,6 +24,77 @@ function tailwindImportViolations(input) {
24
24
  message: `a second @import "tailwindcss" (the first is in ${first}). The import graph owns exactly one; remove this one.`
25
25
  }));
26
26
  }
27
+ /** The layer names the old kit's build owned. Author CSS may not declare them. */
28
+ const RETIRED_LAYERS = /* @__PURE__ */ new Set(["sections", "template"]);
29
+ /**
30
+ * `css` with comments and string literals blanked to spaces, newlines kept.
31
+ *
32
+ * Both halves are load-bearing. Every ported stylesheet explains the layer it used to
33
+ * sit in, so reading a comment as a declaration would fail the templates this rule
34
+ * exists to keep clean; and `content: "@layer template"` is a string, not a layer.
35
+ */
36
+ function maskNonCode(css) {
37
+ const out = [...css];
38
+ const blank = (from, to) => {
39
+ for (let k = from; k < Math.min(to, css.length); k += 1) if (out[k] !== "\n") out[k] = " ";
40
+ };
41
+ for (let i = 0; i < css.length;) if (css[i] === "/" && css[i + 1] === "*") {
42
+ const end = css.indexOf("*/", i + 2);
43
+ const stop = end === -1 ? css.length : end + 2;
44
+ blank(i, stop);
45
+ i = stop;
46
+ } else if (css[i] === "\"" || css[i] === "'") {
47
+ const quote = css[i];
48
+ let k = i + 1;
49
+ while (k < css.length && css[k] !== quote) k += css[k] === "\\" ? 2 : 1;
50
+ blank(i, k + 1);
51
+ i = k + 1;
52
+ } else i += 1;
53
+ return out.join("");
54
+ }
55
+ const AT_LAYER_RE = /@layer\s+([^;{]+)[;{]/gi;
56
+ const LAYER_FN_RE = /\blayer\(\s*([^)]*?)\s*\)/gi;
57
+ /** Every cascade layer a stylesheet names, root segment only (`sections.hero` → `sections`). */
58
+ function declaredLayerRoots(css) {
59
+ const source = maskNonCode(css);
60
+ const roots = [];
61
+ for (const re of [AT_LAYER_RE, LAYER_FN_RE]) {
62
+ re.lastIndex = 0;
63
+ for (let m = re.exec(source); m !== null; m = re.exec(source)) for (const name of (m[1] ?? "").split(",")) {
64
+ const root = name.trim().split(".")[0]?.trim();
65
+ if (root !== void 0 && root !== "") roots.push(root);
66
+ }
67
+ }
68
+ return roots;
69
+ }
70
+ /**
71
+ * `css/retired-layer`: author CSS declares `sections` or `template`, the layers the old
72
+ * kit's build folded hand-CSS into.
73
+ *
74
+ * Those layers ranked below `utilities`, so a declaration in one lost to any utility
75
+ * setting the same property on the same element — whatever its specificity, and
76
+ * invisibly, since the dev server served the same CSS unlayered. `base.css` no longer
77
+ * declares them, which means a stylesheet naming one now creates an IMPLICIT layer
78
+ * sorted after every declared one: the same rule would silently start winning instead.
79
+ * Either ordering is a trap, so the names are refused outright and author CSS stays
80
+ * unlayered, where what you wrote is what applies.
81
+ */
82
+ async function retiredLayerViolations(input) {
83
+ const violations = [];
84
+ for (const file of input.sources) {
85
+ const seen = /* @__PURE__ */ new Set();
86
+ for (const layer of declaredLayerRoots(await readFile(file, "utf8"))) {
87
+ if (!RETIRED_LAYERS.has(layer) || seen.has(layer)) continue;
88
+ seen.add(layer);
89
+ violations.push({
90
+ rule: "css/retired-layer",
91
+ file: workspaceRelative(input.root, file),
92
+ message: `declares @layer ${layer}, which @homepages/concrete retired. Your CSS is not layered: delete the wrapper and a plain rule outranks every utility setting the same property. To demote someone else's stylesheet instead, import it into a layer of your own naming — @import "pkg/x.css" layer(components).`
93
+ });
94
+ }
95
+ }
96
+ return violations;
97
+ }
27
98
  const EXTERNAL_RE = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
28
99
  const INLINE_RE = /^data:/i;
29
100
  const URL_FUNCTION_RE = /url\(\s*(['"]?)([^'")\s]+)\1\s*\)/gi;
@@ -62,4 +133,4 @@ async function externalUrlViolations(input) {
62
133
  }
63
134
 
64
135
  //#endregion
65
- export { externalUrlViolations, findExternalUrls, tailwindImportViolations, workspaceRelative };
136
+ export { declaredLayerRoots, externalUrlViolations, findExternalUrls, retiredLayerViolations, tailwindImportViolations, workspaceRelative };
@@ -1,6 +1,7 @@
1
1
  import { CONCRETE_RULES } from "../rules/registry.js";
2
2
  import { editorDeclaration } from "./rules/editor-declaration.js";
3
3
  import { editorReason } from "./rules/editor-reason.js";
4
+ import { islandIds } from "./rules/island-ids.js";
4
5
  import { noClientRuntime } from "./rules/no-client-runtime.js";
5
6
  import { noEditorGlobals } from "./rules/no-editor-globals.js";
6
7
  import { noHardCodedColor } from "./rules/no-hard-coded-color.js";
@@ -21,6 +22,7 @@ const AUTHORING_MODULES = {
21
22
  "concrete/islands/editor-declaration": editorDeclaration,
22
23
  "concrete/islands/editor-reason": editorReason,
23
24
  "concrete/islands/no-editor-globals": noEditorGlobals,
25
+ "concrete/islands/island-ids": islandIds,
24
26
  "concrete/slots/no-marker-literal": noMarkerLiteral,
25
27
  "concrete/slots/no-raw-values": noRawValues,
26
28
  "concrete/style/no-hard-coded-color": noHardCodedColor,
@@ -0,0 +1,39 @@
1
+ import { hasClientDirective } from "../../islands/client-module.js";
2
+
3
+ //#region src/eslint/rules/island-ids.ts
4
+ /** The call this node makes, by the name being called — `React.useId()` counts as `useId`. */
5
+ function calledName(callee) {
6
+ if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier") return callee.property.name;
7
+ return callee.type === "Identifier" ? callee.name : null;
8
+ }
9
+ const islandIds = {
10
+ meta: {
11
+ type: "problem",
12
+ docs: { description: "An island's own ids come from useIslandId, and only an island's do" },
13
+ schema: [],
14
+ messages: {
15
+ islandUseId: "`useId` returns a different id in this island's server render and its browser hydration, so markup carrying one hydrates into an attribute mismatch — reported in the console, on published pages too. Fix: compose the id from `useIslandId()` (`@homepages/concrete`), which is the id the server minted for this island, read back from its marker in the browser: ``const bodyId = `${useIslandId()}-body`;``.",
16
+ sectionIslandId: "`useIslandId` answers with an island's id, and server-rendered code is not inside one — it would hand back the same constant for every instance of this section on a page, which is a duplicate id. Fix: this markup renders once and hydrates never, so give it an id from what already distinguishes it (a slot id, a row key, `nav.selfAnchor`), and pass that to an island as a prop if the island needs it."
17
+ }
18
+ },
19
+ create(context) {
20
+ const sourceCode = context.sourceCode;
21
+ const inIsland = hasClientDirective(sourceCode.getText());
22
+ const banned = inIsland ? "useId" : "useIslandId";
23
+ const messageId = inIsland ? "islandUseId" : "sectionIslandId";
24
+ return { CallExpression(node) {
25
+ if (calledName(node.callee) !== banned) return;
26
+ if (node.callee.type === "Identifier") {
27
+ const ref = sourceCode.getScope(node).references.find((r) => r.identifier === node.callee);
28
+ if (ref?.resolved && ref.resolved.defs.some((d) => d.type !== "ImportBinding")) return;
29
+ }
30
+ context.report({
31
+ node,
32
+ messageId
33
+ });
34
+ } };
35
+ }
36
+ };
37
+
38
+ //#endregion
39
+ export { islandIds };
@@ -1,6 +1,7 @@
1
1
  import { isFixture } from "./brand.js";
2
2
  import { MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "./media-plugin.js";
3
3
  import { runningCopyPlugin } from "../template/running-copy.js";
4
+ import { createPackageStylesheetsPlugin } from "./package-stylesheets.js";
4
5
  import { readdirSync } from "node:fs";
5
6
  import { join, relative, sep } from "node:path";
6
7
  import { pathToFileURL } from "node:url";
@@ -41,6 +42,7 @@ let importSerial = 0;
41
42
  /** The default loader: one esbuild pass over every fixture module, then a dynamic import of each output. */
42
43
  async function bundleAndImportFixtureModules(root, files) {
43
44
  const media = createFixtureMediaPlugin(root);
45
+ const stylesheets = await createPackageStylesheetsPlugin(root);
44
46
  const outdir = join(root, ".concrete", "cache", "fixtures");
45
47
  let result;
46
48
  try {
@@ -63,7 +65,8 @@ async function bundleAndImportFixtureModules(root, files) {
63
65
  plugins: [
64
66
  runningCopyPlugin(),
65
67
  externalOutsideWorkspace(root),
66
- media.plugin
68
+ media.plugin,
69
+ stylesheets.plugin
67
70
  ],
68
71
  metafile: true,
69
72
  write: true,
@@ -81,6 +84,8 @@ async function bundleAndImportFixtureModules(root, files) {
81
84
  message: m.location === null || m.location === void 0 ? m.text : `${m.text} (${m.location.file}:${m.location.line})`
82
85
  }))
83
86
  };
87
+ } finally {
88
+ await stylesheets.dispose();
84
89
  }
85
90
  const outputByInput = /* @__PURE__ */ new Map();
86
91
  for (const [out, meta] of Object.entries(result.metafile.outputs)) if (meta.entryPoint !== void 0) outputByInput.set(join(root, meta.entryPoint), join(root, out));
@@ -79,6 +79,35 @@ function fixtureMediaUrl(path, bytes) {
79
79
  const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 8);
80
80
  return `${FIXTURE_MEDIA_PATH}/${basename(path, ext)}-${hash}${ext.toLowerCase()}`;
81
81
  }
82
+ /** Every extension a media import can name — the ambient shim's list, spelled once in MEDIA_LOADERS. */
83
+ const MEDIA_EXTENSIONS = new Set(Object.keys(MEDIA_LOADERS));
84
+ /**
85
+ * What a media import evaluates to, and the asset it stands for. THE one spelling of the
86
+ * two lanes: `concrete dev` runs a workspace through two module graphs — esbuild for the
87
+ * server, Vite for the islands — and an island is in BOTH, so an import that evaluates
88
+ * differently in each hydrates into an attribute mismatch on the element carrying it.
89
+ * Both graphs' plugins resolve through here so there is nothing for them to disagree on.
90
+ */
91
+ function fixtureMediaModule(path, bytes) {
92
+ const url = fixtureMediaUrl(path, bytes);
93
+ const derived = DERIVED_EXTENSIONS.has(extname(path).toLowerCase());
94
+ return {
95
+ asset: {
96
+ url,
97
+ path,
98
+ bytes: bytes.byteLength,
99
+ derived
100
+ },
101
+ value: derived ? {
102
+ url,
103
+ responsive: null,
104
+ ...imageDimensions(bytes) ?? {
105
+ width: 0,
106
+ height: 0
107
+ }
108
+ } : url
109
+ };
110
+ }
82
111
  /** A fresh plugin per pass; `assets` is what the pass recorded. */
83
112
  function createFixtureMediaPlugin(root) {
84
113
  const assets = /* @__PURE__ */ new Map();
@@ -109,22 +138,8 @@ function createFixtureMediaPlugin(root) {
109
138
  namespace: NAMESPACE
110
139
  }, async (args) => {
111
140
  const bytes = await readFile(args.path);
112
- const url = fixtureMediaUrl(args.path, bytes);
113
- const derived = DERIVED_EXTENSIONS.has(extname(args.path).toLowerCase());
114
- assets.set(url, {
115
- url,
116
- path: args.path,
117
- bytes: bytes.byteLength,
118
- derived
119
- });
120
- const value = derived ? {
121
- url,
122
- responsive: null,
123
- ...imageDimensions(bytes) ?? {
124
- width: 0,
125
- height: 0
126
- }
127
- } : url;
141
+ const { asset, value } = fixtureMediaModule(args.path, bytes);
142
+ assets.set(asset.url, asset);
128
143
  return {
129
144
  contents: `export default ${JSON.stringify(value)};`,
130
145
  loader: "js",
@@ -138,4 +153,4 @@ function createFixtureMediaPlugin(root) {
138
153
  }
139
154
 
140
155
  //#endregion
141
- export { FIXTURE_MEDIA_PATH, MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace, fixtureMediaUrl };
156
+ export { FIXTURE_MEDIA_PATH, MEDIA_EXTENSIONS, MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace, fixtureMediaModule, fixtureMediaUrl };
@@ -1,3 +1,5 @@
1
+ import { tourEmbedUrl, videoEmbedUrl } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
+
1
3
  //#region src/fixtures/media.ts
2
4
  const clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
3
5
  /**
@@ -68,11 +70,22 @@ function imageValue(entry, ref, resolver) {
68
70
  };
69
71
  return value;
70
72
  }
73
+ function posterOf(entry, resolver) {
74
+ if (entry.posterFile !== void 0) {
75
+ const served = resolver.file(entry.posterFile);
76
+ return served.responsive === null ? { poster: served.url } : {
77
+ poster: served.url,
78
+ poster_responsive: served.responsive
79
+ };
80
+ }
81
+ return { poster: entry.posterUrl ?? "" };
82
+ }
71
83
  function videoValue(entry, resolver) {
84
+ const poster = posterOf(entry, resolver);
72
85
  if (entry.file === null) return {
73
86
  video_id: entry.id,
74
- url: entry.url ?? "",
75
- poster: "",
87
+ url: videoEmbedUrl(entry.url ?? "") ?? "",
88
+ ...poster,
76
89
  alt: entry.alt,
77
90
  source: "link",
78
91
  ...entry.provider === null ? {} : { provider: entry.provider }
@@ -80,16 +93,16 @@ function videoValue(entry, resolver) {
80
93
  return {
81
94
  video_id: entry.id,
82
95
  url: resolver.file(entry.file).url,
83
- poster: "",
96
+ ...poster,
84
97
  alt: entry.alt,
85
98
  source: "upload"
86
99
  };
87
100
  }
88
- function tourValue(entry) {
101
+ function tourValue(entry, resolver) {
89
102
  return {
90
103
  tour_id: entry.id,
91
- url: entry.url ?? "",
92
- poster: "",
104
+ url: tourEmbedUrl(entry.url ?? "") ?? "",
105
+ ...posterOf(entry, resolver),
93
106
  alt: entry.alt,
94
107
  ...entry.provider === null ? {} : { provider: entry.provider }
95
108
  };
@@ -116,7 +129,7 @@ function renderMediaRef(kind, value, media, resolver) {
116
129
  switch (kind) {
117
130
  case "image": return imageValue(entry, value, resolver);
118
131
  case "video": return videoValue(entry, resolver);
119
- case "tour": return tourValue(entry);
132
+ case "tour": return tourValue(entry, resolver);
120
133
  case "document": return documentValue(entry, resolver);
121
134
  default: return null;
122
135
  }
@@ -127,6 +140,26 @@ const MEDIA_KINDS = /* @__PURE__ */ new Set([
127
140
  "tour",
128
141
  "document"
129
142
  ]);
143
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
144
+ function floorPlanValue(ref, media, resolver) {
145
+ const id = typeof ref.id === "string" ? ref.id : "";
146
+ const floorLabel = typeof ref.floor_label === "string" ? ref.floor_label : null;
147
+ const entry = id === "" ? void 0 : media.get(id);
148
+ const served = entry?.kind === "image" && entry.file !== null ? resolver.file(entry.file) : null;
149
+ return {
150
+ id,
151
+ ...typeof ref.upload_id === "string" ? { upload_id: ref.upload_id } : {},
152
+ url: served?.url ?? "",
153
+ alt: floorLabel ?? "Floor plan",
154
+ floor_label: floorLabel,
155
+ position: typeof ref.position === "number" ? ref.position : 0,
156
+ ...served?.responsive ? { responsive: served.responsive } : {}
157
+ };
158
+ }
159
+ function renderRowField(def, value, media, resolver) {
160
+ if (def.type === "image" && Array.isArray(value)) return value.filter(isRecord).map((ref) => floorPlanValue(ref, media, resolver));
161
+ return renderValue(def, value, media, resolver);
162
+ }
130
163
  function renderValue(def, value, media, resolver) {
131
164
  if (value === null || value === void 0) return value;
132
165
  if (MEDIA_KINDS.has(def.type)) return renderMediaRef(def.type, value, media, resolver);
@@ -137,7 +170,7 @@ function renderValue(def, value, media, resolver) {
137
170
  return items.map((row) => {
138
171
  if (typeof row !== "object" || row === null) return row;
139
172
  const out = { ...row };
140
- for (const [field, fieldDef] of Object.entries(fields)) out[field] = renderValue(fieldDef, out[field], media, resolver);
173
+ for (const [field, fieldDef] of Object.entries(fields)) out[field] = renderRowField(fieldDef, out[field], media, resolver);
141
174
  return out;
142
175
  });
143
176
  }
@@ -0,0 +1,59 @@
1
+ import { context } from "esbuild";
2
+
3
+ //#region src/fixtures/package-stylesheets.ts
4
+ const NAMESPACE = "concrete-package-stylesheet";
5
+ /**
6
+ * Whether a bare specifier names a stylesheet is only known once it resolves, and a
7
+ * pass's own `build.resolve` honours `packages: "external"` and never does. So the plugin
8
+ * asks a resolver context of its own, without that option, and claims only what
9
+ * resolves to `.css`; everything else falls through to the pass unchanged.
10
+ */
11
+ async function createPackageStylesheetsPlugin(root) {
12
+ let resolve;
13
+ const resolver = await context({
14
+ absWorkingDir: root,
15
+ platform: "node",
16
+ logLevel: "silent",
17
+ plugins: [{
18
+ name: `${NAMESPACE}-resolver`,
19
+ setup: (api) => void (resolve = (path, options) => api.resolve(path, options))
20
+ }]
21
+ });
22
+ const stylesheets = /* @__PURE__ */ new Map();
23
+ return {
24
+ plugin: {
25
+ name: NAMESPACE,
26
+ setup(api) {
27
+ api.onResolve({ filter: /^[^./]/ }, async (args) => {
28
+ if (args.kind === "entry-point" || args.path.startsWith("node:") || resolve === void 0) return null;
29
+ const key = `${args.kind}\0${args.resolveDir}\0${args.path}`;
30
+ let stylesheet = stylesheets.get(key);
31
+ if (stylesheet === void 0) {
32
+ stylesheet = resolve(args.path, {
33
+ kind: args.kind,
34
+ importer: args.importer,
35
+ resolveDir: args.resolveDir
36
+ }).then((resolved) => resolved.errors.length === 0 && !resolved.external && resolved.path.endsWith(".css") ? resolved.path : null);
37
+ stylesheets.set(key, stylesheet);
38
+ }
39
+ const path = await stylesheet;
40
+ return path === null ? null : {
41
+ path,
42
+ namespace: NAMESPACE
43
+ };
44
+ });
45
+ api.onLoad({
46
+ filter: /.*/,
47
+ namespace: NAMESPACE
48
+ }, () => ({
49
+ contents: "",
50
+ loader: "empty"
51
+ }));
52
+ }
53
+ },
54
+ dispose: () => resolver.dispose()
55
+ };
56
+ }
57
+
58
+ //#endregion
59
+ export { createPackageStylesheetsPlugin };
@@ -3,6 +3,16 @@ import "../packages/internal/property-facts/dist/index.js";
3
3
  import { basename, extname } from "node:path";
4
4
 
5
5
  //#region src/fixtures/property.ts
6
+ /**
7
+ * The id a contact's image takes. A contact card's avatar and logos are uploads like any
8
+ * other, but the platform holds them on the card rather than in a pool, so a fixture's
9
+ * property has no entry to carry their id and this mints one. The resolver mints the
10
+ * same id when a content entry states the image (a `ContactImageEntry`), which is why
11
+ * both go through here.
12
+ */
13
+ function contactImageId(contactId, field) {
14
+ return `contact:${contactId}:${field}`;
15
+ }
6
16
  const MIME_BY_EXTENSION = {
7
17
  ".pdf": "application/pdf",
8
18
  ".mp4": "video/mp4",
@@ -88,34 +98,55 @@ function canonicalizeProperty(property, file) {
88
98
  });
89
99
  media.set(plan.id, entry(plan.id, "image", planFile, ""));
90
100
  }
101
+ const admitThumbnail = (value, path) => {
102
+ if (value === void 0) return {};
103
+ if (typeof value === "string" && value !== "") return { posterUrl: value };
104
+ invalid(`${path}.thumbnail_source_url: expected a non-empty URL`);
105
+ return null;
106
+ };
91
107
  const videos = [];
92
108
  for (const [i, video] of (property.videos ?? []).entries()) {
93
109
  const path = `videos[${i}]`;
94
110
  if (!admit("videos", video.id, path)) continue;
95
111
  if (video.source === "upload") {
96
112
  if (!admitFile(video.file, `${path}.file`)) continue;
97
- const { file: videoFile, ...row } = video;
113
+ const { file: videoFile, poster, ...row } = video;
114
+ if (poster !== void 0 && !admitFile(poster, `${path}.poster`)) continue;
98
115
  videos.push({
99
116
  ...row,
100
117
  url: null,
101
118
  provider: null
102
119
  });
103
- media.set(video.id, entry(video.id, "video", videoFile, video.caption ?? ""));
120
+ media.set(video.id, {
121
+ ...entry(video.id, "video", videoFile, video.caption ?? ""),
122
+ ...poster === void 0 ? {} : { posterFile: poster }
123
+ });
104
124
  } else {
105
- videos.push(video);
125
+ const { thumbnail_source_url: thumbnail, ...row } = video;
126
+ const poster = admitThumbnail(thumbnail, path);
127
+ if (poster === null) continue;
128
+ videos.push(row);
106
129
  media.set(video.id, {
107
130
  ...entry(video.id, "video", null, video.caption ?? ""),
108
131
  url: video.url,
109
- provider: video.provider
132
+ provider: video.provider,
133
+ ...poster
110
134
  });
111
135
  }
112
136
  }
137
+ const tours = [];
113
138
  for (const [i, tour] of (property.tours ?? []).entries()) {
114
- if (!admit("tours", tour.id, `tours[${i}]`)) continue;
139
+ const path = `tours[${i}]`;
140
+ if (!admit("tours", tour.id, path)) continue;
141
+ const { thumbnail_source_url: thumbnail, ...row } = tour;
142
+ const poster = admitThumbnail(thumbnail, path);
143
+ if (poster === null) continue;
144
+ tours.push(row);
115
145
  media.set(tour.id, {
116
146
  ...entry(tour.id, "tour", null, ""),
117
147
  url: tour.url,
118
- provider: tour.provider
148
+ provider: tour.provider,
149
+ ...poster
119
150
  });
120
151
  }
121
152
  const documents = [];
@@ -144,7 +175,7 @@ function canonicalizeProperty(property, file) {
144
175
  const image = (value, field) => {
145
176
  if (value === null || value === void 0) return null;
146
177
  if (!admitFile(value, `${path}.${field}`)) return null;
147
- const id = `contact:${contact.id}:${field}`;
178
+ const id = contactImageId(contact.id, field);
148
179
  media.set(id, entry(id, "image", value, contact.name ?? ""));
149
180
  return id;
150
181
  };
@@ -168,7 +199,7 @@ function canonicalizeProperty(property, file) {
168
199
  listing_intent: property.listing_intent,
169
200
  units: property.units,
170
201
  narrative: property.narrative,
171
- tours: property.tours,
202
+ tours,
172
203
  comparables: property.comparables,
173
204
  photos,
174
205
  floor_plans: floorPlans,
@@ -207,4 +238,4 @@ function entry(id, kind, file, alt) {
207
238
  }
208
239
 
209
240
  //#endregion
210
- export { canonicalizeProperty, mediaUrl };
241
+ export { canonicalizeProperty, contactImageId, mediaUrl };
@@ -4,8 +4,8 @@ import { buildDeriveFactsView } from "../packages/internal/property-facts/dist/d
4
4
  import { bakeDisplayEntries, bakePropertyRefSlots } from "../packages/internal/fill-bake/dist/bake-property-ref.js";
5
5
  import { applyReconcile } from "../packages/internal/fill-bake/dist/reconcile-cross-section.js";
6
6
  import "../packages/internal/fill-bake/dist/index.js";
7
- import { canonicalizeProperty } from "./property.js";
8
- import { canonicalizeRows } from "./rows.js";
7
+ import { canonicalizeProperty, contactImageId } from "./property.js";
8
+ import { blankForField, canonicalizeRows } from "./rows.js";
9
9
 
10
10
  //#region src/fixtures/resolve.ts
11
11
  const MEDIA_KINDS = /* @__PURE__ */ new Set([
@@ -125,7 +125,13 @@ function resolveInstance(placement, entry, ctx) {
125
125
  if (gate !== void 0 && (variant === void 0 || !gate.includes(variant))) continue;
126
126
  const source = def.source;
127
127
  if (source?.kind === "direct" && typeof source.field === "string") {
128
- slots[id] = baked[id] ?? null;
128
+ const rows = baked[id] ?? null;
129
+ const fields = def.type === "list" ? def.fields : void 0;
130
+ slots[id] = fields === void 0 ? rows : enrichedRows(fields, rows, values[id], {
131
+ ...ctx,
132
+ instance: placement.instance,
133
+ slot: id
134
+ });
129
135
  provenance[id] = {
130
136
  kind: "fact",
131
137
  ref: source.field
@@ -164,6 +170,34 @@ function resolveInstance(placement, entry, ctx) {
164
170
  provenance
165
171
  };
166
172
  }
173
+ function enrichedRows(fields, baked, stated, ctx) {
174
+ if (!Array.isArray(baked)) return baked;
175
+ const bakedRows = baked;
176
+ const statedRows = Array.isArray(stated) ? stated : [];
177
+ if (statedRows.length > bakedRows.length) ctx.violations.push({
178
+ rule: "fixtures/rows-not-in-property",
179
+ file: ctx.module,
180
+ message: `fixture "${ctx.fixtureId}": "${ctx.instance}".${ctx.slot} states ${String(statedRows.length)} rows, but its property carries ${String(bakedRows.length)} — the rows of a bound list are the property's`
181
+ });
182
+ const blanks = {};
183
+ for (const [field, fieldDef] of Object.entries(fields)) if (fieldDef.source === void 0) blanks[field] = blankForField(fieldDef);
184
+ return bakedRows.map((row, index) => {
185
+ if (typeof row !== "object" || row === null) return row;
186
+ const out = {
187
+ ...blanks,
188
+ ...row
189
+ };
190
+ const statedRow = statedRows[index];
191
+ if (typeof statedRow !== "object" || statedRow === null || Array.isArray(statedRow)) return out;
192
+ for (const [field, fieldDef] of Object.entries(fields)) {
193
+ if (fieldDef.source !== void 0) continue;
194
+ const value = statedRow[field];
195
+ if (value === void 0 || value === null) continue;
196
+ out[field] = authoredValue(fieldDef, value, ctx);
197
+ }
198
+ return out;
199
+ });
200
+ }
167
201
  function authoredValue(def, value, ctx) {
168
202
  if (MEDIA_KINDS.has(def.type)) return mediaRef(def.type, value, ctx);
169
203
  if (def.type === "list") {
@@ -184,14 +218,33 @@ function authoredValue(def, value, ctx) {
184
218
  }
185
219
  return value;
186
220
  }
221
+ const CONTACT_IMAGE_FIELDS = /* @__PURE__ */ new Set([
222
+ "avatar",
223
+ "logo_dark",
224
+ "logo_light"
225
+ ]);
226
+ function contactImage(value) {
227
+ if (typeof value !== "object" || value === null) return null;
228
+ const { contact, field } = value;
229
+ if (typeof field !== "string" || !CONTACT_IMAGE_FIELDS.has(field)) return null;
230
+ const contactId = typeof contact === "object" && contact !== null ? contact.id : void 0;
231
+ if (typeof contactId !== "string") return null;
232
+ return {
233
+ id: contactImageId(contactId, field),
234
+ contact: contactId,
235
+ field
236
+ };
237
+ }
187
238
  function mediaRef(kind, value, ctx) {
188
- const id = typeof value === "object" && value !== null ? value.id : void 0;
239
+ const stated = kind === "image" ? contactImage(value) : null;
240
+ const id = stated?.id ?? (typeof value === "object" && value !== null ? value.id : void 0);
189
241
  const carried = typeof id === "string" ? ctx.media.get(id) : void 0;
190
242
  if (carried === void 0 || carried.kind !== kind) {
243
+ const what = stated !== null ? `the "${stated.field}" of contact "${stated.contact}", which its property does not carry` : typeof id === "string" ? `${kind} "${id}", which its property does not carry` : `a value that is not a ${kind} entry of its property`;
191
244
  ctx.violations.push({
192
245
  rule: "fixtures/media-not-in-property",
193
246
  file: ctx.module,
194
- message: `fixture "${ctx.fixtureId}": "${ctx.instance}".${ctx.slot} references ` + (typeof id === "string" ? `${kind} "${id}", which its property does not carry` : `a value that is not a ${kind} entry of its property`)
247
+ message: `fixture "${ctx.fixtureId}": "${ctx.instance}".${ctx.slot} references ${what}`
195
248
  });
196
249
  return null;
197
250
  }
@@ -63,6 +63,11 @@ function blankCollectionRow(collection, facts, rowFields) {
63
63
  };
64
64
  return COLLECTION_PROJECTIONS[collection](oneEmptyRow, rowFields)[0] ?? {};
65
65
  }
66
+ /**
67
+ * The per-kind blank of one declared row field — the same canonical form the binding
68
+ * layer normalizes an unfilled value to. Kept to the kinds a row field may take (a
69
+ * record cannot nest inside a record).
70
+ */
66
71
  function blankForField(def) {
67
72
  switch (def.type) {
68
73
  case "text":
@@ -105,4 +110,4 @@ function canonicalizeRows(slot, value, facts, rowFields) {
105
110
  }
106
111
 
107
112
  //#endregion
108
- export { canonicalizeRows };
113
+ export { blankForField, canonicalizeRows };