@kensnzk/koyu 0.15.0 → 0.17.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/README.ja.md +14 -10
- package/README.md +16 -13
- package/dist/cli.js +162 -84
- package/dist/cli.js.map +1 -1
- package/dist/core/derive.d.ts +264 -0
- package/dist/core/derive.d.ts.map +1 -0
- package/dist/core/derive.js +576 -0
- package/dist/core/derive.js.map +1 -0
- package/dist/{check.d.ts → core/diagnose.d.ts} +15 -15
- package/dist/core/diagnose.d.ts.map +1 -0
- package/dist/{check.js → core/diagnose.js} +269 -223
- package/dist/core/diagnose.js.map +1 -0
- package/dist/{diff.d.ts → core/diff.d.ts} +3 -2
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/{diff.js → core/diff.js} +89 -43
- package/dist/core/diff.js.map +1 -0
- package/dist/{fabric.d.ts → core/fabric.d.ts} +5 -3
- package/dist/core/fabric.d.ts.map +1 -0
- package/dist/{fabric.js → core/fabric.js} +12 -11
- package/dist/core/fabric.js.map +1 -0
- package/dist/{graph.d.ts → core/graph.d.ts} +2 -4
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/{graph.js → core/graph.js} +53 -54
- package/dist/core/graph.js.map +1 -0
- package/dist/core/light.d.ts +24 -0
- package/dist/core/light.d.ts.map +1 -0
- package/dist/{light.js → core/light.js} +17 -12
- package/dist/core/light.js.map +1 -0
- package/dist/{model.d.ts → core/model.d.ts} +178 -18
- package/dist/core/model.d.ts.map +1 -0
- package/dist/{model.js → core/model.js} +307 -68
- package/dist/core/model.js.map +1 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/{parse.js → core/parse.js} +546 -133
- package/dist/core/parse.js.map +1 -0
- package/dist/{poly.d.ts → core/poly.d.ts} +3 -6
- package/dist/core/poly.d.ts.map +1 -0
- package/dist/{poly.js → core/poly.js} +8 -13
- package/dist/core/poly.js.map +1 -0
- package/dist/core/site.d.ts.map +1 -0
- package/dist/{site.js → core/site.js} +2 -2
- package/dist/core/site.js.map +1 -0
- package/dist/core/tolerance.d.ts +26 -0
- package/dist/core/tolerance.d.ts.map +1 -0
- package/dist/core/tolerance.js +48 -0
- package/dist/core/tolerance.js.map +1 -0
- package/dist/{vertical.d.ts → core/vertical.d.ts} +48 -12
- package/dist/core/vertical.d.ts.map +1 -0
- package/dist/{vertical.js → core/vertical.js} +53 -105
- package/dist/core/vertical.js.map +1 -0
- package/dist/core/vocabulary.d.ts +40 -0
- package/dist/core/vocabulary.d.ts.map +1 -0
- package/dist/core/vocabulary.js +176 -0
- package/dist/core/vocabulary.js.map +1 -0
- package/dist/{axo.d.ts → draw/axo.d.ts} +1 -1
- package/dist/draw/axo.d.ts.map +1 -0
- package/dist/{axo.js → draw/axo.js} +53 -81
- package/dist/draw/axo.js.map +1 -0
- package/dist/draw/index.d.ts +3 -0
- package/dist/draw/index.d.ts.map +1 -0
- package/dist/draw/index.js +11 -0
- package/dist/draw/index.js.map +1 -0
- package/dist/draw/plan.d.ts +10 -0
- package/dist/draw/plan.d.ts.map +1 -0
- package/dist/draw/plan.js +284 -0
- package/dist/draw/plan.js.map +1 -0
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -12
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +112 -50
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -1
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +19 -4
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/access.d.ts +6 -0
- package/dist/validate/access.d.ts.map +1 -0
- package/dist/validate/access.js +248 -0
- package/dist/validate/access.js.map +1 -0
- package/dist/validate/envelope.d.ts +4 -0
- package/dist/validate/envelope.d.ts.map +1 -0
- package/dist/validate/envelope.js +55 -0
- package/dist/validate/envelope.js.map +1 -0
- package/dist/validate/index.d.ts +60 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +77 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/light.d.ts +6 -0
- package/dist/validate/light.d.ts.map +1 -0
- package/dist/validate/light.js +28 -0
- package/dist/validate/light.js.map +1 -0
- package/dist/validate/runs.d.ts +16 -0
- package/dist/validate/runs.d.ts.map +1 -0
- package/dist/validate/runs.js +60 -0
- package/dist/validate/runs.js.map +1 -0
- package/dist/validate/site.d.ts +6 -0
- package/dist/validate/site.d.ts.map +1 -0
- package/dist/validate/site.js +63 -0
- package/dist/validate/site.js.map +1 -0
- package/editors/vscode/.vscodeignore +2 -0
- package/editors/vscode/README.md +28 -0
- package/editors/vscode/extension.js +150 -0
- package/editors/vscode/language-configuration.json +19 -0
- package/editors/vscode/package.json +57 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +226 -0
- package/examples/basement/main.muro +3 -3
- package/examples/complex/main.muro +1 -1
- package/examples/complex/podium.muro +1 -1
- package/examples/complex/site.muro +6 -6
- package/examples/house/L2.muro +1 -1
- package/examples/house/main.muro +2 -2
- package/examples/house/site.muro +4 -4
- package/examples/house.muro +7 -7
- package/examples/mansion.muro +3 -3
- package/examples/office.muro +4 -4
- package/examples/steps/01-one-room.muro +1 -1
- package/examples/steps/02-two-rooms.muro +1 -1
- package/examples/steps/03-door.muro +1 -1
- package/examples/steps/04-exterior.muro +2 -2
- package/examples/steps/05-two-storeys.muro +2 -2
- package/examples/steps/06-finished.muro +3 -3
- package/examples/tower/L2.muro +1 -1
- package/examples/tower/main.muro +1 -1
- package/examples/tower/site.muro +4 -4
- package/examples/twin/main.muro +2 -2
- package/examples/twin/podium.muro +4 -4
- package/examples/twin/site.muro +8 -8
- package/examples/two-rooms.canonical.json +6 -4
- package/examples/two-rooms.muro +3 -3
- package/package.json +18 -3
- package/src/cli.ts +173 -83
- package/src/core/derive.ts +869 -0
- package/src/{check.ts → core/diagnose.ts} +313 -235
- package/src/{diff.ts → core/diff.ts} +91 -43
- package/src/{fabric.ts → core/fabric.ts} +22 -12
- package/src/{graph.ts → core/graph.ts} +64 -63
- package/src/core/light.ts +69 -0
- package/src/{model.ts → core/model.ts} +361 -74
- package/src/{parse.ts → core/parse.ts} +618 -135
- package/src/{poly.ts → core/poly.ts} +8 -16
- package/src/{site.ts → core/site.ts} +2 -2
- package/src/core/tolerance.ts +55 -0
- package/src/{vertical.ts → core/vertical.ts} +73 -116
- package/src/core/vocabulary.ts +210 -0
- package/src/{axo.ts → draw/axo.ts} +51 -94
- package/src/draw/index.ts +11 -0
- package/src/draw/plan.ts +344 -0
- package/src/index.ts +201 -34
- package/src/mcp.ts +119 -50
- package/src/parse-file.ts +19 -5
- package/src/validate/access.ts +291 -0
- package/src/validate/envelope.ts +59 -0
- package/src/validate/index.ts +107 -0
- package/src/validate/light.ts +43 -0
- package/src/validate/runs.ts +87 -0
- package/src/validate/site.ts +84 -0
- package/dist/axo.d.ts.map +0 -1
- package/dist/axo.js.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js.map +0 -1
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js.map +0 -1
- package/dist/fabric.d.ts.map +0 -1
- package/dist/fabric.js.map +0 -1
- package/dist/graph.d.ts.map +0 -1
- package/dist/graph.js.map +0 -1
- package/dist/light.d.ts +0 -15
- package/dist/light.d.ts.map +0 -1
- package/dist/light.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/parse.d.ts.map +0 -1
- package/dist/parse.js.map +0 -1
- package/dist/plan.d.ts +0 -10
- package/dist/plan.d.ts.map +0 -1
- package/dist/plan.js +0 -354
- package/dist/plan.js.map +0 -1
- package/dist/poly.d.ts.map +0 -1
- package/dist/poly.js.map +0 -1
- package/dist/site.d.ts.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/vertical.d.ts.map +0 -1
- package/dist/vertical.js.map +0 -1
- package/src/light.ts +0 -63
- package/src/plan.ts +0 -472
- /package/dist/{parse.d.ts → core/parse.d.ts} +0 -0
- /package/dist/{site.d.ts → core/site.d.ts} +0 -0
package/src/draw/plan.ts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// koyu — 平面図の生成
|
|
2
|
+
//
|
|
3
|
+
// **ここに形の規則は一つも無い。**壁の厚みも、開口の位置も、扉の吊元も、階段がどこで
|
|
4
|
+
// 切れるかも、`derive(model)` が返す `Form` に既に入っている (ADR-0040)。この頁が持つのは
|
|
5
|
+
// 色・線種・線幅・書体・記号・注記の言葉・縮尺・紙面の余白 — すべて**見た目**であり、
|
|
6
|
+
// 消費者ごとに違ってよいものである (docs/reference/scope.md)。
|
|
7
|
+
//
|
|
8
|
+
// 形と見た目の線引きはこうである。境界線分の座標・壁の厚み・開口で割られた区間・
|
|
9
|
+
// 扉の軌跡の中心と半径と掃き方向・切断面を跨ぐ位置は Form が持つ。1/4円を破線で描くか、
|
|
10
|
+
// 切断線を平行な二本の斜線として引くか、矢印に "UP" と書くかは、ここが決める。
|
|
11
|
+
|
|
12
|
+
import { band, derive, type PlanEntity } from "../core/derive.js";
|
|
13
|
+
import { canonicalBoundaryOrder, displayName, polyBounds, type Model, type Pt } from "../core/model.js";
|
|
14
|
+
import { slopeText } from "../core/vertical.js";
|
|
15
|
+
|
|
16
|
+
export interface PlanOptions {
|
|
17
|
+
level?: string;
|
|
18
|
+
/** px per mm */
|
|
19
|
+
scale?: number;
|
|
20
|
+
/** 切断面の高さ mm (FLから) — **形を決める引数**なので Form の入力へ渡る */
|
|
21
|
+
cut?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const INK = "#1f1f1f";
|
|
25
|
+
const PAPER = "#faf8f4";
|
|
26
|
+
const ROOM = "#f1ebdd";
|
|
27
|
+
const GRID = "#b5aa94";
|
|
28
|
+
const FAINT = "#b3ab9c";
|
|
29
|
+
|
|
30
|
+
export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
31
|
+
const level = opts.level ?? Object.keys(model.levels)[0];
|
|
32
|
+
if (!level) throw new Error("No level is defined");
|
|
33
|
+
const scale = opts.scale ?? 0.05;
|
|
34
|
+
|
|
35
|
+
const form = derive(model, opts.cut !== undefined ? { cut: opts.cut } : {});
|
|
36
|
+
const plan = form.plans.find((p) => p.level === level);
|
|
37
|
+
const rooms = form.spaces.filter((s) => s.level === level);
|
|
38
|
+
if (!plan || rooms.length === 0) {
|
|
39
|
+
throw new Error(`There is no space with a region on level ${level}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 敷地形状 (ADR-0011) は最下階の平面 (配置図兼用) に敷地境界線として描く — 紙面の構成の判断
|
|
43
|
+
const lowest = form.levels[0]?.name;
|
|
44
|
+
const sitePolys = level === lowest ? form.site : [];
|
|
45
|
+
|
|
46
|
+
// 紙面の外接範囲。**書かれた割付も含める** — 切られた形より外へ割付がはみ出しても紙に載る
|
|
47
|
+
const modelRooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level === level);
|
|
48
|
+
const allRects = modelRooms.flatMap((s) => s.rects);
|
|
49
|
+
const polyPts = [...sitePolys.flatMap((p) => p.points), ...rooms.flatMap((s) => s.outline.flat())];
|
|
50
|
+
const minX = Math.min(...allRects.map((r) => r.x1), ...polyPts.map((p) => p.x));
|
|
51
|
+
const maxX = Math.max(...allRects.map((r) => r.x2), ...polyPts.map((p) => p.x));
|
|
52
|
+
const minY = Math.min(...allRects.map((r) => r.y1), ...polyPts.map((p) => p.y));
|
|
53
|
+
const maxY = Math.max(...allRects.map((r) => r.y2), ...polyPts.map((p) => p.y));
|
|
54
|
+
|
|
55
|
+
const M = 84; // 余白 px (通り芯記号ぶん)
|
|
56
|
+
const W = (maxX - minX) * scale + M * 2;
|
|
57
|
+
const H = (maxY - minY) * scale + M * 2;
|
|
58
|
+
const sx = (x: number) => (x - minX) * scale + M;
|
|
59
|
+
const sy = (y: number) => (maxY - y) * scale + M;
|
|
60
|
+
const path2d = (poly: Pt[]): string =>
|
|
61
|
+
poly.map((p, i) => `${i === 0 ? "M" : "L"} ${sx(p.x)} ${sy(p.y)}`).join(" ") + " Z";
|
|
62
|
+
const line = (g: { x1: number; y1: number; x2: number; y2: number }, stroke: string, w: number, dash = "") =>
|
|
63
|
+
`<line x1="${sx(g.x1)}" y1="${sy(g.y1)}" x2="${sx(g.x2)}" y2="${sy(g.y2)}" stroke="${stroke}" stroke-width="${w}"${dash ? ` stroke-dasharray="${dash}"` : ""}/>`;
|
|
64
|
+
const fill = (poly: Pt[], c: string) => `<path d="${path2d(poly)}" fill="${c}"/>`;
|
|
65
|
+
|
|
66
|
+
const parts: string[] = [];
|
|
67
|
+
parts.push(
|
|
68
|
+
`<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">`,
|
|
69
|
+
);
|
|
70
|
+
parts.push(`<rect width="${W}" height="${H}" fill="${PAPER}"/>`);
|
|
71
|
+
|
|
72
|
+
// 敷地境界線 (一点二点鎖線 — 作図慣習)。所与の形をそのまま引く
|
|
73
|
+
for (const poly of sitePolys) {
|
|
74
|
+
parts.push(
|
|
75
|
+
`<path d="${path2d(poly.points)}" fill="none" stroke="#8a8171" stroke-width="1.1" stroke-dasharray="14 3 2.5 3 2.5 3"/>`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 空間の面 — 切断面が気積を切った姿。同色・輪郭なしなのでL字も切られた形も一体に見える。
|
|
80
|
+
// 半屋外は淡く塗り分け、屋外であることが図から読めるように
|
|
81
|
+
for (const s of rooms) {
|
|
82
|
+
const isVoid = s.void;
|
|
83
|
+
for (const poly of s.outline) {
|
|
84
|
+
parts.push(fill(poly, isVoid ? PAPER : s.semiOutdoor ? "#f8f5ec" : ROOM));
|
|
85
|
+
if (isVoid) {
|
|
86
|
+
// 吹抜け: 破線の対角線 (作図慣習)
|
|
87
|
+
const r = polyBounds(poly);
|
|
88
|
+
parts.push(
|
|
89
|
+
line({ x1: r.x1, y1: r.y1, x2: r.x2, y2: r.y2 }, FAINT, 0.8, "6 4"),
|
|
90
|
+
line({ x1: r.x1, y1: r.y2, x2: r.x2, y2: r.y1 }, FAINT, 0.8, "6 4"),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 数えない分節 (area): 床材の切替など。書かれた与件をそのまま引く — 導出ではない
|
|
97
|
+
for (const s of modelRooms) {
|
|
98
|
+
for (const a of s.areas) {
|
|
99
|
+
const r = a.rect;
|
|
100
|
+
parts.push(
|
|
101
|
+
`<rect x="${sx(r.x1)}" y="${sy(r.y2)}" width="${(r.x2 - r.x1) * scale}" height="${(r.y2 - r.y1) * scale}" fill="#e7dfcc" fill-opacity="0.55" stroke="${FAINT}" stroke-width="0.8" stroke-dasharray="4 3"/>`,
|
|
102
|
+
);
|
|
103
|
+
const label = [a.attrs["name"], a.attrs["floor"]]
|
|
104
|
+
.filter((v): v is string => typeof v === "string")
|
|
105
|
+
.join(" · ");
|
|
106
|
+
if (label) {
|
|
107
|
+
parts.push(
|
|
108
|
+
`<text x="${sx(r.x1) + 6}" y="${sy(r.y2) + 12}" font-size="8.5" fill="#8a8171">${esc(label)}</text>`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 通り芯 (与件)
|
|
115
|
+
for (const [i, x] of model.grid.X.coords.entries()) {
|
|
116
|
+
if (x < minX - 1 || x > maxX + 1) continue;
|
|
117
|
+
parts.push(
|
|
118
|
+
`<line x1="${sx(x)}" y1="${M - 26}" x2="${sx(x)}" y2="${H - M + 26}" stroke="${GRID}" stroke-width="0.8" stroke-dasharray="7 3 1.5 3"/>`,
|
|
119
|
+
`<circle cx="${sx(x)}" cy="${M - 40}" r="11" fill="none" stroke="${GRID}" stroke-width="1"/>`,
|
|
120
|
+
`<text x="${sx(x)}" y="${M - 36}" text-anchor="middle" font-size="10" fill="${GRID}">${model.grid.X.names[i]!}</text>`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
for (const [i, y] of model.grid.Y.coords.entries()) {
|
|
124
|
+
if (y < minY - 1 || y > maxY + 1) continue;
|
|
125
|
+
parts.push(
|
|
126
|
+
`<line x1="${M - 26}" y1="${sy(y)}" x2="${W - M + 26}" y2="${sy(y)}" stroke="${GRID}" stroke-width="0.8" stroke-dasharray="7 3 1.5 3"/>`,
|
|
127
|
+
`<circle cx="${M - 40}" cy="${sy(y)}" r="11" fill="none" stroke="${GRID}" stroke-width="1"/>`,
|
|
128
|
+
`<text x="${M - 40}" y="${sy(y) + 3.5}" text-anchor="middle" font-size="10" fill="${GRID}">${model.grid.Y.names[i]!}</text>`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 壁 — Form が返す「開口で割られた区間」をそのまま塗る。
|
|
133
|
+
// **欠き取り (紙の色で塗り潰して穴に見せる手) は無い** — 壁は最初から穴の空いた列である
|
|
134
|
+
const byRef = new Map(form.boundaries.map((b) => [b.ref, b]));
|
|
135
|
+
for (const e of plan.entities) {
|
|
136
|
+
if (e.of !== "boundary") continue;
|
|
137
|
+
const b = byRef.get(e.ref);
|
|
138
|
+
if (!e.polygon) {
|
|
139
|
+
// 物を持たない境界 (open): 構成の線として破線で示す (基本計画の抽象度)
|
|
140
|
+
for (const g of e.lines ?? []) parts.push(line(g, FAINT, 1, "6 4"));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (e.class === "above") continue; // 垂れ壁は切断面より上 — 平面には出ない
|
|
144
|
+
if (b?.air) {
|
|
145
|
+
// 遮蔽しない物 (手すり・柵): 細実線 — 「囲われていない」ことが図から読めるように。
|
|
146
|
+
// 切断面より上でも下でも一本の線で描く (厚みを持たない作図表現)。
|
|
147
|
+
// **芯線は Form が持つ** — 足あとの四辺形から復元しない
|
|
148
|
+
for (const g of e.lines ?? []) parts.push(line(g, INK, 1.4));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
// 切断面が切った区間だけを黒帯にする。腰壁 (class:below) は開口の下なので描かない —
|
|
152
|
+
// **これが「欠き取り」の代わりである**。紙の色で塗り潰す操作はもう無い
|
|
153
|
+
if (e.class === "cut") parts.push(fill(e.polygon, INK));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 数えない分節 (seg): 壁材が途中から変わる区間 — 色調を変えて示す。
|
|
157
|
+
// 帯の形は core の構成子が起こす。ここから引くのは注記の言葉 (`spec`) だけで、
|
|
158
|
+
// それは形ではないので Form には載らない — 添字は宣言の並びの位置 = seg の同一性である
|
|
159
|
+
const ordered = canonicalBoundaryOrder(model);
|
|
160
|
+
for (const g of form.segs) {
|
|
161
|
+
if (g.level !== level) continue;
|
|
162
|
+
parts.push(fill(band(g.segment, g.cx, g.cy, g.w, g.t), "#77716a"));
|
|
163
|
+
// `g.boundary` は **Form の境界の添字 = 正準順の添字**である (docs/reference/form/index.md)。
|
|
164
|
+
// 宣言順の配列を引くと、宣言順を入れ替えただけで注記が別の境界のものになる
|
|
165
|
+
const spec = ordered[g.boundary]?.segs[g.index]?.attrs["spec"];
|
|
166
|
+
if (typeof spec === "string") {
|
|
167
|
+
const h = g.segment.horizontal;
|
|
168
|
+
parts.push(
|
|
169
|
+
`<text x="${sx(g.cx) + (h ? 0 : 8)}" y="${sy(g.cy) + (h ? -7 : 3)}" text-anchor="${h ? "middle" : "start"}" font-size="8" fill="#77716a">${esc(spec)}</text>`,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 開口 — 窓は芯線一本、扉は葉と軌跡 (1/4円の破線)
|
|
175
|
+
const openings = new Map(form.openings.map((o) => [o.ref, o]));
|
|
176
|
+
for (const e of plan.entities) {
|
|
177
|
+
if (e.of !== "opening") continue;
|
|
178
|
+
const o = openings.get(e.ref);
|
|
179
|
+
if (!o) continue;
|
|
180
|
+
if (e.class === "swing") {
|
|
181
|
+
if (o.sliding) {
|
|
182
|
+
// 引戸・自動ドア: 開き軌跡ではなく吊元側の控え (戸袋側) にパネルを描く
|
|
183
|
+
const off = 110; // 壁面からの控え mm (作図表現)
|
|
184
|
+
const sw = o.swing!;
|
|
185
|
+
const ux = (sw.leaf.x - sw.hinge.x) / o.w;
|
|
186
|
+
const uy = (sw.leaf.y - sw.hinge.y) / o.w;
|
|
187
|
+
const ax = (sw.jamb.x - sw.hinge.x) / o.w;
|
|
188
|
+
const ay = (sw.jamb.y - sw.hinge.y) / o.w;
|
|
189
|
+
const s1 = { x: sw.hinge.x - ax * o.w + ux * off, y: sw.hinge.y - ay * o.w + uy * off };
|
|
190
|
+
const s2 = { x: sw.hinge.x + ux * off, y: sw.hinge.y + uy * off };
|
|
191
|
+
parts.push(
|
|
192
|
+
line({ x1: s1.x, y1: s1.y, x2: s2.x, y2: s2.y }, INK, 2),
|
|
193
|
+
line({ x1: s2.x, y1: s2.y, x2: sw.hinge.x, y2: sw.hinge.y }, INK, 0.7),
|
|
194
|
+
);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (e.lines) for (const g of e.lines) parts.push(line(g, INK, 1.4));
|
|
198
|
+
if (e.arc) {
|
|
199
|
+
const r = e.arc.r * scale;
|
|
200
|
+
// 掃引方向: 世界の反時計回りは、y を反転した紙の上では時計回りになる
|
|
201
|
+
const sweep = e.arc.ccw ? 0 : 1;
|
|
202
|
+
parts.push(
|
|
203
|
+
`<path d="M ${sx(e.arc.from.x)} ${sy(e.arc.from.y)} A ${r} ${r} 0 0 ${sweep} ${sx(e.arc.to.x)} ${sy(e.arc.to.y)}" fill="none" stroke="${INK}" stroke-width="0.7" stroke-dasharray="3 2.5"/>`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (o.kind !== "door" && e.lines) {
|
|
209
|
+
// 窓: 芯線一本
|
|
210
|
+
for (const g of e.lines) parts.push(line(g, INK, 1));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 柱 (ADR-0023) — 位置はどこにも書かれていない。通り芯の交点と床の交わりから現れる
|
|
215
|
+
for (const e of plan.entities) {
|
|
216
|
+
if (e.of === "column" && e.polygon) parts.push(fill(e.polygon, INK));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 縦動線 (ADR-0021) — そのレベルで切った姿。上る走りは切断線で切れ、
|
|
220
|
+
// その先には下りる走り (下階の走りを上から見たもの) が現れる
|
|
221
|
+
const runs = new Map(form.runs.map((r) => [r.path, r]));
|
|
222
|
+
for (const e of plan.entities) {
|
|
223
|
+
if (e.of !== "run") continue;
|
|
224
|
+
if (e.role === "outline") for (const g of e.lines ?? []) parts.push(line(g, INK, 1.1));
|
|
225
|
+
else if (e.role === "tread") for (const g of e.lines ?? []) parts.push(line(g, INK, 0.7));
|
|
226
|
+
else if (e.role === "break") for (const g of e.lines ?? []) parts.push(...breakMark(g, line));
|
|
227
|
+
else if (e.role === "arrow") parts.push(...arrow(e, line, sx, sy));
|
|
228
|
+
else if (e.class === "anchor" && e.anchor) {
|
|
229
|
+
const r = runs.get(e.ref);
|
|
230
|
+
if (!r) continue;
|
|
231
|
+
const text =
|
|
232
|
+
r.device === "stair"
|
|
233
|
+
? `${r.risers}段 蹴上${Math.round(r.riser)}/踏面${Math.round(r.tread)}`
|
|
234
|
+
: `${r.lanes > 1 ? `${r.lanes}台 ` : ""}勾配 ${slopeText(r.slope)}`;
|
|
235
|
+
parts.push(
|
|
236
|
+
`<text x="${sx(e.anchor.x)}" y="${sy(e.anchor.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171">${esc(text)}</text>`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// 空間ラベル (最大の凸片の中心に置く)
|
|
242
|
+
for (const s of rooms) {
|
|
243
|
+
const space = model.spaces.get(s.path)!;
|
|
244
|
+
const poly = [...s.outline].sort((a, b) => polyArea(b) - polyArea(a))[0]!;
|
|
245
|
+
const r = polyBounds(poly);
|
|
246
|
+
const cx = sx((r.x1 + r.x2) / 2);
|
|
247
|
+
const cy = sy((r.y1 + r.y2) / 2);
|
|
248
|
+
const sub =
|
|
249
|
+
s.void
|
|
250
|
+
? "void"
|
|
251
|
+
: `${s.type ? `${esc(s.type)} · ` : ""}${s.areaM2} m2${s.semiOutdoor ? " · semi-outdoor" : ""}`;
|
|
252
|
+
parts.push(
|
|
253
|
+
`<text x="${cx}" y="${cy - 4}" text-anchor="middle" font-size="14" fill="${INK}">${esc(displayName(space))}</text>`,
|
|
254
|
+
`<text x="${cx}" y="${cy + 13}" text-anchor="middle" font-size="10" fill="#8a8171">${sub}</text>`,
|
|
255
|
+
`<text x="${cx}" y="${cy + 27}" text-anchor="middle" font-size="8.5" fill="${FAINT}">${esc(s.path)}</text>`,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 切断面より上のものの投影 (上部吹抜け — 作図慣習)
|
|
260
|
+
for (const e of plan.entities) {
|
|
261
|
+
if (e.class !== "above" || e.of !== "space" || !e.polygon) continue;
|
|
262
|
+
const r = polyBounds(e.polygon);
|
|
263
|
+
parts.push(
|
|
264
|
+
`<path d="${path2d(e.polygon)}" fill="none" stroke="${FAINT}" stroke-width="0.8" stroke-dasharray="6 4"/>`,
|
|
265
|
+
`<text x="${sx((r.x1 + r.x2) / 2)}" y="${sy((r.y1 + r.y2) / 2) + 40}" text-anchor="middle" font-size="9" fill="${FAINT}">void above</text>`,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 表題
|
|
270
|
+
const title = `${model.name ?? "Untitled"} — ${level} plan`;
|
|
271
|
+
parts.push(
|
|
272
|
+
`<text x="${M - 62}" y="${H - 18}" font-size="12" fill="${INK}">${esc(title)}</text>`,
|
|
273
|
+
`<text x="${W - M + 62}" y="${H - 18}" text-anchor="end" font-size="9" fill="#a49b8a">koyu — generated from spaces (wall centrelines, mm)</text>`,
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
parts.push("</svg>");
|
|
277
|
+
return parts.join("\n") + "\n";
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
type Line = (
|
|
281
|
+
g: { x1: number; y1: number; x2: number; y2: number },
|
|
282
|
+
stroke: string,
|
|
283
|
+
w: number,
|
|
284
|
+
dash?: string,
|
|
285
|
+
) => string;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 切断線 — 作図慣習の平行な二本の斜線。Form が持つのは「走りを横切る切断の位置」だけで、
|
|
289
|
+
* 二本にすることも振り分けの寸法も、ここが決める見た目である
|
|
290
|
+
*/
|
|
291
|
+
function breakMark(g: { x1: number; y1: number; x2: number; y2: number }, line: Line): string[] {
|
|
292
|
+
const dx = g.x2 - g.x1;
|
|
293
|
+
const dy = g.y2 - g.y1;
|
|
294
|
+
const width = Math.hypot(dx, dy) || 1;
|
|
295
|
+
// 走る向き (切断線に直交する単位ベクトル)
|
|
296
|
+
const tx = dy / width;
|
|
297
|
+
const ty = -dx / width;
|
|
298
|
+
const s = Math.min(300, width / 4);
|
|
299
|
+
const off = Math.min(220, s);
|
|
300
|
+
const at = (k: number, l: number) => ({
|
|
301
|
+
x1: g.x1 + tx * (k),
|
|
302
|
+
y1: g.y1 + ty * (k),
|
|
303
|
+
x2: g.x2 + tx * (l),
|
|
304
|
+
y2: g.y2 + ty * (l),
|
|
305
|
+
});
|
|
306
|
+
return [line(at(-s - off, s - off), INK, 1.4), line(at(-s + off, s + off), INK, 1.4)];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** 矢印 — 三角の頭と "UP"/"DN" の言葉は、どちらも見た目である */
|
|
310
|
+
function arrow(
|
|
311
|
+
e: PlanEntity,
|
|
312
|
+
line: Line,
|
|
313
|
+
sx: (x: number) => number,
|
|
314
|
+
sy: (y: number) => number,
|
|
315
|
+
): string[] {
|
|
316
|
+
const g = e.lines?.[0];
|
|
317
|
+
if (!g) return [];
|
|
318
|
+
const dx = g.x2 - g.x1;
|
|
319
|
+
const dy = g.y2 - g.y1;
|
|
320
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
321
|
+
const hx = (dx / len) * 420;
|
|
322
|
+
const hy = (dy / len) * 420;
|
|
323
|
+
const px = (-dy / len) * 200;
|
|
324
|
+
const py = (dx / len) * 200;
|
|
325
|
+
return [
|
|
326
|
+
line(g, INK, 1),
|
|
327
|
+
`<path d="M ${sx(g.x2)} ${sy(g.y2)} L ${sx(g.x2 - hx + px)} ${sy(g.y2 - hy + py)} L ${sx(g.x2 - hx - px)} ${sy(g.y2 - hy - py)} Z" fill="${INK}"/>`,
|
|
328
|
+
`<text x="${sx(g.x1) + 4}" y="${sy(g.y1) + 4}" font-size="9" fill="${INK}">${e.anchor?.up ? "UP" : "DN"}</text>`,
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function polyArea(poly: Pt[]): number {
|
|
333
|
+
let s = 0;
|
|
334
|
+
for (let i = 0; i < poly.length; i++) {
|
|
335
|
+
const a = poly[i]!;
|
|
336
|
+
const b = poly[(i + 1) % poly.length]!;
|
|
337
|
+
s += a.x * b.y - b.x * a.y;
|
|
338
|
+
}
|
|
339
|
+
return Math.abs(s / 2);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function esc(s: string): string {
|
|
343
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
344
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,44 +1,211 @@
|
|
|
1
|
-
// koyu
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
1
|
+
// koyu — 公開面 (ADR-0037)
|
|
2
|
+
//
|
|
3
|
+
// **ここに書き下された名だけが約束である。**`export *` は使わない — モジュールに
|
|
4
|
+
// export を足した瞬間に、誰も宣言していない約束が凍る面に増えてしまうからである。
|
|
5
|
+
// 凍らせる面は、書き下されていなければならない (docs/reference/scope.md)。
|
|
6
|
+
//
|
|
7
|
+
// 載せる基準は一つ — **面の外に利用者がいること。**
|
|
8
|
+
// 1. パッケージの外 (ugatsu / eval / scripts / editors) が実際に呼ぶ
|
|
9
|
+
// 2. CLI か MCP が答えるものを API からも答えるために要る
|
|
10
|
+
// (「CLIが答えるものはすべてこのAPIが答える」— docs/reference/api/index.md)
|
|
11
|
+
// 3. 公開文書が名指しで約束する導出 (docs/reference/scope.md)
|
|
12
|
+
// 4. test が契約として固定している
|
|
13
|
+
// core のモジュール同士が引き合うだけの配管は面ではない。型は、載せた値の署名を
|
|
14
|
+
// 書き下すのに要るものだけを載せる。
|
|
15
|
+
//
|
|
16
|
+
// この一覧と docs/reference/api/index.md の表は集合として一致する — test/public-api.test.ts が縛る。
|
|
17
|
+
|
|
18
|
+
// ---- 解析と合成 (docs/reference/muro/import.md) ----
|
|
19
|
+
export { parse, parseFiles, parseWith, tokenize, type LayerLoader } from "./core/parse.js";
|
|
20
|
+
|
|
21
|
+
// ---- モデルの語彙 — 書かれた構成の型 ----
|
|
22
|
+
export type {
|
|
23
|
+
Area,
|
|
24
|
+
Asset,
|
|
25
|
+
Attrs,
|
|
26
|
+
AttrValue,
|
|
27
|
+
Boundary,
|
|
28
|
+
BoundaryKind,
|
|
29
|
+
Column,
|
|
30
|
+
ColumnDecl,
|
|
31
|
+
DrawnLine,
|
|
32
|
+
Edge,
|
|
33
|
+
GridAxis,
|
|
34
|
+
GridRef,
|
|
35
|
+
Level,
|
|
36
|
+
Model,
|
|
37
|
+
Opening,
|
|
38
|
+
Pt,
|
|
39
|
+
Rect,
|
|
40
|
+
Seg,
|
|
41
|
+
SitePolygon,
|
|
42
|
+
Space,
|
|
43
|
+
Zone,
|
|
44
|
+
} from "./core/model.js";
|
|
45
|
+
|
|
46
|
+
// ---- モデルへの問い・導出・機械形式 ----
|
|
47
|
+
// **合否は言わない** (docs/reference/scope.md)。数と形を返すところまでが core である
|
|
6
48
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
49
|
+
areaM2,
|
|
50
|
+
canonicalBoundaryOrder,
|
|
51
|
+
columnsFor,
|
|
52
|
+
DEFAULT_LANGUAGE_VERSION,
|
|
53
|
+
displayName,
|
|
54
|
+
effectiveUse,
|
|
55
|
+
heff,
|
|
56
|
+
isCoveredAbove,
|
|
57
|
+
isIndoor,
|
|
58
|
+
isOutside,
|
|
59
|
+
isSemiOutdoor,
|
|
60
|
+
isVoid,
|
|
61
|
+
levelsSorted,
|
|
62
|
+
newUids,
|
|
63
|
+
pointInPolygon,
|
|
64
|
+
polyBounds,
|
|
65
|
+
polygonAreaM2,
|
|
66
|
+
rectToPoly,
|
|
67
|
+
SourceError,
|
|
68
|
+
srcRef,
|
|
69
|
+
SUPPORTED_LANGUAGE_VERSIONS,
|
|
70
|
+
toCanonical,
|
|
71
|
+
unionAreaM2,
|
|
72
|
+
zoneAreaM2,
|
|
73
|
+
} from "./core/model.js";
|
|
74
|
+
|
|
75
|
+
// ---- 構造整合の診断 (ADR-0016) ----
|
|
20
76
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
77
|
+
check,
|
|
78
|
+
checkDiagnostics,
|
|
79
|
+
DIAGNOSTIC_CODES,
|
|
80
|
+
type CheckResult,
|
|
81
|
+
type Diagnostic,
|
|
82
|
+
type DiagnosticCode,
|
|
83
|
+
} from "./core/diagnose.js";
|
|
84
|
+
|
|
85
|
+
// ---- 空間グラフと導出の部品 ----
|
|
86
|
+
export {
|
|
87
|
+
deriveDefaultBoundaries,
|
|
88
|
+
doorsBetween,
|
|
89
|
+
envelopeGaps,
|
|
90
|
+
neighbors,
|
|
91
|
+
passable,
|
|
92
|
+
placeBand,
|
|
93
|
+
placeOpening,
|
|
94
|
+
segmentsFor,
|
|
95
|
+
type Band,
|
|
96
|
+
type BandCode,
|
|
97
|
+
type BandError,
|
|
98
|
+
type NeighborInfo,
|
|
99
|
+
type PlacedBand,
|
|
100
|
+
type Route,
|
|
101
|
+
type Segment,
|
|
102
|
+
} from "./core/graph.js";
|
|
103
|
+
|
|
104
|
+
// ---- 形の参照実装 (ADR-0040) — **これが形の唯一の入口である** ----
|
|
105
|
+
// Form は見た目を持たない (docs/reference/scope.md)。規則は docs/reference/form/index.md が持つ
|
|
106
|
+
// 実体の構成子 (thicken / bandLine / band / columnRect / runPrism) も core が唯一の実装を
|
|
107
|
+
// 持つ — 芯線と厚みから四辺形や角柱を起こす規則も導出の一部だからである
|
|
108
|
+
export {
|
|
109
|
+
band,
|
|
110
|
+
bandLine,
|
|
111
|
+
columnRect,
|
|
112
|
+
derive,
|
|
113
|
+
DERIVATION_CONSTANTS,
|
|
114
|
+
levelPitch,
|
|
115
|
+
runPrism,
|
|
116
|
+
thicken,
|
|
117
|
+
type DeriveOptions,
|
|
118
|
+
type Form,
|
|
119
|
+
type FormBoundary,
|
|
120
|
+
type FormColumn,
|
|
121
|
+
type FormInput,
|
|
122
|
+
type FormLevel,
|
|
123
|
+
type FormOpening,
|
|
124
|
+
type FormPanel,
|
|
125
|
+
type FormPlan,
|
|
126
|
+
type FormPrism,
|
|
127
|
+
type FormRun,
|
|
128
|
+
type FormSeg,
|
|
129
|
+
type FormSite,
|
|
130
|
+
type FormSpace,
|
|
131
|
+
type FormSwing,
|
|
132
|
+
type PlanClass,
|
|
133
|
+
type PlanEntity,
|
|
134
|
+
type PlanRole,
|
|
135
|
+
type PlanSubject,
|
|
136
|
+
} from "./core/derive.js";
|
|
137
|
+
export { TOLERANCES } from "./core/tolerance.js";
|
|
138
|
+
|
|
139
|
+
// ---- 床・天井・屋根 (ADR-0024) ----
|
|
140
|
+
export { slabs, type Slab, type SlabKind } from "./core/fabric.js";
|
|
141
|
+
|
|
142
|
+
// ---- 採光の入力 (ADR-0020) ----
|
|
143
|
+
export { daylightInputs, type DaylightInput } from "./core/light.js";
|
|
144
|
+
|
|
145
|
+
// ---- 縦動線 (ADR-0021) ----
|
|
146
|
+
export {
|
|
147
|
+
RUN_KEYS,
|
|
23
148
|
runDecls,
|
|
24
|
-
runSolids,
|
|
25
149
|
runDrawsForLevel,
|
|
26
|
-
|
|
150
|
+
runSolids,
|
|
27
151
|
slopeText,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
RUN_FORMS,
|
|
152
|
+
verticalRuns,
|
|
153
|
+
type RunArrow,
|
|
154
|
+
type RunDecl,
|
|
32
155
|
type RunDevice,
|
|
156
|
+
type RunDraw,
|
|
33
157
|
type RunForm,
|
|
34
158
|
type RunPart,
|
|
35
|
-
type VerticalRun,
|
|
36
159
|
type RunSolid,
|
|
37
|
-
type RunDraw,
|
|
38
|
-
type RunArrow,
|
|
39
|
-
type RunIssue,
|
|
40
160
|
type Seg2,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
161
|
+
type VerticalRun,
|
|
162
|
+
} from "./core/vertical.js";
|
|
163
|
+
|
|
164
|
+
// ---- 敷地 (ADR-0009 / ADR-0011) ----
|
|
165
|
+
export { siteReport, type RoadFrontage, type SiteReport } from "./core/site.js";
|
|
166
|
+
|
|
167
|
+
// ---- 構成の言葉の差分 (ADR-0018) ----
|
|
168
|
+
export {
|
|
169
|
+
renderDiff,
|
|
170
|
+
semanticDiff,
|
|
171
|
+
type BoundaryChange,
|
|
172
|
+
type BoundaryItem,
|
|
173
|
+
type ChangedItem,
|
|
174
|
+
type ColumnItem,
|
|
175
|
+
type FieldChange,
|
|
176
|
+
type GridChange,
|
|
177
|
+
type ModelDiff,
|
|
178
|
+
type RenamedItem,
|
|
179
|
+
type SpaceItem,
|
|
180
|
+
} from "./core/diff.js";
|
|
181
|
+
|
|
182
|
+
// ---- 属性の台帳 — **書いてよいキーの一覧であって、読むキーの一覧ではない** ----
|
|
183
|
+
//
|
|
184
|
+
// 利用者の側にも境界が要る。台帳を出していなかった間、消費側のアプリは
|
|
185
|
+
// 「この鍵はこの要素に書けるか」を答えるために台帳を手で写すしかなく、写しは必ずずれる。
|
|
186
|
+
// `outside` と `void` を型の位置から台帳へ移した以上、その台帳は読めなければ意味がない。
|
|
187
|
+
export {
|
|
188
|
+
ASSET_ELEM,
|
|
189
|
+
ATTR_LEDGER,
|
|
190
|
+
attrSpec,
|
|
191
|
+
CARRY_NAMESPACE,
|
|
192
|
+
isNamespaced,
|
|
193
|
+
known,
|
|
194
|
+
type AttrSpec,
|
|
195
|
+
type AttrTier,
|
|
196
|
+
} from "./core/vocabulary.js";
|
|
197
|
+
|
|
198
|
+
// ---- 生成 — **凍らない** (docs/reference/scope.md)。SVGの中身は約束の外にある ----
|
|
199
|
+
// 領域としては `@kensnzk/koyu/draw` にも分けてある
|
|
200
|
+
export { svgPlan, type PlanOptions } from "./draw/plan.js";
|
|
201
|
+
export { svgAxo, type AxoOptions } from "./draw/axo.js";
|
|
202
|
+
|
|
203
|
+
// ---- 検証 — **core ではない。**凍らない・増える・合否を言う (docs/reference/scope.md) ----
|
|
204
|
+
// Finding は Diagnostic と別の型で、フィールド名から違う (rule/level と code/severity)。
|
|
205
|
+
// 領域としては `@kensnzk/koyu/validate` にも分けてある
|
|
206
|
+
export {
|
|
207
|
+
validate,
|
|
208
|
+
VALIDATION_RULES,
|
|
209
|
+
type Finding,
|
|
210
|
+
type ValidationRule,
|
|
211
|
+
} from "./validate/index.js";
|