@yuzhouu/canvas-kit 0.1.2
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 +145 -0
- package/_vendor/canvas-core/bindings/BindingUtil.ts +92 -0
- package/_vendor/canvas-core/bindings/BindingUtilRegistry.ts +22 -0
- package/_vendor/canvas-core/bindings/arrow/arrowBindingHelpers.ts +52 -0
- package/_vendor/canvas-core/contextMenu.ts +85 -0
- package/_vendor/canvas-core/editor/Editor.ts +2614 -0
- package/_vendor/canvas-core/editor/HistoryManager.ts +83 -0
- package/_vendor/canvas-core/editor/StateNode.ts +162 -0
- package/_vendor/canvas-core/editor/camera.ts +6 -0
- package/_vendor/canvas-core/editor/clipboard.ts +478 -0
- package/_vendor/canvas-core/editor/commands.ts +833 -0
- package/_vendor/canvas-core/editor/edgeScroll.ts +37 -0
- package/_vendor/canvas-core/editor/editorComputedHelpers.ts +257 -0
- package/_vendor/canvas-core/editor/editorSelectionTransforms.ts +116 -0
- package/_vendor/canvas-core/editor/events.ts +93 -0
- package/_vendor/canvas-core/editor/index.ts +12 -0
- package/_vendor/canvas-core/editor/interactions.ts +101 -0
- package/_vendor/canvas-core/editor/internal.ts +22 -0
- package/_vendor/canvas-core/editor/managers/BindingManager.ts +262 -0
- package/_vendor/canvas-core/editor/managers/CameraManager.ts +147 -0
- package/_vendor/canvas-core/editor/managers/ClipboardManager.ts +32 -0
- package/_vendor/canvas-core/editor/managers/DocumentSnapshotManager.ts +256 -0
- package/_vendor/canvas-core/editor/managers/InputsManager.ts +319 -0
- package/_vendor/canvas-core/editor/managers/InteractionTransientManager.ts +218 -0
- package/_vendor/canvas-core/editor/managers/QueryManager.ts +837 -0
- package/_vendor/canvas-core/editor/managers/RenderWindowManager.ts +347 -0
- package/_vendor/canvas-core/editor/managers/SelectionLayoutManager.ts +196 -0
- package/_vendor/canvas-core/editor/managers/SelectionManager.ts +98 -0
- package/_vendor/canvas-core/editor/managers/SelectionOverlayManager.ts +308 -0
- package/_vendor/canvas-core/editor/managers/ShapeEditingManager.ts +226 -0
- package/_vendor/canvas-core/editor/managers/ShapeGeometryManager.ts +162 -0
- package/_vendor/canvas-core/editor/managers/ShapeHierarchyManager.ts +797 -0
- package/_vendor/canvas-core/editor/managers/SideEffectManager.ts +83 -0
- package/_vendor/canvas-core/editor/managers/SnapManager.ts +433 -0
- package/_vendor/canvas-core/editor/managers/SnapSnapshotBuilder.ts +430 -0
- package/_vendor/canvas-core/editor/managers/SpatialIndexManager.ts +354 -0
- package/_vendor/canvas-core/editor/managers/ToolManager.ts +81 -0
- package/_vendor/canvas-core/editor/managers/queryState.ts +583 -0
- package/_vendor/canvas-core/editor/managers/selectionGeometry.ts +287 -0
- package/_vendor/canvas-core/editor/managers/shapeOrder.ts +350 -0
- package/_vendor/canvas-core/editor/managers/shapeReparenting.ts +160 -0
- package/_vendor/canvas-core/editor/managers/snapCalculations.ts +412 -0
- package/_vendor/canvas-core/editor/managers/snapGeometry.ts +202 -0
- package/_vendor/canvas-core/editor/managers/snapIndicators.ts +403 -0
- package/_vendor/canvas-core/editor/managers/snapTypes.ts +122 -0
- package/_vendor/canvas-core/editor/queries/shapeTransforms.ts +171 -0
- package/_vendor/canvas-core/editor/renderWindow.ts +439 -0
- package/_vendor/canvas-core/editor/resizeGeometry.ts +654 -0
- package/_vendor/canvas-core/editor/selection.ts +489 -0
- package/_vendor/canvas-core/editor/selectionHandleInteractions.ts +43 -0
- package/_vendor/canvas-core/editor/selectionOverlay.ts +567 -0
- package/_vendor/canvas-core/exports/integrity.ts +174 -0
- package/_vendor/canvas-core/exports/svg.ts +494 -0
- package/_vendor/canvas-core/geometry/Box.ts +80 -0
- package/_vendor/canvas-core/geometry/Ellipse2d.ts +67 -0
- package/_vendor/canvas-core/geometry/Geometry2d.ts +52 -0
- package/_vendor/canvas-core/geometry/Mat.ts +92 -0
- package/_vendor/canvas-core/geometry/Polyline2d.ts +63 -0
- package/_vendor/canvas-core/geometry/Rectangle2d.ts +64 -0
- package/_vendor/canvas-core/geometry/Vec.ts +123 -0
- package/_vendor/canvas-core/geometry/index.ts +13 -0
- package/_vendor/canvas-core/geometry/segments.ts +65 -0
- package/_vendor/canvas-core/index.ts +391 -0
- package/_vendor/canvas-core/plugins/index.ts +5 -0
- package/_vendor/canvas-core/plugins/types.ts +53 -0
- package/_vendor/canvas-core/reactivity.ts +16 -0
- package/_vendor/canvas-core/schema/records.ts +221 -0
- package/_vendor/canvas-core/schema/snapshots.ts +527 -0
- package/_vendor/canvas-core/shapes/ShapeUtil.ts +516 -0
- package/_vendor/canvas-core/shapes/ShapeUtilRegistry.ts +26 -0
- package/_vendor/canvas-core/shapes/capabilities.ts +67 -0
- package/_vendor/canvas-core/shapes/types.ts +20 -0
- package/_vendor/canvas-core/toolbar.ts +148 -0
- package/_vendor/canvas-core/tools/hand/HandTool.ts +75 -0
- package/_vendor/canvas-core/tools/index.ts +2 -0
- package/_vendor/canvas-core/tools/select/SelectTool.ts +33 -0
- package/_vendor/canvas-core/tools/select/selectContainment.ts +104 -0
- package/_vendor/canvas-core/tools/select/selectToolHelpers.ts +801 -0
- package/_vendor/canvas-core/tools/select/states/BrushingState.ts +145 -0
- package/_vendor/canvas-core/tools/select/states/DraggingSelectionHandleInteractionState.ts +116 -0
- package/_vendor/canvas-core/tools/select/states/IdleState.ts +159 -0
- package/_vendor/canvas-core/tools/select/states/PointingCanvasState.ts +41 -0
- package/_vendor/canvas-core/tools/select/states/PointingResizeHandleState.ts +78 -0
- package/_vendor/canvas-core/tools/select/states/PointingRotateHandleState.ts +64 -0
- package/_vendor/canvas-core/tools/select/states/PointingSelectionHandleInteractionState.ts +34 -0
- package/_vendor/canvas-core/tools/select/states/PointingShapeState.ts +140 -0
- package/_vendor/canvas-core/tools/select/states/ResizingState.ts +171 -0
- package/_vendor/canvas-core/tools/select/states/RotatingState.ts +124 -0
- package/_vendor/canvas-core/tools/select/states/SelectStateNode.ts +128 -0
- package/_vendor/canvas-core/tools/select/states/TranslatingState.ts +139 -0
- package/_vendor/canvas-core/tools/select/states/index.ts +11 -0
- package/_vendor/canvas-plugin-api/feature.ts +204 -0
- package/_vendor/canvas-plugin-api/index.ts +142 -0
- package/_vendor/canvas-product-react/api/apiRegistry.ts +35 -0
- package/_vendor/canvas-product-react/api/canvasProductApi.ts +422 -0
- package/_vendor/canvas-product-react/api/index.ts +31 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/clipboardService.ts +36 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/systemClipboard.ts +245 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/systemContextMenu.ts +396 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/useContextMenuSurface.ts +59 -0
- package/_vendor/canvas-product-react/capabilities/export/useSvgExport.ts +156 -0
- package/_vendor/canvas-product-react/capabilities/history/useHistoryControls.ts +23 -0
- package/_vendor/canvas-product-react/capabilities/pages/usePageControls.ts +41 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/systemToolbar.ts +490 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/useToolbarSurfaces.ts +92 -0
- package/_vendor/canvas-product-react/capabilities/zoom/useZoomControls.ts +27 -0
- package/_vendor/canvas-product-react/index.ts +84 -0
- package/_vendor/canvas-product-react/persistence/index.ts +18 -0
- package/_vendor/canvas-product-react/persistence/localSnapshotPersistence.ts +294 -0
- package/_vendor/canvas-product-react/runtime/CanvasProductRoot.tsx +250 -0
- package/_vendor/canvas-product-react/runtime/productDefinition.ts +72 -0
- package/_vendor/canvas-product-react/runtime/productServices.ts +96 -0
- package/_vendor/canvas-react/components/CanvasView.tsx +796 -0
- package/_vendor/canvas-react/components/OverlayLayer.tsx +879 -0
- package/_vendor/canvas-react/components/PageSpace.tsx +34 -0
- package/_vendor/canvas-react/components/ShapeLayer.tsx +428 -0
- package/_vendor/canvas-react/components/index.ts +4 -0
- package/_vendor/canvas-react/hooks/useEditor.ts +11 -0
- package/_vendor/canvas-react/hooks/useValue.ts +14 -0
- package/_vendor/canvas-react/host/CanvasRendererRegistryContext.tsx +14 -0
- package/_vendor/canvas-react/host/contextMenuRegistry.ts +61 -0
- package/_vendor/canvas-react/host/domEventGuards.ts +61 -0
- package/_vendor/canvas-react/host/index.ts +38 -0
- package/_vendor/canvas-react/host/pluginHost.ts +635 -0
- package/_vendor/canvas-react/host/rendererRegistry.tsx +58 -0
- package/_vendor/canvas-react/host/toolbarRegistry.ts +100 -0
- package/_vendor/canvas-react/index.ts +3 -0
- package/_vendor/plugin-arrow/ArrowBindingUtil.ts +239 -0
- package/_vendor/plugin-arrow/ArrowShapeUtil.ts +311 -0
- package/_vendor/plugin-arrow/ArrowTool.ts +208 -0
- package/_vendor/plugin-arrow/arrowGeometry.ts +441 -0
- package/_vendor/plugin-arrow/arrowTerminalBindingResolver.ts +253 -0
- package/_vendor/plugin-arrow/arrowTerminalCommands.ts +230 -0
- package/_vendor/plugin-arrow/canvas.tsx +92 -0
- package/_vendor/plugin-arrow/core.ts +409 -0
- package/_vendor/plugin-arrow/feature.ts +20 -0
- package/_vendor/plugin-arrow/index.ts +28 -0
- package/_vendor/plugin-arrow/selectionHandleInteractions.ts +154 -0
- package/_vendor/plugin-arrow/types.ts +63 -0
- package/_vendor/plugin-draw/DrawShapeRenderer.tsx +60 -0
- package/_vendor/plugin-draw/DrawShapeUtil.ts +372 -0
- package/_vendor/plugin-draw/DrawTool.ts +444 -0
- package/_vendor/plugin-draw/canvas.tsx +24 -0
- package/_vendor/plugin-draw/core.ts +515 -0
- package/_vendor/plugin-draw/drawGeometry.ts +491 -0
- package/_vendor/plugin-draw/drawHitTest.ts +271 -0
- package/_vendor/plugin-draw/drawInterpolation.ts +250 -0
- package/_vendor/plugin-draw/drawPath.ts +550 -0
- package/_vendor/plugin-draw/drawSegments.ts +106 -0
- package/_vendor/plugin-draw/drawSelectionTransform.ts +67 -0
- package/_vendor/plugin-draw/drawShapeGeometry.ts +307 -0
- package/_vendor/plugin-draw/drawStrokeGeometry.ts +454 -0
- package/_vendor/plugin-draw/feature.ts +20 -0
- package/_vendor/plugin-draw/index.ts +31 -0
- package/_vendor/plugin-draw/types.ts +36 -0
- package/_vendor/plugin-eraser/EraserTool.ts +297 -0
- package/_vendor/plugin-eraser/canvas.tsx +616 -0
- package/_vendor/plugin-eraser/core.ts +49 -0
- package/_vendor/plugin-eraser/feature.ts +20 -0
- package/_vendor/plugin-eraser/index.ts +4 -0
- package/_vendor/plugin-frame/FrameShapeUtil.ts +173 -0
- package/_vendor/plugin-frame/FrameTool.ts +225 -0
- package/_vendor/plugin-frame/canvas.tsx +75 -0
- package/_vendor/plugin-frame/core.ts +534 -0
- package/_vendor/plugin-frame/feature.ts +20 -0
- package/_vendor/plugin-frame/index.ts +6 -0
- package/_vendor/plugin-geo/GeoShapeUtil.ts +463 -0
- package/_vendor/plugin-geo/GeoTools.ts +247 -0
- package/_vendor/plugin-geo/canvas.tsx +90 -0
- package/_vendor/plugin-geo/core.ts +495 -0
- package/_vendor/plugin-geo/feature.ts +20 -0
- package/_vendor/plugin-geo/index.ts +7 -0
- package/_vendor/plugin-geo/types.ts +27 -0
- package/_vendor/plugin-group/GroupShapeUtil.ts +59 -0
- package/_vendor/plugin-group/canvas.tsx +59 -0
- package/_vendor/plugin-group/core.ts +40 -0
- package/_vendor/plugin-group/feature.ts +20 -0
- package/_vendor/plugin-group/index.ts +5 -0
- package/_vendor/plugin-image/ImageShapeUtil.ts +95 -0
- package/_vendor/plugin-image/canvas.tsx +212 -0
- package/_vendor/plugin-image/core.ts +542 -0
- package/_vendor/plugin-image/crop.ts +770 -0
- package/_vendor/plugin-image/cropInteractions.ts +350 -0
- package/_vendor/plugin-image/cropSession.ts +38 -0
- package/_vendor/plugin-image/feature.ts +20 -0
- package/_vendor/plugin-image/index.ts +29 -0
- package/_vendor/plugin-image/types.ts +55 -0
- package/_vendor/plugin-image-product-react/ImageImportController.tsx +143 -0
- package/_vendor/plugin-image-product-react/imageAssetService.ts +52 -0
- package/_vendor/plugin-image-product-react/imageBlobStore.ts +315 -0
- package/_vendor/plugin-image-product-react/imageHostActions.ts +438 -0
- package/_vendor/plugin-image-product-react/imageProductApi.ts +88 -0
- package/_vendor/plugin-image-product-react/imageToolbarHostBridge.ts +48 -0
- package/_vendor/plugin-image-product-react/imageToolbarRuntime.ts +21 -0
- package/_vendor/plugin-image-product-react/index.ts +60 -0
- package/_vendor/plugin-image-product-react/snapshotGuards.ts +33 -0
- package/_vendor/plugin-image-product-react/svgImageAssetInliner.ts +54 -0
- package/_vendor/plugin-image-product-react/useImageImport.ts +64 -0
- package/_vendor/plugin-laser/LaserTool.ts +154 -0
- package/_vendor/plugin-laser/canvas.tsx +645 -0
- package/_vendor/plugin-laser/core.ts +49 -0
- package/_vendor/plugin-laser/feature.ts +20 -0
- package/_vendor/plugin-laser/index.ts +4 -0
- package/_vendor/plugin-text/ArrowLabelBindingUtil.ts +336 -0
- package/_vendor/plugin-text/GeoLabelBindingUtil.ts +391 -0
- package/_vendor/plugin-text/TextShapeSvgExporter.ts +101 -0
- package/_vendor/plugin-text/TextShapeUtil.ts +284 -0
- package/_vendor/plugin-text/TextTool.ts +228 -0
- package/_vendor/plugin-text/canvas.tsx +115 -0
- package/_vendor/plugin-text/core.ts +422 -0
- package/_vendor/plugin-text/feature.ts +20 -0
- package/_vendor/plugin-text/host/RichTextEditingBox.tsx +144 -0
- package/_vendor/plugin-text/host/RichTextToolbar.tsx +266 -0
- package/_vendor/plugin-text/host/TiptapTextEditor.tsx +191 -0
- package/_vendor/plugin-text/host/richTextRendering.tsx +49 -0
- package/_vendor/plugin-text/host/textDomSelection.ts +93 -0
- package/_vendor/plugin-text/host/textEditingBoxStyle.ts +36 -0
- package/_vendor/plugin-text/host/textEntryFocus.ts +307 -0
- package/_vendor/plugin-text/host/textFontLoader.ts +149 -0
- package/_vendor/plugin-text/host/textMeasurement.ts +258 -0
- package/_vendor/plugin-text/host/textMeasurementSync.ts +77 -0
- package/_vendor/plugin-text/host/textRangeSelection.ts +134 -0
- package/_vendor/plugin-text/host/textShapeRendererRuntime.tsx +89 -0
- package/_vendor/plugin-text/host/textShapeSync.ts +173 -0
- package/_vendor/plugin-text/host/tiptapTextEditorController.ts +148 -0
- package/_vendor/plugin-text/index.ts +18 -0
- package/_vendor/plugin-text/richTextUtils.ts +259 -0
- package/_vendor/plugin-text/textInteractions.ts +366 -0
- package/_vendor/plugin-text/textLabelHelpers.ts +235 -0
- package/_vendor/plugin-text/textShapeHelpers.ts +123 -0
- package/_vendor/plugin-text/textStyle.ts +96 -0
- package/_vendor/plugin-text/textTypes.ts +48 -0
- package/_vendor/signals/atom.ts +74 -0
- package/_vendor/signals/computed.ts +132 -0
- package/_vendor/signals/core.ts +130 -0
- package/_vendor/signals/effect.ts +117 -0
- package/_vendor/signals/index.ts +9 -0
- package/_vendor/signals/types.ts +17 -0
- package/_vendor/store/Store.ts +171 -0
- package/_vendor/store/diff.ts +229 -0
- package/_vendor/store/history.ts +177 -0
- package/_vendor/store/index.ts +32 -0
- package/_vendor/store/types.ts +37 -0
- package/api/canvasKitApi.d.ts +29 -0
- package/index.css +3 -0
- package/index.d.ts +16 -0
- package/index.mjs +1 -0
- package/internal-modules.d.ts +187 -0
- package/package.json +48 -0
- package/product/Shell.d.ts +19 -0
- package/product/chromeContext.d.ts +70 -0
- package/product/createCanvasKitEditor.d.ts +6 -0
- package/product/index.d.ts +7 -0
- package/product/persistence.d.ts +3 -0
- package/product/product.d.ts +22 -0
- package/product/useCanvasClipboardShortcuts.d.ts +6 -0
- package/product-iyBbEPIs.mjs +4 -0
- package/product.mjs +1 -0
- package/standard/extensions.d.ts +1 -0
- package/standard/index.d.ts +3 -0
- package/standard/standardApi.d.ts +91 -0
- package/standard-BmrxwqpJ.mjs +44 -0
- package/standard.mjs +1 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { Box, Vec } from "@land/canvas-core";
|
|
2
|
+
import {
|
|
3
|
+
drawPointToVec,
|
|
4
|
+
getClosedDrawCenterlinePathFromPoints,
|
|
5
|
+
getDrawCenterlinePathFromPoints,
|
|
6
|
+
getDrawPointSamplingLimit,
|
|
7
|
+
getDrawSegmentsFromPoints,
|
|
8
|
+
getFlattenedDrawSegmentPoints,
|
|
9
|
+
getSmoothClosedSvgPathFromVecs,
|
|
10
|
+
sampleDrawPoints,
|
|
11
|
+
type DrawPointSamplingOptions,
|
|
12
|
+
} from "./drawPath";
|
|
13
|
+
import {
|
|
14
|
+
cloneDrawPoints,
|
|
15
|
+
cloneDrawSegment,
|
|
16
|
+
cloneDrawSegments,
|
|
17
|
+
translateDrawSegments,
|
|
18
|
+
} from "./drawSegments";
|
|
19
|
+
import {
|
|
20
|
+
createStrokeDerivedPoints,
|
|
21
|
+
getStrokeOutlineVertices,
|
|
22
|
+
} from "./drawStrokeGeometry";
|
|
23
|
+
import type { DrawShapePoint, DrawShapeSegment } from "./types";
|
|
24
|
+
|
|
25
|
+
export interface DrawShapeSamplingStats {
|
|
26
|
+
rawPointCount: number;
|
|
27
|
+
sampledPointCount: number;
|
|
28
|
+
sampledPointLimit: number;
|
|
29
|
+
reduced: boolean;
|
|
30
|
+
capped: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface DrawShapeGeometry {
|
|
34
|
+
normalizedSegments: DrawShapeSegment[];
|
|
35
|
+
normalizedPoints: DrawShapePoint[];
|
|
36
|
+
pointBounds: Box;
|
|
37
|
+
path: string | null;
|
|
38
|
+
selectionPath: string | null;
|
|
39
|
+
fillPath: string | null;
|
|
40
|
+
localBounds: Box;
|
|
41
|
+
renderBounds: Box;
|
|
42
|
+
outlineVertices: Vec[];
|
|
43
|
+
outlinePolygons: Vec[][];
|
|
44
|
+
sampling: DrawShapeSamplingStats;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface DrawSegmentGeometryPart {
|
|
48
|
+
normalizedSegment: DrawShapeSegment;
|
|
49
|
+
sampling: DrawShapeSamplingStats;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const drawSegmentGeometryCache = new WeakMap<
|
|
53
|
+
DrawShapeSegment,
|
|
54
|
+
Map<string, DrawSegmentGeometryPart>
|
|
55
|
+
>();
|
|
56
|
+
|
|
57
|
+
function getFallbackBounds(): Box {
|
|
58
|
+
return new Box(0, 0, 1, 1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function cloneSamplingStats(
|
|
62
|
+
sampling: DrawShapeSamplingStats,
|
|
63
|
+
): DrawShapeSamplingStats {
|
|
64
|
+
return { ...sampling };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function translateOutlineVertices(
|
|
68
|
+
points: readonly Vec[],
|
|
69
|
+
dx: number,
|
|
70
|
+
dy: number,
|
|
71
|
+
): Vec[] {
|
|
72
|
+
return points.map((point) => new Vec(point.x + dx, point.y + dy));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function translateOutlinePolygons(
|
|
76
|
+
polygons: readonly Vec[][],
|
|
77
|
+
dx: number,
|
|
78
|
+
dy: number,
|
|
79
|
+
): Vec[][] {
|
|
80
|
+
return polygons.map((polygon) => translateOutlineVertices(polygon, dx, dy));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getCompoundDrawOutlinePath(polygons: readonly Vec[][]): string | null {
|
|
84
|
+
const paths = polygons
|
|
85
|
+
.map((polygon) => getSmoothClosedSvgPathFromVecs(polygon))
|
|
86
|
+
.filter((path): path is string => path !== null);
|
|
87
|
+
return paths.length > 0 ? paths.join(" ") : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function createDrawGeometryFromDerivedData({
|
|
91
|
+
segments,
|
|
92
|
+
outlineVertices,
|
|
93
|
+
outlinePolygons,
|
|
94
|
+
strokeWidth,
|
|
95
|
+
sampling,
|
|
96
|
+
isClosed,
|
|
97
|
+
}: {
|
|
98
|
+
segments: readonly DrawShapeSegment[];
|
|
99
|
+
outlineVertices: readonly Vec[];
|
|
100
|
+
outlinePolygons?: readonly Vec[][];
|
|
101
|
+
strokeWidth: number;
|
|
102
|
+
sampling: DrawShapeSamplingStats;
|
|
103
|
+
isClosed: boolean;
|
|
104
|
+
}): DrawShapeGeometry {
|
|
105
|
+
const points = getFlattenedDrawSegmentPoints(segments);
|
|
106
|
+
const pointVecs = points.map(drawPointToVec);
|
|
107
|
+
const pointBounds =
|
|
108
|
+
pointVecs.length > 0 ? Box.FromPoints(pointVecs) : getFallbackBounds();
|
|
109
|
+
const localBounds =
|
|
110
|
+
outlineVertices.length > 0
|
|
111
|
+
? Box.FromPoints([...outlineVertices])
|
|
112
|
+
: pointBounds.expand(Math.max(strokeWidth / 2, 1));
|
|
113
|
+
const fillPath =
|
|
114
|
+
isClosed && points.length >= 3
|
|
115
|
+
? getClosedDrawCenterlinePathFromPoints(points)
|
|
116
|
+
: null;
|
|
117
|
+
const outlinePath =
|
|
118
|
+
outlinePolygons !== undefined
|
|
119
|
+
? getCompoundDrawOutlinePath(outlinePolygons)
|
|
120
|
+
: getSmoothClosedSvgPathFromVecs(outlineVertices);
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
normalizedSegments: cloneDrawSegments(segments),
|
|
124
|
+
normalizedPoints: cloneDrawPoints(points),
|
|
125
|
+
pointBounds,
|
|
126
|
+
path: outlinePath,
|
|
127
|
+
selectionPath: fillPath ?? getDrawCenterlinePathFromPoints(points),
|
|
128
|
+
fillPath,
|
|
129
|
+
localBounds,
|
|
130
|
+
renderBounds: localBounds.clone(),
|
|
131
|
+
outlineVertices: outlineVertices.map((point) => point.clone()),
|
|
132
|
+
outlinePolygons: outlinePolygons
|
|
133
|
+
? outlinePolygons.map((polygon) => polygon.map((point) => point.clone()))
|
|
134
|
+
: [outlineVertices.map((point) => point.clone())],
|
|
135
|
+
sampling: cloneSamplingStats(sampling),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function createTranslatedDrawGeometry(
|
|
140
|
+
geometry: DrawShapeGeometry,
|
|
141
|
+
strokeWidth: number,
|
|
142
|
+
dx: number,
|
|
143
|
+
dy: number,
|
|
144
|
+
isClosed: boolean,
|
|
145
|
+
): DrawShapeGeometry {
|
|
146
|
+
return createDrawGeometryFromDerivedData({
|
|
147
|
+
segments: translateDrawSegments(geometry.normalizedSegments, dx, dy),
|
|
148
|
+
outlineVertices: translateOutlineVertices(geometry.outlineVertices, dx, dy),
|
|
149
|
+
outlinePolygons: translateOutlinePolygons(geometry.outlinePolygons, dx, dy),
|
|
150
|
+
strokeWidth,
|
|
151
|
+
sampling: geometry.sampling,
|
|
152
|
+
isClosed,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getDrawPointSamplingOptions(
|
|
157
|
+
strokeWidth: number,
|
|
158
|
+
isPen: boolean,
|
|
159
|
+
): DrawPointSamplingOptions {
|
|
160
|
+
return {
|
|
161
|
+
minPointDistance: isPen
|
|
162
|
+
? Math.max(0.35, strokeWidth * 0.18)
|
|
163
|
+
: Math.max(0.55, strokeWidth * 0.28),
|
|
164
|
+
positionBlend: isPen ? 0.68 : 0.66,
|
|
165
|
+
pressureBlend: isPen ? 0.68 : 0.45,
|
|
166
|
+
maxPointCount: getDrawPointSamplingLimit(isPen),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function getDrawSegmentGeometryCacheKey({
|
|
171
|
+
strokeWidth,
|
|
172
|
+
isPen,
|
|
173
|
+
}: {
|
|
174
|
+
strokeWidth: number;
|
|
175
|
+
isPen: boolean;
|
|
176
|
+
}): string {
|
|
177
|
+
return [strokeWidth, isPen ? "pen" : "pointer"].join(":");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function getCachedDrawSegmentGeometryPart(
|
|
181
|
+
segment: DrawShapeSegment,
|
|
182
|
+
samplingOptions: DrawPointSamplingOptions,
|
|
183
|
+
strokeWidth: number,
|
|
184
|
+
isPen: boolean,
|
|
185
|
+
): DrawSegmentGeometryPart {
|
|
186
|
+
const cacheKey = getDrawSegmentGeometryCacheKey({
|
|
187
|
+
strokeWidth,
|
|
188
|
+
isPen,
|
|
189
|
+
});
|
|
190
|
+
const cachedByKey = drawSegmentGeometryCache.get(segment);
|
|
191
|
+
const cached = cachedByKey?.get(cacheKey);
|
|
192
|
+
if (cached) {
|
|
193
|
+
return {
|
|
194
|
+
normalizedSegment: cloneDrawSegment(cached.normalizedSegment),
|
|
195
|
+
sampling: cloneSamplingStats(cached.sampling),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const sampled = sampleDrawPoints(segment.points, samplingOptions);
|
|
200
|
+
const part: DrawSegmentGeometryPart = {
|
|
201
|
+
normalizedSegment: { points: cloneDrawPoints(sampled.points) },
|
|
202
|
+
sampling: {
|
|
203
|
+
rawPointCount: sampled.rawPointCount,
|
|
204
|
+
sampledPointCount: sampled.sampledPointCount,
|
|
205
|
+
sampledPointLimit: sampled.maxPointCount,
|
|
206
|
+
reduced: sampled.reduced,
|
|
207
|
+
capped: sampled.capped,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const nextCachedByKey =
|
|
212
|
+
cachedByKey ?? new Map<string, DrawSegmentGeometryPart>();
|
|
213
|
+
nextCachedByKey.set(cacheKey, {
|
|
214
|
+
normalizedSegment: cloneDrawSegment(part.normalizedSegment),
|
|
215
|
+
sampling: cloneSamplingStats(part.sampling),
|
|
216
|
+
});
|
|
217
|
+
if (!cachedByKey) {
|
|
218
|
+
drawSegmentGeometryCache.set(segment, nextCachedByKey);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return part;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function getCombinedDrawSegmentSamplingStats(
|
|
225
|
+
samplings: readonly DrawShapeSamplingStats[],
|
|
226
|
+
sampledPointLimit: number,
|
|
227
|
+
): DrawShapeSamplingStats {
|
|
228
|
+
return {
|
|
229
|
+
rawPointCount: samplings.reduce(
|
|
230
|
+
(sum, sampling) => sum + sampling.rawPointCount,
|
|
231
|
+
0,
|
|
232
|
+
),
|
|
233
|
+
sampledPointCount: samplings.reduce(
|
|
234
|
+
(sum, sampling) => sum + sampling.sampledPointCount,
|
|
235
|
+
0,
|
|
236
|
+
),
|
|
237
|
+
sampledPointLimit,
|
|
238
|
+
reduced: samplings.some((sampling) => sampling.reduced),
|
|
239
|
+
capped: samplings.some((sampling) => sampling.capped),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function getDrawPointGeometry(
|
|
244
|
+
points: readonly DrawShapePoint[],
|
|
245
|
+
strokeWidth: number,
|
|
246
|
+
isPen = false,
|
|
247
|
+
isClosed = false,
|
|
248
|
+
): DrawShapeGeometry {
|
|
249
|
+
return getDrawSegmentGeometry(
|
|
250
|
+
getDrawSegmentsFromPoints(points),
|
|
251
|
+
strokeWidth,
|
|
252
|
+
isPen,
|
|
253
|
+
isClosed,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function getDrawSegmentGeometry(
|
|
258
|
+
segments: readonly DrawShapeSegment[],
|
|
259
|
+
strokeWidth: number,
|
|
260
|
+
isPen = false,
|
|
261
|
+
isClosed = false,
|
|
262
|
+
): DrawShapeGeometry {
|
|
263
|
+
const samplingOptions = getDrawPointSamplingOptions(strokeWidth, isPen);
|
|
264
|
+
const normalizedSegments: DrawShapeSegment[] = [];
|
|
265
|
+
const segmentSamplings: DrawShapeSamplingStats[] = [];
|
|
266
|
+
|
|
267
|
+
const nonEmptySegments = segments.filter(
|
|
268
|
+
(segment) => segment.points.length > 0,
|
|
269
|
+
);
|
|
270
|
+
for (
|
|
271
|
+
let segmentIndex = 0;
|
|
272
|
+
segmentIndex < nonEmptySegments.length;
|
|
273
|
+
segmentIndex += 1
|
|
274
|
+
) {
|
|
275
|
+
const segment = nonEmptySegments[segmentIndex]!;
|
|
276
|
+
const part = getCachedDrawSegmentGeometryPart(
|
|
277
|
+
segment,
|
|
278
|
+
samplingOptions,
|
|
279
|
+
strokeWidth,
|
|
280
|
+
isPen,
|
|
281
|
+
);
|
|
282
|
+
normalizedSegments.push(cloneDrawSegment(part.normalizedSegment));
|
|
283
|
+
segmentSamplings.push(cloneSamplingStats(part.sampling));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const normalizedPoints = getFlattenedDrawSegmentPoints(normalizedSegments);
|
|
287
|
+
const strokePoints = createStrokeDerivedPoints(
|
|
288
|
+
normalizedPoints,
|
|
289
|
+
strokeWidth,
|
|
290
|
+
isPen,
|
|
291
|
+
isClosed,
|
|
292
|
+
);
|
|
293
|
+
const outlineVertices = getStrokeOutlineVertices(strokePoints, isClosed);
|
|
294
|
+
const sampling = getCombinedDrawSegmentSamplingStats(
|
|
295
|
+
segmentSamplings,
|
|
296
|
+
samplingOptions.maxPointCount,
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
return createDrawGeometryFromDerivedData({
|
|
300
|
+
segments: normalizedSegments,
|
|
301
|
+
outlineVertices,
|
|
302
|
+
outlinePolygons: outlineVertices.length > 0 ? [outlineVertices] : [],
|
|
303
|
+
strokeWidth,
|
|
304
|
+
sampling,
|
|
305
|
+
isClosed,
|
|
306
|
+
});
|
|
307
|
+
}
|