@homepages/concrete 1.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 (327) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +174 -0
  3. package/codemods/manifest.json +9 -0
  4. package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
  5. package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
  6. package/dist/artifact/playground/client/index.html +13 -0
  7. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
  8. package/dist/artifact/playground/host.mjs +127 -0
  9. package/dist/asset-modules.d.ts +99 -0
  10. package/dist/base.css +220 -0
  11. package/dist/browser/site-config.d.ts +18 -0
  12. package/dist/browser/site-config.js +56 -0
  13. package/dist/browser/submit-lead.d.ts +98 -0
  14. package/dist/browser/submit-lead.js +188 -0
  15. package/dist/browser.d.ts +3 -0
  16. package/dist/browser.js +4 -0
  17. package/dist/cli/build/artifact.js +225 -0
  18. package/dist/cli/build/captures.js +67 -0
  19. package/dist/cli/build/esbuild.js +127 -0
  20. package/dist/cli/build/fixtures.js +96 -0
  21. package/dist/cli/build/icons.js +76 -0
  22. package/dist/cli/build/index.js +38 -0
  23. package/dist/cli/build/playground.js +31 -0
  24. package/dist/cli/build/sections.js +236 -0
  25. package/dist/cli/build/source.js +62 -0
  26. package/dist/cli/build/static.js +156 -0
  27. package/dist/cli/capture/bundle.js +37 -0
  28. package/dist/cli/capture/capture-browser.js +51 -0
  29. package/dist/cli/capture/capture.js +121 -0
  30. package/dist/cli/check/analyze.js +95 -0
  31. package/dist/cli/check/index.js +19 -0
  32. package/dist/cli/check/load-workspace.js +119 -0
  33. package/dist/cli/check/messages.js +16 -0
  34. package/dist/cli/check/render/class-conflicts.js +39 -0
  35. package/dist/cli/check/render/html.js +86 -0
  36. package/dist/cli/check/render/inputs.js +53 -0
  37. package/dist/cli/check/render/invariants.js +58 -0
  38. package/dist/cli/check/render/island-frames.js +72 -0
  39. package/dist/cli/check/render/marker-coverage.js +102 -0
  40. package/dist/cli/check/render/nav.js +64 -0
  41. package/dist/cli/check/report.js +73 -0
  42. package/dist/cli/check/stages/bundles.js +129 -0
  43. package/dist/cli/check/stages/composition.js +67 -0
  44. package/dist/cli/check/stages/contracts.js +22 -0
  45. package/dist/cli/check/stages/dependencies.js +261 -0
  46. package/dist/cli/check/stages/fixtures.js +74 -0
  47. package/dist/cli/check/stages/lint.js +41 -0
  48. package/dist/cli/check/stages/logic.js +63 -0
  49. package/dist/cli/check/stages/render.js +144 -0
  50. package/dist/cli/check/stages/sections.js +83 -0
  51. package/dist/cli/check/stages/stylesheet.js +31 -0
  52. package/dist/cli/check/stages/typecheck.js +68 -0
  53. package/dist/cli/check/stages/workspace.js +26 -0
  54. package/dist/cli/commands.js +342 -0
  55. package/dist/cli/currency/cache.js +89 -0
  56. package/dist/cli/currency/decide.js +65 -0
  57. package/dist/cli/currency/opt-out.js +16 -0
  58. package/dist/cli/currency/preamble.js +183 -0
  59. package/dist/cli/currency/prompt.js +28 -0
  60. package/dist/cli/currency/refresh.js +44 -0
  61. package/dist/cli/currency/resolve-latest.js +185 -0
  62. package/dist/cli/currency/version-order.js +38 -0
  63. package/dist/cli/dev/crop.js +22 -0
  64. package/dist/cli/dev/hmr.js +26 -0
  65. package/dist/cli/dev/http.js +129 -0
  66. package/dist/cli/dev/index.js +70 -0
  67. package/dist/cli/dev/islands.js +390 -0
  68. package/dist/cli/dev/load-template.js +46 -0
  69. package/dist/cli/dev/request-error.js +22 -0
  70. package/dist/cli/dev/server.js +307 -0
  71. package/dist/cli/dev/tsconfig-paths.js +95 -0
  72. package/dist/cli/dev/vite.js +85 -0
  73. package/dist/cli/dev/workspace-reader.js +274 -0
  74. package/dist/cli/io.d.ts +14 -0
  75. package/dist/cli/media/cache.js +125 -0
  76. package/dist/cli/media/derive.js +252 -0
  77. package/dist/cli/media/deriver-plugin.js +71 -0
  78. package/dist/cli/property/index.js +180 -0
  79. package/dist/cli/property/library.js +137 -0
  80. package/dist/cli/publish/client.js +119 -0
  81. package/dist/cli/publish/freshness.js +66 -0
  82. package/dist/cli/publish/git.js +43 -0
  83. package/dist/cli/publish/index.js +207 -0
  84. package/dist/cli/publish/pack.js +78 -0
  85. package/dist/cli/publish/report.js +98 -0
  86. package/dist/cli/publish/target.js +87 -0
  87. package/dist/cli/publish/wire.js +29 -0
  88. package/dist/cli/tar.js +87 -0
  89. package/dist/cli/upgrade/codemod.js +56 -0
  90. package/dist/cli/upgrade/index.js +263 -0
  91. package/dist/cli/upgrade/manifest.js +72 -0
  92. package/dist/cli/upgrade/plan.js +68 -0
  93. package/dist/cli/upgrade/stage.js +71 -0
  94. package/dist/cli/version.d.ts +12 -0
  95. package/dist/cli/version.js +15 -0
  96. package/dist/cli/workspace.js +108 -0
  97. package/dist/cli.d.ts +6 -0
  98. package/dist/cli.js +94 -0
  99. package/dist/css/compile.js +77 -0
  100. package/dist/css/graph.js +109 -0
  101. package/dist/css/inline.js +132 -0
  102. package/dist/css/rules.js +65 -0
  103. package/dist/design-system/format-variants.js +127 -0
  104. package/dist/eslint/authoring.js +46 -0
  105. package/dist/eslint/correctness.js +42 -0
  106. package/dist/eslint/rules/editor-declaration.js +103 -0
  107. package/dist/eslint/rules/editor-reason.js +135 -0
  108. package/dist/eslint/rules/island-imports.js +20 -0
  109. package/dist/eslint/rules/jsx-visitor.js +20 -0
  110. package/dist/eslint/rules/no-client-runtime.js +88 -0
  111. package/dist/eslint/rules/no-editor-globals.js +60 -0
  112. package/dist/eslint/rules/no-hard-coded-color.js +183 -0
  113. package/dist/eslint/rules/no-inline-style.js +24 -0
  114. package/dist/eslint/rules/no-marker-literal.js +37 -0
  115. package/dist/eslint/rules/no-nondeterminism.js +44 -0
  116. package/dist/eslint/rules/no-px-breakpoint.js +44 -0
  117. package/dist/eslint/rules/no-raw-values.js +45 -0
  118. package/dist/eslint/rules/serializable-props.js +95 -0
  119. package/dist/eslint.d.ts +6 -0
  120. package/dist/eslint.js +26 -0
  121. package/dist/fixtures/brand.d.ts +4 -0
  122. package/dist/fixtures/brand.js +9 -0
  123. package/dist/fixtures/bundle-rule.js +67 -0
  124. package/dist/fixtures/canonical.d.ts +149 -0
  125. package/dist/fixtures/image-dimensions.js +59 -0
  126. package/dist/fixtures/load.js +154 -0
  127. package/dist/fixtures/media-plugin.js +141 -0
  128. package/dist/fixtures/media.js +165 -0
  129. package/dist/fixtures/property.js +210 -0
  130. package/dist/fixtures/resolve.js +202 -0
  131. package/dist/fixtures/rows.js +108 -0
  132. package/dist/fixtures/synthesize-empties.js +42 -0
  133. package/dist/fixtures.d.ts +213 -0
  134. package/dist/fixtures.js +37 -0
  135. package/dist/index.d.ts +53 -0
  136. package/dist/index.js +37 -0
  137. package/dist/islands/client-module.js +97 -0
  138. package/dist/islands/marker.d.ts +43 -0
  139. package/dist/islands/marker.js +44 -0
  140. package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
  141. package/dist/packages/external/concrete/package.js +5 -0
  142. package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
  143. package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
  144. package/dist/packages/internal/fill-bake/dist/display.js +9 -0
  145. package/dist/packages/internal/fill-bake/dist/index.js +6 -0
  146. package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
  147. package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
  148. package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
  149. package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
  150. package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
  151. package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
  152. package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
  153. package/dist/packages/internal/format-geometry/dist/index.js +4 -0
  154. package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
  155. package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
  156. package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
  157. package/dist/packages/internal/image-ladder/dist/index.js +4 -0
  158. package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
  159. package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
  160. package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
  161. package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
  162. package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
  163. package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
  164. package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
  165. package/dist/packages/internal/island-runtime/dist/index.js +163 -0
  166. package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
  167. package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
  168. package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
  169. package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
  170. package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
  171. package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
  172. package/dist/packages/internal/property-facts/dist/index.js +3 -0
  173. package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
  174. package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
  175. package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
  176. package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
  177. package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
  178. package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
  179. package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
  180. package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
  181. package/dist/packages/internal/section-contracts/dist/index.js +26 -0
  182. package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
  183. package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
  184. package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
  185. package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
  186. package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
  187. package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
  188. package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
  189. package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
  190. package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
  191. package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
  192. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
  193. package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
  194. package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
  195. package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
  196. package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
  197. package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
  198. package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
  199. package/dist/packages/internal/source-resolution/dist/index.js +222 -0
  200. package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
  201. package/dist/packages/internal/template-artifact/dist/index.js +7 -0
  202. package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
  203. package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
  204. package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
  205. package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
  206. package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
  207. package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
  208. package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
  209. package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
  210. package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
  211. package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
  212. package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
  213. package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
  214. package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
  215. package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
  216. package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
  217. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
  218. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
  219. package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
  220. package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
  221. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
  222. package/dist/playground/host/page-state.js +12 -0
  223. package/dist/playground/host/paths.js +9 -0
  224. package/dist/playground/layout.js +24 -0
  225. package/dist/playground/wire.js +36 -0
  226. package/dist/playground-island-runtime.d.ts +3 -0
  227. package/dist/playground-island-runtime.js +4 -0
  228. package/dist/primitives/FrameShell.d.ts +29 -0
  229. package/dist/primitives/FrameShell.js +34 -0
  230. package/dist/primitives/Image.d.ts +119 -0
  231. package/dist/primitives/Image.js +173 -0
  232. package/dist/primitives/Section.d.ts +22 -0
  233. package/dist/primitives/Section.js +26 -0
  234. package/dist/primitives/Tour.d.ts +43 -0
  235. package/dist/primitives/Tour.js +72 -0
  236. package/dist/primitives/Video.d.ts +57 -0
  237. package/dist/primitives/Video.js +116 -0
  238. package/dist/primitives/embed-playback.js +50 -0
  239. package/dist/primitives/index.d.ts +11 -0
  240. package/dist/primitives/marker-attrs.js +44 -0
  241. package/dist/primitives/object-fit.js +11 -0
  242. package/dist/primitives/picture-sources.d.ts +24 -0
  243. package/dist/primitives/picture-sources.js +52 -0
  244. package/dist/primitives/probe-context.js +24 -0
  245. package/dist/primitives/slot-bindings.d.ts +96 -0
  246. package/dist/primitives/slot-bindings.js +226 -0
  247. package/dist/primitives/slot-document.d.ts +35 -0
  248. package/dist/primitives/slot-document.js +37 -0
  249. package/dist/primitives/slot-group.d.ts +40 -0
  250. package/dist/primitives/slot-group.js +45 -0
  251. package/dist/primitives/slot-list.d.ts +21 -0
  252. package/dist/primitives/slot-list.js +23 -0
  253. package/dist/primitives/slot-media.d.ts +71 -0
  254. package/dist/primitives/slot-media.js +98 -0
  255. package/dist/primitives/slot-scalar.d.ts +53 -0
  256. package/dist/primitives/slot-scalar.js +98 -0
  257. package/dist/primitives/slot.d.ts +26 -0
  258. package/dist/primitives/slot.js +28 -0
  259. package/dist/rules/registry.js +479 -0
  260. package/dist/schema/compute.d.ts +22 -0
  261. package/dist/schema/compute.js +30 -0
  262. package/dist/schema/define-schema.d.ts +27 -0
  263. package/dist/schema/define-schema.js +73 -0
  264. package/dist/schema/extract-fill-spec.js +246 -0
  265. package/dist/schema/extract-used-facts.js +176 -0
  266. package/dist/schema/fact.d.ts +65 -0
  267. package/dist/schema/fact.js +33 -0
  268. package/dist/schema/fill-builders.d.ts +387 -0
  269. package/dist/schema/fill-builders.js +263 -0
  270. package/dist/schema/fill-declaration.d.ts +76 -0
  271. package/dist/schema/fill-declaration.js +43 -0
  272. package/dist/schema/fill-spec.d.ts +18 -0
  273. package/dist/schema/fill-spec.js +170 -0
  274. package/dist/schema/format-presets.d.ts +27 -0
  275. package/dist/schema/format-presets.js +76 -0
  276. package/dist/schema/format.d.ts +22 -0
  277. package/dist/schema/format.js +40 -0
  278. package/dist/schema/formats.d.ts +6 -0
  279. package/dist/schema/formats.js +7 -0
  280. package/dist/schema/layout.d.ts +32 -0
  281. package/dist/schema/layout.js +30 -0
  282. package/dist/schema/manifest.js +300 -0
  283. package/dist/schema/property-facts.d.ts +83 -0
  284. package/dist/schema/runtime-values.d.ts +88 -0
  285. package/dist/schema/section-nav.d.ts +38 -0
  286. package/dist/schema/section-nav.js +29 -0
  287. package/dist/schema/section-props.d.ts +98 -0
  288. package/dist/schema/section-schema.d.ts +53 -0
  289. package/dist/schema/section-schema.js +54 -0
  290. package/dist/schema/slot-builders.d.ts +497 -0
  291. package/dist/schema/slot-builders.js +331 -0
  292. package/dist/schema/slot-types.d.ts +110 -0
  293. package/dist/schema/slot-types.js +187 -0
  294. package/dist/section/declare.d.ts +44 -0
  295. package/dist/section/declare.js +27 -0
  296. package/dist/section/discovery.js +76 -0
  297. package/dist/section/groups.js +74 -0
  298. package/dist/section/materialize.js +28 -0
  299. package/dist/section/placements.js +28 -0
  300. package/dist/section/section.d.ts +69 -0
  301. package/dist/section/section.js +101 -0
  302. package/dist/site-analytics.d.ts +1 -0
  303. package/dist/site-analytics.js +15 -0
  304. package/dist/site-runtime/analytics.js +97 -0
  305. package/dist/site-runtime/site-integrations.js +97 -0
  306. package/dist/styles.css +60 -0
  307. package/dist/template/define-template.d.ts +139 -0
  308. package/dist/template/define-template.js +98 -0
  309. package/dist/template/logic-build.js +191 -0
  310. package/dist/template/logic-shim.d.ts +43 -0
  311. package/dist/template/logic-shim.js +52 -0
  312. package/dist/template/logic-transform.js +92 -0
  313. package/dist/template/materialize.js +107 -0
  314. package/dist/template/reconcile.d.ts +67 -0
  315. package/dist/template/reconcile.js +25 -0
  316. package/dist/template/running-copy.js +58 -0
  317. package/guide/reference/cli/INDEX.md +79 -0
  318. package/guide/reference/cli/build.md +48 -0
  319. package/guide/reference/cli/check.md +49 -0
  320. package/guide/reference/cli/dev.md +46 -0
  321. package/guide/reference/cli/property-add.md +53 -0
  322. package/guide/reference/cli/property-list.md +46 -0
  323. package/guide/reference/cli/publish.md +54 -0
  324. package/guide/reference/cli/upgrade.md +48 -0
  325. package/guide/reference/rules/INDEX.md +190 -0
  326. package/package.json +137 -0
  327. package/tsconfig.base.json +16 -0
