@fieldnotes/core 0.51.0 → 0.52.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/README.md +24 -3
- package/dist/index.cjs +150 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -4
- package/dist/index.d.ts +21 -4
- package/dist/index.js +150 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -447,7 +447,24 @@ declare class HistoryStack {
|
|
|
447
447
|
private notifyChange;
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
|
|
450
|
+
type HtmlExportRenderer = (element: HtmlElement) => CanvasImageSource | null | Promise<CanvasImageSource | null>;
|
|
451
|
+
type HtmlExportErrorReason = 'unsupported' | 'timeout' | 'render' | 'encode';
|
|
452
|
+
interface HtmlExportError {
|
|
453
|
+
elementId: string;
|
|
454
|
+
htmlType?: string;
|
|
455
|
+
reason: HtmlExportErrorReason;
|
|
456
|
+
cause?: unknown;
|
|
457
|
+
}
|
|
458
|
+
interface HtmlExportOptions {
|
|
459
|
+
/** Converts an application-owned HTML embed into a ready canvas image source. */
|
|
460
|
+
renderHtml?: HtmlExportRenderer;
|
|
461
|
+
/** Maximum wait for each HTML renderer. Defaults to 10 seconds. */
|
|
462
|
+
htmlTimeoutMs?: number;
|
|
463
|
+
/** Called when an HTML embed cannot be rendered or encoded. The export continues. */
|
|
464
|
+
onHtmlError?: (error: HtmlExportError) => void;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
interface ExportImageOptions extends ExportResourceOptions, HtmlExportOptions {
|
|
451
468
|
scale?: number;
|
|
452
469
|
padding?: number;
|
|
453
470
|
background?: string;
|
|
@@ -472,7 +489,7 @@ interface ExportResourceOptions {
|
|
|
472
489
|
}
|
|
473
490
|
declare function exportImage(store: ElementStore, options?: ExportImageOptions, layerManager?: LayerManager): Promise<Blob | null>;
|
|
474
491
|
|
|
475
|
-
interface ExportSvgOptions extends ExportResourceOptions {
|
|
492
|
+
interface ExportSvgOptions extends ExportResourceOptions, HtmlExportOptions {
|
|
476
493
|
padding?: number;
|
|
477
494
|
background?: string;
|
|
478
495
|
filter?: (el: CanvasElement) => boolean;
|
|
@@ -1140,6 +1157,6 @@ declare class LaserTool implements Tool {
|
|
|
1140
1157
|
private notifyOptionsChange;
|
|
1141
1158
|
}
|
|
1142
1159
|
|
|
1143
|
-
declare const VERSION = "0.
|
|
1160
|
+
declare const VERSION = "0.52.0";
|
|
1144
1161
|
|
|
1145
|
-
export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, LocalStorageAdapter, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, type RotateDirection, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, boundsIntersect, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
|
|
1162
|
+
export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type HtmlExportError, type HtmlExportErrorReason, type HtmlExportOptions, type HtmlExportRenderer, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, LocalStorageAdapter, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, type RotateDirection, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, boundsIntersect, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
|
package/dist/index.d.ts
CHANGED
|
@@ -447,7 +447,24 @@ declare class HistoryStack {
|
|
|
447
447
|
private notifyChange;
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
|
|
450
|
+
type HtmlExportRenderer = (element: HtmlElement) => CanvasImageSource | null | Promise<CanvasImageSource | null>;
|
|
451
|
+
type HtmlExportErrorReason = 'unsupported' | 'timeout' | 'render' | 'encode';
|
|
452
|
+
interface HtmlExportError {
|
|
453
|
+
elementId: string;
|
|
454
|
+
htmlType?: string;
|
|
455
|
+
reason: HtmlExportErrorReason;
|
|
456
|
+
cause?: unknown;
|
|
457
|
+
}
|
|
458
|
+
interface HtmlExportOptions {
|
|
459
|
+
/** Converts an application-owned HTML embed into a ready canvas image source. */
|
|
460
|
+
renderHtml?: HtmlExportRenderer;
|
|
461
|
+
/** Maximum wait for each HTML renderer. Defaults to 10 seconds. */
|
|
462
|
+
htmlTimeoutMs?: number;
|
|
463
|
+
/** Called when an HTML embed cannot be rendered or encoded. The export continues. */
|
|
464
|
+
onHtmlError?: (error: HtmlExportError) => void;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
interface ExportImageOptions extends ExportResourceOptions, HtmlExportOptions {
|
|
451
468
|
scale?: number;
|
|
452
469
|
padding?: number;
|
|
453
470
|
background?: string;
|
|
@@ -472,7 +489,7 @@ interface ExportResourceOptions {
|
|
|
472
489
|
}
|
|
473
490
|
declare function exportImage(store: ElementStore, options?: ExportImageOptions, layerManager?: LayerManager): Promise<Blob | null>;
|
|
474
491
|
|
|
475
|
-
interface ExportSvgOptions extends ExportResourceOptions {
|
|
492
|
+
interface ExportSvgOptions extends ExportResourceOptions, HtmlExportOptions {
|
|
476
493
|
padding?: number;
|
|
477
494
|
background?: string;
|
|
478
495
|
filter?: (el: CanvasElement) => boolean;
|
|
@@ -1140,6 +1157,6 @@ declare class LaserTool implements Tool {
|
|
|
1140
1157
|
private notifyOptionsChange;
|
|
1141
1158
|
}
|
|
1142
1159
|
|
|
1143
|
-
declare const VERSION = "0.
|
|
1160
|
+
declare const VERSION = "0.52.0";
|
|
1144
1161
|
|
|
1145
|
-
export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, LocalStorageAdapter, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, type RotateDirection, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, boundsIntersect, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
|
|
1162
|
+
export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, type DistributeAxis, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportAssetError, type ExportAssetErrorReason, type ExportImageOptions, type ExportResourceOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type HtmlExportError, type HtmlExportErrorReason, type HtmlExportOptions, type HtmlExportRenderer, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, LocalStorageAdapter, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, type RotateDirection, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, boundsIntersect, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportSvg, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
|
package/dist/index.js
CHANGED
|
@@ -5355,6 +5355,67 @@ function renderTextOnCanvas(ctx, text) {
|
|
|
5355
5355
|
ctx.restore();
|
|
5356
5356
|
}
|
|
5357
5357
|
|
|
5358
|
+
// src/canvas/html-export.ts
|
|
5359
|
+
var DEFAULT_HTML_TIMEOUT_MS = 1e4;
|
|
5360
|
+
var TIMEOUT = /* @__PURE__ */ Symbol("html-export-timeout");
|
|
5361
|
+
function validateHtmlExportOptions(options) {
|
|
5362
|
+
const timeoutMs = options.htmlTimeoutMs ?? DEFAULT_HTML_TIMEOUT_MS;
|
|
5363
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
5364
|
+
throw new RangeError("htmlTimeoutMs must be a finite number greater than 0");
|
|
5365
|
+
}
|
|
5366
|
+
return timeoutMs;
|
|
5367
|
+
}
|
|
5368
|
+
async function renderHtmlElements(elements, options) {
|
|
5369
|
+
const timeoutMs = validateHtmlExportOptions(options);
|
|
5370
|
+
const sources = /* @__PURE__ */ new Map();
|
|
5371
|
+
await Promise.all(
|
|
5372
|
+
elements.map(async (element) => {
|
|
5373
|
+
if (!options.renderHtml) {
|
|
5374
|
+
options.onHtmlError?.({
|
|
5375
|
+
elementId: element.id,
|
|
5376
|
+
htmlType: element.htmlType,
|
|
5377
|
+
reason: "unsupported"
|
|
5378
|
+
});
|
|
5379
|
+
return;
|
|
5380
|
+
}
|
|
5381
|
+
let timer;
|
|
5382
|
+
try {
|
|
5383
|
+
const timeout = new Promise((resolve) => {
|
|
5384
|
+
timer = setTimeout(() => resolve(TIMEOUT), timeoutMs);
|
|
5385
|
+
});
|
|
5386
|
+
const result = await Promise.race([Promise.resolve(options.renderHtml(element)), timeout]);
|
|
5387
|
+
if (result === TIMEOUT) {
|
|
5388
|
+
options.onHtmlError?.({
|
|
5389
|
+
elementId: element.id,
|
|
5390
|
+
htmlType: element.htmlType,
|
|
5391
|
+
reason: "timeout"
|
|
5392
|
+
});
|
|
5393
|
+
return;
|
|
5394
|
+
}
|
|
5395
|
+
if (!result) {
|
|
5396
|
+
options.onHtmlError?.({
|
|
5397
|
+
elementId: element.id,
|
|
5398
|
+
htmlType: element.htmlType,
|
|
5399
|
+
reason: "render"
|
|
5400
|
+
});
|
|
5401
|
+
return;
|
|
5402
|
+
}
|
|
5403
|
+
sources.set(element.id, result);
|
|
5404
|
+
} catch (cause) {
|
|
5405
|
+
options.onHtmlError?.({
|
|
5406
|
+
elementId: element.id,
|
|
5407
|
+
htmlType: element.htmlType,
|
|
5408
|
+
reason: "render",
|
|
5409
|
+
cause
|
|
5410
|
+
});
|
|
5411
|
+
} finally {
|
|
5412
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
5413
|
+
}
|
|
5414
|
+
})
|
|
5415
|
+
);
|
|
5416
|
+
return sources;
|
|
5417
|
+
}
|
|
5418
|
+
|
|
5358
5419
|
// src/canvas/export-image.ts
|
|
5359
5420
|
var DEFAULT_IMAGE_TIMEOUT_MS = 1e4;
|
|
5360
5421
|
var DEFAULT_MAX_DIMENSION = 16384;
|
|
@@ -5559,6 +5620,7 @@ async function exportImage(store, options = {}, layerManager) {
|
|
|
5559
5620
|
const scale = positiveOption(options.scale, 2, "scale");
|
|
5560
5621
|
const padding = nonNegativeOption(options.padding, 0, "padding");
|
|
5561
5622
|
validateExportResourceOptions(options);
|
|
5623
|
+
validateHtmlExportOptions(options);
|
|
5562
5624
|
const background = options.background ?? "#ffffff";
|
|
5563
5625
|
const filter = options.filter;
|
|
5564
5626
|
const allElements = store.getAll();
|
|
@@ -5572,6 +5634,8 @@ async function exportImage(store, options = {}, layerManager) {
|
|
|
5572
5634
|
const height = Math.ceil(bounds.h * scale);
|
|
5573
5635
|
assertExportSize(width, height, options);
|
|
5574
5636
|
const imageCache = await loadImages(visibleElements, options);
|
|
5637
|
+
const htmlElements = visibleElements.filter((el) => el.type === "html");
|
|
5638
|
+
const htmlSources = await renderHtmlElements(htmlElements, options);
|
|
5575
5639
|
const canvas = document.createElement("canvas");
|
|
5576
5640
|
canvas.width = width;
|
|
5577
5641
|
canvas.height = height;
|
|
@@ -5596,6 +5660,24 @@ async function exportImage(store, options = {}, layerManager) {
|
|
|
5596
5660
|
return;
|
|
5597
5661
|
}
|
|
5598
5662
|
if (el.type === "html") {
|
|
5663
|
+
const source = htmlSources.get(el.id);
|
|
5664
|
+
if (!source) return;
|
|
5665
|
+
const b = getElementBounds(el);
|
|
5666
|
+
try {
|
|
5667
|
+
withRotation(
|
|
5668
|
+
target,
|
|
5669
|
+
el,
|
|
5670
|
+
b ? center(b) : el.position,
|
|
5671
|
+
() => target.drawImage(source, el.position.x, el.position.y, el.size.w, el.size.h)
|
|
5672
|
+
);
|
|
5673
|
+
} catch (cause) {
|
|
5674
|
+
options.onHtmlError?.({
|
|
5675
|
+
elementId: el.id,
|
|
5676
|
+
htmlType: el.htmlType,
|
|
5677
|
+
reason: "render",
|
|
5678
|
+
cause
|
|
5679
|
+
});
|
|
5680
|
+
}
|
|
5599
5681
|
return;
|
|
5600
5682
|
}
|
|
5601
5683
|
if (el.type === "image") {
|
|
@@ -5751,7 +5833,7 @@ function emitArrow(arrow, store) {
|
|
|
5751
5833
|
return out;
|
|
5752
5834
|
}
|
|
5753
5835
|
function emitImage(image, dataUri) {
|
|
5754
|
-
const href = dataUri ?? image.src;
|
|
5836
|
+
const href = dataUri ?? ("src" in image ? image.src : "");
|
|
5755
5837
|
if (!href) return "";
|
|
5756
5838
|
const { x, y } = image.position;
|
|
5757
5839
|
const { w, h } = image.size;
|
|
@@ -5955,6 +6037,7 @@ async function exportSvg(store, options = {}, layerManager) {
|
|
|
5955
6037
|
const padding = nonNegativeOption(options.padding, 0, "padding");
|
|
5956
6038
|
const rasterScale = positiveOption(options.rasterScale, 2, "rasterScale");
|
|
5957
6039
|
validateExportResourceOptions(options);
|
|
6040
|
+
validateHtmlExportOptions(options);
|
|
5958
6041
|
const filter = options.filter;
|
|
5959
6042
|
const allElements = store.getAll();
|
|
5960
6043
|
let visibleElements = layerManager ? allElements.filter((el) => layerManager.isLayerVisible(el.layerId)) : allElements;
|
|
@@ -5969,6 +6052,9 @@ async function exportSvg(store, options = {}, layerManager) {
|
|
|
5969
6052
|
);
|
|
5970
6053
|
const imageCache = await loadImages(remoteImages, options);
|
|
5971
6054
|
const imageDataUris = encodeImages(visibleElements, imageCache, rasterScale, options);
|
|
6055
|
+
const htmlElements = visibleElements.filter((el) => el.type === "html");
|
|
6056
|
+
const htmlSources = await renderHtmlElements(htmlElements, options);
|
|
6057
|
+
const htmlDataUris = encodeHtmlElements(htmlElements, htmlSources, rasterScale, options);
|
|
5972
6058
|
const grids = visibleElements.filter((el) => el.type === "grid");
|
|
5973
6059
|
const firstGrid = grids[0];
|
|
5974
6060
|
let body = "";
|
|
@@ -5977,7 +6063,15 @@ async function exportSvg(store, options = {}, layerManager) {
|
|
|
5977
6063
|
}
|
|
5978
6064
|
const layerBodies = /* @__PURE__ */ new Map();
|
|
5979
6065
|
for (const el of visibleElements) {
|
|
5980
|
-
const emitted = emitElement(
|
|
6066
|
+
const emitted = emitElement(
|
|
6067
|
+
el,
|
|
6068
|
+
imageDataUris,
|
|
6069
|
+
htmlDataUris,
|
|
6070
|
+
rasterScale,
|
|
6071
|
+
firstGrid,
|
|
6072
|
+
store,
|
|
6073
|
+
options
|
|
6074
|
+
);
|
|
5981
6075
|
layerBodies.set(el.layerId, (layerBodies.get(el.layerId) ?? "") + emitted);
|
|
5982
6076
|
}
|
|
5983
6077
|
for (const [layerId, emitted] of layerBodies) {
|
|
@@ -5991,7 +6085,7 @@ async function exportSvg(store, options = {}, layerManager) {
|
|
|
5991
6085
|
}
|
|
5992
6086
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${n(bounds.w)}" height="${n(bounds.h)}" viewBox="${n(bounds.x)} ${n(bounds.y)} ${n(bounds.w)} ${n(bounds.h)}">${body}</svg>`;
|
|
5993
6087
|
}
|
|
5994
|
-
function emitElement(el, imageDataUris, rasterScale, firstGrid, store, resourceOptions) {
|
|
6088
|
+
function emitElement(el, imageDataUris, htmlDataUris, rasterScale, firstGrid, store, resourceOptions) {
|
|
5995
6089
|
switch (el.type) {
|
|
5996
6090
|
case "stroke":
|
|
5997
6091
|
return withRotationSvg(el, emitStroke(el));
|
|
@@ -6010,11 +6104,62 @@ function emitElement(el, imageDataUris, rasterScale, firstGrid, store, resourceO
|
|
|
6010
6104
|
case "grid":
|
|
6011
6105
|
return "";
|
|
6012
6106
|
case "html":
|
|
6013
|
-
return
|
|
6107
|
+
return withRotationSvg(el, emitImage(el, htmlDataUris.get(el.id)));
|
|
6014
6108
|
default:
|
|
6015
6109
|
return "";
|
|
6016
6110
|
}
|
|
6017
6111
|
}
|
|
6112
|
+
function encodeHtmlElements(elements, sources, rasterScale, options) {
|
|
6113
|
+
const encoded = /* @__PURE__ */ new Map();
|
|
6114
|
+
for (const element of elements) {
|
|
6115
|
+
const source = sources.get(element.id);
|
|
6116
|
+
if (!source) continue;
|
|
6117
|
+
const width = Math.max(1, Math.ceil(element.size.w * rasterScale));
|
|
6118
|
+
const height = Math.max(1, Math.ceil(element.size.h * rasterScale));
|
|
6119
|
+
assertExportSize(width, height, options);
|
|
6120
|
+
if (typeof document === "undefined") {
|
|
6121
|
+
options.onHtmlError?.({
|
|
6122
|
+
elementId: element.id,
|
|
6123
|
+
htmlType: element.htmlType,
|
|
6124
|
+
reason: "encode"
|
|
6125
|
+
});
|
|
6126
|
+
continue;
|
|
6127
|
+
}
|
|
6128
|
+
const canvas = document.createElement("canvas");
|
|
6129
|
+
canvas.width = width;
|
|
6130
|
+
canvas.height = height;
|
|
6131
|
+
const ctx = canvas.getContext("2d");
|
|
6132
|
+
if (!ctx) {
|
|
6133
|
+
options.onHtmlError?.({
|
|
6134
|
+
elementId: element.id,
|
|
6135
|
+
htmlType: element.htmlType,
|
|
6136
|
+
reason: "encode"
|
|
6137
|
+
});
|
|
6138
|
+
continue;
|
|
6139
|
+
}
|
|
6140
|
+
try {
|
|
6141
|
+
ctx.drawImage(source, 0, 0, width, height);
|
|
6142
|
+
const dataUri = canvas.toDataURL();
|
|
6143
|
+
if (dataUri.startsWith("data:")) {
|
|
6144
|
+
encoded.set(element.id, dataUri);
|
|
6145
|
+
} else {
|
|
6146
|
+
options.onHtmlError?.({
|
|
6147
|
+
elementId: element.id,
|
|
6148
|
+
htmlType: element.htmlType,
|
|
6149
|
+
reason: "encode"
|
|
6150
|
+
});
|
|
6151
|
+
}
|
|
6152
|
+
} catch (cause) {
|
|
6153
|
+
options.onHtmlError?.({
|
|
6154
|
+
elementId: element.id,
|
|
6155
|
+
htmlType: element.htmlType,
|
|
6156
|
+
reason: "encode",
|
|
6157
|
+
cause
|
|
6158
|
+
});
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
return encoded;
|
|
6162
|
+
}
|
|
6018
6163
|
function encodeImages(elements, imageCache, rasterScale, resourceOptions) {
|
|
6019
6164
|
const out = /* @__PURE__ */ new Map();
|
|
6020
6165
|
for (const el of elements) {
|
|
@@ -10815,7 +10960,7 @@ var LaserTool = class {
|
|
|
10815
10960
|
};
|
|
10816
10961
|
|
|
10817
10962
|
// src/index.ts
|
|
10818
|
-
var VERSION = "0.
|
|
10963
|
+
var VERSION = "0.52.0";
|
|
10819
10964
|
export {
|
|
10820
10965
|
ArrowTool,
|
|
10821
10966
|
AutoSave,
|