@kensnzk/koyu 0.27.0 → 0.28.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.
Files changed (136) hide show
  1. package/assets/plan/README.md +18 -0
  2. package/assets/plan/catalog.muro +87 -0
  3. package/assets/plan/library.muro +26 -0
  4. package/assets/plan/svg/bathtub.svg +9 -0
  5. package/assets/plan/svg/bed-double.svg +9 -0
  6. package/assets/plan/svg/bed-single.svg +8 -0
  7. package/assets/plan/svg/cabinet.svg +9 -0
  8. package/assets/plan/svg/chair.svg +8 -0
  9. package/assets/plan/svg/desk.svg +9 -0
  10. package/assets/plan/svg/hedge-2m.svg +7 -0
  11. package/assets/plan/svg/kitchen-sink.svg +10 -0
  12. package/assets/plan/svg/locker.svg +9 -0
  13. package/assets/plan/svg/office-chair.svg +25 -0
  14. package/assets/plan/svg/potted-plant.svg +14 -0
  15. package/assets/plan/svg/refrigerator.svg +10 -0
  16. package/assets/plan/svg/shelf.svg +9 -0
  17. package/assets/plan/svg/shrub-1m.svg +7 -0
  18. package/assets/plan/svg/sofa-2.svg +9 -0
  19. package/assets/plan/svg/sofa-3.svg +9 -0
  20. package/assets/plan/svg/table-rect.svg +7 -0
  21. package/assets/plan/svg/table-round.svg +7 -0
  22. package/assets/plan/svg/tree-3m.svg +8 -0
  23. package/assets/plan/svg/urinal.svg +9 -0
  24. package/assets/plan/svg/washing-machine-pan.svg +13 -0
  25. package/assets/plan/svg/washing-machine.svg +10 -0
  26. package/assets/plan/svg/washstand-500.svg +12 -0
  27. package/assets/plan/svg/washstand.svg +12 -0
  28. package/assets/plan/svg/wc-cabinet.svg +14 -0
  29. package/assets/plan/svg/wc.svg +9 -0
  30. package/dist/cli.js +2 -2
  31. package/dist/cli.js.map +1 -1
  32. package/dist/core/components.d.ts +31 -0
  33. package/dist/core/components.d.ts.map +1 -0
  34. package/dist/core/components.js +167 -0
  35. package/dist/core/components.js.map +1 -0
  36. package/dist/core/derive.d.ts +9 -1
  37. package/dist/core/derive.d.ts.map +1 -1
  38. package/dist/core/derive.js +33 -3
  39. package/dist/core/derive.js.map +1 -1
  40. package/dist/core/diagnose.d.ts +6 -0
  41. package/dist/core/diagnose.d.ts.map +1 -1
  42. package/dist/core/diagnose.js +137 -4
  43. package/dist/core/diagnose.js.map +1 -1
  44. package/dist/core/model.d.ts +5 -5
  45. package/dist/core/model.d.ts.map +1 -1
  46. package/dist/core/model.js +6 -1
  47. package/dist/core/model.js.map +1 -1
  48. package/dist/core/parse.d.ts.map +1 -1
  49. package/dist/core/parse.js +5 -4
  50. package/dist/core/parse.js.map +1 -1
  51. package/dist/core/vocabulary.d.ts +20 -4
  52. package/dist/core/vocabulary.d.ts.map +1 -1
  53. package/dist/core/vocabulary.js +107 -9
  54. package/dist/core/vocabulary.js.map +1 -1
  55. package/dist/draw/component-files.d.ts +8 -0
  56. package/dist/draw/component-files.d.ts.map +1 -0
  57. package/dist/draw/component-files.js +35 -0
  58. package/dist/draw/component-files.js.map +1 -0
  59. package/dist/draw/component-svg.d.ts +14 -0
  60. package/dist/draw/component-svg.d.ts.map +1 -0
  61. package/dist/draw/component-svg.js +67 -0
  62. package/dist/draw/component-svg.js.map +1 -0
  63. package/dist/draw/conventions/architectural.d.ts +32 -0
  64. package/dist/draw/conventions/architectural.d.ts.map +1 -0
  65. package/dist/draw/conventions/architectural.js +29 -0
  66. package/dist/draw/conventions/architectural.js.map +1 -0
  67. package/dist/draw/index.d.ts +1 -1
  68. package/dist/draw/index.d.ts.map +1 -1
  69. package/dist/draw/index.js +1 -1
  70. package/dist/draw/index.js.map +1 -1
  71. package/dist/draw/marks.d.ts +37 -12
  72. package/dist/draw/marks.d.ts.map +1 -1
  73. package/dist/draw/marks.js +508 -38
  74. package/dist/draw/marks.js.map +1 -1
  75. package/dist/draw/plan.d.ts +3 -1
  76. package/dist/draw/plan.d.ts.map +1 -1
  77. package/dist/draw/plan.js +247 -85
  78. package/dist/draw/plan.js.map +1 -1
  79. package/dist/form.d.ts +1 -1
  80. package/dist/form.d.ts.map +1 -1
  81. package/dist/form.js.map +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/mcp.js +21 -3
  84. package/dist/mcp.js.map +1 -1
  85. package/dist/parse-file.d.ts +1 -0
  86. package/dist/parse-file.d.ts.map +1 -1
  87. package/dist/parse-file.js +1 -0
  88. package/dist/parse-file.js.map +1 -1
  89. package/dist/validate/builtin/index.d.ts +4 -2
  90. package/dist/validate/builtin/index.d.ts.map +1 -1
  91. package/dist/validate/builtin/index.js +9 -2
  92. package/dist/validate/builtin/index.js.map +1 -1
  93. package/dist/validate/builtin/opening-operations.d.ts +63 -0
  94. package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
  95. package/dist/validate/builtin/opening-operations.js +406 -0
  96. package/dist/validate/builtin/opening-operations.js.map +1 -0
  97. package/editors/vscode/syntaxes/koyu.tmLanguage.json +3 -3
  98. package/examples/basement/main.muro +3 -3
  99. package/examples/complex/L1.muro +1 -1
  100. package/examples/complex/assets.muro +2 -2
  101. package/examples/complex/main.muro +1 -1
  102. package/examples/house/L1.muro +3 -3
  103. package/examples/house/L2.muro +2 -2
  104. package/examples/house/assets.muro +8 -8
  105. package/examples/house/main.muro +1 -1
  106. package/examples/house/site.muro +2 -2
  107. package/examples/house.muro +6 -6
  108. package/examples/mansion.muro +1 -1
  109. package/examples/office.muro +1 -1
  110. package/examples/steps/06-finished.muro +1 -1
  111. package/examples/tower/assets.muro +1 -1
  112. package/examples/tower/main.muro +1 -1
  113. package/examples/twin/assets.muro +2 -2
  114. package/examples/twin/main.muro +1 -1
  115. package/examples/two-rooms.canonical.json +1 -1
  116. package/examples/two-rooms.muro +1 -1
  117. package/package.json +7 -4
  118. package/src/cli.ts +2 -2
  119. package/src/core/components.ts +224 -0
  120. package/src/core/derive.ts +47 -4
  121. package/src/core/diagnose.ts +182 -4
  122. package/src/core/model.ts +10 -5
  123. package/src/core/parse.ts +5 -4
  124. package/src/core/vocabulary.ts +115 -9
  125. package/src/draw/component-files.ts +36 -0
  126. package/src/draw/component-svg.ts +79 -0
  127. package/src/draw/conventions/architectural.ts +60 -0
  128. package/src/draw/index.ts +1 -1
  129. package/src/draw/marks.ts +564 -44
  130. package/src/draw/plan.ts +253 -88
  131. package/src/form.ts +1 -0
  132. package/src/index.ts +1 -1
  133. package/src/mcp.ts +21 -3
  134. package/src/parse-file.ts +1 -0
  135. package/src/validate/builtin/index.ts +14 -2
  136. package/src/validate/builtin/opening-operations.ts +519 -0
