@homepages/concrete 12.0.0 → 13.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 (311) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/README.md +8 -10
  3. package/codemods/fixtures-are-data.mjs +7 -0
  4. package/codemods/fixtures-list-properties.mjs +6 -0
  5. package/codemods/manifest.json +11 -0
  6. package/codemods/steps/fixtures-list-properties.mjs +16 -0
  7. package/codemods/steps/fixtures-to-data.mjs +41 -0
  8. package/dist/artifact/playground/client/assets/archivo-latin-ext-wght-normal-C4zznr8T.woff2 +0 -0
  9. package/dist/artifact/playground/client/assets/archivo-latin-wght-normal-E0tuGl4L.woff2 +0 -0
  10. package/dist/artifact/playground/client/assets/archivo-vietnamese-wght-normal-XAtsl5Q_.woff2 +0 -0
  11. package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +1338 -0
  12. package/dist/artifact/playground/client/assets/index-C01UCAWD.css +1 -0
  13. package/dist/artifact/playground/client/index.html +2 -2
  14. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
  15. package/dist/artifact/playground/host.mjs +110 -59
  16. package/dist/base.css +2 -2
  17. package/dist/cli/build/icons.js +1 -1
  18. package/dist/cli/build/index.js +11 -10
  19. package/dist/cli/build/manifest.js +44 -0
  20. package/dist/cli/build/record.js +123 -0
  21. package/dist/cli/build/sections.js +28 -18
  22. package/dist/cli/build/source.js +1 -1
  23. package/dist/cli/build/static.js +8 -5
  24. package/dist/cli/build/template-build.js +614 -0
  25. package/dist/cli/check/analyze.js +18 -1
  26. package/dist/cli/check/load-workspace.js +2 -2
  27. package/dist/cli/check/portable-names.js +1 -1
  28. package/dist/cli/check/render/corpus.js +119 -0
  29. package/dist/cli/check/render/invariants.js +1 -0
  30. package/dist/cli/check/stages/bundles.js +15 -18
  31. package/dist/cli/check/stages/composition.js +8 -25
  32. package/dist/cli/check/stages/fixtures.js +14 -10
  33. package/dist/cli/check/stages/logic.js +7 -23
  34. package/dist/cli/check/stages/render.js +12 -14
  35. package/dist/cli/check/stages/sections.js +22 -66
  36. package/dist/cli/check/stages/stylesheet.js +4 -26
  37. package/dist/cli/check/stages/workspace.js +27 -22
  38. package/dist/cli/commands.js +51 -23
  39. package/dist/cli/currency/preamble.js +1 -1
  40. package/dist/cli/currency/resolve-latest.js +3 -2
  41. package/dist/cli/dev/capture-browser.js +26 -0
  42. package/dist/cli/dev/fixture-schema.js +441 -0
  43. package/dist/cli/dev/folder-files.js +244 -0
  44. package/dist/cli/dev/index.js +7 -3
  45. package/dist/cli/dev/playground-server.js +34 -0
  46. package/dist/cli/dev/section-ladders.js +76 -0
  47. package/dist/cli/dev/server.js +120 -304
  48. package/dist/cli/install/background.js +16 -0
  49. package/dist/cli/install/index.js +45 -0
  50. package/dist/cli/install/tools.js +27 -0
  51. package/dist/cli/media/derive.js +19 -13
  52. package/dist/cli/media/deriver-plugin.js +14 -3
  53. package/dist/cli/property/fixture-list.js +46 -0
  54. package/dist/cli/property/index.js +12 -9
  55. package/dist/cli/property/library.js +12 -10
  56. package/dist/cli/publish/artifact.js +90 -0
  57. package/dist/cli/publish/captures.js +61 -0
  58. package/dist/cli/publish/fixtures.js +17 -0
  59. package/dist/cli/publish/index.js +10 -18
  60. package/dist/cli/{build → publish}/playground.js +3 -3
  61. package/dist/cli/publish/report.js +15 -33
  62. package/dist/cli/upgrade/codemod.d.ts +14 -0
  63. package/dist/cli/upgrade/fixture-conversion.d.ts +11 -0
  64. package/dist/cli/upgrade/fixture-conversion.js +54 -0
  65. package/dist/cli/upgrade/fixture-modules.js +125 -0
  66. package/dist/cli/upgrade/fixtures-to-data.d.ts +40 -0
  67. package/dist/cli/upgrade/fixtures-to-data.js +498 -0
  68. package/dist/cli/upgrade/index.js +18 -2
  69. package/dist/cli/upgrade/legacy-fixtures.d.ts +34 -0
  70. package/dist/cli/upgrade/legacy-fixtures.js +22 -0
  71. package/dist/cli/upgrade/stage.js +1 -1
  72. package/dist/cli/workspace-fixtures.js +80 -0
  73. package/dist/cli.js +1 -0
  74. package/dist/css/compile.js +9 -3
  75. package/dist/fixtures/bundle-rule.js +16 -16
  76. package/dist/fixtures/media-plugin.js +12 -33
  77. package/dist/fixtures/synthesize-empties.js +3 -2
  78. package/dist/index.d.ts +7 -7
  79. package/dist/{playground-island-runtime.d.ts → island-runtime.d.ts} +1 -2
  80. package/dist/{playground-island-runtime.js → island-runtime.js} +1 -2
  81. package/dist/islands/client-module.js +1 -1
  82. package/dist/{cli/dev → islands}/tsconfig-paths.js +2 -14
  83. package/dist/islands/wrap.js +40 -0
  84. package/dist/node_modules/.pnpm/acorn@8.18.0/node_modules/acorn/dist/acorn.js +5119 -0
  85. package/dist/packages/external/concrete/package.js +1 -1
  86. package/dist/packages/internal/bundle-evaluation/dist/cache.js +36 -0
  87. package/dist/packages/internal/bundle-evaluation/dist/evaluate.js +174 -0
  88. package/dist/packages/internal/bundle-evaluation/dist/index.js +5 -0
  89. package/dist/packages/internal/bundle-evaluation/dist/section-code.js +10 -0
  90. package/dist/packages/internal/capture-settle/dist/index.js +2 -2
  91. package/dist/packages/internal/capture-settle/dist/settle.js +88 -13
  92. package/dist/packages/internal/code-fingerprint/dist/index.js +57 -0
  93. package/dist/packages/internal/content-doc-ops/dist/index.js +176 -0
  94. package/dist/packages/internal/content-doc-ops/dist/made-rows.js +15 -0
  95. package/dist/packages/internal/deliverable-reads/dist/bootstrap.js +81 -0
  96. package/dist/packages/internal/deliverable-reads/dist/display.js +21 -0
  97. package/dist/packages/internal/deliverable-reads/dist/format.js +15 -0
  98. package/dist/packages/internal/deliverable-reads/dist/index.js +7 -0
  99. package/dist/packages/internal/deliverable-reads/dist/pages.js +29 -0
  100. package/dist/packages/internal/deliverable-reads/dist/requirements.js +72 -0
  101. package/dist/{cli/capture → packages/internal/download-files/dist}/bundle.js +8 -4
  102. package/dist/packages/internal/download-files/dist/capture-origin.js +126 -0
  103. package/dist/packages/internal/download-files/dist/capture-routes.js +139 -0
  104. package/dist/packages/internal/download-files/dist/capture-shell.js +38 -0
  105. package/dist/packages/internal/download-files/dist/capture.js +74 -0
  106. package/dist/packages/internal/download-files/dist/egress-watch.js +38 -0
  107. package/dist/packages/internal/download-files/dist/files.js +7 -0
  108. package/dist/packages/internal/download-files/dist/finish.js +35 -0
  109. package/dist/packages/internal/download-files/dist/fleet.js +94 -0
  110. package/dist/packages/internal/download-files/dist/format.js +40 -0
  111. package/dist/packages/internal/download-files/dist/make.js +105 -0
  112. package/dist/packages/internal/download-files/dist/master-tally.js +32 -0
  113. package/dist/packages/internal/download-files/dist/names.js +24 -0
  114. package/dist/packages/internal/download-files/dist/pdf-boxes.js +33 -0
  115. package/dist/packages/internal/download-files/dist/pdf-image-placements.js +194 -0
  116. package/dist/packages/internal/download-files/dist/pdf-images.js +289 -0
  117. package/dist/packages/internal/file-store/dist/files.js +8 -0
  118. package/dist/packages/internal/file-store/dist/lru.js +40 -0
  119. package/dist/packages/internal/file-store/dist/refusal.js +12 -0
  120. package/dist/packages/internal/file-store/dist/trees.js +151 -0
  121. package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +1 -1
  122. package/dist/packages/internal/fill-bake/dist/compute-reads.js +47 -21
  123. package/dist/packages/internal/fill-bake/dist/index.js +5 -1
  124. package/dist/packages/internal/fill-bake/dist/item-merge.js +4 -3
  125. package/dist/packages/internal/fill-bake/dist/resolve-instance.js +9 -0
  126. package/dist/packages/internal/fill-bake/dist/resolve.js +3 -0
  127. package/dist/packages/internal/fill-bake/dist/round-trip.js +2 -0
  128. package/dist/packages/internal/fill-bake/dist/strip.js +6 -0
  129. package/dist/packages/internal/fill-vocabulary/dist/holder.js +1 -1
  130. package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +1 -1
  131. package/dist/packages/internal/fill-vocabulary/dist/verbs.js +1 -1
  132. package/dist/packages/internal/island-runtime/dist/index.js +1 -10
  133. package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +5 -0
  134. package/dist/packages/internal/lead-fields/dist/ingest.js +72 -0
  135. package/dist/packages/internal/media-resolution/dist/video.js +6 -2
  136. package/dist/packages/internal/page-render/dist/addresses.js +57 -0
  137. package/dist/packages/internal/page-render/dist/index.js +6 -0
  138. package/dist/packages/internal/page-render/dist/kept.js +30 -0
  139. package/dist/packages/internal/page-render/dist/nav.js +42 -0
  140. package/dist/packages/internal/page-render/dist/render.js +152 -0
  141. package/dist/packages/internal/page-shell/dist/assemble.js +161 -0
  142. package/dist/packages/internal/page-shell/dist/escape.js +10 -0
  143. package/dist/packages/internal/page-shell/dist/frame.js +23 -0
  144. package/dist/packages/internal/page-shell/dist/index.js +26 -0
  145. package/dist/packages/internal/playground/dist/build-fingerprint.js +18 -0
  146. package/dist/packages/internal/playground/dist/fixture-conversions/list-names-properties.js +76 -0
  147. package/dist/packages/internal/playground/dist/fixture-formats.d.ts +37 -0
  148. package/dist/packages/internal/playground/dist/fixture-formats.js +20 -0
  149. package/dist/packages/internal/playground/dist/host/bootstrap.js +108 -0
  150. package/dist/packages/internal/playground/dist/host/built.js +202 -0
  151. package/dist/packages/internal/playground/dist/host/catalog-fixture.js +53 -0
  152. package/dist/packages/internal/playground/dist/host/download.js +34 -0
  153. package/dist/packages/internal/playground/dist/host/env.js +11 -0
  154. package/dist/packages/internal/playground/dist/host/everywhere-saves.js +353 -0
  155. package/dist/packages/internal/playground/dist/host/fixture-addresses.js +52 -0
  156. package/dist/packages/internal/playground/dist/host/fixture-documents.js +494 -0
  157. package/dist/packages/internal/playground/dist/host/fixture-operations.js +364 -0
  158. package/dist/packages/internal/playground/dist/host/fixture-units.js +93 -0
  159. package/dist/{fixtures → packages/internal/playground/dist/host}/image-dimensions.js +1 -1
  160. package/dist/packages/internal/playground/dist/host/leads.js +41 -0
  161. package/dist/packages/internal/playground/dist/host/media-saves.js +309 -0
  162. package/dist/{fixtures → packages/internal/playground/dist/host}/media-store.js +79 -26
  163. package/dist/packages/internal/playground/dist/host/overridable.js +9 -0
  164. package/dist/packages/internal/playground/dist/host/owned-saves.js +203 -0
  165. package/dist/{playground → packages/internal/playground/dist}/host/page-state.js +1 -1
  166. package/dist/packages/internal/playground/dist/host/program.js +54 -0
  167. package/dist/packages/internal/playground/dist/host/property-derive.js +216 -0
  168. package/dist/packages/internal/playground/dist/host/property-saves.js +74 -0
  169. package/dist/{fixtures → packages/internal/playground/dist/host}/property.js +88 -229
  170. package/dist/packages/internal/playground/dist/host/provenance.js +49 -0
  171. package/dist/packages/internal/playground/dist/host/resolve.js +553 -0
  172. package/dist/packages/internal/playground/dist/host/row-images.js +41 -0
  173. package/dist/{fixtures → packages/internal/playground/dist/host}/rows.js +1 -1
  174. package/dist/packages/internal/playground/dist/host/save.js +429 -0
  175. package/dist/packages/internal/playground/dist/host/serve.js +952 -0
  176. package/dist/packages/internal/playground/dist/host/site.js +79 -0
  177. package/dist/packages/internal/playground/dist/host/slots.js +202 -0
  178. package/dist/packages/internal/playground/dist/host/stated-content.js +93 -0
  179. package/dist/packages/internal/playground/dist/host/stored-fixtures.js +135 -0
  180. package/dist/packages/internal/playground/dist/host/violations.js +7 -0
  181. package/dist/packages/internal/playground/dist/jobs/lanes.js +24 -0
  182. package/dist/packages/internal/playground/dist/jobs/memory-queue.js +112 -0
  183. package/dist/packages/internal/playground/dist/jobs/probe.js +37 -0
  184. package/dist/packages/internal/playground/dist/jobs/queue.js +28 -0
  185. package/dist/packages/internal/playground/dist/jobs/runner.js +207 -0
  186. package/dist/packages/internal/playground/dist/layout.js +14 -0
  187. package/dist/packages/internal/playground/dist/platform.js +33 -0
  188. package/dist/packages/internal/playground/dist/server/changes.js +57 -0
  189. package/dist/packages/internal/playground/dist/server/crop.js +47 -0
  190. package/dist/packages/internal/playground/dist/server/derived-files.js +88 -0
  191. package/dist/packages/internal/playground/dist/server/download.js +158 -0
  192. package/dist/{cli/dev → packages/internal/playground/dist/server}/http.js +4 -12
  193. package/dist/packages/internal/playground/dist/server/jobs.js +29 -0
  194. package/dist/{cli/dev → packages/internal/playground/dist/server}/listen.js +4 -11
  195. package/dist/packages/internal/playground/dist/server/playground-server.js +424 -0
  196. package/dist/{cli/dev → packages/internal/playground/dist/server}/request-error.js +1 -1
  197. package/dist/packages/internal/playground/dist/server/size-ladders.js +170 -0
  198. package/dist/packages/internal/playground/dist/server/verification.js +75 -0
  199. package/dist/packages/internal/playground/dist/server/verify-build.js +139 -0
  200. package/dist/packages/internal/playground/dist/wire.js +78 -0
  201. package/dist/packages/internal/property-facts/dist/registry-facts.js +1 -1
  202. package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -1
  203. package/dist/packages/internal/section-contracts/dist/reads-acyclic-contract.js +1 -1
  204. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -1
  205. package/dist/packages/internal/site-files/dist/head.js +59 -0
  206. package/dist/packages/internal/site-files/dist/index.js +4 -0
  207. package/dist/packages/internal/site-files/dist/site.js +211 -0
  208. package/dist/packages/internal/static-assets-binding/dist/index.js +32 -0
  209. package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +38 -5
  210. package/dist/packages/internal/template-artifact/dist/asset-mime.js +8 -1
  211. package/dist/packages/internal/template-artifact/dist/build.js +148 -0
  212. package/dist/packages/internal/template-artifact/dist/composition.js +62 -0
  213. package/dist/packages/internal/template-artifact/dist/index.js +2 -2
  214. package/dist/packages/internal/template-artifact/dist/layout.js +48 -12
  215. package/dist/packages/internal/template-artifact/dist/manifest.js +3 -10
  216. package/dist/packages/internal/template-artifact/dist/verify.js +51 -31
  217. package/dist/packages/internal/template-contracts/dist/address-value.js +6 -1
  218. package/dist/packages/internal/template-contracts/dist/content-categories.js +10 -1
  219. package/dist/packages/internal/template-contracts/dist/fact-compute.d.ts +1 -1
  220. package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +1 -1
  221. package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +3 -3
  222. package/dist/packages/internal/template-contracts/dist/fact-registry.js +59 -32
  223. package/dist/packages/internal/template-contracts/dist/fill-spec.js +14 -1
  224. package/dist/packages/internal/template-contracts/dist/list.d.ts +3 -3
  225. package/dist/packages/internal/template-contracts/dist/media-candidates.js +67 -2
  226. package/dist/packages/internal/template-contracts/dist/media-offer.js +180 -0
  227. package/dist/packages/internal/template-contracts/dist/object.d.ts +2 -2
  228. package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +9 -2
  229. package/dist/packages/internal/template-contracts/dist/read-graph.js +36 -2
  230. package/dist/packages/internal/template-contracts/dist/ref-locate.js +16 -1
  231. package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +9 -10
  232. package/dist/packages/internal/template-contracts/dist/registry-facts.js +12 -1
  233. package/dist/packages/internal/template-contracts/dist/registry-graph.js +112 -0
  234. package/dist/packages/internal/template-contracts/dist/registry-shape.js +15 -2
  235. package/dist/packages/internal/template-contracts/dist/require-graph.js +300 -0
  236. package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +3 -3
  237. package/dist/packages/internal/template-contracts/dist/row.d.ts +3 -3
  238. package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +1 -1
  239. package/dist/{schema → packages/internal/template-contracts/dist}/section-nav.d.ts +1 -1
  240. package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +4 -4
  241. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +3 -1
  242. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +24 -1
  243. package/dist/packages/internal/template-contracts/dist/slot-overrides.js +26 -1
  244. package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +1 -1
  245. package/dist/packages/internal/template-contracts/dist/slot-types.js +1 -1
  246. package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +1 -1
  247. package/dist/packages/internal/template-contracts/dist/table-members.js +7 -2
  248. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
  249. package/dist/packages/internal/upload-formats/dist/heic.js +35 -0
  250. package/dist/packages/internal/upload-formats/dist/index.js +80 -0
  251. package/dist/packages/internal/upload-formats/dist/magic-bytes.js +293 -0
  252. package/dist/platform/paths.js +1 -0
  253. package/dist/platform/process.js +49 -1
  254. package/dist/rules/registry.js +27 -3
  255. package/dist/schema/fact.d.ts +2 -2
  256. package/dist/schema/facts-view.d.ts +1 -1
  257. package/dist/schema/section-props.d.ts +1 -1
  258. package/dist/schema/section-schema.d.ts +1 -1
  259. package/dist/schema/section-schema.js +1 -0
  260. package/dist/section/declare.d.ts +1 -1
  261. package/dist/section/discovery.js +6 -2
  262. package/dist/section/publish-shape.js +38 -0
  263. package/dist/section/section.d.ts +1 -1
  264. package/dist/template/define-template.d.ts +14 -4
  265. package/dist/template/define-template.js +2 -0
  266. package/dist/template/logic-shim.d.ts +1 -1
  267. package/dist/template/materialize.js +1 -1
  268. package/dist/template/running-copy.js +0 -1
  269. package/dist/template/section-reads.js +1 -1
  270. package/guide/reference/cli/INDEX.md +6 -5
  271. package/guide/reference/cli/build.md +10 -8
  272. package/guide/reference/cli/check.md +4 -2
  273. package/guide/reference/cli/dev.md +6 -2
  274. package/guide/reference/cli/install.md +41 -0
  275. package/guide/reference/cli/property-add.md +5 -4
  276. package/guide/reference/cli/property-list.md +2 -2
  277. package/guide/reference/cli/publish.md +5 -5
  278. package/guide/reference/cli/upgrade.md +1 -1
  279. package/guide/reference/rules/INDEX.md +8 -4
  280. package/package.json +14 -30
  281. package/dist/artifact/playground/client/assets/index-BcLGpWLR.js +0 -1266
  282. package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +0 -1
  283. package/dist/cli/build/artifact.js +0 -220
  284. package/dist/cli/build/captures.js +0 -48
  285. package/dist/cli/build/fixtures.js +0 -92
  286. package/dist/cli/capture/capture-browser.js +0 -37
  287. package/dist/cli/capture/capture.js +0 -115
  288. package/dist/cli/check/render/inputs.js +0 -60
  289. package/dist/cli/check/render/nav.js +0 -31
  290. package/dist/cli/dev/crop.js +0 -20
  291. package/dist/cli/dev/fixture-ladders.js +0 -96
  292. package/dist/cli/dev/hmr.js +0 -26
  293. package/dist/cli/dev/islands.js +0 -234
  294. package/dist/cli/dev/load-template.js +0 -52
  295. package/dist/cli/dev/vite.js +0 -114
  296. package/dist/cli/dev/workspace-reader.js +0 -249
  297. package/dist/cli/publish/freshness.js +0 -64
  298. package/dist/fixtures/brand.d.ts +0 -4
  299. package/dist/fixtures/brand.js +0 -8
  300. package/dist/fixtures/load.js +0 -159
  301. package/dist/fixtures/resolve.js +0 -392
  302. package/dist/fixtures.d.ts +0 -429
  303. package/dist/fixtures.js +0 -23
  304. package/dist/packages/internal/canvas-core/dist/island-host.js +0 -62
  305. package/dist/packages/internal/canvas-core/dist/island-shields.js +0 -30
  306. package/dist/playground/canvas-island-host.d.ts +0 -11
  307. package/dist/playground/canvas-island-host.js +0 -29
  308. package/dist/playground/canvas-markers.js +0 -14
  309. package/dist/playground/host/paths.js +0 -8
  310. package/dist/playground/layout.js +0 -17
  311. package/dist/playground/wire.js +0 -28
