@kensnzk/koyu 0.27.0 → 0.29.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 (167) hide show
  1. package/README.ja.md +1 -1
  2. package/README.md +1 -1
  3. package/assets/plan/README.md +18 -0
  4. package/assets/plan/catalog.muro +87 -0
  5. package/assets/plan/library.muro +26 -0
  6. package/assets/plan/svg/bathtub.svg +9 -0
  7. package/assets/plan/svg/bed-double.svg +9 -0
  8. package/assets/plan/svg/bed-single.svg +8 -0
  9. package/assets/plan/svg/cabinet.svg +9 -0
  10. package/assets/plan/svg/chair.svg +8 -0
  11. package/assets/plan/svg/desk.svg +9 -0
  12. package/assets/plan/svg/hedge-2m.svg +7 -0
  13. package/assets/plan/svg/kitchen-sink.svg +10 -0
  14. package/assets/plan/svg/locker.svg +9 -0
  15. package/assets/plan/svg/office-chair.svg +25 -0
  16. package/assets/plan/svg/potted-plant.svg +14 -0
  17. package/assets/plan/svg/refrigerator.svg +10 -0
  18. package/assets/plan/svg/shelf.svg +9 -0
  19. package/assets/plan/svg/shrub-1m.svg +7 -0
  20. package/assets/plan/svg/sofa-2.svg +9 -0
  21. package/assets/plan/svg/sofa-3.svg +9 -0
  22. package/assets/plan/svg/table-rect.svg +7 -0
  23. package/assets/plan/svg/table-round.svg +7 -0
  24. package/assets/plan/svg/tree-3m.svg +8 -0
  25. package/assets/plan/svg/urinal.svg +9 -0
  26. package/assets/plan/svg/washing-machine-pan.svg +13 -0
  27. package/assets/plan/svg/washing-machine.svg +10 -0
  28. package/assets/plan/svg/washstand-500.svg +12 -0
  29. package/assets/plan/svg/washstand.svg +12 -0
  30. package/assets/plan/svg/wc-cabinet.svg +14 -0
  31. package/assets/plan/svg/wc.svg +9 -0
  32. package/dist/analysis/contracts.d.ts +1 -0
  33. package/dist/analysis/contracts.d.ts.map +1 -1
  34. package/dist/cli.js +16 -4
  35. package/dist/cli.js.map +1 -1
  36. package/dist/core/components.d.ts +31 -0
  37. package/dist/core/components.d.ts.map +1 -0
  38. package/dist/core/components.js +167 -0
  39. package/dist/core/components.js.map +1 -0
  40. package/dist/core/derive.d.ts +13 -2
  41. package/dist/core/derive.d.ts.map +1 -1
  42. package/dist/core/derive.js +36 -5
  43. package/dist/core/derive.js.map +1 -1
  44. package/dist/core/diagnose.d.ts +7 -0
  45. package/dist/core/diagnose.d.ts.map +1 -1
  46. package/dist/core/diagnose.js +141 -5
  47. package/dist/core/diagnose.js.map +1 -1
  48. package/dist/core/diff.d.ts +4 -0
  49. package/dist/core/diff.d.ts.map +1 -1
  50. package/dist/core/diff.js +4 -0
  51. package/dist/core/diff.js.map +1 -1
  52. package/dist/core/fabric.js +1 -1
  53. package/dist/core/fabric.js.map +1 -1
  54. package/dist/core/graph.d.ts +8 -0
  55. package/dist/core/graph.d.ts.map +1 -1
  56. package/dist/core/graph.js +31 -1
  57. package/dist/core/graph.js.map +1 -1
  58. package/dist/core/light.d.ts.map +1 -1
  59. package/dist/core/light.js +2 -0
  60. package/dist/core/light.js.map +1 -1
  61. package/dist/core/model.d.ts +20 -14
  62. package/dist/core/model.d.ts.map +1 -1
  63. package/dist/core/model.js +15 -8
  64. package/dist/core/model.js.map +1 -1
  65. package/dist/core/parse.d.ts.map +1 -1
  66. package/dist/core/parse.js +23 -4
  67. package/dist/core/parse.js.map +1 -1
  68. package/dist/core/vocabulary.d.ts +20 -4
  69. package/dist/core/vocabulary.d.ts.map +1 -1
  70. package/dist/core/vocabulary.js +107 -9
  71. package/dist/core/vocabulary.js.map +1 -1
  72. package/dist/draw/component-files.d.ts +8 -0
  73. package/dist/draw/component-files.d.ts.map +1 -0
  74. package/dist/draw/component-files.js +35 -0
  75. package/dist/draw/component-files.js.map +1 -0
  76. package/dist/draw/component-svg.d.ts +14 -0
  77. package/dist/draw/component-svg.d.ts.map +1 -0
  78. package/dist/draw/component-svg.js +67 -0
  79. package/dist/draw/component-svg.js.map +1 -0
  80. package/dist/draw/conventions/architectural.d.ts +32 -0
  81. package/dist/draw/conventions/architectural.d.ts.map +1 -0
  82. package/dist/draw/conventions/architectural.js +29 -0
  83. package/dist/draw/conventions/architectural.js.map +1 -0
  84. package/dist/draw/index.d.ts +1 -1
  85. package/dist/draw/index.d.ts.map +1 -1
  86. package/dist/draw/index.js +1 -1
  87. package/dist/draw/index.js.map +1 -1
  88. package/dist/draw/marks.d.ts +37 -12
  89. package/dist/draw/marks.d.ts.map +1 -1
  90. package/dist/draw/marks.js +508 -38
  91. package/dist/draw/marks.js.map +1 -1
  92. package/dist/draw/plan.d.ts +3 -1
  93. package/dist/draw/plan.d.ts.map +1 -1
  94. package/dist/draw/plan.js +257 -86
  95. package/dist/draw/plan.js.map +1 -1
  96. package/dist/form.d.ts +1 -1
  97. package/dist/form.d.ts.map +1 -1
  98. package/dist/form.js.map +1 -1
  99. package/dist/index.js +1 -1
  100. package/dist/mcp.js +22 -3
  101. package/dist/mcp.js.map +1 -1
  102. package/dist/parse-file.d.ts +1 -0
  103. package/dist/parse-file.d.ts.map +1 -1
  104. package/dist/parse-file.js +1 -0
  105. package/dist/parse-file.js.map +1 -1
  106. package/dist/validate/assessment.js +13 -2
  107. package/dist/validate/assessment.js.map +1 -1
  108. package/dist/validate/builtin/index.d.ts +4 -2
  109. package/dist/validate/builtin/index.d.ts.map +1 -1
  110. package/dist/validate/builtin/index.js +9 -2
  111. package/dist/validate/builtin/index.js.map +1 -1
  112. package/dist/validate/builtin/opening-operations.d.ts +63 -0
  113. package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
  114. package/dist/validate/builtin/opening-operations.js +406 -0
  115. package/dist/validate/builtin/opening-operations.js.map +1 -0
  116. package/dist/validate/contracts.d.ts +1 -0
  117. package/dist/validate/contracts.d.ts.map +1 -1
  118. package/dist/validate/contracts.js.map +1 -1
  119. package/editors/vscode/syntaxes/koyu.tmLanguage.json +4 -4
  120. package/examples/basement/main.muro +3 -3
  121. package/examples/complex/L1.muro +1 -1
  122. package/examples/complex/assets.muro +2 -2
  123. package/examples/complex/main.muro +1 -1
  124. package/examples/house/L1.muro +3 -3
  125. package/examples/house/L2.muro +2 -2
  126. package/examples/house/assets.muro +8 -8
  127. package/examples/house/main.muro +1 -1
  128. package/examples/house/site.muro +2 -2
  129. package/examples/house.muro +6 -6
  130. package/examples/mansion.muro +1 -1
  131. package/examples/office.muro +1 -1
  132. package/examples/spatial/layout.muro +8 -0
  133. package/examples/spatial/main.muro +4 -0
  134. package/examples/steps/06-finished.muro +1 -1
  135. package/examples/tower/assets.muro +1 -1
  136. package/examples/tower/main.muro +1 -1
  137. package/examples/twin/assets.muro +2 -2
  138. package/examples/twin/main.muro +1 -1
  139. package/examples/two-rooms.canonical.json +1 -1
  140. package/examples/two-rooms.muro +1 -1
  141. package/package.json +9 -5
  142. package/src/analysis/contracts.ts +1 -0
  143. package/src/cli.ts +15 -4
  144. package/src/core/components.ts +224 -0
  145. package/src/core/derive.ts +53 -6
  146. package/src/core/diagnose.ts +185 -5
  147. package/src/core/diff.ts +3 -0
  148. package/src/core/fabric.ts +1 -1
  149. package/src/core/graph.ts +32 -0
  150. package/src/core/light.ts +1 -0
  151. package/src/core/model.ts +23 -13
  152. package/src/core/parse.ts +21 -4
  153. package/src/core/vocabulary.ts +115 -9
  154. package/src/draw/component-files.ts +36 -0
  155. package/src/draw/component-svg.ts +79 -0
  156. package/src/draw/conventions/architectural.ts +60 -0
  157. package/src/draw/index.ts +1 -1
  158. package/src/draw/marks.ts +564 -44
  159. package/src/draw/plan.ts +262 -89
  160. package/src/form.ts +1 -0
  161. package/src/index.ts +1 -1
  162. package/src/mcp.ts +22 -3
  163. package/src/parse-file.ts +1 -0
  164. package/src/validate/assessment.ts +17 -3
  165. package/src/validate/builtin/index.ts +14 -2
  166. package/src/validate/builtin/opening-operations.ts +519 -0
  167. package/src/validate/contracts.ts +1 -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,25 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
