@ai-matrx/media 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/CHANGELOG.md ADDED
@@ -0,0 +1,61 @@
1
+ # @ai-matrx/media
2
+
3
+ ## 0.1.0 — 2026-08-29
4
+
5
+ Initial release (campaign ruling C19). Root types + `/core` headless hooks +
6
+ `/react` DOM bindings, ported from the matrx-frontend originals with only the
7
+ coupling seams inverted.
8
+
9
+ **Ported units** (behavior verbatim; seams noted):
10
+
11
+ - `InlineMediaRef` (from `features/files/components/inline/InlineMediaRef.tsx`) —
12
+ resolution/transport/Redux hydration → `MediaClient.resolve`
13
+ (`transport: "blob"` is the private-pixels lane); blob bytes →
14
+ `MediaClient.getBlob`; the session-refresh retry → `MediaClient.recoverLoadError`;
15
+ `next/image` → the injected `MediaHostPorts.ImageComponent`; the audio
16
+ output-sink and exclusive-playback hooks → `MediaHostPorts.playbackSession`.
17
+ The `ref` CONTENT prop is preserved for the existing 116 call sites.
18
+ - `MediaThumbnail` — the 4-tier source priority became `/core`'s
19
+ `useThumbnailSource` (explicit `thumbnailUrl` → `resolution.thumbnailSrc`
20
+ variant metadata → live source render incl. video poster + private blob
21
+ lane → icon).
22
+ - `FileIcon` + the icon-relevant slice of the `file-types.ts` registry
23
+ (`getFileKindDetails`/`getFolderKindDetails`) — every extension→icon/color
24
+ row, MIME-prefix override, audio/webm disambiguation, dotfile-text
25
+ heuristic, folder + unknown defaults. Preview/thumbnail-strategy/size-cap
26
+ columns deliberately stay in the app (C8).
27
+ - `useFileAs`/`useDurableSrc`/`useFileBlob`/`useFileUpload` → the headless
28
+ `useMediaResolution`, `useMediaLoadRecovery`, `useMediaBlob`,
29
+ `useMediaUpload` (+ per-file tray `entries`, replacing the Redux
30
+ `selectVisibleUploads` coupling).
31
+ - `FileUploadDropzone` + `UploadProgressList` — `react-dropzone` replaced by
32
+ the package's own headless `useMediaDropzone` (native drag/paste/picker);
33
+ acquisition sources (Drive, local folder, existing files) became the
34
+ `actions` slot.
35
+
36
+ **THE SHARE MANDATE (C19)**: the complete headless `MediaActionsPort`
37
+ contract (share/download/copy/open + the `SharePopover` slot) ships now, with
38
+ `MediaActionToolbar` and `MediaLightbox` shells wired to it and failing
39
+ closed. The share-popover BODIES land as a mandated tracked wave the moment
40
+ the associations package provides its ports — additively, through this same
41
+ contract.
42
+
43
+ **Icons**: the package ships its own inlined SVGs (32 glyphs copied from
44
+ lucide-react v1.22.0, ISC) — no icon-library dependency, per C19.
45
+
46
+ **Deliberate divergences from the originals** (not defects in either):
47
+
48
+ - `UploadProgressList` counts only `"uploading"` entries as active (the
49
+ original also counted a Redux-only `"pending"` state that has no analog in
50
+ the hook-owned tray).
51
+ - `InlineMediaRef` renders a skeleton while the private blob lane loads
52
+ (the original rendered the resolved-URL path immediately because its blob
53
+ cache hydrated synchronously; the cache now lives behind the client).
54
+ - The dropzone's inline mode renders a "Browse files" button (the original's
55
+ picker affordance lived in the app-shaped `FileAcquisitionActions`, now the
56
+ `actions` slot).
57
+
58
+ **Defects found in the originals during the port**: none rising to a fix —
59
+ the known duplicate retry implementations (`useUnifiedImageUrl` /
60
+ `useUnifiedVideoUrl`) are wave-2 scope and recorded in the design doc, not
61
+ silently patched here.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AI Matrix Engine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # @ai-matrx/media
2
+
3
+ Media components that **just work** with a durable file system. Renderers for
4
+ images, video, audio and file thumbnails that take a durable reference — a
5
+ `file_id` or a permanent public URL — and own the whole URL lifecycle:
6
+ resolution, auth transport, load-error recovery, typed unavailable states,
7
+ upload progress, and share/download/copy/open actions.
8
+
9
+ The package ships **zero transport**. Everything data-shaped arrives through
10
+ one injected port, the `MediaClient`. That is the point: every media breakage
11
+ we ever shipped came from code that hand-built a URL or an `<img>`; here the
12
+ correct path is the only path the types allow.
13
+
14
+ ```
15
+ @ai-matrx/media types only — MediaRef, DurableSrc, MediaClient, host ports
16
+ @ai-matrx/media/core headless React hooks (platform-free state machines)
17
+ @ai-matrx/media/react DOM components (Tailwind classes, inlined SVG icons)
18
+ ```
19
+
20
+ ## The rules the types enforce
21
+
22
+ 1. **The package never fetches a media URL itself.** Bytes exist only via
23
+ `MediaClient.getBlob`.
24
+ 2. **Every component takes a ref, never a `src`.** Even a caller-supplied URL
25
+ string is classified by `resolve()`, never trusted.
26
+ 3. **A signed URL is a handoff, never an identity.** The only string a media
27
+ element binds is the branded `DurableSrc`, which only a `MediaClient`
28
+ implementation can mint. An expiring URL cannot pass the types without an
29
+ unsafe cast.
30
+ 4. **Share affordances fail closed.** `shareableUrl` returns `null` rather
31
+ than ever emitting a signed URL; unwired actions render disabled.
32
+ 5. **One retry policy.** Load errors route through
33
+ `MediaClient.recoverLoadError` (session refresh → same-URL retry →
34
+ terminal). The package has no retry logic of its own.
35
+
36
+ ## Quick start
37
+
38
+ ```tsx
39
+ import { MediaProvider } from "@ai-matrx/media/core";
40
+ import { InlineMediaRef, MediaThumbnail, MediaLightbox } from "@ai-matrx/media/react";
41
+
42
+ // `client` implements the MediaClient interface from "@ai-matrx/media".
43
+ // Matrx apps wire the canonical implementation from @ai-matrx/data/files;
44
+ // any structural implementation works.
45
+ <MediaProvider client={client} ports={{ ImageComponent, actions, playbackSession }}>
46
+ <InlineMediaRef ref={{ file_id }} size="md" fit="cover" />
47
+ <MediaThumbnail mediaRef={{ file_id }} fileName="report.pdf" />
48
+ </MediaProvider>
49
+ ```
50
+
51
+ `InlineMediaRef` accepts a `MediaRef` (`{ file_id, url?, mime_type? }`), a
52
+ bare fileId string, or an external public URL string — and renders a
53
+ correctly-sized `<img>` / `<video>` / `<audio>` with fallback and informative
54
+ error states. `ref` is a content prop (React 19); use `mediaElementRef` for
55
+ DOM access.
56
+
57
+ ## Headless hooks (`/core`)
58
+
59
+ | Hook | What it owns |
60
+ |---|---|
61
+ | `useMediaResolution(ref)` | ref → `MediaResolution` as state (`empty` / `ready` / `unavailable` with a typed reason) |
62
+ | `useMediaLoadRecovery(src)` | the retry-key/error machine over the client's ONE recovery policy |
63
+ | `useMediaBlob(ref)` | object-URL bytes with lifecycle + release |
64
+ | `useMediaUpload()` | single + batch upload, progress, and a per-file tray (`entries`) |
65
+ | `useThumbnailSource(ref, opts)` | the 4-tier thumbnail decision (rendered thumb → variant → live source → icon) |
66
+ | `useMediaActions(ref)` | share/download/copy/open availability + execution over the injected actions port |
67
+ | `getFileKindDetails(name, mime)` | filename/MIME → category, icon name, color |
68
+
69
+ ## Components (`/react`)
70
+
71
+ `InlineMediaRef` · `MediaThumbnail` · `FileIcon` · `FileUploadDropzone` (+
72
+ `UploadProgressList`, `useMediaDropzone`) · `MediaActionToolbar` ·
73
+ `MediaLightbox` — plus the package's own inlined SVG icon set (no icon
74
+ library dependency).
75
+
76
+ ### Actions & sharing
77
+
78
+ Hosts inject a `MediaActionsPort` (`share`, `download`, `copy`, `open`
79
+ handlers and/or a rich `SharePopover` component). The toolbar and lightbox
80
+ render whatever is wired and disable the rest — sharing integration plugs in
81
+ without touching this package.
82
+
83
+ ```tsx
84
+ <MediaProvider client={client} ports={{ actions: { download, share, SharePopover } }}>
85
+ <MediaActionToolbar mediaRef={{ file_id }} fileName="photo.png" />
86
+ </MediaProvider>
87
+ ```
88
+
89
+ ## Styling
90
+
91
+ `/react` uses Tailwind utility classes with semantic tokens (`bg-muted`,
92
+ `text-destructive`, …). Tailwind v4 hosts register the package as a source:
93
+
94
+ ```css
95
+ @source "../node_modules/@ai-matrx/media";
96
+ ```
97
+
98
+ ## SSR / RSC
99
+
100
+ The root entry is server-safe (types + one pure function). `/core` and
101
+ `/react` are client modules (`"use client"` is stamped per entry). Nothing
102
+ touches `window` at import time.
103
+
104
+ ## License
105
+
106
+ MIT. Inlined icon paths copied from [Lucide](https://lucide.dev) (ISC).