@jam-overture/loom 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (401) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +743 -0
  3. package/dist/catalogue.d.ts +70 -0
  4. package/dist/catalogue.js +88 -0
  5. package/dist/cli/args.d.ts +17 -0
  6. package/dist/cli/args.js +83 -0
  7. package/dist/cli/filesystem.d.ts +15 -0
  8. package/dist/cli/filesystem.js +31 -0
  9. package/dist/cli/index.d.ts +12 -0
  10. package/dist/cli/index.js +12 -0
  11. package/dist/cli/main.d.ts +3 -0
  12. package/dist/cli/main.js +30 -0
  13. package/dist/cli/namespace.d.ts +40 -0
  14. package/dist/cli/namespace.js +40 -0
  15. package/dist/cli/plan.d.ts +84 -0
  16. package/dist/cli/plan.js +113 -0
  17. package/dist/cli/run.d.ts +17 -0
  18. package/dist/cli/run.js +75 -0
  19. package/dist/cli/templates.d.ts +43 -0
  20. package/dist/cli/templates.js +134 -0
  21. package/dist/closed-set.d.ts +34 -0
  22. package/dist/closed-set.js +34 -0
  23. package/dist/data/adapter.d.ts +123 -0
  24. package/dist/data/adapter.js +91 -0
  25. package/dist/data/binding.d.ts +48 -0
  26. package/dist/data/binding.js +39 -0
  27. package/dist/data/catalogue.d.ts +26 -0
  28. package/dist/data/catalogue.js +6 -0
  29. package/dist/data/index.d.ts +14 -0
  30. package/dist/data/index.js +14 -0
  31. package/dist/data/plan.d.ts +58 -0
  32. package/dist/data/plan.js +0 -0
  33. package/dist/data/resolution.d.ts +91 -0
  34. package/dist/data/resolution.js +96 -0
  35. package/dist/data/resolve.d.ts +46 -0
  36. package/dist/data/resolve.js +37 -0
  37. package/dist/data/source.d.ts +40 -0
  38. package/dist/data/source.js +45 -0
  39. package/dist/deadline.d.ts +57 -0
  40. package/dist/deadline.js +78 -0
  41. package/dist/frame/catalogue.d.ts +24 -0
  42. package/dist/frame/catalogue.js +5 -0
  43. package/dist/frame/index.d.ts +12 -0
  44. package/dist/frame/index.js +12 -0
  45. package/dist/frame/origin.d.ts +87 -0
  46. package/dist/frame/origin.js +114 -0
  47. package/dist/frame/resolution.d.ts +85 -0
  48. package/dist/frame/resolution.js +79 -0
  49. package/dist/grammar.d.ts +26 -0
  50. package/dist/grammar.js +28 -0
  51. package/dist/ids.d.ts +57 -0
  52. package/dist/ids.js +104 -0
  53. package/dist/index.d.ts +26 -0
  54. package/dist/index.js +26 -0
  55. package/dist/interactivity.d.ts +50 -0
  56. package/dist/interactivity.js +22 -0
  57. package/dist/interpretation/anthropic.d.ts +22 -0
  58. package/dist/interpretation/anthropic.js +76 -0
  59. package/dist/interpretation/client.d.ts +83 -0
  60. package/dist/interpretation/client.js +2 -0
  61. package/dist/interpretation/draft.d.ts +234 -0
  62. package/dist/interpretation/draft.js +84 -0
  63. package/dist/interpretation/index.d.ts +15 -0
  64. package/dist/interpretation/index.js +15 -0
  65. package/dist/interpretation/interpreter.d.ts +62 -0
  66. package/dist/interpretation/interpreter.js +151 -0
  67. package/dist/interpretation/materialize.d.ts +42 -0
  68. package/dist/interpretation/materialize.js +107 -0
  69. package/dist/interpretation/prompt.d.ts +229 -0
  70. package/dist/interpretation/prompt.js +285 -0
  71. package/dist/interpretation/render.d.ts +76 -0
  72. package/dist/interpretation/render.js +272 -0
  73. package/dist/interpretation/schema.d.ts +49 -0
  74. package/dist/interpretation/schema.js +131 -0
  75. package/dist/json.d.ts +35 -0
  76. package/dist/json.js +11 -0
  77. package/dist/paging.d.ts +60 -0
  78. package/dist/paging.js +49 -0
  79. package/dist/primitive-type.d.ts +32 -0
  80. package/dist/primitive-type.js +39 -0
  81. package/dist/render/addressing.d.ts +59 -0
  82. package/dist/render/addressing.js +60 -0
  83. package/dist/render/anchor.d.ts +105 -0
  84. package/dist/render/anchor.js +84 -0
  85. package/dist/render/behaviour-adjust.d.ts +62 -0
  86. package/dist/render/behaviour-adjust.js +78 -0
  87. package/dist/render/behaviour-copy.d.ts +53 -0
  88. package/dist/render/behaviour-copy.js +75 -0
  89. package/dist/render/behaviour-disclose.d.ts +74 -0
  90. package/dist/render/behaviour-disclose.js +77 -0
  91. package/dist/render/behaviour-present.d.ts +123 -0
  92. package/dist/render/behaviour-present.js +173 -0
  93. package/dist/render/behaviour.d.ts +243 -0
  94. package/dist/render/behaviour.js +284 -0
  95. package/dist/render/control.d.ts +81 -0
  96. package/dist/render/control.js +80 -0
  97. package/dist/render/decorative.d.ts +62 -0
  98. package/dist/render/decorative.js +2 -0
  99. package/dist/render/diagnostics.d.ts +260 -0
  100. package/dist/render/diagnostics.js +61 -0
  101. package/dist/render/disclosed.d.ts +37 -0
  102. package/dist/render/disclosed.js +37 -0
  103. package/dist/render/editable.d.ts +34 -0
  104. package/dist/render/editable.js +35 -0
  105. package/dist/render/frame.d.ts +42 -0
  106. package/dist/render/frame.js +31 -0
  107. package/dist/render/index.d.ts +35 -0
  108. package/dist/render/index.js +35 -0
  109. package/dist/render/inline-variables.d.ts +77 -0
  110. package/dist/render/inline-variables.js +220 -0
  111. package/dist/render/presented.d.ts +82 -0
  112. package/dist/render/presented.js +82 -0
  113. package/dist/render/primitive.d.ts +228 -0
  114. package/dist/render/primitive.js +36 -0
  115. package/dist/render/props.d.ts +48 -0
  116. package/dist/render/props.js +2 -0
  117. package/dist/render/reads.d.ts +73 -0
  118. package/dist/render/reads.js +45 -0
  119. package/dist/render/render.d.ts +164 -0
  120. package/dist/render/render.js +571 -0
  121. package/dist/render/request.d.ts +111 -0
  122. package/dist/render/request.js +60 -0
  123. package/dist/render/text.d.ts +91 -0
  124. package/dist/render/text.js +44 -0
  125. package/dist/render/theme.d.ts +61 -0
  126. package/dist/render/theme.js +52 -0
  127. package/dist/reserved-props.d.ts +35 -0
  128. package/dist/reserved-props.js +45 -0
  129. package/dist/result.d.ts +27 -0
  130. package/dist/result.js +30 -0
  131. package/dist/role.d.ts +71 -0
  132. package/dist/role.js +22 -0
  133. package/dist/runtime/analysis.d.ts +149 -0
  134. package/dist/runtime/analysis.js +187 -0
  135. package/dist/runtime/assessment.d.ts +35 -0
  136. package/dist/runtime/assessment.js +13 -0
  137. package/dist/runtime/disposition.d.ts +102 -0
  138. package/dist/runtime/disposition.js +59 -0
  139. package/dist/runtime/events.d.ts +187 -0
  140. package/dist/runtime/events.js +7 -0
  141. package/dist/runtime/gate.d.ts +43 -0
  142. package/dist/runtime/gate.js +169 -0
  143. package/dist/runtime/index.d.ts +27 -0
  144. package/dist/runtime/index.js +27 -0
  145. package/dist/runtime/intent.d.ts +60 -0
  146. package/dist/runtime/intent.js +36 -0
  147. package/dist/runtime/interpreter.d.ts +117 -0
  148. package/dist/runtime/interpreter.js +46 -0
  149. package/dist/runtime/inverse-interpreter.d.ts +90 -0
  150. package/dist/runtime/inverse-interpreter.js +56 -0
  151. package/dist/runtime/inverse.d.ts +87 -0
  152. package/dist/runtime/inverse.js +48 -0
  153. package/dist/runtime/narration.d.ts +24 -0
  154. package/dist/runtime/narration.js +36 -0
  155. package/dist/runtime/nesting.d.ts +31 -0
  156. package/dist/runtime/nesting.js +46 -0
  157. package/dist/runtime/pipeline.d.ts +124 -0
  158. package/dist/runtime/pipeline.js +178 -0
  159. package/dist/runtime/policy-fingerprint.d.ts +29 -0
  160. package/dist/runtime/policy-fingerprint.js +119 -0
  161. package/dist/runtime/policy-source.d.ts +42 -0
  162. package/dist/runtime/policy-source.js +8 -0
  163. package/dist/runtime/policy.d.ts +156 -0
  164. package/dist/runtime/policy.js +107 -0
  165. package/dist/runtime/proposal.d.ts +423 -0
  166. package/dist/runtime/proposal.js +109 -0
  167. package/dist/runtime/redirection.d.ts +53 -0
  168. package/dist/runtime/redirection.js +38 -0
  169. package/dist/runtime/repointing.d.ts +71 -0
  170. package/dist/runtime/repointing.js +0 -0
  171. package/dist/runtime/reversibility.d.ts +36 -0
  172. package/dist/runtime/reversibility.js +39 -0
  173. package/dist/runtime/stake-level.d.ts +33 -0
  174. package/dist/runtime/stake-level.js +58 -0
  175. package/dist/runtime/stakes.d.ts +47 -0
  176. package/dist/runtime/stakes.js +305 -0
  177. package/dist/runtime/vocabulary.d.ts +122 -0
  178. package/dist/runtime/vocabulary.js +87 -0
  179. package/dist/sdk/audit.d.ts +195 -0
  180. package/dist/sdk/audit.js +128 -0
  181. package/dist/sdk/catalogue.d.ts +37 -0
  182. package/dist/sdk/catalogue.js +16 -0
  183. package/dist/sdk/conformance.d.ts +342 -0
  184. package/dist/sdk/conformance.js +494 -0
  185. package/dist/sdk/copy.d.ts +105 -0
  186. package/dist/sdk/copy.js +90 -0
  187. package/dist/sdk/definition.d.ts +242 -0
  188. package/dist/sdk/definition.js +64 -0
  189. package/dist/sdk/index.d.ts +19 -0
  190. package/dist/sdk/index.js +19 -0
  191. package/dist/sdk/interactivity.d.ts +29 -0
  192. package/dist/sdk/interactivity.js +34 -0
  193. package/dist/sdk/pairings.d.ts +124 -0
  194. package/dist/sdk/pairings.js +81 -0
  195. package/dist/sdk/registry.d.ts +162 -0
  196. package/dist/sdk/registry.js +329 -0
  197. package/dist/sdk/selection.d.ts +46 -0
  198. package/dist/sdk/selection.js +24 -0
  199. package/dist/sdk/text.d.ts +100 -0
  200. package/dist/sdk/text.js +105 -0
  201. package/dist/sdk/vocabulary.d.ts +39 -0
  202. package/dist/sdk/vocabulary.js +36 -0
  203. package/dist/signals/broadcast.d.ts +134 -0
  204. package/dist/signals/broadcast.js +451 -0
  205. package/dist/signals/collect.d.ts +184 -0
  206. package/dist/signals/collect.js +196 -0
  207. package/dist/signals/deliver.d.ts +64 -0
  208. package/dist/signals/deliver.js +85 -0
  209. package/dist/signals/fold.d.ts +112 -0
  210. package/dist/signals/fold.js +76 -0
  211. package/dist/signals/index.d.ts +31 -0
  212. package/dist/signals/index.js +31 -0
  213. package/dist/signals/ingest.d.ts +51 -0
  214. package/dist/signals/ingest.js +70 -0
  215. package/dist/signals/intake.d.ts +149 -0
  216. package/dist/signals/intake.js +154 -0
  217. package/dist/signals/journal.d.ts +94 -0
  218. package/dist/signals/journal.js +11 -0
  219. package/dist/signals/kinds.d.ts +22 -0
  220. package/dist/signals/kinds.js +22 -0
  221. package/dist/signals/ledger.d.ts +46 -0
  222. package/dist/signals/ledger.js +81 -0
  223. package/dist/signals/memory.d.ts +17 -0
  224. package/dist/signals/memory.js +99 -0
  225. package/dist/signals/migrate.d.ts +27 -0
  226. package/dist/signals/migrate.js +78 -0
  227. package/dist/signals/postgres.d.ts +7 -0
  228. package/dist/signals/postgres.js +295 -0
  229. package/dist/signals/rollup.d.ts +142 -0
  230. package/dist/signals/rollup.js +0 -0
  231. package/dist/signals/schema.d.ts +534 -0
  232. package/dist/signals/schema.js +92 -0
  233. package/dist/signals/signal.d.ts +381 -0
  234. package/dist/signals/signal.js +150 -0
  235. package/dist/signals/tally.d.ts +70 -0
  236. package/dist/signals/tally.js +2 -0
  237. package/dist/signals/view.d.ts +51 -0
  238. package/dist/signals/view.js +54 -0
  239. package/dist/store/attribution.d.ts +125 -0
  240. package/dist/store/attribution.js +116 -0
  241. package/dist/store/database.d.ts +14 -0
  242. package/dist/store/database.js +2 -0
  243. package/dist/store/driver.d.ts +29 -0
  244. package/dist/store/driver.js +39 -0
  245. package/dist/store/errors.d.ts +56 -0
  246. package/dist/store/errors.js +37 -0
  247. package/dist/store/index.d.ts +16 -0
  248. package/dist/store/index.js +16 -0
  249. package/dist/store/memory.d.ts +3 -0
  250. package/dist/store/memory.js +115 -0
  251. package/dist/store/migrate.d.ts +54 -0
  252. package/dist/store/migrate.js +122 -0
  253. package/dist/store/postgres-holds.d.ts +4 -0
  254. package/dist/store/postgres-holds.js +192 -0
  255. package/dist/store/postgres.d.ts +8 -0
  256. package/dist/store/postgres.js +262 -0
  257. package/dist/store/replay.d.ts +94 -0
  258. package/dist/store/replay.js +82 -0
  259. package/dist/store/revert.d.ts +116 -0
  260. package/dist/store/revert.js +243 -0
  261. package/dist/store/schema.d.ts +371 -0
  262. package/dist/store/schema.js +78 -0
  263. package/dist/store/source.d.ts +23 -0
  264. package/dist/store/source.js +37 -0
  265. package/dist/store/store.d.ts +231 -0
  266. package/dist/store/store.js +52 -0
  267. package/dist/store/undone.d.ts +18 -0
  268. package/dist/store/undone.js +89 -0
  269. package/dist/submit/catalogue.d.ts +20 -0
  270. package/dist/submit/catalogue.js +5 -0
  271. package/dist/submit/declaration.d.ts +39 -0
  272. package/dist/submit/declaration.js +30 -0
  273. package/dist/submit/endpoint.d.ts +131 -0
  274. package/dist/submit/endpoint.js +160 -0
  275. package/dist/submit/index.d.ts +13 -0
  276. package/dist/submit/index.js +13 -0
  277. package/dist/submit/plan.d.ts +49 -0
  278. package/dist/submit/plan.js +47 -0
  279. package/dist/submit/resolution.d.ts +61 -0
  280. package/dist/submit/resolution.js +64 -0
  281. package/dist/submit/resolve.d.ts +45 -0
  282. package/dist/submit/resolve.js +36 -0
  283. package/dist/telemetry/calibration.d.ts +132 -0
  284. package/dist/telemetry/calibration.js +151 -0
  285. package/dist/telemetry/episode.d.ts +140 -0
  286. package/dist/telemetry/episode.js +272 -0
  287. package/dist/telemetry/event.d.ts +2310 -0
  288. package/dist/telemetry/event.js +405 -0
  289. package/dist/telemetry/index.d.ts +15 -0
  290. package/dist/telemetry/index.js +15 -0
  291. package/dist/telemetry/journal.d.ts +116 -0
  292. package/dist/telemetry/journal.js +11 -0
  293. package/dist/telemetry/memory.d.ts +24 -0
  294. package/dist/telemetry/memory.js +75 -0
  295. package/dist/telemetry/migrate.d.ts +26 -0
  296. package/dist/telemetry/migrate.js +40 -0
  297. package/dist/telemetry/postgres.d.ts +6 -0
  298. package/dist/telemetry/postgres.js +139 -0
  299. package/dist/telemetry/retention.d.ts +131 -0
  300. package/dist/telemetry/retention.js +217 -0
  301. package/dist/telemetry/schema.d.ts +113 -0
  302. package/dist/telemetry/schema.js +33 -0
  303. package/dist/telemetry/sink.d.ts +42 -0
  304. package/dist/telemetry/sink.js +61 -0
  305. package/dist/testing/contracts.d.ts +34 -0
  306. package/dist/testing/contracts.js +34 -0
  307. package/dist/testing/definitions.d.ts +15 -0
  308. package/dist/testing/definitions.js +48 -0
  309. package/dist/testing/doubles.d.ts +94 -0
  310. package/dist/testing/doubles.js +141 -0
  311. package/dist/testing/episode-harness.d.ts +49 -0
  312. package/dist/testing/episode-harness.js +65 -0
  313. package/dist/testing/filesystem.d.ts +17 -0
  314. package/dist/testing/filesystem.js +17 -0
  315. package/dist/testing/fixtures.d.ts +57 -0
  316. package/dist/testing/fixtures.js +84 -0
  317. package/dist/testing/hold-contract.d.ts +19 -0
  318. package/dist/testing/hold-contract.js +374 -0
  319. package/dist/testing/index.d.ts +41 -0
  320. package/dist/testing/index.js +41 -0
  321. package/dist/testing/journal-contract.d.ts +17 -0
  322. package/dist/testing/journal-contract.js +353 -0
  323. package/dist/testing/model-replies.d.ts +34 -0
  324. package/dist/testing/model-replies.js +101 -0
  325. package/dist/testing/primitives.d.ts +7 -0
  326. package/dist/testing/primitives.js +29 -0
  327. package/dist/testing/reader-signal-contract.d.ts +38 -0
  328. package/dist/testing/reader-signal-contract.js +318 -0
  329. package/dist/testing/row-security.d.ts +17 -0
  330. package/dist/testing/row-security.js +21 -0
  331. package/dist/testing/store-contract.d.ts +25 -0
  332. package/dist/testing/store-contract.js +500 -0
  333. package/dist/theme/apply.d.ts +17 -0
  334. package/dist/theme/apply.js +60 -0
  335. package/dist/theme/contrast.d.ts +197 -0
  336. package/dist/theme/contrast.js +259 -0
  337. package/dist/theme/derive.d.ts +77 -0
  338. package/dist/theme/derive.js +167 -0
  339. package/dist/theme/faces.d.ts +73 -0
  340. package/dist/theme/faces.js +119 -0
  341. package/dist/theme/font-packs.d.ts +25 -0
  342. package/dist/theme/font-packs.js +257 -0
  343. package/dist/theme/index.d.ts +20 -0
  344. package/dist/theme/index.js +20 -0
  345. package/dist/theme/lab.d.ts +30 -0
  346. package/dist/theme/lab.js +46 -0
  347. package/dist/theme/library.d.ts +114 -0
  348. package/dist/theme/library.js +300 -0
  349. package/dist/theme/measure.d.ts +144 -0
  350. package/dist/theme/measure.js +145 -0
  351. package/dist/theme/palettes.d.ts +64 -0
  352. package/dist/theme/palettes.js +497 -0
  353. package/dist/theme/registry.d.ts +59 -0
  354. package/dist/theme/registry.js +60 -0
  355. package/dist/theme/separation.d.ts +177 -0
  356. package/dist/theme/separation.js +203 -0
  357. package/dist/theme/style-presets.d.ts +60 -0
  358. package/dist/theme/style-presets.js +124 -0
  359. package/dist/theme/theme.d.ts +253 -0
  360. package/dist/theme/theme.js +171 -0
  361. package/dist/tree/apply.d.ts +16 -0
  362. package/dist/tree/apply.js +104 -0
  363. package/dist/tree/builders.d.ts +19 -0
  364. package/dist/tree/builders.js +20 -0
  365. package/dist/tree/compare.d.ts +68 -0
  366. package/dist/tree/compare.js +75 -0
  367. package/dist/tree/configuration.d.ts +25 -0
  368. package/dist/tree/configuration.js +108 -0
  369. package/dist/tree/delta.d.ts +288 -0
  370. package/dist/tree/delta.js +88 -0
  371. package/dist/tree/errors.d.ts +69 -0
  372. package/dist/tree/errors.js +34 -0
  373. package/dist/tree/identity.d.ts +117 -0
  374. package/dist/tree/identity.js +145 -0
  375. package/dist/tree/index.d.ts +21 -0
  376. package/dist/tree/index.js +21 -0
  377. package/dist/tree/inverse.d.ts +24 -0
  378. package/dist/tree/inverse.js +112 -0
  379. package/dist/tree/mutation.d.ts +18 -0
  380. package/dist/tree/mutation.js +49 -0
  381. package/dist/tree/naming.d.ts +4 -0
  382. package/dist/tree/naming.js +35 -0
  383. package/dist/tree/navigation.d.ts +38 -0
  384. package/dist/tree/navigation.js +83 -0
  385. package/dist/tree/node.d.ts +103 -0
  386. package/dist/tree/node.js +46 -0
  387. package/dist/tree/outline.d.ts +28 -0
  388. package/dist/tree/outline.js +10 -0
  389. package/dist/tree/tree.d.ts +83 -0
  390. package/dist/tree/tree.js +62 -0
  391. package/dist/write/commit.d.ts +124 -0
  392. package/dist/write/commit.js +234 -0
  393. package/dist/write/held.d.ts +674 -0
  394. package/dist/write/held.js +185 -0
  395. package/dist/write/index.d.ts +11 -0
  396. package/dist/write/index.js +11 -0
  397. package/dist/write/liveness.d.ts +132 -0
  398. package/dist/write/liveness.js +91 -0
  399. package/dist/write/revert.d.ts +79 -0
  400. package/dist/write/revert.js +134 -0
  401. package/package.json +160 -0
