@buerli.io/core 2.0.0-beta.20261017202221 → 2.0.0-beta.20261018104453

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.
Files changed (73) hide show
  1. package/build/cjs/geometry/ThreeGeometryCreator.js +96 -10
  2. package/build/cjs/graphic/filters.js +100 -0
  3. package/build/cjs/index.js +60 -0
  4. package/build/cjs/store/index.js +102 -1
  5. package/build/cjs/store/states/buerli.js +1 -2
  6. package/build/cjs/store/states/cad.js +32 -0
  7. package/build/cjs/store/states/geometry.js +50 -3
  8. package/build/cjs/store/states/graphic.js +17 -0
  9. package/build/cjs/store/states/interaction.js +9 -9
  10. package/build/cjs/store/states/message.js +5 -0
  11. package/build/cjs/store/states/plugin.js +34 -0
  12. package/build/cjs/store/states/selection.js +117 -0
  13. package/build/cjs/store/states/structure.js +57 -4
  14. package/build/cjs/store/store.js +24 -0
  15. package/build/cjs/store/subscribtion/subscribeToDrawing.js +26 -0
  16. package/build/cjs/types/InteractionInfo.js +23 -0
  17. package/build/cjs/types/index.js +3 -2
  18. package/build/cjs/utils/Math.js +50 -7
  19. package/build/cjs/utils/Measure.js +99 -0
  20. package/build/cjs/utils/Timing.js +44 -0
  21. package/build/esm/geometry/ThreeGeometryCreator.js +96 -10
  22. package/build/esm/graphic/filters.js +100 -0
  23. package/build/esm/index.js +60 -0
  24. package/build/esm/re-export.js +10 -10
  25. package/build/esm/store/index.js +102 -1
  26. package/build/esm/store/states/buerli.js +1 -2
  27. package/build/esm/store/states/cad.js +32 -0
  28. package/build/esm/store/states/geometry.js +50 -3
  29. package/build/esm/store/states/graphic.js +17 -0
  30. package/build/esm/store/states/interaction.js +9 -9
  31. package/build/esm/store/states/message.js +5 -0
  32. package/build/esm/store/states/plugin.js +34 -0
  33. package/build/esm/store/states/selection.js +117 -0
  34. package/build/esm/store/states/structure.js +57 -4
  35. package/build/esm/store/store.js +24 -0
  36. package/build/esm/store/subscribtion/subscribeToDrawing.js +26 -0
  37. package/build/esm/types/InteractionInfo.js +23 -0
  38. package/build/esm/types/index.js +3 -2
  39. package/build/esm/utils/Math.js +50 -7
  40. package/build/esm/utils/Measure.js +99 -0
  41. package/build/esm/utils/Timing.js +44 -0
  42. package/build/types/geometry/ThreeGeometryCreator.d.ts +400 -1
  43. package/build/types/graphic/filters.d.ts +100 -0
  44. package/build/types/index.d.ts +102 -0
  45. package/build/types/re-export.d.ts +33 -33
  46. package/build/types/store/index.d.ts +102 -1
  47. package/build/types/store/states/buerli.d.ts +108 -0
  48. package/build/types/store/states/cad.d.ts +71 -0
  49. package/build/types/store/states/drawing.d.ts +98 -0
  50. package/build/types/store/states/geometry.d.ts +125 -3
  51. package/build/types/store/states/graphic.d.ts +26 -0
  52. package/build/types/store/states/interaction.d.ts +17 -9
  53. package/build/types/store/states/message.d.ts +48 -0
  54. package/build/types/store/states/plugin.d.ts +142 -2
  55. package/build/types/store/states/selection.d.ts +245 -6
  56. package/build/types/store/states/structure.d.ts +67 -4
  57. package/build/types/store/store.d.ts +24 -0
  58. package/build/types/store/subscribtion/subscribeToDrawing.d.ts +26 -0
  59. package/build/types/types/InteractionInfo.d.ts +52 -14
  60. package/build/types/types/index.d.ts +3 -2
  61. package/build/types/utils/Math.d.ts +50 -7
  62. package/build/types/utils/Measure.d.ts +158 -0
  63. package/build/types/utils/Timing.d.ts +19 -0
  64. package/doc/api/advanced/measure.md +237 -0
  65. package/doc/api/advanced/plugins.md +217 -0
  66. package/doc/api/advanced/utilities.md +84 -0
  67. package/doc/api/drawings.md +355 -0
  68. package/doc/api/geometry.md +510 -0
  69. package/doc/api/index.md +52 -0
  70. package/doc/api/messages.md +126 -0
  71. package/doc/api/selection.md +593 -0
  72. package/package.json +4 -3
  73. package/typedoc.json +8 -0