@@ -0,0 +1,274 @@
1
+ import { stampCollectionBounds } from "../../packages/internal/template-contracts/dist/slot-catalog.js";
2
+ import { isTemplate } from "../../template/define-template.js";
3
+ import { compileTemplateCss } from "../../css/compile.js";
4
+ import { renderInstanceSlots } from "../../fixtures/media.js";
5
+ import { materializeTemplate, resolveEdit } from "../../template/materialize.js";
6
+ import { loadFixtures } from "../../fixtures/load.js";
7
+ import { resolveFixture } from "../../fixtures/resolve.js";
8
+ import { synthesizeEmptyFixtures } from "../../fixtures/synthesize-empties.js";
9
+ import { materializeSection } from "../../section/materialize.js";
10
+ import { loadTemplateModule } from "./load-template.js";
11
+ import { createElement } from "react";
12
+ import { existsSync } from "node:fs";
13
+ import { join } from "node:path";
14
+ import { renderToString } from "react-dom/server";
15
+
16
+ //#region src/cli/dev/workspace-reader.ts
17
+ const TEMPLATE_FILE = "template.ts";
18
+ function violationText(violations) {
19
+ return violations.map((v) => ` ${v.file}: ${v.message} (${v.rule})`).join("\n");
20
+ }
21
+ /** Concrete's reconcile rules address sections by key; the resolver's runner addresses instances. */
22
+ function bakeReconcileRules(template, instanceBySection) {
23
+ return template.reconcile.map((rule) => ({
24
+ description: rule.description,
25
+ reads: rule.reads.flatMap((ref) => {
26
+ const instanceId = instanceBySection[ref.section];
27
+ return instanceId === void 0 ? [] : [{
28
+ instanceId,
29
+ slot: ref.slot
30
+ }];
31
+ }),
32
+ fn: (ctx) => rule.fn({
33
+ site: ctx.site,
34
+ facts: ctx.facts
35
+ }).map((edit) => resolveEdit(edit, instanceBySection))
36
+ }));
37
+ }
38
+ function schemaWire(section, states) {
39
+ const materialized = materializeSection(section, states);
40
+ const slots = materialized.slots;
41
+ stampCollectionBounds(slots);
42
+ const groups = materialized.meta.groups;
43
+ return {
44
+ slots,
45
+ slot_order: materialized.slot_order,
46
+ ...groups === void 0 ? {} : { groups }
47
+ };
48
+ }
49
+ /** What the section declares about its display: a required section, and its variant's cases and lock. */
50
+ function displayOf(section) {
51
+ const variant = section.schema.meta.display?.variant;
52
+ return {
53
+ required: section.required,
54
+ variant: variant === void 0 ? null : {
55
+ cases: [...variant.cases],
56
+ locked: variant.locked === true
57
+ }
58
+ };
59
+ }
60
+ /** A resolved fixture as the host reads it: plain records, each media entry with its file's size when the loader knows it. */
61
+ function hostFixture(fixture, sizeOf) {
62
+ const media = {};
63
+ for (const [id, entry] of fixture.media) {
64
+ const url = entry.file === null ? void 0 : typeof entry.file === "string" ? entry.file : entry.file.url;
65
+ const size = url === void 0 ? void 0 : sizeOf(url);
66
+ media[id] = size === void 0 ? entry : {
67
+ ...entry,
68
+ sizeBytes: size
69
+ };
70
+ }
71
+ return {
72
+ id: fixture.id,
73
+ label: fixture.label,
74
+ facts: fixture.facts,
75
+ media,
76
+ instances: fixture.contentDoc.instances,
77
+ provenance: fixture.provenance,
78
+ ...fixture.synthesized ? { synthesized: true } : {}
79
+ };
80
+ }
81
+ var DevWorkspace = class {
82
+ options;
83
+ live = true;
84
+ capture;
85
+ composition = null;
86
+ fixtureSet = null;
87
+ stylesheet = null;
88
+ sectionAssets = /* @__PURE__ */ new Map();
89
+ constructor(options) {
90
+ this.options = options;
91
+ if (options.capture !== void 0) this.capture = options.capture;
92
+ }
93
+ get root() {
94
+ return this.options.root;
95
+ }
96
+ /** A module changed: everything derived from source is stale. */
97
+ invalidateSource() {
98
+ this.composition = null;
99
+ this.fixtureSet = null;
100
+ this.stylesheet = null;
101
+ }
102
+ /** A fixture module changed. */
103
+ invalidateFixtures() {
104
+ this.fixtureSet = null;
105
+ }
106
+ /** A stylesheet changed. */
107
+ invalidateStylesheet() {
108
+ this.stylesheet = null;
109
+ }
110
+ loadComposition() {
111
+ this.composition ??= (async () => {
112
+ const file = join(this.root, TEMPLATE_FILE);
113
+ if (!existsSync(file)) throw new Error(`There is no ${TEMPLATE_FILE} at ${this.root}. The workspace's template is declared there.`);
114
+ const loaded = await loadTemplateModule({
115
+ root: this.root,
116
+ templateFile: file,
117
+ markerSpecifier: this.options.markerSpecifier
118
+ });
119
+ if (!isTemplate(loaded.template)) throw new Error(`${TEMPLATE_FILE} must default-export the value defineTemplate() returns.`);
120
+ return {
121
+ template: loaded.template,
122
+ materialized: materializeTemplate(loaded.template),
123
+ assets: loaded.assets
124
+ };
125
+ })();
126
+ this.composition.catch(() => {
127
+ this.composition = null;
128
+ });
129
+ return this.composition;
130
+ }
131
+ loadFixtureSet() {
132
+ this.fixtureSet ??= (async () => {
133
+ const { template, materialized } = await this.loadComposition();
134
+ const loaded = await loadFixtures({ root: this.root });
135
+ const reconcile = bakeReconcileRules(template, materialized.instanceBySection);
136
+ const resolved = /* @__PURE__ */ new Map();
137
+ const violations = [...loaded.violations];
138
+ for (const fixture of loaded.fixtures) {
139
+ const result = resolveFixture(fixture, {
140
+ placements: materialized.placements,
141
+ reconcile
142
+ });
143
+ violations.push(...result.violations);
144
+ if (result.resolved !== null) resolved.set(fixture.id, result.resolved);
145
+ }
146
+ const authored = loaded.fixtures.flatMap((f) => resolved.get(f.id) ?? []);
147
+ const first = authored[0];
148
+ const empties = first === void 0 ? [] : synthesizeEmptyFixtures(first, materialized.placements);
149
+ const sizeOf = (url) => loaded.assets.get(url)?.bytes;
150
+ return {
151
+ loaded,
152
+ resolved,
153
+ hosted: [...authored, ...empties].map((fixture) => hostFixture(fixture, sizeOf)),
154
+ violations
155
+ };
156
+ })();
157
+ this.fixtureSet.catch(() => {
158
+ this.fixtureSet = null;
159
+ });
160
+ return this.fixtureSet;
161
+ }
162
+ async template() {
163
+ const { template, materialized } = await this.loadComposition();
164
+ const set = await this.loadFixtureSet();
165
+ const { manifest } = materialized;
166
+ const instances = materialized.instances.map(({ key, instanceId }) => {
167
+ const section = materialized.sections.get(key);
168
+ const states = [...set.resolved.values()].flatMap((fixture) => {
169
+ const instance = fixture.contentDoc.instances.find((i) => i.instance_id === instanceId);
170
+ return instance === void 0 ? [] : [renderInstanceSlots(instance, section, fixture.media)];
171
+ });
172
+ return {
173
+ instanceId,
174
+ section: key,
175
+ label: section.label,
176
+ sectionSchema: schemaWire(section, states),
177
+ display: displayOf(section)
178
+ };
179
+ });
180
+ return {
181
+ key: template.key,
182
+ name: template.name,
183
+ output: template.output,
184
+ formats: template.output === "website" ? [] : template.formats,
185
+ pages: manifest.pages.map((page) => ({
186
+ id: page.id,
187
+ label: page.label,
188
+ ..."path" in page && typeof page.path === "string" ? { path: page.path } : {},
189
+ sections: page.sections.map((s) => ({
190
+ instanceId: s.instance_id,
191
+ section: s.section
192
+ }))
193
+ })),
194
+ canvases: manifest.canvases.map((canvas) => ({
195
+ id: canvas.id,
196
+ label: canvas.label,
197
+ pages: [...canvas.pages]
198
+ })),
199
+ instances
200
+ };
201
+ }
202
+ async fixtures() {
203
+ const set = await this.loadFixtureSet();
204
+ return {
205
+ fixtures: set.hosted,
206
+ ...set.violations.length === 0 ? {} : { problems: violationText(set.violations) }
207
+ };
208
+ }
209
+ islands() {
210
+ const islands = this.options.islands();
211
+ return Promise.resolve({
212
+ map: islands.map,
213
+ canvasHost: islands.canvasHost,
214
+ documentLoader: islands.previewHost === null || Object.keys(islands.map).length === 0 ? { kind: "none" } : {
215
+ kind: "viteModules",
216
+ islandMap: islands.map,
217
+ bootstrapUrl: islands.previewHost
218
+ }
219
+ });
220
+ }
221
+ /** React over the composition's own section values: the renderer the host is handed in `dev`. */
222
+ renderer() {
223
+ return {
224
+ section: async (key) => {
225
+ const section = (await this.loadComposition()).materialized.sections.get(key);
226
+ if (section === void 0) throw new Error(`The composition places no section "${key}".`);
227
+ return section;
228
+ },
229
+ createElement: (type, props) => createElement(type, props),
230
+ renderToString: (element, options) => renderToString(element, options)
231
+ };
232
+ }
233
+ /** A media file the fixture loader or the template's own modules minted a URL for. */
234
+ async fixtureAsset(url) {
235
+ return (await this.loadComposition()).assets.get(url) ?? (await this.loadFixtureSet()).loaded.assets.get(url);
236
+ }
237
+ /** The template stylesheet. A graph that does not compile answers with the reason as a CSS comment. */
238
+ async templateCss() {
239
+ this.stylesheet ??= (async () => {
240
+ const { template } = await this.loadComposition();
241
+ return compileTemplateCss({
242
+ root: this.root,
243
+ templateFile: join(this.root, TEMPLATE_FILE),
244
+ template: {
245
+ key: template.key,
246
+ output: template.output,
247
+ formats: template.formats
248
+ }
249
+ });
250
+ })();
251
+ this.stylesheet.catch(() => {
252
+ this.stylesheet = null;
253
+ });
254
+ const result = await this.stylesheet;
255
+ if (result.bundle !== null) {
256
+ for (const asset of result.bundle.assets) this.sectionAssets.set(asset.filename, asset);
257
+ return {
258
+ css: new TextDecoder().decode(result.bundle.bytes),
259
+ violations: result.violations
260
+ };
261
+ }
262
+ return {
263
+ css: `/* the template stylesheet did not compile:\n${violationText(result.violations)}\n*/`,
264
+ violations: result.violations
265
+ };
266
+ }
267
+ /** An asset the template stylesheet references, by its content-hashed filename. */
268
+ sectionAsset(filename) {
269
+ return this.sectionAssets.get(filename);
270
+ }
271
+ };
272
+
273
+ //#endregion
274
+ export { DevWorkspace, TEMPLATE_FILE, bakeReconcileRules };
@@ -0,0 +1,14 @@
1
+ //#region src/cli/io.d.ts
2
+ interface CliIo {
3
+ /** The directory the command was invoked from. The workspace root is found from it. */
4
+ readonly cwd: string;
5
+ readonly env: Readonly<Record<string, string | undefined>>;
6
+ /** The command's own report. Nothing else writes here. */
7
+ readonly stdout: NodeJS.WritableStream;
8
+ /** Every notice, diagnostic and preamble line. */
9
+ readonly stderr: NodeJS.WritableStream;
10
+ /** Whether this is an attended session — stdout is a terminal. */
11
+ readonly tty: boolean;
12
+ }
13
+ //#endregion
14
+ export { CliIo };
@@ -0,0 +1,125 @@
1
+ import { LADDER_POLICY_FINGERPRINT } from "../../packages/internal/image-ladder/dist/policy.js";
2
+ import { basename, join } from "node:path";
3
+ import { mkdir, readFile, readdir, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
4
+ import { createHash } from "node:crypto";
5
+
6
+ //#region src/cli/media/cache.ts
7
+ const POLICY_VERSION = "1";
8
+ const MANIFEST = "manifest.json";
9
+ /**
10
+ * Where a workspace keeps its derived ladders: a `media/` subdirectory of the
11
+ * workspace's `.concrete/` directory, which the scaffold gitignores.
12
+ */
13
+ function mediaCacheDir(workspaceRoot) {
14
+ return join(workspaceRoot, ".concrete", "cache", "media");
15
+ }
16
+ /**
17
+ * Cache key for one master, namespaced by the derivation version AND the ladder
18
+ * policy's own fingerprint. Without the fingerprint term, changing the encoder settings
19
+ * and forgetting to bump `POLICY_VERSION` would leave this cache returning the OLD
20
+ * encodes indefinitely — a wrong preview and a wrong asset-budget number, with every
21
+ * gate still green.
22
+ *
23
+ * `masterKey` is `<stem>|<hash>`: the stem is part of it so two identically-byted
24
+ * masters with different names never inherit each other's derivative filenames.
25
+ *
26
+ * `policyFingerprint` defaults to the real policy's; a test overrides it to prove two
27
+ * policies produce two keys without touching the policy itself.
28
+ */
29
+ function cacheKey(masterKey, policyFingerprint = LADDER_POLICY_FINGERPRINT) {
30
+ return createHash("sha256").update(`${POLICY_VERSION}|${policyFingerprint}|${masterKey}`).digest("hex").slice(0, 24);
31
+ }
32
+ function isValidResponsive(responsive) {
33
+ if (responsive === null) return true;
34
+ if (typeof responsive !== "object") return false;
35
+ const candidate = responsive;
36
+ if (!Array.isArray(candidate.sources)) return false;
37
+ if (typeof candidate.width !== "number" || typeof candidate.height !== "number") return false;
38
+ return candidate.sources.every((source) => typeof source === "object" && source !== null && typeof source.type === "string" && typeof source.srcset === "string");
39
+ }
40
+ function isValidImage(image) {
41
+ if (typeof image !== "object" || image === null) return false;
42
+ const candidate = image;
43
+ return typeof candidate.url === "string" && typeof candidate.width === "number" && typeof candidate.height === "number" && isValidResponsive(candidate.responsive);
44
+ }
45
+ function isValidManifestDerivatives(derivatives) {
46
+ return derivatives.every((d) => typeof d === "object" && d !== null && typeof d.filename === "string" && typeof d.contentType === "string");
47
+ }
48
+ function referencesBaseRung(image, derivatives) {
49
+ const base = basename(image.url);
50
+ return derivatives.some((d) => d.filename === base);
51
+ }
52
+ /**
53
+ * The cached derivation for `key`, or null on any miss — absent, truncated, malformed,
54
+ * or missing one of its byte files. A partially-written entry MUST read as a miss: a
55
+ * half-populated ladder that looked like a hit would ship a broken srcset.
56
+ *
57
+ * SIDE EFFECT: a hit touches the entry's manifest mtime, which is what
58
+ * `pruneMediaCache` orders by. Eviction is therefore least-recently-USED, not
59
+ * least-recently-written. The touch is best-effort and never fails a read.
60
+ */
61
+ async function readCached(key, dir) {
62
+ const entry = join(dir, key);
63
+ try {
64
+ const manifest = JSON.parse(await readFile(join(entry, MANIFEST), "utf8"));
65
+ if (!Array.isArray(manifest.derivatives)) return null;
66
+ if (!isValidManifestDerivatives(manifest.derivatives)) return null;
67
+ if (!isValidImage(manifest.image)) return null;
68
+ if (!referencesBaseRung(manifest.image, manifest.derivatives)) return null;
69
+ const derivatives = [];
70
+ for (const d of manifest.derivatives) derivatives.push({
71
+ ...d,
72
+ bytes: new Uint8Array(await readFile(join(entry, d.filename)))
73
+ });
74
+ try {
75
+ const now = /* @__PURE__ */ new Date();
76
+ await utimes(join(entry, MANIFEST), now, now);
77
+ } catch {}
78
+ return {
79
+ image: manifest.image,
80
+ derivatives
81
+ };
82
+ } catch {
83
+ return null;
84
+ }
85
+ }
86
+ /**
87
+ * Persist one derivation. The manifest is written LAST and via rename, so a crash
88
+ * mid-write leaves an entry `readCached` rejects rather than a hit pointing at bytes
89
+ * that were never flushed. Rejects on an unusable directory — the caller decides
90
+ * whether that is fatal (it is not).
91
+ *
92
+ * Every byte file is also written to a process-unique temp name and renamed into
93
+ * place, never written in place — that guards a REWRITE of an existing key, not just
94
+ * the first write. A `check` and a `dev` server sharing one workspace can both miss
95
+ * the same cold key and both write it; and a single process can re-derive a key whose
96
+ * manifest is still intact but a byte file vanished (`readCached`'s own miss path).
97
+ * Either way, a second writer starts overwriting filenames the OLD, still-valid
98
+ * manifest still names — in place, a reader in that window would see a truncated
99
+ * file under a manifest that vouches for it. Renaming keeps every reader seeing
100
+ * either the fully-old or fully-new file, never a partial one, on either name.
101
+ */
102
+ async function writeCached(key, value, dir) {
103
+ const entry = join(dir, key);
104
+ await mkdir(entry, { recursive: true });
105
+ const tag = `${process.pid}-${Math.random().toString(36).slice(2)}`;
106
+ for (const d of value.derivatives) {
107
+ const tmp = join(entry, `${d.filename}.${tag}.tmp`);
108
+ await writeFile(tmp, d.bytes);
109
+ await rename(tmp, join(entry, d.filename));
110
+ }
111
+ const manifest = {
112
+ image: value.image,
113
+ derivatives: value.derivatives.map(({ filename, contentType }) => ({
114
+ filename,
115
+ contentType
116
+ }))
117
+ };
118
+ const tmpPath = join(entry, `${MANIFEST}.${tag}.tmp`);
119
+ await writeFile(tmpPath, JSON.stringify(manifest));
120
+ await rename(tmpPath, join(entry, MANIFEST));
121
+ }
122
+ const GARBAGE_RANK = Number.MIN_SAFE_INTEGER;
123
+
124
+ //#endregion
125
+ export { cacheKey, mediaCacheDir, readCached, writeCached };
@@ -0,0 +1,252 @@
1
+ import { cacheKey, readCached, writeCached } from "./cache.js";
2
+ import { basename, extname } from "node:path";
3
+ import { createHash } from "node:crypto";
4
+
5
+ //#region src/cli/media/derive.ts
6
+ function loadImageLadder() {
7
+ return import("../../packages/internal/image-ladder/dist/index.js");
8
+ }
9
+ /** The extensions a JS import derives. `.svg`/`.gif`/`.ico` are deliberately absent:
10
+ * rasterising line art is a regression, and a ladder cannot express an animation. */
11
+ const DERIVABLE_EXTENSIONS = /* @__PURE__ */ new Set([
12
+ ".jpg",
13
+ ".jpeg",
14
+ ".png",
15
+ ".webp",
16
+ ".avif"
17
+ ]);
18
+ /** 8 hex chars of sha256 over the master's bytes — the shared stem of every derivative. */
19
+ function masterHash(bytes) {
20
+ return createHash("sha256").update(bytes).digest("hex").slice(0, 8);
21
+ }
22
+ async function defaultLoadSharp() {
23
+ try {
24
+ return (await import("sharp")).default;
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+ const ASSET_PUBLIC_PATH = "/section-assets";
30
+ const PASSTHROUGH_CONTENT_TYPES = {
31
+ ".jpg": "image/jpeg",
32
+ ".jpeg": "image/jpeg",
33
+ ".png": "image/png",
34
+ ".webp": "image/webp",
35
+ ".avif": "image/avif"
36
+ };
37
+ /** The characters a derivative filename may contain — it is interpolated verbatim
38
+ * into a public URL and a space-delimited srcset candidate list. */
39
+ const SAFE_STEM = /^[A-Za-z0-9._-]+$/;
40
+ /**
41
+ * How many of a master's rung x format encodes run at once.
42
+ *
43
+ * MEASURED, not a core count. `sharp` is already multi-threaded per call — libvips
44
+ * sizes its own pool to the CPU count — so N concurrent encodes ask for roughly
45
+ * N x cores threads and hold N decoded copies of a large master resident at the same
46
+ * time. Past a point that buys nothing and costs RSS, on a machine already running
47
+ * the rest of a dev stack.
48
+ *
49
+ * Cold derivation of a 2560px photographic master — 9 rungs x 3 formats, 27 encodes
50
+ * — on a 4-core dev box, best of three interleaved rounds, peak process RSS:
51
+ *
52
+ * limit 1 (the serial loop this replaced) 17.2 s 483 MB
53
+ * limit 2 9.9 s 645 MB
54
+ * limit 3 8.0 s 742 MB
55
+ * limit 4 7.6 s 841 MB
56
+ * limit 6 8.0 s 814 MB
57
+ * limit 8 9.2 s 856 MB
58
+ *
59
+ * 4 is the bottom of the curve and it turns back up past it: the extra encodes only
60
+ * queue for the same cores while each one still pins its own decoded buffers. The
61
+ * cost of choosing it over 3 is ~100 MB for ~5% — take 3 if a dev box is the tighter
62
+ * constraint. Held at a constant rather than `availableParallelism()` deliberately:
63
+ * the quantity being bounded is how many large rasters may be decoded at once, and a
64
+ * 64-core CI box has the same answer to that as a laptop.
65
+ *
66
+ * End to end, the same change over a cold two-master section render (48 encodes)
67
+ * through the dev server's `/api/render`, three interleaved rounds, best of each:
68
+ * 64.0 s -> 31.3 s, peak server RSS 531 MB -> 945 MB. That ceiling is set by the pool
69
+ * and not by the corpus — masters are derived one at a time, and the three parallel
70
+ * rounds peaked within 4 MB of each other, so a 21-master workspace peaks where a
71
+ * two-master one does.
72
+ */
73
+ const ENCODE_CONCURRENCY = 4;
74
+ /**
75
+ * Run `task` over `items` with at most `limit` in flight, returning results in
76
+ * INPUT order — the ladder is positional (see the call site), so a completion-ordered
77
+ * result array would silently reshuffle every srcset it feeds.
78
+ *
79
+ * A rejection stops the pool from claiming further items and propagates, so one bad
80
+ * encode does not leave the rest of the ladder churning behind an already-failed call.
81
+ *
82
+ * EXPORTED FOR ITS TEST, and the test has to be here rather than over a real
83
+ * derivation: the ladder's own encodes get MORE expensive per rung and are fed in
84
+ * rung order, so they finish in very nearly input order anyway and a
85
+ * completion-ordered bug passes a byte-comparison against the serial run (verified —
86
+ * that mutant survives). Only a task whose completion order is deliberately inverted
87
+ * grades this.
88
+ */
89
+ async function mapConcurrent(items, limit, task) {
90
+ const results = new Array(items.length);
91
+ let next = 0;
92
+ let failed = false;
93
+ const worker = async () => {
94
+ for (let i = next++; i < items.length && !failed; i = next++) try {
95
+ results[i] = await task(items[i]);
96
+ } catch (err) {
97
+ failed = true;
98
+ throw err;
99
+ }
100
+ };
101
+ await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, worker));
102
+ return results;
103
+ }
104
+ var UnsafeStemError = class extends Error {
105
+ constructor(absPath, stem) {
106
+ super(`derive: "${stem}" (from ${absPath}) is not a safe derivative filename stem — only letters, digits, '.', '_', and '-' are allowed. A space, '#', '?', or '%' corrupts the emitted URL and the srcset it sits in. Rename the source file.`);
107
+ this.name = "UnsafeStemError";
108
+ }
109
+ };
110
+ const derivationCache = /* @__PURE__ */ new Map();
111
+ /**
112
+ * The master as an emitted file. Pure over (stem, hash, extension, bytes), so it is
113
+ * built OUTSIDE both cache tiers and attached on every path — an entry written
114
+ * before masters existed still serves one, and no cache holds a second copy of
115
+ * bytes the caller already has in hand.
116
+ */
117
+ function masterAsset(absPath, hash, bytes) {
118
+ const ext = extname(absPath).toLowerCase();
119
+ const key = `${basename(absPath, extname(absPath))}-${hash}`;
120
+ return {
121
+ key,
122
+ filename: `${key}${ext}`,
123
+ bytes,
124
+ contentType: PASSTHROUGH_CONTENT_TYPES[ext] ?? "application/octet-stream"
125
+ };
126
+ }
127
+ function toDerivation(cached, master, masterByteLength, passthrough) {
128
+ return {
129
+ image: cached.image,
130
+ derivatives: cached.derivatives,
131
+ master,
132
+ masterBytes: masterByteLength,
133
+ derivedBytes: cached.derivatives.reduce((n, d) => n + d.bytes.byteLength, 0),
134
+ passthrough
135
+ };
136
+ }
137
+ /**
138
+ * Derive `bytes` into a ladder and the `AuthorImage` that references it.
139
+ *
140
+ * `absPath` supplies only the derivative stem (its basename); nothing is read
141
+ * from disk here — the caller already has the bytes, and keeping this a pure
142
+ * function of them is what makes the in-process memoization sound.
143
+ *
144
+ * Without `sharp`, returns the master verbatim with `responsive: null` and
145
+ * `width`/`height` of 0 — unless a cached derivation for these exact bytes already
146
+ * exists, which is served regardless. `<Image>` reads dimensions only off
147
+ * `responsive`, so a zero is inert at render; it is reported by `check` rather than
148
+ * hidden.
149
+ */
150
+ async function deriveAuthorImage(absPath, bytes, opts = {}) {
151
+ const encodeConcurrency = opts.encodeConcurrency ?? ENCODE_CONCURRENCY;
152
+ const hash = masterHash(bytes);
153
+ const stem = basename(absPath, extname(absPath));
154
+ if (!SAFE_STEM.test(stem)) throw new UnsafeStemError(absPath, stem);
155
+ const masterKey = `${stem}|${hash}`;
156
+ const memoKey = `${opts.cacheDir ?? ""}|${masterKey}`;
157
+ const master = masterAsset(absPath, hash, bytes);
158
+ const memoHit = derivationCache.get(memoKey);
159
+ if (memoHit) return toDerivation(memoHit, master, bytes.byteLength, false);
160
+ const diskKey = cacheKey(masterKey);
161
+ if (opts.cacheDir !== void 0) {
162
+ const diskHit = await readCached(diskKey, opts.cacheDir);
163
+ if (diskHit) {
164
+ const memo = {
165
+ image: diskHit.image,
166
+ derivatives: diskHit.derivatives
167
+ };
168
+ derivationCache.set(memoKey, memo);
169
+ return toDerivation(memo, master, bytes.byteLength, false);
170
+ }
171
+ }
172
+ const sharp = await (opts.loadSharp ?? defaultLoadSharp)();
173
+ if (!sharp) return {
174
+ image: {
175
+ url: `${ASSET_PUBLIC_PATH}/${master.filename}`,
176
+ responsive: null,
177
+ width: 0,
178
+ height: 0
179
+ },
180
+ derivatives: [{
181
+ filename: master.filename,
182
+ bytes: master.bytes,
183
+ contentType: master.contentType
184
+ }],
185
+ master,
186
+ masterBytes: bytes.byteLength,
187
+ derivedBytes: bytes.byteLength,
188
+ passthrough: true
189
+ };
190
+ const { encodeRung, formatPolicyFor, rungsFor } = await loadImageLadder();
191
+ const buffer = Buffer.from(bytes);
192
+ const meta = await sharp(buffer).metadata();
193
+ const rungs = rungsFor(Math.max(meta.width ?? 0, meta.height ?? 0));
194
+ const specs = formatPolicyFor({
195
+ format: meta.format,
196
+ hasAlpha: meta.hasAlpha
197
+ });
198
+ const jobs = rungs.flatMap((edge) => specs.map((spec) => ({
199
+ edge,
200
+ spec
201
+ })));
202
+ const encoded = await mapConcurrent(jobs, encodeConcurrency, ({ edge, spec }) => encodeRung(buffer, edge, spec));
203
+ const derivatives = [];
204
+ const srcsetByType = /* @__PURE__ */ new Map();
205
+ let base = null;
206
+ const topRung = rungs[rungs.length - 1];
207
+ for (const [i, { edge, spec }] of jobs.entries()) {
208
+ const out = encoded[i];
209
+ const filename = `${stem}-${hash}-w${edge}.${out.ext}`;
210
+ const url = `${ASSET_PUBLIC_PATH}/${filename}`;
211
+ derivatives.push({
212
+ filename,
213
+ bytes: new Uint8Array(out.bytes),
214
+ contentType: out.contentType
215
+ });
216
+ const list = srcsetByType.get(out.contentType) ?? [];
217
+ list.push(`${url} ${out.width}w`);
218
+ srcsetByType.set(out.contentType, list);
219
+ if (edge === topRung && spec === specs[specs.length - 1]) base = {
220
+ url,
221
+ width: out.width,
222
+ height: out.height
223
+ };
224
+ }
225
+ if (!base) throw new Error(`derive: no base rung produced for ${absPath}`);
226
+ const derived = {
227
+ image: {
228
+ url: base.url,
229
+ responsive: {
230
+ sources: specs.map((spec) => ({
231
+ type: spec.contentType,
232
+ srcset: (srcsetByType.get(spec.contentType) ?? []).join(", ")
233
+ })),
234
+ width: base.width,
235
+ height: base.height
236
+ },
237
+ width: base.width,
238
+ height: base.height
239
+ },
240
+ derivatives
241
+ };
242
+ derivationCache.set(memoKey, derived);
243
+ if (opts.cacheDir !== void 0) try {
244
+ await writeCached(diskKey, derived, opts.cacheDir);
245
+ } catch (err) {
246
+ console.warn(`derive: could not write the media cache entry for ${absPath} (continuing without it):`, err);
247
+ }
248
+ return toDerivation(derived, master, bytes.byteLength, false);
249
+ }
250
+
251
+ //#endregion
252
+ export { DERIVABLE_EXTENSIONS, UnsafeStemError, deriveAuthorImage, mapConcurrent, masterHash };