@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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<!--
|
|
7
|
+
Device HTML view environment (RFC 0023). Deploy this file, content.html, environment.js,
|
|
8
|
+
environment-sw.js and content.js together in the directory behind viewBaseUrlTemplate. This
|
|
9
|
+
trusted document keeps its own page for the life of the view and creates the inner sandbox
|
|
10
|
+
frame from the real content.html document of the same directory, then writes the author
|
|
11
|
+
document into that frame; it never rewrites itself, so an author navigation is a fault. The
|
|
12
|
+
inline policy mirrors HTML_VIEW_ENVIRONMENT_POLICY in paths.ts: it allows the one inner frame
|
|
13
|
+
of this deployment directory plus the asset worker. content.html repeats
|
|
14
|
+
HTML_VIEW_CONTENT_POLICY and still refuses every further frame.
|
|
15
|
+
-->
|
|
16
|
+
<meta
|
|
17
|
+
http-equiv="Content-Security-Policy"
|
|
18
|
+
content="default-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data: blob:; media-src 'self' data: blob:; connect-src 'self' blob:; worker-src 'self'; frame-src 'self'; object-src 'none'; form-action 'none'; base-uri 'self'"
|
|
19
|
+
/>
|
|
20
|
+
<title>Mica device view</title>
|
|
21
|
+
<style>
|
|
22
|
+
html,
|
|
23
|
+
body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
height: 100%;
|
|
26
|
+
background: transparent;
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
29
|
+
<script type="module" src="./environment.js"></script>
|
|
30
|
+
</head>
|
|
31
|
+
<body></body>
|
|
32
|
+
</html>
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
//#region src/fused/runtime/wire.ts
|
|
2
|
+
/** `name` of a failure whose message carries a {@link IFusedFailurePayload}. */
|
|
3
|
+
var FUSED_WIRE_FAILURE = "FusedSandboxFailure";
|
|
4
|
+
/**
|
|
5
|
+
* Host-side failure of the fused sandbox bridge.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors `FusedRuntimeError` (`code`, optional `instanceId`) and keeps the business payload of a
|
|
8
|
+
* model `MethodError` rejection. Guest code uses the same class to build the failure it throws.
|
|
9
|
+
*/
|
|
10
|
+
var FusedBridgeError = class extends Error {
|
|
11
|
+
code;
|
|
12
|
+
instanceId;
|
|
13
|
+
details;
|
|
14
|
+
constructor(code, message, options = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = options.name ?? "FusedBridgeError";
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.instanceId = options.instanceId;
|
|
19
|
+
this.details = options.details;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function isFusedBridgeError(value) {
|
|
23
|
+
return value instanceof FusedBridgeError;
|
|
24
|
+
}
|
|
25
|
+
/** Encodes one failure as an `Error` the RPC layer can carry. */
|
|
26
|
+
function toWireFailure(cause) {
|
|
27
|
+
const payload = failurePayload(cause);
|
|
28
|
+
return Object.assign(new Error(JSON.stringify(payload)), { name: FUSED_WIRE_FAILURE });
|
|
29
|
+
}
|
|
30
|
+
/** Rebuilds the failure of a rejected guest call; other errors pass through. */
|
|
31
|
+
function fromWireFailure(cause) {
|
|
32
|
+
if (!(cause instanceof Error) || cause.name !== "FusedSandboxFailure") return cause instanceof Error ? cause : new Error(String(cause));
|
|
33
|
+
const payload = decodePayload(cause.message);
|
|
34
|
+
if (payload === void 0) return cause;
|
|
35
|
+
return new FusedBridgeError(payload.code, payload.message, {
|
|
36
|
+
...payload.kind === "method" ? { name: "MethodError" } : {},
|
|
37
|
+
...payload.instanceId === void 0 ? {} : { instanceId: payload.instanceId },
|
|
38
|
+
...payload.details === void 0 ? {} : { details: payload.details }
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Runs one guest call and rebuilds a wire failure of its rejection. */
|
|
42
|
+
async function mapWireFailure(run) {
|
|
43
|
+
try {
|
|
44
|
+
return await run();
|
|
45
|
+
} catch (cause) {
|
|
46
|
+
throw fromWireFailure(cause);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Whether a value is a decodable overlay bitmap of this realm. */
|
|
50
|
+
function isImageBitmap(value) {
|
|
51
|
+
return typeof ImageBitmap !== "undefined" && value instanceof ImageBitmap;
|
|
52
|
+
}
|
|
53
|
+
/** Transfer list of one `prepare` result: every byte snapshot of the presentation props. */
|
|
54
|
+
function transferPresentationBytes(member, value) {
|
|
55
|
+
if (member !== "prepare") return [];
|
|
56
|
+
const instances = value?.instances ?? [];
|
|
57
|
+
const buffers = /* @__PURE__ */ new Set();
|
|
58
|
+
for (const instance of instances) for (const prop of Object.values(instance.props)) collectPropBytes(prop, buffers);
|
|
59
|
+
return [...buffers];
|
|
60
|
+
}
|
|
61
|
+
function collectPropBytes(value, buffers) {
|
|
62
|
+
if (value instanceof Uint8Array) {
|
|
63
|
+
if (value.buffer instanceof ArrayBuffer) buffers.add(value.buffer);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const snapshot = value;
|
|
67
|
+
if (snapshot === null || typeof snapshot !== "object") return;
|
|
68
|
+
if (snapshot.kind === "filesystem") {
|
|
69
|
+
for (const file of snapshot.files) collectPropBytes(file.data, buffers);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (snapshot.kind !== "firmware") return;
|
|
73
|
+
for (const segment of snapshot.segments) if (segment.bytes instanceof Uint8Array && segment.bytes.buffer instanceof ArrayBuffer) buffers.add(segment.bytes.buffer);
|
|
74
|
+
}
|
|
75
|
+
/** Transfer list of one `render` result. */
|
|
76
|
+
function transferOverlayFrame(member, value) {
|
|
77
|
+
if (member !== "render") return [];
|
|
78
|
+
const frame = value;
|
|
79
|
+
if (frame === void 0 || frame === null) return [];
|
|
80
|
+
return isImageBitmap(frame.bitmap) ? [frame.bitmap] : [];
|
|
81
|
+
}
|
|
82
|
+
/** Transfer list of one `Uint8Array` result. */
|
|
83
|
+
function transferBytes(value) {
|
|
84
|
+
if (!(value instanceof Uint8Array)) return [];
|
|
85
|
+
if (!(value.buffer instanceof ArrayBuffer)) return [];
|
|
86
|
+
if (value.byteOffset !== 0 || value.byteLength !== value.buffer.byteLength) return [];
|
|
87
|
+
return [value.buffer];
|
|
88
|
+
}
|
|
89
|
+
/** Transfer list of one host package `read` result. */
|
|
90
|
+
function transferPackageBytes(member, value) {
|
|
91
|
+
return member === "read" ? transferBytes(value) : [];
|
|
92
|
+
}
|
|
93
|
+
/** Transfer list of one host `readResource` result. */
|
|
94
|
+
function transferResourceBytes(member, value) {
|
|
95
|
+
return member === "readResource" ? transferBytes(value) : [];
|
|
96
|
+
}
|
|
97
|
+
function transferProgramArtifact(member, value) {
|
|
98
|
+
if (member !== "resolveProgramProject") return [];
|
|
99
|
+
const artifact = value;
|
|
100
|
+
const files = artifact.files;
|
|
101
|
+
return [...new Set(files ? files.flatMap((file) => transferBytes(file.data)) : transferBytes(artifact.data))];
|
|
102
|
+
}
|
|
103
|
+
function failurePayload(cause) {
|
|
104
|
+
const message = messageOf(cause);
|
|
105
|
+
const method = methodErrorOf(cause);
|
|
106
|
+
if (method !== void 0) return {
|
|
107
|
+
kind: "method",
|
|
108
|
+
code: method.code,
|
|
109
|
+
message: method.message,
|
|
110
|
+
...method.details === void 0 ? {} : { details: jsonSafe(method.details) }
|
|
111
|
+
};
|
|
112
|
+
const code = codeOf(cause);
|
|
113
|
+
const instanceId = instanceIdOf(cause);
|
|
114
|
+
return {
|
|
115
|
+
kind: code === "Error" ? "failure" : "runtime",
|
|
116
|
+
code,
|
|
117
|
+
message,
|
|
118
|
+
...instanceId === void 0 ? {} : { instanceId }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function decodePayload(message) {
|
|
122
|
+
let parsed;
|
|
123
|
+
try {
|
|
124
|
+
parsed = JSON.parse(message);
|
|
125
|
+
} catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
129
|
+
const candidate = parsed;
|
|
130
|
+
if (typeof candidate["code"] !== "string" || typeof candidate["message"] !== "string") return;
|
|
131
|
+
return {
|
|
132
|
+
kind: candidate["kind"] === "method" || candidate["kind"] === "runtime" ? candidate["kind"] : "failure",
|
|
133
|
+
code: candidate["code"],
|
|
134
|
+
message: candidate["message"],
|
|
135
|
+
...typeof candidate["instanceId"] === "string" ? { instanceId: candidate["instanceId"] } : {},
|
|
136
|
+
...candidate["details"] === void 0 ? {} : { details: candidate["details"] }
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function codeOf(cause) {
|
|
140
|
+
if (typeof cause !== "object" || cause === null) return "Error";
|
|
141
|
+
const code = cause.code;
|
|
142
|
+
if (typeof code === "string" && code.length > 0) return code;
|
|
143
|
+
const name = cause.name;
|
|
144
|
+
return typeof name === "string" && name.length > 0 ? name : "Error";
|
|
145
|
+
}
|
|
146
|
+
function instanceIdOf(cause) {
|
|
147
|
+
if (typeof cause !== "object" || cause === null) return void 0;
|
|
148
|
+
const instanceId = cause.instanceId;
|
|
149
|
+
return typeof instanceId === "string" ? instanceId : void 0;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Recognizes a model business rejection without importing the SDK: the runtime and its guests may
|
|
153
|
+
* carry different copies of the class, so the shape plus the registered name is what counts.
|
|
154
|
+
*/
|
|
155
|
+
function methodErrorOf(cause) {
|
|
156
|
+
if (typeof cause !== "object" || cause === null) return void 0;
|
|
157
|
+
const candidate = cause;
|
|
158
|
+
if (candidate.name !== "MethodError" || typeof candidate.code !== "string") return void 0;
|
|
159
|
+
if (typeof candidate.message !== "string") return void 0;
|
|
160
|
+
return {
|
|
161
|
+
code: candidate.code,
|
|
162
|
+
message: candidate.message,
|
|
163
|
+
...candidate.details === void 0 ? {} : { details: candidate.details }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** JSON-safe copy of a model value; byte payloads become number arrays. */
|
|
167
|
+
function jsonSafe(value) {
|
|
168
|
+
if (value instanceof Uint8Array) return [...value];
|
|
169
|
+
if (Array.isArray(value)) return value.map((item) => jsonSafe(item));
|
|
170
|
+
if (typeof value === "object" && value !== null) {
|
|
171
|
+
const record = {};
|
|
172
|
+
for (const [key, member] of Object.entries(value)) record[key] = jsonSafe(member);
|
|
173
|
+
return record;
|
|
174
|
+
}
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
function messageOf(cause) {
|
|
178
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
export { isImageBitmap as a, toWireFailure as c, transferPackageBytes as d, transferPresentationBytes as f, isFusedBridgeError as i, transferBytes as l, transferResourceBytes as m, FusedBridgeError as n, mapWireFailure as o, transferProgramArtifact as p, fromWireFailure as r, messageOf as s, FUSED_WIRE_FAILURE as t, transferOverlayFrame as u };
|
|
182
|
+
|
|
183
|
+
//# sourceMappingURL=wire-BDHL5Aj9.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-BDHL5Aj9.js","names":[],"sources":["../src/fused/runtime/wire.ts"],"sourcesContent":["/**\n * Failure and transfer conventions of the fused sandbox bridge (RFC 0025).\n *\n * RPC carries only `name` and `message` across a sandbox boundary, so a contract failure travels as\n * JSON inside the message and is rebuilt on the other side. Nothing here imports device or model\n * code: the main thread must never pull model execution into its own bundle.\n */\nimport type { Value } from '@mica-js/document/fused';\nimport type {\n IFusedFirmwareSnapshot,\n IFusedProgramFilesSnapshot,\n IFusedOverlayFrame,\n IFusedPrepareResult,\n} from './protocol';\n\n/** `name` of a failure whose message carries a {@link IFusedFailurePayload}. */\nexport const FUSED_WIRE_FAILURE = 'FusedSandboxFailure';\n\n/** One failure of a guest call, flattened for the wire. */\nexport interface IFusedFailurePayload {\n /** `method` keeps a business rejection, `runtime` a contract error, `failure` anything else. */\n readonly kind: 'method' | 'runtime' | 'failure';\n readonly code: string;\n readonly message: string;\n readonly instanceId?: string;\n /** JSON-safe snapshot of a `MethodError` payload. */\n readonly details?: unknown;\n}\n\nexport interface IFusedBridgeErrorOptions {\n readonly instanceId?: string;\n readonly details?: Value;\n /**\n * Error name. A method rejection keeps `MethodError`, so the SDK predicate of the consumer still\n * recognizes it; every other failure keeps the default name.\n */\n readonly name?: string;\n}\n\n/**\n * Host-side failure of the fused sandbox bridge.\n *\n * Mirrors `FusedRuntimeError` (`code`, optional `instanceId`) and keeps the business payload of a\n * model `MethodError` rejection. Guest code uses the same class to build the failure it throws.\n */\nexport class FusedBridgeError extends Error {\n readonly code: string;\n readonly instanceId: string | undefined;\n readonly details: Value | undefined;\n\n constructor(code: string, message: string, options: IFusedBridgeErrorOptions = {}) {\n super(message);\n this.name = options.name ?? 'FusedBridgeError';\n this.code = code;\n this.instanceId = options.instanceId;\n this.details = options.details;\n }\n}\n\nexport function isFusedBridgeError(value: unknown): value is FusedBridgeError {\n return value instanceof FusedBridgeError;\n}\n\n/** Encodes one failure as an `Error` the RPC layer can carry. */\nexport function toWireFailure(cause: unknown): Error {\n const payload = failurePayload(cause);\n return Object.assign(new Error(JSON.stringify(payload)), { name: FUSED_WIRE_FAILURE });\n}\n\n/** Rebuilds the failure of a rejected guest call; other errors pass through. */\nexport function fromWireFailure(cause: unknown): Error {\n if (!(cause instanceof Error) || cause.name !== FUSED_WIRE_FAILURE) {\n return cause instanceof Error ? cause : new Error(String(cause));\n }\n const payload = decodePayload(cause.message);\n if (payload === undefined) {\n return cause;\n }\n return new FusedBridgeError(payload.code, payload.message, {\n ...(payload.kind === 'method' ? { name: 'MethodError' } : {}),\n ...(payload.instanceId === undefined ? {} : { instanceId: payload.instanceId }),\n ...(payload.details === undefined ? {} : { details: payload.details as Value }),\n });\n}\n\n/** Runs one guest call and rebuilds a wire failure of its rejection. */\nexport async function mapWireFailure<T>(run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (cause) {\n throw fromWireFailure(cause);\n }\n}\n\n/** Whether a value is a decodable overlay bitmap of this realm. */\nexport function isImageBitmap(value: unknown): value is ImageBitmap {\n return typeof ImageBitmap !== 'undefined' && value instanceof ImageBitmap;\n}\n\n/** Transfer list of one `prepare` result: every byte snapshot of the presentation props. */\nexport function transferPresentationBytes(member: string, value: unknown): readonly Transferable[] {\n if (member !== 'prepare') return [];\n const instances = (value as IFusedPrepareResult | undefined)?.instances ?? [];\n const buffers = new Set<ArrayBuffer>();\n for (const instance of instances) {\n for (const prop of Object.values(instance.props)) collectPropBytes(prop, buffers);\n }\n return [...buffers];\n}\n\nfunction collectPropBytes(value: unknown, buffers: Set<ArrayBuffer>): void {\n if (value instanceof Uint8Array) {\n if (value.buffer instanceof ArrayBuffer) buffers.add(value.buffer);\n return;\n }\n const snapshot = value as IFusedFirmwareSnapshot | IFusedProgramFilesSnapshot | null;\n if (snapshot === null || typeof snapshot !== 'object') return;\n if (snapshot.kind === 'filesystem') {\n for (const file of snapshot.files) collectPropBytes(file.data, buffers);\n return;\n }\n if (snapshot.kind !== 'firmware') return;\n for (const segment of snapshot.segments) {\n if (segment.bytes instanceof Uint8Array && segment.bytes.buffer instanceof ArrayBuffer) {\n buffers.add(segment.bytes.buffer);\n }\n }\n}\n/** Transfer list of one `render` result. */\nexport function transferOverlayFrame(member: string, value: unknown): readonly Transferable[] {\n if (member !== 'render') return [];\n const frame = value as IFusedOverlayFrame | undefined;\n if (frame === undefined || frame === null) return [];\n return isImageBitmap(frame.bitmap) ? [frame.bitmap] : [];\n}\n\n/** Transfer list of one `Uint8Array` result. */\nexport function transferBytes(value: unknown): readonly Transferable[] {\n if (!(value instanceof Uint8Array)) return [];\n if (!(value.buffer instanceof ArrayBuffer)) return [];\n if (value.byteOffset !== 0 || value.byteLength !== value.buffer.byteLength) return [];\n return [value.buffer];\n}\n\n/** Transfer list of one host package `read` result. */\nexport function transferPackageBytes(member: string, value: unknown): readonly Transferable[] {\n return member === 'read' ? transferBytes(value) : [];\n}\n\n/** Transfer list of one host `readResource` result. */\nexport function transferResourceBytes(member: string, value: unknown): readonly Transferable[] {\n return member === 'readResource' ? transferBytes(value) : [];\n}\n\nexport function transferProgramArtifact(member: string, value: unknown): readonly Transferable[] {\n if (member !== 'resolveProgramProject') return [];\n const artifact = value as {\n readonly kind?: string;\n readonly data?: Uint8Array;\n readonly files?: readonly { readonly data: Uint8Array }[];\n };\n const files = artifact.files;\n return [\n ...new Set(\n files ? files.flatMap((file) => transferBytes(file.data)) : transferBytes(artifact.data),\n ),\n ];\n}\n\nfunction failurePayload(cause: unknown): IFusedFailurePayload {\n const message = messageOf(cause);\n const method = methodErrorOf(cause);\n if (method !== undefined) {\n return {\n kind: 'method',\n code: method.code,\n message: method.message,\n ...(method.details === undefined ? {} : { details: jsonSafe(method.details) }),\n };\n }\n const code = codeOf(cause);\n const instanceId = instanceIdOf(cause);\n return {\n kind: code === 'Error' ? 'failure' : 'runtime',\n code,\n message,\n ...(instanceId === undefined ? {} : { instanceId }),\n };\n}\n\nfunction decodePayload(message: string): IFusedFailurePayload | undefined {\n let parsed: unknown;\n try {\n parsed = JSON.parse(message);\n } catch {\n return undefined;\n }\n if (typeof parsed !== 'object' || parsed === null) return undefined;\n const candidate = parsed as Record<string, unknown>;\n if (typeof candidate['code'] !== 'string' || typeof candidate['message'] !== 'string') {\n return undefined;\n }\n const kind =\n candidate['kind'] === 'method' || candidate['kind'] === 'runtime'\n ? candidate['kind']\n : 'failure';\n return {\n kind,\n code: candidate['code'],\n message: candidate['message'],\n ...(typeof candidate['instanceId'] === 'string' ? { instanceId: candidate['instanceId'] } : {}),\n ...(candidate['details'] === undefined ? {} : { details: candidate['details'] }),\n };\n}\n\nfunction codeOf(cause: unknown): string {\n if (typeof cause !== 'object' || cause === null) return 'Error';\n const code = (cause as { readonly code?: unknown }).code;\n if (typeof code === 'string' && code.length > 0) return code;\n const name = (cause as { readonly name?: unknown }).name;\n return typeof name === 'string' && name.length > 0 ? name : 'Error';\n}\n\nfunction instanceIdOf(cause: unknown): string | undefined {\n if (typeof cause !== 'object' || cause === null) return undefined;\n const instanceId = (cause as { readonly instanceId?: unknown }).instanceId;\n return typeof instanceId === 'string' ? instanceId : undefined;\n}\n\n/**\n * Recognizes a model business rejection without importing the SDK: the runtime and its guests may\n * carry different copies of the class, so the shape plus the registered name is what counts.\n */\nfunction methodErrorOf(\n cause: unknown,\n): { readonly code: string; readonly message: string; readonly details?: unknown } | undefined {\n if (typeof cause !== 'object' || cause === null) return undefined;\n const candidate = cause as {\n readonly name?: unknown;\n readonly code?: unknown;\n readonly message?: unknown;\n readonly details?: unknown;\n };\n if (candidate.name !== 'MethodError' || typeof candidate.code !== 'string') return undefined;\n if (typeof candidate.message !== 'string') return undefined;\n return {\n code: candidate.code,\n message: candidate.message,\n ...(candidate.details === undefined ? {} : { details: candidate.details }),\n };\n}\n\n/** JSON-safe copy of a model value; byte payloads become number arrays. */\nfunction jsonSafe(value: unknown): unknown {\n if (value instanceof Uint8Array) return [...value];\n if (Array.isArray(value)) return value.map((item: unknown) => jsonSafe(item));\n if (typeof value === 'object' && value !== null) {\n const record: Record<string, unknown> = {};\n for (const [key, member] of Object.entries(value)) record[key] = jsonSafe(member);\n return record;\n }\n return value;\n}\n\nexport function messageOf(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n"],"mappings":";;AAgBA,IAAa,qBAAqB;;;;;;;AA6BlC,IAAa,mBAAb,cAAsC,MAAM;CAC1C;CACA;CACA;CAEA,YAAY,MAAc,SAAiB,UAAoC,CAAC,GAAG;EACjF,MAAM,OAAO;EACb,KAAK,OAAO,QAAQ,QAAQ;EAC5B,KAAK,OAAO;EACZ,KAAK,aAAa,QAAQ;EAC1B,KAAK,UAAU,QAAQ;CACzB;AACF;AAEA,SAAgB,mBAAmB,OAA2C;CAC5E,OAAO,iBAAiB;AAC1B;;AAGA,SAAgB,cAAc,OAAuB;CACnD,MAAM,UAAU,eAAe,KAAK;CACpC,OAAO,OAAO,OAAO,IAAI,MAAM,KAAK,UAAU,OAAO,CAAC,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvF;;AAGA,SAAgB,gBAAgB,OAAuB;CACrD,IAAI,EAAE,iBAAiB,UAAU,MAAM,SAAA,uBACrC,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;CAEjE,MAAM,UAAU,cAAc,MAAM,OAAO;CAC3C,IAAI,YAAY,KAAA,GACd,OAAO;CAET,OAAO,IAAI,iBAAiB,QAAQ,MAAM,QAAQ,SAAS;EACzD,GAAI,QAAQ,SAAS,WAAW,EAAE,MAAM,cAAc,IAAI,CAAC;EAC3D,GAAI,QAAQ,eAAe,KAAA,IAAY,C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AG,KAAK;CACjD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,KAAK,SAAkB,SAAS,IAAI,CAAC;CAC5E,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;EAC/C,MAAM,SAAkC,CAAC;EACzC,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,KAAK,GAAG,OAAO,OAAO,SAAS,MAAM;EAChF,OAAO;CACT;CACA,OAAO;AACT;AAEA,SAAgB,UAAU,OAAwB;CAChD,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { GROUND_DEVICE, LABEL_DEVICE, POWER_DEVICE, parseDeviceReference, projectOnSegment, symbolPinPosition, symbolRole } from "@mica-js/document/schematic";
|
|
2
|
+
//#region src/schematic/editing/segment-drag.ts
|
|
3
|
+
/**
|
|
4
|
+
* Wire points produced by sliding one segment by `delta` along its normal.
|
|
5
|
+
*
|
|
6
|
+
* The whole run of segments parallel to the dragged one moves along, so no neighbour is left
|
|
7
|
+
* diagonal. Where that run ends at a pin, an anchor, a junction or another wire, the vertex stays
|
|
8
|
+
* put and the wire gains a dogleg. Pure geometry: the caller decides how to apply it.
|
|
9
|
+
*/
|
|
10
|
+
function planSegmentDrag(document, wireId, segment, delta, options = {}) {
|
|
11
|
+
const wire = document.sheet.wires.find((candidate) => candidate.id === wireId);
|
|
12
|
+
return wire === void 0 ? void 0 : planWireSegmentDrag(document, wire, segment, delta, options);
|
|
13
|
+
}
|
|
14
|
+
function planWireSegmentDrag(document, wire, segment, delta, options) {
|
|
15
|
+
return planPolylineSegmentDrag(wire.points, segment, delta, (point) => isConnectedVertex(document, point, wire.id, options));
|
|
16
|
+
}
|
|
17
|
+
/** Slides a polyline segment, keeping connected vertices fixed with doglegs. */
|
|
18
|
+
function planPolylineSegmentDrag(points, segment, delta, connected) {
|
|
19
|
+
const start = points[segment];
|
|
20
|
+
const end = points[segment + 1];
|
|
21
|
+
if (start === void 0 || end === void 0 || delta.x === 0 && delta.y === 0) return;
|
|
22
|
+
if (start.x === end.x && start.y === end.y) return;
|
|
23
|
+
const horizontal = start.y === end.y;
|
|
24
|
+
const isParallel = (from, to) => horizontal ? from.y === to.y : from.x === to.x;
|
|
25
|
+
let first = segment;
|
|
26
|
+
while (first > 0) {
|
|
27
|
+
const previous = points[first - 1];
|
|
28
|
+
const current = points[first];
|
|
29
|
+
if (previous === void 0 || current === void 0 || !isParallel(previous, current) || connected(current)) break;
|
|
30
|
+
first -= 1;
|
|
31
|
+
}
|
|
32
|
+
let last = segment + 1;
|
|
33
|
+
while (last < points.length - 1) {
|
|
34
|
+
const current = points[last];
|
|
35
|
+
const next = points[last + 1];
|
|
36
|
+
if (current === void 0 || next === void 0 || !isParallel(current, next) || connected(current)) break;
|
|
37
|
+
last += 1;
|
|
38
|
+
}
|
|
39
|
+
const firstPoint = points[first];
|
|
40
|
+
const lastPoint = points[last];
|
|
41
|
+
if (firstPoint === void 0 || lastPoint === void 0) return;
|
|
42
|
+
const shift = (point) => ({
|
|
43
|
+
x: point.x + delta.x,
|
|
44
|
+
y: point.y + delta.y
|
|
45
|
+
});
|
|
46
|
+
const moved = [];
|
|
47
|
+
for (let index = first; index <= last; index += 1) {
|
|
48
|
+
const point = points[index];
|
|
49
|
+
if (point !== void 0) moved.push(shift(point));
|
|
50
|
+
}
|
|
51
|
+
if (connected(firstPoint)) moved.unshift(firstPoint);
|
|
52
|
+
if (connected(lastPoint)) moved.push(lastPoint);
|
|
53
|
+
return [
|
|
54
|
+
...points.slice(0, first),
|
|
55
|
+
...moved,
|
|
56
|
+
...points.slice(last + 1)
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
/** True when something other than the wire itself is attached at `point`. */
|
|
60
|
+
function isConnectedVertex(document, point, wireId, options = {}) {
|
|
61
|
+
const same = (candidate) => candidate.x === point.x && candidate.y === point.y;
|
|
62
|
+
for (const junction of document.sheet.junctions) if (same(junction)) return true;
|
|
63
|
+
for (const wire of document.sheet.wires) if (wire.id !== wireId && wire.points.some(same)) return true;
|
|
64
|
+
for (const symbol of document.sheet.symbols) {
|
|
65
|
+
if (symbolRole(symbol.device) !== "component") {
|
|
66
|
+
if (same({
|
|
67
|
+
x: symbol.x,
|
|
68
|
+
y: symbol.y
|
|
69
|
+
})) return true;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const reference = parseDeviceReference(symbol.device);
|
|
73
|
+
const definition = reference === void 0 ? void 0 : options.devices?.getDeviceSymbol(reference);
|
|
74
|
+
if (definition === void 0) continue;
|
|
75
|
+
for (const anchor of Object.values(definition.pins)) if (same(symbolPinPosition(symbol, anchor))) return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/schematic/editor/snapping/nodes.ts
|
|
81
|
+
/** World position of a pin / label / power / ground anchor under `point`. */
|
|
82
|
+
function connectionNodeAt(context, point) {
|
|
83
|
+
const hit = context.hitTest(point, {
|
|
84
|
+
tolerance: context.tolerance * 2,
|
|
85
|
+
includeSymbols: false
|
|
86
|
+
});
|
|
87
|
+
if (hit?.kind === "pin") return pinPosition(context, hit);
|
|
88
|
+
const anchor = anchorSymbolAt(context, point);
|
|
89
|
+
if (anchor !== void 0) return {
|
|
90
|
+
x: anchor.x,
|
|
91
|
+
y: anchor.y
|
|
92
|
+
};
|
|
93
|
+
return wireEndpointAt(context, point);
|
|
94
|
+
}
|
|
95
|
+
/** Endpoint of an existing wire under `point`; used to close a connection. */
|
|
96
|
+
function wireEndpointAt(context, point) {
|
|
97
|
+
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 {
|
|
98
|
+
x: endpoint.x,
|
|
99
|
+
y: endpoint.y
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Builtin connection symbol (label / power / ground) anchored under `point`. */
|
|
103
|
+
function anchorSymbolAt(context, point) {
|
|
104
|
+
for (const symbol of context.document.sheet.symbols) {
|
|
105
|
+
const device = symbol.device;
|
|
106
|
+
if (device !== LABEL_DEVICE && device !== POWER_DEVICE && device !== GROUND_DEVICE) continue;
|
|
107
|
+
if (Math.abs(symbol.x - point.x) <= context.tolerance && Math.abs(symbol.y - point.y) <= context.tolerance) return symbol;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function pinPosition(context, hit) {
|
|
111
|
+
const symbol = context.document.sheet.symbols.find((item) => item.id === hit.symbolId);
|
|
112
|
+
if (symbol === void 0) return;
|
|
113
|
+
const reference = parseDeviceReference(symbol.device);
|
|
114
|
+
const anchor = reference === void 0 ? void 0 : context.devices?.getDeviceSymbol(reference)?.pins[hit.pinId];
|
|
115
|
+
return anchor === void 0 ? void 0 : symbolPinPosition(symbol, anchor);
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/schematic/editor/snapping/drag.ts
|
|
119
|
+
function snapToGrid(point, display) {
|
|
120
|
+
if (!display.snap || !(display.gridSize > 0)) return point;
|
|
121
|
+
const size = display.gridSize;
|
|
122
|
+
return {
|
|
123
|
+
x: Math.round(point.x / size) * size,
|
|
124
|
+
y: Math.round(point.y / size) * size
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Offset for dragging something anchored at `anchor` from `from` to `to`: the result is snapped,
|
|
129
|
+
* not the raw pointer delta, so an off-grid symbol lands on the grid.
|
|
130
|
+
*
|
|
131
|
+
* Dragging uses the fine grid spacing (`gridSize / gridSubdivisions`).
|
|
132
|
+
* A drag that stays within half a fine grid cell on one axis does not move that axis at all, so an
|
|
133
|
+
* anchor that started off-grid keeps its column/row instead of jittering sideways.
|
|
134
|
+
*/
|
|
135
|
+
function snapDragOffset(anchor, from, to, display) {
|
|
136
|
+
const dx = to.x - from.x;
|
|
137
|
+
const dy = to.y - from.y;
|
|
138
|
+
if (!display.snap || !(display.gridSize > 0)) return {
|
|
139
|
+
x: dx,
|
|
140
|
+
y: dy
|
|
141
|
+
};
|
|
142
|
+
const subdivisions = Number.isFinite(display.gridSubdivisions) && display.gridSubdivisions >= 1 ? Math.round(display.gridSubdivisions) : 1;
|
|
143
|
+
const size = display.gridSize / subdivisions;
|
|
144
|
+
const target = snapToGrid({
|
|
145
|
+
x: anchor.x + dx,
|
|
146
|
+
y: anchor.y + dy
|
|
147
|
+
}, {
|
|
148
|
+
...display,
|
|
149
|
+
gridSize: size
|
|
150
|
+
});
|
|
151
|
+
const lock = size / 2;
|
|
152
|
+
return {
|
|
153
|
+
x: (Math.abs(dx) < lock ? anchor.x : target.x) - anchor.x,
|
|
154
|
+
y: (Math.abs(dy) < lock ? anchor.y : target.y) - anchor.y
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/schematic/editor/snapping/wire.ts
|
|
159
|
+
/**
|
|
160
|
+
* Waypoints needed to reach `to` from `from` with horizontal/vertical segments only.
|
|
161
|
+
* Returns `[to]` when already aligned, otherwise an elbow plus `to` (long axis first).
|
|
162
|
+
*/
|
|
163
|
+
function orthogonalWaypoints(from, to) {
|
|
164
|
+
if (from.x === to.x || from.y === to.y) return [to];
|
|
165
|
+
return [Math.abs(to.x - from.x) >= Math.abs(to.y - from.y) ? {
|
|
166
|
+
x: to.x,
|
|
167
|
+
y: from.y
|
|
168
|
+
} : {
|
|
169
|
+
x: from.x,
|
|
170
|
+
y: to.y
|
|
171
|
+
}, to];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Waypoints for one new wire leg. When the target lands on an existing wire the last leg runs
|
|
175
|
+
* perpendicular to it, so the branch taps into a T instead of doubling back along the host.
|
|
176
|
+
*/
|
|
177
|
+
function wireWaypoints(from, to, host) {
|
|
178
|
+
if (host === void 0 || from.x === to.x || from.y === to.y) return orthogonalWaypoints(from, to);
|
|
179
|
+
return host === "vertical" ? [{
|
|
180
|
+
x: from.x,
|
|
181
|
+
y: to.y
|
|
182
|
+
}, to] : [{
|
|
183
|
+
x: to.x,
|
|
184
|
+
y: from.y
|
|
185
|
+
}, to];
|
|
186
|
+
}
|
|
187
|
+
/** Extends a routed path, folding retraced collinear legs instead of leaving dangling branches. */
|
|
188
|
+
function extendWirePath(points, to, host) {
|
|
189
|
+
const from = points[points.length - 1];
|
|
190
|
+
const candidates = from === void 0 ? [to] : [...points, ...wireWaypoints(from, to, host)];
|
|
191
|
+
const path = [];
|
|
192
|
+
for (const point of candidates) {
|
|
193
|
+
while (path.length >= 2) {
|
|
194
|
+
const a = path[path.length - 2];
|
|
195
|
+
const b = path[path.length - 1];
|
|
196
|
+
if (a.x === b.x && b.x === point.x || a.y === b.y && b.y === point.y) path.pop();
|
|
197
|
+
else break;
|
|
198
|
+
}
|
|
199
|
+
const previous = path[path.length - 1];
|
|
200
|
+
if (previous === void 0 || previous.x !== point.x || previous.y !== point.y) path.push(point);
|
|
201
|
+
}
|
|
202
|
+
return path;
|
|
203
|
+
}
|
|
204
|
+
/** Snaps to a nearby connection node, then to a nearby wire, otherwise to the grid. */
|
|
205
|
+
function snapForWire(context, point) {
|
|
206
|
+
return connectionNodeAt(context, point) ?? wireBodyPointAt(context, point) ?? snapToGrid(point, context.display);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Closest point on an existing wire's run when `point` is within the snap radius. Lets the wire
|
|
210
|
+
* tool land exactly on another wire, which is what turns the run into a T junction. Only the
|
|
211
|
+
* offset beside the host is absorbed: the position along it still follows the grid.
|
|
212
|
+
*/
|
|
213
|
+
function wireBodyPointAt(context, point) {
|
|
214
|
+
const radius = context.tolerance * 2;
|
|
215
|
+
const display = context.display;
|
|
216
|
+
let best;
|
|
217
|
+
for (const wire of context.document.sheet.wires) for (let index = 1; index < wire.points.length; index += 1) {
|
|
218
|
+
const a = wire.points[index - 1];
|
|
219
|
+
const b = wire.points[index];
|
|
220
|
+
if (a === void 0 || b === void 0) continue;
|
|
221
|
+
const projected = projectOnSegment(point, a, b);
|
|
222
|
+
const distance = Math.hypot(projected.x - point.x, projected.y - point.y);
|
|
223
|
+
if (distance > radius || best !== void 0 && distance >= best.distance) continue;
|
|
224
|
+
best = {
|
|
225
|
+
point: gridAlongHost(projected, a, b, display),
|
|
226
|
+
distance
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return best?.point;
|
|
230
|
+
}
|
|
231
|
+
function gridAlongHost(projected, a, b, display) {
|
|
232
|
+
if (a.y === b.y && a.x !== b.x) {
|
|
233
|
+
const x = snapToGrid(projected, display).x;
|
|
234
|
+
return x >= Math.min(a.x, b.x) && x <= Math.max(a.x, b.x) ? {
|
|
235
|
+
x,
|
|
236
|
+
y: a.y
|
|
237
|
+
} : {
|
|
238
|
+
x: projected.x,
|
|
239
|
+
y: a.y
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (a.x === b.x && a.y !== b.y) {
|
|
243
|
+
const y = snapToGrid(projected, display).y;
|
|
244
|
+
return y >= Math.min(a.y, b.y) && y <= Math.max(a.y, b.y) ? {
|
|
245
|
+
x: a.x,
|
|
246
|
+
y
|
|
247
|
+
} : {
|
|
248
|
+
x: a.x,
|
|
249
|
+
y: projected.y
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
x: projected.x,
|
|
254
|
+
y: projected.y
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
export { snapToGrid as a, planPolylineSegmentDrag as c, snapDragOffset as i, planSegmentDrag as l, orthogonalWaypoints as n, connectionNodeAt as o, snapForWire as r, pinPosition as s, extendWirePath as t };
|
|
259
|
+
|
|
260
|
+
//# sourceMappingURL=wire-JZIiIOI0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-JZIiIOI0.js","names":[],"sources":["../src/schematic/editing/segment-drag.ts","../src/schematic/editor/snapping/nodes.ts","../src/schematic/editor/snapping/drag.ts","../src/schematic/editor/snapping/wire.ts"],"sourcesContent":["import {\n parseDeviceReference,\n symbolRole,\n type DeviceSymbolProvider,\n type SchematicDocument,\n type SchematicWire,\n type Point,\n symbolPinPosition,\n} from '@mica-js/document/schematic';\n\nexport interface ISegmentDragOptions {\n readonly devices?: DeviceSymbolProvider;\n}\n\n/**\n * Wire points produced by sliding one segment by `delta` along its normal.\n *\n * The whole run of segments parallel to the dragged one moves along, so no neighbour is left\n * diagonal. Where that run ends at a pin, an anchor, a junction or another wire, the vertex stays\n * put and the wire gains a dogleg. Pure geometry: the caller decides how to apply it.\n */\nexport function planSegmentDrag(\n document: SchematicDocument,\n wireId: string,\n segment: number,\n delta: Point,\n options: ISegmentDragOptions = {},\n): readonly Point[] | undefined {\n const wire = document.sheet.wires.find((candidate) => candidate.id === wireId);\n return wire === undefined\n ? undefined\n : planWireSegmentDrag(document, wire, segment, delta, options);\n}\n\nfunction planWireSegmentDrag(\n document: SchematicDocument,\n wire: SchematicWire,\n segment: number,\n delta: Point,\n options: ISegmentDragOptions,\n): readonly Point[] | undefined {\n return planPolylineSegmentDrag(wire.points, segment, delta, (point) =>\n isConnectedVertex(document, point, wire.id, options),\n );\n}\n\n/** Slides a polyline segment, keeping connected vertices fixed with doglegs. */\nexport function planPolylineSegmentDrag(\n points: readonly Point[],\n segment: number,\n delta: Point,\n connected: (point: Point) => boolean,\n): readonly Point[] | undefined {\n const start = points[segment];\n const end = points[segment + 1];\n if (start === undefined || end === undefined || (delta.x === 0 && delta.y === 0)) {\n return undefined;\n }\n if (start.x === end.x && start.y === end.y) {\n return undefined;\n }\n // Dragging a horizontal segment moves its run vertically; the run only breaks at a segment\n // pointing the other way (it just stretches) or at a connected vertex (it needs a dogleg).\n const horizontal = start.y === end.y;\n const isParallel = (from: Point, to: Point): boolean =>\n horizontal ? from.y === to.y : from.x === to.x;\n let first = segment;\n while (first > 0) {\n const previous = points[first - 1];\n const current = points[first];\n if (\n previous === undefined ||\n current === undefined ||\n !isParallel(previous, current) ||\n connected(current)\n ) {\n break;\n }\n first -= 1;\n }\n let last = segment + 1;\n while (last < points.length - 1) {\n const current = points[last];\n const next = points[last + 1];\n if (\n current === undefined ||\n next === undefined ||\n !isParallel(current, next) ||\n connected(current)\n ) {\n break;\n }\n last += 1;\n }\n\n const firstPoint = points[first];\n const lastPoint = points[last];\n if (firstPoint === undefined || lastPoint === undefined) {\n return undefined;\n }\n const shift = (point: Point): Point => ({ x: point.x + delta.x, y: point.y + delta.y });\n const moved: Point[] = [];\n for (let index = first; index <= last; index += 1) {\n const point = points[index];\n if (point !== undefined) {\n moved.push(shift(point));\n }\n }\n if (connected(firstPoint)) {\n moved.unshift(firstPoint);\n }\n if (connected(lastPoint)) {\n moved.push(lastPoint);\n }\n return [...points.slice(0, first), ...moved, ...points.slice(last + 1)];\n}\n\n/** True when something other than the wire itself is attached at `point`. */\nexport function isConnectedVertex(\n document: SchematicDocument,\n point: Point,\n wireId: string,\n options: ISegmentDragOptions = {},\n): boolean {\n const same = (candidate: Point): boolean => candidate.x === point.x && candidate.y === point.y;\n for (const junction of document.sheet.junctions) {\n if (same(junction)) {\n return true;\n }\n }\n for (const wire of document.sheet.wires) {\n if (wire.id !== wireId && wire.points.some(same)) {\n return true;\n }\n }\n for (const symbol of document.sheet.symbols) {\n const role = symbolRole(symbol.device);\n if (role !== 'component') {\n if (same({ x: symbol.x, y: symbol.y })) {\n return true;\n }\n continue;\n }\n const reference = parseDeviceReference(symbol.device);\n const definition =\n reference === undefined ? undefined : options.devices?.getDeviceSymbol(reference);\n if (definition === undefined) {\n continue;\n }\n for (const anchor of Object.values(definition.pins)) {\n if (same(symbolPinPosition(symbol, anchor))) {\n return true;\n }\n }\n }\n return false;\n}\n","import {\n GROUND_DEVICE,\n LABEL_DEVICE,\n POWER_DEVICE,\n parseDeviceReference,\n symbolPinPosition,\n type DeviceSymbolProvider,\n type Point,\n type SchematicDocument,\n} from '@mica-js/document/schematic';\nimport { type IHitTestOptions, type SchematicHit } from '../../editing/query';\nimport type { IDisplayOptions } from '../../types';\n\n/** Screen-space hit radius; callers divide by the viewport scale. */\nexport const MIN_HIT_PIXELS = 6;\n\nexport interface ISnapContext {\n readonly document: SchematicDocument;\n readonly display: IDisplayOptions;\n readonly devices: DeviceSymbolProvider | undefined;\n /** Hit tolerance in page units. */\n readonly tolerance: number;\n readonly hitTest: (point: Point, options?: IHitTestOptions) => SchematicHit | undefined;\n}\n\n/** World position of a pin / label / power / ground anchor under `point`. */\nexport function connectionNodeAt(context: ISnapContext, point: Point): Point | undefined {\n const hit = context.hitTest(point, {\n tolerance: context.tolerance * 2,\n includeSymbols: false,\n });\n if (hit?.kind === 'pin') {\n return pinPosition(context, hit);\n }\n const anchor = anchorSymbolAt(context, point);\n if (anchor !== undefined) {\n return { x: anchor.x, y: anchor.y };\n }\n return wireEndpointAt(context, point);\n}\n\n/** Endpoint of an existing wire under `point`; used to close a connection. */\nexport function wireEndpointAt(context: ISnapContext, point: Point): Point | undefined {\n for (const wire of context.document.sheet.wires) {\n for (const endpoint of [wire.points[0], wire.points[wire.points.length - 1]]) {\n if (\n endpoint !== undefined &&\n Math.abs(endpoint.x - point.x) <= context.tolerance * 2 &&\n Math.abs(endpoint.y - point.y) <= context.tolerance * 2\n ) {\n return { x: endpoint.x, y: endpoint.y };\n }\n }\n }\n return undefined;\n}\n\n/** Builtin connection symbol (label / power / ground) anchored under `point`. */\nexport function anchorSymbolAt(\n context: ISnapContext,\n point: Point,\n): { readonly x: number; readonly y: number } | undefined {\n // Anchors sit on wire endpoints, where `hitTest` reports the wire first, so scan directly.\n for (const symbol of context.document.sheet.symbols) {\n const device = symbol.device;\n if (device !== LABEL_DEVICE && device !== POWER_DEVICE && device !== GROUND_DEVICE) {\n continue;\n }\n if (\n Math.abs(symbol.x - point.x) <= context.tolerance &&\n Math.abs(symbol.y - point.y) <= context.tolerance\n ) {\n return symbol;\n }\n }\n return undefined;\n}\n\nexport function pinPosition(\n context: ISnapContext,\n hit: { readonly symbolId: string; readonly pinId: string },\n): Point | undefined {\n const symbol = context.document.sheet.symbols.find((item) => item.id === hit.symbolId);\n if (symbol === undefined) {\n return undefined;\n }\n const reference = parseDeviceReference(symbol.device);\n const anchor =\n reference === undefined\n ? undefined\n : context.devices?.getDeviceSymbol(reference)?.pins[hit.pinId];\n return anchor === undefined ? undefined : symbolPinPosition(symbol, anchor);\n}\n","import type { Point } from '@mica-js/document/schematic';\nimport type { IDisplayOptions } from '../../types';\n\nexport function snapToGrid(point: Point, display: IDisplayOptions): Point {\n if (!display.snap || !(display.gridSize > 0)) {\n return point;\n }\n const size = display.gridSize;\n return { x: Math.round(point.x / size) * size, y: Math.round(point.y / size) * size };\n}\n\n/**\n * Offset for dragging something anchored at `anchor` from `from` to `to`: the result is snapped,\n * not the raw pointer delta, so an off-grid symbol lands on the grid.\n *\n * Dragging uses the fine grid spacing (`gridSize / gridSubdivisions`).\n * A drag that stays within half a fine grid cell on one axis does not move that axis at all, so an\n * anchor that started off-grid keeps its column/row instead of jittering sideways.\n */\nexport function snapDragOffset(\n anchor: Point,\n from: Point,\n to: Point,\n display: IDisplayOptions,\n): Point {\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n if (!display.snap || !(display.gridSize > 0)) {\n return { x: dx, y: dy };\n }\n const subdivisions =\n Number.isFinite(display.gridSubdivisions) && display.gridSubdivisions >= 1\n ? Math.round(display.gridSubdivisions)\n : 1;\n const size = display.gridSize / subdivisions;\n const target = snapToGrid({ x: anchor.x + dx, y: anchor.y + dy }, { ...display, gridSize: size });\n const lock = size / 2;\n return {\n x: (Math.abs(dx) < lock ? anchor.x : target.x) - anchor.x,\n y: (Math.abs(dy) < lock ? anchor.y : target.y) - anchor.y,\n };\n}\n","import { projectOnSegment, type Point } from '@mica-js/document/schematic';\nimport type { IDisplayOptions } from '../../types';\nimport type { ISnapContext } from './nodes';\nimport { connectionNodeAt } from './nodes';\nimport { snapToGrid } from './drag';\n\n/**\n * Waypoints needed to reach `to` from `from` with horizontal/vertical segments only.\n * Returns `[to]` when already aligned, otherwise an elbow plus `to` (long axis first).\n */\nexport function orthogonalWaypoints(from: Point, to: Point): readonly Point[] {\n if (from.x === to.x || from.y === to.y) {\n return [to];\n }\n const elbow =\n Math.abs(to.x - from.x) >= Math.abs(to.y - from.y)\n ? { x: to.x, y: from.y }\n : { x: from.x, y: to.y };\n return [elbow, to];\n}\n\nexport type WireAxis = 'horizontal' | 'vertical';\n\n/**\n * Waypoints for one new wire leg. When the target lands on an existing wire the last leg runs\n * perpendicular to it, so the branch taps into a T instead of doubling back along the host.\n */\nexport function wireWaypoints(\n from: Point,\n to: Point,\n host: WireAxis | undefined,\n): readonly Point[] {\n if (host === undefined || from.x === to.x || from.y === to.y) {\n return orthogonalWaypoints(from, to);\n }\n return host === 'vertical' ? [{ x: from.x, y: to.y }, to] : [{ x: to.x, y: from.y }, to];\n}\n\n/** Extends a routed path, folding retraced collinear legs instead of leaving dangling branches. */\nexport function extendWirePath(\n points: readonly Point[],\n to: Point,\n host: WireAxis | undefined,\n): Point[] {\n const from = points[points.length - 1];\n const candidates = from === undefined ? [to] : [...points, ...wireWaypoints(from, to, host)];\n const path: Point[] = [];\n for (const point of candidates) {\n while (path.length >= 2) {\n const a = path[path.length - 2]!;\n const b = path[path.length - 1]!;\n if ((a.x === b.x && b.x === point.x) || (a.y === b.y && b.y === point.y)) {\n path.pop();\n } else {\n break;\n }\n }\n const previous = path[path.length - 1];\n if (previous === undefined || previous.x !== point.x || previous.y !== point.y) {\n path.push(point);\n }\n }\n return path;\n}\n\n/** Snaps to a nearby connection node, then to a nearby wire, otherwise to the grid. */\nexport function snapForWire(context: ISnapContext, point: Point): Point {\n return (\n connectionNodeAt(context, point) ??\n wireBodyPointAt(context, point) ??\n snapToGrid(point, context.display)\n );\n}\n\n/**\n * Closest point on an existing wire's run when `point` is within the snap radius. Lets the wire\n * tool land exactly on another wire, which is what turns the run into a T junction. Only the\n * offset beside the host is absorbed: the position along it still follows the grid.\n */\nexport function wireBodyPointAt(context: ISnapContext, point: Point): Point | undefined {\n const radius = context.tolerance * 2;\n const display = context.display;\n let best: { readonly point: Point; readonly distance: number } | undefined;\n for (const wire of context.document.sheet.wires) {\n for (let index = 1; index < wire.points.length; index += 1) {\n const a = wire.points[index - 1];\n const b = wire.points[index];\n if (a === undefined || b === undefined) {\n continue;\n }\n const projected = projectOnSegment(point, a, b);\n const distance = Math.hypot(projected.x - point.x, projected.y - point.y);\n if (distance > radius || (best !== undefined && distance >= best.distance)) {\n continue;\n }\n best = { point: gridAlongHost(projected, a, b, display), distance };\n }\n }\n return best?.point;\n}\n\nfunction gridAlongHost(projected: Point, a: Point, b: Point, display: IDisplayOptions): Point {\n // The axis normal to the host keeps the run's own coordinate so the tap stays on it; the axis\n // along the run follows the pointer, so it still has to honour the grid.\n if (a.y === b.y && a.x !== b.x) {\n const x = snapToGrid(projected, display).x;\n return x >= Math.min(a.x, b.x) && x <= Math.max(a.x, b.x)\n ? { x, y: a.y }\n : { x: projected.x, y: a.y };\n }\n if (a.x === b.x && a.y !== b.y) {\n const y = snapToGrid(projected, display).y;\n return y >= Math.min(a.y, b.y) && y <= Math.max(a.y, b.y)\n ? { x: a.x, y }\n : { x: a.x, y: projected.y };\n }\n return { x: projected.x, y: projected.y };\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,gBACd,UACA,QACA,SACA,OACA,UAA+B,CAAC,GACF;CAC9B,MAAM,OAAO,SAAS,MAAM,MAAM,MAAM,cAAc,UAAU,OAAO,MAAM;CAC7E,OAAO,SAAS,KAAA,IACZ,KAAA,IACA,oBAAoB,UAAU,MAAM,SAAS,OAAO,OAAO;AACjE;AAEA,SAAS,oBACP,UACA,MACA,SACA,OACA,SAC8B;CAC9B,OAAO,wBAAwB,KAAK,QAAQ,SAAS,QAAQ,UAC3D,kBAAkB,UAAU,OAAO,KAAK,IAAI,OAAO,CACrD;AACF;;AAGA,SAAgB,wBACd,Q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