@johnhenry/mallory-cli 0.0.0-stage → 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.
- package/README.md +60 -2
- package/bin/mallory.mjs +51 -0
- package/package.json +51 -4
- package/src/a2a/client.js +511 -0
- package/src/a2a/demo-agent.js +396 -0
- package/src/a2a/hub.js +578 -0
- package/src/a2a/settings.js +88 -0
- package/src/a2a/task.js +358 -0
- package/src/acp/client.js +573 -0
- package/src/acp/demo-agent.js +332 -0
- package/src/acp/hub.js +632 -0
- package/src/acp/settings.js +78 -0
- package/src/actions/map.js +524 -0
- package/src/agent/cloud.js +77 -0
- package/src/agent/compact.js +84 -0
- package/src/agent/constants.js +39 -0
- package/src/agent/diff.js +101 -0
- package/src/agent/fork.js +159 -0
- package/src/agent/grounding.js +73 -0
- package/src/agent/guards.js +129 -0
- package/src/agent/local-transport.js +152 -0
- package/src/agent/loop.js +479 -0
- package/src/agent/park-store.js +77 -0
- package/src/agent/park.js +76 -0
- package/src/agent/ports.js +28 -0
- package/src/agent/providers.js +591 -0
- package/src/agent/restart.js +51 -0
- package/src/agent/router.js +380 -0
- package/src/agent/run.js +861 -0
- package/src/agent/tools.js +247 -0
- package/src/agent-library/engine.js +43 -0
- package/src/ai/bridge.js +155 -0
- package/src/ai/policy.js +131 -0
- package/src/aimatey/vendor.js +18 -0
- package/src/audio/container-duration.js +35 -0
- package/src/audio/instruments.js +776 -0
- package/src/audio/lanes.js +230 -0
- package/src/audio/patch.js +1410 -0
- package/src/audio/plan.js +276 -0
- package/src/audio/rack.js +1006 -0
- package/src/audio/sample-trim.js +293 -0
- package/src/audio/soundfont.js +243 -0
- package/src/audio/take-store.js +87 -0
- package/src/audio/takes.js +129 -0
- package/src/audio/wav.js +170 -0
- package/src/audio/zzfx.js +333 -0
- package/src/autonomy/bundle.js +207 -0
- package/src/autonomy/confine.js +61 -0
- package/src/autonomy/enforce.js +155 -0
- package/src/autonomy/file-kv.js +88 -0
- package/src/autonomy/ledger.js +203 -0
- package/src/autonomy/pins.js +50 -0
- package/src/autonomy/psl/index.js +32 -0
- package/src/autonomy/psl/suffixes.json +1 -0
- package/src/autonomy/record.js +28 -0
- package/src/autonomy/routines.js +107 -0
- package/src/autonomy/server.js +175 -0
- package/src/autonomy/signer-node.js +167 -0
- package/src/autonomy/store.js +43 -0
- package/src/autonomy/unattended.js +13 -0
- package/src/bytes/bytes.js +378 -0
- package/src/calc/syntax.js +125 -0
- package/src/calc/tex.js +28 -0
- package/src/calendar/vendor.js +2 -0
- package/src/clipboard.js +130 -0
- package/src/clsh/clsh.js +3417 -0
- package/src/codec/capnp.js +1804 -0
- package/src/codec/core.js +2043 -0
- package/src/codec/vendor/avro.js +136 -0
- package/src/codec/vendor/cbor.js +25 -0
- package/src/codec/vendor/flatbuffers.js +206 -0
- package/src/codec/vendor/msgpack.js +9 -0
- package/src/codec/vendor/protobuf.js +53 -0
- package/src/delegation/caps.js +60 -0
- package/src/delegation/config.js +32 -0
- package/src/device/model.js +246 -0
- package/src/device/recording.js +198 -0
- package/src/device/stream-model.js +151 -0
- package/src/documents/documents.js +1224 -0
- package/src/effects/catalog.js +63 -0
- package/src/effects/extras.js +133 -0
- package/src/effects/parse.js +339 -0
- package/src/embed/protocol.js +131 -0
- package/src/env/env.js +159 -0
- package/src/exact/vendor.js +45 -0
- package/src/example-meta.js +164 -0
- package/src/examples.js +94 -0
- package/src/export/canvas-image.js +217 -0
- package/src/export/expr-latex-lazy.js +8 -0
- package/src/export/formats.js +322 -0
- package/src/export/latex.js +183 -0
- package/src/export/pane.js +184 -0
- package/src/export/value.js +452 -0
- package/src/export/zip.js +214 -0
- package/src/ext/access.js +58 -0
- package/src/ext/btasks.js +225 -0
- package/src/ext/client.js +209 -0
- package/src/ext/tools.js +69 -0
- package/src/ext/view.js +105 -0
- package/src/ext/webmcp-tabs.js +299 -0
- package/src/files/archive.js +232 -0
- package/src/files/files.js +317 -0
- package/src/formats/json.js +24 -0
- package/src/formats/jupyter.js +188 -0
- package/src/formats/markdown.js +254 -0
- package/src/formats/n8n.js +276 -0
- package/src/formats/node-red.js +363 -0
- package/src/formats/registry.js +177 -0
- package/src/formats/rivet.js +259 -0
- package/src/formats/shared.js +98 -0
- package/src/formats/structure.js +182 -0
- package/src/formats/yaml.js +127 -0
- package/src/frame/frame.js +962 -0
- package/src/frame/vendor.js +1484 -0
- package/src/gate/audit.js +116 -0
- package/src/gate/gate.js +365 -0
- package/src/gate/policy.js +295 -0
- package/src/gate/scripted.js +110 -0
- package/src/gate/seams.js +32 -0
- package/src/gate/store.js +66 -0
- package/src/geometry/model.js +533 -0
- package/src/grant-key.js +149 -0
- package/src/graph/model.js +381 -0
- package/src/headless/a2a-push.js +123 -0
- package/src/headless/channels/config.js +142 -0
- package/src/headless/channels/connectors.js +283 -0
- package/src/headless/channels/index.js +257 -0
- package/src/headless/channels/mail.js +197 -0
- package/src/headless/channels/mailnet.js +223 -0
- package/src/headless/channels/platforms.js +194 -0
- package/src/headless/channels/replay.js +49 -0
- package/src/headless/cli.js +1397 -0
- package/src/headless/companion-client.js +182 -0
- package/src/headless/cost-cli.js +177 -0
- package/src/headless/deprecations-cli.js +102 -0
- package/src/headless/examples.js +48 -0
- package/src/headless/ffmpeg-exec.js +217 -0
- package/src/headless/gateways/config.js +213 -0
- package/src/headless/gateways/homeassistant.js +159 -0
- package/src/headless/gateways/index.js +121 -0
- package/src/headless/gateways/matter.js +150 -0
- package/src/headless/gateways/mqtt-client.js +177 -0
- package/src/headless/gateways/mqtt.js +70 -0
- package/src/headless/gateways/netway.js +226 -0
- package/src/headless/gateways/serverpod-worker.mjs +16 -0
- package/src/headless/gateways/serverpod.js +71 -0
- package/src/headless/gateways/util.js +27 -0
- package/src/headless/grant-cli.js +208 -0
- package/src/headless/guard.js +125 -0
- package/src/headless/guards.js +124 -0
- package/src/headless/machine-cli.js +853 -0
- package/src/headless/mcp-endpoint.js +287 -0
- package/src/headless/mcp-roots.js +38 -0
- package/src/headless/model-endpoint.js +88 -0
- package/src/headless/net.js +151 -0
- package/src/headless/node.js +263 -0
- package/src/headless/npm-tarball.js +29 -0
- package/src/headless/operator-page.js +112 -0
- package/src/headless/operator.js +242 -0
- package/src/headless/people.js +34 -0
- package/src/headless/pkg-cli.js +1103 -0
- package/src/headless/pkg-serve.js +138 -0
- package/src/headless/process-worker.js +88 -0
- package/src/headless/runner-remote.js +477 -0
- package/src/headless/sandbox-child.mjs +21 -0
- package/src/headless/scheduled.js +557 -0
- package/src/headless/serve-stream.js +97 -0
- package/src/headless/serve.js +2238 -0
- package/src/headless/short-links.js +158 -0
- package/src/headless/static-dirs.js +207 -0
- package/src/headless/trust-file.js +51 -0
- package/src/headless/watch.js +291 -0
- package/src/headless/ws-connect.js +65 -0
- package/src/headless/ws-connections.js +44 -0
- package/src/headless/ws-echo.js +150 -0
- package/src/headless/ws-proxy.js +354 -0
- package/src/headless/ws-ticket.js +48 -0
- package/src/hooks/config.js +50 -0
- package/src/hooks/engine.js +189 -0
- package/src/input/log.js +613 -0
- package/src/input/player.js +217 -0
- package/src/input/replay.js +209 -0
- package/src/jth/vendor.js +28 -0
- package/src/ledger/tx.js +94 -0
- package/src/machine/apply.js +193 -0
- package/src/machine/diff.js +168 -0
- package/src/machine/drive.js +296 -0
- package/src/machine/engine.js +478 -0
- package/src/machine/files-tool.js +76 -0
- package/src/machine/lint.js +139 -0
- package/src/machine/llmtm-trace.js +117 -0
- package/src/machine/llmtm.js +475 -0
- package/src/machine/otel.js +80 -0
- package/src/machine/pane-provider.js +51 -0
- package/src/machine/propose.js +159 -0
- package/src/machine/random.js +52 -0
- package/src/machine/risk.js +107 -0
- package/src/machine/session.js +1017 -0
- package/src/machine/shell-tool.js +45 -0
- package/src/machine/tape.js +349 -0
- package/src/machine/templates.js +104 -0
- package/src/machine/trace.js +664 -0
- package/src/machine/view.js +73 -0
- package/src/machine/vm-tool.js +47 -0
- package/src/machine/watchdog.js +46 -0
- package/src/mcp/app-args.js +51 -0
- package/src/mcp/app-run.js +56 -0
- package/src/mcp/apps.js +468 -0
- package/src/mcp/cache.js +232 -0
- package/src/mcp/client.js +507 -0
- package/src/mcp/demo-app.js +183 -0
- package/src/mcp/demo-server.js +602 -0
- package/src/mcp/elicitation.js +116 -0
- package/src/mcp/hub.js +1326 -0
- package/src/mcp/roots.js +139 -0
- package/src/mcp/sampling.js +105 -0
- package/src/mcp/settings.js +125 -0
- package/src/mcp/tape.js +292 -0
- package/src/mcp/uri-template.js +156 -0
- package/src/mcp/wsh-client.js +164 -0
- package/src/media/animated-codec.js +7 -0
- package/src/media/animated.js +623 -0
- package/src/media/compare-agent.js +70 -0
- package/src/media/compare-job.js +63 -0
- package/src/media/compare-page.js +296 -0
- package/src/media/compare-worker.js +14 -0
- package/src/media/compare.js +600 -0
- package/src/media/contract.js +62 -0
- package/src/media/decode-frame.js +57 -0
- package/src/media/decode-pool.js +188 -0
- package/src/media/ffmpeg-edit.js +344 -0
- package/src/media/ffmpeg-wasm-client.js +121 -0
- package/src/media/ffmpeg-wasm-session.js +79 -0
- package/src/media/ffmpeg-wasm.js +139 -0
- package/src/media/ffmpeg-worker.js +23 -0
- package/src/media/ffmpeg.js +903 -0
- package/src/media/helpers.js +419 -0
- package/src/media/keep.js +108 -0
- package/src/media/metadata-worker.js +16 -0
- package/src/media/metadata.js +2518 -0
- package/src/media/mime.js +102 -0
- package/src/media/page-decode.js +74 -0
- package/src/media/persist.js +114 -0
- package/src/media/png.js +226 -0
- package/src/media/sample-input.js +67 -0
- package/src/media/store.js +86 -0
- package/src/media/wav.js +109 -0
- package/src/midi/mappings.js +250 -0
- package/src/midi/message.js +125 -0
- package/src/model/action-hub.js +143 -0
- package/src/model/adapters.js +284 -0
- package/src/model/agent-runs.js +12 -0
- package/src/model/arrange.js +308 -0
- package/src/model/automation-clock.js +494 -0
- package/src/model/automation.js +653 -0
- package/src/model/batches.js +78 -0
- package/src/model/binary-view.js +195 -0
- package/src/model/breakpoints.js +392 -0
- package/src/model/calc-settings.js +65 -0
- package/src/model/calendar.js +254 -0
- package/src/model/canvas-id.js +5 -0
- package/src/model/canvas.js +5048 -0
- package/src/model/channel-names.js +29 -0
- package/src/model/channels.js +692 -0
- package/src/model/chart-clock.js +631 -0
- package/src/model/chart-code.js +69 -0
- package/src/model/codecs.js +60 -0
- package/src/model/companion-access.js +271 -0
- package/src/model/companion-pane.js +50 -0
- package/src/model/composite.js +324 -0
- package/src/model/context.js +380 -0
- package/src/model/controls.js +231 -0
- package/src/model/converter-presets.js +368 -0
- package/src/model/cost.js +580 -0
- package/src/model/curve-transform.js +122 -0
- package/src/model/cycles.js +176 -0
- package/src/model/debug-log.js +168 -0
- package/src/model/decision-clock.js +100 -0
- package/src/model/decisions.js +265 -0
- package/src/model/desk.js +87 -0
- package/src/model/device-hub.js +400 -0
- package/src/model/diff.js +445 -0
- package/src/model/emit-events.js +179 -0
- package/src/model/errors.js +238 -0
- package/src/model/event-presets.js +297 -0
- package/src/model/events.js +1303 -0
- package/src/model/explicit-setters.js +139 -0
- package/src/model/field-mapping.js +623 -0
- package/src/model/files-pane.js +263 -0
- package/src/model/flow-idle.js +89 -0
- package/src/model/foreach.js +549 -0
- package/src/model/frame-loop.js +71 -0
- package/src/model/frame-pressure.js +180 -0
- package/src/model/function-scaffold.js +1000 -0
- package/src/model/geometry-settings.js +54 -0
- package/src/model/goals.js +176 -0
- package/src/model/graph-settings.js +76 -0
- package/src/model/grid-widget.js +175 -0
- package/src/model/groups.js +332 -0
- package/src/model/hash.js +21 -0
- package/src/model/history.js +259 -0
- package/src/model/http-copy.js +88 -0
- package/src/model/http-send-companion.js +110 -0
- package/src/model/http-send.js +163 -0
- package/src/model/http-tap.js +521 -0
- package/src/model/http-tools.js +1138 -0
- package/src/model/import-lock.js +78 -0
- package/src/model/imports.js +258 -0
- package/src/model/infer-outputs.js +822 -0
- package/src/model/ink-connect.js +150 -0
- package/src/model/ink-diff.js +75 -0
- package/src/model/ink-gone.js +71 -0
- package/src/model/ink-route.js +120 -0
- package/src/model/ink-svg.js +206 -0
- package/src/model/ink.js +739 -0
- package/src/model/input-log-hub.js +456 -0
- package/src/model/input-split.js +69 -0
- package/src/model/json-schema-host.js +9 -0
- package/src/model/json-schema.js +368 -0
- package/src/model/jth.js +78 -0
- package/src/model/latex-expr.js +528 -0
- package/src/model/layout-history.js +120 -0
- package/src/model/lazy-map.js +88 -0
- package/src/model/ledger-pane.js +101 -0
- package/src/model/legacy-viaframe.js +90 -0
- package/src/model/lessons.js +448 -0
- package/src/model/links.js +981 -0
- package/src/model/live.js +411 -0
- package/src/model/math-widget.js +53 -0
- package/src/model/memory-settings.js +33 -0
- package/src/model/midi-controls.js +350 -0
- package/src/model/nl-time.js +408 -0
- package/src/model/notebook.js +137 -0
- package/src/model/pane-view-store.js +15 -0
- package/src/model/partial.js +115 -0
- package/src/model/pause-clock.js +53 -0
- package/src/model/peer-pane.js +32 -0
- package/src/model/persist-state.js +290 -0
- package/src/model/person-only.js +122 -0
- package/src/model/pin.js +209 -0
- package/src/model/plot-3d.js +213 -0
- package/src/model/plot-series.js +157 -0
- package/src/model/plot-settings.js +531 -0
- package/src/model/ports.js +312 -0
- package/src/model/presentation.js +222 -0
- package/src/model/preset-apply.js +316 -0
- package/src/model/preset-banks.js +335 -0
- package/src/model/preset-morph.js +263 -0
- package/src/model/preset-ops.js +205 -0
- package/src/model/preset-player.js +283 -0
- package/src/model/preset-states.js +172 -0
- package/src/model/profile-settings.js +109 -0
- package/src/model/promote.js +103 -0
- package/src/model/protected.js +10 -0
- package/src/model/proxy-log.js +230 -0
- package/src/model/proxy.js +367 -0
- package/src/model/quantity-widget.js +61 -0
- package/src/model/queue-book.js +359 -0
- package/src/model/quick-add.js +224 -0
- package/src/model/rate-limit.js +313 -0
- package/src/model/rate.js +95 -0
- package/src/model/recovery.js +216 -0
- package/src/model/rename-follow.js +113 -0
- package/src/model/repeater.js +1126 -0
- package/src/model/retention.js +664 -0
- package/src/model/route-edit.js +132 -0
- package/src/model/router.js +155 -0
- package/src/model/runaway.js +232 -0
- package/src/model/runlog.js +1033 -0
- package/src/model/runners/a2a.js +2 -0
- package/src/model/runners/acp.js +2 -0
- package/src/model/runners/actions.js +4 -0
- package/src/model/runners/agent.js +4 -0
- package/src/model/runners/audio.js +21 -0
- package/src/model/runners/automation.js +2 -0
- package/src/model/runners/calc.js +23 -0
- package/src/model/runners/catch.js +10 -0
- package/src/model/runners/codec.js +24 -0
- package/src/model/runners/companion-run.js +2 -0
- package/src/model/runners/device.js +7 -0
- package/src/model/runners/dom.js +13 -0
- package/src/model/runners/effects.js +2 -0
- package/src/model/runners/embed.js +11 -0
- package/src/model/runners/eval.js +2 -0
- package/src/model/runners/files.js +19 -0
- package/src/model/runners/geometry.js +23 -0
- package/src/model/runners/goals.js +18 -0
- package/src/model/runners/graph.js +23 -0
- package/src/model/runners/html.js +2 -0
- package/src/model/runners/http-proxy.js +185 -0
- package/src/model/runners/http-send.js +61 -0
- package/src/model/runners/http-static.js +83 -0
- package/src/model/runners/http-tap.js +26 -0
- package/src/model/runners/http.js +40 -0
- package/src/model/runners/import.js +2 -0
- package/src/model/runners/index.js +74 -0
- package/src/model/runners/input.js +14 -0
- package/src/model/runners/inputlog.js +7 -0
- package/src/model/runners/ledger.js +15 -0
- package/src/model/runners/machine.js +4 -0
- package/src/model/runners/mcp.js +2 -0
- package/src/model/runners/mcpapp.js +2 -0
- package/src/model/runners/media.js +18 -0
- package/src/model/runners/memory.js +28 -0
- package/src/model/runners/mesh-inspect.js +13 -0
- package/src/model/runners/peer.js +14 -0
- package/src/model/runners/plot.js +22 -0
- package/src/model/runners/render.js +14 -0
- package/src/model/runners/respond.js +2 -0
- package/src/model/runners/sample-soundfont.js +85 -0
- package/src/model/runners/sample.js +159 -0
- package/src/model/runners/scene.js +8 -0
- package/src/model/runners/score.js +24 -0
- package/src/model/runners/secret.js +10 -0
- package/src/model/runners/select.js +2 -0
- package/src/model/runners/shared.js +4 -0
- package/src/model/runners/shares.js +15 -0
- package/src/model/runners/shell.js +7 -0
- package/src/model/runners/skill.js +26 -0
- package/src/model/runners/state.js +2 -0
- package/src/model/runners/statechart.js +4 -0
- package/src/model/runners/subgraph.js +9 -0
- package/src/model/runners/tabs.js +25 -0
- package/src/model/runners/terminal.js +5 -0
- package/src/model/runners/text.js +4 -0
- package/src/model/runners/timer.js +7 -0
- package/src/model/runners/traffic.js +65 -0
- package/src/model/runners/trigger.js +2 -0
- package/src/model/runners/verdict.js +29 -0
- package/src/model/runners/vm.js +7 -0
- package/src/model/runners/wait.js +4 -0
- package/src/model/runners/ws-client.js +57 -0
- package/src/model/safe-regex.js +719 -0
- package/src/model/sample-settings.js +43 -0
- package/src/model/sample-source.js +47 -0
- package/src/model/saved-mapping.js +153 -0
- package/src/model/score-controllers.js +87 -0
- package/src/model/score-edit.js +399 -0
- package/src/model/score-instruments.js +300 -0
- package/src/model/score-library.js +407 -0
- package/src/model/score-markup.js +235 -0
- package/src/model/score-mix.js +248 -0
- package/src/model/score-patterns.js +276 -0
- package/src/model/score-selection.js +34 -0
- package/src/model/score-time.js +139 -0
- package/src/model/score-transforms.js +336 -0
- package/src/model/score-transport.js +192 -0
- package/src/model/selection.js +351 -0
- package/src/model/serial-controls.js +328 -0
- package/src/model/shares-pane.js +17 -0
- package/src/model/shell-pane.js +106 -0
- package/src/model/signature.js +1122 -0
- package/src/model/size-hints.js +106 -0
- package/src/model/size-ratio.js +12 -0
- package/src/model/skill-settings.js +23 -0
- package/src/model/snapping.js +466 -0
- package/src/model/split.js +375 -0
- package/src/model/spring-player.js +222 -0
- package/src/model/statecharts.js +1369 -0
- package/src/model/states-preset.js +208 -0
- package/src/model/static-route.js +100 -0
- package/src/model/step-words.js +45 -0
- package/src/model/subgraph.js +1042 -0
- package/src/model/switch.js +98 -0
- package/src/model/tabs-store.js +10 -0
- package/src/model/tensor-view.js +146 -0
- package/src/model/timer-clock.js +361 -0
- package/src/model/timers.js +422 -0
- package/src/model/timing.js +212 -0
- package/src/model/traffic-agent.js +111 -0
- package/src/model/traffic-store.js +20 -0
- package/src/model/traffic.js +665 -0
- package/src/model/transport.js +364 -0
- package/src/model/turns.js +86 -0
- package/src/model/types.js +425 -0
- package/src/model/value-path.js +138 -0
- package/src/model/versions.js +535 -0
- package/src/model/view-outputs.js +144 -0
- package/src/model/viewport-bookmarks.js +194 -0
- package/src/model/virtual-clock.js +85 -0
- package/src/model/vm-pane.js +258 -0
- package/src/model/wait-clock.js +715 -0
- package/src/model/wait-persist.js +248 -0
- package/src/model/waits.js +431 -0
- package/src/model/watch.js +80 -0
- package/src/model/webhook.js +496 -0
- package/src/model/when.js +48 -0
- package/src/model/widget-values.js +392 -0
- package/src/model/window-commands.js +278 -0
- package/src/model/windows.js +348 -0
- package/src/model/wire-inspect.js +343 -0
- package/src/model/wire-ops.js +324 -0
- package/src/model/wire-pipeline.js +378 -0
- package/src/model/wire-route.js +637 -0
- package/src/model/workspaces.js +122 -0
- package/src/model/ws-client.js +155 -0
- package/src/model/ws-demo.js +31 -0
- package/src/model/ws-frames.js +141 -0
- package/src/model/ws-hub.js +219 -0
- package/src/model/ws-served.js +13 -0
- package/src/model/xstate.js +374 -0
- package/src/narrative/narrative.js +1557 -0
- package/src/network/auth.js +224 -0
- package/src/network/csp-frame.js +197 -0
- package/src/network/declarative-shadow.js +27 -0
- package/src/network/frame-net-shim.js +962 -0
- package/src/network/hosts.js +157 -0
- package/src/network/policy.js +520 -0
- package/src/network/rtc-shim.js +418 -0
- package/src/network/secret-gate.js +78 -0
- package/src/network/secrets.js +261 -0
- package/src/network/sockets.js +287 -0
- package/src/network/store.js +186 -0
- package/src/network/streams.js +99 -0
- package/src/packages/asset-values.js +50 -0
- package/src/packages/assets.js +99 -0
- package/src/packages/deprecation.js +203 -0
- package/src/packages/fetch.js +152 -0
- package/src/packages/function-canvas.js +73 -0
- package/src/packages/module.js +120 -0
- package/src/packages/package.js +474 -0
- package/src/packages/published.js +27 -0
- package/src/packages/requires.js +83 -0
- package/src/packages/signing.js +145 -0
- package/src/packages/trust.js +107 -0
- package/src/panes/a2a.js +51 -0
- package/src/panes/acp.js +60 -0
- package/src/panes/actions.js +54 -0
- package/src/panes/agent.js +83 -0
- package/src/panes/audio.js +103 -0
- package/src/panes/automation.js +112 -0
- package/src/panes/calc.js +67 -0
- package/src/panes/catch.js +52 -0
- package/src/panes/codec.js +59 -0
- package/src/panes/colors.js +12 -0
- package/src/panes/companion.js +54 -0
- package/src/panes/decision.js +65 -0
- package/src/panes/device.js +56 -0
- package/src/panes/dom.js +37 -0
- package/src/panes/effects.js +118 -0
- package/src/panes/embed.js +30 -0
- package/src/panes/eval.js +186 -0
- package/src/panes/fields.js +299 -0
- package/src/panes/files.js +45 -0
- package/src/panes/gate.js +70 -0
- package/src/panes/geometry.js +64 -0
- package/src/panes/goals.js +75 -0
- package/src/panes/graph.js +66 -0
- package/src/panes/html.js +54 -0
- package/src/panes/http.js +82 -0
- package/src/panes/import.js +38 -0
- package/src/panes/input.js +124 -0
- package/src/panes/inputlog.js +66 -0
- package/src/panes/ledger.js +56 -0
- package/src/panes/machine.js +138 -0
- package/src/panes/mcp.js +85 -0
- package/src/panes/mcpapp.js +64 -0
- package/src/panes/media.js +38 -0
- package/src/panes/memory.js +46 -0
- package/src/panes/mesh-inspect.js +49 -0
- package/src/panes/note.js +38 -0
- package/src/panes/peer.js +44 -0
- package/src/panes/plot.js +196 -0
- package/src/panes/registry.js +475 -0
- package/src/panes/render.js +87 -0
- package/src/panes/respond.js +44 -0
- package/src/panes/router.js +84 -0
- package/src/panes/sample.js +75 -0
- package/src/panes/scene.js +55 -0
- package/src/panes/score.js +87 -0
- package/src/panes/secret.js +38 -0
- package/src/panes/select.js +67 -0
- package/src/panes/shader.js +166 -0
- package/src/panes/shared.js +33 -0
- package/src/panes/shares.js +43 -0
- package/src/panes/shell.js +47 -0
- package/src/panes/skill.js +44 -0
- package/src/panes/state.js +91 -0
- package/src/panes/statechart.js +63 -0
- package/src/panes/story.js +33 -0
- package/src/panes/subgraph.js +94 -0
- package/src/panes/tabs.js +52 -0
- package/src/panes/terminal.js +57 -0
- package/src/panes/text.js +36 -0
- package/src/panes/timer.js +55 -0
- package/src/panes/traffic.js +59 -0
- package/src/panes/verdict.js +62 -0
- package/src/panes/vm.js +46 -0
- package/src/panes/wait.js +61 -0
- package/src/panes/watch.js +57 -0
- package/src/panes/webhook.js +67 -0
- package/src/panes/ws-client.js +67 -0
- package/src/persist.js +281 -0
- package/src/plot/tex.js +19 -0
- package/src/plot/vendor.js +59 -0
- package/src/plot/view-vendor.js +5 -0
- package/src/privacy/levels.js +108 -0
- package/src/protocol/devtools.js +116 -0
- package/src/protocol/inspector.js +368 -0
- package/src/render/time.js +381 -0
- package/src/rooms/mesh-metrics.js +162 -0
- package/src/run/companion.js +355 -0
- package/src/run/describe.js +114 -0
- package/src/run/local-model.js +150 -0
- package/src/run/monitor.js +208 -0
- package/src/run/publish.js +360 -0
- package/src/run/respond-outcome.js +12 -0
- package/src/run/run.js +820 -0
- package/src/run/runner-pairing.js +243 -0
- package/src/run/values.js +122 -0
- package/src/runtime/compile.js +122 -0
- package/src/runtime/console-tag.js +64 -0
- package/src/runtime/frame-signals.js +126 -0
- package/src/runtime/iteration-push.js +19 -0
- package/src/runtime/keys.js +474 -0
- package/src/runtime/midi-input.js +170 -0
- package/src/runtime/person-waits.js +140 -0
- package/src/runtime/resource-timing.js +56 -0
- package/src/runtime/runtime.js +2150 -0
- package/src/runtime/sandbox-modules.js +163 -0
- package/src/runtime/spring.js +246 -0
- package/src/runtime/strict.js +215 -0
- package/src/runtime/transfer.js +75 -0
- package/src/runtime/tween.js +158 -0
- package/src/runtime/wasm-fuel.js +596 -0
- package/src/runtime/worker/00-prelude.js +88 -0
- package/src/runtime/worker/10-helpers.js +295 -0
- package/src/runtime/worker/20-io.js +645 -0
- package/src/runtime/worker/30-previews.js +210 -0
- package/src/runtime/worker/40-profile-lineage.js +278 -0
- package/src/runtime/worker/50-own-worker.js +233 -0
- package/src/runtime/worker/60-timers.js +172 -0
- package/src/runtime/worker/70-state-keyed.js +193 -0
- package/src/runtime/worker/80-each-compile-generators.js +619 -0
- package/src/runtime/worker/90-events-operators.js +655 -0
- package/src/runtime/worker/95-agents-batches.js +1820 -0
- package/src/runtime/worker/96-plot.js +47 -0
- package/src/runtime/worker/97-calc.js +28 -0
- package/src/runtime/worker/98-geometry.js +24 -0
- package/src/runtime/worker/99-graph.js +30 -0
- package/src/runtime/worker/99-shell.js +30 -0
- package/src/safety/config.js +57 -0
- package/src/safety/engine.js +324 -0
- package/src/scene/pixi-scene.js +806 -0
- package/src/scene/scene-assets.js +241 -0
- package/src/scene/scene-edit.js +319 -0
- package/src/secret/settings.js +41 -0
- package/src/security/multipart.js +257 -0
- package/src/security/redact.js +261 -0
- package/src/serial/broker.js +473 -0
- package/src/serial/config.js +185 -0
- package/src/serial/framers.js +389 -0
- package/src/serial/packets.js +64 -0
- package/src/shader/audio-texture.js +87 -0
- package/src/shader/channels.js +496 -0
- package/src/shader/common.js +90 -0
- package/src/shader/model.js +867 -0
- package/src/shader/passes.js +150 -0
- package/src/shader/shadertoy.js +198 -0
- package/src/shell/hub.js +287 -0
- package/src/sim/checkpoints.js +850 -0
- package/src/sim/compile.js +37 -0
- package/src/sim/fixed.js +377 -0
- package/src/sim/headless.js +205 -0
- package/src/sim/physics.js +399 -0
- package/src/smf-helper/vendor.js +2 -0
- package/src/sources/config.js +435 -0
- package/src/storage.js +153 -0
- package/src/table/table-geo.js +2344 -0
- package/src/table/table-lineage.js +808 -0
- package/src/table/table-quality.js +355 -0
- package/src/table/table-schema.js +392 -0
- package/src/table/table-sql.js +1650 -0
- package/src/table/table-stats.js +480 -0
- package/src/table/table.js +2102 -0
- package/src/tensor/tensor.js +1153 -0
- package/src/terminal/hub.js +715 -0
- package/src/terminal/screen.js +516 -0
- package/src/tests/capture.js +88 -0
- package/src/tests/compare.js +480 -0
- package/src/tests/dataset.js +170 -0
- package/src/tests/evaluate.js +286 -0
- package/src/tests/from-runs.js +99 -0
- package/src/tests/judge.js +134 -0
- package/src/tests/matchers.js +263 -0
- package/src/tests/matrix-spec.js +87 -0
- package/src/tests/matrix.js +397 -0
- package/src/tests/metrics.js +369 -0
- package/src/tests/no-value.js +42 -0
- package/src/tests/pane-check.js +45 -0
- package/src/tests/report.js +124 -0
- package/src/tests/reporters.js +140 -0
- package/src/tests/run.js +155 -0
- package/src/tilemap/tilemap.js +1122 -0
- package/src/units/units.js +3 -0
- package/src/util/bytes-text.js +21 -0
- package/src/util/num.js +10 -0
- package/src/util/regexp.js +2 -0
- package/src/util/text.js +38 -0
- package/src/verdict/engine.js +154 -0
- package/src/vm/guest-wsh.js +108 -0
- package/src/vm/hub.js +457 -0
- package/src/vm/image-files.js +4 -0
- package/src/vm/image.js +33 -0
- package/src/vm/image.lock.json +13 -0
- package/src/vm/link.js +266 -0
- package/src/vm/mount.js +212 -0
- package/src/vm/net.js +85 -0
- package/src/vm/pipe-ws.js +187 -0
- package/src/vm/v86-loader.js +11 -0
- package/src/webmcp/args.js +212 -0
- package/src/webmcp/hidden.js +218 -0
- package/src/webmcp/text.js +250 -0
- package/src/webmcp/tools/bookmark-tools.js +106 -0
- package/src/webmcp/tools/breakpoint-tools.js +48 -0
- package/src/webmcp/tools/canvases.js +208 -0
- package/src/webmcp/tools/context-tools.js +84 -0
- package/src/webmcp/tools/core.js +170 -0
- package/src/webmcp/tools/devices.js +41 -0
- package/src/webmcp/tools/edit.js +357 -0
- package/src/webmcp/tools/event-tools.js +145 -0
- package/src/webmcp/tools/image-tools.js +173 -0
- package/src/webmcp/tools/ink-tools.js +247 -0
- package/src/webmcp/tools/input-log-tools.js +163 -0
- package/src/webmcp/tools/live.js +166 -0
- package/src/webmcp/tools/machine-tools.js +74 -0
- package/src/webmcp/tools/media.js +161 -0
- package/src/webmcp/tools/midi-tools.js +32 -0
- package/src/webmcp/tools/preset-tools.js +184 -0
- package/src/webmcp/tools/quick-add-tools.js +95 -0
- package/src/webmcp/tools/reshape.js +152 -0
- package/src/webmcp/tools/run-tools.js +309 -0
- package/src/webmcp/tools/runs.js +101 -0
- package/src/webmcp/tools/scaffold-tools.js +161 -0
- package/src/webmcp/tools/serial-tools.js +36 -0
- package/src/webmcp/tools/shared.js +338 -0
- package/src/webmcp/tools/subgraphs.js +360 -0
- package/src/webmcp/tools/tests.js +170 -0
- package/src/webmcp/tools/traffic-tools.js +70 -0
- package/src/webmcp/tools/transport-tools.js +65 -0
- package/src/webmcp/tools/version-tools.js +126 -0
- package/src/webmcp/tools/versions.js +11 -0
- package/src/webmcp/tools/wire-tools.js +90 -0
- package/src/webmcp/tools/workspace-tools.js +93 -0
- package/src/webmcp/tools.js +1323 -0
- package/src/wsh/connect.js +347 -0
- package/src/wsh/demo-host.js +361 -0
- package/src/wsh/e2e.js +27 -0
- package/src/wsh/keys.js +154 -0
- package/src/wsh/known-hosts.js +39 -0
- package/src/wsh/private-key.js +95 -0
- package/src/wsh/reverse.js +34 -0
- package/src/wsh/settings.js +118 -0
- package/src/wsh/transfer.js +62 -0
- package/src/wsh/vendor.js +5 -0
- package/src/x402/challenge.js +171 -0
- package/src/x402/demo-server.js +127 -0
- package/src/x402/pay.js +125 -0
- package/src/x402/retry.js +95 -0
- package/src/x402/store.js +76 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// Implicit adapters at typed inputs.
|
|
2
|
+
//
|
|
3
|
+
// A typed input (a shader uniform, sampler or data channel, an effects pane's picture, an audio patch's sample input) states what it accepts. A value of
|
|
4
|
+
// another well-known kind is converted for it, and only when the conversion is lossless or obvious:
|
|
5
|
+
//
|
|
6
|
+
// pixels { width, height, data } (RGBA8) → image (encoded as a PNG)
|
|
7
|
+
// bytes that start like a PNG, JPEG, GIF or WebP → image (the same bytes, typed)
|
|
8
|
+
// a number → vec2 / vec3 / vec4 (the same value in every component)
|
|
9
|
+
// { x, y, z, w } or { r, g, b, a } → vecN / color
|
|
10
|
+
// 0 or 1 → bool; numeric text → number
|
|
11
|
+
// a keyboard device's state { held, pressed, toggled } → Shadertoy's 256×3 keyboard texture (at a data channel)
|
|
12
|
+
// PCM { channels, sampleRate }, audio-file bytes, a base64 data: URL → audio (at a sample input; the frame decodes it)
|
|
13
|
+
//
|
|
14
|
+
// The input row names the conversion that was done ("pixels 64×64 → image"), so nothing happens out of sight.
|
|
15
|
+
// Anything else fails and says which converter preset to add (+ add → converters): a conversion that loses
|
|
16
|
+
// something or needs a decision (a list of numbers as a texture, float pixels, bytes of no known picture
|
|
17
|
+
// type) is a pane you can see and edit, not a guess.
|
|
18
|
+
//
|
|
19
|
+
// Pure: no DOM, no canvas, no imports. It runs under node --test, in the page and in the headless runner.
|
|
20
|
+
|
|
21
|
+
/** The converter presets that exist to do what an implicit adapter will not (names as "+ add → converters" lists them). */
|
|
22
|
+
export const CONVERTERS = {
|
|
23
|
+
imagePixels: "image ↔ pixels",
|
|
24
|
+
dataTexture: "pixels ↔ data texture",
|
|
25
|
+
tableToFloat32: "table of numbers → Float32Array",
|
|
26
|
+
audioPcm: "audio ↔ PCM",
|
|
27
|
+
pcmWav: "PCM → WAV",
|
|
28
|
+
bytesText: "bytes ↔ hex/base64/text",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** "add the "image ↔ pixels" converter (+ add → converters)". */
|
|
32
|
+
export const converterHint = (preset) => `add the "${CONVERTERS[preset] ?? preset}" converter (+ add → converters)`;
|
|
33
|
+
|
|
34
|
+
const tagOf = (v) => Object.prototype.toString.call(v).slice(8, -1);
|
|
35
|
+
const isBlob = (v) => typeof Blob !== "undefined" && v instanceof Blob;
|
|
36
|
+
const isMediaValue = (v) => Boolean(v) && typeof v === "object" && typeof v.$media === "string";
|
|
37
|
+
const BYTE_VIEWS = ["Uint8Array", "Uint8ClampedArray"];
|
|
38
|
+
const NUMBER_VIEWS = ["Float32Array", "Float64Array", "Int8Array", "Int16Array", "Int32Array", "Uint16Array", "Uint32Array"];
|
|
39
|
+
|
|
40
|
+
/** Is `value` RGBA8 pixels, `{ width, height, data }` with 4 bytes a pixel (ImageData is)? */
|
|
41
|
+
export const isPixels = (value) =>
|
|
42
|
+
Boolean(value) && typeof value === "object" && Number.isInteger(value.width) && Number.isInteger(value.height) && value.width > 0 && value.height > 0 && ArrayBuffer.isView(value.data) && BYTE_VIEWS.includes(tagOf(value.data)) && value.data.length === value.width * value.height * 4;
|
|
43
|
+
|
|
44
|
+
/** The image type the first bytes say (PNG, JPEG, GIF, WebP), or "". */
|
|
45
|
+
export function imageTypeOfBytes(bytes) {
|
|
46
|
+
const b = bytes;
|
|
47
|
+
if (b.length >= 8 && b[0] === 0x89 && b[1] === 0x50 && b[2] === 0x4e && b[3] === 0x47 && b[4] === 0x0d && b[5] === 0x0a && b[6] === 0x1a && b[7] === 0x0a) return "image/png";
|
|
48
|
+
if (b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff) return "image/jpeg";
|
|
49
|
+
if (b.length >= 6 && b[0] === 0x47 && b[1] === 0x49 && b[2] === 0x46 && b[3] === 0x38) return "image/gif";
|
|
50
|
+
if (b.length >= 12 && b[0] === 0x52 && b[1] === 0x49 && b[2] === 0x46 && b[3] === 0x46 && b[8] === 0x57 && b[9] === 0x45 && b[10] === 0x42 && b[11] === 0x50) return "image/webp";
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const bytesOf = (value) => (value instanceof ArrayBuffer ? new Uint8Array(value) : new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* What a value is, for a decision and a message: `{ kind, words }`. Kinds: image, audio, video, file (media values
|
|
58
|
+
* and Blobs), pixels, bytes, numbers (a list or typed array of numbers), number, boolean, text, list, object, nothing.
|
|
59
|
+
*/
|
|
60
|
+
export function describeValue(value) {
|
|
61
|
+
if (value === null || value === undefined) return { kind: "nothing", words: "nothing" };
|
|
62
|
+
if (isMediaValue(value)) return { kind: ["image", "audio", "video"].includes(value.$media) ? value.$media : "file", words: value.$media === "image" ? "an image" : value.$media === "audio" ? "audio" : value.$media === "video" ? "a video" : "a file" };
|
|
63
|
+
if (isBlob(value)) {
|
|
64
|
+
const top = String(value.type).split("/")[0];
|
|
65
|
+
const kind = ["image", "audio", "video"].includes(top) ? top : "file";
|
|
66
|
+
return { kind, words: kind === "image" ? "an image" : kind === "audio" ? "audio" : kind === "video" ? "a video" : "a file" };
|
|
67
|
+
}
|
|
68
|
+
if (typeof value === "number") return { kind: "number", words: "a number" };
|
|
69
|
+
if (typeof value === "boolean") return { kind: "boolean", words: "true or false" };
|
|
70
|
+
if (typeof value === "string") return { kind: "text", words: "text" };
|
|
71
|
+
if (isKeyboardState(value)) return { kind: "keyboard", words: "keyboard state" };
|
|
72
|
+
if (isPixels(value)) return { kind: "pixels", words: `pixels ${value.width}×${value.height}` };
|
|
73
|
+
if (value instanceof ArrayBuffer || (ArrayBuffer.isView(value) && BYTE_VIEWS.includes(tagOf(value)))) return { kind: "bytes", words: `${bytesOf(value).length} bytes` };
|
|
74
|
+
if (ArrayBuffer.isView(value) && NUMBER_VIEWS.includes(tagOf(value))) return { kind: "numbers", words: `a ${tagOf(value)} of ${value.length} numbers` };
|
|
75
|
+
if (Array.isArray(value)) return value.length && value.every((n) => typeof n === "number") ? { kind: "numbers", words: `a list of ${value.length} numbers` } : { kind: "list", words: "a list" };
|
|
76
|
+
if (typeof value === "object" && typeof value.width === "number" && typeof value.height === "number" && "data" in value) return { kind: "other-pixels", words: `pixel data ${value.width}×${value.height} that is not RGBA8` };
|
|
77
|
+
if (typeof value === "object") return { kind: "object", words: "an object" };
|
|
78
|
+
return { kind: typeof value, words: `a ${typeof value}` };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ── images ─────────────────────────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Can an image input take `value`? `{ ok: true, via?, convert? }` (`via`: the conversion in words, none when the
|
|
85
|
+
* value already is an image; `convert`: how to make it an image Blob, "pixels" or "bytes") or `{ ok: false, problem }`
|
|
86
|
+
* saying what it is and, when a converter preset does the job, which one to add.
|
|
87
|
+
*/
|
|
88
|
+
export function adaptImage(value) {
|
|
89
|
+
const d = describeValue(value);
|
|
90
|
+
if (d.kind === "image") return { ok: true };
|
|
91
|
+
if (d.kind === "pixels") return { ok: true, via: `${d.words} → image`, convert: "pixels" };
|
|
92
|
+
if (d.kind === "bytes") {
|
|
93
|
+
const type = imageTypeOfBytes(bytesOf(value));
|
|
94
|
+
if (type) return { ok: true, via: `bytes (${type.split("/")[1].toUpperCase()}) → image`, convert: "bytes", type };
|
|
95
|
+
return { ok: false, problem: `${d.words} that don't start like a PNG, JPEG, GIF or WebP picture, not an image: ${converterHint("imagePixels")}, or ${converterHint("bytesText")} to look at them` };
|
|
96
|
+
}
|
|
97
|
+
if (d.kind === "numbers" || d.kind === "number") return { ok: false, problem: `${d.words}, not an image: ${converterHint("dataTexture")} to make a texture from numbers, or ${converterHint("tableToFloat32")}` };
|
|
98
|
+
if (d.kind === "other-pixels") return { ok: false, problem: `${d.words}, not an image: ${converterHint("dataTexture")} for float data, or ${converterHint("imagePixels")}` };
|
|
99
|
+
if (d.kind === "audio") return { ok: false, problem: `audio, not an image: ${converterHint("audioPcm")} to get its samples, then draw them` };
|
|
100
|
+
if (d.kind === "keyboard") return { ok: false, problem: "keyboard state, not an image: wire it to a channel that takes data (as auto or numbers), where it is the 256×3 keyboard texture" };
|
|
101
|
+
if (d.kind === "video" || d.kind === "file") return { ok: false, problem: `${d.words}, not an image` };
|
|
102
|
+
return { ok: false, problem: `${d.words}, not an image` };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** An image Blob from a value `adaptImage` accepted by converting (`encode(pixels)` makes the PNG bytes: the page's encoder). */
|
|
106
|
+
export async function toImageBlob(value, adapted, encode) {
|
|
107
|
+
if (adapted.convert === "pixels") {
|
|
108
|
+
const png = await encode({ width: value.width, height: value.height, data: value.data });
|
|
109
|
+
return new Blob([png], { type: "image/png" });
|
|
110
|
+
}
|
|
111
|
+
if (adapted.convert === "bytes") return new Blob([bytesOf(value)], { type: adapted.type });
|
|
112
|
+
throw new TypeError("nothing to convert");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Make the image inputs of a pane image media values: `names` are the inputs that take a picture. A value an
|
|
117
|
+
* adapter converts (pixels, picture bytes) is replaced by a media image; the rest are left for the pane to refuse.
|
|
118
|
+
* `inputs` is not changed. `{ inputs, adapted: [{ name, from, to, label }] }`.
|
|
119
|
+
*/
|
|
120
|
+
export async function adaptImageInputs(names, inputs, encode) {
|
|
121
|
+
const out = { ...inputs };
|
|
122
|
+
const adapted = [];
|
|
123
|
+
for (const name of names) {
|
|
124
|
+
const value = inputs[name];
|
|
125
|
+
if (value === undefined || value === null) continue;
|
|
126
|
+
const found = adaptImage(value);
|
|
127
|
+
if (!found.ok || !found.convert) continue;
|
|
128
|
+
const blob = await toImageBlob(value, found, encode);
|
|
129
|
+
out[name] = { $media: "image", blob, name: `${name}.${found.type ? found.type.split("/")[1] : "png"}` };
|
|
130
|
+
adapted.push({ name, from: describeValue(value).kind, to: "image", label: found.via });
|
|
131
|
+
}
|
|
132
|
+
return { inputs: out, adapted };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ── numbers ────────────────────────────────────────────────────────────────
|
|
136
|
+
|
|
137
|
+
const COMPONENTS = { vec2: 2, vec3: 3, vec4: 4, color: 4 };
|
|
138
|
+
const finiteNumber = (n) => typeof n === "number" && Number.isFinite(n);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The conversion a number-like uniform makes of `value` (one the uniform's own coercion accepts: src/shader/model.js
|
|
142
|
+
* `coerce`), in words, or "" when the value already is what the uniform holds. The input row shows it.
|
|
143
|
+
*/
|
|
144
|
+
export function numberVia(type, value) {
|
|
145
|
+
const n = COMPONENTS[type];
|
|
146
|
+
switch (type) {
|
|
147
|
+
case "float":
|
|
148
|
+
case "int":
|
|
149
|
+
return typeof value === "string" ? "text → number" : "";
|
|
150
|
+
case "bool":
|
|
151
|
+
return typeof value === "number" ? "number → bool" : "";
|
|
152
|
+
case "vec2":
|
|
153
|
+
case "vec3":
|
|
154
|
+
case "vec4":
|
|
155
|
+
if (typeof value === "number") return `number → ${type}`;
|
|
156
|
+
return value && typeof value === "object" && !Array.isArray(value) ? `{${"xyzw".slice(0, n).split("").join(", ")}} → ${type}` : "";
|
|
157
|
+
case "color":
|
|
158
|
+
if (Array.isArray(value)) return value.length === 3 ? "[r, g, b] → color" : "";
|
|
159
|
+
return value && typeof value === "object" ? "{r, g, b} → color" : "";
|
|
160
|
+
default:
|
|
161
|
+
return "";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** A short pointer to add to a number-like uniform's refusal of `value`, or "". */
|
|
166
|
+
export function numberHint(type, value) {
|
|
167
|
+
const d = describeValue(value);
|
|
168
|
+
if (type === "int" && finiteNumber(value) && !Number.isInteger(value)) return "round it first (an eval pane with Math.round), or make the uniform a float";
|
|
169
|
+
if ((type === "float" || type === "int" || type === "bool") && d.kind === "numbers") return `pick one number out of ${d.words} first, or declare a vec uniform for it`;
|
|
170
|
+
if (["float", "int", "vec2", "vec3", "vec4", "color"].includes(type) && d.kind === "bytes") return `${converterHint("bytesText")} to read them as numbers`;
|
|
171
|
+
if (type === "bool" && finiteNumber(value)) return "a bool takes true, false, 0 or 1";
|
|
172
|
+
return "";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The adapted-input records of a resolved uniform list: `[{ name, from, to, label }]` for each input a conversion was done on. */
|
|
176
|
+
export const numberAdaptations = (decls, inputs) =>
|
|
177
|
+
decls.flatMap((d) => {
|
|
178
|
+
if (d.type === "sampler" || !Object.hasOwn(inputs, d.name) || inputs[d.name] === undefined) return [];
|
|
179
|
+
const label = numberVia(d.type, inputs[d.name]);
|
|
180
|
+
return label ? [{ name: d.name, from: describeValue(inputs[d.name]).kind, to: d.type, label }] : [];
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// ── audio ──────────────────────────────────────────────────────────────────
|
|
184
|
+
|
|
185
|
+
/** The audio type the first bytes say (WAV, MP3, Ogg, FLAC, AAC/MP4, WebM, AIFF), or "". */
|
|
186
|
+
export function audioTypeOfBytes(bytes) {
|
|
187
|
+
const b = bytes;
|
|
188
|
+
const ascii = (at, text) => b.length >= at + text.length && [...text].every((c, i) => b[at + i] === c.charCodeAt(0));
|
|
189
|
+
if (ascii(0, "RIFF") && ascii(8, "WAVE")) return "audio/wav";
|
|
190
|
+
if (ascii(0, "ID3") || (b.length >= 2 && b[0] === 0xff && (b[1] & 0xe0) === 0xe0 && (b[1] & 0x06) !== 0)) return "audio/mpeg";
|
|
191
|
+
if (ascii(0, "OggS")) return "audio/ogg";
|
|
192
|
+
if (ascii(0, "fLaC")) return "audio/flac";
|
|
193
|
+
if (ascii(4, "ftyp")) return "audio/mp4";
|
|
194
|
+
if (b.length >= 2 && b[0] === 0xff && (b[1] & 0xf6) === 0xf0) return "audio/aac";
|
|
195
|
+
if (b.length >= 4 && b[0] === 0x1a && b[1] === 0x45 && b[2] === 0xdf && b[3] === 0xa3) return "audio/webm";
|
|
196
|
+
if (ascii(0, "FORM") && (ascii(8, "AIFF") || ascii(8, "AIFC"))) return "audio/aiff";
|
|
197
|
+
return "";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const AUDIO_NAMES = { "audio/wav": "WAV", "audio/mpeg": "MP3", "audio/ogg": "Ogg", "audio/flac": "FLAC", "audio/mp4": "MP4", "audio/aac": "AAC", "audio/webm": "WebM", "audio/aiff": "AIFF" };
|
|
201
|
+
const rateText = (hz) => `${Number((hz / 1000).toFixed(3))} kHz`;
|
|
202
|
+
const isPcm = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v) && !ArrayBuffer.isView(v) && (Array.isArray(v.channels) || v.samples !== undefined);
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Can an audio sample input (a DSP patch's sample module reads one) take `value`? `{ ok: true, via? }` (`via`: the conversion
|
|
206
|
+
* in words, none when the value already is audio) or `{ ok: false, problem }` naming the converter to add. The conversion
|
|
207
|
+
* itself is the audio frame's (src/audio/modules.js decodeSample): this decides and says it, so the input row shows it and a
|
|
208
|
+
* value that would fail there fails here first with a pointer. Bytes of no known audio type are left to the browser's decoder.
|
|
209
|
+
*/
|
|
210
|
+
export function adaptAudio(value) {
|
|
211
|
+
const d = describeValue(value);
|
|
212
|
+
if (d.kind === "audio") return { ok: true };
|
|
213
|
+
if (d.kind === "video") return { ok: true, via: "a video → audio (its sound track)" };
|
|
214
|
+
if (typeof value === "string" && /^data:/i.test(value)) {
|
|
215
|
+
const type = /^data:([^,;]*)/i.exec(value)[1] || "audio";
|
|
216
|
+
return { ok: true, via: `data: URL (${type}) → audio` };
|
|
217
|
+
}
|
|
218
|
+
if (isPcm(value)) {
|
|
219
|
+
const channels = value.channels ?? [value.samples];
|
|
220
|
+
if (typeof value.sampleRate !== "number") return { ok: false, problem: `PCM with no sampleRate, not audio: give { channels, sampleRate }, or ${converterHint("pcmWav")}` };
|
|
221
|
+
const frames = channels[0]?.length ?? 0;
|
|
222
|
+
return { ok: true, via: `PCM ${channels.length} channel${channels.length === 1 ? "" : "s"} × ${frames} at ${rateText(value.sampleRate)} → audio`, from: "pcm" };
|
|
223
|
+
}
|
|
224
|
+
if (d.kind === "bytes") {
|
|
225
|
+
const type = audioTypeOfBytes(bytesOf(value));
|
|
226
|
+
return { ok: true, via: type ? `bytes (${AUDIO_NAMES[type]}) → audio` : `${d.words} → audio (decoded by the browser)` };
|
|
227
|
+
}
|
|
228
|
+
if (d.kind === "numbers") return { ok: false, problem: `${d.words}, samples with no sample rate: ${converterHint("pcmWav")}, or give { channels, sampleRate }` };
|
|
229
|
+
if (d.kind === "list" && Array.isArray(value) && value.length && value.every((c) => ArrayBuffer.isView(c) || Array.isArray(c))) return { ok: false, problem: `a list of ${value.length} channels with no sample rate: ${converterHint("pcmWav")}, or give { channels, sampleRate }` };
|
|
230
|
+
if (d.kind === "image" || d.kind === "pixels") return { ok: false, problem: `${d.words}, not audio` };
|
|
231
|
+
if (d.kind === "text") return { ok: false, problem: "text, not audio: nothing is fetched here (a URL is the canvas's to allow: fetch it in a pane), and a base64 data: URL is read" };
|
|
232
|
+
return { ok: false, problem: `${d.words}, not audio: ${converterHint("audioPcm")} to make audio from samples` };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The audio inputs a pane's sample modules read (`names`), checked: `{ adapted: [{ name, from, to, label }], problems }`.
|
|
237
|
+
* An input that isn't there is left out (the frame says so when it plays).
|
|
238
|
+
*/
|
|
239
|
+
export function adaptAudioInputs(names, inputs) {
|
|
240
|
+
const adapted = [];
|
|
241
|
+
const problems = [];
|
|
242
|
+
for (const name of new Set(names)) {
|
|
243
|
+
const value = inputs?.[name];
|
|
244
|
+
if (value === undefined || value === null) continue;
|
|
245
|
+
if (typeof value?.unavailable === "string") continue; // a sample pane with nothing to play says why in this field: the frame says it, it is not an error here
|
|
246
|
+
const found = adaptAudio(value);
|
|
247
|
+
if (!found.ok) problems.push(`the input ${name} is ${found.problem}`);
|
|
248
|
+
else if (found.via) adapted.push({ name, from: found.from ?? describeValue(value).kind, to: "audio", label: found.via });
|
|
249
|
+
}
|
|
250
|
+
return { adapted, problems };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ── keyboard state ─────────────────────────────────────────────────────────
|
|
254
|
+
|
|
255
|
+
/** KeyboardEvent.code → the legacy key code Shadertoy's keyboard texture is indexed by (texelFetch(iChannel0, ivec2(65, 0), 0).x is A down). */
|
|
256
|
+
export const KEY_CODES = (() => {
|
|
257
|
+
const t = { Backspace: 8, Tab: 9, Enter: 13, NumpadEnter: 13, ShiftLeft: 16, ShiftRight: 16, ControlLeft: 17, ControlRight: 17, AltLeft: 18, AltRight: 18, Pause: 19, CapsLock: 20, Escape: 27, Space: 32, PageUp: 33, PageDown: 34, End: 35, Home: 36, ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40, PrintScreen: 44, Insert: 45, Delete: 46, MetaLeft: 91, MetaRight: 92, ContextMenu: 93, NumpadMultiply: 106, NumpadAdd: 107, NumpadSubtract: 109, NumpadDecimal: 110, NumpadDivide: 111, NumLock: 144, ScrollLock: 145, Semicolon: 186, Equal: 187, Comma: 188, Minus: 189, Period: 190, Slash: 191, Backquote: 192, BracketLeft: 219, Backslash: 220, BracketRight: 221, Quote: 222 };
|
|
258
|
+
for (let i = 0; i < 26; i++) t[`Key${String.fromCharCode(65 + i)}`] = 65 + i;
|
|
259
|
+
for (let i = 0; i < 10; i++) (t[`Digit${i}`] = 48 + i), (t[`Numpad${i}`] = 96 + i);
|
|
260
|
+
for (let i = 1; i <= 12; i++) t[`F${i}`] = 111 + i;
|
|
261
|
+
return Object.freeze(t);
|
|
262
|
+
})();
|
|
263
|
+
|
|
264
|
+
const codeList = (v) => Array.isArray(v) && v.every((c) => typeof c === "string");
|
|
265
|
+
|
|
266
|
+
/** Is `value` a keyboard device pane's state, `{ held, pressed, toggled }` lists of KeyboardEvent.code (src/device/model.js)? */
|
|
267
|
+
export const isKeyboardState = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value) && codeList(value.held) && codeList(value.pressed) && codeList(value.toggled);
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* A keyboard state as Shadertoy's keyboard texture: 256 × 3 numbers, 1 where a key is down (row 0), went down in this update
|
|
271
|
+
* (row 1) or is toggled on (row 2), by legacy key code. `{ width, height, data: Float32Array, unknown }` (`unknown`: codes with no key code).
|
|
272
|
+
*/
|
|
273
|
+
export function keyboardTexture(state) {
|
|
274
|
+
const data = new Float32Array(256 * 3);
|
|
275
|
+
const unknown = [];
|
|
276
|
+
["held", "pressed", "toggled"].forEach((row, y) => {
|
|
277
|
+
for (const code of state[row]) {
|
|
278
|
+
const k = KEY_CODES[code];
|
|
279
|
+
if (k === undefined) unknown.includes(code) || unknown.push(code);
|
|
280
|
+
else data[y * 256 + k] = 1;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
return { width: 256, height: 3, data, unknown };
|
|
284
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Whether a tool call of an agent is running on a canvas (src/webmcp/tools.js counts them), so a runner can tell an agent's run from a person's.
|
|
2
|
+
// A WeakMap keyed by the root canvas: nothing is written onto the canvas itself.
|
|
3
|
+
const counts = new WeakMap();
|
|
4
|
+
const rootOf = (canvas) => canvas?.root ?? canvas;
|
|
5
|
+
export function enterAgentCall(canvas) {
|
|
6
|
+
const root = rootOf(canvas);
|
|
7
|
+
if (root && typeof root === "object") counts.set(root, (counts.get(root) ?? 0) + 1);
|
|
8
|
+
return () => {
|
|
9
|
+
if (root && typeof root === "object") counts.set(root, Math.max(0, (counts.get(root) ?? 1) - 1));
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export const isAgentRun = (canvas) => (counts.get(rootOf(canvas)) ?? 0) > 0;
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// Pure layout geometry for arranging panes: no DOM, no canvas. Every function
|
|
2
|
+
// takes rects ({ id, x, y, width, height, leftPad? } in world units; leftPad is
|
|
3
|
+
// room a pane needs on its left for its input labels) and returns a Map of
|
|
4
|
+
// id -> { x, y }: the new top-left corner of each pane it places. Sizes never
|
|
5
|
+
// change. The UI applies the result as one undoable gesture.
|
|
6
|
+
|
|
7
|
+
import { stepsOf, polarRound, polarSpokes } from "./snapping.js";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_GAP = 32;
|
|
10
|
+
|
|
11
|
+
/** Every arrangement, by name (src/ui/layout.js ARRANGEMENTS has their labels and runs them; the agent tool mallory_arrange takes these). */
|
|
12
|
+
export const ARRANGE_OPS = ["align-left", "align-center", "align-right", "align-top", "align-middle", "align-bottom", "distribute-horizontal", "distribute-vertical", "tidy", "grid", "stack", "radial"];
|
|
13
|
+
|
|
14
|
+
/** Round to the grid (or to whole units without one). */
|
|
15
|
+
const roundTo = (v, grid) => (grid > 0 ? Math.round(v / grid) * grid : Math.round(v));
|
|
16
|
+
/** Round up to the grid, so a "no closer than" constraint still holds after snapping. */
|
|
17
|
+
const ceilTo = (v, grid) => (grid > 0 ? Math.ceil(v / grid) * grid : Math.ceil(v));
|
|
18
|
+
// `grid` options below are one step for both axes (a number) or { x, y }: each axis rounds to its own.
|
|
19
|
+
|
|
20
|
+
const bounds = (rects) => {
|
|
21
|
+
const left = Math.min(...rects.map((r) => r.x));
|
|
22
|
+
const top = Math.min(...rects.map((r) => r.y));
|
|
23
|
+
const right = Math.max(...rects.map((r) => r.x + r.width));
|
|
24
|
+
const bottom = Math.max(...rects.map((r) => r.y + r.height));
|
|
25
|
+
return { left, top, right, bottom };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const byPosition = (a, b) => a.y - b.y || a.x - b.x || String(a.id).localeCompare(String(b.id));
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Line panes up along one edge or center of their bounding box.
|
|
32
|
+
* `edge`: "left" | "center" (vertical center line) | "right" | "top" | "middle" (horizontal center line) | "bottom".
|
|
33
|
+
*/
|
|
34
|
+
export function align(rects, edge) {
|
|
35
|
+
const out = new Map();
|
|
36
|
+
if (rects.length < 2) return out;
|
|
37
|
+
const b = bounds(rects);
|
|
38
|
+
const cx = (b.left + b.right) / 2;
|
|
39
|
+
const cy = (b.top + b.bottom) / 2;
|
|
40
|
+
for (const r of rects) {
|
|
41
|
+
const p = { x: r.x, y: r.y };
|
|
42
|
+
if (edge === "left") p.x = b.left;
|
|
43
|
+
else if (edge === "right") p.x = b.right - r.width;
|
|
44
|
+
else if (edge === "center") p.x = cx - r.width / 2;
|
|
45
|
+
else if (edge === "top") p.y = b.top;
|
|
46
|
+
else if (edge === "bottom") p.y = b.bottom - r.height;
|
|
47
|
+
else if (edge === "middle") p.y = cy - r.height / 2;
|
|
48
|
+
else throw new RangeError(`align: unknown edge ${edge}`);
|
|
49
|
+
out.set(r.id, { x: Math.round(p.x), y: Math.round(p.y) });
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Space panes evenly along an axis ("horizontal" | "vertical"): the first and
|
|
56
|
+
* last stay put and the gaps between neighbours become equal. When the panes
|
|
57
|
+
* are wider (taller) than the span, they are laid out `minGap` apart instead
|
|
58
|
+
* of overlapping.
|
|
59
|
+
*/
|
|
60
|
+
export function distribute(rects, axis, { minGap = DEFAULT_GAP } = {}) {
|
|
61
|
+
const out = new Map();
|
|
62
|
+
if (rects.length < 3) return out;
|
|
63
|
+
const [pos, size] = axis === "horizontal" ? ["x", "width"] : axis === "vertical" ? ["y", "height"] : [];
|
|
64
|
+
if (!pos) throw new RangeError(`distribute: unknown axis ${axis}`);
|
|
65
|
+
const sorted = [...rects].sort((a, b) => a[pos] - b[pos] || a[pos] + a[size] - (b[pos] + b[size]));
|
|
66
|
+
const first = sorted[0];
|
|
67
|
+
const end = Math.max(...sorted.map((r) => r[pos] + r[size]));
|
|
68
|
+
const total = sorted.reduce((sum, r) => sum + r[size], 0);
|
|
69
|
+
let gap = (end - first[pos] - total) / (sorted.length - 1);
|
|
70
|
+
if (gap < 0) gap = minGap;
|
|
71
|
+
let at = first[pos];
|
|
72
|
+
for (const r of sorted) {
|
|
73
|
+
out.set(r.id, { x: r.x, y: r.y, [pos]: Math.round(at) });
|
|
74
|
+
at += r[size] + gap;
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Auto-layout by the dataflow graph: one column per dependency depth (sources
|
|
81
|
+
* on the left, dependents to their right), each column ordered to reduce wire
|
|
82
|
+
* crossings (barycenter sweeps), each pane placed level with the panes it
|
|
83
|
+
* reads from where it can be without overlapping its column. Cycles are
|
|
84
|
+
* broken at an arbitrary edge. Panes with no wires join the first column.
|
|
85
|
+
*
|
|
86
|
+
* @param {Array<{ id, x, y, width, height, leftPad? }>} rects
|
|
87
|
+
* @param {Array<[string, string]>} edges [sourceId, targetId] pairs
|
|
88
|
+
* @param {{ gapX?: number, gapY?: number, grid?: number | { x: number, y: number } }} [options] a grid snaps every corner to it
|
|
89
|
+
*/
|
|
90
|
+
export function tidy(rects, edges, { gapX = 72, gapY = DEFAULT_GAP, grid: g = 0 } = {}) {
|
|
91
|
+
const out = new Map();
|
|
92
|
+
if (!rects.length) return out;
|
|
93
|
+
const { x: gx, y: gy } = stepsOf(g);
|
|
94
|
+
const byId = new Map(rects.map((r) => [r.id, r]));
|
|
95
|
+
const layers = layerize(rects, edges);
|
|
96
|
+
const { preds } = graph(rects, edges);
|
|
97
|
+
|
|
98
|
+
// Columns: each as wide as its widest pane, with room for the next column's input labels.
|
|
99
|
+
const b = bounds(rects);
|
|
100
|
+
const colX = [];
|
|
101
|
+
layers.forEach((layer, l) => {
|
|
102
|
+
if (l === 0) colX.push(roundTo(b.left, gx));
|
|
103
|
+
else {
|
|
104
|
+
const prev = layers[l - 1];
|
|
105
|
+
const width = Math.max(...prev.map((id) => byId.get(id).width));
|
|
106
|
+
const labels = Math.max(0, ...layer.map((id) => byId.get(id).leftPad ?? 0));
|
|
107
|
+
colX.push(ceilTo(colX[l - 1] + width + Math.max(gapX, labels + 24), gx));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const top = roundTo(b.top, gy);
|
|
112
|
+
const center = new Map(); // id -> world center y once placed
|
|
113
|
+
layers.forEach((layer, l) => {
|
|
114
|
+
let floor = top; // the next pane in this column starts at or below this
|
|
115
|
+
for (const id of layer) {
|
|
116
|
+
const r = byId.get(id);
|
|
117
|
+
const sources = (preds.get(id) ?? []).filter((s) => center.has(s));
|
|
118
|
+
const wanted = sources.length ? Math.round(sources.reduce((sum, s) => sum + center.get(s), 0) / sources.length - r.height / 2) : floor;
|
|
119
|
+
const y = ceilTo(Math.max(floor, wanted), gy);
|
|
120
|
+
out.set(id, { x: colX[l], y });
|
|
121
|
+
center.set(id, y + r.height / 2);
|
|
122
|
+
floor = y + r.height + gapY;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Columns of ids for `tidy`: longest-path depth, then barycenter ordering. Exported for tests. */
|
|
129
|
+
export function layerize(rects, edges, { sweeps = 4 } = {}) {
|
|
130
|
+
const { preds, succs, acyclic } = graph(rects, edges);
|
|
131
|
+
// Longest path from a source, in topological order (Kahn) over the acyclic edges.
|
|
132
|
+
const depth = new Map(rects.map((r) => [r.id, 0]));
|
|
133
|
+
const indegree = new Map(rects.map((r) => [r.id, 0]));
|
|
134
|
+
for (const [, t] of acyclic) indegree.set(t, indegree.get(t) + 1);
|
|
135
|
+
const queue = [...rects].sort(byPosition).map((r) => r.id).filter((id) => indegree.get(id) === 0);
|
|
136
|
+
while (queue.length) {
|
|
137
|
+
const id = queue.shift();
|
|
138
|
+
for (const t of succs.get(id)) {
|
|
139
|
+
depth.set(t, Math.max(depth.get(t), depth.get(id) + 1));
|
|
140
|
+
indegree.set(t, indegree.get(t) - 1);
|
|
141
|
+
if (indegree.get(t) === 0) queue.push(t);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const count = Math.max(...depth.values()) + 1;
|
|
145
|
+
const layers = Array.from({ length: count }, () => []);
|
|
146
|
+
for (const r of [...rects].sort(byPosition)) layers[depth.get(r.id)].push(r.id); // start from the current top-to-bottom order
|
|
147
|
+
|
|
148
|
+
// Barycenter sweeps: order each column by the mean position of its neighbours
|
|
149
|
+
// in the columns already ordered, down then back up.
|
|
150
|
+
const index = new Map();
|
|
151
|
+
const reindex = () => layers.forEach((layer) => layer.forEach((id, i) => index.set(id, (i + 0.5) / layer.length)));
|
|
152
|
+
const order = (layer, neighbours) => {
|
|
153
|
+
const key = new Map(
|
|
154
|
+
layer.map((id, i) => {
|
|
155
|
+
const ns = neighbours.get(id).filter((n) => index.has(n));
|
|
156
|
+
return [id, ns.length ? ns.reduce((s, n) => s + index.get(n), 0) / ns.length : (i + 0.5) / layer.length];
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
// A stable sort keeps the current order between equal keys.
|
|
160
|
+
layer.sort((a, b) => key.get(a) - key.get(b));
|
|
161
|
+
};
|
|
162
|
+
reindex();
|
|
163
|
+
for (let s = 0; s < sweeps; s++) {
|
|
164
|
+
for (let l = 1; l < layers.length; l++) (order(layers[l], preds), reindex());
|
|
165
|
+
for (let l = layers.length - 2; l >= 0; l--) (order(layers[l], succs), reindex());
|
|
166
|
+
}
|
|
167
|
+
return layers;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Adjacency between the given panes (edges to panes not in `rects` are ignored), with cycles broken. */
|
|
171
|
+
function graph(rects, edges) {
|
|
172
|
+
const ids = new Set(rects.map((r) => r.id));
|
|
173
|
+
const preds = new Map(rects.map((r) => [r.id, []]));
|
|
174
|
+
const succs = new Map(rects.map((r) => [r.id, []]));
|
|
175
|
+
const seen = new Set();
|
|
176
|
+
const unique = [];
|
|
177
|
+
for (const [s, t] of edges) {
|
|
178
|
+
const key = `${s}\u0000${t}`;
|
|
179
|
+
if (s === t || !ids.has(s) || !ids.has(t) || seen.has(key)) continue;
|
|
180
|
+
seen.add(key);
|
|
181
|
+
unique.push([s, t]);
|
|
182
|
+
}
|
|
183
|
+
// Depth-first from the top-left pane, dropping edges back into the current path.
|
|
184
|
+
const out = new Map(rects.map((r) => [r.id, []]));
|
|
185
|
+
for (const [s, t] of unique) out.get(s).push(t);
|
|
186
|
+
const state = new Map(); // 1 = on the path, 2 = done
|
|
187
|
+
const back = new Set();
|
|
188
|
+
const visit = (root) => {
|
|
189
|
+
const stack = [[root, 0]];
|
|
190
|
+
state.set(root, 1);
|
|
191
|
+
while (stack.length) {
|
|
192
|
+
const frame = stack[stack.length - 1];
|
|
193
|
+
const [id, i] = frame;
|
|
194
|
+
const next = out.get(id)[i];
|
|
195
|
+
if (next === undefined) {
|
|
196
|
+
state.set(id, 2);
|
|
197
|
+
stack.pop();
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
frame[1]++;
|
|
201
|
+
if (state.get(next) === 1) back.add(`${id}\u0000${next}`);
|
|
202
|
+
else if (!state.has(next)) {
|
|
203
|
+
state.set(next, 1);
|
|
204
|
+
stack.push([next, 0]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
for (const r of [...rects].sort(byPosition)) if (!state.has(r.id)) visit(r.id);
|
|
209
|
+
const acyclic = unique.filter(([s, t]) => !back.has(`${s}\u0000${t}`));
|
|
210
|
+
for (const [s, t] of acyclic) {
|
|
211
|
+
preds.get(t).push(s);
|
|
212
|
+
succs.get(s).push(t);
|
|
213
|
+
}
|
|
214
|
+
return { preds, succs, acyclic };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* A grid in reading order (top-to-bottom, then left-to-right), about square
|
|
219
|
+
* unless `columns` is given. Each column is as wide as its widest pane and
|
|
220
|
+
* each row as tall as its tallest.
|
|
221
|
+
*/
|
|
222
|
+
export function grid(rects, { columns, gap = DEFAULT_GAP, grid: g = 0 } = {}) {
|
|
223
|
+
const out = new Map();
|
|
224
|
+
if (!rects.length) return out;
|
|
225
|
+
const sorted = [...rects].sort(byPosition);
|
|
226
|
+
const cols = Math.max(1, Math.min(sorted.length, columns ?? Math.ceil(Math.sqrt(sorted.length))));
|
|
227
|
+
const rows = Math.ceil(sorted.length / cols);
|
|
228
|
+
const colW = Array(cols).fill(0);
|
|
229
|
+
const colPad = Array(cols).fill(0);
|
|
230
|
+
const rowH = Array(rows).fill(0);
|
|
231
|
+
sorted.forEach((r, i) => {
|
|
232
|
+
const c = i % cols;
|
|
233
|
+
const row = Math.floor(i / cols);
|
|
234
|
+
colW[c] = Math.max(colW[c], r.width);
|
|
235
|
+
colPad[c] = Math.max(colPad[c], r.leftPad ?? 0);
|
|
236
|
+
rowH[row] = Math.max(rowH[row], r.height);
|
|
237
|
+
});
|
|
238
|
+
const b = bounds(rects);
|
|
239
|
+
const { x: gx, y: gy } = stepsOf(g);
|
|
240
|
+
const xs = [roundTo(b.left, gx)];
|
|
241
|
+
for (let c = 1; c < cols; c++) xs.push(ceilTo(xs[c - 1] + colW[c - 1] + Math.max(gap, colPad[c] ? colPad[c] + 12 : 0), gx));
|
|
242
|
+
const ys = [roundTo(b.top, gy)];
|
|
243
|
+
for (let row = 1; row < rows; row++) ys.push(ceilTo(ys[row - 1] + rowH[row - 1] + gap, gy));
|
|
244
|
+
sorted.forEach((r, i) => out.set(r.id, { x: xs[i % cols], y: ys[Math.floor(i / cols)] }));
|
|
245
|
+
return out;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** A cascade in the given order (bottom of the stack first), each pane `offset` below and right of the last. */
|
|
249
|
+
export function stack(rects, { offset = 32, grid: g = 0 } = {}) {
|
|
250
|
+
const out = new Map();
|
|
251
|
+
if (!rects.length) return out;
|
|
252
|
+
const b = bounds(rects);
|
|
253
|
+
const { x: gx, y: gy } = stepsOf(g);
|
|
254
|
+
const stepX = gx > 0 ? Math.max(gx, roundTo(offset, gx)) : offset;
|
|
255
|
+
const stepY = gy > 0 ? Math.max(gy, roundTo(offset, gy)) : offset;
|
|
256
|
+
const x0 = roundTo(b.left, gx);
|
|
257
|
+
const y0 = roundTo(b.top, gy);
|
|
258
|
+
rects.forEach((r, i) => out.set(r.id, { x: x0 + i * stepX, y: y0 + i * stepY }));
|
|
259
|
+
return out;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* A ring around a hub: the panes, in the order they already go round
|
|
264
|
+
* it (clockwise from the right), at equal angles, on the nearest ring out
|
|
265
|
+
* where no two of them overlap and none overlaps the hub. `hub` is a rect
|
|
266
|
+
* (a pane: its centre) or a point. With `ring` the radius is a whole number
|
|
267
|
+
* of rings; with `angle` (the polar grid's step in degrees, or the
|
|
268
|
+
* older `spokes`, a count) and no more panes than spokes, each pane's centre
|
|
269
|
+
* sits on a spoke, spread as evenly as the spokes allow, starting with the
|
|
270
|
+
* spoke nearest the first pane. Centres land exactly on the polar grid, so
|
|
271
|
+
* snapping them again leaves them where they are.
|
|
272
|
+
*/
|
|
273
|
+
export function radial(rects, { hub = { x: 0, y: 0 }, ring = 0, angle = 0, spokes = 0, gap = DEFAULT_GAP } = {}) {
|
|
274
|
+
const out = new Map();
|
|
275
|
+
if (!rects.length) return out;
|
|
276
|
+
const hc = { x: hub.x + (hub.width ?? 0) / 2, y: hub.y + (hub.height ?? 0) / 2 };
|
|
277
|
+
const hubRadius = Math.hypot(hub.width ?? 0, hub.height ?? 0) / 2;
|
|
278
|
+
const centre = (r) => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });
|
|
279
|
+
const turn = (r) => {
|
|
280
|
+
const c = centre(r);
|
|
281
|
+
const a = Math.atan2(c.y - hc.y, c.x - hc.x);
|
|
282
|
+
return a < 0 ? a + 2 * Math.PI : a;
|
|
283
|
+
};
|
|
284
|
+
const sorted = [...rects].sort((a, b) => turn(a) - turn(b) || Math.hypot(centre(a).x - hc.x, centre(a).y - hc.y) - Math.hypot(centre(b).x - hc.x, centre(b).y - hc.y) || String(a.id).localeCompare(String(b.id)));
|
|
285
|
+
const n = sorted.length;
|
|
286
|
+
const first = turn(sorted[0]);
|
|
287
|
+
let angles;
|
|
288
|
+
const onSpokes = angle > 0 || Math.floor(spokes) > 0;
|
|
289
|
+
const { n: spokeCount, step } = onSpokes ? polarSpokes({ angle, spokes }) : { n: 0, step: 0 };
|
|
290
|
+
if (spokeCount > 0 && n <= spokeCount) {
|
|
291
|
+
const start = polarRound({ x: Math.cos(first), y: Math.sin(first) }, { angle, spokes }).spoke;
|
|
292
|
+
angles = sorted.map((_, i) => ((start + Math.round((i * spokeCount) / n)) % spokeCount) * step);
|
|
293
|
+
} else angles = sorted.map((_, i) => first + (i * 2 * Math.PI) / n);
|
|
294
|
+
// The closest two neighbours set how far out the ring must be for the panes (as circles round them) not to touch.
|
|
295
|
+
const size = Math.max(...sorted.map((r) => Math.hypot(r.width, r.height)));
|
|
296
|
+
let closest = 2 * Math.PI;
|
|
297
|
+
for (let i = 0; i < n && n > 1; i++) closest = Math.min(closest, (angles[(i + 1) % n] - angles[i] + 4 * Math.PI) % (2 * Math.PI) || 2 * Math.PI);
|
|
298
|
+
let radius = Math.max(hubRadius + size / 2 + gap, n > 1 ? (size + gap) / (2 * Math.sin(Math.min(Math.PI, closest) / 2)) : 0, ring > 0 ? ring : 0);
|
|
299
|
+
radius = ring > 0 ? Math.ceil(radius / ring - 1e-9) * ring : Math.ceil(radius);
|
|
300
|
+
sorted.forEach((r, i) => {
|
|
301
|
+
const p = spokeCount > 0 && n <= spokeCount ? polarRound({ x: hc.x + radius * Math.cos(angles[i]), y: hc.y + radius * Math.sin(angles[i]) }, { hub: hc, ring, angle, spokes }) : { x: hc.x + radius * Math.cos(angles[i]), y: hc.y + radius * Math.sin(angles[i]) };
|
|
302
|
+
out.set(r.id, { x: Math.round(p.x - r.width / 2), y: Math.round(p.y - r.height / 2) });
|
|
303
|
+
});
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** True when two rects overlap (touching edges don't count). */
|
|
308
|
+
export const overlaps = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
|