@snaptrude/plugin-core 1.0.2-plainpoint-20261026.2 → 1.0.2-plainpoint-20261102.2
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 +1 -0
- package/CHANGELOG.md +12 -0
- package/api-manifest.json +116 -39
- package/dist/api/core/camera/index.d.ts +4 -2
- package/dist/api/core/camera/index.d.ts.map +1 -1
- package/dist/api/core/storeys/index.d.ts +5 -0
- package/dist/api/core/storeys/index.d.ts.map +1 -1
- package/dist/api/design/create/bulk-items.d.ts +64 -12
- package/dist/api/design/create/bulk-items.d.ts.map +1 -1
- package/dist/api/design/create/index.d.ts +67 -32
- package/dist/api/design/create/index.d.ts.map +1 -1
- package/dist/api/design/create/opening-fields.d.ts +18 -6
- package/dist/api/design/create/opening-fields.d.ts.map +1 -1
- package/dist/api/design/erase/index.d.ts +2 -10
- package/dist/api/design/erase/index.d.ts.map +1 -1
- package/dist/api/design/index.d.ts +5 -0
- package/dist/api/design/index.d.ts.map +1 -1
- package/dist/api/design/text.d.ts +400 -0
- package/dist/api/design/text.d.ts.map +1 -0
- package/dist/api/entity/story.d.ts +4 -0
- package/dist/api/entity/story.d.ts.map +1 -1
- package/dist/api/presentation/drawings.d.ts +45 -0
- package/dist/api/presentation/drawings.d.ts.map +1 -1
- package/dist/api/presentation/graphics.d.ts +4 -0
- package/dist/api/presentation/graphics.d.ts.map +1 -1
- package/dist/api/presentation/placedViews.d.ts +29 -1
- package/dist/api/presentation/placedViews.d.ts.map +1 -1
- package/dist/api/presentation/standards.d.ts +14 -0
- package/dist/api/presentation/standards.d.ts.map +1 -1
- package/dist/api/presentation/views.d.ts +5 -1
- package/dist/api/presentation/views.d.ts.map +1 -1
- package/dist/index.cjs +2209 -2102
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2197 -2102
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/core/camera/index.ts +4 -2
- package/src/api/core/storeys/index.ts +5 -0
- package/src/api/design/create/bulk-items.ts +4 -0
- package/src/api/design/create/index.ts +7 -20
- package/src/api/design/create/opening-fields.ts +7 -7
- package/src/api/design/erase/index.ts +2 -2
- package/src/api/design/index.ts +5 -0
- package/src/api/design/text.ts +394 -0
- package/src/api/entity/story.ts +4 -0
- package/src/api/presentation/graphics.ts +4 -1
- package/src/api/presentation/placedViews.ts +12 -0
- package/src/api/presentation/standards.ts +6 -0
- package/src/api/presentation/views.ts +7 -2
- package/test/designText.test.mjs +72 -0
- package/test/paperPensContract.test.mjs +39 -0
package/package.json
CHANGED
|
@@ -30,12 +30,14 @@ export abstract class PluginCameraApi {
|
|
|
30
30
|
* Point the camera: place its eye at `eye` looking toward `target` (world
|
|
31
31
|
* coordinates, internal `babylon` units). View-state only — not undoable.
|
|
32
32
|
*
|
|
33
|
+
* From a 2D plan the camera first switches to 3D (a plan's camera is pinned
|
|
34
|
+
* top-down, so an eye there would be ignored); read `getPose().mode` after.
|
|
33
35
|
* While Present is open this sets the Design frame a view saved in Present
|
|
34
36
|
* is taken from; it never moves the Present sheet canvas; use
|
|
35
37
|
* `presentation.camera` for that.
|
|
36
38
|
*
|
|
37
|
-
* @param eye - Camera position
|
|
38
|
-
* @param target - Point the camera looks at
|
|
39
|
+
* @param eye - Camera position: a {@linkcode Vec3Handle} or a plain `{ x, y, z }`
|
|
40
|
+
* @param target - Point the camera looks at: a {@linkcode Vec3Handle} or a plain `{ x, y, z }`
|
|
39
41
|
* @returns `true` once the camera has been positioned.
|
|
40
42
|
*
|
|
41
43
|
* @examplePrompt Look at the model from above the north-east corner
|
|
@@ -101,6 +101,11 @@ export abstract class PluginCoreStoreysApi {
|
|
|
101
101
|
* The new storey is inserted at the position specified by `storyValue`. This
|
|
102
102
|
* operation is undoable.
|
|
103
103
|
*
|
|
104
|
+
* Storeys are added at the ends of the stack only. A value above the top (or below the
|
|
105
|
+
* bottom) also creates every storey in between at the default height — `create(5)` on a
|
|
106
|
+
* stack of 1–2 adds 3, 4 and 5 and returns only 5 — and a value inside a gap of the
|
|
107
|
+
* stack is refused (PRECONDITION_FAILED). Read the stack back with `list` afterwards.
|
|
108
|
+
*
|
|
104
109
|
* @param storyValue - Integer storey number
|
|
105
110
|
* to create (e.g. `3` to add a third floor)
|
|
106
111
|
* @param height - Optional height in Babylon
|
|
@@ -38,6 +38,10 @@ export type PluginWallTopProfilePoint = z.infer<
|
|
|
38
38
|
>
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
+
* Current hosts refuse a non-null top profile (`PRECONDITION_FAILED`, "Walls have one
|
|
42
|
+
* height: sloped or stepped tops are not supported") and create nothing; the shape is
|
|
43
|
+
* kept for compatibility. The description below is the original contract.
|
|
44
|
+
*
|
|
41
45
|
* The top edge of ONE wall as a polyline over its centerline: at least two
|
|
42
46
|
* points, `along` strictly increasing from `0` (curve start) to `1` (curve end),
|
|
43
47
|
* straight segments between them. Two points give a single slope (a raked
|
|
@@ -497,10 +497,10 @@ export abstract class PluginDesignCreateApi {
|
|
|
497
497
|
* single undo entry. The storey must already exist
|
|
498
498
|
* (`core.storeys.create` first). Default: geometry-derived — a profile
|
|
499
499
|
* drawn at y = 0 lands on storey 1; the ACTIVE storey is NOT consulted.
|
|
500
|
-
* @param topProfiles -
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
500
|
+
* @param topProfiles - Top edge per curve of `profile` (same order). Current
|
|
501
|
+
* hosts build walls with one height: any non-null entry is refused with
|
|
502
|
+
* `PRECONDITION_FAILED` ("sloped or stepped tops are not supported") and
|
|
503
|
+
* nothing is created. Pass `null` entries or omit it.
|
|
504
504
|
* @returns a {@linkcode ComponentHandle}`[]` (one per wall), in profile order
|
|
505
505
|
* @throws if the profile is empty, `wallType` names no wall type in the
|
|
506
506
|
* project, `storey` does not exist, `topProfiles` has more entries than the
|
|
@@ -514,9 +514,6 @@ export abstract class PluginDesignCreateApi {
|
|
|
514
514
|
* @examplePrompt Add walls with mitred corners along the path
|
|
515
515
|
* @examplePrompt Draw brick walls with plaster along this outline
|
|
516
516
|
* @examplePrompt Build the perimeter in exposed concrete walls
|
|
517
|
-
* @examplePrompt Create a raked wall that slopes from 3m to 5m
|
|
518
|
-
* @examplePrompt Build a gable end wall with the ridge in the middle
|
|
519
|
-
* @examplePrompt Draw a wall with a sloped top edge
|
|
520
517
|
*
|
|
521
518
|
* # Example
|
|
522
519
|
* ```ts
|
|
@@ -532,13 +529,6 @@ export abstract class PluginDesignCreateApi {
|
|
|
532
529
|
* const brickWalls = await snaptrude.design.create.walls(
|
|
533
530
|
* centerlines, 3, undefined, brick.label,
|
|
534
531
|
* )
|
|
535
|
-
* // …a raked wall (3m at the start, 5m at the end) on a single centerline:
|
|
536
|
-
* const run = await snaptrude.core.geom.create.profileFromCurves([
|
|
537
|
-
* await snaptrude.core.geom.create.line(await v.new(0, 0, 10), await v.new(8, 0, 10)),
|
|
538
|
-
* ])
|
|
539
|
-
* const [raked] = await snaptrude.design.create.walls(run, undefined, 0.2, undefined, undefined, [
|
|
540
|
-
* [{ along: 0, height: 3 }, { along: 1, height: 5 }],
|
|
541
|
-
* ])
|
|
542
532
|
* ```
|
|
543
533
|
*
|
|
544
534
|
* @performance For MORE THAN ONE run, call `design.create.wallRuns(items[])` — one
|
|
@@ -561,8 +551,9 @@ export abstract class PluginDesignCreateApi {
|
|
|
561
551
|
* item's profile chain, mitred at shared endpoints. Junctions resolve within a
|
|
562
552
|
* run, not between runs. Each item carries its own
|
|
563
553
|
* dimensions, `wallType` and `storey`, so a single call can build a whole
|
|
564
|
-
* floor plate or several storeys at once.
|
|
565
|
-
*
|
|
554
|
+
* floor plate or several storeys at once. Walls have one height: a non-null
|
|
555
|
+
* `topProfiles` entry is refused with `PRECONDITION_FAILED` (`details.itemIndex`
|
|
556
|
+
* names the item) and nothing is created. Validate-all-or-throw;
|
|
566
557
|
* one command.
|
|
567
558
|
*
|
|
568
559
|
* @param items - One {@linkcode PluginCreateWallRunItem} per run to create
|
|
@@ -583,7 +574,6 @@ export abstract class PluginDesignCreateApi {
|
|
|
583
574
|
* @examplePrompt Bulk create wall runs from these centerlines
|
|
584
575
|
* @examplePrompt Create the walls for both storeys in a single undo step
|
|
585
576
|
* @examplePrompt Turn these polylines into 200mm brick walls together
|
|
586
|
-
* @examplePrompt Import these raked walls with their top profiles in one go
|
|
587
577
|
*
|
|
588
578
|
* @performance Bulk creator — the whole batch is ONE host round-trip and ONE undo
|
|
589
579
|
* entry. Always prefer this over calling `design.create.walls` in a loop: build the
|
|
@@ -604,9 +594,6 @@ export abstract class PluginDesignCreateApi {
|
|
|
604
594
|
* const [groundWalls, upperWalls] = await snaptrude.design.create.wallRuns([
|
|
605
595
|
* { profile: ground, height: 3, thickness: 0.2 },
|
|
606
596
|
* { profile: upper, height: 3, storey: 2 },
|
|
607
|
-
* // one gable wall: 3m at both ends, 5m ridge in the middle
|
|
608
|
-
* { profile: upper, thickness: 0.2, storey: 3,
|
|
609
|
-
* topProfiles: [[{ along: 0, height: 3 }, { along: 0.5, height: 5 }, { along: 1, height: 3 }]] },
|
|
610
597
|
* ])
|
|
611
598
|
* console.log(groundWalls.length, "walls on the ground floor")
|
|
612
599
|
* ```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from "zod"
|
|
2
|
-
import { ComponentHandle,
|
|
2
|
+
import { ComponentHandle, Vec3Input } from "../../../handles"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The shared field bag every hosted opening (door / window) carries — used by
|
|
@@ -17,9 +17,9 @@ import { ComponentHandle, Vec3Handle } from "../../../handles"
|
|
|
17
17
|
* | `version` | `number`? | Exact family version; newest known by default |
|
|
18
18
|
* | `values` | `Record<string, number \| string>`? | Authored instance parameters; numeric lengths use Snaptrude units |
|
|
19
19
|
* | `hostWall` | {@linkcode ComponentHandle} | The wall to host the opening |
|
|
20
|
-
* | `position` | {@linkcode
|
|
21
|
-
* | `facing` | {@linkcode
|
|
22
|
-
* | `hinge` | {@linkcode
|
|
20
|
+
* | `position` | {@linkcode Vec3Input} | World point projected onto the wall (a vec3 handle or a plain `{ x, y, z }`) |
|
|
21
|
+
* | `facing` | {@linkcode Vec3Input}? | World point on the side of the wall the opening swings open to (default engine-chosen) |
|
|
22
|
+
* | `hinge` | {@linkcode Vec3Input}? | World point near the hinged jamb; requires the recipe's hand parameter |
|
|
23
23
|
* | `label` | `string`? | Instance name (optional) |
|
|
24
24
|
* | `width` | `number`? | Sets the declared width parameter, not the opening's evaluated envelope |
|
|
25
25
|
* | `height` | `number`? | Sets the declared height parameter |
|
|
@@ -31,9 +31,9 @@ export const PluginOpeningBaseOptions = {
|
|
|
31
31
|
.record(z.string(), z.union([z.number().finite(), z.string()]))
|
|
32
32
|
.optional(),
|
|
33
33
|
hostWall: ComponentHandle,
|
|
34
|
-
position:
|
|
35
|
-
facing:
|
|
36
|
-
hinge:
|
|
34
|
+
position: Vec3Input,
|
|
35
|
+
facing: Vec3Input.optional(),
|
|
36
|
+
hinge: Vec3Input.optional(),
|
|
37
37
|
label: z.string().optional(),
|
|
38
38
|
width: z.number().finite().positive().optional(),
|
|
39
39
|
height: z.number().finite().positive().optional(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as z from "zod"
|
|
2
2
|
import { PluginApiReturn } from "../../../types"
|
|
3
|
-
import { ComponentHandle,
|
|
3
|
+
import { ComponentHandle, Vec3Handle } from "../../../handles"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The erase strategies exposed to plugins. `SplitAndUnion` is *enumerable* but
|
|
@@ -38,7 +38,7 @@ export const ErasableEdgeRef = z.object({
|
|
|
38
38
|
/** The components this edge is incident to — one for external (DirectDelete); two or more for internal (DirectUnion; 3+ at T-junctions where several masses share the edge). */
|
|
39
39
|
components: z.array(ComponentHandle),
|
|
40
40
|
/** A representative point on the edge (its head endpoint). Diagnostic only. */
|
|
41
|
-
snapPoint:
|
|
41
|
+
snapPoint: Vec3Handle,
|
|
42
42
|
})
|
|
43
43
|
export type ErasableEdgeRef = z.infer<typeof ErasableEdgeRef>
|
|
44
44
|
|
package/src/api/design/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { PluginDesignEditApi } from "./edit"
|
|
|
15
15
|
import { PluginDesignUpdateApi } from "./update"
|
|
16
16
|
import { PluginDesignVisibilityApi } from "./visibility"
|
|
17
17
|
import { PluginDesignDimensionsApi } from "./dimensions"
|
|
18
|
+
import { PluginDesignTextApi } from "./text"
|
|
18
19
|
import { PluginDesignTypesApi } from "./types"
|
|
19
20
|
import { PluginDesignFamilyApi } from "./family"
|
|
20
21
|
import { PluginDesignGridsApi } from "./grids"
|
|
@@ -41,6 +42,7 @@ import {
|
|
|
41
42
|
* - {@linkcode PluginDesignApi.delete} — hard entity removal
|
|
42
43
|
* - {@linkcode PluginDesignApi.visibility} — hide / isolate / reveal entities
|
|
43
44
|
* - {@linkcode PluginDesignApi.dimensions} — dimension lines (Measuring Tape): create / list / delete / hide
|
|
45
|
+
* - {@linkcode PluginDesignApi.text} — authored text and annotations (Text / Annotate tools): create / list / get / update / setLeader
|
|
44
46
|
* - {@linkcode PluginDesignApi.types} — read-only building type / assembly reference
|
|
45
47
|
* - {@linkcode PluginDesignApi.family} — author parametric families from a JSON spec
|
|
46
48
|
* - {@linkcode PluginDesignApi.lock} / {@linkcode PluginDesignApi.unlock} / {@linkcode PluginDesignApi.isLocked} / {@linkcode PluginDesignApi.listLocked} — lock state (top-level design verbs, §2A.1)
|
|
@@ -79,6 +81,8 @@ export abstract class PluginDesignApi {
|
|
|
79
81
|
public abstract visibility: PluginDesignVisibilityApi
|
|
80
82
|
/** Dimension lines (Measuring Tape). See {@linkcode PluginDesignDimensionsApi}. */
|
|
81
83
|
public abstract dimensions: PluginDesignDimensionsApi
|
|
84
|
+
/** Authored text and annotations (Text / Annotate tools). See {@linkcode PluginDesignTextApi}. */
|
|
85
|
+
public abstract text: PluginDesignTextApi
|
|
82
86
|
/** Read-only building type / assembly reference. See {@linkcode PluginDesignTypesApi}. */
|
|
83
87
|
public abstract types: PluginDesignTypesApi
|
|
84
88
|
/** Author parametric families from a JSON spec. See {@linkcode PluginDesignFamilyApi}. */
|
|
@@ -296,6 +300,7 @@ export * from "./edit"
|
|
|
296
300
|
export * from "./update"
|
|
297
301
|
export * from "./visibility"
|
|
298
302
|
export * from "./dimensions"
|
|
303
|
+
export * from "./text"
|
|
299
304
|
export * from "./types"
|
|
300
305
|
export * from "./family"
|
|
301
306
|
export * from "./grids"
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import { PluginApiReturn } from "../../types"
|
|
3
|
+
import { ComponentHandle, Vec3Components, Vec3Handle } from "../../handles"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Authored text — what the Text and Annotate tools place on a drawing.
|
|
7
|
+
*
|
|
8
|
+
* A text is a single line of words drawn flat in its drawing: a **plain text**
|
|
9
|
+
* is centred on its position; an **annotation** is the same text with a leader,
|
|
10
|
+
* a line from an arrowhead (the point it labels) to the text's position, then a
|
|
11
|
+
* short landing to where the words start. Texts are scene components, so their
|
|
12
|
+
* id is a {@linkcode ComponentHandle} and the generic component APIs work on
|
|
13
|
+
* them:
|
|
14
|
+
*
|
|
15
|
+
* - delete: `design.delete.entities`
|
|
16
|
+
* - move / rotate / mirror: `design.transform.*` (the leader travels with the text)
|
|
17
|
+
* - copy: `design.create.copy`
|
|
18
|
+
* - hide / show / isolate: `design.visibility.*`
|
|
19
|
+
* - lock / unlock: `design.lock` / `design.unlock`
|
|
20
|
+
* - select: `design.selection.*`
|
|
21
|
+
*
|
|
22
|
+
* **Where a text lives.** Plan text belongs to one storey and is drawn only in
|
|
23
|
+
* that storey's plan (never in 3D). Text placed while a section or elevation is
|
|
24
|
+
* open belongs to that drawing and is drawn only there. The record's `drawing`
|
|
25
|
+
* and `drawingId` say which.
|
|
26
|
+
*
|
|
27
|
+
* **Size and pens.** A text has no size of its own: every text draws at the
|
|
28
|
+
* project's Text size (Object Styles → Text, `presentation.standards`
|
|
29
|
+
* `annotation.Text.textMm`, paper mm) at the active view scale, and the leader
|
|
30
|
+
* draws with the Text category's projection pen
|
|
31
|
+
* (`presentation.graphics` / `presentation.standards` `objectStyles.Text`).
|
|
32
|
+
* Present sheets restyle all texts of a placed view at once through the
|
|
33
|
+
* `"Text"` and `"Annotation"` categories of
|
|
34
|
+
* `presentation.placedViews.updateStyles` (colour, font, leader visibility).
|
|
35
|
+
*
|
|
36
|
+
* **Fonts.** `fontFamily` is a Google Fonts family (`"Inter"`, `"Roboto"`,
|
|
37
|
+
* `"Open Sans"`, …) or one of the built-ins `"Arial"`, `"Helvetica"`,
|
|
38
|
+
* `"Times New Roman"`, `"Courier New"`, matched case-insensitively and stored
|
|
39
|
+
* in its canonical spelling; an unknown family is refused (`VALIDATION`). A
|
|
40
|
+
* font style the family does not have falls back to `"Regular"`, as in the
|
|
41
|
+
* Properties panel, so read back the style that applied.
|
|
42
|
+
*
|
|
43
|
+
* **Units.** Positions are world points in Babylon units (1 BU = 0.254 m).
|
|
44
|
+
*
|
|
45
|
+
* Every mutator here commits through the engine's command manager: one undo
|
|
46
|
+
* entry per call, autosaved, replayed to collaborators.
|
|
47
|
+
*
|
|
48
|
+
* Accessed via `snaptrude.design.text`.
|
|
49
|
+
*/
|
|
50
|
+
export abstract class PluginDesignTextApi {
|
|
51
|
+
constructor() {}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Place a text, or an annotation when `options.arrowhead` is given.
|
|
55
|
+
*
|
|
56
|
+
* Where it goes:
|
|
57
|
+
* - `options.storey` given → plan text on that storey, at its floor level
|
|
58
|
+
* (the `y` of `position` is ignored).
|
|
59
|
+
* - otherwise, with a section or elevation open on the canvas → that
|
|
60
|
+
* drawing; `position` (and `arrowhead`) are projected onto its plane.
|
|
61
|
+
* - otherwise → plan text on the active storey.
|
|
62
|
+
*
|
|
63
|
+
* The text is created unrotated (it reads along +X in plan); rotate it with
|
|
64
|
+
* `design.transform.rotate`. The font style falls back to `"Regular"` when the
|
|
65
|
+
* family has no such style.
|
|
66
|
+
*
|
|
67
|
+
* @param position - World point the text is placed at: the centre of a plain
|
|
68
|
+
* text, or the leader's text end (where the landing starts) of an
|
|
69
|
+
* annotation.
|
|
70
|
+
* @param content - The words, one line (no line breaks), not blank.
|
|
71
|
+
* @param options - `arrowhead` (world point the leader points at; makes an
|
|
72
|
+
* annotation), `color` (`#rrggbb`, default `#000000`), `fontFamily`
|
|
73
|
+
* (see **Fonts** above, default `"Inter"`), `fontStyle` (default
|
|
74
|
+
* `"Regular"`), `storey` (plan text on this storey).
|
|
75
|
+
* @returns The new text's {@linkcode ComponentHandle}.
|
|
76
|
+
* @throws `VALIDATION` for malformed arguments, blank or multi-line
|
|
77
|
+
* `content`, an unknown `fontFamily`, or an `arrowhead` on top of
|
|
78
|
+
* `position`; `PRECONDITION_FAILED`
|
|
79
|
+
* when `storey` does not exist or the editor is not mounted;
|
|
80
|
+
* `METHOD_NOT_PERMITTED` when plugin writes are disabled.
|
|
81
|
+
*
|
|
82
|
+
* @examplePrompt Label the living room "LIVING" on the plan
|
|
83
|
+
* @examplePrompt Add an annotation pointing at this column saying "RCC 300x300"
|
|
84
|
+
* @examplePrompt Write "NORTH ENTRY" in red bold text at the entrance on level 2
|
|
85
|
+
*
|
|
86
|
+
* # Example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const { design, core } = snaptrude
|
|
89
|
+
* const v = core.math.vec3
|
|
90
|
+
* // A plain label on storey 1.
|
|
91
|
+
* await design.text.create(await v.new(10, 0, 20), "LIVING", { storey: 1 })
|
|
92
|
+
* // An annotation whose leader points at a wall corner.
|
|
93
|
+
* await design.text.create(await v.new(30, 0, 40), "Shear wall", {
|
|
94
|
+
* arrowhead: await v.new(22, 0, 32),
|
|
95
|
+
* color: "#c62828",
|
|
96
|
+
* fontStyle: "Bold",
|
|
97
|
+
* })
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
public abstract create(
|
|
101
|
+
position: Vec3Handle,
|
|
102
|
+
content: string,
|
|
103
|
+
options?: {
|
|
104
|
+
arrowhead?: Vec3Handle
|
|
105
|
+
color?: string
|
|
106
|
+
fontFamily?: string
|
|
107
|
+
fontStyle?: PluginTextFontStyle
|
|
108
|
+
storey?: number
|
|
109
|
+
},
|
|
110
|
+
): PluginApiReturn<ComponentHandle>
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* List the texts and annotations of every building in the active design
|
|
114
|
+
* option as full records (each carries its `buildingId`).
|
|
115
|
+
*
|
|
116
|
+
* Filters combine with AND: `storeys` keeps texts on those storeys (plan
|
|
117
|
+
* text, and texts of a section or elevation, carry the storey they were
|
|
118
|
+
* placed from), `kind` keeps only plain texts or only annotations,
|
|
119
|
+
* `isHidden` only the ones whose user Hide flag equals the value given.
|
|
120
|
+
*
|
|
121
|
+
* @param options - `storeys`, `kind`, `isHidden` filters (all optional,
|
|
122
|
+
* ANDed).
|
|
123
|
+
* @returns The matching {@linkcode PluginText} records (`[]` when nothing
|
|
124
|
+
* matches).
|
|
125
|
+
* @throws `VALIDATION` for malformed filters.
|
|
126
|
+
*
|
|
127
|
+
* @examplePrompt List all the text labels on level 1
|
|
128
|
+
* @examplePrompt Which annotations are in this model?
|
|
129
|
+
* @examplePrompt Find the text that says "LOBBY"
|
|
130
|
+
*
|
|
131
|
+
* @performance Array read — one host round-trip returns every record.
|
|
132
|
+
* Filter in one call rather than calling `get` per text.
|
|
133
|
+
*
|
|
134
|
+
* # Example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const texts = await snaptrude.design.text.list({ storeys: [1] })
|
|
137
|
+
* const lobby = texts.find((t) => t.content === "LOBBY")
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
public abstract list(options?: {
|
|
141
|
+
storeys?: number[]
|
|
142
|
+
kind?: PluginTextKind
|
|
143
|
+
isHidden?: boolean
|
|
144
|
+
}): PluginApiReturn<PluginText[]>
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Read one text by handle.
|
|
148
|
+
*
|
|
149
|
+
* Returns `null` — rather than throwing — when the id is not a live text
|
|
150
|
+
* (deleted, undone, or another kind of component), so a handle kept across a
|
|
151
|
+
* delete or an undo can be polled safely.
|
|
152
|
+
*
|
|
153
|
+
* @param text - The text to read.
|
|
154
|
+
* @returns Its {@linkcode PluginText} record, or `null`.
|
|
155
|
+
* @throws `VALIDATION` if `text` is not a non-empty id string.
|
|
156
|
+
*
|
|
157
|
+
* @examplePrompt What does this text say?
|
|
158
|
+
* @examplePrompt Read the annotation I just placed
|
|
159
|
+
*
|
|
160
|
+
* # Example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const t = await snaptrude.design.text.get(handle)
|
|
163
|
+
* if (t?.leader) console.log(t.content, "points at", t.leader.arrowhead)
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
public abstract get(text: ComponentHandle): PluginApiReturn<PluginText | null>
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Change the words, colour or font of one or more texts — the same edit as
|
|
170
|
+
* the Properties panel. Fields left out keep each text's own value. A font
|
|
171
|
+
* style the (new) family does not have falls back to `"Regular"`, as in the
|
|
172
|
+
* panel. One undo entry for the whole batch.
|
|
173
|
+
*
|
|
174
|
+
* @param texts - The texts to change (at least one).
|
|
175
|
+
* @param patch - `content`, `color`, `fontFamily`, `fontStyle` (at least
|
|
176
|
+
* one).
|
|
177
|
+
* @returns The texts that actually changed, as
|
|
178
|
+
* {@linkcode PluginTextChangeResult} — texts already matching the patch
|
|
179
|
+
* are omitted.
|
|
180
|
+
* @throws `VALIDATION` for malformed arguments, blank / multi-line
|
|
181
|
+
* `content` or an unknown `fontFamily`; `HANDLE_INVALID` if any handle
|
|
182
|
+
* is not a live text (the whole call rejects before anything changes);
|
|
183
|
+
* `PRECONDITION_FAILED` if any text is locked or outside the active
|
|
184
|
+
* design option; `METHOD_NOT_PERMITTED`
|
|
185
|
+
* when plugin writes are disabled.
|
|
186
|
+
*
|
|
187
|
+
* @examplePrompt Make all the room labels bold
|
|
188
|
+
* @examplePrompt Change this annotation to read "Fire exit"
|
|
189
|
+
* @examplePrompt Use Roboto in blue for every text on level 2
|
|
190
|
+
*
|
|
191
|
+
* @performance Array API — pass the whole set in one call (one host
|
|
192
|
+
* round-trip, one undo entry). Never loop this per text.
|
|
193
|
+
*
|
|
194
|
+
* # Example
|
|
195
|
+
* ```ts
|
|
196
|
+
* const text = snaptrude.design.text
|
|
197
|
+
* const level2 = await text.list({ storeys: [2] })
|
|
198
|
+
* await text.update(level2.map((t) => t.id), { fontFamily: "Roboto", color: "#1565c0" })
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
public abstract update(
|
|
202
|
+
texts: ComponentHandle[],
|
|
203
|
+
patch: PluginTextPatch,
|
|
204
|
+
): PluginApiReturn<PluginTextChangeResult>
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Point a text's leader at a new place — the same edit as dragging an
|
|
208
|
+
* annotation's arrowhead with the Edit tool. Passing `null` removes the
|
|
209
|
+
* leader (the annotation becomes a plain text); giving a plain text an
|
|
210
|
+
* arrowhead turns it into an annotation. The text itself does not move. To
|
|
211
|
+
* move the text while its arrowhead stays put, move it with
|
|
212
|
+
* `design.transform.move`, then call this with the old `leader.arrowhead`.
|
|
213
|
+
*
|
|
214
|
+
* @param text - The text to change.
|
|
215
|
+
* @param arrowhead - World point the leader points at (projected onto the
|
|
216
|
+
* text's drawing plane), or `null` to remove the leader.
|
|
217
|
+
* @returns The updated {@linkcode PluginText} record.
|
|
218
|
+
* @throws `VALIDATION` for malformed arguments or an arrowhead on top of the
|
|
219
|
+
* text's position; `HANDLE_INVALID` if `text` is not a live text;
|
|
220
|
+
* `PRECONDITION_FAILED` if it is locked or outside the active design
|
|
221
|
+
* option; `METHOD_NOT_PERMITTED` when plugin writes are disabled.
|
|
222
|
+
*
|
|
223
|
+
* @examplePrompt Point this annotation at the door instead
|
|
224
|
+
* @examplePrompt Remove the leader from this label
|
|
225
|
+
*
|
|
226
|
+
* # Example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const { design, core } = snaptrude
|
|
229
|
+
* await design.text.setLeader(handle, await core.math.vec3.new(12, 0, 8))
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
public abstract setLeader(
|
|
233
|
+
text: ComponentHandle,
|
|
234
|
+
arrowhead: Vec3Handle | null,
|
|
235
|
+
): PluginApiReturn<PluginText>
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The four font styles a text can use (the Properties panel's Style list). */
|
|
239
|
+
export const PluginTextFontStyle = z.enum([
|
|
240
|
+
"Regular",
|
|
241
|
+
"Bold",
|
|
242
|
+
"Italic",
|
|
243
|
+
"Bold Italic",
|
|
244
|
+
])
|
|
245
|
+
export type PluginTextFontStyle = z.infer<typeof PluginTextFontStyle>
|
|
246
|
+
|
|
247
|
+
/** `"text"` — a plain text; `"annotation"` — a text with a leader. */
|
|
248
|
+
export const PluginTextKind = z.enum(["text", "annotation"])
|
|
249
|
+
export type PluginTextKind = z.infer<typeof PluginTextKind>
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The drawing a text belongs to: `"plan"` (its storey's plan), `"section"`,
|
|
253
|
+
* `"elevation"`, or `"view"` (a saved 2D view).
|
|
254
|
+
*/
|
|
255
|
+
export const PluginTextDrawing = z.enum(["plan", "section", "elevation", "view"])
|
|
256
|
+
export type PluginTextDrawing = z.infer<typeof PluginTextDrawing>
|
|
257
|
+
|
|
258
|
+
const TextContent = z
|
|
259
|
+
.string()
|
|
260
|
+
.refine((s) => s.trim().length > 0, { message: "content must not be blank" })
|
|
261
|
+
.refine((s) => !/[\r\n]/.test(s), {
|
|
262
|
+
message: "content must be one line (no line breaks)",
|
|
263
|
+
})
|
|
264
|
+
const TextColor = z
|
|
265
|
+
.string()
|
|
266
|
+
.regex(/^#[0-9a-fA-F]{6}$/, "color must be a #rrggbb hex color")
|
|
267
|
+
const TextFontFamily = z
|
|
268
|
+
.string()
|
|
269
|
+
.refine((s) => s.trim().length > 0, { message: "fontFamily must not be blank" })
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* One text or annotation. Positions are world points in Babylon units.
|
|
273
|
+
*
|
|
274
|
+
* | Property | Type | Description |
|
|
275
|
+
* |---|---|---|
|
|
276
|
+
* | `id` | {@linkcode ComponentHandle} | The text's handle |
|
|
277
|
+
* | `kind` | {@linkcode PluginTextKind} | `"text"` or `"annotation"` (has a leader) |
|
|
278
|
+
* | `content` | `string` | The words |
|
|
279
|
+
* | `color` | `string` | `#rrggbb` |
|
|
280
|
+
* | `fontFamily` | `string` | Font family |
|
|
281
|
+
* | `fontStyle` | {@linkcode PluginTextFontStyle} | Font style |
|
|
282
|
+
* | `position` | {@linkcode Vec3Components} | Centre of a plain text; the leader's text end of an annotation |
|
|
283
|
+
* | `rotation` | `number` | Rotation in its drawing in degrees, positive clockwise as seen on screen — in plan, the sense a positive `design.transform.rotate` angle turns it (0 = reads along +X) |
|
|
284
|
+
* | `leader` | `{ arrowhead: Vec3Components } \| null` | Where the leader points; `null` for plain text |
|
|
285
|
+
* | `storey` | `number` | Storey it belongs to |
|
|
286
|
+
* | `buildingId` | `string \| null` | Building it belongs to |
|
|
287
|
+
* | `drawing` | {@linkcode PluginTextDrawing} | The drawing it is drawn in |
|
|
288
|
+
* | `drawingId` | `string \| null` | The section id, elevation preset or view id; `null` for plan text |
|
|
289
|
+
* | `isHidden` | `boolean` | The user Hide flag (`design.visibility.hide` / `show`) |
|
|
290
|
+
* | `isLocked` | `boolean` | Locked against edits — its own lock (`design.lock` / `unlock`) or a locked group or design option, as `design.isLocked` reports |
|
|
291
|
+
*/
|
|
292
|
+
export const PluginText = z.object({
|
|
293
|
+
id: ComponentHandle,
|
|
294
|
+
kind: PluginTextKind,
|
|
295
|
+
content: z.string(),
|
|
296
|
+
color: z.string(),
|
|
297
|
+
fontFamily: z.string(),
|
|
298
|
+
fontStyle: PluginTextFontStyle,
|
|
299
|
+
position: Vec3Components,
|
|
300
|
+
rotation: z.number(),
|
|
301
|
+
leader: z.object({ arrowhead: Vec3Components }).nullable(),
|
|
302
|
+
storey: z.number(),
|
|
303
|
+
buildingId: z.string().nullable(),
|
|
304
|
+
drawing: PluginTextDrawing,
|
|
305
|
+
drawingId: z.string().nullable(),
|
|
306
|
+
isHidden: z.boolean(),
|
|
307
|
+
isLocked: z.boolean(),
|
|
308
|
+
})
|
|
309
|
+
export type PluginText = z.infer<typeof PluginText>
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* A sparse edit for {@linkcode PluginDesignTextApi.update} — at least one
|
|
313
|
+
* field.
|
|
314
|
+
*
|
|
315
|
+
* | Property | Type | Description |
|
|
316
|
+
* |---|---|---|
|
|
317
|
+
* | `content` | `string`? | New words (one line, not blank) |
|
|
318
|
+
* | `color` | `string`? | `#rrggbb` |
|
|
319
|
+
* | `fontFamily` | `string`? | Google Fonts family (`"Inter"`, `"Roboto"`, …) or `"Arial"` / `"Helvetica"` / `"Times New Roman"` / `"Courier New"` |
|
|
320
|
+
* | `fontStyle` | {@linkcode PluginTextFontStyle}? | Falls back to `"Regular"` when the family lacks it |
|
|
321
|
+
*/
|
|
322
|
+
export const PluginTextPatch = z
|
|
323
|
+
.object({
|
|
324
|
+
content: TextContent.optional(),
|
|
325
|
+
color: TextColor.optional(),
|
|
326
|
+
fontFamily: TextFontFamily.optional(),
|
|
327
|
+
fontStyle: PluginTextFontStyle.optional(),
|
|
328
|
+
})
|
|
329
|
+
.strict()
|
|
330
|
+
.refine((p) => Object.keys(p).length > 0, {
|
|
331
|
+
message: "patch must set at least one field",
|
|
332
|
+
})
|
|
333
|
+
export type PluginTextPatch = z.infer<typeof PluginTextPatch>
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Result of {@linkcode PluginDesignTextApi.update}: the texts the call
|
|
337
|
+
* changed.
|
|
338
|
+
*
|
|
339
|
+
* | Property | Type | Description |
|
|
340
|
+
* |---|---|---|
|
|
341
|
+
* | `affected` | {@linkcode ComponentHandle}`[]` | The texts the call changed |
|
|
342
|
+
*/
|
|
343
|
+
export const PluginTextChangeResult = z.object({
|
|
344
|
+
affected: z.array(ComponentHandle),
|
|
345
|
+
})
|
|
346
|
+
export type PluginTextChangeResult = z.infer<typeof PluginTextChangeResult>
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Arguments for {@linkcode PluginDesignTextApi.create} (options flattened).
|
|
350
|
+
*
|
|
351
|
+
* TRANSPORT: positional args — validated host-side as this object.
|
|
352
|
+
*/
|
|
353
|
+
export const PluginDesignTextCreateArgs = z.object({
|
|
354
|
+
position: Vec3Handle,
|
|
355
|
+
content: TextContent,
|
|
356
|
+
arrowhead: Vec3Handle.optional(),
|
|
357
|
+
color: TextColor.optional(),
|
|
358
|
+
fontFamily: TextFontFamily.optional(),
|
|
359
|
+
fontStyle: PluginTextFontStyle.optional(),
|
|
360
|
+
storey: z.number().int().optional(),
|
|
361
|
+
})
|
|
362
|
+
export type PluginDesignTextCreateArgs = z.infer<
|
|
363
|
+
typeof PluginDesignTextCreateArgs
|
|
364
|
+
>
|
|
365
|
+
|
|
366
|
+
/** Arguments for {@linkcode PluginDesignTextApi.list} (options flattened). */
|
|
367
|
+
export const PluginDesignTextListArgs = z.object({
|
|
368
|
+
storeys: z.array(z.number()).optional(),
|
|
369
|
+
kind: PluginTextKind.optional(),
|
|
370
|
+
isHidden: z.boolean().optional(),
|
|
371
|
+
})
|
|
372
|
+
export type PluginDesignTextListArgs = z.infer<typeof PluginDesignTextListArgs>
|
|
373
|
+
|
|
374
|
+
/** Arguments for {@linkcode PluginDesignTextApi.get}. */
|
|
375
|
+
export const PluginDesignTextGetArgs = z.object({ text: ComponentHandle })
|
|
376
|
+
export type PluginDesignTextGetArgs = z.infer<typeof PluginDesignTextGetArgs>
|
|
377
|
+
|
|
378
|
+
/** Arguments for {@linkcode PluginDesignTextApi.update}. */
|
|
379
|
+
export const PluginDesignTextUpdateArgs = z.object({
|
|
380
|
+
texts: z.array(ComponentHandle).min(1),
|
|
381
|
+
patch: PluginTextPatch,
|
|
382
|
+
})
|
|
383
|
+
export type PluginDesignTextUpdateArgs = z.infer<
|
|
384
|
+
typeof PluginDesignTextUpdateArgs
|
|
385
|
+
>
|
|
386
|
+
|
|
387
|
+
/** Arguments for {@linkcode PluginDesignTextApi.setLeader}. */
|
|
388
|
+
export const PluginDesignTextSetLeaderArgs = z.object({
|
|
389
|
+
text: ComponentHandle,
|
|
390
|
+
arrowhead: Vec3Handle.nullable(),
|
|
391
|
+
})
|
|
392
|
+
export type PluginDesignTextSetLeaderArgs = z.infer<
|
|
393
|
+
typeof PluginDesignTextSetLeaderArgs
|
|
394
|
+
>
|
package/src/api/entity/story.ts
CHANGED
|
@@ -88,6 +88,10 @@ export abstract class PluginStoryApi {
|
|
|
88
88
|
* @returns A {@linkcode PluginStoryCreateResult} with `storyId` and `storyValue`
|
|
89
89
|
* @throws If a story with the given value already exists or creation fails
|
|
90
90
|
*
|
|
91
|
+
* Storeys are added at the ends of the stack only: a value above the top also creates
|
|
92
|
+
* every storey in between (returning only the requested one), and a value inside a gap
|
|
93
|
+
* is refused.
|
|
94
|
+
*
|
|
91
95
|
* @examplePrompt Add a third floor to the building
|
|
92
96
|
* @examplePrompt Create a new storey above the second floor
|
|
93
97
|
* @examplePrompt Add a basement level to this project
|
|
@@ -41,17 +41,20 @@ export const PluginGraphicsModelCategory = z.enum([
|
|
|
41
41
|
"Walls",
|
|
42
42
|
"Windows",
|
|
43
43
|
])
|
|
44
|
+
/** Text is authored text and annotations; its projection pen draws their leader lines. */
|
|
44
45
|
export const PluginGraphicsAnnotationCategory = z.enum([
|
|
45
46
|
"Dimension",
|
|
46
47
|
"Grids",
|
|
47
48
|
"Sections",
|
|
49
|
+
"Text",
|
|
48
50
|
])
|
|
49
51
|
export const PluginGraphicsCategory = z.enum([
|
|
50
52
|
...PluginGraphicsModelCategory.options,
|
|
51
53
|
...PluginGraphicsAnnotationCategory.options,
|
|
52
54
|
])
|
|
55
|
+
/** Text has no view override: its meshes are not hidden or halftoned by category. */
|
|
53
56
|
export const PluginGraphicsOverrideCategory = z.enum([
|
|
54
|
-
...PluginGraphicsCategory.options,
|
|
57
|
+
...PluginGraphicsCategory.exclude(["Text"]).options,
|
|
55
58
|
"Lines",
|
|
56
59
|
])
|
|
57
60
|
export type PluginGraphicsOverrideCategory = z.infer<
|
|
@@ -820,6 +820,8 @@ export const PluginViewSettingCategory = z.enum([
|
|
|
820
820
|
"Reference Line",
|
|
821
821
|
"Adjacency Line",
|
|
822
822
|
"Landscape elements",
|
|
823
|
+
"Text",
|
|
824
|
+
"Annotation",
|
|
823
825
|
])
|
|
824
826
|
export type PluginViewSettingCategory = z.infer<
|
|
825
827
|
typeof PluginViewSettingCategory
|
|
@@ -864,6 +866,10 @@ export type PluginViewLineStyle = z.infer<typeof PluginViewLineStyle>
|
|
|
864
866
|
* | `viewStyle` | `"NONE" \| "FILLET" \| "BUBBLE"`? | Shape restyle: block / rounded corner / bubble |
|
|
865
867
|
* | `radius` | `number`? | Corner radius for `FILLET` (feet) |
|
|
866
868
|
* | `inset` | `number`? | Shape inset/offset |
|
|
869
|
+
* | `textColor` | `string`? | Dimension / Text / Annotation: `#rrggbb`, or `inherit` (each text keeps its own) |
|
|
870
|
+
* | `textFontFamily` | `string`? | Text / Annotation: one font family for every text, or `inherit` |
|
|
871
|
+
* | `textFontStyle` | `"inherit" \| "Regular" \| "Bold" \| "Italic" \| "Bold Italic"`? | Text / Annotation: one font style, or `inherit` (a family without it draws Regular) |
|
|
872
|
+
* | `leaderVisible` | `boolean`? | Annotation: draw the leaders (line, landing, arrowhead) |
|
|
867
873
|
*/
|
|
868
874
|
export const PluginPlacedViewStylePatch = z
|
|
869
875
|
.object({
|
|
@@ -921,6 +927,12 @@ export const PluginPlacedViewStylePatch = z
|
|
|
921
927
|
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
922
928
|
.optional(),
|
|
923
929
|
textMaskPadding: z.number().finite().min(0).max(5).optional(),
|
|
930
|
+
// Text and Annotation rows: one font for every authored text, or `inherit`.
|
|
931
|
+
textFontFamily: z.string().trim().min(1).optional(),
|
|
932
|
+
textFontStyle: z
|
|
933
|
+
.enum(["inherit", "Regular", "Bold", "Italic", "Bold Italic"])
|
|
934
|
+
.optional(),
|
|
935
|
+
leaderVisible: z.boolean().optional(),
|
|
924
936
|
})
|
|
925
937
|
.strict()
|
|
926
938
|
.refine((p) => Object.keys(p).length > 0, {
|