@popmelt.com/core 0.18.0 → 0.18.1

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.
@@ -0,0 +1,339 @@
1
+ import { P as PopmeltSubjectAdapter, f as PopmeltSubject, E as ElementInfo, h as PopmeltSubjectCreationSession, g as PopmeltSubjectBounds, i as PopmeltSubjectTrackingAnchor } from './subjects-CeqtFged.mjs';
2
+
3
+ /** Geometry is normalized against the loaded image, not its rendered size. */
4
+ type ImageObjectBox = {
5
+ left: number;
6
+ top: number;
7
+ width: number;
8
+ height: number;
9
+ };
10
+ /** A provider's observation; no inference runtime is required by Core. */
11
+ type ImageObjectObservation = {
12
+ label: string;
13
+ score: number;
14
+ box: ImageObjectBox;
15
+ };
16
+
17
+ type PersistedImageSubject = {
18
+ id: string;
19
+ label: string;
20
+ detectedLabel?: string;
21
+ score: number;
22
+ box: ImageObjectBox;
23
+ detectedBox?: ImageObjectBox;
24
+ origin: 'detected' | 'manual';
25
+ boundsOverridden?: boolean;
26
+ };
27
+ type PersistedImageSuppression = {
28
+ detectedLabel: string;
29
+ detectedBox: ImageObjectBox;
30
+ };
31
+ type PersistedImageAnalysis = {
32
+ schemaVersion: 1;
33
+ source: string;
34
+ imageHash: string;
35
+ inferenceKey: string;
36
+ dedupeKey: string;
37
+ subjects: readonly PersistedImageSubject[];
38
+ /** Inferred objects explicitly removed by the user for this image hash. */
39
+ suppressions?: readonly PersistedImageSuppression[];
40
+ updatedAt: number;
41
+ };
42
+ type ImageSubjectStore = {
43
+ load(key: string): PersistedImageAnalysis | null | Promise<PersistedImageAnalysis | null>;
44
+ save(key: string, analysis: PersistedImageAnalysis): void | Promise<void>;
45
+ remove?(key: string): void | Promise<void>;
46
+ /** Older content-hash versions retained before the active record changed. */
47
+ loadHistory?(key: string): readonly PersistedImageAnalysis[] | Promise<readonly PersistedImageAnalysis[]>;
48
+ };
49
+ type BrowserImageSubjectStoreOptions = {
50
+ /** Prefix used for browser storage entries. */
51
+ namespace?: string;
52
+ /** Override localStorage, primarily for embedded browsers and tests. */
53
+ storage?: Storage;
54
+ };
55
+ declare function createBrowserImageSubjectStore(options?: BrowserImageSubjectStoreOptions): ImageSubjectStore;
56
+ declare function createMemoryImageSubjectStore(): ImageSubjectStore;
57
+
58
+ type ImageContentHasher = (image: HTMLImageElement) => string | Promise<string>;
59
+ /** Optional perception boundary. Core keeps media authoring usable without it. */
60
+ type ImageRecognitionProvider = {
61
+ cacheKey: string;
62
+ configurationKey: string;
63
+ detect(image: HTMLImageElement): Promise<readonly ImageObjectObservation[]>;
64
+ reconcile(observations: readonly ImageObjectObservation[], previousSubjects: readonly PersistedImageSubject[], suppressions: readonly PersistedImageSuppression[]): readonly PersistedImageSubject[];
65
+ dispose?(): void | Promise<void>;
66
+ };
67
+ type ImageSubjectAdapterOptions = {
68
+ /** Optional perception; omit for manual-only image annotation. */
69
+ recognition?: ImageRecognitionProvider;
70
+ /** Restore saved subjects without hashing or running recognition. */
71
+ hydrateOnly?: boolean;
72
+ /** Images to analyze when the adapter starts. Defaults to every image. */
73
+ selector?: string;
74
+ /** Root to scan and observe. Defaults to document. */
75
+ root?: Document | Element;
76
+ /** Observe added images and src changes. Defaults to true. */
77
+ observe?: boolean;
78
+ /** Override the durable Core adapter id. */
79
+ id?: string;
80
+ /** Persist detections and user overrides. Omit to keep adapter state ephemeral. */
81
+ store?: ImageSubjectStore;
82
+ /** Override content hashing, primarily for authenticated or virtual images. */
83
+ imageHasher?: ImageContentHasher;
84
+ onError?: (error: unknown, image: HTMLImageElement) => void;
85
+ };
86
+ declare class ImageSubjectAdapter implements PopmeltSubjectAdapter {
87
+ private readonly options;
88
+ readonly surfaceKind: "image";
89
+ readonly id: string;
90
+ private readonly records;
91
+ private readonly imageKeys;
92
+ private readonly analyzedSources;
93
+ private readonly pending;
94
+ private readonly analysisMetadata;
95
+ private readonly suppressions;
96
+ private readonly writeChains;
97
+ private readonly pendingWrites;
98
+ private readonly observer;
99
+ private refreshQueued;
100
+ private destroyed;
101
+ private readyPromise;
102
+ private manualSequence;
103
+ constructor(options?: ImageSubjectAdapterOptions);
104
+ whenReady(): Promise<void>;
105
+ listSubjects(): readonly PopmeltSubject[];
106
+ refresh(): Promise<void>;
107
+ hitTest(clientPoint: {
108
+ x: number;
109
+ y: number;
110
+ }): PopmeltSubject | null;
111
+ resolve(key: string): PopmeltSubject | null;
112
+ restoreSubject(key: string, elementInfo: ElementInfo): PopmeltSubject | null;
113
+ private imageObjectContext;
114
+ captureSubject(key: string): Promise<Blob | null>;
115
+ beginCreate(clientPoint: {
116
+ x: number;
117
+ y: number;
118
+ }): PopmeltSubjectCreationSession | null;
119
+ renameSubject(key: string, label: string): PopmeltSubject | null;
120
+ updateSubjectBounds(key: string, bounds: PopmeltSubjectBounds): PopmeltSubject | null;
121
+ removeSubject(key: string): void;
122
+ destroy(): Promise<void>;
123
+ private queueRefresh;
124
+ private analyze;
125
+ private replaceImageRecords;
126
+ private imageIdentity;
127
+ private matchingImages;
128
+ private clampedImagePoint;
129
+ private newObjectId;
130
+ private persistImage;
131
+ private saveImage;
132
+ private imageSubjects;
133
+ private persistencePayload;
134
+ private removeImage;
135
+ }
136
+ declare function createImageSubjectAdapter(options?: ImageSubjectAdapterOptions): ImageSubjectAdapter;
137
+
138
+ type VideoObjectBox = ImageObjectBox;
139
+ type VideoTrackingAnchor = PopmeltSubjectTrackingAnchor;
140
+ type VideoTrackKeyframe = {
141
+ time: number;
142
+ box: VideoObjectBox;
143
+ score: number;
144
+ source: 'manual' | 'tracked';
145
+ };
146
+ type VideoTrackObservation = {
147
+ time: number;
148
+ box: VideoObjectBox;
149
+ score: number;
150
+ };
151
+ type VideoTrackingAttempt = {
152
+ /** Expand the normal local search crop during reacquisition. */
153
+ searchScale?: number;
154
+ };
155
+ type VideoTrackSegment = {
156
+ /** First media time at which this object is confidently observable. */
157
+ start: number;
158
+ /** Last confidently observable media time. Omitted while the segment is open. */
159
+ end?: number;
160
+ };
161
+ type VideoTrackingSeed = {
162
+ video: HTMLVideoElement;
163
+ time: number;
164
+ box: VideoObjectBox;
165
+ anchors?: readonly VideoTrackingAnchor[];
166
+ };
167
+ type VideoTrackingSession = {
168
+ track(video: HTMLVideoElement, time: number, attempt?: VideoTrackingAttempt): Promise<VideoTrackObservation | null>;
169
+ reseed?(seed: VideoTrackingSeed): void | Promise<void>;
170
+ dispose?(): void | Promise<void>;
171
+ };
172
+ type VideoTrackSmoother = {
173
+ /** Builds one presentation frame from a chronological durable observation. */
174
+ smooth(frame: VideoTrackKeyframe): VideoTrackKeyframe;
175
+ };
176
+ type VideoMotionState = {
177
+ visible: boolean;
178
+ misses: number;
179
+ hits: number;
180
+ lostAt?: number;
181
+ };
182
+ type VideoMotionPresenceDecision = {
183
+ state: VideoMotionState;
184
+ action: 'accept' | 'hold' | 'close' | 'reopen';
185
+ };
186
+ type VideoMotionAttempt = {
187
+ framesPerSecond: number;
188
+ tracking: VideoTrackingAttempt;
189
+ };
190
+ type VideoBackwardAnalysisOptions = {
191
+ source: HTMLVideoElement;
192
+ seedTime: number;
193
+ keyframes: readonly VideoTrackKeyframe[];
194
+ anchors: readonly VideoTrackingAnchor[];
195
+ maximumFramesPerSecond: number;
196
+ cancelled: () => boolean;
197
+ forwardWork: () => Promise<void> | undefined;
198
+ };
199
+ type VideoBackwardAnalysisResult = {
200
+ earliestTime: number;
201
+ keyframes: VideoTrackKeyframe[];
202
+ };
203
+ /**
204
+ * Pixel-derived motion policy supplied by a perception extension. Core invokes
205
+ * it, then stores and renders the resulting durable and presentation tracks.
206
+ */
207
+ type VideoMotionPolicy = {
208
+ createSmoother(): VideoTrackSmoother;
209
+ attempt(options: {
210
+ state: VideoMotionState;
211
+ time: number;
212
+ maximumFramesPerSecond: number;
213
+ }): VideoMotionAttempt;
214
+ observe(options: {
215
+ state: VideoMotionState;
216
+ time: number;
217
+ observation: VideoTrackObservation | null;
218
+ }): VideoMotionPresenceDecision;
219
+ analyzeBackward(options: VideoBackwardAnalysisOptions): Promise<VideoBackwardAnalysisResult>;
220
+ };
221
+ /** Optional local perception boundary. Core owns tracks and authoring. */
222
+ type VideoTrackingProvider = {
223
+ cacheKey: string;
224
+ configurationKey: string;
225
+ motion: VideoMotionPolicy;
226
+ createSession(seed: VideoTrackingSeed): Promise<VideoTrackingSession>;
227
+ dispose?(): void | Promise<void>;
228
+ };
229
+ type PersistedVideoTrack = {
230
+ id: string;
231
+ label: string;
232
+ origin: 'manual' | 'detected';
233
+ keyframes: readonly VideoTrackKeyframe[];
234
+ /** See-derived display geometry, persisted so Core can replay it alone. */
235
+ presentationKeyframes?: readonly VideoTrackKeyframe[];
236
+ anchors?: readonly VideoTrackingAnchor[];
237
+ /** Explicit visible spans. Missing on schema-v1 tracks, which migrate open-ended. */
238
+ segments?: readonly VideoTrackSegment[];
239
+ /** Furthest media time already covered by forward inference. */
240
+ analyzedThrough?: number;
241
+ createdAt: number;
242
+ updatedAt: number;
243
+ };
244
+ type PersistedVideoAnalysis = {
245
+ schemaVersion: 1 | 2 | 3;
246
+ source: string;
247
+ duration: number;
248
+ tracks: readonly PersistedVideoTrack[];
249
+ updatedAt: number;
250
+ };
251
+ type VideoSubjectStore = {
252
+ load(key: string): PersistedVideoAnalysis | null | Promise<PersistedVideoAnalysis | null>;
253
+ save(key: string, analysis: PersistedVideoAnalysis): void | Promise<void>;
254
+ remove?(key: string): void | Promise<void>;
255
+ };
256
+
257
+ type VideoSubjectAdapterOptions = {
258
+ tracking?: VideoTrackingProvider;
259
+ selector?: string;
260
+ root?: Document | Element;
261
+ observe?: boolean;
262
+ id?: string;
263
+ store?: VideoSubjectStore;
264
+ maxTrackingFramesPerSecond?: number;
265
+ onError?: (error: unknown, video: HTMLVideoElement) => void;
266
+ };
267
+ declare class VideoSubjectAdapter implements PopmeltSubjectAdapter {
268
+ private readonly options;
269
+ readonly surfaceKind: "video";
270
+ readonly id: string;
271
+ private readonly records;
272
+ private readonly videoKeys;
273
+ private readonly metadata;
274
+ private readonly analyzedSources;
275
+ private readonly listeners;
276
+ private readonly frameHandles;
277
+ private readonly persistTimers;
278
+ private readonly writeChains;
279
+ private readonly pendingWrites;
280
+ private readonly observer;
281
+ private refreshQueued;
282
+ private destroyed;
283
+ private manualSequence;
284
+ private activeTrackingKey;
285
+ private readyPromise;
286
+ constructor(options?: VideoSubjectAdapterOptions);
287
+ whenReady(): Promise<void>;
288
+ listSubjects(): readonly PopmeltSubject[];
289
+ refresh(): Promise<void>;
290
+ hitTest(point: {
291
+ x: number;
292
+ y: number;
293
+ }): PopmeltSubject | null;
294
+ resolve(key: string): PopmeltSubject | null;
295
+ captureSubject(key: string): Promise<Blob | null>;
296
+ beginCreate(point: {
297
+ x: number;
298
+ y: number;
299
+ }): PopmeltSubjectCreationSession | null;
300
+ renameSubject(key: string, label: string): PopmeltSubject | null;
301
+ updateSubjectBounds(key: string, bounds: PopmeltSubjectBounds): PopmeltSubject | null;
302
+ updateSubjectTrackingAnchors(key: string, anchors: readonly PopmeltSubjectTrackingAnchor[]): PopmeltSubject | null;
303
+ removeSubject(key: string): void;
304
+ destroy(): Promise<void>;
305
+ private analyze;
306
+ private addVideoListeners;
307
+ private removeVideoListeners;
308
+ private scheduleFrame;
309
+ private trackVideo;
310
+ private startSession;
311
+ private reseed;
312
+ private failTracking;
313
+ private activeRecordFor;
314
+ private activateMostRecentRecord;
315
+ private activateTrackingRecord;
316
+ private scheduleBackwardAnalysis;
317
+ private cancelBackwardAnalysis;
318
+ private runBackwardAnalysis;
319
+ private acceptObservation;
320
+ private openSegment;
321
+ private closeSegment;
322
+ private insertKeyframe;
323
+ private rebuildPresentationTrack;
324
+ private clearLiveFrames;
325
+ private videoObjectContext;
326
+ private replaceVideoRecords;
327
+ private persistVideo;
328
+ private schedulePersistence;
329
+ private flushScheduledPersistence;
330
+ private matchingVideos;
331
+ private videoIdentity;
332
+ private newObjectId;
333
+ private removeVideoRecords;
334
+ private removeVideo;
335
+ private queueRefresh;
336
+ }
337
+ declare function createVideoSubjectAdapter(options?: VideoSubjectAdapterOptions): VideoSubjectAdapter;
338
+
339
+ export { type VideoTrackingSeed as A, type BrowserImageSubjectStoreOptions as B, type VideoTrackingSession as C, createBrowserImageSubjectStore as D, createImageSubjectAdapter as E, createMemoryImageSubjectStore as F, createVideoSubjectAdapter as G, type ImageRecognitionProvider as I, type PersistedImageAnalysis as P, type VideoTrackingProvider as V, type ImageSubjectAdapterOptions as a, type VideoSubjectAdapterOptions as b, type ImageObjectBox as c, type VideoSubjectStore as d, type VideoObjectBox as e, type ImageContentHasher as f, type ImageObjectObservation as g, ImageSubjectAdapter as h, type ImageSubjectStore as i, type PersistedImageSubject as j, type PersistedImageSuppression as k, type PersistedVideoAnalysis as l, type PersistedVideoTrack as m, type VideoBackwardAnalysisOptions as n, type VideoBackwardAnalysisResult as o, type VideoMotionAttempt as p, type VideoMotionPolicy as q, type VideoMotionPresenceDecision as r, type VideoMotionState as s, VideoSubjectAdapter as t, type VideoTrackKeyframe as u, type VideoTrackObservation as v, type VideoTrackSegment as w, type VideoTrackSmoother as x, type VideoTrackingAnchor as y, type VideoTrackingAttempt as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popmelt.com/core",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "A tiny, powerful design layer for humans and AI",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "author": "Popmelt <reb@popmelt.com> (https://popmelt.com)",
@@ -24,6 +24,7 @@
24
24
  "popmelt": "dist/cli.mjs"
25
25
  },
26
26
  "sideEffects": false,
27
+ "packageManager": "pnpm@9.12.0",
27
28
  "engines": {
28
29
  "node": ">=18.0.0"
29
30
  },
@@ -88,6 +89,10 @@
88
89
  "./three": {
89
90
  "types": "./dist/adapter-three.d.mts",
90
91
  "import": "./dist/adapter-three.mjs"
92
+ },
93
+ "./react-three-fiber": {
94
+ "types": "./dist/adapter-react-three-fiber.d.mts",
95
+ "import": "./dist/adapter-react-three-fiber.mjs"
91
96
  }
92
97
  },
