@kensnzk/koyu 0.22.0 → 0.24.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/dist/cli.js +51 -2
- package/dist/cli.js.map +1 -1
- package/dist/core/bodies.d.ts +26 -0
- package/dist/core/bodies.d.ts.map +1 -0
- package/dist/core/bodies.js +67 -0
- package/dist/core/bodies.js.map +1 -0
- package/dist/core/model.d.ts +20 -1
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/model.js +27 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/parse.d.ts.map +1 -1
- package/dist/core/parse.js +11 -13
- package/dist/core/parse.js.map +1 -1
- package/dist/core/poly.d.ts +35 -0
- package/dist/core/poly.d.ts.map +1 -1
- package/dist/core/poly.js +67 -0
- package/dist/core/poly.js.map +1 -1
- package/dist/core/section.d.ts +88 -0
- package/dist/core/section.d.ts.map +1 -0
- package/dist/core/section.js +247 -0
- package/dist/core/section.js.map +1 -0
- package/dist/draw/axo.d.ts.map +1 -1
- package/dist/draw/axo.js +13 -31
- package/dist/draw/axo.js.map +1 -1
- package/dist/draw/index.d.ts +4 -0
- package/dist/draw/index.d.ts.map +1 -1
- package/dist/draw/index.js +4 -0
- package/dist/draw/index.js.map +1 -1
- package/dist/draw/marks.d.ts +126 -0
- package/dist/draw/marks.d.ts.map +1 -0
- package/dist/draw/marks.js +227 -0
- package/dist/draw/marks.js.map +1 -0
- package/dist/draw/plan.d.ts.map +1 -1
- package/dist/draw/plan.js +117 -133
- package/dist/draw/plan.js.map +1 -1
- package/dist/draw/scene.d.ts +133 -0
- package/dist/draw/scene.d.ts.map +1 -0
- package/dist/draw/scene.js +251 -0
- package/dist/draw/scene.js.map +1 -0
- package/dist/draw/section.d.ts +23 -0
- package/dist/draw/section.d.ts.map +1 -0
- package/dist/draw/section.js +168 -0
- package/dist/draw/section.js.map +1 -0
- package/dist/draw/sheet.d.ts +40 -0
- package/dist/draw/sheet.d.ts.map +1 -0
- package/dist/draw/sheet.js +93 -0
- package/dist/draw/sheet.js.map +1 -0
- package/dist/draw/written.d.ts +27 -0
- package/dist/draw/written.d.ts.map +1 -0
- package/dist/draw/written.js +50 -0
- package/dist/draw/written.js.map +1 -0
- package/dist/form.d.ts +1 -0
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +4 -0
- package/dist/form.js.map +1 -1
- package/dist/mcp.js +67 -3
- package/dist/mcp.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +57 -1
- package/src/core/bodies.ts +90 -0
- package/src/core/model.ts +32 -1
- package/src/core/parse.ts +13 -12
- package/src/core/poly.ts +76 -0
- package/src/core/section.ts +311 -0
- package/src/draw/axo.ts +13 -29
- package/src/draw/index.ts +24 -0
- package/src/draw/marks.ts +315 -0
- package/src/draw/plan.ts +111 -130
- package/src/draw/scene.ts +389 -0
- package/src/draw/section.ts +224 -0
- package/src/draw/sheet.ts +102 -0
- package/src/draw/written.ts +64 -0
- package/src/form.ts +18 -0
- package/src/mcp.ts +75 -2
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// koyu — the page every drawing is put on.
|
|
2
|
+
//
|
|
3
|
+
// **Nothing here decides shape.** This module holds what a sheet of paper is: the two inks, the
|
|
4
|
+
// escaping a piece of text needs before it can sit in markup, the rounding that keeps a path
|
|
5
|
+
// readable, the opening element, and the accumulator that measures how far the drawing reaches.
|
|
6
|
+
//
|
|
7
|
+
// It exists because there are three renderers now. While `plan.ts` and `axo.ts` were the only two,
|
|
8
|
+
// each carrying its own copy of `esc` and its own spelling of `#1f1f1f`, the duplication was
|
|
9
|
+
// cheap; a third copy is the point at which "the paper is the same paper" stops being visible in
|
|
10
|
+
// the code. What is **not** here is anything the three do differently — the world-to-paper mapping
|
|
11
|
+
// (a plan flips y, an axonometric does not), the title block, the margin. Sharing those would mean
|
|
12
|
+
// parameterising them until the shared version says less than the three separate ones did.
|
|
13
|
+
|
|
14
|
+
// The palette. Shared so that a plan and a section of the same building read as one set of
|
|
15
|
+
// drawings — which is the whole use of being able to lay them side by side. Every one of these may
|
|
16
|
+
// change; none of them is on a frozen surface.
|
|
17
|
+
|
|
18
|
+
/** The drawing ink. */
|
|
19
|
+
export const INK = "#1f1f1f";
|
|
20
|
+
/** The paper. */
|
|
21
|
+
export const PAPER = "#faf8f4";
|
|
22
|
+
/** The air of a room, cut open. */
|
|
23
|
+
export const ROOM = "#f1ebdd";
|
|
24
|
+
/** Given lines — the grid, and the level datums that are the grid of a section. */
|
|
25
|
+
export const GRID = "#b5aa94";
|
|
26
|
+
/** A line that is present but not the subject. */
|
|
27
|
+
export const FAINT = "#b3ab9c";
|
|
28
|
+
|
|
29
|
+
/** Two decimal places — enough for a coordinate on paper, and it keeps the path text short. */
|
|
30
|
+
export const r2 = (v: number): number => Math.round(v * 100) / 100;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Text on its way into markup. Only the three characters that would end the surrounding element —
|
|
34
|
+
* no name from the source is ever put inside an attribute, so quotes need no treatment.
|
|
35
|
+
*/
|
|
36
|
+
export const esc = (s: string): string =>
|
|
37
|
+
s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
38
|
+
|
|
39
|
+
/** The opening element, the paper under the drawing, and the mark in the corner. */
|
|
40
|
+
export function openSheet(w: number, h: number): string[] {
|
|
41
|
+
return [
|
|
42
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" font-family="'Hiragino Sans','Noto Sans JP',sans-serif">`,
|
|
43
|
+
`<rect width="${w}" height="${h}" fill="${PAPER}"/>`,
|
|
44
|
+
koyuMark(14, 13, 19),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The mark, drawn rather than linked. A drawing koyu makes should say so on its face, and an SVG
|
|
49
|
+
// that reaches for a file is a drawing that arrives broken as often as not — so the two paths are
|
|
50
|
+
// here, in the light-mode colours, because the paper is light.
|
|
51
|
+
//
|
|
52
|
+
// The outline is a room in plan: a wall running round, stopping short at the foot to leave a
|
|
53
|
+
// doorway, one partition inside it, and an opening in red. Which is the whole notation in one
|
|
54
|
+
// figure, and the reason it is the mark.
|
|
55
|
+
const MARK_INK = "#171A18";
|
|
56
|
+
const MARK_OPENING = "#A84940";
|
|
57
|
+
const MARK_W = 803.138;
|
|
58
|
+
const MARK_H = 872.069;
|
|
59
|
+
const MARK_X = 224.392;
|
|
60
|
+
const MARK_Y = 171.361;
|
|
61
|
+
|
|
62
|
+
/** The koyu mark, its top-left corner at (x, y) and `size` tall. */
|
|
63
|
+
export function koyuMark(x: number, y: number, size: number): string {
|
|
64
|
+
const k = size / MARK_H;
|
|
65
|
+
const tx = r2(x - MARK_X * k);
|
|
66
|
+
const ty = r2(y - MARK_Y * k);
|
|
67
|
+
return (
|
|
68
|
+
`<g transform="translate(${tx} ${ty}) scale(${r2(k * 1000) / 1000})">` +
|
|
69
|
+
`<path d="M1027.53 171.361L224.461 171.363L224.392 1043.39L361.454 1043.42L361.567 308.689L889.587 308.679L889.581 904.864L566.4 904.876L566.387 524.585L419.01 452.015L419.047 1043.39L1027.51 1043.43L1027.53 171.361Z" fill="${MARK_INK}"/>` +
|
|
70
|
+
`<path d="M707 445.022L811.864 445L811.858 613.697C811.831 648.974 812.209 684.759 811.831 720L707.005 719.933L707 445.022Z" fill="${MARK_OPENING}"/>` +
|
|
71
|
+
`</g>`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** How wide the mark drawn by `openSheet` is, so a caller can keep clear of it. */
|
|
76
|
+
export const MARK_WIDTH = (19 / MARK_H) * MARK_W;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* How far the drawing reaches.
|
|
80
|
+
*
|
|
81
|
+
* **It folds; it does not spread.** `Math.min(...points)` passes one argument per point and a large
|
|
82
|
+
* model runs past the limit on the number of arguments a call may take — a wall split by its
|
|
83
|
+
* openings is one body per interval, so the bundled examples reach past a hundred thousand points.
|
|
84
|
+
*/
|
|
85
|
+
export class Extent {
|
|
86
|
+
min0 = Infinity;
|
|
87
|
+
max0 = -Infinity;
|
|
88
|
+
min1 = Infinity;
|
|
89
|
+
max1 = -Infinity;
|
|
90
|
+
|
|
91
|
+
see(a: number, b: number): void {
|
|
92
|
+
if (a < this.min0) this.min0 = a;
|
|
93
|
+
if (a > this.max0) this.max0 = a;
|
|
94
|
+
if (b < this.min1) this.min1 = b;
|
|
95
|
+
if (b > this.max1) this.max1 = b;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Whether anything was ever seen. */
|
|
99
|
+
get empty(): boolean {
|
|
100
|
+
return this.min0 === Infinity;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// koyu — reading back what was written, from a mark or a scene node (`@kensnzk/koyu/draw`)
|
|
2
|
+
//
|
|
3
|
+
// `Mark.written` and `SceneNode.written` give a place in **canonical boundary order**. Reaching the
|
|
4
|
+
// attributes from that place needs the model, and needs it read in exactly one way: `Form`'s index
|
|
5
|
+
// is an index into `canonicalBoundaryOrder(model)`, never into `model.boundaries`. Declaration
|
|
6
|
+
// order is information the canonical form discards, so indexing by it does not throw — **it reads
|
|
7
|
+
// another boundary's `spec`**, on some models and not others (ADR-0041).
|
|
8
|
+
//
|
|
9
|
+
// **Why this and not the ordering function itself.** Two things go wrong when a consumer holds the
|
|
10
|
+
// sorted array. It sorts per lookup — both viewers did, once per boundary, re-sorting the whole
|
|
11
|
+
// building each time, which is the cost ADR-0041 names. And the raw array invites
|
|
12
|
+
// `model.boundaries[i]` to be substituted for it by anyone who does not know the difference, which
|
|
13
|
+
// is the failure the ordering exists to prevent. A window that answers "what was written here"
|
|
14
|
+
// closes both: sorted once per model, and there is no array to mis-index.
|
|
15
|
+
//
|
|
16
|
+
// This lives in the presentation face because it is not part of the language. `spec` is a carried
|
|
17
|
+
// free word — core neither reads it nor promises what it means (docs/reference/muro/attributes.md);
|
|
18
|
+
// only a drawing ever asks.
|
|
19
|
+
import { canonicalBoundaryOrder, type Model } from "../core/model.js";
|
|
20
|
+
|
|
21
|
+
/** What a model wrote at a place the `Form` points to. */
|
|
22
|
+
export interface Written {
|
|
23
|
+
/** the `spec` on a boundary, by its place in canonical order */
|
|
24
|
+
boundarySpec(boundary: number): string | undefined;
|
|
25
|
+
/** the `spec` on a segment that does not count */
|
|
26
|
+
segSpec(boundary: number, index: number): string | undefined;
|
|
27
|
+
/** the `spec` on an opening */
|
|
28
|
+
openingSpec(boundary: number, index: number): string | undefined;
|
|
29
|
+
/** any carried attribute on a boundary, including a namespaced one */
|
|
30
|
+
boundaryAttr(boundary: number, key: string): string | number | boolean | undefined;
|
|
31
|
+
/** any carried attribute on an opening */
|
|
32
|
+
openingAttr(boundary: number, index: number, key: string): string | number | boolean | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// A model is a value, so the answer for one never changes. Sorting is O(n log n) over every
|
|
36
|
+
// boundary; doing it once per model is the whole point of the cache.
|
|
37
|
+
const cache = new WeakMap<Model, Written>();
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A window onto what a model wrote, addressed the way `Form` addresses it.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const written = writtenOf(model);
|
|
44
|
+
* for (const n of sceneOf(form).nodes) {
|
|
45
|
+
* const spec = n.written && written.boundarySpec(n.written.boundary);
|
|
46
|
+
* // deciding that a spec containing "glass" means transparent is the viewer's judgement
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function writtenOf(model: Model): Written {
|
|
51
|
+
const hit = cache.get(model);
|
|
52
|
+
if (hit) return hit;
|
|
53
|
+
const ordered = canonicalBoundaryOrder(model);
|
|
54
|
+
const str = (v: unknown): string | undefined => (typeof v === "string" ? v : undefined);
|
|
55
|
+
const made: Written = {
|
|
56
|
+
boundarySpec: (b) => str(ordered[b]?.attrs["spec"]),
|
|
57
|
+
segSpec: (b, i) => str(ordered[b]?.segs[i]?.attrs["spec"]),
|
|
58
|
+
openingSpec: (b, i) => str(ordered[b]?.openings[i]?.attrs["spec"]),
|
|
59
|
+
boundaryAttr: (b, key) => ordered[b]?.attrs[key],
|
|
60
|
+
openingAttr: (b, i, key) => ordered[b]?.openings[i]?.attrs[key],
|
|
61
|
+
};
|
|
62
|
+
cache.set(model, made);
|
|
63
|
+
return made;
|
|
64
|
+
}
|
package/src/form.ts
CHANGED
|
@@ -36,6 +36,24 @@ export {
|
|
|
36
36
|
type PlanSubject,
|
|
37
37
|
} from "./core/derive.js";
|
|
38
38
|
|
|
39
|
+
// The section and the elevation. **They read a `Form` and assemble no matter** — the classifying
|
|
40
|
+
// of what a vertical plane cut and what stands behind it is derivation's, for the same reason the
|
|
41
|
+
// horizontal one is (docs/why/plan-is-not-a-section.md).
|
|
42
|
+
export {
|
|
43
|
+
axisOf,
|
|
44
|
+
defaultLook,
|
|
45
|
+
elevationForm,
|
|
46
|
+
sectionArea,
|
|
47
|
+
sectionForm,
|
|
48
|
+
type FormSection,
|
|
49
|
+
type SectionAxis,
|
|
50
|
+
type SectionClass,
|
|
51
|
+
type SectionEntity,
|
|
52
|
+
type SectionPt,
|
|
53
|
+
type SectionSpec,
|
|
54
|
+
type SectionSubject,
|
|
55
|
+
} from "./core/section.js";
|
|
56
|
+
|
|
39
57
|
export { TOLERANCES } from "./core/tolerance.js";
|
|
40
58
|
|
|
41
59
|
export type { Slab, SlabKind } from "./core/fabric.js";
|
package/src/mcp.ts
CHANGED
|
@@ -11,17 +11,20 @@ import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
|
11
11
|
import { daylightInputs } from "./core/light.js";
|
|
12
12
|
import {
|
|
13
13
|
DEFAULT_LANGUAGE_VERSION,
|
|
14
|
+
type Edge,
|
|
15
|
+
gridRef,
|
|
14
16
|
KOYU_VERSION,
|
|
15
17
|
NEWEST_LANGUAGE_VERSION,
|
|
16
18
|
polygonAreaM2,
|
|
17
19
|
SUPPORTED_LANGUAGE_VERSIONS,
|
|
18
20
|
} from "./core/model.js";
|
|
21
|
+
import { axisOf } from "./core/section.js";
|
|
19
22
|
import { check } from "./core/diagnose.js";
|
|
20
23
|
import { siteReport } from "./core/site.js";
|
|
21
24
|
import { assess } from "./validate/assessment.js";
|
|
22
25
|
import { createSchematicRegistry, SCHEMATIC_PROFILE_ID } from "./validate/builtin/index.js";
|
|
23
26
|
import { checkDiagnostics } from "./diagnostics.js";
|
|
24
|
-
import { svgPlan } from "./draw/index.js";
|
|
27
|
+
import { svgElevation, svgPlan, svgSection } from "./draw/index.js";
|
|
25
28
|
import { doorsBetween } from "./graph.js";
|
|
26
29
|
import {
|
|
27
30
|
areaM2,
|
|
@@ -191,6 +194,22 @@ const str = (v: unknown, name: string): string => {
|
|
|
191
194
|
return v;
|
|
192
195
|
};
|
|
193
196
|
|
|
197
|
+
/**
|
|
198
|
+
* A compass word, checked rather than trusted.
|
|
199
|
+
*
|
|
200
|
+
* **A schema is what the tool advertises, not what the server enforces.** A raw `tools/call` can
|
|
201
|
+
* carry anything, and a word that is not one of the four falls through the direction tests to a
|
|
202
|
+
* default — so an unsupported `look` would come back as a plausible drawing of a plane nobody
|
|
203
|
+
* asked for, which is worse than an error.
|
|
204
|
+
*/
|
|
205
|
+
const edge = (v: unknown, name: string): Edge => {
|
|
206
|
+
const s = str(v, name);
|
|
207
|
+
if (s !== "N" && s !== "E" && s !== "S" && s !== "W") {
|
|
208
|
+
throw new Error(`${name} is one of N / E / S / W: ${s}`);
|
|
209
|
+
}
|
|
210
|
+
return s;
|
|
211
|
+
};
|
|
212
|
+
|
|
194
213
|
/** An optional array of attribute keys. Absent is not the same as empty, but both group nothing. */
|
|
195
214
|
const keys = (v: unknown, name: string): string[] => {
|
|
196
215
|
if (v === undefined) return [];
|
|
@@ -427,6 +446,60 @@ const TOOLS: Record<string, Tool> = {
|
|
|
427
446
|
},
|
|
428
447
|
run: (a) => svgPlan(load(str(a.file, "file")), { level: str(a.level, "level") }),
|
|
429
448
|
},
|
|
449
|
+
section_svg: {
|
|
450
|
+
description:
|
|
451
|
+
"Generates and returns the section SVG cut at a grid reference (form is generated, not written). The reference names the plane: X3 cuts across the X axis, Y2-600 across the Y axis",
|
|
452
|
+
schema: {
|
|
453
|
+
type: "object",
|
|
454
|
+
properties: {
|
|
455
|
+
...FILE_PROP,
|
|
456
|
+
at: {
|
|
457
|
+
type: "string",
|
|
458
|
+
description: "Grid reference for the cut — X3, X3+450, Y2-600. A plane on a grid line usually runs along a wall; offset it to cut through the rooms",
|
|
459
|
+
},
|
|
460
|
+
look: {
|
|
461
|
+
type: "string",
|
|
462
|
+
enum: ["N", "E", "S", "W"],
|
|
463
|
+
description: "Direction of view. Must cross the plane: E or W for an X reference, N or S for a Y reference. Defaults to W and N",
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
required: ["file", "at"],
|
|
467
|
+
},
|
|
468
|
+
run: (a) => {
|
|
469
|
+
const model = load(str(a.file, "file"));
|
|
470
|
+
const at = str(a.at, "at");
|
|
471
|
+
const g = gridRef(model, at);
|
|
472
|
+
if (!g) {
|
|
473
|
+
throw new Error(
|
|
474
|
+
`Undefined grid reference: ${at} (declared: ${model.grid.X.names.join(" ")} ${model.grid.Y.names.join(" ")})`,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
const look = a.look === undefined ? undefined : edge(a.look, "look");
|
|
478
|
+
if (look && axisOf(look) !== g.axis) {
|
|
479
|
+
throw new Error(
|
|
480
|
+
`look ${look} runs along ${at} rather than across it (an X reference is looked at from E or W, a Y reference from N or S)`,
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
return svgSection(model, { axis: g.axis, at: g.coord, atRef: at, ...(look ? { look } : {}) });
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
elevation_svg: {
|
|
487
|
+
description:
|
|
488
|
+
"Generates and returns the elevation SVG of one face (form is generated, not written). An elevation is a section whose plane stands outside the mass, so it cuts nothing",
|
|
489
|
+
schema: {
|
|
490
|
+
type: "object",
|
|
491
|
+
properties: {
|
|
492
|
+
...FILE_PROP,
|
|
493
|
+
face: {
|
|
494
|
+
type: "string",
|
|
495
|
+
enum: ["N", "E", "S", "W"],
|
|
496
|
+
description: "The side the viewer stands on. S is the south elevation, seen from the south",
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
required: ["file", "face"],
|
|
500
|
+
},
|
|
501
|
+
run: (a) => svgElevation(load(str(a.file, "file")), { face: edge(a.face, "face") }),
|
|
502
|
+
},
|
|
430
503
|
canonical_json: {
|
|
431
504
|
description: "The canonical JSON (machine format — one composed model, byte-stable). The ground for diffing and for external connections",
|
|
432
505
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
@@ -476,7 +549,7 @@ function handle(msg: Json): void {
|
|
|
476
549
|
},
|
|
477
550
|
},
|
|
478
551
|
instructions:
|
|
479
|
-
"Server for koyu, a space-first architectural description. Grasp the building with model_summary, read the original layers with layers, and edit with write_layer. check is the gatekeeper of the build and returns errors tagged layer:line — it guarantees structural consistency only. validate delivers the architectural verdicts, which are a separate and unfrozen surface. doors/light/site/spaces are different questions put to the same description. Form (plan_svg) is generated, never written.",
|
|
552
|
+
"Server for koyu, a space-first architectural description. Grasp the building with model_summary, read the original layers with layers, and edit with write_layer. check is the gatekeeper of the build and returns errors tagged layer:line — it guarantees structural consistency only. validate delivers the architectural verdicts, which are a separate and unfrozen surface. doors/light/site/spaces are different questions put to the same description. Form (the drawings — plan_svg, section_svg, elevation_svg) is generated, never written.",
|
|
480
553
|
});
|
|
481
554
|
return;
|
|
482
555
|
}
|