@descix/frqtl-node 0.0.0-stage → 0.6.0-p0.1

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 (217) hide show
  1. package/CLAUDE.md +87 -0
  2. package/README.md +84 -2
  3. package/dist/dist-manifest.json +218 -0
  4. package/dist/eyes/index.js +109 -0
  5. package/dist/fat/pkg-node/egpt_wasm.js +1277 -0
  6. package/dist/fat/pkg-node/egpt_wasm_bg.wasm +0 -0
  7. package/dist/fat/pkg-node/package.json +12 -0
  8. package/dist/frqtl/assets/vendor/chroma.mjs +64 -0
  9. package/dist/frqtl/compat/boot-node.js +34 -0
  10. package/dist/frqtl/compat/engine.js +127 -0
  11. package/dist/frqtl/compat/package-root.js +24 -0
  12. package/dist/frqtl/compat/providers/wasm-engine.js +2501 -0
  13. package/dist/frqtl/compat/providers/wasm-load-browser.js +134 -0
  14. package/dist/frqtl/compat/providers/wasm-load-node.js +59 -0
  15. package/dist/frqtl/compat/renderer/FieldBuilder.js +145 -0
  16. package/dist/frqtl/compat/renderer/Filters.js +163 -0
  17. package/dist/frqtl/compat/renderer/RenderFamily.js +85 -0
  18. package/dist/frqtl/compat/renderer/RenderMesh.js +100 -0
  19. package/dist/frqtl/compat/renderer/RenderShape.js +154 -0
  20. package/dist/frqtl/compat/renderer/camera2d-geometry.js +183 -0
  21. package/dist/frqtl/compat/renderer/captureStill-common.js +259 -0
  22. package/dist/frqtl/compat/renderer/display-slot.js +96 -0
  23. package/dist/frqtl/compat/renderer/lo-drawn-center.js +231 -0
  24. package/dist/frqtl/compat/renderer/orbit-bag.js +216 -0
  25. package/dist/frqtl/compat/renderer/providers/godrays-layer.js +213 -0
  26. package/dist/frqtl/compat/renderer/providers/index.js +22 -0
  27. package/dist/frqtl/compat/renderer/providers/p5-provider.js +861 -0
  28. package/dist/frqtl/compat/renderer/providers/three-camera-contract.js +160 -0
  29. package/dist/frqtl/compat/renderer/providers/three-camera-geometry.js +571 -0
  30. package/dist/frqtl/compat/renderer/providers/three-provider.js +2474 -0
  31. package/dist/frqtl/compat/renderer/renderCapabilities-common.js +186 -0
  32. package/dist/frqtl/compat/renderer/renderer-provider-contract.js +238 -0
  33. package/dist/frqtl/compat/renderer/unprojectStill.js +172 -0
  34. package/dist/frqtl/compat/vendor.js +196 -0
  35. package/dist/frqtl/node-entry.js +17 -0
  36. package/dist/frqtl/objects/FrqtlApp.js +2922 -0
  37. package/dist/frqtl/objects/ObjectFactory.js +297 -0
  38. package/dist/frqtl/objects/RecipeContext.js +322 -0
  39. package/dist/frqtl/objects/collectors/DataCollector.js +116 -0
  40. package/dist/frqtl/objects/constants/WallBehaviors.js +178 -0
  41. package/dist/frqtl/objects/geometry/SlabFace.js +258 -0
  42. package/dist/frqtl/objects/instruments/capture-host.js +453 -0
  43. package/dist/frqtl/objects/instruments/capture.js +711 -0
  44. package/dist/frqtl/objects/instruments/hosted-eyes.js +985 -0
  45. package/dist/frqtl/objects/kinds-entry.js +14 -0
  46. package/dist/frqtl/objects/kinds.js +190 -0
  47. package/dist/frqtl/objects/objects/Box.js +273 -0
  48. package/dist/frqtl/objects/objects/Bullet.js +155 -0
  49. package/dist/frqtl/objects/objects/CircuitGate.js +380 -0
  50. package/dist/frqtl/objects/objects/CircuitProbe.js +214 -0
  51. package/dist/frqtl/objects/objects/DirectedTunnel.js +412 -0
  52. package/dist/frqtl/objects/objects/EgptFractal.js +164 -0
  53. package/dist/frqtl/objects/objects/LightSource.js +354 -0
  54. package/dist/frqtl/objects/objects/QuantumEmitter.js +760 -0
  55. package/dist/frqtl/objects/objects/Tube.js +471 -0
  56. package/dist/frqtl/objects/objects/absorbRadiation.js +310 -0
  57. package/dist/frqtl/objects/objects/actionCompiler.js +1747 -0
  58. package/dist/frqtl/objects/objects/controlAction.js +89 -0
  59. package/dist/frqtl/objects/objects/controlBind.js +278 -0
  60. package/dist/frqtl/objects/objects/directedRedirectProgram.js +120 -0
  61. package/dist/frqtl/objects/objects/emitterProgram.js +209 -0
  62. package/dist/frqtl/objects/objects/frqtl-control-slider.js +197 -0
  63. package/dist/frqtl/objects/objects/frqtl-control-sync.js +272 -0
  64. package/dist/frqtl/objects/objects/frqtl-control-widgets.js +219 -0
  65. package/dist/frqtl/objects/objects/frqtl-control-write-queue.js +174 -0
  66. package/dist/frqtl/objects/objects/makeControlsForObject.js +824 -0
  67. package/dist/frqtl/objects/objects/makeControlsForRenderSurface.js +161 -0
  68. package/dist/frqtl/objects/objects/slitLinerScatter.js +263 -0
  69. package/dist/frqtl/objects/objects/sustainedSource.js +299 -0
  70. package/dist/frqtl/objects/objects/tagger.js +228 -0
  71. package/dist/frqtl/objects/schema/engine-scopes.js +469 -0
  72. package/dist/frqtl/objects/schema/index.js +256 -0
  73. package/dist/frqtl/objects/schema/scopes.js +457 -0
  74. package/dist/frqtl/objects/schema/validate-descriptor.js +49 -0
  75. package/dist/frqtl/objects/schema/valueNormalizer.js +366 -0
  76. package/dist/frqtl/objects/setup/_collisionMatrixLanes.js +66 -0
  77. package/dist/frqtl/objects/setup/_setupOptions.js +118 -0
  78. package/dist/frqtl/objects/setup/_worldInit.js +162 -0
  79. package/dist/frqtl/objects/setup/setupBlackbodySubstrate.js +242 -0
  80. package/dist/frqtl/objects/setup/setupCircuitBasic.js +447 -0
  81. package/dist/frqtl/objects/setup/setupCollisionMatrix.js +188 -0
  82. package/dist/frqtl/objects/setup/setupConeEmitter3D.js +251 -0
  83. package/dist/frqtl/objects/setup/setupDoubleSlit.js +327 -0
  84. package/dist/frqtl/objects/setup/setupDoubleSlit_Laser.js +229 -0
  85. package/dist/frqtl/objects/setup/setupEmpty.js +59 -0
  86. package/dist/frqtl/objects/setup/setupFxSmoke.js +209 -0
  87. package/dist/frqtl/objects/setup/setupG1Race.js +80 -0
  88. package/dist/frqtl/objects/setup/setupG2Sweep.js +89 -0
  89. package/dist/frqtl/objects/setup/setupG3Collide.js +177 -0
  90. package/dist/frqtl/objects/setup/setupLightSourceLab.js +280 -0
  91. package/dist/frqtl/objects/setup/setupOscillator.js +68 -0
  92. package/dist/frqtl/objects/setup/setupParticleWalk.js +93 -0
  93. package/dist/frqtl/objects/setup/setupParticleWalk3D.js +133 -0
  94. package/dist/frqtl/objects/setup/setupSphereEmitter3D.js +1259 -0
  95. package/dist/frqtl/objects/setup/setupTraceCircuit.js +239 -0
  96. package/dist/frqtl/objects/setup/setupTunnelLab.js +242 -0
  97. package/dist/frqtl/objects/setup/setupTunnelPointExit.js +306 -0
  98. package/dist/frqtl/objects/setup/setupWaveInterference.js +178 -0
  99. package/dist/frqtl/objects/v1-replacements.js +30 -0
  100. package/dist/frqtl/package-core.js +23 -0
  101. package/dist/frqtl/parts/CameraControls.js +643 -0
  102. package/dist/frqtl/parts/CameraPath.js +575 -0
  103. package/dist/frqtl/parts/CollisionActions.js +35 -0
  104. package/dist/frqtl/parts/CollisionTypes.js +31 -0
  105. package/dist/frqtl/parts/DetectorWall.js +496 -0
  106. package/dist/frqtl/parts/FrqtlControlOverlay.js +227 -0
  107. package/dist/frqtl/parts/FrqtlControlsPanel.js +415 -0
  108. package/dist/frqtl/parts/FrqtlVision.js +818 -0
  109. package/dist/frqtl/parts/GraphingDetectorWall.js +490 -0
  110. package/dist/frqtl/parts/LargeObject.js +406 -0
  111. package/dist/frqtl/parts/LightColor.js +255 -0
  112. package/dist/frqtl/parts/LiveChart.js +285 -0
  113. package/dist/frqtl/parts/LogicGate.js +720 -0
  114. package/dist/frqtl/parts/OvenBox.js +612 -0
  115. package/dist/frqtl/parts/PointSource.js +763 -0
  116. package/dist/frqtl/parts/Rectangle.js +200 -0
  117. package/dist/frqtl/parts/SlitLightSource.js +234 -0
  118. package/dist/frqtl/parts/SlitScreen.js +628 -0
  119. package/dist/frqtl/parts/SphereEmitter.js +946 -0
  120. package/dist/frqtl/parts/Trace.js +508 -0
  121. package/dist/frqtl/parts/Tunnel.js +1057 -0
  122. package/dist/frqtl/parts/Wall.js +1211 -0
  123. package/dist/frqtl/parts/index.js +33 -0
  124. package/dist/frqtl/scenes/absorbing-wall-3d.js +33 -0
  125. package/dist/frqtl/scenes/absorbing-wall.js +32 -0
  126. package/dist/frqtl/scenes/atomic-model.js +88 -0
  127. package/dist/frqtl/scenes/big-bang.js +46 -0
  128. package/dist/frqtl/scenes/blackbody.js +81 -0
  129. package/dist/frqtl/scenes/circuit-sat.js +127 -0
  130. package/dist/frqtl/scenes/collision-matrix-3d.js +107 -0
  131. package/dist/frqtl/scenes/counting-wall-3d.js +36 -0
  132. package/dist/frqtl/scenes/counting-wall.js +38 -0
  133. package/dist/frqtl/scenes/double-slit.js +31 -0
  134. package/dist/frqtl/scenes/dse-one-emitter.js +196 -0
  135. package/dist/frqtl/scenes/dse-one-slit.js +114 -0
  136. package/dist/frqtl/scenes/dse-photoelectric.js +70 -0
  137. package/dist/frqtl/scenes/dse-tunnel-rebuild.js +244 -0
  138. package/dist/frqtl/scenes/dse-two-emitters.js +196 -0
  139. package/dist/frqtl/scenes/dse-two-slits.js +132 -0
  140. package/dist/frqtl/scenes/empty.js +14 -0
  141. package/dist/frqtl/scenes/laser-buildup.js +49 -0
  142. package/dist/frqtl/scenes/mirror-3d.js +56 -0
  143. package/dist/frqtl/scenes/mirror-route.js +140 -0
  144. package/dist/frqtl/scenes/mirror.js +38 -0
  145. package/dist/frqtl/scenes/omni-3d.js +27 -0
  146. package/dist/frqtl/scenes/omni-source.js +22 -0
  147. package/dist/frqtl/scenes/self-interference.js +39 -0
  148. package/dist/frqtl/scenes/smoking-gun.js +122 -0
  149. package/dist/frqtl/scenes/straight-walk.js +22 -0
  150. package/dist/frqtl/scenes/sun.js +39 -0
  151. package/dist/frqtl/scenes/two-source.js +37 -0
  152. package/dist/frqtl/scenes/wave.js +26 -0
  153. package/dist/shim/bundle/frqnb.js +112 -0
  154. package/dist/shim/bundle/index.js +121 -0
  155. package/dist/shim/bundle/indexHtml.js +107 -0
  156. package/dist/shim/bundle/manifest.js +95 -0
  157. package/dist/shim/bundle/zip.js +243 -0
  158. package/dist/shim/bus.js +67 -0
  159. package/dist/shim/controls/index.js +627 -0
  160. package/dist/shim/controls/registry.js +274 -0
  161. package/dist/shim/engine/artifact-shell.js +212 -0
  162. package/dist/shim/engine/boot-phases.js +44 -0
  163. package/dist/shim/engine/engine-stack-boot.js +59 -0
  164. package/dist/shim/engine/router.js +692 -0
  165. package/dist/shim/experiment-frame/index.js +296 -0
  166. package/dist/shim/expr/ast-schema.js +369 -0
  167. package/dist/shim/field-descriptor/index.js +326 -0
  168. package/dist/shim/frame-data/index.js +224 -0
  169. package/dist/shim/index.js +67 -0
  170. package/dist/shim/notebook/canvas-guard.js +82 -0
  171. package/dist/shim/notebook/catalog.js +35 -0
  172. package/dist/shim/notebook/format.js +736 -0
  173. package/dist/shim/notebook/frqtl-setups-importmap.js +81 -0
  174. package/dist/shim/notebook/kernel.js +672 -0
  175. package/dist/shim/notebook/knob.js +151 -0
  176. package/dist/shim/notebook/module-resolver.js +260 -0
  177. package/dist/shim/notebook/notebook-knobs.js +65 -0
  178. package/dist/shim/notebook/produced-bindings.js +67 -0
  179. package/dist/shim/notebook/realm-registry.js +121 -0
  180. package/dist/shim/notebook/realm-transport.js +73 -0
  181. package/dist/shim/notebook/setup-builder.js +510 -0
  182. package/dist/shim/notebook/store.js +159 -0
  183. package/dist/shim/notebook/vendor-importmap.js +134 -0
  184. package/dist/shim/notebook/view-builder.js +189 -0
  185. package/dist/shim/notebook/view-ctx.js +100 -0
  186. package/dist/shim/notebook/view-handle.js +202 -0
  187. package/dist/shim/notebook/warmup.js +102 -0
  188. package/dist/shim/package.json +4 -0
  189. package/dist/shim/page-params/index.js +214 -0
  190. package/dist/shim/project/identity.js +112 -0
  191. package/dist/shim/project/index.js +19 -0
  192. package/dist/shim/project/link.js +402 -0
  193. package/dist/shim/project/node-specifier-hook.mjs +35 -0
  194. package/dist/shim/project/register-node.mjs +17 -0
  195. package/dist/shim/project/specifiers.js +106 -0
  196. package/dist/shim/registry/copy-gate.js +110 -0
  197. package/dist/shim/registry/exhibits.js +455 -0
  198. package/dist/shim/registry/experiments.js +215 -0
  199. package/dist/shim/registry/index.js +19 -0
  200. package/dist/shim/registry/scene-source.js +157 -0
  201. package/dist/shim/registry/walkthrough.js +807 -0
  202. package/dist/shim/render/capture-envelope.js +279 -0
  203. package/dist/shim/render/heat-colormap.js +92 -0
  204. package/dist/shim/render/render-stages.js +855 -0
  205. package/dist/shim/render/sun-look.js +33 -0
  206. package/dist/shim/render-state/apply.js +262 -0
  207. package/dist/shim/render-state/index.js +74 -0
  208. package/dist/shim/rpc/index.js +207 -0
  209. package/dist/shim/runtime/index.js +1023 -0
  210. package/dist/shim/storage/boot.js +69 -0
  211. package/dist/shim/storage/index.js +169 -0
  212. package/dist/shim/storage/local-storage-provider.js +230 -0
  213. package/dist/shim/storage/make-namespace-store.js +132 -0
  214. package/dist/shim/storage/modules.js +249 -0
  215. package/dist/shim/storage/projects.js +150 -0
  216. package/llms.txt +12 -0
  217. package/package.json +62 -4
