@canvas-harness/core 0.0.5 → 0.1.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.cjs +328 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +122 -6
- package/dist/index.d.ts +122 -6
- package/dist/index.js +322 -58
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -922,7 +922,14 @@ declare const defineNode: (opts: NodeTypeDefOptions) => NodeTypeDef;
|
|
|
922
922
|
* nesting, no escapes — single-pass regex tokenization keeps layout
|
|
923
923
|
* fast at scale. See ARCHITECTURE.md §8.
|
|
924
924
|
*/
|
|
925
|
-
type InlineType = 'text' | 'bold' | 'italic' | 'underline' | 'strike' | 'highlight' | 'code' | 'link'
|
|
925
|
+
type InlineType = 'text' | 'bold' | 'italic' | 'underline' | 'strike' | 'highlight' | 'code' | 'link'
|
|
926
|
+
/**
|
|
927
|
+
* LaTeX math expression, content is the source between `$...$` (no
|
|
928
|
+
* leading/trailing whitespace, no line breaks). Rendered via MathJax
|
|
929
|
+
* SVG output and rasterized to an inline bitmap at paint time. See
|
|
930
|
+
* `text/math/`.
|
|
931
|
+
*/
|
|
932
|
+
| 'math';
|
|
926
933
|
type Token = {
|
|
927
934
|
type: InlineType;
|
|
928
935
|
content: string;
|
|
@@ -963,6 +970,12 @@ type LayoutOptions = {
|
|
|
963
970
|
fontFamily: FontFamily;
|
|
964
971
|
fontSize: FontSize;
|
|
965
972
|
textStyle: TextStyle;
|
|
973
|
+
/**
|
|
974
|
+
* Used to key the math bitmap cache. Both layout (for measured dims)
|
|
975
|
+
* and paint (for the actual bitmap) need to query the same cache
|
|
976
|
+
* entry. Defaults to `#000000` for estimate-only callers.
|
|
977
|
+
*/
|
|
978
|
+
textColor?: string;
|
|
966
979
|
};
|
|
967
980
|
/**
|
|
968
981
|
* Turns tokens into drawable lines. Output consumed by the canvas paint pass.
|
|
@@ -1037,6 +1050,97 @@ declare const subscribeFontEpoch: (listener: (epoch: number) => void) => (() =>
|
|
|
1037
1050
|
*/
|
|
1038
1051
|
declare const getFontEpoch: () => number;
|
|
1039
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
* Lazy loader for MathJax — same pattern as `render/rough/loader.ts`.
|
|
1055
|
+
*
|
|
1056
|
+
* MathJax is ~600KB and only useful for scenes with LaTeX math. We
|
|
1057
|
+
* defer loading until the first `$...$` token requests a compile,
|
|
1058
|
+
* then convert LaTeX → SVG strings off the main rAF path.
|
|
1059
|
+
*
|
|
1060
|
+
* Loaded from jsDelivr CDN rather than bundled because the v4
|
|
1061
|
+
* tex-svg.js bundle uses `importScripts('sre/speech-worker.js')` for
|
|
1062
|
+
* accessibility; the relative URL resolves wrong when served from a
|
|
1063
|
+
* dev bundler's node_modules. The CDN serves sibling files at
|
|
1064
|
+
* predictable paths so the bundle finds its workers. Self-host by
|
|
1065
|
+
* pointing `VENDOR_URL` at your own copy of the v4 component files.
|
|
1066
|
+
*
|
|
1067
|
+
* Notes:
|
|
1068
|
+
* - MathJax's `tex-svg.js` bundle attaches itself to `window.MathJax`
|
|
1069
|
+
* when loaded. This is the documented v4 browser API.
|
|
1070
|
+
* - If a consumer also uses MathJax, they should configure the
|
|
1071
|
+
* global *before* canvas-harness's first math node loads.
|
|
1072
|
+
*/
|
|
1073
|
+
type MathJaxLike = {
|
|
1074
|
+
tex2svgPromise(source: string, opts?: {
|
|
1075
|
+
display?: boolean;
|
|
1076
|
+
em?: number;
|
|
1077
|
+
ex?: number;
|
|
1078
|
+
containerWidth?: number;
|
|
1079
|
+
}): Promise<MathJaxSvgElement>;
|
|
1080
|
+
startup: {
|
|
1081
|
+
/**
|
|
1082
|
+
* The "lite adaptor" used by the SVG output in browser context.
|
|
1083
|
+
* `serializeXML` returns standalone-valid SVG markup with
|
|
1084
|
+
* namespaces intact (which `outerHTML` does not always do).
|
|
1085
|
+
*/
|
|
1086
|
+
adaptor: {
|
|
1087
|
+
serializeXML?(el: MathJaxSvgElement): string;
|
|
1088
|
+
outerHTML(el: MathJaxSvgElement): string;
|
|
1089
|
+
};
|
|
1090
|
+
};
|
|
1091
|
+
};
|
|
1092
|
+
/**
|
|
1093
|
+
* MathJax returns a "lite element" virtual-DOM node, not a real SVG
|
|
1094
|
+
* element. We only need to serialize it via the adaptor.
|
|
1095
|
+
*/
|
|
1096
|
+
type MathJaxSvgElement = unknown;
|
|
1097
|
+
declare global {
|
|
1098
|
+
var MathJax: unknown;
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Returns the configured MathJax instance if loaded, else `null` and
|
|
1102
|
+
* triggers the lazy import on first call. Subscribers via `onMathJaxReady`
|
|
1103
|
+
* are notified when the import resolves.
|
|
1104
|
+
*/
|
|
1105
|
+
declare const getMathJax: () => MathJaxLike | null;
|
|
1106
|
+
/**
|
|
1107
|
+
* Registers a callback that fires once when MathJax becomes available.
|
|
1108
|
+
* No-op if already loaded — caller should check `getMathJax() !== null`
|
|
1109
|
+
* first. Used to trigger a re-paint of math-bearing text nodes.
|
|
1110
|
+
*/
|
|
1111
|
+
declare const onMathJaxReady: (cb: () => void) => void;
|
|
1112
|
+
|
|
1113
|
+
/** Result of a successful math compile + raster. */
|
|
1114
|
+
type MathBitmap = {
|
|
1115
|
+
bitmap: ImageBitmap;
|
|
1116
|
+
/** Width in logical CSS pixels at the requested font size. */
|
|
1117
|
+
width: number;
|
|
1118
|
+
/** Height in logical CSS pixels at the requested font size. */
|
|
1119
|
+
height: number;
|
|
1120
|
+
/**
|
|
1121
|
+
* Baseline offset in CSS pixels (positive = bitmap top sits ABOVE
|
|
1122
|
+
* the text baseline; the bottom dips below by `height - baseline`).
|
|
1123
|
+
* Parsed from MathJax's `vertical-align: -Nex` style attribute.
|
|
1124
|
+
*/
|
|
1125
|
+
baselineOffset: number;
|
|
1126
|
+
};
|
|
1127
|
+
declare const getMathEpoch: () => number;
|
|
1128
|
+
declare const subscribeMathEpoch: (cb: () => void) => (() => void);
|
|
1129
|
+
/**
|
|
1130
|
+
* Look up a math bitmap or kick off compilation. Returns the cached
|
|
1131
|
+
* bitmap if ready, `null` if still loading / queued (caller should
|
|
1132
|
+
* paint a placeholder this frame). Triggers a math-epoch bump when
|
|
1133
|
+
* the formula resolves.
|
|
1134
|
+
*
|
|
1135
|
+
* `sizePx` is the on-screen height in logical px (typically the line
|
|
1136
|
+
* height of the surrounding text × DPR).
|
|
1137
|
+
*/
|
|
1138
|
+
declare const getMathBitmap: (source: string, color: string, sizePx: number) => MathBitmap | null;
|
|
1139
|
+
/** Test / debug aid. */
|
|
1140
|
+
declare const clearMathCache: () => void;
|
|
1141
|
+
/** Test / debug aid. */
|
|
1142
|
+
declare const getMathCacheSize: () => number;
|
|
1143
|
+
|
|
1040
1144
|
/**
|
|
1041
1145
|
* Buckets zoom to avoid cache churn from sub-1%-zoom changes.
|
|
1042
1146
|
*/
|
|
@@ -1495,14 +1599,21 @@ interface CanvasStore {
|
|
|
1495
1599
|
* Adds a node. Returns its id. If `node.style.autoFit !== false` and
|
|
1496
1600
|
* `node.content` is set, height is grown to fit.
|
|
1497
1601
|
*
|
|
1602
|
+
* `z` is optional — omit to land on top of the current stack (uses
|
|
1603
|
+
* the internal `topZ` counter). Pass a literal value (incl. `0` or
|
|
1604
|
+
* negative) to place the node at that exact z.
|
|
1605
|
+
*
|
|
1498
1606
|
* @example
|
|
1607
|
+
* // Omit z → goes on top of the current stack.
|
|
1499
1608
|
* const id = store.addNode({
|
|
1500
1609
|
* id: asNodeId(store.generateId()),
|
|
1501
1610
|
* type: 'rect', x: 0, y: 0, w: 200, h: 100,
|
|
1502
|
-
* angle: 0,
|
|
1611
|
+
* angle: 0, groups: [],
|
|
1503
1612
|
* })
|
|
1504
1613
|
*/
|
|
1505
|
-
addNode(node: Node
|
|
1614
|
+
addNode(node: Omit<Node, 'z'> & {
|
|
1615
|
+
z?: number;
|
|
1616
|
+
}): NodeId;
|
|
1506
1617
|
/**
|
|
1507
1618
|
* Patches fields on an existing node. Captures the previous slice on
|
|
1508
1619
|
* the op so undo is free. Autofit re-runs when `content` or font
|
|
@@ -1566,8 +1677,13 @@ interface CanvasStore {
|
|
|
1566
1677
|
alt?: string;
|
|
1567
1678
|
style?: Style;
|
|
1568
1679
|
}): Promise<NodeId>;
|
|
1569
|
-
/**
|
|
1570
|
-
|
|
1680
|
+
/**
|
|
1681
|
+
* Adds an edge. Returns its id. `z` is optional — same auto-top
|
|
1682
|
+
* semantics as {@link CanvasStore.addNode}.
|
|
1683
|
+
*/
|
|
1684
|
+
addEdge(edge: Omit<Edge, 'z'> & {
|
|
1685
|
+
z?: number;
|
|
1686
|
+
}): EdgeId;
|
|
1571
1687
|
/** Patches fields on an existing edge. */
|
|
1572
1688
|
updateEdge(id: EdgeId, patch: Partial<Edge>): void;
|
|
1573
1689
|
/** Removes an edge. */
|
|
@@ -3252,4 +3368,4 @@ declare const installedExtensions: (store: CanvasStore) => string[];
|
|
|
3252
3368
|
*/
|
|
3253
3369
|
declare const VERSION = "0.0.0";
|
|
3254
3370
|
|
|
3255
|
-
export { type AnthropicToolDef, type Arrowhead, BEZIER_SEGMENTS, type BatchId, type BitmapCacheEntry, type BitmapCacheRequest, type BuiltInNodeType, CODE_BG_COLOR, CODE_BLOCK_MARGIN_Y, CODE_BLOCK_PADDING_X, CONTENT_HEIGHT_BUFFER, CONTENT_PADDING, type CameraState, type CanvasBackground, type CanvasBackgroundPattern, type CanvasStore, type CanvasSurface, type ClientId, type ClipResult, type ConflictRecord, type ContextEdge, type ContextNode, DEFAULT_BACKGROUND, DEFAULT_CAMERA, DEFAULT_HIGHLIGHT_COLOR, DEFAULT_HIGHLIGHT_COLOR_DARK, DEFAULT_MINIMAP_MAX_NODES, DEFAULT_STYLE, DEFAULT_TEXT_COLOR, type DeserializeOptions, type DragOriginal, type DrawTextOptions, EDGE_HANDLE_SLOP_PX, EDGE_HIT_SLOP_PX, type Edge, type EdgeEnd, type EdgeGeometry, EdgeGeometryCache, type EdgeHit, type EdgeId, type EdgeStyle, type EditorAdapter, type EditorAdapterFactory, type EditorAdapterMountOptions, type EstimateOptions, type ExportOptions, type Extension, type ExtensionApi, FONT_FAMILY_MAP, FONT_SIZE_MAP, type FontFamily, type FontSize, type FrameLoop, type FrameStats, type GetContextOptions, type Group, type GroupId, type Hit, type IconNodeData, type IdGenerator, type ImageNodeData, type InlineType, type InteractionMode, type InteractionState, LINE_HEIGHT_MAP, LINK_COLOR, type LayoutLine, type LayoutOptions, MAX_IMAGE_BYTES, MAX_SVG_BYTES, MAX_ZOOM, MIN_ZOOM, type Migrator, type MinimapContentOptions, type Node, type NodeHit, type NodeId, type NodeType, type NodeTypeDef, type NodeTypeDefOptions, type Op, type OpBatch, type OpOrigin, PALM_REJECTION_GRACE_MS, type PalmRejectionState, type PathStyle, type PointerInfo, type PresenceEvent, type PresencePatch, type PresenceSlice, type PresenceState, type PrimitiveType, RESIZE_HANDLES, RESIZE_HANDLE_SIZE_PX, ROTATE_HANDLE_OFFSET_PX, ROTATE_HANDLE_RADIUS_PX, type RenderEnv, type Renderer, type RendererOptions, type ResizeHandle, SCHEMA_VERSION, type Scene, type SceneContextJson, type SchemaVersion, type SerializedClipboard, type SerializedScene, type Side, type SnapshotEnv, type SpatialId, type SpatialQuery, type SpatialResult, type StoreEventHandler, type StoreEventName, type StoreEvents, type StoreOptions, type StrokeStyle, type Style, type StyledRun, type SvgExportOptions, type SyncAdapter, type SyncAdapterCapabilities, type TextAlign, type TextStyle, type ThemeResolver, type Token, type Transform, UniformGrid, type Unsubscribe, VERSION, type Vec2, type WorldRect, applyCameraTransform, applySvgColor, arrowheadLength, asBatchId, asClientId, asEdgeId, asGroupId, asNodeId, attachSync, autoRouteControls, blobToDataUri, clampEffectiveScale, clampZoom, clearMeasureCache, clearSurface, clearTextBitmapCache, clipSamples, computeAutoFitHeight, computeEdgeGeometry, copy, createCanvasStore, createDefaultTextareaEditor, createFrameLoop, createPalmRejectionState, createRenderer, cubicBezier, cubicBezierTangent, cut, defineExtension, defineNode, deserializeClipboard, detectConflicts, downscaleImageBlob, drawArrowhead, drawEdge, drawMinimapViewport, drawShape, drawTextToCanvas, drawWithNodeTransform, edgeAABBFromSamples, edgeLabelBoundsWorld, emptyPresenceState, estimateMarkdownContentHeight, exportSelection, exportSelectionSvg, exportViewport, extractSvgDimensions, fromSerialized, fullVisibleClipResult, getCanvasFont, getContentHeight, getContext, getDpr, getFontEpoch, getMarkdownLineHeightPx, getOrRenderTextBitmap, getPointAndTangentAtArcLength, getTextBitmapCacheSize, handleEnter, handleWorldPositions, hitTestAny, hitTestEdge, hitTestHandles, hitTestPoint, hitTestRotateHandle, idleInteractionState, inflateRect, insertLink, installExtension, installedExtensions, inverseBatch, inverseOp, isAttached, isCanvasHarnessClipboard, isDrawablePrimitive, isMoving, isNodeRemoteEditing, layoutTokens, makeIdGenerator, marqueeNodes, measureText, midpointToCubicControls, minimapScreenToWorld, nodeAABB, nodeIntersectsRect, nodeLocalToWorld, notePenActive, notePenInactive, opSchemas, opSchemasAsAnthropicTools, paintBackground, panByScreen, paste, pointInNode, projectEndToWorld, projectToNodeBoundary, quantizeDpr, quantizeZoom, randomClientId, rectContainsPoint, rectFromPoints, rectsIntersect, registerMigrator, renderMinimapContent, resolveColor, resolveOpacity, resolveRenderScale, resolveStrokeWidth, rotateHandleWorldPosition, rotateVecByAngle, sampleBezier, sampleSelfLoop, samplesFor, sanitizeSvg, sceneBounds, screenToWorld, selfLoopGeometry, serializeSelection, setupSurface, shouldAutoFit, shouldRejectTouch, sideNormalLocal, sideOf, sizeSurface, storeToJSON, subscribeFontEpoch, tangentAtArcLength, toImageBlob, toSerialized, toggleBold, toggleCode, toggleItalic, toggleStrike, toggleUnderline, tokenize, unionRects, validateImageInput, validateSvgMarkup, viewportWorldRect, withAutoFitHeight, worldToNodeLocal, worldToScreen, worldViewport, worldViewportFromCamera, zoomAtScreenPoint };
|
|
3371
|
+
export { type AnthropicToolDef, type Arrowhead, BEZIER_SEGMENTS, type BatchId, type BitmapCacheEntry, type BitmapCacheRequest, type BuiltInNodeType, CODE_BG_COLOR, CODE_BLOCK_MARGIN_Y, CODE_BLOCK_PADDING_X, CONTENT_HEIGHT_BUFFER, CONTENT_PADDING, type CameraState, type CanvasBackground, type CanvasBackgroundPattern, type CanvasStore, type CanvasSurface, type ClientId, type ClipResult, type ConflictRecord, type ContextEdge, type ContextNode, DEFAULT_BACKGROUND, DEFAULT_CAMERA, DEFAULT_HIGHLIGHT_COLOR, DEFAULT_HIGHLIGHT_COLOR_DARK, DEFAULT_MINIMAP_MAX_NODES, DEFAULT_STYLE, DEFAULT_TEXT_COLOR, type DeserializeOptions, type DragOriginal, type DrawTextOptions, EDGE_HANDLE_SLOP_PX, EDGE_HIT_SLOP_PX, type Edge, type EdgeEnd, type EdgeGeometry, EdgeGeometryCache, type EdgeHit, type EdgeId, type EdgeStyle, type EditorAdapter, type EditorAdapterFactory, type EditorAdapterMountOptions, type EstimateOptions, type ExportOptions, type Extension, type ExtensionApi, FONT_FAMILY_MAP, FONT_SIZE_MAP, type FontFamily, type FontSize, type FrameLoop, type FrameStats, type GetContextOptions, type Group, type GroupId, type Hit, type IconNodeData, type IdGenerator, type ImageNodeData, type InlineType, type InteractionMode, type InteractionState, LINE_HEIGHT_MAP, LINK_COLOR, type LayoutLine, type LayoutOptions, MAX_IMAGE_BYTES, MAX_SVG_BYTES, MAX_ZOOM, MIN_ZOOM, type MathBitmap, type Migrator, type MinimapContentOptions, type Node, type NodeHit, type NodeId, type NodeType, type NodeTypeDef, type NodeTypeDefOptions, type Op, type OpBatch, type OpOrigin, PALM_REJECTION_GRACE_MS, type PalmRejectionState, type PathStyle, type PointerInfo, type PresenceEvent, type PresencePatch, type PresenceSlice, type PresenceState, type PrimitiveType, RESIZE_HANDLES, RESIZE_HANDLE_SIZE_PX, ROTATE_HANDLE_OFFSET_PX, ROTATE_HANDLE_RADIUS_PX, type RenderEnv, type Renderer, type RendererOptions, type ResizeHandle, SCHEMA_VERSION, type Scene, type SceneContextJson, type SchemaVersion, type SerializedClipboard, type SerializedScene, type Side, type SnapshotEnv, type SpatialId, type SpatialQuery, type SpatialResult, type StoreEventHandler, type StoreEventName, type StoreEvents, type StoreOptions, type StrokeStyle, type Style, type StyledRun, type SvgExportOptions, type SyncAdapter, type SyncAdapterCapabilities, type TextAlign, type TextStyle, type ThemeResolver, type Token, type Transform, UniformGrid, type Unsubscribe, VERSION, type Vec2, type WorldRect, applyCameraTransform, applySvgColor, arrowheadLength, asBatchId, asClientId, asEdgeId, asGroupId, asNodeId, attachSync, autoRouteControls, blobToDataUri, clampEffectiveScale, clampZoom, clearMathCache, clearMeasureCache, clearSurface, clearTextBitmapCache, clipSamples, computeAutoFitHeight, computeEdgeGeometry, copy, createCanvasStore, createDefaultTextareaEditor, createFrameLoop, createPalmRejectionState, createRenderer, cubicBezier, cubicBezierTangent, cut, defineExtension, defineNode, deserializeClipboard, detectConflicts, downscaleImageBlob, drawArrowhead, drawEdge, drawMinimapViewport, drawShape, drawTextToCanvas, drawWithNodeTransform, edgeAABBFromSamples, edgeLabelBoundsWorld, emptyPresenceState, estimateMarkdownContentHeight, exportSelection, exportSelectionSvg, exportViewport, extractSvgDimensions, fromSerialized, fullVisibleClipResult, getCanvasFont, getContentHeight, getContext, getDpr, getFontEpoch, getMarkdownLineHeightPx, getMathBitmap, getMathCacheSize, getMathEpoch, getMathJax, getOrRenderTextBitmap, getPointAndTangentAtArcLength, getTextBitmapCacheSize, handleEnter, handleWorldPositions, hitTestAny, hitTestEdge, hitTestHandles, hitTestPoint, hitTestRotateHandle, idleInteractionState, inflateRect, insertLink, installExtension, installedExtensions, inverseBatch, inverseOp, isAttached, isCanvasHarnessClipboard, isDrawablePrimitive, isMoving, isNodeRemoteEditing, layoutTokens, makeIdGenerator, marqueeNodes, measureText, midpointToCubicControls, minimapScreenToWorld, nodeAABB, nodeIntersectsRect, nodeLocalToWorld, notePenActive, notePenInactive, onMathJaxReady, opSchemas, opSchemasAsAnthropicTools, paintBackground, panByScreen, paste, pointInNode, projectEndToWorld, projectToNodeBoundary, quantizeDpr, quantizeZoom, randomClientId, rectContainsPoint, rectFromPoints, rectsIntersect, registerMigrator, renderMinimapContent, resolveColor, resolveOpacity, resolveRenderScale, resolveStrokeWidth, rotateHandleWorldPosition, rotateVecByAngle, sampleBezier, sampleSelfLoop, samplesFor, sanitizeSvg, sceneBounds, screenToWorld, selfLoopGeometry, serializeSelection, setupSurface, shouldAutoFit, shouldRejectTouch, sideNormalLocal, sideOf, sizeSurface, storeToJSON, subscribeFontEpoch, subscribeMathEpoch, tangentAtArcLength, toImageBlob, toSerialized, toggleBold, toggleCode, toggleItalic, toggleStrike, toggleUnderline, tokenize, unionRects, validateImageInput, validateSvgMarkup, viewportWorldRect, withAutoFitHeight, worldToNodeLocal, worldToScreen, worldViewport, worldViewportFromCamera, zoomAtScreenPoint };
|
package/dist/index.d.ts
CHANGED
|
@@ -922,7 +922,14 @@ declare const defineNode: (opts: NodeTypeDefOptions) => NodeTypeDef;
|
|
|
922
922
|
* nesting, no escapes — single-pass regex tokenization keeps layout
|
|
923
923
|
* fast at scale. See ARCHITECTURE.md §8.
|
|
924
924
|
*/
|
|
925
|
-
type InlineType = 'text' | 'bold' | 'italic' | 'underline' | 'strike' | 'highlight' | 'code' | 'link'
|
|
925
|
+
type InlineType = 'text' | 'bold' | 'italic' | 'underline' | 'strike' | 'highlight' | 'code' | 'link'
|
|
926
|
+
/**
|
|
927
|
+
* LaTeX math expression, content is the source between `$...$` (no
|
|
928
|
+
* leading/trailing whitespace, no line breaks). Rendered via MathJax
|
|
929
|
+
* SVG output and rasterized to an inline bitmap at paint time. See
|
|
930
|
+
* `text/math/`.
|
|
931
|
+
*/
|
|
932
|
+
| 'math';
|
|
926
933
|
type Token = {
|
|
927
934
|
type: InlineType;
|
|
928
935
|
content: string;
|
|
@@ -963,6 +970,12 @@ type LayoutOptions = {
|
|
|
963
970
|
fontFamily: FontFamily;
|
|
964
971
|
fontSize: FontSize;
|
|
965
972
|
textStyle: TextStyle;
|
|
973
|
+
/**
|
|
974
|
+
* Used to key the math bitmap cache. Both layout (for measured dims)
|
|
975
|
+
* and paint (for the actual bitmap) need to query the same cache
|
|
976
|
+
* entry. Defaults to `#000000` for estimate-only callers.
|
|
977
|
+
*/
|
|
978
|
+
textColor?: string;
|
|
966
979
|
};
|
|
967
980
|
/**
|
|
968
981
|
* Turns tokens into drawable lines. Output consumed by the canvas paint pass.
|
|
@@ -1037,6 +1050,97 @@ declare const subscribeFontEpoch: (listener: (epoch: number) => void) => (() =>
|
|
|
1037
1050
|
*/
|
|
1038
1051
|
declare const getFontEpoch: () => number;
|
|
1039
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
* Lazy loader for MathJax — same pattern as `render/rough/loader.ts`.
|
|
1055
|
+
*
|
|
1056
|
+
* MathJax is ~600KB and only useful for scenes with LaTeX math. We
|
|
1057
|
+
* defer loading until the first `$...$` token requests a compile,
|
|
1058
|
+
* then convert LaTeX → SVG strings off the main rAF path.
|
|
1059
|
+
*
|
|
1060
|
+
* Loaded from jsDelivr CDN rather than bundled because the v4
|
|
1061
|
+
* tex-svg.js bundle uses `importScripts('sre/speech-worker.js')` for
|
|
1062
|
+
* accessibility; the relative URL resolves wrong when served from a
|
|
1063
|
+
* dev bundler's node_modules. The CDN serves sibling files at
|
|
1064
|
+
* predictable paths so the bundle finds its workers. Self-host by
|
|
1065
|
+
* pointing `VENDOR_URL` at your own copy of the v4 component files.
|
|
1066
|
+
*
|
|
1067
|
+
* Notes:
|
|
1068
|
+
* - MathJax's `tex-svg.js` bundle attaches itself to `window.MathJax`
|
|
1069
|
+
* when loaded. This is the documented v4 browser API.
|
|
1070
|
+
* - If a consumer also uses MathJax, they should configure the
|
|
1071
|
+
* global *before* canvas-harness's first math node loads.
|
|
1072
|
+
*/
|
|
1073
|
+
type MathJaxLike = {
|
|
1074
|
+
tex2svgPromise(source: string, opts?: {
|
|
1075
|
+
display?: boolean;
|
|
1076
|
+
em?: number;
|
|
1077
|
+
ex?: number;
|
|
1078
|
+
containerWidth?: number;
|
|
1079
|
+
}): Promise<MathJaxSvgElement>;
|
|
1080
|
+
startup: {
|
|
1081
|
+
/**
|
|
1082
|
+
* The "lite adaptor" used by the SVG output in browser context.
|
|
1083
|
+
* `serializeXML` returns standalone-valid SVG markup with
|
|
1084
|
+
* namespaces intact (which `outerHTML` does not always do).
|
|
1085
|
+
*/
|
|
1086
|
+
adaptor: {
|
|
1087
|
+
serializeXML?(el: MathJaxSvgElement): string;
|
|
1088
|
+
outerHTML(el: MathJaxSvgElement): string;
|
|
1089
|
+
};
|
|
1090
|
+
};
|
|
1091
|
+
};
|
|
1092
|
+
/**
|
|
1093
|
+
* MathJax returns a "lite element" virtual-DOM node, not a real SVG
|
|
1094
|
+
* element. We only need to serialize it via the adaptor.
|
|
1095
|
+
*/
|
|
1096
|
+
type MathJaxSvgElement = unknown;
|
|
1097
|
+
declare global {
|
|
1098
|
+
var MathJax: unknown;
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Returns the configured MathJax instance if loaded, else `null` and
|
|
1102
|
+
* triggers the lazy import on first call. Subscribers via `onMathJaxReady`
|
|
1103
|
+
* are notified when the import resolves.
|
|
1104
|
+
*/
|
|
1105
|
+
declare const getMathJax: () => MathJaxLike | null;
|
|
1106
|
+
/**
|
|
1107
|
+
* Registers a callback that fires once when MathJax becomes available.
|
|
1108
|
+
* No-op if already loaded — caller should check `getMathJax() !== null`
|
|
1109
|
+
* first. Used to trigger a re-paint of math-bearing text nodes.
|
|
1110
|
+
*/
|
|
1111
|
+
declare const onMathJaxReady: (cb: () => void) => void;
|
|
1112
|
+
|
|
1113
|
+
/** Result of a successful math compile + raster. */
|
|
1114
|
+
type MathBitmap = {
|
|
1115
|
+
bitmap: ImageBitmap;
|
|
1116
|
+
/** Width in logical CSS pixels at the requested font size. */
|
|
1117
|
+
width: number;
|
|
1118
|
+
/** Height in logical CSS pixels at the requested font size. */
|
|
1119
|
+
height: number;
|
|
1120
|
+
/**
|
|
1121
|
+
* Baseline offset in CSS pixels (positive = bitmap top sits ABOVE
|
|
1122
|
+
* the text baseline; the bottom dips below by `height - baseline`).
|
|
1123
|
+
* Parsed from MathJax's `vertical-align: -Nex` style attribute.
|
|
1124
|
+
*/
|
|
1125
|
+
baselineOffset: number;
|
|
1126
|
+
};
|
|
1127
|
+
declare const getMathEpoch: () => number;
|
|
1128
|
+
declare const subscribeMathEpoch: (cb: () => void) => (() => void);
|
|
1129
|
+
/**
|
|
1130
|
+
* Look up a math bitmap or kick off compilation. Returns the cached
|
|
1131
|
+
* bitmap if ready, `null` if still loading / queued (caller should
|
|
1132
|
+
* paint a placeholder this frame). Triggers a math-epoch bump when
|
|
1133
|
+
* the formula resolves.
|
|
1134
|
+
*
|
|
1135
|
+
* `sizePx` is the on-screen height in logical px (typically the line
|
|
1136
|
+
* height of the surrounding text × DPR).
|
|
1137
|
+
*/
|
|
1138
|
+
declare const getMathBitmap: (source: string, color: string, sizePx: number) => MathBitmap | null;
|
|
1139
|
+
/** Test / debug aid. */
|
|
1140
|
+
declare const clearMathCache: () => void;
|
|
1141
|
+
/** Test / debug aid. */
|
|
1142
|
+
declare const getMathCacheSize: () => number;
|
|
1143
|
+
|
|
1040
1144
|
/**
|
|
1041
1145
|
* Buckets zoom to avoid cache churn from sub-1%-zoom changes.
|
|
1042
1146
|
*/
|
|
@@ -1495,14 +1599,21 @@ interface CanvasStore {
|
|
|
1495
1599
|
* Adds a node. Returns its id. If `node.style.autoFit !== false` and
|
|
1496
1600
|
* `node.content` is set, height is grown to fit.
|
|
1497
1601
|
*
|
|
1602
|
+
* `z` is optional — omit to land on top of the current stack (uses
|
|
1603
|
+
* the internal `topZ` counter). Pass a literal value (incl. `0` or
|
|
1604
|
+
* negative) to place the node at that exact z.
|
|
1605
|
+
*
|
|
1498
1606
|
* @example
|
|
1607
|
+
* // Omit z → goes on top of the current stack.
|
|
1499
1608
|
* const id = store.addNode({
|
|
1500
1609
|
* id: asNodeId(store.generateId()),
|
|
1501
1610
|
* type: 'rect', x: 0, y: 0, w: 200, h: 100,
|
|
1502
|
-
* angle: 0,
|
|
1611
|
+
* angle: 0, groups: [],
|
|
1503
1612
|
* })
|
|
1504
1613
|
*/
|
|
1505
|
-
addNode(node: Node
|
|
1614
|
+
addNode(node: Omit<Node, 'z'> & {
|
|
1615
|
+
z?: number;
|
|
1616
|
+
}): NodeId;
|
|
1506
1617
|
/**
|
|
1507
1618
|
* Patches fields on an existing node. Captures the previous slice on
|
|
1508
1619
|
* the op so undo is free. Autofit re-runs when `content` or font
|
|
@@ -1566,8 +1677,13 @@ interface CanvasStore {
|
|
|
1566
1677
|
alt?: string;
|
|
1567
1678
|
style?: Style;
|
|
1568
1679
|
}): Promise<NodeId>;
|
|
1569
|
-
/**
|
|
1570
|
-
|
|
1680
|
+
/**
|
|
1681
|
+
* Adds an edge. Returns its id. `z` is optional — same auto-top
|
|
1682
|
+
* semantics as {@link CanvasStore.addNode}.
|
|
1683
|
+
*/
|
|
1684
|
+
addEdge(edge: Omit<Edge, 'z'> & {
|
|
1685
|
+
z?: number;
|
|
1686
|
+
}): EdgeId;
|
|
1571
1687
|
/** Patches fields on an existing edge. */
|
|
1572
1688
|
updateEdge(id: EdgeId, patch: Partial<Edge>): void;
|
|
1573
1689
|
/** Removes an edge. */
|
|
@@ -3252,4 +3368,4 @@ declare const installedExtensions: (store: CanvasStore) => string[];
|
|
|
3252
3368
|
*/
|
|
3253
3369
|
declare const VERSION = "0.0.0";
|
|
3254
3370
|
|
|
3255
|
-
export { type AnthropicToolDef, type Arrowhead, BEZIER_SEGMENTS, type BatchId, type BitmapCacheEntry, type BitmapCacheRequest, type BuiltInNodeType, CODE_BG_COLOR, CODE_BLOCK_MARGIN_Y, CODE_BLOCK_PADDING_X, CONTENT_HEIGHT_BUFFER, CONTENT_PADDING, type CameraState, type CanvasBackground, type CanvasBackgroundPattern, type CanvasStore, type CanvasSurface, type ClientId, type ClipResult, type ConflictRecord, type ContextEdge, type ContextNode, DEFAULT_BACKGROUND, DEFAULT_CAMERA, DEFAULT_HIGHLIGHT_COLOR, DEFAULT_HIGHLIGHT_COLOR_DARK, DEFAULT_MINIMAP_MAX_NODES, DEFAULT_STYLE, DEFAULT_TEXT_COLOR, type DeserializeOptions, type DragOriginal, type DrawTextOptions, EDGE_HANDLE_SLOP_PX, EDGE_HIT_SLOP_PX, type Edge, type EdgeEnd, type EdgeGeometry, EdgeGeometryCache, type EdgeHit, type EdgeId, type EdgeStyle, type EditorAdapter, type EditorAdapterFactory, type EditorAdapterMountOptions, type EstimateOptions, type ExportOptions, type Extension, type ExtensionApi, FONT_FAMILY_MAP, FONT_SIZE_MAP, type FontFamily, type FontSize, type FrameLoop, type FrameStats, type GetContextOptions, type Group, type GroupId, type Hit, type IconNodeData, type IdGenerator, type ImageNodeData, type InlineType, type InteractionMode, type InteractionState, LINE_HEIGHT_MAP, LINK_COLOR, type LayoutLine, type LayoutOptions, MAX_IMAGE_BYTES, MAX_SVG_BYTES, MAX_ZOOM, MIN_ZOOM, type Migrator, type MinimapContentOptions, type Node, type NodeHit, type NodeId, type NodeType, type NodeTypeDef, type NodeTypeDefOptions, type Op, type OpBatch, type OpOrigin, PALM_REJECTION_GRACE_MS, type PalmRejectionState, type PathStyle, type PointerInfo, type PresenceEvent, type PresencePatch, type PresenceSlice, type PresenceState, type PrimitiveType, RESIZE_HANDLES, RESIZE_HANDLE_SIZE_PX, ROTATE_HANDLE_OFFSET_PX, ROTATE_HANDLE_RADIUS_PX, type RenderEnv, type Renderer, type RendererOptions, type ResizeHandle, SCHEMA_VERSION, type Scene, type SceneContextJson, type SchemaVersion, type SerializedClipboard, type SerializedScene, type Side, type SnapshotEnv, type SpatialId, type SpatialQuery, type SpatialResult, type StoreEventHandler, type StoreEventName, type StoreEvents, type StoreOptions, type StrokeStyle, type Style, type StyledRun, type SvgExportOptions, type SyncAdapter, type SyncAdapterCapabilities, type TextAlign, type TextStyle, type ThemeResolver, type Token, type Transform, UniformGrid, type Unsubscribe, VERSION, type Vec2, type WorldRect, applyCameraTransform, applySvgColor, arrowheadLength, asBatchId, asClientId, asEdgeId, asGroupId, asNodeId, attachSync, autoRouteControls, blobToDataUri, clampEffectiveScale, clampZoom, clearMeasureCache, clearSurface, clearTextBitmapCache, clipSamples, computeAutoFitHeight, computeEdgeGeometry, copy, createCanvasStore, createDefaultTextareaEditor, createFrameLoop, createPalmRejectionState, createRenderer, cubicBezier, cubicBezierTangent, cut, defineExtension, defineNode, deserializeClipboard, detectConflicts, downscaleImageBlob, drawArrowhead, drawEdge, drawMinimapViewport, drawShape, drawTextToCanvas, drawWithNodeTransform, edgeAABBFromSamples, edgeLabelBoundsWorld, emptyPresenceState, estimateMarkdownContentHeight, exportSelection, exportSelectionSvg, exportViewport, extractSvgDimensions, fromSerialized, fullVisibleClipResult, getCanvasFont, getContentHeight, getContext, getDpr, getFontEpoch, getMarkdownLineHeightPx, getOrRenderTextBitmap, getPointAndTangentAtArcLength, getTextBitmapCacheSize, handleEnter, handleWorldPositions, hitTestAny, hitTestEdge, hitTestHandles, hitTestPoint, hitTestRotateHandle, idleInteractionState, inflateRect, insertLink, installExtension, installedExtensions, inverseBatch, inverseOp, isAttached, isCanvasHarnessClipboard, isDrawablePrimitive, isMoving, isNodeRemoteEditing, layoutTokens, makeIdGenerator, marqueeNodes, measureText, midpointToCubicControls, minimapScreenToWorld, nodeAABB, nodeIntersectsRect, nodeLocalToWorld, notePenActive, notePenInactive, opSchemas, opSchemasAsAnthropicTools, paintBackground, panByScreen, paste, pointInNode, projectEndToWorld, projectToNodeBoundary, quantizeDpr, quantizeZoom, randomClientId, rectContainsPoint, rectFromPoints, rectsIntersect, registerMigrator, renderMinimapContent, resolveColor, resolveOpacity, resolveRenderScale, resolveStrokeWidth, rotateHandleWorldPosition, rotateVecByAngle, sampleBezier, sampleSelfLoop, samplesFor, sanitizeSvg, sceneBounds, screenToWorld, selfLoopGeometry, serializeSelection, setupSurface, shouldAutoFit, shouldRejectTouch, sideNormalLocal, sideOf, sizeSurface, storeToJSON, subscribeFontEpoch, tangentAtArcLength, toImageBlob, toSerialized, toggleBold, toggleCode, toggleItalic, toggleStrike, toggleUnderline, tokenize, unionRects, validateImageInput, validateSvgMarkup, viewportWorldRect, withAutoFitHeight, worldToNodeLocal, worldToScreen, worldViewport, worldViewportFromCamera, zoomAtScreenPoint };
|
|
3371
|
+
export { type AnthropicToolDef, type Arrowhead, BEZIER_SEGMENTS, type BatchId, type BitmapCacheEntry, type BitmapCacheRequest, type BuiltInNodeType, CODE_BG_COLOR, CODE_BLOCK_MARGIN_Y, CODE_BLOCK_PADDING_X, CONTENT_HEIGHT_BUFFER, CONTENT_PADDING, type CameraState, type CanvasBackground, type CanvasBackgroundPattern, type CanvasStore, type CanvasSurface, type ClientId, type ClipResult, type ConflictRecord, type ContextEdge, type ContextNode, DEFAULT_BACKGROUND, DEFAULT_CAMERA, DEFAULT_HIGHLIGHT_COLOR, DEFAULT_HIGHLIGHT_COLOR_DARK, DEFAULT_MINIMAP_MAX_NODES, DEFAULT_STYLE, DEFAULT_TEXT_COLOR, type DeserializeOptions, type DragOriginal, type DrawTextOptions, EDGE_HANDLE_SLOP_PX, EDGE_HIT_SLOP_PX, type Edge, type EdgeEnd, type EdgeGeometry, EdgeGeometryCache, type EdgeHit, type EdgeId, type EdgeStyle, type EditorAdapter, type EditorAdapterFactory, type EditorAdapterMountOptions, type EstimateOptions, type ExportOptions, type Extension, type ExtensionApi, FONT_FAMILY_MAP, FONT_SIZE_MAP, type FontFamily, type FontSize, type FrameLoop, type FrameStats, type GetContextOptions, type Group, type GroupId, type Hit, type IconNodeData, type IdGenerator, type ImageNodeData, type InlineType, type InteractionMode, type InteractionState, LINE_HEIGHT_MAP, LINK_COLOR, type LayoutLine, type LayoutOptions, MAX_IMAGE_BYTES, MAX_SVG_BYTES, MAX_ZOOM, MIN_ZOOM, type MathBitmap, type Migrator, type MinimapContentOptions, type Node, type NodeHit, type NodeId, type NodeType, type NodeTypeDef, type NodeTypeDefOptions, type Op, type OpBatch, type OpOrigin, PALM_REJECTION_GRACE_MS, type PalmRejectionState, type PathStyle, type PointerInfo, type PresenceEvent, type PresencePatch, type PresenceSlice, type PresenceState, type PrimitiveType, RESIZE_HANDLES, RESIZE_HANDLE_SIZE_PX, ROTATE_HANDLE_OFFSET_PX, ROTATE_HANDLE_RADIUS_PX, type RenderEnv, type Renderer, type RendererOptions, type ResizeHandle, SCHEMA_VERSION, type Scene, type SceneContextJson, type SchemaVersion, type SerializedClipboard, type SerializedScene, type Side, type SnapshotEnv, type SpatialId, type SpatialQuery, type SpatialResult, type StoreEventHandler, type StoreEventName, type StoreEvents, type StoreOptions, type StrokeStyle, type Style, type StyledRun, type SvgExportOptions, type SyncAdapter, type SyncAdapterCapabilities, type TextAlign, type TextStyle, type ThemeResolver, type Token, type Transform, UniformGrid, type Unsubscribe, VERSION, type Vec2, type WorldRect, applyCameraTransform, applySvgColor, arrowheadLength, asBatchId, asClientId, asEdgeId, asGroupId, asNodeId, attachSync, autoRouteControls, blobToDataUri, clampEffectiveScale, clampZoom, clearMathCache, clearMeasureCache, clearSurface, clearTextBitmapCache, clipSamples, computeAutoFitHeight, computeEdgeGeometry, copy, createCanvasStore, createDefaultTextareaEditor, createFrameLoop, createPalmRejectionState, createRenderer, cubicBezier, cubicBezierTangent, cut, defineExtension, defineNode, deserializeClipboard, detectConflicts, downscaleImageBlob, drawArrowhead, drawEdge, drawMinimapViewport, drawShape, drawTextToCanvas, drawWithNodeTransform, edgeAABBFromSamples, edgeLabelBoundsWorld, emptyPresenceState, estimateMarkdownContentHeight, exportSelection, exportSelectionSvg, exportViewport, extractSvgDimensions, fromSerialized, fullVisibleClipResult, getCanvasFont, getContentHeight, getContext, getDpr, getFontEpoch, getMarkdownLineHeightPx, getMathBitmap, getMathCacheSize, getMathEpoch, getMathJax, getOrRenderTextBitmap, getPointAndTangentAtArcLength, getTextBitmapCacheSize, handleEnter, handleWorldPositions, hitTestAny, hitTestEdge, hitTestHandles, hitTestPoint, hitTestRotateHandle, idleInteractionState, inflateRect, insertLink, installExtension, installedExtensions, inverseBatch, inverseOp, isAttached, isCanvasHarnessClipboard, isDrawablePrimitive, isMoving, isNodeRemoteEditing, layoutTokens, makeIdGenerator, marqueeNodes, measureText, midpointToCubicControls, minimapScreenToWorld, nodeAABB, nodeIntersectsRect, nodeLocalToWorld, notePenActive, notePenInactive, onMathJaxReady, opSchemas, opSchemasAsAnthropicTools, paintBackground, panByScreen, paste, pointInNode, projectEndToWorld, projectToNodeBoundary, quantizeDpr, quantizeZoom, randomClientId, rectContainsPoint, rectFromPoints, rectsIntersect, registerMigrator, renderMinimapContent, resolveColor, resolveOpacity, resolveRenderScale, resolveStrokeWidth, rotateHandleWorldPosition, rotateVecByAngle, sampleBezier, sampleSelfLoop, samplesFor, sanitizeSvg, sceneBounds, screenToWorld, selfLoopGeometry, serializeSelection, setupSurface, shouldAutoFit, shouldRejectTouch, sideNormalLocal, sideOf, sizeSurface, storeToJSON, subscribeFontEpoch, subscribeMathEpoch, tangentAtArcLength, toImageBlob, toSerialized, toggleBold, toggleCode, toggleItalic, toggleStrike, toggleUnderline, tokenize, unionRects, validateImageInput, validateSvgMarkup, viewportWorldRect, withAutoFitHeight, worldToNodeLocal, worldToScreen, worldViewport, worldViewportFromCamera, zoomAtScreenPoint };
|