docblocks-react-ui 0.32.0 → 0.33.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/CHANGELOG.md +68 -0
- package/dist/{Editor-DFPJA2hv.mjs → Editor-DoT9RYUJ.mjs} +1970 -722
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/mermaid/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -12066,6 +12066,15 @@ const EnumOptionsMotionSlot = createContext(null);
|
|
|
12066
12066
|
function useEnumOptionsMotion() {
|
|
12067
12067
|
return useContext(EnumOptionsMotionSlot);
|
|
12068
12068
|
}
|
|
12069
|
+
// src/editing/shortcut-letter.ts
|
|
12070
|
+
/** The letter the shortcut stands (lowercase), or null when the event stands none. */
|
|
12071
|
+
function shortcutLetter(event) {
|
|
12072
|
+
if (event.altKey === true) return null;
|
|
12073
|
+
const fromCode = /^Key([A-Z])$/.exec(event.code ?? "");
|
|
12074
|
+
if (fromCode !== null) return (fromCode[1] ?? "").toLowerCase();
|
|
12075
|
+
const key = event.key.toLowerCase();
|
|
12076
|
+
return /^[a-z]$/.test(key) ? key : null;
|
|
12077
|
+
}
|
|
12069
12078
|
// src/database/grid/grid-cell-actions.ts
|
|
12070
12079
|
/** Clears every selected cell in one bridge batch and one history entry;
|
|
12071
12080
|
* the system columns' cells stand read-only (the bridge owns their
|
|
@@ -12240,7 +12249,7 @@ async function writeDatabaseGridClipboard(clipboard) {
|
|
|
12240
12249
|
function handleGridCellKeyDown(event, ctx) {
|
|
12241
12250
|
const { tableId, refTableData, readOnly, rows, columns, locale, data, selectionFrame, editingCell, selectedCells, setSelectionFrame, setEditingCell } = ctx;
|
|
12242
12251
|
if (readOnly) return;
|
|
12243
|
-
if ((event.metaKey || event.ctrlKey) && !event.shiftKey && event
|
|
12252
|
+
if ((event.metaKey || event.ctrlKey) && !event.shiftKey && shortcutLetter(event) === "c") {
|
|
12244
12253
|
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
|
|
12245
12254
|
if (selectionFrame === null) return;
|
|
12246
12255
|
event.preventDefault();
|
|
@@ -12256,7 +12265,7 @@ function handleGridCellKeyDown(event, ctx) {
|
|
|
12256
12265
|
if (clipboard !== null) writeDatabaseGridClipboard(clipboard);
|
|
12257
12266
|
return;
|
|
12258
12267
|
}
|
|
12259
|
-
if ((event.metaKey || event.ctrlKey) && event
|
|
12268
|
+
if ((event.metaKey || event.ctrlKey) && shortcutLetter(event) === "z") {
|
|
12260
12269
|
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
|
|
12261
12270
|
event.preventDefault();
|
|
12262
12271
|
event.stopPropagation();
|
|
@@ -14178,186 +14187,6 @@ function darkStore() {
|
|
|
14178
14187
|
function useDarkTheme() {
|
|
14179
14188
|
return useStore(darkStore(), (state) => state.dark);
|
|
14180
14189
|
}
|
|
14181
|
-
/** The dark corridor's HSL stand: the lightness over the dark's (the
|
|
14182
|
-
* 20–30% band's middle), the saturation's drop (the pastel's stand — the
|
|
14183
|
-
* muted's, not the neon's). */
|
|
14184
|
-
const DARK_LIGHTNESS = .24;
|
|
14185
|
-
const DARK_SATURATION_SCALE = .55;
|
|
14186
|
-
const HEX_FILL_RE = /^#([0-9a-f]{3,8})$/i;
|
|
14187
|
-
/** The fixed hex's fill parse (`#rgb` / `#rrggbb` / `#rrggbbaa`, the
|
|
14188
|
-
* `#rgba`'s 8-digit's stand) — `null` over the non-hex (the `var()`'s
|
|
14189
|
-
* token's stand, the named's, the absence). */
|
|
14190
|
-
function parseHexFill(value) {
|
|
14191
|
-
const match = value.trim().match(HEX_FILL_RE);
|
|
14192
|
-
if (match === null) return null;
|
|
14193
|
-
const raw = match[1].toLowerCase();
|
|
14194
|
-
const is8 = raw.length === 8 || raw.length === 4;
|
|
14195
|
-
const hex = raw.length === 3 || raw.length === 4 ? raw.split("").map((c) => c + c).join("") : raw;
|
|
14196
|
-
const alpha = is8 ? Number.parseInt(hex.slice(6, 8), 16) : null;
|
|
14197
|
-
return {
|
|
14198
|
-
r: Number.parseInt(hex.slice(0, 2), 16),
|
|
14199
|
-
g: Number.parseInt(hex.slice(2, 4), 16),
|
|
14200
|
-
b: Number.parseInt(hex.slice(4, 6), 16),
|
|
14201
|
-
a: alpha === null ? null : alpha
|
|
14202
|
-
};
|
|
14203
|
-
}
|
|
14204
|
-
function toHexPair(value) {
|
|
14205
|
-
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
|
|
14206
|
-
}
|
|
14207
|
-
/** The WCAG's relative luminance (the 0..1's stand). */
|
|
14208
|
-
function relativeLuminance(r, g, b) {
|
|
14209
|
-
const channel = (value) => {
|
|
14210
|
-
const s = value / 255;
|
|
14211
|
-
return s <= .04045 ? s / 12.92 : Math.pow((s + .055) / 1.055, 2.4);
|
|
14212
|
-
};
|
|
14213
|
-
return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
|
|
14214
|
-
}
|
|
14215
|
-
/** The sRGB → HSL (the hue over the 0..360's, the lightness / saturation
|
|
14216
|
-
* over the 0..1's). */
|
|
14217
|
-
function rgbToHsl(r, g, b) {
|
|
14218
|
-
const rn = r / 255;
|
|
14219
|
-
const gn = g / 255;
|
|
14220
|
-
const bn = b / 255;
|
|
14221
|
-
const max = Math.max(rn, gn, bn);
|
|
14222
|
-
const min = Math.min(rn, gn, bn);
|
|
14223
|
-
const l = (max + min) / 2;
|
|
14224
|
-
if (max === min) return {
|
|
14225
|
-
h: 0,
|
|
14226
|
-
s: 0,
|
|
14227
|
-
l
|
|
14228
|
-
};
|
|
14229
|
-
const d = max - min;
|
|
14230
|
-
const s = l > .5 ? d / (2 - max - min) : d / (max + min);
|
|
14231
|
-
let h;
|
|
14232
|
-
if (max === rn) h = ((gn - bn) / d + (gn < bn ? 6 : 0)) * 60;
|
|
14233
|
-
else if (max === gn) h = ((bn - rn) / d + 2) * 60;
|
|
14234
|
-
else h = ((rn - gn) / d + 4) * 60;
|
|
14235
|
-
return {
|
|
14236
|
-
h,
|
|
14237
|
-
s,
|
|
14238
|
-
l
|
|
14239
|
-
};
|
|
14240
|
-
}
|
|
14241
|
-
/** The HSL → sRGB (the 0..255's channels). */
|
|
14242
|
-
function hslToRgb(h, s, l) {
|
|
14243
|
-
if (s === 0) {
|
|
14244
|
-
const v = l * 255;
|
|
14245
|
-
return {
|
|
14246
|
-
r: v,
|
|
14247
|
-
g: v,
|
|
14248
|
-
b: v
|
|
14249
|
-
};
|
|
14250
|
-
}
|
|
14251
|
-
const hue2rgb = (p, q, t) => {
|
|
14252
|
-
let tt = t;
|
|
14253
|
-
if (tt < 0) tt += 1;
|
|
14254
|
-
if (tt > 1) tt -= 1;
|
|
14255
|
-
if (tt < 1 / 6) return p + (q - p) * 6 * tt;
|
|
14256
|
-
if (tt < .5) return q;
|
|
14257
|
-
if (tt < 2 / 3) return p + (q - p) * (2 / 3 - tt) * 6;
|
|
14258
|
-
return p;
|
|
14259
|
-
};
|
|
14260
|
-
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
14261
|
-
const p = 2 * l - q;
|
|
14262
|
-
const hn = (h % 360 + 360) % 360 / 360;
|
|
14263
|
-
return {
|
|
14264
|
-
r: hue2rgb(p, q, hn + 1 / 3) * 255,
|
|
14265
|
-
g: hue2rgb(p, q, hn) * 255,
|
|
14266
|
-
b: hue2rgb(p, q, hn - 1 / 3) * 255
|
|
14267
|
-
};
|
|
14268
|
-
}
|
|
14269
|
-
/** The dark corridor's value over the light's hex (the hue's stand, the
|
|
14270
|
-
* lightness / saturation's stand); the hue-less's (the gray's) stands the
|
|
14271
|
-
* gray's dark (the `#FFFFFF`'s dark neutral's stand). The alpha's stand
|
|
14272
|
-
* (the present's 8-digit's stand over the computed's RGB). */
|
|
14273
|
-
function darkenHexHex(parts) {
|
|
14274
|
-
const { h, s } = rgbToHsl(parts.r, parts.g, parts.b);
|
|
14275
|
-
const rgb = hslToRgb(h, s * DARK_SATURATION_SCALE, DARK_LIGHTNESS);
|
|
14276
|
-
const hex = `#${toHexPair(rgb.r)}${toHexPair(rgb.g)}${toHexPair(rgb.b)}`;
|
|
14277
|
-
return parts.a === null ? hex : `${hex}${toHexPair(parts.a)}`;
|
|
14278
|
-
}
|
|
14279
|
-
/**
|
|
14280
|
-
* The effective data color (the render's stand): the dark theme's light
|
|
14281
|
-
* fixed hex stands the dark corridor's value; every other stand (the
|
|
14282
|
-
* light's theme, the dark's value, the non-hex) stands verbatim
|
|
14283
|
-
* (`undefined` stands the absence — the caller's default's stand).
|
|
14284
|
-
*/
|
|
14285
|
-
function effectiveColorOf(value, isDark) {
|
|
14286
|
-
if (value === void 0) return void 0;
|
|
14287
|
-
if (isDark) {
|
|
14288
|
-
const parts = parseHexFill(value);
|
|
14289
|
-
if (parts !== null && relativeLuminance(parts.r, parts.g, parts.b) > .2) return darkenHexHex(parts);
|
|
14290
|
-
}
|
|
14291
|
-
return value;
|
|
14292
|
-
}
|
|
14293
|
-
/**
|
|
14294
|
-
* The text's contrast over the effective fill (the WCAG's ratio's stand —
|
|
14295
|
-
* the black / white over the better). The explicit `textColor` stands
|
|
14296
|
-
* (the data's stand) — the caller's resolution. `null` over the
|
|
14297
|
-
* non-hex's effective fill (the theme's foreground's inheritance's stand)
|
|
14298
|
-
* and the absent's fill.
|
|
14299
|
-
*/
|
|
14300
|
-
function contrastTextOf(fill, isDark) {
|
|
14301
|
-
const effective = effectiveColorOf(fill, isDark);
|
|
14302
|
-
if (effective === void 0) return null;
|
|
14303
|
-
const parts = parseHexFill(effective);
|
|
14304
|
-
if (parts === null) return null;
|
|
14305
|
-
const luminance = relativeLuminance(parts.r, parts.g, parts.b);
|
|
14306
|
-
const ratioOverBlack = (luminance + .05) / .05;
|
|
14307
|
-
return 1.05 / (luminance + .05) >= ratioOverBlack ? "#ffffff" : "#000000";
|
|
14308
|
-
}
|
|
14309
|
-
// src/canvas/connector-constants.ts
|
|
14310
|
-
/** The canvas connector's render constants: the v1 connector stroke (the
|
|
14311
|
-
* shape token), the selected connector's stroke (the canvas selection's
|
|
14312
|
-
* cyan — the token stands in both themes; the page `--accent` is a hover
|
|
14313
|
-
* surface, not a line color), the connect badge's green (the endpoint
|
|
14314
|
-
* drag's port snap indicator), the line's stroke width bounds (canvas px;
|
|
14315
|
-
* the data stand is 1–4, the absent stand is 1 — the registry spec's
|
|
14316
|
-
* parity), the selection's width emphasis, the arrowhead's length (the marker's coordinate space), the
|
|
14317
|
-
* circle endpoint's radius, the connect badge's radius + its offset from
|
|
14318
|
-
* the snapped port along its outward normal. */
|
|
14319
|
-
const CONNECTOR_STROKE = "var(--docblocks-canvas-shape-stroke, currentColor)";
|
|
14320
|
-
/** The selected connector's stroke (the canvas selection's cyan — the
|
|
14321
|
-
* token stands in both themes; the page `--accent` is a hover surface,
|
|
14322
|
-
* not a line color). */
|
|
14323
|
-
const CONNECTOR_SELECTED_STROKE = "var(--docblocks-canvas-selected-stroke)";
|
|
14324
|
-
/** The connect badge's green (the endpoint drag's port snap indicator). */
|
|
14325
|
-
const CONNECT_COLOR = "var(--docblocks-canvas-connect-color, #16a34a)";
|
|
14326
|
-
// src/canvas/connector-utils.ts
|
|
14327
|
-
/**
|
|
14328
|
-
* The arrowhead def's id over the surface's id and the fill value (the
|
|
14329
|
-
* per-value def: the token / the selection's accent keep their legacy
|
|
14330
|
-
* ids, the data color stands its own id — the non-id characters are
|
|
14331
|
-
* dropped: a hex's "#" would break the url(#...) fragment).
|
|
14332
|
-
*/
|
|
14333
|
-
function arrowDefId(surfaceId, fill) {
|
|
14334
|
-
return `docblocks-conn-arrow-${surfaceId}${fill === "var(--docblocks-canvas-shape-stroke, currentColor)" ? "" : fill === "var(--docblocks-canvas-selected-stroke)" ? "-selected" : `-c${fill.replace(/[^a-z0-9]/gi, "")}`}`;
|
|
14335
|
-
}
|
|
14336
|
-
/** The line's effective width: the 1–4 data attr's clamp stand (the
|
|
14337
|
-
* lenient render over the raw write) + the selection's bump. The label
|
|
14338
|
-
* chip's frame reads the same stand (the frame stands the line). */
|
|
14339
|
-
function connectorStrokeWidthOf(attrs, selected) {
|
|
14340
|
-
const baseWidth = Math.min(4, Math.max(1, Math.round(attrs.strokeWidth ?? 1)));
|
|
14341
|
-
return selected ? baseWidth + 1 : baseWidth;
|
|
14342
|
-
}
|
|
14343
|
-
/** The connector's effective stroke: the selection's accent wins, the
|
|
14344
|
-
* data color (a hex) next, the token otherwise (the "none" color stands
|
|
14345
|
-
* the token — the line is still drawn, the paint is the theme's). */
|
|
14346
|
-
function connectorStrokeOf(block, selected) {
|
|
14347
|
-
const attrs = block.attrs;
|
|
14348
|
-
if (selected) return CONNECTOR_SELECTED_STROKE;
|
|
14349
|
-
if (attrs === void 0 || attrs.strokeColor === void 0 || attrs.strokeColor === "none") return CONNECTOR_STROKE;
|
|
14350
|
-
return attrs.strokeColor;
|
|
14351
|
-
}
|
|
14352
|
-
/** The connector's effective stroke over the themes (the render-time's
|
|
14353
|
-
* transform — the data stands the source hex): the dark theme's light
|
|
14354
|
-
* fixed `strokeColor` stands the dark corridor's value (the parity with
|
|
14355
|
-
* the shape's fill / stroke); the token's stands (the theme's default /
|
|
14356
|
-
* the selection's accent) stand pass-through on their own. */
|
|
14357
|
-
function effectiveConnectorStrokeOf(block, selected, isDark) {
|
|
14358
|
-
const stroke = connectorStrokeOf(block, selected);
|
|
14359
|
-
return effectiveColorOf(stroke, isDark) ?? stroke;
|
|
14360
|
-
}
|
|
14361
14190
|
// src/canvas/geometry/constants.ts
|
|
14362
14191
|
/** The canvas-only element types (they render ONLY inside a surface). */
|
|
14363
14192
|
const CANVAS_SUB_TYPES = [
|
|
@@ -14403,6 +14232,16 @@ function segmentAxisOf(from, to) {
|
|
|
14403
14232
|
if (from.y === to.y && from.x !== to.x) return "y";
|
|
14404
14233
|
return null;
|
|
14405
14234
|
}
|
|
14235
|
+
/** Whether the two consecutive runs (p→q and q→r) stand on one line (the
|
|
14236
|
+
* collinear middle): the shared vertex q's parallel move would tilt the
|
|
14237
|
+
* second run out of its line. A zero-length first run stands no direction
|
|
14238
|
+
* (the zero run bears no line to tilt). */
|
|
14239
|
+
function collinearRuns(p, q, r) {
|
|
14240
|
+
const d1x = q.x - p.x;
|
|
14241
|
+
const d1y = q.y - p.y;
|
|
14242
|
+
if (d1x === 0 && d1y === 0) return false;
|
|
14243
|
+
return d1x * (r.y - q.y) - d1y * (r.x - q.x) === 0;
|
|
14244
|
+
}
|
|
14406
14245
|
/** The point's distance to the segment (the press's pick's measure). */
|
|
14407
14246
|
function distanceToSegment(point, from, to) {
|
|
14408
14247
|
const dx = to.x - from.x;
|
|
@@ -14414,14 +14253,16 @@ function distanceToSegment(point, from, to) {
|
|
|
14414
14253
|
}
|
|
14415
14254
|
/**
|
|
14416
14255
|
* The route's segment nearest the point (the index over the vertices — the
|
|
14417
|
-
* segment `i` stands between `points[i]` and `points[i + 1]`): the
|
|
14418
|
-
*
|
|
14419
|
-
*
|
|
14256
|
+
* segment `i` stands between `points[i]` and `points[i + 1]`): the STUB's
|
|
14257
|
+
* runs (the first / the last segment — the port's attachment) stand the
|
|
14258
|
+
* PORT-ADJACENT run's pick (the press at the line's start / end drags the
|
|
14259
|
+
* line as near the figure — the adjacent run's parallel move's jog's stand),
|
|
14260
|
+
* so the pick stands the inner runs' indices only.
|
|
14420
14261
|
*/
|
|
14421
14262
|
function nearestSegmentOf(points, point, reach) {
|
|
14422
14263
|
let best = null;
|
|
14423
14264
|
let bestDistance = reach;
|
|
14424
|
-
for (let i =
|
|
14265
|
+
for (let i = 0; i < points.length - 1; i += 1) {
|
|
14425
14266
|
const from = points[i];
|
|
14426
14267
|
const to = points[i + 1];
|
|
14427
14268
|
if (from === void 0 || to === void 0) continue;
|
|
@@ -14432,6 +14273,8 @@ function nearestSegmentOf(points, point, reach) {
|
|
|
14432
14273
|
bestDistance = distance;
|
|
14433
14274
|
}
|
|
14434
14275
|
}
|
|
14276
|
+
if (best === 0) return 1;
|
|
14277
|
+
if (best === points.length - 2) return points.length - 3;
|
|
14435
14278
|
return best;
|
|
14436
14279
|
}
|
|
14437
14280
|
/** The point moved by `delta` along the run's movable axis. */
|
|
@@ -14445,30 +14288,69 @@ function shifted(point, axis, delta) {
|
|
|
14445
14288
|
};
|
|
14446
14289
|
}
|
|
14447
14290
|
/**
|
|
14448
|
-
* The route
|
|
14449
|
-
*
|
|
14450
|
-
*
|
|
14451
|
-
*
|
|
14452
|
-
*
|
|
14291
|
+
* The route's NEAREST point (the straight line's SEED press): the press's
|
|
14292
|
+
* point clamps to the route's own runs (the projection over the nearest
|
|
14293
|
+
* run, the run's end over the reach's tail), the run's index stands the
|
|
14294
|
+
* seed's INSERT position over the stored waypoints (the run `i` stands
|
|
14295
|
+
* between `route[i]` and `route[i+1]`, and the new waypoint lands at the
|
|
14296
|
+
* `points` index `i`). `null` over the reach's miss.
|
|
14453
14297
|
*/
|
|
14454
|
-
function
|
|
14298
|
+
function nearestRoutePointOf(route, point, reach) {
|
|
14299
|
+
let best = null;
|
|
14300
|
+
let bestDistance = reach;
|
|
14301
|
+
for (let i = 0; i < route.length - 1; i += 1) {
|
|
14302
|
+
const from = route[i];
|
|
14303
|
+
const to = route[i + 1];
|
|
14304
|
+
if (from === void 0 || to === void 0) continue;
|
|
14305
|
+
const dx = to.x - from.x;
|
|
14306
|
+
const dy = to.y - from.y;
|
|
14307
|
+
const lengthSq = dx * dx + dy * dy;
|
|
14308
|
+
const t = lengthSq === 0 ? 0 : Math.max(0, Math.min(1, ((point.x - from.x) * dx + (point.y - from.y) * dy) / lengthSq));
|
|
14309
|
+
const px = from.x + t * dx;
|
|
14310
|
+
const py = from.y + t * dy;
|
|
14311
|
+
const distance = Math.hypot(point.x - px, point.y - py);
|
|
14312
|
+
if (distance <= bestDistance) {
|
|
14313
|
+
best = {
|
|
14314
|
+
index: i,
|
|
14315
|
+
point: {
|
|
14316
|
+
x: px,
|
|
14317
|
+
y: py
|
|
14318
|
+
}
|
|
14319
|
+
};
|
|
14320
|
+
bestDistance = distance;
|
|
14321
|
+
}
|
|
14322
|
+
}
|
|
14323
|
+
return best;
|
|
14324
|
+
}
|
|
14325
|
+
/**
|
|
14326
|
+
* The route with the segment moved parallel by `delta`: the run's own
|
|
14327
|
+
* vertices take the new coordinate; a vertex that stands the port's
|
|
14328
|
+
* attachment (the route's stub end — the first / the last inner vertex) or
|
|
14329
|
+
* a COLLINEAR run keeps its place and a JOG vertex lands beside it, so the
|
|
14330
|
+
* line still leaves / enters the port along its normal and the collinear
|
|
14331
|
+
* neighbour's line stays orthogonal (the vertex moved out of its line would
|
|
14332
|
+
* tilt it). The port points themselves stand unchanged.
|
|
14333
|
+
*/
|
|
14334
|
+
function moveSegmentRoute(points, index, delta) {
|
|
14455
14335
|
const from = points[index];
|
|
14456
14336
|
const to = points[index + 1];
|
|
14457
14337
|
if (from === void 0 || to === void 0 || delta === 0) return [...points];
|
|
14458
14338
|
const axis = segmentAxisOf(from, to);
|
|
14459
14339
|
if (axis === null) return [...points];
|
|
14460
14340
|
if (index <= 0 || index >= points.length - 2) return [...points];
|
|
14461
|
-
const
|
|
14462
|
-
const
|
|
14341
|
+
const startFixed = index === 1 || collinearRuns(points[index - 1], from, to);
|
|
14342
|
+
const endFixed = index + 1 === points.length - 2 || collinearRuns(from, to, points[index + 2]);
|
|
14463
14343
|
const next = [];
|
|
14464
14344
|
for (let i = 0; i < points.length; i += 1) {
|
|
14345
|
+
if (i === index + 1) {
|
|
14346
|
+
if (startFixed) next.push(shifted(points[index], axis, delta));
|
|
14347
|
+
if (endFixed) next.push(shifted(points[index + 1], axis, delta));
|
|
14348
|
+
}
|
|
14465
14349
|
const point = { ...points[i] };
|
|
14466
|
-
if (i === index && !
|
|
14467
|
-
if (i === index + 1 && !
|
|
14468
|
-
if (startStub && i === 2) next.push(shifted(points[1], axis, delta));
|
|
14350
|
+
if (i === index && !startFixed) point[axis] += delta;
|
|
14351
|
+
if (i === index + 1 && !endFixed) point[axis] += delta;
|
|
14469
14352
|
next.push(point);
|
|
14470
14353
|
}
|
|
14471
|
-
if (endStub) next.splice(next.length - 2, 0, shifted(points[points.length - 2], axis, delta));
|
|
14472
14354
|
return next;
|
|
14473
14355
|
}
|
|
14474
14356
|
/**
|
|
@@ -14495,27 +14377,108 @@ function simplifyRoute(points) {
|
|
|
14495
14377
|
}
|
|
14496
14378
|
return simplified;
|
|
14497
14379
|
}
|
|
14498
|
-
/** The
|
|
14499
|
-
|
|
14500
|
-
|
|
14501
|
-
|
|
14502
|
-
|
|
14380
|
+
/** The non-diagonal guard (the axis-aligned run stands as committed). */
|
|
14381
|
+
const isDiagonal = (from, to) => from.x !== to.x && from.y !== to.y;
|
|
14382
|
+
/**
|
|
14383
|
+
* The START's ATTACHMENT run (the stub's neighbour) over the moved anchor:
|
|
14384
|
+
* the diagonal run stands the corner's insert at the STUB's column / row —
|
|
14385
|
+
* the exit run stands the stub's line (the line leaves the port along its
|
|
14386
|
+
* normal, the corner slides with the port over the shape's move). The free
|
|
14387
|
+
* endpoint (the zero normal) stands the run as committed (its point is the
|
|
14388
|
+
* line's own end — the stored stand, no axis to re-orth over).
|
|
14389
|
+
*/
|
|
14390
|
+
function reorthStartRun(from, to, endpoint) {
|
|
14391
|
+
if (endpoint.nx === 0 && endpoint.ny === 0 || !isDiagonal(from, to)) return [from, to];
|
|
14392
|
+
return endpoint.ny !== 0 ? [
|
|
14393
|
+
from,
|
|
14394
|
+
{
|
|
14395
|
+
x: to.x,
|
|
14396
|
+
y: from.y
|
|
14397
|
+
},
|
|
14398
|
+
to
|
|
14399
|
+
] : [
|
|
14400
|
+
from,
|
|
14401
|
+
{
|
|
14402
|
+
x: from.x,
|
|
14403
|
+
y: to.y
|
|
14404
|
+
},
|
|
14405
|
+
to
|
|
14406
|
+
];
|
|
14407
|
+
}
|
|
14408
|
+
/**
|
|
14409
|
+
* The END's ATTACHMENT run (the stub's neighbour) over the moved anchor:
|
|
14410
|
+
* the diagonal run stands the corner's insert at the STUB's column / row —
|
|
14411
|
+
* the approach run stands the stub's line (the line enters the port along
|
|
14412
|
+
* its normal), the previous run keeps its line (the corner slides with the
|
|
14413
|
+
* port over the shape's move). The free endpoint stands the run as
|
|
14414
|
+
* committed (the zero normal's stand).
|
|
14415
|
+
*/
|
|
14416
|
+
function reorthEndRun(from, to, endpoint) {
|
|
14417
|
+
if (endpoint.nx === 0 && endpoint.ny === 0 || !isDiagonal(from, to)) return [from, to];
|
|
14418
|
+
return endpoint.ny !== 0 ? [
|
|
14419
|
+
from,
|
|
14420
|
+
{
|
|
14421
|
+
x: from.x,
|
|
14422
|
+
y: to.y
|
|
14423
|
+
},
|
|
14424
|
+
to
|
|
14425
|
+
] : [
|
|
14426
|
+
from,
|
|
14427
|
+
{
|
|
14428
|
+
x: to.x,
|
|
14429
|
+
y: from.y
|
|
14430
|
+
},
|
|
14431
|
+
to
|
|
14432
|
+
];
|
|
14433
|
+
}
|
|
14434
|
+
/**
|
|
14435
|
+
* The route's full vertex list with the ATTACHMENT runs' re-orthogonal
|
|
14436
|
+
* corners: `[a] + [aOut, corner?, P1] + [P2..Pn-1] + [Pn, corner?, bIn] +
|
|
14437
|
+
* [b]` — the canonical stand (the explicit stub's vertices, the segment
|
|
14438
|
+
* editing's pick / move / commit space). The single bend (P1 = Pn) stands
|
|
14439
|
+
* no duplicate (the head's tail is the tail's head). The unsimplified stand
|
|
14440
|
+
* over the re-orth's corners: the drawn stand deduplicates (the look
|
|
14441
|
+
* preserved), the commit's filter stands the stub's points' identity.
|
|
14442
|
+
*/
|
|
14443
|
+
function reorthRoute(a, aOut, bends, bIn, b, start, end) {
|
|
14444
|
+
if (bends.length === 0) return [
|
|
14445
|
+
a,
|
|
14446
|
+
aOut,
|
|
14447
|
+
bIn,
|
|
14448
|
+
b
|
|
14449
|
+
];
|
|
14450
|
+
const first = bends[0];
|
|
14451
|
+
const last = bends[bends.length - 1];
|
|
14452
|
+
const head = reorthStartRun(aOut, first, start);
|
|
14453
|
+
const tail = reorthEndRun(last, bIn, end);
|
|
14454
|
+
const middle = bends.slice(1, -1);
|
|
14455
|
+
return first === last ? [
|
|
14456
|
+
a,
|
|
14457
|
+
...head,
|
|
14458
|
+
...tail.slice(1),
|
|
14459
|
+
b
|
|
14460
|
+
] : [
|
|
14461
|
+
a,
|
|
14462
|
+
...head,
|
|
14463
|
+
...middle,
|
|
14464
|
+
...tail,
|
|
14465
|
+
b
|
|
14466
|
+
];
|
|
14503
14467
|
}
|
|
14504
14468
|
/**
|
|
14505
|
-
* The route the reader adjusted, materialized
|
|
14506
|
-
*
|
|
14507
|
-
*
|
|
14469
|
+
* The route the reader adjusted, materialized over the EXPLICIT stub
|
|
14470
|
+
* vertices (the zero-length stub's stand over the free point): the stored
|
|
14471
|
+
* bends hold the middle (the world position's stand — the endpoint's anchor
|
|
14472
|
+
* moved with the shape), the stub's points stand the attachment (the
|
|
14473
|
+
* parallel move's jog's stand), and the ATTACHMENT runs re-orthogonalize
|
|
14474
|
+
* (the moved anchor's diagonal run stands the corner's insert — the line
|
|
14475
|
+
* leaves / enters the port along its normal, the bends keep their position).
|
|
14508
14476
|
*/
|
|
14509
|
-
function customRouteOf(a, b, aOut, bIn, bends
|
|
14510
|
-
|
|
14511
|
-
if (stubEnds.first) points.push(aOut);
|
|
14512
|
-
for (const [x, y] of bends) points.push({
|
|
14477
|
+
function customRouteOf(a, b, aOut, bIn, bends) {
|
|
14478
|
+
return reorthRoute(a, aOut, bends.map(([x, y]) => ({
|
|
14513
14479
|
x,
|
|
14514
14480
|
y
|
|
14515
|
-
});
|
|
14516
|
-
if (stubEnds.last) points.push(bIn);
|
|
14517
|
-
points.push(b);
|
|
14518
|
-
return simplifyRoute(points);
|
|
14481
|
+
})), bIn, b, a, b);
|
|
14519
14482
|
}
|
|
14520
14483
|
// src/canvas/geometry/utils/obstacles.ts
|
|
14521
14484
|
/**
|
|
@@ -14846,8 +14809,7 @@ function routeLength(points) {
|
|
|
14846
14809
|
/** The route's bend count (the direction changes in the axis-aligned
|
|
14847
14810
|
* polyline — straight = 0, the single-bend elbow = 1, the two-bend U = 2).
|
|
14848
14811
|
* The consecutive duplicate points collapse first (the degenerate bends
|
|
14849
|
-
* stand no direction change). */
|
|
14850
|
-
function routeBends(points) {
|
|
14812
|
+
* stand no direction change). */ function routeBends(points) {
|
|
14851
14813
|
const pts = [];
|
|
14852
14814
|
for (const p of points) {
|
|
14853
14815
|
const last = pts[pts.length - 1];
|
|
@@ -14900,24 +14862,84 @@ function cubicMid(a, c1, c2, b) {
|
|
|
14900
14862
|
y: .125 * a.y + .375 * c1.y + .375 * c2.y + .125 * b.y
|
|
14901
14863
|
};
|
|
14902
14864
|
}
|
|
14865
|
+
/** The route's canonical geometric KEY (the selection's tie-break): the
|
|
14866
|
+
* deduplicated vertex sequence's flat coordinates at fixed precision (the
|
|
14867
|
+
* 2-decimal's rounding). The key is a function of the route's OWN geometry
|
|
14868
|
+
* — the pool's index and the iteration's order stand off the selection:
|
|
14869
|
+
* two equal-fitness routes always resolve to the same winner, and the
|
|
14870
|
+
* winner stands stable over the small's shifts until the geometry crosses
|
|
14871
|
+
* a threshold (the competitive flicker's stand off). */
|
|
14872
|
+
function routeKeyOf(points) {
|
|
14873
|
+
const flat = [];
|
|
14874
|
+
let lastX = NaN;
|
|
14875
|
+
let lastY = NaN;
|
|
14876
|
+
for (const p of points) {
|
|
14877
|
+
const x = Math.round(p.x * 100) / 100;
|
|
14878
|
+
const y = Math.round(p.y * 100) / 100;
|
|
14879
|
+
if (x === lastX && y === lastY) continue;
|
|
14880
|
+
flat.push(x, y);
|
|
14881
|
+
lastX = x;
|
|
14882
|
+
lastY = y;
|
|
14883
|
+
}
|
|
14884
|
+
return flat;
|
|
14885
|
+
}
|
|
14886
|
+
/** The route keys' lexicographic comparison (the flat coordinates' order). */
|
|
14887
|
+
function routeKeyLess(a, b) {
|
|
14888
|
+
const n = Math.min(a.length, b.length);
|
|
14889
|
+
for (let i = 0; i < n; i += 1) {
|
|
14890
|
+
const av = a[i];
|
|
14891
|
+
const bv = b[i];
|
|
14892
|
+
if (av !== bv) return av < bv;
|
|
14893
|
+
}
|
|
14894
|
+
return a.length < b.length;
|
|
14895
|
+
}
|
|
14896
|
+
/** The END SPIKE's stand (the route's last two runs antiparallel — the
|
|
14897
|
+
* approach runs into the port and right back: the drawn `d`'s collapse
|
|
14898
|
+
* drops the port's approach run and the arrowhead reads off the normal).
|
|
14899
|
+
* The consecutive duplicates collapse first. The start's slide (the stub's
|
|
14900
|
+
* line's backtrack) stands tolerated — its drawn stand keeps the port's
|
|
14901
|
+
* exit run. */
|
|
14902
|
+
function hasEndSpike(points) {
|
|
14903
|
+
const pts = [];
|
|
14904
|
+
for (const p of points) {
|
|
14905
|
+
const last = pts[pts.length - 1];
|
|
14906
|
+
if (last === void 0 || last.x !== p.x || last.y !== p.y) pts.push(p);
|
|
14907
|
+
}
|
|
14908
|
+
const r = pts[pts.length - 1];
|
|
14909
|
+
const q = pts[pts.length - 2];
|
|
14910
|
+
const p = pts[pts.length - 3];
|
|
14911
|
+
if (p === void 0) return false;
|
|
14912
|
+
const dx1 = q.x - p.x;
|
|
14913
|
+
const dy1 = q.y - p.y;
|
|
14914
|
+
const dx2 = r.x - q.x;
|
|
14915
|
+
const dy2 = r.y - q.y;
|
|
14916
|
+
if (dx1 === 0 && dx2 === 0 && dy1 * dy2 < 0) return true;
|
|
14917
|
+
if (dy1 === 0 && dy2 === 0 && dx1 * dx2 < 0) return true;
|
|
14918
|
+
return false;
|
|
14919
|
+
}
|
|
14903
14920
|
// src/canvas/geometry/utils/ortho-route.ts
|
|
14904
14921
|
/**
|
|
14905
14922
|
* The orthogonal connector's route: the port stubs (the anchored endpoint
|
|
14906
|
-
* leaves / enters along its outward normal
|
|
14907
|
-
*
|
|
14908
|
-
*
|
|
14909
|
-
* the
|
|
14910
|
-
*
|
|
14911
|
-
*
|
|
14923
|
+
* leaves / enters along its outward normal; the free point stands the
|
|
14924
|
+
* zero-length stub — its own point), the reader's stored bends (the custom
|
|
14925
|
+
* route — the automatic avoidance off), the automatic avoidance's candidate
|
|
14926
|
+
* selection (the shortest clear route over the single-bend pool + the
|
|
14927
|
+
* two-bend-line U's — the length stands first, then the bend count, then
|
|
14928
|
+
* the pool's deterministic order; the obstacle-free scene stands the default
|
|
14929
|
+
* elbow — the single candidate's stand, no selection), and the live segment
|
|
14930
|
+
* drag's parallel move. The returned vertices are the route's CANONICAL
|
|
14931
|
+
* stand (the explicit stub's vertices included — the segment editing's
|
|
14932
|
+
* pick / move / commit space); the drawn `d` deduplicates them (the zero
|
|
14933
|
+
* runs collapse, the look and the label's seat stand preserved).
|
|
14912
14934
|
*/
|
|
14913
14935
|
/** The ortho route's vertices (the stub points + the bends). */
|
|
14914
14936
|
function orthoRouteOf(a, b, options) {
|
|
14915
|
-
const { obstacles, custom, segment
|
|
14937
|
+
const { obstacles, custom, segment } = options;
|
|
14916
14938
|
const dx = b.x - a.x;
|
|
14917
14939
|
const dy = b.y - a.y;
|
|
14918
14940
|
if (dx === 0 && dy === 0) return [a, b];
|
|
14919
|
-
const aAnchored =
|
|
14920
|
-
const bAnchored =
|
|
14941
|
+
const aAnchored = a.nx !== 0 || a.ny !== 0;
|
|
14942
|
+
const bAnchored = b.nx !== 0 || b.ny !== 0;
|
|
14921
14943
|
const aOut = aAnchored ? {
|
|
14922
14944
|
x: a.x + a.nx * 18,
|
|
14923
14945
|
y: a.y + a.ny * 18
|
|
@@ -14926,14 +14948,9 @@ function orthoRouteOf(a, b, options) {
|
|
|
14926
14948
|
x: b.x + b.nx * 18,
|
|
14927
14949
|
y: b.y + b.ny * 18
|
|
14928
14950
|
} : b;
|
|
14929
|
-
const stubEnds = {
|
|
14930
|
-
first: aAnchored,
|
|
14931
|
-
last: bAnchored
|
|
14932
|
-
};
|
|
14933
|
-
const customRoute = (bends) => customRouteOf(a, b, aOut, bIn, bends, stubEnds);
|
|
14934
14951
|
if (custom !== void 0 && custom.length > 0) {
|
|
14935
|
-
const
|
|
14936
|
-
return
|
|
14952
|
+
const base = customRouteOf(a, b, aOut, bIn, custom);
|
|
14953
|
+
return segment !== void 0 && segment !== null ? moveSegmentRoute(base, segment.index, segment.delta) : base;
|
|
14937
14954
|
}
|
|
14938
14955
|
const horizontal = Math.abs(dx) >= Math.abs(dy);
|
|
14939
14956
|
const structures = [horizontal ? (t) => [{
|
|
@@ -14984,11 +15001,9 @@ function orthoRouteOf(a, b, options) {
|
|
|
14984
15001
|
};
|
|
14985
15002
|
const tsList = [horizontal ? tsOf(aOut.x, bIn.x, true) : tsOf(aOut.y, bIn.y, false), horizontal ? tsOf(aOut.y, bIn.y, false) : tsOf(aOut.x, bIn.x, true)];
|
|
14986
15003
|
const routeOf = (bend) => {
|
|
14987
|
-
const points = [a];
|
|
14988
|
-
if (aAnchored) points.push(aOut);
|
|
15004
|
+
const points = [a, aOut];
|
|
14989
15005
|
points.push(...bend);
|
|
14990
|
-
|
|
14991
|
-
points.push(b);
|
|
15006
|
+
points.push(bIn, b);
|
|
14992
15007
|
return points;
|
|
14993
15008
|
};
|
|
14994
15009
|
const pool = [];
|
|
@@ -14998,11 +15013,13 @@ function orthoRouteOf(a, b, options) {
|
|
|
14998
15013
|
if (structure === void 0 || ts === void 0) continue;
|
|
14999
15014
|
for (const t of ts) {
|
|
15000
15015
|
const candidate = routeOf(structure(t));
|
|
15016
|
+
if (hasEndSpike(candidate)) continue;
|
|
15001
15017
|
if (avoid && hits(candidate)) continue;
|
|
15002
15018
|
pool.push({
|
|
15003
15019
|
points: candidate,
|
|
15004
|
-
length:
|
|
15005
|
-
bends: routeBends(candidate)
|
|
15020
|
+
length: Math.round(routeLength(candidate) * 100) / 100,
|
|
15021
|
+
bends: routeBends(candidate),
|
|
15022
|
+
key: routeKeyOf(candidate)
|
|
15006
15023
|
});
|
|
15007
15024
|
}
|
|
15008
15025
|
}
|
|
@@ -15032,10 +15049,11 @@ function orthoRouteOf(a, b, options) {
|
|
|
15032
15049
|
y: y1
|
|
15033
15050
|
}
|
|
15034
15051
|
]);
|
|
15035
|
-
if (!hits(f1)) pool.push({
|
|
15052
|
+
if (!hits(f1) && !hasEndSpike(f1)) pool.push({
|
|
15036
15053
|
points: f1,
|
|
15037
|
-
length: routeLength(f1),
|
|
15038
|
-
bends: routeBends(f1)
|
|
15054
|
+
length: Math.round(routeLength(f1) * 100) / 100,
|
|
15055
|
+
bends: routeBends(f1),
|
|
15056
|
+
key: routeKeyOf(f1)
|
|
15039
15057
|
});
|
|
15040
15058
|
const f2 = routeOf([
|
|
15041
15059
|
{
|
|
@@ -15051,31 +15069,53 @@ function orthoRouteOf(a, b, options) {
|
|
|
15051
15069
|
y: bIn.y
|
|
15052
15070
|
}
|
|
15053
15071
|
]);
|
|
15054
|
-
if (!hits(f2)) pool.push({
|
|
15072
|
+
if (!hits(f2) && !hasEndSpike(f2)) pool.push({
|
|
15055
15073
|
points: f2,
|
|
15056
|
-
length: routeLength(f2),
|
|
15057
|
-
bends: routeBends(f2)
|
|
15074
|
+
length: Math.round(routeLength(f2) * 100) / 100,
|
|
15075
|
+
bends: routeBends(f2),
|
|
15076
|
+
key: routeKeyOf(f2)
|
|
15058
15077
|
});
|
|
15059
15078
|
}
|
|
15060
15079
|
}
|
|
15061
15080
|
let points = null;
|
|
15062
15081
|
if (pool.length > 0) {
|
|
15063
15082
|
let best = 0;
|
|
15064
|
-
for (let i = 1; i < pool.length; i
|
|
15083
|
+
for (let i = 1; i < pool.length; i += 1) {
|
|
15065
15084
|
const candidate = pool[i];
|
|
15066
15085
|
const current = pool[best];
|
|
15067
|
-
|
|
15068
|
-
if (candidate.length < current.length || fewerBends) best = i;
|
|
15086
|
+
if (candidate.length < current.length || candidate.length === current.length && (candidate.bends < current.bends || candidate.bends === current.bends && routeKeyLess(candidate.key, current.key))) best = i;
|
|
15069
15087
|
}
|
|
15070
15088
|
points = pool[best].points;
|
|
15071
15089
|
}
|
|
15072
15090
|
const midCoord = horizontal ? (aOut.x + bIn.x) / 2 : (aOut.y + bIn.y) / 2;
|
|
15073
15091
|
const final = points ?? routeOf(structures[0](midCoord));
|
|
15074
|
-
|
|
15075
|
-
return segment !== void 0 && segment !== null ? simplifyRoute(moveSegmentRoute(deduped, segment.index, segment.delta, stubEnds)) : deduped;
|
|
15092
|
+
return segment !== void 0 && segment !== null ? moveSegmentRoute(final, segment.index, segment.delta) : final;
|
|
15076
15093
|
}
|
|
15077
15094
|
// src/canvas/geometry/utils/connector.ts
|
|
15078
15095
|
/**
|
|
15096
|
+
* The connector's path over its RESOLVED endpoint points (the free-port
|
|
15097
|
+
* generalization of the box-to-box `connectorPath`): the variant's shape —
|
|
15098
|
+
* the straight segment (the stored bends stand the polyline), the orthogonal
|
|
15099
|
+
* route (`./ortho-route`: the port stubs, the reader's bends, the obstacle
|
|
15100
|
+
* avoidance), the curved bow.
|
|
15101
|
+
*/
|
|
15102
|
+
/**
|
|
15103
|
+
* The orthogonal endpoint's STUB point: the anchored endpoint (the non-zero
|
|
15104
|
+
* normal) stands the outward normal's offset beyond the port point; the free
|
|
15105
|
+
* point (the zero normal) stands its own point (the zero-length stub's
|
|
15106
|
+
* stand).
|
|
15107
|
+
*/
|
|
15108
|
+
function orthoStubOf(point) {
|
|
15109
|
+
if (point.nx === 0 && point.ny === 0) return {
|
|
15110
|
+
x: point.x,
|
|
15111
|
+
y: point.y
|
|
15112
|
+
};
|
|
15113
|
+
return {
|
|
15114
|
+
x: point.x + point.nx * 18,
|
|
15115
|
+
y: point.y + point.ny * 18
|
|
15116
|
+
};
|
|
15117
|
+
}
|
|
15118
|
+
/**
|
|
15079
15119
|
* The connector's path over the RESOLVED endpoint points — the free-port
|
|
15080
15120
|
* generalization of the box-to-box `connectorPath`: the straight segment (the
|
|
15081
15121
|
* stored bends stand the polyline through them), the orthogonal route
|
|
@@ -15156,23 +15196,93 @@ function connectorPathPoints(a, b, variant, options = {}) {
|
|
|
15156
15196
|
points: []
|
|
15157
15197
|
};
|
|
15158
15198
|
}
|
|
15159
|
-
/**
|
|
15160
|
-
|
|
15161
|
-
|
|
15162
|
-
|
|
15163
|
-
|
|
15164
|
-
|
|
15165
|
-
|
|
15166
|
-
|
|
15167
|
-
|
|
15168
|
-
|
|
15169
|
-
|
|
15170
|
-
|
|
15171
|
-
|
|
15172
|
-
|
|
15173
|
-
|
|
15174
|
-
|
|
15175
|
-
|
|
15199
|
+
/**
|
|
15200
|
+
* The seat's on-line guard: the point's stand over the polyline within
|
|
15201
|
+
* `eps` (the segment's clamp's distance). The drawn stand's collapse (the
|
|
15202
|
+
* backtrack's spike's shrink over the moved endpoint) can pull the
|
|
15203
|
+
* canonical seat off the drawn line — where the projection's stand.
|
|
15204
|
+
*/
|
|
15205
|
+
function pointOnRoute(point, points, eps) {
|
|
15206
|
+
for (let i = 0; i < points.length - 1; i += 1) {
|
|
15207
|
+
const a = points[i];
|
|
15208
|
+
const b = points[i + 1];
|
|
15209
|
+
const dx = b.x - a.x;
|
|
15210
|
+
const dy = b.y - a.y;
|
|
15211
|
+
const len2 = dx * dx + dy * dy;
|
|
15212
|
+
if (len2 === 0) {
|
|
15213
|
+
if (Math.hypot(point.x - a.x, point.y - a.y) <= eps) return true;
|
|
15214
|
+
continue;
|
|
15215
|
+
}
|
|
15216
|
+
const t = Math.max(0, Math.min(1, ((point.x - a.x) * dx + (point.y - a.y) * dy) / len2));
|
|
15217
|
+
if (Math.hypot(point.x - (a.x + dx * t), point.y - (a.y + dy * t)) <= eps) return true;
|
|
15218
|
+
}
|
|
15219
|
+
return false;
|
|
15220
|
+
}
|
|
15221
|
+
/** The nearest point of `point` over the polyline (the segments' clamps). */
|
|
15222
|
+
function nearestPointOnRoute(point, points) {
|
|
15223
|
+
let best = {
|
|
15224
|
+
x: point.x,
|
|
15225
|
+
y: point.y
|
|
15226
|
+
};
|
|
15227
|
+
let bestDist = 1e400;
|
|
15228
|
+
for (let i = 0; i < points.length - 1; i += 1) {
|
|
15229
|
+
const a = points[i];
|
|
15230
|
+
const b = points[i + 1];
|
|
15231
|
+
const dx = b.x - a.x;
|
|
15232
|
+
const dy = b.y - a.y;
|
|
15233
|
+
const len2 = dx * dx + dy * dy;
|
|
15234
|
+
const t = len2 === 0 ? 0 : Math.max(0, Math.min(1, ((point.x - a.x) * dx + (point.y - a.y) * dy) / len2));
|
|
15235
|
+
const px = a.x + dx * t;
|
|
15236
|
+
const py = a.y + dy * t;
|
|
15237
|
+
const dist = (point.x - px) * (point.x - px) + (point.y - py) * (point.y - py);
|
|
15238
|
+
if (dist < bestDist) {
|
|
15239
|
+
bestDist = dist;
|
|
15240
|
+
best = {
|
|
15241
|
+
x: px,
|
|
15242
|
+
y: py
|
|
15243
|
+
};
|
|
15244
|
+
}
|
|
15245
|
+
}
|
|
15246
|
+
return best;
|
|
15247
|
+
}
|
|
15248
|
+
/**
|
|
15249
|
+
* The route's path stand over its vertices: the DRAWN `d` stands the
|
|
15250
|
+
* SIMPLIFIED stand (the collinear middles drop — a run that would backtrack
|
|
15251
|
+
* over its neighbour (the moved endpoint's own stand) shrinks to the stub's
|
|
15252
|
+
* line instead of spiking; the stub's zero runs collapse). The label's seat
|
|
15253
|
+
* stands the DEDUPLICATED route's longest run (the stub's short runs keep
|
|
15254
|
+
* the seat off the line's ends — the simplified stand's merged run would
|
|
15255
|
+
* shift it) and stands PROJECTED onto the drawn polyline when the
|
|
15256
|
+
* backtrack's collapse pulls it off the line (the seat is always on the
|
|
15257
|
+
* drawn line — the chip never floats in the air). The `points` output stands
|
|
15258
|
+
* the route's OWN vertices (the segment editing's pick / move / commit space
|
|
15259
|
+
* — the explicit stub's stand kept).
|
|
15260
|
+
*/
|
|
15261
|
+
function routePathOf(points, end) {
|
|
15262
|
+
const deduped = [];
|
|
15263
|
+
for (const point of points) {
|
|
15264
|
+
const last = deduped[deduped.length - 1];
|
|
15265
|
+
if (last !== void 0 && last.x === point.x && last.y === point.y) continue;
|
|
15266
|
+
deduped.push(point);
|
|
15267
|
+
}
|
|
15268
|
+
const drawn = simplifyRoute(points);
|
|
15269
|
+
const d = drawn.map((point, i) => `${i === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" ");
|
|
15270
|
+
const seat = longestSegmentMid(deduped);
|
|
15271
|
+
return {
|
|
15272
|
+
d,
|
|
15273
|
+
end: {
|
|
15274
|
+
x: end.x,
|
|
15275
|
+
y: end.y
|
|
15276
|
+
},
|
|
15277
|
+
mid: pointOnRoute(seat, drawn, .01) ? seat : nearestPointOnRoute(seat, drawn),
|
|
15278
|
+
points: points.map((point) => ({
|
|
15279
|
+
x: point.x,
|
|
15280
|
+
y: point.y
|
|
15281
|
+
}))
|
|
15282
|
+
};
|
|
15283
|
+
}
|
|
15284
|
+
// src/canvas/geometry/utils/geometry.ts
|
|
15285
|
+
function isCanvasSubType(type) {
|
|
15176
15286
|
return CANVAS_SUB_TYPES.includes(type);
|
|
15177
15287
|
}
|
|
15178
15288
|
/**
|
|
@@ -15505,54 +15615,690 @@ function connectorHandlePoints(childIds, blocks, connectorId, previews) {
|
|
|
15505
15615
|
};
|
|
15506
15616
|
}
|
|
15507
15617
|
/**
|
|
15508
|
-
* The
|
|
15509
|
-
*
|
|
15510
|
-
*
|
|
15511
|
-
* the
|
|
15512
|
-
*
|
|
15513
|
-
*
|
|
15514
|
-
* With `previews` (the in-flight canvas session) the seat stands the live
|
|
15515
|
-
* geometry (the move / resize's previewed blocks + the endpoint drag's
|
|
15516
|
-
* live point / the snap's stick) — the same inputs as the line's re-draw,
|
|
15517
|
-
* so the seat follows the line mid-drag and the release stands no jump
|
|
15518
|
-
* (the preview's stand is the commit's stand). The `connectorId` (the
|
|
15519
|
-
* block's map key — the block's own shape carries no id) stands the
|
|
15520
|
-
* endpoint drag's identity match (like the handles' and the line's).
|
|
15618
|
+
* The connector's STORED waypoints (the bend dots' stand): the attrs'
|
|
15619
|
+
* `points` in the route's own order, the in-flight waypoint drag's point
|
|
15620
|
+
* substituted at its index (the dot follows the handle — the release
|
|
15621
|
+
* commits the same position); the seeded waypoint (the line's press-drag)
|
|
15622
|
+
* stands the live point INSERTED at its route index (the dot's stand over
|
|
15623
|
+
* the in-flight seed). The surface-local px (the line's own space).
|
|
15521
15624
|
*/
|
|
15522
|
-
function
|
|
15523
|
-
|
|
15524
|
-
|
|
15525
|
-
const
|
|
15526
|
-
|
|
15527
|
-
|
|
15528
|
-
|
|
15529
|
-
|
|
15530
|
-
|
|
15531
|
-
|
|
15532
|
-
|
|
15533
|
-
|
|
15534
|
-
|
|
15535
|
-
|
|
15536
|
-
|
|
15537
|
-
|
|
15538
|
-
|
|
15625
|
+
function connectorWaypointPoints(block, previews) {
|
|
15626
|
+
if (block === void 0 || block.type !== "connector" || block.attrs === void 0) return [];
|
|
15627
|
+
const drag = previews?.endpointDrag ?? null;
|
|
15628
|
+
const preview = previews?.endpointPreview ?? null;
|
|
15629
|
+
const stored = (block.attrs.points ?? []).map(([x, y]) => ({
|
|
15630
|
+
x,
|
|
15631
|
+
y
|
|
15632
|
+
}));
|
|
15633
|
+
if (drag === null || drag.which !== "waypoint" || preview === null || drag.index === void 0) return stored;
|
|
15634
|
+
const index = drag.index;
|
|
15635
|
+
const live = {
|
|
15636
|
+
x: preview.point.x,
|
|
15637
|
+
y: preview.point.y
|
|
15638
|
+
};
|
|
15639
|
+
if (drag.seeded) return [
|
|
15640
|
+
...stored.slice(0, index),
|
|
15641
|
+
live,
|
|
15642
|
+
...stored.slice(index)
|
|
15643
|
+
];
|
|
15644
|
+
return stored.map((point, i) => i === index ? live : point);
|
|
15645
|
+
}
|
|
15646
|
+
// src/canvas/geometry/utils/frame-window.ts
|
|
15647
|
+
/**
|
|
15648
|
+
* The window's offset: the box-local position of the surface's world
|
|
15649
|
+
* origin (0,0) — the box's top-left corner (the center minus the half
|
|
15650
|
+
* spans) shifted to the origin. The window's content wrapper stands at
|
|
15651
|
+
* this point, so the world's content stands at its world coordinates over
|
|
15652
|
+
* the box (the center-anchor model: the content's center anchor is the
|
|
15653
|
+
* world origin).
|
|
15654
|
+
*/
|
|
15655
|
+
function frameWindowOffset(box) {
|
|
15656
|
+
return {
|
|
15657
|
+
left: box.w / 2 - box.x,
|
|
15658
|
+
top: box.h / 2 - box.y
|
|
15659
|
+
};
|
|
15660
|
+
}
|
|
15661
|
+
/**
|
|
15662
|
+
* The frame box's background's inline style: the canvas background's dot
|
|
15663
|
+
* grid (the canvas view's grid token's dot) phase-aligned to the world's
|
|
15664
|
+
* 24px grid from the box's WORLD top-left (the positive mod — the phase
|
|
15665
|
+
* stands for negative coordinates too): the canvas view's tile stands its
|
|
15666
|
+
* dot at the tile's CENTER over the world's grid line (the container's
|
|
15667
|
+
* percentage position's stand), so the box's background position offsets
|
|
15668
|
+
* the tile's half step back — the dot stands on the world's grid line and
|
|
15669
|
+
* the box slides over the still dots.
|
|
15670
|
+
*/
|
|
15671
|
+
function frameDotBackground(topLeftX, topLeftY) {
|
|
15672
|
+
const step = 24;
|
|
15673
|
+
const phase = (value) => (value % step + step) % step;
|
|
15674
|
+
const positionOf = (value) => ((step - step / 2 - phase(value)) % step + step) % step;
|
|
15675
|
+
return {
|
|
15676
|
+
backgroundImage: "radial-gradient(circle, var(--docblocks-canvas-view-dot) 1px, transparent 1px)",
|
|
15677
|
+
backgroundSize: `${step}px ${step}px`,
|
|
15678
|
+
backgroundPosition: `${positionOf(topLeftX)}px ${positionOf(topLeftY)}px`
|
|
15679
|
+
};
|
|
15680
|
+
}
|
|
15681
|
+
// src/canvas/geometry/utils/sector-links.ts
|
|
15682
|
+
/**
|
|
15683
|
+
* The fixed-sectors' links' machinery (the sector's model's building
|
|
15684
|
+
* blocks): the sector's carrier's line (the axis + the offset) + the
|
|
15685
|
+
* extent's helpers (the dead's detection, the route's crossing's
|
|
15686
|
+
* parameter), the absolute's lines (the fixed's extensions + the stub's —
|
|
15687
|
+
* a run over them stands the no-hit-test), the drop's candidate's columns
|
|
15688
|
+
* (the canonical's first, the obstacle's near's edges, the detour's), and
|
|
15689
|
+
* the auto's links (the cursor → the line's / the point's connection over
|
|
15690
|
+
* the clear's candidates — the length's parity, the first clear's stand).
|
|
15691
|
+
*/
|
|
15692
|
+
const pt = (p) => ({
|
|
15693
|
+
x: p.x,
|
|
15694
|
+
y: p.y
|
|
15695
|
+
});
|
|
15696
|
+
/** The route's points without the consecutive duplicates (the zero run's
|
|
15697
|
+
* collapse — the vertex's own identity kept). */
|
|
15698
|
+
function dedupPoints(points) {
|
|
15699
|
+
const result = [];
|
|
15700
|
+
for (const p of points) {
|
|
15701
|
+
const last = result[result.length - 1];
|
|
15702
|
+
if (last !== void 0 && last.x === p.x && last.y === p.y) continue;
|
|
15703
|
+
result.push(p);
|
|
15704
|
+
}
|
|
15705
|
+
return result;
|
|
15706
|
+
}
|
|
15707
|
+
/** The sector's run (the entry → the exit) over the UNSIGNED length —
|
|
15708
|
+
* the line is undirected (the drag's fix locks the carrier's line, not
|
|
15709
|
+
* the travel's direction): a sector stands dead only when its boundary's
|
|
15710
|
+
* corners coincide (the length ≤ 0 — the merge), never over the travel's
|
|
15711
|
+
* direction vs the stored extent's orientation. */
|
|
15712
|
+
function extentOf(s, entry, exit) {
|
|
15713
|
+
return s.axis === "h" ? Math.abs(exit.x - entry.x) : Math.abs(exit.y - entry.y);
|
|
15714
|
+
}
|
|
15715
|
+
/**
|
|
15716
|
+
* The line's CROSSING parameter over the start→end chord (the route's
|
|
15717
|
+
* traversal's order): the parameter `t` where the straight aOut→bIn chord
|
|
15718
|
+
* crosses the carrier's line (the `t` < 0's lines stand the entry's side,
|
|
15719
|
+
* the `t` > 1's the exit's side). The degenerate chord (the parallel's
|
|
15720
|
+
* stand) stands the no-order stand (0.5 — the stable sort's tie keeps the
|
|
15721
|
+
* stored's order).
|
|
15722
|
+
*/
|
|
15723
|
+
function crossParam(s, aOut, bIn) {
|
|
15724
|
+
if (s.axis === "h") {
|
|
15725
|
+
const dy = bIn.y - aOut.y;
|
|
15726
|
+
if (dy === 0) return .5;
|
|
15727
|
+
return (s.offset - aOut.y) / dy;
|
|
15728
|
+
}
|
|
15729
|
+
const dx = bIn.x - aOut.x;
|
|
15730
|
+
if (dx === 0) return .5;
|
|
15731
|
+
return (s.offset - aOut.x) / dx;
|
|
15732
|
+
}
|
|
15733
|
+
/** The absolute's lines: the fixed's (the live's sectors) + the stub's
|
|
15734
|
+
* (the port's normal's line — the zero stub's stands none). */
|
|
15735
|
+
function absoluteLines(live, sectors, a, aOut, b, bIn) {
|
|
15736
|
+
const abs = [];
|
|
15737
|
+
for (const idx of live) {
|
|
15738
|
+
const s = sectors[idx];
|
|
15739
|
+
if (s !== void 0) abs.push({
|
|
15740
|
+
axis: s.axis,
|
|
15741
|
+
coord: s.offset
|
|
15742
|
+
});
|
|
15743
|
+
}
|
|
15744
|
+
if (a.nx !== 0) abs.push({
|
|
15745
|
+
axis: "h",
|
|
15746
|
+
coord: aOut.y
|
|
15747
|
+
});
|
|
15748
|
+
else if (a.ny !== 0) abs.push({
|
|
15749
|
+
axis: "v",
|
|
15750
|
+
coord: aOut.x
|
|
15751
|
+
});
|
|
15752
|
+
if (b.nx !== 0) abs.push({
|
|
15753
|
+
axis: "h",
|
|
15754
|
+
coord: bIn.y
|
|
15755
|
+
});
|
|
15756
|
+
else if (b.ny !== 0) abs.push({
|
|
15757
|
+
axis: "v",
|
|
15758
|
+
coord: bIn.x
|
|
15759
|
+
});
|
|
15760
|
+
return abs;
|
|
15761
|
+
}
|
|
15762
|
+
/** The segment's absolute stand (the straight run over an absolute's
|
|
15763
|
+
* line — the diagonal's stand impossible over the axis-aligned's
|
|
15764
|
+
* construction, the defensive's none). */
|
|
15765
|
+
function isAbsolute(seg, abs) {
|
|
15766
|
+
const [p, q] = seg;
|
|
15767
|
+
if (p.x === q.x) return abs.some((l) => l.axis === "v" && l.coord === p.x);
|
|
15768
|
+
if (p.y === q.y) return abs.some((l) => l.axis === "h" && l.coord === p.y);
|
|
15769
|
+
return false;
|
|
15770
|
+
}
|
|
15771
|
+
/** The drop's candidate's columns (the auto's link's stand): the
|
|
15772
|
+
* canonical's first, then the obstacle's near's edges (the top-K's
|
|
15773
|
+
* stand), then the detour's columns (± the detour's px) — the dedup, the
|
|
15774
|
+
* (|Δ|, the value)'s order (the deterministic's stand). */
|
|
15775
|
+
function dropCandidates(px, obstacles) {
|
|
15776
|
+
const xs = [px];
|
|
15777
|
+
if (obstacles.length > 0) {
|
|
15778
|
+
const edges = [];
|
|
15779
|
+
for (const r of obstacles) edges.push(r.x - r.w / 2 - 12, r.x + r.w / 2 + 12);
|
|
15780
|
+
xs.push(...topKSpanEdges(edges, px, px, 8));
|
|
15781
|
+
xs.push(px - 24, px + 24);
|
|
15782
|
+
}
|
|
15783
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15784
|
+
const uniq = [];
|
|
15785
|
+
for (const v of xs) {
|
|
15786
|
+
const r = Math.round(v * 100) / 100;
|
|
15787
|
+
if (seen.has(r)) continue;
|
|
15788
|
+
seen.add(r);
|
|
15789
|
+
uniq.push(r);
|
|
15790
|
+
}
|
|
15791
|
+
return uniq.sort((u, v) => Math.abs(u - px) - Math.abs(v - px) || u - v);
|
|
15792
|
+
}
|
|
15793
|
+
/** The link's clearness over the candidates' runs: the absolute's runs
|
|
15794
|
+
* stand the no-hit-test, the other's — the obstacle's hit's stand. */
|
|
15795
|
+
function linkClear(from, verts, to, abs, obstacles) {
|
|
15796
|
+
const all = [
|
|
15797
|
+
from,
|
|
15798
|
+
...verts,
|
|
15799
|
+
to
|
|
15800
|
+
];
|
|
15801
|
+
for (let i = 0; i < all.length - 1; i += 1) {
|
|
15802
|
+
const p = all[i];
|
|
15803
|
+
const q = all[i + 1];
|
|
15804
|
+
if (p.x === q.x && p.y === q.y) continue;
|
|
15805
|
+
if (isAbsolute([p, q], abs)) continue;
|
|
15806
|
+
if (routeHitsObstacles([p, q], obstacles)) return false;
|
|
15807
|
+
}
|
|
15808
|
+
return true;
|
|
15809
|
+
}
|
|
15810
|
+
/**
|
|
15811
|
+
* The AUTO's link over the LINE: the drop from the `cursor` to the
|
|
15812
|
+
* sector's line (the entry's stand). The canonical's straight drop's
|
|
15813
|
+
* first, the detour's candidates over the drop's column / row (the
|
|
15814
|
+
* slide's over the previous's line — the absolute's extension). The
|
|
15815
|
+
* blocked at all's candidates stands the canonical (the crossing's
|
|
15816
|
+
* fallback). The output: the link's vertices (the cursor stands excluded,
|
|
15817
|
+
* the landing's over the line included) + the landing's point.
|
|
15818
|
+
*/
|
|
15819
|
+
function linkToLine(cursor, s, abs, obstacles) {
|
|
15820
|
+
if (s.axis === "h" && cursor.y === s.offset || s.axis === "v" && cursor.x === s.offset) return {
|
|
15821
|
+
verts: [],
|
|
15822
|
+
land: pt(cursor)
|
|
15823
|
+
};
|
|
15824
|
+
const candidates = dropCandidates(s.axis === "h" ? cursor.x : cursor.y, obstacles);
|
|
15825
|
+
for (const c of candidates) {
|
|
15826
|
+
const slide = s.axis === "h" ? {
|
|
15827
|
+
x: c,
|
|
15828
|
+
y: cursor.y
|
|
15829
|
+
} : {
|
|
15830
|
+
x: cursor.x,
|
|
15831
|
+
y: c
|
|
15832
|
+
};
|
|
15833
|
+
const land = s.axis === "h" ? {
|
|
15834
|
+
x: c,
|
|
15835
|
+
y: s.offset
|
|
15836
|
+
} : {
|
|
15837
|
+
x: s.offset,
|
|
15838
|
+
y: c
|
|
15839
|
+
};
|
|
15840
|
+
const verts = slide.x === cursor.x && slide.y === cursor.y ? [land] : [slide, land];
|
|
15841
|
+
if (linkClear(cursor, verts, land, abs, obstacles)) return {
|
|
15842
|
+
verts,
|
|
15843
|
+
land: pt(land)
|
|
15844
|
+
};
|
|
15845
|
+
}
|
|
15846
|
+
const land = s.axis === "h" ? {
|
|
15847
|
+
x: cursor.x,
|
|
15848
|
+
y: s.offset
|
|
15849
|
+
} : {
|
|
15850
|
+
x: s.offset,
|
|
15851
|
+
y: cursor.y
|
|
15852
|
+
};
|
|
15853
|
+
return {
|
|
15854
|
+
verts: [pt(land)],
|
|
15855
|
+
land: pt(land)
|
|
15856
|
+
};
|
|
15857
|
+
}
|
|
15858
|
+
/**
|
|
15859
|
+
* The AUTO's link over the POINT (the exit's stand): the run over the
|
|
15860
|
+
* last's line to the drop's start, the drop to the target's line / row,
|
|
15861
|
+
* the slide over the target's stub's line to the `target`. The
|
|
15862
|
+
* canonical's column / row = the target's own coordinate (the straight
|
|
15863
|
+
* drop's stand). The output: the vertices (the cursor stands excluded,
|
|
15864
|
+
* the target included) + the line's run's end (the drop's start — the
|
|
15865
|
+
* sector's run's extent's stand).
|
|
15866
|
+
*/
|
|
15867
|
+
function linkToPoint(cursor, target, s, abs, obstacles) {
|
|
15868
|
+
if (s.axis === "h") {
|
|
15869
|
+
const candidates = dropCandidates(target.x, obstacles);
|
|
15870
|
+
for (const c of candidates) {
|
|
15871
|
+
const onLine = {
|
|
15872
|
+
x: c,
|
|
15873
|
+
y: s.offset
|
|
15539
15874
|
};
|
|
15540
|
-
|
|
15541
|
-
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
15546
|
-
|
|
15547
|
-
|
|
15548
|
-
|
|
15549
|
-
|
|
15875
|
+
const verts = dedupPoints([
|
|
15876
|
+
onLine,
|
|
15877
|
+
{
|
|
15878
|
+
x: c,
|
|
15879
|
+
y: target.y
|
|
15880
|
+
},
|
|
15881
|
+
pt(target)
|
|
15882
|
+
]);
|
|
15883
|
+
if (linkClear(cursor, verts, target, abs, obstacles)) return {
|
|
15884
|
+
verts,
|
|
15885
|
+
onLine: pt(onLine)
|
|
15886
|
+
};
|
|
15887
|
+
}
|
|
15888
|
+
const onLine = {
|
|
15889
|
+
x: target.x,
|
|
15890
|
+
y: s.offset
|
|
15891
|
+
};
|
|
15892
|
+
return {
|
|
15893
|
+
verts: dedupPoints([pt(onLine), pt(target)]),
|
|
15894
|
+
onLine: pt(onLine)
|
|
15895
|
+
};
|
|
15896
|
+
}
|
|
15897
|
+
const candidates = dropCandidates(target.y, obstacles);
|
|
15898
|
+
for (const c of candidates) {
|
|
15899
|
+
const onLine = {
|
|
15900
|
+
x: s.offset,
|
|
15901
|
+
y: c
|
|
15902
|
+
};
|
|
15903
|
+
const verts = dedupPoints([
|
|
15904
|
+
onLine,
|
|
15905
|
+
{
|
|
15906
|
+
x: target.x,
|
|
15907
|
+
y: c
|
|
15908
|
+
},
|
|
15909
|
+
pt(target)
|
|
15910
|
+
]);
|
|
15911
|
+
if (linkClear(cursor, verts, target, abs, obstacles)) return {
|
|
15912
|
+
verts,
|
|
15913
|
+
onLine: pt(onLine)
|
|
15914
|
+
};
|
|
15915
|
+
}
|
|
15916
|
+
const onLine = {
|
|
15917
|
+
x: s.offset,
|
|
15918
|
+
y: target.y
|
|
15919
|
+
};
|
|
15920
|
+
return {
|
|
15921
|
+
verts: dedupPoints([pt(onLine), pt(target)]),
|
|
15922
|
+
onLine: pt(onLine)
|
|
15923
|
+
};
|
|
15924
|
+
}
|
|
15925
|
+
/** The next's junction's coordinate over the parallel's chain (the first
|
|
15926
|
+
* subsequent's perpendicular's line's offset, the target's own coordinate
|
|
15927
|
+
* over the chain's end) — the drop's canonical's column / row. */
|
|
15928
|
+
function nextJunctionCoord(s, live, fromPos, sectors, target) {
|
|
15929
|
+
for (let pos = fromPos; pos < live.length; pos += 1) {
|
|
15930
|
+
const n = sectors[live[pos]];
|
|
15931
|
+
if (n !== void 0 && n.axis !== s.axis) return n.offset;
|
|
15932
|
+
}
|
|
15933
|
+
return s.axis === "h" ? target.x : target.y;
|
|
15934
|
+
}
|
|
15935
|
+
// src/canvas/geometry/utils/sector-route.ts
|
|
15936
|
+
/**
|
|
15937
|
+
* The PARALLEL's link (the middle's stand): the run over `s` to the
|
|
15938
|
+
* drop's start (the canonical's column = the next's junction's
|
|
15939
|
+
* coordinate), the drop to the `next`'s line (the detour's candidates),
|
|
15940
|
+
* the landing over `next`. The output: the vertices (the cursor stands
|
|
15941
|
+
* excluded) + the landing's point + the line's run's end (the extent's
|
|
15942
|
+
* stand).
|
|
15943
|
+
*/
|
|
15944
|
+
function linkParallel(cursor, s, next, junction, abs, obstacles) {
|
|
15945
|
+
if (s.offset === next.offset) return {
|
|
15946
|
+
verts: [],
|
|
15947
|
+
land: pt(cursor),
|
|
15948
|
+
onLine: pt(cursor)
|
|
15949
|
+
};
|
|
15950
|
+
const candidates = dropCandidates(junction, obstacles);
|
|
15951
|
+
for (const c of candidates) {
|
|
15952
|
+
const onLine = s.axis === "h" ? {
|
|
15953
|
+
x: c,
|
|
15954
|
+
y: s.offset
|
|
15955
|
+
} : {
|
|
15956
|
+
x: s.offset,
|
|
15957
|
+
y: c
|
|
15958
|
+
};
|
|
15959
|
+
const land = s.axis === "h" ? {
|
|
15960
|
+
x: c,
|
|
15961
|
+
y: next.offset
|
|
15962
|
+
} : {
|
|
15963
|
+
x: next.offset,
|
|
15964
|
+
y: c
|
|
15965
|
+
};
|
|
15966
|
+
const verts = dedupPoints([onLine, land]);
|
|
15967
|
+
if (linkClear(cursor, verts, land, abs, obstacles)) return {
|
|
15968
|
+
verts,
|
|
15969
|
+
land: pt(land),
|
|
15970
|
+
onLine: pt(onLine)
|
|
15971
|
+
};
|
|
15972
|
+
}
|
|
15973
|
+
const onLine = s.axis === "h" ? {
|
|
15974
|
+
x: junction,
|
|
15975
|
+
y: s.offset
|
|
15976
|
+
} : {
|
|
15977
|
+
x: s.offset,
|
|
15978
|
+
y: junction
|
|
15979
|
+
};
|
|
15980
|
+
const land = s.axis === "h" ? {
|
|
15981
|
+
x: junction,
|
|
15982
|
+
y: next.offset
|
|
15983
|
+
} : {
|
|
15984
|
+
x: next.offset,
|
|
15985
|
+
y: junction
|
|
15986
|
+
};
|
|
15987
|
+
return {
|
|
15988
|
+
verts: dedupPoints([pt(onLine), pt(land)]),
|
|
15989
|
+
land: pt(land),
|
|
15990
|
+
onLine: pt(onLine)
|
|
15991
|
+
};
|
|
15992
|
+
}
|
|
15993
|
+
/**
|
|
15994
|
+
* The route's build over the live's sectors: the stub's start, the
|
|
15995
|
+
* sectors' chain (the entry's links, the runs, the middle's links), the
|
|
15996
|
+
* exit's link, the stub's end. The dead's sectors' extent's are
|
|
15997
|
+
* collected (the caller's fixed-point's prune's stand).
|
|
15998
|
+
*/
|
|
15999
|
+
function buildRoute(a, b, live, sectors, obstacles) {
|
|
16000
|
+
if (live.length === 0) return {
|
|
16001
|
+
points: orthoRouteOf(a, b, { obstacles }),
|
|
16002
|
+
dead: []
|
|
16003
|
+
};
|
|
16004
|
+
const aOut = orthoStubOf(a);
|
|
16005
|
+
const bIn = orthoStubOf(b);
|
|
16006
|
+
const abs = absoluteLines(live, sectors, a, aOut, b, bIn);
|
|
16007
|
+
const dead = [];
|
|
16008
|
+
const pts = [pt(a), pt(aOut)];
|
|
16009
|
+
let cursor = pt(aOut);
|
|
16010
|
+
for (let pos = 0; pos < live.length; pos += 1) {
|
|
16011
|
+
const s = sectors[live[pos]];
|
|
16012
|
+
const isLast = pos === live.length - 1;
|
|
16013
|
+
const entry = linkToLine(cursor, s, abs, obstacles);
|
|
16014
|
+
pts.push(...entry.verts);
|
|
16015
|
+
const E = entry.land;
|
|
16016
|
+
cursor = pt(E);
|
|
16017
|
+
let X;
|
|
16018
|
+
if (isLast) {
|
|
16019
|
+
const exit = linkToPoint(cursor, bIn, s, abs, obstacles);
|
|
16020
|
+
pts.push(...exit.verts);
|
|
16021
|
+
X = exit.onLine;
|
|
16022
|
+
} else {
|
|
16023
|
+
const next = sectors[live[pos + 1]];
|
|
16024
|
+
if (next.axis !== s.axis) {
|
|
16025
|
+
const Xp = s.axis === "h" ? {
|
|
16026
|
+
x: next.offset,
|
|
16027
|
+
y: s.offset
|
|
16028
|
+
} : {
|
|
16029
|
+
x: s.offset,
|
|
16030
|
+
y: next.offset
|
|
15550
16031
|
};
|
|
16032
|
+
if (Xp.x !== cursor.x || Xp.y !== cursor.y) pts.push(Xp);
|
|
16033
|
+
cursor = Xp;
|
|
16034
|
+
X = Xp;
|
|
16035
|
+
} else {
|
|
16036
|
+
const junction = nextJunctionCoord(s, live, pos + 1, sectors, bIn);
|
|
16037
|
+
const link = linkParallel(cursor, s, next, junction, abs, obstacles);
|
|
16038
|
+
pts.push(...link.verts);
|
|
16039
|
+
cursor = pt(link.land);
|
|
16040
|
+
X = link.onLine;
|
|
16041
|
+
}
|
|
16042
|
+
}
|
|
16043
|
+
if (extentOf(s, E, X) <= 0) dead.push(live[pos]);
|
|
16044
|
+
}
|
|
16045
|
+
pts.push(pt(bIn), pt(b));
|
|
16046
|
+
return {
|
|
16047
|
+
points: dedupPoints(pts),
|
|
16048
|
+
dead
|
|
16049
|
+
};
|
|
16050
|
+
}
|
|
16051
|
+
/**
|
|
16052
|
+
* The route's CHAIN's order over the live's sectors: the full permutation's
|
|
16053
|
+
* pool over the small's count (the ≤ 3's lines — the user's fix's count),
|
|
16054
|
+
* the crossing's parameter's single chain over the rest (the factorial's
|
|
16055
|
+
* cost's cap). The stored's data's order stands the selection's input only
|
|
16056
|
+
* (the stale's order's stand — the selection's winner's route stands the
|
|
16057
|
+
* data's order's irrelevance, the commit's path's order's convergence).
|
|
16058
|
+
*/
|
|
16059
|
+
function chainOrders(live, sectors, aOut, bIn) {
|
|
16060
|
+
if (live.length <= 1) return [[...live]];
|
|
16061
|
+
if (live.length > 3) return [[...live].sort((u, v) => crossParam(sectors[u], aOut, bIn) - crossParam(sectors[v], aOut, bIn))];
|
|
16062
|
+
const orders = [];
|
|
16063
|
+
const permute = (rest, acc) => {
|
|
16064
|
+
if (rest.length === 0) {
|
|
16065
|
+
orders.push(acc);
|
|
16066
|
+
return;
|
|
16067
|
+
}
|
|
16068
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
16069
|
+
const head = rest[i];
|
|
16070
|
+
permute([...rest.slice(0, i), ...rest.slice(i + 1)], [...acc, head]);
|
|
16071
|
+
}
|
|
16072
|
+
};
|
|
16073
|
+
permute([...live], []);
|
|
16074
|
+
return orders;
|
|
16075
|
+
}
|
|
16076
|
+
/** The single order's fixed-point's resolve (the dead's sectors' prune's
|
|
16077
|
+
* re-solve, up to the sectors' count — the dead's accumulate over the
|
|
16078
|
+
* iterations: a sector pruned by the middle's re-solve stands reported
|
|
16079
|
+
* too). */
|
|
16080
|
+
function resolveOrder(a, b, live, sectors, obstacles) {
|
|
16081
|
+
let currentLive = [...live];
|
|
16082
|
+
const deadAll = /* @__PURE__ */ new Set();
|
|
16083
|
+
let result = buildRoute(a, b, currentLive, sectors, obstacles);
|
|
16084
|
+
let iter = 0;
|
|
16085
|
+
while (result.dead.length > 0 && iter < sectors.length + 1) {
|
|
16086
|
+
iter += 1;
|
|
16087
|
+
for (const d of result.dead) deadAll.add(d);
|
|
16088
|
+
const deadSet = new Set(result.dead);
|
|
16089
|
+
const nextLive = currentLive.filter((i) => !deadSet.has(i));
|
|
16090
|
+
if (nextLive.length === currentLive.length) break;
|
|
16091
|
+
currentLive = nextLive;
|
|
16092
|
+
result = buildRoute(a, b, currentLive, sectors, obstacles);
|
|
16093
|
+
}
|
|
16094
|
+
return {
|
|
16095
|
+
points: result.points,
|
|
16096
|
+
dead: [...deadAll].sort((u, v) => u - v)
|
|
16097
|
+
};
|
|
16098
|
+
}
|
|
16099
|
+
/**
|
|
16100
|
+
* The fixed-sectors' route (the public's entry): the chain's order's
|
|
16101
|
+
* selection over the permutation's pool (the small's count's stand) — the
|
|
16102
|
+
* strict TOTAL order (the dead's count first: the user's fixed's lines
|
|
16103
|
+
* stand preserved over the length's shorten, then the length's, the
|
|
16104
|
+
* bends', the route's OWN canonical key — the unique winner's stand, the
|
|
16105
|
+
* deterministic's rerun's parity). The winner's dead's list stands the
|
|
16106
|
+
* data's prune's stand over the commit.
|
|
16107
|
+
*/
|
|
16108
|
+
function sectorRouteOf(a, b, sectors, obstacles) {
|
|
16109
|
+
if (a.x === b.x && a.y === b.y) return {
|
|
16110
|
+
points: [pt(a), pt(b)],
|
|
16111
|
+
dead: sectors.map((_, i) => i)
|
|
16112
|
+
};
|
|
16113
|
+
const aOut = orthoStubOf(a);
|
|
16114
|
+
const bIn = orthoStubOf(b);
|
|
16115
|
+
const all = sectors.map((_, i) => i);
|
|
16116
|
+
let best = null;
|
|
16117
|
+
for (const order of chainOrders(all, sectors, aOut, bIn)) {
|
|
16118
|
+
const route = resolveOrder(a, b, order, sectors, obstacles);
|
|
16119
|
+
const deadCount = route.dead.length;
|
|
16120
|
+
const length = routeLength(route.points);
|
|
16121
|
+
const bends = routeBends(route.points);
|
|
16122
|
+
const key = routeKeyOf(route.points);
|
|
16123
|
+
if (best === null || deadCount < best.deadCount || deadCount === best.deadCount && (length < best.length || length === best.length && (bends < best.bends || bends === best.bends && routeKeyLess(key, best.key)))) best = {
|
|
16124
|
+
route,
|
|
16125
|
+
deadCount,
|
|
16126
|
+
length,
|
|
16127
|
+
bends,
|
|
16128
|
+
key
|
|
16129
|
+
};
|
|
16130
|
+
}
|
|
16131
|
+
return best !== null ? best.route : {
|
|
16132
|
+
points: [pt(a), pt(b)],
|
|
16133
|
+
dead: all
|
|
16134
|
+
};
|
|
16135
|
+
}
|
|
16136
|
+
/** The run's sector (both vertices on the carrier line, over the eps) —
|
|
16137
|
+
* the fixed sector's index, or `null` over the auto run (the drag's new
|
|
16138
|
+
* sector's stand). */
|
|
16139
|
+
function sectorIndexOfRun(sectors, route, runIndex) {
|
|
16140
|
+
const p = route[runIndex];
|
|
16141
|
+
const q = route[runIndex + 1];
|
|
16142
|
+
if (p === void 0 || q === void 0 || p.x === q.x && p.y === q.y) return null;
|
|
16143
|
+
for (let i = 0; i < sectors.length; i += 1) {
|
|
16144
|
+
const s = sectors[i];
|
|
16145
|
+
if (s.axis === "h" ? Math.abs(p.y - s.offset) <= .01 && Math.abs(q.y - s.offset) <= .01 : Math.abs(p.x - s.offset) <= .01 && Math.abs(q.x - s.offset) <= .01) return i;
|
|
16146
|
+
}
|
|
16147
|
+
return null;
|
|
16148
|
+
}
|
|
16149
|
+
/**
|
|
16150
|
+
* The parallel drag's candidate sectors (the live preview's inputs): the
|
|
16151
|
+
* stored sectors, the dragged run's sector's carrier line shifted by the
|
|
16152
|
+
* delta (the run's axis's perpendicular: the horizontal's over y, the
|
|
16153
|
+
* vertical's over x). The dragged run's AUTO stand (no stored sector over
|
|
16154
|
+
* its line) stands the NEW sector's stand — the run's own line over the
|
|
16155
|
+
* drag's moment (the fix's moment's from / to), the commit's conversion's
|
|
16156
|
+
* stand.
|
|
16157
|
+
*/
|
|
16158
|
+
function draggedSectorsOf(sectors, route, runIndex, delta) {
|
|
16159
|
+
const own = sectorIndexOfRun(sectors, route, runIndex);
|
|
16160
|
+
const live = own === null ? [...sectors] : sectors.map((s, i) => i === own ? { ...s } : s);
|
|
16161
|
+
if (own === null) {
|
|
16162
|
+
const p = route[runIndex];
|
|
16163
|
+
const q = route[runIndex + 1];
|
|
16164
|
+
const axis = p.y === q.y ? "h" : "v";
|
|
16165
|
+
const offset = (axis === "h" ? p.y : p.x) + delta;
|
|
16166
|
+
live.push({
|
|
16167
|
+
axis,
|
|
16168
|
+
offset,
|
|
16169
|
+
from: {
|
|
16170
|
+
x: p.x,
|
|
16171
|
+
y: p.y
|
|
16172
|
+
},
|
|
16173
|
+
to: {
|
|
16174
|
+
x: q.x,
|
|
16175
|
+
y: q.y
|
|
15551
16176
|
}
|
|
16177
|
+
});
|
|
16178
|
+
return live;
|
|
16179
|
+
}
|
|
16180
|
+
const s = live[own];
|
|
16181
|
+
s.offset += delta;
|
|
16182
|
+
return live;
|
|
16183
|
+
}
|
|
16184
|
+
// src/canvas/connector-live.ts
|
|
16185
|
+
/** The previewed blocks over the in-flight move / resize sessions (the
|
|
16186
|
+
* untouched blocks' references stand — the stable read's parity). */
|
|
16187
|
+
function previewBlocksOf(session, blocks, childIds) {
|
|
16188
|
+
const { movePreview, resizePreview } = session;
|
|
16189
|
+
if (movePreview === null && resizePreview === null) return blocks;
|
|
16190
|
+
const next = { ...blocks };
|
|
16191
|
+
for (const childId of childIds) {
|
|
16192
|
+
const item = next[childId];
|
|
16193
|
+
if (item === void 0 || item.type === "connector") continue;
|
|
16194
|
+
if (resizePreview !== null && resizePreview.id === childId) next[childId] = {
|
|
16195
|
+
...item,
|
|
16196
|
+
geometry: {
|
|
16197
|
+
...item.geometry,
|
|
16198
|
+
...resizePreview.box
|
|
16199
|
+
}
|
|
16200
|
+
};
|
|
16201
|
+
else if (movePreview !== null && movePreview.idSet.has(childId)) {
|
|
16202
|
+
const g = effectiveGeometry(item);
|
|
16203
|
+
next[childId] = {
|
|
16204
|
+
...item,
|
|
16205
|
+
geometry: {
|
|
16206
|
+
x: g.x + movePreview.dx,
|
|
16207
|
+
y: g.y + movePreview.dy,
|
|
16208
|
+
w: g.w,
|
|
16209
|
+
h: g.h
|
|
16210
|
+
}
|
|
16211
|
+
};
|
|
15552
16212
|
}
|
|
15553
16213
|
}
|
|
15554
|
-
|
|
15555
|
-
|
|
16214
|
+
return next;
|
|
16215
|
+
}
|
|
16216
|
+
/** The route's AVOIDANCE obstacles' boxes (the previewed stand — the
|
|
16217
|
+
* dragged figure's box stands live, the line's re-route follows the
|
|
16218
|
+
* frame's). */
|
|
16219
|
+
function connectorObstacleBoxes(previewBlocks, childIds) {
|
|
16220
|
+
const boxes = [];
|
|
16221
|
+
for (const childId of childIds) {
|
|
16222
|
+
const item = previewBlocks[childId];
|
|
16223
|
+
if (item === void 0 || item.type === "connector" || item.type === "group") continue;
|
|
16224
|
+
boxes.push(effectiveGeometry(item));
|
|
16225
|
+
}
|
|
16226
|
+
return boxes;
|
|
16227
|
+
}
|
|
16228
|
+
// src/canvas/connector-sector-geometry.ts
|
|
16229
|
+
/** The lenient's parse over `attrs.sectors` (the orthogonal's variant
|
|
16230
|
+
* only — the other's variant's sectors' stand ignored, the variant's
|
|
16231
|
+
* switch's drop; the absent attr stands none). */
|
|
16232
|
+
function parseSectorEntries(sectors, variant) {
|
|
16233
|
+
const entries = [];
|
|
16234
|
+
if (variant !== "orthogonal" || !Array.isArray(sectors)) return entries;
|
|
16235
|
+
for (let index = 0; index < sectors.length; index += 1) {
|
|
16236
|
+
const item = sectors[index];
|
|
16237
|
+
if (item === null || typeof item !== "object") continue;
|
|
16238
|
+
const { axis, offset, from, to } = item;
|
|
16239
|
+
if (axis !== "h" && axis !== "v" || typeof offset !== "number" || !Number.isFinite(offset)) continue;
|
|
16240
|
+
if (!Array.isArray(from) || from.length !== 2 || !Array.isArray(to) || to.length !== 2) continue;
|
|
16241
|
+
if (![
|
|
16242
|
+
from[0],
|
|
16243
|
+
from[1],
|
|
16244
|
+
to[0],
|
|
16245
|
+
to[1]
|
|
16246
|
+
].every((c) => typeof c === "number" && Number.isFinite(c))) continue;
|
|
16247
|
+
entries.push({
|
|
16248
|
+
line: {
|
|
16249
|
+
axis,
|
|
16250
|
+
offset,
|
|
16251
|
+
from: {
|
|
16252
|
+
x: from[0],
|
|
16253
|
+
y: from[1]
|
|
16254
|
+
},
|
|
16255
|
+
to: {
|
|
16256
|
+
x: to[0],
|
|
16257
|
+
y: to[1]
|
|
16258
|
+
}
|
|
16259
|
+
},
|
|
16260
|
+
index
|
|
16261
|
+
});
|
|
16262
|
+
}
|
|
16263
|
+
return entries;
|
|
16264
|
+
}
|
|
16265
|
+
/** The solver's dead's indexes over the STORED list (the parsed list's
|
|
16266
|
+
* order's map — the malformed's drop's stand). */
|
|
16267
|
+
function deadIndexesOf(entries, dead) {
|
|
16268
|
+
return dead.map((index) => entries[index]?.index ?? -1).filter((index) => index >= 0);
|
|
16269
|
+
}
|
|
16270
|
+
/** The FIXED sectors' geometry (the new model's stand): `null` over the
|
|
16271
|
+
* pure AUTO line (the legacy auto route's stand — the solver stands over
|
|
16272
|
+
* the sectors' data or the drag's NEW sector only). */
|
|
16273
|
+
function sectorRouteGeometryOf(args) {
|
|
16274
|
+
const { entries, segment, startDraw, endDraw, obstacles } = args;
|
|
16275
|
+
if (entries.length === 0 && segment === null) return null;
|
|
16276
|
+
const sectorLines = entries.map((entry) => entry.line);
|
|
16277
|
+
if (segment === null) {
|
|
16278
|
+
const result = sectorRouteOf(startDraw, endDraw, sectorLines, obstacles);
|
|
16279
|
+
return {
|
|
16280
|
+
path: routePathOf(result.points, endDraw),
|
|
16281
|
+
dead: deadIndexesOf(entries, result.dead)
|
|
16282
|
+
};
|
|
16283
|
+
}
|
|
16284
|
+
return {
|
|
16285
|
+
path: routePathOf(sectorRouteOf(startDraw, endDraw, draggedSectorsOf(sectorLines, sectorRouteOf(startDraw, endDraw, sectorLines, obstacles).points, segment.index, segment.delta), obstacles).points, endDraw),
|
|
16286
|
+
dead: []
|
|
16287
|
+
};
|
|
16288
|
+
}
|
|
16289
|
+
// src/canvas/connector-line-geometry.ts
|
|
16290
|
+
function connectorLineGeometryOf(connectorId, block, childIds, blocks, session) {
|
|
16291
|
+
const attrs = block.attrs;
|
|
16292
|
+
if (attrs === void 0) return null;
|
|
16293
|
+
const { endpointDrag, endpointPreview, segmentDrag } = session;
|
|
16294
|
+
const segment = segmentDrag !== null && segmentDrag.connectorId === connectorId ? {
|
|
16295
|
+
index: segmentDrag.index,
|
|
16296
|
+
delta: segmentDrag.delta
|
|
16297
|
+
} : null;
|
|
16298
|
+
const previewBlocks = previewBlocksOf(session, blocks, childIds);
|
|
16299
|
+
const obstacleBoxes = connectorObstacleBoxes(previewBlocks, childIds);
|
|
16300
|
+
const startBox = endpointBoxOf(attrs.start, childIds, previewBlocks);
|
|
16301
|
+
const endBox = endpointBoxOf(attrs.end, childIds, previewBlocks);
|
|
15556
16302
|
const startFree = attrs.start.x !== void 0 && attrs.start.y !== void 0 ? {
|
|
15557
16303
|
x: attrs.start.x,
|
|
15558
16304
|
y: attrs.start.y
|
|
@@ -15575,27 +16321,26 @@ function connectorMidpoint(connectorId, childIds, blocks, previews) {
|
|
|
15575
16321
|
x: 0,
|
|
15576
16322
|
y: 0
|
|
15577
16323
|
};
|
|
15578
|
-
const startPoint = endpointPointOf(attrs.start, childIds,
|
|
15579
|
-
const endPoint = endpointPointOf(attrs.end, childIds,
|
|
16324
|
+
const startPoint = endpointPointOf(attrs.start, childIds, previewBlocks, startToward);
|
|
16325
|
+
const endPoint = endpointPointOf(attrs.end, childIds, previewBlocks, endToward);
|
|
15580
16326
|
if (startPoint === null || endPoint === null) return null;
|
|
15581
|
-
const
|
|
15582
|
-
const
|
|
15583
|
-
|
|
15584
|
-
|
|
15585
|
-
if (endpointDrag === null || endpointDrag.connectorId !== connectorId || endpointDrag.which !== which) return resolved;
|
|
15586
|
-
const preview = previews?.endpointPreview ?? null;
|
|
15587
|
-
if (preview === null) return resolved;
|
|
15588
|
-
const snap = preview.snap;
|
|
16327
|
+
const dragging = endpointDrag !== null && endpointDrag.connectorId === connectorId;
|
|
16328
|
+
const snapPoint = (which) => {
|
|
16329
|
+
if (!dragging || endpointDrag === null || endpointDrag.which !== which || endpointPreview === null) return null;
|
|
16330
|
+
const snap = endpointPreview.snap;
|
|
15589
16331
|
const point = {
|
|
15590
|
-
x:
|
|
15591
|
-
y:
|
|
15592
|
-
};
|
|
15593
|
-
if (snap === null) return {
|
|
15594
|
-
...point,
|
|
15595
|
-
nx: resolved.nx,
|
|
15596
|
-
ny: resolved.ny
|
|
16332
|
+
x: endpointPreview.point.x,
|
|
16333
|
+
y: endpointPreview.point.y
|
|
15597
16334
|
};
|
|
15598
|
-
|
|
16335
|
+
if (snap === null) {
|
|
16336
|
+
const stored = which === "start" ? startPoint : endPoint;
|
|
16337
|
+
return {
|
|
16338
|
+
...point,
|
|
16339
|
+
nx: stored.nx,
|
|
16340
|
+
ny: stored.ny
|
|
16341
|
+
};
|
|
16342
|
+
}
|
|
16343
|
+
const sibling = previewBlocks[snap.blockId];
|
|
15599
16344
|
if (sibling === void 0) return {
|
|
15600
16345
|
...point,
|
|
15601
16346
|
nx: 0,
|
|
@@ -15610,93 +16355,329 @@ function connectorMidpoint(connectorId, childIds, blocks, previews) {
|
|
|
15610
16355
|
ny: normal.ny
|
|
15611
16356
|
};
|
|
15612
16357
|
};
|
|
15613
|
-
const startDraw =
|
|
15614
|
-
const endDraw =
|
|
15615
|
-
const
|
|
15616
|
-
|
|
15617
|
-
|
|
15618
|
-
|
|
15619
|
-
|
|
15620
|
-
|
|
15621
|
-
|
|
15622
|
-
|
|
15623
|
-
|
|
15624
|
-
|
|
15625
|
-
|
|
15626
|
-
|
|
15627
|
-
|
|
16358
|
+
const startDraw = dragging && endpointDrag !== null && endpointDrag.which === "start" ? snapPoint("start") ?? startPoint : startPoint;
|
|
16359
|
+
const endDraw = dragging && endpointDrag !== null && endpointDrag.which === "end" ? snapPoint("end") ?? endPoint : endPoint;
|
|
16360
|
+
const legacy = startBox !== null && endBox !== null && startFree === null && endFree === null && attrs.start.port === void 0 && attrs.end.port === void 0 && !dragging;
|
|
16361
|
+
const storedPoints = attrs.points ?? [];
|
|
16362
|
+
const waypointDrag = dragging && endpointDrag !== null && endpointDrag.which === "waypoint" && endpointPreview !== null ? endpointDrag : null;
|
|
16363
|
+
const waypointIndex = waypointDrag !== null ? waypointDrag.index : void 0;
|
|
16364
|
+
const livePoint = endpointPreview !== null ? {
|
|
16365
|
+
x: endpointPreview.point.x,
|
|
16366
|
+
y: endpointPreview.point.y
|
|
16367
|
+
} : null;
|
|
16368
|
+
const points = waypointDrag === null || waypointIndex === void 0 || livePoint === null ? storedPoints : waypointDrag.seeded ? [
|
|
16369
|
+
...storedPoints.slice(0, waypointIndex),
|
|
16370
|
+
[livePoint.x, livePoint.y],
|
|
16371
|
+
...storedPoints.slice(waypointIndex)
|
|
16372
|
+
] : storedPoints.map(([x, y], index) => index === waypointIndex ? [livePoint.x, livePoint.y] : [x, y]);
|
|
16373
|
+
const variant = attrs.variant ?? "straight";
|
|
16374
|
+
const custom = variant === "curved" ? [] : points;
|
|
16375
|
+
const sectorEntries = parseSectorEntries(attrs.sectors, variant);
|
|
16376
|
+
const sector = variant === "orthogonal" && custom.length === 0 ? sectorRouteGeometryOf({
|
|
16377
|
+
entries: sectorEntries,
|
|
16378
|
+
segment,
|
|
16379
|
+
startDraw,
|
|
16380
|
+
endDraw,
|
|
16381
|
+
obstacles: obstacleBoxes
|
|
16382
|
+
}) : null;
|
|
16383
|
+
if (legacy && variant === "orthogonal") {
|
|
16384
|
+
if (sector !== null) return {
|
|
16385
|
+
path: sector.path.d,
|
|
16386
|
+
mid: sector.path.mid,
|
|
16387
|
+
startDraw,
|
|
16388
|
+
endDraw,
|
|
16389
|
+
dragging,
|
|
16390
|
+
points: sector.path.points.map((point) => ({
|
|
16391
|
+
x: point.x,
|
|
16392
|
+
y: point.y
|
|
16393
|
+
})),
|
|
16394
|
+
stubs: {
|
|
16395
|
+
start: orthoStubOf(startDraw),
|
|
16396
|
+
end: orthoStubOf(endDraw)
|
|
16397
|
+
},
|
|
16398
|
+
deadSectors: sector.dead
|
|
16399
|
+
};
|
|
16400
|
+
const routeBends = custom.length > 0 ? custom : null;
|
|
16401
|
+
const basePoints = routeBends !== null && routeBends.length > 0 ? reorthRoute(startPoint, startPoint, routeBends.map(([x, y]) => ({
|
|
16402
|
+
x,
|
|
16403
|
+
y
|
|
16404
|
+
})), endPoint, endPoint, startPoint, endPoint).map((point) => ({
|
|
16405
|
+
x: point.x,
|
|
16406
|
+
y: point.y
|
|
16407
|
+
})) : connectorPath(startBox, endBox, variant).points;
|
|
16408
|
+
const first = basePoints[0];
|
|
16409
|
+
const last = basePoints[basePoints.length - 1];
|
|
16410
|
+
const canonical = [
|
|
16411
|
+
{
|
|
16412
|
+
x: first.x,
|
|
16413
|
+
y: first.y
|
|
16414
|
+
},
|
|
16415
|
+
{
|
|
16416
|
+
x: first.x,
|
|
16417
|
+
y: first.y
|
|
16418
|
+
},
|
|
16419
|
+
...basePoints.slice(1),
|
|
16420
|
+
{
|
|
16421
|
+
x: last.x,
|
|
16422
|
+
y: last.y
|
|
16423
|
+
}
|
|
16424
|
+
];
|
|
16425
|
+
const moved = segment === null ? canonical : moveSegmentRoute(canonical, segment.index, segment.delta);
|
|
15628
16426
|
return {
|
|
15629
|
-
|
|
15630
|
-
|
|
16427
|
+
path: simplifyRoute(moved).map((point, i) => `${i === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" "),
|
|
16428
|
+
mid: routePathOf(moved, {
|
|
16429
|
+
x: last.x,
|
|
16430
|
+
y: last.y
|
|
16431
|
+
}).mid,
|
|
16432
|
+
startDraw,
|
|
16433
|
+
endDraw,
|
|
16434
|
+
dragging,
|
|
16435
|
+
points: moved.map((point) => ({
|
|
16436
|
+
x: point.x,
|
|
16437
|
+
y: point.y
|
|
16438
|
+
})),
|
|
16439
|
+
stubs: {
|
|
16440
|
+
start: {
|
|
16441
|
+
x: first.x,
|
|
16442
|
+
y: first.y
|
|
16443
|
+
},
|
|
16444
|
+
end: {
|
|
16445
|
+
x: last.x,
|
|
16446
|
+
y: last.y
|
|
16447
|
+
}
|
|
16448
|
+
},
|
|
16449
|
+
deadSectors: []
|
|
15631
16450
|
};
|
|
15632
16451
|
}
|
|
15633
|
-
|
|
15634
|
-
|
|
15635
|
-
|
|
15636
|
-
|
|
15637
|
-
|
|
15638
|
-
|
|
16452
|
+
const resolved = (() => {
|
|
16453
|
+
if (sector !== null) return sector.path;
|
|
16454
|
+
if (custom.length > 0) return variant === "straight" ? connectorPathPoints({
|
|
16455
|
+
...startDraw,
|
|
16456
|
+
nx: 0,
|
|
16457
|
+
ny: 0
|
|
16458
|
+
}, {
|
|
16459
|
+
...endDraw,
|
|
16460
|
+
nx: 0,
|
|
16461
|
+
ny: 0
|
|
16462
|
+
}, "straight", { custom }) : connectorPathPoints(startDraw, endDraw, variant, {
|
|
16463
|
+
custom,
|
|
16464
|
+
segment
|
|
16465
|
+
});
|
|
16466
|
+
if (legacy) {
|
|
16467
|
+
const base = connectorPath(startBox, endBox, variant);
|
|
16468
|
+
return segment === null ? base : routePathOf(moveSegmentRoute(base.points, segment.index, segment.delta), base.end);
|
|
16469
|
+
}
|
|
16470
|
+
return connectorPathPoints(startDraw, endDraw, variant, {
|
|
16471
|
+
obstacles: obstacleBoxes,
|
|
16472
|
+
segment
|
|
16473
|
+
});
|
|
16474
|
+
})();
|
|
16475
|
+
return {
|
|
16476
|
+
path: resolved.d,
|
|
16477
|
+
mid: resolved.mid,
|
|
16478
|
+
startDraw,
|
|
16479
|
+
endDraw,
|
|
16480
|
+
dragging,
|
|
16481
|
+
points: resolved.points.map((point) => ({
|
|
16482
|
+
x: point.x,
|
|
16483
|
+
y: point.y
|
|
16484
|
+
})),
|
|
16485
|
+
stubs: {
|
|
16486
|
+
start: orthoStubOf(startDraw),
|
|
16487
|
+
end: orthoStubOf(endDraw)
|
|
16488
|
+
},
|
|
16489
|
+
deadSectors: sector?.dead ?? []
|
|
16490
|
+
};
|
|
16491
|
+
}
|
|
16492
|
+
/** The dark corridor's HSL stand: the lightness over the dark's (the
|
|
16493
|
+
* 20–30% band's middle), the saturation's drop (the pastel's stand — the
|
|
16494
|
+
* muted's, not the neon's). */
|
|
16495
|
+
const DARK_LIGHTNESS = .24;
|
|
16496
|
+
const DARK_SATURATION_SCALE = .55;
|
|
16497
|
+
const HEX_FILL_RE = /^#([0-9a-f]{3,8})$/i;
|
|
16498
|
+
/** The fixed hex's fill parse (`#rgb` / `#rrggbb` / `#rrggbbaa`, the
|
|
16499
|
+
* `#rgba`'s 8-digit's stand) — `null` over the non-hex (the `var()`'s
|
|
16500
|
+
* token's stand, the named's, the absence). */
|
|
16501
|
+
function parseHexFill(value) {
|
|
16502
|
+
const match = value.trim().match(HEX_FILL_RE);
|
|
16503
|
+
if (match === null) return null;
|
|
16504
|
+
const raw = match[1].toLowerCase();
|
|
16505
|
+
const is8 = raw.length === 8 || raw.length === 4;
|
|
16506
|
+
const hex = raw.length === 3 || raw.length === 4 ? raw.split("").map((c) => c + c).join("") : raw;
|
|
16507
|
+
const alpha = is8 ? Number.parseInt(hex.slice(6, 8), 16) : null;
|
|
16508
|
+
return {
|
|
16509
|
+
r: Number.parseInt(hex.slice(0, 2), 16),
|
|
16510
|
+
g: Number.parseInt(hex.slice(2, 4), 16),
|
|
16511
|
+
b: Number.parseInt(hex.slice(4, 6), 16),
|
|
16512
|
+
a: alpha === null ? null : alpha
|
|
16513
|
+
};
|
|
16514
|
+
}
|
|
16515
|
+
function toHexPair(value) {
|
|
16516
|
+
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
|
|
16517
|
+
}
|
|
16518
|
+
/** The WCAG's relative luminance (the 0..1's stand). */
|
|
16519
|
+
function relativeLuminance(r, g, b) {
|
|
16520
|
+
const channel = (value) => {
|
|
16521
|
+
const s = value / 255;
|
|
16522
|
+
return s <= .04045 ? s / 12.92 : Math.pow((s + .055) / 1.055, 2.4);
|
|
16523
|
+
};
|
|
16524
|
+
return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
|
|
16525
|
+
}
|
|
16526
|
+
/** The sRGB → HSL (the hue over the 0..360's, the lightness / saturation
|
|
16527
|
+
* over the 0..1's). */
|
|
16528
|
+
function rgbToHsl(r, g, b) {
|
|
16529
|
+
const rn = r / 255;
|
|
16530
|
+
const gn = g / 255;
|
|
16531
|
+
const bn = b / 255;
|
|
16532
|
+
const max = Math.max(rn, gn, bn);
|
|
16533
|
+
const min = Math.min(rn, gn, bn);
|
|
16534
|
+
const l = (max + min) / 2;
|
|
16535
|
+
if (max === min) return {
|
|
16536
|
+
h: 0,
|
|
16537
|
+
s: 0,
|
|
16538
|
+
l
|
|
16539
|
+
};
|
|
16540
|
+
const d = max - min;
|
|
16541
|
+
const s = l > .5 ? d / (2 - max - min) : d / (max + min);
|
|
16542
|
+
let h;
|
|
16543
|
+
if (max === rn) h = ((gn - bn) / d + (gn < bn ? 6 : 0)) * 60;
|
|
16544
|
+
else if (max === gn) h = ((bn - rn) / d + 2) * 60;
|
|
16545
|
+
else h = ((rn - gn) / d + 4) * 60;
|
|
16546
|
+
return {
|
|
16547
|
+
h,
|
|
16548
|
+
s,
|
|
16549
|
+
l
|
|
16550
|
+
};
|
|
16551
|
+
}
|
|
16552
|
+
/** The HSL → sRGB (the 0..255's channels). */
|
|
16553
|
+
function hslToRgb(h, s, l) {
|
|
16554
|
+
if (s === 0) {
|
|
16555
|
+
const v = l * 255;
|
|
16556
|
+
return {
|
|
16557
|
+
r: v,
|
|
16558
|
+
g: v,
|
|
16559
|
+
b: v
|
|
16560
|
+
};
|
|
15639
16561
|
}
|
|
15640
|
-
|
|
16562
|
+
const hue2rgb = (p, q, t) => {
|
|
16563
|
+
let tt = t;
|
|
16564
|
+
if (tt < 0) tt += 1;
|
|
16565
|
+
if (tt > 1) tt -= 1;
|
|
16566
|
+
if (tt < 1 / 6) return p + (q - p) * 6 * tt;
|
|
16567
|
+
if (tt < .5) return q;
|
|
16568
|
+
if (tt < 2 / 3) return p + (q - p) * (2 / 3 - tt) * 6;
|
|
16569
|
+
return p;
|
|
16570
|
+
};
|
|
16571
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
16572
|
+
const p = 2 * l - q;
|
|
16573
|
+
const hn = (h % 360 + 360) % 360 / 360;
|
|
16574
|
+
return {
|
|
16575
|
+
r: hue2rgb(p, q, hn + 1 / 3) * 255,
|
|
16576
|
+
g: hue2rgb(p, q, hn) * 255,
|
|
16577
|
+
b: hue2rgb(p, q, hn - 1 / 3) * 255
|
|
16578
|
+
};
|
|
16579
|
+
}
|
|
16580
|
+
/** The dark corridor's value over the light's hex (the hue's stand, the
|
|
16581
|
+
* lightness / saturation's stand); the hue-less's (the gray's) stands the
|
|
16582
|
+
* gray's dark (the `#FFFFFF`'s dark neutral's stand). The alpha's stand
|
|
16583
|
+
* (the present's 8-digit's stand over the computed's RGB). */
|
|
16584
|
+
function darkenHexHex(parts) {
|
|
16585
|
+
const { h, s } = rgbToHsl(parts.r, parts.g, parts.b);
|
|
16586
|
+
const rgb = hslToRgb(h, s * DARK_SATURATION_SCALE, DARK_LIGHTNESS);
|
|
16587
|
+
const hex = `#${toHexPair(rgb.r)}${toHexPair(rgb.g)}${toHexPair(rgb.b)}`;
|
|
16588
|
+
return parts.a === null ? hex : `${hex}${toHexPair(parts.a)}`;
|
|
15641
16589
|
}
|
|
15642
16590
|
/**
|
|
15643
|
-
* The
|
|
15644
|
-
*
|
|
15645
|
-
*
|
|
15646
|
-
*
|
|
16591
|
+
* The effective data color (the render's stand): the dark theme's light
|
|
16592
|
+
* fixed hex stands the dark corridor's value; every other stand (the
|
|
16593
|
+
* light's theme, the dark's value, the non-hex) stands verbatim
|
|
16594
|
+
* (`undefined` stands the absence — the caller's default's stand).
|
|
15647
16595
|
*/
|
|
15648
|
-
function
|
|
15649
|
-
if (
|
|
15650
|
-
|
|
15651
|
-
|
|
15652
|
-
|
|
15653
|
-
|
|
15654
|
-
|
|
15655
|
-
}));
|
|
15656
|
-
const index = drag.index;
|
|
15657
|
-
const live = preview.point;
|
|
15658
|
-
return (block.attrs.points ?? []).map(([x, y], i) => i === index ? {
|
|
15659
|
-
x: live.x,
|
|
15660
|
-
y: live.y
|
|
15661
|
-
} : {
|
|
15662
|
-
x,
|
|
15663
|
-
y
|
|
15664
|
-
});
|
|
16596
|
+
function effectiveColorOf(value, isDark) {
|
|
16597
|
+
if (value === void 0) return void 0;
|
|
16598
|
+
if (isDark) {
|
|
16599
|
+
const parts = parseHexFill(value);
|
|
16600
|
+
if (parts !== null && relativeLuminance(parts.r, parts.g, parts.b) > .2) return darkenHexHex(parts);
|
|
16601
|
+
}
|
|
16602
|
+
return value;
|
|
15665
16603
|
}
|
|
15666
|
-
// src/canvas/geometry/utils/frame-window.ts
|
|
15667
16604
|
/**
|
|
15668
|
-
* The
|
|
15669
|
-
*
|
|
15670
|
-
*
|
|
15671
|
-
*
|
|
15672
|
-
*
|
|
15673
|
-
* world origin).
|
|
16605
|
+
* The text's contrast over the effective fill (the WCAG's ratio's stand —
|
|
16606
|
+
* the black / white over the better). The explicit `textColor` stands
|
|
16607
|
+
* (the data's stand) — the caller's resolution. `null` over the
|
|
16608
|
+
* non-hex's effective fill (the theme's foreground's inheritance's stand)
|
|
16609
|
+
* and the absent's fill.
|
|
15674
16610
|
*/
|
|
15675
|
-
function
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
16611
|
+
function contrastTextOf(fill, isDark) {
|
|
16612
|
+
const effective = effectiveColorOf(fill, isDark);
|
|
16613
|
+
if (effective === void 0) return null;
|
|
16614
|
+
const parts = parseHexFill(effective);
|
|
16615
|
+
if (parts === null) return null;
|
|
16616
|
+
const luminance = relativeLuminance(parts.r, parts.g, parts.b);
|
|
16617
|
+
const ratioOverBlack = (luminance + .05) / .05;
|
|
16618
|
+
return 1.05 / (luminance + .05) >= ratioOverBlack ? "#ffffff" : "#000000";
|
|
15680
16619
|
}
|
|
16620
|
+
// src/canvas/connector-constants.ts
|
|
16621
|
+
/** The canvas connector's render constants: the v1 connector stroke (the
|
|
16622
|
+
* shape token), the selected connector's stroke (the canvas selection's
|
|
16623
|
+
* cyan — the token stands in both themes; the page `--accent` is a hover
|
|
16624
|
+
* surface, not a line color), the connect badge's green (the endpoint
|
|
16625
|
+
* drag's port snap indicator), the line's stroke width bounds (canvas px;
|
|
16626
|
+
* the data stand is 1–4, the absent stand is 1 — the registry spec's
|
|
16627
|
+
* parity), the selection's width emphasis, the arrowhead's length (the marker's coordinate space), the
|
|
16628
|
+
* circle endpoint's radius, the connect badge's radius + its offset from
|
|
16629
|
+
* the snapped port along its outward normal. */
|
|
16630
|
+
const CONNECTOR_STROKE = "var(--docblocks-canvas-shape-stroke, currentColor)";
|
|
16631
|
+
/** The selected connector's stroke (the canvas selection's cyan — the
|
|
16632
|
+
* token stands in both themes; the page `--accent` is a hover surface,
|
|
16633
|
+
* not a line color). */
|
|
16634
|
+
const CONNECTOR_SELECTED_STROKE = "var(--docblocks-canvas-selected-stroke)";
|
|
16635
|
+
/** The connect badge's green (the endpoint drag's port snap indicator). */
|
|
16636
|
+
const CONNECT_COLOR = "var(--docblocks-canvas-connect-color, #16a34a)";
|
|
16637
|
+
// src/canvas/connector-utils.ts
|
|
15681
16638
|
/**
|
|
15682
|
-
* The
|
|
15683
|
-
*
|
|
15684
|
-
*
|
|
15685
|
-
*
|
|
15686
|
-
* dot at the tile's CENTER over the world's grid line (the container's
|
|
15687
|
-
* percentage position's stand), so the box's background position offsets
|
|
15688
|
-
* the tile's half step back — the dot stands on the world's grid line and
|
|
15689
|
-
* the box slides over the still dots.
|
|
16639
|
+
* The arrowhead def's id over the surface's id and the fill value (the
|
|
16640
|
+
* per-value def: the token / the selection's accent keep their legacy
|
|
16641
|
+
* ids, the data color stands its own id — the non-id characters are
|
|
16642
|
+
* dropped: a hex's "#" would break the url(#...) fragment).
|
|
15690
16643
|
*/
|
|
15691
|
-
function
|
|
15692
|
-
|
|
15693
|
-
|
|
15694
|
-
|
|
15695
|
-
|
|
15696
|
-
|
|
15697
|
-
|
|
15698
|
-
|
|
15699
|
-
|
|
16644
|
+
function arrowDefId(surfaceId, fill) {
|
|
16645
|
+
return `docblocks-conn-arrow-${surfaceId}${fill === "var(--docblocks-canvas-shape-stroke, currentColor)" ? "" : fill === "var(--docblocks-canvas-selected-stroke)" ? "-selected" : `-c${fill.replace(/[^a-z0-9]/gi, "")}`}`;
|
|
16646
|
+
}
|
|
16647
|
+
/** The line's effective width: the 1–4 data attr's clamp stand (the
|
|
16648
|
+
* lenient render over the raw write) + the selection's bump. The label
|
|
16649
|
+
* chip's frame reads the same stand (the frame stands the line). */
|
|
16650
|
+
function connectorStrokeWidthOf(attrs, selected) {
|
|
16651
|
+
const baseWidth = Math.min(4, Math.max(1, Math.round(attrs.strokeWidth ?? 1)));
|
|
16652
|
+
return selected ? baseWidth + 1 : baseWidth;
|
|
16653
|
+
}
|
|
16654
|
+
/** The connector's effective stroke: the selection's accent wins, the
|
|
16655
|
+
* data color (a hex) next, the token otherwise (the "none" color stands
|
|
16656
|
+
* the token — the line is still drawn, the paint is the theme's). */
|
|
16657
|
+
function connectorStrokeOf(block, selected) {
|
|
16658
|
+
const attrs = block.attrs;
|
|
16659
|
+
if (selected) return CONNECTOR_SELECTED_STROKE;
|
|
16660
|
+
if (attrs === void 0 || attrs.strokeColor === void 0 || attrs.strokeColor === "none") return CONNECTOR_STROKE;
|
|
16661
|
+
return attrs.strokeColor;
|
|
16662
|
+
}
|
|
16663
|
+
/** The connector's effective stroke over the themes (the render-time's
|
|
16664
|
+
* transform — the data stands the source hex): the dark theme's light
|
|
16665
|
+
* fixed `strokeColor` stands the dark corridor's value (the parity with
|
|
16666
|
+
* the shape's fill / stroke); the token's stands (the theme's default /
|
|
16667
|
+
* the selection's accent) stand pass-through on their own. */
|
|
16668
|
+
function effectiveConnectorStrokeOf(block, selected, isDark) {
|
|
16669
|
+
const stroke = connectorStrokeOf(block, selected);
|
|
16670
|
+
return effectiveColorOf(stroke, isDark) ?? stroke;
|
|
16671
|
+
}
|
|
16672
|
+
/** The line's own resolved geometry's SEAT (the label's chip / the
|
|
16673
|
+
* toolbar's anchor / the label's edit's frame — the line's own vertices'
|
|
16674
|
+
* mid, projected onto the drawn line, so the seat never stands off the
|
|
16675
|
+
* drawn line): the session's stand (the toolbar's read over the in-flight
|
|
16676
|
+
* endpoint / segment sessions, the label's edit over the committed's)
|
|
16677
|
+
* keeps the seat live over the line's re-draw. `null` over the
|
|
16678
|
+
* unresolvable line (the caller stands its absent's stand). */
|
|
16679
|
+
function connectorMidOf(id, block, children, blocks, session) {
|
|
16680
|
+
return connectorLineGeometryOf(id, block, children, blocks, session)?.mid ?? null;
|
|
15700
16681
|
}
|
|
15701
16682
|
// src/canvas/viewport/constants.ts
|
|
15702
16683
|
/** The zoom bounds (25%–400%). */
|
|
@@ -16488,259 +17469,99 @@ function createConnectorSessions(store, doc, standPoint) {
|
|
|
16488
17469
|
state.setConnectorEndpoint(null);
|
|
16489
17470
|
state.setConnectorEndpointPreview(null);
|
|
16490
17471
|
if (session === null || !session.dragging) return;
|
|
16491
|
-
if (releaseClientX !== void 0 && releaseClientY !== void 0 && Math.hypot(releaseClientX - session.startClientX, releaseClientY - session.startClientY) < 3) return;
|
|
16492
|
-
const snap = snapEndpointEdge(doc, session.surfaceId, session.point);
|
|
16493
|
-
const ref = snap !== null ? {
|
|
16494
|
-
blockId: snap.blockId,
|
|
16495
|
-
port: snap.port,
|
|
16496
|
-
portT: roundPortT(snap.t)
|
|
16497
|
-
} : {
|
|
16498
|
-
x: Number(session.point.x.toFixed(2)),
|
|
16499
|
-
y: Number(session.point.y.toFixed(2)),
|
|
16500
|
-
...session.direction !== null ? { port: session.direction } : {}
|
|
16501
|
-
};
|
|
16502
|
-
try {
|
|
16503
|
-
doc.transact(() => {
|
|
16504
|
-
doc.updateBlock(session.connectorId, session.which === "start" ? { start: ref } : { end: ref });
|
|
16505
|
-
});
|
|
16506
|
-
} catch {}
|
|
16507
|
-
};
|
|
16508
|
-
const cancelConnectorEndpoint = () => {
|
|
16509
|
-
endpointRef.current = null;
|
|
16510
|
-
const state = store.getState();
|
|
16511
|
-
state.setConnectorEndpoint(null);
|
|
16512
|
-
state.setConnectorEndpointPreview(null);
|
|
16513
|
-
};
|
|
16514
|
-
return {
|
|
16515
|
-
onConnectorPick,
|
|
16516
|
-
onConnectorCommit,
|
|
16517
|
-
beginConnectorEndpoint,
|
|
16518
|
-
moveConnectorEndpoint,
|
|
16519
|
-
endConnectorEndpoint,
|
|
16520
|
-
cancelConnectorEndpoint
|
|
16521
|
-
};
|
|
16522
|
-
}
|
|
16523
|
-
// src/canvas/viewport/session-place.ts
|
|
16524
|
-
/** The placement's commands (the doc writes; the tool's reset over the
|
|
16525
|
-
* viewport's store). */
|
|
16526
|
-
function createPlaceCommands(store, doc) {
|
|
16527
|
-
const onPlace = (point) => {
|
|
16528
|
-
const tool = store.getState().activeTool;
|
|
16529
|
-
if (tool === null || tool === "connector" || tool === "pen") return;
|
|
16530
|
-
const size = TOOL_SIZES[tool];
|
|
16531
|
-
try {
|
|
16532
|
-
switch (tool) {
|
|
16533
|
-
case "rect":
|
|
16534
|
-
case "rounded":
|
|
16535
|
-
case "ellipse":
|
|
16536
|
-
case "diamond":
|
|
16537
|
-
case "cylinder":
|
|
16538
|
-
case "cloud":
|
|
16539
|
-
placeShape(doc, tool, point, size);
|
|
16540
|
-
break;
|
|
16541
|
-
case "container":
|
|
16542
|
-
placeContainer(doc, point, size);
|
|
16543
|
-
break;
|
|
16544
|
-
case "text":
|
|
16545
|
-
placeCanvasText(doc, point, size);
|
|
16546
|
-
break;
|
|
16547
|
-
case "frame":
|
|
16548
|
-
placeFrame(doc, point, size);
|
|
16549
|
-
break;
|
|
16550
|
-
default: assertNever(tool);
|
|
16551
|
-
}
|
|
16552
|
-
} catch {}
|
|
16553
|
-
store.getState().setActiveTool(null);
|
|
16554
|
-
};
|
|
16555
|
-
const onPlaceSize = (tool, point, size) => {
|
|
16556
|
-
store.getState().setPlacePreview(null);
|
|
16557
|
-
try {
|
|
16558
|
-
switch (tool) {
|
|
16559
|
-
case "rect":
|
|
16560
|
-
case "rounded":
|
|
16561
|
-
case "ellipse":
|
|
16562
|
-
case "diamond":
|
|
16563
|
-
case "cylinder":
|
|
16564
|
-
case "cloud":
|
|
16565
|
-
placeShape(doc, tool, point, size);
|
|
16566
|
-
break;
|
|
16567
|
-
case "container":
|
|
16568
|
-
placeContainer(doc, point, size);
|
|
16569
|
-
break;
|
|
16570
|
-
case "frame": placeFrame(doc, point, size);
|
|
16571
|
-
}
|
|
16572
|
-
} catch {}
|
|
16573
|
-
store.getState().setActiveTool(null);
|
|
16574
|
-
};
|
|
16575
|
-
const onPen = (stroke) => {
|
|
16576
|
-
try {
|
|
16577
|
-
placePenStroke(doc, stroke);
|
|
16578
|
-
} catch {}
|
|
16579
|
-
};
|
|
16580
|
-
return {
|
|
16581
|
-
onPlace,
|
|
16582
|
-
onPlaceSize,
|
|
16583
|
-
onPen
|
|
16584
|
-
};
|
|
16585
|
-
}
|
|
16586
|
-
// src/canvas/connector-line-geometry.ts
|
|
16587
|
-
function connectorLineGeometryOf(connectorId, block, childIds, blocks, session) {
|
|
16588
|
-
const attrs = block.attrs;
|
|
16589
|
-
if (attrs === void 0) return null;
|
|
16590
|
-
const { movePreview, resizePreview, endpointDrag, endpointPreview, segmentDrag } = session;
|
|
16591
|
-
const segment = segmentDrag !== null && segmentDrag.connectorId === connectorId ? {
|
|
16592
|
-
index: segmentDrag.index,
|
|
16593
|
-
delta: segmentDrag.delta
|
|
16594
|
-
} : null;
|
|
16595
|
-
const previewBlocks = (() => {
|
|
16596
|
-
if (movePreview === null && resizePreview === null) return blocks;
|
|
16597
|
-
const next = { ...blocks };
|
|
16598
|
-
for (const childId of childIds) {
|
|
16599
|
-
const item = next[childId];
|
|
16600
|
-
if (item === void 0 || item.type === "connector") continue;
|
|
16601
|
-
if (resizePreview !== null && resizePreview.id === childId) next[childId] = {
|
|
16602
|
-
...item,
|
|
16603
|
-
geometry: {
|
|
16604
|
-
...item.geometry,
|
|
16605
|
-
...resizePreview.box
|
|
16606
|
-
}
|
|
16607
|
-
};
|
|
16608
|
-
else if (movePreview !== null && movePreview.idSet.has(childId)) {
|
|
16609
|
-
const g = effectiveGeometry(item);
|
|
16610
|
-
next[childId] = {
|
|
16611
|
-
...item,
|
|
16612
|
-
geometry: {
|
|
16613
|
-
x: g.x + movePreview.dx,
|
|
16614
|
-
y: g.y + movePreview.dy,
|
|
16615
|
-
w: g.w,
|
|
16616
|
-
h: g.h
|
|
16617
|
-
}
|
|
16618
|
-
};
|
|
16619
|
-
}
|
|
16620
|
-
}
|
|
16621
|
-
return next;
|
|
16622
|
-
})();
|
|
16623
|
-
const obstacleBoxes = [];
|
|
16624
|
-
for (const childId of childIds) {
|
|
16625
|
-
const item = previewBlocks[childId];
|
|
16626
|
-
if (item === void 0 || item.type === "connector" || item.type === "group") continue;
|
|
16627
|
-
obstacleBoxes.push(effectiveGeometry(item));
|
|
16628
|
-
}
|
|
16629
|
-
const startBox = endpointBoxOf(attrs.start, childIds, previewBlocks);
|
|
16630
|
-
const endBox = endpointBoxOf(attrs.end, childIds, previewBlocks);
|
|
16631
|
-
const startFree = attrs.start.x !== void 0 && attrs.start.y !== void 0 ? {
|
|
16632
|
-
x: attrs.start.x,
|
|
16633
|
-
y: attrs.start.y
|
|
16634
|
-
} : null;
|
|
16635
|
-
const endFree = attrs.end.x !== void 0 && attrs.end.y !== void 0 ? {
|
|
16636
|
-
x: attrs.end.x,
|
|
16637
|
-
y: attrs.end.y
|
|
16638
|
-
} : null;
|
|
16639
|
-
const startToward = endBox !== null ? {
|
|
16640
|
-
x: endBox.x,
|
|
16641
|
-
y: endBox.y
|
|
16642
|
-
} : endFree ?? {
|
|
16643
|
-
x: 0,
|
|
16644
|
-
y: 0
|
|
16645
|
-
};
|
|
16646
|
-
const endToward = startBox !== null ? {
|
|
16647
|
-
x: startBox.x,
|
|
16648
|
-
y: startBox.y
|
|
16649
|
-
} : startFree ?? {
|
|
16650
|
-
x: 0,
|
|
16651
|
-
y: 0
|
|
16652
|
-
};
|
|
16653
|
-
const startPoint = endpointPointOf(attrs.start, childIds, previewBlocks, startToward);
|
|
16654
|
-
const endPoint = endpointPointOf(attrs.end, childIds, previewBlocks, endToward);
|
|
16655
|
-
if (startPoint === null || endPoint === null) return null;
|
|
16656
|
-
const dragging = endpointDrag !== null && endpointDrag.connectorId === connectorId;
|
|
16657
|
-
const snapPoint = (which) => {
|
|
16658
|
-
if (!dragging || endpointDrag === null || endpointDrag.which !== which || endpointPreview === null) return null;
|
|
16659
|
-
const snap = endpointPreview.snap;
|
|
16660
|
-
const point = {
|
|
16661
|
-
x: endpointPreview.point.x,
|
|
16662
|
-
y: endpointPreview.point.y
|
|
16663
|
-
};
|
|
16664
|
-
if (snap === null) {
|
|
16665
|
-
const stored = which === "start" ? startPoint : endPoint;
|
|
16666
|
-
return {
|
|
16667
|
-
...point,
|
|
16668
|
-
nx: stored.nx,
|
|
16669
|
-
ny: stored.ny
|
|
16670
|
-
};
|
|
16671
|
-
}
|
|
16672
|
-
const sibling = previewBlocks[snap.blockId];
|
|
16673
|
-
if (sibling === void 0) return {
|
|
16674
|
-
...point,
|
|
16675
|
-
nx: 0,
|
|
16676
|
-
ny: 0
|
|
16677
|
-
};
|
|
16678
|
-
const p = edgePointOf(effectiveGeometry(sibling), snap.port, snap.t);
|
|
16679
|
-
const normal = PORT_NORMAL[snap.port];
|
|
16680
|
-
return {
|
|
16681
|
-
x: p.x,
|
|
16682
|
-
y: p.y,
|
|
16683
|
-
nx: normal.nx,
|
|
16684
|
-
ny: normal.ny
|
|
16685
|
-
};
|
|
16686
|
-
};
|
|
16687
|
-
const startDraw = dragging && endpointDrag !== null && endpointDrag.which === "start" ? snapPoint("start") ?? startPoint : startPoint;
|
|
16688
|
-
const endDraw = dragging && endpointDrag !== null && endpointDrag.which === "end" ? snapPoint("end") ?? endPoint : endPoint;
|
|
16689
|
-
const legacy = startBox !== null && endBox !== null && startFree === null && endFree === null && attrs.start.port === void 0 && attrs.end.port === void 0 && !dragging;
|
|
16690
|
-
const polyPoint = (ref, resolved, box, key) => {
|
|
16691
|
-
const dragged = dragging && endpointDrag !== null && endpointDrag.which === key;
|
|
16692
|
-
return ref.x !== void 0 && ref.y !== void 0 ? {
|
|
16693
|
-
x: ref.x,
|
|
16694
|
-
y: ref.y
|
|
16695
|
-
} : ref.port !== void 0 || box === null || dragged ? {
|
|
16696
|
-
x: resolved.x,
|
|
16697
|
-
y: resolved.y
|
|
17472
|
+
if (releaseClientX !== void 0 && releaseClientY !== void 0 && Math.hypot(releaseClientX - session.startClientX, releaseClientY - session.startClientY) < 3) return;
|
|
17473
|
+
const snap = snapEndpointEdge(doc, session.surfaceId, session.point);
|
|
17474
|
+
const ref = snap !== null ? {
|
|
17475
|
+
blockId: snap.blockId,
|
|
17476
|
+
port: snap.port,
|
|
17477
|
+
portT: roundPortT(snap.t)
|
|
16698
17478
|
} : {
|
|
16699
|
-
x:
|
|
16700
|
-
y:
|
|
17479
|
+
x: Number(session.point.x.toFixed(2)),
|
|
17480
|
+
y: Number(session.point.y.toFixed(2)),
|
|
17481
|
+
...session.direction !== null ? { port: session.direction } : {}
|
|
16701
17482
|
};
|
|
17483
|
+
try {
|
|
17484
|
+
doc.transact(() => {
|
|
17485
|
+
doc.updateBlock(session.connectorId, session.which === "start" ? { start: ref } : { end: ref });
|
|
17486
|
+
});
|
|
17487
|
+
} catch {}
|
|
17488
|
+
};
|
|
17489
|
+
const cancelConnectorEndpoint = () => {
|
|
17490
|
+
endpointRef.current = null;
|
|
17491
|
+
const state = store.getState();
|
|
17492
|
+
state.setConnectorEndpoint(null);
|
|
17493
|
+
state.setConnectorEndpointPreview(null);
|
|
16702
17494
|
};
|
|
16703
|
-
const startPoly = polyPoint(attrs.start, startDraw, startBox, "start");
|
|
16704
|
-
const endPoly = polyPoint(attrs.end, endDraw, endBox, "end");
|
|
16705
|
-
const points = (attrs.points ?? []).map(([x, y], index) => {
|
|
16706
|
-
if (!dragging || endpointDrag === null || endpointDrag.which !== "waypoint") return [x, y];
|
|
16707
|
-
if (endpointDrag.index !== index || endpointPreview === null) return [x, y];
|
|
16708
|
-
return [endpointPreview.point.x, endpointPreview.point.y];
|
|
16709
|
-
});
|
|
16710
|
-
const variant = attrs.variant ?? "straight";
|
|
16711
|
-
const custom = variant === "curved" ? [] : points;
|
|
16712
|
-
const resolved = (() => {
|
|
16713
|
-
if (custom.length > 0) return variant === "straight" ? connectorPathPoints({
|
|
16714
|
-
...startPoly,
|
|
16715
|
-
nx: 0,
|
|
16716
|
-
ny: 0
|
|
16717
|
-
}, {
|
|
16718
|
-
...endPoly,
|
|
16719
|
-
nx: 0,
|
|
16720
|
-
ny: 0
|
|
16721
|
-
}, "straight", { custom }) : connectorPathPoints(startDraw, endDraw, variant, {
|
|
16722
|
-
custom,
|
|
16723
|
-
segment,
|
|
16724
|
-
noStub: legacy
|
|
16725
|
-
});
|
|
16726
|
-
if (legacy) {
|
|
16727
|
-
const base = connectorPath(startBox, endBox, variant);
|
|
16728
|
-
return segment === null ? base : routePathOf(moveSegmentRoute(base.points, segment.index, segment.delta, {
|
|
16729
|
-
first: false,
|
|
16730
|
-
last: false
|
|
16731
|
-
}), base.end);
|
|
16732
|
-
}
|
|
16733
|
-
return connectorPathPoints(startDraw, endDraw, variant, {
|
|
16734
|
-
obstacles: obstacleBoxes,
|
|
16735
|
-
segment
|
|
16736
|
-
});
|
|
16737
|
-
})();
|
|
16738
17495
|
return {
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
|
|
16742
|
-
|
|
16743
|
-
|
|
17496
|
+
onConnectorPick,
|
|
17497
|
+
onConnectorCommit,
|
|
17498
|
+
beginConnectorEndpoint,
|
|
17499
|
+
moveConnectorEndpoint,
|
|
17500
|
+
endConnectorEndpoint,
|
|
17501
|
+
cancelConnectorEndpoint
|
|
17502
|
+
};
|
|
17503
|
+
}
|
|
17504
|
+
// src/canvas/viewport/session-place.ts
|
|
17505
|
+
/** The placement's commands (the doc writes; the tool's reset over the
|
|
17506
|
+
* viewport's store). */
|
|
17507
|
+
function createPlaceCommands(store, doc) {
|
|
17508
|
+
const onPlace = (point) => {
|
|
17509
|
+
const tool = store.getState().activeTool;
|
|
17510
|
+
if (tool === null || tool === "connector" || tool === "pen") return;
|
|
17511
|
+
const size = TOOL_SIZES[tool];
|
|
17512
|
+
try {
|
|
17513
|
+
switch (tool) {
|
|
17514
|
+
case "rect":
|
|
17515
|
+
case "rounded":
|
|
17516
|
+
case "ellipse":
|
|
17517
|
+
case "diamond":
|
|
17518
|
+
case "cylinder":
|
|
17519
|
+
case "cloud":
|
|
17520
|
+
placeShape(doc, tool, point, size);
|
|
17521
|
+
break;
|
|
17522
|
+
case "container":
|
|
17523
|
+
placeContainer(doc, point, size);
|
|
17524
|
+
break;
|
|
17525
|
+
case "text":
|
|
17526
|
+
placeCanvasText(doc, point, size);
|
|
17527
|
+
break;
|
|
17528
|
+
case "frame":
|
|
17529
|
+
placeFrame(doc, point, size);
|
|
17530
|
+
break;
|
|
17531
|
+
default: assertNever(tool);
|
|
17532
|
+
}
|
|
17533
|
+
} catch {}
|
|
17534
|
+
store.getState().setActiveTool(null);
|
|
17535
|
+
};
|
|
17536
|
+
const onPlaceSize = (tool, point, size) => {
|
|
17537
|
+
store.getState().setPlacePreview(null);
|
|
17538
|
+
try {
|
|
17539
|
+
switch (tool) {
|
|
17540
|
+
case "rect":
|
|
17541
|
+
case "rounded":
|
|
17542
|
+
case "ellipse":
|
|
17543
|
+
case "diamond":
|
|
17544
|
+
case "cylinder":
|
|
17545
|
+
case "cloud":
|
|
17546
|
+
placeShape(doc, tool, point, size);
|
|
17547
|
+
break;
|
|
17548
|
+
case "container":
|
|
17549
|
+
placeContainer(doc, point, size);
|
|
17550
|
+
break;
|
|
17551
|
+
case "frame": placeFrame(doc, point, size);
|
|
17552
|
+
}
|
|
17553
|
+
} catch {}
|
|
17554
|
+
store.getState().setActiveTool(null);
|
|
17555
|
+
};
|
|
17556
|
+
const onPen = (stroke) => {
|
|
17557
|
+
try {
|
|
17558
|
+
placePenStroke(doc, stroke);
|
|
17559
|
+
} catch {}
|
|
17560
|
+
};
|
|
17561
|
+
return {
|
|
17562
|
+
onPlace,
|
|
17563
|
+
onPlaceSize,
|
|
17564
|
+
onPen
|
|
16744
17565
|
};
|
|
16745
17566
|
}
|
|
16746
17567
|
// src/canvas/viewport/session-segment.ts
|
|
@@ -16759,12 +17580,110 @@ function surfaceOf(doc, connectorId) {
|
|
|
16759
17580
|
blocks
|
|
16760
17581
|
};
|
|
16761
17582
|
}
|
|
17583
|
+
const round2 = (value) => Number(value.toFixed(2));
|
|
17584
|
+
/** The route's run's SPAN over a carrier line (the committed route's runs
|
|
17585
|
+
* 1..n-3 — the port's stub runs (the first / the last) stand excluded:
|
|
17586
|
+
* their line is the port's normal's line, not a sector's): the span's
|
|
17587
|
+
* min / max over the runs' BOTH ends (the run's direction's stand — a
|
|
17588
|
+
* right-to-left's run stands the same span) + the FIRST run's index (the
|
|
17589
|
+
* line's position over the route — the commit's path's order). `null` over
|
|
17590
|
+
* the absent / the degenerate span (the dead sector's stand). */
|
|
17591
|
+
function spanOfLine(route, axis, coord) {
|
|
17592
|
+
let min = null;
|
|
17593
|
+
let max = null;
|
|
17594
|
+
let position = -1;
|
|
17595
|
+
for (let i = 1; i < route.length - 2; i += 1) {
|
|
17596
|
+
const a = route[i];
|
|
17597
|
+
const b = route[i + 1];
|
|
17598
|
+
if (a.x === b.x && a.y === b.y) continue;
|
|
17599
|
+
if (!(axis === "h" ? Math.abs(a.y - coord) <= .01 && Math.abs(b.y - coord) <= .01 : Math.abs(a.x - coord) <= .01 && Math.abs(b.x - coord) <= .01)) continue;
|
|
17600
|
+
if (position === -1) position = i;
|
|
17601
|
+
const av = axis === "h" ? a.x : a.y;
|
|
17602
|
+
const bv = axis === "h" ? b.x : b.y;
|
|
17603
|
+
min = min === null ? Math.min(av, bv) : Math.min(min, av, bv);
|
|
17604
|
+
max = max === null ? Math.max(av, bv) : Math.max(max, av, bv);
|
|
17605
|
+
}
|
|
17606
|
+
if (min === null || max === null || max - min <= .01) return null;
|
|
17607
|
+
return {
|
|
17608
|
+
min,
|
|
17609
|
+
max,
|
|
17610
|
+
position
|
|
17611
|
+
};
|
|
17612
|
+
}
|
|
17613
|
+
/**
|
|
17614
|
+
* The commit's SECTORS over the committed route (the release's truth): the
|
|
17615
|
+
* dragged run stands the FIXED sector — the axis over the session's movable
|
|
17616
|
+
* axis (the vertical run's "x"'s stand the "v", the horizontal's "y"'s the
|
|
17617
|
+
* "h") + the carrier's line over the PRE-drag's run's line shifted by the
|
|
17618
|
+
* delta (the pre-route's index space — the post-drag's re-solution's
|
|
17619
|
+
* vertices stand no parity over the press's index) — the NEW sector's
|
|
17620
|
+
* stand over the auto run (the first's fix), and over the old line's
|
|
17621
|
+
* `points` the CONVERSION's stand (only the drag's run stands
|
|
17622
|
+
* fixed, the rest stands auto — the `points`' drop). The stored sectors'
|
|
17623
|
+
* extents stand re-derived over the committed route's spans (the
|
|
17624
|
+
* boundary's corners slid over the drag — the extent's update); the
|
|
17625
|
+
* span-less (the extent ≤ 0) stand the DEAD prune (the data's prune — the
|
|
17626
|
+
* sector leaves the data). The list stands the route's PATH order (the
|
|
17627
|
+
* first run's position over the committed route — the solver's traversal's
|
|
17628
|
+
* order's convergence). The lenient read's parity over the stored
|
|
17629
|
+
* shape's corrupt's entries.
|
|
17630
|
+
*/
|
|
17631
|
+
function commitSectorsOf(sectors, session, preRoute, postRoute) {
|
|
17632
|
+
const axis = session.axis === "y" ? "h" : "v";
|
|
17633
|
+
const p = preRoute[session.index];
|
|
17634
|
+
const q = preRoute[session.index + 1];
|
|
17635
|
+
const preCoord = p !== void 0 && q !== void 0 && (axis === "h" ? p.y === q.y : p.x === q.x) ? axis === "h" ? p.y : p.x : null;
|
|
17636
|
+
const slots = [];
|
|
17637
|
+
const draggedOffset = preCoord === null ? null : preCoord + session.delta;
|
|
17638
|
+
if (draggedOffset !== null) {
|
|
17639
|
+
const span = spanOfLine(postRoute, axis, draggedOffset);
|
|
17640
|
+
if (span !== null) {
|
|
17641
|
+
const from = axis === "h" ? [span.min, round2(draggedOffset)] : [round2(draggedOffset), span.min];
|
|
17642
|
+
const to = axis === "h" ? [span.max, round2(draggedOffset)] : [round2(draggedOffset), span.max];
|
|
17643
|
+
slots.push({
|
|
17644
|
+
sector: {
|
|
17645
|
+
axis,
|
|
17646
|
+
offset: round2(draggedOffset),
|
|
17647
|
+
from,
|
|
17648
|
+
to
|
|
17649
|
+
},
|
|
17650
|
+
position: span.position
|
|
17651
|
+
});
|
|
17652
|
+
}
|
|
17653
|
+
}
|
|
17654
|
+
for (const sector of sectors ?? []) {
|
|
17655
|
+
if (sector === null || typeof sector !== "object") continue;
|
|
17656
|
+
const { axis: sAxis, offset, from, to } = sector;
|
|
17657
|
+
if (sAxis !== "h" && sAxis !== "v" || typeof offset !== "number" || !Number.isFinite(offset)) continue;
|
|
17658
|
+
if (!Array.isArray(from) || !Array.isArray(to)) continue;
|
|
17659
|
+
if (sAxis === axis && preCoord !== null && Math.abs(offset - preCoord) <= .01) continue;
|
|
17660
|
+
const span = spanOfLine(postRoute, sAxis, offset);
|
|
17661
|
+
if (span === null) continue;
|
|
17662
|
+
const sFrom = sAxis === "h" ? [span.min, round2(offset)] : [round2(offset), span.min];
|
|
17663
|
+
const sTo = sAxis === "h" ? [span.max, round2(offset)] : [round2(offset), span.max];
|
|
17664
|
+
slots.push({
|
|
17665
|
+
sector: {
|
|
17666
|
+
axis: sAxis,
|
|
17667
|
+
offset: round2(offset),
|
|
17668
|
+
from: sFrom,
|
|
17669
|
+
to: sTo
|
|
17670
|
+
},
|
|
17671
|
+
position: span.position
|
|
17672
|
+
});
|
|
17673
|
+
}
|
|
17674
|
+
slots.sort((u, v) => u.position - v.position);
|
|
17675
|
+
return slots.map((slot) => slot.sector);
|
|
17676
|
+
}
|
|
16762
17677
|
/** The connector's segment-drag commands. */
|
|
16763
17678
|
function createSegmentSessions(store, doc) {
|
|
16764
17679
|
const ref = { current: null };
|
|
16765
|
-
/** The line's
|
|
16766
|
-
*
|
|
16767
|
-
|
|
17680
|
+
/** The line's geometry over the live stand (the stored bends or the auto
|
|
17681
|
+
* route, the dragged run moved): the route's vertices (the pick / move /
|
|
17682
|
+
* commit space) + the stub's points (the commit's bends' extraction). The
|
|
17683
|
+
* no-drag's stand (the committed geometry — the commit's pre-route's
|
|
17684
|
+
* inputs) stands the empty segment.
|
|
17685
|
+
*/
|
|
17686
|
+
const routeOf = (session, dragged) => {
|
|
16768
17687
|
const block = doc.getBlock(session.connectorId);
|
|
16769
17688
|
if (block === null || block.type !== "connector") return null;
|
|
16770
17689
|
const surface = surfaceOf(doc, session.connectorId);
|
|
@@ -16774,13 +17693,13 @@ function createSegmentSessions(store, doc) {
|
|
|
16774
17693
|
resizePreview: null,
|
|
16775
17694
|
endpointDrag: null,
|
|
16776
17695
|
endpointPreview: null,
|
|
16777
|
-
segmentDrag: {
|
|
17696
|
+
segmentDrag: dragged ? {
|
|
16778
17697
|
connectorId: session.connectorId,
|
|
16779
17698
|
index: session.index,
|
|
16780
17699
|
delta: session.delta
|
|
16781
|
-
}
|
|
17700
|
+
} : null
|
|
16782
17701
|
};
|
|
16783
|
-
return connectorLineGeometryOf(session.connectorId, block, surface.children, surface.blocks, live)
|
|
17702
|
+
return connectorLineGeometryOf(session.connectorId, block, surface.children, surface.blocks, live);
|
|
16784
17703
|
};
|
|
16785
17704
|
/** The gesture's stepping: the pointer's movement along the run's movable
|
|
16786
17705
|
* axis (canvas px) over the step grid. */
|
|
@@ -16789,9 +17708,6 @@ function createSegmentSessions(store, doc) {
|
|
|
16789
17708
|
const to = session.axis === "x" ? pointer.x : pointer.y;
|
|
16790
17709
|
return Math.round((to - from) / zoom / 10) * 10;
|
|
16791
17710
|
};
|
|
16792
|
-
/** An anchored endpoint (the route's own stub vertex): a free point
|
|
16793
|
-
* without a port stands none. */
|
|
16794
|
-
const anchored = (ref) => ref.x === void 0 || ref.port !== void 0;
|
|
16795
17711
|
const beginConnectorSegment = (connectorId, index, axis, pointer) => {
|
|
16796
17712
|
ref.current = {
|
|
16797
17713
|
connectorId,
|
|
@@ -16830,15 +17746,24 @@ function createSegmentSessions(store, doc) {
|
|
|
16830
17746
|
if (session === null || session.delta === 0) return;
|
|
16831
17747
|
const block = doc.getBlock(session.connectorId);
|
|
16832
17748
|
if (block === null || block.type !== "connector") return;
|
|
16833
|
-
const
|
|
16834
|
-
|
|
16835
|
-
|
|
16836
|
-
|
|
16837
|
-
|
|
16838
|
-
|
|
16839
|
-
|
|
16840
|
-
|
|
16841
|
-
|
|
17749
|
+
const variant = block.attrs?.variant ?? "straight";
|
|
17750
|
+
const live = routeOf(session, true);
|
|
17751
|
+
if (live === null) return;
|
|
17752
|
+
if (variant === "orthogonal") {
|
|
17753
|
+
const pre = routeOf(session, false);
|
|
17754
|
+
if (pre === null) return;
|
|
17755
|
+
const sectors = commitSectorsOf(block.attrs?.sectors, session, pre.points, live.points);
|
|
17756
|
+
try {
|
|
17757
|
+
doc.transact(() => {
|
|
17758
|
+
if (sectors.length === 0) doc.removeBlockAttr(session.connectorId, "sectors");
|
|
17759
|
+
else doc.updateBlock(session.connectorId, { sectors });
|
|
17760
|
+
doc.removeBlockAttr(session.connectorId, "points");
|
|
17761
|
+
});
|
|
17762
|
+
} catch {}
|
|
17763
|
+
return;
|
|
17764
|
+
}
|
|
17765
|
+
const { start, end } = live.stubs;
|
|
17766
|
+
const bends = simplifyRoute(live.points.slice(1, -1).filter((point) => (point.x !== start.x || point.y !== start.y) && (point.x !== end.x || point.y !== end.y))).map((point) => [Number(point.x.toFixed(2)), Number(point.y.toFixed(2))]);
|
|
16842
17767
|
try {
|
|
16843
17768
|
doc.transact(() => {
|
|
16844
17769
|
if (bends.length === 0) doc.removeBlockAttr(session.connectorId, "points");
|
|
@@ -16918,6 +17843,50 @@ function computeDropIndicators(types, snapshot, containers, groupMembers, ids, d
|
|
|
16918
17843
|
}
|
|
16919
17844
|
return indicators;
|
|
16920
17845
|
}
|
|
17846
|
+
// src/canvas/viewport/session-shape-prune.ts
|
|
17847
|
+
/** The no-op geometry session (the committed geometry's read — no
|
|
17848
|
+
* in-flight preview over the prune's pass). */
|
|
17849
|
+
const PRUNE_SESSION = {
|
|
17850
|
+
movePreview: null,
|
|
17851
|
+
resizePreview: null,
|
|
17852
|
+
endpointDrag: null,
|
|
17853
|
+
endpointPreview: null,
|
|
17854
|
+
segmentDrag: null
|
|
17855
|
+
};
|
|
17856
|
+
/** The connector's type guard (the lenient read's narrowing). */
|
|
17857
|
+
function isConnectorBlock(block) {
|
|
17858
|
+
return block.type === "connector";
|
|
17859
|
+
}
|
|
17860
|
+
/** The dead's sectors' prune over every surface (the committed geometry's
|
|
17861
|
+
* read — the in-flight sessions' stand none: the prune stands the
|
|
17862
|
+
* release's committed state). */
|
|
17863
|
+
function pruneDeadSectors(doc) {
|
|
17864
|
+
for (const surfaceId of doc.getChildren(doc.meta.id)) {
|
|
17865
|
+
const surface = doc.getBlock(surfaceId);
|
|
17866
|
+
if (surface === null || surface.type !== "surface") continue;
|
|
17867
|
+
const children = doc.getChildren(surfaceId);
|
|
17868
|
+
const blocks = {};
|
|
17869
|
+
for (const childId of children) {
|
|
17870
|
+
const child = doc.getBlock(childId);
|
|
17871
|
+
if (child !== null) blocks[childId] = child;
|
|
17872
|
+
}
|
|
17873
|
+
for (const childId of children) {
|
|
17874
|
+
const block = blocks[childId];
|
|
17875
|
+
if (block === void 0 || !isConnectorBlock(block)) continue;
|
|
17876
|
+
const attrs = block.attrs;
|
|
17877
|
+
if (attrs === void 0 || (attrs.variant ?? "straight") !== "orthogonal") continue;
|
|
17878
|
+
const sectors = attrs.sectors ?? [];
|
|
17879
|
+
if (sectors.length === 0) continue;
|
|
17880
|
+
const geometry = connectorLineGeometryOf(childId, block, children, blocks, PRUNE_SESSION);
|
|
17881
|
+
if (geometry === null || geometry.deadSectors.length === 0) continue;
|
|
17882
|
+
const dead = new Set(geometry.deadSectors);
|
|
17883
|
+
const kept = sectors.filter((_, index) => !dead.has(index));
|
|
17884
|
+
if (kept.length === sectors.length) continue;
|
|
17885
|
+
if (kept.length === 0) doc.removeBlockAttr(childId, "sectors");
|
|
17886
|
+
else doc.updateBlock(childId, { sectors: kept });
|
|
17887
|
+
}
|
|
17888
|
+
}
|
|
17889
|
+
}
|
|
16921
17890
|
// src/canvas/viewport/session-shape.ts
|
|
16922
17891
|
/**
|
|
16923
17892
|
* The container's unit members — all the transitive members (a nested
|
|
@@ -17058,6 +18027,7 @@ function createShapeSessions(store, doc) {
|
|
|
17058
18027
|
if (home !== null && home.type === "group" && !home.attrs.members.includes(id)) doc.updateBlock(target.id, { members: [...home.attrs.members, id] });
|
|
17059
18028
|
}
|
|
17060
18029
|
}
|
|
18030
|
+
pruneDeadSectors(doc);
|
|
17061
18031
|
});
|
|
17062
18032
|
};
|
|
17063
18033
|
const cancelMove = () => {
|
|
@@ -17123,6 +18093,7 @@ function createShapeSessions(store, doc) {
|
|
|
17123
18093
|
w: box.w,
|
|
17124
18094
|
h: box.h
|
|
17125
18095
|
});
|
|
18096
|
+
pruneDeadSectors(doc);
|
|
17126
18097
|
});
|
|
17127
18098
|
};
|
|
17128
18099
|
const cancelResize = () => {
|
|
@@ -17166,31 +18137,53 @@ function createWaypointSessions(store, doc) {
|
|
|
17166
18137
|
});
|
|
17167
18138
|
} catch {}
|
|
17168
18139
|
};
|
|
17169
|
-
const beginConnectorWaypoint = (connectorId, index, pointer, startClientX, startClientY) => {
|
|
18140
|
+
const beginConnectorWaypoint = (connectorId, index, pointer, startClientX, startClientY, seed) => {
|
|
17170
18141
|
const state = store.getState();
|
|
17171
18142
|
const block = doc.getBlock(connectorId);
|
|
17172
18143
|
if (block === null || block.type !== "connector") return;
|
|
17173
|
-
|
|
17174
|
-
|
|
17175
|
-
|
|
18144
|
+
if (seed === void 0) {
|
|
18145
|
+
const stored = pointsOf(connectorId)[index];
|
|
18146
|
+
if (stored === void 0) return;
|
|
18147
|
+
const canvas = screenToCanvas(pointer, state.zoom, state.pan);
|
|
18148
|
+
waypointRef.current = {
|
|
18149
|
+
connectorId,
|
|
18150
|
+
index,
|
|
18151
|
+
startClientX,
|
|
18152
|
+
startClientY,
|
|
18153
|
+
dragging: false,
|
|
18154
|
+
point: canvas
|
|
18155
|
+
};
|
|
18156
|
+
state.setConnectorEndpoint({
|
|
18157
|
+
connectorId,
|
|
18158
|
+
which: "waypoint",
|
|
18159
|
+
index
|
|
18160
|
+
});
|
|
18161
|
+
state.setConnectorEndpointPreview({
|
|
18162
|
+
point: {
|
|
18163
|
+
x: stored[0],
|
|
18164
|
+
y: stored[1]
|
|
18165
|
+
},
|
|
18166
|
+
snap: null
|
|
18167
|
+
});
|
|
18168
|
+
return;
|
|
18169
|
+
}
|
|
17176
18170
|
waypointRef.current = {
|
|
17177
18171
|
connectorId,
|
|
17178
18172
|
index,
|
|
17179
18173
|
startClientX,
|
|
17180
18174
|
startClientY,
|
|
17181
18175
|
dragging: false,
|
|
17182
|
-
point:
|
|
18176
|
+
point: seed,
|
|
18177
|
+
seeded: true
|
|
17183
18178
|
};
|
|
17184
18179
|
state.setConnectorEndpoint({
|
|
17185
18180
|
connectorId,
|
|
17186
18181
|
which: "waypoint",
|
|
17187
|
-
index
|
|
18182
|
+
index,
|
|
18183
|
+
seeded: true
|
|
17188
18184
|
});
|
|
17189
18185
|
state.setConnectorEndpointPreview({
|
|
17190
|
-
point:
|
|
17191
|
-
x: stored[0],
|
|
17192
|
-
y: stored[1]
|
|
17193
|
-
},
|
|
18186
|
+
point: seed,
|
|
17194
18187
|
snap: null
|
|
17195
18188
|
});
|
|
17196
18189
|
};
|
|
@@ -17215,6 +18208,11 @@ function createWaypointSessions(store, doc) {
|
|
|
17215
18208
|
if (session === null || !session.dragging) return;
|
|
17216
18209
|
if (releaseClientX !== void 0 && releaseClientY !== void 0 && Math.hypot(releaseClientX - session.startClientX, releaseClientY - session.startClientY) < 3) return;
|
|
17217
18210
|
const points = pointsOf(session.connectorId);
|
|
18211
|
+
if (session.seeded) {
|
|
18212
|
+
points.splice(session.index, 0, rounded(session.point));
|
|
18213
|
+
writePoints(session.connectorId, points);
|
|
18214
|
+
return;
|
|
18215
|
+
}
|
|
17218
18216
|
if (points[session.index] === void 0) return;
|
|
17219
18217
|
points[session.index] = rounded(session.point);
|
|
17220
18218
|
writePoints(session.connectorId, points);
|
|
@@ -17713,7 +18711,18 @@ function useKbFocus(id) {
|
|
|
17713
18711
|
* stable objects between the store's writes — a built object per call
|
|
17714
18712
|
* would stand the re-render loop).
|
|
17715
18713
|
*/
|
|
17716
|
-
|
|
18714
|
+
/** The line's session's narrow subscription (the viewport's store): the
|
|
18715
|
+
* stable EMPTY stand while the in-flight previews touch NEITHER of the
|
|
18716
|
+
* line's endpoint blocks NOR one of its obstacle siblings (the content
|
|
18717
|
+
* memo holds — no re-route, no re-render, the frame), the live session (a
|
|
18718
|
+
* fresh object per frame) over the touched lines (the endpoints' resolution
|
|
18719
|
+
* + the obstacle's avoidance stand the live's re-route mid-drag — the
|
|
18720
|
+
* figure's drag stands the line's follow over the frame's). The
|
|
18721
|
+
* `obstacleIds`'s set stands the touch's read over the moving/resize's
|
|
18722
|
+
* third-party's figures (the small's idSet's iteration — the O(siblings)
|
|
18723
|
+
* stand stands the memoized's set over the caller's side, not the frame's
|
|
18724
|
+
* per-notification's). */
|
|
18725
|
+
function useLineSession(id, startBlockId, endBlockId, obstacleIds) {
|
|
17717
18726
|
const store = useCanvasViewportStore();
|
|
17718
18727
|
const cacheRef = useRef(null);
|
|
17719
18728
|
return useStore(store, (s) => {
|
|
@@ -17723,9 +18732,9 @@ function useLineSession(id, startBlockId, endBlockId) {
|
|
|
17723
18732
|
const ep = s.connectorEndpointPreview;
|
|
17724
18733
|
const sd = s.connectorSegment;
|
|
17725
18734
|
const cache = cacheRef.current;
|
|
17726
|
-
if (cache !== null && cache.mv === mv && cache.rp === rp && cache.ed === ed && cache.ep === ep && cache.sd === sd) return cache.value;
|
|
17727
|
-
const mvTouches = mv !== null && (startBlockId !== null && mv.idSet.has(startBlockId) || endBlockId !== null && mv.idSet.has(endBlockId));
|
|
17728
|
-
const rpTouches = rp !== null && (rp.id === startBlockId || rp.id === endBlockId);
|
|
18735
|
+
if (cache !== null && cache.mv === mv && cache.rp === rp && cache.ed === ed && cache.ep === ep && cache.sd === sd && cache.obs === obstacleIds) return cache.value;
|
|
18736
|
+
const mvTouches = mv !== null && (startBlockId !== null && mv.idSet.has(startBlockId) || endBlockId !== null && mv.idSet.has(endBlockId) || [...mv.idSet].some((touched) => obstacleIds.has(touched)));
|
|
18737
|
+
const rpTouches = rp !== null && (rp.id === startBlockId || rp.id === endBlockId || obstacleIds.has(rp.id));
|
|
17729
18738
|
const edTouches = ed !== null && ed.connectorId === id;
|
|
17730
18739
|
const sdTouches = sd !== null && sd.connectorId === id;
|
|
17731
18740
|
const value = !mvTouches && !rpTouches && !edTouches && !sdTouches ? EMPTY_LINE_SESSION : {
|
|
@@ -17741,6 +18750,7 @@ function useLineSession(id, startBlockId, endBlockId) {
|
|
|
17741
18750
|
ed,
|
|
17742
18751
|
ep,
|
|
17743
18752
|
sd,
|
|
18753
|
+
obs: obstacleIds,
|
|
17744
18754
|
value
|
|
17745
18755
|
};
|
|
17746
18756
|
return value;
|
|
@@ -17875,10 +18885,12 @@ const EMPTY_SELECTED = [];
|
|
|
17875
18885
|
/** The per-label midpoint's cache key (the preview's touch stand): the
|
|
17876
18886
|
* committed-geometry's stand over the untouched label, the preview's
|
|
17877
18887
|
* values' stand over the touched one (a touched label re-computes its
|
|
17878
|
-
* midpoint per frame, the untouched one stands the cache).
|
|
18888
|
+
* midpoint per frame, the untouched one stands the cache). The segment's
|
|
18889
|
+
* parallel drag's touch stands too (the line re-routes live over the drag,
|
|
18890
|
+
* the seat with it). */
|
|
17879
18891
|
function midpointSignature(stand, previews) {
|
|
17880
|
-
const { movePreview, resizePreview, endpointDrag, endpointPreview } = previews;
|
|
17881
|
-
if (movePreview === null && resizePreview === null && endpointDrag === null) return "i";
|
|
18892
|
+
const { movePreview, resizePreview, endpointDrag, endpointPreview, segmentDrag } = previews;
|
|
18893
|
+
if (movePreview === null && resizePreview === null && endpointDrag === null && segmentDrag === null) return "i";
|
|
17882
18894
|
const parts = [];
|
|
17883
18895
|
if (movePreview !== null && (stand.startBlockId !== null && movePreview.idSet.has(stand.startBlockId) || stand.endBlockId !== null && movePreview.idSet.has(stand.endBlockId))) parts.push(`m${movePreview.dx}x${movePreview.dy}`);
|
|
17884
18896
|
if (resizePreview !== null && (resizePreview.id === stand.startBlockId || resizePreview.id === stand.endBlockId)) parts.push(`r${resizePreview.box.x},${resizePreview.box.y},${resizePreview.box.w},${resizePreview.box.h}`);
|
|
@@ -17887,6 +18899,7 @@ function midpointSignature(stand, previews) {
|
|
|
17887
18899
|
const snap = endpointPreview?.snap ?? null;
|
|
17888
18900
|
parts.push(`e${point !== null ? `${point.x},${point.y}` : "-"},${snap !== null ? snap.blockId : "-"}`);
|
|
17889
18901
|
}
|
|
18902
|
+
if (segmentDrag !== null && segmentDrag.connectorId === stand.id) parts.push(`s${segmentDrag.index}x${segmentDrag.delta}`);
|
|
17890
18903
|
return parts.length === 0 ? "i" : parts.join(";");
|
|
17891
18904
|
}
|
|
17892
18905
|
function ConnectorLabelChips({ children, selectedIds = EMPTY_SELECTED, skipId = null }) {
|
|
@@ -17933,7 +18946,8 @@ function ConnectorLabelChips({ children, selectedIds = EMPTY_SELECTED, skipId =
|
|
|
17933
18946
|
let mid;
|
|
17934
18947
|
if (cached !== void 0 && cached.sig === sig) mid = cached.mid;
|
|
17935
18948
|
else {
|
|
17936
|
-
|
|
18949
|
+
const block = blocks[stand.id];
|
|
18950
|
+
mid = block !== void 0 && block.type === "connector" ? connectorLineGeometryOf(stand.id, block, children, blocks, previews)?.mid ?? null : null;
|
|
17937
18951
|
midCache.set(cacheKey, {
|
|
17938
18952
|
sig,
|
|
17939
18953
|
mid
|
|
@@ -17979,6 +18993,17 @@ function useBlockContext() {
|
|
|
17979
18993
|
}
|
|
17980
18994
|
// src/canvas/canvas-text-edit-context.tsx
|
|
17981
18995
|
const CanvasTextEditContext = createContext(null);
|
|
18996
|
+
/** The inert stand's session: the frame window's copy (the page card's
|
|
18997
|
+
* mirror of the surface) renders the committed text only. A module
|
|
18998
|
+
* singleton with no-op setters — an inert layer re-provides it, so the
|
|
18999
|
+
* copies stand no editing surface of their own and their focus effects
|
|
19000
|
+
* never take the live editor's focus. */
|
|
19001
|
+
const INERT_CANVAS_TEXT_EDIT = {
|
|
19002
|
+
editingId: null,
|
|
19003
|
+
setEditingId: () => void 0,
|
|
19004
|
+
canvasTextEditingId: null,
|
|
19005
|
+
setCanvasTextEditingId: () => void 0
|
|
19006
|
+
};
|
|
17982
19007
|
/**
|
|
17983
19008
|
* The edit session's access (the canvas view's provider). Null outside
|
|
17984
19009
|
* the canvas view (the page view's inert surfaces render the shape's
|
|
@@ -18005,6 +19030,17 @@ function CanvasTextEditProvider({ editingId, setEditingId, canvasTextEditingId,
|
|
|
18005
19030
|
children
|
|
18006
19031
|
});
|
|
18007
19032
|
}
|
|
19033
|
+
/**
|
|
19034
|
+
* The inert layers' session (the frame window's copy over the surface):
|
|
19035
|
+
* no edit stands — the copies render the committed text, the setters are
|
|
19036
|
+
* no-ops. The parity with the empty viewport store's re-provide.
|
|
19037
|
+
*/
|
|
19038
|
+
function CanvasTextEditInertProvider({ children }) {
|
|
19039
|
+
return /* @__PURE__ */ jsx(CanvasTextEditContext.Provider, {
|
|
19040
|
+
value: INERT_CANVAS_TEXT_EDIT,
|
|
19041
|
+
children
|
|
19042
|
+
});
|
|
19043
|
+
}
|
|
18008
19044
|
// src/editing/block-commands/utils/commands-reads.ts
|
|
18009
19045
|
/** The flattened text of the runs. */
|
|
18010
19046
|
function textOf$1(runs) {
|
|
@@ -18342,7 +19378,11 @@ function moveSegmentInSequence(doc, contextId, startIndex, length, target) {
|
|
|
18342
19378
|
* soft line break) consumes that break: the gesture drops it and the new
|
|
18343
19379
|
* block stands empty (the quote/callout/code exit parity — without this
|
|
18344
19380
|
* the break would survive the split in the first block as a ghost empty
|
|
18345
|
-
* line).
|
|
19381
|
+
* line). A caret at the START of an internal line (right after a soft
|
|
19382
|
+
* line break) stands an empty block of its own: the text before the break
|
|
19383
|
+
* keeps the block, the new empty block takes the caret, and the caret's
|
|
19384
|
+
* line and below move to the next block — the break consumed, no ghost
|
|
19385
|
+
* line in either part.
|
|
18346
19386
|
* Empty: a child block (indent > 0) outdents one level (the type stands,
|
|
18347
19387
|
* until the indent reaches 0); a root-level non-text block resets its type
|
|
18348
19388
|
* to a plain paragraph (in place — the type-specific attrs are dropped, the
|
|
@@ -18387,6 +19427,14 @@ function splitAt(doc, id, contextId, offset) {
|
|
|
18387
19427
|
doc.deleteText(id, text.length - 1, text.length);
|
|
18388
19428
|
return;
|
|
18389
19429
|
}
|
|
19430
|
+
if (offset > 0 && offset < text.length && text.charCodeAt(offset - 1) === 10) {
|
|
19431
|
+
const middle = insertSameTypeAfter(doc, block, contextId, id);
|
|
19432
|
+
const tail = insertSameTypeAfter(doc, block, contextId, middle);
|
|
19433
|
+
copyRunsRange(doc, runs, offset, text.length, tail, 0);
|
|
19434
|
+
doc.deleteText(id, offset - 1, text.length);
|
|
19435
|
+
focusId = middle;
|
|
19436
|
+
return;
|
|
19437
|
+
}
|
|
18390
19438
|
focusId = insertSameTypeAfter(doc, block, contextId, id);
|
|
18391
19439
|
copyRunsRange(doc, runs, offset, text.length, focusId, 0);
|
|
18392
19440
|
doc.deleteText(id, offset, text.length);
|
|
@@ -19992,9 +21040,9 @@ function useMentionMenuApi() {
|
|
|
19992
21040
|
* over the editor root — the text DOM is imperative, the re-rendered chip
|
|
19993
21041
|
* stands no React signal).
|
|
19994
21042
|
*/
|
|
19995
|
-
const CHIP_SELECTOR = "[data-slot=\"docblocks/mention\"]";
|
|
21043
|
+
const CHIP_SELECTOR$1 = "[data-slot=\"docblocks/mention\"]";
|
|
19996
21044
|
const CARD_SELECTOR = "[data-slot=\"docblocks/mention-card\"]";
|
|
19997
|
-
const EDITOR_ROOT_SELECTOR = "[data-slot=\"docblocks/editor\"]";
|
|
21045
|
+
const EDITOR_ROOT_SELECTOR$1 = "[data-slot=\"docblocks/editor\"]";
|
|
19998
21046
|
/** The hover's stands: the open's delay (a read-through is not a target)
|
|
19999
21047
|
* and the close's grace over the zone's exit (the chip → card's move
|
|
20000
21048
|
* stands inside it). */
|
|
@@ -20051,7 +21099,7 @@ function useMentionCard(rootRef) {
|
|
|
20051
21099
|
if (!(target instanceof Element)) return null;
|
|
20052
21100
|
const rootEl = rootRef.current;
|
|
20053
21101
|
if (rootEl === null || !rootEl.contains(target)) return null;
|
|
20054
|
-
const nearestRoot = target.closest(EDITOR_ROOT_SELECTOR);
|
|
21102
|
+
const nearestRoot = target.closest(EDITOR_ROOT_SELECTOR$1);
|
|
20055
21103
|
if (nearestRoot !== null && nearestRoot !== rootEl) return null;
|
|
20056
21104
|
return target;
|
|
20057
21105
|
};
|
|
@@ -20067,7 +21115,7 @@ function useMentionCard(rootRef) {
|
|
|
20067
21115
|
return;
|
|
20068
21116
|
}
|
|
20069
21117
|
const scoped = scopedTarget(target);
|
|
20070
|
-
const chip = scoped !== null ? scoped.closest(CHIP_SELECTOR) ?? null : null;
|
|
21118
|
+
const chip = scoped !== null ? scoped.closest(CHIP_SELECTOR$1) ?? null : null;
|
|
20071
21119
|
if (chip === null) {
|
|
20072
21120
|
if (closeTimerRef.current !== null) return;
|
|
20073
21121
|
if (openRef.current === null && pendingRef.current === null) return;
|
|
@@ -20113,7 +21161,7 @@ function useMentionCard(rootRef) {
|
|
|
20113
21161
|
const click = (event) => {
|
|
20114
21162
|
const scoped = scopedTarget(event.target);
|
|
20115
21163
|
if (scoped === null) return;
|
|
20116
|
-
const chip = scoped.closest(CHIP_SELECTOR);
|
|
21164
|
+
const chip = scoped.closest(CHIP_SELECTOR$1);
|
|
20117
21165
|
if (chip === null) return;
|
|
20118
21166
|
const mark = mentionMarkOf(chip);
|
|
20119
21167
|
if (mark === null) return;
|
|
@@ -23967,6 +25015,22 @@ function styleMarksOf(style) {
|
|
|
23967
25015
|
}
|
|
23968
25016
|
return result;
|
|
23969
25017
|
}
|
|
25018
|
+
/**
|
|
25019
|
+
* The mention chip's target over the pasted span: the clipboard's
|
|
25020
|
+
* serialization carries `data-mention` (the kind) + `data-mention-id`, the
|
|
25021
|
+
* chip's own DOM carries `data-mention-kind` — both are the editor's own
|
|
25022
|
+
* stands. The identity needs both halves (the model's closed kind set, a
|
|
25023
|
+
* non-empty id); a half-stated span degrades to its text.
|
|
25024
|
+
*/
|
|
25025
|
+
function mentionOf(element) {
|
|
25026
|
+
const kind = element.getAttribute("data-mention") ?? element.getAttribute("data-mention-kind");
|
|
25027
|
+
const id = element.getAttribute("data-mention-id");
|
|
25028
|
+
if (kind !== "user" && kind !== "doc" || id === null || id === "") return null;
|
|
25029
|
+
return {
|
|
25030
|
+
kind,
|
|
25031
|
+
id
|
|
25032
|
+
};
|
|
25033
|
+
}
|
|
23970
25034
|
/** The mark one whitelisted element adds over its inherited marks; null when it maps to none. */
|
|
23971
25035
|
function elementMarks(element) {
|
|
23972
25036
|
const simple = tagEmphasisMarks(element.nodeName);
|
|
@@ -23979,6 +25043,8 @@ function elementMarks(element) {
|
|
|
23979
25043
|
case "SPAN": {
|
|
23980
25044
|
const style = styleMarksOf(element.getAttribute("style"));
|
|
23981
25045
|
const marks = {};
|
|
25046
|
+
const mention = mentionOf(element);
|
|
25047
|
+
if (mention !== null) marks.mention = mention;
|
|
23982
25048
|
if (style.color !== void 0) marks.color = { value: style.color };
|
|
23983
25049
|
if (style.highlight !== void 0) marks.highlight = { value: style.highlight };
|
|
23984
25050
|
return Object.keys(marks).length > 0 ? marks : null;
|
|
@@ -24799,8 +25865,8 @@ function useBlockKeyboard({ id, blockType, context, innerRef }) {
|
|
|
24799
25865
|
return;
|
|
24800
25866
|
}
|
|
24801
25867
|
if (mod && !event.nativeEvent.isComposing && blockType !== "code") {
|
|
24802
|
-
const
|
|
24803
|
-
const mark = !event.shiftKey ?
|
|
25868
|
+
const letter = shortcutLetter(event);
|
|
25869
|
+
const mark = !event.shiftKey ? letter === "b" ? "bold" : letter === "i" ? "italic" : letter === "u" ? "underline" : letter === "e" ? "code" : null : letter === "x" ? "strike" : null;
|
|
24804
25870
|
if (mark === null) return;
|
|
24805
25871
|
const domSelection = window.getSelection();
|
|
24806
25872
|
if (domSelection === null || domSelection.rangeCount === 0) return;
|
|
@@ -26470,7 +27536,7 @@ function useLinkPopover(rootRef) {
|
|
|
26470
27536
|
* current view's selection, the no-op's stand over a non-text's view. */
|
|
26471
27537
|
const handleKeyDown = useCallback((event) => {
|
|
26472
27538
|
if (viewMode) return false;
|
|
26473
|
-
if (!(event.metaKey || event.ctrlKey) || event.shiftKey || event
|
|
27539
|
+
if (!(event.metaKey || event.ctrlKey) || event.shiftKey || shortcutLetter(event) !== "k") return false;
|
|
26474
27540
|
const target = event.target instanceof Element ? event.target : null;
|
|
26475
27541
|
if (target !== null && target.closest("input, textarea") !== null) return false;
|
|
26476
27542
|
const root = rootRef.current;
|
|
@@ -27917,8 +28983,22 @@ function ConnectorLine({ id, interactive = true }) {
|
|
|
27917
28983
|
const block = useBlock(id);
|
|
27918
28984
|
const selected = useStore(store, (state) => state.selection.kind === "blocks" && state.selection.ids.includes(id));
|
|
27919
28985
|
const context = useBlockContext();
|
|
27920
|
-
const
|
|
28986
|
+
const startBlockId = block !== void 0 && block.type === "connector" && typeof block.attrs.start.blockId === "string" ? block.attrs.start.blockId : null;
|
|
28987
|
+
const endBlockId = block !== void 0 && block.type === "connector" && typeof block.attrs.end.blockId === "string" ? block.attrs.end.blockId : null;
|
|
27921
28988
|
const chromeStamp = useStore(store, (state) => state.chromeStamp);
|
|
28989
|
+
const session = useLineSession(id, startBlockId, endBlockId, useMemo(() => {
|
|
28990
|
+
const blocks = store.getState().blocks;
|
|
28991
|
+
const set = /* @__PURE__ */ new Set();
|
|
28992
|
+
for (const sibling of context.siblings) {
|
|
28993
|
+
const item = blocks[sibling];
|
|
28994
|
+
if (item !== void 0 && item.type !== "connector" && item.type !== "group") set.add(sibling);
|
|
28995
|
+
}
|
|
28996
|
+
return set;
|
|
28997
|
+
}, [
|
|
28998
|
+
context.siblings,
|
|
28999
|
+
chromeStamp,
|
|
29000
|
+
store
|
|
29001
|
+
]));
|
|
27922
29002
|
const isDark = useDarkTheme();
|
|
27923
29003
|
const content = useMemo(() => block === void 0 || block.type !== "connector" ? null : connectorLineOf(context.parentId, id, block, context.siblings, store.getState().blocks, selected, interactive, session, isDark), [
|
|
27924
29004
|
block,
|
|
@@ -29108,9 +30188,28 @@ function setConnectorVariant(doc, id, next) {
|
|
|
29108
30188
|
if (block === null || block.type !== "connector" || block.attrs === void 0) return;
|
|
29109
30189
|
if ((block.attrs.variant ?? "straight") === next) return;
|
|
29110
30190
|
const drops = next !== "straight" && block.attrs.points !== void 0;
|
|
30191
|
+
const dropsSectors = next !== "orthogonal" && block.attrs.sectors !== void 0;
|
|
29111
30192
|
doc.transact(() => {
|
|
29112
30193
|
doc.updateBlock(id, { variant: next });
|
|
29113
30194
|
if (drops) doc.removeBlockAttr(id, "points");
|
|
30195
|
+
if (dropsSectors) doc.removeBlockAttr(id, "sectors");
|
|
30196
|
+
});
|
|
30197
|
+
}
|
|
30198
|
+
/**
|
|
30199
|
+
* The orthogonal's AUTO route's restore (the toolbar's re-pick of the
|
|
30200
|
+
* current type): the reader's custom bends (the stored points) + the
|
|
30201
|
+
* FIXED sectors drop in one transaction, so the automatic route returns.
|
|
30202
|
+
* The absent data's / the non-orthogonal's re-pick stands the no-op; a
|
|
30203
|
+
* concurrent removal stands the no-op too.
|
|
30204
|
+
*/
|
|
30205
|
+
function resetConnectorRoute(doc, id) {
|
|
30206
|
+
const block = doc.getBlock(id);
|
|
30207
|
+
if (block === null || block.type !== "connector" || block.attrs === void 0) return;
|
|
30208
|
+
if ((block.attrs.variant ?? "straight") !== "orthogonal") return;
|
|
30209
|
+
if (block.attrs.points === void 0 && block.attrs.sectors === void 0) return;
|
|
30210
|
+
doc.transact(() => {
|
|
30211
|
+
if (block.attrs.points !== void 0) doc.removeBlockAttr(id, "points");
|
|
30212
|
+
if (block.attrs.sectors !== void 0) doc.removeBlockAttr(id, "sectors");
|
|
29114
30213
|
});
|
|
29115
30214
|
}
|
|
29116
30215
|
// src/canvas/shape-toolbar/constants.ts
|
|
@@ -29336,7 +30435,10 @@ function ConnectorToolbar({ id, variant, strokeColor, strokeWidth, strokeStyle,
|
|
|
29336
30435
|
});
|
|
29337
30436
|
};
|
|
29338
30437
|
const applyVariant = (next) => {
|
|
29339
|
-
if (next === variant)
|
|
30438
|
+
if (next === variant) {
|
|
30439
|
+
resetConnectorRoute(doc, id);
|
|
30440
|
+
return;
|
|
30441
|
+
}
|
|
29340
30442
|
setConnectorVariant(doc, id, next);
|
|
29341
30443
|
};
|
|
29342
30444
|
const applyWidth = (index) => {
|
|
@@ -30588,14 +31690,14 @@ function SurfaceLayer({ id, children, pendingConnector, inert = false, excludedI
|
|
|
30588
31690
|
value: contextValue,
|
|
30589
31691
|
children: /* @__PURE__ */ jsx(CanvasViewportStoreContext.Provider, {
|
|
30590
31692
|
value: EMPTY_VIEWPORT_STORE,
|
|
30591
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
31693
|
+
children: /* @__PURE__ */ jsx(CanvasTextEditInertProvider, { children: /* @__PURE__ */ jsx("div", {
|
|
30592
31694
|
className: "pointer-events-none relative",
|
|
30593
31695
|
style: {
|
|
30594
31696
|
width: 0,
|
|
30595
31697
|
height: 0
|
|
30596
31698
|
},
|
|
30597
31699
|
children: content
|
|
30598
|
-
})
|
|
31700
|
+
}) })
|
|
30599
31701
|
})
|
|
30600
31702
|
});
|
|
30601
31703
|
return /* @__PURE__ */ jsx(BlockContext.Provider, {
|
|
@@ -35232,10 +36334,10 @@ function CanvasSurface({ containerRef, containerSize, cursor, viewport, handlers
|
|
|
35232
36334
|
onKeyUp: handlers.onKeyUp,
|
|
35233
36335
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
35234
36336
|
"data-slot": "docblocks/canvas-world",
|
|
35235
|
-
className: cn("absolute inset-0", (viewport.moveSession || viewport.resizeSession || viewport.connectorEndpoint !== null) && "select-none"),
|
|
36337
|
+
className: cn("absolute inset-0", (viewport.moveSession || viewport.resizeSession || viewport.connectorEndpoint !== null || viewport.connectorSegment !== null) && "select-none"),
|
|
35236
36338
|
style: {
|
|
35237
|
-
transform: `translate(${viewport.pan.x + worldSnap.x}px, ${viewport.pan.y + worldSnap.y
|
|
35238
|
-
|
|
36339
|
+
transform: `translate(${(viewport.pan.x + worldSnap.x) / viewport.zoom}px, ${(viewport.pan.y + worldSnap.y) / viewport.zoom}px)`,
|
|
36340
|
+
zoom: viewport.zoom,
|
|
35239
36341
|
"--docblocks-canvas-inv-zoom": 1 / viewport.zoom
|
|
35240
36342
|
},
|
|
35241
36343
|
children: [
|
|
@@ -35556,7 +36658,7 @@ function useCanvasFit(doc, containerRef, storedViewport, viewport) {
|
|
|
35556
36658
|
function handleCanvasClipboard(deps, event) {
|
|
35557
36659
|
const { viewport, selection, doc, store, containerRef, lastPointerRef } = deps;
|
|
35558
36660
|
if (!(event.metaKey || event.ctrlKey) || event.shiftKey || event.altKey) return false;
|
|
35559
|
-
const modKey = event
|
|
36661
|
+
const modKey = shortcutLetter(event);
|
|
35560
36662
|
if (modKey === "c") {
|
|
35561
36663
|
const sel = selection.view?.get();
|
|
35562
36664
|
if (sel?.kind !== "blocks" || sel.ids.length === 0) return false;
|
|
@@ -35759,7 +36861,7 @@ function useCanvasKeys({ containerRef, viewport, sessionRef, selection, doc, sto
|
|
|
35759
36861
|
return;
|
|
35760
36862
|
}
|
|
35761
36863
|
if (viewMode) return;
|
|
35762
|
-
if (event
|
|
36864
|
+
if (shortcutLetter(event) === "m") {
|
|
35763
36865
|
event.preventDefault();
|
|
35764
36866
|
viewport.setMode("default");
|
|
35765
36867
|
return;
|
|
@@ -35776,7 +36878,7 @@ function useCanvasKeys({ containerRef, viewport, sessionRef, selection, doc, sto
|
|
|
35776
36878
|
}
|
|
35777
36879
|
return;
|
|
35778
36880
|
}
|
|
35779
|
-
if ((event.metaKey || event.ctrlKey) && event
|
|
36881
|
+
if ((event.metaKey || event.ctrlKey) && shortcutLetter(event) === "g") {
|
|
35780
36882
|
const sel = selection.view?.get();
|
|
35781
36883
|
if (sel?.kind !== "blocks") return;
|
|
35782
36884
|
event.preventDefault();
|
|
@@ -36341,6 +37443,29 @@ const TITLE_CHIP_SELECTOR = "[data-slot='docblocks/group-title'], [data-slot='do
|
|
|
36341
37443
|
function pointElementOf(event) {
|
|
36342
37444
|
return (typeof document.elementFromPoint === "function" ? document.elementFromPoint(event.clientX, event.clientY) : null) ?? (event.target instanceof Element ? event.target : null);
|
|
36343
37445
|
}
|
|
37446
|
+
/** The shape's text target under the point (the dblclick's shape's text
|
|
37447
|
+
* entry's resolution — the connector's label's entry's guard's shared
|
|
37448
|
+
* read): the event's target's closest first (the retargeted event's stand),
|
|
37449
|
+
* the point's element STACK (the line's hit path — the wide transparent
|
|
37450
|
+
* stroke, the pointer-events' stand — is DOM-top over a shape it paints
|
|
37451
|
+
* over, so the single element's hit test resolves the line's element and
|
|
37452
|
+
* never the shape's target), the single elementFromPoint's fallback (the
|
|
37453
|
+
* jsdom's stack's absence). */
|
|
37454
|
+
function shapeTextTargetAt(event) {
|
|
37455
|
+
if (event.target instanceof Element) {
|
|
37456
|
+
const fromTarget = event.target.closest("[data-slot='docblocks/shape-text-target']");
|
|
37457
|
+
if (fromTarget !== null) return fromTarget;
|
|
37458
|
+
}
|
|
37459
|
+
if (typeof document.elementsFromPoint === "function") {
|
|
37460
|
+
for (const element of document.elementsFromPoint(event.clientX, event.clientY)) {
|
|
37461
|
+
const target = element.closest("[data-slot='docblocks/shape-text-target']");
|
|
37462
|
+
if (target !== null) return target;
|
|
37463
|
+
}
|
|
37464
|
+
return null;
|
|
37465
|
+
}
|
|
37466
|
+
const element = typeof document.elementFromPoint === "function" ? document.elementFromPoint(event.clientX, event.clientY) : null;
|
|
37467
|
+
return element instanceof Element ? element.closest("[data-slot='docblocks/shape-text-target']") ?? null : null;
|
|
37468
|
+
}
|
|
36344
37469
|
/** The title chip's double-click: the title's inline edit (the chip's own
|
|
36345
37470
|
* target — the chip stands in the screen layer outside the box, so the
|
|
36346
37471
|
* container's double-click handler never sees it). Only the chip itself
|
|
@@ -36381,7 +37506,8 @@ function createContentDoubleClick(ctx) {
|
|
|
36381
37506
|
}
|
|
36382
37507
|
if (ctx.viewport.mode === "default" && ctx.viewport.activeTool === null) {
|
|
36383
37508
|
const dblElement = pointElementOf(event);
|
|
36384
|
-
|
|
37509
|
+
const ghostWorld = screenToCanvas(ctx.centerRelativePoint(event), ctx.viewport.zoom, ctx.viewport.pan);
|
|
37510
|
+
if (dblElement instanceof Element && event.currentTarget.contains(dblElement) && dblElement.closest("[data-slot=\"docblocks/canvas-chrome\"]") === null && dblElement.closest("[data-slot=\"docblocks/canvas-text-ghost\"]") === null && dblElement.closest("[data-slot=\"docblocks/canvas-item\"]") === null && dblElement.closest("[data-slot=\"docblocks/page-card\"]") === null && dblElement.closest("[data-connector-hit]") === null && dblElement.closest(TITLE_CHIP_SELECTOR) === null && pressHitAt(ctx.doc, ghostWorld, ctx.viewport.zoom) === null) {
|
|
36385
37511
|
event.preventDefault();
|
|
36386
37512
|
ctx.viewport.setPendingText(screenToCanvas(ctx.centerRelativePoint(event), ctx.viewport.zoom, ctx.viewport.pan));
|
|
36387
37513
|
return;
|
|
@@ -36418,9 +37544,10 @@ function createContentDoubleClick(ctx) {
|
|
|
36418
37544
|
if (inner !== null) focusCaretInElement(inner, offset);
|
|
36419
37545
|
return;
|
|
36420
37546
|
}
|
|
37547
|
+
const shapeTextTarget = shapeTextTargetAt(event);
|
|
36421
37548
|
const labelWorld = screenToCanvas(ctx.centerRelativePoint(event), ctx.viewport.zoom, ctx.viewport.pan);
|
|
36422
37549
|
const labelCandidate = pressHitAt(ctx.doc, labelWorld, ctx.viewport.zoom);
|
|
36423
|
-
if (labelCandidate !== null && labelCandidate.type === "connector") {
|
|
37550
|
+
if (labelCandidate !== null && labelCandidate.type === "connector" && shapeTextTarget === null) {
|
|
36424
37551
|
ctx.viewport.setConnectorLabelEditing(labelCandidate.id);
|
|
36425
37552
|
return;
|
|
36426
37553
|
}
|
|
@@ -36441,9 +37568,7 @@ function createContentDoubleClick(ctx) {
|
|
|
36441
37568
|
return;
|
|
36442
37569
|
}
|
|
36443
37570
|
}
|
|
36444
|
-
const
|
|
36445
|
-
const element = fromTarget !== null ? fromTarget : document.elementFromPoint(event.clientX, event.clientY);
|
|
36446
|
-
const target = element instanceof Element ? element.closest("[data-slot='docblocks/shape-text-target']") : null;
|
|
37571
|
+
const target = shapeTextTarget;
|
|
36447
37572
|
if (target === null) return;
|
|
36448
37573
|
const id = target.closest("[data-slot='docblocks/canvas-item']")?.getAttribute("data-block-id") ?? null;
|
|
36449
37574
|
if (id !== null) ctx.viewport.setShapeTextEditing(id);
|
|
@@ -36459,20 +37584,49 @@ const NO_SESSION = {
|
|
|
36459
37584
|
segmentDrag: null
|
|
36460
37585
|
};
|
|
36461
37586
|
/**
|
|
36462
|
-
* Opens the
|
|
36463
|
-
*
|
|
36464
|
-
*
|
|
37587
|
+
* Opens the line's drag over the pressed connector: the orthogonal run's
|
|
37588
|
+
* segment drag OR the straight line's waypoint seed (the press's clamp's
|
|
37589
|
+
* point, the run's insert index). True when the press stood on a movable
|
|
37590
|
+
* run (the caller keeps the pointer capture and the session's release),
|
|
37591
|
+
* false otherwise.
|
|
36465
37592
|
*/
|
|
36466
37593
|
function beginSegmentPress(ctx, event, id, world) {
|
|
36467
37594
|
if (ctx.viewMode) return false;
|
|
36468
37595
|
const block = ctx.doc.getBlock(id);
|
|
36469
37596
|
if (block === null || block.type !== "connector") return false;
|
|
36470
|
-
|
|
37597
|
+
const variant = block.attrs?.variant ?? "straight";
|
|
36471
37598
|
const surface = ctx.surfaces.find((entry) => entry.children.includes(id));
|
|
36472
37599
|
if (surface === void 0) return false;
|
|
37600
|
+
const reach = 6 / ctx.viewport.zoom + (block.attrs?.strokeWidth ?? 1) / 2;
|
|
37601
|
+
if (variant !== "orthogonal") {
|
|
37602
|
+
if (variant !== "straight") return false;
|
|
37603
|
+
const geometry = connectorLineGeometryOf(id, block, surface.children, ctx.blocks, NO_SESSION);
|
|
37604
|
+
const route = geometry === null ? null : flattenPath(geometry.path);
|
|
37605
|
+
if (route === null || route.length < 2) return false;
|
|
37606
|
+
const endpointReach = 24 / ctx.viewport.zoom;
|
|
37607
|
+
const start = route[0];
|
|
37608
|
+
const end = route[route.length - 1];
|
|
37609
|
+
if (start !== void 0 && Math.hypot(world.x - start.x, world.y - start.y) <= endpointReach) {
|
|
37610
|
+
event.preventDefault();
|
|
37611
|
+
ctx.containerRef.current?.setPointerCapture?.(event.pointerId);
|
|
37612
|
+
ctx.viewport.beginConnectorEndpoint(id, "start", ctx.centerRelativePoint(event), event.clientX, event.clientY);
|
|
37613
|
+
return true;
|
|
37614
|
+
}
|
|
37615
|
+
if (end !== void 0 && Math.hypot(world.x - end.x, world.y - end.y) <= endpointReach) {
|
|
37616
|
+
event.preventDefault();
|
|
37617
|
+
ctx.containerRef.current?.setPointerCapture?.(event.pointerId);
|
|
37618
|
+
ctx.viewport.beginConnectorEndpoint(id, "end", ctx.centerRelativePoint(event), event.clientX, event.clientY);
|
|
37619
|
+
return true;
|
|
37620
|
+
}
|
|
37621
|
+
const seed = nearestRoutePointOf(route, world, reach);
|
|
37622
|
+
if (seed === null) return false;
|
|
37623
|
+
event.preventDefault();
|
|
37624
|
+
ctx.containerRef.current?.setPointerCapture?.(event.pointerId);
|
|
37625
|
+
ctx.viewport.beginConnectorWaypoint(id, seed.index, ctx.centerRelativePoint(event), event.clientX, event.clientY, seed.point);
|
|
37626
|
+
return true;
|
|
37627
|
+
}
|
|
36473
37628
|
const geometry = connectorLineGeometryOf(id, block, surface.children, ctx.blocks, NO_SESSION);
|
|
36474
37629
|
if (geometry === null || geometry.points.length < 3) return false;
|
|
36475
|
-
const reach = 6 / ctx.viewport.zoom + (block.attrs?.strokeWidth ?? 1) / 2;
|
|
36476
37630
|
const index = nearestSegmentOf(geometry.points, world, reach);
|
|
36477
37631
|
if (index === null) return false;
|
|
36478
37632
|
const from = geometry.points[index];
|
|
@@ -36480,6 +37634,7 @@ function beginSegmentPress(ctx, event, id, world) {
|
|
|
36480
37634
|
if (from === void 0 || to === void 0) return false;
|
|
36481
37635
|
const axis = segmentAxisOf(from, to);
|
|
36482
37636
|
if (axis === null) return false;
|
|
37637
|
+
event.preventDefault();
|
|
36483
37638
|
ctx.containerRef.current?.setPointerCapture?.(event.pointerId);
|
|
36484
37639
|
ctx.viewport.beginConnectorSegment(id, index, axis, ctx.centerRelativePoint(event));
|
|
36485
37640
|
return true;
|
|
@@ -37138,6 +38293,15 @@ function useCanvasSessions(deps) {
|
|
|
37138
38293
|
* selected line's endpoint handles, and the pending connector's preview
|
|
37139
38294
|
* stand points. All stand on the root's children, the block map, the store
|
|
37140
38295
|
* selection, and the viewport's live session state. */
|
|
38296
|
+
/** The committed geometry's session (the label's edit's frame stands on the
|
|
38297
|
+
* committed's route — the gesture's stand none). */
|
|
38298
|
+
const COMMITTED_GEOMETRY_SESSION = {
|
|
38299
|
+
movePreview: null,
|
|
38300
|
+
resizePreview: null,
|
|
38301
|
+
endpointDrag: null,
|
|
38302
|
+
endpointPreview: null,
|
|
38303
|
+
segmentDrag: null
|
|
38304
|
+
};
|
|
37141
38305
|
function useCanvasTargets({ rootChildren, blocks, storeSelection, viewport, rootBlockId }) {
|
|
37142
38306
|
const isDark = useDarkTheme();
|
|
37143
38307
|
const { pageChildren, surfaces } = useMemo(() => {
|
|
@@ -37260,11 +38424,12 @@ function useCanvasTargets({ rootChildren, blocks, storeSelection, viewport, root
|
|
|
37260
38424
|
const surface = surfaces.find((entry) => entry.children.includes(id));
|
|
37261
38425
|
if (surface === void 0) return null;
|
|
37262
38426
|
const childIds = surface.children;
|
|
37263
|
-
const mid =
|
|
38427
|
+
const mid = connectorMidOf(id, block, childIds, blocks, {
|
|
37264
38428
|
movePreview: null,
|
|
37265
38429
|
resizePreview: null,
|
|
37266
38430
|
endpointDrag: viewport.connectorEndpoint,
|
|
37267
|
-
endpointPreview: viewport.connectorEndpointPreview
|
|
38431
|
+
endpointPreview: viewport.connectorEndpointPreview,
|
|
38432
|
+
segmentDrag: viewport.connectorSegment
|
|
37268
38433
|
});
|
|
37269
38434
|
if (mid === null) return null;
|
|
37270
38435
|
return {
|
|
@@ -37287,7 +38452,7 @@ function useCanvasTargets({ rootChildren, blocks, storeSelection, viewport, root
|
|
|
37287
38452
|
if (block === void 0 || block.type !== "connector" || block.attrs === void 0) return null;
|
|
37288
38453
|
const surface = surfaces.find((entry) => entry.children.includes(id));
|
|
37289
38454
|
if (surface === void 0) return null;
|
|
37290
|
-
const mid =
|
|
38455
|
+
const mid = connectorMidOf(id, block, surface.children, blocks, COMMITTED_GEOMETRY_SESSION);
|
|
37291
38456
|
if (mid === null) return null;
|
|
37292
38457
|
const selected = storeSelection?.kind === "blocks" && storeSelection.ids.includes(id);
|
|
37293
38458
|
return {
|
|
@@ -40805,6 +41970,88 @@ function useCrossDrag(rootRef, doc, readOnly = false) {
|
|
|
40805
41970
|
}, []);
|
|
40806
41971
|
return { onPointerDown };
|
|
40807
41972
|
}
|
|
41973
|
+
// src/editing/mention/use-mention-caret.ts
|
|
41974
|
+
/**
|
|
41975
|
+
* The mention chip's caret stand: a click seats the caret on the side the
|
|
41976
|
+
* pointer pressed — the chip's left half before it, the right half after it
|
|
41977
|
+
* ("the end of the word").
|
|
41978
|
+
*
|
|
41979
|
+
* The press over the chip belongs to the island (the mousedown's default is
|
|
41980
|
+
* suppressed — the browser's own seat would pull the focus and the scroll
|
|
41981
|
+
* port over the shared page editable) and plants no focus of its own: a
|
|
41982
|
+
* press over the chip from outside the editing surface stands the consumer's
|
|
41983
|
+
* delivery only (the island is never a focus's entry). The seat stands over
|
|
41984
|
+
* a live caret — a text inner of this editor holds the focus — where the
|
|
41985
|
+
* chip's click is the caret's move: the chip's slot in the flat text is the
|
|
41986
|
+
* boundary, the block's inner takes the caret.
|
|
41987
|
+
*
|
|
41988
|
+
* The press's side is recorded at the mousedown and applied at the mouseup
|
|
41989
|
+
* over a plain click only: a drag stands a range (the selection's own
|
|
41990
|
+
* contract) and is left untouched. The listeners stand over the document,
|
|
41991
|
+
* scoped at event time to this editor's root — a nested editor (a
|
|
41992
|
+
* sync-embed) stands its own instance's stand.
|
|
41993
|
+
*/
|
|
41994
|
+
const CHIP_SELECTOR = "[data-slot=\"docblocks/mention\"]";
|
|
41995
|
+
const EDITOR_ROOT_SELECTOR = "[data-slot=\"docblocks/editor\"]";
|
|
41996
|
+
const INNER_SELECTOR = "[data-slot=\"docblocks/block-content\"]";
|
|
41997
|
+
/** The chip of the event's target when it belongs to this editor root. */
|
|
41998
|
+
function chipOf(root, target) {
|
|
41999
|
+
if (root === null || !(target instanceof Element) || !root.contains(target)) return null;
|
|
42000
|
+
const chip = target.closest(CHIP_SELECTOR);
|
|
42001
|
+
if (chip === null) return null;
|
|
42002
|
+
return chip.closest(EDITOR_ROOT_SELECTOR) === root ? chip : null;
|
|
42003
|
+
}
|
|
42004
|
+
/** Whether this editor holds the focus (the page's shared editable or a
|
|
42005
|
+
* block's own inner; a nested editor stands its own root). */
|
|
42006
|
+
function editingFocusIn(root) {
|
|
42007
|
+
if (root === null) return false;
|
|
42008
|
+
const active = document.activeElement;
|
|
42009
|
+
return active instanceof HTMLElement && root.contains(active) && active !== root;
|
|
42010
|
+
}
|
|
42011
|
+
/** Whether the selection's anchor stands in a text inner of this editor (the
|
|
42012
|
+
* live caret's stand over the press). */
|
|
42013
|
+
function caretInsideEditable(selection, root) {
|
|
42014
|
+
const anchor = selection.anchorNode;
|
|
42015
|
+
const inner = (anchor instanceof Element ? anchor : anchor?.parentElement ?? null)?.closest(INNER_SELECTOR) ?? null;
|
|
42016
|
+
return inner !== null && root.contains(inner);
|
|
42017
|
+
}
|
|
42018
|
+
function useMentionChipCaret(rootRef, viewMode) {
|
|
42019
|
+
useEffect(() => {
|
|
42020
|
+
if (viewMode) return;
|
|
42021
|
+
let press = null;
|
|
42022
|
+
const down = (event) => {
|
|
42023
|
+
press = null;
|
|
42024
|
+
if (event.button !== 0) return;
|
|
42025
|
+
const chip = chipOf(rootRef.current, event.target);
|
|
42026
|
+
if (chip === null) return;
|
|
42027
|
+
const rect = chip.getBoundingClientRect();
|
|
42028
|
+
press = {
|
|
42029
|
+
chip,
|
|
42030
|
+
after: event.clientX >= rect.left + rect.width / 2
|
|
42031
|
+
};
|
|
42032
|
+
};
|
|
42033
|
+
const up = (event) => {
|
|
42034
|
+
const current = press;
|
|
42035
|
+
press = null;
|
|
42036
|
+
if (current === null || chipOf(rootRef.current, event.target) !== current.chip) return;
|
|
42037
|
+
const selection = window.getSelection();
|
|
42038
|
+
if (selection === null) return;
|
|
42039
|
+
if (selection.rangeCount > 0 && !selection.isCollapsed) return;
|
|
42040
|
+
const inner = current.chip.closest(INNER_SELECTOR);
|
|
42041
|
+
const root = rootRef.current;
|
|
42042
|
+
if (inner === null || root === null) return;
|
|
42043
|
+
if (!editingFocusIn(root) || !caretInsideEditable(selection, root)) return;
|
|
42044
|
+
const slot = chipSlot(current.chip, current.after);
|
|
42045
|
+
restoreSelection(inner, caretOffsetIn(inner, slot.node, slot.offset), null);
|
|
42046
|
+
};
|
|
42047
|
+
document.addEventListener("mousedown", down, true);
|
|
42048
|
+
document.addEventListener("mouseup", up, true);
|
|
42049
|
+
return () => {
|
|
42050
|
+
document.removeEventListener("mousedown", down, true);
|
|
42051
|
+
document.removeEventListener("mouseup", up, true);
|
|
42052
|
+
};
|
|
42053
|
+
}, [rootRef, viewMode]);
|
|
42054
|
+
}
|
|
40808
42055
|
// src/editing/editor-root/blocks-keys.ts
|
|
40809
42056
|
/**
|
|
40810
42057
|
* The blocks selection's keys. A text row's own wrapper handles the same
|
|
@@ -40889,7 +42136,7 @@ function wrapRun(text, marks) {
|
|
|
40889
42136
|
if (marks.color !== void 0) out = `<span style="color: ${escapeHtml(marks.color.value)}">${out}</span>`;
|
|
40890
42137
|
if (marks.highlight?.value !== void 0) out = `<span style="background-color: ${escapeHtml(marks.highlight.value)}">${out}</span>`;
|
|
40891
42138
|
if (marks.link !== void 0 && isSafeLinkHref(marks.link.href)) out = `<a href="${escapeHtml(marks.link.href)}">${out}</a>`;
|
|
40892
|
-
if (marks.mention !== void 0) out = `<span data-mention="${escapeHtml(marks.mention.kind)}">${out}</span>`;
|
|
42139
|
+
if (marks.mention !== void 0) out = `<span data-mention="${escapeHtml(marks.mention.kind)}" data-mention-id="${escapeHtml(marks.mention.id)}">${out}</span>`;
|
|
40893
42140
|
return out;
|
|
40894
42141
|
}
|
|
40895
42142
|
/** The [from, to) segment of the runs as plain text + html. */
|
|
@@ -41210,7 +42457,7 @@ function ownsDocumentKeys(target, root) {
|
|
|
41210
42457
|
* over the range). True = consumed.
|
|
41211
42458
|
*/
|
|
41212
42459
|
function handleSelectAll(event, deps) {
|
|
41213
|
-
if (!(event.metaKey || event.ctrlKey) || event
|
|
42460
|
+
if (!(event.metaKey || event.ctrlKey) || shortcutLetter(event) !== "a" || event.shiftKey) return false;
|
|
41214
42461
|
if (!ownsDocumentKeys(deps.target, deps.root)) return false;
|
|
41215
42462
|
event.preventDefault();
|
|
41216
42463
|
const textIds = textBlockIdsOf(deps.doc, deps.rootBlockId);
|
|
@@ -41314,6 +42561,7 @@ function useEditing() {
|
|
|
41314
42561
|
const rootRef = useRef(null);
|
|
41315
42562
|
const crossDrag = useCrossDrag(rootRef, doc, viewMode);
|
|
41316
42563
|
useSelectionTracking(doc, rootRef, selectionRef, viewMode);
|
|
42564
|
+
useMentionChipCaret(rootRef, viewMode);
|
|
41317
42565
|
return {
|
|
41318
42566
|
rootRef,
|
|
41319
42567
|
onKeyDown: useCallback((event) => {
|
|
@@ -41342,13 +42590,13 @@ function useEditing() {
|
|
|
41342
42590
|
view
|
|
41343
42591
|
})) return;
|
|
41344
42592
|
if (!(event.metaKey || event.ctrlKey)) return;
|
|
41345
|
-
const
|
|
41346
|
-
if (
|
|
42593
|
+
const letter = shortcutLetter(event);
|
|
42594
|
+
if (letter === "z" && !event.shiftKey) {
|
|
41347
42595
|
event.preventDefault();
|
|
41348
42596
|
doc.undo();
|
|
41349
42597
|
selectionRef.reseatUntil.current = Date.now() + RESEAT_WINDOW_MS;
|
|
41350
42598
|
scheduleHistoryReseat(doc, view, root);
|
|
41351
|
-
} else if (
|
|
42599
|
+
} else if (letter === "z" && event.shiftKey || letter === "y") {
|
|
41352
42600
|
event.preventDefault();
|
|
41353
42601
|
doc.redo();
|
|
41354
42602
|
selectionRef.reseatUntil.current = Date.now() + RESEAT_WINDOW_MS;
|