@@ -0,0 +1,77 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { ThemeVariables } from "../theme/apply.js";
3
+ import { type LoomPrimitive, type LoomPrimitiveProps } from "./primitive.js";
4
+ /**
5
+ * A render whose colours are values rather than references.
6
+ *
7
+ * The renderer is a total pure projection into React
8
+ * ([0008](../../decisions/0008-the-renderer-is-a-total-pure-projection.md)) and a
9
+ * primitive paints itself by *naming* a custom property — `loom.section` emits
10
+ * `var(--loom-bg-surface)`, and the root mounts the theme as variables
11
+ * ([0050](../../decisions/0050-the-runtimes-props-are-namespaced-and-the-root-mounts-the-theme.md)).
12
+ * Those two facts are what make a re-theme one `configure` on the root and
13
+ * nothing else (0049), and together they assume a cascade.
14
+ *
15
+ * Something has to render where there is no cascade. An image renderer takes
16
+ * inline styles and literal values; it resolves no custom properties, so a
17
+ * projection whose every colour is a `var()` renders as a blank rectangle. So
18
+ * does an email body, and so does anything else that has to show a page outside
19
+ * a browser. `Loom marketing` hit it first and drew its share card by hand,
20
+ * reading the resolved theme itself, and filed the hand-drawn copy of a page as
21
+ * the finding.
22
+ *
23
+ * This is the substitution the browser would have done, done here instead: the
24
+ * same walk the renderer already produced, with every `var(--loom-…)` in an
25
+ * inline style replaced by what the mounted theme says it is. Nothing about any
26
+ * primitive changes, and nothing about the tree changes — a primitive still
27
+ * names a slot and still never learns which palette answered it.
28
+ *
29
+ * **What it does not reach**, because a browser is doing more than substitution:
30
+ *
31
+ * - **The library stylesheet.** `:hover`, `:last-child`, keyframes and
32
+ * `::after` are the five things that cannot be said inline, and no renderer
33
+ * without a cascade evaluates them either — so a medium that needs this is a
34
+ * medium those rules were never going to reach.
35
+ * - **Inside a component element.** A control renders on the client, so its
36
+ * subtree does not exist yet. Its own `style` prop is substituted; what it
37
+ * returns is not there to walk.
38
+ *
39
+ * Both are the same shape of limit: this resolves the values a render *has*
40
+ * produced, and does not run the parts of CSS that are not values.
41
+ */
42
+ /** A CSS value with the theme's variables resolved, and what could not be. */
43
+ export type VariableSubstitution = {
44
+ readonly value: string;
45
+ /**
46
+ * Custom properties the theme does not declare **and** that named no
47
+ * fallback. A reference with a fallback is not reported: the fallback is the
48
+ * value, exactly as it is in a browser, and `--loom-mono-family` is written
49
+ * that way on purpose (0085).
50
+ */
51
+ readonly unresolved: readonly string[];
52
+ };
53
+ export declare const substituteVariables: (value: string, variables: ThemeVariables) => VariableSubstitution;
54
+ /** A projection with the theme resolved into it, and what the theme did not answer. */
55
+ export type InlinedProjection = {
56
+ readonly element: ReactNode;
57
+ readonly unresolved: readonly string[];
58
+ };
59
+ /**
60
+ * The projection, with every theme reference in an inline style replaced by
61
+ * what the mounted theme says it is.
62
+ *
63
+ * Pure and structurally sharing: a subtree with nothing to substitute comes back
64
+ * as the identical element, so a render this changes nothing about is the render
65
+ * it was handed.
66
+ */
67
+ export declare const inlineThemeVariables: (element: ReactNode, variables: ThemeVariables) => InlinedProjection;
68
+ /**
69
+ * A node's primitive, standing behind the substitution, under the node's own key.
70
+ *
71
+ * A class component is mounted as it always was and keeps its references: it
72
+ * cannot be called, and the alternative — rendering it and walking the result —
73
+ * is the pass this file exists because nothing can do. Nothing in this package
74
+ * is one, and a host that registers one gets a page rather than an exception.
75
+ */
76
+ export declare const literalThemeElement: (primitive: LoomPrimitive, variables: ThemeVariables, key: string, forwarded: LoomPrimitiveProps) => ReactElement;
77
+ //# sourceMappingURL=inline-variables.d.ts.map
@@ -0,0 +1,220 @@
1
+ import { cloneElement, createElement, isValidElement, } from "react";
2
+ import { asCallablePrimitive, } from "./primitive.js";
3
+ const REFERENCE = "var(";
4
+ /** A quote closes at its own kind, and a backslash inside one escapes anything. */
5
+ const endOfQuoted = (text, open) => {
6
+ const quote = text[open];
7
+ for (let index = open + 1; index < text.length; index += 1) {
8
+ if (text[index] === "\\") {
9
+ index += 1;
10
+ continue;
11
+ }
12
+ if (text[index] === quote)
13
+ return index;
14
+ }
15
+ return text.length - 1;
16
+ };
17
+ /**
18
+ * The index of the next `var(` outside a quoted string, or -1.
19
+ *
20
+ * The quote check is not pedantry: a font stack is the value most likely to
21
+ * carry a parenthesis, and `'Foo (Text)'` is a family somebody has shipped.
22
+ */
23
+ const nextReference = (text, from) => {
24
+ for (let index = from; index < text.length; index += 1) {
25
+ const character = text[index];
26
+ if (character === '"' || character === "'") {
27
+ index = endOfQuoted(text, index);
28
+ continue;
29
+ }
30
+ if (text.startsWith(REFERENCE, index))
31
+ return index;
32
+ }
33
+ return -1;
34
+ };
35
+ /** The index of the `)` closing the `(` at `open`, or -1 if nothing does. */
36
+ const closingParen = (text, open) => {
37
+ let depth = 0;
38
+ for (let index = open; index < text.length; index += 1) {
39
+ const character = text[index];
40
+ if (character === '"' || character === "'") {
41
+ index = endOfQuoted(text, index);
42
+ continue;
43
+ }
44
+ if (character === "(")
45
+ depth += 1;
46
+ else if (character === ")") {
47
+ depth -= 1;
48
+ if (depth === 0)
49
+ return index;
50
+ }
51
+ }
52
+ return -1;
53
+ };
54
+ /** `--loom-accent, #fff` → the name, and everything after the first comma. */
55
+ const readReference = (inner) => {
56
+ let depth = 0;
57
+ for (let index = 0; index < inner.length; index += 1) {
58
+ const character = inner[index];
59
+ if (character === '"' || character === "'") {
60
+ index = endOfQuoted(inner, index);
61
+ continue;
62
+ }
63
+ if (character === "(")
64
+ depth += 1;
65
+ else if (character === ")")
66
+ depth -= 1;
67
+ else if (character === "," && depth === 0) {
68
+ /**
69
+ * Trimmed, because the space after the comma is how a reference is
70
+ * written and not part of the value — `var(--x, red)` falls back to `red`
71
+ * in a browser, not to ` red`.
72
+ */
73
+ return { name: inner.slice(0, index).trim(), fallback: inner.slice(index + 1).trim() };
74
+ }
75
+ }
76
+ return { name: inner.trim(), fallback: undefined };
77
+ };
78
+ const substitute = (value, variables, unresolved) => {
79
+ let out = "";
80
+ let index = 0;
81
+ while (index < value.length) {
82
+ const at = nextReference(value, index);
83
+ if (at === -1)
84
+ return out + value.slice(index);
85
+ out += value.slice(index, at);
86
+ const close = closingParen(value, at + REFERENCE.length - 1);
87
+ /**
88
+ * An unclosed `var(` is not a reference this can read, and guessing where it
89
+ * ends would invent a value. The rest of the declaration is copied through
90
+ * exactly as the primitive wrote it.
91
+ */
92
+ if (close === -1)
93
+ return out + value.slice(at);
94
+ const reference = readReference(value.slice(at + REFERENCE.length, close));
95
+ const declared = reference.name.startsWith("--") ? variables[reference.name] : undefined;
96
+ if (declared !== undefined) {
97
+ /**
98
+ * The declared value is written through as-is and not walked again. Every
99
+ * variable the theme mounts is a literal, so there is nothing to resolve
100
+ * — and not re-entering is what makes a theme that somehow referred to
101
+ * itself a value rather than a hang.
102
+ */
103
+ out += declared;
104
+ }
105
+ else if (reference.fallback !== undefined) {
106
+ out += substitute(reference.fallback, variables, unresolved);
107
+ }
108
+ else {
109
+ if (reference.name.startsWith("--"))
110
+ unresolved.add(reference.name);
111
+ out += value.slice(at, close + 1);
112
+ }
113
+ index = close + 1;
114
+ }
115
+ return out;
116
+ };
117
+ export const substituteVariables = (value, variables) => {
118
+ const unresolved = new Set();
119
+ return { value: substitute(value, variables, unresolved), unresolved: [...unresolved].sort() };
120
+ };
121
+ const isStyleObject = (style) => typeof style === "object" && style !== null && !Array.isArray(style);
122
+ const inlineStyle = (style, variables, unresolved) => {
123
+ let next;
124
+ for (const [property, value] of Object.entries(style)) {
125
+ if (typeof value !== "string" || !value.includes(REFERENCE))
126
+ continue;
127
+ const resolved = substitute(value, variables, unresolved);
128
+ if (resolved === value)
129
+ continue;
130
+ next = next ?? { ...style };
131
+ next[property] = resolved;
132
+ }
133
+ return next;
134
+ };
135
+ const inlineNode = (node, variables, unresolved) => {
136
+ if (Array.isArray(node)) {
137
+ const children = node;
138
+ let changed = false;
139
+ const next = children.map((child) => {
140
+ const walked = inlineNode(child, variables, unresolved);
141
+ if (walked !== child)
142
+ changed = true;
143
+ return walked;
144
+ });
145
+ return changed ? next : node;
146
+ }
147
+ if (!isValidElement(node))
148
+ return node;
149
+ const element = node;
150
+ const { style, children } = element.props;
151
+ const nextStyle = isStyleObject(style) ? inlineStyle(style, variables, unresolved) : undefined;
152
+ const nextChildren = children === undefined ? undefined : inlineNode(children, variables, unresolved);
153
+ const childrenChanged = nextChildren !== undefined && nextChildren !== children;
154
+ if (!nextStyle && !childrenChanged)
155
+ return node;
156
+ /**
157
+ * `cloneElement` rather than `createElement`, because it carries the key and
158
+ * the ref across. Ids are React keys here (§1), so an element that lost its
159
+ * key on the way through would be reconciled as a delete and an insert — the
160
+ * one property the whole projection is built to keep.
161
+ */
162
+ return cloneElement(element, {
163
+ ...(nextStyle ? { style: nextStyle } : {}),
164
+ ...(childrenChanged ? { children: nextChildren } : {}),
165
+ });
166
+ };
167
+ /**
168
+ * The projection, with every theme reference in an inline style replaced by
169
+ * what the mounted theme says it is.
170
+ *
171
+ * Pure and structurally sharing: a subtree with nothing to substitute comes back
172
+ * as the identical element, so a render this changes nothing about is the render
173
+ * it was handed.
174
+ */
175
+ export const inlineThemeVariables = (element, variables) => {
176
+ const unresolved = new Set();
177
+ return {
178
+ element: inlineNode(element, variables, unresolved),
179
+ unresolved: [...unresolved].sort(),
180
+ };
181
+ };
182
+ /**
183
+ * One node's primitive, rendered and then resolved.
184
+ *
185
+ * The substitution cannot be a pass over what `renderLoomTree` returns, and the
186
+ * reason is worth stating because it is the whole shape of this file: the
187
+ * projection is a tree of *component* elements, and what a primitive paints does
188
+ * not exist until something renders it. A walk over the projection sees
189
+ * `<loom.card>` and no styles at all.
190
+ *
191
+ * So it happens one node in, where the styles are. This stands in for the
192
+ * primitive, calls it, and substitutes into what it produced — stopping at the
193
+ * child elements, which are the next nodes' stand-ins and resolve their own
194
+ * output the same way when they are rendered. Every node pays for itself and
195
+ * nothing is walked twice.
196
+ *
197
+ * **Calling the primitive rather than mounting it** is what keeps this one
198
+ * element per node instead of two. A primitive is a pure function of the props
199
+ * the seam hands it and holds no state (0008) — that is the same property the
200
+ * whole projection rests on, and a primitive that broke it would already have
201
+ * broken rendering the same tree twice. Hooks are what the rule forbids, and
202
+ * this is where forbidding them pays.
203
+ */
204
+ const LiteralTheme = ({ primitive, variables, ...forwarded }) => inlineThemeVariables(primitive(forwarded), variables).element;
205
+ LiteralTheme.displayName = "loom(literal-theme)";
206
+ /**
207
+ * A node's primitive, standing behind the substitution, under the node's own key.
208
+ *
209
+ * A class component is mounted as it always was and keeps its references: it
210
+ * cannot be called, and the alternative — rendering it and walking the result —
211
+ * is the pass this file exists because nothing can do. Nothing in this package
212
+ * is one, and a host that registers one gets a page rather than an exception.
213
+ */
214
+ export const literalThemeElement = (primitive, variables, key, forwarded) => {
215
+ const callable = asCallablePrimitive(primitive);
216
+ return callable.ok
217
+ ? createElement(LiteralTheme, { key, primitive: callable.value, variables, ...forwarded })
218
+ : createElement(primitive, { key, ...forwarded });
219
+ };
220
+ //# sourceMappingURL=inline-variables.js.map
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The present contract's one name, in a module with nothing else in it.
3
+ *
4
+ * It lives apart from `behaviour.ts` for the reason `disclosed.ts` does: code
5
+ * that only needs to *read* whether a region is showing should not have to
6
+ * import the React controls that write it (0136).
7
+ */
8
+ /**
9
+ * The attribute a presentation control stamps on **the element the primitive
10
+ * placed it in**: `"true"` while the region it opens is showing, `"false"`
11
+ * otherwise.
12
+ *
13
+ * **This is the whole of the contract between the runtime and a primitive that
14
+ * takes `present`.** It is an attribute for `disclosed.ts`'s reason — a
15
+ * stylesheet is what reads it — and it is on the *parent* for
16
+ * [0096](../../decisions/0096-a-behaviour-publishes-a-value-on-the-element-the-primitive-placed-it-in.md)'s,
17
+ * with the opposite half of that record's reasoning doing the work.
18
+ *
19
+ * `data-loom-disclosed` sits on the control's own button and is read
20
+ * **sideways**, by a sibling selector, because the region a disclosure opens is
21
+ * laid out beside its button. An overlay is not: a dialog's panel, a dropdown's
22
+ * menu and a lightbox's frame are all *inside* the box the primitive owns and
23
+ * the trigger is one element within it. A sibling selector cannot reach from the
24
+ * button to a region that is not its sibling, and the primitive cannot make it
25
+ * one without giving the trigger a wrapper whose only purpose is to be selected
26
+ * from — which is the cost `control.ts` already records against that shape.
27
+ *
28
+ * So the state goes on the parent, where a **descendant** selector reaches
29
+ * anything the primitive laid out:
30
+ *
31
+ * ```css
32
+ * [data-loom-presented="false"] .my-panel { display: none }
33
+ * ```
34
+ *
35
+ * The two properties that make the sibling form safe hold here unchanged, and
36
+ * they are the reason the rule must be written in this direction rather than
37
+ * its inverse. It matches nothing until the control has mounted, which is the
38
+ * no-scripting case — so the region must default to *visible* and be hidden by
39
+ * the rule, never shown by it, or a page served without scripting hides a panel
40
+ * behind a button that never arrives. And `display: none` takes the region out
41
+ * of the accessibility tree as well as the layout, so a closed panel is closed
42
+ * for a screen reader too, which the trigger's `aria-expanded` then describes
43
+ * correctly instead of contradicting.
44
+ */
45
+ export declare const PRESENTED_ATTRIBUTE = "data-loom-presented";
46
+ /**
47
+ * The event a dismiss control dispatches to close the presentation it sits
48
+ * inside: bubbling, so the nearest presentation above it hears it and no other.
49
+ *
50
+ * This is the part of the seam that has no counterpart in `disclose`, and it is
51
+ * here because of the one thing a disclosure never has to do — **be closed by
52
+ * something that is not the control that opened it.** A menu is closed by its
53
+ * own button. A dialog is closed by a cross inside the panel, by Escape, and by
54
+ * a press on the page behind it; a dropdown by choosing something; a lightbox by
55
+ * any of the three. The first of those is a second control, and a click handler
56
+ * is a function, so it is the runtime's to build for the same reason the first
57
+ * one is (0009).
58
+ *
59
+ * Two controls of one primitive therefore have to agree about one boolean, and
60
+ * nothing in the seam let them. A behaviour is built as an independent node the
61
+ * primitive places where it likes, so the two have no common React ancestor to
62
+ * hold state, no provider between them, and no way to be handed a shared object:
63
+ * `build` runs on the server and a control's props cross the client boundary, so
64
+ * anything passed between them has to be serialisable.
65
+ *
66
+ * What they do share is the **DOM**, because the primitive placed both of them
67
+ * in it — and a bubbling event is the one channel that needs no common ancestor
68
+ * named in advance, no key to agree on, and nothing to clean up. The dismiss
69
+ * control dispatches from its own button; the presentation control listens on
70
+ * the element it was placed in. If the primitive laid the region out inside that
71
+ * element, which is what presenting a region means, the event arrives. If it did
72
+ * not, nothing happens — the same way a sibling selector matches nothing when a
73
+ * disclosure's region is not its sibling.
74
+ *
75
+ * A module-level store keyed by node id was the alternative and is worse in the
76
+ * way that matters: it would make two controls that are not in each other's
77
+ * subtree agree anyway, which reads as a feature and is really a guarantee that
78
+ * the first primitive to place them apart gets a dialog closed by a button
79
+ * somewhere else on the page.
80
+ */
81
+ export declare const DISMISS_EVENT = "loom:dismiss";
82
+ //# sourceMappingURL=presented.d.ts.map
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The present contract's one name, in a module with nothing else in it.
3
+ *
4
+ * It lives apart from `behaviour.ts` for the reason `disclosed.ts` does: code
5
+ * that only needs to *read* whether a region is showing should not have to
6
+ * import the React controls that write it (0136).
7
+ */
8
+ /**
9
+ * The attribute a presentation control stamps on **the element the primitive
10
+ * placed it in**: `"true"` while the region it opens is showing, `"false"`
11
+ * otherwise.
12
+ *
13
+ * **This is the whole of the contract between the runtime and a primitive that
14
+ * takes `present`.** It is an attribute for `disclosed.ts`'s reason — a
15
+ * stylesheet is what reads it — and it is on the *parent* for
16
+ * [0096](../../decisions/0096-a-behaviour-publishes-a-value-on-the-element-the-primitive-placed-it-in.md)'s,
17
+ * with the opposite half of that record's reasoning doing the work.
18
+ *
19
+ * `data-loom-disclosed` sits on the control's own button and is read
20
+ * **sideways**, by a sibling selector, because the region a disclosure opens is
21
+ * laid out beside its button. An overlay is not: a dialog's panel, a dropdown's
22
+ * menu and a lightbox's frame are all *inside* the box the primitive owns and
23
+ * the trigger is one element within it. A sibling selector cannot reach from the
24
+ * button to a region that is not its sibling, and the primitive cannot make it
25
+ * one without giving the trigger a wrapper whose only purpose is to be selected
26
+ * from — which is the cost `control.ts` already records against that shape.
27
+ *
28
+ * So the state goes on the parent, where a **descendant** selector reaches
29
+ * anything the primitive laid out:
30
+ *
31
+ * ```css
32
+ * [data-loom-presented="false"] .my-panel { display: none }
33
+ * ```
34
+ *
35
+ * The two properties that make the sibling form safe hold here unchanged, and
36
+ * they are the reason the rule must be written in this direction rather than
37
+ * its inverse. It matches nothing until the control has mounted, which is the
38
+ * no-scripting case — so the region must default to *visible* and be hidden by
39
+ * the rule, never shown by it, or a page served without scripting hides a panel
40
+ * behind a button that never arrives. And `display: none` takes the region out
41
+ * of the accessibility tree as well as the layout, so a closed panel is closed
42
+ * for a screen reader too, which the trigger's `aria-expanded` then describes
43
+ * correctly instead of contradicting.
44
+ */
45
+ export const PRESENTED_ATTRIBUTE = "data-loom-presented";
46
+ /**
47
+ * The event a dismiss control dispatches to close the presentation it sits
48
+ * inside: bubbling, so the nearest presentation above it hears it and no other.
49
+ *
50
+ * This is the part of the seam that has no counterpart in `disclose`, and it is
51
+ * here because of the one thing a disclosure never has to do — **be closed by
52
+ * something that is not the control that opened it.** A menu is closed by its
53
+ * own button. A dialog is closed by a cross inside the panel, by Escape, and by
54
+ * a press on the page behind it; a dropdown by choosing something; a lightbox by
55
+ * any of the three. The first of those is a second control, and a click handler
56
+ * is a function, so it is the runtime's to build for the same reason the first
57
+ * one is (0009).
58
+ *
59
+ * Two controls of one primitive therefore have to agree about one boolean, and
60
+ * nothing in the seam let them. A behaviour is built as an independent node the
61
+ * primitive places where it likes, so the two have no common React ancestor to
62
+ * hold state, no provider between them, and no way to be handed a shared object:
63
+ * `build` runs on the server and a control's props cross the client boundary, so
64
+ * anything passed between them has to be serialisable.
65
+ *
66
+ * What they do share is the **DOM**, because the primitive placed both of them
67
+ * in it — and a bubbling event is the one channel that needs no common ancestor
68
+ * named in advance, no key to agree on, and nothing to clean up. The dismiss
69
+ * control dispatches from its own button; the presentation control listens on
70
+ * the element it was placed in. If the primitive laid the region out inside that
71
+ * element, which is what presenting a region means, the event arrives. If it did
72
+ * not, nothing happens — the same way a sibling selector matches nothing when a
73
+ * disclosure's region is not its sibling.
74
+ *
75
+ * A module-level store keyed by node id was the alternative and is worse in the
76
+ * way that matters: it would make two controls that are not in each other's
77
+ * subtree agree anyway, which reads as a feature and is really a guarantee that
78
+ * the first primitive to place them apart gets a dialog closed by a button
79
+ * somewhere else on the page.
80
+ */
81
+ export const DISMISS_EVENT = "loom:dismiss";
82
+ //# sourceMappingURL=presented.js.map