@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,496 @@
|
|
|
1
|
+
// Shader channels, the pure part: named texture inputs that are not capped at Shadertoy's four.
|
|
2
|
+
//
|
|
3
|
+
// A channel is declared as data, like a uniform:
|
|
4
|
+
//
|
|
5
|
+
// { name: "photo", from?: "input name", filter: "linear", wrap: "clamp", vflip?: true, as?: "array" }
|
|
6
|
+
//
|
|
7
|
+
// The input named `from` (the channel's own name when `from` is left out) is the channel's source, and
|
|
8
|
+
// its value decides what the channel is, by kind (the conversion happens here, at the input, and the
|
|
9
|
+
// channel's row shows what happened):
|
|
10
|
+
//
|
|
11
|
+
// an image (media value or Blob) a sampler2D
|
|
12
|
+
// a list of images of one size one sampler2DArray, with a `<name>Count` uniform for its layers
|
|
13
|
+
// pixels { width, height, data } a sampler2D (RGBA8)
|
|
14
|
+
// numbers (a list, typed array or a table) a sampler2D of floats (R32F), read exactly (nearest)
|
|
15
|
+
// a video (media value or Blob) a sampler2D the frame fills from the video at the frame's time
|
|
16
|
+
// audio (an audio pane's WAV, a recording) Shadertoy's 512×2 texture: FFT (row 0) and waveform (row 1) at the frame's time
|
|
17
|
+
// a gamepad device's state a 32×2 float texture: axes (row 0), button values (row 1)
|
|
18
|
+
// a camera or screen device's frame a sampler2D (it is an image); with `live: true` the frames come as they are drawn
|
|
19
|
+
// a microphone device's analysis Shadertoy's 512×2 texture: spectrum (row 0) and waveform (row 1), each frame with `live: true`
|
|
20
|
+
//
|
|
21
|
+
// `as` overrides the choice ("image", "array", "pixels", "numbers", "video" or "audio"); "auto" (or none) is by value.
|
|
22
|
+
// `live: true` reads the frames of the pane wired to the input as they are drawn (render, shader and effects panes send
|
|
23
|
+
// them; src/shader/live.js and src/ui/shader-live.js relay them), instead of only its picture at the shader's frame.
|
|
24
|
+
// The real limit is the GPU's MAX_TEXTURE_IMAGE_UNITS, less the units the pane itself uses (the
|
|
25
|
+
// previous frame for feedback), which the pane shows. iChannel0…iChannel3 are names for the first four.
|
|
26
|
+
// Nothing here touches WebGL or the DOM: the frame (src/shader/frame.js) makes the textures.
|
|
27
|
+
import { adaptImage, adaptImageInputs, isKeyboardState, keyboardTexture, audioTypeOfBytes } from "../model/adapters.js";
|
|
28
|
+
import { decodeWav } from "../audio/wav.js";
|
|
29
|
+
import { mixDown } from "./audio-texture.js";
|
|
30
|
+
import { isAudioStream, audioTexture as micTexture } from "../device/stream-model.js";
|
|
31
|
+
import { RESERVED_WORDS, ALIAS_NAMES, ALIAS_CHANNELS, BUFFER_NAMES, channelAlias, isChannelAlias, describe, imageOf } from "./common.js";
|
|
32
|
+
|
|
33
|
+
export const CHANNEL_FILTERS = ["nearest", "linear", "mipmap"];
|
|
34
|
+
export const CHANNEL_WRAPS = ["clamp", "repeat"];
|
|
35
|
+
export const CHANNEL_AS = ["auto", "image", "array", "pixels", "numbers", "video", "audio"];
|
|
36
|
+
|
|
37
|
+
/** What the declarations and the textures are bounded by (the GPU's own limits apply on top, see `limitsOf` in the frame). */
|
|
38
|
+
export const CHANNEL_LIMITS = {
|
|
39
|
+
maxDeclared: 128, // a sanity bound on the list; the GPU's texture units are the real cap
|
|
40
|
+
minUnits: 16, // MAX_TEXTURE_IMAGE_UNITS WebGL2 guarantees
|
|
41
|
+
minLayers: 256, // MAX_ARRAY_TEXTURE_LAYERS WebGL2 guarantees
|
|
42
|
+
side: 4096, // pixels a side of any channel texture
|
|
43
|
+
maxBytes: 256 * 1024 * 1024, // all the channels' textures together
|
|
44
|
+
audioSamples: 8 * 1024 * 1024, // samples of one audio channel kept for its texture (about 3 minutes at 48 kHz); the rest is left out, with a note
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const KEYS = ["name", "from", "buffer", "filter", "wrap", "vflip", "as", "live"];
|
|
48
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]{0,31}$/;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The problems with a channel list as written: `[{ index, name, message }]`, none when it is fine.
|
|
52
|
+
* `uniforms` are the names the pane's uniforms already use (a channel may not share one, nor `<name>Count`).
|
|
53
|
+
*/
|
|
54
|
+
export function checkChannels(list, { uniforms = [] } = {}) {
|
|
55
|
+
const problems = [];
|
|
56
|
+
if (list === undefined || list === null) return problems;
|
|
57
|
+
if (!Array.isArray(list)) return [{ index: -1, name: "", message: "channels must be a list of { name, from?, filter?, wrap?, vflip?, as? }" }];
|
|
58
|
+
if (list.length > CHANNEL_LIMITS.maxDeclared) problems.push({ index: -1, name: "", message: `at most ${CHANNEL_LIMITS.maxDeclared} channels are declared (there are ${list.length}); the GPU's texture units are the real limit` });
|
|
59
|
+
const used = new Set(uniforms);
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
list.forEach((c, index) => {
|
|
62
|
+
const name = typeof c?.name === "string" ? c.name : "";
|
|
63
|
+
const add = (message) => problems.push({ index, name, message: `${name ? `channel ${name}` : `channel #${index + 1}`}: ${message}` });
|
|
64
|
+
if (!c || typeof c !== "object" || Array.isArray(c)) return add("must be an object { name, … }");
|
|
65
|
+
if (!NAME.test(name)) return add("name must be a GLSL identifier of at most 32 characters (letters, digits, _)");
|
|
66
|
+
if (name.startsWith("gl_") || name.includes("__")) add("names starting gl_ or containing __ are reserved in GLSL");
|
|
67
|
+
else if (RESERVED_WORDS.has(name)) add("that is a GLSL keyword or the shader's own name");
|
|
68
|
+
else if (/^u_/.test(name) || name === "time" || name === "frame" || (ALIAS_NAMES.has(name) && !isChannelAlias(name))) add("u_… names, Shadertoy's i… names, and the inputs time and frame belong to the shader's clock and size (iChannel0…iChannel3 are fine)");
|
|
69
|
+
if (seen.has(name)) add("declared twice");
|
|
70
|
+
else if (used.has(name)) add("a uniform has that name");
|
|
71
|
+
seen.add(name);
|
|
72
|
+
for (const key of Object.keys(c)) if (!KEYS.includes(key)) add(`${key} is not a setting (${KEYS.join(", ")})`);
|
|
73
|
+
if (c.from !== undefined && (typeof c.from !== "string" || !c.from.trim() || c.from.length > 64)) add("from must be the name of an input (a non-empty string)");
|
|
74
|
+
if (c.filter !== undefined && !CHANNEL_FILTERS.includes(c.filter)) add(`filter must be one of ${CHANNEL_FILTERS.join(", ")}`);
|
|
75
|
+
if (c.wrap !== undefined && !CHANNEL_WRAPS.includes(c.wrap)) add(`wrap must be one of ${CHANNEL_WRAPS.join(", ")}`);
|
|
76
|
+
if (c.vflip !== undefined && typeof c.vflip !== "boolean") add("vflip must be true or false");
|
|
77
|
+
if (c.as !== undefined && !CHANNEL_AS.includes(c.as)) add(`as must be one of ${CHANNEL_AS.join(", ")}`);
|
|
78
|
+
if (c.live !== undefined && typeof c.live !== "boolean") add("live must be true or false");
|
|
79
|
+
if (c.buffer !== undefined) {
|
|
80
|
+
// A channel that reads one of the pane's own buffers (Buffer A to D): it takes the buffer's texture, not an input.
|
|
81
|
+
if (!BUFFER_NAMES.includes(c.buffer)) add(`buffer must be one of ${BUFFER_NAMES.join(", ")}`);
|
|
82
|
+
for (const key of ["from", "as", "vflip", "live"]) if (c[key] !== undefined) add(`a channel that reads a buffer has no ${key}: it takes only filter and wrap`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
// `<name>Count` is declared for a list: no other name may take it.
|
|
86
|
+
const names = new Set([...used, ...seen]);
|
|
87
|
+
list.forEach((c, index) => {
|
|
88
|
+
if (c && typeof c.name === "string" && NAME.test(c.name) && names.has(`${c.name}Count`)) problems.push({ index, name: c.name, message: `channel ${c.name}: ${c.name}Count is another name's, and a list of images declares it (the layer count)` });
|
|
89
|
+
});
|
|
90
|
+
return problems;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Fill in a declaration's defaults: `{ name, from?, buffer?, filter, wrap, vflip?, as?, live? }` (`from` only when it is another name; `vflip`, `as` and `live` only when given; a buffer channel has none of them, nor `from`). */
|
|
94
|
+
export function normalizeChannel(c) {
|
|
95
|
+
const out = { name: c.name };
|
|
96
|
+
if (BUFFER_NAMES.includes(c.buffer)) {
|
|
97
|
+
out.buffer = c.buffer;
|
|
98
|
+
out.filter = CHANNEL_FILTERS.includes(c.filter) ? c.filter : "linear";
|
|
99
|
+
out.wrap = CHANNEL_WRAPS.includes(c.wrap) ? c.wrap : "clamp";
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
if (typeof c.from === "string" && c.from.trim() && c.from.trim() !== c.name) out.from = c.from.trim();
|
|
103
|
+
out.filter = CHANNEL_FILTERS.includes(c.filter) ? c.filter : "linear";
|
|
104
|
+
out.wrap = CHANNEL_WRAPS.includes(c.wrap) ? c.wrap : "clamp";
|
|
105
|
+
if (typeof c.vflip === "boolean") out.vflip = c.vflip;
|
|
106
|
+
if (CHANNEL_AS.includes(c.as) && c.as !== "auto") out.as = c.as;
|
|
107
|
+
if (c.live === true) out.live = true;
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The declared channels with defaults, invalid ones left out (see checkChannels). */
|
|
112
|
+
export function normalizeChannels(list, options) {
|
|
113
|
+
const bad = new Set(checkChannels(list, options).map((p) => p.index));
|
|
114
|
+
return (Array.isArray(list) ? list : []).filter((c, i) => !bad.has(i)).map(normalizeChannel);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ── what an input is ───────────────────────────────────────────────────────
|
|
118
|
+
|
|
119
|
+
const isNum = (n) => typeof n === "number" && Number.isFinite(n);
|
|
120
|
+
const isTyped = (v) => ArrayBuffer.isView(v) && !(v instanceof DataView) && typeof v.length === "number" && typeof v[0] !== "bigint";
|
|
121
|
+
const isByteList = (v) => v instanceof Uint8Array || v instanceof Uint8ClampedArray;
|
|
122
|
+
const isNumberList = (v) => (Array.isArray(v) ? v.length > 0 && v.every(isNum) : isTyped(v) && v.length > 0);
|
|
123
|
+
|
|
124
|
+
/** The pixels `{ width, height, data }` of a value as RGBA8 bytes, or null. */
|
|
125
|
+
function pixelsOf(value, side) {
|
|
126
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || ArrayBuffer.isView(value)) return null;
|
|
127
|
+
const { width, height, data } = value;
|
|
128
|
+
if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1) return null;
|
|
129
|
+
if (width > side || height > side) return { problem: `pixels ${width}×${height} are over the ${side} a side a channel may hold` };
|
|
130
|
+
const want = width * height * 4;
|
|
131
|
+
let bytes = null;
|
|
132
|
+
if (isByteList(data)) bytes = new Uint8Array(data.buffer, data.byteOffset, data.length);
|
|
133
|
+
else if (data instanceof ArrayBuffer) bytes = new Uint8Array(data);
|
|
134
|
+
else if (Array.isArray(data) && data.length === want && data.every((n) => Number.isInteger(n) && n >= 0 && n <= 255)) bytes = Uint8Array.from(data);
|
|
135
|
+
if (!bytes) return null;
|
|
136
|
+
if (bytes.length !== want) return { problem: `pixels ${width}×${height} need ${want} bytes (RGBA), not ${bytes.length}` };
|
|
137
|
+
return { width, height, data: bytes };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Numbers as a float texture: a flat list in rows of at most `side`, a table of equal rows, or `{ width, height, data }` of width × height numbers. `{ width, height, data }` | `{ problem }` | null. */
|
|
141
|
+
function numbersOf(value, side) {
|
|
142
|
+
if (isNumberList(value)) {
|
|
143
|
+
const n = value.length;
|
|
144
|
+
const width = Math.min(n, side);
|
|
145
|
+
const height = Math.ceil(n / width);
|
|
146
|
+
if (height > side) return { problem: `${n} numbers are over the ${side * side} a channel may hold` };
|
|
147
|
+
const data = new Float32Array(width * height);
|
|
148
|
+
data.set(Float32Array.from(value));
|
|
149
|
+
return { width, height, data };
|
|
150
|
+
}
|
|
151
|
+
if (Array.isArray(value) && value.length && value.every(isNumberList)) {
|
|
152
|
+
const width = value[0].length;
|
|
153
|
+
if (value.some((row) => row.length !== width)) return { problem: "the rows of the table are not all the same length" };
|
|
154
|
+
if (width > side || value.length > side) return { problem: `a table of ${width}×${value.length} numbers is over the ${side} a side a channel may hold` };
|
|
155
|
+
const data = new Float32Array(width * value.length);
|
|
156
|
+
value.forEach((row, y) => data.set(Float32Array.from(row), y * width));
|
|
157
|
+
return { width, height: value.length, data };
|
|
158
|
+
}
|
|
159
|
+
if (value && typeof value === "object" && !Array.isArray(value) && !ArrayBuffer.isView(value) && Number.isInteger(value.width) && Number.isInteger(value.height) && isNumberList(value.data) && value.data.length === value.width * value.height) {
|
|
160
|
+
if (value.width > side || value.height > side) return { problem: `${value.width}×${value.height} numbers are over the ${side} a side a channel may hold` };
|
|
161
|
+
return { width: value.width, height: value.height, data: Float32Array.from(value.data) };
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** A video input's bytes: a media value or a Blob of a video type. */
|
|
167
|
+
export function videoOf(value) {
|
|
168
|
+
const blob = value?.$media === "video" ? value.blob : typeof Blob !== "undefined" && value instanceof Blob ? value : null;
|
|
169
|
+
return blob && /^video\//.test(blob.type || (value?.$media === "video" ? "video/" : "")) ? blob : null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Is `value` audio as a texture's samples (what adaptChannelInputs makes of an audio input): `{ $shaderAudio: { pcm, sampleRate, duration } }`? */
|
|
173
|
+
export const isAudioSamples = (value) => Boolean(value?.$shaderAudio?.pcm) && typeof value.$shaderAudio.sampleRate === "number";
|
|
174
|
+
|
|
175
|
+
/** Is `value` audio a channel can take: an audio media value, a Blob of an audio type, or samples already read? */
|
|
176
|
+
export const isAudioInput = (value) => isAudioSamples(value) || value?.$media === "audio" || (typeof Blob !== "undefined" && value instanceof Blob && /^audio\//.test(value.type));
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* What an input value is as a channel, and its data ready for the frame: `{ kind: "image", blob }`,
|
|
180
|
+
* `{ kind: "array", blobs }`, `{ kind: "pixels", width, height, data }`, `{ kind: "numbers", width, height, data }`, or `{ problem }`.
|
|
181
|
+
* `as` forces one of them (a lone image becomes a one-layer list for "array").
|
|
182
|
+
*/
|
|
183
|
+
export function classify(value, as = "auto", { side = CHANNEL_LIMITS.side } = {}) {
|
|
184
|
+
const blob = imageOf(value);
|
|
185
|
+
const blobs = Array.isArray(value) && value.length && value.every((v) => imageOf(v)) ? value.map(imageOf) : null;
|
|
186
|
+
const tryPixels = () => pixelsOf(value, side);
|
|
187
|
+
const tryNumbers = () => numbersOf(value, side);
|
|
188
|
+
const hint = `an image, a list of images, pixels { width, height, data }, numbers (a list, a typed array or a table), a video or audio, not ${describe(value)}`;
|
|
189
|
+
const video = videoOf(value);
|
|
190
|
+
const audio = isAudioSamples(value) ? value.$shaderAudio : null;
|
|
191
|
+
switch (as) {
|
|
192
|
+
case "image":
|
|
193
|
+
return blob ? { kind: "image", blob } : { problem: `the input is ${adaptImage(value).problem ?? `not an image (a media value or an image Blob): ${describe(value)}`}` };
|
|
194
|
+
case "array":
|
|
195
|
+
if (blobs) return { kind: "array", blobs };
|
|
196
|
+
return blob ? { kind: "array", blobs: [blob] } : { problem: `as array needs a list of images, not ${describe(value)}` };
|
|
197
|
+
case "pixels": {
|
|
198
|
+
const px = tryPixels();
|
|
199
|
+
return px?.data ? { kind: "pixels", ...px } : { problem: px?.problem ?? `as pixels needs { width, height, data } of RGBA bytes, not ${describe(value)}` };
|
|
200
|
+
}
|
|
201
|
+
case "numbers": {
|
|
202
|
+
const nums = tryNumbers();
|
|
203
|
+
return nums?.data ? { kind: "numbers", ...nums } : { problem: nums?.problem ?? `as numbers needs a list of numbers, a typed array or a table of numbers, not ${describe(value)}` };
|
|
204
|
+
}
|
|
205
|
+
case "video":
|
|
206
|
+
return video ? { kind: "video", blob: video } : { problem: `as video needs a video (a media value or a Blob of a video type), not ${describe(value)}` };
|
|
207
|
+
case "audio": {
|
|
208
|
+
if (value?.$audioRows) return { kind: "pixels", ...tryPixels() }; // a microphone's analysis, made Shadertoy's texture by adaptChannelInputs
|
|
209
|
+
return audio ? { kind: "audio", ...audio } : { problem: `as audio needs audio (an audio pane's WAV, a recording, an audio Blob, or a microphone device pane), not ${describe(value)}` };
|
|
210
|
+
}
|
|
211
|
+
default: {
|
|
212
|
+
if (blob) return { kind: "image", blob };
|
|
213
|
+
if (video) return { kind: "video", blob: video };
|
|
214
|
+
if (audio) return { kind: "audio", ...audio };
|
|
215
|
+
if (blobs) return { kind: "array", blobs };
|
|
216
|
+
const px = tryPixels();
|
|
217
|
+
if (px) return px.data ? { kind: "pixels", ...px } : { problem: px.problem };
|
|
218
|
+
const nums = tryNumbers();
|
|
219
|
+
if (nums) return nums.data ? { kind: "numbers", ...nums } : { problem: nums.problem };
|
|
220
|
+
return { problem: `the input is not ${hint}` };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The GLSL type a channel of this kind is, given `as` (a channel nothing is wired to is a plain sampler unless `as` says list). */
|
|
226
|
+
export const glslOf = (kind, as) => (kind === "array" || (kind === "none" && as === "array") ? "sampler2DArray" : "sampler2D");
|
|
227
|
+
|
|
228
|
+
/** What a channel shows about its input: "image 64×64", "3 images, 64×64 each", "pixels 8×8", "16 numbers", "nothing wired". */
|
|
229
|
+
export function describeChannel(item) {
|
|
230
|
+
switch (item.kind) {
|
|
231
|
+
case "image":
|
|
232
|
+
return item.width ? `image ${item.width}×${item.height}` : "image";
|
|
233
|
+
case "array":
|
|
234
|
+
return `${item.layers} image${item.layers === 1 ? "" : "s"} as one array${item.width ? `, ${item.width}×${item.height} each` : ""}`;
|
|
235
|
+
case "pixels":
|
|
236
|
+
return item.audioRows ? `the microphone as 512×2: spectrum (y 0.25) and waveform (y 0.75)${item.live ? ", each frame" : ""}` : `pixels ${item.width}×${item.height}`;
|
|
237
|
+
case "numbers":
|
|
238
|
+
return item.height === 1 ? `${item.width} number${item.width === 1 ? "" : "s"}` : `${item.width}×${item.height} numbers`;
|
|
239
|
+
case "buffer":
|
|
240
|
+
return `buffer ${item.buffer}${item.width ? `, ${item.width}×${item.height}` : ""}${item.format ? ` ${item.format}` : ""}`;
|
|
241
|
+
case "video":
|
|
242
|
+
return `video${item.width ? ` ${item.width}×${item.height}` : ""}, the frame at the shader's time`;
|
|
243
|
+
case "audio":
|
|
244
|
+
return `audio${item.duration ? ` (${Math.round(item.duration * 100) / 100} s)` : ""} as 512×2: FFT (y 0.25) and waveform (y 0.75) at the shader's time`;
|
|
245
|
+
default:
|
|
246
|
+
return "nothing wired";
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Resolve the declared channels against the run's inputs. `channels` are normalized declarations (a pane's
|
|
252
|
+
* sampler uniforms come in as channels with `label: "uniform name"` and `as: "image"`). Returns
|
|
253
|
+
* `{ plan, problems, notes }`: `plan` has one item per channel, in order:
|
|
254
|
+
* { name, from, label, given, kind, glsl, filter, wrap, vflip, as, layers?, width?, height?, summary, payload }
|
|
255
|
+
* where `payload` is what the frame uploads (null for a channel with nothing wired).
|
|
256
|
+
*/
|
|
257
|
+
export function resolveChannels(channels, inputs = {}, { side = CHANNEL_LIMITS.side, maxLayers = CHANNEL_LIMITS.minLayers } = {}) {
|
|
258
|
+
const plan = [];
|
|
259
|
+
const problems = [];
|
|
260
|
+
const notes = [];
|
|
261
|
+
for (const c of channels) {
|
|
262
|
+
const from = c.from ?? c.name;
|
|
263
|
+
const label = c.label ?? `channel ${c.name}`;
|
|
264
|
+
if (c.buffer) {
|
|
265
|
+
// One of the pane's own buffers: its texture is made by the frame, so there is nothing to upload or wait for.
|
|
266
|
+
const item = { name: c.name, from: undefined, buffer: c.buffer, label, given: true, kind: "buffer", glsl: "sampler2D", filter: c.filter ?? "linear", wrap: c.wrap ?? "clamp", as: "auto", vflip: false, payload: null };
|
|
267
|
+
item.summary = describeChannel(item);
|
|
268
|
+
plan.push(item);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const given = Object.hasOwn(inputs, from) && inputs[from] !== undefined;
|
|
272
|
+
const as = c.as ?? "auto";
|
|
273
|
+
let item = { name: c.name, from, label, given, kind: "none", filter: c.filter ?? "linear", wrap: c.wrap ?? "clamp", as, payload: null };
|
|
274
|
+
if (given) {
|
|
275
|
+
const got = classify(inputs[from], as, { side });
|
|
276
|
+
if (got.problem) {
|
|
277
|
+
problems.push(`${label}: ${got.problem.replace(/^the input is/, `the input ${from} is`)}`);
|
|
278
|
+
item.kind = "none";
|
|
279
|
+
item.given = false;
|
|
280
|
+
} else {
|
|
281
|
+
item.kind = got.kind;
|
|
282
|
+
if (got.kind === "array") {
|
|
283
|
+
item.layers = got.blobs.length;
|
|
284
|
+
if (got.blobs.length > maxLayers) problems.push(`${label}: ${got.blobs.length} images are over the ${maxLayers} layers this GPU's array textures hold`);
|
|
285
|
+
item.payload = { blobs: got.blobs };
|
|
286
|
+
} else if (got.kind === "image" || got.kind === "video") item.payload = { blob: got.blob };
|
|
287
|
+
else if (got.kind === "audio") {
|
|
288
|
+
item.duration = got.duration;
|
|
289
|
+
item.payload = { pcm: got.pcm, sampleRate: got.sampleRate };
|
|
290
|
+
} else {
|
|
291
|
+
item.width = got.width;
|
|
292
|
+
item.height = got.height;
|
|
293
|
+
item.payload = { width: got.width, height: got.height, data: got.data };
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
notes.push(`${label}: no input named ${from}, so it reads opaque black`);
|
|
298
|
+
}
|
|
299
|
+
item.glsl = glslOf(item.kind, as);
|
|
300
|
+
if (item.kind === "numbers") {
|
|
301
|
+
if (item.filter !== "nearest") notes.push(`${label}: numbers are read exactly, so the filter is nearest`);
|
|
302
|
+
item.filter = "nearest";
|
|
303
|
+
}
|
|
304
|
+
// Numbers and Shadertoy's audio rows (a clip's, a microphone's) are read as laid out (row 0 at y = 0); pictures are flipped so their first row is at the top.
|
|
305
|
+
const audioRows = item.kind === "pixels" && Boolean(inputs[from]?.$audioRows);
|
|
306
|
+
if (audioRows) item.audioRows = true;
|
|
307
|
+
item.vflip = typeof c.vflip === "boolean" ? c.vflip : item.kind !== "numbers" && item.kind !== "audio" && !audioRows;
|
|
308
|
+
if (c.live) item.live = true;
|
|
309
|
+
item.summary = describeChannel(item);
|
|
310
|
+
plan.push(item);
|
|
311
|
+
}
|
|
312
|
+
return { plan, problems, notes };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The units a set of channels needs: a channel with something wired has a unit of its own; every channel with nothing wired
|
|
317
|
+
* shares one (a sampler2D) or one more (a sampler2DArray), which read opaque black. `internal` units belong to the pane (feedback's previous frame).
|
|
318
|
+
* `{ used, wired, internal, limit, free, text }`.
|
|
319
|
+
*/
|
|
320
|
+
export function channelBudget(plan, { limit = CHANNEL_LIMITS.minUnits, internal = 0, known = true } = {}) {
|
|
321
|
+
const wired = plan.filter((p) => p.kind !== "none").length;
|
|
322
|
+
const blank = (plan.some((p) => p.kind === "none" && p.glsl === "sampler2D") ? 1 : 0) + (plan.some((p) => p.kind === "none" && p.glsl === "sampler2DArray") ? 1 : 0);
|
|
323
|
+
const used = wired + blank;
|
|
324
|
+
const free = Math.max(0, limit - internal - used);
|
|
325
|
+
const gpu = known ? `this GPU has ${limit} texture units` : `WebGL2 guarantees ${limit} texture units`;
|
|
326
|
+
const text = `${used} of ${Math.max(0, limit - internal)} texture units used by channels (${gpu}${internal ? `, ${internal} for the previous frame` : ""})`;
|
|
327
|
+
return { used, wired, internal, limit, free, text };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Problems when the channels need more units than the GPU has for them. */
|
|
331
|
+
export function budgetProblems(plan, options) {
|
|
332
|
+
const b = channelBudget(plan, options);
|
|
333
|
+
return b.used > b.limit - b.internal ? [`the channels need ${b.used} texture units and ${b.limit - b.internal} are free (${b.limit} on this GPU${b.internal ? `, ${b.internal} used by the previous frame` : ""}): drop a channel, or put several images in one list`] : [];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Put channel names in Shadertoy's slots. A channel named iChannel0…iChannel3 sits in that slot; the others fill the free
|
|
338
|
+
* slots from the lowest. `{ slots, implicit }`: `slots[i]` is the name of slot i; a slot nothing fills is called iChannel<i>
|
|
339
|
+
* and listed in `implicit` (it reads opaque black). `extra` makes sure at least that many slots exist.
|
|
340
|
+
*/
|
|
341
|
+
export function slotOrder(names, extra = 0) {
|
|
342
|
+
const slots = [];
|
|
343
|
+
const rest = [];
|
|
344
|
+
for (const name of names) {
|
|
345
|
+
const m = /^iChannel([0-3])$/.exec(name);
|
|
346
|
+
if (m && slots[Number(m[1])] === undefined) slots[Number(m[1])] = name;
|
|
347
|
+
else rest.push(name);
|
|
348
|
+
}
|
|
349
|
+
let i = 0;
|
|
350
|
+
for (const name of rest) {
|
|
351
|
+
while (slots[i] !== undefined) i++;
|
|
352
|
+
slots[i] = name;
|
|
353
|
+
}
|
|
354
|
+
for (let j = slots.length; j < extra; j++) slots[j] = undefined;
|
|
355
|
+
const implicit = [];
|
|
356
|
+
const filled = Array.from(slots, (name, j) => {
|
|
357
|
+
if (name !== undefined) return name;
|
|
358
|
+
implicit.push(channelAlias(j));
|
|
359
|
+
return channelAlias(j);
|
|
360
|
+
});
|
|
361
|
+
return { slots: filled, implicit };
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The highest iChannel<n> (n below the alias count) the code reads, plus one; 0 when it reads none. */
|
|
365
|
+
export function aliasesUsed(strippedCode) {
|
|
366
|
+
let max = 0;
|
|
367
|
+
for (const m of String(strippedCode).matchAll(/\biChannel([0-9]+)\b/g)) if (Number(m[1]) < ALIAS_CHANNELS) max = Math.max(max, Number(m[1]) + 1);
|
|
368
|
+
return max;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The prelude lines for the channels, and where each lands. `channels` are `{ name, glsl }` (the declared ones), `samplerNames` the
|
|
373
|
+
* pane's sampler uniforms (declared with the other uniforms, counted as channels after these). `{ lines, tail, slots, implicit }`:
|
|
374
|
+
* `lines` come before the pane's own uniforms, `tail` (the iChannel<n> names) after.
|
|
375
|
+
*/
|
|
376
|
+
export function channelPrelude(channels, samplerNames, strippedCode) {
|
|
377
|
+
const declared = channels.map((c) => c.name);
|
|
378
|
+
const { slots, implicit } = slotOrder([...declared, ...samplerNames], aliasesUsed(strippedCode));
|
|
379
|
+
const lines = [];
|
|
380
|
+
for (const c of channels) {
|
|
381
|
+
if (c.glsl === "sampler2DArray") lines.push(`uniform highp sampler2DArray ${c.name};`, `uniform int ${c.name}Count;`);
|
|
382
|
+
else lines.push(`uniform sampler2D ${c.name};`);
|
|
383
|
+
}
|
|
384
|
+
for (const name of implicit) lines.push(`uniform sampler2D ${name};`);
|
|
385
|
+
lines.push(`uniform vec3 iChannelResolution[${Math.max(ALIAS_CHANNELS, slots.length)}];`, `uniform float iChannelTime[${Math.max(ALIAS_CHANNELS, slots.length)}];`);
|
|
386
|
+
const tail = [];
|
|
387
|
+
slots.slice(0, ALIAS_CHANNELS).forEach((name, i) => {
|
|
388
|
+
const alias = channelAlias(i);
|
|
389
|
+
if (name !== alias) tail.push(`#define ${alias} ${name}`);
|
|
390
|
+
});
|
|
391
|
+
return { lines, tail, slots, implicit };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** Is `value` a pointer device pane's state, `{ x, y, buttons, width, height, inside }` (src/device/model.js)? */
|
|
395
|
+
export const isPointerState = (value) =>
|
|
396
|
+
Boolean(value) && typeof value === "object" && !Array.isArray(value) && ["x", "y", "buttons", "width", "height"].every((k) => typeof value[k] === "number") && typeof value.inside === "boolean";
|
|
397
|
+
|
|
398
|
+
/** Is `value` a gamepad device pane's state, `{ connected, id, index, axes, buttons, pressed }` (src/device/model.js)? */
|
|
399
|
+
export const isGamepadState = (value) =>
|
|
400
|
+
Boolean(value) && typeof value === "object" && !Array.isArray(value) && typeof value.connected === "boolean" && Array.isArray(value.axes) && Array.isArray(value.buttons) && Array.isArray(value.pressed);
|
|
401
|
+
|
|
402
|
+
/** The most axes and buttons the gamepad texture has room for: one row each. */
|
|
403
|
+
export const GAMEPAD_TEXTURE_WIDTH = 32;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* A gamepad state as a data texture: 32 × 2 numbers, row 0 the axes (-1…1, after the pane's dead zone), row 1 the buttons' values
|
|
407
|
+
* (0…1), by index; all zero while no controller is connected. `{ width, height, data: Float32Array }`.
|
|
408
|
+
*/
|
|
409
|
+
export function gamepadTexture(state) {
|
|
410
|
+
const width = GAMEPAD_TEXTURE_WIDTH;
|
|
411
|
+
const data = new Float32Array(width * 2);
|
|
412
|
+
if (state?.connected) {
|
|
413
|
+
(state.axes ?? []).slice(0, width).forEach((v, i) => (data[i] = Number.isFinite(v) ? v : 0));
|
|
414
|
+
(state.buttons ?? []).slice(0, width).forEach((v, i) => (data[width + i] = Number.isFinite(v) ? v : typeof v === "object" && Number.isFinite(v?.value) ? v.value : 0));
|
|
415
|
+
}
|
|
416
|
+
return { width, height: 2, data };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Audio's samples for its texture: `{ $shaderAudio: { pcm, sampleRate, duration, channels, truncated } }` (one channel, the mean
|
|
421
|
+
* of its channels; at most CHANNEL_LIMITS.audioSamples). A WAV is read here (src/audio/wav.js); anything else goes to
|
|
422
|
+
* `decodeAudio(bytes)` (the page's Web Audio decoder), which gives `{ channels, sampleRate }`.
|
|
423
|
+
*/
|
|
424
|
+
export async function audioSamples(value, { decodeAudio } = {}) {
|
|
425
|
+
if (isAudioSamples(value)) return value;
|
|
426
|
+
const blob = value?.$media === "audio" ? value.blob : value;
|
|
427
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
428
|
+
let decoded;
|
|
429
|
+
if (audioTypeOfBytes(bytes) === "audio/wav") {
|
|
430
|
+
try {
|
|
431
|
+
decoded = decodeWav(bytes);
|
|
432
|
+
} catch {
|
|
433
|
+
decoded = null; // a WAV encoding this reader doesn't know (8-bit, compressed): the browser's decoder may
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (!decoded) {
|
|
437
|
+
if (!decodeAudio) throw new Error("only WAV audio can be read here");
|
|
438
|
+
decoded = await decodeAudio(bytes);
|
|
439
|
+
}
|
|
440
|
+
let pcm = mixDown(decoded.channels);
|
|
441
|
+
const truncated = pcm.length > CHANNEL_LIMITS.audioSamples;
|
|
442
|
+
if (truncated) pcm = pcm.slice(0, CHANNEL_LIMITS.audioSamples);
|
|
443
|
+
return { $shaderAudio: { pcm, sampleRate: decoded.sampleRate, duration: pcm.length / decoded.sampleRate, channels: decoded.channels.length, truncated } };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Make the inputs of the channels that want a picture (`as: "image"`, which a sampler uniform is) images: pixels and picture
|
|
448
|
+
* bytes are converted by an implicit adapter (src/model/adapters.js, `encode` makes the PNG) and listed in `adapted`;
|
|
449
|
+
* anything else is left for resolveChannels to refuse. A channel that takes data (`auto`, `numbers`) takes a keyboard device's
|
|
450
|
+
* state as Shadertoy's 256×3 keyboard texture and a gamepad's as a 32×2 texture (listed in `adapted` too); a channel that takes
|
|
451
|
+
* `auto` or `audio` takes audio (an audio media value or Blob) as the samples Shadertoy's 512×2 audio texture is made from
|
|
452
|
+
* (`options.decodeAudio` reads what isn't WAV). Otherwise data channels are not touched.
|
|
453
|
+
* `{ inputs, adapted }`; `inputs` is not changed.
|
|
454
|
+
*/
|
|
455
|
+
export async function adaptChannelInputs(channels, inputs, encode, { decodeAudio } = {}) {
|
|
456
|
+
const names = [...new Set(channels.filter((c) => c.as === "image").map((c) => c.from ?? c.name))];
|
|
457
|
+
const out = await adaptImageInputs(names, inputs, encode);
|
|
458
|
+
// A keyboard device's state at a channel that takes data is Shadertoy's keyboard texture (256×3, rows down/pressed/toggled).
|
|
459
|
+
const data = [...new Set(channels.filter((c) => !c.buffer && ["auto", "numbers", undefined].includes(c.as)).map((c) => c.from ?? c.name))];
|
|
460
|
+
for (const name of data) {
|
|
461
|
+
const value = inputs[name];
|
|
462
|
+
if (isKeyboardState(value)) {
|
|
463
|
+
const { width, height, data: texture } = keyboardTexture(value);
|
|
464
|
+
out.inputs[name] = { width, height, data: texture };
|
|
465
|
+
out.adapted.push({ name, from: "keyboard", to: "texture", label: `keyboard (${value.held.length} held) → 256×3 texture` });
|
|
466
|
+
} else if (isGamepadState(value)) {
|
|
467
|
+
out.inputs[name] = gamepadTexture(value);
|
|
468
|
+
out.adapted.push({ name, from: "gamepad", to: "texture", label: `gamepad (${value.connected ? `${value.axes.length} axes, ${value.buttons.length} buttons` : "not connected"}) → 32×2 texture (axes, buttons)` });
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
// A microphone device pane's analysis at a channel that takes audio or data: Shadertoy's 512×2 mic texture (row 0 the
|
|
472
|
+
// spectrum, row 1 the waveform). Live, the page sends a new one each frame the shader draws (src/ui/shader-live.js).
|
|
473
|
+
const mic = [...new Set(channels.filter((c) => !c.buffer && ["auto", "audio", "pixels", undefined].includes(c.as)).map((c) => c.from ?? c.name))];
|
|
474
|
+
for (const name of mic) {
|
|
475
|
+
const value = inputs[name];
|
|
476
|
+
if (!isAudioStream(value)) continue;
|
|
477
|
+
out.inputs[name] = { ...micTexture(value), $audioRows: true };
|
|
478
|
+
out.adapted.push({ name, from: "microphone", to: "texture", label: `microphone (${value.spectrum.length} bands, level ${Number(value.level).toFixed(2)}) → 512×2 spectrum and waveform texture` });
|
|
479
|
+
}
|
|
480
|
+
// Audio at a channel that takes it: Shadertoy's music channel, made from the samples at the frame's time.
|
|
481
|
+
const sound = [...new Set(channels.filter((c) => !c.buffer && ["auto", "audio", undefined].includes(c.as)).map((c) => c.from ?? c.name))];
|
|
482
|
+
for (const name of sound) {
|
|
483
|
+
const value = inputs[name];
|
|
484
|
+
if (!isAudioInput(value) || isAudioSamples(value)) continue;
|
|
485
|
+
let samples;
|
|
486
|
+
try {
|
|
487
|
+
samples = await audioSamples(value, { decodeAudio });
|
|
488
|
+
} catch (error) {
|
|
489
|
+
throw new Error(`the input ${name} is audio that couldn't be read (${error?.message ?? error})`);
|
|
490
|
+
}
|
|
491
|
+
out.inputs[name] = samples;
|
|
492
|
+
const a = samples.$shaderAudio;
|
|
493
|
+
out.adapted.push({ name, from: "audio", to: "texture", label: `audio (${Math.round(a.duration * 100) / 100} s, ${a.channels === 1 ? "mono" : `${a.channels} channels mixed`}) → 512×2 FFT and waveform texture${a.truncated ? " (only the first part: it is long)" : ""}` });
|
|
494
|
+
}
|
|
495
|
+
return out;
|
|
496
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// What the shader modules share: the words a name may not be, Shadertoy's names for the things a
|
|
2
|
+
// shader reads (the aliases), and a few small helpers. Pure: no DOM, no WebGL.
|
|
3
|
+
|
|
4
|
+
/** GLSL's keywords and the shader's own names, none of which a uniform or a channel may be called. */
|
|
5
|
+
export const RESERVED_WORDS = new Set(
|
|
6
|
+
("attribute bool break bvec2 bvec3 bvec4 case centroid const continue default discard do double else false flat float for highp if in inout int invariant ivec2 ivec3 ivec4 layout lowp main mat2 mat3 mat4 mediump out outColor precision return sampler2D sampler3D samplerCube smooth struct switch true uint uniform uvec2 uvec3 uvec4 varying vec2 vec3 vec4 void while mainImage fragColor fragCoord " +
|
|
7
|
+
"input output common partition active asm class union enum typedef template this resource goto inline noinline public static extern external interface long short half fixed unsigned superp namespace using sizeof cast filter sampler1D sampler2DRect volatile sampler2DArray")
|
|
8
|
+
.split(/\s+/),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Shadertoy's names for what a shader reads, always declared for the shader (`u_*` names keep working beside
|
|
13
|
+
* them). `mallory` is the matching name of the shader pane's own where there is one.
|
|
14
|
+
*/
|
|
15
|
+
export const ALIASES = [
|
|
16
|
+
{ name: "iResolution", type: "vec3", glsl: "vec3", mallory: "u_resolution", description: "the output size in pixels: (width, height, 1)" },
|
|
17
|
+
{ name: "iTime", type: "float", glsl: "float", mallory: "u_time", description: "seconds: shader.t, or the input named time" },
|
|
18
|
+
{ name: "iTimeDelta", type: "float", glsl: "float", description: "seconds one frame lasts: 1 / fps" },
|
|
19
|
+
{ name: "iFrame", type: "int", glsl: "int", mallory: "u_frame", description: "the frame number: shader.frame, or the input named frame" },
|
|
20
|
+
{ name: "iFrameRate", type: "float", glsl: "float", description: "frames per second: shader.fps" },
|
|
21
|
+
{ name: "iMouse", type: "vec4", glsl: "vec4", description: "Shadertoy's mouse (xy: the pointer in pixels, zw: where it went down) from the input named mouse or iMouse (numbers, or a pointer device pane's state); zero without one" },
|
|
22
|
+
{ name: "iDate", type: "vec4", glsl: "vec4", description: "(year, month 0-11, day 1-31, seconds since midnight) of a fixed epoch plus t, never the wall clock" },
|
|
23
|
+
{ name: "iSampleRate", type: "float", glsl: "float", description: "44100: the rate Shadertoy reports for its audio" },
|
|
24
|
+
{ name: "iChannelResolution", type: "vec3[]", glsl: "vec3", description: "per channel: (width, height, 1) of its texture; z is the layer count of a list" },
|
|
25
|
+
{ name: "iChannelTime", type: "float[]", glsl: "float", description: "per channel: the playback time of its media, 0 for a picture" },
|
|
26
|
+
];
|
|
27
|
+
export const ALIAS_NAMES = new Set(ALIASES.map((a) => a.name));
|
|
28
|
+
/** The buffer passes a shader may have, in the order they run (Shadertoy's Buffer A to Buffer D). */
|
|
29
|
+
export const BUFFER_NAMES = ["A", "B", "C", "D"];
|
|
30
|
+
/** iChannel0…iChannel3: Shadertoy's four, names for the first four channels. */
|
|
31
|
+
export const ALIAS_CHANNELS = 4;
|
|
32
|
+
export const channelAlias = (index) => `iChannel${index}`;
|
|
33
|
+
/** Is `name` one of Shadertoy's channel names (iChannel followed by digits)? */
|
|
34
|
+
export const isChannelAlias = (name) => /^iChannel\d+$/.test(String(name));
|
|
35
|
+
|
|
36
|
+
export const finite = (n, fallback) => (Number.isFinite(Number(n)) && n !== null && n !== "" && typeof n !== "boolean" ? Number(n) : fallback);
|
|
37
|
+
|
|
38
|
+
export const describe = (v) => {
|
|
39
|
+
try {
|
|
40
|
+
const s = JSON.stringify(v);
|
|
41
|
+
return s === undefined ? String(v) : s.length > 40 ? `${s.slice(0, 37)}…` : s;
|
|
42
|
+
} catch {
|
|
43
|
+
return String(v);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** An image input's bytes: a media value or a Blob (a URL is fetched by the page first). */
|
|
48
|
+
export function imageOf(value) {
|
|
49
|
+
const blob = value?.$media === "image" ? value.blob : typeof Blob !== "undefined" && value instanceof Blob ? value : null;
|
|
50
|
+
return blob && (!blob.type || blob.type.startsWith("image/")) ? blob : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The epoch iDate counts from: 2000-01-01 00:00:00 UTC. A shader never sees the wall clock. */
|
|
54
|
+
export const DATE_EPOCH_MS = Date.UTC(2000, 0, 1);
|
|
55
|
+
|
|
56
|
+
/** iDate at `t` seconds: [year, month 0-11, day 1-31, seconds since midnight (UTC)]. */
|
|
57
|
+
export function iDateOf(t) {
|
|
58
|
+
const d = new Date(DATE_EPOCH_MS + Math.round(finite(t, 0) * 1000));
|
|
59
|
+
return [d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours() * 3600 + d.getUTCMinutes() * 60 + d.getUTCSeconds() + d.getUTCMilliseconds() / 1000];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const SAMPLE_RATE = 44100;
|
|
63
|
+
|
|
64
|
+
const MOUSE_NAMES = ["iMouse", "mouse"];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* iMouse for a run, from the input named `iMouse` or `mouse` (unless a declared uniform or channel owns that name):
|
|
68
|
+
* a list of 2 to 4 numbers or `{ x, y, z, w }`, in pixels, as Shadertoy defines them. `{ value, problem, name }`; zero without one.
|
|
69
|
+
*/
|
|
70
|
+
export function mouseOf(inputs = {}, owned = new Set()) {
|
|
71
|
+
const name = MOUSE_NAMES.find((n) => !owned.has(n) && Object.hasOwn(inputs, n) && inputs[n] !== undefined);
|
|
72
|
+
if (!name) return { value: [0, 0, 0, 0], name: null };
|
|
73
|
+
const given = inputs[name];
|
|
74
|
+
// A pointer device pane's state ({ x, y, buttons, width, height, inside }): xy where it is, zw where it is too while a button is
|
|
75
|
+
// down and negated while none is (Shadertoy's sign convention; a value has no memory of where the button went down). Its y is from
|
|
76
|
+
// the top unless the pointer pane flips it (flipY), as Shadertoy counts from the bottom.
|
|
77
|
+
if (given && typeof given === "object" && !Array.isArray(given) && ["x", "y", "buttons", "width", "height"].every((k) => typeof given[k] === "number") && typeof given.inside === "boolean") {
|
|
78
|
+
const x = finite(given.x, 0);
|
|
79
|
+
const y = finite(given.y, 0);
|
|
80
|
+
const down = given.buttons > 0;
|
|
81
|
+
return { value: [x, y, down ? x : -x, down ? y : -y], name, from: "pointer" };
|
|
82
|
+
}
|
|
83
|
+
const parts = Array.isArray(given) ? given : given && typeof given === "object" ? ["x", "y", "z", "w"].map((k) => given[k]) : null;
|
|
84
|
+
const trimmed = parts && !Array.isArray(given) ? parts.map((p) => (p === undefined ? 0 : p)) : parts;
|
|
85
|
+
if (!trimmed || trimmed.length < 2 || trimmed.length > 4 || trimmed.some((p) => finite(p, null) === null)) {
|
|
86
|
+
return { value: [0, 0, 0, 0], name, problem: `the input ${name} (${describe(given)}) is not a list of 2 to 4 numbers or { x, y, z, w }` };
|
|
87
|
+
}
|
|
88
|
+
const value = [0, 0, 0, 0].map((_, i) => finite(trimmed[i], 0));
|
|
89
|
+
return { value, name };
|
|
90
|
+
}
|