@@ -0,0 +1,309 @@
1
+ import { kindOfLink, kindOfMime, matchLinkProvider } from "../../../template-contracts/dist/slot-catalog.js";
2
+ import { MAGIC_PREFIX_BYTES, verifyMagicBytes } from "../../../upload-formats/dist/magic-bytes.js";
3
+ import { ACCEPTED_UPLOAD_SUMMARY, MAX_UPLOAD_BYTES, extensionOf, heicRefusal, isAcceptedUpload, normalizeMime } from "../../../upload-formats/dist/index.js";
4
+ import { HostRefusal } from "./env.js";
5
+ import { documentText, readDocument } from "./save.js";
6
+
7
+ //#region ../../internal/playground/dist/host/media-saves.js
8
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9
+ const FIXTURE_FILES = {
10
+ image: [
11
+ ".png",
12
+ ".jpg",
13
+ ".jpeg",
14
+ ".webp",
15
+ ".avif",
16
+ ".gif"
17
+ ],
18
+ video: [
19
+ ".mp4",
20
+ ".webm",
21
+ ".mov"
22
+ ],
23
+ document: [".pdf"]
24
+ };
25
+ const FIXTURE_FILE_EXTENSIONS = new Set(Object.values(FIXTURE_FILES).flat());
26
+ function fileKindOfExtension(ext) {
27
+ return Object.keys(FIXTURE_FILES).find((kind) => FIXTURE_FILES[kind].includes(ext.toLowerCase())) ?? null;
28
+ }
29
+ const FILE_LISTS = {
30
+ uploads: [
31
+ "image",
32
+ "video",
33
+ "document"
34
+ ],
35
+ property_media: ["image", "video"],
36
+ floor_plans: ["image"],
37
+ property_documents: [
38
+ "document",
39
+ "image",
40
+ "video"
41
+ ]
42
+ };
43
+ const LINK_LISTS = {
44
+ uploads: ["video", "tour"],
45
+ property_media: ["video", "tour"],
46
+ property_documents: ["video"]
47
+ };
48
+ const SORTED_LISTS = [
49
+ "property_media",
50
+ "floor_plans",
51
+ "property_documents"
52
+ ];
53
+ const ENTRY_FILES = [
54
+ "file",
55
+ "poster",
56
+ "preview"
57
+ ];
58
+ const ROW_FILES = [["contacts", [
59
+ "headshot",
60
+ "logo_dark",
61
+ "logo_light"
62
+ ]], ["comparables", ["photo"]]];
63
+ const bareList = (list) => list.replace(/^property\./, "");
64
+ const listOf = (value) => Array.isArray(value) ? value : [];
65
+ const idOf = (value) => isRecord(value) ? value["media"] ?? value["id"] : void 0;
66
+ const folderOf = (path) => path.slice(0, path.lastIndexOf("/") + 1);
67
+ function admitFile(upload, kinds, holder = "this list") {
68
+ const { name, type, bytes } = upload;
69
+ if (!isAcceptedUpload(name, type)) throw new HostRefusal(415, heicRefusal(name, type) ?? `Got '${name}' as '${type}'; expected ${"an image, a video, or a document (PDF, Word, Excel .xlsx, PowerPoint .pptx, CSV, or text)"}.`);
70
+ if (bytes.byteLength > 524288e3) throw new HostRefusal(413, `Got ${String(bytes.byteLength)} bytes; the cap is ${String(MAX_UPLOAD_BYTES)} bytes (500 MB).`);
71
+ const verdict = verifyMagicBytes(bytes.subarray(0, MAGIC_PREFIX_BYTES), normalizeMime(type));
72
+ if (!verdict.ok) throw new HostRefusal(415, verdict.detail);
73
+ const mediaKind = kindOfMime(type);
74
+ const kind = mediaKind === "tour" || mediaKind === null ? null : mediaKind;
75
+ if (kind === null || !FIXTURE_FILES[kind].includes(extensionOf(name))) throw new HostRefusal(415, `A fixture holds media files of these types: ${[...FIXTURE_FILE_EXTENSIONS].join(", ")}. '${name}' is not one; add it to the property by hand if a template needs it.`);
76
+ if (!kinds.includes(kind)) throw new HostRefusal(415, `Got ${kind === "image" ? "an" : "a"} ${kind}; ${holder} holds ${kinds.join(" or ")}.`);
77
+ return kind;
78
+ }
79
+ function freshId(target, property, stem, numberFirst) {
80
+ const taken = /* @__PURE__ */ new Set([...listOf(property["uploads"]).map(idOf), ...Object.keys(target.media)]);
81
+ let n = 1;
82
+ let id = numberFirst ? `${stem}-1` : stem;
83
+ while (taken.has(id)) id = `${stem}-${String(++n)}`;
84
+ return id;
85
+ }
86
+ function fileStem(name) {
87
+ const base = name.slice(Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\")) + 1);
88
+ const dot = base.lastIndexOf(".");
89
+ const stem = (dot > 0 ? base.slice(0, dot) : base).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
90
+ return stem === "" ? "upload" : stem;
91
+ }
92
+ function namedFiles(property) {
93
+ const named = /* @__PURE__ */ new Set();
94
+ for (const entry of listOf(property["uploads"])) {
95
+ if (!isRecord(entry)) continue;
96
+ for (const member of ENTRY_FILES) if (typeof entry[member] === "string") named.add(entry[member]);
97
+ }
98
+ for (const [table, members] of ROW_FILES) for (const row of listOf(property[table])) {
99
+ if (!isRecord(row)) continue;
100
+ for (const member of members) if (typeof row[member] === "string") named.add(row[member]);
101
+ }
102
+ return named;
103
+ }
104
+ async function freshFile(store, folder, property, id, ext, taken = /* @__PURE__ */ new Set()) {
105
+ const named = namedFiles(property);
106
+ for (let n = 1;; n++) {
107
+ const file = `media/${n === 1 ? id : `${id}-${String(n)}`}${ext}`;
108
+ if (!named.has(file) && !taken.has(file) && await store.readText(`${folder}${file}`) === null) return file;
109
+ }
110
+ }
111
+ const isOwnFile = (file) => !file.startsWith("/") && !file.split("/").includes("..");
112
+ function unnamedPropertyFiles(path, before, after) {
113
+ const still = namedFiles(after);
114
+ const folder = folderOf(path);
115
+ return [...namedFiles(before)].filter((file) => !still.has(file) && isOwnFile(file)).map((file) => ({
116
+ path: `${folder}${file.replace(/^\.\//, "")}`,
117
+ remove: true
118
+ }));
119
+ }
120
+ function withEntry(property, entry, list) {
121
+ const next = {
122
+ ...property,
123
+ uploads: [...listOf(property["uploads"]), entry]
124
+ };
125
+ if (list !== "uploads") next[list] = [...listOf(property[list]), { media: entry["id"] }];
126
+ return next;
127
+ }
128
+ async function uploadSave(into, store, upload) {
129
+ const { target } = upload;
130
+ if (!("list" in target)) throw new Error("uploadSave: a slot's own file and a row's image are saved by ./owned-saves.ts");
131
+ const list = bareList(target.list);
132
+ const kinds = FILE_LISTS[list];
133
+ if (kinds === void 0) throw new HostRefusal(400, `A file is uploaded into the uploads, the property's media, its floor plans or its documents, not "${target.list}".`);
134
+ const kind = admitFile(upload, kinds);
135
+ const { doc: property } = await readDocument(store, into.property);
136
+ const id = freshId(into, property, fileStem(upload.name), false);
137
+ const folder = folderOf(into.property);
138
+ const file = await freshFile(store, folder, property, id, extensionOf(upload.name));
139
+ const entry = fileEntry(id, kind, file);
140
+ return {
141
+ writes: [{
142
+ path: `${folder}${file}`,
143
+ bytes: upload.bytes
144
+ }, {
145
+ path: into.property,
146
+ text: documentText(withEntry(property, entry, list))
147
+ }],
148
+ media: id
149
+ };
150
+ }
151
+ function admitLink(url, kinds, holder = "this list") {
152
+ const kind = kindOfLink(url);
153
+ const provider = matchLinkProvider(url);
154
+ if (kind !== "video" && kind !== "tour" || provider === null) throw new HostRefusal(422, `'${url}' is no tour or video link this platform plays.`);
155
+ if (!kinds.includes(kind)) throw new HostRefusal(415, `Got a ${kind}; ${holder} holds ${kinds.length === 0 ? "no link" : kinds.join(" or ")}.`);
156
+ return {
157
+ kind,
158
+ provider
159
+ };
160
+ }
161
+ function linkEntry(id, url, { kind, provider }) {
162
+ return kind === "video" ? {
163
+ id,
164
+ kind,
165
+ source: "link",
166
+ url,
167
+ provider,
168
+ duration_ms: null
169
+ } : {
170
+ id,
171
+ kind,
172
+ url,
173
+ provider
174
+ };
175
+ }
176
+ function fileEntry(id, kind, file) {
177
+ return kind === "video" ? {
178
+ id,
179
+ kind,
180
+ source: "upload",
181
+ file,
182
+ duration_ms: null
183
+ } : {
184
+ id,
185
+ kind,
186
+ file
187
+ };
188
+ }
189
+ async function linkSave(target, store, request) {
190
+ const list = bareList(request.list);
191
+ const kinds = LINK_LISTS[list];
192
+ if (kinds === void 0) throw new HostRefusal(400, `A link is added to the uploads, the property's media or its documents, not to "${request.list}".`);
193
+ const admitted = admitLink(request.url, kinds);
194
+ const { doc: property } = await readDocument(store, target.property);
195
+ const id = freshId(target, property, "link", true);
196
+ const entry = linkEntry(id, request.url, admitted);
197
+ return {
198
+ writes: [{
199
+ path: target.property,
200
+ text: documentText(withEntry(property, entry, list))
201
+ }],
202
+ media: id
203
+ };
204
+ }
205
+ const PICKS_FROM = {
206
+ property_media: [
207
+ "hero",
208
+ "units.photos",
209
+ "commercial_spaces.photos"
210
+ ],
211
+ floor_plans: ["units.floor_plans", "commercial_spaces.floor_plans"],
212
+ property_documents: []
213
+ };
214
+ function withoutItem(property, id, lists) {
215
+ const next = { ...property };
216
+ for (const list of lists) next[list] = listOf(property[list]).filter((item) => idOf(item) !== id);
217
+ for (const pick of lists.flatMap((list) => PICKS_FROM[list])) {
218
+ if (pick === "hero") {
219
+ if (idOf(next["hero"]) === id) next["hero"] = null;
220
+ continue;
221
+ }
222
+ const [table, field] = pick.split(".");
223
+ if (!Array.isArray(next[table])) continue;
224
+ next[table] = next[table].map((row) => {
225
+ if (!isRecord(row) || !Array.isArray(row[field])) return row;
226
+ const items = row[field];
227
+ const kept = items.filter((item) => idOf(isRecord(item) && "image" in item ? item["image"] : item) !== id);
228
+ return kept.length === items.length ? row : {
229
+ ...row,
230
+ [field]: kept
231
+ };
232
+ });
233
+ }
234
+ return next;
235
+ }
236
+ async function removeSave(target, store, request) {
237
+ const list = bareList(request.list);
238
+ const id = request.media;
239
+ if (list !== "uploads" && !SORTED_LISTS.includes(list)) throw new HostRefusal(400, `An item is removed from the uploads, the property's media, its floor plans or its documents, not "${request.list}".`);
240
+ const { doc: property } = await readDocument(store, target.property);
241
+ const holds = (name) => listOf(property[name]).some((item) => idOf(item) === id);
242
+ if (!holds(list)) throw new HostRefusal(404, `The property's ${list} holds no media "${id}".`);
243
+ if (list !== "uploads") {
244
+ const next = withoutItem(property, id, [list]);
245
+ return { writes: [{
246
+ path: target.property,
247
+ text: documentText(next)
248
+ }] };
249
+ }
250
+ const entry = listOf(property["uploads"]).find((item) => idOf(item) === id);
251
+ const next = withoutItem({
252
+ ...property,
253
+ uploads: listOf(property["uploads"]).filter((item) => item !== entry)
254
+ }, id, SORTED_LISTS.filter(holds));
255
+ const stillNamed = namedFiles(next);
256
+ const folder = folderOf(target.property);
257
+ const removed = [];
258
+ for (const member of ENTRY_FILES) {
259
+ const file = isRecord(entry) ? entry[member] : void 0;
260
+ if (typeof file === "string" && !stillNamed.has(file) && isOwnFile(file)) removed.push({
261
+ path: `${folder}${file.replace(/^\.\//, "")}`,
262
+ remove: true
263
+ });
264
+ }
265
+ return { writes: [{
266
+ path: target.property,
267
+ text: documentText(next)
268
+ }, ...removed] };
269
+ }
270
+ function parseLibraryRequest(text) {
271
+ let body;
272
+ try {
273
+ body = JSON.parse(text);
274
+ } catch (err) {
275
+ throw new HostRefusal(400, `request body is not JSON: ${err instanceof Error ? err.message : String(err)}`);
276
+ }
277
+ if (!isRecord(body)) throw new HostRefusal(400, "A library change is a JSON object.");
278
+ const { property, fixture } = body;
279
+ if (body.kind === "link") {
280
+ if (typeof body.url !== "string") throw new HostRefusal(400, "A link carries the URL.");
281
+ if (typeof property === "string" && typeof body.list === "string") return {
282
+ kind: "link",
283
+ property,
284
+ list: body.list,
285
+ url: body.url
286
+ };
287
+ if (typeof fixture === "string" && typeof body.instance === "string" && typeof body.slot === "string") return {
288
+ kind: "link",
289
+ fixture,
290
+ instance: body.instance,
291
+ slot: body.slot,
292
+ url: body.url
293
+ };
294
+ throw new HostRefusal(400, "A link names where it lands: a property and its list, or a content fixture, an instance and its slot.");
295
+ }
296
+ if (body.kind === "remove") {
297
+ if (typeof property !== "string" || typeof body.list !== "string" || typeof body.media !== "string") throw new HostRefusal(400, "A removal names a property, a list and the media to remove from it.");
298
+ return {
299
+ kind: "remove",
300
+ property,
301
+ list: body.list,
302
+ media: body.media
303
+ };
304
+ }
305
+ throw new HostRefusal(400, "A library change's kind is \"link\" or \"remove\".");
306
+ }
307
+
308
+ //#endregion
309
+ export { FIXTURE_FILE_EXTENSIONS, admitFile, admitLink, fileEntry, fileKindOfExtension, fileStem, folderOf, freshFile, isOwnFile, linkEntry, linkSave, namedFiles, parseLibraryRequest, removeSave, unnamedPropertyFiles, uploadSave };
@@ -1,10 +1,11 @@
1
- import { mediaRecords } from "../packages/internal/template-contracts/dist/registry-facts.js";
2
- import { cropKeyOwner } from "../packages/internal/media-resolution/dist/crop-key.js";
3
- import { recordsOf } from "../packages/internal/media-resolution/dist/records.js";
4
- import { resolveSlotValue } from "../packages/internal/media-resolution/dist/slot.js";
5
- import "../packages/internal/media-resolution/dist/index.js";
1
+ import { mediaRecords } from "../../../template-contracts/dist/registry-facts.js";
2
+ import { contentTypeFor, mediaPath } from "../../../page-render/dist/addresses.js";
3
+ import { cropKeyOwner } from "../../../media-resolution/dist/crop-key.js";
4
+ import { recordsOf } from "../../../media-resolution/dist/records.js";
5
+ import "../../../media-resolution/dist/index.js";
6
+ import "../../../page-render/dist/index.js";
6
7
 
7
- //#region src/fixtures/media-store.ts
8
+ //#region ../../internal/playground/dist/host/media-store.js
8
9
  const clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
9
10
  function cropRectOf(value) {
10
11
  if (typeof value !== "object" || value === null) return null;
@@ -27,6 +28,51 @@ function cropRectOf(value) {
27
28
  return rect.nx === 0 && rect.ny === 0 && rect.nw === 1 && rect.nh === 1 ? null : rect;
28
29
  }
29
30
  const CROP_KEY = /^processed\/crops\/([^/]+)\/(-?[\d.e-]+)_(-?[\d.e-]+)_(-?[\d.e-]+)_(-?[\d.e-]+)$/;
31
+ function fixtureCropKey(id, rect) {
32
+ return `processed/crops/${id}/${rect.nx}_${rect.ny}_${rect.nw}_${rect.nh}`;
33
+ }
34
+ const storedCropOf = (rect) => ({
35
+ x: rect.nx,
36
+ y: rect.ny,
37
+ width: rect.nw,
38
+ height: rect.nh
39
+ });
40
+ function cropRectOfStored(crop) {
41
+ if (typeof crop !== "object" || crop === null) return null;
42
+ const { x, y, width, height } = crop;
43
+ return cropRectOf({
44
+ nx: x,
45
+ ny: y,
46
+ nw: width,
47
+ nh: height
48
+ });
49
+ }
50
+ function fixtureCut(id, rect) {
51
+ return {
52
+ key: fixtureCropKey(id, rect),
53
+ mime: null,
54
+ width: null,
55
+ height: null,
56
+ bytes: null,
57
+ over: {
58
+ crop: storedCropOf(rect),
59
+ options: {}
60
+ }
61
+ };
62
+ }
63
+ function croppedImageCopy(id, crop, mobile) {
64
+ return {
65
+ file: id,
66
+ ...crop === null ? {} : {
67
+ crop: storedCropOf(crop),
68
+ renditions: { crop: fixtureCut(id, crop) }
69
+ },
70
+ ...mobile === null ? {} : { mobile: {
71
+ crop: storedCropOf(mobile),
72
+ renditions: { crop: fixtureCut(id, mobile) }
73
+ } }
74
+ };
75
+ }
30
76
  function cropOfKey(key) {
31
77
  const match = CROP_KEY.exec(key);
32
78
  if (match === null || cropKeyOwner(key) === null) return null;
@@ -47,20 +93,37 @@ function keyOf(file) {
47
93
  }
48
94
  function fixtureMediaStore(media, serving = {}) {
49
95
  const serve = serving.url ?? ((path) => path);
96
+ const { content } = serving;
97
+ const addressed = (key, url, contentType, master) => {
98
+ const path = content === void 0 || contentType === null ? null : mediaPath(key, contentType, null, content.hash);
99
+ if (path === null) return url;
100
+ const address = `${content.contentBase}${path}`;
101
+ content.listed(address, {
102
+ url,
103
+ contentType,
104
+ ...master === void 0 ? {} : { master }
105
+ });
106
+ return address;
107
+ };
50
108
  const files = /* @__PURE__ */ new Map();
51
109
  for (const entry of media.values()) for (const file of [entry.file, entry.posterFile]) {
52
110
  const key = keyOf(file);
53
111
  if (key !== null) files.set(key, file);
54
112
  }
55
- const fileUrl = (key) => files.has(key) ? serve(key) : key;
113
+ const fileUrl = (key) => files.has(key) ? addressed(key, serve(key), contentTypeFor(key)) : key;
56
114
  const responsiveOf = (key) => {
57
115
  const file = key === null ? void 0 : files.get(key);
58
- if (file === void 0 || typeof file === "string" || file.responsive === null) return null;
116
+ if (key === null || file === void 0 || typeof file === "string" || file.responsive === null) return null;
117
+ const masterType = contentTypeFor(key);
118
+ const master = masterType === null ? void 0 : {
119
+ url: serve(key),
120
+ contentType: masterType
121
+ };
59
122
  return {
60
123
  ...file.responsive,
61
124
  sources: file.responsive.sources.map((source) => ({
62
125
  ...source,
63
- srcset: serveSrcset(source.srcset, serve)
126
+ srcset: serveSrcset(source.srcset, (rung) => addressed(rung, serve(rung), contentTypeFor(rung, source.type), master))
64
127
  }))
65
128
  };
66
129
  };
@@ -70,7 +133,7 @@ function fixtureMediaStore(media, serving = {}) {
70
133
  if (crop === null) return Promise.resolve(fileUrl(key));
71
134
  const source = keyOf(media.get(crop.id)?.file);
72
135
  if (source === null) return Promise.reject(/* @__PURE__ */ new Error(`no image "${crop.id}" to crop`));
73
- return Promise.resolve(serving.crop === void 0 ? serve(source) : serving.crop(source, crop.rect));
136
+ return Promise.resolve(addressed(key, serving.crop === void 0 ? serve(source) : serving.crop(source, crop.rect), contentTypeFor(source)));
74
137
  },
75
138
  fileUrl: (key) => Promise.resolve(fileUrl(key)),
76
139
  ladder: () => Promise.resolve({ responsiveFor: (key) => Promise.resolve(responsiveOf(key)) })
@@ -82,8 +145,11 @@ function serveSrcset(srcset, serve) {
82
145
  return [serve(url), ...descriptors].join(" ");
83
146
  }).join(", ");
84
147
  }
85
- function fixtureMediaRecords(facts, media, sizeOf) {
86
- const records = recordsOf(facts === null ? null : mediaRecords(facts));
148
+ function fixtureMediaRecords(facts, media, sizeOf, owned) {
149
+ const records = recordsOf({
150
+ ...facts === null ? {} : mediaRecords(facts),
151
+ ...owned
152
+ });
87
153
  const sized = /* @__PURE__ */ new Map();
88
154
  for (const entry of media.values()) {
89
155
  const key = keyOf(entry.file);
@@ -97,19 +163,6 @@ function fixtureMediaRecords(facts, media, sizeOf) {
97
163
  }];
98
164
  }));
99
165
  }
