@drawback/core 0.2.0-rc.20261201121350 → 0.2.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/dist/geometry/index.d.mts +1 -1
- package/dist/geometry/index.mjs +1 -1
- package/dist/{geometry-Brsa66kT.mjs → geometry-B6555wfO.mjs} +2 -8
- package/dist/grid/index.d.mts +1 -1
- package/dist/grid/index.mjs +1 -1
- package/dist/{grid-BR8od5w8.mjs → grid-BjZ79Ib6.mjs} +1 -4
- package/dist/{index-CYSqrhal.d.mts → index-BUdcJ8w8.d.mts} +1 -4
- package/dist/{index-Bt8yLTLG.d.mts → index-CukXdXbn.d.mts} +1 -4
- package/dist/index.d.mts +39 -157
- package/dist/index.mjs +48 -129
- package/package.json +1 -1
- package/src/assets/references.ts +1 -4
- package/src/assets/types.ts +1 -5
- package/src/assets/url.ts +1 -4
- package/src/bindings/bindings.ts +2 -15
- package/src/bindings/derive.ts +1 -4
- package/src/clipboard/format.ts +1 -4
- package/src/clipboard/insert.ts +1 -4
- package/src/commands/builtin.ts +13 -0
- package/src/editing-host.ts +3 -15
- package/src/editor.ts +7 -27
- package/src/events.ts +1 -4
- package/src/frames/frames.ts +2 -16
- package/src/geometry/curves.ts +1 -4
- package/src/geometry/simplify.ts +1 -4
- package/src/grid/math.ts +1 -4
- package/src/groups/cleanup.ts +1 -4
- package/src/image/images.ts +1 -4
- package/src/input/handle-sessions.ts +2 -7
- package/src/input/router.ts +1 -4
- package/src/interactions/interactions.ts +1 -4
- package/src/linear/elbow.ts +2 -8
- package/src/linear/linear.ts +1 -4
- package/src/links/links.ts +3 -14
- package/src/model/elements.ts +3 -12
- package/src/model/frame.ts +2 -9
- package/src/model/linear.ts +2 -8
- package/src/model/settings.ts +2 -5
- package/src/model/style.ts +2 -8
- package/src/modes/modes.ts +1 -0
- package/src/permissions/capabilities.ts +1 -0
- package/src/permissions/permissions.ts +6 -8
- package/src/plugins/plugins.ts +1 -6
- package/src/presence/presence.ts +1 -4
- package/src/scene/scene.ts +1 -5
- package/src/selection/selection.ts +1 -4
- package/src/snapping/snapping.ts +1 -2
- package/src/styles/styles.ts +1 -4
- package/src/sync/projection.ts +1 -4
- package/src/text/layout.ts +1 -4
- package/src/text/measure.ts +2 -8
- package/src/text/text.ts +1 -4
- package/src/transform/transform.ts +1 -2
- package/src/tx/derivation.ts +2 -10
- package/src/tx/document-steps.ts +1 -4
- package/src/tx/record-writer.ts +1 -4
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as elementMatrix, B as CommitRejectedError, C as boxIntersects, D as transformBox, E as expandBox, F as translationMatrix, G as PermissionDeniedError, H as DuplicateIdError, I as viewportMatrix, J as UnknownTypeError, K as RevisionUnavailableError, L as AnimationCancelledError, M as multiplyMatrix, N as rotationMatrix, O as IDENTITY_MATRIX, P as scaleMatrix, R as CanvasError, S as boxFromPoints, T as boxesEqual, U as NotFoundError, V as DisposedError, W as PendingAssetsError, X as toError, Y as ValidationError, _ as shapeSubpaths, a as distanceToPolyline, b as boxContainsPoint, c as projectOnSegment, d as containedInBox, f as containsPoint, g as shapeBounds, h as intersectsBox, i as closestPointOnOutline, j as invertMatrix, k as applyMatrix, l as rayOutlineIntersections, m as flattenPath, n as simplifyPoints, o as polylineSegments, p as distanceToOutline, q as UnavailableToolError, r as catmullRomSegments, s as projectOnPolyline, t as simplifyIndices, u as roundedPolygonSegments, v as boxArea, w as boxUnion, x as boxCorners, y as boxContains, z as CapabilityError } from "./geometry-
|
|
1
|
+
import { A as elementMatrix, B as CommitRejectedError, C as boxIntersects, D as transformBox, E as expandBox, F as translationMatrix, G as PermissionDeniedError, H as DuplicateIdError, I as viewportMatrix, J as UnknownTypeError, K as RevisionUnavailableError, L as AnimationCancelledError, M as multiplyMatrix, N as rotationMatrix, O as IDENTITY_MATRIX, P as scaleMatrix, R as CanvasError, S as boxFromPoints, T as boxesEqual, U as NotFoundError, V as DisposedError, W as PendingAssetsError, X as toError, Y as ValidationError, _ as shapeSubpaths, a as distanceToPolyline, b as boxContainsPoint, c as projectOnSegment, d as containedInBox, f as containsPoint, g as shapeBounds, h as intersectsBox, i as closestPointOnOutline, j as invertMatrix, k as applyMatrix, l as rayOutlineIntersections, m as flattenPath, n as simplifyPoints, o as polylineSegments, p as distanceToOutline, q as UnavailableToolError, r as catmullRomSegments, s as projectOnPolyline, t as simplifyIndices, u as roundedPolygonSegments, v as boxArea, w as boxUnion, x as boxCorners, y as boxContains, z as CapabilityError } from "./geometry-B6555wfO.mjs";
|
|
2
2
|
import { generateKeyBetween, generateNKeysBetween } from "fractional-indexing";
|
|
3
3
|
import { array, boolean, check, finite as finite$2, literal, maxLength, maxValue, minLength, minValue, nullable, number, object, optional, picklist, pipe, safeParse, string, transform, tuple, variant } from "valibot";
|
|
4
4
|
import RBush from "rbush";
|
|
5
|
-
import { _ as cubeRound, a as cellVertices, b as offsetToAxial, c as intersectionsNear, d as snapPoint, f as worldToGrid, g as axialToOffset, h as axialToCube, i as cellSpacing, l as isHexGrid, m as axialRound, n as cellBounds, o as cellsInBox, p as HEX_DIRECTIONS, r as cellCenter, s as gridToWorld, t as cellAt, u as neighbors, v as cubeSteps, y as cubeToAxial } from "./grid-
|
|
5
|
+
import { _ as cubeRound, a as cellVertices, b as offsetToAxial, c as intersectionsNear, d as snapPoint, f as worldToGrid, g as axialToOffset, h as axialToCube, i as cellSpacing, l as isHexGrid, m as axialRound, n as cellBounds, o as cellsInBox, p as HEX_DIRECTIONS, r as cellCenter, s as gridToWorld, t as cellAt, u as neighbors, v as cubeSteps, y as cubeToAxial } from "./grid-BjZ79Ib6.mjs";
|
|
6
6
|
// src/events.ts
|
|
7
7
|
function surfaceUnhandledError(error) {
|
|
8
8
|
const queue = Reflect.get(globalThis, "queueMicrotask");
|
|
@@ -602,18 +602,12 @@ function mergeStyleDefaults(...levels) {
|
|
|
602
602
|
}
|
|
603
603
|
return Object.freeze(result);
|
|
604
604
|
}
|
|
605
|
-
/**
|
|
606
|
-
* Tolerant render-time resolution: valid stored values win, invalid or missing ones
|
|
607
|
-
* fall back to `defaults` and then to {@link DEFAULT_ELEMENT_STYLE}.
|
|
608
|
-
*/
|
|
605
|
+
/** Valid stored values, then `defaults`, then {@link DEFAULT_ELEMENT_STYLE}. */
|
|
609
606
|
const NO_DEFAULTS = Object.freeze({});
|
|
610
607
|
const NO_STYLE = Object.freeze({});
|
|
611
608
|
/** Resolved styles by defaults object, then style object; both are immutable in practice. */
|
|
612
609
|
const resolvedStyles = /* @__PURE__ */ new WeakMap();
|
|
613
|
-
/**
|
|
614
|
-
* The element's style over `defaults`, with every key present. Results are cached per
|
|
615
|
-
* (defaults, style) object pair and frozen, so callers must not mutate them.
|
|
616
|
-
*/
|
|
610
|
+
/** Full style over `defaults`, cached per (defaults, style) pair and frozen: never mutate. */
|
|
617
611
|
function resolveStyle(element, defaults = NO_DEFAULTS) {
|
|
618
612
|
const styleKey = element.style ?? NO_STYLE;
|
|
619
613
|
let byStyle = resolvedStyles.get(defaults);
|
|
@@ -749,10 +743,7 @@ function isHostScheme(value) {
|
|
|
749
743
|
"file"
|
|
750
744
|
].includes(value);
|
|
751
745
|
}
|
|
752
|
-
/**
|
|
753
|
-
* Durable asset sources: http(s), relative URLs and host schemes. Runtime-only
|
|
754
|
-
* (`blob:`, `data:`) and script URLs are rejected.
|
|
755
|
-
*/
|
|
746
|
+
/** Durable asset sources only: http(s), relative and host schemes; no `blob:`/`data:`/script. */
|
|
756
747
|
function validateAssetSource(src, context, hostSchemes) {
|
|
757
748
|
if (typeof src !== "string" || src.trim().length === 0 || src.length > 8192) throw new ValidationError(`${context}.src must be a non-empty URL of at most 8192 characters.`);
|
|
758
749
|
const scheme = urlScheme(src);
|
|
@@ -1191,10 +1182,7 @@ function typeLabel(type) {
|
|
|
1191
1182
|
const words = (type.split(".").at(-1) ?? type).replace(/[-_]+/g, " ").trim();
|
|
1192
1183
|
return words.length === 0 ? type : words[0].toUpperCase() + words.slice(1);
|
|
1193
1184
|
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Display name and icon id: the record's `name`, then the definition's `describe`, then a
|
|
1196
|
-
* built-in label (text elements use their first line), then a label derived from the type.
|
|
1197
|
-
*/
|
|
1185
|
+
/** Display name and icon: `name`, then `describe`, then a built-in label, then the type. */
|
|
1198
1186
|
function describeElement(element, definition) {
|
|
1199
1187
|
let hint = {};
|
|
1200
1188
|
try {
|
|
@@ -1510,10 +1498,7 @@ function axisLines(from, to, boxes, axis) {
|
|
|
1510
1498
|
for (const [, maxA] of ranges) for (const [minB] of ranges) if (minB > maxA) values.push((maxA + minB) / 2);
|
|
1511
1499
|
return uniqueSorted(values);
|
|
1512
1500
|
}
|
|
1513
|
-
/**
|
|
1514
|
-
* Orthogonal leg from `from` (leaving along `leave`) to `to` (arriving along `arrive`) that keeps
|
|
1515
|
-
* out of `boxes`. Cost is length plus a penalty per bend; ties resolve deterministically.
|
|
1516
|
-
*/
|
|
1501
|
+
/** Orthogonal leg avoiding `boxes`; cost is length plus a per-bend penalty, ties fixed. */
|
|
1517
1502
|
function leg(from, leave, to, arrive, boxes) {
|
|
1518
1503
|
const xs = axisLines(from.x, to.x, boxes, "x");
|
|
1519
1504
|
const ys = axisLines(from.y, to.y, boxes, "y");
|
|
@@ -1646,10 +1631,7 @@ function simplifyOrthogonal(points) {
|
|
|
1646
1631
|
}
|
|
1647
1632
|
return result;
|
|
1648
1633
|
}
|
|
1649
|
-
/**
|
|
1650
|
-
* Orthogonal route between two ends. Bound ends leave their target along `heading`, the route
|
|
1651
|
-
* avoids the padded targets and passes through pinned segments in order. Deterministic.
|
|
1652
|
-
*/
|
|
1634
|
+
/** Deterministic orthogonal route around padded targets, through pinned segments. */
|
|
1653
1635
|
function routeElbow(start, end, options = {}) {
|
|
1654
1636
|
const margin = options.margin ?? 24;
|
|
1655
1637
|
const boxes = [start.box, end.box].filter((box) => box !== void 0).map((box) => expandBox(box, margin));
|
|
@@ -1839,10 +1821,7 @@ function elbowEnd(point, box, other) {
|
|
|
1839
1821
|
box
|
|
1840
1822
|
};
|
|
1841
1823
|
}
|
|
1842
|
-
/**
|
|
1843
|
-
* Re-routes an elbow arrow between world end points, keeping its pinned segments. `targets` are
|
|
1844
|
-
* the world bounds of bound targets.
|
|
1845
|
-
*/
|
|
1824
|
+
/** Re-routes an elbow arrow between world ends, keeping pinned segments. */
|
|
1846
1825
|
function elbowArrowUpdate(element, ends, targets = {}, fixed = elbowFixedSegmentsWorld(element)) {
|
|
1847
1826
|
const route = routeElbow(elbowEnd(ends.start, targets.start, ends.end), elbowEnd(ends.end, targets.end, ends.start), { fixed });
|
|
1848
1827
|
const placement = linearFromWorldPoints(element, route.length >= 2 ? route : [ends.start, ends.end], .01);
|
|
@@ -1889,10 +1868,7 @@ function linearShape(element) {
|
|
|
1889
1868
|
function round$1(value, quantum) {
|
|
1890
1869
|
return quantum === void 0 ? value : Math.round(value / quantum) * quantum;
|
|
1891
1870
|
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Computes box and normalized local points for world-space points, keeping the element's
|
|
1894
|
-
* rotation and flips. `quantum` rounds local points (e.g. `0.01`).
|
|
1895
|
-
*/
|
|
1871
|
+
/** Box and normalized local points for world points, keeping rotation and flips. */
|
|
1896
1872
|
function linearFromWorldPoints(element, world, quantum) {
|
|
1897
1873
|
const unrotate = rotationMatrix(-element.rotation);
|
|
1898
1874
|
const rotate = rotationMatrix(element.rotation);
|
|
@@ -2207,10 +2183,7 @@ function isFrame(element) {
|
|
|
2207
2183
|
function frameName(element) {
|
|
2208
2184
|
return typeof element.name === "string" && element.name.trim() !== "" ? element.name : DEFAULT_FRAME_NAME;
|
|
2209
2185
|
}
|
|
2210
|
-
/**
|
|
2211
|
-
* Frame-local box of the name label at `zoom` (the label keeps its screen size). The width is
|
|
2212
|
-
* estimated from the name length and never exceeds the frame width.
|
|
2213
|
-
*/
|
|
2186
|
+
/** Frame-local name label box at `zoom`, estimated from the name, capped to the frame width. */
|
|
2214
2187
|
function frameLabelBox(element, zoom) {
|
|
2215
2188
|
const scale = 1 / Math.max(zoom, 1e-6);
|
|
2216
2189
|
const width = Math.min(element.w, (frameName(element).length * FRAME_LABEL.charWidth + FRAME_LABEL.padding * 2) * scale);
|
|
@@ -2222,11 +2195,7 @@ function frameLabelBox(element, zoom) {
|
|
|
2222
2195
|
maxY
|
|
2223
2196
|
};
|
|
2224
2197
|
}
|
|
2225
|
-
/**
|
|
2226
|
-
* A frame groups the elements inside it: it clips them, moves them along and is deleted and
|
|
2227
|
-
* duplicated with them. Children store the frame in `frameId`. Frames are hit on their border
|
|
2228
|
-
* and name label only, so clicks inside reach the canvas and the children.
|
|
2229
|
-
*/
|
|
2198
|
+
/** Frames clip, move and delete with their children; hit only on border and name label. */
|
|
2230
2199
|
const frameElement = defineElement({
|
|
2231
2200
|
type: FRAME_TYPE,
|
|
2232
2201
|
version: 1,
|
|
@@ -2832,10 +2801,7 @@ function elementCenter$1(element) {
|
|
|
2832
2801
|
function isFixedBinding(binding) {
|
|
2833
2802
|
return binding.mode !== "element";
|
|
2834
2803
|
}
|
|
2835
|
-
/**
|
|
2836
|
-
* Resolves a binding to a world point. `reference` (world) is the point the connector comes
|
|
2837
|
-
* from; only `element` mode uses it.
|
|
2838
|
-
*/
|
|
2804
|
+
/** Binding as a world point; `element` mode aims from `reference`, the connector's source. */
|
|
2839
2805
|
function resolveBindingPoint(context, binding, reference) {
|
|
2840
2806
|
const target = context.element(binding.elementId);
|
|
2841
2807
|
if (target === void 0) return;
|
|
@@ -3154,11 +3120,7 @@ var BindingsController = class {
|
|
|
3154
3120
|
}
|
|
3155
3121
|
for (const event of events) this.#host.emit("binding.change", event);
|
|
3156
3122
|
}
|
|
3157
|
-
/**
|
|
3158
|
-
* Derives connector updates for a local commit: unbinds ends of deleted targets and
|
|
3159
|
-
* translated-alone connectors, validates new bindings and moves bound endpoints.
|
|
3160
|
-
* Returns the record keys it changed.
|
|
3161
|
-
*/
|
|
3123
|
+
/** Connector updates for a local commit (unbind, validate, follow); returns changed keys. */
|
|
3162
3124
|
deriveCommit(staged, operations, update) {
|
|
3163
3125
|
const editor = this.#host.editor;
|
|
3164
3126
|
const context = this.#stagedContext(staged);
|
|
@@ -3220,10 +3182,7 @@ var BindingsController = class {
|
|
|
3220
3182
|
}
|
|
3221
3183
|
return keys;
|
|
3222
3184
|
}
|
|
3223
|
-
/**
|
|
3224
|
-
* Verifies connector operations of a checked remote change set: they must equal the
|
|
3225
|
-
* recomputation from the staged state. Returns ids of connectors that do not.
|
|
3226
|
-
*/
|
|
3185
|
+
/** Ids of connectors in a checked remote change set that differ from the recomputation. */
|
|
3227
3186
|
verify(staged, ids) {
|
|
3228
3187
|
const context = this.#stagedContext(staged);
|
|
3229
3188
|
return ids.filter((id) => {
|
|
@@ -3553,12 +3512,7 @@ var FramesController = class {
|
|
|
3553
3512
|
this.#parentOf.set(id, element.frameId);
|
|
3554
3513
|
}
|
|
3555
3514
|
}
|
|
3556
|
-
/**
|
|
3557
|
-
* Adjusts a local transaction before it commits: deleting a frame deletes its children,
|
|
3558
|
-
* translating a frame moves its children, and (with `autoAssign`) elements join the frame
|
|
3559
|
-
* that contains them and leave a frame they no longer overlap. Returns the element ids it
|
|
3560
|
-
* changed.
|
|
3561
|
-
*/
|
|
3515
|
+
/** Local commit step: frames carry children on delete and move; `autoAssign` joins and leaves. */
|
|
3562
3516
|
deriveCommit(operations, staged) {
|
|
3563
3517
|
const editor = this.#host.editor;
|
|
3564
3518
|
const changed = /* @__PURE__ */ new Set();
|
|
@@ -3773,10 +3727,7 @@ function elementIdsOf(operations) {
|
|
|
3773
3727
|
else if (operation.op === "patch" && operation.kind === "element") ids.push(asElementId(operation.id));
|
|
3774
3728
|
return ids;
|
|
3775
3729
|
}
|
|
3776
|
-
/**
|
|
3777
|
-
* Runs `steps` in order and returns every record key they changed. The operations a step sees
|
|
3778
|
-
* are recomputed only when an earlier step changed something.
|
|
3779
|
-
*/
|
|
3730
|
+
/** Runs `steps` in order, recomputing operations only after a step changed something. */
|
|
3780
3731
|
function runCommitDerivations(steps, run) {
|
|
3781
3732
|
const derived = [];
|
|
3782
3733
|
let operations = run.intended;
|
|
@@ -3806,10 +3757,7 @@ function textDerivation(text) {
|
|
|
3806
3757
|
};
|
|
3807
3758
|
}
|
|
3808
3759
|
// src/groups/cleanup.ts
|
|
3809
|
-
/**
|
|
3810
|
-
* Removes groups a local transaction left empty (and their parents, if they became empty in
|
|
3811
|
-
* turn), in the same change set.
|
|
3812
|
-
*/
|
|
3760
|
+
/** Removes groups a local transaction emptied (and emptied parents) in the same change set. */
|
|
3813
3761
|
const emptyGroupDerivation = {
|
|
3814
3762
|
id: "groups",
|
|
3815
3763
|
derive: ({ operations, committed, record, records, deleteRecord }) => {
|
|
@@ -3852,10 +3800,7 @@ const emptyGroupDerivation = {
|
|
|
3852
3800
|
}
|
|
3853
3801
|
};
|
|
3854
3802
|
// src/tx/document-steps.ts
|
|
3855
|
-
/**
|
|
3856
|
-
* Runs the editor's internal reactions to document changes and loads, in the order they are
|
|
3857
|
-
* listed, before any public listener. A failing step is reported and the others still run.
|
|
3858
|
-
*/
|
|
3803
|
+
/** Internal reactions to changes and loads, before public listeners; a failure skips one step. */
|
|
3859
3804
|
var DocumentSteps = class {
|
|
3860
3805
|
#change;
|
|
3861
3806
|
#load;
|
|
@@ -4688,10 +4633,7 @@ const RECORD_LABELS = {
|
|
|
4688
4633
|
group: "Group",
|
|
4689
4634
|
asset: "Asset"
|
|
4690
4635
|
};
|
|
4691
|
-
/**
|
|
4692
|
-
* Creates and updates normalized records inside a transaction's record store: ids, default
|
|
4693
|
-
* layer, order keys, style materialization and validation.
|
|
4694
|
-
*/
|
|
4636
|
+
/** Writes normalized records in a transaction: ids, layer, order, styles, validation. */
|
|
4695
4637
|
var RecordWriter = class {
|
|
4696
4638
|
#deps;
|
|
4697
4639
|
constructor(dependencies) {
|
|
@@ -5596,11 +5538,7 @@ var SceneIndex = class {
|
|
|
5596
5538
|
#viewFilter;
|
|
5597
5539
|
/** Frames are hit on a screen-sized name label outside their indexed bounds. */
|
|
5598
5540
|
#frameIds = /* @__PURE__ */ new Set();
|
|
5599
|
-
/**
|
|
5600
|
-
* Geometry and bounds per record. Records are immutable, so a record is its own cache key;
|
|
5601
|
-
* anything else they depend on (definitions, style defaults, text layout, fonts, masks)
|
|
5602
|
-
* rebuilds the scene, which drops the caches.
|
|
5603
|
-
*/
|
|
5541
|
+
/** Geometry and bounds keyed by immutable record; other inputs rebuild the scene. */
|
|
5604
5542
|
#geometryCache = /* @__PURE__ */ new WeakMap();
|
|
5605
5543
|
#boundsCache = /* @__PURE__ */ new WeakMap();
|
|
5606
5544
|
/** Whole-document results (queries, content bounds) for the current document version. */
|
|
@@ -8473,7 +8411,10 @@ function orderCommand(id, label, run) {
|
|
|
8473
8411
|
canRun: (_args, { editor }) => editor.order.eligible(editor.selection.get()).length > 0
|
|
8474
8412
|
};
|
|
8475
8413
|
}
|
|
8414
|
+
/** Two Escapes within this window leave zen mode, like VS Code. */
|
|
8415
|
+
const ZEN_EXIT_WINDOW = 500;
|
|
8476
8416
|
function builtinCommands() {
|
|
8417
|
+
let lastCancel = Number.NEGATIVE_INFINITY;
|
|
8477
8418
|
return [
|
|
8478
8419
|
{
|
|
8479
8420
|
id: "core.undo",
|
|
@@ -8604,6 +8545,13 @@ function builtinCommands() {
|
|
|
8604
8545
|
id: "core.cancel",
|
|
8605
8546
|
label: "Cancel",
|
|
8606
8547
|
run: (_args, { editor }) => {
|
|
8548
|
+
const now = Date.now();
|
|
8549
|
+
const twice = now - lastCancel < ZEN_EXIT_WINDOW;
|
|
8550
|
+
lastCancel = twice ? Number.NEGATIVE_INFINITY : now;
|
|
8551
|
+
if (twice && editor.modes.presentation().zen) {
|
|
8552
|
+
editor.modes.setPresentation({ zen: false });
|
|
8553
|
+
return;
|
|
8554
|
+
}
|
|
8607
8555
|
if (editor.interactions.cancel()) return;
|
|
8608
8556
|
if (editor.linear.editing() !== void 0) {
|
|
8609
8557
|
editor.linear.exit();
|
|
@@ -10220,11 +10168,7 @@ function builtinTools() {
|
|
|
10220
10168
|
];
|
|
10221
10169
|
}
|
|
10222
10170
|
// src/input/handle-sessions.ts
|
|
10223
|
-
/**
|
|
10224
|
-
* Starts the pointer session for a selection handle: resize, rotate, a point handle or a
|
|
10225
|
-
* definition's custom handle. Returns `undefined` when nothing is selected or the handle has
|
|
10226
|
-
* no session.
|
|
10227
|
-
*/
|
|
10171
|
+
/** Pointer session for a selection handle; `undefined` without a selection or session. */
|
|
10228
10172
|
function startHandleSession(deps, handle, down) {
|
|
10229
10173
|
const editor = deps.editor;
|
|
10230
10174
|
const records = deps.selection.elements();
|
|
@@ -10764,10 +10708,7 @@ var InputController = class {
|
|
|
10764
10708
|
setPointSessions(factory) {
|
|
10765
10709
|
this.#pointSessions = factory;
|
|
10766
10710
|
}
|
|
10767
|
-
/**
|
|
10768
|
-
* Knob handles (corners, rotation, points, custom) win within `handleSize`; otherwise a side
|
|
10769
|
-
* resize handle is hit anywhere within half that distance of its side.
|
|
10770
|
-
*/
|
|
10711
|
+
/** Knobs win within `handleSize`; sides hit within half that distance of the side. */
|
|
10771
10712
|
#hitHandle(event) {
|
|
10772
10713
|
const zoom = this.#host.editor.viewport.get().zoom;
|
|
10773
10714
|
const radius = this.#selection.options().handleSize / zoom;
|
|
@@ -11939,10 +11880,7 @@ function graphemeSegments(text) {
|
|
|
11939
11880
|
graphemes ??= new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
11940
11881
|
return Array.from(graphemes.segment(text), (part) => part.segment);
|
|
11941
11882
|
}
|
|
11942
|
-
/**
|
|
11943
|
-
* Deterministic measurer for headless editors: widths come from per-script em
|
|
11944
|
-
* advances, so results are identical on every machine.
|
|
11945
|
-
*/
|
|
11883
|
+
/** Headless measurer from per-script em advances: identical results on every machine. */
|
|
11946
11884
|
function createApproximateMeasurer(metricsOf = () => void 0) {
|
|
11947
11885
|
return { measure(text, font) {
|
|
11948
11886
|
const metrics = metricsOf(font.family) ?? DEFAULT_METRICS;
|
|
@@ -11968,10 +11906,7 @@ function createApproximateMeasurer(metricsOf = () => void 0) {
|
|
|
11968
11906
|
function fontSpecKey(font) {
|
|
11969
11907
|
return `${font.style}|${font.weight}|${font.size}|${font.family}`;
|
|
11970
11908
|
}
|
|
11971
|
-
/**
|
|
11972
|
-
* Wraps a measurer with a two-generation width cache keyed by font and string: entries
|
|
11973
|
-
* used since the last rotation survive, so the hot set stays cached in O(1) per lookup.
|
|
11974
|
-
*/
|
|
11909
|
+
/** Two-generation width cache by font and string: O(1) lookups that keep the hot set. */
|
|
11975
11910
|
function cachedMeasurer(measurer, capacity = 2e4) {
|
|
11976
11911
|
let current = /* @__PURE__ */ new Map();
|
|
11977
11912
|
let previous = /* @__PURE__ */ new Map();
|
|
@@ -12091,10 +12026,7 @@ function wrapParagraph(paragraph, maxWidth, width) {
|
|
|
12091
12026
|
lines.push(line);
|
|
12092
12027
|
return lines;
|
|
12093
12028
|
}
|
|
12094
|
-
/**
|
|
12095
|
-
* Lays out plain text. Break decisions use unit widths; final line widths are
|
|
12096
|
-
* measured on whole lines so they match what the renderer draws.
|
|
12097
|
-
*/
|
|
12029
|
+
/** Lays out plain text; widths are measured per whole line to match the renderer. */
|
|
12098
12030
|
function layoutText(text, options, measurer) {
|
|
12099
12031
|
const { font } = options;
|
|
12100
12032
|
const lineHeight = font.size * options.lineHeight;
|
|
@@ -12424,10 +12356,7 @@ var TextController = class {
|
|
|
12424
12356
|
const local = applyMatrix(invertMatrix(elementMatrix(element)), world);
|
|
12425
12357
|
return boxContainsPoint(expandBox(layout.box, LABEL_GAP_PADDING), local);
|
|
12426
12358
|
}
|
|
12427
|
-
/**
|
|
12428
|
-
* Extra fields that keep a text record consistent: auto boxes fit their text, fixed
|
|
12429
|
-
* boxes fit their height, corner scaling scales the font, labels grow their shape.
|
|
12430
|
-
*/
|
|
12359
|
+
/** Fields that keep a text record consistent (box fitting, corner scaling, labels). */
|
|
12431
12360
|
normalize(before, after, force = false) {
|
|
12432
12361
|
if (after.type === "core.text") return this.#normalizeText(before, after, force);
|
|
12433
12362
|
const hooks = this.#dependencies.definitionOf(after.type)?.label;
|
|
@@ -12894,10 +12823,7 @@ function isClipboardText(text) {
|
|
|
12894
12823
|
const trimmed = text.trimStart();
|
|
12895
12824
|
return trimmed.startsWith("{") && trimmed.includes(`"interactive-canvas-clipboard"`);
|
|
12896
12825
|
}
|
|
12897
|
-
/**
|
|
12898
|
-
* Validates an untrusted payload (object or JSON text). Records are normalized with the
|
|
12899
|
-
* same rules as documents; the payload must not exceed the element and size limits.
|
|
12900
|
-
*/
|
|
12826
|
+
/** Validates an untrusted payload (object or JSON) with document rules and size limits. */
|
|
12901
12827
|
function parseClipboardPayload(input, normalize) {
|
|
12902
12828
|
let value = input;
|
|
12903
12829
|
if (typeof input === "string") {
|
|
@@ -12970,10 +12896,7 @@ function groupDepth(group, byId) {
|
|
|
12970
12896
|
}
|
|
12971
12897
|
return depth;
|
|
12972
12898
|
}
|
|
12973
|
-
/**
|
|
12974
|
-
* Inserts foreign records into the document as one transaction: new element, group and
|
|
12975
|
-
* layer ids, remapped references, reused assets, orders appended on top of each layer.
|
|
12976
|
-
*/
|
|
12899
|
+
/** Inserts foreign records in one transaction: new ids, remapped refs, orders on top. */
|
|
12977
12900
|
function insertRecords(editor, definitionOf, hooksOf, records, options, generate) {
|
|
12978
12901
|
const assetMap = /* @__PURE__ */ new Map();
|
|
12979
12902
|
const newAssets = [];
|
|
@@ -14580,10 +14503,7 @@ function createAbortController() {
|
|
|
14580
14503
|
var AssetReferenceIndex = class {
|
|
14581
14504
|
#byAsset = /* @__PURE__ */ new Map();
|
|
14582
14505
|
#byElement = /* @__PURE__ */ new Map();
|
|
14583
|
-
/**
|
|
14584
|
-
* Replaces the assets `element` references. Returns the assets nobody references anymore
|
|
14585
|
-
* because of this change.
|
|
14586
|
-
*/
|
|
14506
|
+
/** Replaces `element`'s asset references; returns assets no longer referenced. */
|
|
14587
14507
|
set(element, assets) {
|
|
14588
14508
|
const released = [];
|
|
14589
14509
|
for (const asset of this.#byElement.get(element) ?? []) {
|
|
@@ -15693,10 +15613,7 @@ var ImagesController = class {
|
|
|
15693
15613
|
onCancel: () => gesture.cancel()
|
|
15694
15614
|
};
|
|
15695
15615
|
}
|
|
15696
|
-
/**
|
|
15697
|
-
* Keeps image elements consistent with their assets for local commits: natural size
|
|
15698
|
-
* follows the asset when it is known or changes, and crops are clamped to it.
|
|
15699
|
-
*/
|
|
15616
|
+
/** Keeps images consistent with their assets on local commits (natural size, crop clamp). */
|
|
15700
15617
|
normalize(element, assetOf) {
|
|
15701
15618
|
if (!isImageElement(element)) return;
|
|
15702
15619
|
const props = readImageProps(element);
|
|
@@ -15738,11 +15655,7 @@ function pageUrl() {
|
|
|
15738
15655
|
const href = location !== null && typeof location === "object" ? Reflect.get(location, "href") : void 0;
|
|
15739
15656
|
return typeof href === "string" ? parseUrl(href) : void 0;
|
|
15740
15657
|
}
|
|
15741
|
-
/**
|
|
15742
|
-
* Default element links, like Excalidraw's "Copy link to object": the current page with
|
|
15743
|
-
* `?element=<id>` (other query parameters and the hash are kept). A URL counts as an element
|
|
15744
|
-
* link when it has the same origin and path as the current page and an `element` parameter.
|
|
15745
|
-
*/
|
|
15658
|
+
/** Default element links, like Excalidraw: the current page with `?element=<id>`. */
|
|
15746
15659
|
const pageElementLinks = {
|
|
15747
15660
|
toUrl: (id) => {
|
|
15748
15661
|
const url = pageUrl();
|
|
@@ -16164,6 +16077,7 @@ const CORE_CAPABILITIES = [
|
|
|
16164
16077
|
"group"
|
|
16165
16078
|
]],
|
|
16166
16079
|
["core.manage-layers", ["layer", "editor"]],
|
|
16080
|
+
["core.rename", ["layer"]],
|
|
16167
16081
|
["core.manage-permissions", ALL_TARGETS],
|
|
16168
16082
|
["core.interact", ["element"]],
|
|
16169
16083
|
["core.bind", ["element"]],
|
|
@@ -16696,6 +16610,10 @@ var PermissionController = class {
|
|
|
16696
16610
|
capability: map[field] ?? fallback,
|
|
16697
16611
|
target
|
|
16698
16612
|
});
|
|
16613
|
+
if (kind === "layer" && field === "name") requirements.push({
|
|
16614
|
+
capability: "core.rename",
|
|
16615
|
+
target
|
|
16616
|
+
});
|
|
16699
16617
|
}
|
|
16700
16618
|
if (kind === "element" && after?.kind === "element") for (const targetId of this.#newBindingTargets(before, after)) requirements.push({
|
|
16701
16619
|
capability: "core.bind",
|
|
@@ -16782,6 +16700,7 @@ const VIEW_MODE_RESTRICTIONS = [
|
|
|
16782
16700
|
"core.group",
|
|
16783
16701
|
"core.lock",
|
|
16784
16702
|
"core.manage-layers",
|
|
16703
|
+
"core.rename",
|
|
16785
16704
|
"core.edit.assets",
|
|
16786
16705
|
"core.manage-grid",
|
|
16787
16706
|
"core.manage-canvas",
|
package/package.json
CHANGED
package/src/assets/references.ts
CHANGED
|
@@ -5,10 +5,7 @@ export class AssetReferenceIndex {
|
|
|
5
5
|
readonly #byAsset = new Map<AssetId, Set<ElementId>>();
|
|
6
6
|
readonly #byElement = new Map<ElementId, readonly AssetId[]>();
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Replaces the assets `element` references. Returns the assets nobody references anymore
|
|
10
|
-
* because of this change.
|
|
11
|
-
*/
|
|
8
|
+
/** Replaces `element`'s asset references; returns assets no longer referenced. */
|
|
12
9
|
set(element: ElementId, assets: readonly AssetId[]): AssetId[] {
|
|
13
10
|
const released: AssetId[] = [];
|
|
14
11
|
|
package/src/assets/types.ts
CHANGED
|
@@ -186,11 +186,7 @@ export interface AssetsApi {
|
|
|
186
186
|
/** Asset ids an element references through its definition's `assets` hook. */
|
|
187
187
|
assetsOf(element: ElementRecord): readonly AssetId[];
|
|
188
188
|
setLoader(loader: AssetLoader | undefined): () => void;
|
|
189
|
-
/**
|
|
190
|
-
* Where an asset's pixels can be read from on this client: its local file while pending,
|
|
191
|
-
* otherwise the resolver's result or the record's `src`. `undefined` without a source.
|
|
192
|
-
* `purpose` (default `display`) is passed to the resolver.
|
|
193
|
-
*/
|
|
189
|
+
/** Where an asset's pixels come from: local file while pending, else resolver or `src`. */
|
|
194
190
|
source(
|
|
195
191
|
id: AssetId,
|
|
196
192
|
options?: { readonly signal?: AbortSignalLike; readonly purpose?: AssetResolvePurpose },
|
package/src/assets/url.ts
CHANGED
|
@@ -26,10 +26,7 @@ export function isHostScheme(value: string): boolean {
|
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Durable asset sources: http(s), relative URLs and host schemes. Runtime-only
|
|
31
|
-
* (`blob:`, `data:`) and script URLs are rejected.
|
|
32
|
-
*/
|
|
29
|
+
/** Durable asset sources only: http(s), relative and host schemes; no `blob:`/`data:`/script. */
|
|
33
30
|
export function validateAssetSource(
|
|
34
31
|
src: unknown,
|
|
35
32
|
context: string,
|
package/src/bindings/bindings.ts
CHANGED
|
@@ -256,8 +256,6 @@ export class BindingsController {
|
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
// ---------------------------------------------------------------- index
|
|
260
|
-
|
|
261
259
|
rebuild(records: Iterable<DocumentRecord>): void {
|
|
262
260
|
this.#reverse.clear();
|
|
263
261
|
this.#forward.clear();
|
|
@@ -359,13 +357,7 @@ export class BindingsController {
|
|
|
359
357
|
}
|
|
360
358
|
}
|
|
361
359
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Derives connector updates for a local commit: unbinds ends of deleted targets and
|
|
366
|
-
* translated-alone connectors, validates new bindings and moves bound endpoints.
|
|
367
|
-
* Returns the record keys it changed.
|
|
368
|
-
*/
|
|
360
|
+
/** Connector updates for a local commit (unbind, validate, follow); returns changed keys. */
|
|
369
361
|
deriveCommit(
|
|
370
362
|
staged: StagedRecords,
|
|
371
363
|
operations: readonly ChangeOperation[],
|
|
@@ -477,10 +469,7 @@ export class BindingsController {
|
|
|
477
469
|
return keys;
|
|
478
470
|
}
|
|
479
471
|
|
|
480
|
-
/**
|
|
481
|
-
* Verifies connector operations of a checked remote change set: they must equal the
|
|
482
|
-
* recomputation from the staged state. Returns ids of connectors that do not.
|
|
483
|
-
*/
|
|
472
|
+
/** Ids of connectors in a checked remote change set that differ from the recomputation. */
|
|
484
473
|
verify(staged: StagedRecords, ids: readonly ElementId[]): ElementId[] {
|
|
485
474
|
const context = this.#stagedContext(staged);
|
|
486
475
|
return ids.filter((id) => {
|
|
@@ -554,8 +543,6 @@ export class BindingsController {
|
|
|
554
543
|
}
|
|
555
544
|
}
|
|
556
545
|
|
|
557
|
-
// ---------------------------------------------------------------- API
|
|
558
|
-
|
|
559
546
|
#requireConnector(id: ElementId): ElementRecord {
|
|
560
547
|
const element = this.#host.editor.elements.get(id);
|
|
561
548
|
|
package/src/bindings/derive.ts
CHANGED
|
@@ -131,10 +131,7 @@ export function isFixedBinding(binding: Binding): boolean {
|
|
|
131
131
|
return binding.mode !== 'element';
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
/**
|
|
135
|
-
* Resolves a binding to a world point. `reference` (world) is the point the connector comes
|
|
136
|
-
* from; only `element` mode uses it.
|
|
137
|
-
*/
|
|
134
|
+
/** Binding as a world point; `element` mode aims from `reference`, the connector's source. */
|
|
138
135
|
export function resolveBindingPoint(
|
|
139
136
|
context: BindingContext,
|
|
140
137
|
binding: Binding,
|
package/src/clipboard/format.ts
CHANGED
|
@@ -31,10 +31,7 @@ export function isClipboardText(text: string): boolean {
|
|
|
31
31
|
return trimmed.startsWith('{') && trimmed.includes(`"${CLIPBOARD_FORMAT}"`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Validates an untrusted payload (object or JSON text). Records are normalized with the
|
|
36
|
-
* same rules as documents; the payload must not exceed the element and size limits.
|
|
37
|
-
*/
|
|
34
|
+
/** Validates an untrusted payload (object or JSON) with document rules and size limits. */
|
|
38
35
|
export function parseClipboardPayload(
|
|
39
36
|
input: unknown,
|
|
40
37
|
normalize: (record: unknown) => DocumentRecord,
|
package/src/clipboard/insert.ts
CHANGED
|
@@ -101,10 +101,7 @@ function groupDepth(group: GroupRecord, byId: ReadonlyMap<string, GroupRecord>):
|
|
|
101
101
|
return depth;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Inserts foreign records into the document as one transaction: new element, group and
|
|
106
|
-
* layer ids, remapped references, reused assets, orders appended on top of each layer.
|
|
107
|
-
*/
|
|
104
|
+
/** Inserts foreign records in one transaction: new ids, remapped refs, orders on top. */
|
|
108
105
|
export function insertRecords(
|
|
109
106
|
editor: AnyEditor,
|
|
110
107
|
definitionOf: (type: string) => ElementDefinition | undefined,
|
package/src/commands/builtin.ts
CHANGED
|
@@ -147,7 +147,11 @@ function orderCommand(
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
/** Two Escapes within this window leave zen mode, like VS Code. */
|
|
151
|
+
const ZEN_EXIT_WINDOW = 500;
|
|
152
|
+
|
|
150
153
|
export function builtinCommands(): readonly CommandDefinition[] {
|
|
154
|
+
let lastCancel = Number.NEGATIVE_INFINITY;
|
|
151
155
|
return [
|
|
152
156
|
{
|
|
153
157
|
id: 'core.undo',
|
|
@@ -305,6 +309,15 @@ export function builtinCommands(): readonly CommandDefinition[] {
|
|
|
305
309
|
id: 'core.cancel',
|
|
306
310
|
label: 'Cancel',
|
|
307
311
|
run: (_args, { editor }) => {
|
|
312
|
+
const now = Date.now();
|
|
313
|
+
const twice = now - lastCancel < ZEN_EXIT_WINDOW;
|
|
314
|
+
lastCancel = twice ? Number.NEGATIVE_INFINITY : now;
|
|
315
|
+
|
|
316
|
+
if (twice && editor.modes.presentation().zen) {
|
|
317
|
+
editor.modes.setPresentation({ zen: false });
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
308
321
|
if (editor.interactions.cancel()) {
|
|
309
322
|
return;
|
|
310
323
|
}
|
package/src/editing-host.ts
CHANGED
|
@@ -3,17 +3,10 @@ import type { Platform } from './input/types.js';
|
|
|
3
3
|
import type { FrameScheduler } from './viewport/types.js';
|
|
4
4
|
import type { AnyEditor } from './editor.js';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* What a controller gets from the editor that owns it. `Editor` is the part of the editor API
|
|
8
|
-
* the controller itself calls, an {@link EditorSlice}.
|
|
9
|
-
*/
|
|
6
|
+
/** What a controller gets from its editor; `Editor` is the {@link EditorSlice} it calls. */
|
|
10
7
|
export interface EditingHost<Editor = AnyEditor, ExtensionEditor = unknown> {
|
|
11
8
|
readonly editor: Editor;
|
|
12
|
-
/**
|
|
13
|
-
* The full editor, only for handing to public extension points (tool contexts, element
|
|
14
|
-
* hooks, permission resolvers, paste hooks, link handlers, snap strategies). Modules that run
|
|
15
|
-
* extensions declare it as `AnyEditor`; for everyone else it is `unknown`.
|
|
16
|
-
*/
|
|
9
|
+
/** The full editor, only for public extension points; `unknown` unless declared `AnyEditor`. */
|
|
17
10
|
readonly extensionEditor: ExtensionEditor;
|
|
18
11
|
readonly scheduler: FrameScheduler;
|
|
19
12
|
readonly platform: Platform;
|
|
@@ -26,12 +19,7 @@ type SliceSpec = {
|
|
|
26
19
|
readonly [Namespace in keyof AnyEditor]?: true | keyof AnyEditor[Namespace];
|
|
27
20
|
};
|
|
28
21
|
|
|
29
|
-
/**
|
|
30
|
-
* A narrow view of the editor API: each namespace maps to the members a controller uses, or to
|
|
31
|
-
* `true` for the whole namespace (or a top-level method such as `transact`).
|
|
32
|
-
*
|
|
33
|
-
* @example EditorSlice<{ elements: 'get' | 'boundsFor'; transact: true }>
|
|
34
|
-
*/
|
|
22
|
+
/** Narrow editor API: each namespace maps to the members used, or `true` for all of it. */
|
|
35
23
|
export type EditorSlice<Spec extends SliceSpec> = {
|
|
36
24
|
readonly [Namespace in keyof Spec & keyof AnyEditor]: Spec[Namespace] extends true
|
|
37
25
|
? AnyEditor[Namespace]
|