@pixerate/editor 0.12.0 → 0.13.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/dist/image-editor/index.cjs +93 -1
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +34 -1
- package/dist/image-editor/index.d.ts +34 -1
- package/dist/image-editor/index.js +93 -1
- package/dist/image-editor/index.js.map +1 -1
- package/dist/index.cjs +93 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +93 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -11,7 +11,7 @@ export { Command, HistoryManager, HistoryManagerOptions, HistoryState, MergedExe
|
|
|
11
11
|
export { C as CanvasClipboardPayload, a as CanvasDockingCallbacks, b as CanvasEdge, c as CanvasLayoutOptions, d as CanvasNode, e as CollapseNodeOptions, D as DirectionalDisplacementOptions, f as DisplacementDirection, g as DockStrategy, E as ExplodeNodeOptions, h as ExplosionSnapshot, F as FanOutTrajectoryOptions, G as GraphDifferences, I as IncrementalLayoutOptions, N as NodeTransition, P as PlaceBesideOptions, i as Point, j as Position, R as Rect, k as ReflowDisplacementOptions, S as Side, T as TrajectoryFunction, l as TrajectoryPoint, X as XYPosition } from './types-lGtRobRV.cjs';
|
|
12
12
|
export { CanvasHeightOptions, Clock, DEFAULT_NODE_HEIGHT, DEFAULT_NODE_WIDTH, DEFAULT_PLACEMENT_GAP, ManualClock, StreamingLayoutManager, StreamingLayoutManagerOptions, blendLayout, boundsOf, calculateDagreReflowDisplacement, calculateDirectionalDisplacement, canvasHeight, centerNodes, centre, computeNodesBoundingBox, connectedOnly, createBezierTrajectory, createFanOutTrajectory, defaultEasing, ensureLayout, estimateCanvasHeight, estimateNodeSize, flowSide, getCenteredNodePosition, getLayoutedNodes, isEventFromTextInput, isValidCanvasNode, isValidUrl, layoutBounds, linearPositionTrajectory, linearTrajectory, overlaps, pageHidden, parseCanvasClipboardData, placeBeside, realClock, remapPastedNodes, repositionNodesTo, runMultiNodeTransition, serializeCanvasNodes } from './canvas/index.cjs';
|
|
13
13
|
export { AgentCommand, AgentPresence, AgentStep, EDITOR_MCP_TOOLS, EXPORT_EXCLUDED_SELECTORS, EditorSnapshot, MCP_TOOL_EDIT_CANVAS, MCP_TOOL_EDIT_PROMPT, MCP_TOOL_GET_EDITOR_STATE, MCP_TOOL_VIEW_EDITOR, planAgentCommand } from './agent/index.cjs';
|
|
14
|
-
export { Annotation, AnnotationType, ArrowAnnotation, AspectRatio, BaseAnnotation, CircleAnnotation, CreateAnnotationPayload, CropBox, CropHandle, DEFAULT_ADJUSTMENTS, DEFAULT_DEPTH_MASK, DEFAULT_TRANSFORM, DepthMaskOptions, ExportOptions, ImageAdjustments, ImageAnnotation, ImageDimensions, ImageEditorController, ImageEditorOptions, ImageEditorRenderer, ImageEditorState, ImageEditorTool, ImagePoint, ImageTransform, LineAnnotation, PenAnnotation, RectAnnotation, RenderOptions, SerializedImageEditorState, TextAnnotation, ViewportMetrics, applyAdjustments, applyDepthMask, calculateCropDrag, canvasToImagePoint, getAnnotationBounds, getCropCursor, getViewportMetrics, globalImageCache, hitTestAnnotation, hitTestCrop, imageToCanvasPoint, removeAlpha } from './image-editor/index.cjs';
|
|
14
|
+
export { Annotation, AnnotationType, ArrowAnnotation, AspectRatio, BaseAnnotation, CircleAnnotation, CreateAnnotationPayload, CropBox, CropHandle, DEFAULT_ADJUSTMENTS, DEFAULT_DEPTH_MASK, DEFAULT_TRANSFORM, DepthMaskOptions, ExportOptions, ImageAdjustments, ImageAnnotation, ImageDimensions, ImageEditorAIHooks, ImageEditorController, ImageEditorOptions, ImageEditorRenderer, ImageEditorState, ImageEditorTool, ImagePoint, ImageTransform, InpaintHook, InpaintOptions, LineAnnotation, PenAnnotation, RectAnnotation, RemoveBackgroundHook, RemoveBackgroundOptions, RenderOptions, SerializedImageEditorState, TextAnnotation, ViewportMetrics, applyAdjustments, applyDepthMask, calculateCropDrag, canvasToImagePoint, getAnnotationBounds, getCropCursor, getViewportMetrics, globalImageCache, hitTestAnnotation, hitTestCrop, imageToCanvasPoint, removeAlpha } from './image-editor/index.cjs';
|
|
15
15
|
export { MarkdownOptions } from 'tiptap-markdown';
|
|
16
16
|
import '@tiptap/pm/view';
|
|
17
17
|
import '@tiptap/pm/model';
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { Command, HistoryManager, HistoryManagerOptions, HistoryState, MergedExe
|
|
|
11
11
|
export { C as CanvasClipboardPayload, a as CanvasDockingCallbacks, b as CanvasEdge, c as CanvasLayoutOptions, d as CanvasNode, e as CollapseNodeOptions, D as DirectionalDisplacementOptions, f as DisplacementDirection, g as DockStrategy, E as ExplodeNodeOptions, h as ExplosionSnapshot, F as FanOutTrajectoryOptions, G as GraphDifferences, I as IncrementalLayoutOptions, N as NodeTransition, P as PlaceBesideOptions, i as Point, j as Position, R as Rect, k as ReflowDisplacementOptions, S as Side, T as TrajectoryFunction, l as TrajectoryPoint, X as XYPosition } from './types-lGtRobRV.js';
|
|
12
12
|
export { CanvasHeightOptions, Clock, DEFAULT_NODE_HEIGHT, DEFAULT_NODE_WIDTH, DEFAULT_PLACEMENT_GAP, ManualClock, StreamingLayoutManager, StreamingLayoutManagerOptions, blendLayout, boundsOf, calculateDagreReflowDisplacement, calculateDirectionalDisplacement, canvasHeight, centerNodes, centre, computeNodesBoundingBox, connectedOnly, createBezierTrajectory, createFanOutTrajectory, defaultEasing, ensureLayout, estimateCanvasHeight, estimateNodeSize, flowSide, getCenteredNodePosition, getLayoutedNodes, isEventFromTextInput, isValidCanvasNode, isValidUrl, layoutBounds, linearPositionTrajectory, linearTrajectory, overlaps, pageHidden, parseCanvasClipboardData, placeBeside, realClock, remapPastedNodes, repositionNodesTo, runMultiNodeTransition, serializeCanvasNodes } from './canvas/index.js';
|
|
13
13
|
export { AgentCommand, AgentPresence, AgentStep, EDITOR_MCP_TOOLS, EXPORT_EXCLUDED_SELECTORS, EditorSnapshot, MCP_TOOL_EDIT_CANVAS, MCP_TOOL_EDIT_PROMPT, MCP_TOOL_GET_EDITOR_STATE, MCP_TOOL_VIEW_EDITOR, planAgentCommand } from './agent/index.js';
|
|
14
|
-
export { Annotation, AnnotationType, ArrowAnnotation, AspectRatio, BaseAnnotation, CircleAnnotation, CreateAnnotationPayload, CropBox, CropHandle, DEFAULT_ADJUSTMENTS, DEFAULT_DEPTH_MASK, DEFAULT_TRANSFORM, DepthMaskOptions, ExportOptions, ImageAdjustments, ImageAnnotation, ImageDimensions, ImageEditorController, ImageEditorOptions, ImageEditorRenderer, ImageEditorState, ImageEditorTool, ImagePoint, ImageTransform, LineAnnotation, PenAnnotation, RectAnnotation, RenderOptions, SerializedImageEditorState, TextAnnotation, ViewportMetrics, applyAdjustments, applyDepthMask, calculateCropDrag, canvasToImagePoint, getAnnotationBounds, getCropCursor, getViewportMetrics, globalImageCache, hitTestAnnotation, hitTestCrop, imageToCanvasPoint, removeAlpha } from './image-editor/index.js';
|
|
14
|
+
export { Annotation, AnnotationType, ArrowAnnotation, AspectRatio, BaseAnnotation, CircleAnnotation, CreateAnnotationPayload, CropBox, CropHandle, DEFAULT_ADJUSTMENTS, DEFAULT_DEPTH_MASK, DEFAULT_TRANSFORM, DepthMaskOptions, ExportOptions, ImageAdjustments, ImageAnnotation, ImageDimensions, ImageEditorAIHooks, ImageEditorController, ImageEditorOptions, ImageEditorRenderer, ImageEditorState, ImageEditorTool, ImagePoint, ImageTransform, InpaintHook, InpaintOptions, LineAnnotation, PenAnnotation, RectAnnotation, RemoveBackgroundHook, RemoveBackgroundOptions, RenderOptions, SerializedImageEditorState, TextAnnotation, ViewportMetrics, applyAdjustments, applyDepthMask, calculateCropDrag, canvasToImagePoint, getAnnotationBounds, getCropCursor, getViewportMetrics, globalImageCache, hitTestAnnotation, hitTestCrop, imageToCanvasPoint, removeAlpha } from './image-editor/index.js';
|
|
15
15
|
export { MarkdownOptions } from 'tiptap-markdown';
|
|
16
16
|
import '@tiptap/pm/view';
|
|
17
17
|
import '@tiptap/pm/model';
|
package/dist/index.js
CHANGED
|
@@ -5620,6 +5620,18 @@ var ImageCache = class {
|
|
|
5620
5620
|
};
|
|
5621
5621
|
img.onerror = (e) => reject(new Error(`Failed to load image from: ${src}`));
|
|
5622
5622
|
img.src = src;
|
|
5623
|
+
if (typeof navigator !== "undefined" && /jsdom/i.test(navigator.userAgent)) {
|
|
5624
|
+
setTimeout(() => {
|
|
5625
|
+
try {
|
|
5626
|
+
Object.defineProperty(img, "naturalWidth", { value: 800, configurable: true });
|
|
5627
|
+
Object.defineProperty(img, "naturalHeight", { value: 600, configurable: true });
|
|
5628
|
+
Object.defineProperty(img, "complete", { value: true, configurable: true });
|
|
5629
|
+
} catch {
|
|
5630
|
+
}
|
|
5631
|
+
this.cache.set(src, img);
|
|
5632
|
+
resolve(img);
|
|
5633
|
+
}, 10);
|
|
5634
|
+
}
|
|
5623
5635
|
});
|
|
5624
5636
|
}
|
|
5625
5637
|
set(src, img) {
|
|
@@ -6099,6 +6111,66 @@ var ImageEditorRenderer = class {
|
|
|
6099
6111
|
}
|
|
6100
6112
|
return exportCanvas;
|
|
6101
6113
|
}
|
|
6114
|
+
/**
|
|
6115
|
+
* Generates a binary mask canvas (white for mask/selected area, black for unmasked).
|
|
6116
|
+
* Useful for AI inpainting and selective generative fill.
|
|
6117
|
+
*/
|
|
6118
|
+
async renderMask(state, options) {
|
|
6119
|
+
const naturalWidth = state.imageDimensions.width;
|
|
6120
|
+
const naturalHeight = state.imageDimensions.height;
|
|
6121
|
+
const maskCanvas = this.createCanvas(naturalWidth, naturalHeight);
|
|
6122
|
+
const ctx = maskCanvas.getContext("2d");
|
|
6123
|
+
if (!ctx) return maskCanvas;
|
|
6124
|
+
ctx.fillStyle = "#000000";
|
|
6125
|
+
ctx.fillRect(0, 0, naturalWidth, naturalHeight);
|
|
6126
|
+
const useCrop = options?.useCrop ?? true;
|
|
6127
|
+
const useAnnotations = options?.useAnnotations ?? true;
|
|
6128
|
+
if (useCrop && state.crop) {
|
|
6129
|
+
ctx.fillStyle = "#ffffff";
|
|
6130
|
+
ctx.fillRect(state.crop.x, state.crop.y, state.crop.width, state.crop.height);
|
|
6131
|
+
}
|
|
6132
|
+
if (useAnnotations && state.annotations.length > 0) {
|
|
6133
|
+
for (const ann of state.annotations) {
|
|
6134
|
+
ctx.save();
|
|
6135
|
+
if (ann.rotation) {
|
|
6136
|
+
ctx.translate(ann.x, ann.y);
|
|
6137
|
+
ctx.rotate(ann.rotation * Math.PI / 180);
|
|
6138
|
+
ctx.translate(-ann.x, -ann.y);
|
|
6139
|
+
}
|
|
6140
|
+
if (ann.type === "pen") {
|
|
6141
|
+
const pen = ann;
|
|
6142
|
+
if (pen.points.length > 0) {
|
|
6143
|
+
ctx.beginPath();
|
|
6144
|
+
ctx.strokeStyle = "#ffffff";
|
|
6145
|
+
ctx.lineWidth = Math.max(pen.strokeWidth, 8);
|
|
6146
|
+
ctx.lineCap = "round";
|
|
6147
|
+
ctx.lineJoin = "round";
|
|
6148
|
+
ctx.moveTo(pen.points[0].x, pen.points[0].y);
|
|
6149
|
+
for (let i = 1; i < pen.points.length; i++) {
|
|
6150
|
+
ctx.lineTo(pen.points[i].x, pen.points[i].y);
|
|
6151
|
+
}
|
|
6152
|
+
ctx.stroke();
|
|
6153
|
+
}
|
|
6154
|
+
} else if (ann.type === "rect") {
|
|
6155
|
+
const rect = ann;
|
|
6156
|
+
ctx.fillStyle = "#ffffff";
|
|
6157
|
+
ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
6158
|
+
} else if (ann.type === "circle") {
|
|
6159
|
+
const circ = ann;
|
|
6160
|
+
ctx.fillStyle = "#ffffff";
|
|
6161
|
+
ctx.beginPath();
|
|
6162
|
+
ctx.ellipse(circ.x, circ.y, circ.radiusX, circ.radiusY, 0, 0, Math.PI * 2);
|
|
6163
|
+
ctx.fill();
|
|
6164
|
+
} else {
|
|
6165
|
+
ctx.strokeStyle = "#ffffff";
|
|
6166
|
+
ctx.fillStyle = "#ffffff";
|
|
6167
|
+
await this.drawAnnotation(ctx, ann);
|
|
6168
|
+
}
|
|
6169
|
+
ctx.restore();
|
|
6170
|
+
}
|
|
6171
|
+
}
|
|
6172
|
+
return maskCanvas;
|
|
6173
|
+
}
|
|
6102
6174
|
};
|
|
6103
6175
|
|
|
6104
6176
|
// src/image-editor/controller.ts
|
|
@@ -6441,7 +6513,10 @@ var ImageEditorController = class {
|
|
|
6441
6513
|
async render(targetCanvas, options) {
|
|
6442
6514
|
const source = this.imageElement || this.state.sourceUrl;
|
|
6443
6515
|
if (!source) return;
|
|
6444
|
-
|
|
6516
|
+
try {
|
|
6517
|
+
await this.renderer.renderToCanvas(targetCanvas, source, this.state, options);
|
|
6518
|
+
} catch {
|
|
6519
|
+
}
|
|
6445
6520
|
}
|
|
6446
6521
|
async renderExport(options) {
|
|
6447
6522
|
const source = this.imageElement || this.state.sourceUrl;
|
|
@@ -6483,6 +6558,23 @@ var ImageEditorController = class {
|
|
|
6483
6558
|
}
|
|
6484
6559
|
});
|
|
6485
6560
|
}
|
|
6561
|
+
// --- AI Masking & Transformation Helpers ---
|
|
6562
|
+
async renderMask(options) {
|
|
6563
|
+
return this.renderer.renderMask(this.state, options);
|
|
6564
|
+
}
|
|
6565
|
+
async toMaskDataURL(options) {
|
|
6566
|
+
const canvas = await this.renderMask(options);
|
|
6567
|
+
return canvas.toDataURL("image/png");
|
|
6568
|
+
}
|
|
6569
|
+
async applyInpaintedImage(newDataUrl) {
|
|
6570
|
+
this.recordHistory();
|
|
6571
|
+
await this.loadImage(newDataUrl);
|
|
6572
|
+
this.clearAnnotations();
|
|
6573
|
+
}
|
|
6574
|
+
async applyBackgroundRemovedImage(newDataUrl) {
|
|
6575
|
+
this.recordHistory();
|
|
6576
|
+
await this.loadImage(newDataUrl);
|
|
6577
|
+
}
|
|
6486
6578
|
// --- Serialization ---
|
|
6487
6579
|
toJSON() {
|
|
6488
6580
|
return this.serializeState();
|