@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,106 @@
|
|
|
1
|
+
// Size hints for a pane's outer rect (window-algebra's constrainSize): a type's
|
|
2
|
+
// minimum and maximum size, an aspect ratio to keep, and width/height
|
|
3
|
+
// increments for panes that read in character cells. Pure: the page, a
|
|
4
|
+
// headless session and tests all go through `constrainPane`.
|
|
5
|
+
//
|
|
6
|
+
// A pane type's record gives `sizeHint(pane)`, an object with any of
|
|
7
|
+
// minWidth, minHeight, maxWidth, maxHeight the outer rect's limits (defaults 180 and 60)
|
|
8
|
+
// aspectRatio width / height of the pane's content
|
|
9
|
+
// chromeWidth, chromeHeight what the pane's header, toolbar and padding take of
|
|
10
|
+
// the outer rect, so the ratio holds for the content
|
|
11
|
+
// widthIncrement, heightIncrement the cell size; the outer size is base + n * increment
|
|
12
|
+
// baseWidth, baseHeight the chrome around the cells (default: the chrome)
|
|
13
|
+
// Only the outer rect changes: a pane's body lays itself out inside it.
|
|
14
|
+
import { geometry } from "@johnhenry/window-algebra";
|
|
15
|
+
import { paneType } from "../panes/registry.js";
|
|
16
|
+
|
|
17
|
+
export const MIN_WIDTH = 180;
|
|
18
|
+
export const MIN_HEIGHT = 60;
|
|
19
|
+
|
|
20
|
+
const finite = (v) => typeof v === "number" && Number.isFinite(v);
|
|
21
|
+
const positive = (v) => finite(v) && v > 0;
|
|
22
|
+
|
|
23
|
+
/** The hints of `pane` (its record's `sizeHint`), with the defaults filled in; never throws. */
|
|
24
|
+
export function hintsOf(pane) {
|
|
25
|
+
let raw;
|
|
26
|
+
try {
|
|
27
|
+
const hint = paneType(pane?.type)?.sizeHint;
|
|
28
|
+
raw = typeof hint === "function" ? hint(pane) : hint;
|
|
29
|
+
} catch {
|
|
30
|
+
raw = undefined;
|
|
31
|
+
}
|
|
32
|
+
const h = raw && typeof raw === "object" ? raw : {};
|
|
33
|
+
const chromeWidth = finite(h.chromeWidth) ? Math.max(0, h.chromeWidth) : 0;
|
|
34
|
+
const chromeHeight = finite(h.chromeHeight) ? Math.max(0, h.chromeHeight) : 0;
|
|
35
|
+
return {
|
|
36
|
+
minWidth: finite(h.minWidth) ? Math.max(MIN_WIDTH, h.minWidth) : MIN_WIDTH,
|
|
37
|
+
minHeight: finite(h.minHeight) ? Math.max(MIN_HEIGHT, h.minHeight) : MIN_HEIGHT,
|
|
38
|
+
maxWidth: positive(h.maxWidth) ? h.maxWidth : Infinity,
|
|
39
|
+
maxHeight: positive(h.maxHeight) ? h.maxHeight : Infinity,
|
|
40
|
+
aspectRatio: positive(h.aspectRatio) ? h.aspectRatio : undefined,
|
|
41
|
+
chromeWidth,
|
|
42
|
+
chromeHeight,
|
|
43
|
+
widthIncrement: positive(h.widthIncrement) ? h.widthIncrement : undefined,
|
|
44
|
+
heightIncrement: positive(h.heightIncrement) ? h.heightIncrement : undefined,
|
|
45
|
+
baseWidth: finite(h.baseWidth) ? h.baseWidth : chromeWidth,
|
|
46
|
+
baseHeight: finite(h.baseHeight) ? h.baseHeight : chromeHeight,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The size `pane` gets for a requested `{ width, height }`. A `height` of 0 is
|
|
52
|
+
* "size to content": it stays 0, and only the width is constrained (no ratio,
|
|
53
|
+
* no row increments). `preserve` ("width" or "height") is the side an aspect
|
|
54
|
+
* ratio holds still; the default is the width.
|
|
55
|
+
*/
|
|
56
|
+
export function constrainPane(pane, request, { preserve = "width" } = {}) {
|
|
57
|
+
const hints = hintsOf(pane);
|
|
58
|
+
const auto = !(request.height > 0);
|
|
59
|
+
const { chromeWidth: cw, chromeHeight: ch } = hints;
|
|
60
|
+
// The ratio and the cells are about the content: take the chrome off, constrain, put it back.
|
|
61
|
+
const fixedRatio = !auto && hints.aspectRatio !== undefined;
|
|
62
|
+
const out = geometry.constrainSize(
|
|
63
|
+
{ width: request.width - cw, height: auto ? hints.minHeight - ch : request.height - ch },
|
|
64
|
+
{
|
|
65
|
+
minWidth: hints.minWidth - cw,
|
|
66
|
+
minHeight: hints.minHeight - ch,
|
|
67
|
+
maxWidth: hints.maxWidth - cw,
|
|
68
|
+
maxHeight: hints.maxHeight - ch,
|
|
69
|
+
aspectRatio: fixedRatio ? hints.aspectRatio : undefined,
|
|
70
|
+
widthIncrement: hints.widthIncrement,
|
|
71
|
+
heightIncrement: auto ? undefined : hints.heightIncrement,
|
|
72
|
+
baseWidth: hints.baseWidth - cw,
|
|
73
|
+
baseHeight: hints.baseHeight - ch,
|
|
74
|
+
},
|
|
75
|
+
{ preserve },
|
|
76
|
+
);
|
|
77
|
+
return { width: Math.round(out.width + cw), height: auto ? 0 : Math.round(out.height + ch) };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The `{ cols, rows }` readout ("80×24") of a pane with increments at `size`, or null. */
|
|
81
|
+
export function cellsOf(pane, size) {
|
|
82
|
+
const h = hintsOf(pane);
|
|
83
|
+
if (!h.widthIncrement && !h.heightIncrement) return null;
|
|
84
|
+
return geometry.sizeToCells(
|
|
85
|
+
{ width: size.width, height: size.height },
|
|
86
|
+
{ widthIncrement: h.widthIncrement, heightIncrement: h.heightIncrement, baseWidth: h.baseWidth, baseHeight: h.baseHeight },
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** "80×24" for cells (a missing side shows as "–"), or "". */
|
|
91
|
+
export function cellsText(cells) {
|
|
92
|
+
return cells ? `${cells.cols ?? "–"}×${cells.rows ?? "–"}` : "";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** What `pane` has of hints, for a person or an agent to read; undefined when it has only the defaults. */
|
|
96
|
+
export function describeHints(pane) {
|
|
97
|
+
const h = hintsOf(pane);
|
|
98
|
+
const out = {};
|
|
99
|
+
if (h.aspectRatio) out.aspectRatio = Math.round(h.aspectRatio * 1000) / 1000;
|
|
100
|
+
if (h.widthIncrement || h.heightIncrement) out.cell = { width: h.widthIncrement ?? null, height: h.heightIncrement ?? null };
|
|
101
|
+
if (h.minWidth !== MIN_WIDTH) out.minWidth = h.minWidth;
|
|
102
|
+
if (h.minHeight !== MIN_HEIGHT) out.minHeight = h.minHeight;
|
|
103
|
+
if (h.maxWidth !== Infinity) out.maxWidth = h.maxWidth;
|
|
104
|
+
if (h.maxHeight !== Infinity) out.maxHeight = h.maxHeight;
|
|
105
|
+
return Object.keys(out).length ? out : undefined;
|
|
106
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Small helpers for pane records' size hints (src/model/size-hints.js). Kept apart from it so a record can
|
|
2
|
+
// import them without a cycle through the registry.
|
|
3
|
+
|
|
4
|
+
/** width / height of `{ width, height }` when both are positive numbers, else undefined (no ratio to keep). */
|
|
5
|
+
export const ratioOf = (size) => {
|
|
6
|
+
const w = Number(size?.width);
|
|
7
|
+
const h = Number(size?.height);
|
|
8
|
+
return Number.isFinite(w) && Number.isFinite(h) && w > 0 && h > 0 ? w / h : undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** The hints of a pane read in character cells (monospace text, 12px): 10px a column, 17px a row, inside the pane's chrome. */
|
|
12
|
+
export const CELL_HINT = { widthIncrement: 10, heightIncrement: 17, baseWidth: 20, baseHeight: 94 };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// A skill pane's settings (CLW-SKL-01; docs/guide/agents-and-machines.md "Skills"): which skill it ASKS to read. Pure; imports nothing of the skills module. `name` is only a
|
|
2
|
+
// REQUEST: the canvas document never holds a skill's instructions, a grant or the library's switch. A pane reads only what the person's per-pane grant allows
|
|
3
|
+
// (src/skills/config.js), and `name` is a person-only setting (src/panes/skill.js), so a file or an agent cannot ask for a skill on the person's behalf.
|
|
4
|
+
export const defaultSkill = () => ({ name: "" });
|
|
5
|
+
|
|
6
|
+
const NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
7
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
8
|
+
|
|
9
|
+
/** The settings in bounds (never throws). */
|
|
10
|
+
export const skillSettings = (raw) => ({ name: isObject(raw) && typeof raw.name === "string" && raw.name.length <= 64 && NAME.test(raw.name) ? raw.name : "" });
|
|
11
|
+
|
|
12
|
+
/** Why these settings are not sound, or "". */
|
|
13
|
+
export function skillProblem(raw) {
|
|
14
|
+
if (raw === undefined) return "";
|
|
15
|
+
if (!isObject(raw)) return "skill: { name }";
|
|
16
|
+
if (raw.name !== undefined && !(typeof raw.name === "string" && (raw.name === "" || (raw.name.length <= 64 && NAME.test(raw.name))))) return "skill.name: a skill's name (lower-case letters, digits and hyphens)";
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const describeSkill = (raw) => {
|
|
21
|
+
const s = skillSettings(raw);
|
|
22
|
+
return `Skill: asks to read ${s.name ? `the skill "${s.name}"` : "a skill (none chosen yet)"}. Nothing is in this file; the person's own skill is read only if they allow this pane.`;
|
|
23
|
+
};
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
// The geometry of snapping: pure, no DOM, no settings. Rects are
|
|
2
|
+
// { id?, x, y, width, height } in world units (x, y: the top-left corner).
|
|
3
|
+
//
|
|
4
|
+
// - the square lattice: a corner rounds to multiples of the x step and the
|
|
5
|
+
// y step, each axis its own (snapLattice);
|
|
6
|
+
// - the polar lattice: a pane's CENTRE rounds to the nearest ring (a
|
|
7
|
+
// multiple of the ring step r) and spoke (every `angle` degrees,
|
|
8
|
+
// spoke 0 pointing right, clockwise on screen) around a hub (polarRound);
|
|
9
|
+
// every lattice point comes from polarPoint, which the grid's dots
|
|
10
|
+
// (polarDots) use too, so what is drawn is where panes land;
|
|
11
|
+
// - alignment guides: a moving rect's left / centre / right (top / middle /
|
|
12
|
+
// bottom) meets the same lines of other panes within a threshold
|
|
13
|
+
// (findAlignment, over a sorted index so a drag stays fast with hundreds
|
|
14
|
+
// of panes), and equal spacing: the gap to a neighbour in the same row
|
|
15
|
+
// (column) matches a gap between two panes there (findSpacing);
|
|
16
|
+
// - snapMove / snapResize combine them: on each axis a guide beats the grid,
|
|
17
|
+
// and the closer of an alignment and a spacing match wins (alignment on a
|
|
18
|
+
// tie). The polar lattice moves both coordinates at once, so it applies
|
|
19
|
+
// only when no guide applies on either axis.
|
|
20
|
+
//
|
|
21
|
+
// src/ui/snapping.js reads the settings, measures the panes and draws the
|
|
22
|
+
// guides; src/model/arrange.js `radial` places panes on the polar lattice.
|
|
23
|
+
|
|
24
|
+
/** Guides catch within this many screen pixels, whatever the zoom (divide by the zoom for world units). */
|
|
25
|
+
export const GUIDE_PX = 6;
|
|
26
|
+
|
|
27
|
+
const EPS = 1e-6;
|
|
28
|
+
|
|
29
|
+
/** Round `v` to a multiple of `step` (no step: unchanged). */
|
|
30
|
+
export const roundTo = (v, step) => (step > 0 ? Math.round(v / step) * step || 0 : v); // || 0: never -0
|
|
31
|
+
|
|
32
|
+
/** A corner on the square lattice: `x` rounds to the x step, `y` to the y step. */
|
|
33
|
+
export function snapLattice(point, steps) {
|
|
34
|
+
const { x: gx, y: gy } = stepsOf(steps);
|
|
35
|
+
return { x: roundTo(point.x, gx), y: roundTo(point.y, gy) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** `{ x, y }` steps from a number (both axes) or an object; missing or bad steps are 0 (no rounding). */
|
|
39
|
+
export function stepsOf(steps) {
|
|
40
|
+
const ok = (n) => (Number.isFinite(n) && n > 0 ? n : 0);
|
|
41
|
+
if (typeof steps === "number") return { x: ok(steps), y: ok(steps) };
|
|
42
|
+
return { x: ok(steps?.x), y: ok(steps?.y) };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Square grid lines closer than this many screen pixels are thinned. */
|
|
46
|
+
export const LINE_MIN_PX = 6;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Every how many snap lines the square grid's lines style draws one:
|
|
50
|
+
* 1, 2, 4, … — the fewest that keeps them `minPx` apart on screen at `zoom`.
|
|
51
|
+
* Every line drawn is still a snap line.
|
|
52
|
+
*/
|
|
53
|
+
export function lineEvery(step, zoom, minPx = LINE_MIN_PX) {
|
|
54
|
+
if (!(step > 0) || !(zoom > 0)) return 1;
|
|
55
|
+
let every = 1;
|
|
56
|
+
while (step * zoom * every < minPx && every < 1 << 20) every *= 2;
|
|
57
|
+
return every;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The spokes of a polar grid: `angle` degrees apart (1 to 360),
|
|
62
|
+
* spoke 0 pointing right. n = ⌈360 / angle⌉ spokes, spoke s at s × angle;
|
|
63
|
+
* when the angle divides 360 they are evenly spaced, else the last gap (from
|
|
64
|
+
* spoke n − 1 back round to spoke 0) is the shorter remainder, 360 −
|
|
65
|
+
* (n − 1) × angle degrees. A grid given the old way, `spokes` (a count) and
|
|
66
|
+
* no `angle`, has 360 / spokes. Returns { n, step } (step in radians).
|
|
67
|
+
*/
|
|
68
|
+
export function polarSpokes(grid) {
|
|
69
|
+
const deg = angleOf(grid);
|
|
70
|
+
return { n: Math.max(1, Math.ceil(360 / deg - 1e-9)), step: (deg * Math.PI) / 180, angle: deg };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A grid's angle step in degrees: `angle` (clamped to 1…360), else 360 / `spokes`, else 360 (one spoke). */
|
|
74
|
+
export function angleOf(grid) {
|
|
75
|
+
const a = Number(grid?.angle);
|
|
76
|
+
if (Number.isFinite(a) && a > 0) return Math.min(360, Math.max(1, a));
|
|
77
|
+
const n = Math.floor(Number(grid?.spokes));
|
|
78
|
+
return n >= 1 ? 360 / n : 360;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The polar lattice point nearest `point` around `hub`: the radius rounds to
|
|
83
|
+
* a multiple of `ring` (at least `minRing` rings out: 1 keeps panes off a hub
|
|
84
|
+
* pane), the angle to the nearest spoke (polarSpokes: every `angle` degrees,
|
|
85
|
+
* 0 pointing right, then clockwise on screen, as y grows downward; past the
|
|
86
|
+
* last spoke the next is spoke 0 again, at 360°). Returns the point and its
|
|
87
|
+
* ring and spoke indices.
|
|
88
|
+
*/
|
|
89
|
+
export function polarRound(point, grid = {}) {
|
|
90
|
+
const { hub = { x: 0, y: 0 }, ring, minRing = 0 } = grid;
|
|
91
|
+
const dx = point.x - hub.x;
|
|
92
|
+
const dy = point.y - hub.y;
|
|
93
|
+
const r = Math.hypot(dx, dy);
|
|
94
|
+
const k = ring > 0 ? Math.max(minRing, Math.round(r / ring)) : r;
|
|
95
|
+
const radius = ring > 0 ? k * ring : r;
|
|
96
|
+
const { n, step } = polarSpokes(grid);
|
|
97
|
+
// At the hub itself the angle is undefined: spoke 0.
|
|
98
|
+
let a = r < EPS ? 0 : Math.atan2(dy, dx);
|
|
99
|
+
if (a < 0) a += 2 * Math.PI;
|
|
100
|
+
// Between spoke s0 and the next one (spoke 0 again, at 360°, after the last): the nearer; halfway goes to the next.
|
|
101
|
+
const s0 = Math.min(n - 1, Math.floor(a / step + EPS));
|
|
102
|
+
const next = s0 + 1 < n ? (s0 + 1) * step : 2 * Math.PI;
|
|
103
|
+
const s = a - s0 * step < next - a - EPS ? s0 : (s0 + 1) % n;
|
|
104
|
+
return { ...polarPoint(grid, k, s, radius), ring: ring > 0 ? k : undefined, spoke: s, radius, angle: s * step };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The polar lattice point on ring `k`, spoke `s` (at `radius`, k rings out
|
|
109
|
+
* by default): where snapping puts a pane's centre (polarRound, polarFree)
|
|
110
|
+
* and where the polar grid draws a dot (polarDots). Ring 0 is the hub.
|
|
111
|
+
*/
|
|
112
|
+
export function polarPoint(grid, k, s, radius = k * grid.ring) {
|
|
113
|
+
const hub = grid.hub ?? { x: 0, y: 0 };
|
|
114
|
+
const a = s * polarSpokes(grid).step;
|
|
115
|
+
return { x: hub.x + radius * Math.cos(a), y: hub.y + radius * Math.sin(a) };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Rings closer than this many screen pixels are thinned (drawn every second, third, … one): the lines style. */
|
|
119
|
+
export const POLAR_MIN_PX = 8;
|
|
120
|
+
|
|
121
|
+
/** The dots style thins rings and spokes closer than this (its dots are larger, so they need more room not to crowd). */
|
|
122
|
+
export const POLAR_DOT_MIN_PX = 12;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Which rings to draw (k = first, first + every, … ≤ last) for the polar grid
|
|
126
|
+
* around `hub` seen through `view` (a world rect) at `zoom`: the rings that
|
|
127
|
+
* cross the view, every `every`-th one so that they are at least `minPx`
|
|
128
|
+
* apart on screen, and never more than `max` of them. `close` is the view's
|
|
129
|
+
* nearest distance from the hub (0 when the hub is in view) and `far` its
|
|
130
|
+
* farthest.
|
|
131
|
+
*/
|
|
132
|
+
export function polarRings({ hub = { x: 0, y: 0 }, ring }, view, { zoom = 1, minPx = POLAR_MIN_PX, max = 400 } = {}) {
|
|
133
|
+
const corners = [
|
|
134
|
+
[view.x, view.y],
|
|
135
|
+
[view.x + view.width, view.y],
|
|
136
|
+
[view.x, view.y + view.height],
|
|
137
|
+
[view.x + view.width, view.y + view.height],
|
|
138
|
+
];
|
|
139
|
+
const far = Math.max(...corners.map(([x, y]) => Math.hypot(x - hub.x, y - hub.y)));
|
|
140
|
+
const nx = Math.max(view.x, Math.min(hub.x, view.x + view.width));
|
|
141
|
+
const ny = Math.max(view.y, Math.min(hub.y, view.y + view.height));
|
|
142
|
+
const close = Math.hypot(nx - hub.x, ny - hub.y);
|
|
143
|
+
if (!(ring > 0)) return { first: 1, last: 0, every: 1, close, far };
|
|
144
|
+
let every = Math.max(1, Math.ceil(minPx / (ring * zoom)));
|
|
145
|
+
const first = Math.max(1, Math.ceil(close / ring));
|
|
146
|
+
const last = Math.floor(far / ring);
|
|
147
|
+
while ((last - first) / every > max) every *= 2;
|
|
148
|
+
return { first: Math.ceil(first / every) * every, last, every, close, far };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The dots the polar grid draws in `view` (a world rect) at `zoom`: one at
|
|
153
|
+
* each snap point, every ring × spoke (polarPoint, the same math snapping
|
|
154
|
+
* uses), plus the hub's centre. Only points in the view; rings are thinned as
|
|
155
|
+
* polarRings thins them, and on a ring whose neighbouring spokes are closer
|
|
156
|
+
* than `minPx` on screen (near the hub, zoomed out) every d-th spoke is kept,
|
|
157
|
+
* d a divisor of the spoke count (spoke 0 always). `minPx` defaults to
|
|
158
|
+
* POLAR_DOT_MIN_PX: dots are larger than lines are wide. Returns [{ x, y, ring, spoke }].
|
|
159
|
+
*/
|
|
160
|
+
export function polarDots(grid, view, { zoom = 1, minPx = POLAR_DOT_MIN_PX, max } = {}) {
|
|
161
|
+
const { hub = { x: 0, y: 0 }, ring } = grid;
|
|
162
|
+
const { n, step } = polarSpokes(grid);
|
|
163
|
+
const inView = (p) => p.x >= view.x && p.x <= view.x + view.width && p.y >= view.y && p.y <= view.y + view.height;
|
|
164
|
+
const out = [];
|
|
165
|
+
if (inView(hub)) out.push({ x: hub.x, y: hub.y, ring: 0, spoke: 0 });
|
|
166
|
+
if (!(ring > 0)) return out;
|
|
167
|
+
const { first, last, every } = polarRings(grid, view, { zoom, minPx, max });
|
|
168
|
+
const divisors = [];
|
|
169
|
+
for (let d = 1; d <= n; d++) if (n % d === 0) divisors.push(d);
|
|
170
|
+
for (let k = first; k <= last; k += every) {
|
|
171
|
+
const arc = k * ring * step * zoom; // screen px between neighbouring spokes on this ring
|
|
172
|
+
const stride = divisors.find((d) => arc * d >= minPx) ?? n;
|
|
173
|
+
for (let s = 0; s < n; s += stride) {
|
|
174
|
+
const p = polarPoint(grid, k, s);
|
|
175
|
+
if (inView(p)) out.push({ x: p.x, y: p.y, ring: k, spoke: s });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** True when two rects overlap (touching edges don't count). */
|
|
182
|
+
const overlap = (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;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The nearest FREE spot on the polar lattice for a pane of `size` ({ width,
|
|
186
|
+
* height }) whose centre the pointer put at `point`: the spots (every ring
|
|
187
|
+
* from `minRing`, every spoke) are tried by their distance from `point`
|
|
188
|
+
* (ties: the inner ring first, then the lower spoke), and the first where the
|
|
189
|
+
* pane, placed as snapping places it (its corner on whole units), overlaps
|
|
190
|
+
* none of `obstacles` wins. Only spots within `reach` of `point` are tried
|
|
191
|
+
* (default: the nearest spot's distance plus two ring steps or the pane's
|
|
192
|
+
* diagonal, whichever is more), so a pane is
|
|
193
|
+
* never thrown far from the pointer: null when none of them is free (the
|
|
194
|
+
* caller then leaves the pane where the pointer put it). Returns
|
|
195
|
+
* { x, y, centre, ring, spoke, distance, nearest } where x, y is the
|
|
196
|
+
* corner and `nearest` says whether it is the nearest spot (not displaced).
|
|
197
|
+
*/
|
|
198
|
+
export function polarFree(point, size, grid, obstacles = [], { reach } = {}) {
|
|
199
|
+
const { hub = { x: 0, y: 0 }, ring, minRing = 0 } = grid ?? {};
|
|
200
|
+
const { n } = polarSpokes(grid);
|
|
201
|
+
const w = size.width;
|
|
202
|
+
const h = size.height;
|
|
203
|
+
const spot = (k, s, r = k * ring) => {
|
|
204
|
+
const centre = polarPoint({ ...grid, hub }, k, s, r);
|
|
205
|
+
return { x: Math.round(centre.x - w / 2), y: Math.round(centre.y - h / 2), width: w, height: h, centre, ring: k, spoke: s, distance: Math.hypot(centre.x - point.x, centre.y - point.y) };
|
|
206
|
+
};
|
|
207
|
+
const first = polarRound(point, grid ?? {});
|
|
208
|
+
const nearestSpot = spot(first.ring ?? 0, first.spoke, first.radius);
|
|
209
|
+
// Far enough to reach the next spoke over for a pane of this size, never far from the pointer.
|
|
210
|
+
const limit = reach ?? nearestSpot.distance + Math.max(2 * (ring > 0 ? ring : 0), Math.hypot(w, h));
|
|
211
|
+
// Only the panes the pane could reach matter.
|
|
212
|
+
const area = { x: point.x - limit - w / 2, y: point.y - limit - h / 2, width: 2 * limit + w, height: 2 * limit + h };
|
|
213
|
+
const near = obstacles.filter((o) => o && overlap(o, area));
|
|
214
|
+
const free = (c) => !near.some((o) => overlap(c, o));
|
|
215
|
+
if (!(ring > 0)) return free(nearestSpot) ? { ...nearestSpot, nearest: true } : null;
|
|
216
|
+
const r0 = Math.hypot(point.x - hub.x, point.y - hub.y);
|
|
217
|
+
const candidates = [];
|
|
218
|
+
for (let k = Math.max(minRing, Math.floor((r0 - limit) / ring)); k <= Math.ceil((r0 + limit) / ring); k++) {
|
|
219
|
+
for (let s = 0; s < (k === 0 ? 1 : n); s++) {
|
|
220
|
+
const c = spot(k, s);
|
|
221
|
+
if (c.distance <= limit + EPS) candidates.push(c);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
candidates.sort((a, b) => a.distance - b.distance || a.ring - b.ring || a.spoke - b.spoke);
|
|
225
|
+
const found = candidates.find(free);
|
|
226
|
+
return found ? { ...found, nearest: found.ring === nearestSpot.ring && found.spoke === nearestSpot.spoke } : null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ── alignment guides ─────────────────────────────────────────────────────────
|
|
230
|
+
|
|
231
|
+
const AXES = {
|
|
232
|
+
x: { pos: "x", size: "width", other: "y", otherSize: "height" },
|
|
233
|
+
y: { pos: "y", size: "height", other: "x", otherSize: "width" },
|
|
234
|
+
};
|
|
235
|
+
const KINDS = ["start", "center", "end"];
|
|
236
|
+
|
|
237
|
+
/** A rect's three lines on an axis: start (left/top), center, end (right/bottom). */
|
|
238
|
+
export function linesOf(rect, axis) {
|
|
239
|
+
const { pos, size } = AXES[axis];
|
|
240
|
+
return { start: rect[pos], center: rect[pos] + rect[size] / 2, end: rect[pos] + rect[size] };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* An index of other panes' lines, sorted per axis, so each query is a binary
|
|
245
|
+
* search plus the lines within the threshold (fast with hundreds of panes).
|
|
246
|
+
*/
|
|
247
|
+
export function guideIndex(rects) {
|
|
248
|
+
const list = rects.filter((r) => r && Number.isFinite(r.x) && Number.isFinite(r.y) && r.width >= 0 && r.height >= 0);
|
|
249
|
+
const lines = (axis) =>
|
|
250
|
+
list
|
|
251
|
+
.flatMap((rect) => {
|
|
252
|
+
const l = linesOf(rect, axis);
|
|
253
|
+
return KINDS.map((kind) => ({ at: l[kind], kind, rect }));
|
|
254
|
+
})
|
|
255
|
+
.sort((a, b) => a.at - b.at);
|
|
256
|
+
return { rects: list, x: lines("x"), y: lines("y") };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Index of the first line at or after `v` (binary search). */
|
|
260
|
+
function lowerBound(lines, v) {
|
|
261
|
+
let lo = 0;
|
|
262
|
+
let hi = lines.length;
|
|
263
|
+
while (lo < hi) {
|
|
264
|
+
const mid = (lo + hi) >> 1;
|
|
265
|
+
if (lines[mid].at < v) lo = mid + 1;
|
|
266
|
+
else hi = mid;
|
|
267
|
+
}
|
|
268
|
+
return lo;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** The gap between two rects on the other axis (0 when they overlap there): how far apart they are, for ties. */
|
|
272
|
+
function apart(a, b, axis) {
|
|
273
|
+
const { other, otherSize } = AXES[axis];
|
|
274
|
+
return Math.max(0, a[other] - (b[other] + b[otherSize]), b[other] - (a[other] + a[otherSize]));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The alignment of `moving` on `axis` against the indexed lines: the move
|
|
279
|
+
* (`delta`) that puts one of its lines (`own`: which of start / center / end
|
|
280
|
+
* may snap) on another pane's line, within `threshold`. The smallest move
|
|
281
|
+
* wins; on a tie, the same kind of line (left to left) before a different
|
|
282
|
+
* one, then the nearer pane, then the lower id. Every match the chosen move
|
|
283
|
+
* makes is returned (to draw them all). Null when nothing is close enough.
|
|
284
|
+
*/
|
|
285
|
+
export function findAlignment(moving, index, { axis, threshold, own = KINDS } = {}) {
|
|
286
|
+
const lines = index?.[axis];
|
|
287
|
+
if (!lines?.length || !(threshold >= 0)) return null;
|
|
288
|
+
const mine = linesOf(moving, axis);
|
|
289
|
+
const found = [];
|
|
290
|
+
for (const kind of own) {
|
|
291
|
+
const at = mine[kind];
|
|
292
|
+
for (let i = lowerBound(lines, at - threshold - EPS); i < lines.length && lines[i].at <= at + threshold + EPS; i++) {
|
|
293
|
+
const line = lines[i];
|
|
294
|
+
found.push({ delta: line.at - at, at: line.at, kind: line.kind, own: kind, rect: line.rect });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (!found.length) return null;
|
|
298
|
+
const rank = (m) => [Math.abs(m.delta), m.kind === m.own ? 0 : 1, apart(moving, m.rect, axis), String(m.rect.id ?? "")];
|
|
299
|
+
const better = (a, b) => {
|
|
300
|
+
const [ra, rb] = [rank(a), rank(b)];
|
|
301
|
+
if (Math.abs(ra[0] - rb[0]) > EPS) return ra[0] - rb[0];
|
|
302
|
+
for (let i = 1; i < ra.length; i++) if (ra[i] !== rb[i]) return ra[i] < rb[i] ? -1 : 1;
|
|
303
|
+
return 0;
|
|
304
|
+
};
|
|
305
|
+
found.sort(better);
|
|
306
|
+
const best = found[0];
|
|
307
|
+
const matches = found.filter((m) => Math.abs(m.delta - best.delta) < EPS);
|
|
308
|
+
return { delta: best.delta, matches };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Equal spacing on `axis` (x: a row, y: a column): the panes that share the
|
|
313
|
+
* moving rect's row are its neighbours; the gaps between neighbouring panes
|
|
314
|
+
* of that row are the gaps it may copy. Candidates: `moving` a known gap
|
|
315
|
+
* after the pane before it, or before the pane after it, or centred between
|
|
316
|
+
* the two (equal gaps both sides). The smallest move within `threshold`
|
|
317
|
+
* wins (centred first on a tie). Returns { delta, gap, segments } where
|
|
318
|
+
* segments are the gaps to draw ({ axis, from, to, at }), or null.
|
|
319
|
+
*/
|
|
320
|
+
export function findSpacing(moving, rects, { axis, threshold } = {}) {
|
|
321
|
+
if (!(threshold >= 0)) return null;
|
|
322
|
+
const { pos, size, other, otherSize } = AXES[axis];
|
|
323
|
+
const overlapsRow = (a, b) => a[other] < b[other] + b[otherSize] && b[other] < a[other] + a[otherSize];
|
|
324
|
+
const row = rects.filter((r) => overlapsRow(r, moving)).sort((a, b) => a[pos] - b[pos] || String(a.id ?? "").localeCompare(String(b.id ?? "")));
|
|
325
|
+
if (!row.length) return null;
|
|
326
|
+
const start = moving[pos];
|
|
327
|
+
const end = start + moving[size];
|
|
328
|
+
const endOf = (r) => r[pos] + r[size];
|
|
329
|
+
// Neighbours: the nearest pane ending before the moving one starts, and the nearest starting after it ends.
|
|
330
|
+
let before;
|
|
331
|
+
let after;
|
|
332
|
+
for (const r of row) {
|
|
333
|
+
if (endOf(r) <= start + threshold && (!before || endOf(r) > endOf(before))) before = r;
|
|
334
|
+
if (r[pos] >= end - threshold && (!after || r[pos] < after[pos])) after = r;
|
|
335
|
+
}
|
|
336
|
+
if (!before && !after) return null;
|
|
337
|
+
// Gaps between panes of the row (each pane and the nearest one after it that it doesn't overlap, both in the row).
|
|
338
|
+
const gaps = [];
|
|
339
|
+
for (let i = 0; i < row.length; i++) {
|
|
340
|
+
const a = row[i];
|
|
341
|
+
let next;
|
|
342
|
+
for (let j = 0; j < row.length; j++) {
|
|
343
|
+
const b = row[j];
|
|
344
|
+
if (b === a || b[pos] < endOf(a) || !overlapsRow(a, b)) continue;
|
|
345
|
+
if (!next || b[pos] < next[pos]) next = b;
|
|
346
|
+
}
|
|
347
|
+
if (next && next[pos] - endOf(a) > EPS) gaps.push({ a, b: next, gap: next[pos] - endOf(a) });
|
|
348
|
+
}
|
|
349
|
+
const mid = (a, b) => (Math.max(a[other], b[other]) + Math.min(a[other] + a[otherSize], b[other] + b[otherSize])) / 2;
|
|
350
|
+
const seg = (a, b, from, to) => ({ axis, from, to, at: mid(a, b) });
|
|
351
|
+
const options = [];
|
|
352
|
+
if (before && after && after[pos] - endOf(before) >= moving[size]) {
|
|
353
|
+
const target = (endOf(before) + after[pos] - moving[size]) / 2;
|
|
354
|
+
options.push({ order: 0, delta: target - start, gap: target - endOf(before), segments: (t) => [seg(before, t, endOf(before), t[pos]), seg(t, after, endOf(t), after[pos])] });
|
|
355
|
+
}
|
|
356
|
+
for (const g of gaps) {
|
|
357
|
+
if (before && g.a !== before) {
|
|
358
|
+
const target = endOf(before) + g.gap;
|
|
359
|
+
options.push({ order: 1, delta: target - start, gap: g.gap, segments: (t) => [seg(g.a, g.b, endOf(g.a), g.b[pos]), seg(before, t, endOf(before), t[pos])] });
|
|
360
|
+
}
|
|
361
|
+
if (after && g.b !== after) {
|
|
362
|
+
const target = after[pos] - g.gap - moving[size];
|
|
363
|
+
options.push({ order: 2, delta: target - start, gap: g.gap, segments: (t) => [seg(g.a, g.b, endOf(g.a), g.b[pos]), seg(t, after, endOf(t), after[pos])] });
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const close = options.filter((o) => Math.abs(o.delta) <= threshold + EPS && o.gap > 0);
|
|
367
|
+
if (!close.length) return null;
|
|
368
|
+
close.sort((a, b) => Math.abs(a.delta) - Math.abs(b.delta) || a.order - b.order);
|
|
369
|
+
const best = close[0];
|
|
370
|
+
const placed = { ...moving, [pos]: start + best.delta };
|
|
371
|
+
return { delta: best.delta, gap: best.gap, segments: best.segments(placed) };
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** A line to draw for alignment matches: across the moving rect and every pane it lines up with. */
|
|
375
|
+
function alignmentGuide(axis, result, moved) {
|
|
376
|
+
const { other, otherSize } = AXES[axis];
|
|
377
|
+
const byLine = new Map();
|
|
378
|
+
for (const m of result.matches) byLine.set(m.at, [...(byLine.get(m.at) ?? []), m]);
|
|
379
|
+
return [...byLine.values()].map((ms) => {
|
|
380
|
+
const rects = [moved, ...ms.map((m) => m.rect)];
|
|
381
|
+
return { axis, at: ms[0].at, from: Math.min(...rects.map((r) => r[other])), to: Math.max(...rects.map((r) => r[other] + r[otherSize])), kind: "align" };
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Snap a moving rect (a pane, or a selection's bounding box), as it would be
|
|
387
|
+
* with no snapping. Options:
|
|
388
|
+
* index, rects: the other panes (guideIndex(rects)), or none;
|
|
389
|
+
* threshold: world units (GUIDE_PX / zoom);
|
|
390
|
+
* guides: alignment guides on; spacing: equal-spacing guides on;
|
|
391
|
+
* grid: null, { mode: "square", x, y } or { mode: "polar", hub, ring, angle, minRing }.
|
|
392
|
+
* obstacles: the panes a polar snap must not land on (default: rects);
|
|
393
|
+
* when the nearest ring and spoke is taken, the nearest free
|
|
394
|
+
* spot wins (polarFree), and with none near, no polar snap.
|
|
395
|
+
* Returns { dx, dy, guides, polar? } — the move to add, what to draw, and the polar spot taken.
|
|
396
|
+
*/
|
|
397
|
+
export function snapMove(moving, { index, rects = index?.rects ?? [], obstacles = rects, threshold = 0, guides = true, spacing = true, grid = null } = {}) {
|
|
398
|
+
const out = { dx: 0, dy: 0, guides: [] };
|
|
399
|
+
const caught = { x: null, y: null };
|
|
400
|
+
for (const axis of ["x", "y"]) {
|
|
401
|
+
const align = guides && index ? findAlignment(moving, index, { axis, threshold }) : null;
|
|
402
|
+
const space = guides && spacing ? findSpacing(moving, rects, { axis, threshold }) : null;
|
|
403
|
+
// The closer match wins; alignment on a tie.
|
|
404
|
+
if (align && (!space || Math.abs(align.delta) <= Math.abs(space.delta) + EPS)) caught[axis] = { delta: align.delta, align };
|
|
405
|
+
else if (space) caught[axis] = { delta: space.delta, space };
|
|
406
|
+
}
|
|
407
|
+
out.dx = caught.x?.delta ?? 0;
|
|
408
|
+
out.dy = caught.y?.delta ?? 0;
|
|
409
|
+
if (grid?.mode === "polar") {
|
|
410
|
+
if (!caught.x && !caught.y) {
|
|
411
|
+
const c = { x: moving.x + moving.width / 2, y: moving.y + moving.height / 2 };
|
|
412
|
+
const p = polarFree(c, moving, grid, obstacles);
|
|
413
|
+
if (p) {
|
|
414
|
+
out.dx = p.x - moving.x;
|
|
415
|
+
out.dy = p.y - moving.y;
|
|
416
|
+
out.polar = { ring: p.ring, spoke: p.spoke, ...(p.nearest ? {} : { displaced: true }) };
|
|
417
|
+
} else out.polar = { blocked: true }; // every spot near is taken: stay where the pointer put it
|
|
418
|
+
}
|
|
419
|
+
} else if (grid) {
|
|
420
|
+
const { x: gx, y: gy } = stepsOf(grid);
|
|
421
|
+
if (!caught.x && gx) out.dx = roundTo(moving.x, gx) - moving.x;
|
|
422
|
+
if (!caught.y && gy) out.dy = roundTo(moving.y, gy) - moving.y;
|
|
423
|
+
}
|
|
424
|
+
const moved = { ...moving, x: moving.x + out.dx, y: moving.y + out.dy };
|
|
425
|
+
for (const axis of ["x", "y"]) {
|
|
426
|
+
const c = caught[axis];
|
|
427
|
+
if (c?.align) out.guides.push(...alignmentGuide(axis, c.align, moved));
|
|
428
|
+
// Spacing segments run along the axis, so their cross position follows the other axis's snap.
|
|
429
|
+
if (c?.space) out.guides.push(...(findSpacing(moved, rects, { axis, threshold: EPS }) ?? c.space).segments.map((s) => ({ ...s, kind: "gap" })));
|
|
430
|
+
}
|
|
431
|
+
return out;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Snap a resize: the moving rect's right edge (x) and bottom edge (y) meet
|
|
436
|
+
* other panes' lines (guides), else the square lattice. A polar grid doesn't
|
|
437
|
+
* apply to sizes. Returns { dw, dh, guides }.
|
|
438
|
+
*/
|
|
439
|
+
export function snapResize(moving, { index, threshold = 0, guides = true, grid = null, axes = ["x", "y"] } = {}) {
|
|
440
|
+
const out = { dw: 0, dh: 0, guides: [] };
|
|
441
|
+
const caught = {};
|
|
442
|
+
for (const axis of axes) {
|
|
443
|
+
const align = guides && index ? findAlignment(moving, index, { axis, threshold, own: ["end"] }) : null;
|
|
444
|
+
if (align) caught[axis] = align;
|
|
445
|
+
}
|
|
446
|
+
const { x: gx, y: gy } = grid && grid.mode !== "polar" ? stepsOf(grid) : { x: 0, y: 0 };
|
|
447
|
+
const endX = moving.x + moving.width;
|
|
448
|
+
const endY = moving.y + moving.height;
|
|
449
|
+
if (axes.includes("x")) out.dw = caught.x ? caught.x.delta : gx ? roundTo(endX, gx) - endX : 0;
|
|
450
|
+
if (axes.includes("y")) out.dh = caught.y ? caught.y.delta : gy ? roundTo(endY, gy) - endY : 0;
|
|
451
|
+
const moved = { ...moving, width: moving.width + out.dw, height: moving.height + out.dh };
|
|
452
|
+
for (const axis of axes) if (caught[axis]) out.guides.push(...alignmentGuide(axis, caught[axis], moved));
|
|
453
|
+
return out;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The bounding box of rects ({ x, y, width, height }), or undefined for none. */
|
|
457
|
+
export function boxOf(rects) {
|
|
458
|
+
const list = [...rects];
|
|
459
|
+
if (!list.length) return undefined;
|
|
460
|
+
const x = Math.min(...list.map((r) => r.x));
|
|
461
|
+
const y = Math.min(...list.map((r) => r.y));
|
|
462
|
+
return { x, y, width: Math.max(...list.map((r) => r.x + r.width)) - x, height: Math.max(...list.map((r) => r.y + r.height)) - y };
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** Rects within (or crossing) `area`: the panes worth checking for guides. */
|
|
466
|
+
export const within = (rects, area) => rects.filter((r) => r.x < area.x + area.width && area.x < r.x + r.width && r.y < area.y + area.height && area.y < r.y + r.height);
|