@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.
Files changed (145) hide show
  1. package/README.md +1 -1
  2. package/dist/ai/providers.d.ts +6 -1
  3. package/dist/ai/providers.d.ts.map +1 -1
  4. package/dist/ai/providers.js +9 -0
  5. package/dist/ai/providers.js.map +1 -1
  6. package/dist/canvas/highlight-rect.d.ts +10 -1
  7. package/dist/canvas/highlight-rect.d.ts.map +1 -1
  8. package/dist/canvas/highlight-rect.js +16 -8
  9. package/dist/canvas/highlight-rect.js.map +1 -1
  10. package/dist/canvas/index.d.ts +2 -3
  11. package/dist/canvas/index.js +1 -2
  12. package/dist/canvas/issues/draw.d.ts +2 -6
  13. package/dist/canvas/issues/draw.d.ts.map +1 -1
  14. package/dist/canvas/issues/draw.js +2 -99
  15. package/dist/canvas/issues/draw.js.map +1 -1
  16. package/dist/canvas/issues/types.d.ts +2 -33
  17. package/dist/canvas/issues/types.d.ts.map +1 -1
  18. package/dist/canvas/overlays/{ai.d.ts → ai/draw.d.ts} +3 -3
  19. package/dist/canvas/overlays/ai/draw.d.ts.map +1 -0
  20. package/dist/canvas/overlays/ai/draw.js +102 -0
  21. package/dist/canvas/overlays/ai/draw.js.map +1 -0
  22. package/dist/canvas/overlays/ai/motion.d.ts +23 -0
  23. package/dist/canvas/overlays/ai/motion.d.ts.map +1 -0
  24. package/dist/canvas/overlays/ai/motion.js +32 -0
  25. package/dist/canvas/overlays/ai/motion.js.map +1 -0
  26. package/dist/canvas/renderer/methods.js +1 -1
  27. package/dist/canvas/renderer/methods.js.map +1 -1
  28. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  29. package/dist/canvas/renderer/overlay-pass.js +2 -47
  30. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  31. package/dist/canvas/renderer/pipeline.js +1 -1
  32. package/dist/canvas/renderer/pipeline.js.map +1 -1
  33. package/dist/canvas/renderer/state.d.ts +5 -3
  34. package/dist/canvas/renderer/state.d.ts.map +1 -1
  35. package/dist/canvas/renderer/state.js +18 -6
  36. package/dist/canvas/renderer/state.js.map +1 -1
  37. package/dist/canvas/renderer/types.d.ts +2 -2
  38. package/dist/canvas/renderer/types.d.ts.map +1 -1
  39. package/dist/canvas/renderer.d.ts +12 -8
  40. package/dist/canvas/renderer.d.ts.map +1 -1
  41. package/dist/canvas/renderer.js +9 -9
  42. package/dist/canvas/renderer.js.map +1 -1
  43. package/dist/canvas/text/preparation/cache.d.ts +5 -0
  44. package/dist/canvas/text/preparation/cache.d.ts.map +1 -1
  45. package/dist/canvas/text/preparation/cache.js +8 -1
  46. package/dist/canvas/text/preparation/cache.js.map +1 -1
  47. package/dist/constants.d.ts +13 -18
  48. package/dist/constants.d.ts.map +1 -1
  49. package/dist/constants.js +16 -21
  50. package/dist/constants.js.map +1 -1
  51. package/dist/design-jsx/index.d.ts +2 -2
  52. package/dist/design-jsx/index.js +2 -2
  53. package/dist/design-jsx/preview/picture.d.ts +12 -5
  54. package/dist/design-jsx/preview/picture.d.ts.map +1 -1
  55. package/dist/design-jsx/preview/picture.js +40 -15
  56. package/dist/design-jsx/preview/picture.js.map +1 -1
  57. package/dist/editor/bridges/undo.d.ts +1 -1
  58. package/dist/editor/create.d.ts +3 -6
  59. package/dist/editor/create.d.ts.map +1 -1
  60. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  61. package/dist/editor/history/atomic-tool.js +11 -8
  62. package/dist/editor/history/atomic-tool.js.map +1 -1
  63. package/dist/editor/history/document-change.d.ts +9 -1
  64. package/dist/editor/history/document-change.d.ts.map +1 -1
  65. package/dist/editor/history/document-change.js +100 -2
  66. package/dist/editor/history/document-change.js.map +1 -1
  67. package/dist/editor/history/snapshot/graph.d.ts +15 -3
  68. package/dist/editor/history/snapshot/graph.d.ts.map +1 -1
  69. package/dist/editor/history/snapshot/graph.js +29 -8
  70. package/dist/editor/history/snapshot/graph.js.map +1 -1
  71. package/dist/editor/index.d.ts +3 -3
  72. package/dist/editor/index.js +3 -3
  73. package/dist/editor/issues.d.ts +1 -4
  74. package/dist/editor/issues.d.ts.map +1 -1
  75. package/dist/editor/issues.js +5 -44
  76. package/dist/editor/issues.js.map +1 -1
  77. package/dist/editor/nudge.js +3 -2
  78. package/dist/editor/nudge.js.map +1 -1
  79. package/dist/editor/read-only/actions.js +0 -3
  80. package/dist/editor/read-only/actions.js.map +1 -1
  81. package/dist/editor/state/shared.js +1 -1
  82. package/dist/editor/state/shared.js.map +1 -1
  83. package/dist/editor/types.d.ts +7 -4
  84. package/dist/editor/types.d.ts.map +1 -1
  85. package/dist/index.d.ts +3 -3
  86. package/dist/index.js +3 -3
  87. package/dist/io/subgraph.d.ts +5 -2
  88. package/dist/io/subgraph.d.ts.map +1 -1
  89. package/dist/io/subgraph.js +6 -2
  90. package/dist/io/subgraph.js.map +1 -1
  91. package/dist/layout/mutations.d.ts +1 -1
  92. package/dist/layout/mutations.d.ts.map +1 -1
  93. package/dist/layout/mutations.js +1 -1
  94. package/dist/layout/mutations.js.map +1 -1
  95. package/dist/text/font/faces.js +1 -1
  96. package/dist/text/font/faces.js.map +1 -1
  97. package/dist/text/web-font/providers.d.ts +2 -11
  98. package/dist/text/web-font/providers.d.ts.map +1 -1
  99. package/dist/text/web-font/providers.js +8 -7
  100. package/dist/text/web-font/providers.js.map +1 -1
  101. package/dist/tools/analyze/diff/jsx.d.ts +2 -1
  102. package/dist/tools/analyze/diff/jsx.d.ts.map +1 -1
  103. package/dist/tools/analyze/diff/jsx.js +4 -2
  104. package/dist/tools/analyze/diff/jsx.js.map +1 -1
  105. package/package.json +24 -9
  106. package/src/ai/providers.ts +15 -1
  107. package/src/canvas/highlight-rect.ts +30 -9
  108. package/src/canvas/index.ts +1 -15
  109. package/src/canvas/issues/draw.ts +2 -165
  110. package/src/canvas/issues/types.ts +1 -36
  111. package/src/canvas/overlays/ai/draw.ts +129 -0
  112. package/src/canvas/overlays/ai/motion.ts +46 -0
  113. package/src/canvas/renderer/methods.ts +1 -1
  114. package/src/canvas/renderer/overlay-pass.ts +2 -49
  115. package/src/canvas/renderer/pipeline.ts +1 -1
  116. package/src/canvas/renderer/state.ts +20 -5
  117. package/src/canvas/renderer/types.ts +2 -2
  118. package/src/canvas/renderer.ts +9 -10
  119. package/src/canvas/text/preparation/cache.ts +9 -1
  120. package/src/constants.ts +12 -17
  121. package/src/design-jsx/index.ts +1 -1
  122. package/src/design-jsx/preview/picture.ts +55 -18
  123. package/src/editor/history/atomic-tool.ts +15 -8
  124. package/src/editor/history/document-change.ts +117 -1
  125. package/src/editor/history/snapshot/graph.ts +48 -8
  126. package/src/editor/index.ts +10 -2
  127. package/src/editor/issues.ts +6 -36
  128. package/src/editor/nudge.ts +4 -2
  129. package/src/editor/read-only/actions.ts +0 -3
  130. package/src/editor/state/shared.ts +1 -1
  131. package/src/editor/types.ts +6 -4
  132. package/src/io/subgraph.ts +10 -5
  133. package/src/layout/mutations.ts +2 -2
  134. package/src/text/font/faces.ts +1 -1
  135. package/src/text/web-font/providers.ts +19 -13
  136. package/src/tools/analyze/diff/jsx.ts +10 -5
  137. package/dist/canvas/issues/layout.d.ts +0 -37
  138. package/dist/canvas/issues/layout.d.ts.map +0 -1
  139. package/dist/canvas/issues/layout.js +0 -303
  140. package/dist/canvas/issues/layout.js.map +0 -1
  141. package/dist/canvas/overlays/ai.d.ts.map +0 -1
  142. package/dist/canvas/overlays/ai.js +0 -26
  143. package/dist/canvas/overlays/ai.js.map +0 -1
  144. package/src/canvas/issues/layout.ts +0 -376
  145. package/src/canvas/overlays/ai.ts +0 -34