@@ -0,0 +1,112 @@
1
+ /* Copyright 2023-2026 by Essam Abadir */
2
+
3
+ /**
4
+ * lib/shim/bundle/frqnb.js — the `.frqnb` teaching/gallery projection of a
5
+ * recipe bundle (ws-experiments-walkthrough Bite 2).
6
+ *
7
+ * Builds a notebook OBJECT (never hand-emitted `<cell>` markup) and serializes
8
+ * it THROUGH `lib/shim/notebook/format.js` `serialize` — the ONE notebook
9
+ * serializer (no second serializer, no CELL_ATTRS mirror). The projection is:
10
+ *
11
+ * 1. markdown prose cell — title + teaching blurb.
12
+ * 2. module cell (name './experiment.js') — carries the recipe source verbatim.
13
+ * 3. canvas cell — wired to '<module>' (a recipe is the module's default export), carrying the render
14
+ * intent (stage/seed/render3d/cameraPreset/renderOptions) ferried from the
15
+ * normalized renderState bag.
16
+ *
17
+ * Because it serializes through format.js, ANY new CELL_ATTR added there flows
18
+ * through this projection automatically — the Bite-2 conformance gate asserts it.
19
+ *
20
+ * The canvas cell carries `shape="recipe"` (the CELL_ATTRS discriminator owned by format.js):
21
+ * the module's default export is a RecipeContext recipe (its co-init call + `exp.addObject`), and
22
+ * the shim's setup-builder synthesizes `frqtl.RecipeContext` + `exp.build(buildExperiment)` for it.
23
+ *
24
+ * Layer 2 (physics): none — pure notebook projection.
25
+ */
26
+
27
+ 'use strict';
28
+
29
+ import { serialize } from '../notebook/format.js';
30
+
31
+ var MODULE_NAME = './experiment.js';
32
+ var CANVAS_ID = 'c-recipe';
33
+
34
+ /**
35
+ * Fold a normalized renderState `render` array ([{key,value}]) into a plain
36
+ * `{key: value}` bag for the canvas cell's `renderOptions` (CELL_ATTRS 'opts' kind).
37
+ * @param {{key:string,value:*}[]} render
38
+ * @returns {object}
39
+ */
40
+ function _renderOptionsBag(render) {
41
+ var bag = {};
42
+ if (Array.isArray(render)) {
43
+ for (var i = 0; i < render.length; i++) {
44
+ var row = render[i];
45
+ if (row && typeof row.key === 'string' && row.key.length > 0) {
46
+ bag[row.key] = row.value;
47
+ }
48
+ }
49
+ }
50
+ return bag;
51
+ }
52
+
53
+ /**
54
+ * Build the `.frqnb` notebook string for a recipe bundle.
55
+ *
56
+ * @param {object} args
57
+ * @param {string} args.name — human-readable project name (notebook title + markdown heading).
58
+ * @param {string} args.source — the `experiment.js` recipe source (module cell body).
59
+ * @param {object} [args.renderState] — a NORMALIZED renderState bag (from
60
+ * `lib/shim/render-state` normalizeSavedRenderState). Render intent is ferried
61
+ * onto the canvas cell; absent → the canvas carries stage/seed defaults only.
62
+ * @param {string} [args.stage='600x400'] — canvas stage '<W>x<H>'.
63
+ * @param {string} [args.prose] — optional teaching blurb appended under the heading.
64
+ * @returns {string} the serialized `.frqnb` notebook.
65
+ */
66
+ export function buildFrqnb(args) {
67
+ args = args || {};
68
+ if (typeof args.source !== 'string' || args.source.length === 0) {
69
+ throw new Error('[bundle/frqnb] buildFrqnb: args.source (experiment.js) is required.');
70
+ }
71
+ var name = (typeof args.name === 'string' && args.name.length > 0) ? args.name : 'FRQTL Recipe';
72
+ var rs = args.renderState || {};
73
+ var stage = (typeof args.stage === 'string' && args.stage.length > 0) ? args.stage : '600x400';
74
+ var seed = (rs.seed != null && rs.seed !== '') ? String(rs.seed) : '42';
75
+
76
+ var markdownBody = '# ' + name + '\n\n' +
77
+ (typeof args.prose === 'string' && args.prose.length > 0
78
+ ? args.prose
79
+ : 'A FRQTL recipe. The module cell below is the `experiment.js` source of truth; ' +
80
+ 'the canvas runs it live.');
81
+
82
+ var canvasCell = {
83
+ type: 'canvas',
84
+ id: CANVAS_ID,
85
+ setup: MODULE_NAME,
86
+ // Bite 5c: the module's DEFAULT export is a `buildExperiment(exp)` RECIPE (RecipeContext
87
+ // form), NOT a `(frqtl,universe,options)` setup factory — declare it so the
88
+ // shim synthesizes the RecipeContext path (a recipe canvas names no export).
89
+ shape: 'recipe',
90
+ stage: stage,
91
+ seed: seed
92
+ };
93
+ // Ferry render intent from the normalized renderState bag onto the canvas cell.
94
+ if (rs.renderer === 'three') { canvasCell.render3d = true; } // three IS the 3D display
95
+ if (rs.camera && typeof rs.camera.preset === 'string' && rs.camera.preset.length > 0) {
96
+ canvasCell.cameraPreset = rs.camera.preset;
97
+ }
98
+ var renderOptions = _renderOptionsBag(rs.render);
99
+ if (Object.keys(renderOptions).length > 0) { canvasCell.renderOptions = renderOptions; }
100
+
101
+ var notebook = {
102
+ version: '1',
103
+ title: name,
104
+ cells: [
105
+ { type: 'markdown', body: markdownBody },
106
+ { type: 'module', name: MODULE_NAME, body: args.source },
107
+ canvasCell
108
+ ]
109
+ };
110
+
111
+ return serialize(notebook);
112
+ }
@@ -0,0 +1,121 @@
1
+ /* Copyright 2023-2026 by Essam Abadir */
2
+
3
+ /**
4
+ * lib/shim/bundle/index.js — the recipe-bundle assembler + importer
5
+ * (ws-experiments-walkthrough Bite 2). The canonical owner of the bundle format
6
+ * (design §2): a folder that zips for download —
7
+ *
8
+ * experiment.js ← THE source of truth (the buildExperiment(exp) recipe)
9
+ * experiment.frqnb ← teaching/gallery projection (notebook/format.serialize)
10
+ * index.html ← standalone host (@descix/frqtl-web bootProject over the served folder)
11
+ * manifest.json ← Module envelope minus `source` + bundle-only fields (E1)
12
+ * preview.png ← optional golden screenshot
13
+ *
14
+ * PURE + DOM-free: emits/consumes `Uint8Array`. STUDIO's export button and any
15
+ * future DeSciX publisher CONSUME this — passing the generated `experiment.js`
16
+ * source + envelope + renderState DOWN (this module never imports codegen/
17
+ * save-state — those live above the shim; the arrow stays one-way). The browser
18
+ * `Blob`+`a.click` download trigger is a THIN feature-side helper.
19
+ *
20
+ * Layer 2 (physics): none — pure format/packaging.
21
+ */
22
+
23
+ 'use strict';
24
+
25
+ import { buildManifest, manifestToEnvelope } from './manifest.js';
26
+ import { buildFrqnb } from './frqnb.js';
27
+ import { buildIndexHtml } from './indexHtml.js';
28
+ import { zipStore, unzipStore, textBytes, bytesText } from './zip.js';
29
+ import { normalizeSavedRenderState } from '../render-state/index.js';
30
+
31
+ // ── Canonical bundle file names ──────────────────────────────────────────────
32
+ export var FILE_EXPERIMENT_JS = 'experiment.js';
33
+ export var FILE_EXPERIMENT_FRQNB = 'experiment.frqnb';
34
+ export var FILE_INDEX_HTML = 'index.html';
35
+ export var FILE_MANIFEST_JSON = 'manifest.json';
36
+ export var FILE_PREVIEW_PNG = 'preview.png';
37
+
38
+ /**
39
+ * Assemble a recipe bundle from a Module envelope + bundle inputs.
40
+ *
41
+ * Conceptually the dispatch's `(source, envelopeMeta, renderState, previewPngBytes,
42
+ * sdkVersion)`: here `source` + `renderState` + `envelopeMeta` arrive together AS
43
+ * the Module envelope (the exact shape STUDIO's Save path already builds), so the
44
+ * bundle↔envelope round-trip is a clean identity. `manifest` ferries the envelope
45
+ * minus `source` (E1) — no field re-enumeration.
46
+ *
47
+ * @param {object} envelope — a `lib/shim/storage/modules.js` Module envelope
48
+ * (`{id,name,source,renderState,…}`; `source` = the recipe, REQUIRED).
49
+ * @param {object} opts
50
+ * @param {string} opts.sdkVersion — REQUIRED CDN pin (derived, never a literal).
51
+ * @param {Uint8Array|null} [opts.previewPngBytes] — preview image bytes, or null.
52
+ * @param {string} [opts.stage='600x400'] — canvas stage for the .frqnb projection.
53
+ * @param {string} [opts.prose] — optional teaching blurb for the .frqnb markdown.
54
+ * @returns {{files: {name:string, bytes:Uint8Array}[], zipBytes: Uint8Array}}
55
+ */
56
+ export function assembleBundle(envelope, opts) {
57
+ if (!envelope || typeof envelope !== 'object') {
58
+ throw new Error('[bundle] assembleBundle(envelope): envelope must be an object.');
59
+ }
60
+ if (typeof envelope.source !== 'string' || envelope.source.length === 0) {
61
+ throw new Error('[bundle] assembleBundle: envelope.source (the recipe) is required.');
62
+ }
63
+ opts = opts || {};
64
+ var preview = (opts.previewPngBytes instanceof Uint8Array && opts.previewPngBytes.length > 0)
65
+ ? opts.previewPngBytes : null;
66
+
67
+ var manifest = buildManifest(envelope, {
68
+ sdkVersion: opts.sdkVersion,
69
+ preview: preview ? FILE_PREVIEW_PNG : null
70
+ });
71
+
72
+ var normalizedRs = normalizeSavedRenderState(envelope.renderState);
73
+
74
+ var files = [
75
+ { name: FILE_EXPERIMENT_JS, bytes: textBytes(envelope.source) },
76
+ { name: FILE_EXPERIMENT_FRQNB, bytes: textBytes(buildFrqnb({
77
+ name: envelope.name, source: envelope.source,
78
+ renderState: normalizedRs, stage: opts.stage, prose: opts.prose
79
+ })) },
80
+ { name: FILE_INDEX_HTML, bytes: textBytes(buildIndexHtml({
81
+ name: envelope.name, sdkVersion: opts.sdkVersion, renderState: normalizedRs,
82
+ scripts: Array.isArray(envelope.scripts) ? envelope.scripts : [] // the envelope's setup-factory delta
83
+ })) },
84
+ { name: FILE_MANIFEST_JSON, bytes: textBytes(JSON.stringify(manifest, null, 2)) }
85
+ ];
86
+ if (preview) { files.push({ name: FILE_PREVIEW_PNG, bytes: preview }); }
87
+
88
+ return { files: files, zipBytes: zipStore(files) };
89
+ }
90
+
91
+ /**
92
+ * Import a recipe bundle: recover the Module envelope (source re-attached from
93
+ * `experiment.js` per E1) + the preview bytes.
94
+ *
95
+ * @param {Uint8Array} zipBytes — a bundle `.zip` (from `assembleBundle`).
96
+ * @returns {{envelope: object, previewPngBytes: Uint8Array|null}}
97
+ */
98
+ export function importBundle(zipBytes) {
99
+ var entries = unzipStore(zipBytes);
100
+ var byName = Object.create(null);
101
+ for (var i = 0; i < entries.length; i++) { byName[entries[i].name] = entries[i].bytes; }
102
+
103
+ if (!byName[FILE_MANIFEST_JSON]) {
104
+ throw new Error('[bundle] importBundle: ' + FILE_MANIFEST_JSON + ' missing from the archive.');
105
+ }
106
+ if (!byName[FILE_EXPERIMENT_JS]) {
107
+ throw new Error('[bundle] importBundle: ' + FILE_EXPERIMENT_JS + ' missing from the archive.');
108
+ }
109
+
110
+ var manifest;
111
+ try {
112
+ manifest = JSON.parse(bytesText(byName[FILE_MANIFEST_JSON]));
113
+ } catch (e) {
114
+ throw new Error('[bundle] importBundle: ' + FILE_MANIFEST_JSON + ' is not valid JSON — ' + (e && e.message));
115
+ }
116
+ var source = bytesText(byName[FILE_EXPERIMENT_JS]);
117
+ var envelope = manifestToEnvelope(manifest, source);
118
+ var previewPngBytes = byName[FILE_PREVIEW_PNG] || null;
119
+
120
+ return { envelope: envelope, previewPngBytes: previewPngBytes };
121
+ }
@@ -0,0 +1,107 @@
1
+ /* Copyright 2023-2026 by Essam Abadir */
2
+
3
+ /**
4
+ * lib/shim/bundle/indexHtml.js — the standalone `index.html` projection of a
5
+ * recipe bundle.
6
+ *
7
+ * A byte-template host that boots the bundle folder as a SERVED PROJECT: `bootProject(mount,
8
+ * { url: './', entry: 'experiment.js' }, { renderState })` from `@descix/frqtl-web@<pin>` on the CDN. The
9
+ * recipe is a sketch module whose imports name the published self-reference (`@descix/frqtl-web/...`);
10
+ * the page's import map carries those rows and the scene doors' row, rendered by the ONE table
11
+ * (`pageImportMapFor(<the pinned dist root>/)`, lib/shim/project/specifiers.js), so the sketch resolves
12
+ * to the SAME module URLs the boot loads. The pinned dist root is the router's one spelling
13
+ * (`cdnDistBaseFor`); the `@<pin>` is the passed-in `sdkVersion` (DERIVED at export time — never a
14
+ * literal here).
15
+ *
16
+ * DRY: `experiment.js` stays the ONE source of truth — the page links it where it is served rather than
17
+ * embedding a second copy. `renderState` (small, manifest-derived) is embedded inline as JSON. A page
18
+ * opened via `file://` cannot fetch the project: the error says to serve the folder over http.
19
+ *
20
+ * Layer 2 (physics): none — pure host projection.
21
+ */
22
+
23
+ 'use strict';
24
+
25
+ import { pageImportMapFor, FRQTL_WEB_BOOT } from '../project/specifiers.js';
26
+ import { cdnDistBaseFor } from '../engine/router.js';
27
+
28
+ function _escapeHtml(s) {
29
+ return String(s == null ? '' : s)
30
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
31
+ }
32
+
33
+ /** Safe inline-JSON: escape `<` so a `</script>`-like payload can't break out. */
34
+ function _inlineJson(obj) {
35
+ return JSON.stringify(obj == null ? null : obj).replace(/</g, '\\u003c');
36
+ }
37
+
38
+ /**
39
+ * Build the standalone `index.html` for a recipe bundle.
40
+ *
41
+ * @param {object} args
42
+ * @param {string} args.name — project name (page title).
43
+ * @param {string} args.sdkVersion — the `@descix/frqtl-web@<pin>` version (REQUIRED).
44
+ * @param {object} [args.renderState] — normalized renderState bag (inlined as JSON;
45
+ * forwarded to bootProject's `{renderState}`).
46
+ * @param {string[]} [args.scripts] — the v4 envelope's setup-factory delta (inlined as JSON): nothing
47
+ * classic is left to load, so the page REFUSES a non-empty list at boot,
48
+ * naming the fix (import the factory in the sketch).
49
+ * @param {string} [args.recipeFile='experiment.js'] — the project's entry file.
50
+ * @returns {string} the complete `index.html`.
51
+ */
52
+ export function buildIndexHtml(args) {
53
+ args = args || {};
54
+ if (typeof args.sdkVersion !== 'string' || args.sdkVersion.length === 0) {
55
+ throw new Error('[bundle/indexHtml] buildIndexHtml: args.sdkVersion is REQUIRED (the CDN pin).');
56
+ }
57
+ var name = (typeof args.name === 'string' && args.name.length > 0) ? args.name : 'FRQTL Recipe';
58
+ var recipeFile = (typeof args.recipeFile === 'string' && args.recipeFile.length > 0)
59
+ ? args.recipeFile : 'experiment.js';
60
+ var importMapJson = _inlineJson(pageImportMapFor(cdnDistBaseFor(args.sdkVersion) + '/'));
61
+ var renderStateJson = _inlineJson(args.renderState || null);
62
+ var scriptsJson = _inlineJson(Array.isArray(args.scripts) ? args.scripts : []);
63
+
64
+ return [
65
+ '<!DOCTYPE html>',
66
+ '<html lang="en">',
67
+ '<head>',
68
+ ' <meta charset="UTF-8">',
69
+ ' <meta name="viewport" content="width=device-width, initial-scale=1">',
70
+ ' <title>' + _escapeHtml(name) + ' — FRQTL</title>',
71
+ ' <style>',
72
+ ' html,body{margin:0;height:100%;background:#0b0b0f;color:#ddd;',
73
+ ' font:14px/1.5 ui-sans-serif,system-ui,sans-serif;}',
74
+ ' #frqtl-mount{position:relative;width:100vw;height:100vh;}',
75
+ ' #frqtl-err{position:absolute;inset:0;padding:16px;white-space:pre-wrap;',
76
+ ' font:12px/1.5 ui-monospace,Menlo,Consolas,monospace;color:#ff6b6b;',
77
+ ' background:#1a0000;display:none;overflow:auto;}',
78
+ ' </style>',
79
+ '</head>',
80
+ '<body>',
81
+ ' <div id="frqtl-mount"></div>',
82
+ ' <pre id="frqtl-err"></pre>',
83
+ ' <script type="importmap">' + importMapJson + '</script>',
84
+ ' <script type="module">',
85
+ ' import { bootProject } from ' + JSON.stringify(FRQTL_WEB_BOOT.specifier) + ';',
86
+ ' const RENDER_STATE = ' + renderStateJson + ';',
87
+ ' const SCRIPTS = ' + scriptsJson + ';',
88
+ ' const mount = document.getElementById("frqtl-mount");',
89
+ ' const errBox = document.getElementById("frqtl-err");',
90
+ ' function fail(title, detail){',
91
+ ' errBox.style.display = "block";',
92
+ ' errBox.textContent = title + "\\n\\n" + detail;',
93
+ ' }',
94
+ ' if (SCRIPTS.length > 0) {',
95
+ ' fail("FRQTL project boot refused", "scripts " + JSON.stringify(SCRIPTS) + " is a classic setup-factory delta, and nothing classic is left to load — import the factory in the sketch (it imports what it uses from @descix/frqtl-web/...).");',
96
+ ' } else if (location.protocol === "file:") {',
97
+ ' fail("Serve this folder over http", "e.g. `npx serve` — a file:// page cannot fetch ' + _escapeHtml(recipeFile) + '.");',
98
+ ' } else {',
99
+ ' bootProject(mount, { url: new URL("./", location.href).href, entry: ' + JSON.stringify(recipeFile) + ' }, { renderState: RENDER_STATE })',
100
+ ' .catch((e) => fail("FRQTL project boot failed", String(e && e.stack || e)));',
101
+ ' }',
102
+ ' </script>',
103
+ '</body>',
104
+ '</html>',
105
+ ''
106
+ ].join('\n');
107
+ }
@@ -0,0 +1,95 @@
1
+ /* Copyright 2023-2026 by Essam Abadir */
2
+
3
+ /**
4
+ * lib/shim/bundle/manifest.js — the bundle manifest as an ENVELOPE FERRY
5
+ * (ws-experiments-walkthrough Bite 2, CEO ruling E1).
6
+ *
7
+ * ── The rule (E1): manifest = the Module envelope minus `source` ─────────────
8
+ *
9
+ * The bundle is a projection of the `lib/shim/storage/modules.js` Module
10
+ * envelope. `experiment.js` = `module.source`. The manifest carries EVERYTHING
11
+ * ELSE from the envelope, ferried VERBATIM (`{...envelope}` minus `source`) plus
12
+ * a small set of bundle-only fields. Critically this module NEVER re-enumerates
13
+ * the envelope's field list (`{name: mod.name, renderState: mod.renderState, …}`)
14
+ * — that would be a schema mirror of modules.js. It spreads the whole envelope
15
+ * and deletes the ONE key (`source`) the sibling `experiment.js` file owns. Any
16
+ * field modules.js adds in future rides through automatically; `renderState`
17
+ * rides through as an ordinary envelope field, opaque (never parsed here).
18
+ *
19
+ * ── Bundle-only fields ───────────────────────────────────────────────────────
20
+ *
21
+ * sdkVersion : string — the `@descix/frqtl-web@<pin>` the index.html imports.
22
+ * A VALUE passed IN by the caller (the feature side
23
+ * DERIVES it from the built SDK's package.json at export
24
+ * time — truth-in-labeling; NEVER a literal in bundle
25
+ * code). REQUIRED — FAIL-LOUD when absent.
26
+ * preview : string|null — the preview image filename ref (e.g. 'preview.png'),
27
+ * or null when no preview was captured.
28
+ * descix : {} — reserved inert publish block (DeSciX now-vs-later).
29
+ *
30
+ * Layer 2 (physics): none — pure metadata projection.
31
+ */
32
+
33
+ 'use strict';
34
+
35
+ /** The envelope key the sibling `experiment.js` file owns (never in the manifest). */
36
+ export var SOURCE_KEY = 'source';
37
+
38
+ /** Bundle-only manifest keys (NOT envelope fields — stripped on import). */
39
+ export var BUNDLE_ONLY_KEYS = ['sdkVersion', 'preview', 'descix'];
40
+
41
+ /**
42
+ * Build the manifest object from a Module envelope + bundle-only inputs.
43
+ *
44
+ * @param {object} envelope — a `lib/shim/storage/modules.js` Module envelope
45
+ * (MUST carry `source`; every other field is ferried verbatim).
46
+ * @param {object} opts
47
+ * @param {string} opts.sdkVersion — REQUIRED; the CDN pin (e.g. '0.6.0-p0.1').
48
+ * @param {string|null} [opts.preview] — preview filename ref, or null/omitted.
49
+ * @returns {object} the manifest (JSON-serializable).
50
+ */
51
+ export function buildManifest(envelope, opts) {
52
+ if (!envelope || typeof envelope !== 'object') {
53
+ throw new Error('[bundle/manifest] buildManifest(envelope): envelope must be an object.');
54
+ }
55
+ opts = opts || {};
56
+ if (typeof opts.sdkVersion !== 'string' || opts.sdkVersion.length === 0) {
57
+ throw new Error('[bundle/manifest] buildManifest: opts.sdkVersion is REQUIRED (a derived value, ' +
58
+ 'never a literal) — the index.html CDN pin depends on it.');
59
+ }
60
+
61
+ // Ferry the WHOLE envelope minus `source` (no per-field re-enumeration).
62
+ var manifest = Object.assign({}, envelope);
63
+ delete manifest[SOURCE_KEY];
64
+
65
+ // Bundle-only fields.
66
+ manifest.sdkVersion = opts.sdkVersion;
67
+ manifest.preview = (opts.preview != null) ? opts.preview : null;
68
+ manifest.descix = {}; // reserved inert publish block
69
+
70
+ return manifest;
71
+ }
72
+
73
+ /**
74
+ * Recover the Module envelope from a manifest + the `experiment.js` source.
75
+ * Inverse of `buildManifest`: strips the bundle-only fields and re-attaches
76
+ * `source`. The result is a full Module envelope (validatable by modules.js).
77
+ *
78
+ * @param {object} manifest — the parsed manifest.json object.
79
+ * @param {string} source — the `experiment.js` recipe source.
80
+ * @returns {object} the reconstructed Module envelope.
81
+ */
82
+ export function manifestToEnvelope(manifest, source) {
83
+ if (!manifest || typeof manifest !== 'object') {
84
+ throw new Error('[bundle/manifest] manifestToEnvelope(manifest): manifest must be an object.');
85
+ }
86
+ if (typeof source !== 'string') {
87
+ throw new Error('[bundle/manifest] manifestToEnvelope: source (experiment.js) must be a string.');
88
+ }
89
+ var envelope = Object.assign({}, manifest);
90
+ for (var i = 0; i < BUNDLE_ONLY_KEYS.length; i++) {
91
+ delete envelope[BUNDLE_ONLY_KEYS[i]];
92
+ }
93
+ envelope[SOURCE_KEY] = source;
94
+ return envelope;
95
+ }