package/src/draw/plan.ts CHANGED
@@ -1,18 +1,20 @@
1
- // koyu — 平面図の生成
1
+ // koyu — plan SVG generation
2
2
  //
3
- // **ここに形の規則は一つも無い。**壁の厚みも、開口の位置も、扉の吊元も、階段がどこで
4
- // 切れるかも、`derive(model)` が返す `Form` に既に入っている (ADR-0040)。この頁が持つのは
5
- // 色・線種・線幅・書体・記号・注記の言葉・縮尺・紙面の余白 — すべて**見た目**であり、
6
- // 消費者ごとに違ってよいものである (docs/reference/scope.md)。
3
+ // **No rule of building shape lives here.** Wall thickness, opening position, door hinge and stair
4
+ // cut are already in the `Form` returned by `derive(model)` (ADR-0040). This page owns colour,
5
+ // line type, line weight, typography, symbols, annotation wording, scale and sheet margins — all
6
+ // presentation, and all allowed to differ by consumer (docs/reference/scope.md).
7
7
  //
8
- // 形と見た目の線引きはこうである。境界線分の座標・壁の厚み・開口で割られた区間・
9
- // 扉の軌跡の中心と半径と掃き方向・切断面を跨ぐ位置は Form が持つ。1/4円を破線で描くか、
10
- // 切断線を平行な二本の斜線として引くか、矢印に "UP" と書くかは、ここが決める。
8
+ // Form carries boundary coordinates, wall thickness, opening intervals, door-arc geometry and
9
+ // the position where a cut crosses a run. The architectural convention and this renderer decide
10
+ // whether a break becomes a diagonal zigzag and whether an arrowhead is open.
11
11
 
12
12
  import { derive } from "../core/derive.js";
13
13
  import { displayName, polyBounds, type Model, type Pt } from "../core/model.js";
14
14
  import { slopeText } from "../core/vertical.js";
15
15
  import { planMarks, type Mark } from "./marks.js";
16
+ import { ARCHITECTURAL_PLAN_CONVENTION } from "./conventions/architectural.js";
17
+ import { componentSvg } from "./component-svg.js";
16
18
  import { esc, Extent, FAINT, GRID, INK, openSheet, OUTDOOR, PAPER, ROOM, SEMI_OUTDOOR } from "./sheet.js";
17
19
  import { writtenOf } from "./written.js";
18
20
 
@@ -20,8 +22,10 @@ export interface PlanOptions {
20
22
  level?: string;
21
23
  /** px per mm */
22
24
  scale?: number;
23
- /** 切断面の高さ mm (FLから) — **形を決める引数**なので Form の入力へ渡る */
25
+ /** Cut height above finished floor, mm. It changes the slice, so it is passed into Form. */
24
26
  cut?: number;
27
+ /** Plan SVG bytes keyed by component asset name, for models made with the pure `parse` entry. */
28
+ componentSvgs?: Readonly<Record<string, string>>;
25
29
  }