@@ -52,7 +52,10 @@ const convertType = (contType) => {
52
52
  return type;
53
53
  };
54
54
  /**
55
- * Creates THREE geometry based on the data within a @see IGraphicContainer.
55
+ * Makes the three.js geometry of a graphic container (`ScgGraphicContainer`): what `geometry.cache` of a drawing
56
+ * holds.
57
+ *
58
+ * @internal
56
59
  */
57
60
  class ThreeGeometryCreator {
58
61
  constructor() {
@@ -69,11 +72,24 @@ class ThreeGeometryCreator {
69
72
  const rgbColor = color ? new THREE.Color(`rgb(${color[0]}, ${color[1]}, ${color[2]})`) : undefined;
70
73
  const layer = geomProps && geomProps.layer ? geomProps.layer : container.properties.layer;
71
74
  return {
75
+ /** The color ClassCAD gave it (its material), if any. */
72
76
  color: rgbColor,
77
+ /** The opacity ClassCAD gave it, from 0 to 1; `0` when it has none. */
73
78
  opacity,
79
+ /** The layer ClassCAD put it on. */
74
80
  layer,
81
+ /**
82
+ * The container (solid) it is in.
83
+ *
84
+ * @privateRemarks `@property __type.<name>` documents a field of the object type that is written on one line.
85
+ * @property __type.id - The container's id, the solid's CAD entity, as in `geometry.cache`.
86
+ * @property __type.ownerId - The solid object it belongs to, in the structure tree.
87
+ * @property __type.type - What kind of container: `brep`, `polyBrep` or `curveArray`.
88
+ */
75
89
  container: { id: container.id, ownerId: container.owner, type: convertType(container.type) },
90
+ /** The operation (feature) that made a face. */
76
91
  operationId: (_a = geometry === null || geometry === void 0 ? void 0 : geometry.properties) === null || _a === void 0 ? void 0 : _a.operationId,
92
+ /** The element as ClassCAD sent it (`ScgGraphicElement`). */
77
93
  rawGraphic: geometry,
78
94
  };
79
95
  }
@@ -161,9 +177,15 @@ class ThreeGeometryCreator {
161
177
  mesh.normals && geometry.setAttribute('normal', new THREE.Float32BufferAttribute(mesh.normals, 3));
162
178
  return Object.assign({
163
179
  // TODO: The server should not send invalid meshes.
164
- isValid: mesh.vertices && mesh.vertices.length > 0, geometry,
180
+ /** Whether the face has vertices; faces without are left out. */
181
+ isValid: mesh.vertices && mesh.vertices.length > 0,
182
+ /** The face's triangles, with normals. */
183
+ geometry,
184
+ /** The face's id in its container. */
165
185
  graphicId,
186
+ /** The kind of face: `plane`, `cylinder`, `cone`, `sphere` or `nurbsSurface`. */
166
187
  type,
188
+ /** The loops of edges around the face, each a list of edge ids. */
167
189
  loops }, this.getMetadata(mesh, container, color));
168
190
  }
169
191
  createPlane(mesh, meshGeom) {
@@ -205,8 +227,17 @@ class ThreeGeometryCreator {
205
227
  this.insertPoint(container, `${startId}|point`, startId, start.clone(), line.id, 'start', points);
206
228
  this.insertPoint(container, `${endId}|point`, endId, end.clone(), line.id, 'end', points);
207
229
  const geometry = new THREE.BufferGeometry().setFromPoints([start.clone(), end.clone()]);
208
- return Object.assign(Object.assign({ geometry,
209
- graphicId, type: type }, this.getMetadata(line, container, color)), { start: start.clone(), end: end.clone() });
230
+ return Object.assign(Object.assign({
231
+ /** The line, as a line segment. */
232
+ geometry,
233
+ /** The edge's id in its container. */
234
+ graphicId,
235
+ /** `line`, or `curveLine` in a sketch's curves. */
236
+ type: type }, this.getMetadata(line, container, color)), {
237
+ /** Where the line starts. */
238
+ start: start.clone(),
239
+ /** Where it ends. */
240
+ end: end.clone() });
210
241
  }
211
242
  createEdge(edge, container, points, color) {
212
243
  const threePts = [];
@@ -235,8 +266,17 @@ class ThreeGeometryCreator {
235
266
  this.insertPoint(container, `${startId}|point`, startId, start, edge.id, 'start', points);
236
267
  this.insertPoint(container, `${endId}|point`, endId, end, edge.id, 'end', points);
237
268
  const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
238
- return Object.assign(Object.assign({ geometry,
239
- graphicId, type: type }, this.getMetadata(edge, container, color)), { start: start.clone(), end: end.clone() });
269
+ return Object.assign(Object.assign({
270
+ /** The curve, as line segments. */
271
+ geometry,
272
+ /** The edge's id in its container. */
273
+ graphicId,
274
+ /** `nurbsCurve`, or `curveSpline` in a sketch's curves. */
275
+ type: type }, this.getMetadata(edge, container, color)), {
276
+ /** Where the curve starts. */
277
+ start: start.clone(),
278
+ /** Where it ends. */
279
+ end: end.clone() });
240
280
  }
241
281
  createArc(arc, container, points, color) {
242
282
  const graphicId = arc.id;
@@ -283,12 +323,47 @@ class ThreeGeometryCreator {
283
323
  this.insertPoint(container, `${startId}|point`, startId, start, arc.id, 'start', points);
284
324
  this.insertPoint(container, `${endId}|point`, endId, end, arc.id, 'end', points);
285
325
  const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
286
- return Object.assign(Object.assign({ geometry,
287
- graphicId, type: type }, this.getMetadata(arc, container, color)), { normal: normal.clone(), center: center.clone(), start: start.clone(), end: end.clone(), radius: arc.radius, angle: arc.angle });
326
+ return Object.assign(Object.assign({
327
+ /** The arc, as line segments. */
328
+ geometry,
329
+ /** The edge's id in its container. */
330
+ graphicId,
331
+ /** `arc` or `circle`, or `curveArc` or `curveCircle` in a sketch's curves. */
332
+ type: type }, this.getMetadata(arc, container, color)), {
333
+ /** The normal of the arc's plane, of length 1. */
334
+ normal: normal.clone(),
335
+ /** The center. */
336
+ center: center.clone(),
337
+ /** Where the arc starts. */
338
+ start: start.clone(),
339
+ /** Where it ends; where it starts for a circle. */
340
+ end: end.clone(),
341
+ /** The radius. */
342
+ radius: arc.radius,
343
+ /** The angle the arc spans, in radians. */
344
+ angle: arc.angle });
288
345
  }
289
346
  createPoint(container, key, graphicId, position, ownerId, type) {
290
- return Object.assign(Object.assign({ key,
291
- graphicId, type: (container.type === re_export_1.ContainerType.CURVEARRAY ? re_export_1.GraphicType.CURVEPOINT : re_export_1.GraphicType.POINT) }, this.getMetadata(null, container)), { position: position.clone(), geometry: position.clone(), owners: [{ ownerId, type }] });
347
+ return Object.assign(Object.assign({
348
+ /** The point's key in its container, `<graphicId>|point`. */
349
+ key,
350
+ /** The point's id in its container. */
351
+ graphicId,
352
+ /** `point`, or `curvePoint` in a sketch's curves. */
353
+ type: (container.type === re_export_1.ContainerType.CURVEARRAY ? re_export_1.GraphicType.CURVEPOINT : re_export_1.GraphicType.POINT) }, this.getMetadata(null, container)), {
354
+ /** Where the point is. */
355
+ position: position.clone(),
356
+ /** Where the point is, as for `position`. */
357
+ geometry: position.clone(),
358
+ /** The edges the point is an end of: each edge's id (`ownerId`) and which end it is (`type`). */
359
+ owners: [
360
+ {
361
+ /** The edge's id. */
362
+ ownerId,
363
+ /** Which end of the edge the point is. */
364
+ type,
365
+ },
366
+ ] });
292
367
  }
293
368
  insertPoint(container, key, graphicId, position, ownerId, type, points) {
294
369
  const existingPoint = points[key];
@@ -304,6 +379,11 @@ class ThreeGeometryCreator {
304
379
  }
305
380
  }
306
381
  exports.ThreeGeometryCreator = ThreeGeometryCreator;
382
+ /**
383
+ * Returns the geometry of an empty container.
384
+ *
385
+ * @internal
386
+ */
307
387
  const EMPTY_CONTAINER_GEOMETRY = () => {
308
388
  return {
309
389
  graphicId: Number.NaN,
@@ -324,6 +404,12 @@ const EMPTY_CONTAINER_GEOMETRY = () => {
324
404
  };
325
405
  };
326
406
  exports.EMPTY_CONTAINER_GEOMETRY = EMPTY_CONTAINER_GEOMETRY;
407
+ /**
408
+ * Returns whether two elements of the geometry are the same: the same `graphicId` and `type`.
409
+ *
410
+ * @advanced
411
+ * @category Geometry
412
+ */
327
413
  const isEqualGeometry = (a, b) => {
328
414
  return a.graphicId === b.graphicId && a.type === b.type;
329
415
  };
@@ -3,23 +3,123 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.solidFilter = exports.loopFilter = exports.planeFilter = exports.meshFilter = exports.pointFilter = exports.arcCircleFilter = exports.circleFilter = exports.arcFilter = exports.edgeFilter = exports.lineFilter = void 0;
4
4
  const re_export_1 = require("../re-export");
5
5
  const selection_1 = require("../store/states/selection");
6
+ /**
7
+ * Takes straight edges of solids.
8
+ *
9
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
10
+ *
11
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
12
+ * @param data - The element's `GraphicType`.
13
+ * @advanced
14
+ * @category Selection
15
+ */
6
16
  const lineFilter = (scope, data) => scope === selection_1.BuerliScope && data === re_export_1.GraphicType.LINE;
7
17
  exports.lineFilter = lineFilter;
18
+ /**
19
+ * Takes edges of solids: lines, arcs, circles and other curves.
20
+ *
21
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
22
+ *
23
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
24
+ * @param data - The element's `GraphicType`.
25
+ * @advanced
26
+ * @category Selection
27
+ */
8
28
  const edgeFilter = (scope, data) => scope === selection_1.BuerliScope && re_export_1.EdgeTypes.includes(data);
9
29
  exports.edgeFilter = edgeFilter;
30
+ /**
31
+ * Takes arcs of solids, not full circles.
32
+ *
33
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
34
+ *
35
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
36
+ * @param data - The element's `GraphicType`.
37
+ * @advanced
38
+ * @category Selection
39
+ */
10
40
  const arcFilter = (scope, data) => scope === selection_1.BuerliScope && data === re_export_1.GraphicType.ARC;
11
41
  exports.arcFilter = arcFilter;
42
+ /**
43
+ * Takes circles of solids.
44
+ *
45
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
46
+ *
47
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
48
+ * @param data - The element's `GraphicType`.
49
+ * @advanced
50
+ * @category Selection
51
+ */
12
52
  const circleFilter = (scope, data) => scope === selection_1.BuerliScope && data === re_export_1.GraphicType.CIRCLE;
13
53
  exports.circleFilter = circleFilter;
54
+ /**
55
+ * Takes arcs and circles, for example for a center or a radius.
56
+ *
57
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
58
+ *
59
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
60
+ * @param data - The element's `GraphicType`.
61
+ * @advanced
62
+ * @category Selection
63
+ */
14
64
  const arcCircleFilter = (scope, data) => scope === selection_1.BuerliScope && (data === re_export_1.GraphicType.ARC || data === re_export_1.GraphicType.CIRCLE);
15
65
  exports.arcCircleFilter = arcCircleFilter;
66
+ /**
67
+ * Takes points of solids: the ends of their edges.
68
+ *
69
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
70
+ *
71
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
72
+ * @param data - The element's `GraphicType`.
73
+ * @advanced
74
+ * @category Selection
75
+ */
16
76
  const pointFilter = (scope, data) => scope === selection_1.BuerliScope && data === re_export_1.GraphicType.POINT;
17
77
  exports.pointFilter = pointFilter;
78
+ /**
79
+ * Takes faces of solids: planar, cylindrical, conical, spherical and free-form faces.
80
+ *
81
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
82
+ *
83
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
84
+ * @param data - The element's `GraphicType`.
85
+ * @advanced
86
+ * @category Selection
87
+ */
18
88
  const meshFilter = (scope, data) => scope === selection_1.BuerliScope && re_export_1.MeshTypes.includes(data);
19
89
  exports.meshFilter = meshFilter;
90
+ /**
91
+ * Takes planar faces.
92
+ *
93
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
94
+ *
95
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
96
+ * @param data - The element's `GraphicType`.
97
+ * @advanced
98
+ * @category Selection
99
+ */
20
100
  const planeFilter = (scope, data) => scope === selection_1.BuerliScope && data === re_export_1.GraphicType.PLANE;
21
101
  exports.planeFilter = planeFilter;
102
+ /**
103
+ * Takes loops, the edges around a face: the 3D view takes the loop of the face that is picked.
104
+ *
105
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
106
+ *
107
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
108
+ * @param data - The element's `GraphicType`.
109
+ * @advanced
110
+ * @category Selection
111
+ */
22
112
  const loopFilter = (scope, data) => scope === selection_1.BuerliScope && data === re_export_1.GraphicType.LOOP;
23
113
  exports.loopFilter = loopFilter;
114
+ /**
115
+ * Takes whole solids: picking any face or edge selects its solid.
116
+ *
117
+ * Use it as a selector's filter ({@link SelectionFilter}): {@link Selector} has an example.
118
+ *
119
+ * @param scope - The item's scope; only {@link BuerliScope} is taken.
120
+ * @param data - The element's `GraphicType`.
121
+ * @advanced
122
+ * @category Selection
123
+ */
24
124
  const solidFilter = (scope, data) => scope === selection_1.BuerliScope && data === re_export_1.GraphicType.BREP;
25
125
  exports.solidFilter = solidFilter;
@@ -1,4 +1,64 @@
1
1
  "use strict";
2
+ /**
3
+ * The state the buerli packages share: the drawings, each with its structure tree, its geometry, its selection
4
+ * and its plugins, and the messages for the app. `@buerli.io/classcad` fills a drawing as ClassCAD changes it, and
5
+ * `@buerli.io/react` renders it; apps mostly reach it through those two, and use a few things from here directly.
6
+ *
7
+ * ## What it exposes
8
+ *
9
+ * - {@link getDrawing}: a drawing's state, its structure tree, geometry, selection and plugins, and its API.
10
+ * - {@link DrawingState} and {@link DrawingAPI}: what a drawing holds and what it can do.
11
+ * - {@link api}: the store itself, with all drawings, to read, change and subscribe to.
12
+ * - {@link subscribeToDrawing}: calls back when a part of a drawing changes.
13
+ * - {@link showMessage}: tells the user something, in the message display of react-cad and Buerligons.
14
+ * - {@link Selector} and {@link SelectedItem}: the lists the user picks faces, edges and other items into.
15
+ * - {@link GeometryConfig}: how the geometry of solids is shown.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { BuerliCadFacade, createApi, init, WASMClient } from '@buerli.io/classcad'
20
+ * import { getDrawing } from '@buerli.io/core'
21
+ *
22
+ * init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
23
+ *
24
+ * // Connecting makes a drawing in the store
25
+ * const drawingId = await new BuerliCadFacade().connect()
26
+ * if (drawingId) {
27
+ * await createApi(drawingId).v1.part.create({ name: 'Part' })
28
+ * // The structure tree that ClassCAD sent: its objects by id
29
+ * const { tree } = getDrawing(drawingId).structure
30
+ * console.log(Object.values(tree).map(object => `${object.class} ${object.name}`))
31
+ * }
32
+ * ```
33
+ *
34
+ * @categoryDescription Drawings
35
+ * A drawing is one model in the store: its structure tree, geometry, selections and plugins, which
36
+ * `@buerli.io/classcad` keeps up to date. Read it when an app needs to know what the model holds.
37
+ *
38
+ * @categoryDescription Messages
39
+ * Messages for the user, which the message displays of react-cad and Buerligons show: to tell what an app is doing.
40
+ *
41
+ * @categoryDescription Selection
42
+ * Selectors, the lists the user picks faces, edges and other items into in the 3D view, and what the user has
43
+ * selected in the model: for apps that let the user pick.
44
+ *
45
+ * @categoryDescription Geometry
46
+ * How the geometry of solids is shown, and the bounds of a model. The three.js geometry itself, made from the
47
+ * graphic ClassCAD sends, is for apps that work with faces and edges directly.
48
+ *
49
+ * @categoryDescription Measure
50
+ * Positions, lengths, distances and angles of elements of the geometry, as the Measure plugin of react-cad shows
51
+ * them.
52
+ *
53
+ * @categoryDescription Plugins
54
+ * Plugins add panels and 3D views to a CAD app, for the features of a model or for a whole drawing: for those who
55
+ * make plugins.
56
+ *
57
+ * @categoryDescription Utilities
58
+ * Math for the coordinate systems of ClassCAD, and timing.
59
+ *
60
+ * @packageDocumentation
61
+ */
2
62
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
63
  if (k2 === undefined) k2 = k;
4
64
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -8,27 +8,128 @@ exports.showMessage = showMessage;
8
8
  exports.updateMessage = updateMessage;
9
9
  exports.closeMessage = closeMessage;
10
10
  const store_1 = require("./store");
11
+ /**
12
+ * Returns a drawing's state: its structure tree, geometry, selection and plugins, and its API.
13
+ *
14
+ * It is the state as it is now, read once; to follow it as it changes, use {@link subscribeToDrawing}, or
15
+ * `useDrawing` of `@buerli.io/react` in a component. Returns `undefined` for a drawing that does not exist (any more),
16
+ * although the type does not say so.
17
+ *
18
+ * @param id - The drawing, as `@buerli.io/classcad` returns it when it connects.
19
+ * @returns The drawing's state, or `undefined`.
20
+ * @example
21
+ * ```ts
22
+ * import { BuerliCadFacade, init, WASMClient } from '@buerli.io/classcad'
23
+ * import { getDrawing } from '@buerli.io/core'
24
+ *
25
+ * init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
26
+ *
27
+ * const facade = new BuerliCadFacade()
28
+ * const drawingId = await facade.connect()
29
+ * const part = drawingId && (await facade.api.v1.part.create({ name: 'Bracket' }))
30
+ * if (drawingId && part) {
31
+ * await facade.api.v1.part.box({ id: part, length: 100, width: 50, height: 20 })
32
+ *
33
+ * const drawing = getDrawing(drawingId)
34
+ * // The part in the structure tree, and the three.js geometry of its solids
35
+ * const object = drawing.structure.tree[part]
36
+ * const solids = (object.solids ?? []).map(id => drawing.geometry.cache[id])
37
+ * console.log(object.name, solids.length)
38
+ * }
39
+ * ```
40
+ * @category Drawings
41
+ */
11
42
  function getDrawing(id) {
12
43
  const { drawing } = store_1.api.getState();
13
44
  return drawing.refs[id];
14
45
  }
15
46
  /**
16
- * @returns PluginState or undefined if either drawing or plugin don't exist
47
+ * Returns a plugin's state: its description, its own `state`, and `set` to change that.
48
+ *
49
+ * Plugins of features are created when their feature is opened, global plugins when the drawing is made
50
+ * (see {@link PluginState}). Read once; `usePlugin` of `@buerli.io/react` follows it in a component.
51
+ *
52
+ * @param drawingId - The drawing the plugin belongs to.
53
+ * @param pluginId - The plugin: for a feature's plugin, the feature's object id.
54
+ * @returns The plugin's state, or `undefined` when the drawing or the plugin does not exist.
55
+ * @example
56
+ * ```ts
57
+ * import { getDrawing, getPlugin } from '@buerli.io/core'
58
+ *
59
+ * // Open the Measure plugin of a drawing, and have it show three digits
60
+ * const drawing = getDrawing(drawingId)
61
+ * const measureId = drawing.plugin.global.find(id => drawing.plugin.refs[id]?.name === 'Measure')
62
+ * if (measureId) {
63
+ * drawing.api.plugin.setActiveGlobal(measureId, true)
64
+ * getPlugin(drawingId, measureId)?.set({ digits: 3 })
65
+ * }
66
+ * ```
67
+ * @advanced
68
+ * @category Plugins
17
69
  */
18
70
  function getPlugin(drawingId, pluginId) {
19
71
  var _a;
20
72
  const { drawing } = store_1.api.getState();
21
73
  return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
22
74
  }
75
+ /**
76
+ * Sets options of the store; `init` of `@buerli.io/classcad` calls it with the options it is given.
77
+ *
78
+ * @internal
79
+ */
23
80
  function init(options) {
24
81
  store_1.api.getState().api.init(options);
25
82
  }
83
+ /**
84
+ * Tells the user something: shows a message in the message display of react-cad and Buerligons.
85
+ *
86
+ * The store holds one message, the latest (`message` of {@link BuerliState}): a new one takes the place of the one
87
+ * before, and the display, which keeps a list of them, shows it as it comes. Warnings and errors of ClassCAD calls
88
+ * come this way as well.
89
+ *
90
+ * @param message - What to say, and what kind of message it is.
91
+ * @returns The message's id, for {@link updateMessage} and {@link closeMessage}.
92
+ * @example
93
+ * ```ts
94
+ * import { createApi } from '@buerli.io/classcad'
95
+ * import { closeMessage, showMessage, updateMessage } from '@buerli.io/core'
96
+ *
97
+ * const id = showMessage({ type: 'busy', text: 'Recalculating …', drawingId })
98
+ * try {
99
+ * await createApi(drawingId).v1.common.recalc()
100
+ * updateMessage(id, { type: 'success', text: 'Recalculated', drawingId })
101
+ * } catch {
102
+ * // ClassCAD's error comes as a message of its own
103
+ * closeMessage(id)
104
+ * }
105
+ * ```
106
+ * @category Messages
107
+ */
26
108
  function showMessage(message) {
27
109
  return store_1.api.getState().message.api.show(message);
28
110
  }
111
+ /**
112
+ * Replaces a message that {@link showMessage} showed, for example a busy message with its outcome.
113
+ *
114
+ * The replacement becomes the store's latest message, with the same id, also when other messages came since.
115
+ * {@link showMessage} has an example.
116
+ *
117
+ * @param id - The message, as {@link showMessage} returned it.
118
+ * @param message - What the message says now.
119
+ * @category Messages
120
+ */
29
121
  function updateMessage(id, message) {
30
122
  store_1.api.getState().message.api.update(id, message);
31
123
  }
124
+ /**
125
+ * Takes a message back: clears the store's latest message if it is this one.
126
+ *
127
+ * A display of the latest message, like Buerligons' one-line message, clears with it; react-cad's list keeps the
128
+ * messages it has shown. {@link showMessage} has an example.
129
+ *
130
+ * @param id - The message, as {@link showMessage} returned it.
131
+ * @category Messages
132
+ */
32
133
  function closeMessage(id) {
33
134
  store_1.api.getState().message.api.close(id);
34
135
  }
@@ -27,8 +27,7 @@ exports.createState = createState;
27
27
  const generalApi = set => ({
28
28
  // TODO: rename init to setOptions and remove initDone if everything is ok
29
29
  /**
30
- * This api method initializes state. Considering user can accidentally ommit some important like elements,
31
- * there is a warning disaplying for these cases.
30
+ * Merges the given options into `state.options` (the ones it names replace the ones there) and sets `initDone`.
32
31
  *
33
32
  * @param options - options which will be set into state.options
34
33
  */
@@ -15,8 +15,23 @@ exports.cadData = cadData;
15
15
  // API
16
16
  ////////////////////////////////////////////////////
17
17
  const cadApi = (set, get, buerliApi) => ({
18
+ /**
19
+ * Sets the undo history, as ClassCAD reports it.
20
+ *
21
+ * @internal
22
+ */
18
23
  setStates: (current, stack, captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { current, stack, captionMap }) }) })),
24
+ /**
25
+ * Sets what the changes of the undo history are called.
26
+ *
27
+ * @internal
28
+ */
19
29
  setCaptionMap: (captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { captionMap }) }) })),
