@snaptrude/plugin-client 0.3.0 → 0.6.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/AGENTS.md +39 -45
- package/CHANGELOG.md +121 -0
- package/CLAUDE.md +1 -1
- package/dist/api/index.d.ts +13 -13
- package/dist/api/index.d.ts.map +1 -1
- package/dist/index.cjs +24 -467
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -460
- package/dist/index.js.map +1 -1
- package/dist/rpc-proxy.d.ts +28 -0
- package/dist/rpc-proxy.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/api/index.ts +29 -18
- package/src/rpc-proxy.ts +56 -0
- package/dist/api/core/geom/arc.d.ts +0 -5
- package/dist/api/core/geom/arc.d.ts.map +0 -1
- package/dist/api/core/geom/curve.d.ts +0 -5
- package/dist/api/core/geom/curve.d.ts.map +0 -1
- package/dist/api/core/geom/index.d.ts +0 -17
- package/dist/api/core/geom/index.d.ts.map +0 -1
- package/dist/api/core/geom/line.d.ts +0 -5
- package/dist/api/core/geom/line.d.ts.map +0 -1
- package/dist/api/core/geom/profile.d.ts +0 -7
- package/dist/api/core/geom/profile.d.ts.map +0 -1
- package/dist/api/core/index.d.ts +0 -11
- package/dist/api/core/index.d.ts.map +0 -1
- package/dist/api/core/math/index.d.ts +0 -11
- package/dist/api/core/math/index.d.ts.map +0 -1
- package/dist/api/core/math/quat.d.ts +0 -5
- package/dist/api/core/math/quat.d.ts.map +0 -1
- package/dist/api/core/math/vec3.d.ts +0 -5
- package/dist/api/core/math/vec3.d.ts.map +0 -1
- package/dist/api/entity/department.d.ts +0 -7
- package/dist/api/entity/department.d.ts.map +0 -1
- package/dist/api/entity/index.d.ts +0 -17
- package/dist/api/entity/index.d.ts.map +0 -1
- package/dist/api/entity/referenceLine.d.ts +0 -9
- package/dist/api/entity/referenceLine.d.ts.map +0 -1
- package/dist/api/entity/space.d.ts +0 -11
- package/dist/api/entity/space.d.ts.map +0 -1
- package/dist/api/entity/story.d.ts +0 -9
- package/dist/api/entity/story.d.ts.map +0 -1
- package/dist/api/tools/copy.d.ts +0 -3
- package/dist/api/tools/copy.d.ts.map +0 -1
- package/dist/api/tools/index.d.ts +0 -17
- package/dist/api/tools/index.d.ts.map +0 -1
- package/dist/api/tools/material.d.ts +0 -6
- package/dist/api/tools/material.d.ts.map +0 -1
- package/dist/api/tools/offset.d.ts +0 -3
- package/dist/api/tools/offset.d.ts.map +0 -1
- package/dist/api/tools/selection.d.ts +0 -6
- package/dist/api/tools/selection.d.ts.map +0 -1
- package/dist/api/tools/transform.d.ts +0 -7
- package/dist/api/tools/transform.d.ts.map +0 -1
- package/dist/api/units/index.d.ts +0 -7
- package/dist/api/units/index.d.ts.map +0 -1
- package/src/api/core/geom/arc.ts +0 -7
- package/src/api/core/geom/curve.ts +0 -7
- package/src/api/core/geom/index.ts +0 -25
- package/src/api/core/geom/line.ts +0 -7
- package/src/api/core/geom/profile.ts +0 -17
- package/src/api/core/index.ts +0 -17
- package/src/api/core/math/index.ts +0 -17
- package/src/api/core/math/quat.ts +0 -7
- package/src/api/core/math/vec3.ts +0 -7
- package/src/api/entity/department.ts +0 -30
- package/src/api/entity/index.ts +0 -25
- package/src/api/entity/referenceLine.ts +0 -54
- package/src/api/entity/space.ts +0 -98
- package/src/api/entity/story.ts +0 -66
- package/src/api/tools/copy.ts +0 -10
- package/src/api/tools/index.ts +0 -36
- package/src/api/tools/material.ts +0 -22
- package/src/api/tools/offset.ts +0 -15
- package/src/api/tools/selection.ts +0 -15
- package/src/api/tools/transform.ts +0 -44
- package/src/api/units/index.ts +0 -34
package/dist/index.cjs
CHANGED
|
@@ -30,26 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
ClientArcApi: () => ClientArcApi,
|
|
34
|
-
ClientCoreApi: () => ClientCoreApi,
|
|
35
|
-
ClientCurveApi: () => ClientCurveApi,
|
|
36
|
-
ClientDepartmentApi: () => ClientDepartmentApi,
|
|
37
|
-
ClientEntityApi: () => ClientEntityApi,
|
|
38
|
-
ClientGeomApi: () => ClientGeomApi,
|
|
39
|
-
ClientLineApi: () => ClientLineApi,
|
|
40
|
-
ClientMaterialApi: () => ClientMaterialApi,
|
|
41
|
-
ClientMathApi: () => ClientMathApi,
|
|
42
33
|
ClientPluginApi: () => ClientPluginApi,
|
|
43
|
-
ClientProfileApi: () => ClientProfileApi,
|
|
44
|
-
ClientQuatApi: () => ClientQuatApi,
|
|
45
|
-
ClientReferenceLineApi: () => ClientReferenceLineApi,
|
|
46
|
-
ClientSelectionApi: () => ClientSelectionApi,
|
|
47
|
-
ClientSpaceApi: () => ClientSpaceApi,
|
|
48
|
-
ClientStoryApi: () => ClientStoryApi,
|
|
49
|
-
ClientToolsApi: () => ClientToolsApi,
|
|
50
|
-
ClientTransformApi: () => ClientTransformApi,
|
|
51
|
-
ClientUnitsApi: () => ClientUnitsApi,
|
|
52
|
-
ClientVec3Api: () => ClientVec3Api,
|
|
53
34
|
PluginWorker: () => PluginWorker,
|
|
54
35
|
createHostApi: () => createHostApi,
|
|
55
36
|
getHostApi: () => getHostApi,
|
|
@@ -57,66 +38,8 @@ __export(index_exports, {
|
|
|
57
38
|
});
|
|
58
39
|
module.exports = __toCommonJS(index_exports);
|
|
59
40
|
|
|
60
|
-
// src/api/
|
|
61
|
-
var import_plugin_core9 = require("@snaptrude/plugin-core");
|
|
62
|
-
|
|
63
|
-
// src/api/core/math/index.ts
|
|
64
|
-
var import_plugin_core3 = require("@snaptrude/plugin-core");
|
|
65
|
-
|
|
66
|
-
// src/api/core/math/vec3.ts
|
|
41
|
+
// src/api/index.ts
|
|
67
42
|
var import_plugin_core = require("@snaptrude/plugin-core");
|
|
68
|
-
var ClientVec3Api = class extends import_plugin_core.PluginVec3Api {
|
|
69
|
-
constructor() {
|
|
70
|
-
super();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// src/api/core/math/quat.ts
|
|
75
|
-
var import_plugin_core2 = require("@snaptrude/plugin-core");
|
|
76
|
-
var ClientQuatApi = class extends import_plugin_core2.PluginQuatApi {
|
|
77
|
-
constructor() {
|
|
78
|
-
super();
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/api/core/math/index.ts
|
|
83
|
-
var ClientMathApi = class extends import_plugin_core3.PluginMathApi {
|
|
84
|
-
constructor() {
|
|
85
|
-
super();
|
|
86
|
-
this.vec3 = new ClientVec3Api();
|
|
87
|
-
this.quat = new ClientQuatApi();
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// src/api/core/geom/index.ts
|
|
92
|
-
var import_plugin_core8 = require("@snaptrude/plugin-core");
|
|
93
|
-
|
|
94
|
-
// src/api/core/geom/line.ts
|
|
95
|
-
var import_plugin_core4 = require("@snaptrude/plugin-core");
|
|
96
|
-
var ClientLineApi = class extends import_plugin_core4.PluginLineApi {
|
|
97
|
-
constructor() {
|
|
98
|
-
super();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// src/api/core/geom/arc.ts
|
|
103
|
-
var import_plugin_core5 = require("@snaptrude/plugin-core");
|
|
104
|
-
var ClientArcApi = class extends import_plugin_core5.PluginArcApi {
|
|
105
|
-
constructor() {
|
|
106
|
-
super();
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// src/api/core/geom/curve.ts
|
|
111
|
-
var import_plugin_core6 = require("@snaptrude/plugin-core");
|
|
112
|
-
var ClientCurveApi = class extends import_plugin_core6.PluginCurveApi {
|
|
113
|
-
constructor() {
|
|
114
|
-
super();
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// src/api/core/geom/profile.ts
|
|
119
|
-
var import_plugin_core7 = require("@snaptrude/plugin-core");
|
|
120
43
|
|
|
121
44
|
// src/host-api.ts
|
|
122
45
|
var Comlink = __toESM(require("comlink"), 1);
|
|
@@ -146,383 +69,36 @@ function getHostApi() {
|
|
|
146
69
|
};
|
|
147
70
|
}
|
|
148
71
|
|
|
149
|
-
// src/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// src/api/core/geom/index.ts
|
|
164
|
-
var ClientGeomApi = class extends import_plugin_core8.PluginGeomApi {
|
|
165
|
-
constructor() {
|
|
166
|
-
super();
|
|
167
|
-
this.line = new ClientLineApi();
|
|
168
|
-
this.arc = new ClientArcApi();
|
|
169
|
-
this.curve = new ClientCurveApi();
|
|
170
|
-
this.profile = new ClientProfileApi();
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// src/api/core/index.ts
|
|
175
|
-
var ClientCoreApi = class extends import_plugin_core9.PluginCoreApi {
|
|
176
|
-
constructor() {
|
|
177
|
-
super();
|
|
178
|
-
this.math = new ClientMathApi();
|
|
179
|
-
this.geom = new ClientGeomApi();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
// src/api/entity/index.ts
|
|
184
|
-
var import_plugin_core14 = require("@snaptrude/plugin-core");
|
|
185
|
-
|
|
186
|
-
// src/api/entity/department.ts
|
|
187
|
-
var import_plugin_core10 = require("@snaptrude/plugin-core");
|
|
188
|
-
var ClientDepartmentApi = class extends import_plugin_core10.PluginDepartmentApi {
|
|
189
|
-
constructor() {
|
|
190
|
-
super();
|
|
191
|
-
}
|
|
192
|
-
async create(args) {
|
|
193
|
-
const hostApi = getHostApi();
|
|
194
|
-
return hostApi.call({
|
|
195
|
-
method: "entity.department.create",
|
|
196
|
-
args
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async getAll() {
|
|
200
|
-
const hostApi = getHostApi();
|
|
201
|
-
return hostApi.call({
|
|
202
|
-
method: "entity.department.getAll"
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
// src/api/entity/referenceLine.ts
|
|
208
|
-
var import_plugin_core11 = require("@snaptrude/plugin-core");
|
|
209
|
-
var ClientReferenceLineApi = class extends import_plugin_core11.PluginReferenceLineApi {
|
|
210
|
-
constructor() {
|
|
211
|
-
super();
|
|
212
|
-
}
|
|
213
|
-
async createMulti(args) {
|
|
214
|
-
const hostApi = getHostApi();
|
|
215
|
-
return hostApi.call({
|
|
216
|
-
method: "entity.referenceLine.createMulti",
|
|
217
|
-
args
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
async get(args) {
|
|
221
|
-
const hostApi = getHostApi();
|
|
222
|
-
return hostApi.call({
|
|
223
|
-
method: "entity.referenceLine.get",
|
|
224
|
-
args
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
async getAll() {
|
|
228
|
-
const hostApi = getHostApi();
|
|
229
|
-
return hostApi.call({
|
|
230
|
-
method: "entity.referenceLine.getAll"
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
async delete(args) {
|
|
234
|
-
const hostApi = getHostApi();
|
|
235
|
-
return hostApi.call({
|
|
236
|
-
method: "entity.referenceLine.delete",
|
|
237
|
-
args
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
// src/api/entity/space.ts
|
|
243
|
-
var import_plugin_core12 = require("@snaptrude/plugin-core");
|
|
244
|
-
var ClientSpaceApi = class extends import_plugin_core12.PluginSpaceApi {
|
|
245
|
-
constructor() {
|
|
246
|
-
super();
|
|
247
|
-
}
|
|
248
|
-
async createRectangular({
|
|
249
|
-
position,
|
|
250
|
-
dimensions
|
|
251
|
-
}) {
|
|
252
|
-
const hostApi = getHostApi();
|
|
253
|
-
return hostApi.call({
|
|
254
|
-
method: "entity.space.createRectangular",
|
|
255
|
-
args: {
|
|
256
|
-
position,
|
|
257
|
-
dimensions
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
async createFromProfile({
|
|
262
|
-
profile,
|
|
263
|
-
extrudeHeight,
|
|
264
|
-
position
|
|
265
|
-
}) {
|
|
266
|
-
const hostApi = getHostApi();
|
|
267
|
-
return hostApi.call({
|
|
268
|
-
method: "entity.space.createFromProfile",
|
|
269
|
-
args: {
|
|
270
|
-
profile,
|
|
271
|
-
extrudeHeight,
|
|
272
|
-
position
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
async get({
|
|
277
|
-
spaceId,
|
|
278
|
-
properties
|
|
279
|
-
}) {
|
|
280
|
-
const hostApi = getHostApi();
|
|
281
|
-
return hostApi.call({
|
|
282
|
-
method: "entity.space.get",
|
|
283
|
-
args: {
|
|
284
|
-
spaceId,
|
|
285
|
-
properties
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
async getAll() {
|
|
290
|
-
const hostApi = getHostApi();
|
|
291
|
-
return hostApi.call({
|
|
292
|
-
method: "entity.space.getAll"
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
async delete({
|
|
296
|
-
spaceId
|
|
297
|
-
}) {
|
|
298
|
-
const hostApi = getHostApi();
|
|
299
|
-
return hostApi.call({
|
|
300
|
-
method: "entity.space.delete",
|
|
301
|
-
args: {
|
|
302
|
-
spaceId
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
async update({
|
|
307
|
-
spaceId,
|
|
308
|
-
properties
|
|
309
|
-
}) {
|
|
310
|
-
const hostApi = getHostApi();
|
|
311
|
-
return hostApi.call({
|
|
312
|
-
method: "entity.space.update",
|
|
313
|
-
args: {
|
|
314
|
-
spaceId,
|
|
315
|
-
properties
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
// src/api/entity/story.ts
|
|
322
|
-
var import_plugin_core13 = require("@snaptrude/plugin-core");
|
|
323
|
-
var ClientStoryApi = class extends import_plugin_core13.PluginStoryApi {
|
|
324
|
-
constructor() {
|
|
325
|
-
super();
|
|
326
|
-
}
|
|
327
|
-
async get({
|
|
328
|
-
storyValue,
|
|
329
|
-
properties
|
|
330
|
-
}) {
|
|
331
|
-
const hostApi = getHostApi();
|
|
332
|
-
return hostApi.call({
|
|
333
|
-
method: "entity.story.get",
|
|
334
|
-
args: {
|
|
335
|
-
storyValue,
|
|
336
|
-
properties
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
async getAll() {
|
|
341
|
-
const hostApi = getHostApi();
|
|
342
|
-
return hostApi.call({
|
|
343
|
-
method: "entity.story.getAll"
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
async create({
|
|
347
|
-
storyValue,
|
|
348
|
-
height
|
|
349
|
-
}) {
|
|
350
|
-
const hostApi = getHostApi();
|
|
351
|
-
return hostApi.call({
|
|
352
|
-
method: "entity.story.create",
|
|
353
|
-
args: {
|
|
354
|
-
storyValue,
|
|
355
|
-
height
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
async update({
|
|
360
|
-
storyValue,
|
|
361
|
-
height
|
|
362
|
-
}) {
|
|
363
|
-
const hostApi = getHostApi();
|
|
364
|
-
return hostApi.call({
|
|
365
|
-
method: "entity.story.update",
|
|
366
|
-
args: {
|
|
367
|
-
storyValue,
|
|
368
|
-
height
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
// src/api/entity/index.ts
|
|
375
|
-
var ClientEntityApi = class extends import_plugin_core14.PluginEntityApi {
|
|
376
|
-
constructor() {
|
|
377
|
-
super();
|
|
378
|
-
this.space = new ClientSpaceApi();
|
|
379
|
-
this.story = new ClientStoryApi();
|
|
380
|
-
this.referenceLine = new ClientReferenceLineApi();
|
|
381
|
-
this.department = new ClientDepartmentApi();
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
// src/api/tools/index.ts
|
|
386
|
-
var import_plugin_core18 = require("@snaptrude/plugin-core");
|
|
387
|
-
|
|
388
|
-
// src/api/tools/selection.ts
|
|
389
|
-
var import_plugin_core15 = require("@snaptrude/plugin-core");
|
|
390
|
-
var ClientSelectionApi = class extends import_plugin_core15.PluginSelectionApi {
|
|
391
|
-
constructor() {
|
|
392
|
-
super();
|
|
393
|
-
}
|
|
394
|
-
async get() {
|
|
395
|
-
const hostApi = getHostApi();
|
|
396
|
-
return hostApi.call({
|
|
397
|
-
method: "tools.selection.get"
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
// src/api/tools/transform.ts
|
|
403
|
-
var import_plugin_core16 = require("@snaptrude/plugin-core");
|
|
404
|
-
var ClientTransformApi = class extends import_plugin_core16.PluginTransformApi {
|
|
405
|
-
constructor() {
|
|
406
|
-
super();
|
|
407
|
-
}
|
|
408
|
-
async move({
|
|
409
|
-
componentIds,
|
|
410
|
-
displacement
|
|
411
|
-
}) {
|
|
412
|
-
const hostApi = getHostApi();
|
|
413
|
-
return hostApi.call({
|
|
414
|
-
method: "tools.transform.move",
|
|
415
|
-
args: {
|
|
416
|
-
componentIds,
|
|
417
|
-
displacement
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
async rotate({
|
|
422
|
-
componentIds,
|
|
423
|
-
angle,
|
|
424
|
-
axis,
|
|
425
|
-
pivot
|
|
426
|
-
}) {
|
|
427
|
-
const hostApi = getHostApi();
|
|
428
|
-
return hostApi.call({
|
|
429
|
-
method: "tools.transform.rotate",
|
|
430
|
-
args: {
|
|
431
|
-
componentIds,
|
|
432
|
-
angle,
|
|
433
|
-
axis,
|
|
434
|
-
pivot
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
// src/api/tools/material.ts
|
|
441
|
-
var import_plugin_core17 = require("@snaptrude/plugin-core");
|
|
442
|
-
var ClientMaterialApi = class extends import_plugin_core17.PluginMaterialApi {
|
|
443
|
-
constructor() {
|
|
444
|
-
super();
|
|
445
|
-
}
|
|
446
|
-
async apply({
|
|
447
|
-
materialName,
|
|
448
|
-
componentIds
|
|
449
|
-
}) {
|
|
450
|
-
const hostApi = getHostApi();
|
|
451
|
-
return hostApi.call({
|
|
452
|
-
method: "tools.material.apply",
|
|
453
|
-
args: {
|
|
454
|
-
materialName,
|
|
455
|
-
componentIds
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
// src/api/tools/copy.ts
|
|
462
|
-
async function copy(args) {
|
|
463
|
-
const hostApi = getHostApi();
|
|
464
|
-
return hostApi.call({
|
|
465
|
-
method: "tools.copy",
|
|
466
|
-
args
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// src/api/tools/offset.ts
|
|
471
|
-
async function offset(args) {
|
|
472
|
-
const hostApi = getHostApi();
|
|
473
|
-
return hostApi.call({
|
|
474
|
-
method: "tools.offset",
|
|
475
|
-
args
|
|
72
|
+
// src/rpc-proxy.ts
|
|
73
|
+
function createRpcNamespace(basePath) {
|
|
74
|
+
const build = (path) => new Proxy(NOOP, {
|
|
75
|
+
get(_target, prop) {
|
|
76
|
+
if (typeof prop !== "string" || prop === "then") return void 0;
|
|
77
|
+
return build(`${path}.${prop}`);
|
|
78
|
+
},
|
|
79
|
+
apply(_target, _thisArg, argArray) {
|
|
80
|
+
const payload = {
|
|
81
|
+
method: path,
|
|
82
|
+
args: argArray
|
|
83
|
+
};
|
|
84
|
+
return getHostApi().call(payload);
|
|
85
|
+
}
|
|
476
86
|
});
|
|
87
|
+
return build(basePath);
|
|
477
88
|
}
|
|
478
|
-
|
|
479
|
-
// src/api/tools/index.ts
|
|
480
|
-
var ClientToolsApi = class extends import_plugin_core18.PluginToolsApi {
|
|
481
|
-
constructor() {
|
|
482
|
-
super();
|
|
483
|
-
this.selection = new ClientSelectionApi();
|
|
484
|
-
this.transform = new ClientTransformApi();
|
|
485
|
-
this.material = new ClientMaterialApi();
|
|
486
|
-
}
|
|
487
|
-
async copy(args) {
|
|
488
|
-
return copy(args);
|
|
489
|
-
}
|
|
490
|
-
async offset(args) {
|
|
491
|
-
return offset(args);
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
// src/api/units/index.ts
|
|
496
|
-
var import_plugin_core19 = require("@snaptrude/plugin-core");
|
|
497
|
-
var ClientUnitsApi = class extends import_plugin_core19.PluginUnitsApi {
|
|
498
|
-
constructor() {
|
|
499
|
-
super();
|
|
500
|
-
}
|
|
501
|
-
async convertFrom(args) {
|
|
502
|
-
const hostApi = getHostApi();
|
|
503
|
-
return hostApi.call({
|
|
504
|
-
method: "units.convertFrom",
|
|
505
|
-
args
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
async convertTo(args) {
|
|
509
|
-
const hostApi = getHostApi();
|
|
510
|
-
return hostApi.call({
|
|
511
|
-
method: "units.convertTo",
|
|
512
|
-
args
|
|
513
|
-
});
|
|
514
|
-
}
|
|
89
|
+
var NOOP = () => {
|
|
515
90
|
};
|
|
516
91
|
|
|
517
92
|
// src/api/index.ts
|
|
518
|
-
var
|
|
519
|
-
var ClientPluginApi = class _ClientPluginApi extends import_plugin_core20.PluginApi {
|
|
93
|
+
var ClientPluginApi = class _ClientPluginApi extends import_plugin_core.PluginApi {
|
|
520
94
|
constructor() {
|
|
521
95
|
super();
|
|
522
|
-
this.core =
|
|
523
|
-
this.
|
|
524
|
-
this.entity =
|
|
525
|
-
this.
|
|
96
|
+
this.core = createRpcNamespace("core");
|
|
97
|
+
this.design = createRpcNamespace("design");
|
|
98
|
+
this.entity = createRpcNamespace("entity");
|
|
99
|
+
this.program = createRpcNamespace("program");
|
|
100
|
+
this.presentation = createRpcNamespace("presentation");
|
|
101
|
+
this.analysis = createRpcNamespace("analysis");
|
|
526
102
|
}
|
|
527
103
|
static getInstance() {
|
|
528
104
|
if (!_ClientPluginApi.instance) {
|
|
@@ -594,26 +170,7 @@ var PluginWorker = class {
|
|
|
594
170
|
var snaptrude = ClientPluginApi.getInstance();
|
|
595
171
|
// Annotate the CommonJS export names for ESM import in node:
|
|
596
172
|
0 && (module.exports = {
|
|
597
|
-
ClientArcApi,
|
|
598
|
-
ClientCoreApi,
|
|
599
|
-
ClientCurveApi,
|
|
600
|
-
ClientDepartmentApi,
|
|
601
|
-
ClientEntityApi,
|
|
602
|
-
ClientGeomApi,
|
|
603
|
-
ClientLineApi,
|
|
604
|
-
ClientMaterialApi,
|
|
605
|
-
ClientMathApi,
|
|
606
173
|
ClientPluginApi,
|
|
607
|
-
ClientProfileApi,
|
|
608
|
-
ClientQuatApi,
|
|
609
|
-
ClientReferenceLineApi,
|
|
610
|
-
ClientSelectionApi,
|
|
611
|
-
ClientSpaceApi,
|
|
612
|
-
ClientStoryApi,
|
|
613
|
-
ClientToolsApi,
|
|
614
|
-
ClientTransformApi,
|
|
615
|
-
ClientUnitsApi,
|
|
616
|
-
ClientVec3Api,
|
|
617
174
|
PluginWorker,
|
|
618
175
|
createHostApi,
|
|
619
176
|
getHostApi,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/api/core/index.ts","../src/api/core/math/index.ts","../src/api/core/math/vec3.ts","../src/api/core/math/quat.ts","../src/api/core/geom/index.ts","../src/api/core/geom/line.ts","../src/api/core/geom/arc.ts","../src/api/core/geom/curve.ts","../src/api/core/geom/profile.ts","../src/host-api.ts","../src/api/entity/index.ts","../src/api/entity/department.ts","../src/api/entity/referenceLine.ts","../src/api/entity/space.ts","../src/api/entity/story.ts","../src/api/tools/index.ts","../src/api/tools/selection.ts","../src/api/tools/transform.ts","../src/api/tools/material.ts","../src/api/tools/copy.ts","../src/api/tools/offset.ts","../src/api/units/index.ts","../src/api/index.ts","../src/plugin-worker.ts"],"sourcesContent":["import { ClientPluginApi } from \"./api\"\n\nexport * from \"./api\"\nexport * from \"./host-api\"\nexport * from \"./plugin-worker\"\n\n/**\n * The Snaptrude plugin client API.\n *\n * The main entry point for plugins to interact with the Snaptrude platform.\n */\nexport const snaptrude = ClientPluginApi.getInstance()\n","import { PluginCoreApi } from \"@snaptrude/plugin-core\"\nimport { ClientMathApi } from \"./math\"\nimport { ClientGeomApi } from \"./geom\"\n\nexport class ClientCoreApi extends PluginCoreApi {\n public math: ClientMathApi\n public geom: ClientGeomApi\n\n constructor() {\n super()\n this.math = new ClientMathApi()\n this.geom = new ClientGeomApi()\n }\n}\n\nexport * from \"./math\"\nexport * from \"./geom\"\n","import { PluginMathApi } from \"@snaptrude/plugin-core\"\nimport { ClientVec3Api } from \"./vec3\"\nimport { ClientQuatApi } from \"./quat\"\n\nexport class ClientMathApi extends PluginMathApi {\n public vec3: ClientVec3Api\n public quat: ClientQuatApi\n\n constructor() {\n super()\n this.vec3 = new ClientVec3Api()\n this.quat = new ClientQuatApi()\n }\n}\n\nexport * from \"./vec3\"\nexport * from \"./quat\"\n","import { PluginVec3Api } from \"@snaptrude/plugin-core\"\n\nexport class ClientVec3Api extends PluginVec3Api {\n constructor() {\n super()\n }\n}\n","import { PluginQuatApi } from \"@snaptrude/plugin-core\"\n\nexport class ClientQuatApi extends PluginQuatApi {\n constructor() {\n super()\n }\n}\n","import { PluginGeomApi } from \"@snaptrude/plugin-core\"\nimport { ClientLineApi } from \"./line\"\nimport { ClientArcApi } from \"./arc\"\nimport { ClientCurveApi } from \"./curve\"\nimport { ClientProfileApi } from \"./profile\"\n\nexport class ClientGeomApi extends PluginGeomApi {\n public line: ClientLineApi\n public arc: ClientArcApi\n public curve: ClientCurveApi\n public profile: ClientProfileApi\n\n constructor() {\n super()\n this.line = new ClientLineApi()\n this.arc = new ClientArcApi()\n this.curve = new ClientCurveApi()\n this.profile = new ClientProfileApi()\n }\n}\n\nexport * from \"./line\"\nexport * from \"./arc\"\nexport * from \"./curve\"\nexport * from \"./profile\"\n","import { PluginLineApi } from \"@snaptrude/plugin-core\"\n\nexport class ClientLineApi extends PluginLineApi {\n constructor() {\n super()\n }\n}\n","import { PluginArcApi } from \"@snaptrude/plugin-core\"\n\nexport class ClientArcApi extends PluginArcApi {\n constructor() {\n super()\n }\n}\n","import { PluginCurveApi } from \"@snaptrude/plugin-core\"\n\nexport class ClientCurveApi extends PluginCurveApi {\n constructor() {\n super()\n }\n}\n","import { PluginProfileApi } from \"@snaptrude/plugin-core\"\nimport type { PProfile, PluginProfileFromLinePointsArgs } from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../../host-api\"\n\nexport class ClientProfileApi extends PluginProfileApi {\n constructor() {\n super()\n }\n\n public async fromLinePoints(args: PluginProfileFromLinePointsArgs): Promise<PProfile> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"core.geom.profile.fromLinePoints\",\n args,\n })\n }\n}\n","import * as Comlink from \"comlink\"\nimport type {\n PluginApiMethod,\n PluginApiCallPayload,\n PluginApiCallWrappedResult,\n PluginApiCallResult,\n} from \"@snaptrude/plugin-core\"\n\nexport interface HostApi {\n call<M extends PluginApiMethod>(\n payload: PluginApiCallPayload<M>\n ): Promise<PluginApiCallWrappedResult<M>>\n}\n\nexport interface HostApiWrapped {\n call<M extends PluginApiMethod>(\n payload: PluginApiCallPayload<M>\n ): Promise<PluginApiCallResult<M>>\n}\n\nexport function createHostApi(endpoint?: Comlink.Endpoint): HostApi {\n return Comlink.wrap<HostApi>(\n endpoint ?? (globalThis as unknown as Comlink.Endpoint)\n ) as unknown as HostApi\n}\n\nlet _instance: HostApi | null = null\n\nexport function getHostApi(): HostApiWrapped {\n if (!_instance) {\n _instance = createHostApi()\n }\n return {\n call: async <M extends PluginApiMethod>(payload: PluginApiCallPayload<M>): Promise<PluginApiCallResult<M>> => {\n if (!_instance) {\n throw new Error(\"Host API not initialized\")\n }\n return _instance.call(payload).then(result => {\n if (result.success) {\n return result.data\n } else {\n throw new Error(result.error)\n }\n })\n }\n }\n}\n","import { PluginEntityApi } from \"@snaptrude/plugin-core\"\nimport { ClientDepartmentApi } from \"./department\"\nimport { ClientReferenceLineApi } from \"./referenceLine\"\nimport { ClientSpaceApi } from \"./space\"\nimport { ClientStoryApi } from \"./story\"\n\nexport class ClientEntityApi extends PluginEntityApi {\n public space: ClientSpaceApi\n public story: ClientStoryApi\n public referenceLine: ClientReferenceLineApi\n public department: ClientDepartmentApi\n\n constructor() {\n super()\n this.space = new ClientSpaceApi()\n this.story = new ClientStoryApi()\n this.referenceLine = new ClientReferenceLineApi()\n this.department = new ClientDepartmentApi()\n }\n}\n\nexport * from \"./department\"\nexport * from \"./referenceLine\"\nexport * from \"./space\"\nexport * from \"./story\"\n","import {\n PluginDepartmentApi,\n PluginDepartmentCreateArgs,\n PluginDepartmentCreateResult,\n PluginDepartmentGetAllResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientDepartmentApi extends PluginDepartmentApi {\n constructor() {\n super()\n }\n\n public async create(\n args: PluginDepartmentCreateArgs\n ): Promise<PluginDepartmentCreateResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.department.create\",\n args,\n })\n }\n\n public async getAll(): Promise<PluginDepartmentGetAllResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.department.getAll\",\n })\n }\n}\n","import {\n PluginReferenceLineApi,\n PluginReferenceLineCreateMultiArgs,\n PluginReferenceLineCreateMultiResult,\n PluginReferenceLineGetArgs,\n PluginReferenceLineGetResult,\n PluginReferenceLineGetAllResult,\n PluginReferenceLineDeleteArgs,\n PluginReferenceLineDeleteResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientReferenceLineApi extends PluginReferenceLineApi {\n constructor() {\n super()\n }\n\n public async createMulti(\n args: PluginReferenceLineCreateMultiArgs\n ): Promise<PluginReferenceLineCreateMultiResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.referenceLine.createMulti\",\n args,\n })\n }\n\n public async get(\n args: PluginReferenceLineGetArgs\n ): Promise<PluginReferenceLineGetResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.referenceLine.get\",\n args,\n })\n }\n\n public async getAll(): Promise<PluginReferenceLineGetAllResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.referenceLine.getAll\",\n })\n }\n\n public async delete(\n args: PluginReferenceLineDeleteArgs\n ): Promise<PluginReferenceLineDeleteResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.referenceLine.delete\",\n args,\n })\n }\n}\n","import {\n PluginSpaceApi,\n PluginSpaceCreateRectangularArgs,\n PluginSpaceCreateRectangularResult,\n PluginSpaceCreateFromProfileArgs,\n PluginSpaceCreateFromProfileResult,\n PluginSpaceDeleteArgs,\n PluginSpaceDeleteResult,\n PluginSpaceGetArgs,\n PluginSpaceGetResult,\n PluginSpaceGetAllResult,\n PluginSpaceUpdateArgs,\n PluginSpaceUpdateResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientSpaceApi extends PluginSpaceApi {\n constructor() {\n super()\n }\n\n public async createRectangular({\n position,\n dimensions,\n }: PluginSpaceCreateRectangularArgs): Promise<PluginSpaceCreateRectangularResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.createRectangular\",\n args: {\n position,\n dimensions,\n },\n })\n }\n\n public async createFromProfile({\n profile,\n extrudeHeight,\n position,\n }: PluginSpaceCreateFromProfileArgs): Promise<PluginSpaceCreateFromProfileResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.createFromProfile\",\n args: {\n profile,\n extrudeHeight,\n position,\n },\n })\n }\n\n public async get({\n spaceId,\n properties,\n }: PluginSpaceGetArgs): Promise<PluginSpaceGetResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.get\",\n args: {\n spaceId,\n properties,\n },\n })\n }\n\n public async getAll(): Promise<PluginSpaceGetAllResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.getAll\",\n })\n }\n\n public async delete({\n spaceId,\n }: PluginSpaceDeleteArgs): Promise<PluginSpaceDeleteResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.delete\",\n args: {\n spaceId,\n },\n })\n }\n\n public async update({\n spaceId,\n properties,\n }: PluginSpaceUpdateArgs): Promise<PluginSpaceUpdateResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.update\",\n args: {\n spaceId,\n properties,\n },\n })\n }\n}\n","import {\n PluginStoryApi,\n PluginStoryGetArgs,\n PluginStoryGetResult,\n PluginStoryGetAllResult,\n PluginStoryCreateArgs,\n PluginStoryCreateResult,\n PluginStoryUpdateArgs,\n PluginStoryUpdateResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientStoryApi extends PluginStoryApi {\n constructor() {\n super()\n }\n\n public async get({\n storyValue,\n properties,\n }: PluginStoryGetArgs): Promise<PluginStoryGetResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.story.get\",\n args: {\n storyValue,\n properties,\n },\n })\n }\n\n public async getAll(): Promise<PluginStoryGetAllResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.story.getAll\",\n })\n }\n\n public async create({\n storyValue,\n height,\n }: PluginStoryCreateArgs): Promise<PluginStoryCreateResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.story.create\",\n args: {\n storyValue,\n height,\n },\n })\n }\n\n public async update({\n storyValue,\n height,\n }: PluginStoryUpdateArgs): Promise<PluginStoryUpdateResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.story.update\",\n args: {\n storyValue,\n height,\n },\n })\n }\n}\n","import { PluginToolsApi } from \"@snaptrude/plugin-core\"\nimport type {\n PluginCopyArgs,\n PluginCopyResult,\n PluginOffsetArgs,\n PluginOffsetResult,\n} from \"@snaptrude/plugin-core\"\nimport { ClientSelectionApi } from \"./selection\"\nimport { ClientTransformApi } from \"./transform\"\nimport { ClientMaterialApi } from \"./material\"\nimport { copy } from \"./copy\"\nimport { offset } from \"./offset\"\n\nexport class ClientToolsApi extends PluginToolsApi {\n public selection: ClientSelectionApi\n public transform: ClientTransformApi\n public material: ClientMaterialApi\n constructor() {\n super()\n this.selection = new ClientSelectionApi()\n this.transform = new ClientTransformApi()\n this.material = new ClientMaterialApi()\n }\n\n public async copy(args: PluginCopyArgs): Promise<PluginCopyResult> {\n return copy(args)\n }\n\n public async offset(args: PluginOffsetArgs): Promise<PluginOffsetResult> {\n return offset(args)\n }\n}\n\nexport * from \"./selection\"\nexport * from \"./transform\"\nexport * from \"./material\"","import { PluginSelectionApi, PluginSelectionGetResult } from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientSelectionApi extends PluginSelectionApi {\n constructor() {\n super()\n }\n\n public async get(): Promise<PluginSelectionGetResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.selection.get\",\n })\n }\n}\n","import {\n PluginTransformApi,\n PluginMoveArgs,\n PluginRotateArgs,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientTransformApi extends PluginTransformApi {\n constructor() {\n super()\n }\n\n public async move({\n componentIds,\n displacement,\n }: PluginMoveArgs): Promise<void> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.transform.move\",\n args: {\n componentIds,\n displacement,\n },\n })\n }\n\n public async rotate({\n componentIds,\n angle,\n axis,\n pivot,\n }: PluginRotateArgs): Promise<void> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.transform.rotate\",\n args: {\n componentIds,\n angle,\n axis,\n pivot,\n },\n })\n }\n}\n","import { PluginMaterialApi, PluginMaterialArgs } from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientMaterialApi extends PluginMaterialApi {\n constructor() {\n super()\n }\n\n public async apply({\n materialName,\n componentIds,\n }: PluginMaterialArgs): Promise<void> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.material.apply\",\n args: {\n materialName,\n componentIds,\n },\n })\n }\n}\n","import type { PluginCopyArgs, PluginCopyResult } from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport async function copy(args: PluginCopyArgs): Promise<PluginCopyResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.copy\",\n args,\n })\n}\n","import type {\n PluginOffsetArgs,\n PluginOffsetResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport async function offset(\n args: PluginOffsetArgs,\n): Promise<PluginOffsetResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.offset\",\n args,\n })\n}\n","import {\n PluginUnitsApi,\n PluginUnitsConvertFromArgs,\n PluginUnitsConvertFromResult,\n PluginUnitsConvertToArgs,\n PluginUnitsConvertToResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientUnitsApi extends PluginUnitsApi {\n constructor() {\n super()\n }\n\n public async convertFrom(\n args: PluginUnitsConvertFromArgs,\n ): Promise<PluginUnitsConvertFromResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"units.convertFrom\",\n args,\n })\n }\n\n public async convertTo(\n args: PluginUnitsConvertToArgs,\n ): Promise<PluginUnitsConvertToResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"units.convertTo\",\n args,\n })\n }\n}\n","import { ClientCoreApi } from \"./core\"\nimport { ClientEntityApi } from \"./entity\"\nimport { ClientToolsApi } from \"./tools\"\nimport { ClientUnitsApi } from \"./units\"\nimport { PluginApi } from \"@snaptrude/plugin-core\"\n\nexport class ClientPluginApi extends PluginApi {\n private static instance: ClientPluginApi\n\n public core: ClientCoreApi\n public tools: ClientToolsApi\n public entity: ClientEntityApi\n public units: ClientUnitsApi\n\n private constructor() {\n super()\n this.core = new ClientCoreApi()\n this.tools = new ClientToolsApi()\n this.entity = new ClientEntityApi()\n this.units = new ClientUnitsApi()\n }\n\n static getInstance(): ClientPluginApi {\n if (!ClientPluginApi.instance) {\n ClientPluginApi.instance = new ClientPluginApi()\n }\n return ClientPluginApi.instance\n }\n}\n\nexport * from \"./core\"\nexport * from \"./entity\"\nexport * from \"./tools\"\nexport * from \"./units\"\n","import * as Comlink from \"comlink\"\n\nexport interface UIMessage {\n action: string\n payload: unknown\n}\n\ninterface PluginConfig {\n pluginId: string\n}\n\n/**\n * Base class for Snaptrude plugin workers.\n *\n * Handles Comlink wiring, host communication, and the standard lifecycle\n * methods (`init`, `destroy`, `ping`, `onUIMessage`). Subclass this and\n * override only the methods you need — then call `start()` to expose the\n * worker API.\n *\n * The plugin ID is received automatically from the host during\n * initialization — no need to pass it manually.\n *\n * @example\n * ```ts\n * import { PluginWorker } from \"@snaptrude/plugin-client\";\n *\n * class MyPlugin extends PluginWorker {\n * async onUIMessage(message: UIMessage) {\n * // handle messages from the UI panel\n * }\n * }\n *\n * new MyPlugin().start();\n * ```\n */\nexport abstract class PluginWorker {\n protected pluginId!: string\n private hostAPI: Comlink.Remote<Record<string, unknown>>\n\n constructor() {\n this.hostAPI = Comlink.wrap<Record<string, unknown>>(\n self as unknown as Comlink.Endpoint\n )\n }\n\n protected sendToUI(action: string, payload: unknown): void {\n ;(this.hostAPI as Record<string, any>).ui.sendToUI({ action, payload })\n }\n\n /**\n * Signal the host that this plugin has finished its work and should be\n * stopped. Use this in headless (UI-less) plugins that run a task and\n * self-terminate.\n */\n protected complete(): void {\n ;(this.hostAPI as Record<string, any>).lifecycle.complete()\n }\n\n async init(): Promise<void> {\n console.log(this.pluginId, \"init() called\")\n console.log(this.pluginId, \"Initialization complete\")\n }\n\n async destroy(): Promise<void> {\n console.log(this.pluginId, \"destroy() called — cleaning up\")\n }\n\n async ping(): Promise<string> {\n return \"pong\"\n }\n\n async onUIMessage(_message: UIMessage): Promise<void> {\n // Override in subclass to handle UI messages\n }\n\n /**\n * Expose the worker API via Comlink and start listening.\n * Call this once after constructing the plugin instance.\n *\n * The host calls `init(config)` with `{ pluginId }`,\n * which is captured here to set `this.pluginId` before the\n * subclass's `init()` runs.\n */\n start(): void {\n Comlink.expose(\n {\n init: (config: PluginConfig) => {\n this.pluginId = config.pluginId\n return this.init()\n },\n destroy: () => this.destroy(),\n ping: () => this.ping(),\n onUIMessage: (message: UIMessage) => this.onUIMessage(message),\n },\n self as unknown as Comlink.Endpoint\n )\n console.log(\"Worker loaded, API exposed via Comlink\")\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,sBAA8B;;;ACA9B,IAAAC,sBAA8B;;;ACA9B,yBAA8B;AAEvB,IAAM,gBAAN,cAA4B,iCAAc;AAAA,EAC/C,cAAc;AACZ,UAAM;AAAA,EACR;AACF;;;ACNA,IAAAC,sBAA8B;AAEvB,IAAM,gBAAN,cAA4B,kCAAc;AAAA,EAC/C,cAAc;AACZ,UAAM;AAAA,EACR;AACF;;;AFFO,IAAM,gBAAN,cAA4B,kCAAc;AAAA,EAI/C,cAAc;AACZ,UAAM;AACN,SAAK,OAAO,IAAI,cAAc;AAC9B,SAAK,OAAO,IAAI,cAAc;AAAA,EAChC;AACF;;;AGbA,IAAAC,sBAA8B;;;ACA9B,IAAAC,sBAA8B;AAEvB,IAAM,gBAAN,cAA4B,kCAAc;AAAA,EAC/C,cAAc;AACZ,UAAM;AAAA,EACR;AACF;;;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GAAG,SAAS,EAAE,QAAQ,QAAQ,CAAC;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,WAAiB;AACzB;AAAC,IAAC,KAAK,QAAgC,UAAU,SAAS;AAAA,EAC5D;AAAA,EAEA,MAAM,OAAsB;AAC1B,YAAQ,IAAI,KAAK,UAAU,eAAe;AAC1C,YAAQ,IAAI,KAAK,UAAU,yBAAyB;AAAA,EACtD;AAAA,EAEA,MAAM,UAAyB;AAC7B,YAAQ,IAAI,KAAK,UAAU,qCAAgC;AAAA,EAC7D;AAAA,EAEA,MAAM,OAAwB;AAC5B,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,YAAY,UAAoC;AAAA,EAEtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,QAAc;AACZ,IAAQ;AAAA,MACN;AAAA,QACE,MAAM,CAAC,WAAyB;AAC9B,eAAK,WAAW,OAAO;AACvB,iBAAO,KAAK,KAAK;AAAA,QACnB;AAAA,QACA,SAAS,MAAM,KAAK,QAAQ;AAAA,QAC5B,MAAM,MAAM,KAAK,KAAK;AAAA,QACtB,aAAa,CAAC,YAAuB,KAAK,YAAY,OAAO;AAAA,MAC/D;AAAA,MACA;AAAA,IACF;AACA,YAAQ,IAAI,wCAAwC;AAAA,EACtD;AACF;;;AxBvFO,IAAM,YAAY,gBAAgB,YAAY;","names":["import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","Comlink"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api/index.ts","../src/host-api.ts","../src/rpc-proxy.ts","../src/plugin-worker.ts"],"sourcesContent":["import { ClientPluginApi } from \"./api\"\n\nexport * from \"./api\"\nexport * from \"./host-api\"\nexport * from \"./plugin-worker\"\n\n/**\n * The Snaptrude plugin client API.\n *\n * The main entry point for plugins to interact with the Snaptrude platform.\n */\nexport const snaptrude = ClientPluginApi.getInstance()\n","import {\n PluginApi,\n PluginCoreApi,\n PluginDesignApi,\n PluginEntityApi,\n PluginProgramApi,\n PluginPresentationApi,\n PluginAnalysisApi,\n} from \"@snaptrude/plugin-core\"\nimport { createRpcNamespace } from \"../rpc-proxy\"\n\nexport class ClientPluginApi extends PluginApi {\n private static instance: ClientPluginApi\n\n /**\n * Every namespace is fully remote under the all-handle model: math/geom now\n * cross to the host (values are opaque handles), so there is no in-worker\n * compute left. All dispatch through a single generic RPC Proxy. Units live\n * under `core.units`, so they ride the `core` proxy.\n */\n public core: PluginCoreApi\n public design: PluginDesignApi\n public entity: PluginEntityApi\n public program: PluginProgramApi\n public presentation: PluginPresentationApi\n public analysis: PluginAnalysisApi\n\n private constructor() {\n super()\n this.core = createRpcNamespace<PluginCoreApi>(\"core\")\n this.design = createRpcNamespace<PluginDesignApi>(\"design\")\n this.entity = createRpcNamespace<PluginEntityApi>(\"entity\")\n this.program = createRpcNamespace<PluginProgramApi>(\"program\")\n this.presentation =\n createRpcNamespace<PluginPresentationApi>(\"presentation\")\n this.analysis = createRpcNamespace<PluginAnalysisApi>(\"analysis\")\n }\n\n static getInstance(): ClientPluginApi {\n if (!ClientPluginApi.instance) {\n ClientPluginApi.instance = new ClientPluginApi()\n }\n return ClientPluginApi.instance\n }\n}\n","import * as Comlink from \"comlink\"\nimport type {\n PluginApiMethod,\n PluginApiCallPayload,\n PluginApiCallWrappedResult,\n PluginApiCallResult,\n} from \"@snaptrude/plugin-core\"\n\nexport interface HostApi {\n call<M extends PluginApiMethod>(\n payload: PluginApiCallPayload<M>\n ): Promise<PluginApiCallWrappedResult<M>>\n}\n\nexport interface HostApiWrapped {\n call<M extends PluginApiMethod>(\n payload: PluginApiCallPayload<M>\n ): Promise<PluginApiCallResult<M>>\n}\n\nexport function createHostApi(endpoint?: Comlink.Endpoint): HostApi {\n return Comlink.wrap<HostApi>(\n endpoint ?? (globalThis as unknown as Comlink.Endpoint)\n ) as unknown as HostApi\n}\n\nlet _instance: HostApi | null = null\n\nexport function getHostApi(): HostApiWrapped {\n if (!_instance) {\n _instance = createHostApi()\n }\n return {\n call: async <M extends PluginApiMethod>(payload: PluginApiCallPayload<M>): Promise<PluginApiCallResult<M>> => {\n if (!_instance) {\n throw new Error(\"Host API not initialized\")\n }\n return _instance.call(payload).then(result => {\n if (result.success) {\n return result.data\n } else {\n throw new Error(result.error)\n }\n })\n }\n }\n}\n","import type {\n PluginApiCallPayload,\n PluginApiMethod,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"./host-api\"\n\n/**\n * Build a namespace object whose nested property access maps to a\n * dot-separated host RPC method path, and whose every call dispatches that\n * path through the host bridge.\n *\n * The host exposes the entire plugin API behind a single generic `call()`\n * (see the host `bridge.ts`), and the method string is exactly the property\n * path — so one Proxy replaces every hand-written per-method RPC wrapper for\n * every namespace (`core.*`, `design.*`, `entity.*`):\n *\n * The POSITIONAL transport forwards the whole argument tuple; the host router\n * spreads it back into the resolved method (`fn(...args)`):\n *\n * ```ts\n * snaptrude.core.math.vec3.new(1, 2, 3)\n * // → getHostApi().call({ method: \"core.math.vec3.new\", args: [1, 2, 3] })\n * ```\n *\n * Typed at the call site, e.g. `createRpcNamespace<PluginEntityApi>(\"entity\")`.\n * The Proxy is structurally cast to the abstract API type — argument and\n * return types are enforced by that type, while dispatch is dynamic.\n *\n * Every namespace uses this — including `core.math.*` and `core.geom.*`: under\n * the all-handle model there is no in-worker compute; math and geometry are\n * host calls like everything else.\n */\nexport function createRpcNamespace<T extends object>(basePath: string): T {\n const build = (path: string): unknown =>\n new Proxy(NOOP, {\n get(_target, prop) {\n // Symbols and `then` must not resolve to a callable proxy, otherwise\n // the namespace would look thenable and break Promise resolution if it\n // ever reached an `await`.\n if (typeof prop !== \"string\" || prop === \"then\") return undefined\n return build(`${path}.${prop}`)\n },\n apply(_target, _thisArg, argArray: unknown[]) {\n const payload = {\n method: path,\n args: argArray,\n } as unknown as PluginApiCallPayload<PluginApiMethod>\n return getHostApi().call(payload)\n },\n })\n\n return build(basePath) as T\n}\n\n/** Proxy target must be callable for the `apply` trap; identity is irrelevant. */\nconst NOOP = (): void => {}\n","import * as Comlink from \"comlink\"\n\nexport interface UIMessage {\n action: string\n payload: unknown\n}\n\ninterface PluginConfig {\n pluginId: string\n}\n\n/**\n * Base class for Snaptrude plugin workers.\n *\n * Handles Comlink wiring, host communication, and the standard lifecycle\n * methods (`init`, `destroy`, `ping`, `onUIMessage`). Subclass this and\n * override only the methods you need — then call `start()` to expose the\n * worker API.\n *\n * The plugin ID is received automatically from the host during\n * initialization — no need to pass it manually.\n *\n * @example\n * ```ts\n * import { PluginWorker } from \"@snaptrude/plugin-client\";\n *\n * class MyPlugin extends PluginWorker {\n * async onUIMessage(message: UIMessage) {\n * // handle messages from the UI panel\n * }\n * }\n *\n * new MyPlugin().start();\n * ```\n */\nexport abstract class PluginWorker {\n protected pluginId!: string\n private hostAPI: Comlink.Remote<Record<string, unknown>>\n\n constructor() {\n this.hostAPI = Comlink.wrap<Record<string, unknown>>(\n self as unknown as Comlink.Endpoint\n )\n }\n\n protected sendToUI(action: string, payload: unknown): void {\n ;(this.hostAPI as Record<string, any>).ui.sendToUI({ action, payload })\n }\n\n /**\n * Signal the host that this plugin has finished its work and should be\n * stopped. Use this in headless (UI-less) plugins that run a task and\n * self-terminate.\n */\n protected complete(): void {\n ;(this.hostAPI as Record<string, any>).lifecycle.complete()\n }\n\n async init(): Promise<void> {\n console.log(this.pluginId, \"init() called\")\n console.log(this.pluginId, \"Initialization complete\")\n }\n\n async destroy(): Promise<void> {\n console.log(this.pluginId, \"destroy() called — cleaning up\")\n }\n\n async ping(): Promise<string> {\n return \"pong\"\n }\n\n async onUIMessage(_message: UIMessage): Promise<void> {\n // Override in subclass to handle UI messages\n }\n\n /**\n * Expose the worker API via Comlink and start listening.\n * Call this once after constructing the plugin instance.\n *\n * The host calls `init(config)` with `{ pluginId }`,\n * which is captured here to set `this.pluginId` before the\n * subclass's `init()` runs.\n */\n start(): void {\n Comlink.expose(\n {\n init: (config: PluginConfig) => {\n this.pluginId = config.pluginId\n return this.init()\n },\n destroy: () => this.destroy(),\n ping: () => this.ping(),\n onUIMessage: (message: UIMessage) => this.onUIMessage(message),\n },\n self as unknown as Comlink.Endpoint\n )\n console.log(\"Worker loaded, API exposed via Comlink\")\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAQO;;;ACRP,cAAyB;AAoBlB,SAAS,cAAc,UAAsC;AAClE,SAAe;AAAA,IACb,YAAa;AAAA,EACf;AACF;AAEA,IAAI,YAA4B;AAEzB,SAAS,aAA6B;AAC3C,MAAI,CAAC,WAAW;AACd,gBAAY,cAAc;AAAA,EAC5B;AACA,SAAO;AAAA,IACL,MAAM,OAAkC,YAAsE;AAC5G,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AACA,aAAO,UAAU,KAAK,OAAO,EAAE,KAAK,YAAU;AAC5C,YAAI,OAAO,SAAS;AAClB,iBAAO,OAAO;AAAA,QAChB,OAAO;AACL,gBAAM,IAAI,MAAM,OAAO,KAAK;AAAA,QAC9B;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;;;ACdO,SAAS,mBAAqC,UAAqB;AACxE,QAAM,QAAQ,CAAC,SACb,IAAI,MAAM,MAAM;AAAA,IACd,IAAI,SAAS,MAAM;AAIjB,UAAI,OAAO,SAAS,YAAY,SAAS,OAAQ,QAAO;AACxD,aAAO,MAAM,GAAG,IAAI,IAAI,IAAI,EAAE;AAAA,IAChC;AAAA,IACA,MAAM,SAAS,UAAU,UAAqB;AAC5C,YAAM,UAAU;AAAA,QACd,QAAQ;AAAA,QACR,MAAM;AAAA,MACR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