cadorange 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index-DceghC4N.d.ts +305 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +48 -0
- package/dist/io-DD2D1UYF.js +52 -0
- package/dist/selectors-C0-da9aQ.js +968 -0
- package/dist/workplane/index.d.ts +27 -0
- package/dist/workplane/index.js +208 -0
- package/package.json +33 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LAU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
//#region src/geom/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Geometric value types and pure vector math.
|
|
4
|
+
*
|
|
5
|
+
* Ported from build123d's geometry semantics (Apache-2.0): `Axis` with
|
|
6
|
+
* `isParallel` (angle tolerance), vector ops as pure functions over `Vec3`.
|
|
7
|
+
*/
|
|
8
|
+
type Vec3 = readonly [number, number, number];
|
|
9
|
+
declare const v: {
|
|
10
|
+
add: (a: Vec3, b: Vec3) => Vec3;
|
|
11
|
+
sub: (a: Vec3, b: Vec3) => Vec3;
|
|
12
|
+
scale: (a: Vec3, k: number) => Vec3;
|
|
13
|
+
dot: (a: Vec3, b: Vec3) => number;
|
|
14
|
+
cross: (a: Vec3, b: Vec3) => Vec3;
|
|
15
|
+
length: (a: Vec3) => number;
|
|
16
|
+
distance: (a: Vec3, b: Vec3) => number;
|
|
17
|
+
normalize: (a: Vec3) => Vec3;
|
|
18
|
+
/** Componentwise closeness. */
|
|
19
|
+
eq: (a: Vec3, b: Vec3, tol?: number) => boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* An oriented axis (origin + direction), build123d-style. Used by selectors:
|
|
23
|
+
* `part.edges().filterBy(Axis.Z)` keeps edges parallel to Z.
|
|
24
|
+
*/
|
|
25
|
+
declare class Axis {
|
|
26
|
+
readonly origin: Vec3;
|
|
27
|
+
static readonly X: Axis;
|
|
28
|
+
static readonly Y: Axis;
|
|
29
|
+
static readonly Z: Axis;
|
|
30
|
+
readonly direction: Vec3;
|
|
31
|
+
constructor(origin: Vec3, direction: Vec3);
|
|
32
|
+
/**
|
|
33
|
+
* True when this axis and `other` point the same or opposite way, within an
|
|
34
|
+
* angle of `toleranceDegrees` (build123d: `Axis.is_parallel`, default 1e-2°).
|
|
35
|
+
*/
|
|
36
|
+
isParallel(other: Axis, toleranceDegrees?: number): boolean;
|
|
37
|
+
}
|
|
38
|
+
type AxisName = "X" | "Y" | "Z";
|
|
39
|
+
declare function axisByName(name: AxisName): Axis;
|
|
40
|
+
/** Placement: origin plus optional local axis directions. */
|
|
41
|
+
interface Location {
|
|
42
|
+
origin: Vec3;
|
|
43
|
+
/** Local Z direction; defaults to the global +Z. */
|
|
44
|
+
zDir?: Vec3;
|
|
45
|
+
/** Local X direction; defaults to the global +X. */
|
|
46
|
+
xDir?: Vec3;
|
|
47
|
+
}
|
|
48
|
+
/** Short alias used by the kernel interface. */
|
|
49
|
+
type Loc = Location;
|
|
50
|
+
interface Axis3 {
|
|
51
|
+
origin: Vec3;
|
|
52
|
+
dir: Vec3;
|
|
53
|
+
}
|
|
54
|
+
interface Plane {
|
|
55
|
+
origin: Vec3;
|
|
56
|
+
normal: Vec3;
|
|
57
|
+
xDir: Vec3;
|
|
58
|
+
}
|
|
59
|
+
/** A plane from just origin + normal (xDir derived deterministically). */
|
|
60
|
+
declare function planeFrom(origin: Vec3, normal: Vec3): Plane;
|
|
61
|
+
interface BBox {
|
|
62
|
+
min: Vec3;
|
|
63
|
+
max: Vec3;
|
|
64
|
+
}
|
|
65
|
+
interface Mesh {
|
|
66
|
+
positions: Float32Array;
|
|
67
|
+
normals?: Float32Array;
|
|
68
|
+
indices: Uint32Array;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/kernel/types.d.ts
|
|
72
|
+
/** Opaque handle to a shape owned by the Kernel (WASM memory). Never construct one. */
|
|
73
|
+
interface ShapeHandle {
|
|
74
|
+
readonly id: number;
|
|
75
|
+
}
|
|
76
|
+
/** Surface geometry kinds, mirroring OCCT analytic surfaces (build123d `GeomType`). */
|
|
77
|
+
type SurfaceKind = "plane" | "cylinder" | "cone" | "sphere" | "torus" | "bspline-surface" | "other";
|
|
78
|
+
/** Curve geometry kinds (build123d `GeomType`). */
|
|
79
|
+
type CurveKind = "line" | "circle" | "ellipse" | "bspline" | "other";
|
|
80
|
+
/**
|
|
81
|
+
* Metadata for one face, normalized from the kernel's interrogation output.
|
|
82
|
+
* `index` is the kernel's 1-based selection index (fillet/draft/shell targets).
|
|
83
|
+
*
|
|
84
|
+
* `center` is a reference point on the face's axis of symmetry where one
|
|
85
|
+
* exists (kernel `axisPoint` — cylinder/cone/sphere/torus), the integral
|
|
86
|
+
* centroid for planes and generic surfaces. Selection semantics key on it;
|
|
87
|
+
* occt.ts ≥0.10.0 reports both, we keep the axis-stable one.
|
|
88
|
+
*/
|
|
89
|
+
interface FaceMeta {
|
|
90
|
+
readonly index: number;
|
|
91
|
+
readonly surface: SurfaceKind;
|
|
92
|
+
readonly area: number;
|
|
93
|
+
readonly center: Vec3;
|
|
94
|
+
/** Plane only — unit normal. */
|
|
95
|
+
readonly normal?: Vec3;
|
|
96
|
+
/** Cylinder/cone/torus — unit axis. */
|
|
97
|
+
readonly axis?: Vec3;
|
|
98
|
+
/** Cylinder/sphere/torus. */
|
|
99
|
+
readonly radius?: number;
|
|
100
|
+
}
|
|
101
|
+
/** Metadata for one edge. `index` is the kernel's 1-based fillet/chamfer index. */
|
|
102
|
+
interface EdgeMeta {
|
|
103
|
+
readonly index: number;
|
|
104
|
+
readonly curve: CurveKind;
|
|
105
|
+
readonly length: number;
|
|
106
|
+
/**
|
|
107
|
+
* Line: midpoint. Circle/ellipse: the underlying circle/ellipse center
|
|
108
|
+
* (kernel `axisPoint`, not the arc's integral centroid — matches
|
|
109
|
+
* build123d selector semantics). Others: integral centroid.
|
|
110
|
+
*/
|
|
111
|
+
readonly center: Vec3;
|
|
112
|
+
/** Line only — unit direction (start → end). */
|
|
113
|
+
readonly direction?: Vec3;
|
|
114
|
+
/** Circle/ellipse — unit axis. */
|
|
115
|
+
readonly axis?: Vec3;
|
|
116
|
+
/** Circle only. */
|
|
117
|
+
readonly radius?: number;
|
|
118
|
+
}
|
|
119
|
+
/** A through-cylindrical-feature heuristic hit (bore/hole/boss). */
|
|
120
|
+
interface HoleMeta {
|
|
121
|
+
readonly radius: number;
|
|
122
|
+
readonly axis: Vec3;
|
|
123
|
+
readonly center: Vec3;
|
|
124
|
+
readonly length: number | null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Everything the kernel can tell us about a shape in one interrogation call.
|
|
128
|
+
* Sub-shape metadata (not handles) is the foundation selectors stand on.
|
|
129
|
+
*/
|
|
130
|
+
interface ShapeMeta {
|
|
131
|
+
readonly shapeType: string;
|
|
132
|
+
readonly volume: number;
|
|
133
|
+
readonly area: number;
|
|
134
|
+
readonly bbox: BBox;
|
|
135
|
+
readonly center: Vec3;
|
|
136
|
+
readonly valid: boolean;
|
|
137
|
+
readonly faces: readonly FaceMeta[];
|
|
138
|
+
readonly edges: readonly EdgeMeta[];
|
|
139
|
+
readonly holes: readonly HoleMeta[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The only surface allowed to touch occt.ts.
|
|
143
|
+
*
|
|
144
|
+
* Revised for occt.ts reality (it is a high-level API, not an OCP-style class
|
|
145
|
+
* mirror): sub-shapes are addressed by 1-based `index` into `meta()`, never by
|
|
146
|
+
* handles; there are no lazily-composed locations — transforms execute
|
|
147
|
+
* immediately. Anything occt.ts cannot express shows up here as a missing
|
|
148
|
+
* method (see docs/occt-requirements.md before adding workarounds below this
|
|
149
|
+
* interface).
|
|
150
|
+
*/
|
|
151
|
+
interface Kernel {
|
|
152
|
+
makeBox(dx: number, dy: number, dz: number, at?: Vec3, dir?: Vec3): ShapeHandle;
|
|
153
|
+
makeCylinder(radius: number, height: number, at?: Vec3, dir?: Vec3): ShapeHandle;
|
|
154
|
+
makeSphere(radius: number, at?: Vec3): ShapeHandle;
|
|
155
|
+
makeCone(radius1: number, radius2: number, height: number, at?: Vec3): ShapeHandle;
|
|
156
|
+
makeTorus(radius1: number, radius2: number, at?: Vec3): ShapeHandle;
|
|
157
|
+
/**
|
|
158
|
+
* Booleans clean by default (UnifySameDomain — same as build123d/CadQuery):
|
|
159
|
+
* coplanar faces merge, collinear edges join. `clean: false` keeps raw
|
|
160
|
+
* fragment topology for callers that count fragments.
|
|
161
|
+
*/
|
|
162
|
+
boolean(op: "fuse" | "cut" | "common", a: ShapeHandle, b: ShapeHandle, opts?: {
|
|
163
|
+
clean?: boolean;
|
|
164
|
+
}): ShapeHandle;
|
|
165
|
+
/** `edgeIndices` are 1-based indices into `meta(s).edges`. Empty = all edges. */
|
|
166
|
+
fillet(s: ShapeHandle, radius: number, edgeIndices: number[]): ShapeHandle;
|
|
167
|
+
chamfer(s: ShapeHandle, distance: number, edgeIndices: number[]): ShapeHandle;
|
|
168
|
+
translate(s: ShapeHandle, by: Vec3): ShapeHandle;
|
|
169
|
+
rotate(s: ShapeHandle, axisDir: Vec3, angleDegrees: number): ShapeHandle;
|
|
170
|
+
/** One interrogation call; implementations cache per handle. */
|
|
171
|
+
meta(s: ShapeHandle): ShapeMeta;
|
|
172
|
+
isValid(s: ShapeHandle): boolean;
|
|
173
|
+
exportStep(s: ShapeHandle): Uint8Array;
|
|
174
|
+
/** Ascii STL. */
|
|
175
|
+
exportStl(s: ShapeHandle, tolerance?: number): string;
|
|
176
|
+
exportGlb(s: ShapeHandle): Uint8Array;
|
|
177
|
+
importStep(data: Uint8Array): ShapeHandle;
|
|
178
|
+
/** Deterministic checksum (BRep serialization hash), for caching and eval replay. */
|
|
179
|
+
hash(s: ShapeHandle): string;
|
|
180
|
+
/** WASM memory is not GC'd — dispose explicitly. */
|
|
181
|
+
dispose(s: ShapeHandle): void;
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/topo/index.d.ts
|
|
185
|
+
/** Plain-JSON shape summary returned by `describe()`. */
|
|
186
|
+
interface Describe {
|
|
187
|
+
volume: number;
|
|
188
|
+
area: number;
|
|
189
|
+
bbox: {
|
|
190
|
+
min: Vec3;
|
|
191
|
+
max: Vec3;
|
|
192
|
+
};
|
|
193
|
+
center: Vec3;
|
|
194
|
+
faces: number;
|
|
195
|
+
edges: number;
|
|
196
|
+
valid: boolean;
|
|
197
|
+
}
|
|
198
|
+
/** A shape owned by the kernel: solids, and later shells/wires/faces. */
|
|
199
|
+
declare class Shape {
|
|
200
|
+
#private;
|
|
201
|
+
readonly handle: ShapeHandle;
|
|
202
|
+
constructor(handle: ShapeHandle);
|
|
203
|
+
/** One kernel interrogation, cached per instance. */
|
|
204
|
+
meta(): ShapeMeta;
|
|
205
|
+
describe(): Describe;
|
|
206
|
+
volume(): number;
|
|
207
|
+
area(): number;
|
|
208
|
+
center(): Vec3;
|
|
209
|
+
isValid(): boolean;
|
|
210
|
+
hash(): string;
|
|
211
|
+
faces(): ShapeList<Face>;
|
|
212
|
+
edges(): ShapeList<Edge>;
|
|
213
|
+
/**
|
|
214
|
+
* Not available yet: the kernel's interrogation output carries no vertex
|
|
215
|
+
* records (docs/occt-requirements.md R5). Will land with that kernel API.
|
|
216
|
+
*/
|
|
217
|
+
vertices(): ShapeList<never>;
|
|
218
|
+
/** See `Kernel.boolean` — cleaned by default (UnifySameDomain). */
|
|
219
|
+
cut(b: Shape, opts?: {
|
|
220
|
+
clean?: boolean;
|
|
221
|
+
}): Solid;
|
|
222
|
+
fuse(b: Shape, opts?: {
|
|
223
|
+
clean?: boolean;
|
|
224
|
+
}): Solid;
|
|
225
|
+
/** build123d's `intersect` (OCCT `common`). */
|
|
226
|
+
common(b: Shape, opts?: {
|
|
227
|
+
clean?: boolean;
|
|
228
|
+
}): Solid;
|
|
229
|
+
/** Immediate-bake transform (occt.ts has no lazy location chain). */
|
|
230
|
+
translate(by: Vec3): Solid;
|
|
231
|
+
fillet(edges: ShapeList<Edge> | readonly Edge[], radius: number): Solid;
|
|
232
|
+
chamfer(edges: ShapeList<Edge> | readonly Edge[], distance: number): Solid;
|
|
233
|
+
/** Export by file extension (.step/.stl/.glb). Node writes to disk. */
|
|
234
|
+
export(path: string, opts?: {
|
|
235
|
+
tolerance?: number;
|
|
236
|
+
}): Promise<void>;
|
|
237
|
+
dispose(): void;
|
|
238
|
+
}
|
|
239
|
+
declare class Solid extends Shape {}
|
|
240
|
+
/** A face "view": kernel metadata plus the parent it was selected from. */
|
|
241
|
+
declare class Face {
|
|
242
|
+
readonly parent: Shape;
|
|
243
|
+
readonly meta: FaceMeta;
|
|
244
|
+
constructor(parent: Shape, meta: FaceMeta);
|
|
245
|
+
get index(): number;
|
|
246
|
+
get surface(): FaceMeta["surface"];
|
|
247
|
+
get area(): number;
|
|
248
|
+
get center(): Vec3;
|
|
249
|
+
get normal(): Vec3 | undefined;
|
|
250
|
+
get axis(): Axis | undefined;
|
|
251
|
+
get radius(): number | undefined;
|
|
252
|
+
}
|
|
253
|
+
/** An edge "view". `index` is the kernel's fillet/chamfer selection index. */
|
|
254
|
+
declare class Edge {
|
|
255
|
+
readonly parent: Shape;
|
|
256
|
+
readonly meta: EdgeMeta;
|
|
257
|
+
constructor(parent: Shape, meta: EdgeMeta);
|
|
258
|
+
get index(): number;
|
|
259
|
+
get curve(): EdgeMeta["curve"];
|
|
260
|
+
get length(): number;
|
|
261
|
+
get center(): Vec3;
|
|
262
|
+
get direction(): Vec3 | undefined;
|
|
263
|
+
get axis(): Axis | undefined;
|
|
264
|
+
get radius(): number | undefined;
|
|
265
|
+
}
|
|
266
|
+
type FilterBy<T> = Axis | Plane | string | ((item: T) => boolean);
|
|
267
|
+
/**
|
|
268
|
+
* A typed, chainable collection of sub-shapes, build123d-style.
|
|
269
|
+
*
|
|
270
|
+
* - `filterBy(Axis)`: planar faces with parallel normal, line edges with
|
|
271
|
+
* parallel tangent; everything else drops out.
|
|
272
|
+
* - `filterBy(Plane)`: faces parallel to the plane; circle/ellipse edges
|
|
273
|
+
* lying in the plane; line edges with center in plane and tangent ⊥ normal.
|
|
274
|
+
* - `filterBy("cylinder" | "line" | ...)`: geometry-type equality.
|
|
275
|
+
* - `filterBy(fn)`: custom predicate.
|
|
276
|
+
*/
|
|
277
|
+
declare class ShapeList<T extends Face | Edge> implements Iterable<T> {
|
|
278
|
+
#private;
|
|
279
|
+
readonly items: readonly T[];
|
|
280
|
+
constructor(items: readonly T[]);
|
|
281
|
+
[Symbol.iterator](): Iterator<T>;
|
|
282
|
+
count(): number;
|
|
283
|
+
first(): T | undefined;
|
|
284
|
+
last(): T | undefined;
|
|
285
|
+
/** Exactly one, else a structured error (build123d raises on ambiguity). */
|
|
286
|
+
single(what?: string): T;
|
|
287
|
+
filterBy(filter: FilterBy<T>, opts?: {
|
|
288
|
+
reverse?: boolean;
|
|
289
|
+
}): ShapeList<T>;
|
|
290
|
+
/**
|
|
291
|
+
* Filter and sort by sub-shape center projected on `axis`
|
|
292
|
+
* (build123d `filter_by_position`).
|
|
293
|
+
*/
|
|
294
|
+
filterByPosition(axis: Axis, minimum: number, maximum: number, inclusive?: [boolean, boolean]): ShapeList<T>;
|
|
295
|
+
/**
|
|
296
|
+
* Group by a key then return the groups sorted by that key
|
|
297
|
+
* (build123d `group_by`; Axis keys project centers, rounded to 6 digits).
|
|
298
|
+
*/
|
|
299
|
+
groupBy(key: Axis | "length" | "radius" | "area" | "volume" | ((item: T) => number | string)): ShapeList<T>[];
|
|
300
|
+
/** Sort (build123d `sort_by`); Axis keys project centers on the axis). */
|
|
301
|
+
sortBy(key: Axis | "length" | "radius" | "area" | "volume" | ((item: T) => number), reverse?: boolean): ShapeList<T>;
|
|
302
|
+
sortByKey(keyFn: (item: T) => number | string, reverse?: boolean): ShapeList<T>;
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
export { Vec3 as C, v as E, Plane as S, planeFrom as T, AxisName as _, ShapeList as a, Location as b, EdgeMeta as c, Kernel as d, ShapeHandle as f, Axis3 as g, Axis as h, Shape as i, FaceMeta as l, SurfaceKind as m, Edge as n, Solid as o, ShapeMeta as p, Face as r, CurveKind as s, Describe as t, HoleMeta as u, BBox as v, axisByName as w, Mesh as x, Loc as y };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { C as Vec3, E as v, S as Plane, T as planeFrom, _ as AxisName, a as ShapeList, b as Location, c as EdgeMeta, d as Kernel, f as ShapeHandle, g as Axis3, h as Axis, i as Shape, l as FaceMeta, m as SurfaceKind, n as Edge, o as Solid, p as ShapeMeta, r as Face, s as CurveKind, t as Describe, u as HoleMeta, v as BBox, w as axisByName, x as Mesh, y as Loc } from "./index-DceghC4N.js";
|
|
2
|
+
import "occt.ts";
|
|
3
|
+
//#region src/io/index.d.ts
|
|
4
|
+
type ExportFormat = "step" | "stl" | "glb";
|
|
5
|
+
export declare function exportStep(s: Shape): Uint8Array;
|
|
6
|
+
export declare function exportStl(s: Shape, tolerance?: number): string;
|
|
7
|
+
export declare function exportGlb(s: Shape): Uint8Array;
|
|
8
|
+
export declare function importStep(data: Uint8Array | string): Promise<Solid>;
|
|
9
|
+
/** Writes a shape to disk (Node). Extension picks the format. */
|
|
10
|
+
export declare function exportShape(s: Shape, path: string, opts?: {
|
|
11
|
+
tolerance?: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/kernel/occt.d.ts
|
|
15
|
+
interface InitOptions {
|
|
16
|
+
/** Explicit URL or path to the OCCT WASM binary (file, http(s) or data:). */
|
|
17
|
+
wasmUrl?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Loads the OCCT WASM kernel exactly once per process (idempotent). */
|
|
20
|
+
export declare function init(opts?: InitOptions): Promise<void>;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/ops/index.d.ts
|
|
23
|
+
export declare function fuse(a: Solid, b: Shape, opts?: {
|
|
24
|
+
clean?: boolean;
|
|
25
|
+
}): Solid;
|
|
26
|
+
export declare function cut(a: Solid, b: Shape, opts?: {
|
|
27
|
+
clean?: boolean;
|
|
28
|
+
}): Solid;
|
|
29
|
+
/** build123d `intersect` — OCCT `common`. */
|
|
30
|
+
export declare function intersect(a: Solid, b: Shape, opts?: {
|
|
31
|
+
clean?: boolean;
|
|
32
|
+
}): Solid;
|
|
33
|
+
/** Keep the OCCT name for code translated from CadQuery. */
|
|
34
|
+
export declare const common: typeof intersect;
|
|
35
|
+
export declare function fillet(s: Shape, edges: ShapeList<Edge> | readonly Edge[], radius: number): Solid;
|
|
36
|
+
/** Equal-distance chamfer; asymmetric needs kernel support (R3). */
|
|
37
|
+
export declare function chamfer(s: Shape, edges: ShapeList<Edge> | readonly Edge[], distance: number): Solid;
|
|
38
|
+
export declare function translate(s: Shape, by: readonly [number, number, number]): Solid;
|
|
39
|
+
/** M1: extrude a 2D sketch into a solid. */
|
|
40
|
+
export declare function extrude(_sketch: unknown, _height: number): Solid;
|
|
41
|
+
/** M1: revolve a 2D sketch around an axis. */
|
|
42
|
+
export declare function revolve(_sketch: unknown, _axis: unknown, _angle?: number): Solid;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/primitives/index.d.ts
|
|
45
|
+
export declare function Box(dx: number, dy: number, dz: number, loc?: Loc): Solid;
|
|
46
|
+
export declare function Cylinder(opts: {
|
|
47
|
+
radius: number;
|
|
48
|
+
height: number;
|
|
49
|
+
loc?: Loc;
|
|
50
|
+
}): Solid;
|
|
51
|
+
export declare function Sphere(opts: {
|
|
52
|
+
radius: number;
|
|
53
|
+
loc?: Loc;
|
|
54
|
+
}): Solid;
|
|
55
|
+
export declare function Cone(opts: {
|
|
56
|
+
radius1: number;
|
|
57
|
+
radius2: number;
|
|
58
|
+
height: number;
|
|
59
|
+
loc?: Loc;
|
|
60
|
+
}): Solid;
|
|
61
|
+
export declare function Torus(opts: {
|
|
62
|
+
radius1: number;
|
|
63
|
+
radius2: number;
|
|
64
|
+
loc?: Loc;
|
|
65
|
+
}): Solid;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/record.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Op recording — the day-one rule from docs/architecture.md §3.3:
|
|
70
|
+
* every mutating core operation goes through `record()`, so the runtime
|
|
71
|
+
* Session/OpLog can observe, snapshot and replay the exact same stream
|
|
72
|
+
* regardless of which API style (core algebra or workplane facade) produced it.
|
|
73
|
+
*
|
|
74
|
+
* With no subscribers installed this is a transparent pass-through.
|
|
75
|
+
*/
|
|
76
|
+
interface OpRecord {
|
|
77
|
+
/** Monotonic, process-wide — the id the OpLog keys snapshots by. */
|
|
78
|
+
readonly id: number;
|
|
79
|
+
readonly type: string;
|
|
80
|
+
readonly args: unknown;
|
|
81
|
+
}
|
|
82
|
+
type OpStatus = "done" | "error";
|
|
83
|
+
interface OpEvent {
|
|
84
|
+
readonly op: OpRecord;
|
|
85
|
+
readonly status: OpStatus;
|
|
86
|
+
readonly result?: ShapeHandle;
|
|
87
|
+
readonly error?: unknown;
|
|
88
|
+
}
|
|
89
|
+
type OpListener = (event: OpEvent) => void;
|
|
90
|
+
/** Subscribe to every recorded operation. Returns an unsubscribe function. */
|
|
91
|
+
export declare function onOp(listener: OpListener): () => void;
|
|
92
|
+
/**
|
|
93
|
+
* Runs `run()` and records it as one op. Errors propagate unchanged after
|
|
94
|
+
* being recorded — structured error mapping (runtime) subscribes via onOp.
|
|
95
|
+
*/
|
|
96
|
+
export declare function record<T>(type: string, args: unknown, run: () => T): T;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/selectors/index.d.ts
|
|
99
|
+
type SubShape = Face | Edge;
|
|
100
|
+
interface Selector {
|
|
101
|
+
/** The source string, for error messages and op-log readability. */
|
|
102
|
+
readonly source: string;
|
|
103
|
+
select(items: readonly SubShape[]): SubShape[];
|
|
104
|
+
}
|
|
105
|
+
/** Parses a CadQuery-style selector string into an executable selector. */
|
|
106
|
+
export declare function parseSelector(source: string): Selector;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { Axis, type Axis3, type AxisName, type BBox, type CurveKind, type Describe, Edge, type EdgeMeta, type ExportFormat, Face, type FaceMeta, type HoleMeta, type InitOptions, type Kernel, type Loc, type Location, type Mesh, type OpEvent, type OpListener, type OpRecord, type OpStatus, type Plane, type Selector, Shape, type ShapeHandle, ShapeList, type ShapeMeta, Solid, type SubShape, type SurfaceKind, type Vec3, axisByName, planeFrom, v };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { a as importStep, i as exportStl, n as exportShape, r as exportStep, t as exportGlb } from "./io-DD2D1UYF.js";
|
|
2
|
+
import { _ as Axis, a as Sphere, b as v, c as Face, d as Solid, g as init, i as Cylinder, l as Shape, m as record, n as Box, o as Torus, p as onOp, r as Cone, s as Edge, t as parseSelector, u as ShapeList, v as axisByName, y as planeFrom } from "./selectors-C0-da9aQ.js";
|
|
3
|
+
//#region src/util.ts
|
|
4
|
+
/** Thrown by every skeleton stub until the real M0 implementation lands. */
|
|
5
|
+
var NotImplementedError = class extends Error {
|
|
6
|
+
constructor(what) {
|
|
7
|
+
super(`${what} is not implemented yet — this is the M0 repository skeleton.`);
|
|
8
|
+
this.name = "NotImplementedError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
/** Stub body helper: keeps signatures real while bodies wait for M0. */
|
|
12
|
+
function todo(what) {
|
|
13
|
+
throw new NotImplementedError(what);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/ops/index.ts
|
|
17
|
+
function fuse(a, b, opts) {
|
|
18
|
+
return a.fuse(b, opts);
|
|
19
|
+
}
|
|
20
|
+
function cut(a, b, opts) {
|
|
21
|
+
return a.cut(b, opts);
|
|
22
|
+
}
|
|
23
|
+
/** build123d `intersect` — OCCT `common`. */
|
|
24
|
+
function intersect(a, b, opts) {
|
|
25
|
+
return a.common(b, opts);
|
|
26
|
+
}
|
|
27
|
+
/** Keep the OCCT name for code translated from CadQuery. */
|
|
28
|
+
const common = intersect;
|
|
29
|
+
function fillet(s, edges, radius) {
|
|
30
|
+
return s.fillet(edges, radius);
|
|
31
|
+
}
|
|
32
|
+
/** Equal-distance chamfer; asymmetric needs kernel support (R3). */
|
|
33
|
+
function chamfer(s, edges, distance) {
|
|
34
|
+
return s.chamfer(edges, distance);
|
|
35
|
+
}
|
|
36
|
+
function translate(s, by) {
|
|
37
|
+
return s.translate(by);
|
|
38
|
+
}
|
|
39
|
+
/** M1: extrude a 2D sketch into a solid. */
|
|
40
|
+
function extrude(_sketch, _height) {
|
|
41
|
+
todo("extrude");
|
|
42
|
+
}
|
|
43
|
+
/** M1: revolve a 2D sketch around an axis. */
|
|
44
|
+
function revolve(_sketch, _axis, _angle) {
|
|
45
|
+
todo("revolve");
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { Axis, Box, Cone, Cylinder, Edge, Face, Shape, ShapeList, Solid, Sphere, Torus, axisByName, chamfer, common, cut, exportGlb, exportShape, exportStep, exportStl, extrude, fillet, fuse, importStep, init, intersect, onOp, parseSelector, planeFrom, record, revolve, translate, v };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { f as solidFromKernel, h as getKernel, m as record } from "./selectors-C0-da9aQ.js";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __exportAll = (all, no_symbols) => {
|
|
5
|
+
let target = {};
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/io/index.ts
|
|
15
|
+
/**
|
|
16
|
+
* Import/export. `exportShape(shape, path)` writes to disk in Node; in the
|
|
17
|
+
* browser (or for in-memory pipelines) call the format functions directly.
|
|
18
|
+
*/
|
|
19
|
+
var io_exports = /* @__PURE__ */ __exportAll({
|
|
20
|
+
exportGlb: () => exportGlb,
|
|
21
|
+
exportShape: () => exportShape,
|
|
22
|
+
exportStep: () => exportStep,
|
|
23
|
+
exportStl: () => exportStl,
|
|
24
|
+
importStep: () => importStep
|
|
25
|
+
});
|
|
26
|
+
function exportStep(s) {
|
|
27
|
+
return getKernel().exportStep(s.handle);
|
|
28
|
+
}
|
|
29
|
+
function exportStl(s, tolerance) {
|
|
30
|
+
return getKernel().exportStl(s.handle, tolerance);
|
|
31
|
+
}
|
|
32
|
+
function exportGlb(s) {
|
|
33
|
+
return getKernel().exportGlb(s.handle);
|
|
34
|
+
}
|
|
35
|
+
function importStep(data) {
|
|
36
|
+
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
37
|
+
return Promise.resolve(record("importStep", { bytes: bytes.length }, () => solidFromKernel(getKernel().importStep(bytes))));
|
|
38
|
+
}
|
|
39
|
+
function formatFor(path) {
|
|
40
|
+
const ext = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
41
|
+
if (ext === "step" || ext === "stp" || ext === "stl" || ext === "glb") return ext === "stp" ? "step" : ext;
|
|
42
|
+
throw new Error(`Unsupported export extension in ${JSON.stringify(path)} — use .step, .stl or .glb.`);
|
|
43
|
+
}
|
|
44
|
+
/** Writes a shape to disk (Node). Extension picks the format. */
|
|
45
|
+
async function exportShape(s, path, opts) {
|
|
46
|
+
const format = formatFor(path);
|
|
47
|
+
const payload = format === "step" ? exportStep(s) : format === "glb" ? exportGlb(s) : exportStl(s, opts?.tolerance);
|
|
48
|
+
const { writeFile } = await import("node:fs/promises");
|
|
49
|
+
await writeFile(path, payload);
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { importStep as a, exportStl as i, exportShape as n, io_exports as o, exportStep as r, exportGlb as t };
|