@fieldnotes/core 0.40.0 → 0.40.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.
package/dist/index.d.cts CHANGED
@@ -1048,6 +1048,6 @@ declare class LaserTool implements Tool {
1048
1048
  private notifyOptionsChange;
1049
1049
  }
1050
1050
 
1051
- declare const VERSION = "0.40.0";
1051
+ declare const VERSION = "0.40.1";
1052
1052
 
1053
1053
  export { type ActiveFormats, type AlignEdge, type ArrowElement, 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, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportImageOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StrokeElement, type StrokePoint, type TemplateElement, 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, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
package/dist/index.d.ts CHANGED
@@ -1048,6 +1048,6 @@ declare class LaserTool implements Tool {
1048
1048
  private notifyOptionsChange;
1049
1049
  }
1050
1050
 
1051
- declare const VERSION = "0.40.0";
1051
+ declare const VERSION = "0.40.1";
1052
1052
 
1053
1053
  export { type ActiveFormats, type AlignEdge, type ArrowElement, 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, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportImageOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StrokeElement, type StrokePoint, type TemplateElement, 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, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
package/dist/index.js CHANGED
@@ -4682,6 +4682,16 @@ function renderStyledRuns(ctx, runs, startX, startY, maxWidth) {
4682
4682
  }
4683
4683
  }
4684
4684
 
4685
+ // src/canvas/text-canvas-renderer.ts
4686
+ function renderTextOnCanvas(ctx, text) {
4687
+ const pad = 2;
4688
+ ctx.save();
4689
+ ctx.fillStyle = text.color;
4690
+ const runs = parseStyledRuns(text.text ?? "", text.fontSize);
4691
+ renderStyledRuns(ctx, runs, text.position.x + pad, text.position.y + pad, text.size.w - pad * 2);
4692
+ ctx.restore();
4693
+ }
4694
+
4685
4695
  // src/canvas/export-image.ts
4686
4696
  var center = (b) => ({ x: b.x + b.w / 2, y: b.y + b.h / 2 });
4687
4697
  function getStrokeBounds(el) {
@@ -4764,30 +4774,6 @@ function computeBounds(elements, padding) {
4764
4774
  h: maxY - minY + padding * 2
4765
4775
  };
4766
4776
  }
4767
- function renderTextOnCanvas(ctx, text) {
4768
- if (!text.text) return;
4769
- ctx.save();
4770
- ctx.fillStyle = text.color;
4771
- ctx.font = `${text.fontSize}px system-ui, sans-serif`;
4772
- ctx.textBaseline = "top";
4773
- ctx.textAlign = text.textAlign;
4774
- const pad = 2;
4775
- let textX = text.position.x + pad;
4776
- if (text.textAlign === "center") {
4777
- textX = text.position.x + text.size.w / 2;
4778
- } else if (text.textAlign === "right") {
4779
- textX = text.position.x + text.size.w - pad;
4780
- }
4781
- const lineHeight = text.fontSize * 1.4;
4782
- const lines = text.text.split("\n");
4783
- for (let i = 0; i < lines.length; i++) {
4784
- const line = lines[i];
4785
- if (line !== void 0) {
4786
- ctx.fillText(line, textX, text.position.y + pad + i * lineHeight);
4787
- }
4788
- }
4789
- ctx.restore();
4790
- }
4791
4777
  function renderGridForBounds(ctx, grid, bounds) {
4792
4778
  const visibleBounds = {
4793
4779
  minX: bounds.x,
@@ -5009,28 +4995,27 @@ function emitImage(image, dataUri) {
5009
4995
  const { w, h } = image.size;
5010
4996
  return `<image href="${esc(href)}" x="${n(x)}" y="${n(y)}" width="${n(w)}" height="${n(h)}" />`;
5011
4997
  }
5012
- function emitText(text) {
4998
+ function emitText(text, rasterScale) {
5013
4999
  if (!text.text) return "";
5014
- const pad = 2;
5015
- let anchor = "start";
5016
- let textX = text.position.x + pad;
5017
- if (text.textAlign === "center") {
5018
- anchor = "middle";
5019
- textX = text.position.x + text.size.w / 2;
5020
- } else if (text.textAlign === "right") {
5021
- anchor = "end";
5022
- textX = text.position.x + text.size.w - pad;
5023
- }
5024
- const lineHeight = text.fontSize * 1.4;
5025
- const lines = text.text.split("\n");
5026
- let out = "";
5027
- for (let i = 0; i < lines.length; i++) {
5028
- const line = lines[i];
5029
- if (line === void 0) continue;
5030
- const y = text.position.y + pad + i * lineHeight;
5031
- out += `<text x="${n(textX)}" y="${n(y)}" font-family="system-ui, sans-serif" font-size="${n(text.fontSize)}" fill="${esc(text.color)}" text-anchor="${anchor}" dominant-baseline="text-before-edge">${esc(line)}</text>`;
5000
+ const { x, y } = text.position;
5001
+ const { w, h } = text.size;
5002
+ if (typeof document === "undefined") return "";
5003
+ const canvas = document.createElement("canvas");
5004
+ canvas.width = Math.max(1, Math.ceil(w * rasterScale));
5005
+ canvas.height = Math.max(1, Math.ceil(h * rasterScale));
5006
+ const ctx = canvas.getContext("2d");
5007
+ if (!ctx) return "";
5008
+ ctx.scale(rasterScale, rasterScale);
5009
+ ctx.translate(-x, -y);
5010
+ renderTextOnCanvas(ctx, text);
5011
+ let dataUri;
5012
+ try {
5013
+ dataUri = canvas.toDataURL();
5014
+ } catch {
5015
+ return "";
5032
5016
  }
5033
- return out;
5017
+ if (!dataUri || !dataUri.startsWith("data:")) return "";
5018
+ return `<image href="${esc(dataUri)}" x="${n(x)}" y="${n(y)}" width="${n(w)}" height="${n(h)}" />`;
5034
5019
  }
5035
5020
  function emitNote(note, rasterScale) {
5036
5021
  const { x, y } = note.position;
@@ -5213,7 +5198,7 @@ function emitElement(el, imageDataUris, rasterScale, firstGrid, store) {
5213
5198
  case "image":
5214
5199
  return withRotationSvg(el, emitImage(el, imageDataUris.get(el.id)));
5215
5200
  case "text":
5216
- return withRotationSvg(el, emitText(el));
5201
+ return withRotationSvg(el, emitText(el, rasterScale));
5217
5202
  case "note":
5218
5203
  return withRotationSvg(el, emitNote(el, rasterScale));
5219
5204
  case "template":
@@ -5676,10 +5661,9 @@ var DomNodeManager = class {
5676
5661
  cursor: "default",
5677
5662
  userSelect: "none",
5678
5663
  wordWrap: "break-word",
5679
- whiteSpace: "pre-wrap",
5680
5664
  lineHeight: "1.4"
5681
5665
  });
5682
- node.textContent = element.text || "";
5666
+ node.innerHTML = element.text || "";
5683
5667
  const detector = new DoubleTapDetector();
5684
5668
  node.addEventListener("pointerup", (e) => {
5685
5669
  if (detector.feed(e)) {
@@ -5690,8 +5674,9 @@ var DomNodeManager = class {
5690
5674
  });
5691
5675
  }
5692
5676
  if (!this.isEditingElement(element.id)) {
5693
- if (node.textContent !== element.text) {
5694
- node.textContent = element.text || "";
5677
+ const text = element.text || "";
5678
+ if (node.innerHTML !== text) {
5679
+ node.innerHTML = text;
5695
5680
  }
5696
5681
  Object.assign(node.style, {
5697
5682
  fontSize: `${element.fontSize}px`,
@@ -9669,7 +9654,7 @@ var LaserTool = class {
9669
9654
  };
9670
9655
 
9671
9656
  // src/index.ts
9672
- var VERSION = "0.40.0";
9657
+ var VERSION = "0.40.1";
9673
9658
  export {
9674
9659
  ArrowTool,
9675
9660
  AutoSave,