26
30
 
27
31
  export function svgPlan(model: Model, opts: PlanOptions = {}): string {
@@ -36,15 +40,15 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
36
40
  throw new Error(`There is no space with a region on level ${level}`);
37
41
  }
38
42
 
39
- // 敷地形状 (ADR-0011) は最下階の平面 (配置図兼用) に敷地境界線として描く — 紙面の構成の判断
43
+ // Site geometry (ADR-0011) appears on the lowest plan, which also serves as the site plan.
40
44
  const lowest = form.levels[0]?.name;
41
45
  const sitePolys = level === lowest ? form.site : [];
42
46
 
43
- // 紙面の外接範囲。**書かれた割付も含める** — 切られた形より外へ割付がはみ出しても紙に載る
47
+ // Sheet extent includes written allocation, even where it reaches outside the cut shape.
44
48
  const modelRooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level === level);
45
49
  const allRects = modelRooms.flatMap((s) => s.rects);
46
50
  const polyPts = [...sitePolys.flatMap((p) => p.points), ...rooms.flatMap((s) => s.outline.flat())];
47
- // **畳んで取る** (Extent) — 引数を展開すると、大きな階では点の数がスタックの限界に当たる
51
+ // Fold through Extent: spreading every point can hit the call-stack limit on a large storey.
48
52
  const ext = new Extent();
