@pairdraw/core 0.16.0 → 0.16.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 +1 -1
- package/dist/ai/providers.d.ts +6 -1
- package/dist/ai/providers.d.ts.map +1 -1
- package/dist/ai/providers.js +9 -0
- package/dist/ai/providers.js.map +1 -1
- package/dist/canvas/highlight-rect.d.ts +10 -1
- package/dist/canvas/highlight-rect.d.ts.map +1 -1
- package/dist/canvas/highlight-rect.js +16 -8
- package/dist/canvas/highlight-rect.js.map +1 -1
- package/dist/canvas/index.d.ts +2 -3
- package/dist/canvas/index.js +1 -2
- package/dist/canvas/issues/draw.d.ts +2 -6
- package/dist/canvas/issues/draw.d.ts.map +1 -1
- package/dist/canvas/issues/draw.js +2 -99
- package/dist/canvas/issues/draw.js.map +1 -1
- package/dist/canvas/issues/types.d.ts +2 -33
- package/dist/canvas/issues/types.d.ts.map +1 -1
- package/dist/canvas/overlays/{ai.d.ts → ai/draw.d.ts} +3 -3
- package/dist/canvas/overlays/ai/draw.d.ts.map +1 -0
- package/dist/canvas/overlays/ai/draw.js +102 -0
- package/dist/canvas/overlays/ai/draw.js.map +1 -0
- package/dist/canvas/overlays/ai/motion.d.ts +23 -0
- package/dist/canvas/overlays/ai/motion.d.ts.map +1 -0
- package/dist/canvas/overlays/ai/motion.js +32 -0
- package/dist/canvas/overlays/ai/motion.js.map +1 -0
- package/dist/canvas/renderer/methods.js +1 -1
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +2 -47
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.js +1 -1
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/state.d.ts +5 -3
- package/dist/canvas/renderer/state.d.ts.map +1 -1
- package/dist/canvas/renderer/state.js +18 -6
- package/dist/canvas/renderer/state.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +2 -2
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +12 -8
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +9 -9
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/text/preparation/cache.d.ts +5 -0
- package/dist/canvas/text/preparation/cache.d.ts.map +1 -1
- package/dist/canvas/text/preparation/cache.js +8 -1
- package/dist/canvas/text/preparation/cache.js.map +1 -1
- package/dist/constants.d.ts +13 -18
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +16 -21
- package/dist/constants.js.map +1 -1
- package/dist/design-jsx/index.d.ts +2 -2
- package/dist/design-jsx/index.js +2 -2
- package/dist/design-jsx/preview/picture.d.ts +12 -5
- package/dist/design-jsx/preview/picture.d.ts.map +1 -1
- package/dist/design-jsx/preview/picture.js +40 -15
- package/dist/design-jsx/preview/picture.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/create.d.ts +3 -6
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +11 -8
- package/dist/editor/history/atomic-tool.js.map +1 -1
- package/dist/editor/history/document-change.d.ts +9 -1
- package/dist/editor/history/document-change.d.ts.map +1 -1
- package/dist/editor/history/document-change.js +100 -2
- package/dist/editor/history/document-change.js.map +1 -1
- package/dist/editor/history/snapshot/graph.d.ts +15 -3
- package/dist/editor/history/snapshot/graph.d.ts.map +1 -1
- package/dist/editor/history/snapshot/graph.js +29 -8
- package/dist/editor/history/snapshot/graph.js.map +1 -1
- package/dist/editor/index.d.ts +3 -3
- package/dist/editor/index.js +3 -3
- package/dist/editor/issues.d.ts +1 -4
- package/dist/editor/issues.d.ts.map +1 -1
- package/dist/editor/issues.js +5 -44
- package/dist/editor/issues.js.map +1 -1
- package/dist/editor/nudge.js +3 -2
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/read-only/actions.js +0 -3
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/state/shared.js +1 -1
- package/dist/editor/state/shared.js.map +1 -1
- package/dist/editor/types.d.ts +7 -4
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/io/subgraph.d.ts +5 -2
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +6 -2
- package/dist/io/subgraph.js.map +1 -1
- package/dist/layout/mutations.d.ts +1 -1
- package/dist/layout/mutations.d.ts.map +1 -1
- package/dist/layout/mutations.js +1 -1
- package/dist/layout/mutations.js.map +1 -1
- package/dist/text/font/faces.js +1 -1
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/web-font/providers.d.ts +2 -11
- package/dist/text/web-font/providers.d.ts.map +1 -1
- package/dist/text/web-font/providers.js +8 -7
- package/dist/text/web-font/providers.js.map +1 -1
- package/dist/tools/analyze/diff/jsx.d.ts +2 -1
- package/dist/tools/analyze/diff/jsx.d.ts.map +1 -1
- package/dist/tools/analyze/diff/jsx.js +4 -2
- package/dist/tools/analyze/diff/jsx.js.map +1 -1
- package/package.json +24 -9
- package/src/ai/providers.ts +15 -1
- package/src/canvas/highlight-rect.ts +30 -9
- package/src/canvas/index.ts +1 -15
- package/src/canvas/issues/draw.ts +2 -165
- package/src/canvas/issues/types.ts +1 -36
- package/src/canvas/overlays/ai/draw.ts +129 -0
- package/src/canvas/overlays/ai/motion.ts +46 -0
- package/src/canvas/renderer/methods.ts +1 -1
- package/src/canvas/renderer/overlay-pass.ts +2 -49
- package/src/canvas/renderer/pipeline.ts +1 -1
- package/src/canvas/renderer/state.ts +20 -5
- package/src/canvas/renderer/types.ts +2 -2
- package/src/canvas/renderer.ts +9 -10
- package/src/canvas/text/preparation/cache.ts +9 -1
- package/src/constants.ts +12 -17
- package/src/design-jsx/index.ts +1 -1
- package/src/design-jsx/preview/picture.ts +55 -18
- package/src/editor/history/atomic-tool.ts +15 -8
- package/src/editor/history/document-change.ts +117 -1
- package/src/editor/history/snapshot/graph.ts +48 -8
- package/src/editor/index.ts +10 -2
- package/src/editor/issues.ts +6 -36
- package/src/editor/nudge.ts +4 -2
- package/src/editor/read-only/actions.ts +0 -3
- package/src/editor/state/shared.ts +1 -1
- package/src/editor/types.ts +6 -4
- package/src/io/subgraph.ts +10 -5
- package/src/layout/mutations.ts +2 -2
- package/src/text/font/faces.ts +1 -1
- package/src/text/web-font/providers.ts +19 -13
- package/src/tools/analyze/diff/jsx.ts +10 -5
- package/dist/canvas/issues/layout.d.ts +0 -37
- package/dist/canvas/issues/layout.d.ts.map +0 -1
- package/dist/canvas/issues/layout.js +0 -303
- package/dist/canvas/issues/layout.js.map +0 -1
- package/dist/canvas/overlays/ai.d.ts.map +0 -1
- package/dist/canvas/overlays/ai.js +0 -26
- package/dist/canvas/overlays/ai.js.map +0 -1
- package/src/canvas/issues/layout.ts +0 -376
- package/src/canvas/overlays/ai.ts +0 -34
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
2
|
-
import Matrix from '@pairdraw/scene-graph/matrix'
|
|
3
|
-
import type { Rect, Vector } from '@pairdraw/scene-graph/primitives'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
ISSUE_EDGE_ARROW,
|
|
7
|
-
ISSUE_EDGE_MERGE_GAP,
|
|
8
|
-
ISSUE_MARKER_GAP,
|
|
9
|
-
ISSUE_MARKER_HEIGHT,
|
|
10
|
-
ISSUE_MARKER_MAX_COUNT,
|
|
11
|
-
ISSUE_MARKER_MIN_TARGET,
|
|
12
|
-
ISSUE_MARKER_OFFSET,
|
|
13
|
-
ISSUE_MARKER_PADDING_X,
|
|
14
|
-
ISSUE_MARKER_RING_WIDTH,
|
|
15
|
-
ISSUE_MARKER_VIEWPORT_INSET
|
|
16
|
-
} from '#core/constants'
|
|
17
|
-
import { createSceneGeometry, type RotationPreview, type ViewportTransform } from '#core/geometry'
|
|
18
|
-
|
|
19
|
-
import type { DesignIssueMarker, DesignIssueSeverity, PlacedIssueMarker } from './types'
|
|
20
|
-
|
|
21
|
-
export interface IssueMarkerView extends ViewportTransform {
|
|
22
|
-
width: number
|
|
23
|
-
height: number
|
|
24
|
-
/** Space taken by chrome along the top and left edges, such as rulers. */
|
|
25
|
-
insetTop: number
|
|
26
|
-
insetLeft: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface IssueMarkerLayoutOptions {
|
|
30
|
-
pageId: string
|
|
31
|
-
view: IssueMarkerView
|
|
32
|
-
/** Layers whose markers would cover an active edit, such as the text being typed. */
|
|
33
|
-
suppressedIds?: ReadonlySet<string>
|
|
34
|
-
preview?: RotationPreview | null
|
|
35
|
-
measureText: (text: string) => number
|
|
36
|
-
/** Screen rectangles of UI floating over the canvas, such as a toolbar, to keep pins clear of. */
|
|
37
|
-
obstacles?: readonly Rect[]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const SEVERITY_RANK: Record<DesignIssueSeverity, number> = { error: 3, warning: 2, info: 1 }
|
|
41
|
-
|
|
42
|
-
export function issueSeverityRank(severity: DesignIssueSeverity): number {
|
|
43
|
-
return SEVERITY_RANK[severity]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function issueMarkerLabel(count: number): string {
|
|
47
|
-
if (count <= 1) return '!'
|
|
48
|
-
return count > ISSUE_MARKER_MAX_COUNT ? `${ISSUE_MARKER_MAX_COUNT}+` : String(count)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function issueMarkerWidth(count: number, measureText: (text: string) => number): number {
|
|
52
|
-
const textWidth = measureText(issueMarkerLabel(count))
|
|
53
|
-
return Math.max(ISSUE_MARKER_HEIGHT, Math.ceil(textWidth + ISSUE_MARKER_PADDING_X * 2))
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function intersect(a: Rect, b: Rect): Rect | null {
|
|
57
|
-
const x = Math.max(a.x, b.x)
|
|
58
|
-
const y = Math.max(a.y, b.y)
|
|
59
|
-
const right = Math.min(a.x + a.width, b.x + b.width)
|
|
60
|
-
const bottom = Math.min(a.y + a.height, b.y + b.height)
|
|
61
|
-
if (right < x || bottom < y) return null
|
|
62
|
-
return { x, y, width: right - x, height: bottom - y }
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function overlaps(a: Rect, b: Rect, gap: number): boolean {
|
|
66
|
-
return (
|
|
67
|
-
a.x < b.x + b.width + gap &&
|
|
68
|
-
b.x < a.x + a.width + gap &&
|
|
69
|
-
a.y < b.y + b.height + gap &&
|
|
70
|
-
b.y < a.y + a.height + gap
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function screenBounds(
|
|
75
|
-
node: SceneNode,
|
|
76
|
-
geometry: ReturnType<typeof createSceneGeometry>,
|
|
77
|
-
view: ViewportTransform
|
|
78
|
-
): Rect {
|
|
79
|
-
const points = Matrix.mapPoints(geometry.screenMatrix(node, view), [
|
|
80
|
-
0,
|
|
81
|
-
0,
|
|
82
|
-
node.width,
|
|
83
|
-
0,
|
|
84
|
-
node.width,
|
|
85
|
-
node.height,
|
|
86
|
-
0,
|
|
87
|
-
node.height
|
|
88
|
-
])
|
|
89
|
-
let minX = Infinity
|
|
90
|
-
let minY = Infinity
|
|
91
|
-
let maxX = -Infinity
|
|
92
|
-
let maxY = -Infinity
|
|
93
|
-
for (let index = 0; index < points.length; index += 2) {
|
|
94
|
-
minX = Math.min(minX, points[index])
|
|
95
|
-
maxX = Math.max(maxX, points[index])
|
|
96
|
-
minY = Math.min(minY, points[index + 1])
|
|
97
|
-
maxY = Math.max(maxY, points[index + 1])
|
|
98
|
-
}
|
|
99
|
-
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* The screen rectangle a layer's marker attaches to, or null when the layer should not be marked.
|
|
104
|
-
*
|
|
105
|
-
* Hidden and clipped-out layers stay listed in the panel but get no marker, so a marker never
|
|
106
|
-
* points at empty canvas. A layer too small to point at on screen hands its marker to the nearest
|
|
107
|
-
* ancestor that is large enough, so zoomed-out designs gather markers at frame corners instead of
|
|
108
|
-
* scattering them over detail that cannot be seen.
|
|
109
|
-
*/
|
|
110
|
-
function markerTarget(
|
|
111
|
-
graph: SceneGraph,
|
|
112
|
-
node: SceneNode,
|
|
113
|
-
pageId: string,
|
|
114
|
-
geometry: ReturnType<typeof createSceneGeometry>,
|
|
115
|
-
view: ViewportTransform
|
|
116
|
-
): Rect | null {
|
|
117
|
-
const chain: SceneNode[] = []
|
|
118
|
-
let current: SceneNode | undefined = node
|
|
119
|
-
while (current) {
|
|
120
|
-
if (!current.visible) return null
|
|
121
|
-
chain.push(current)
|
|
122
|
-
if (current.parentId === pageId) break
|
|
123
|
-
current = current.parentId ? graph.getNode(current.parentId) : undefined
|
|
124
|
-
}
|
|
125
|
-
if (!current) return null
|
|
126
|
-
|
|
127
|
-
// Clip each layer's bounds by the clipping ancestors above it, walking top-down. A clipping
|
|
128
|
-
// layer that is entirely clipped away hides everything inside it.
|
|
129
|
-
const visible = Array.from<Rect | null>({ length: chain.length })
|
|
130
|
-
let clip: Rect | null = null
|
|
131
|
-
for (let index = chain.length - 1; index >= 0; index--) {
|
|
132
|
-
const layer = chain[index]
|
|
133
|
-
const bounds = screenBounds(layer, geometry, view)
|
|
134
|
-
const clipped: Rect | null = clip ? intersect(bounds, clip) : bounds
|
|
135
|
-
visible[index] = clipped
|
|
136
|
-
if (!layer.clipsContent) continue
|
|
137
|
-
if (!clipped) return null
|
|
138
|
-
clip = clipped
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (!visible[0]) return null
|
|
142
|
-
for (let index = 0; index < chain.length; index++) {
|
|
143
|
-
const bounds = visible[index]
|
|
144
|
-
if (!bounds) continue
|
|
145
|
-
const last = index === chain.length - 1
|
|
146
|
-
if (last || Math.max(bounds.width, bounds.height) >= ISSUE_MARKER_MIN_TARGET) return bounds
|
|
147
|
-
}
|
|
148
|
-
return visible[0]
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
interface Candidate {
|
|
152
|
-
marker: DesignIssueMarker
|
|
153
|
-
anchor: Vector
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
interface EdgeCandidate {
|
|
157
|
-
marker: DesignIssueMarker
|
|
158
|
-
/** Where the ray toward the layer leaves the viewport. */
|
|
159
|
-
point: Vector
|
|
160
|
-
direction: Vector
|
|
161
|
-
distance: number
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Where the ray from the viewport center toward a layer leaves `area`, so an off-screen issue
|
|
166
|
-
* is pinned in its own direction, on a side or in a corner.
|
|
167
|
-
*/
|
|
168
|
-
function edgePoint(
|
|
169
|
-
area: Rect,
|
|
170
|
-
target: Vector
|
|
171
|
-
): { point: Vector; direction: Vector; distance: number } {
|
|
172
|
-
const center = { x: area.x + area.width / 2, y: area.y + area.height / 2 }
|
|
173
|
-
const dx = target.x - center.x
|
|
174
|
-
const dy = target.y - center.y
|
|
175
|
-
const distance = Math.hypot(dx, dy) || 1
|
|
176
|
-
const direction = { x: dx / distance, y: dy / distance }
|
|
177
|
-
const tx = direction.x === 0 ? Infinity : area.width / 2 / Math.abs(direction.x)
|
|
178
|
-
const ty = direction.y === 0 ? Infinity : area.height / 2 / Math.abs(direction.y)
|
|
179
|
-
const t = Math.min(tx, ty)
|
|
180
|
-
return {
|
|
181
|
-
point: { x: center.x + direction.x * t, y: center.y + direction.y * t },
|
|
182
|
-
direction,
|
|
183
|
-
distance
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** Slides a pin along the edge it sits on until it no longer covers floating UI. */
|
|
188
|
-
function avoidObstacles(rect: Rect, area: Rect, obstacles: readonly Rect[]): Rect {
|
|
189
|
-
let placed = rect
|
|
190
|
-
for (const obstacle of obstacles) {
|
|
191
|
-
if (!overlaps(placed, obstacle, ISSUE_MARKER_GAP)) continue
|
|
192
|
-
const onHorizontalEdge =
|
|
193
|
-
placed.y <= area.y + 1 || placed.y + placed.height >= area.y + area.height - 1
|
|
194
|
-
if (onHorizontalEdge) {
|
|
195
|
-
const left = obstacle.x - ISSUE_MARKER_GAP - placed.width
|
|
196
|
-
const right = obstacle.x + obstacle.width + ISSUE_MARKER_GAP
|
|
197
|
-
const x =
|
|
198
|
-
Math.abs(left - placed.x) <= Math.abs(right - placed.x) && left >= area.x
|
|
199
|
-
? left
|
|
200
|
-
: Math.min(right, area.x + area.width - placed.width)
|
|
201
|
-
placed = { ...placed, x }
|
|
202
|
-
} else {
|
|
203
|
-
const above = obstacle.y - ISSUE_MARKER_GAP - placed.height
|
|
204
|
-
const below = obstacle.y + obstacle.height + ISSUE_MARKER_GAP
|
|
205
|
-
const y =
|
|
206
|
-
Math.abs(above - placed.y) <= Math.abs(below - placed.y) && above >= area.y
|
|
207
|
-
? above
|
|
208
|
-
: Math.min(below, area.y + area.height - placed.height)
|
|
209
|
-
placed = { ...placed, y }
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return placed
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Pins issues outside the viewport to its edge, in their direction. Pins near each other along
|
|
217
|
-
* the edge merge, keeping the most severe; each lists its layers most severe first, then
|
|
218
|
-
* nearest, so following a pin reaches the closest issue of the severity it shows.
|
|
219
|
-
*/
|
|
220
|
-
function layoutEdgePins(
|
|
221
|
-
candidates: EdgeCandidate[],
|
|
222
|
-
area: Rect,
|
|
223
|
-
obstacles: readonly Rect[],
|
|
224
|
-
measureText: (text: string) => number
|
|
225
|
-
): PlacedIssueMarker[] {
|
|
226
|
-
candidates.sort(
|
|
227
|
-
(a, b) =>
|
|
228
|
-
SEVERITY_RANK[b.marker.severity] - SEVERITY_RANK[a.marker.severity] || a.distance - b.distance
|
|
229
|
-
)
|
|
230
|
-
const rectAt = (point: Vector, count: number): Rect => {
|
|
231
|
-
const width = issueMarkerWidth(count, measureText)
|
|
232
|
-
const x = Math.min(Math.max(point.x - width / 2, area.x), area.x + area.width - width)
|
|
233
|
-
const y = Math.min(
|
|
234
|
-
Math.max(point.y - ISSUE_MARKER_HEIGHT / 2, area.y),
|
|
235
|
-
area.y + area.height - ISSUE_MARKER_HEIGHT
|
|
236
|
-
)
|
|
237
|
-
const rect = { x: Math.round(x), y: Math.round(y), width, height: ISSUE_MARKER_HEIGHT }
|
|
238
|
-
return avoidObstacles(rect, area, obstacles)
|
|
239
|
-
}
|
|
240
|
-
type Pin = PlacedIssueMarker & { point: Vector; order: Map<string, [number, number]> }
|
|
241
|
-
const pins: Pin[] = []
|
|
242
|
-
for (const { marker, point, direction, distance } of candidates) {
|
|
243
|
-
const rect = rectAt(point, marker.count)
|
|
244
|
-
const pin = pins.find((existing) => overlaps(existing.rect, rect, ISSUE_EDGE_MERGE_GAP))
|
|
245
|
-
if (pin) {
|
|
246
|
-
pin.nodeIds.push(marker.nodeId)
|
|
247
|
-
pin.order.set(marker.nodeId, [SEVERITY_RANK[marker.severity], distance])
|
|
248
|
-
pin.count += marker.count
|
|
249
|
-
pin.rect = rectAt(pin.point, pin.count)
|
|
250
|
-
continue
|
|
251
|
-
}
|
|
252
|
-
pins.push({
|
|
253
|
-
key: `edge:${marker.nodeId}`,
|
|
254
|
-
nodeIds: [marker.nodeId],
|
|
255
|
-
severity: marker.severity,
|
|
256
|
-
count: marker.count,
|
|
257
|
-
rect,
|
|
258
|
-
anchor: point,
|
|
259
|
-
direction,
|
|
260
|
-
point,
|
|
261
|
-
order: new Map([[marker.nodeId, [SEVERITY_RANK[marker.severity], distance]]])
|
|
262
|
-
})
|
|
263
|
-
}
|
|
264
|
-
const rank = (order: Pin['order'], id: string) => order.get(id) ?? [0, 0]
|
|
265
|
-
return pins.map(({ point: _point, order, ...pin }) => ({
|
|
266
|
-
...pin,
|
|
267
|
-
nodeIds: pin.nodeIds.toSorted((a, b) => {
|
|
268
|
-
const [severityA, distanceA] = rank(order, a)
|
|
269
|
-
const [severityB, distanceB] = rank(order, b)
|
|
270
|
-
return severityB - severityA || distanceA - distanceB
|
|
271
|
-
})
|
|
272
|
-
}))
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Places one marker at the outer top-right corner of each marked layer, then merges markers that
|
|
277
|
-
* would overlap. Merging keeps the position of the most severe marker, so the canvas never shows
|
|
278
|
-
* a warning on top of an error it hides.
|
|
279
|
-
*/
|
|
280
|
-
export function layoutIssueMarkers(
|
|
281
|
-
graph: SceneGraph,
|
|
282
|
-
markers: readonly DesignIssueMarker[],
|
|
283
|
-
options: IssueMarkerLayoutOptions
|
|
284
|
-
): PlacedIssueMarker[] {
|
|
285
|
-
const { view, pageId, suppressedIds, measureText } = options
|
|
286
|
-
const geometry = createSceneGeometry(graph, options.preview)
|
|
287
|
-
const viewport: Rect = {
|
|
288
|
-
x: view.insetLeft,
|
|
289
|
-
y: view.insetTop,
|
|
290
|
-
width: Math.max(0, view.width - view.insetLeft),
|
|
291
|
-
height: Math.max(0, view.height - view.insetTop)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const candidates: Candidate[] = []
|
|
295
|
-
const edgeCandidates: EdgeCandidate[] = []
|
|
296
|
-
// Edge pins keep room between themselves and the edge for the chevron they point with.
|
|
297
|
-
const edgeInset = ISSUE_MARKER_VIEWPORT_INSET + ISSUE_EDGE_ARROW + ISSUE_MARKER_RING_WIDTH * 2
|
|
298
|
-
const edgeArea: Rect = {
|
|
299
|
-
x: viewport.x + edgeInset,
|
|
300
|
-
y: viewport.y + edgeInset,
|
|
301
|
-
width: Math.max(0, viewport.width - edgeInset * 2),
|
|
302
|
-
height: Math.max(0, viewport.height - edgeInset * 2)
|
|
303
|
-
}
|
|
304
|
-
for (const marker of markers) {
|
|
305
|
-
if (marker.count <= 0 || suppressedIds?.has(marker.nodeId)) continue
|
|
306
|
-
const node = graph.getNode(marker.nodeId)
|
|
307
|
-
if (!node) continue
|
|
308
|
-
const bounds = markerTarget(graph, node, pageId, geometry, view)
|
|
309
|
-
if (!bounds) continue
|
|
310
|
-
if (intersect(bounds, viewport)) {
|
|
311
|
-
candidates.push({ marker, anchor: { x: bounds.x + bounds.width, y: bounds.y } })
|
|
312
|
-
continue
|
|
313
|
-
}
|
|
314
|
-
const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 }
|
|
315
|
-
edgeCandidates.push({ marker, ...edgePoint(edgeArea, center) })
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
candidates.sort(
|
|
319
|
-
(a, b) =>
|
|
320
|
-
SEVERITY_RANK[b.marker.severity] - SEVERITY_RANK[a.marker.severity] ||
|
|
321
|
-
a.anchor.y - b.anchor.y ||
|
|
322
|
-
b.anchor.x - a.anchor.x
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
const minX = viewport.x + ISSUE_MARKER_VIEWPORT_INSET
|
|
326
|
-
const minY = viewport.y + ISSUE_MARKER_VIEWPORT_INSET
|
|
327
|
-
const maxRight = view.width - ISSUE_MARKER_VIEWPORT_INSET
|
|
328
|
-
const maxBottom = view.height - ISSUE_MARKER_VIEWPORT_INSET
|
|
329
|
-
|
|
330
|
-
function rectAt(anchor: Vector, count: number): Rect {
|
|
331
|
-
const width = issueMarkerWidth(count, measureText)
|
|
332
|
-
const x = Math.min(Math.max(anchor.x + ISSUE_MARKER_OFFSET, minX), maxRight - width)
|
|
333
|
-
const y = Math.min(
|
|
334
|
-
Math.max(anchor.y - ISSUE_MARKER_OFFSET - ISSUE_MARKER_HEIGHT, minY),
|
|
335
|
-
maxBottom - ISSUE_MARKER_HEIGHT
|
|
336
|
-
)
|
|
337
|
-
return { x: Math.round(x), y: Math.round(y), width, height: ISSUE_MARKER_HEIGHT }
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const placed: PlacedIssueMarker[] = []
|
|
341
|
-
for (const { marker, anchor } of candidates) {
|
|
342
|
-
const rect = rectAt(anchor, marker.count)
|
|
343
|
-
const target = placed.find((existing) => overlaps(existing.rect, rect, ISSUE_MARKER_GAP))
|
|
344
|
-
if (target) {
|
|
345
|
-
target.nodeIds.push(marker.nodeId)
|
|
346
|
-
target.count += marker.count
|
|
347
|
-
target.rect = rectAt(target.anchor, target.count)
|
|
348
|
-
continue
|
|
349
|
-
}
|
|
350
|
-
placed.push({
|
|
351
|
-
key: marker.nodeId,
|
|
352
|
-
nodeIds: [marker.nodeId],
|
|
353
|
-
severity: marker.severity,
|
|
354
|
-
count: marker.count,
|
|
355
|
-
rect,
|
|
356
|
-
anchor
|
|
357
|
-
})
|
|
358
|
-
}
|
|
359
|
-
const edgePins = layoutEdgePins(edgeCandidates, edgeArea, options.obstacles ?? [], measureText)
|
|
360
|
-
return [...placed, ...edgePins]
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/** Topmost marker under a screen point; markers placed first are drawn on top. */
|
|
364
|
-
export function hitTestIssueMarkers(
|
|
365
|
-
placed: readonly PlacedIssueMarker[],
|
|
366
|
-
x: number,
|
|
367
|
-
y: number
|
|
368
|
-
): PlacedIssueMarker | null {
|
|
369
|
-
for (const marker of placed) {
|
|
370
|
-
const { rect } = marker
|
|
371
|
-
if (x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height) {
|
|
372
|
-
return marker
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
return null
|
|
376
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Canvas } from 'canvaskit-wasm'
|
|
2
|
-
|
|
3
|
-
import type { SceneGraph } from '@pairdraw/scene-graph'
|
|
4
|
-
|
|
5
|
-
import { drawNodeHighlightRect } from '#core/canvas/highlight-rect'
|
|
6
|
-
import type { SkiaRenderer } from '#core/canvas/renderer'
|
|
7
|
-
import {
|
|
8
|
-
AI_ACTIVE_COLOR,
|
|
9
|
-
AI_DONE_COLOR,
|
|
10
|
-
AI_PULSE_PERIOD_MS,
|
|
11
|
-
AI_DONE_DURATION_MS
|
|
12
|
-
} from '#core/constants'
|
|
13
|
-
|
|
14
|
-
export function drawAIOverlays(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph): void {
|
|
15
|
-
const now = performance.now()
|
|
16
|
-
|
|
17
|
-
for (const nodeId of r._aiActiveNodes) {
|
|
18
|
-
const phase = (now % AI_PULSE_PERIOD_MS) / AI_PULSE_PERIOD_MS
|
|
19
|
-
const opacity = 0.3 + 0.5 * (0.5 + 0.5 * Math.sin(phase * Math.PI * 2))
|
|
20
|
-
drawNodeHighlightRect(r, canvas, graph, nodeId, AI_ACTIVE_COLOR, opacity)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
for (let i = r._aiDoneFlashes.length - 1; i >= 0; i--) {
|
|
24
|
-
const flash = r._aiDoneFlashes[i]
|
|
25
|
-
const elapsed = now - flash.startTime
|
|
26
|
-
if (elapsed > AI_DONE_DURATION_MS) {
|
|
27
|
-
r._aiDoneFlashes.splice(i, 1)
|
|
28
|
-
continue
|
|
29
|
-
}
|
|
30
|
-
const t = elapsed / AI_DONE_DURATION_MS
|
|
31
|
-
const opacity = t < 0.3 ? t / 0.3 : 1 - (t - 0.3) / 0.7
|
|
32
|
-
drawNodeHighlightRect(r, canvas, graph, flash.nodeId, AI_DONE_COLOR, opacity)
|
|
33
|
-
}
|
|
34
|
-
}
|