94
97
  }
95
98
  }
96
99
 
97
- // 数えない分節 (area): 床材の切替など。書かれた与件をそのまま引く — 導出ではない
100
+ if (form.mode === "spatial") {
101
+ parts.push(`<desc>Spatial model: dashed faces are unresolved; circulation, daylight and egress are not evaluated.</desc>`);
102
+ for (const face of form.unresolved ?? []) {
103
+ if (face.level === level) parts.push(`<g data-unresolved="true">${line(face.segment, FAINT, 1, "6 4")}</g>`);
104
+ }
105
+ }
106
+
107
+ // Uncounted area subdivisions, such as a floor-finish change, reproduce the written input.
98
108
  for (const s of modelRooms) {
99
109
  for (const a of s.areas) {
100
110
  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"]]
111
+ const componentHost = a.attrs["asset"] !== undefined;
112
+ const visibleSubdivision = a.attrs["floor"] !== undefined || a.attrs["spec"] !== undefined;
113
+ if (!componentHost || visibleSubdivision) {
114
+ parts.push(
115
+ `<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"/>`,
116
+ );
117
+ }
118
+ const label = [componentHost ? undefined : a.attrs["name"], a.attrs["floor"]]
105
119
  .filter((v): v is string => typeof v === "string")
106
120
  .join(" · ");
107
121
  if (label) {
@@ -112,7 +126,29 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
112
126
  }
113
127
  }
114
128
 
115
- // 通り芯 (与件)
129
+ // Components are below cut matter and room labels. The source SVG remains isolated as an image,
130
+ // preserving its defs and IDs while the Form supplies all placement geometry.
131
+ for (const component of form.components ?? []) {
132
+ if (component.level !== level) continue;
133
+ const asset = model.assets.get(component.asset);
134
+ if (!asset || asset.kind !== "component") continue;
135
+ const source = opts.componentSvgs?.[asset.name];
136
+ if (!source) {
137
+ throw new Error(
138
+ `Component asset ${asset.name} has no plan SVG bytes; pass PlanOptions.componentSvgs`,
139
+ );
140
+ }
141
+ const artwork = componentSvg(asset, source);
142
+ const cx = sx(component.centre.x);
143
+ const cy = sy(component.centre.y);
144
+ const width = component.w * scale;
145
+ const height = component.d * scale;
146
+ parts.push(
147
+ `<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})"/>`,
148
+ );
149
+ }
150
+
151
+ // Written grid axes.
116
152
  for (const [i, x] of model.grid.X.coords.entries()) {
117
153
  if (x < minX - 1 || x > maxX + 1) continue;
118
154
  parts.push(
@@ -130,15 +166,34 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
130
166
  );
131
167
  }
132
168
 
133
- // 印 — 形の写しは `planMarks` にある。**この頁が足すのは色・線幅・線種・記号・注記の言葉だけ**
134
- // である。ugatsu も architype も同じ印から別の見た目を引く。
169
+ // Marks copy Form geometry. This page adds only colour, weight, dash, glyph and wording; another
170
+ // consumer can render the same marks differently.
135
171
  const marks = planMarks(form, level);
136
172
  const written = writtenOf(model);
137
173
  const segByRef = new Map(form.segs.map((g) => [g.ref, g]));
174
+ // A generic room label over a stair repeats what the treads already say and obscures the arrow.
175
+ // Seed the set from actual stair runs, then follow only vertical boundaries connected to them so
176
+ // ramps, escalators and lift shafts keep their existing labels.
177
+ const stairSpaces = new Set(form.runs.filter((r) => r.device === "stair").map((r) => r.path));
178
+ let grew = true;
179
+ while (grew) {
180
+ grew = false;
181
+ for (const b of model.boundaries) {
182
+ if (b.kind !== "stair" || (!stairSpaces.has(b.a) && !stairSpaces.has(b.b))) continue;
183
+ if (!stairSpaces.has(b.a)) {
184
+ stairSpaces.add(b.a);
185
+ grew = true;
186
+ }
187
+ if (!stairSpaces.has(b.b)) {
188
+ stairSpaces.add(b.b);
189
+ grew = true;
190
+ }
191
+ }
192
+ }
138
193
  for (const k of marks) {
139
194
  switch (k.role) {
140
- // 空間の面と分節の帯は下 (`rooms` / `form.segs`) から引く — 切られた面ではなく外形を塗り、
141
- // 分節には Form しか持たない座と向きが要るため。上部吹抜けは空間ラベルより後ろに置く
195
+ // Space faces and subdivision bands are rendered from their full outlines elsewhere. Upper
196
+ // void projections are deliberately placed behind space labels.
142
197
  case "space":
143
198
  case "space-semi-outdoor":
144
199
  case "space-outdoor":
@@ -146,10 +201,9 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
146
201
  case "void-hatch":
147
202
  case "void-above":
148
203
  break;
149
- // 数えない分節 (seg): 壁材が途中から変わる区間 — 色調を変えて示す。
150
- // ここから引くのは注記の言葉 (`spec`) だけで、それは形ではないので Form には載らない。
151
- // **`written.boundary` は正準順の添字である** — 宣言順の配列を引くと、並べ替えただけで
152
- // 注記が別の境界のものになる
204
+ // An uncounted segment can mark a wall specification change. Only the annotation wording is
205
+ // recovered from the source. `written.boundary` indexes canonical order, never declaration
206
+ // order, so a harmless source reorder cannot move the note to another boundary.
153
207
  case "seg": {
154
208
  parts.push(fill(k.polygon!, "#77716a"));
155
209
  const spec = written.segSpec(k.written!.boundary, k.written!.index!);
@@ -162,43 +216,135 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
162
216
  }
163
217
  break;
164
218
  }
165
- // 物を持たない境界 (open): 構成の線として破線で示す (基本計画の抽象度)
219
+ // A boundary with no matter remains legible as a light dashed relation.
166
220
  case "open":
167
221
  for (const g of k.lines ?? []) parts.push(line(g, FAINT, 1, "6 4"));
168
222
  break;
169
- // 遮蔽しない物 (手すり・柵): 細実線 — 「囲われていない」ことが図から読めるように。
170
- // **芯線は Form が持つ** — 足あとの四辺形から復元しない
223
+ // A rail stays lighter than a wall, while the endpoint posts keep a short rail from reading
224
+ // as an accidental construction line. The axis itself comes from Form; the circles are a
225
+ // paper convention and add no building geometry.
171
226
  case "rail":
172
- for (const g of k.lines ?? []) parts.push(line(g, INK, 1.4));
227
+ parts.push(`<g class="boundary-rail">`);
228
+ for (const g of k.lines ?? []) {
229
+ parts.push(line(g, INK, 1.1));
230
+ parts.push(
231
+ `<circle class="boundary-rail-post" cx="${sx(g.x1)}" cy="${sy(g.y1)}" r="1.45" fill="${INK}"/>`,
232
+ `<circle class="boundary-rail-post" cx="${sx(g.x2)}" cy="${sy(g.y2)}" r="1.45" fill="${INK}"/>`,
233
+ );
234
+ }
235
+ parts.push(`</g>`);
173
236
  break;
174
- // 切断面が切った区間と柱を黒帯にする。腰壁は開口の下なので印にならない —
175
- // **これが「欠き取り」の代わりである**。紙の色で塗り潰す操作はもう無い
237
+ // Only intervals and columns cut by the plane become black bodies. Sill walls lie below the
238
+ // cut; no paper-coloured mask is needed to erase openings.
176
239
  case "wall":
177
240
  case "column":
178
241
  parts.push(fill(k.polygon!, INK));
179
242
  break;
180
- // 引戸・自動ドア: 開き軌跡ではなく吊元側の控え (戸袋側) にパネルを描く
243
+ // A sliding leaf has no swing trace. Its solid line closes the opening; the thin dashed
244
+ // continuation says which way it retracts without turning the opening into a box.
181
245
  case "slide-panel":
182
- for (const g of k.lines ?? []) parts.push(line(g, INK, 2));
246
+ parts.push(`<g class="opening-slide-panel">`);
247
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 1.2));
248
+ parts.push(`</g>`);
183
249
  break;