49
53
  for (const r of allRects) {
50
54
  ext.see(r.x1, r.y1);
@@ -56,7 +60,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
56
60
  const minY = ext.min1;
57
61
  const maxY = ext.max1;
58
62
 
59
- const M = 84; // 余白 px (通り芯記号ぶん)
63
+ const M = 84; // sheet margin in px, including grid bubbles
60
64
  const W = (maxX - minX) * scale + M * 2;
61
65
  const H = (maxY - minY) * scale + M * 2;
62
66
  const sx = (x: number) => (x - minX) * scale + M;
@@ -69,22 +73,21 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
69
73
 
70
74
  const parts: string[] = openSheet(W, H);
71
75
 
72
- // 敷地境界線 (一点二点鎖線 — 作図慣習)。所与の形をそのまま引く
76
+ // Site boundary: a drafting dash pattern applied to the supplied geometry.
73
77
  for (const poly of sitePolys) {
74
78
  parts.push(
75
79
  `<path d="${path2d(poly.points)}" fill="none" stroke="#8a8171" stroke-width="1.1" stroke-dasharray="14 3 2.5 3 2.5 3"/>`,
76
80
  );
77
81
  }
78
82
 
79
- // 空間の面 — 切断面が気積を切った姿。同色・輪郭なしなのでL字も切られた形も一体に見える。
80
- // **暖色が屋内、寒色が屋外**である。宣言された屋外 (outside:1)・半屋外・屋内の三段で、
81
- // 前庭と玄関ホールが同じ一枚のクリームに見えていた状態を分ける
83
+ // Space faces are the cut through volume. A shared fill and no outline make split convex pieces
84
+ // read as one room. Warm denotes indoors; cooler tones separate outside and semi-outdoor space.
82
85
  for (const s of rooms) {
83
86
  const isVoid = s.void;
84
87
  for (const poly of s.outline) {
85
88
  parts.push(fill(poly, isVoid ? PAPER : s.outside ? OUTDOOR : s.semiOutdoor ? SEMI_OUTDOOR : ROOM));
86
89
  if (isVoid) {
87
- // 吹抜け: 破線の対角線 (作図慣習)
90
+ // Void: dashed diagonals are a paper convention.
88
91
  const r = polyBounds(poly);
89
92
  parts.push(
90
93
  line({ x1: r.x1, y1: r.y1, x2: r.x2, y2: r.y2 }, FAINT, 0.8, "6 4"),
@@ -94,14 +97,18 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
94
97
  }
95
98
  }
96
99
 
97
- // 数えない分節 (area): 床材の切替など。書かれた与件をそのまま引く — 導出ではない
100
+ // Uncounted area subdivisions, such as a floor-finish change, reproduce the written input.
98
101
  for (const s of modelRooms) {
99
102
  for (const a of s.areas) {
100
103
  const r = a.rect;
101
- parts.push(
102
- `<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"/>`,
103
- );
104
- const label = [a.attrs["name"], a.attrs["floor"]]
104
+ const componentHost = a.attrs["asset"] !== undefined;
105
+ const visibleSubdivision = a.attrs["floor"] !== undefined || a.attrs["spec"] !== undefined;
106
+ if (!componentHost || visibleSubdivision) {
107
+ parts.push(
108
+ `<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"/>`,
109
+ );
110
+ }
111
+ const label = [componentHost ? undefined : a.attrs["name"], a.attrs["floor"]]
105
112
  .filter((v): v is string => typeof v === "string")
106
113
  .join(" · ");
107
114
  if (label) {
@@ -112,7 +119,29 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
112
119
  }
113
120
  }
114
121
 
115
- // 通り芯 (与件)
122
+ // Components are below cut matter and room labels. The source SVG remains isolated as an image,
123
+ // preserving its defs and IDs while the Form supplies all placement geometry.
124
+ for (const component of form.components ?? []) {
125
+ if (component.level !== level) continue;
126
+ const asset = model.assets.get(component.asset);
127
+ if (!asset || asset.kind !== "component") continue;
128
+ const source = opts.componentSvgs?.[asset.name];
129
+ if (!source) {
130
+ throw new Error(
131
+ `Component asset ${asset.name} has no plan SVG bytes; pass PlanOptions.componentSvgs`,
132
+ );
133
+ }
134
+ const artwork = componentSvg(asset, source);
135
+ const cx = sx(component.centre.x);
136
+ const cy = sy(component.centre.y);
137
+ const width = component.w * scale;
138
+ const height = component.d * scale;
139
+ parts.push(
140
+ `<image class="component-asset" data-asset="${esc(asset.name)}" x="${cx - width / 2}" y="${cy - height / 2}" width="${width}" height="${height}" preserveAspectRatio="none" href="${artwork.dataUri}" transform="rotate(${-component.rotation} ${cx} ${cy})"/>`,
141
+ );
142
+ }
143
+
144
+ // Written grid axes.
116
145
  for (const [i, x] of model.grid.X.coords.entries()) {
117
146
  if (x < minX - 1 || x > maxX + 1) continue;
118
147
  parts.push(
@@ -130,15 +159,34 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
130
159
  );
131
160
  }
132
161
 
133
- // 印 — 形の写しは `planMarks` にある。**この頁が足すのは色・線幅・線種・記号・注記の言葉だけ**
134
- // である。ugatsu も architype も同じ印から別の見た目を引く。
162
+ // Marks copy Form geometry. This page adds only colour, weight, dash, glyph and wording; another
163
+ // consumer can render the same marks differently.
135
164
  const marks = planMarks(form, level);
136
165
  const written = writtenOf(model);
137
166
  const segByRef = new Map(form.segs.map((g) => [g.ref, g]));
167
+ // A generic room label over a stair repeats what the treads already say and obscures the arrow.
168
+ // Seed the set from actual stair runs, then follow only vertical boundaries connected to them so
169
+ // ramps, escalators and lift shafts keep their existing labels.
170
+ const stairSpaces = new Set(form.runs.filter((r) => r.device === "stair").map((r) => r.path));
171
+ let grew = true;
172
+ while (grew) {
173
+ grew = false;
174
+ for (const b of model.boundaries) {
175
+ if (b.kind !== "stair" || (!stairSpaces.has(b.a) && !stairSpaces.has(b.b))) continue;
176
+ if (!stairSpaces.has(b.a)) {
177
+ stairSpaces.add(b.a);
178
+ grew = true;
179
+ }
180
+ if (!stairSpaces.has(b.b)) {
181
+ stairSpaces.add(b.b);
182
+ grew = true;
183
+ }
184
+ }
185
+ }
138
186
  for (const k of marks) {
139
187
  switch (k.role) {
140
- // 空間の面と分節の帯は下 (`rooms` / `form.segs`) から引く — 切られた面ではなく外形を塗り、
141
- // 分節には Form しか持たない座と向きが要るため。上部吹抜けは空間ラベルより後ろに置く
188
+ // Space faces and subdivision bands are rendered from their full outlines elsewhere. Upper
189
+ // void projections are deliberately placed behind space labels.
142
190
  case "space":
143
191
  case "space-semi-outdoor":
144
192
  case "space-outdoor":
@@ -146,10 +194,9 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
146
194
  case "void-hatch":
147
195
  case "void-above":
148
196
  break;
149
- // 数えない分節 (seg): 壁材が途中から変わる区間 — 色調を変えて示す。
150
- // ここから引くのは注記の言葉 (`spec`) だけで、それは形ではないので Form には載らない。
151
- // **`written.boundary` は正準順の添字である** — 宣言順の配列を引くと、並べ替えただけで
152
- // 注記が別の境界のものになる
197
+ // An uncounted segment can mark a wall specification change. Only the annotation wording is
198
+ // recovered from the source. `written.boundary` indexes canonical order, never declaration
199
+ // order, so a harmless source reorder cannot move the note to another boundary.
153
200
  case "seg": {
154
201
  parts.push(fill(k.polygon!, "#77716a"));
155
202
  const spec = written.segSpec(k.written!.boundary, k.written!.index!);
@@ -162,43 +209,135 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
162
209
  }
163
210
  break;
164
211
  }
165
- // 物を持たない境界 (open): 構成の線として破線で示す (基本計画の抽象度)
212
+ // A boundary with no matter remains legible as a light dashed relation.
166
213
  case "open":
167
214
  for (const g of k.lines ?? []) parts.push(line(g, FAINT, 1, "6 4"));
168
215
  break;
169
- // 遮蔽しない物 (手すり・柵): 細実線 — 「囲われていない」ことが図から読めるように。
170
- // **芯線は Form が持つ** — 足あとの四辺形から復元しない
216
+ // A rail stays lighter than a wall, while the endpoint posts keep a short rail from reading
217
+ // as an accidental construction line. The axis itself comes from Form; the circles are a
218
+ // paper convention and add no building geometry.
171
219
  case "rail":
172
- for (const g of k.lines ?? []) parts.push(line(g, INK, 1.4));
220
+ parts.push(`<g class="boundary-rail">`);
221
+ for (const g of k.lines ?? []) {
222
+ parts.push(line(g, INK, 1.1));
223
+ parts.push(
224
+ `<circle class="boundary-rail-post" cx="${sx(g.x1)}" cy="${sy(g.y1)}" r="1.45" fill="${INK}"/>`,
225
+ `<circle class="boundary-rail-post" cx="${sx(g.x2)}" cy="${sy(g.y2)}" r="1.45" fill="${INK}"/>`,
226
+ );
227
+ }
228
+ parts.push(`</g>`);
173
229
  break;
174
- // 切断面が切った区間と柱を黒帯にする。腰壁は開口の下なので印にならない —
175
- // **これが「欠き取り」の代わりである**。紙の色で塗り潰す操作はもう無い
230
+ // Only intervals and columns cut by the plane become black bodies. Sill walls lie below the
231
+ // cut; no paper-coloured mask is needed to erase openings.
176
232
  case "wall":
177
233
  case "column":
178
234
  parts.push(fill(k.polygon!, INK));
179
235
  break;
180
- // 引戸・自動ドア: 開き軌跡ではなく吊元側の控え (戸袋側) にパネルを描く
236
+ // A sliding leaf has no swing trace. Its solid line closes the opening; the thin dashed
237
+ // continuation says which way it retracts without turning the opening into a box.
181
238
  case "slide-panel":
182
- for (const g of k.lines ?? []) parts.push(line(g, INK, 2));
239
+ parts.push(`<g class="opening-slide-panel">`);
240
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 1.2));
241
+ parts.push(`</g>`);
183
242
  break;
184
- case "slide-tail":
243
+ case "slide-centre":
244
+ parts.push(`<g class="opening-slide-centre">`);
185
245
  for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
246
+ parts.push(`</g>`);
247
+ break;
248
+ case "slide-tail":
249
+ parts.push(`<g class="opening-slide-guide">`);
250
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65, "5 3"));
251
+ parts.push(`</g>`);
252
+ break;
253
+ case "auto-direction":
254
+ parts.push(`<g class="opening-auto-direction">`);
255
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65));
256
+ parts.push(`</g>`);
257
+ break;
258
+ case "entrance":
259
+ parts.push(`<g class="opening-entrance">`);
260
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.75));
261
+ parts.push(`</g>`);
262
+ break;
263
+ case "gate-post":
264
+ parts.push(`<g class="opening-gate-post">`);
265
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 2));
266
+ parts.push(`</g>`);
267
+ break;
268
+ case "rolling-shutter":
269
+ parts.push(`<g class="opening-rolling-shutter">`);
270
+ for (const g of k.lines ?? []) {
271
+ parts.push(line(g, INK, 1));
272
+ parts.push(
273
+ `<rect x="${sx(g.x1) - 1.5}" y="${sy(g.y1) - 1.5}" width="3" height="3" fill="${INK}"/>`,
274
+ `<rect x="${sx(g.x2) - 1.5}" y="${sy(g.y2) - 1.5}" width="3" height="3" fill="${INK}"/>`,
275
+ );
276
+ }
277
+ parts.push(`</g>`);
278
+ break;
279
+ case "overhead-door":
280
+ parts.push(`<g class="opening-overhead-door">`);
281
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1, "2 1"));
282
+ parts.push(`</g>`);
186
283
  break;
