@asyra/preset 0.5.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/LICENSE +21 -0
- package/README.md +14 -0
- package/dist/catalog.d.ts +3 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +61 -0
- package/dist/catalog.js.map +1 -0
- package/dist/cleanup-reporter.d.ts +6 -0
- package/dist/cleanup-reporter.d.ts.map +1 -0
- package/dist/cleanup-reporter.js +14 -0
- package/dist/cleanup-reporter.js.map +1 -0
- package/dist/components/fills.d.ts +28 -0
- package/dist/components/fills.d.ts.map +1 -0
- package/dist/components/fills.js +180 -0
- package/dist/components/fills.js.map +1 -0
- package/dist/components/frame.d.ts +4 -0
- package/dist/components/frame.d.ts.map +1 -0
- package/dist/components/frame.js +44 -0
- package/dist/components/frame.js.map +1 -0
- package/dist/components/group.d.ts +72 -0
- package/dist/components/group.d.ts.map +1 -0
- package/dist/components/group.js +491 -0
- package/dist/components/group.js.map +1 -0
- package/dist/components/index.d.ts +24 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +65 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/oval.d.ts +4 -0
- package/dist/components/oval.d.ts.map +1 -0
- package/dist/components/oval.js +56 -0
- package/dist/components/oval.js.map +1 -0
- package/dist/components/rectangle.d.ts +4 -0
- package/dist/components/rectangle.d.ts.map +1 -0
- package/dist/components/rectangle.js +54 -0
- package/dist/components/rectangle.js.map +1 -0
- package/dist/components/shape-hit-area.d.ts +8 -0
- package/dist/components/shape-hit-area.d.ts.map +1 -0
- package/dist/components/shape-hit-area.js +30 -0
- package/dist/components/shape-hit-area.js.map +1 -0
- package/dist/components/stroke-defaults.d.ts +5 -0
- package/dist/components/stroke-defaults.d.ts.map +1 -0
- package/dist/components/stroke-defaults.js +4 -0
- package/dist/components/stroke-defaults.js.map +1 -0
- package/dist/components/vector.d.ts +7 -0
- package/dist/components/vector.d.ts.map +1 -0
- package/dist/components/vector.js +961 -0
- package/dist/components/vector.js.map +1 -0
- package/dist/composition/error.d.ts +16 -0
- package/dist/composition/error.d.ts.map +1 -0
- package/dist/composition/error.js +12 -0
- package/dist/composition/error.js.map +1 -0
- package/dist/composition/profile-provider.d.ts +7 -0
- package/dist/composition/profile-provider.d.ts.map +1 -0
- package/dist/composition/profile-provider.js +24 -0
- package/dist/composition/profile-provider.js.map +1 -0
- package/dist/composition/resolve.d.ts +11 -0
- package/dist/composition/resolve.d.ts.map +1 -0
- package/dist/composition/resolve.js +96 -0
- package/dist/composition/resolve.js.map +1 -0
- package/dist/composition/result.d.ts +3 -0
- package/dist/composition/result.d.ts.map +1 -0
- package/dist/composition/result.js +7 -0
- package/dist/composition/result.js.map +1 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +30 -0
- package/dist/constants.js.map +1 -0
- package/dist/defaults/install.d.ts +16 -0
- package/dist/defaults/install.d.ts.map +1 -0
- package/dist/defaults/install.js +51 -0
- package/dist/defaults/install.js.map +1 -0
- package/dist/defaults/installation.d.ts +14 -0
- package/dist/defaults/installation.d.ts.map +1 -0
- package/dist/defaults/installation.js +85 -0
- package/dist/defaults/installation.js.map +1 -0
- package/dist/defaults/modules/basic-shapes.d.ts +3 -0
- package/dist/defaults/modules/basic-shapes.d.ts.map +1 -0
- package/dist/defaults/modules/basic-shapes.js +9 -0
- package/dist/defaults/modules/basic-shapes.js.map +1 -0
- package/dist/defaults/modules/containers.d.ts +3 -0
- package/dist/defaults/modules/containers.d.ts.map +1 -0
- package/dist/defaults/modules/containers.js +9 -0
- package/dist/defaults/modules/containers.js.map +1 -0
- package/dist/defaults/modules/input.d.ts +3 -0
- package/dist/defaults/modules/input.d.ts.map +1 -0
- package/dist/defaults/modules/input.js +7 -0
- package/dist/defaults/modules/input.js.map +1 -0
- package/dist/defaults/modules/selection.d.ts +3 -0
- package/dist/defaults/modules/selection.d.ts.map +1 -0
- package/dist/defaults/modules/selection.js +20 -0
- package/dist/defaults/modules/selection.js.map +1 -0
- package/dist/defaults/modules/ui-context.d.ts +3 -0
- package/dist/defaults/modules/ui-context.d.ts.map +1 -0
- package/dist/defaults/modules/ui-context.js +9 -0
- package/dist/defaults/modules/ui-context.js.map +1 -0
- package/dist/defaults/modules/vector-editing.d.ts +3 -0
- package/dist/defaults/modules/vector-editing.d.ts.map +1 -0
- package/dist/defaults/modules/vector-editing.js +22 -0
- package/dist/defaults/modules/vector-editing.js.map +1 -0
- package/dist/defaults/modules/vector.d.ts +3 -0
- package/dist/defaults/modules/vector.d.ts.map +1 -0
- package/dist/defaults/modules/vector.js +9 -0
- package/dist/defaults/modules/vector.js.map +1 -0
- package/dist/defaults/modules/viewport.d.ts +3 -0
- package/dist/defaults/modules/viewport.d.ts.map +1 -0
- package/dist/defaults/modules/viewport.js +7 -0
- package/dist/defaults/modules/viewport.js.map +1 -0
- package/dist/defaults/owned-state.d.ts +3 -0
- package/dist/defaults/owned-state.d.ts.map +1 -0
- package/dist/defaults/owned-state.js +72 -0
- package/dist/defaults/owned-state.js.map +1 -0
- package/dist/defaults/private-manager.d.ts +3 -0
- package/dist/defaults/private-manager.d.ts.map +1 -0
- package/dist/defaults/private-manager.js +15 -0
- package/dist/defaults/private-manager.js.map +1 -0
- package/dist/defaults/types.d.ts +12 -0
- package/dist/defaults/types.d.ts.map +1 -0
- package/dist/defaults/types.js +2 -0
- package/dist/defaults/types.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +3 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/input-events.d.ts +19 -0
- package/dist/events/input-events.d.ts.map +1 -0
- package/dist/events/input-events.js +18 -0
- package/dist/events/input-events.js.map +1 -0
- package/dist/events/preset-event-names.d.ts +136 -0
- package/dist/events/preset-event-names.d.ts.map +1 -0
- package/dist/events/preset-event-names.js +18 -0
- package/dist/events/preset-event-names.js.map +1 -0
- package/dist/events/register-events.d.ts +4 -0
- package/dist/events/register-events.d.ts.map +1 -0
- package/dist/events/register-events.js +30 -0
- package/dist/events/register-events.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/preset.d.ts +3 -0
- package/dist/preset.d.ts.map +1 -0
- package/dist/preset.js +86 -0
- package/dist/preset.js.map +1 -0
- package/dist/props/components/anchor-point-component.d.ts +3 -0
- package/dist/props/components/anchor-point-component.d.ts.map +1 -0
- package/dist/props/components/anchor-point-component.js +6 -0
- package/dist/props/components/anchor-point-component.js.map +1 -0
- package/dist/props/components/anchor-points-component.d.ts +3 -0
- package/dist/props/components/anchor-points-component.d.ts.map +1 -0
- package/dist/props/components/anchor-points-component.js +43 -0
- package/dist/props/components/anchor-points-component.js.map +1 -0
- package/dist/props/components/children-map-property-component.d.ts +15 -0
- package/dist/props/components/children-map-property-component.d.ts.map +1 -0
- package/dist/props/components/children-map-property-component.js +205 -0
- package/dist/props/components/children-map-property-component.js.map +1 -0
- package/dist/props/components/custom-component.d.ts +3 -0
- package/dist/props/components/custom-component.d.ts.map +1 -0
- package/dist/props/components/custom-component.js +6 -0
- package/dist/props/components/custom-component.js.map +1 -0
- package/dist/props/components/dimension-component.d.ts +3 -0
- package/dist/props/components/dimension-component.d.ts.map +1 -0
- package/dist/props/components/dimension-component.js +6 -0
- package/dist/props/components/dimension-component.js.map +1 -0
- package/dist/props/components/fill-component.d.ts +3 -0
- package/dist/props/components/fill-component.d.ts.map +1 -0
- package/dist/props/components/fill-component.js +25 -0
- package/dist/props/components/fill-component.js.map +1 -0
- package/dist/props/components/fills-component.d.ts +3 -0
- package/dist/props/components/fills-component.d.ts.map +1 -0
- package/dist/props/components/fills-component.js +33 -0
- package/dist/props/components/fills-component.js.map +1 -0
- package/dist/props/components/index.d.ts +7 -0
- package/dist/props/components/index.d.ts.map +1 -0
- package/dist/props/components/index.js +51 -0
- package/dist/props/components/index.js.map +1 -0
- package/dist/props/components/number-value.d.ts +2 -0
- package/dist/props/components/number-value.d.ts.map +1 -0
- package/dist/props/components/number-value.js +2 -0
- package/dist/props/components/number-value.js.map +1 -0
- package/dist/props/components/position-component.d.ts +3 -0
- package/dist/props/components/position-component.d.ts.map +1 -0
- package/dist/props/components/position-component.js +6 -0
- package/dist/props/components/position-component.js.map +1 -0
- package/dist/props/components/stroke-component.d.ts +3 -0
- package/dist/props/components/stroke-component.d.ts.map +1 -0
- package/dist/props/components/stroke-component.js +29 -0
- package/dist/props/components/stroke-component.js.map +1 -0
- package/dist/props/components/strokes-component.d.ts +3 -0
- package/dist/props/components/strokes-component.d.ts.map +1 -0
- package/dist/props/components/strokes-component.js +44 -0
- package/dist/props/components/strokes-component.js.map +1 -0
- package/dist/props/components/vector-network-component.d.ts +3 -0
- package/dist/props/components/vector-network-component.d.ts.map +1 -0
- package/dist/props/components/vector-network-component.js +10 -0
- package/dist/props/components/vector-network-component.js.map +1 -0
- package/dist/props/components/vector-networks-component.d.ts +2 -0
- package/dist/props/components/vector-networks-component.d.ts.map +1 -0
- package/dist/props/components/vector-networks-component.js +28 -0
- package/dist/props/components/vector-networks-component.js.map +1 -0
- package/dist/props/components/vector-point-component.d.ts +3 -0
- package/dist/props/components/vector-point-component.d.ts.map +1 -0
- package/dist/props/components/vector-point-component.js +15 -0
- package/dist/props/components/vector-point-component.js.map +1 -0
- package/dist/props/components/vector-points-component.d.ts +2 -0
- package/dist/props/components/vector-points-component.d.ts.map +1 -0
- package/dist/props/components/vector-points-component.js +66 -0
- package/dist/props/components/vector-points-component.js.map +1 -0
- package/dist/props/components/vector-segment-component.d.ts +3 -0
- package/dist/props/components/vector-segment-component.d.ts.map +1 -0
- package/dist/props/components/vector-segment-component.js +11 -0
- package/dist/props/components/vector-segment-component.js.map +1 -0
- package/dist/props/components/vector-segments-component.d.ts +2 -0
- package/dist/props/components/vector-segments-component.d.ts.map +1 -0
- package/dist/props/components/vector-segments-component.js +25 -0
- package/dist/props/components/vector-segments-component.js.map +1 -0
- package/dist/props/register-property-schemas.d.ts +7 -0
- package/dist/props/register-property-schemas.d.ts.map +1 -0
- package/dist/props/register-property-schemas.js +475 -0
- package/dist/props/register-property-schemas.js.map +1 -0
- package/dist/registration.d.ts +6 -0
- package/dist/registration.d.ts.map +1 -0
- package/dist/registration.js +15 -0
- package/dist/registration.js.map +1 -0
- package/dist/render-layers/index.d.ts +3 -0
- package/dist/render-layers/index.d.ts.map +1 -0
- package/dist/render-layers/index.js +3 -0
- package/dist/render-layers/index.js.map +1 -0
- package/dist/render-layers/selection-overlay-render-layer.d.ts +15 -0
- package/dist/render-layers/selection-overlay-render-layer.d.ts.map +1 -0
- package/dist/render-layers/selection-overlay-render-layer.js +393 -0
- package/dist/render-layers/selection-overlay-render-layer.js.map +1 -0
- package/dist/render-layers/vector-path-editing-render-layer.d.ts +31 -0
- package/dist/render-layers/vector-path-editing-render-layer.d.ts.map +1 -0
- package/dist/render-layers/vector-path-editing-render-layer.js +815 -0
- package/dist/render-layers/vector-path-editing-render-layer.js.map +1 -0
- package/dist/selection/channels.d.ts +23 -0
- package/dist/selection/channels.d.ts.map +1 -0
- package/dist/selection/channels.js +25 -0
- package/dist/selection/channels.js.map +1 -0
- package/dist/selection/ids.d.ts +8 -0
- package/dist/selection/ids.d.ts.map +1 -0
- package/dist/selection/ids.js +49 -0
- package/dist/selection/ids.js.map +1 -0
- package/dist/selection/register-default-selections.d.ts +6 -0
- package/dist/selection/register-default-selections.d.ts.map +1 -0
- package/dist/selection/register-default-selections.js +52 -0
- package/dist/selection/register-default-selections.js.map +1 -0
- package/dist/subscriptions/data-channel.d.ts +12 -0
- package/dist/subscriptions/data-channel.d.ts.map +1 -0
- package/dist/subscriptions/data-channel.js +1366 -0
- package/dist/subscriptions/data-channel.js.map +1 -0
- package/dist/subscriptions/index.d.ts +4 -0
- package/dist/subscriptions/index.d.ts.map +1 -0
- package/dist/subscriptions/index.js +4 -0
- package/dist/subscriptions/index.js.map +1 -0
- package/dist/subscriptions/render-system.d.ts +3 -0
- package/dist/subscriptions/render-system.d.ts.map +1 -0
- package/dist/subscriptions/render-system.js +41 -0
- package/dist/subscriptions/render-system.js.map +1 -0
- package/dist/subscriptions/shared-channels.d.ts +7 -0
- package/dist/subscriptions/shared-channels.d.ts.map +1 -0
- package/dist/subscriptions/shared-channels.js +67 -0
- package/dist/subscriptions/shared-channels.js.map +1 -0
- package/dist/system-property-keys.d.ts +69 -0
- package/dist/system-property-keys.d.ts.map +1 -0
- package/dist/system-property-keys.js +44 -0
- package/dist/system-property-keys.js.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/register-properties.d.ts +12 -0
- package/dist/ui/register-properties.d.ts.map +1 -0
- package/dist/ui/register-properties.js +318 -0
- package/dist/ui/register-properties.js.map +1 -0
- package/dist/vector/synthetic-handle.d.ts +3 -0
- package/dist/vector/synthetic-handle.d.ts.map +1 -0
- package/dist/vector/synthetic-handle.js +38 -0
- package/dist/vector/synthetic-handle.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,815 @@
|
|
|
1
|
+
import { VECTOR_TOKENS, createOverlayLayerRegistration, getVectorControlId as getControlId, getVectorNetworkAnchorHandleRefs, sampleOverlayBezierPoints, sortVectorItemsById } from '@asyra/core';
|
|
2
|
+
import { emitDiagnosticCounter, measureBrowserDragPhase, projectWorkspacePointToViewport } from '@asyra/utils';
|
|
3
|
+
import { SelectionChannels } from '../selection/channels.js';
|
|
4
|
+
import { decodeVectorPointSelectionId } from '../selection/ids.js';
|
|
5
|
+
import { resolveSyntheticVectorHandlePosition } from '../vector/synthetic-handle.js';
|
|
6
|
+
import { PresetSystemPropertyKeys } from '../system-property-keys.js';
|
|
7
|
+
import { getVectorRenderLocalPoint } from '../components/vector.js';
|
|
8
|
+
const VECTOR_EDITING_LAYER_NAME = 'vector-editing-layer';
|
|
9
|
+
const POINT_RADIUS = 6;
|
|
10
|
+
const POINT_FILL_COLOR = 0x9ca3af;
|
|
11
|
+
const POINT_STROKE_COLOR = 0x4b5563;
|
|
12
|
+
const HANDLE_STROKE_COLOR = 0xffffff;
|
|
13
|
+
const SEGMENT_COLOR = 0x9ca3af;
|
|
14
|
+
const SEGMENT_WIDTH = 1;
|
|
15
|
+
const PREVIEW_WIDTH = 2;
|
|
16
|
+
const GHOST_POINT_FILL_COLOR = 0xffffff;
|
|
17
|
+
const GHOST_POINT_STROKE_COLOR = 0x157ae7;
|
|
18
|
+
const GHOST_POINT_STROKE_WIDTH = 2;
|
|
19
|
+
const SELECTION_OUTLINE_COLOR = 0x157ae7;
|
|
20
|
+
const HOVER_COLOR = SELECTION_OUTLINE_COLOR;
|
|
21
|
+
const HOVER_OUTLINE_WIDTH = 2;
|
|
22
|
+
const HOVER_OUTLINE_RADIUS = POINT_RADIUS + 2;
|
|
23
|
+
export const VECTOR_EDITING_HOVER_SEGMENT_STROKE = {
|
|
24
|
+
width: 2,
|
|
25
|
+
color: HOVER_COLOR
|
|
26
|
+
};
|
|
27
|
+
const SELECTED_POINT_OUTLINE_COLOR = SELECTION_OUTLINE_COLOR;
|
|
28
|
+
const SELECTED_POINT_OUTLINE_WIDTH = 2;
|
|
29
|
+
const SELECTED_POINT_OUTLINE_RADIUS = POINT_RADIUS + 3;
|
|
30
|
+
export const VECTOR_EDITING_SELECTED_SEGMENT_STROKE = {
|
|
31
|
+
width: 3,
|
|
32
|
+
color: SELECTED_POINT_OUTLINE_COLOR
|
|
33
|
+
};
|
|
34
|
+
const getNetworkAdjacentPointIds = (network, pointIndex) => {
|
|
35
|
+
let previousPointId = null;
|
|
36
|
+
let nextPointId = null;
|
|
37
|
+
if (network.closed) {
|
|
38
|
+
previousPointId = network.pointIds[network.pointIds.length - 1];
|
|
39
|
+
nextPointId = network.pointIds[0];
|
|
40
|
+
}
|
|
41
|
+
if (pointIndex > 0) {
|
|
42
|
+
previousPointId = network.pointIds[pointIndex - 1];
|
|
43
|
+
}
|
|
44
|
+
if (pointIndex < network.pointIds.length - 1) {
|
|
45
|
+
nextPointId = network.pointIds[pointIndex + 1];
|
|
46
|
+
}
|
|
47
|
+
return { previousPointId, nextPointId };
|
|
48
|
+
};
|
|
49
|
+
const PenPreviewMode = {
|
|
50
|
+
NONE: 'none',
|
|
51
|
+
CONNECTED_SEGMENT_PREVIEW: 'connected-segment-preview',
|
|
52
|
+
SEGMENT_INSERT_PREVIEW: 'segment-insert-preview'
|
|
53
|
+
};
|
|
54
|
+
const measureVectorEditingOverlayPhase = (phaseName, run) => measureBrowserDragPhase(phaseName, run);
|
|
55
|
+
const appendPositionSignature = (parts, prefix, point) => {
|
|
56
|
+
parts.push(prefix);
|
|
57
|
+
if (!point) {
|
|
58
|
+
parts.push('');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
parts.push(String(point.x), String(point.y));
|
|
62
|
+
};
|
|
63
|
+
const appendSelectedPointSignature = (parts, prefix, point) => {
|
|
64
|
+
parts.push(prefix);
|
|
65
|
+
if (!point) {
|
|
66
|
+
parts.push('');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
parts.push(point.elementId, point.pointId, String(point.index), point.target, String(point.x), String(point.y));
|
|
70
|
+
};
|
|
71
|
+
const appendStringListSignature = (parts, prefix, values) => {
|
|
72
|
+
parts.push(prefix, values.join(','));
|
|
73
|
+
};
|
|
74
|
+
const appendSelectedSegmentSignature = (parts, prefix, segment) => {
|
|
75
|
+
parts.push(prefix);
|
|
76
|
+
if (!segment) {
|
|
77
|
+
parts.push('');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
parts.push(segment.elementId, segment.segmentId);
|
|
81
|
+
};
|
|
82
|
+
const appendInsertPointSignature = (parts, prefix, point) => {
|
|
83
|
+
parts.push(prefix);
|
|
84
|
+
if (!point) {
|
|
85
|
+
parts.push('');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
parts.push(point.elementId, point.segmentId, String(point.x), String(point.y));
|
|
89
|
+
};
|
|
90
|
+
const buildOverlayDrawSignature = (input) => {
|
|
91
|
+
const parts = [
|
|
92
|
+
'draw',
|
|
93
|
+
input.vectorModelSignature,
|
|
94
|
+
String(input.viewportPosition.x),
|
|
95
|
+
String(input.viewportPosition.y),
|
|
96
|
+
String(input.viewportScale),
|
|
97
|
+
input.primaryTool ?? '',
|
|
98
|
+
input.pathEditingVectorId ?? '',
|
|
99
|
+
input.startNewSubpath ? '1' : '0'
|
|
100
|
+
];
|
|
101
|
+
appendPositionSignature(parts, 'mouse', input.mousePosition);
|
|
102
|
+
appendSelectedPointSignature(parts, 'selected-point', input.selectedVectorPoint);
|
|
103
|
+
appendStringListSignature(parts, 'selected-point-ids', input.selectedVectorPointSelectionIds);
|
|
104
|
+
appendSelectedPointSignature(parts, 'hovered-point', input.hoveredVectorPoint);
|
|
105
|
+
appendSelectedSegmentSignature(parts, 'selected-segment', input.selectedVectorSegment);
|
|
106
|
+
appendSelectedSegmentSignature(parts, 'hovered-segment', input.hoveredVectorSegment);
|
|
107
|
+
appendInsertPointSignature(parts, 'insert-point', input.hoveredVectorSegmentInsertPoint);
|
|
108
|
+
return parts.join('|');
|
|
109
|
+
};
|
|
110
|
+
const appendSortedVectorPointSignature = (parts, points) => {
|
|
111
|
+
Object.keys(points)
|
|
112
|
+
.sort()
|
|
113
|
+
.forEach((pointId) => {
|
|
114
|
+
const point = points[pointId];
|
|
115
|
+
if (!point) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
parts.push('p', pointId, point.kind, String(point.x), String(point.y));
|
|
119
|
+
if (point.kind === VECTOR_TOKENS.POINT.KIND.CONTROL) {
|
|
120
|
+
parts.push(point.controlForId ?? '', point.controlRole ?? '');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const appendSortedVectorSegmentSignature = (parts, segments) => {
|
|
125
|
+
Object.keys(segments)
|
|
126
|
+
.sort()
|
|
127
|
+
.forEach((segmentId) => {
|
|
128
|
+
const segment = segments[segmentId];
|
|
129
|
+
if (!segment) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
parts.push('s', segmentId, segment.startId, segment.endId, segment.inControlId ?? '', segment.outControlId ?? '');
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const appendSortedVectorNetworkSignature = (parts, networks) => {
|
|
136
|
+
Object.keys(networks)
|
|
137
|
+
.sort()
|
|
138
|
+
.forEach((networkId) => {
|
|
139
|
+
const network = networks[networkId];
|
|
140
|
+
if (!network) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
parts.push('n', networkId, network.closed ? '1' : '0', network.pointIds.join(','), network.segmentIds.join(','));
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
const buildOverlayVectorDataSignature = (computed, transform) => {
|
|
147
|
+
const parts = [
|
|
148
|
+
'o',
|
|
149
|
+
computed.pointCoordinateSpace ?? 'missing-workspace',
|
|
150
|
+
String(transform.a),
|
|
151
|
+
String(transform.b),
|
|
152
|
+
String(transform.c),
|
|
153
|
+
String(transform.d),
|
|
154
|
+
String(transform.tx),
|
|
155
|
+
String(transform.ty)
|
|
156
|
+
];
|
|
157
|
+
appendSortedVectorPointSignature(parts, computed.points);
|
|
158
|
+
appendSortedVectorSegmentSignature(parts, computed.segments);
|
|
159
|
+
appendSortedVectorNetworkSignature(parts, computed.networks);
|
|
160
|
+
return parts.join('|');
|
|
161
|
+
};
|
|
162
|
+
export const resolveOverlayHandlePosition = resolveSyntheticVectorHandlePosition;
|
|
163
|
+
const getPathEditingVectorDataWithDeps = (deps, cache) => {
|
|
164
|
+
const pathEditingVectorId = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.PATH_EDITING_VECTOR_ID);
|
|
165
|
+
if (!pathEditingVectorId) {
|
|
166
|
+
if (cache) {
|
|
167
|
+
cache.current = null;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const element = deps.sceneTree.getElementById(pathEditingVectorId);
|
|
172
|
+
if (!element || element.get('type') !== 'vector') {
|
|
173
|
+
if (cache) {
|
|
174
|
+
cache.current = null;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const computed = element.getAllComputedData();
|
|
179
|
+
if (!computed.points || !computed.segments || !computed.networks) {
|
|
180
|
+
if (cache) {
|
|
181
|
+
cache.current = null;
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
if (computed.pointCoordinateSpace !== 'workspace') {
|
|
186
|
+
if (cache) {
|
|
187
|
+
cache.current = null;
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const canonicalPoints = computed.points;
|
|
192
|
+
const computedSegments = computed.segments;
|
|
193
|
+
const computedNetworks = computed.networks;
|
|
194
|
+
const renderElement = deps.render.getElementById(pathEditingVectorId);
|
|
195
|
+
if (!renderElement) {
|
|
196
|
+
if (cache) {
|
|
197
|
+
cache.current = null;
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const signature = measureVectorEditingOverlayPhase('editing-overlay:model-signature', () => buildOverlayVectorDataSignature({
|
|
202
|
+
points: canonicalPoints,
|
|
203
|
+
segments: computedSegments,
|
|
204
|
+
networks: computedNetworks,
|
|
205
|
+
x: computed.x,
|
|
206
|
+
y: computed.y,
|
|
207
|
+
pointCoordinateSpace: computed.pointCoordinateSpace
|
|
208
|
+
}, renderElement.worldTransform));
|
|
209
|
+
const cached = cache?.current;
|
|
210
|
+
if (cached &&
|
|
211
|
+
cached.vectorId === pathEditingVectorId &&
|
|
212
|
+
cached.signature === signature) {
|
|
213
|
+
emitDiagnosticCounter('editing-overlay-model-cache-hit');
|
|
214
|
+
return cached.data;
|
|
215
|
+
}
|
|
216
|
+
emitDiagnosticCounter('editing-overlay-model-cache-miss');
|
|
217
|
+
emitDiagnosticCounter('editing-overlay-full-topology-walk');
|
|
218
|
+
emitDiagnosticCounter('editing-overlay-walk-point-count', Object.keys(canonicalPoints).length);
|
|
219
|
+
emitDiagnosticCounter('editing-overlay-walk-segment-count', Object.keys(computedSegments).length);
|
|
220
|
+
emitDiagnosticCounter('editing-overlay-walk-network-count', Object.keys(computedNetworks).length);
|
|
221
|
+
const computedPoints = {};
|
|
222
|
+
for (const [pointId, point] of Object.entries(canonicalPoints)) {
|
|
223
|
+
const localPosition = getVectorRenderLocalPoint(renderElement, point);
|
|
224
|
+
const workspacePosition = localPosition
|
|
225
|
+
? deps.render.elementLocalToWorkspace(pathEditingVectorId, localPosition)
|
|
226
|
+
: null;
|
|
227
|
+
if (!workspacePosition) {
|
|
228
|
+
if (cache) {
|
|
229
|
+
cache.current = null;
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
computedPoints[pointId] = {
|
|
234
|
+
...point,
|
|
235
|
+
x: workspacePosition.x,
|
|
236
|
+
y: workspacePosition.y
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const offsetX = 0;
|
|
240
|
+
const offsetY = 0;
|
|
241
|
+
const orderedNetworks = sortVectorItemsById(Object.values(computedNetworks));
|
|
242
|
+
const subpaths = [];
|
|
243
|
+
const segmentsById = {};
|
|
244
|
+
orderedNetworks.forEach((network) => {
|
|
245
|
+
const points = [];
|
|
246
|
+
const anchorHandleRefs = getVectorNetworkAnchorHandleRefs(network, computedSegments);
|
|
247
|
+
network.pointIds.forEach((pointId, pointIndex) => {
|
|
248
|
+
const anchor = computedPoints[pointId];
|
|
249
|
+
if (!anchor || anchor.kind !== VECTOR_TOKENS.POINT.KIND.ANCHOR) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const handleRefs = anchorHandleRefs.get(pointId);
|
|
253
|
+
const inHandle = handleRefs?.inControlId &&
|
|
254
|
+
computedPoints[handleRefs.inControlId]?.kind ===
|
|
255
|
+
VECTOR_TOKENS.POINT.KIND.CONTROL
|
|
256
|
+
? computedPoints[handleRefs.inControlId]
|
|
257
|
+
: computedPoints[getControlId(pointId, VECTOR_TOKENS.CONTROL.ROLE.IN)];
|
|
258
|
+
const outHandle = handleRefs?.outControlId &&
|
|
259
|
+
computedPoints[handleRefs.outControlId]?.kind ===
|
|
260
|
+
VECTOR_TOKENS.POINT.KIND.CONTROL
|
|
261
|
+
? computedPoints[handleRefs.outControlId]
|
|
262
|
+
: computedPoints[getControlId(pointId, VECTOR_TOKENS.CONTROL.ROLE.OUT)];
|
|
263
|
+
const { previousPointId, nextPointId } = getNetworkAdjacentPointIds(network, pointIndex);
|
|
264
|
+
const previousAnchor = previousPointId
|
|
265
|
+
? computedPoints[previousPointId]
|
|
266
|
+
: null;
|
|
267
|
+
const nextAnchor = nextPointId ? computedPoints[nextPointId] : null;
|
|
268
|
+
const anchorPosition = {
|
|
269
|
+
x: anchor.x + offsetX,
|
|
270
|
+
y: anchor.y + offsetY
|
|
271
|
+
};
|
|
272
|
+
const actualInHandle = inHandle && inHandle.kind === VECTOR_TOKENS.POINT.KIND.CONTROL
|
|
273
|
+
? { x: inHandle.x + offsetX, y: inHandle.y + offsetY }
|
|
274
|
+
: null;
|
|
275
|
+
const actualOutHandle = outHandle && outHandle.kind === VECTOR_TOKENS.POINT.KIND.CONTROL
|
|
276
|
+
? { x: outHandle.x + offsetX, y: outHandle.y + offsetY }
|
|
277
|
+
: null;
|
|
278
|
+
points.push({
|
|
279
|
+
id: pointId,
|
|
280
|
+
...anchorPosition,
|
|
281
|
+
inHandle: resolveOverlayHandlePosition(anchorPosition, actualInHandle, previousAnchor &&
|
|
282
|
+
previousAnchor.kind === VECTOR_TOKENS.POINT.KIND.ANCHOR
|
|
283
|
+
? { x: previousAnchor.x + offsetX, y: previousAnchor.y + offsetY }
|
|
284
|
+
: null, actualOutHandle),
|
|
285
|
+
outHandle: resolveOverlayHandlePosition(anchorPosition, actualOutHandle, nextAnchor && nextAnchor.kind === VECTOR_TOKENS.POINT.KIND.ANCHOR
|
|
286
|
+
? { x: nextAnchor.x + offsetX, y: nextAnchor.y + offsetY }
|
|
287
|
+
: null, actualInHandle)
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
network.segmentIds.forEach((segmentId) => {
|
|
291
|
+
const segment = computedSegments[segmentId];
|
|
292
|
+
if (!segment) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const start = computedPoints[segment.startId];
|
|
296
|
+
const end = computedPoints[segment.endId];
|
|
297
|
+
if (!start ||
|
|
298
|
+
!end ||
|
|
299
|
+
start.kind !== VECTOR_TOKENS.POINT.KIND.ANCHOR ||
|
|
300
|
+
end.kind !== VECTOR_TOKENS.POINT.KIND.ANCHOR) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const outControl = segment.outControlId &&
|
|
304
|
+
computedPoints[segment.outControlId]?.kind ===
|
|
305
|
+
VECTOR_TOKENS.POINT.KIND.CONTROL
|
|
306
|
+
? computedPoints[segment.outControlId]
|
|
307
|
+
: null;
|
|
308
|
+
const inControl = segment.inControlId &&
|
|
309
|
+
computedPoints[segment.inControlId]?.kind ===
|
|
310
|
+
VECTOR_TOKENS.POINT.KIND.CONTROL
|
|
311
|
+
? computedPoints[segment.inControlId]
|
|
312
|
+
: null;
|
|
313
|
+
segmentsById[segmentId] = {
|
|
314
|
+
id: segmentId,
|
|
315
|
+
from: { x: start.x + offsetX, y: start.y + offsetY },
|
|
316
|
+
to: { x: end.x + offsetX, y: end.y + offsetY },
|
|
317
|
+
outHandle: outControl
|
|
318
|
+
? { x: outControl.x + offsetX, y: outControl.y + offsetY }
|
|
319
|
+
: null,
|
|
320
|
+
inHandle: inControl
|
|
321
|
+
? { x: inControl.x + offsetX, y: inControl.y + offsetY }
|
|
322
|
+
: null
|
|
323
|
+
};
|
|
324
|
+
});
|
|
325
|
+
if (points.length > 0) {
|
|
326
|
+
subpaths.push({
|
|
327
|
+
points,
|
|
328
|
+
segmentIds: [...network.segmentIds],
|
|
329
|
+
closed: network.closed
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
if (subpaths.length === 0) {
|
|
334
|
+
if (cache) {
|
|
335
|
+
cache.current = null;
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
const data = {
|
|
340
|
+
subpaths,
|
|
341
|
+
segmentsById
|
|
342
|
+
};
|
|
343
|
+
if (cache) {
|
|
344
|
+
cache.current = {
|
|
345
|
+
vectorId: pathEditingVectorId,
|
|
346
|
+
signature,
|
|
347
|
+
data
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
return data;
|
|
351
|
+
};
|
|
352
|
+
const projectOverlayVectorDataToScreen = (vectorData, viewportPosition, viewportScale, cache) => {
|
|
353
|
+
const cached = cache?.current;
|
|
354
|
+
if (cached &&
|
|
355
|
+
cached.source === vectorData &&
|
|
356
|
+
cached.viewportX === viewportPosition.x &&
|
|
357
|
+
cached.viewportY === viewportPosition.y &&
|
|
358
|
+
cached.viewportScale === viewportScale) {
|
|
359
|
+
emitDiagnosticCounter('editing-overlay-screen-cache-hit');
|
|
360
|
+
return cached.data;
|
|
361
|
+
}
|
|
362
|
+
emitDiagnosticCounter('editing-overlay-screen-cache-miss');
|
|
363
|
+
const subpaths = vectorData.subpaths.map((subpath) => ({
|
|
364
|
+
closed: subpath.closed,
|
|
365
|
+
segmentIds: [...subpath.segmentIds],
|
|
366
|
+
points: subpath.points.map((point) => ({
|
|
367
|
+
id: point.id,
|
|
368
|
+
...projectWorkspacePointToViewport(point, viewportPosition, viewportScale),
|
|
369
|
+
inHandle: point.inHandle
|
|
370
|
+
? projectWorkspacePointToViewport(point.inHandle, viewportPosition, viewportScale)
|
|
371
|
+
: null,
|
|
372
|
+
outHandle: point.outHandle
|
|
373
|
+
? projectWorkspacePointToViewport(point.outHandle, viewportPosition, viewportScale)
|
|
374
|
+
: null
|
|
375
|
+
}))
|
|
376
|
+
}));
|
|
377
|
+
const segmentsById = Object.fromEntries(Object.entries(vectorData.segmentsById).map(([segmentId, segment]) => [
|
|
378
|
+
segmentId,
|
|
379
|
+
(() => {
|
|
380
|
+
const from = projectWorkspacePointToViewport(segment.from, viewportPosition, viewportScale);
|
|
381
|
+
const to = projectWorkspacePointToViewport(segment.to, viewportPosition, viewportScale);
|
|
382
|
+
const inHandle = segment.inHandle
|
|
383
|
+
? projectWorkspacePointToViewport(segment.inHandle, viewportPosition, viewportScale)
|
|
384
|
+
: null;
|
|
385
|
+
const outHandle = segment.outHandle
|
|
386
|
+
? projectWorkspacePointToViewport(segment.outHandle, viewportPosition, viewportScale)
|
|
387
|
+
: null;
|
|
388
|
+
return {
|
|
389
|
+
...segment,
|
|
390
|
+
from,
|
|
391
|
+
to,
|
|
392
|
+
inHandle,
|
|
393
|
+
outHandle,
|
|
394
|
+
sampledPoints: outHandle || inHandle
|
|
395
|
+
? sampleOverlayBezierPoints(from, outHandle ?? from, inHandle ?? to, to)
|
|
396
|
+
: undefined
|
|
397
|
+
};
|
|
398
|
+
})()
|
|
399
|
+
]));
|
|
400
|
+
const data = {
|
|
401
|
+
subpaths,
|
|
402
|
+
segmentsById,
|
|
403
|
+
flatPoints: subpaths.flatMap((subpath) => subpath.points)
|
|
404
|
+
};
|
|
405
|
+
if (cache) {
|
|
406
|
+
cache.current = {
|
|
407
|
+
source: vectorData,
|
|
408
|
+
viewportX: viewportPosition.x,
|
|
409
|
+
viewportY: viewportPosition.y,
|
|
410
|
+
viewportScale,
|
|
411
|
+
data
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
return data;
|
|
415
|
+
};
|
|
416
|
+
const getDiamondPoints = (center, radius) => [
|
|
417
|
+
{ x: center.x, y: center.y - radius },
|
|
418
|
+
{ x: center.x + radius, y: center.y },
|
|
419
|
+
{ x: center.x, y: center.y + radius },
|
|
420
|
+
{ x: center.x - radius, y: center.y }
|
|
421
|
+
];
|
|
422
|
+
const drawSegment = (canvas, segment, stroke) => {
|
|
423
|
+
if (segment.sampledPoints) {
|
|
424
|
+
canvas.polyline(segment.sampledPoints, stroke);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const hasCurve = !!segment.outHandle || !!segment.inHandle;
|
|
428
|
+
if (!hasCurve) {
|
|
429
|
+
canvas.line(segment.from, segment.to, stroke);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
canvas.bezierCurve(segment.from, segment.outHandle ?? segment.from, segment.inHandle ?? segment.to, segment.to, stroke);
|
|
433
|
+
};
|
|
434
|
+
const drawSubpathSegments = (canvas, subpath, segmentsById) => {
|
|
435
|
+
if (subpath.segmentIds.length === 0) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const stroke = {
|
|
439
|
+
width: SEGMENT_WIDTH,
|
|
440
|
+
color: SEGMENT_COLOR
|
|
441
|
+
};
|
|
442
|
+
subpath.segmentIds.forEach((segmentId) => {
|
|
443
|
+
const segment = segmentsById[segmentId];
|
|
444
|
+
if (!segment) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
drawSegment(canvas, segment, stroke);
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
const drawHighlightedSegments = (canvas, segmentsById, selectedSegmentId, hoveredSegmentId) => {
|
|
451
|
+
if (selectedSegmentId) {
|
|
452
|
+
const selectedSegment = segmentsById[selectedSegmentId];
|
|
453
|
+
if (selectedSegment) {
|
|
454
|
+
drawSegment(canvas, selectedSegment, VECTOR_EDITING_SELECTED_SEGMENT_STROKE);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (!hoveredSegmentId || hoveredSegmentId === selectedSegmentId) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const hoveredSegment = segmentsById[hoveredSegmentId];
|
|
461
|
+
if (!hoveredSegment) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
drawSegment(canvas, hoveredSegment, VECTOR_EDITING_HOVER_SEGMENT_STROKE);
|
|
465
|
+
};
|
|
466
|
+
const drawHandleLines = (canvas, points, visibleAnchorIds) => {
|
|
467
|
+
points.forEach((point) => {
|
|
468
|
+
if (!visibleAnchorIds.has(point.id)) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (point.inHandle) {
|
|
472
|
+
canvas.line(point, point.inHandle, {
|
|
473
|
+
width: SEGMENT_WIDTH,
|
|
474
|
+
color: SEGMENT_COLOR
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
if (point.outHandle) {
|
|
478
|
+
canvas.line(point, point.outHandle, {
|
|
479
|
+
width: SEGMENT_WIDTH,
|
|
480
|
+
color: SEGMENT_COLOR
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
const drawAnchorPoints = (canvas, points, selectedPointId, selectedTarget, hoveredPointId, hoveredTarget) => {
|
|
486
|
+
points.forEach((point) => {
|
|
487
|
+
canvas.circle(point, POINT_RADIUS, POINT_FILL_COLOR, {
|
|
488
|
+
width: 1,
|
|
489
|
+
color: POINT_STROKE_COLOR
|
|
490
|
+
});
|
|
491
|
+
const isSelectedAnchor = selectedPointId === point.id &&
|
|
492
|
+
selectedTarget === VECTOR_TOKENS.POINT.TARGET.ANCHOR;
|
|
493
|
+
const isHoveredAnchor = !isSelectedAnchor &&
|
|
494
|
+
hoveredPointId === point.id &&
|
|
495
|
+
hoveredTarget === VECTOR_TOKENS.POINT.TARGET.ANCHOR;
|
|
496
|
+
if (isHoveredAnchor) {
|
|
497
|
+
canvas.circle(point, HOVER_OUTLINE_RADIUS, POINT_FILL_COLOR, {
|
|
498
|
+
width: HOVER_OUTLINE_WIDTH,
|
|
499
|
+
color: HOVER_COLOR
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
if (isSelectedAnchor) {
|
|
503
|
+
canvas.circle(point, SELECTED_POINT_OUTLINE_RADIUS, POINT_FILL_COLOR, {
|
|
504
|
+
width: SELECTED_POINT_OUTLINE_WIDTH,
|
|
505
|
+
color: SELECTED_POINT_OUTLINE_COLOR
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
};
|
|
510
|
+
const drawHandlePoints = (canvas, points, visibleAnchorIds, selectedPointId, selectedTarget, hoveredPointId, hoveredTarget) => {
|
|
511
|
+
points.forEach((point) => {
|
|
512
|
+
if (!visibleAnchorIds.has(point.id)) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const handles = [
|
|
516
|
+
{
|
|
517
|
+
target: VECTOR_TOKENS.POINT.TARGET.IN_HANDLE,
|
|
518
|
+
position: point.inHandle
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
target: VECTOR_TOKENS.POINT.TARGET.OUT_HANDLE,
|
|
522
|
+
position: point.outHandle
|
|
523
|
+
}
|
|
524
|
+
];
|
|
525
|
+
handles.forEach(({ target, position }) => {
|
|
526
|
+
if (!position) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
canvas.polygon(getDiamondPoints(position, POINT_RADIUS), POINT_FILL_COLOR, {
|
|
530
|
+
width: 1,
|
|
531
|
+
color: HANDLE_STROKE_COLOR
|
|
532
|
+
});
|
|
533
|
+
const isSelectedHandle = selectedPointId === point.id && selectedTarget === target;
|
|
534
|
+
const isHoveredHandle = !isSelectedHandle &&
|
|
535
|
+
hoveredPointId === point.id &&
|
|
536
|
+
hoveredTarget === target;
|
|
537
|
+
if (isHoveredHandle) {
|
|
538
|
+
canvas.polygon(getDiamondPoints(position, HOVER_OUTLINE_RADIUS), POINT_FILL_COLOR, {
|
|
539
|
+
width: HOVER_OUTLINE_WIDTH,
|
|
540
|
+
color: HOVER_COLOR
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
if (isSelectedHandle) {
|
|
544
|
+
canvas.polygon(getDiamondPoints(position, SELECTED_POINT_OUTLINE_RADIUS), POINT_FILL_COLOR, {
|
|
545
|
+
width: SELECTED_POINT_OUTLINE_WIDTH,
|
|
546
|
+
color: SELECTED_POINT_OUTLINE_COLOR
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
const appendVisibleHandleAnchorIdsForSubpathIndex = (visibleIds, subpath, index) => {
|
|
553
|
+
const pointCount = subpath.points.length;
|
|
554
|
+
const offsets = [-1, 0, 1];
|
|
555
|
+
offsets.forEach((offset) => {
|
|
556
|
+
const rawIndex = index + offset;
|
|
557
|
+
if (!subpath.closed) {
|
|
558
|
+
if (rawIndex < 0 || rawIndex >= pointCount) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
visibleIds.add(subpath.points[rawIndex].id);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const wrappedIndex = ((rawIndex % pointCount) + pointCount) % pointCount;
|
|
565
|
+
visibleIds.add(subpath.points[wrappedIndex].id);
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
const appendVisibleHandleAnchorIdsForSelection = (visibleIds, subpaths, selection) => {
|
|
569
|
+
const selectedAnchorId = selection.pointId;
|
|
570
|
+
if (typeof selection.index === 'number' && selection.index >= 0) {
|
|
571
|
+
let flatStartIndex = 0;
|
|
572
|
+
for (const subpath of subpaths) {
|
|
573
|
+
const pointCount = subpath.points.length;
|
|
574
|
+
const flatEndIndex = flatStartIndex + pointCount;
|
|
575
|
+
if (selection.index >= flatStartIndex && selection.index < flatEndIndex) {
|
|
576
|
+
const index = selection.index - flatStartIndex;
|
|
577
|
+
const selectedPoint = subpath.points[index];
|
|
578
|
+
if (selectedPoint?.id === selectedAnchorId) {
|
|
579
|
+
appendVisibleHandleAnchorIdsForSubpathIndex(visibleIds, subpath, index);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
flatStartIndex = flatEndIndex;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
for (const subpath of subpaths) {
|
|
587
|
+
const index = subpath.points.findIndex((point) => point.id === selectedAnchorId);
|
|
588
|
+
if (index === -1) {
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
appendVisibleHandleAnchorIdsForSubpathIndex(visibleIds, subpath, index);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
export const getVisibleHandleAnchorIds = (subpaths, selections) => {
|
|
596
|
+
const visibleIds = new Set();
|
|
597
|
+
selections.forEach((selection) => appendVisibleHandleAnchorIdsForSelection(visibleIds, subpaths, selection));
|
|
598
|
+
return visibleIds;
|
|
599
|
+
};
|
|
600
|
+
const isSubpathEndpoint = (subpaths, pointId) => subpaths.some((subpath) => {
|
|
601
|
+
if (subpath.points.length === 0) {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
const firstPoint = subpath.points[0];
|
|
605
|
+
const lastPoint = subpath.points[subpath.points.length - 1];
|
|
606
|
+
return firstPoint.id === pointId || lastPoint.id === pointId;
|
|
607
|
+
});
|
|
608
|
+
const drawPreview = (canvas, lastPoint, mouseScreenPos, shouldRender, handleSide) => {
|
|
609
|
+
if (!shouldRender) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const handle = handleSide === 'in' ? lastPoint.inHandle : lastPoint.outHandle;
|
|
613
|
+
const hasCurve = !!handle;
|
|
614
|
+
if (!hasCurve) {
|
|
615
|
+
canvas.line(lastPoint, mouseScreenPos, {
|
|
616
|
+
width: PREVIEW_WIDTH,
|
|
617
|
+
color: SEGMENT_COLOR
|
|
618
|
+
});
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
canvas.bezierCurve(lastPoint, handle ?? lastPoint, mouseScreenPos, mouseScreenPos, {
|
|
622
|
+
width: PREVIEW_WIDTH,
|
|
623
|
+
color: SEGMENT_COLOR
|
|
624
|
+
});
|
|
625
|
+
};
|
|
626
|
+
const drawGhostInsertPoint = (canvas, point) => {
|
|
627
|
+
if (!point) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
canvas.circle(point, POINT_RADIUS, GHOST_POINT_FILL_COLOR, {
|
|
631
|
+
width: GHOST_POINT_STROKE_WIDTH,
|
|
632
|
+
color: GHOST_POINT_STROKE_COLOR
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
export const registerVectorPathEditingRenderLayer = (registerRenderLayer, deps) => {
|
|
636
|
+
const vectorDataCache = {
|
|
637
|
+
current: null
|
|
638
|
+
};
|
|
639
|
+
const screenDataCache = {
|
|
640
|
+
current: null
|
|
641
|
+
};
|
|
642
|
+
const drawState = {
|
|
643
|
+
current: null
|
|
644
|
+
};
|
|
645
|
+
const layerRegistration = createOverlayLayerRegistration({
|
|
646
|
+
name: VECTOR_EDITING_LAYER_NAME,
|
|
647
|
+
zIndex: 10,
|
|
648
|
+
update: (canvas) => {
|
|
649
|
+
const vectorData = measureVectorEditingOverlayPhase('editing-overlay:model', () => getPathEditingVectorDataWithDeps(deps, vectorDataCache));
|
|
650
|
+
if (!vectorData) {
|
|
651
|
+
screenDataCache.current = null;
|
|
652
|
+
if (drawState.current?.signature !== 'empty') {
|
|
653
|
+
canvas.clear();
|
|
654
|
+
drawState.current = { signature: 'empty' };
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
const vectorModelSignature = vectorDataCache.current?.data === vectorData
|
|
660
|
+
? vectorDataCache.current.signature
|
|
661
|
+
: '';
|
|
662
|
+
const viewportPosition = deps.render.getViewportPosition();
|
|
663
|
+
const viewportScale = deps.render.getViewportScale();
|
|
664
|
+
const snapshot = deps.systemContext.getSystemContextSnapshot();
|
|
665
|
+
const pathEditingVectorId = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.PATH_EDITING_VECTOR_ID) ?? null;
|
|
666
|
+
const selectedVectorPoint = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.SELECTED_VECTOR_POINT) ?? null;
|
|
667
|
+
const selectedVectorPointSelectionIds = Array.from(deps.getSelection(SelectionChannels.VECTOR_POINT)?.getSelectedIds() ??
|
|
668
|
+
[]).sort();
|
|
669
|
+
const hoveredVectorPoint = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.HOVERED_VECTOR_POINT) ?? null;
|
|
670
|
+
const selectedVectorSegment = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.SELECTED_VECTOR_SEGMENT) ?? null;
|
|
671
|
+
const hoveredVectorSegment = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.HOVERED_VECTOR_SEGMENT) ?? null;
|
|
672
|
+
const hoveredVectorSegmentInsertPoint = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.HOVERED_VECTOR_SEGMENT_INSERT_POINT) ?? null;
|
|
673
|
+
const startNewSubpath = deps.systemContext.getManagedProperty(PresetSystemPropertyKeys.PATH_EDITING_START_NEW_SUBPATH) ?? false;
|
|
674
|
+
const drawSignature = buildOverlayDrawSignature({
|
|
675
|
+
vectorModelSignature,
|
|
676
|
+
viewportPosition,
|
|
677
|
+
viewportScale,
|
|
678
|
+
mousePosition: snapshot.mousePosition,
|
|
679
|
+
primaryTool: snapshot.primaryTool,
|
|
680
|
+
pathEditingVectorId,
|
|
681
|
+
selectedVectorPoint,
|
|
682
|
+
selectedVectorPointSelectionIds,
|
|
683
|
+
hoveredVectorPoint,
|
|
684
|
+
selectedVectorSegment,
|
|
685
|
+
hoveredVectorSegment,
|
|
686
|
+
hoveredVectorSegmentInsertPoint,
|
|
687
|
+
startNewSubpath
|
|
688
|
+
});
|
|
689
|
+
if (drawState.current?.signature === drawSignature) {
|
|
690
|
+
emitDiagnosticCounter('editing-overlay-draw-cache-hit');
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
emitDiagnosticCounter('editing-overlay-draw-cache-miss');
|
|
694
|
+
drawState.current = { signature: drawSignature };
|
|
695
|
+
canvas.clear();
|
|
696
|
+
const activeSelectedPoint = pathEditingVectorId &&
|
|
697
|
+
selectedVectorPoint?.elementId === pathEditingVectorId &&
|
|
698
|
+
selectedVectorPoint?.pointId
|
|
699
|
+
? selectedVectorPoint
|
|
700
|
+
: null;
|
|
701
|
+
const selectedPointRefs = selectedVectorPointSelectionIds
|
|
702
|
+
.map((id) => decodeVectorPointSelectionId(id))
|
|
703
|
+
.filter((selection) => selection !== null && selection.elementId === pathEditingVectorId);
|
|
704
|
+
let selectedHandleAnchorRefs = [];
|
|
705
|
+
if (activeSelectedPoint) {
|
|
706
|
+
selectedHandleAnchorRefs = [
|
|
707
|
+
{
|
|
708
|
+
pointId: activeSelectedPoint.pointId,
|
|
709
|
+
index: activeSelectedPoint.index
|
|
710
|
+
}
|
|
711
|
+
];
|
|
712
|
+
}
|
|
713
|
+
if (selectedPointRefs.length > 0) {
|
|
714
|
+
selectedHandleAnchorRefs = selectedPointRefs.map((selection) => ({
|
|
715
|
+
pointId: selection.pointId,
|
|
716
|
+
index: activeSelectedPoint?.pointId === selection.pointId
|
|
717
|
+
? activeSelectedPoint.index
|
|
718
|
+
: null
|
|
719
|
+
}));
|
|
720
|
+
}
|
|
721
|
+
const activeHoveredPoint = pathEditingVectorId &&
|
|
722
|
+
hoveredVectorPoint?.elementId === pathEditingVectorId &&
|
|
723
|
+
hoveredVectorPoint?.pointId
|
|
724
|
+
? hoveredVectorPoint
|
|
725
|
+
: null;
|
|
726
|
+
const activeSelectedSegmentId = pathEditingVectorId &&
|
|
727
|
+
selectedVectorSegment?.elementId === pathEditingVectorId &&
|
|
728
|
+
selectedVectorSegment?.segmentId
|
|
729
|
+
? selectedVectorSegment.segmentId
|
|
730
|
+
: null;
|
|
731
|
+
const activeHoveredSegmentId = activeHoveredPoint ||
|
|
732
|
+
!pathEditingVectorId ||
|
|
733
|
+
hoveredVectorSegment?.elementId !== pathEditingVectorId ||
|
|
734
|
+
!hoveredVectorSegment.segmentId
|
|
735
|
+
? null
|
|
736
|
+
: hoveredVectorSegment.segmentId;
|
|
737
|
+
const mouseWorkspacePos = deps.render.getMousePosInWorkspace({
|
|
738
|
+
clientX: snapshot.mousePosition.x,
|
|
739
|
+
clientY: snapshot.mousePosition.y
|
|
740
|
+
});
|
|
741
|
+
const mouseScreenPos = projectWorkspacePointToViewport(mouseWorkspacePos, viewportPosition, viewportScale);
|
|
742
|
+
const screenData = measureVectorEditingOverlayPhase('editing-overlay:screen-project', () => projectOverlayVectorDataToScreen(vectorData, viewportPosition, viewportScale, screenDataCache));
|
|
743
|
+
const screenSubpaths = screenData.subpaths;
|
|
744
|
+
const screenSegmentsById = screenData.segmentsById;
|
|
745
|
+
const flatScreenPoints = screenData.flatPoints;
|
|
746
|
+
const lastSubpath = screenSubpaths[screenSubpaths.length - 1];
|
|
747
|
+
const defaultPreviewStartPoint = lastSubpath.points[lastSubpath.points.length - 1];
|
|
748
|
+
const selectedPreviewPoint = activeSelectedPoint !== null
|
|
749
|
+
? (flatScreenPoints.find((point) => point.id === activeSelectedPoint.pointId) ?? null)
|
|
750
|
+
: null;
|
|
751
|
+
const previewStartPoint = selectedPreviewPoint &&
|
|
752
|
+
isSubpathEndpoint(screenSubpaths, selectedPreviewPoint.id)
|
|
753
|
+
? selectedPreviewPoint
|
|
754
|
+
: defaultPreviewStartPoint;
|
|
755
|
+
const previewHandleSide = (() => {
|
|
756
|
+
if (!previewStartPoint) {
|
|
757
|
+
return 'out';
|
|
758
|
+
}
|
|
759
|
+
const matchingSubpath = screenSubpaths.find((subpath) => {
|
|
760
|
+
if (subpath.points.length === 0) {
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
const firstPoint = subpath.points[0];
|
|
764
|
+
const lastPoint = subpath.points[subpath.points.length - 1];
|
|
765
|
+
return (firstPoint.id === previewStartPoint.id ||
|
|
766
|
+
lastPoint.id === previewStartPoint.id);
|
|
767
|
+
});
|
|
768
|
+
if (!matchingSubpath || matchingSubpath.points.length === 0) {
|
|
769
|
+
return 'out';
|
|
770
|
+
}
|
|
771
|
+
const firstPoint = matchingSubpath.points[0];
|
|
772
|
+
if (firstPoint.id === previewStartPoint.id) {
|
|
773
|
+
return 'in';
|
|
774
|
+
}
|
|
775
|
+
return 'out';
|
|
776
|
+
})();
|
|
777
|
+
const shouldRenderPreview = snapshot.primaryTool === 'pen' &&
|
|
778
|
+
!startNewSubpath &&
|
|
779
|
+
previewStartPoint !== null;
|
|
780
|
+
let previewMode = PenPreviewMode.NONE;
|
|
781
|
+
if (snapshot.primaryTool === 'pen') {
|
|
782
|
+
previewMode = PenPreviewMode.SEGMENT_INSERT_PREVIEW;
|
|
783
|
+
}
|
|
784
|
+
if (shouldRenderPreview) {
|
|
785
|
+
previewMode = PenPreviewMode.CONNECTED_SEGMENT_PREVIEW;
|
|
786
|
+
}
|
|
787
|
+
const activeGhostInsertPoint = activeHoveredPoint ||
|
|
788
|
+
previewMode !== PenPreviewMode.SEGMENT_INSERT_PREVIEW ||
|
|
789
|
+
!pathEditingVectorId ||
|
|
790
|
+
!activeHoveredSegmentId ||
|
|
791
|
+
hoveredVectorSegmentInsertPoint?.elementId !== pathEditingVectorId ||
|
|
792
|
+
hoveredVectorSegmentInsertPoint?.segmentId !== activeHoveredSegmentId
|
|
793
|
+
? null
|
|
794
|
+
: projectWorkspacePointToViewport({
|
|
795
|
+
x: hoveredVectorSegmentInsertPoint.x,
|
|
796
|
+
y: hoveredVectorSegmentInsertPoint.y
|
|
797
|
+
}, viewportPosition, viewportScale);
|
|
798
|
+
const visibleHandleAnchorIds = getVisibleHandleAnchorIds(screenSubpaths, selectedHandleAnchorRefs);
|
|
799
|
+
measureVectorEditingOverlayPhase('editing-overlay:draw', () => {
|
|
800
|
+
screenSubpaths.forEach((subpath) => drawSubpathSegments(canvas, subpath, screenSegmentsById));
|
|
801
|
+
drawHighlightedSegments(canvas, screenSegmentsById, activeSelectedSegmentId, activeHoveredSegmentId);
|
|
802
|
+
drawHandleLines(canvas, flatScreenPoints, visibleHandleAnchorIds);
|
|
803
|
+
if (previewStartPoint) {
|
|
804
|
+
drawPreview(canvas, previewStartPoint, mouseScreenPos, shouldRenderPreview, previewHandleSide);
|
|
805
|
+
}
|
|
806
|
+
drawGhostInsertPoint(canvas, activeGhostInsertPoint);
|
|
807
|
+
drawAnchorPoints(canvas, flatScreenPoints, activeSelectedPoint?.pointId ?? null, activeSelectedPoint?.target ?? null, activeHoveredPoint?.pointId ?? null, activeHoveredPoint?.target ?? null);
|
|
808
|
+
drawHandlePoints(canvas, flatScreenPoints, visibleHandleAnchorIds, activeSelectedPoint?.pointId ?? null, activeSelectedPoint?.target ?? null, activeHoveredPoint?.pointId ?? null, activeHoveredPoint?.target ?? null);
|
|
809
|
+
});
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
registerRenderLayer(layerRegistration, { override: true });
|
|
814
|
+
};
|
|
815
|
+
//# sourceMappingURL=vector-path-editing-render-layer.js.map
|