184
- case "slide-tail":
250
+ case "slide-centre":
251
+ parts.push(`<g class="opening-slide-centre">`);
185
252
  for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
253
+ parts.push(`</g>`);
254
+ break;
255
+ case "slide-tail":
256
+ parts.push(`<g class="opening-slide-guide">`);
257
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65, "5 3"));
258
+ parts.push(`</g>`);
259
+ break;
260
+ case "auto-direction":
261
+ parts.push(`<g class="opening-auto-direction">`);
262
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65));
263
+ parts.push(`</g>`);
264
+ break;
265
+ case "entrance":
266
+ parts.push(`<g class="opening-entrance">`);
267
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.75));
268
+ parts.push(`</g>`);
269
+ break;
270
+ case "gate-post":
271
+ parts.push(`<g class="opening-gate-post">`);
272
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 2));
273
+ parts.push(`</g>`);
274
+ break;
275
+ case "rolling-shutter":
276
+ parts.push(`<g class="opening-rolling-shutter">`);
277
+ for (const g of k.lines ?? []) {
278
+ parts.push(line(g, INK, 1));
279
+ parts.push(
280
+ `<rect x="${sx(g.x1) - 1.5}" y="${sy(g.y1) - 1.5}" width="3" height="3" fill="${INK}"/>`,
281
+ `<rect x="${sx(g.x2) - 1.5}" y="${sy(g.y2) - 1.5}" width="3" height="3" fill="${INK}"/>`,
282
+ );
283
+ }
284
+ parts.push(`</g>`);
285
+ break;
286
+ case "overhead-door":
287
+ parts.push(`<g class="opening-overhead-door">`);
288
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1, "2 1"));
289
+ parts.push(`</g>`);
186
290
  break;