187
284
  case "door-leaf":
188
- for (const g of k.lines ?? []) parts.push(line(g, INK, 1.4));
285
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1));
286
+ break;
287
+ case "window-leaf":
288
+ parts.push(`<g class="opening-window-leaf">`);
289
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.8));
290
+ parts.push(`</g>`);
189
291
  break;
190
- case "door-arc": {
292
+ case "door-arc":
293
+ case "window-arc": {
191
294
  const a = k.arc!;
192
295
  const r = a.r * scale;
193
- // 掃引方向: 世界の反時計回りは、y を反転した紙の上では時計回りになる
296
+ // World counter-clockwise becomes clockwise after the SVG y-axis is inverted.
194
297
  const sweep = a.ccw ? 0 : 1;
298
+ const window = k.role === "window-arc";
195
299
  parts.push(
196
- `<path d="M ${sx(a.from.x)} ${sy(a.from.y)} A ${r} ${r} 0 0 ${sweep} ${sx(a.to.x)} ${sy(a.to.y)}" fill="none" stroke="${INK}" stroke-width="0.7" stroke-dasharray="3 2.5"/>`,
300
+ `<path class="${window ? "opening-window-arc" : "opening-door-arc"}" d="M ${sx(a.from.x)} ${sy(a.from.y)} A ${r} ${r} 0 0 ${sweep} ${sx(a.to.x)} ${sy(a.to.y)}" fill="none" stroke="${INK}" stroke-width="${window ? 0.55 : 0.7}"/>`,
197
301
  );
198
302
  break;
199
303
  }
200
- case "window":
201
- for (const g of k.lines ?? []) parts.push(line(g, INK, 1));
304
+ case "window": {
305
+ const cut = k.class === "cut";
306
+ const stroke = cut ? INK : FAINT;
307
+ const dash = cut ? "" : "5 3";
308
+ parts.push(`<g class="opening-window">`);
309
+ if (k.polygon && k.polygon.length >= 4) {
310
+ const p = k.polygon;
311
+ // A window continues the two faces of the wall as unfilled lines. Closing this path
312
+ // would add jamb caps and turn the window back into a boxed door opening.
313
+ parts.push(
314
+ `<path d="M ${sx(p[0]!.x)} ${sy(p[0]!.y)} L ${sx(p[1]!.x)} ${sy(p[1]!.y)} M ${sx(p[3]!.x)} ${sy(p[3]!.y)} L ${sx(p[2]!.x)} ${sy(p[2]!.y)}" fill="none" stroke="${stroke}" stroke-width="0.8"${dash ? ` stroke-dasharray="${dash}"` : ""}/>`,
315
+ );
316
+ } else {
317
+ for (const g of k.lines ?? []) parts.push(line(g, stroke, 0.55, dash));
318
+ }
319
+ parts.push(`</g>`);
320
+ break;
321
+ }
322
+ case "window-sash":
323
+ parts.push(`<g class="opening-window-sash">`);
324
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
325
+ parts.push(`</g>`);
326
+ break;
327
+ case "window-fixed":
328
+ parts.push(`<g class="opening-window-fixed">`);
329
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65));
330
+ parts.push(`</g>`);
331
+ break;
332
+ case "curtain-wall-mullion":
333
+ parts.push(`<g class="opening-curtain-wall-mullion">`);
334
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.55));
335
+ parts.push(`</g>`);
336
+ break;
337
+ case "window-sash-centre":
338
+ parts.push(`<g class="opening-window-sash-centre">`);
339
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.55));
340
+ parts.push(`</g>`);
202
341
  break;
