@vibesdotdev/media 0.0.0-stage → 1.0.0-rc.4
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/LICENSE +18 -0
- package/README.md +95 -2
- package/dist/analyzers/frame-guard.d.ts +6 -0
- package/dist/analyzers/frame-guard.d.ts.map +1 -0
- package/dist/analyzers/frame-guard.js +10 -0
- package/dist/analyzers/frame-guard.js.map +1 -0
- package/dist/analyzers/motion-math.d.ts +66 -0
- package/dist/analyzers/motion-math.d.ts.map +1 -0
- package/dist/analyzers/motion-math.js +356 -0
- package/dist/analyzers/motion-math.js.map +1 -0
- package/dist/analyzers/reference-motion-analyzer.impl.d.ts +23 -0
- package/dist/analyzers/reference-motion-analyzer.impl.d.ts.map +1 -0
- package/dist/analyzers/reference-motion-analyzer.impl.js +69 -0
- package/dist/analyzers/reference-motion-analyzer.impl.js.map +1 -0
- package/dist/analyzers/reference-motion.descriptor.d.ts +11 -0
- package/dist/analyzers/reference-motion.descriptor.d.ts.map +1 -0
- package/dist/analyzers/reference-motion.descriptor.js +21 -0
- package/dist/analyzers/reference-motion.descriptor.js.map +1 -0
- package/dist/capture-client.d.ts +34 -0
- package/dist/capture-client.d.ts.map +1 -0
- package/dist/capture-client.js +163 -0
- package/dist/capture-client.js.map +1 -0
- package/dist/config/media.uploads.config.descriptor.d.ts +27 -0
- package/dist/config/media.uploads.config.descriptor.d.ts.map +1 -0
- package/dist/config/media.uploads.config.descriptor.js +46 -0
- package/dist/config/media.uploads.config.descriptor.js.map +1 -0
- package/dist/config/uploads.d.ts +11 -0
- package/dist/config/uploads.d.ts.map +1 -0
- package/dist/config/uploads.js +25 -0
- package/dist/config/uploads.js.map +1 -0
- package/dist/docs/artifact-references.docs.descriptor.d.ts +4 -0
- package/dist/docs/artifact-references.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/artifact-references.docs.descriptor.js +69 -0
- package/dist/docs/artifact-references.docs.descriptor.js.map +1 -0
- package/dist/docs/image-transform.docs.descriptor.d.ts +4 -0
- package/dist/docs/image-transform.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/image-transform.docs.descriptor.js +52 -0
- package/dist/docs/image-transform.docs.descriptor.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/capture-provider.d.ts +33 -0
- package/dist/interfaces/capture-provider.d.ts.map +1 -0
- package/dist/interfaces/capture-provider.js +10 -0
- package/dist/interfaces/capture-provider.js.map +1 -0
- package/dist/interfaces/image-transformer.d.ts +7 -0
- package/dist/interfaces/image-transformer.d.ts.map +1 -0
- package/dist/interfaces/image-transformer.js +2 -0
- package/dist/interfaces/image-transformer.js.map +1 -0
- package/dist/interfaces/index.d.ts +7 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +5 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/motion-analyzer.d.ts +55 -0
- package/dist/interfaces/motion-analyzer.d.ts.map +1 -0
- package/dist/interfaces/motion-analyzer.js +14 -0
- package/dist/interfaces/motion-analyzer.js.map +1 -0
- package/dist/kinds/capture.d.ts +58 -0
- package/dist/kinds/capture.d.ts.map +1 -0
- package/dist/kinds/capture.js +34 -0
- package/dist/kinds/capture.js.map +1 -0
- package/dist/kinds/image-transform.d.ts +91 -0
- package/dist/kinds/image-transform.d.ts.map +1 -0
- package/dist/kinds/image-transform.js +12 -0
- package/dist/kinds/image-transform.js.map +1 -0
- package/dist/kinds/index.d.ts +10 -0
- package/dist/kinds/index.d.ts.map +1 -0
- package/dist/kinds/index.js +7 -0
- package/dist/kinds/index.js.map +1 -0
- package/dist/kinds/motion.d.ts +57 -0
- package/dist/kinds/motion.d.ts.map +1 -0
- package/dist/kinds/motion.js +34 -0
- package/dist/kinds/motion.js.map +1 -0
- package/dist/media.plugin.d.ts +23 -0
- package/dist/media.plugin.d.ts.map +1 -0
- package/dist/media.plugin.js +48 -0
- package/dist/media.plugin.js.map +1 -0
- package/dist/schemas/artifact-reference.d.ts +59 -0
- package/dist/schemas/artifact-reference.d.ts.map +1 -0
- package/dist/schemas/artifact-reference.js +77 -0
- package/dist/schemas/artifact-reference.js.map +1 -0
- package/dist/schemas/capture-descriptor.d.ts +71 -0
- package/dist/schemas/capture-descriptor.d.ts.map +1 -0
- package/dist/schemas/capture-descriptor.js +74 -0
- package/dist/schemas/capture-descriptor.js.map +1 -0
- package/dist/schemas/capture-options.d.ts +51 -0
- package/dist/schemas/capture-options.d.ts.map +1 -0
- package/dist/schemas/capture-options.js +68 -0
- package/dist/schemas/capture-options.js.map +1 -0
- package/dist/schemas/capture-parse.d.ts +10 -0
- package/dist/schemas/capture-parse.d.ts.map +1 -0
- package/dist/schemas/capture-parse.js +30 -0
- package/dist/schemas/capture-parse.js.map +1 -0
- package/dist/schemas/capture-state.d.ts +77 -0
- package/dist/schemas/capture-state.d.ts.map +1 -0
- package/dist/schemas/capture-state.js +25 -0
- package/dist/schemas/capture-state.js.map +1 -0
- package/dist/schemas/image-transform.d.ts +269 -0
- package/dist/schemas/image-transform.d.ts.map +1 -0
- package/dist/schemas/image-transform.js +161 -0
- package/dist/schemas/image-transform.js.map +1 -0
- package/dist/schemas/index.d.ts +20 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +17 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/motion-analysis.d.ts +187 -0
- package/dist/schemas/motion-analysis.d.ts.map +1 -0
- package/dist/schemas/motion-analysis.js +213 -0
- package/dist/schemas/motion-analysis.js.map +1 -0
- package/dist/schemas/motion-descriptor.d.ts +53 -0
- package/dist/schemas/motion-descriptor.d.ts.map +1 -0
- package/dist/schemas/motion-descriptor.js +47 -0
- package/dist/schemas/motion-descriptor.js.map +1 -0
- package/dist/schemas/motion-frame.d.ts +63 -0
- package/dist/schemas/motion-frame.d.ts.map +1 -0
- package/dist/schemas/motion-frame.js +86 -0
- package/dist/schemas/motion-frame.js.map +1 -0
- package/dist/schemas/opaque-id.d.ts +10 -0
- package/dist/schemas/opaque-id.d.ts.map +1 -0
- package/dist/schemas/opaque-id.js +24 -0
- package/dist/schemas/opaque-id.js.map +1 -0
- package/dist/schemas/sharing-state.d.ts +43 -0
- package/dist/schemas/sharing-state.d.ts.map +1 -0
- package/dist/schemas/sharing-state.js +11 -0
- package/dist/schemas/sharing-state.js.map +1 -0
- package/dist/svelte/CaptureLoader.svelte +29 -0
- package/dist/svelte/CaptureLoader.svelte.d.ts +11 -0
- package/dist/svelte/CaptureLoader.svelte.d.ts.map +1 -0
- package/dist/svelte/CapturePanel.svelte +189 -0
- package/dist/svelte/CapturePanel.svelte.d.ts +12 -0
- package/dist/svelte/CapturePanel.svelte.d.ts.map +1 -0
- package/dist/svelte/MediaUploader.svelte +109 -0
- package/dist/svelte/MediaUploader.svelte.d.ts +5 -0
- package/dist/svelte/MediaUploader.svelte.d.ts.map +1 -0
- package/dist/svelte/capture-parse.d.ts +2 -0
- package/dist/svelte/capture-parse.d.ts.map +1 -0
- package/dist/svelte/capture-parse.js +1 -0
- package/dist/svelte/failure-message.d.ts +2 -0
- package/dist/svelte/failure-message.d.ts.map +1 -0
- package/dist/svelte/failure-message.js +1 -0
- package/dist/svelte/index.d.ts +8 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +6 -0
- package/dist/svelte/runtime-log.d.ts +14 -0
- package/dist/svelte/runtime-log.d.ts.map +1 -0
- package/dist/svelte/runtime-log.js +19 -0
- package/dist/svelte/runtime.d.ts +9 -0
- package/dist/svelte/runtime.d.ts.map +1 -0
- package/dist/svelte/runtime.js +27 -0
- package/dist/svelte/sharing/README.md +38 -0
- package/dist/svelte/sharing/components/ShareButton.svelte +57 -0
- package/dist/svelte/sharing/components/ShareButton.svelte.d.ts +11 -0
- package/dist/svelte/sharing/components/ShareButton.svelte.d.ts.map +1 -0
- package/dist/svelte/sharing/components/ShareDialog.svelte +222 -0
- package/dist/svelte/sharing/components/ShareDialog.svelte.d.ts +8 -0
- package/dist/svelte/sharing/components/ShareDialog.svelte.d.ts.map +1 -0
- package/dist/svelte/sharing/components/ShareLoader.svelte +19 -0
- package/dist/svelte/sharing/components/ShareLoader.svelte.d.ts +7 -0
- package/dist/svelte/sharing/components/ShareLoader.svelte.d.ts.map +1 -0
- package/dist/svelte/sharing/index.d.ts +20 -0
- package/dist/svelte/sharing/index.d.ts.map +1 -0
- package/dist/svelte/sharing/index.js +19 -0
- package/dist/svelte/sharing/runtime.d.ts +44 -0
- package/dist/svelte/sharing/runtime.d.ts.map +1 -0
- package/dist/svelte/sharing/runtime.js +81 -0
- package/dist/svelte/sharing/state.svelte.d.ts +28 -0
- package/dist/svelte/sharing/state.svelte.d.ts.map +1 -0
- package/dist/svelte/sharing/state.svelte.js +101 -0
- package/dist/svelte/sharing/styles.css +8 -0
- package/dist/svelte/state.svelte.d.ts +38 -0
- package/dist/svelte/state.svelte.d.ts.map +1 -0
- package/dist/svelte/state.svelte.js +102 -0
- package/dist/svelte/styles.css +2 -0
- package/dist/svelte/uploader.d.ts +17 -0
- package/dist/svelte/uploader.d.ts.map +1 -0
- package/dist/svelte/uploader.js +9 -0
- package/dist/uploads/adapters/local/index.d.ts +9 -0
- package/dist/uploads/adapters/local/index.d.ts.map +1 -0
- package/dist/uploads/adapters/local/index.js +12 -0
- package/dist/uploads/adapters/local/index.js.map +1 -0
- package/dist/uploads/adapters/local/local-storage.descriptor.d.ts +24 -0
- package/dist/uploads/adapters/local/local-storage.descriptor.d.ts.map +1 -0
- package/dist/uploads/adapters/local/local-storage.descriptor.js +20 -0
- package/dist/uploads/adapters/local/local-storage.descriptor.js.map +1 -0
- package/dist/uploads/adapters/local/local-storage.impl.d.ts +123 -0
- package/dist/uploads/adapters/local/local-storage.impl.d.ts.map +1 -0
- package/dist/uploads/adapters/local/local-storage.impl.js +231 -0
- package/dist/uploads/adapters/local/local-storage.impl.js.map +1 -0
- package/dist/uploads/adapters/local/uploads-adapter-local.plugin.d.ts +9 -0
- package/dist/uploads/adapters/local/uploads-adapter-local.plugin.d.ts.map +1 -0
- package/dist/uploads/adapters/local/uploads-adapter-local.plugin.js +41 -0
- package/dist/uploads/adapters/local/uploads-adapter-local.plugin.js.map +1 -0
- package/dist/uploads/client/helper.d.ts +26 -0
- package/dist/uploads/client/helper.d.ts.map +1 -0
- package/dist/uploads/client/helper.js +27 -0
- package/dist/uploads/client/helper.js.map +1 -0
- package/dist/uploads/client/index.d.ts +11 -0
- package/dist/uploads/client/index.d.ts.map +1 -0
- package/dist/uploads/client/index.js +9 -0
- package/dist/uploads/client/index.js.map +1 -0
- package/dist/uploads/client/sharing-client.d.ts +45 -0
- package/dist/uploads/client/sharing-client.d.ts.map +1 -0
- package/dist/uploads/client/sharing-client.js +153 -0
- package/dist/uploads/client/sharing-client.js.map +1 -0
- package/dist/uploads/client/uploads-client.d.ts +200 -0
- package/dist/uploads/client/uploads-client.d.ts.map +1 -0
- package/dist/uploads/client/uploads-client.js +487 -0
- package/dist/uploads/client/uploads-client.js.map +1 -0
- package/dist/uploads/docs/uploads.docs.descriptor.d.ts +4 -0
- package/dist/uploads/docs/uploads.docs.descriptor.d.ts.map +1 -0
- package/dist/uploads/docs/uploads.docs.descriptor.js +65 -0
- package/dist/uploads/docs/uploads.docs.descriptor.js.map +1 -0
- package/dist/uploads/docs/uploads.share-links.docs.descriptor.d.ts +22 -0
- package/dist/uploads/docs/uploads.share-links.docs.descriptor.d.ts.map +1 -0
- package/dist/uploads/docs/uploads.share-links.docs.descriptor.js +86 -0
- package/dist/uploads/docs/uploads.share-links.docs.descriptor.js.map +1 -0
- package/dist/uploads/index.d.ts +12 -0
- package/dist/uploads/index.d.ts.map +1 -0
- package/dist/uploads/index.js +13 -0
- package/dist/uploads/index.js.map +1 -0
- package/dist/uploads/schemas/common.d.ts +135 -0
- package/dist/uploads/schemas/common.d.ts.map +1 -0
- package/dist/uploads/schemas/common.js +152 -0
- package/dist/uploads/schemas/common.js.map +1 -0
- package/dist/uploads/schemas/forms.d.ts +59 -0
- package/dist/uploads/schemas/forms.d.ts.map +1 -0
- package/dist/uploads/schemas/forms.js +41 -0
- package/dist/uploads/schemas/forms.js.map +1 -0
- package/dist/uploads/schemas/index.d.ts +18 -0
- package/dist/uploads/schemas/index.d.ts.map +1 -0
- package/dist/uploads/schemas/index.js +13 -0
- package/dist/uploads/schemas/index.js.map +1 -0
- package/dist/uploads/schemas/records.d.ts +81 -0
- package/dist/uploads/schemas/records.d.ts.map +1 -0
- package/dist/uploads/schemas/records.js +82 -0
- package/dist/uploads/schemas/records.js.map +1 -0
- package/dist/uploads/schemas/requests.d.ts +32 -0
- package/dist/uploads/schemas/requests.d.ts.map +1 -0
- package/dist/uploads/schemas/requests.js +30 -0
- package/dist/uploads/schemas/requests.js.map +1 -0
- package/dist/uploads/schemas/shares.d.ts +67 -0
- package/dist/uploads/schemas/shares.d.ts.map +1 -0
- package/dist/uploads/schemas/shares.js +39 -0
- package/dist/uploads/schemas/shares.js.map +1 -0
- package/dist/uploads/server/backend.d.ts +8 -0
- package/dist/uploads/server/backend.d.ts.map +1 -0
- package/dist/uploads/server/backend.js +11 -0
- package/dist/uploads/server/backend.js.map +1 -0
- package/dist/uploads/server/config.d.ts +5 -0
- package/dist/uploads/server/config.d.ts.map +1 -0
- package/dist/uploads/server/config.js +38 -0
- package/dist/uploads/server/config.js.map +1 -0
- package/dist/uploads/server/service.d.ts +77 -0
- package/dist/uploads/server/service.d.ts.map +1 -0
- package/dist/uploads/server/service.js +152 -0
- package/dist/uploads/server/service.js.map +1 -0
- package/dist/uploads/server/storage-client.d.ts +11 -0
- package/dist/uploads/server/storage-client.d.ts.map +1 -0
- package/dist/uploads/server/storage-client.js +23 -0
- package/dist/uploads/server/storage-client.js.map +1 -0
- package/dist/uploads/server/storage.d.ts +40 -0
- package/dist/uploads/server/storage.d.ts.map +1 -0
- package/dist/uploads/server/storage.js +59 -0
- package/dist/uploads/server/storage.js.map +1 -0
- package/dist/uploads/uploads.plugin.d.ts +11 -0
- package/dist/uploads/uploads.plugin.d.ts.map +1 -0
- package/dist/uploads/uploads.plugin.js +89 -0
- package/dist/uploads/uploads.plugin.js.map +1 -0
- package/dist/utils/attempt.d.ts +27 -0
- package/dist/utils/attempt.d.ts.map +1 -0
- package/dist/utils/attempt.js +39 -0
- package/dist/utils/attempt.js.map +1 -0
- package/dist/utils/failure-message.d.ts +8 -0
- package/dist/utils/failure-message.d.ts.map +1 -0
- package/dist/utils/failure-message.js +28 -0
- package/dist/utils/failure-message.js.map +1 -0
- package/package.json +257 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VIBES DEV LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vibesdotdev/media
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Universal media contracts for the vibes platform: stable artifact-revision identity plus three runtime kinds — `media/capture` (pixels in), `media/image-transform` (bytes in, bytes out), and `media/motion` (what the pixels are doing across time) — with runtime-resolved uploads and Svelte adapters on top.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
The package is workspace-only:
|
|
8
|
+
|
|
9
|
+
```jsonc
|
|
10
|
+
// package.json
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@vibesdotdev/media": "workspace:*"
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
Capture a screenshot through a provider, transform image bytes, or upload a file — always through the runtime, never through direct imports of a provider:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import type { CaptureProvider } from '@vibesdotdev/media';
|
|
22
|
+
|
|
23
|
+
const provider = (await runtime
|
|
24
|
+
.query('media/capture')
|
|
25
|
+
.withId('bridge.screen')
|
|
26
|
+
.resolve()) as CaptureProvider;
|
|
27
|
+
|
|
28
|
+
const shot = await provider.capture({ format: 'png' });
|
|
29
|
+
// shot.data is Uint8Array
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { getVibesUploadsClient } from '@vibesdotdev/media/uploads/client';
|
|
34
|
+
|
|
35
|
+
const uploads = await getVibesUploadsClient(runtime);
|
|
36
|
+
const file = await uploads.upload({
|
|
37
|
+
file: buffer,
|
|
38
|
+
kind: 'chat',
|
|
39
|
+
sourceApp: 'chat',
|
|
40
|
+
sourceId: roomId
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Contracts
|
|
45
|
+
|
|
46
|
+
- [SPEC.md](./SPEC.md) — package contract: artifact references, the three runtime kinds, hard rules, full entrypoint list.
|
|
47
|
+
- [src/svelte/SPEC.md](./src/svelte/SPEC.md) — tree-bound capture composition and compatibility handoff.
|
|
48
|
+
- [src/uploads/SPEC.md](./src/uploads/SPEC.md) — uploads surface: `uploads/store` kind, client, schemas, local adapter.
|
|
49
|
+
- [src/svelte/sharing/SPEC.md](./src/svelte/sharing/SPEC.md) — revocable share-link Svelte surface.
|
|
50
|
+
- [src/uploads/README.md](./src/uploads/README.md) — uploads quick tour.
|
|
51
|
+
|
|
52
|
+
## Upload storage and validation
|
|
53
|
+
|
|
54
|
+
Hosts set `config['media.uploads'].localPath` and compose
|
|
55
|
+
`@vibesdotdev/media/uploads/adapters/local/node`. The runtime-resolved local
|
|
56
|
+
adapter uses that root for save, read, and delete. Relative roots resolve
|
|
57
|
+
against the bound workspace; an omitted root uses `uploads`. Absolute roots
|
|
58
|
+
are supported, and paths cannot escape the selected root.
|
|
59
|
+
|
|
60
|
+
`validateUpload` and `uploadLimitsSchema` are exported from `./uploads/schemas`.
|
|
61
|
+
The default cap is 50 MiB with the exported MIME allowlist. A caller may replace
|
|
62
|
+
either limit. Caps must be positive safe integers; a malformed cap or allowlist
|
|
63
|
+
is refused instead of compared against. `validateUpload` returns
|
|
64
|
+
`INVALID_INPUT/upload-limits-invalid` with legacy code `INVALID_LIMITS` and
|
|
65
|
+
consumes the parsed snapshot; the HTTP client reports the same schema's
|
|
66
|
+
malformed caps as `upload-limits-invalid`, while an unreadable or throwing
|
|
67
|
+
request is `upload-options-invalid`. Valid caps still reject oversized files
|
|
68
|
+
as `upload-file-too-large`.
|
|
69
|
+
|
|
70
|
+
The root entrypoint contains the universal media contract and semantic capture
|
|
71
|
+
client. Implementations resolve through runtime kinds; Svelte components and
|
|
72
|
+
state are available only through explicit `./svelte` subpaths. Universal plugins
|
|
73
|
+
contain no consumer, CLI, or process implementation loaders.
|
|
74
|
+
|
|
75
|
+
## Verification
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
bun run lint
|
|
79
|
+
bun run rules
|
|
80
|
+
bun run check
|
|
81
|
+
bun run test
|
|
82
|
+
bun run build
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Capture UI hosts compose mediaPlugin and runtimeClientPlugin. Retain one
|
|
86
|
+
createMediaCaptureState() result for a sibling loader/panel, or wrap the panel
|
|
87
|
+
in CaptureLoader for context. mediaCaptureState is a factory alias, so former
|
|
88
|
+
singleton callers must migrate. The runtime owns byte sessions; each tree owns
|
|
89
|
+
its browser URLs. The uploads plugin separately registers uploads and
|
|
90
|
+
uploads-storage clients.
|
|
91
|
+
|
|
92
|
+
Check includes source, tests, fixtures and Svelte TypeScript. Tests combine
|
|
93
|
+
Bun contracts with real in-process Svelte mounting under Vitest/Happy DOM.
|
|
94
|
+
Sharing and uploader helpers have helper proof; they are not component proof.
|
|
95
|
+
Build emits core declarations/JavaScript and separately packages Svelte
|
|
96
|
+
components/styles, excluding tests and fixtures.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Frame } from '../schemas/motion-frame.ts';
|
|
2
|
+
export { MAX_FRAME_PIXELS } from '../schemas/motion-frame.ts';
|
|
3
|
+
/** Compatibility guards delegate geometry and buffer validation to the schema owner. */
|
|
4
|
+
export declare function assertFrame(frame: Frame): void;
|
|
5
|
+
export declare function assertFrameSequence(frames: readonly Frame[]): void;
|
|
6
|
+
//# sourceMappingURL=frame-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-guard.d.ts","sourceRoot":"","sources":["../../src/analyzers/frame-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAE5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAE9C;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,CAElE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FrameSchema, FrameSequenceSchema, parseMotionInput } from "../schemas/motion-frame.js";
|
|
2
|
+
export { MAX_FRAME_PIXELS } from "../schemas/motion-frame.js";
|
|
3
|
+
/** Compatibility guards delegate geometry and buffer validation to the schema owner. */
|
|
4
|
+
export function assertFrame(frame) {
|
|
5
|
+
parseMotionInput(FrameSchema, frame);
|
|
6
|
+
}
|
|
7
|
+
export function assertFrameSequence(frames) {
|
|
8
|
+
parseMotionInput(FrameSequenceSchema, [...frames]);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=frame-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-guard.js","sourceRoot":"","sources":["../../src/analyzers/frame-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,gBAAgB,EAAc,MAAM,4BAA4B,CAAC;AAE5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,wFAAwF;AACxF,MAAM,UAAU,WAAW,CAAC,KAAY;IACvC,gBAAgB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAwB;IAC3D,gBAAgB,CAAC,mBAAmB,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion Math — pure kernels
|
|
3
|
+
*
|
|
4
|
+
* The numeric core of the `media/motion` reference analyzer, kept free of any
|
|
5
|
+
* runtime/schema wiring so it can be unit-tested directly and reused by other
|
|
6
|
+
* providers. Everything here operates on `Frame` structs and typed arrays; no
|
|
7
|
+
* FS, no native, no async.
|
|
8
|
+
*
|
|
9
|
+
* Luma convention: values are kept in 0..255 float space through reduction,
|
|
10
|
+
* then scalar summaries are normalized to 0..1 at the boundary. Motion energy
|
|
11
|
+
* works on per-frame zero-mean, unit-variance luma so cross-correlation lands
|
|
12
|
+
* in ~[-1, 1] and the opponent subtraction cleanly cancels non-directional
|
|
13
|
+
* structure.
|
|
14
|
+
*/
|
|
15
|
+
import type { Frame } from '../schemas/motion-frame.ts';
|
|
16
|
+
import type { FrameDiffResult, TemporalStatsResult, OpticalFlowResult, MotionEnergyResult, MotionDirection } from '../schemas/motion-analysis.ts';
|
|
17
|
+
/** A luma plane reduced from a frame. */
|
|
18
|
+
export interface LumaPlane {
|
|
19
|
+
data: Float32Array;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reduce a frame to a single-channel luma plane, optionally box-downsampled by
|
|
25
|
+
* an integer factor. Multi-channel frames are collapsed via Rec.601 luma.
|
|
26
|
+
*/
|
|
27
|
+
export declare function toLuma(frame: Frame, downscale?: number): LumaPlane;
|
|
28
|
+
/** Absolute luma difference between two frames. */
|
|
29
|
+
export declare function frameDiff(a: Frame, b: Frame, opts?: {
|
|
30
|
+
downscale?: number;
|
|
31
|
+
threshold?: number;
|
|
32
|
+
includeMap?: boolean;
|
|
33
|
+
}): FrameDiffResult;
|
|
34
|
+
/** Per-pixel temporal mean + std (Welford) over a sequence. */
|
|
35
|
+
export declare function temporalStats(frames: Frame[], opts?: {
|
|
36
|
+
downscale?: number;
|
|
37
|
+
includeMaps?: boolean;
|
|
38
|
+
}): TemporalStatsResult;
|
|
39
|
+
/** Block-matching optical flow between two frames. */
|
|
40
|
+
export declare function opticalFlow(a: Frame, b: Frame, opts?: {
|
|
41
|
+
downscale?: number;
|
|
42
|
+
blockSize?: number;
|
|
43
|
+
searchRadius?: number;
|
|
44
|
+
step?: number;
|
|
45
|
+
minConfidence?: number;
|
|
46
|
+
}): OpticalFlowResult;
|
|
47
|
+
/** Pick an integer downscale so the longer edge is ≤ maxDim. */
|
|
48
|
+
export declare function autoDownscale(frame: Frame, maxDim: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Reichardt / lag-1 opponent motion energy over a sequence.
|
|
51
|
+
*
|
|
52
|
+
* For every consecutive pair (t, t+1) and every candidate shift s, accumulate
|
|
53
|
+
* the normalized cross-correlation corr(s). The opponent response for a
|
|
54
|
+
* direction is R(s) = mean_t[corr(s)] − mean_t[corr(−s)]: coherent drift by
|
|
55
|
+
* velocity v drives corr(v)→high, corr(−v)→low, so R(v) is large; temporally
|
|
56
|
+
* independent twinkle gives corr(any)≈0 so R≈0. That subtraction is what
|
|
57
|
+
* separates a motion carrier from a static or twinkling background.
|
|
58
|
+
*/
|
|
59
|
+
export declare function motionEnergy(frames: Frame[], opts?: {
|
|
60
|
+
downscale?: number;
|
|
61
|
+
maxDim?: number;
|
|
62
|
+
directions?: MotionDirection[];
|
|
63
|
+
shiftRadius?: number;
|
|
64
|
+
includeMap?: boolean;
|
|
65
|
+
}): MotionEnergyResult;
|
|
66
|
+
//# sourceMappingURL=motion-math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion-math.d.ts","sourceRoot":"","sources":["../../src/analyzers/motion-math.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,EACX,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EAEjB,kBAAkB,EAClB,eAAe,EAGf,MAAM,+BAA+B,CAAC;AAEvC,yCAAyC;AACzC,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAID;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,SAAI,GAAG,SAAS,CAgC7D;AAGD,mDAAmD;AACnD,wBAAgB,SAAS,CACxB,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,KAAK,EACR,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACzE,eAAe,CA2CjB;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAC5B,MAAM,EAAE,KAAK,EAAE,EACf,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACtD,mBAAmB,CAgDrB;AAwBD,sDAAsD;AACtD,wBAAgB,WAAW,CAC1B,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,KAAK,EACR,IAAI,GAAE;IACL,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;CAClB,GACJ,iBAAiB,CA6DnB;AAmDD,gEAAgE;AAChE,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIlE;AAeD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,KAAK,EAAE,EACf,IAAI,GAAE;IACL,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CAChB,GACJ,kBAAkB,CAwEpB"}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion Math — pure kernels
|
|
3
|
+
*
|
|
4
|
+
* The numeric core of the `media/motion` reference analyzer, kept free of any
|
|
5
|
+
* runtime/schema wiring so it can be unit-tested directly and reused by other
|
|
6
|
+
* providers. Everything here operates on `Frame` structs and typed arrays; no
|
|
7
|
+
* FS, no native, no async.
|
|
8
|
+
*
|
|
9
|
+
* Luma convention: values are kept in 0..255 float space through reduction,
|
|
10
|
+
* then scalar summaries are normalized to 0..1 at the boundary. Motion energy
|
|
11
|
+
* works on per-frame zero-mean, unit-variance luma so cross-correlation lands
|
|
12
|
+
* in ~[-1, 1] and the opponent subtraction cleanly cancels non-directional
|
|
13
|
+
* structure.
|
|
14
|
+
*/
|
|
15
|
+
const REC_601 = { r: 0.299, g: 0.587, b: 0.114 };
|
|
16
|
+
/**
|
|
17
|
+
* Reduce a frame to a single-channel luma plane, optionally box-downsampled by
|
|
18
|
+
* an integer factor. Multi-channel frames are collapsed via Rec.601 luma.
|
|
19
|
+
*/
|
|
20
|
+
export function toLuma(frame, downscale = 1) {
|
|
21
|
+
const { data, width, height } = frame;
|
|
22
|
+
const channels = frame.channels ?? 1;
|
|
23
|
+
const ds = Math.max(1, Math.floor(downscale));
|
|
24
|
+
const outW = Math.max(1, Math.floor(width / ds));
|
|
25
|
+
const outH = Math.max(1, Math.floor(height / ds));
|
|
26
|
+
const out = new Float32Array(outW * outH);
|
|
27
|
+
for (let oy = 0; oy < outH; oy++) {
|
|
28
|
+
for (let ox = 0; ox < outW; ox++) {
|
|
29
|
+
let sum = 0;
|
|
30
|
+
let count = 0;
|
|
31
|
+
for (let by = 0; by < ds; by++) {
|
|
32
|
+
const y = oy * ds + by;
|
|
33
|
+
if (y >= height)
|
|
34
|
+
break;
|
|
35
|
+
const row = y * width;
|
|
36
|
+
for (let bx = 0; bx < ds; bx++) {
|
|
37
|
+
const x = ox * ds + bx;
|
|
38
|
+
if (x >= width)
|
|
39
|
+
break;
|
|
40
|
+
const idx = (row + x) * channels;
|
|
41
|
+
const luma = channels === 1
|
|
42
|
+
? data[idx]
|
|
43
|
+
: REC_601.r * data[idx] + REC_601.g * data[idx + 1] + REC_601.b * data[idx + 2];
|
|
44
|
+
sum += luma;
|
|
45
|
+
count++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
out[oy * outW + ox] = count > 0 ? sum / count : 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { data: out, width: outW, height: outH };
|
|
52
|
+
}
|
|
53
|
+
/** Absolute luma difference between two frames. */
|
|
54
|
+
export function frameDiff(a, b, opts = {}) {
|
|
55
|
+
const ds = opts.downscale ?? 1;
|
|
56
|
+
const la = toLuma(a, ds);
|
|
57
|
+
const lb = toLuma(b, ds);
|
|
58
|
+
const n = la.data.length;
|
|
59
|
+
const thr = (opts.threshold ?? 0.08) * 255;
|
|
60
|
+
const map = opts.includeMap ? new Float32Array(n) : undefined;
|
|
61
|
+
let sumDiff = 0;
|
|
62
|
+
let changed = 0;
|
|
63
|
+
let minX = la.width;
|
|
64
|
+
let minY = la.height;
|
|
65
|
+
let maxX = -1;
|
|
66
|
+
let maxY = -1;
|
|
67
|
+
for (let i = 0; i < n; i++) {
|
|
68
|
+
const d = Math.abs(la.data[i] - lb.data[i]);
|
|
69
|
+
sumDiff += d;
|
|
70
|
+
if (map)
|
|
71
|
+
map[i] = d / 255;
|
|
72
|
+
if (d > thr) {
|
|
73
|
+
changed++;
|
|
74
|
+
const x = i % la.width;
|
|
75
|
+
const y = (i / la.width) | 0;
|
|
76
|
+
if (x < minX)
|
|
77
|
+
minX = x;
|
|
78
|
+
if (y < minY)
|
|
79
|
+
minY = y;
|
|
80
|
+
if (x > maxX)
|
|
81
|
+
maxX = x;
|
|
82
|
+
if (y > maxY)
|
|
83
|
+
maxY = y;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const bbox = maxX >= 0 ? { x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1 } : null;
|
|
87
|
+
const result = {
|
|
88
|
+
magnitude: sumDiff / n / 255,
|
|
89
|
+
changedFraction: changed / n,
|
|
90
|
+
width: la.width,
|
|
91
|
+
height: la.height,
|
|
92
|
+
bbox
|
|
93
|
+
};
|
|
94
|
+
if (map)
|
|
95
|
+
result.map = map;
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
/** Per-pixel temporal mean + std (Welford) over a sequence. */
|
|
99
|
+
export function temporalStats(frames, opts = {}) {
|
|
100
|
+
const ds = opts.downscale ?? 1;
|
|
101
|
+
const planes = frames.map((f) => toLuma(f, ds));
|
|
102
|
+
const { width, height } = planes[0];
|
|
103
|
+
const n = width * height;
|
|
104
|
+
const mean = new Float32Array(n);
|
|
105
|
+
const m2 = new Float32Array(n);
|
|
106
|
+
for (let t = 0; t < planes.length; t++) {
|
|
107
|
+
const plane = planes[t].data;
|
|
108
|
+
const count = t + 1;
|
|
109
|
+
for (let i = 0; i < n; i++) {
|
|
110
|
+
const x = plane[i];
|
|
111
|
+
const delta = x - mean[i];
|
|
112
|
+
mean[i] += delta / count;
|
|
113
|
+
m2[i] += delta * (x - mean[i]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const std = new Float32Array(n);
|
|
117
|
+
let sumStd = 0;
|
|
118
|
+
let peak = 0;
|
|
119
|
+
const t = planes.length;
|
|
120
|
+
for (let i = 0; i < n; i++) {
|
|
121
|
+
const s = Math.sqrt(m2[i] / t);
|
|
122
|
+
std[i] = s;
|
|
123
|
+
sumStd += s;
|
|
124
|
+
if (s > peak)
|
|
125
|
+
peak = s;
|
|
126
|
+
}
|
|
127
|
+
const result = {
|
|
128
|
+
meanStd: sumStd / n / 255,
|
|
129
|
+
peakStd: peak / 255,
|
|
130
|
+
width,
|
|
131
|
+
height
|
|
132
|
+
};
|
|
133
|
+
if (opts.includeMaps) {
|
|
134
|
+
const stdNorm = new Float32Array(n);
|
|
135
|
+
const meanNorm = new Float32Array(n);
|
|
136
|
+
for (let i = 0; i < n; i++) {
|
|
137
|
+
stdNorm[i] = std[i] / 255;
|
|
138
|
+
meanNorm[i] = mean[i] / 255;
|
|
139
|
+
}
|
|
140
|
+
result.std = stdNorm;
|
|
141
|
+
result.mean = meanNorm;
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
/** Sum of absolute differences for a block of `a` against `b` shifted by (dx,dy). */
|
|
146
|
+
function blockSad(a, b, width, bx, by, block, dx, dy) {
|
|
147
|
+
let sad = 0;
|
|
148
|
+
for (let yy = 0; yy < block; yy++) {
|
|
149
|
+
const ay = (by + yy) * width;
|
|
150
|
+
const bBy = (by + dy + yy) * width;
|
|
151
|
+
for (let xx = 0; xx < block; xx++) {
|
|
152
|
+
sad += Math.abs(a[ay + bx + xx] - b[bBy + bx + dx + xx]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return sad;
|
|
156
|
+
}
|
|
157
|
+
/** Block-matching optical flow between two frames. */
|
|
158
|
+
export function opticalFlow(a, b, opts = {}) {
|
|
159
|
+
const ds = opts.downscale ?? 1;
|
|
160
|
+
const la = toLuma(a, ds);
|
|
161
|
+
const lb = toLuma(b, ds);
|
|
162
|
+
const { width, height } = la;
|
|
163
|
+
const block = Math.max(2, opts.blockSize ?? 16);
|
|
164
|
+
const search = Math.max(1, opts.searchRadius ?? 8);
|
|
165
|
+
const step = Math.max(1, opts.step ?? block);
|
|
166
|
+
const minConf = opts.minConfidence ?? 0.05;
|
|
167
|
+
const vectors = [];
|
|
168
|
+
let sumDx = 0;
|
|
169
|
+
let sumDy = 0;
|
|
170
|
+
let sumConf = 0;
|
|
171
|
+
let used = 0;
|
|
172
|
+
for (let by = 0; by + block <= height; by += step) {
|
|
173
|
+
for (let bx = 0; bx + block <= width; bx += step) {
|
|
174
|
+
let best = Infinity;
|
|
175
|
+
let second = Infinity;
|
|
176
|
+
let bestDx = 0;
|
|
177
|
+
let bestDy = 0;
|
|
178
|
+
for (let dy = -search; dy <= search; dy++) {
|
|
179
|
+
if (by + dy < 0 || by + dy + block > height)
|
|
180
|
+
continue;
|
|
181
|
+
for (let dx = -search; dx <= search; dx++) {
|
|
182
|
+
if (bx + dx < 0 || bx + dx + block > width)
|
|
183
|
+
continue;
|
|
184
|
+
const sad = blockSad(la.data, lb.data, width, bx, by, block, dx, dy);
|
|
185
|
+
if (sad < best) {
|
|
186
|
+
second = best;
|
|
187
|
+
best = sad;
|
|
188
|
+
bestDx = dx;
|
|
189
|
+
bestDy = dy;
|
|
190
|
+
}
|
|
191
|
+
else if (sad < second) {
|
|
192
|
+
second = sad;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const confidence = Number.isFinite(second) && second > 0 ? Math.min(1, (second - best) / second) : 0;
|
|
197
|
+
vectors.push({ x: bx, y: by, dx: bestDx, dy: bestDy, confidence });
|
|
198
|
+
if (confidence >= minConf) {
|
|
199
|
+
sumDx += bestDx * confidence;
|
|
200
|
+
sumDy += bestDy * confidence;
|
|
201
|
+
sumConf += confidence;
|
|
202
|
+
used++;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
vectors,
|
|
208
|
+
meanDx: sumConf > 0 ? sumDx / sumConf : 0,
|
|
209
|
+
meanDy: sumConf > 0 ? sumDy / sumConf : 0,
|
|
210
|
+
meanConfidence: used > 0 ? sumConf / used : 0,
|
|
211
|
+
width,
|
|
212
|
+
height,
|
|
213
|
+
blockSize: block
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/** Reduce a frame to a zero-mean, unit-variance luma plane. */
|
|
217
|
+
function normalizedPlane(frame, downscale) {
|
|
218
|
+
const plane = toLuma(frame, downscale);
|
|
219
|
+
const n = plane.data.length;
|
|
220
|
+
let sum = 0;
|
|
221
|
+
for (let i = 0; i < n; i++)
|
|
222
|
+
sum += plane.data[i];
|
|
223
|
+
const mean = sum / n;
|
|
224
|
+
let varSum = 0;
|
|
225
|
+
for (let i = 0; i < n; i++) {
|
|
226
|
+
const d = plane.data[i] - mean;
|
|
227
|
+
varSum += d * d;
|
|
228
|
+
}
|
|
229
|
+
const std = Math.sqrt(varSum / n) || 1;
|
|
230
|
+
const out = new Float32Array(n);
|
|
231
|
+
for (let i = 0; i < n; i++)
|
|
232
|
+
out[i] = (plane.data[i] - mean) / std;
|
|
233
|
+
return { data: out, width: plane.width, height: plane.height };
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Normalized cross-correlation between planes `a` and `b` where `b` is sampled
|
|
237
|
+
* at a spatial shift (dx,dy). Averaged over the in-bounds overlap only, so the
|
|
238
|
+
* normalization stays fair near the borders. Inputs are unit-variance, so the
|
|
239
|
+
* result is ~[-1, 1].
|
|
240
|
+
*/
|
|
241
|
+
function shiftedCorrelation(a, b, width, height, dx, dy) {
|
|
242
|
+
let sum = 0;
|
|
243
|
+
let count = 0;
|
|
244
|
+
for (let y = 0; y < height; y++) {
|
|
245
|
+
const yb = y + dy;
|
|
246
|
+
if (yb < 0 || yb >= height)
|
|
247
|
+
continue;
|
|
248
|
+
const rowA = y * width;
|
|
249
|
+
const rowB = yb * width;
|
|
250
|
+
for (let x = 0; x < width; x++) {
|
|
251
|
+
const xb = x + dx;
|
|
252
|
+
if (xb < 0 || xb >= width)
|
|
253
|
+
continue;
|
|
254
|
+
sum += a[rowA + x] * b[rowB + xb];
|
|
255
|
+
count++;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return count > 0 ? sum / count : 0;
|
|
259
|
+
}
|
|
260
|
+
/** Pick an integer downscale so the longer edge is ≤ maxDim. */
|
|
261
|
+
export function autoDownscale(frame, maxDim) {
|
|
262
|
+
const longer = Math.max(frame.width, frame.height);
|
|
263
|
+
if (longer <= maxDim)
|
|
264
|
+
return 1;
|
|
265
|
+
return Math.max(1, Math.ceil(longer / maxDim));
|
|
266
|
+
}
|
|
267
|
+
function generateDirections(radius) {
|
|
268
|
+
const dirs = [];
|
|
269
|
+
const r2 = radius * radius;
|
|
270
|
+
for (let dy = -radius; dy <= radius; dy++) {
|
|
271
|
+
for (let dx = -radius; dx <= radius; dx++) {
|
|
272
|
+
if (dx === 0 && dy === 0)
|
|
273
|
+
continue;
|
|
274
|
+
if (dx * dx + dy * dy > r2)
|
|
275
|
+
continue;
|
|
276
|
+
dirs.push({ dx, dy });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return dirs;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Reichardt / lag-1 opponent motion energy over a sequence.
|
|
283
|
+
*
|
|
284
|
+
* For every consecutive pair (t, t+1) and every candidate shift s, accumulate
|
|
285
|
+
* the normalized cross-correlation corr(s). The opponent response for a
|
|
286
|
+
* direction is R(s) = mean_t[corr(s)] − mean_t[corr(−s)]: coherent drift by
|
|
287
|
+
* velocity v drives corr(v)→high, corr(−v)→low, so R(v) is large; temporally
|
|
288
|
+
* independent twinkle gives corr(any)≈0 so R≈0. That subtraction is what
|
|
289
|
+
* separates a motion carrier from a static or twinkling background.
|
|
290
|
+
*/
|
|
291
|
+
export function motionEnergy(frames, opts = {}) {
|
|
292
|
+
const ds = opts.downscale ?? autoDownscale(frames[0], opts.maxDim ?? 96);
|
|
293
|
+
const planes = frames.map((f) => normalizedPlane(f, ds));
|
|
294
|
+
const { width, height } = planes[0];
|
|
295
|
+
const directions = opts.directions ?? generateDirections(opts.shiftRadius ?? 4);
|
|
296
|
+
// Correlation is symmetric under (frame-swap + shift-negate), so a single
|
|
297
|
+
// key per axis-signed shift lets us look up corr(−s) for the opponent term.
|
|
298
|
+
const key = (dx, dy) => `${dx},${dy}`;
|
|
299
|
+
const corrAccum = new Map();
|
|
300
|
+
// Every shift we will need a correlation for: the candidates and their
|
|
301
|
+
// negations.
|
|
302
|
+
const needed = new Map();
|
|
303
|
+
for (const d of directions) {
|
|
304
|
+
needed.set(key(d.dx, d.dy), d);
|
|
305
|
+
needed.set(key(-d.dx, -d.dy), { dx: -d.dx, dy: -d.dy });
|
|
306
|
+
}
|
|
307
|
+
const pairs = planes.length - 1;
|
|
308
|
+
for (let t = 0; t < pairs; t++) {
|
|
309
|
+
const a = planes[t].data;
|
|
310
|
+
const b = planes[t + 1].data;
|
|
311
|
+
for (const [k, d] of needed) {
|
|
312
|
+
const c = shiftedCorrelation(a, b, width, height, d.dx, d.dy);
|
|
313
|
+
corrAccum.set(k, (corrAccum.get(k) ?? 0) + c);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const meanCorr = (dx, dy) => (corrAccum.get(key(dx, dy)) ?? 0) / pairs;
|
|
317
|
+
const perDirection = directions.map((d) => ({
|
|
318
|
+
dx: d.dx,
|
|
319
|
+
dy: d.dy,
|
|
320
|
+
strength: meanCorr(d.dx, d.dy) - meanCorr(-d.dx, -d.dy)
|
|
321
|
+
}));
|
|
322
|
+
perDirection.sort((p, q) => q.strength - p.strength);
|
|
323
|
+
const dominant = perDirection[0] ?? { dx: 0, dy: 0, strength: 0 };
|
|
324
|
+
const coherence = Math.max(0, Math.min(1, dominant.strength));
|
|
325
|
+
const result = {
|
|
326
|
+
coherence,
|
|
327
|
+
dominant,
|
|
328
|
+
perDirection: perDirection.slice(0, 8),
|
|
329
|
+
width,
|
|
330
|
+
height
|
|
331
|
+
};
|
|
332
|
+
if (opts.includeMap) {
|
|
333
|
+
// Per-pixel motion energy for the dominant direction, averaged over pairs.
|
|
334
|
+
const map = new Float32Array(width * height);
|
|
335
|
+
for (let t = 0; t < pairs; t++) {
|
|
336
|
+
const a = planes[t].data;
|
|
337
|
+
const b = planes[t + 1].data;
|
|
338
|
+
for (let y = 0; y < height; y++) {
|
|
339
|
+
const yb = y + dominant.dy;
|
|
340
|
+
if (yb < 0 || yb >= height)
|
|
341
|
+
continue;
|
|
342
|
+
const rowA = y * width;
|
|
343
|
+
const rowB = yb * width;
|
|
344
|
+
for (let x = 0; x < width; x++) {
|
|
345
|
+
const xb = x + dominant.dx;
|
|
346
|
+
if (xb < 0 || xb >= width)
|
|
347
|
+
continue;
|
|
348
|
+
map[rowA + x] += (a[rowA + x] * b[rowB + xb]) / pairs;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
result.map = map;
|
|
353
|
+
}
|
|
354
|
+
return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AAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;oBAChC,MAAM,EAAE,GAAG,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;oBAC3B,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK;wBAAE,SAAS;oBACpC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;gBACvD,CAAC;YACF,CAAC;QACF,CAAC;QACD,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;IAClB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference Motion Analyzer — `media/motion` implementation
|
|
3
|
+
*
|
|
4
|
+
* Pure-TS `MotionAnalyzer` built on the `motion-math` kernels. Universal: no
|
|
5
|
+
* FS, no native, no async I/O — runs identically on consumer machines and in
|
|
6
|
+
* Cloudflare workers, which is why it ships inside `@vibesdotdev/media` rather
|
|
7
|
+
* than a provider package. A heavier provider (WASM SIMD, native, GPU) can
|
|
8
|
+
* register its own `media/motion` descriptor and win resolution in its scope.
|
|
9
|
+
*
|
|
10
|
+
* The runtime instantiates the default-exported class for each resolving runtime.
|
|
11
|
+
*/
|
|
12
|
+
import type { Frame } from '../schemas/motion-frame.ts';
|
|
13
|
+
import type { MotionAnalyzer } from '../interfaces/motion-analyzer.ts';
|
|
14
|
+
import type { FrameDiffOptions, FrameDiffResult, TemporalStatsOptions, TemporalStatsResult, OpticalFlowOptions, OpticalFlowResult, MotionEnergyOptions, MotionEnergyResult, MotionSummaryOptions, MotionSummary } from '../schemas/motion-analysis.ts';
|
|
15
|
+
export declare class ReferenceMotionAnalyzer implements MotionAnalyzer {
|
|
16
|
+
frameDiff(a: Frame, b: Frame, options?: FrameDiffOptions): Promise<FrameDiffResult>;
|
|
17
|
+
temporalStats(frames: Frame[], options?: TemporalStatsOptions): Promise<TemporalStatsResult>;
|
|
18
|
+
opticalFlow(a: Frame, b: Frame, options?: OpticalFlowOptions): Promise<OpticalFlowResult>;
|
|
19
|
+
motionEnergy(frames: Frame[], options?: MotionEnergyOptions): Promise<MotionEnergyResult>;
|
|
20
|
+
summarize(frames: Frame[], options?: MotionSummaryOptions): Promise<MotionSummary>;
|
|
21
|
+
}
|
|
22
|
+
export default ReferenceMotionAnalyzer;
|
|
23
|
+
//# sourceMappingURL=reference-motion-analyzer.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-motion-analyzer.impl.d.ts","sourceRoot":"","sources":["../../src/analyzers/reference-motion-analyzer.impl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EACX,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,MAAM,+BAA+B,CAAC;AAQvC,qBAAa,uBAAwB,YAAW,cAAc;IACvD,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IAKvF,aAAa,CAClB,MAAM,EAAE,KAAK,EAAE,EACf,OAAO,GAAE,oBAAyB,GAChC,OAAO,CAAC,mBAAmB,CAAC;IAIzB,WAAW,CAChB,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,KAAK,EACR,OAAO,GAAE,kBAAuB,GAC9B,OAAO,CAAC,iBAAiB,CAAC;IAKvB,YAAY,CACjB,MAAM,EAAE,KAAK,EAAE,EACf,OAAO,GAAE,mBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC;IAIxB,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC;CAsC5F;AAED,eAAe,uBAAuB,CAAC"}
|