93
98
  "files": [
@@ -106,18 +111,23 @@
106
111
  "next": ">=14.0.0",
107
112
  "react": ">=18.0.0",
108
113
  "react-dom": ">=18.0.0",
114
+ "@react-three/fiber": ">=8.0.0",
109
115
  "three": ">=0.150.0"
110
116
  },
111
117
  "peerDependenciesMeta": {
112
118
  "next": {
113
119
  "optional": true
114
120
  },
121
+ "@react-three/fiber": {
122
+ "optional": true
123
+ },
115
124
  "three": {
116
125
  "optional": true
117
126
  }
118
127
  },
119
128
  "devDependencies": {
120
129
  "@kit/eslint-config": "workspace:^",
130
+ "@react-three/fiber": "9.7.0",
121
131
  "@tanstack/react-router": "1.120.5",
122
132
  "@types/react": "19.1.0",
123
133
  "@types/react-dom": "19.1.2",
@@ -129,14 +139,14 @@
129
139
  "geist": "1.7.2",
130
140
  "jsdom": "26.1.0",
131
141
  "lucide-react": "^1.23.0",
132
- "next": "15.3.8",
133
- "prettier": "^3.5.3",
142
+ "next": "15.5.24",
143
+ "prettier": "3.5.3",
134
144
  "react": "19.1.0",
135
145
  "react-dom": "19.1.0",
136
146
  "three": "^0.185.1",
137
147
  "tsup": "^8.5.1",
138
148
  "typescript": "^5.8.3",
139
149
  "vite": "7.3.6",
140
- "vitest": "^3.2.4"
150
+ "vitest": "3.2.4"
141
151
  }
142
152
  }