203
342
  case "run-outline":
204
343
  for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1));
@@ -212,24 +351,22 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
212
351
  case "run-arrow":
213
352
  parts.push(...arrow(k, line, sx, sy));
214
353
  break;
215
- // 注記の言葉と丸めはここで初めて生まれる — 印が運ぶのは丸めない事実だけである
354
+ // Wording and rounding begin here; the mark carries only unrounded facts.
216
355
  case "run-note": {
217
356
  const n = k.note;
218
- if (!n || n.of === "direction") break; // 座の注記は向きではない
219
- const text =
220
- n.of === "stair"
221
- ? `${n.risers}段 蹴上${Math.round(n.riser)}/踏面${Math.round(n.tread)}`
222
- : `${n.lanes > 1 ? `${n.lanes}台 ` : ""}勾配 ${slopeText(n.slope)}`;
357
+ if (!n || n.of === "direction" || n.of === "stair") break;
358
+ const text = `${n.lanes > 1 ? `${n.lanes} units ` : ""}slope ${slopeText(n.slope)}`;
223
359
  parts.push(
224
- `<text x="${sx(k.at!.x)}" y="${sy(k.at!.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171">${esc(text)}</text>`,
360
+ `<text class="run-note" x="${sx(k.at!.x)}" y="${sy(k.at!.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171" stroke="${PAPER}" stroke-width="3" paint-order="stroke">${esc(text)}</text>`,
225
361
  );
226
362
  break;
227
363
  }
228
364
  }
229
365
  }
230
366
 
231
- // 空間ラベル (最大の凸片の中心に置く)
367
+ // Place a space label at the centre of its largest convex piece.
232
368
  for (const s of rooms) {
369
+ if (stairSpaces.has(s.path)) continue;
233
370
  const space = model.spaces.get(s.path)!;
234
371
  const poly = [...s.outline].sort((a, b) => polyArea(b) - polyArea(a))[0]!;
235
372
  const r = polyBounds(poly);
@@ -246,7 +383,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
246
383
  );
247
384
  }
248
385
 
249
- // 切断面より上のものの投影 (上部吹抜け — 作図慣習)。空間ラベルの後に置く
386
+ // Projection from above the cut, including an upper void, drawn after space labels.
250
387
  for (const k of marks) {
251
388
  if (k.role !== "void-above") continue;
252
389
  parts.push(
@@ -255,19 +392,19 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
255
392
  );
256
393
  }
257
394
 
258
- // 北矢印 (ADR-0057) — azimuth が書かれているときだけ描く。**表現であって形ではない**ので
259
- // Form には無く、紙の座標に直接置く。これがある理由は装飾ではない — 方位の 180度違い・
260
- // 余角違い・磁北の書き写しは、どれも範囲内の整った数として通る。**絵だけが捕まえる。**
395
+ // North arrow (ADR-0057): drawn only when azimuth is written. It is presentation rather than
396
+ // shape, so it is placed directly in sheet coordinates instead of entering Form. The picture
397
+ // exposes a reversed bearing, a complementary angle or copied magnetic north.
261
398
  //
262
- // 画面上の北: モデルの +Y は上、+X は右。真方位角は +Y から時計回りなので、画面でも時計回り
399
+ // On screen model +Y is up and +X is right; true azimuth remains clockwise from +Y.
263
400
  if (model.azimuth) {
264
401
  const rad = (model.azimuth.deg * Math.PI) / 180;
265
402
  const nx = Math.sin(rad);
266
403
  const ny = -Math.cos(rad);
267
- const cx = W - M / 2; // 右余白の中央 (通り芯記号と同じ帯に、離して置く)
404
+ const cx = W - M / 2; // centre of the right margin, separated from the grid bubbles
268
405
  const cy = M / 2;
269
406
  const R = 21;
270
- const px = -ny; // 軸に直交する向き (矢羽根の底辺)
407
+ const px = -ny; // perpendicular direction for the arrowhead base
271
408
  const py = nx;
272
409
  const r2 = (n: number): string => String(Math.round(n * 100) / 100);
273
410
  const head = [
@@ -286,7 +423,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
286
423
  );
287
424
  }
288
425
 
289
- // 表題
426
+ // Sheet title.
290
427
  const title = `${model.name ?? "Untitled"} — ${level} plan`;