187
291
  case "door-leaf":
188
- for (const g of k.lines ?? []) parts.push(line(g, INK, 1.4));
292
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1));
293
+ break;
294
+ case "window-leaf":
295
+ parts.push(`<g class="opening-window-leaf">`);
296
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.8));
297
+ parts.push(`</g>`);
189
298
  break;
190
- case "door-arc": {
299
+ case "door-arc":
300
+ case "window-arc": {
191
301
  const a = k.arc!;
192
302
  const r = a.r * scale;
193
- // 掃引方向: 世界の反時計回りは、y を反転した紙の上では時計回りになる
303
+ // World counter-clockwise becomes clockwise after the SVG y-axis is inverted.
194
304
  const sweep = a.ccw ? 0 : 1;
305
+ const window = k.role === "window-arc";
195
306
  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"/>`,
307
+ `<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
308
  );
198
309
  break;
199
310
  }
200
- case "window":
201
- for (const g of k.lines ?? []) parts.push(line(g, INK, 1));
311
+ case "window": {
312
+ const cut = k.class === "cut";
313
+ const stroke = cut ? INK : FAINT;
314
+ const dash = cut ? "" : "5 3";
315
+ parts.push(`<g class="opening-window">`);
316
+ if (k.polygon && k.polygon.length >= 4) {
317
+ const p = k.polygon;
318
+ // A window continues the two faces of the wall as unfilled lines. Closing this path
319
+ // would add jamb caps and turn the window back into a boxed door opening.
320
+ parts.push(
321
+ `<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}"` : ""}/>`,
322
+ );
323
+ } else {
324
+ for (const g of k.lines ?? []) parts.push(line(g, stroke, 0.55, dash));
325
+ }
326
+ parts.push(`</g>`);
327
+ break;
328
+ }
329
+ case "window-sash":
330
+ parts.push(`<g class="opening-window-sash">`);
331
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
332
+ parts.push(`</g>`);
333
+ break;
334
+ case "window-fixed":
335
+ parts.push(`<g class="opening-window-fixed">`);
336
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65));
337
+ parts.push(`</g>`);
338
+ break;
339
+ case "curtain-wall-mullion":
340
+ parts.push(`<g class="opening-curtain-wall-mullion">`);
341
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.55));
342
+ parts.push(`</g>`);
343
+ break;
344
+ case "window-sash-centre":
345
+ parts.push(`<g class="opening-window-sash-centre">`);
346
+ for (const g of k.lines ?? []) parts.push(line(g, INK, 0.55));
347
+ parts.push(`</g>`);
202
348
  break;