@@ -11,13 +11,14 @@ import type {
11
11
  VectorVertex
12
12
  } from '@pairdraw/scene-graph'
13
13
  import type { CanvasGuide } from '@pairdraw/scene-graph/guides'
14
+ import type { SceneMutationImpact } from '@pairdraw/scene-graph/mutation-impact'
14
15
  import type { Color, Rect, Vector } from '@pairdraw/scene-graph/primitives'
15
16
  import type { ShapeWithTextType } from '@pairdraw/scene-graph/shape-with-text'
16
17
  import type { SnapGuide } from '@pairdraw/scene-graph/snap'
17
18
  import type { UndoManager } from '@pairdraw/scene-graph/undo'
18
19
 
19
20
  import type { GuideOverlayState } from '#core/canvas/guides/types'
20
- import type { DesignIssueOverlay } from '#core/canvas/issues/types'
21
+ import type { DesignIssueHighlight } from '#core/canvas/issues/types'
21
22
  import type { RulerTheme, SkiaRenderer } from '#core/canvas/renderer'
22
23
  import type {
23
24
  MeasurementMode,
@@ -106,8 +107,8 @@ export interface EditorSharedState {
106
107
  imageEdit?: ImageEdit | null
107
108
  presenceCursors: PresenceCursor[]
108
109
  documentName: string
109
- /** Design check markers and highlight, shared by every canvas pane. */
110
- designIssues: DesignIssueOverlay | null
110
+ /** The layer a design check issue points at, highlighted in every canvas pane. */
111
+ designIssueHighlight: DesignIssueHighlight | null
111
112
  /** The layer of the code element around the cursor in a code editor, shown in every pane. */
112
113
  codeFocusNodeId: string | null
113
114
  rulerTheme?: RulerTheme
@@ -319,7 +320,8 @@ export interface EditorContext {
319
320
  runMutationWithLayout: <T>(
320
321
  operation: () => T | Promise<T>,
321
322
  fallbackId?: string,
322
- beforeLayout?: (result: T) => Promise<void> | void
323
+ /** Runs once the operation is done and before layout, with the layers it touched. */
324
+ beforeLayout?: (result: T, impact: SceneMutationImpact) => Promise<void> | void
323
325
  ) => Promise<T>
324
326
  subscribeToGraph: () => void
325
327
  }
@@ -36,6 +36,8 @@ function includeReferencedStyles(source: SceneGraph, ids: Set<string>): void {
36
36
  if (styleId) referencedStyleIds.add(styleId)
37
37
  }
38
38
  }
39
+ // Style definitions can sit anywhere in the document; only layers that use one need the search.
40
+ if (referencedStyleIds.size === 0) return
39
41
  for (const node of source.getAllNodes()) {
40
42
  if (node.sharedStyleType && node.source.id && referencedStyleIds.has(node.source.id)) {
41
43
  ids.add(node.id)
@@ -262,7 +264,7 @@ function ancestorChain(source: SceneGraph, id: string): string[] {
262
264
 
263
265
  function collectSelectionIds(
264
266
  source: SceneGraph,
265
- nodeIds: string[],
267
+ nodeIds: readonly string[],
266
268
  options: ExtractOptions = {}
267
269
  ): Set<string> {
268
270
  const ids = new Set<string>([source.rootId])
@@ -302,15 +304,18 @@ function rootNodeIds(source: SceneGraph): Set<string> {
302
304
  return ids
303
305
  }
304
306
 
305
- /** Clone `pageId` with only the subtrees of `nodeIds` (none keeps an empty page) and their dependencies. */
307
+ /**
308
+ * Clone `pageId`, or each of several pages, with only the subtrees of `nodeIds` (none keeps an
309
+ * empty page) and their dependencies.
310
+ */
306
311
  export function extractPageContext(
307
312
  source: SceneGraph,
308
- pageId: string,
309
- nodeIds: string[],
313
+ pageId: string | readonly string[],
314
+ nodeIds: readonly string[],
310
315
  options: ExtractOptions = {}
311
316
  ): SceneGraph {
312
317
  const ids = collectSelectionIds(source, nodeIds, options)
313
- ids.add(pageId)
318
+ for (const id of typeof pageId === 'string' ? [pageId] : pageId) ids.add(id)
314
319
  return cloneIntoGraph(source, ids, options)
315
320
  }
316
321
 
@@ -43,11 +43,11 @@ export function createLayoutRunner(getGraph: () => SceneGraph) {
43
43
  async function runMutationWithLayout<T>(
44
44
  operation: () => T | Promise<T>,
45
45
  fallbackId?: string,
46
- beforeLayout?: (result: T) => Promise<void> | void
46
+ beforeLayout?: (result: T, impact: SceneMutationImpact) => Promise<void> | void
47
47
  ): Promise<T> {
48
48
  const graph = getGraph()
49
49
  const { result, impact } = await collectSceneMutation(graph, operation)
50
- await beforeLayout?.(result)
50
+ await beforeLayout?.(result, impact)
51
51
  if (!runLayoutForImpact(impact) && fallbackId) computeAllLayouts(graph, fallbackId)
52
52
  return result
53
53
  }
@@ -86,5 +86,5 @@ export function fontFaceFromFigmaFontName(fontName: {
86
86
  }
87
87
 
88
88
  export function fontFaceRenderFamily(family: string, style: string): string {
89
- return `__op_font__${family.replace(/[^a-z0-9_-]+/giu, '_')}__${style.replace(/[^a-z0-9_-]+/giu, '_')}`
89
+ return `__pairdraw_font__${family.replace(/[^a-z0-9_-]+/giu, '_')}__${style.replace(/[^a-z0-9_-]+/giu, '_')}`
90
90
  }
@@ -1,10 +1,9 @@
1
- import {
2
- createUnifont,
1
+ import type {
2
+ GoogleFamilyOptions,
3
3
  providers,
4
- type GoogleFamilyOptions,
5
- type RemoteFontSource,
6
- type ResolveFontOptions,
7
- type Unifont
4
+ RemoteFontSource,
5
+ ResolveFontOptions,
6
+ Unifont
8
7
  } from 'unifont'
9
8
 
10
9
  import type { WebFontProviderId } from '#core/text/web-font/resolver'
@@ -23,21 +22,28 @@ export type WebFontResolveOptions = Pick<
23
22
  'weights' | 'styles' | 'formats' | 'subsets' | 'variableAxis' | 'options'
24
23
  >
25
24
 
25
+ type UnifontProviders = typeof providers
26
+
26
27
  /**
27
28
  * The unifont providers behind each provider setting. Google serves its Material Symbols from
28
29
  * its icon catalogue, as variable fonts with every axis, so its setting covers both.
29
30
  */
30
- export const providerFactories = {
31
- google: (): WebFontProviders => [providers.google(), providers.googleicons()],
32
- fontsource: (): WebFontProviders => [providers.fontsource()],
33
- bunny: (): WebFontProviders => [providers.bunny()],
34
- fontshare: (): WebFontProviders => [providers.fontshare()]
35
- } satisfies Record<WebFontProviderId, () => WebFontProviders>
31
+ const providerFactories = {
32
+ google: (from: UnifontProviders): WebFontProviders => [from.google(), from.googleicons()],
33
+ fontsource: (from: UnifontProviders): WebFontProviders => [from.fontsource()],
34
+ bunny: (from: UnifontProviders): WebFontProviders => [from.bunny()],
35
+ fontshare: (from: UnifontProviders): WebFontProviders => [from.fontshare()]
36
+ } satisfies Record<WebFontProviderId, (from: UnifontProviders) => WebFontProviders>
36
37
 
38
+ /** Unifont, with its CSS parser, loads with the first font looked up rather than with the editor. */
37
39
  export async function createProviderUnifont(provider: WebFontProviderId): Promise<WebUnifont> {
40
+ const { createUnifont, providers: unifontProviders } = await import('unifont')
38
41
  // In a page unifont sends provider requests to its hosted proxy; ours go through the host's
39
42
  // fetch, which reaches the providers itself.
40
- return createUnifont(providerFactories[provider](), { throwOnError: false, apiBase: false })
43
+ return createUnifont(providerFactories[provider](unifontProviders), {
44
+ throwOnError: false,
45
+ apiBase: false
46
+ })
41
47
  }
42
48
 
43
49
  export function isRemoteFontSource(
@@ -35,16 +35,21 @@ function layerJSX(graph: SceneGraph, id: string): string {
35
35
  /**
36
36
  * Top-level layers of a page whose JSX differs between two states of a document, in their
37
37
  * order afterwards, then removed ones. Both graphs must share node IDs, as a snapshot does.
38
+ * `layerIds` limits the comparison to those top-level layers, such as the ones an edit touched.
38
39
  */
39
40
  export function diffPageLayersJSX(
40
41
  before: SceneGraph,
41
42
  after: SceneGraph,
42
- pageId: string
43
+ pageId: string,
44
+ layerIds?: readonly string[]
43
45
  ): LayerJSXChange[] {
44
- const ids = new Set([
45
- ...(after.getNode(pageId)?.childIds ?? []),
46
- ...(before.getNode(pageId)?.childIds ?? [])
47
- ])
46
+ const only = layerIds ? new Set(layerIds) : null
47
+ const ids = new Set(
48
+ [
49
+ ...(after.getNode(pageId)?.childIds ?? []),
50
+ ...(before.getNode(pageId)?.childIds ?? [])
51
+ ].filter((id) => !only || only.has(id))
52
+ )
48
53
  return [...ids].flatMap((id) => {
49
54
  const from = layerJSX(before, id)
50
55
  const to = layerJSX(after, id)
@@ -1,37 +0,0 @@
1
- import { DesignIssueMarker, DesignIssueSeverity, PlacedIssueMarker } from "./types.js";
2
- import { RotationPreview, ViewportTransform } from "../../geometry/types.js";
3
- import "../../geometry/index.js";
4
- import { SceneGraph } from "@pairdraw/scene-graph";
5
- import { Rect } from "@pairdraw/scene-graph/primitives";
6
- //#region src/canvas/issues/layout.d.ts
7
- interface IssueMarkerView extends ViewportTransform {
8
- width: number;
9
- height: number;
10
- /** Space taken by chrome along the top and left edges, such as rulers. */
11
- insetTop: number;
12
- insetLeft: number;
13
- }
14
- interface IssueMarkerLayoutOptions {
15
- pageId: string;
16
- view: IssueMarkerView;
17
- /** Layers whose markers would cover an active edit, such as the text being typed. */
18
- suppressedIds?: ReadonlySet<string>;
19
- preview?: RotationPreview | null;
20
- measureText: (text: string) => number;
21
- /** Screen rectangles of UI floating over the canvas, such as a toolbar, to keep pins clear of. */
22
- obstacles?: readonly Rect[];
23
- }
24
- declare function issueSeverityRank(severity: DesignIssueSeverity): number;
25
- declare function issueMarkerLabel(count: number): string;
26
- declare function issueMarkerWidth(count: number, measureText: (text: string) => number): number;
27
- /**
28
- * Places one marker at the outer top-right corner of each marked layer, then merges markers that
29
- * would overlap. Merging keeps the position of the most severe marker, so the canvas never shows
30
- * a warning on top of an error it hides.
31
- */
32
- declare function layoutIssueMarkers(graph: SceneGraph, markers: readonly DesignIssueMarker[], options: IssueMarkerLayoutOptions): PlacedIssueMarker[];
33
- /** Topmost marker under a screen point; markers placed first are drawn on top. */
34
- declare function hitTestIssueMarkers(placed: readonly PlacedIssueMarker[], x: number, y: number): PlacedIssueMarker | null;
35
- //#endregion
36
- export { IssueMarkerLayoutOptions, IssueMarkerView, hitTestIssueMarkers, issueMarkerLabel, issueMarkerWidth, issueSeverityRank, layoutIssueMarkers };
37
- //# sourceMappingURL=layout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layout.d.ts","names":[],"sources":["../../../src/canvas/issues/layout.ts"],"mappings":";;;;;;UAoBiB,wBAAwB;EACvC;EACA;;EAEA;EACA;;UAGe;EACf;EACA,MAAM;;EAEN,gBAAgB;EAChB,UAAU;EACV,cAAc;;EAEd,qBAAqB;;iBAKP,kBAAkB,UAAU;iBAI5B,iBAAiB;iBAKjB,iBAAiB,eAAe,cAAc;;;;;;iBAqO9C,mBACd,OAAO,YACP,kBAAkB,qBAClB,SAAS,2BACR;;iBAgFa,oBACd,iBAAiB,qBACjB,WACA,YACC"}
@@ -1,303 +0,0 @@
1
- import { ISSUE_MARKER_RING_WIDTH } from "../../constants.js";
2
- import { createSceneGeometry } from "../../geometry/scene.js";
3
- import Matrix from "@pairdraw/scene-graph/matrix";
4
- //#region src/canvas/issues/layout.ts
5
- const SEVERITY_RANK = {
6
- error: 3,
7
- warning: 2,
8
- info: 1
9
- };
10
- function issueSeverityRank(severity) {
11
- return SEVERITY_RANK[severity];
12
- }
13
- function issueMarkerLabel(count) {
14
- if (count <= 1) return "!";
15
- return count > 99 ? `99+` : String(count);
16
- }
17
- function issueMarkerWidth(count, measureText) {
18
- const textWidth = measureText(issueMarkerLabel(count));
19
- return Math.max(16, Math.ceil(textWidth + 10));
20
- }
21
- function intersect(a, b) {
22
- const x = Math.max(a.x, b.x);
23
- const y = Math.max(a.y, b.y);
24
- const right = Math.min(a.x + a.width, b.x + b.width);
25
- const bottom = Math.min(a.y + a.height, b.y + b.height);
26
- if (right < x || bottom < y) return null;
27
- return {
28
- x,
29
- y,
30
- width: right - x,
31
- height: bottom - y
32
- };
33
- }
34
- function overlaps(a, b, gap) {
35
- return a.x < b.x + b.width + gap && b.x < a.x + a.width + gap && a.y < b.y + b.height + gap && b.y < a.y + a.height + gap;
36
- }
37
- function screenBounds(node, geometry, view) {
38
- const points = Matrix.mapPoints(geometry.screenMatrix(node, view), [
39
- 0,
40
- 0,
41
- node.width,
42
- 0,
43
- node.width,
44
- node.height,
45
- 0,
46
- node.height
47
- ]);
48
- let minX = Infinity;
49
- let minY = Infinity;
50
- let maxX = -Infinity;
51
- let maxY = -Infinity;
52
- for (let index = 0; index < points.length; index += 2) {
53
- minX = Math.min(minX, points[index]);
54
- maxX = Math.max(maxX, points[index]);
55
- minY = Math.min(minY, points[index + 1]);
56
- maxY = Math.max(maxY, points[index + 1]);
57
- }
58
- return {
59
- x: minX,
60
- y: minY,
61
- width: maxX - minX,
62
- height: maxY - minY
63
- };
64
- }
65
- /**
66
- * The screen rectangle a layer's marker attaches to, or null when the layer should not be marked.
67
- *
68
- * Hidden and clipped-out layers stay listed in the panel but get no marker, so a marker never
69
- * points at empty canvas. A layer too small to point at on screen hands its marker to the nearest
70
- * ancestor that is large enough, so zoomed-out designs gather markers at frame corners instead of
71
- * scattering them over detail that cannot be seen.
72
- */
73
- function markerTarget(graph, node, pageId, geometry, view) {
74
- const chain = [];
75
- let current = node;
76
- while (current) {
77
- if (!current.visible) return null;
78
- chain.push(current);
79
- if (current.parentId === pageId) break;
80
- current = current.parentId ? graph.getNode(current.parentId) : void 0;
81
- }
82
- if (!current) return null;
83
- const visible = Array.from({ length: chain.length });
84
- let clip = null;
85
- for (let index = chain.length - 1; index >= 0; index--) {
86
- const layer = chain[index];
87
- const bounds = screenBounds(layer, geometry, view);
88
- const clipped = clip ? intersect(bounds, clip) : bounds;
89
- visible[index] = clipped;
90
- if (!layer.clipsContent) continue;
91
- if (!clipped) return null;
92
- clip = clipped;
93
- }
94
- if (!visible[0]) return null;
95
- for (let index = 0; index < chain.length; index++) {
96
- const bounds = visible[index];
97
- if (!bounds) continue;
98
- if (index === chain.length - 1 || Math.max(bounds.width, bounds.height) >= 24) return bounds;
99
- }
100
- return visible[0];
101
- }
102
- /**
103
- * Where the ray from the viewport center toward a layer leaves `area`, so an off-screen issue
104
- * is pinned in its own direction, on a side or in a corner.
105
- */
106
- function edgePoint(area, target) {
107
- const center = {
108
- x: area.x + area.width / 2,
109
- y: area.y + area.height / 2
110
- };
111
- const dx = target.x - center.x;
112
- const dy = target.y - center.y;
113
- const distance = Math.hypot(dx, dy) || 1;
114
- const direction = {
115
- x: dx / distance,
116
- y: dy / distance
117
- };
118
- const tx = direction.x === 0 ? Infinity : area.width / 2 / Math.abs(direction.x);
119
- const ty = direction.y === 0 ? Infinity : area.height / 2 / Math.abs(direction.y);
120
- const t = Math.min(tx, ty);
121
- return {
122
- point: {
123
- x: center.x + direction.x * t,
124
- y: center.y + direction.y * t
125
- },
126
- direction,
127
- distance
128
- };
129
- }
130
- /** Slides a pin along the edge it sits on until it no longer covers floating UI. */
131
- function avoidObstacles(rect, area, obstacles) {
132
- let placed = rect;
133
- for (const obstacle of obstacles) {
134
- if (!overlaps(placed, obstacle, 2)) continue;
135
- if (placed.y <= area.y + 1 || placed.y + placed.height >= area.y + area.height - 1) {
136
- const left = obstacle.x - 2 - placed.width;
137
- const right = obstacle.x + obstacle.width + 2;
138
- const x = Math.abs(left - placed.x) <= Math.abs(right - placed.x) && left >= area.x ? left : Math.min(right, area.x + area.width - placed.width);
139
- placed = {
140
- ...placed,
141
- x
142
- };
143
- } else {
144
- const above = obstacle.y - 2 - placed.height;
145
- const below = obstacle.y + obstacle.height + 2;
146
- const y = Math.abs(above - placed.y) <= Math.abs(below - placed.y) && above >= area.y ? above : Math.min(below, area.y + area.height - placed.height);
147
- placed = {
148
- ...placed,
149
- y
150
- };
151
- }
152
- }
153
- return placed;
154
- }
155
- /**
156
- * Pins issues outside the viewport to its edge, in their direction. Pins near each other along
157
- * the edge merge, keeping the most severe; each lists its layers most severe first, then
158
- * nearest, so following a pin reaches the closest issue of the severity it shows.
159
- */
160
- function layoutEdgePins(candidates, area, obstacles, measureText) {
161
- candidates.sort((a, b) => SEVERITY_RANK[b.marker.severity] - SEVERITY_RANK[a.marker.severity] || a.distance - b.distance);
162
- const rectAt = (point, count) => {
163
- const width = issueMarkerWidth(count, measureText);
164
- const x = Math.min(Math.max(point.x - width / 2, area.x), area.x + area.width - width);
165
- const y = Math.min(Math.max(point.y - 8, area.y), area.y + area.height - 16);
166
- return avoidObstacles({
167
- x: Math.round(x),
168
- y: Math.round(y),
169
- width,
170
- height: 16
171
- }, area, obstacles);
172
- };
173
- const pins = [];
174
- for (const { marker, point, direction, distance } of candidates) {
175
- const rect = rectAt(point, marker.count);
176
- const pin = pins.find((existing) => overlaps(existing.rect, rect, 24));
177
- if (pin) {
178
- pin.nodeIds.push(marker.nodeId);
179
- pin.order.set(marker.nodeId, [SEVERITY_RANK[marker.severity], distance]);
180
- pin.count += marker.count;
181
- pin.rect = rectAt(pin.point, pin.count);
182
- continue;
183
- }
184
- pins.push({
185
- key: `edge:${marker.nodeId}`,
186
- nodeIds: [marker.nodeId],
187
- severity: marker.severity,
188
- count: marker.count,
189
- rect,
190
- anchor: point,
191
- direction,
192
- point,
193
- order: /* @__PURE__ */ new Map([[marker.nodeId, [SEVERITY_RANK[marker.severity], distance]]])
194
- });
195
- }
196
- const rank = (order, id) => order.get(id) ?? [0, 0];
197
- return pins.map(({ point: _point, order, ...pin }) => ({
198
- ...pin,
199
- nodeIds: pin.nodeIds.toSorted((a, b) => {
200
- const [severityA, distanceA] = rank(order, a);
201
- const [severityB, distanceB] = rank(order, b);
202
- return severityB - severityA || distanceA - distanceB;
203
- })
204
- }));
205
- }
206
- /**
207
- * Places one marker at the outer top-right corner of each marked layer, then merges markers that
208
- * would overlap. Merging keeps the position of the most severe marker, so the canvas never shows
209
- * a warning on top of an error it hides.
210
- */
211
- function layoutIssueMarkers(graph, markers, options) {
212
- const { view, pageId, suppressedIds, measureText } = options;
213
- const geometry = createSceneGeometry(graph, options.preview);
214
- const viewport = {
215
- x: view.insetLeft,
216
- y: view.insetTop,
217
- width: Math.max(0, view.width - view.insetLeft),
218
- height: Math.max(0, view.height - view.insetTop)
219
- };
220
- const candidates = [];
221
- const edgeCandidates = [];
222
- const edgeInset = 9 + ISSUE_MARKER_RING_WIDTH * 2;
223
- const edgeArea = {
224
- x: viewport.x + edgeInset,
225
- y: viewport.y + edgeInset,
226
- width: Math.max(0, viewport.width - edgeInset * 2),
227
- height: Math.max(0, viewport.height - edgeInset * 2)
228
- };
229
- for (const marker of markers) {
230
- if (marker.count <= 0 || suppressedIds?.has(marker.nodeId)) continue;
231
- const node = graph.getNode(marker.nodeId);
232
- if (!node) continue;
233
- const bounds = markerTarget(graph, node, pageId, geometry, view);
234
- if (!bounds) continue;
235
- if (intersect(bounds, viewport)) {
236
- candidates.push({
237
- marker,
238
- anchor: {
239
- x: bounds.x + bounds.width,
240
- y: bounds.y
241
- }
242
- });
243
- continue;
244
- }
245
- const center = {
246
- x: bounds.x + bounds.width / 2,
247
- y: bounds.y + bounds.height / 2
248
- };
249
- edgeCandidates.push({
250
- marker,
251
- ...edgePoint(edgeArea, center)
252
- });
253
- }
254
- candidates.sort((a, b) => SEVERITY_RANK[b.marker.severity] - SEVERITY_RANK[a.marker.severity] || a.anchor.y - b.anchor.y || b.anchor.x - a.anchor.x);
255
- const minX = viewport.x + 4;
256
- const minY = viewport.y + 4;
257
- const maxRight = view.width - 4;
258
- const maxBottom = view.height - 4;
259
- function rectAt(anchor, count) {
260
- const width = issueMarkerWidth(count, measureText);
261
- const x = Math.min(Math.max(anchor.x + 4, minX), maxRight - width);
262
- const y = Math.min(Math.max(anchor.y - 4 - 16, minY), maxBottom - 16);
263
- return {
264
- x: Math.round(x),
265
- y: Math.round(y),
266
- width,
267
- height: 16
268
- };
269
- }
270
- const placed = [];
271
- for (const { marker, anchor } of candidates) {
272
- const rect = rectAt(anchor, marker.count);
273
- const target = placed.find((existing) => overlaps(existing.rect, rect, 2));
274
- if (target) {
275
- target.nodeIds.push(marker.nodeId);
276
- target.count += marker.count;
277
- target.rect = rectAt(target.anchor, target.count);
278
- continue;
279
- }
280
- placed.push({
281
- key: marker.nodeId,
282
- nodeIds: [marker.nodeId],
283
- severity: marker.severity,
284
- count: marker.count,
285
- rect,
286
- anchor
287
- });
288
- }
289
- const edgePins = layoutEdgePins(edgeCandidates, edgeArea, options.obstacles ?? [], measureText);
290
- return [...placed, ...edgePins];
291
- }
292
- /** Topmost marker under a screen point; markers placed first are drawn on top. */
293
- function hitTestIssueMarkers(placed, x, y) {
294
- for (const marker of placed) {
295
- const { rect } = marker;
296
- if (x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height) return marker;
297
- }
298
- return null;
299
- }
300
- //#endregion
301
- export { hitTestIssueMarkers, issueMarkerLabel, issueMarkerWidth, issueSeverityRank, layoutIssueMarkers };
302
-
303
- //# sourceMappingURL=layout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layout.js","names":[],"sources":["../../../src/canvas/issues/layout.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport type { Rect, Vector } from '@pairdraw/scene-graph/primitives'\n\nimport {\n ISSUE_EDGE_ARROW,\n ISSUE_EDGE_MERGE_GAP,\n ISSUE_MARKER_GAP,\n ISSUE_MARKER_HEIGHT,\n ISSUE_MARKER_MAX_COUNT,\n ISSUE_MARKER_MIN_TARGET,\n ISSUE_MARKER_OFFSET,\n ISSUE_MARKER_PADDING_X,\n ISSUE_MARKER_RING_WIDTH,\n ISSUE_MARKER_VIEWPORT_INSET\n} from '#core/constants'\nimport { createSceneGeometry, type RotationPreview, type ViewportTransform } from '#core/geometry'\n\nimport type { DesignIssueMarker, DesignIssueSeverity, PlacedIssueMarker } from './types'\n\nexport interface IssueMarkerView extends ViewportTransform {\n width: number\n height: number\n /** Space taken by chrome along the top and left edges, such as rulers. */\n insetTop: number\n insetLeft: number\n}\n\nexport interface IssueMarkerLayoutOptions {\n pageId: string\n view: IssueMarkerView\n /** Layers whose markers would cover an active edit, such as the text being typed. */\n suppressedIds?: ReadonlySet<string>\n preview?: RotationPreview | null\n measureText: (text: string) => number\n /** Screen rectangles of UI floating over the canvas, such as a toolbar, to keep pins clear of. */\n obstacles?: readonly Rect[]\n}\n\nconst SEVERITY_RANK: Record<DesignIssueSeverity, number> = { error: 3, warning: 2, info: 1 }\n\nexport function issueSeverityRank(severity: DesignIssueSeverity): number {\n return SEVERITY_RANK[severity]\n}\n\nexport function issueMarkerLabel(count: number): string {\n if (count <= 1) return '!'\n return count > ISSUE_MARKER_MAX_COUNT ? `${ISSUE_MARKER_MAX_COUNT}+` : String(count)\n}\n\nexport function issueMarkerWidth(count: number, measureText: (text: string) => number): number {\n const textWidth = measureText(issueMarkerLabel(count))\n return Math.max(ISSUE_MARKER_HEIGHT, Math.ceil(textWidth + ISSUE_MARKER_PADDING_X * 2))\n}\n\nfunction intersect(a: Rect, b: Rect): Rect | null {\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n const right = Math.min(a.x + a.width, b.x + b.width)\n const bottom = Math.min(a.y + a.height, b.y + b.height)\n if (right < x || bottom < y) return null\n return { x, y, width: right - x, height: bottom - y }\n}\n\nfunction overlaps(a: Rect, b: Rect, gap: number): boolean {\n return (\n a.x < b.x + b.width + gap &&\n b.x < a.x + a.width + gap &&\n a.y < b.y + b.height + gap &&\n b.y < a.y + a.height + gap\n )\n}\n\nfunction screenBounds(\n node: SceneNode,\n geometry: ReturnType<typeof createSceneGeometry>,\n view: ViewportTransform\n): Rect {\n const points = Matrix.mapPoints(geometry.screenMatrix(node, view), [\n 0,\n 0,\n node.width,\n 0,\n node.width,\n node.height,\n 0,\n node.height\n ])\n let minX = Infinity\n let minY = Infinity\n let maxX = -Infinity\n let maxY = -Infinity\n for (let index = 0; index < points.length; index += 2) {\n minX = Math.min(minX, points[index])\n maxX = Math.max(maxX, points[index])\n minY = Math.min(minY, points[index + 1])\n maxY = Math.max(maxY, points[index + 1])\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }\n}\n\n/**\n * The screen rectangle a layer's marker attaches to, or null when the layer should not be marked.\n *\n * Hidden and clipped-out layers stay listed in the panel but get no marker, so a marker never\n * points at empty canvas. A layer too small to point at on screen hands its marker to the nearest\n * ancestor that is large enough, so zoomed-out designs gather markers at frame corners instead of\n * scattering them over detail that cannot be seen.\n */\nfunction markerTarget(\n graph: SceneGraph,\n node: SceneNode,\n pageId: string,\n geometry: ReturnType<typeof createSceneGeometry>,\n view: ViewportTransform\n): Rect | null {\n const chain: SceneNode[] = []\n let current: SceneNode | undefined = node\n while (current) {\n if (!current.visible) return null\n chain.push(current)\n if (current.parentId === pageId) break\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n if (!current) return null\n\n // Clip each layer's bounds by the clipping ancestors above it, walking top-down. A clipping\n // layer that is entirely clipped away hides everything inside it.\n const visible = Array.from<Rect | null>({ length: chain.length })\n let clip: Rect | null = null\n for (let index = chain.length - 1; index >= 0; index--) {\n const layer = chain[index]\n const bounds = screenBounds(layer, geometry, view)\n const clipped: Rect | null = clip ? intersect(bounds, clip) : bounds\n visible[index] = clipped\n if (!layer.clipsContent) continue\n if (!clipped) return null\n clip = clipped\n }\n\n if (!visible[0]) return null\n for (let index = 0; index < chain.length; index++) {\n const bounds = visible[index]\n if (!bounds) continue\n const last = index === chain.length - 1\n if (last || Math.max(bounds.width, bounds.height) >= ISSUE_MARKER_MIN_TARGET) return bounds\n }\n return visible[0]\n}\n\ninterface Candidate {\n marker: DesignIssueMarker\n anchor: Vector\n}\n\ninterface EdgeCandidate {\n marker: DesignIssueMarker\n /** Where the ray toward the layer leaves the viewport. */\n point: Vector\n direction: Vector\n distance: number\n}\n\n/**\n * Where the ray from the viewport center toward a layer leaves `area`, so an off-screen issue\n * is pinned in its own direction, on a side or in a corner.\n */\nfunction edgePoint(\n area: Rect,\n target: Vector\n): { point: Vector; direction: Vector; distance: number } {\n const center = { x: area.x + area.width / 2, y: area.y + area.height / 2 }\n const dx = target.x - center.x\n const dy = target.y - center.y\n const distance = Math.hypot(dx, dy) || 1\n const direction = { x: dx / distance, y: dy / distance }\n const tx = direction.x === 0 ? Infinity : area.width / 2 / Math.abs(direction.x)\n const ty = direction.y === 0 ? Infinity : area.height / 2 / Math.abs(direction.y)\n const t = Math.min(tx, ty)\n return {\n point: { x: center.x + direction.x * t, y: center.y + direction.y * t },\n direction,\n distance\n }\n}\n\n/** Slides a pin along the edge it sits on until it no longer covers floating UI. */\nfunction avoidObstacles(rect: Rect, area: Rect, obstacles: readonly Rect[]): Rect {\n let placed = rect\n for (const obstacle of obstacles) {\n if (!overlaps(placed, obstacle, ISSUE_MARKER_GAP)) continue\n const onHorizontalEdge =\n placed.y <= area.y + 1 || placed.y + placed.height >= area.y + area.height - 1\n if (onHorizontalEdge) {\n const left = obstacle.x - ISSUE_MARKER_GAP - placed.width\n const right = obstacle.x + obstacle.width + ISSUE_MARKER_GAP\n const x =\n Math.abs(left - placed.x) <= Math.abs(right - placed.x) && left >= area.x\n ? left\n : Math.min(right, area.x + area.width - placed.width)\n placed = { ...placed, x }\n } else {\n const above = obstacle.y - ISSUE_MARKER_GAP - placed.height\n const below = obstacle.y + obstacle.height + ISSUE_MARKER_GAP\n const y =\n Math.abs(above - placed.y) <= Math.abs(below - placed.y) && above >= area.y\n ? above\n : Math.min(below, area.y + area.height - placed.height)\n placed = { ...placed, y }\n }\n }\n return placed\n}\n\n/**\n * Pins issues outside the viewport to its edge, in their direction. Pins near each other along\n * the edge merge, keeping the most severe; each lists its layers most severe first, then\n * nearest, so following a pin reaches the closest issue of the severity it shows.\n */\nfunction layoutEdgePins(\n candidates: EdgeCandidate[],\n area: Rect,\n obstacles: readonly Rect[],\n measureText: (text: string) => number\n): PlacedIssueMarker[] {\n candidates.sort(\n (a, b) =>\n SEVERITY_RANK[b.marker.severity] - SEVERITY_RANK[a.marker.severity] || a.distance - b.distance\n )\n const rectAt = (point: Vector, count: number): Rect => {\n const width = issueMarkerWidth(count, measureText)\n const x = Math.min(Math.max(point.x - width / 2, area.x), area.x + area.width - width)\n const y = Math.min(\n Math.max(point.y - ISSUE_MARKER_HEIGHT / 2, area.y),\n area.y + area.height - ISSUE_MARKER_HEIGHT\n )\n const rect = { x: Math.round(x), y: Math.round(y), width, height: ISSUE_MARKER_HEIGHT }\n return avoidObstacles(rect, area, obstacles)\n }\n type Pin = PlacedIssueMarker & { point: Vector; order: Map<string, [number, number]> }\n const pins: Pin[] = []\n for (const { marker, point, direction, distance } of candidates) {\n const rect = rectAt(point, marker.count)\n const pin = pins.find((existing) => overlaps(existing.rect, rect, ISSUE_EDGE_MERGE_GAP))\n if (pin) {\n pin.nodeIds.push(marker.nodeId)\n pin.order.set(marker.nodeId, [SEVERITY_RANK[marker.severity], distance])\n pin.count += marker.count\n pin.rect = rectAt(pin.point, pin.count)\n continue\n }\n pins.push({\n key: `edge:${marker.nodeId}`,\n nodeIds: [marker.nodeId],\n severity: marker.severity,\n count: marker.count,\n rect,\n anchor: point,\n direction,\n point,\n order: new Map([[marker.nodeId, [SEVERITY_RANK[marker.severity], distance]]])\n })\n }\n const rank = (order: Pin['order'], id: string) => order.get(id) ?? [0, 0]\n return pins.map(({ point: _point, order, ...pin }) => ({\n ...pin,\n nodeIds: pin.nodeIds.toSorted((a, b) => {\n const [severityA, distanceA] = rank(order, a)\n const [severityB, distanceB] = rank(order, b)\n return severityB - severityA || distanceA - distanceB\n })\n }))\n}\n\n/**\n * Places one marker at the outer top-right corner of each marked layer, then merges markers that\n * would overlap. Merging keeps the position of the most severe marker, so the canvas never shows\n * a warning on top of an error it hides.\n */\nexport function layoutIssueMarkers(\n graph: SceneGraph,\n markers: readonly DesignIssueMarker[],\n options: IssueMarkerLayoutOptions\n): PlacedIssueMarker[] {\n const { view, pageId, suppressedIds, measureText } = options\n const geometry = createSceneGeometry(graph, options.preview)\n const viewport: Rect = {\n x: view.insetLeft,\n y: view.insetTop,\n width: Math.max(0, view.width - view.insetLeft),\n height: Math.max(0, view.height - view.insetTop)\n }\n\n const candidates: Candidate[] = []\n const edgeCandidates: EdgeCandidate[] = []\n // Edge pins keep room between themselves and the edge for the chevron they point with.\n const edgeInset = ISSUE_MARKER_VIEWPORT_INSET + ISSUE_EDGE_ARROW + ISSUE_MARKER_RING_WIDTH * 2\n const edgeArea: Rect = {\n x: viewport.x + edgeInset,\n y: viewport.y + edgeInset,\n width: Math.max(0, viewport.width - edgeInset * 2),\n height: Math.max(0, viewport.height - edgeInset * 2)\n }\n for (const marker of markers) {\n if (marker.count <= 0 || suppressedIds?.has(marker.nodeId)) continue\n const node = graph.getNode(marker.nodeId)\n if (!node) continue\n const bounds = markerTarget(graph, node, pageId, geometry, view)\n if (!bounds) continue\n if (intersect(bounds, viewport)) {\n candidates.push({ marker, anchor: { x: bounds.x + bounds.width, y: bounds.y } })\n continue\n }\n const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 }\n edgeCandidates.push({ marker, ...edgePoint(edgeArea, center) })\n }\n\n candidates.sort(\n (a, b) =>\n SEVERITY_RANK[b.marker.severity] - SEVERITY_RANK[a.marker.severity] ||\n a.anchor.y - b.anchor.y ||\n b.anchor.x - a.anchor.x\n )\n\n const minX = viewport.x + ISSUE_MARKER_VIEWPORT_INSET\n const minY = viewport.y + ISSUE_MARKER_VIEWPORT_INSET\n const maxRight = view.width - ISSUE_MARKER_VIEWPORT_INSET\n const maxBottom = view.height - ISSUE_MARKER_VIEWPORT_INSET\n\n function rectAt(anchor: Vector, count: number): Rect {\n const width = issueMarkerWidth(count, measureText)\n const x = Math.min(Math.max(anchor.x + ISSUE_MARKER_OFFSET, minX), maxRight - width)\n const y = Math.min(\n Math.max(anchor.y - ISSUE_MARKER_OFFSET - ISSUE_MARKER_HEIGHT, minY),\n maxBottom - ISSUE_MARKER_HEIGHT\n )\n return { x: Math.round(x), y: Math.round(y), width, height: ISSUE_MARKER_HEIGHT }\n }\n\n const placed: PlacedIssueMarker[] = []\n for (const { marker, anchor } of candidates) {\n const rect = rectAt(anchor, marker.count)\n const target = placed.find((existing) => overlaps(existing.rect, rect, ISSUE_MARKER_GAP))\n if (target) {\n target.nodeIds.push(marker.nodeId)\n target.count += marker.count\n target.rect = rectAt(target.anchor, target.count)\n continue\n }\n placed.push({\n key: marker.nodeId,\n nodeIds: [marker.nodeId],\n severity: marker.severity,\n count: marker.count,\n rect,\n anchor\n })\n }\n const edgePins = layoutEdgePins(edgeCandidates, edgeArea, options.obstacles ?? [], measureText)\n return [...placed, ...edgePins]\n}\n\n/** Topmost marker under a screen point; markers placed first are drawn on top. */\nexport function hitTestIssueMarkers(\n placed: readonly PlacedIssueMarker[],\n x: number,\n y: number\n): PlacedIssueMarker | null {\n for (const marker of placed) {\n const { rect } = marker\n if (x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height) {\n return marker\n }\n }\n return null\n}\n"],"mappings":";;;;AAuCA,MAAM,gBAAqD;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;AAAE;AAE3F,SAAgB,kBAAkB,UAAuC;CACvE,OAAO,cAAc;AACvB;AAEA,SAAgB,iBAAiB,OAAuB;CACtD,IAAI,SAAS,GAAG,OAAO;CACvB,OAAO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QAAQ,KAAK,OAAO,MAAM;GACjC,OAAO,SAAS,OAAO;GACvB,OAAO,OAAO,OAAO,OAAO,QAAQ,OAAO,KAAK;GAChD;EACF;EACA,OAAO,KAAK;GACV,KAAK,OAAO;GACZ,SAAS,CAAC,OAAO,MAAM;GACvB,UAAU,OAAO;GACjB,OAAO,OAAO;GACd;GACA;EACF,CAAC;CACH;CACA,MAAM,WAAW,eAAe,gBAAgB,UAAU,QAAQ,aAAa,CAAC,GAAG,WAAW;CAC9F,OAAO,CAAC,GAAG,QAAQ,GAAG,QAAQ;AAChC;;AAGA,SAAgB,oBACd,QACA,GACA,GAC0B;CAC1B,KAAK,MAAM,UAAU,QAAQ;EAC3B,MAAM,EAAE,SAAS;EACjB,IAAI,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI,KAAK,SAAS,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI,KAAK,QAC/E,OAAO;CAEX;CACA,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai.d.ts","names":[],"sources":["../../../src/canvas/overlays/ai.ts"],"mappings":";;;;iBAagB,eAAe,GAAG,cAAc,QAAQ,QAAQ,OAAO"}
@@ -1,26 +0,0 @@
1
- import { AI_ACTIVE_COLOR, AI_DONE_COLOR, AI_PULSE_PERIOD_MS } from "../../constants.js";
2
- import { drawNodeHighlightRect } from "../highlight-rect.js";
3
- //#region src/canvas/overlays/ai.ts
4
- function drawAIOverlays(r, canvas, graph) {
5
- const now = performance.now();
6
- for (const nodeId of r._aiActiveNodes) {
7
- const phase = now % AI_PULSE_PERIOD_MS / AI_PULSE_PERIOD_MS;
8
- const opacity = .3 + .5 * (.5 + .5 * Math.sin(phase * Math.PI * 2));
9
- drawNodeHighlightRect(r, canvas, graph, nodeId, AI_ACTIVE_COLOR, opacity);
10
- }
11
- for (let i = r._aiDoneFlashes.length - 1; i >= 0; i--) {
12
- const flash = r._aiDoneFlashes[i];
13
- const elapsed = now - flash.startTime;
14
- if (elapsed > 800) {
15
- r._aiDoneFlashes.splice(i, 1);
16
- continue;
17
- }
18
- const t = elapsed / 800;
19
- const opacity = t < .3 ? t / .3 : 1 - (t - .3) / .7;
20
- drawNodeHighlightRect(r, canvas, graph, flash.nodeId, AI_DONE_COLOR, opacity);
21
- }
22
- }
23
- //#endregion
24
- export { drawAIOverlays };
25
-
26
- //# sourceMappingURL=ai.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai.js","names":[],"sources":["../../../src/canvas/overlays/ai.ts"],"sourcesContent":["import type { Canvas } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { drawNodeHighlightRect } from '#core/canvas/highlight-rect'\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport {\n AI_ACTIVE_COLOR,\n AI_DONE_COLOR,\n AI_PULSE_PERIOD_MS,\n AI_DONE_DURATION_MS\n} from '#core/constants'\n\nexport function drawAIOverlays(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph): void {\n const now = performance.now()\n\n for (const nodeId of r._aiActiveNodes) {\n const phase = (now % AI_PULSE_PERIOD_MS) / AI_PULSE_PERIOD_MS\n const opacity = 0.3 + 0.5 * (0.5 + 0.5 * Math.sin(phase * Math.PI * 2))\n drawNodeHighlightRect(r, canvas, graph, nodeId, AI_ACTIVE_COLOR, opacity)\n }\n\n for (let i = r._aiDoneFlashes.length - 1; i >= 0; i--) {\n const flash = r._aiDoneFlashes[i]\n const elapsed = now - flash.startTime\n if (elapsed > AI_DONE_DURATION_MS) {\n r._aiDoneFlashes.splice(i, 1)\n continue\n }\n const t = elapsed / AI_DONE_DURATION_MS\n const opacity = t < 0.3 ? t / 0.3 : 1 - (t - 0.3) / 0.7\n drawNodeHighlightRect(r, canvas, graph, flash.nodeId, AI_DONE_COLOR, opacity)\n }\n}\n"],"mappings":";;;AAaA,SAAgB,eAAe,GAAiB,QAAgB,OAAyB;CACvF,MAAM,MAAM,YAAY,IAAI;CAE5B,KAAK,MAAM,UAAU,EAAE,gBAAgB;EACrC,MAAM,QAAS,MAAM,qBAAsB;EAC3C,MAAM,UAAU,KAAM,MAAO,KAAM,KAAM,KAAK,IAAI,QAAQ,KAAK,KAAK,CAAC;EACrE,sBAAsB,GAAG,QAAQ,OAAO,QAAQ,iBAAiB,OAAO;CAC1E;CAEA,KAAK,IAAI,IAAI,EAAE,eAAe,SAAS,GAAG,KAAK,GAAG,KAAK;EACrD,MAAM,QAAQ,EAAE,eAAe;EAC/B,MAAM,UAAU,MAAM,MAAM;EAC5B,IAAI,UAAA,KAA+B;GACjC,EAAE,eAAe,OAAO,GAAG,CAAC;GAC5B;EACF;EACA,MAAM,IAAI,UAAA;EACV,MAAM,UAAU,IAAI,KAAM,IAAI,KAAM,KAAK,IAAI,MAAO;EACpD,sBAAsB,GAAG,QAAQ,OAAO,MAAM,QAAQ,eAAe,OAAO;CAC9E;AACF"}