291
428
  parts.push(`<text x="${M - 62}" y="${H - 18}" font-size="12" fill="${INK}">${esc(title)}</text>`);
292
429
 
@@ -302,47 +439,76 @@ type Line = (
302
439
  ) => string;
303
440
 
304
441
  /**
305
- * 切断線 — 作図慣習の平行な二本の斜線。Form が持つのは「走りを横切る切断の位置」だけで、
306
- * 二本にすることも振り分けの寸法も、ここが決める見た目である
442
+ * Form supplies the segment crossing the flight. The renderer scales the supplied 10 by 40 break
443
+ * glyph to that width and rotates it 30 degrees as a paper convention.
307
444
  */
308
445
  function breakMark(g: { x1: number; y1: number; x2: number; y2: number }, line: Line): string[] {
446
+ const glyph = ARCHITECTURAL_PLAN_CONVENTION.stairs.breakGlyph;
309
447
  const dx = g.x2 - g.x1;
310
448
  const dy = g.y2 - g.y1;
311
449
  const width = Math.hypot(dx, dy) || 1;
312
- // 走る向き (切断線に直交する単位ベクトル)
450
+ const ax = dx / width;
451
+ const ay = dy / width;
313
452
  const tx = dy / width;
314
453
  const ty = -dx / width;
315
- const s = Math.min(300, width / 4);
316
- const off = Math.min(220, s);
317
- const at = (k: number, l: number) => ({
318
- x1: g.x1 + tx * (k),
319
- y1: g.y1 + ty * (k),
320
- x2: g.x2 + tx * (l),
321
- y2: g.y2 + ty * (l),
454
+ const cx = (g.x1 + g.x2) / 2;
455
+ const cy = (g.y1 + g.y2) / 2;
456
+ const angle = glyph.angleDegrees * Math.PI / 180;
457
+ const longX = ax * Math.cos(angle) + tx * Math.sin(angle);
458
+ const longY = ay * Math.cos(angle) + ty * Math.sin(angle);
459
+ const crossX = -ax * Math.sin(angle) + tx * Math.cos(angle);
460
+ const crossY = -ay * Math.sin(angle) + ty * Math.cos(angle);
461
+ const scale = width / (glyph.height * Math.cos(angle));
462
+ const point = (x: number, y: number) => ({
463
+ x: cx + (longX * y + crossX * x) * scale,
464
+ y: cy + (longY * y + crossY * x) * scale,
322
465
  });
323
- return [line(at(-s - off, s - off), INK, 1.4), line(at(-s + off, s + off), INK, 1.4)];
466
+ const halfHeight = glyph.height / 2;
467
+ // Exact geometry of the convention's break glyph, centred and rotated on the flight.
468
+ const paths = [
469
+ [point(0, -halfHeight), point(0, -glyph.notch), point(-glyph.notch, -glyph.notch), point(0, 0)],
470
+ [point(0, 0), point(glyph.notch, glyph.notch), point(0, glyph.notch), point(0, halfHeight)],
471
+ ];
472
+ return [
473
+ `<g class="run-break-zigzag">`,
474
+ ...paths.flatMap((points) =>
475
+ points.slice(0, -1).map((p, i) =>
476
+ line({ x1: p.x, y1: p.y, x2: points[i + 1]!.x, y2: points[i + 1]!.y }, INK, 1.35),
477
+ ),
478
+ ),
479
+ `</g>`,
480
+ ];
324
481
  }
325
482
 
326
- /** 矢印 — 三角の頭と "UP"/"DN" の言葉は、どちらも見た目である */
483
+ /** A light, open direction arrow. Its line already points where the presentation mark intends. */
327
484
  function arrow(
328
485
  k: Mark,
329
486
  line: Line,
330
487
  sx: (x: number) => number,
331
488
  sy: (y: number) => number,
332
489
  ): string[] {
333
- const g = k.lines?.[0];
334
- if (!g) return [];
335
- const dx = g.x2 - g.x1;
336
- const dy = g.y2 - g.y1;
337
- const len = Math.hypot(dx, dy) || 1;
338
- const hx = (dx / len) * 420;
339
- const hy = (dy / len) * 420;
340
- const px = (-dy / len) * 200;
341
- const py = (dx / len) * 200;
490
+ const lines = k.lines ?? [];
491
+ const first = lines[0];
492
+ const g = lines[lines.length - 1];
493
+ if (!first || !g) return [];
494
+ // The head is paper-sized, not a dimension of the building. Keeping it in SVG coordinates
495
+ // makes the same stair legible on a compact house and a large floor plate.
496
+ const screenLen = Math.hypot(sx(g.x2) - sx(g.x1), sy(g.y2) - sy(g.y1)) || 1;
497
+ const vx = (sx(g.x2) - sx(g.x1)) / screenLen;
498
+ const vy = (sy(g.y2) - sy(g.y1)) / screenLen;
499
+ const px = -vy;
500
+ const py = vx;
501
+ const head = ARCHITECTURAL_PLAN_CONVENTION.stairs.arrowHead;
502
+ const tip = { x: sx(g.x2), y: sy(g.y2) };
503
+ const back = { x: tip.x - vx * head.length, y: tip.y - vy * head.length };
342
504
  return [
343
- line(g, INK, 1),
344
- `<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}"/>`,
345
- `<text x="${sx(g.x1) + 4}" y="${sy(g.y1) + 4}" font-size="9" fill="${INK}">${k.note?.of === "direction" && k.note.up ? "UP" : "DN"}</text>`,
505
+ `<g class="run-direction-arrow">`,
506
+ ...lines.map((segment) => line(segment, INK, 0.8)),
507
+ ...(k.class === "below"
508
+ ? []
509
+ : [`<circle class="run-direction-arrow-start" cx="${sx(first.x1)}" cy="${sy(first.y1)}" r="${head.startRadius}" fill="${PAPER}" stroke="${INK}" stroke-width="0.8"/>`]),
510
+ `<path class="run-direction-arrow-head" d="M ${back.x + px * head.halfWidth} ${back.y + py * head.halfWidth} L ${tip.x} ${tip.y} L ${back.x - px * head.halfWidth} ${back.y - py * head.halfWidth}" fill="none" stroke="${INK}" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"/>`,
511
+ `</g>`,
346
512
  ];
347
513
  }
348
514
 
@@ -355,4 +521,3 @@ function polyArea(poly: Pt[]): number {
355
521
  }
356
522
  return Math.abs(s / 2);
357
523
  }
358
-
package/src/form.ts CHANGED
@@ -20,6 +20,7 @@ export {
20
20
  type Form,
21
21
  type FormBoundary,
22
22
  type FormColumn,
23
+ type FormComponent,
23
24
  type FormInput,
24
25
  type FormLevel,
25
26
  type FormOpening,
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  //
16
16
  // root is browser-safe: nothing reachable from here pulls a Node builtin.
17
17
  //
18
- // The twelve entry points:
18
+ // The public entry points:
19
19
  //
20
20
  // @kensnzk/koyu this file — compose, check, canonicalise
21
21
  // @kensnzk/koyu/model Model, and the questions the model answers alone
package/src/mcp.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  SUPPORTED_LANGUAGE_VERSIONS,
20
20
  } from "./core/model.js";
21
21
  import { axisOf } from "./core/section.js";
22
+ import { placedComponents } from "./core/components.js";
22
23
  import { check } from "./core/diagnose.js";
23
24
  import { siteReport } from "./core/site.js";
24
25
  import { assess } from "./validate/assessment.js";
@@ -41,7 +42,7 @@ import {
41
42
  type Model,
42
43
  type Space,
43
44
  } from "./model.js";
44
- import { parseFile, parseFileWith } from "./parse-file.js";
45
+ import { componentSvgFiles, parseFile, parseFileWith } from "./parse-file.js";
45
46
 
46
47
  // ---- モデルの読み込みと要約 ----
47
48
 
@@ -109,6 +110,7 @@ function summarize(model: Model, file: string, by: readonly string[] = []): unkn
109
110
  byM2[key] = bucket;
110
111
  }