203
349
  case "run-outline":
204
350
  for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1));
@@ -212,24 +358,22 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
212
358
  case "run-arrow":
213
359
  parts.push(...arrow(k, line, sx, sy));
214
360
  break;
215
- // 注記の言葉と丸めはここで初めて生まれる — 印が運ぶのは丸めない事実だけである
361
+ // Wording and rounding begin here; the mark carries only unrounded facts.
216
362
  case "run-note": {
217
363
  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)}`;
364
+ if (!n || n.of === "direction" || n.of === "stair") break;
365
+ const text = `${n.lanes > 1 ? `${n.lanes} units ` : ""}slope ${slopeText(n.slope)}`;
223
366
  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>`,
367
+ `<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
368
  );
226
369
  break;
227
370
  }
228
371
  }
229
372
  }
230
373
 
231
- // 空間ラベル (最大の凸片の中心に置く)
374
+ // Place a space label at the centre of its largest convex piece.
232
375
  for (const s of rooms) {
376
+ if (stairSpaces.has(s.path)) continue;
233
377
  const space = model.spaces.get(s.path)!;
234
378
  const poly = [...s.outline].sort((a, b) => polyArea(b) - polyArea(a))[0]!;
235
379
  const r = polyBounds(poly);
@@ -246,7 +390,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
246
390
  );
247
391
  }
248
392
 
249
- // 切断面より上のものの投影 (上部吹抜け — 作図慣習)。空間ラベルの後に置く
393
+ // Projection from above the cut, including an upper void, drawn after space labels.
250
394
  for (const k of marks) {
251
395
  if (k.role !== "void-above") continue;
252
396
  parts.push(
@@ -255,19 +399,19 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
255
399
  );
256
400
  }
257
401
 
258
- // 北矢印 (ADR-0057) — azimuth が書かれているときだけ描く。**表現であって形ではない**ので
259
- // Form には無く、紙の座標に直接置く。これがある理由は装飾ではない — 方位の 180度違い・
260
- // 余角違い・磁北の書き写しは、どれも範囲内の整った数として通る。**絵だけが捕まえる。**
402
+ // North arrow (ADR-0057): drawn only when azimuth is written. It is presentation rather than
403
+ // shape, so it is placed directly in sheet coordinates instead of entering Form. The picture
404
+ // exposes a reversed bearing, a complementary angle or copied magnetic north.
261
405
  //
262
- // 画面上の北: モデルの +Y は上、+X は右。真方位角は +Y から時計回りなので、画面でも時計回り
406
+ // On screen model +Y is up and +X is right; true azimuth remains clockwise from +Y.
263
407
  if (model.azimuth) {
264
408
  const rad = (model.azimuth.deg * Math.PI) / 180;
265
409
  const nx = Math.sin(rad);
266
410
  const ny = -Math.cos(rad);
267
- const cx = W - M / 2; // 右余白の中央 (通り芯記号と同じ帯に、離して置く)
411
+ const cx = W - M / 2; // centre of the right margin, separated from the grid bubbles
268
412
  const cy = M / 2;
269
413
  const R = 21;
270
- const px = -ny; // 軸に直交する向き (矢羽根の底辺)
414
+ const px = -ny; // perpendicular direction for the arrowhead base
271
415
  const py = nx;
272
416
  const r2 = (n: number): string => String(Math.round(n * 100) / 100);
273
417
  const head = [
@@ -286,8 +430,9 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
286
430
  );
287
431
  }
288
432
 
289
- // 表題
290
- const title = `${model.name ?? "Untitled"} — ${level} plan`;
433
+ // Sheet title.
434
+ const title = `${model.name ?? "Untitled"} — ${level} ${model.mode === "spatial" ? "spatial plan" : "plan"}`;
435
+ if (model.mode === "spatial") parts.push(`<text x="${M - 62}" y="${H - 38}" font-size="9" fill="${FAINT}">Dashed: unresolved boundary</text>`);
291
436
  parts.push(`<text x="${M - 62}" y="${H - 18}" font-size="12" fill="${INK}">${esc(title)}</text>`);
292
437
 
293
438
  parts.push("</svg>");
@@ -302,47 +447,76 @@ type Line = (
302
447
  ) => string;
303
448
 
304
449
  /**
305
- * 切断線 — 作図慣習の平行な二本の斜線。Form が持つのは「走りを横切る切断の位置」だけで、
306
- * 二本にすることも振り分けの寸法も、ここが決める見た目である
450
+ * Form supplies the segment crossing the flight. The renderer scales the supplied 10 by 40 break
451
+ * glyph to that width and rotates it 30 degrees as a paper convention.
307
452
  */
308
453
  function breakMark(g: { x1: number; y1: number; x2: number; y2: number }, line: Line): string[] {
454
+ const glyph = ARCHITECTURAL_PLAN_CONVENTION.stairs.breakGlyph;
309
455
  const dx = g.x2 - g.x1;
310
456
  const dy = g.y2 - g.y1;
311
457
  const width = Math.hypot(dx, dy) || 1;
312
- // 走る向き (切断線に直交する単位ベクトル)
458
+ const ax = dx / width;
459
+ const ay = dy / width;
313
460
  const tx = dy / width;
314
461
  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),
462
+ const cx = (g.x1 + g.x2) / 2;
463
+ const cy = (g.y1 + g.y2) / 2;
464
+ const angle = glyph.angleDegrees * Math.PI / 180;
465
+ const longX = ax * Math.cos(angle) + tx * Math.sin(angle);
466
+ const longY = ay * Math.cos(angle) + ty * Math.sin(angle);
467
+ const crossX = -ax * Math.sin(angle) + tx * Math.cos(angle);
468
+ const crossY = -ay * Math.sin(angle) + ty * Math.cos(angle);
469
+ const scale = width / (glyph.height * Math.cos(angle));
470
+ const point = (x: number, y: number) => ({
471
+ x: cx + (longX * y + crossX * x) * scale,
472
+ y: cy + (longY * y + crossY * x) * scale,
322
473
  });
323
- return [line(at(-s - off, s - off), INK, 1.4), line(at(-s + off, s + off), INK, 1.4)];
474
+ const halfHeight = glyph.height / 2;
475
+ // Exact geometry of the convention's break glyph, centred and rotated on the flight.
476
+ const paths = [
477
+ [point(0, -halfHeight), point(0, -glyph.notch), point(-glyph.notch, -glyph.notch), point(0, 0)],
478
+ [point(0, 0), point(glyph.notch, glyph.notch), point(0, glyph.notch), point(0, halfHeight)],
479
+ ];
480
+ return [
481
+ `<g class="run-break-zigzag">`,
482
+ ...paths.flatMap((points) =>
483
+ points.slice(0, -1).map((p, i) =>
484
+ line({ x1: p.x, y1: p.y, x2: points[i + 1]!.x, y2: points[i + 1]!.y }, INK, 1.35),
485
+ ),
486
+ ),
487
+ `</g>`,
488
+ ];
324
489
  }
325
490
 
326
- /** 矢印 — 三角の頭と "UP"/"DN" の言葉は、どちらも見た目である */
491
+ /** A light, open direction arrow. Its line already points where the presentation mark intends. */
327
492
  function arrow(
328
493
  k: Mark,
329
494
  line: Line,
330
495
  sx: (x: number) => number,
331
496
  sy: (y: number) => number,
332
497
  ): 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;
498
+ const lines = k.lines ?? [];
499
+ const first = lines[0];
500
+ const g = lines[lines.length - 1];
501
+ if (!first || !g) return [];
502
+ // The head is paper-sized, not a dimension of the building. Keeping it in SVG coordinates
503
+ // makes the same stair legible on a compact house and a large floor plate.
504
+ const screenLen = Math.hypot(sx(g.x2) - sx(g.x1), sy(g.y2) - sy(g.y1)) || 1;
505
+ const vx = (sx(g.x2) - sx(g.x1)) / screenLen;
506
+ const vy = (sy(g.y2) - sy(g.y1)) / screenLen;
507
+ const px = -vy;
508
+ const py = vx;
509
+ const head = ARCHITECTURAL_PLAN_CONVENTION.stairs.arrowHead;
510
+ const tip = { x: sx(g.x2), y: sy(g.y2) };
511
+ const back = { x: tip.x - vx * head.length, y: tip.y - vy * head.length };
342
512
  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>`,