100
- async function resolveFixtureSlots(input) {
101
- const ctx = {
102
- store: input.store,
103
- records: input.records,
104
- resolvePoi: (value) => value
105
- };
106
- const out = {};
107
- for (const [id, value] of Object.entries(input.slots)) {
108
- const def = input.declared[id];
109
- out[id] = await resolveSlotValue(value, def, ctx);
110
- }
111
- return out;
112
- }
113
166
 
114
167
  //#endregion
115
- export { cropRectOf, fixtureMediaRecords, fixtureMediaStore, resolveFixtureSlots };
168
+ export { cropRectOf, cropRectOfStored, croppedImageCopy, fixtureCropKey, fixtureMediaRecords, fixtureMediaStore };
@@ -0,0 +1,9 @@
1
+ //#region ../../internal/playground/dist/host/overridable.js
2
+ function isOverridable(def) {
3
+ if (def.type === "row" || def.type === "object") return false;
4
+ if (def.type === "list" && (def.element?.type === "object" || def.element?.type === "row")) return false;
5
+ return def.source !== void 0 && def.source.kind !== "element" && def.source.kind !== "authored";
6
+ }
7
+
8
+ //#endregion
9
+ export { isOverridable };
@@ -0,0 +1,203 @@
1
+ import { declaredKinds } from "../../../template-contracts/dist/slot-catalog.js";
2
+ import { extensionOf } from "../../../upload-formats/dist/index.js";
3
+ import { HostRefusal } from "./env.js";
4
+ import { ownedRowFieldAt } from "./everywhere-saves.js";
5
+ import { contentSlotOfferAt, ownedRowMemberOf } from "../../../template-contracts/dist/media-offer.js";
6
+ import { documentText, readDocument } from "./save.js";
7
+ import { admitFile, admitLink, fileEntry, fileStem, folderOf, freshFile, isOwnFile, linkEntry } from "./media-saves.js";
8
+
9
+ //#region ../../internal/playground/dist/host/owned-saves.js
10
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
11
+ const listOf = (value) => Array.isArray(value) ? value : [];
12
+ function placedInstance(template, instance) {
13
+ const placed = template.instances.find((i) => i.instanceId === instance);
14
+ if (placed === void 0) throw new HostRefusal(422, `The composition places no instance "${instance}".`);
15
+ return placed;
16
+ }
17
+ function ownedKinds(template, target) {
18
+ const placed = placedInstance(template, target.instance);
19
+ const [first = "", ...rest] = target.slot.split(".");
20
+ let def = placed.sectionSchema.slots[first];
21
+ const along = [];
22
+ for (const field of rest) {
23
+ if (def === void 0) break;
24
+ along.push(def);
25
+ const holder = def.type === "list" ? def.element : def;
26
+ def = holder?.type === "object" ? holder.fields?.[field] : void 0;
27
+ }
28
+ if (def === void 0) throw new HostRefusal(422, `Section "${placed.section}" declares no slot "${target.slot}".`);
29
+ along.push(def);
30
+ const member = ownedRowMemberOf(placed.sectionSchema.slots, target.slot, def);
31
+ if (member !== null) return [member.kind];
32
+ const media = def.type === "list" && def.element !== void 0 ? def.element : def;
33
+ along.push(media);
34
+ const kinds = declaredKinds(media);
35
+ const picks = along.some((d) => typeof d.from === "string" || Array.isArray(d.from) || d.source !== void 0 && d.source.kind !== "authored");
36
+ if (kinds.length === 0 || picks) throw new HostRefusal(422, `"${target.slot}" of "${target.instance}" does not own its media: it ${kinds.length === 0 ? "holds no media" : "picks it"}.`);
37
+ return kinds;
38
+ }
39
+ function adoptedMemberOf(template, target) {
40
+ const placed = placedInstance(template, target.instance);
41
+ const def = contentSlotOfferAt(placed.sectionSchema.slots, target.slot)?.declaration;
42
+ const member = def === void 0 ? null : ownedRowMemberOf(placed.sectionSchema.slots, target.slot, def);
43
+ if (member === null) throw new HostRefusal(400, `"${target.slot}" of "${target.instance}" reads no row's own media, so it has nothing to adopt.`);
44
+ return member;
45
+ }
46
+ function freshOwnedId(fixture, doc, stem) {
47
+ const taken = /* @__PURE__ */ new Set([...Object.keys(fixture.media), ...listOf(doc["files"]).map((entry) => isRecord(entry) ? entry["id"] : void 0)]);
48
+ const base = `${fixture.id}-${stem}`;
49
+ let id = base;
50
+ for (let n = 2; taken.has(id); n++) id = `${base}-${String(n)}`;
51
+ return id;
52
+ }
53
+ const ownFolder = (fixture) => `${fixture.id}/media/`;
54
+ async function freshOwnedFile(store, fixture, doc, id, ext) {
55
+ const named = new Set(listOf(doc["files"]).flatMap((entry) => isRecord(entry) && typeof entry["file"] === "string" ? [entry["file"]] : []));
56
+ for (let n = 1;; n++) {
57
+ const file = `${ownFolder(fixture)}${n === 1 ? id : `${id}-${String(n)}`}${ext}`;
58
+ if (!named.has(file) && await store.readText(`${folderOf(fixture.file)}${file}`) === null) return file;
59
+ }
60
+ }
61
+ const withFile = (doc, entry) => ({
62
+ ...doc,
63
+ files: [...listOf(doc["files"]), entry]
64
+ });
65
+ async function ownedUploadSave(template, fixture, store, upload) {
66
+ const kind = admitFile(upload, ownedKinds(template, upload.target).filter((kind) => kind !== "tour"), "this slot");
67
+ const { doc } = await readDocument(store, fixture.file);
68
+ const id = freshOwnedId(fixture, doc, fileStem(upload.name));
69
+ const file = await freshOwnedFile(store, fixture, doc, id, extensionOf(upload.name));
70
+ return {
71
+ writes: [{
72
+ path: `${folderOf(fixture.file)}${file}`,
73
+ bytes: upload.bytes
74
+ }, {
75
+ path: fixture.file,
76
+ text: documentText(withFile(doc, fileEntry(id, kind, file)))
77
+ }],
78
+ media: id
79
+ };
80
+ }
81
+ async function stagedUploadSave(fixture, store, upload) {
82
+ const { doc: property } = await readDocument(store, fixture.property);
83
+ const field = ownedRowFieldAt(property, upload.target.owner);
84
+ const kind = admitFile(upload, field.kind === "tour" ? [] : [field.kind], "this field");
85
+ const { doc } = await readDocument(store, fixture.file);
86
+ const id = freshOwnedId(fixture, doc, fileStem(upload.name));
87
+ const file = await freshOwnedFile(store, fixture, doc, id, extensionOf(upload.name));
88
+ return {
89
+ writes: [{
90
+ path: `${folderOf(fixture.file)}${file}`,
91
+ bytes: upload.bytes
92
+ }, {
93
+ path: fixture.file,
94
+ text: documentText(withFile(doc, fileEntry(id, kind, file)))
95
+ }],
96
+ media: id
97
+ };
98
+ }
99
+ async function stagedCommits(fixture, store, property, ops) {
100
+ const ids = new Set(ops.flatMap((op) => op.op === "commit_media" || op.op === "adopt_media" ? [op.media_id] : []));
101
+ if (ids.size === 0) return null;
102
+ const { doc } = await readDocument(store, fixture.file);
103
+ const folder = folderOf(fixture.property);
104
+ const staged = /* @__PURE__ */ new Map();
105
+ const taken = /* @__PURE__ */ new Set();
106
+ for (const entry of listOf(doc["files"])) {
107
+ if (!isRecord(entry) || typeof entry["id"] !== "string" || !ids.has(entry["id"])) continue;
108
+ const { id, kind, file: own } = entry;
109
+ if (typeof kind !== "string" || typeof own !== "string" || !isOwnFile(own)) continue;
110
+ const file = await freshFile(store, folder, property, id, extensionOf(own), taken);
111
+ taken.add(file);
112
+ staged.set(id, {
113
+ kind,
114
+ file,
115
+ from: `${folderOf(fixture.file)}${own.replace(/^\.\//, "")}`
116
+ });
117
+ }
118
+ return {
119
+ staged,
120
+ doc,
121
+ settle(committed) {
122
+ const kept = listOf(doc["files"]).filter((entry) => !(isRecord(entry) && typeof entry["id"] === "string" && committed.has(entry["id"])));
123
+ const next = { ...doc };
124
+ if (kept.length === 0) delete next["files"];
125
+ else next["files"] = kept;
126
+ return {
127
+ doc: next,
128
+ moves: [...committed].flatMap((id) => {
129
+ const file = staged.get(id);
130
+ return file === void 0 ? [] : [{
131
+ path: `${folder}${file.file}`,
132
+ from: file.from
133
+ }];
134
+ })
135
+ };
136
+ }
137
+ };
138
+ }
139
+ async function ownedLinkSave(template, fixture, store, request) {
140
+ const kinds = ownedKinds(template, request).filter((kind) => kind === "video" || kind === "tour");
141
+ const admitted = admitLink(request.url, kinds, "this slot");
142
+ const { doc } = await readDocument(store, fixture.file);
143
+ const id = freshOwnedId(fixture, doc, "link");
144
+ return {
145
+ writes: [{
146
+ path: fixture.file,
147
+ text: documentText(withFile(doc, linkEntry(id, request.url, admitted)))
148
+ }],
149
+ media: id
150
+ };
151
+ }
152
+ function namedMedia(content) {
153
+ const named = /* @__PURE__ */ new Set();
154
+ const walk = (node) => {
155
+ if (Array.isArray(node)) for (const member of node) walk(member);
156
+ else if (isRecord(node)) {
157
+ if (typeof node["media"] === "string") named.add(node["media"]);
158
+ for (const member of Object.values(node)) walk(member);
159
+ }
160
+ };
161
+ walk(content);
162
+ return named;
163
+ }
164
+ const ENTRY_FILES = [
165
+ "file",
166
+ "poster",
167
+ "preview"
168
+ ];
169
+ function withoutUnnamedFiles(file, before, after) {
170
+ const entries = listOf(after["files"]);
171
+ if (entries.length === 0) return {
172
+ doc: after,
173
+ removed: []
174
+ };
175
+ const was = namedMedia(before["content"]);
176
+ const now = namedMedia(after["content"]);
177
+ const dropped = (entry) => isRecord(entry) && typeof entry["id"] === "string" && was.has(entry["id"]) && !now.has(entry["id"]);
178
+ if (!entries.some(dropped)) return {
179
+ doc: after,
180
+ removed: []
181
+ };
182
+ const kept = entries.filter((entry) => !dropped(entry));
183
+ const keptFiles = new Set(kept.flatMap((entry) => isRecord(entry) ? ENTRY_FILES.map((member) => entry[member]) : []));
184
+ const removed = [];
185
+ for (const entry of entries.filter(dropped)) for (const member of ENTRY_FILES) {
186
+ const path = entry[member];
187
+ if (typeof path !== "string" || keptFiles.has(path) || !isOwnFile(path)) continue;
188
+ removed.push({
189
+ path: `${folderOf(file)}${path.replace(/^\.\//, "")}`,
190
+ remove: true
191
+ });
192
+ }
193
+ const doc = { ...after };
194
+ if (kept.length === 0) delete doc["files"];
195
+ else doc["files"] = kept;
196
+ return {
197
+ doc,
198
+ removed
199
+ };
200
+ }
201
+
202
+ //#endregion
203
+ export { adoptedMemberOf, ownedLinkSave, ownedUploadSave, stagedCommits, stagedUploadSave, withoutUnnamedFiles };
@@ -1,4 +1,4 @@
1
- //#region src/playground/host/page-state.ts
1
+ //#region ../../internal/playground/dist/host/page-state.js
2
2
  function pageEnabled(fixture, pageId) {
3
3
  return fixture.pages?.[pageId]?.enabled !== false;
4
4
  }