111
112
  const r = check(model);
113
+ const components = placedComponents(model).components;
112
114
  return {
113
115
  name: model.name,
114
116
  unit: model.unit,
@@ -134,6 +136,18 @@ function summarize(model: Model, file: string, by: readonly string[] = []): unkn
134
136
  };
135
137
  }),
136
138
  assets: [...model.assets.values()].map((a) => ({ name: a.name, kind: a.kind, attrs: a.attrs })),
139
+ ...(components.length > 0
140
+ ? {
141
+ componentPlacements: components.map((component) => ({
142
+ space: component.space,
143
+ area: component.area,
144
+ asset: component.asset,
145
+ level: component.level,
146
+ centre: component.centre,
147
+ rotation: component.rotation,
148
+ })),
149
+ }
150
+ : {}),
137
151
  ...(model.polygons.size
138
152
  ? { sitePolygons: [...model.polygons.keys()] }
139
153
  : {}),
@@ -222,7 +236,7 @@ const keys = (v: unknown, name: string): string[] => {
222
236
  const TOOLS: Record<string, Tool> = {
223
237
  model_summary: {
224
238
  description:
225
- "Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first. Pass by:[\"lease.category\"] to also get floor area grouped by those attribute keys",
239
+ "Summary of the building: name, levels, layer composition, zones, reusable assets, placed components, areas, and check counts. Call this first. Pass by:[\"lease.category\"] to also get floor area grouped by those attribute keys",
226
240
  schema: {
227
241
  type: "object",
228
242
  properties: {
@@ -444,7 +458,11 @@ const TOOLS: Record<string, Tool> = {
444
458
  properties: { ...FILE_PROP, level: { type: "string", description: "Level name (e.g. L5)" } },
445
459
  required: ["file", "level"],
446
460
  },
447
- run: (a) => svgPlan(load(str(a.file, "file")), { level: str(a.level, "level") }),
461
+ run: (a) => {
462
+ const model = load(str(a.file, "file"));
463
+ const level = str(a.level, "level");
464
+ return svgPlan(model, { level, componentSvgs: componentSvgFiles(model, level) });
465
+ },
448
466
  },
449
467
  section_svg: {
450
468
  description:
package/src/parse-file.ts CHANGED
@@ -6,6 +6,7 @@ import { readFileSync, realpathSync } from "node:fs";
6
6
  import { dirname, resolve } from "node:path";
7
7
  import type { Model } from "./core/model.js";
8
8
  import { parseWith } from "./core/parse.js";
9
+ export { componentSvgFiles } from "./draw/component-files.js";
9
10
 
10
11
  /** ファイルから読む。import は書かれたファイルからの相対で解決される */
11
12
  export function parseFile(filePath: string): Model {