30
+ /**
31
+ * Adds a call to the calls under way and returns its id.
32
+ *
33
+ * @internal
34
+ */
20
35
  addPending: (name, options) => {
21
36
  const id = (0, uuid_1.v4)();
22
37
  set(state => ({
@@ -24,13 +39,28 @@ const cadApi = (set, get, buerliApi) => ({
24
39
  }));
25
40
  return id;
26
41
  },
42
+ /**
43
+ * Removes a call from the calls under way.
44
+ *
45
+ * @internal
46
+ */
27
47
  removePending: (id) => {
28
48
  const newPending = get().cad.pending.filter(p => p.id !== id);
29
49
  set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: newPending }) }));
30
50
  },
51
+ /**
52
+ * Sets whether the client is connected.
53
+ *
54
+ * @internal
55
+ */
31
56
  setConnected: (connected) => {
32
57
  return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { connected }) }) }));
33
58
  },
59
+ /**
60
+ * Sets whether the client is connected or trying to connect.
61
+ *
62
+ * @internal
63
+ */
34
64
  setActive: (active) => {
35
65
  return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { active }) }) }));
36
66
  },
@@ -39,6 +69,8 @@ const cadApi = (set, get, buerliApi) => ({
39
69
  *
40
70
  * **This method is designed for interal usage only, please do not use it in user code!**
41
71
  * **It will be removed in a future release!**
72
+ *
73
+ * @internal
42
74
  */
43
75
  clearPending: () => {
44
76
  set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: [] }) }));
