@mica-js/editor 0.3.2 → 0.4.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/README.md +96 -1
- package/dist/fused-html.d.ts +849 -0
- package/dist/fused-html.js +1 -0
- package/dist/fused-runtime.d.ts +685 -0
- package/dist/fused-runtime.js +3 -0
- package/dist/fused.d.ts +537 -0
- package/dist/fused.js +6725 -0
- package/dist/fused.js.map +1 -0
- package/dist/html-HXwZq1my.js +1618 -0
- package/dist/html-HXwZq1my.js.map +1 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +174 -280
- package/dist/index.js.map +1 -1
- package/dist/runtime-CXYJzbbj.js +1739 -0
- package/dist/runtime-CXYJzbbj.js.map +1 -0
- package/dist/style.css +1486 -0
- package/dist/view-environment/content.html +36 -0
- package/dist/view-environment/content.js +666 -0
- package/dist/view-environment/environment-sw.js +632 -0
- package/dist/view-environment/environment.js +783 -0
- package/dist/view-environment/index.html +32 -0
- package/dist/wire-BDHL5Aj9.js +183 -0
- package/dist/wire-BDHL5Aj9.js.map +1 -0
- package/dist/wire-JZIiIOI0.js +260 -0
- package/dist/wire-JZIiIOI0.js.map +1 -0
- package/dist/workers-BsocIPUc.js +34 -0
- package/dist/workers-BsocIPUc.js.map +1 -0
- package/package.json +41 -5
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { a as snapToGrid, i as snapDragOffset, l as planSegmentDrag, o as connectionNodeAt, r as snapForWire, s as pinPosition, t as extendWirePath } from "./wire-JZIiIOI0.js";
|
|
1
2
|
import { DisposableStore, Emitter, toDisposable } from "@mica-js/core/lifecycle";
|
|
2
|
-
import { DEFAULT_TEXT_CONTENT, DEFAULT_TOLERANCE, GROUND_DEVICE, LABEL_DEVICE, POWER_DEVICE, SCHEMATIC_VERSION, SchematicError, TEXT_DEVICE, applySchematicCommand, builtinSymbolKind, createDesignatorFactory, createDeviceRegistry, defaultElementIdFactory, deriveSchematicTopology, designatorOf, distanceToSegment, formatDeviceReference, hasDesignator, isLabelDevice, isTextDevice, joinJunctionAt, mergeWiresAtJunction, namesNet, nearestPointOnPolyline, netNameOf, parseDeviceReference, parseSchematic, pinSide, pinStubEnd, pinsBounds, planJunctionRelease, pointOnPolyline, pointOnPolylineAt, pointsEqual,
|
|
3
|
+
import { DEFAULT_TEXT_CONTENT, DEFAULT_TOLERANCE, GROUND_DEVICE, LABEL_DEVICE, POWER_DEVICE, SCHEMATIC_VERSION, SchematicError, TEXT_DEVICE, applySchematicCommand, builtinSymbolKind, createDesignatorFactory, createDeviceRegistry, defaultElementIdFactory, deriveSchematicTopology, designatorOf, distanceToSegment, formatDeviceReference, hasDesignator, isLabelDevice, isTextDevice, joinJunctionAt, mergeWiresAtJunction, namesNet, nearestPointOnPolyline, netNameOf, parseDeviceReference, parseSchematic, pinSide, pinStubEnd, pinsBounds, planJunctionRelease, pointOnPolyline, pointOnPolylineAt, pointsEqual, propertyValueProblem, referenceAnchor, referencePosition, rerouteWireEndpoint, rotatePoint, samePoint, serializeSchematic, splitWireAt, stretchWireEndpoint, symbolBounds, symbolPinPosition, symbolRole, textDeviceContent } from "@mica-js/document/schematic";
|
|
3
4
|
import { applyCanvasCommand, assertCanvasBindings, parseCanvas, resolveDelivery, validateCanvasBindings } from "@mica-js/document/canvas";
|
|
4
5
|
import { timePs, toTimePs } from "@mica-js/core";
|
|
5
6
|
//#region src/schematic/model/inspector.ts
|
|
@@ -383,82 +384,6 @@ function connectionAnchors(devices, device) {
|
|
|
383
384
|
}
|
|
384
385
|
var ON_WIRE_EPSILON = 1e-6;
|
|
385
386
|
//#endregion
|
|
386
|
-
//#region src/schematic/editing/segment-drag.ts
|
|
387
|
-
/**
|
|
388
|
-
* Wire points produced by sliding one segment by `delta` along its normal.
|
|
389
|
-
*
|
|
390
|
-
* The whole run of segments parallel to the dragged one moves along, so no neighbour is left
|
|
391
|
-
* diagonal. Where that run ends at a pin, an anchor, a junction or another wire, the vertex stays
|
|
392
|
-
* put and the wire gains a dogleg. Pure geometry: the caller decides how to apply it.
|
|
393
|
-
*/
|
|
394
|
-
function planSegmentDrag(document, wireId, segment, delta, options = {}) {
|
|
395
|
-
const wire = document.sheet.wires.find((candidate) => candidate.id === wireId);
|
|
396
|
-
return wire === void 0 ? void 0 : planWireSegmentDrag(document, wire, segment, delta, options);
|
|
397
|
-
}
|
|
398
|
-
function planWireSegmentDrag(document, wire, segment, delta, options) {
|
|
399
|
-
const points = wire.points;
|
|
400
|
-
const start = points[segment];
|
|
401
|
-
const end = points[segment + 1];
|
|
402
|
-
if (start === void 0 || end === void 0 || delta.x === 0 && delta.y === 0) return;
|
|
403
|
-
if (start.x === end.x && start.y === end.y) return;
|
|
404
|
-
const horizontal = start.y === end.y;
|
|
405
|
-
const isParallel = (from, to) => horizontal ? from.y === to.y : from.x === to.x;
|
|
406
|
-
const connected = (point) => isConnectedVertex(document, point, wire.id, options);
|
|
407
|
-
let first = segment;
|
|
408
|
-
while (first > 0) {
|
|
409
|
-
const previous = points[first - 1];
|
|
410
|
-
const current = points[first];
|
|
411
|
-
if (previous === void 0 || current === void 0 || !isParallel(previous, current) || connected(current)) break;
|
|
412
|
-
first -= 1;
|
|
413
|
-
}
|
|
414
|
-
let last = segment + 1;
|
|
415
|
-
while (last < points.length - 1) {
|
|
416
|
-
const current = points[last];
|
|
417
|
-
const next = points[last + 1];
|
|
418
|
-
if (current === void 0 || next === void 0 || !isParallel(current, next) || connected(current)) break;
|
|
419
|
-
last += 1;
|
|
420
|
-
}
|
|
421
|
-
const firstPoint = points[first];
|
|
422
|
-
const lastPoint = points[last];
|
|
423
|
-
if (firstPoint === void 0 || lastPoint === void 0) return;
|
|
424
|
-
const shift = (point) => ({
|
|
425
|
-
x: point.x + delta.x,
|
|
426
|
-
y: point.y + delta.y
|
|
427
|
-
});
|
|
428
|
-
const moved = [];
|
|
429
|
-
for (let index = first; index <= last; index += 1) {
|
|
430
|
-
const point = points[index];
|
|
431
|
-
if (point !== void 0) moved.push(shift(point));
|
|
432
|
-
}
|
|
433
|
-
if (connected(firstPoint)) moved.unshift(firstPoint);
|
|
434
|
-
if (connected(lastPoint)) moved.push(lastPoint);
|
|
435
|
-
return [
|
|
436
|
-
...points.slice(0, first),
|
|
437
|
-
...moved,
|
|
438
|
-
...points.slice(last + 1)
|
|
439
|
-
];
|
|
440
|
-
}
|
|
441
|
-
/** True when something other than the wire itself is attached at `point`. */
|
|
442
|
-
function isConnectedVertex(document, point, wireId, options = {}) {
|
|
443
|
-
const same = (candidate) => candidate.x === point.x && candidate.y === point.y;
|
|
444
|
-
for (const junction of document.sheet.junctions) if (same(junction)) return true;
|
|
445
|
-
for (const wire of document.sheet.wires) if (wire.id !== wireId && wire.points.some(same)) return true;
|
|
446
|
-
for (const symbol of document.sheet.symbols) {
|
|
447
|
-
if (symbolRole(symbol.device) !== "component") {
|
|
448
|
-
if (same({
|
|
449
|
-
x: symbol.x,
|
|
450
|
-
y: symbol.y
|
|
451
|
-
})) return true;
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
const reference = parseDeviceReference(symbol.device);
|
|
455
|
-
const definition = reference === void 0 ? void 0 : options.devices?.getDeviceSymbol(reference);
|
|
456
|
-
if (definition === void 0) continue;
|
|
457
|
-
for (const anchor of Object.values(definition.pins)) if (same(symbolPinPosition(symbol, anchor))) return true;
|
|
458
|
-
}
|
|
459
|
-
return false;
|
|
460
|
-
}
|
|
461
|
-
//#endregion
|
|
462
387
|
//#region src/schematic/model/wires.ts
|
|
463
388
|
/**
|
|
464
389
|
* Appends a wire. Endpoints that land inside another wire split it and create a junction, and
|
|
@@ -2743,184 +2668,6 @@ async function readItemText(item) {
|
|
|
2743
2668
|
}
|
|
2744
2669
|
}
|
|
2745
2670
|
//#endregion
|
|
2746
|
-
//#region src/schematic/editor/snapping/nodes.ts
|
|
2747
|
-
/** World position of a pin / label / power / ground anchor under `point`. */
|
|
2748
|
-
function connectionNodeAt(context, point) {
|
|
2749
|
-
const hit = context.hitTest(point, {
|
|
2750
|
-
tolerance: context.tolerance * 2,
|
|
2751
|
-
includeSymbols: false
|
|
2752
|
-
});
|
|
2753
|
-
if (hit?.kind === "pin") return pinPosition(context, hit);
|
|
2754
|
-
const anchor = anchorSymbolAt(context, point);
|
|
2755
|
-
if (anchor !== void 0) return {
|
|
2756
|
-
x: anchor.x,
|
|
2757
|
-
y: anchor.y
|
|
2758
|
-
};
|
|
2759
|
-
return wireEndpointAt(context, point);
|
|
2760
|
-
}
|
|
2761
|
-
/** Endpoint of an existing wire under `point`; used to close a connection. */
|
|
2762
|
-
function wireEndpointAt(context, point) {
|
|
2763
|
-
for (const wire of context.document.sheet.wires) for (const endpoint of [wire.points[0], wire.points[wire.points.length - 1]]) if (endpoint !== void 0 && Math.abs(endpoint.x - point.x) <= context.tolerance * 2 && Math.abs(endpoint.y - point.y) <= context.tolerance * 2) return {
|
|
2764
|
-
x: endpoint.x,
|
|
2765
|
-
y: endpoint.y
|
|
2766
|
-
};
|
|
2767
|
-
}
|
|
2768
|
-
/** Builtin connection symbol (label / power / ground) anchored under `point`. */
|
|
2769
|
-
function anchorSymbolAt(context, point) {
|
|
2770
|
-
for (const symbol of context.document.sheet.symbols) {
|
|
2771
|
-
const device = symbol.device;
|
|
2772
|
-
if (device !== LABEL_DEVICE && device !== POWER_DEVICE && device !== GROUND_DEVICE) continue;
|
|
2773
|
-
if (Math.abs(symbol.x - point.x) <= context.tolerance && Math.abs(symbol.y - point.y) <= context.tolerance) return symbol;
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
function pinPosition(context, hit) {
|
|
2777
|
-
const symbol = context.document.sheet.symbols.find((item) => item.id === hit.symbolId);
|
|
2778
|
-
if (symbol === void 0) return;
|
|
2779
|
-
const reference = parseDeviceReference(symbol.device);
|
|
2780
|
-
const anchor = reference === void 0 ? void 0 : context.devices?.getDeviceSymbol(reference)?.pins[hit.pinId];
|
|
2781
|
-
return anchor === void 0 ? void 0 : symbolPinPosition(symbol, anchor);
|
|
2782
|
-
}
|
|
2783
|
-
//#endregion
|
|
2784
|
-
//#region src/schematic/editor/snapping/drag.ts
|
|
2785
|
-
function snapToGrid(point, display) {
|
|
2786
|
-
if (!display.snap || !(display.gridSize > 0)) return point;
|
|
2787
|
-
const size = display.gridSize;
|
|
2788
|
-
return {
|
|
2789
|
-
x: Math.round(point.x / size) * size,
|
|
2790
|
-
y: Math.round(point.y / size) * size
|
|
2791
|
-
};
|
|
2792
|
-
}
|
|
2793
|
-
/**
|
|
2794
|
-
* Offset for dragging something anchored at `anchor` from `from` to `to`: the result is snapped,
|
|
2795
|
-
* not the raw pointer delta, so an off-grid symbol lands on the grid.
|
|
2796
|
-
*
|
|
2797
|
-
* Dragging uses the fine grid spacing (`gridSize / gridSubdivisions`).
|
|
2798
|
-
* A drag that stays within half a fine grid cell on one axis does not move that axis at all, so an
|
|
2799
|
-
* anchor that started off-grid keeps its column/row instead of jittering sideways.
|
|
2800
|
-
*/
|
|
2801
|
-
function snapDragOffset(anchor, from, to, display) {
|
|
2802
|
-
const dx = to.x - from.x;
|
|
2803
|
-
const dy = to.y - from.y;
|
|
2804
|
-
if (!display.snap || !(display.gridSize > 0)) return {
|
|
2805
|
-
x: dx,
|
|
2806
|
-
y: dy
|
|
2807
|
-
};
|
|
2808
|
-
const subdivisions = Number.isFinite(display.gridSubdivisions) && display.gridSubdivisions >= 1 ? Math.round(display.gridSubdivisions) : 1;
|
|
2809
|
-
const size = display.gridSize / subdivisions;
|
|
2810
|
-
const target = snapToGrid({
|
|
2811
|
-
x: anchor.x + dx,
|
|
2812
|
-
y: anchor.y + dy
|
|
2813
|
-
}, {
|
|
2814
|
-
...display,
|
|
2815
|
-
gridSize: size
|
|
2816
|
-
});
|
|
2817
|
-
const lock = size / 2;
|
|
2818
|
-
return {
|
|
2819
|
-
x: (Math.abs(dx) < lock ? anchor.x : target.x) - anchor.x,
|
|
2820
|
-
y: (Math.abs(dy) < lock ? anchor.y : target.y) - anchor.y
|
|
2821
|
-
};
|
|
2822
|
-
}
|
|
2823
|
-
//#endregion
|
|
2824
|
-
//#region src/schematic/editor/snapping/wire.ts
|
|
2825
|
-
/**
|
|
2826
|
-
* Waypoints needed to reach `to` from `from` with horizontal/vertical segments only.
|
|
2827
|
-
* Returns `[to]` when already aligned, otherwise an elbow plus `to` (long axis first).
|
|
2828
|
-
*/
|
|
2829
|
-
function orthogonalWaypoints(from, to) {
|
|
2830
|
-
if (from.x === to.x || from.y === to.y) return [to];
|
|
2831
|
-
return [Math.abs(to.x - from.x) >= Math.abs(to.y - from.y) ? {
|
|
2832
|
-
x: to.x,
|
|
2833
|
-
y: from.y
|
|
2834
|
-
} : {
|
|
2835
|
-
x: from.x,
|
|
2836
|
-
y: to.y
|
|
2837
|
-
}, to];
|
|
2838
|
-
}
|
|
2839
|
-
/**
|
|
2840
|
-
* Waypoints for one new wire leg. When the target lands on an existing wire the last leg runs
|
|
2841
|
-
* perpendicular to it, so the branch taps into a T instead of doubling back along the host.
|
|
2842
|
-
*/
|
|
2843
|
-
function wireWaypoints(from, to, host) {
|
|
2844
|
-
if (host === void 0 || from.x === to.x || from.y === to.y) return orthogonalWaypoints(from, to);
|
|
2845
|
-
return host === "vertical" ? [{
|
|
2846
|
-
x: from.x,
|
|
2847
|
-
y: to.y
|
|
2848
|
-
}, to] : [{
|
|
2849
|
-
x: to.x,
|
|
2850
|
-
y: from.y
|
|
2851
|
-
}, to];
|
|
2852
|
-
}
|
|
2853
|
-
/** Extends a routed path, folding retraced collinear legs instead of leaving dangling branches. */
|
|
2854
|
-
function extendWirePath(points, to, host) {
|
|
2855
|
-
const from = points[points.length - 1];
|
|
2856
|
-
const candidates = from === void 0 ? [to] : [...points, ...wireWaypoints(from, to, host)];
|
|
2857
|
-
const path = [];
|
|
2858
|
-
for (const point of candidates) {
|
|
2859
|
-
while (path.length >= 2) {
|
|
2860
|
-
const a = path[path.length - 2];
|
|
2861
|
-
const b = path[path.length - 1];
|
|
2862
|
-
if (a.x === b.x && b.x === point.x || a.y === b.y && b.y === point.y) path.pop();
|
|
2863
|
-
else break;
|
|
2864
|
-
}
|
|
2865
|
-
const previous = path[path.length - 1];
|
|
2866
|
-
if (previous === void 0 || previous.x !== point.x || previous.y !== point.y) path.push(point);
|
|
2867
|
-
}
|
|
2868
|
-
return path;
|
|
2869
|
-
}
|
|
2870
|
-
/** Snaps to a nearby connection node, then to a nearby wire, otherwise to the grid. */
|
|
2871
|
-
function snapForWire(context, point) {
|
|
2872
|
-
return connectionNodeAt(context, point) ?? wireBodyPointAt(context, point) ?? snapToGrid(point, context.display);
|
|
2873
|
-
}
|
|
2874
|
-
/**
|
|
2875
|
-
* Closest point on an existing wire's run when `point` is within the snap radius. Lets the wire
|
|
2876
|
-
* tool land exactly on another wire, which is what turns the run into a T junction. Only the
|
|
2877
|
-
* offset beside the host is absorbed: the position along it still follows the grid.
|
|
2878
|
-
*/
|
|
2879
|
-
function wireBodyPointAt(context, point) {
|
|
2880
|
-
const radius = context.tolerance * 2;
|
|
2881
|
-
const display = context.display;
|
|
2882
|
-
let best;
|
|
2883
|
-
for (const wire of context.document.sheet.wires) for (let index = 1; index < wire.points.length; index += 1) {
|
|
2884
|
-
const a = wire.points[index - 1];
|
|
2885
|
-
const b = wire.points[index];
|
|
2886
|
-
if (a === void 0 || b === void 0) continue;
|
|
2887
|
-
const projected = projectOnSegment(point, a, b);
|
|
2888
|
-
const distance = Math.hypot(projected.x - point.x, projected.y - point.y);
|
|
2889
|
-
if (distance > radius || best !== void 0 && distance >= best.distance) continue;
|
|
2890
|
-
best = {
|
|
2891
|
-
point: gridAlongHost(projected, a, b, display),
|
|
2892
|
-
distance
|
|
2893
|
-
};
|
|
2894
|
-
}
|
|
2895
|
-
return best?.point;
|
|
2896
|
-
}
|
|
2897
|
-
function gridAlongHost(projected, a, b, display) {
|
|
2898
|
-
if (a.y === b.y && a.x !== b.x) {
|
|
2899
|
-
const x = snapToGrid(projected, display).x;
|
|
2900
|
-
return x >= Math.min(a.x, b.x) && x <= Math.max(a.x, b.x) ? {
|
|
2901
|
-
x,
|
|
2902
|
-
y: a.y
|
|
2903
|
-
} : {
|
|
2904
|
-
x: projected.x,
|
|
2905
|
-
y: a.y
|
|
2906
|
-
};
|
|
2907
|
-
}
|
|
2908
|
-
if (a.x === b.x && a.y !== b.y) {
|
|
2909
|
-
const y = snapToGrid(projected, display).y;
|
|
2910
|
-
return y >= Math.min(a.y, b.y) && y <= Math.max(a.y, b.y) ? {
|
|
2911
|
-
x: a.x,
|
|
2912
|
-
y
|
|
2913
|
-
} : {
|
|
2914
|
-
x: a.x,
|
|
2915
|
-
y: projected.y
|
|
2916
|
-
};
|
|
2917
|
-
}
|
|
2918
|
-
return {
|
|
2919
|
-
x: projected.x,
|
|
2920
|
-
y: projected.y
|
|
2921
|
-
};
|
|
2922
|
-
}
|
|
2923
|
-
//#endregion
|
|
2924
2671
|
//#region src/schematic/editor/snapping/label.ts
|
|
2925
2672
|
function isPlacementTool(tool) {
|
|
2926
2673
|
return tool === "power" || tool === "ground" || tool === "label" || tool === "text";
|
|
@@ -5639,6 +5386,10 @@ var CanvasSession = class CanvasSession {
|
|
|
5639
5386
|
#running = false;
|
|
5640
5387
|
#timer;
|
|
5641
5388
|
#nextFrame;
|
|
5389
|
+
#advancing = false;
|
|
5390
|
+
#advanceSequence = 0;
|
|
5391
|
+
#lastStartedAt;
|
|
5392
|
+
#lastCompletedAt;
|
|
5642
5393
|
#disposed = false;
|
|
5643
5394
|
#queue = Promise.resolve();
|
|
5644
5395
|
#disposal;
|
|
@@ -5743,13 +5494,13 @@ var CanvasSession = class CanvasSession {
|
|
|
5743
5494
|
this.#changes.fire();
|
|
5744
5495
|
}
|
|
5745
5496
|
step() {
|
|
5746
|
-
return this.#enqueue(() => this.#advance(this.#step));
|
|
5497
|
+
return this.#enqueue(() => this.#advance(this.#step, "step"));
|
|
5747
5498
|
}
|
|
5748
5499
|
dispatch(id, event) {
|
|
5749
5500
|
return this.#enqueue(async () => {
|
|
5750
5501
|
if (this.#mode !== "simulation") return;
|
|
5751
5502
|
await this.#active?.runtimes.widgets.dispatch(id, event);
|
|
5752
|
-
if (!this.#running) await this.#advance(timePs(0));
|
|
5503
|
+
if (!this.#running) await this.#advance(timePs(0), "dispatch");
|
|
5753
5504
|
});
|
|
5754
5505
|
}
|
|
5755
5506
|
dispose() {
|
|
@@ -5797,6 +5548,7 @@ var CanvasSession = class CanvasSession {
|
|
|
5797
5548
|
this.#assertAlive();
|
|
5798
5549
|
await runtimes.simulation.load({
|
|
5799
5550
|
schematic: resources.schematic,
|
|
5551
|
+
...this.configuration.execution === void 0 ? {} : { execution: this.configuration.execution },
|
|
5800
5552
|
...this.configuration.voltageReferences === void 0 ? {} : { voltageReferences: this.configuration.voltageReferences },
|
|
5801
5553
|
devices: resources.devices,
|
|
5802
5554
|
assets: structuredClone(resources.simulationAssets)
|
|
@@ -5833,35 +5585,104 @@ var CanvasSession = class CanvasSession {
|
|
|
5833
5585
|
if (previous) await this.#release(previous).catch((error) => this.#errors.fire(error));
|
|
5834
5586
|
this.#schedule();
|
|
5835
5587
|
}
|
|
5836
|
-
async #advance(dt) {
|
|
5588
|
+
async #advance(dt, trigger, frame) {
|
|
5837
5589
|
const active = this.#active;
|
|
5838
5590
|
if (!active) return;
|
|
5839
|
-
|
|
5840
|
-
|
|
5591
|
+
this.#notifyAdvance("onAdvanceStart");
|
|
5592
|
+
try {
|
|
5593
|
+
const observer = this.configuration.observer;
|
|
5594
|
+
const running = this.#running;
|
|
5595
|
+
const startedAt = observer === void 0 ? 0 : performance.now();
|
|
5596
|
+
const skippedSlots = frame === void 0 || observer === void 0 ? 0 : Math.max(0, Math.floor((startedAt - frame.target) / this.#frameMs));
|
|
5597
|
+
let tickStartedAt;
|
|
5598
|
+
let tickCompletedAt = startedAt;
|
|
5599
|
+
if (this.#mode === "simulation" && dt > 0) {
|
|
5600
|
+
if (observer !== void 0) tickStartedAt = performance.now();
|
|
5601
|
+
const report = await active.runtimes.simulation.tick(dt);
|
|
5602
|
+
if (observer !== void 0) tickCompletedAt = performance.now();
|
|
5603
|
+
this.#assertAlive();
|
|
5604
|
+
this.#simTime = report.simTime;
|
|
5605
|
+
}
|
|
5606
|
+
const widgetStartedAt = observer === void 0 ? 0 : performance.now();
|
|
5607
|
+
await active.runtimes.widgets.step({
|
|
5608
|
+
simTime: this.#simTime,
|
|
5609
|
+
dt,
|
|
5610
|
+
mode: this.#mode
|
|
5611
|
+
});
|
|
5612
|
+
const completedAt = observer === void 0 ? 0 : performance.now();
|
|
5841
5613
|
this.#assertAlive();
|
|
5842
|
-
this.#
|
|
5614
|
+
if (observer !== void 0 && !this.#disposed) this.#observe(observer, {
|
|
5615
|
+
trigger,
|
|
5616
|
+
startedAt,
|
|
5617
|
+
tickStartedAt,
|
|
5618
|
+
tickCompletedAt,
|
|
5619
|
+
widgetStartedAt,
|
|
5620
|
+
completedAt,
|
|
5621
|
+
skippedSlots,
|
|
5622
|
+
dt,
|
|
5623
|
+
running
|
|
5624
|
+
});
|
|
5625
|
+
} finally {
|
|
5626
|
+
this.#notifyAdvance("onAdvanceSettled");
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
#notifyAdvance(hook) {
|
|
5630
|
+
try {
|
|
5631
|
+
this.configuration[hook]?.();
|
|
5632
|
+
} catch (error) {
|
|
5633
|
+
if (!this.#disposed) this.#errors.fire(error);
|
|
5634
|
+
}
|
|
5635
|
+
}
|
|
5636
|
+
#observe(observer, details) {
|
|
5637
|
+
const idleMs = this.#lastCompletedAt === void 0 ? void 0 : details.startedAt - this.#lastCompletedAt;
|
|
5638
|
+
const periodMs = this.#lastStartedAt === void 0 ? void 0 : details.startedAt - this.#lastStartedAt;
|
|
5639
|
+
this.#lastStartedAt = details.startedAt;
|
|
5640
|
+
this.#lastCompletedAt = details.completedAt;
|
|
5641
|
+
this.#advanceSequence += 1;
|
|
5642
|
+
try {
|
|
5643
|
+
observer({
|
|
5644
|
+
sequence: this.#advanceSequence,
|
|
5645
|
+
trigger: details.trigger,
|
|
5646
|
+
startedAt: details.startedAt,
|
|
5647
|
+
tickCompletedAt: details.tickCompletedAt,
|
|
5648
|
+
completedAt: details.completedAt,
|
|
5649
|
+
tickMs: details.tickStartedAt === void 0 ? void 0 : details.tickCompletedAt - details.tickStartedAt,
|
|
5650
|
+
widgetMs: details.completedAt - details.widgetStartedAt,
|
|
5651
|
+
idleMs,
|
|
5652
|
+
periodMs,
|
|
5653
|
+
skippedSlots: details.skippedSlots,
|
|
5654
|
+
simTime: this.#simTime,
|
|
5655
|
+
dt: details.dt,
|
|
5656
|
+
running: details.running,
|
|
5657
|
+
mode: this.#mode,
|
|
5658
|
+
frameMs: this.#frameMs
|
|
5659
|
+
});
|
|
5660
|
+
} catch (error) {
|
|
5661
|
+
if (!this.#disposed) this.#errors.fire(error);
|
|
5843
5662
|
}
|
|
5844
|
-
await active.runtimes.widgets.step({
|
|
5845
|
-
simTime: this.#simTime,
|
|
5846
|
-
dt,
|
|
5847
|
-
mode: this.#mode
|
|
5848
|
-
});
|
|
5849
|
-
this.#assertAlive();
|
|
5850
5663
|
}
|
|
5851
5664
|
#schedule() {
|
|
5852
|
-
if (this.#disposed || !this.#active || this.#timer !== void 0) return;
|
|
5665
|
+
if (this.#disposed || !this.#active || this.#timer !== void 0 || this.#advancing) return;
|
|
5853
5666
|
const now = performance.now();
|
|
5854
5667
|
this.#nextFrame ??= now + this.#frameMs;
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5668
|
+
this.#timer = setTimeout(() => this.#onFrame(), Math.max(0, this.#nextFrame - now));
|
|
5669
|
+
}
|
|
5670
|
+
#onFrame() {
|
|
5671
|
+
this.#timer = void 0;
|
|
5672
|
+
if (this.#disposed || !this.#active) return;
|
|
5673
|
+
const wakeAt = performance.now();
|
|
5674
|
+
const target = this.#nextFrame ?? wakeAt;
|
|
5675
|
+
this.#nextFrame = wakeAt + this.#frameMs;
|
|
5676
|
+
this.#advancing = true;
|
|
5677
|
+
this.#enqueue(() => this.#advance(this.#running ? this.#step : timePs(0), "frame", { target })).then(() => {
|
|
5678
|
+
this.#advancing = false;
|
|
5679
|
+
this.#schedule();
|
|
5680
|
+
}, (error) => {
|
|
5681
|
+
this.#advancing = false;
|
|
5682
|
+
this.#nextFrame = void 0;
|
|
5683
|
+
this.pause();
|
|
5684
|
+
if (!this.#disposed) this.#errors.fire(error);
|
|
5685
|
+
});
|
|
5865
5686
|
}
|
|
5866
5687
|
async #release(active) {
|
|
5867
5688
|
for (const subscription of active.subscriptions) subscription.dispose();
|
|
@@ -6384,6 +6205,7 @@ var CanvasView = class {
|
|
|
6384
6205
|
#gesture;
|
|
6385
6206
|
#preview;
|
|
6386
6207
|
#pointerId;
|
|
6208
|
+
#renderSequence = 0;
|
|
6387
6209
|
#disposed = false;
|
|
6388
6210
|
#hostPress;
|
|
6389
6211
|
#suppressDoubleClick = false;
|
|
@@ -6505,10 +6327,31 @@ var CanvasView = class {
|
|
|
6505
6327
|
}
|
|
6506
6328
|
render() {
|
|
6507
6329
|
if (this.#disposed) return;
|
|
6330
|
+
const observer = this.#options.onRender;
|
|
6331
|
+
const startedAt = observer === void 0 ? 0 : performance.now();
|
|
6508
6332
|
try {
|
|
6509
6333
|
this.#render();
|
|
6510
6334
|
} catch (error) {
|
|
6511
6335
|
this.#report(error);
|
|
6336
|
+
} finally {
|
|
6337
|
+
if (observer !== void 0) {
|
|
6338
|
+
const completedAt = performance.now();
|
|
6339
|
+
try {
|
|
6340
|
+
observer({
|
|
6341
|
+
sequence: ++this.#renderSequence,
|
|
6342
|
+
startedAt,
|
|
6343
|
+
completedAt,
|
|
6344
|
+
durationMs: completedAt - startedAt,
|
|
6345
|
+
mode: this.#isSimulation() ? "simulation" : "edit",
|
|
6346
|
+
widgets: this.#options.model.document.widgets.length,
|
|
6347
|
+
width: this.#width,
|
|
6348
|
+
height: this.#height,
|
|
6349
|
+
dpr: this.#dpr
|
|
6350
|
+
});
|
|
6351
|
+
} catch (error) {
|
|
6352
|
+
this.#report(error);
|
|
6353
|
+
}
|
|
6354
|
+
}
|
|
6512
6355
|
}
|
|
6513
6356
|
}
|
|
6514
6357
|
#render() {
|
|
@@ -7092,9 +6935,55 @@ function createCanvasView(options) {
|
|
|
7092
6935
|
}
|
|
7093
6936
|
//#endregion
|
|
7094
6937
|
//#region src/canvas-editor.ts
|
|
6938
|
+
/** Wraps the existing runtime factory so measurement taps the same events it already exposes. */
|
|
6939
|
+
function measurementRuntimeFactory(measurement, reportError) {
|
|
6940
|
+
const base = new CanvasRuntimeFactory();
|
|
6941
|
+
return { async create(container) {
|
|
6942
|
+
const runtimes = await base.create(container);
|
|
6943
|
+
const subscriptions = new DisposableStore();
|
|
6944
|
+
const tap = (run) => {
|
|
6945
|
+
try {
|
|
6946
|
+
run();
|
|
6947
|
+
} catch (error) {
|
|
6948
|
+
reportError("runtime", error);
|
|
6949
|
+
}
|
|
6950
|
+
};
|
|
6951
|
+
const widgetFrame = measurement.widgetFrame;
|
|
6952
|
+
if (widgetFrame !== void 0) subscriptions.add(runtimes.widgets.onDidRender((frame) => {
|
|
6953
|
+
tap(() => widgetFrame({
|
|
6954
|
+
at: performance.now(),
|
|
6955
|
+
instanceId: frame.instanceId,
|
|
6956
|
+
sequence: frame.sequence,
|
|
6957
|
+
width: frame.width,
|
|
6958
|
+
height: frame.height,
|
|
6959
|
+
dpr: frame.dpr
|
|
6960
|
+
}));
|
|
6961
|
+
}));
|
|
6962
|
+
const topic = measurement.topic;
|
|
6963
|
+
if (topic !== void 0) subscriptions.add(runtimes.simulation.onDidPublish((message) => {
|
|
6964
|
+
tap(() => topic({
|
|
6965
|
+
at: performance.now(),
|
|
6966
|
+
symbol: message.target.symbol,
|
|
6967
|
+
port: message.target.port,
|
|
6968
|
+
simTime: message.simTime,
|
|
6969
|
+
payload: message.payload
|
|
6970
|
+
}));
|
|
6971
|
+
}));
|
|
6972
|
+
return {
|
|
6973
|
+
simulation: runtimes.simulation,
|
|
6974
|
+
widgets: runtimes.widgets,
|
|
6975
|
+
resumeAudio: () => runtimes.resumeAudio(),
|
|
6976
|
+
async dispose() {
|
|
6977
|
+
subscriptions.dispose();
|
|
6978
|
+
await runtimes.dispose();
|
|
6979
|
+
}
|
|
6980
|
+
};
|
|
6981
|
+
} };
|
|
6982
|
+
}
|
|
7095
6983
|
async function createCanvasEditor(options) {
|
|
7096
6984
|
const references = options.voltageReferences;
|
|
7097
6985
|
if (references !== void 0 && (references === null || typeof references !== "object" || Object.getPrototypeOf(references) !== Object.prototype && Object.getPrototypeOf(references) !== null || Reflect.ownKeys(references).some((name) => typeof name !== "string" || name.trim().length === 0 || typeof references[name] !== "number" || !Number.isFinite(references[name])))) throw new Error("Expected a plain voltageReferences map with nonempty net names and finite numeric voltages");
|
|
6986
|
+
const measurement = options.measurement;
|
|
7098
6987
|
const uri = new URL(options.uri).href;
|
|
7099
6988
|
const projectRoot = options.projectRoot === void 0 ? new URL(".", uri).href : new URL(options.projectRoot).href;
|
|
7100
6989
|
const root = projectRoot.endsWith("/") ? projectRoot : `${projectRoot}/`;
|
|
@@ -7136,12 +7025,16 @@ async function createCanvasEditor(options) {
|
|
|
7136
7025
|
...options.projectRoot === void 0 ? {} : { projectRoot: root },
|
|
7137
7026
|
container: options.container,
|
|
7138
7027
|
...options.stepMs === void 0 ? {} : { stepMs: options.stepMs },
|
|
7139
|
-
...options.
|
|
7028
|
+
...options.execution === void 0 ? {} : { execution: options.execution },
|
|
7029
|
+
...options.voltageReferences === void 0 ? {} : { voltageReferences: Object.freeze(structuredClone(options.voltageReferences)) },
|
|
7030
|
+
...measurement?.advance === void 0 ? {} : { observer: measurement.advance },
|
|
7031
|
+
...measurement?.advanceStart === void 0 ? {} : { onAdvanceStart: measurement.advanceStart },
|
|
7032
|
+
...measurement?.advanceSettled === void 0 ? {} : { onAdvanceSettled: measurement.advanceSettled }
|
|
7140
7033
|
});
|
|
7141
7034
|
services.set(ICommandService, new SyncDescriptor(Commands));
|
|
7142
7035
|
services.set(IDeviceLibraryResolver, new SyncDescriptor(DeviceLibraryResolver));
|
|
7143
7036
|
services.set(IWidgetLibraryResolver, new SyncDescriptor(WidgetLibraryResolver));
|
|
7144
|
-
services.set(ICanvasRuntimeFactory, new SyncDescriptor(CanvasRuntimeFactory));
|
|
7037
|
+
services.set(ICanvasRuntimeFactory, measurement?.widgetFrame === void 0 && measurement?.topic === void 0 ? new SyncDescriptor(CanvasRuntimeFactory) : measurementRuntimeFactory(measurement, reportError));
|
|
7145
7038
|
services.set(ICanvasSession, new SyncDescriptor(CanvasSession));
|
|
7146
7039
|
services.set(ICanvasDocumentService, new SyncDescriptor(CanvasDocumentService));
|
|
7147
7040
|
const scope = new InstantiationService(services);
|
|
@@ -7160,6 +7053,7 @@ async function createCanvasEditor(options) {
|
|
|
7160
7053
|
isSimulation: () => session.mode === "simulation",
|
|
7161
7054
|
onDispatch: (id, event) => session.dispatch(id, event),
|
|
7162
7055
|
onError: (error, source = "render") => reportError(source, error),
|
|
7056
|
+
...measurement?.render === void 0 ? {} : { onRender: measurement.render },
|
|
7163
7057
|
onSelectionChange: (value) => selection.fire(editorSnapshot(value)),
|
|
7164
7058
|
onClick: (event) => clicks.fire(editorSnapshot(event)),
|
|
7165
7059
|
onDoubleClick: (event) => doubleClicks.fire(editorSnapshot(event)),
|