513
+ `<g class="run-direction-arrow">`,
514
+ ...lines.map((segment) => line(segment, INK, 0.8)),
515
+ ...(k.class === "below"
516
+ ? []
517
+ : [`<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"/>`]),
518
+ `<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"/>`,
519
+ `</g>`,
346
520
  ];
347
521
  }
348
522
 
@@ -355,4 +529,3 @@ function polyArea(poly: Pt[]): number {
355
529
  }
356
530
  return Math.abs(s / 2);
357
531
  }
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,8 +110,10 @@ 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,
116
+ ...(model.mode ? { mode: model.mode } : {}),
114
117
  unit: model.unit,
115
118
  layers: layerFiles(model),
116
119
  levels: levelsSorted(model).map((l) => ({
@@ -134,6 +137,18 @@ function summarize(model: Model, file: string, by: readonly string[] = []): unkn
134
137
  };
135
138
  }),
136
139
  assets: [...model.assets.values()].map((a) => ({ name: a.name, kind: a.kind, attrs: a.attrs })),
140
+ ...(components.length > 0
141
+ ? {
142
+ componentPlacements: components.map((component) => ({
143
+ space: component.space,
144
+ area: component.area,
145
+ asset: component.asset,
146
+ level: component.level,
147
+ centre: component.centre,
148
+ rotation: component.rotation,
149
+ })),
150
+ }
151
+ : {}),
137
152
  ...(model.polygons.size
138
153
  ? { sitePolygons: [...model.polygons.keys()] }
139
154
  : {}),
@@ -222,7 +237,7 @@ const keys = (v: unknown, name: string): string[] => {
222
237
  const TOOLS: Record<string, Tool> = {
223
238
  model_summary: {
224
239
  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",
240
+ "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
241
  schema: {
227
242
  type: "object",
228
243
  properties: {
@@ -444,7 +459,11 @@ const TOOLS: Record<string, Tool> = {
444
459
  properties: { ...FILE_PROP, level: { type: "string", description: "Level name (e.g. L5)" } },
445
460
  required: ["file", "level"],
446
461
  },
447
- run: (a) => svgPlan(load(str(a.file, "file")), { level: str(a.level, "level") }),
462
+ run: (a) => {
463
+ const model = load(str(a.file, "file"));
464
+ const level = str(a.level, "level");
465
+ return svgPlan(model, { level, componentSvgs: componentSvgFiles(model, level) });
466
+ },
448
467
  },
449
468
  section_svg: {
450
469
  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 {