@indispec/fs-compat 0.0.0-stage → 0.1.1
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/README.md +188 -2
- package/package.json +46 -3
- package/src/engine/assembly.js +481 -0
- package/src/engine/csg.js +580 -0
- package/src/engine/interp.js +1713 -0
- package/src/engine/lex.js +166 -0
- package/src/engine/parse.js +539 -0
- package/src/engine/project.js +409 -0
- package/src/engine/regions.js +923 -0
- package/src/engine/trace.js +211 -0
- package/src/engine/values.js +494 -0
- package/src/index.d.ts +746 -0
- package/src/index.js +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TheTechCompany
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,189 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@indispec/fs-compat`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**FeatureScript-compatible for a documented subset.** A dependency-free lexer, parser, value model
|
|
4
|
+
and interpreter for the FeatureScript language, in plain ESM. No native modules, no build step, no
|
|
5
|
+
dependencies — it runs unchanged in Node (≥ 20) and in a browser worker.
|
|
6
|
+
|
|
7
|
+
The interpreter evaluates a `.fs` module and **records** the geometry it builds as a typed node tree
|
|
8
|
+
(`Box`, `Prism`, `Revolve`, `Union`, `Diff`, `Isect`, `Moved`, `Fillet`, `Loft`, `Sweep`, …). It is
|
|
9
|
+
not a geometry kernel: translating that tree into exact B-rep is a separate concern.
|
|
10
|
+
|
|
11
|
+
> **Status: experimental (0.x).** This is not yet a compatibility promise. The supported subset is
|
|
12
|
+
> real and tested, but the gaps are listed below rather than papered over — and the highest tier,
|
|
13
|
+
> *geometric identity* (same sketch and features producing the same faces as Onshape), is **not
|
|
14
|
+
> claimed**.
|
|
15
|
+
|
|
16
|
+
**Companion:** [`@indispec/cad-kernel`](https://www.npmjs.com/package/@indispec/cad-kernel) turns
|
|
17
|
+
this package's recorded scene into exact OCCT B-rep, metrics and STEP/STL. Pairing the two is the
|
|
18
|
+
supported path — see *Using them together* below.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# The front end alone: parsing, recording, feature tree, BOM.
|
|
24
|
+
npm install @indispec/fs-compat
|
|
25
|
+
|
|
26
|
+
# The recommended pairing: recorded scene -> exact B-rep, metrics, STEP/STL.
|
|
27
|
+
npm install @indispec/fs-compat @indispec/cad-kernel
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Using them together (recommended)
|
|
31
|
+
|
|
32
|
+
This package is the front end: it records what an `.fs` program builds, it does not make faces.
|
|
33
|
+
Exact geometry is the other package's job, and the hand-off is `interp.scene` — a recorded `Scene`
|
|
34
|
+
of typed nodes (`Box`, `Prism`, `Union`, `Moved`, …). No glue code is needed on either side:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import { runFeature } from '@indispec/fs-compat'
|
|
38
|
+
import { initKernel, translateScene, evaluateBodies, exportSceneStep } from '@indispec/cad-kernel'
|
|
39
|
+
|
|
40
|
+
await initKernel() // OCCT wasm, once per process
|
|
41
|
+
const { interp } = runFeature(source, null, null, { includes }) // record
|
|
42
|
+
const bodies = translateScene(interp.scene) // record -> exact B-rep
|
|
43
|
+
const result = evaluateBodies(bodies, { chordMm: 0.5, angleDeg: 15 }) // exact metrics + display mesh
|
|
44
|
+
result.bodies[0].volumeMm3 // from the B-rep, not the mesh
|
|
45
|
+
const step = await exportSceneStep(bodies) // STEP bytes, millimetres
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The two packages are released independently, and the kernel declares the `@indispec/fs-compat` range
|
|
49
|
+
it was built and tested against — so installing the pair is enough, there is no version to pin by
|
|
50
|
+
hand.
|
|
51
|
+
|
|
52
|
+
In a browser module Worker the pairing is **one call, and one package to import**:
|
|
53
|
+
[`@indispec/cad-kernel/browser`](https://www.npmjs.com/package/@indispec/cad-kernel) runs the
|
|
54
|
+
interpreter, translates, measures and tessellates in the worker, and writes STEP/STL there too:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import wasmUrl from 'replicad-opencascadejs/wasm?url'
|
|
58
|
+
import { initBrowserKernel, evaluateBrowser } from '@indispec/cad-kernel/browser'
|
|
59
|
+
|
|
60
|
+
await initBrowserKernel({ wasmUrl })
|
|
61
|
+
const result = await evaluateBrowser({ source, includes, overrides: ['plateLen=240mm'], trace: true })
|
|
62
|
+
// result.positions / result.indices are transferable typed arrays
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Both hosts take the same document inputs — `source`, `includes`, `featureName`, `sourceName` and
|
|
66
|
+
`overrides` (the Node host through `parseOverrides`) — plus `trace` and `stopAfter` where history or
|
|
67
|
+
a rollback view is wanted, so authored defaults, project value bindings and rollback behave
|
|
68
|
+
identically on a server and in a worker.
|
|
69
|
+
|
|
70
|
+
**When this package alone is the right tool:** syntax checking, parameter binding, a feature tree or
|
|
71
|
+
BOM (`projectFeatureList`, `assemblyBom`), sketch regions, or an editor that renders the trace — any
|
|
72
|
+
use that reads the language and the recording rather than the solid. The first time you need a
|
|
73
|
+
volume, a watertight mesh or a STEP file, add the kernel.
|
|
74
|
+
|
|
75
|
+
## Quickstart
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import { runFeature } from '@indispec/fs-compat'
|
|
79
|
+
|
|
80
|
+
const source = `
|
|
81
|
+
annotation { "Feature Type Name" : "Bound plate" }
|
|
82
|
+
export const boundPlate = defineFeature(function(context is Context, id is Id, definition is map)
|
|
83
|
+
precondition
|
|
84
|
+
{
|
|
85
|
+
annotation { "Name" : "Plate length" }
|
|
86
|
+
isLength(definition.plateLen, { (millimeter) : [60, 120, 240] });
|
|
87
|
+
}
|
|
88
|
+
{
|
|
89
|
+
var plateLen = definition.plateLen / millimeter;
|
|
90
|
+
var sk = newSketchOnPlane(context, id + "sk", {
|
|
91
|
+
"sketchPlane" : plane(coordSystem(vector(0, 0, 0) * millimeter, vector(1, 0, 0), vector(0, 0, 1)))
|
|
92
|
+
});
|
|
93
|
+
skCircle(sk, "c", { "center" : vector(0, 0), "radius" : 10 * millimeter });
|
|
94
|
+
skSolve(sk);
|
|
95
|
+
opExtrude(context, id + "ex", {
|
|
96
|
+
"entities" : qCreatedBy(id + "sk", EntityType.FACE),
|
|
97
|
+
"direction" : vector(0, 0, 1),
|
|
98
|
+
"endBound" : BoundingType.BLIND,
|
|
99
|
+
"endDepth" : plateLen * millimeter
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
`
|
|
104
|
+
|
|
105
|
+
const { interp, trace } = runFeature(source, null, null, { trace: true, sourceName: 'plate.fs' })
|
|
106
|
+
|
|
107
|
+
interp.scene.solids.length // 1 recorded solid
|
|
108
|
+
trace.find((entry) => entry.op === 'opExtrude').definition // the invocation's definition
|
|
109
|
+
.endDepth.value // 120 (mm, the authored default)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Bind parameters without rewriting the source
|
|
113
|
+
|
|
114
|
+
The committed program keeps its authored defaults — so it stays portable and valid FeatureScript
|
|
115
|
+
elsewhere — while evaluation runs with values bound from outside:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import { runFeature, parseOverrides } from '@indispec/fs-compat'
|
|
119
|
+
|
|
120
|
+
runFeature(source, null, parseOverrides(['plateLen=240mm'])) // endDepth is now 240
|
|
121
|
+
runFeature(source, null, parseOverrides(['plateLen=12cm'])) // 120 — units are carried
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Values use the engine's own value grammar. An unknown parameter name is an error, never a silent
|
|
125
|
+
ignore.
|
|
126
|
+
|
|
127
|
+
## What you get
|
|
128
|
+
|
|
129
|
+
| Export | Purpose |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `parse(source, sourceName?)` | AST; every node carries an absolute source span |
|
|
132
|
+
| `runFeature(source, featureName?, overrides?, options?)` | Evaluate one custom feature; returns `{ interp, feature, definition, trace, rolledBack }` |
|
|
133
|
+
| `runAssembly(source, ...)` | Record an assembly (instances + placements) instead of solids |
|
|
134
|
+
| `parseOverrides(pairs)` | `name=value` texts → typed values |
|
|
135
|
+
| `scene`, `Solid`, `Node`, geometry classes | The recorded node tree a kernel translates |
|
|
136
|
+
| `sketchRegions`, `regionPolygon`, `regionArea`, … | Sketch topology: contours chained into closed regions with holes |
|
|
137
|
+
| `projectFeatureList`, `projectAssemblyList`, `assemblyBom` | The authored feature tree / BOM derived from the execution trace |
|
|
138
|
+
| `Q`, `Xf`, `Plane`, `Id`, `Color`, `Vec` | The value model (millimetres, radians) |
|
|
139
|
+
|
|
140
|
+
`options.trace` records one entry per feature-producing call with its runtime id path, its source
|
|
141
|
+
span, the call frames that produced it and a snapshot of its definition — which is what an editor's
|
|
142
|
+
feature tree is derived from. `options.stopAfter` stops after N recorded features, for a rollback
|
|
143
|
+
view.
|
|
144
|
+
|
|
145
|
+
Implemented host operations include sketch creation (`newSketchOnPlane`/`skSolve`, lines, arcs,
|
|
146
|
+
circles), `opExtrude` (new/add/remove/intersect, including planar-face profiles), `opBoolean`,
|
|
147
|
+
`opPattern`, `opTransform`, `opDeleteBodies`, `opFillet`, `opChamfer`, `opShell`, `opLoft`,
|
|
148
|
+
`opSweep`, `setProperty`, `reportFeature*`, and assembly composition (`instance`, `part`).
|
|
149
|
+
|
|
150
|
+
## Known gaps
|
|
151
|
+
|
|
152
|
+
These are the **silent** divergences from the reference semantics — the cases where the interpreter
|
|
153
|
+
does something rather than refusing. They are the reason the compatibility claim is not made yet.
|
|
154
|
+
|
|
155
|
+
- **`endBound` is ignored.** Only `BLIND` is honoured; `UP_TO_*` extrudes are treated as blind.
|
|
156
|
+
- **`opRevolve` uses only the first profile** in a sketch; the rest are dropped.
|
|
157
|
+
- **`is` is permissive and `as` is an identity cast.** `is` returns true for any non-boolean value.
|
|
158
|
+
- **`precondition` predicates are not evaluated.** `isLength`, `isNumber`, … all report satisfied; only
|
|
159
|
+
parameter defaults are read from the precondition block.
|
|
160
|
+
- **`setProperty` honours `NAME` and `APPEARANCE` only**, and silently drops other property types.
|
|
161
|
+
- **`import()` is a no-op.** Libraries are prepended textually by `applyIncludes`, so line numbers in
|
|
162
|
+
diagnostics shift relative to the original file.
|
|
163
|
+
- **No FeatureScript standard library is bundled.** Calls into it must be supplied through
|
|
164
|
+
`options.includes`, or they raise an unsupported-function error.
|
|
165
|
+
- There is no B-rep, no tessellation and no geometric-identity guarantee.
|
|
166
|
+
|
|
167
|
+
Syntax and runtime errors do carry a line, column, an absolute span and the source name.
|
|
168
|
+
|
|
169
|
+
## Development
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
node --test test/*.test.mjs # 46 tests, no dependencies
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Provenance and license
|
|
176
|
+
|
|
177
|
+
MIT — see [LICENSE](LICENSE).
|
|
178
|
+
|
|
179
|
+
The engine originated in the `featurescript-studio` project (itself split out of `nitrate-producer`)
|
|
180
|
+
and was extracted into the IndiSpec monorepo. Two deliberate departures from that origin: the
|
|
181
|
+
geometry kernel is not included (only the recorded node tree — pair it with
|
|
182
|
+
[`@indispec/cad-kernel`](https://www.npmjs.com/package/@indispec/cad-kernel) for exact geometry), and
|
|
183
|
+
the GLSL emitter, clip algebra and tessellation code are not carried over.
|
|
184
|
+
|
|
185
|
+
No third-party code is bundled. The FeatureScript standard library is *not* included; when it is
|
|
186
|
+
vendored it is MIT-licensed (© PTC Inc.) and its notice will ship with it.
|
|
187
|
+
|
|
188
|
+
FeatureScript and Onshape are trademarks of PTC Inc. This project is not affiliated with or endorsed
|
|
189
|
+
by PTC.
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indispec/fs-compat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "FeatureScript-compatible lexer, parser, value model and interpreter for a documented language subset.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "TheTechCompany",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "src/index.js",
|
|
9
|
+
"types": "src/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./src/index.d.ts",
|
|
13
|
+
"default": "./src/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src/"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"featurescript",
|
|
25
|
+
"cad",
|
|
26
|
+
"parametric",
|
|
27
|
+
"interpreter",
|
|
28
|
+
"parser",
|
|
29
|
+
"lexer",
|
|
30
|
+
"b-rep",
|
|
31
|
+
"language"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/TheTechCompany/IndiSpec.git",
|
|
36
|
+
"directory": "packages/cad/featurescript"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/TheTechCompany/IndiSpec/tree/main/packages/cad/featurescript",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/TheTechCompany/IndiSpec/issues"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"test": "node --test test/*.test.mjs",
|
|
47
|
+
"prepublishOnly": "node --test test/*.test.mjs"
|
|
48
|
+
}
|
|
6
49
|
}
|