@@ -56,8 +56,9 @@ exports.geometryData = geometryData;
56
56
  ////////////////////////////////////////////////////
57
57
  const geometryApi = (set, get, buerliApi) => ({
58
58
  /**
59
- * Updates the @see geometry.bounds depending on all products of the model.
60
- * The update will only happen, if at least one solid of one product is available.
59
+ * Updates `geometry.bounds` from all products of the model, if a product has a solid.
60
+ *
61
+ * @internal
61
62
  */
62
63
  updateBounds: () => {
63
64
  const { api, structure } = get();
@@ -67,10 +68,12 @@ const geometryApi = (set, get, buerliApi) => ({
67
68
  }
68
69
  },
69
70
  /**
70
- * Batch variant of @see createGeometryIfNotCached: creates the missing geometry of all given containers
71
+ * Batch variant of `createGeometryIfNotCached`: creates the missing geometry of all given containers
71
72
  * and stores it with one state update. Adding the graphic of a large assembly calls this once per batch
72
73
  * instead of once per container, so subscribers are notified once and the cache is copied once.
73
74
  * Returns the number of geometries created.
75
+ *
76
+ * @internal
74
77
  */
75
78
  createGeometriesIfNotCached: (containerIds, color) => {
76
79
  const { graphic, geometry } = get();
@@ -93,6 +96,11 @@ const geometryApi = (set, get, buerliApi) => ({
93
96
  }
94
97
  return count;
95
98
  },
99
+ /**
100
+ * Returns the geometry of a container, and makes it from the graphic first if it is not in the cache.
101
+ *
102
+ * @internal
103
+ */
96
104
  createGeometryIfNotCached: (containerId, color) => {
97
105
  const { graphic, geometry } = get();
98
106
  let geom = geometry.cache[containerId];
@@ -110,6 +118,15 @@ const geometryApi = (set, get, buerliApi) => ({
110
118
  }
111
119
  return geom;
112
120
  },
121
+ /**
122
+ * Colors a face of a solid in the 3D view, until its geometry comes anew from ClassCAD. The model is not changed.
123
+ *
124
+ * @param containerId - The solid, as in `geometry.cache`.
125
+ * @param graphicId - The face.
126
+ * @param r - Red, from 0 to 1.
127
+ * @param g - Green, from 0 to 1.
128
+ * @param b - Blue, from 0 to 1.
129
+ */
113
130
  setGraphicColor: (containerId, graphicId, r, g, b) => {
114
131
  // Provide values as a CSS color string, which will be gamma corrected by three.js
115
132
  const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
@@ -130,6 +147,15 @@ const geometryApi = (set, get, buerliApi) => ({
130
147
  };
131
148
  });
132
149
  },
150
+ /**
151
+ * Colors a solid in the 3D view (its faces without a color of their own), until its geometry comes anew from
152
+ * ClassCAD. The model is not changed.
153
+ *
154
+ * @param containerId - The solid, as in `geometry.cache`.
155
+ * @param r - Red, from 0 to 1.
156
+ * @param g - Green, from 0 to 1.
157
+ * @param b - Blue, from 0 to 1.
158
+ */
133
159
  setContainerColor: (containerId, r, g, b) => {
134
160
  // Provide values as a CSS color string, which will be gamma corrected by three.js
135
161
  const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
@@ -138,12 +164,26 @@ const geometryApi = (set, get, buerliApi) => ({
138
164
  geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
139
165
  }));
140
166
  },
167
+ /**
168
+ * Sets the opacity of a solid in the 3D view (its faces without an opacity of their own), until its geometry
169
+ * comes anew from ClassCAD. The model is not changed.
170
+ *
171
+ * @param containerId - The solid, as in `geometry.cache`.
172
+ * @param opacity - From 0 (invisible) to 1.
173
+ */
141
174
  setOpacity: (containerId, opacity) => {
142
175
  const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
143
176
  set(state => ({
144
177
  geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
145
178
  }));
146
179
  },
180
+ /**
181
+ * Sets how the geometry of a product or a solid is shown: merges `config` into the one it has, or removes it with
182
+ * `null`.
183
+ *
184
+ * @param objId - The product or the solid.
185
+ * @param config - What to change, or `null` to show it as all others.
186
+ */
147
187
  setConfig: (objId, config) => {
148
188
  set(state => {
149
189
  const productConfigs = Object.assign({}, state.geometry.config.product);
@@ -165,10 +205,17 @@ const geometryApi = (set, get, buerliApi) => ({
165
205
  return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
166
206
  });
167
207
  },
208
+ /** Returns the elements of the geometry that ClassCAD gave a label or a color of their own. */
168
209
  findDecorated: () => {
169
210
  const { geometry: api } = get().api;
170
211
  return api.filter(elem => { var _a, _b, _c, _d, _e; return Boolean((_b = (_a = elem.rawGraphic) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.label) || Boolean((_e = (_d = (_c = elem.rawGraphic) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.material) === null || _e === void 0 ? void 0 : _e.color); });
171
212
  },
213
+ /**
214
+ * Returns the elements of the geometry (faces, edges, arcs and lines) that `cb` accepts.
215
+ *
216
+ * @param cb - Whether to take an element.
217
+ * @param options - `onlyOne` stops at the first, `containerId` looks in one solid only.
218
+ */
172
219
  filter: (cb, options) => {
173
220
  const result = [];
174
221
  const { cache } = get().geometry;