@overtone-art/canvas-editor-core 0.2.7 → 0.2.8
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/dist/chunk-ORZZ6MGQ.mjs +228 -0
- package/dist/chunk-ORZZ6MGQ.mjs.map +1 -0
- package/dist/index.d.mts +157 -4
- package/dist/index.d.ts +157 -4
- package/dist/index.global.js +59 -59
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +660 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +500 -21
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +51 -2
- package/dist/node.d.ts +51 -2
- package/dist/node.js +546 -13
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +446 -4
- package/dist/node.mjs.map +1 -1
- package/dist/{types-bOY7oYVq.d.mts → types-D60CfxL9.d.mts} +80 -2
- package/dist/{types-bOY7oYVq.d.ts → types-D60CfxL9.d.ts} +80 -2
- package/package.json +37 -2
- package/dist/chunk-NINRTPOJ.mjs +0 -104
- package/dist/chunk-NINRTPOJ.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Canvas, FabricObject, ImageFormat } from 'fabric';
|
|
2
|
-
import { b as EditorEvents, l as LayerType, k as LayerMeta, L as LayerData,
|
|
3
|
-
export { D as DEFAULT_PATTERN_CONFIG, d as ExportFormat, f as ImageAttribution, n as LicensePayload,
|
|
2
|
+
import { b as EditorEvents, l as LayerType, k as LayerMeta, L as LayerData, U as SerializedLayer, G as PatternSourceResolver, P as PatternConfig, A as PatternLocks, _ as Unit, z as MockupPrintArea, v as MockupConfig, e as FontDefinition, m as LicenseConfig, o as LicenseStatus, Q as ProjectState, M as MaskBrushOptions, p as MaskPoint, r as MaskRefinementProvider, q as MaskRefinementPrompt, t as MaskRefinementResult, E as EditorConfig, V as ShapePlugin, X as TemplateDefinition, I as ImageAdjustments, c as EditorState, S as SemanticExportOptions, W as SvgExportOptions, K as PrintifyPositioning, N as NormalizedLayerPosition, J as PositioningAdapter, h as ImageProviderResult, i as ImageSearchOptions, j as ImageSearchResult, F as FileAdapter, g as ImageProvider, T as SerializedBackgroundImageOptions, B as BackgroundImageOptions, R as ResizeOptions, a as DpiIssue, C as CanvasSizePreset, w as MockupDisplacement } from './types-D60CfxL9.js';
|
|
3
|
+
export { D as DEFAULT_PATTERN_CONFIG, d as ExportFormat, f as ImageAttribution, n as LicensePayload, s as MaskRefinementRequest, u as MockupBlendMode, x as MockupDisplacementChannel, y as MockupOverlay, H as PatternState, O as ProjectPage, Y as TemplateParameter, Z as TileMode } from './types-D60CfxL9.js';
|
|
4
4
|
|
|
5
5
|
type EventHandler<T> = (data: T) => void;
|
|
6
6
|
declare class EventEmitter<TEvents extends {} = Record<string, unknown>> {
|
|
@@ -53,8 +53,12 @@ declare class LayerManager {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
declare class HistoryManager {
|
|
56
|
+
private static readonly ASSET_KEY;
|
|
56
57
|
private undoStack;
|
|
57
58
|
private redoStack;
|
|
59
|
+
private assets;
|
|
60
|
+
private assetIds;
|
|
61
|
+
private nextAssetId;
|
|
58
62
|
private maxSize;
|
|
59
63
|
private maxBytes;
|
|
60
64
|
private paused;
|
|
@@ -94,6 +98,21 @@ declare class HistoryManager {
|
|
|
94
98
|
private emitChanged;
|
|
95
99
|
private snapshotBytes;
|
|
96
100
|
private trimToBudget;
|
|
101
|
+
/**
|
|
102
|
+
* History is internal and can content-address large raster strings without
|
|
103
|
+
* changing the public EditorState wire format. Unchanged images are retained
|
|
104
|
+
* once even when dozens of snapshots reference them.
|
|
105
|
+
*/
|
|
106
|
+
private compactState;
|
|
107
|
+
private expandState;
|
|
108
|
+
/**
|
|
109
|
+
* Runs on every commit, so it scans for the serialized reference marker
|
|
110
|
+
* instead of re-parsing every snapshot — parsing multi-megabyte raster states
|
|
111
|
+
* per save would cost more than the retention it reclaims. `JSON.stringify`
|
|
112
|
+
* emits the marker verbatim; the same text inside user data is escaped and
|
|
113
|
+
* therefore cannot match.
|
|
114
|
+
*/
|
|
115
|
+
private pruneAssets;
|
|
97
116
|
}
|
|
98
117
|
|
|
99
118
|
/**
|
|
@@ -308,6 +327,60 @@ declare class ProjectManager {
|
|
|
308
327
|
private emitChanged;
|
|
309
328
|
}
|
|
310
329
|
|
|
330
|
+
type MaskRefinementErrorCode = 'not-found' | 'cancelled' | 'provider' | 'invalid-result';
|
|
331
|
+
declare class MaskRefinementError extends Error {
|
|
332
|
+
readonly code: MaskRefinementErrorCode;
|
|
333
|
+
readonly cause?: unknown | undefined;
|
|
334
|
+
constructor(code: MaskRefinementErrorCode, message: string, cause?: unknown | undefined);
|
|
335
|
+
}
|
|
336
|
+
interface MaskPerformanceSample {
|
|
337
|
+
width: number;
|
|
338
|
+
height: number;
|
|
339
|
+
backingBytes: number;
|
|
340
|
+
strokeBackupBytes: number;
|
|
341
|
+
estimatedPeakBytes: number;
|
|
342
|
+
historyBytes: number;
|
|
343
|
+
interactionLatencyMs: number;
|
|
344
|
+
usedJsHeapBytes?: number;
|
|
345
|
+
elapsedMs: number;
|
|
346
|
+
}
|
|
347
|
+
/** Raster-mask editing without exposing Fabric brush classes in the public contract. */
|
|
348
|
+
declare class MaskController {
|
|
349
|
+
private readonly editor;
|
|
350
|
+
private backing;
|
|
351
|
+
private context;
|
|
352
|
+
private layerId;
|
|
353
|
+
private brush;
|
|
354
|
+
private previousPoint;
|
|
355
|
+
private strokeBackup;
|
|
356
|
+
private strokeStartedAt;
|
|
357
|
+
private lastInteractionLatencyMs;
|
|
358
|
+
private refinement;
|
|
359
|
+
private disposed;
|
|
360
|
+
constructor(editor: CanvasEditor);
|
|
361
|
+
create(width?: number, height?: number): Promise<Layer>;
|
|
362
|
+
attach(layerId: string): void;
|
|
363
|
+
beginStroke(options: MaskBrushOptions): void;
|
|
364
|
+
addPoint(point: MaskPoint): void;
|
|
365
|
+
endStroke(): Promise<void>;
|
|
366
|
+
cancelStroke(): void;
|
|
367
|
+
isStrokeActive(): boolean;
|
|
368
|
+
activeLayerId(): string | null;
|
|
369
|
+
detach(layerId?: string): void;
|
|
370
|
+
refine(layerId: string, provider: MaskRefinementProvider, prompts: MaskRefinementPrompt[], options?: {
|
|
371
|
+
signal?: AbortSignal;
|
|
372
|
+
onProgress?: (progress: number) => void;
|
|
373
|
+
}): Promise<MaskRefinementResult>;
|
|
374
|
+
cancelRefinement(): void;
|
|
375
|
+
measure(): MaskPerformanceSample | null;
|
|
376
|
+
dispose(): void;
|
|
377
|
+
private drawDot;
|
|
378
|
+
private makeCanvas;
|
|
379
|
+
private attachBacking;
|
|
380
|
+
private requireMask;
|
|
381
|
+
private assertActive;
|
|
382
|
+
}
|
|
383
|
+
|
|
311
384
|
declare class CanvasEditor {
|
|
312
385
|
readonly canvas: Canvas;
|
|
313
386
|
readonly layers: LayerManager;
|
|
@@ -320,12 +393,14 @@ declare class CanvasEditor {
|
|
|
320
393
|
readonly fonts: FontRegistry;
|
|
321
394
|
readonly licensing: LicenseManager;
|
|
322
395
|
readonly pages: ProjectManager;
|
|
396
|
+
readonly masks: MaskController;
|
|
323
397
|
private fileAdapter?;
|
|
324
398
|
private imageProvider?;
|
|
325
399
|
private zoomLevel;
|
|
326
400
|
private mockup;
|
|
327
401
|
private designBackground;
|
|
328
402
|
private designBackgroundImage;
|
|
403
|
+
private backgroundImageOptions;
|
|
329
404
|
constructor(canvasElement: HTMLCanvasElement, config: EditorConfig);
|
|
330
405
|
addImage(url: string, options?: Partial<Record<string, unknown>>): Promise<Layer>;
|
|
331
406
|
/** Replace an image source without changing its layer identity or visual transform. */
|
|
@@ -350,6 +425,10 @@ declare class CanvasEditor {
|
|
|
350
425
|
toPNG(options?: PngExportOptions): Promise<Blob>;
|
|
351
426
|
toJPEG(options?: Omit<PngExportOptions, 'format'>): Promise<Blob>;
|
|
352
427
|
toWebP(options?: Omit<PngExportOptions, 'format'>): Promise<Blob>;
|
|
428
|
+
/** Export one layer in document coordinates or at its native image resolution. */
|
|
429
|
+
exportLayer(id: string, options?: SemanticExportOptions): Promise<Blob>;
|
|
430
|
+
/** Export only the configured document background, excluding design layers. */
|
|
431
|
+
exportBackground(options?: SemanticExportOptions): Promise<Blob>;
|
|
353
432
|
private toRaster;
|
|
354
433
|
toSVG(): string;
|
|
355
434
|
toSVGAsync(options?: SvgExportOptions): Promise<string>;
|
|
@@ -377,9 +456,10 @@ declare class CanvasEditor {
|
|
|
377
456
|
setBackground(color: string): void;
|
|
378
457
|
getDesignBackground(): string;
|
|
379
458
|
getDesignBackgroundImage(): FabricObject | null;
|
|
459
|
+
getBackgroundImageOptions(): SerializedBackgroundImageOptions | null;
|
|
380
460
|
setBackgroundImage(url: string | null, options?: BackgroundImageOptions): Promise<void>;
|
|
381
461
|
/** Used by state restoration and advanced integrations with an existing Fabric object. */
|
|
382
|
-
setBackgroundImageObject(image: FabricObject | null, save?: boolean): void;
|
|
462
|
+
setBackgroundImageObject(image: FabricObject | null, save?: boolean, options?: SerializedBackgroundImageOptions | null): void;
|
|
383
463
|
setTransparentBackground(): void;
|
|
384
464
|
resize(width: number, height: number, options?: ResizeOptions): void;
|
|
385
465
|
/** Effective source resolution for an image at its current physical size. */
|
|
@@ -437,4 +517,77 @@ declare function deserializeEditor(editor: CanvasEditor, state: EditorState): Pr
|
|
|
437
517
|
/** Common print and digital canvas sizes. */
|
|
438
518
|
declare const CANVAS_SIZE_PRESETS: readonly CanvasSizePreset[];
|
|
439
519
|
|
|
440
|
-
|
|
520
|
+
type AnnotationPrimitive = {
|
|
521
|
+
id: string;
|
|
522
|
+
type: 'point';
|
|
523
|
+
x: number;
|
|
524
|
+
y: number;
|
|
525
|
+
label?: string;
|
|
526
|
+
} | {
|
|
527
|
+
id: string;
|
|
528
|
+
type: 'rectangle';
|
|
529
|
+
left: number;
|
|
530
|
+
top: number;
|
|
531
|
+
width: number;
|
|
532
|
+
height: number;
|
|
533
|
+
label?: string;
|
|
534
|
+
} | {
|
|
535
|
+
id: string;
|
|
536
|
+
type: 'label';
|
|
537
|
+
x: number;
|
|
538
|
+
y: number;
|
|
539
|
+
text: string;
|
|
540
|
+
} | {
|
|
541
|
+
id: string;
|
|
542
|
+
type: 'path';
|
|
543
|
+
points: Array<{
|
|
544
|
+
x: number;
|
|
545
|
+
y: number;
|
|
546
|
+
}>;
|
|
547
|
+
label?: string;
|
|
548
|
+
};
|
|
549
|
+
interface ViewportTransform {
|
|
550
|
+
zoom: number;
|
|
551
|
+
panX: number;
|
|
552
|
+
panY: number;
|
|
553
|
+
devicePixelRatio?: number;
|
|
554
|
+
}
|
|
555
|
+
/** Host-owned annotations that never enter editor layers, history, serialization, or exports. */
|
|
556
|
+
declare class AnnotationOverlay {
|
|
557
|
+
private items;
|
|
558
|
+
private transform;
|
|
559
|
+
set(annotation: AnnotationPrimitive): void;
|
|
560
|
+
remove(id: string): boolean;
|
|
561
|
+
clear(): void;
|
|
562
|
+
getAll(): AnnotationPrimitive[];
|
|
563
|
+
setTransform(transform: ViewportTransform): void;
|
|
564
|
+
documentToViewport(point: {
|
|
565
|
+
x: number;
|
|
566
|
+
y: number;
|
|
567
|
+
}): {
|
|
568
|
+
x: number;
|
|
569
|
+
y: number;
|
|
570
|
+
};
|
|
571
|
+
viewportToDocument(point: {
|
|
572
|
+
x: number;
|
|
573
|
+
y: number;
|
|
574
|
+
}): {
|
|
575
|
+
x: number;
|
|
576
|
+
y: number;
|
|
577
|
+
};
|
|
578
|
+
documentToDevice(point: {
|
|
579
|
+
x: number;
|
|
580
|
+
y: number;
|
|
581
|
+
}): {
|
|
582
|
+
x: number;
|
|
583
|
+
y: number;
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Warp RGBA pixels with an equally sized channel map. A channel value of 128
|
|
589
|
+
* is neutral; 0 and 255 move by the configured negative/positive maximum.
|
|
590
|
+
*/
|
|
591
|
+
declare function displaceRgba(source: Uint8ClampedArray, map: Uint8ClampedArray, width: number, height: number, options: Omit<MockupDisplacement, 'image'>): Uint8ClampedArray;
|
|
592
|
+
|
|
593
|
+
export { AnnotationOverlay, type AnnotationPrimitive, BackgroundImageOptions, CANVAS_SIZE_PRESETS, CanvasEditor, CanvasSizePreset, type CoverPlacement, CropController, DpiIssue, EditorConfig, EditorEvents, EditorState, EventEmitter, FileAdapter, FontDefinition, FontRegistry, HistoryManager, ImageAdjustments, ImageProvider, ImageProviderResult, ImageSearchOptions, ImageSearchResult, Layer, LayerData, LayerManager, LayerMeta, LayerType, LicenseConfig, LicenseManager, LicenseStatus, MaskBrushOptions, MaskController, type MaskPerformanceSample, MaskPoint, MaskRefinementError, type MaskRefinementErrorCode, MaskRefinementPrompt, MaskRefinementProvider, MaskRefinementResult, MockupConfig, MockupDisplacement, MockupPrintArea, NormalizedLayerPosition, PatternConfig, PatternLocks, PatternManager, PatternSourceResolver, type PngExportOptions, PositioningAdapter, PrintifyPositioning, ProjectManager, ProjectState, ResizeOptions, SemanticExportOptions, SerializedBackgroundImageOptions, SerializedLayer, ShapePlugin, SnapManager, SvgExportOptions, TemplateDefinition, type TilePlacement, Unit, UnitConverter, type ViewportTransform, applyPatternLocks, buildPatternDataURL, captureLocks, clamp, clearPatternImageCache, computeCoverPlacement, computePrintAreaClip, computeTilePositions, deserializeEditor, displaceRgba, drawTiles, escapeXml, exportDataURL, exportMockup, exportPNG, exportSVG, generateId, isCssColor, loadPatternImage, restoreLocks, round2, sanitizeSvg, serializeEditor };
|