@kensnzk/koyu 0.26.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 (146) 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/section.d.ts +27 -2
  52. package/dist/core/section.d.ts.map +1 -1
  53. package/dist/core/section.js +63 -11
  54. package/dist/core/section.js.map +1 -1
  55. package/dist/core/vocabulary.d.ts +20 -4
  56. package/dist/core/vocabulary.d.ts.map +1 -1
  57. package/dist/core/vocabulary.js +107 -9
  58. package/dist/core/vocabulary.js.map +1 -1
  59. package/dist/draw/component-files.d.ts +8 -0
  60. package/dist/draw/component-files.d.ts.map +1 -0
  61. package/dist/draw/component-files.js +35 -0
  62. package/dist/draw/component-files.js.map +1 -0
  63. package/dist/draw/component-svg.d.ts +14 -0
  64. package/dist/draw/component-svg.d.ts.map +1 -0
  65. package/dist/draw/component-svg.js +67 -0
  66. package/dist/draw/component-svg.js.map +1 -0
  67. package/dist/draw/conventions/architectural.d.ts +32 -0
  68. package/dist/draw/conventions/architectural.d.ts.map +1 -0
  69. package/dist/draw/conventions/architectural.js +29 -0
  70. package/dist/draw/conventions/architectural.js.map +1 -0
  71. package/dist/draw/index.d.ts +2 -2
  72. package/dist/draw/index.d.ts.map +1 -1
  73. package/dist/draw/index.js +2 -2
  74. package/dist/draw/index.js.map +1 -1
  75. package/dist/draw/marks.d.ts +37 -12
  76. package/dist/draw/marks.d.ts.map +1 -1
  77. package/dist/draw/marks.js +508 -38
  78. package/dist/draw/marks.js.map +1 -1
  79. package/dist/draw/plan.d.ts +3 -1
  80. package/dist/draw/plan.d.ts.map +1 -1
  81. package/dist/draw/plan.js +247 -85
  82. package/dist/draw/plan.js.map +1 -1
  83. package/dist/draw/section.d.ts +20 -2
  84. package/dist/draw/section.d.ts.map +1 -1
  85. package/dist/draw/section.js +43 -10
  86. package/dist/draw/section.js.map +1 -1
  87. package/dist/form.d.ts +2 -2
  88. package/dist/form.d.ts.map +1 -1
  89. package/dist/form.js.map +1 -1
  90. package/dist/index.js +1 -1
  91. package/dist/mcp.js +21 -3
  92. package/dist/mcp.js.map +1 -1
  93. package/dist/parse-file.d.ts +1 -0
  94. package/dist/parse-file.d.ts.map +1 -1
  95. package/dist/parse-file.js +1 -0
  96. package/dist/parse-file.js.map +1 -1
  97. package/dist/validate/builtin/index.d.ts +4 -2
  98. package/dist/validate/builtin/index.d.ts.map +1 -1
  99. package/dist/validate/builtin/index.js +9 -2
  100. package/dist/validate/builtin/index.js.map +1 -1
  101. package/dist/validate/builtin/opening-operations.d.ts +63 -0
  102. package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
  103. package/dist/validate/builtin/opening-operations.js +406 -0
  104. package/dist/validate/builtin/opening-operations.js.map +1 -0
  105. package/editors/vscode/syntaxes/koyu.tmLanguage.json +3 -3
  106. package/examples/basement/main.muro +3 -3
  107. package/examples/complex/L1.muro +1 -1
  108. package/examples/complex/assets.muro +2 -2
  109. package/examples/complex/main.muro +1 -1
  110. package/examples/house/L1.muro +3 -3
  111. package/examples/house/L2.muro +2 -2
  112. package/examples/house/assets.muro +8 -8
  113. package/examples/house/main.muro +1 -1
  114. package/examples/house/site.muro +2 -2
  115. package/examples/house.muro +6 -6
  116. package/examples/mansion.muro +1 -1
  117. package/examples/office.muro +1 -1
  118. package/examples/steps/06-finished.muro +1 -1
  119. package/examples/tower/assets.muro +1 -1
  120. package/examples/tower/main.muro +1 -1
  121. package/examples/twin/assets.muro +2 -2
  122. package/examples/twin/main.muro +1 -1
  123. package/examples/two-rooms.canonical.json +1 -1
  124. package/examples/two-rooms.muro +1 -1
  125. package/package.json +7 -4
  126. package/src/cli.ts +2 -2
  127. package/src/core/components.ts +224 -0
  128. package/src/core/derive.ts +47 -4
  129. package/src/core/diagnose.ts +182 -4
  130. package/src/core/model.ts +10 -5
  131. package/src/core/parse.ts +5 -4
  132. package/src/core/section.ts +107 -8
  133. package/src/core/vocabulary.ts +115 -9
  134. package/src/draw/component-files.ts +36 -0
  135. package/src/draw/component-svg.ts +79 -0
  136. package/src/draw/conventions/architectural.ts +60 -0
  137. package/src/draw/index.ts +9 -2
  138. package/src/draw/marks.ts +564 -44
  139. package/src/draw/plan.ts +253 -88
  140. package/src/draw/section.ts +78 -14
  141. package/src/form.ts +4 -0
  142. package/src/index.ts +1 -1
  143. package/src/mcp.ts +21 -3
  144. package/src/parse-file.ts +1 -0
  145. package/src/validate/builtin/index.ts +14 -2
  146. package/src/validate/builtin/opening-operations.ts +519 -0
@@ -30,8 +30,17 @@ import { heff, isSemiOutdoor, levelsSorted, SUPPORTED_LANGUAGE_VERSIONS, type At
30
30
  isVoid,
31
31
  EXTERIOR
32
32
  } from "./model.js";
33
- import { ASSET_ELEM, attrSpec, isNamespaced } from "./vocabulary.js";
33
+ import {
34
+ MURO_1_5_OPENING_ATTRS,
35
+ MURO_1_5_OPENING_STYLES,
36
+ MURO_1_5_COMPONENT_AREA_ATTRS,
37
+ attrSpec,
38
+ assetElem,
39
+ isNamespaced,
40
+ openingStyleOwner,
41
+ } from "./vocabulary.js";
34
42
  import { runDecls, runIssues } from "./vertical.js";
43
+ import { placedComponents } from "./components.js";
35
44
 
36
45
  export interface CheckResult {
37
46
  errors: string[];
@@ -88,6 +97,10 @@ export const DIAGNOSTIC_CODES = {
88
97
  OPN06: "error", // 開口の幅が線分長を超える
89
98
  OPN07: "error", // 開口の明示位置の軸違い
90
99
  OPN08: "error", // 開口の明示位置のはみ出し
100
+ OPN09: "error", // opening kind and operation disagree
101
+ OPN10: "error", // curtain-wall panel layout is not applicable or not a whole count
102
+ CMP01: "error", // component asset declaration or area reference cannot be resolved
103
+ CMP02: "error", // transformed component footprint extends outside its host area
91
104
  SEG01: "error", // 領域を持たない空間へのarea
92
105
  SEG02: "warning", // areaのはみ出し
93
106
  SEG03: "warning", // open境界のseg (解釈されない)
@@ -132,6 +145,8 @@ export const DIAGNOSTIC_CODES = {
132
145
  VER05: "error", // koyu 1.0以前のファイルの型の位置に exterior / void (ADR-0051)
133
146
  VER06: "error", // the file declares a language version newer than this build reads
134
147
  VER07: "error", // the file declares a version in which a key it writes is retired (ADR-0061)
148
+ VER08: "error", // the file uses opening presentation introduced in muro 1.5 (ADR-0068/0074)
149
+ VER09: "error", // the file uses component assets or area placement introduced in muro 1.5
135
150
  SYN01: "error", // 構文・合成エラー (SourceError の写し — check --json のみ)
136
151
  } as const satisfies Record<string, "error" | "warning">;
137
152
 
@@ -211,7 +226,7 @@ function attrSubjects(
211
226
  }
212
227
  }
213
228
  for (const a of model.assets.values()) {
214
- out.push([`asset ${a.name}`, { elem: ASSET_ELEM, of: a.attrs }, { line: a.line, file: a.file }]);
229
+ out.push([`asset ${a.name}`, { elem: assetElem(a.kind), of: a.attrs }, { line: a.line, file: a.file }]);
215
230
  }
216
231
  for (const c of model.columns) {
217
232
  out.push([`column ${c.size}mm`, { elem: "column", of: c.attrs }, { line: c.line, file: c.file }]);
@@ -310,6 +325,8 @@ export function checkDiagnostics(model: Model): Diagnostic[] {
310
325
  checkSpaceOverlap(ctx);
311
326
  checkDaylightScope(ctx);
312
327
  checkAttrValues(ctx);
328
+ checkAssetOpenings(ctx);
329
+ checkComponents(ctx);
313
330
  checkRuns(ctx);
314
331
  checkDrawnLines(ctx);
315
332
  checkColumns(ctx);
@@ -326,6 +343,73 @@ export function checkDiagnostics(model: Model): Diagnostic[] {
326
343
  return diags;
327
344
  }
328
345
 
346
+ function curtainWallPanelIssue(kind: "door" | "window", attrs: Attrs): string | undefined {
347
+ const panels = attrs["panels"];
348
+ if (panels === undefined) return undefined;
349
+ if (kind !== "window" || attrs["style"] !== "curtain-wall") {
350
+ return "panels: may only be written on a window with style:curtain-wall";
351
+ }
352
+ // ATT01 owns non-numeric and non-positive values. This check adds the curtain-wall-specific
353
+ // fact that a count cannot be fractional, without emitting two errors for the same spelling.
354
+ if (typeof panels === "number" && panels > 0 && !Number.isInteger(panels)) {
355
+ return `panels on a curtain wall is a positive whole number: panels:${panels}`;
356
+ }
357
+ return undefined;
358
+ }
359
+
360
+ /** Asset declarations are useful without an instance, so their own opening facts must be valid. */
361
+ function checkAssetOpenings(ctx: Ctx): void {
362
+ const { model, emit } = ctx;
363
+ if (olderThan(model.version, "1.5")) return;
364
+ for (const asset of model.assets.values()) {
365
+ if (asset.kind === "component") continue;
366
+ const style = asset.attrs["style"];
367
+ if (typeof style === "string") {
368
+ const owner = openingStyleOwner(asset.kind, style);
369
+ if (owner) {
370
+ emit(
371
+ "OPN09",
372
+ `style:${style} is a ${owner}-only operation and cannot be used on ${asset.kind} asset ${asset.name}`,
373
+ { line: asset.line, file: asset.file },
374
+ );
375
+ }
376
+ }
377
+ const issue = curtainWallPanelIssue(asset.kind, asset.attrs);
378
+ if (issue) emit("OPN10", `${issue} on asset ${asset.name}`, { line: asset.line, file: asset.file });
379
+ }
380
+ }
381
+
382
+ /** Component declarations and their area-hosted instances are checked in source order. */
383
+ function checkComponents(ctx: Ctx): void {
384
+ const { model, emit } = ctx;
385
+ for (const asset of model.assets.values()) {
386
+ if (asset.kind !== "component") continue;
387
+ const missing = ["w", "d", "plan-svg"].filter((key) => asset.attrs[key] === undefined);
388
+ if (missing.length > 0) {
389
+ emit(
390
+ "CMP01",
391
+ `Component asset ${asset.name} requires ${missing.map((key) => `${key}:`).join(" / ")}`,
392
+ { line: asset.line, file: asset.file },
393
+ );
394
+ }
395
+ const ref = asset.attrs["plan-svg"];
396
+ if (ref !== undefined && (typeof ref !== "string" || (!ref.startsWith("./") && !ref.startsWith("../")))) {
397
+ emit(
398
+ "CMP01",
399
+ `Component asset ${asset.name} plan-svg takes a relative path: ${String(ref)}`,
400
+ { line: asset.line, file: asset.file },
401
+ );
402
+ }
403
+ }
404
+ for (const issue of placedComponents(model).issues) {
405
+ emit(issue.code, issue.message, {
406
+ line: issue.line,
407
+ ...(issue.file ? { file: issue.file } : {}),
408
+ path: issue.path,
409
+ });
410
+ }
411
+ }
412
+
329
413
 
330
414
  /** 吹抜けが下階の空間の平面をどれだけ覆うか (0..1) */
331
415
  function voidCoverage(s: Space, partners: Space[]): number {
@@ -641,10 +725,10 @@ function checkColumns(ctx: Ctx): void {
641
725
  }
642
726
  }
643
727
 
644
- /** 言語版の受理条件 — VER01〜VER05 と VER07 (VER06 は parse が投げる) */
728
+ /** Language-version acceptance: VER01–VER05 and VER07–VER08. Parsing raises VER06. */
645
729
  function checkLanguageVersion(ctx: Ctx): void {
646
730
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
647
- // 言語版の受理条件 (ADR-0017): 旧版は意味保存の場合のみ受理する。
731
+ // Language-version acceptance (ADR-0017): an older file is accepted only where meaning holds.
648
732
  // 既定境界 (ADR-0014) が導出されるファイルは、0.1の意味 (境界なし+警告) と食い違う — エラーで二択を示す
649
733
  if (model.version === "0.1") {
650
734
  for (const b of model.boundaries) {
@@ -764,6 +848,75 @@ function checkLanguageVersion(ctx: Ctx): void {
764
848
  }
765
849
  }
766
850
 
851
+ // The expanded opening operation vocabulary arrives in muro 1.5. An older processor rejects
852
+ // these values, so an older declaration may not use them even though this build can interpret
853
+ // them. Scan written assets and opening declarations; do not report an instance a second time
854
+ // when its value is inherited unchanged from an asset that is already reported.
855
+ if (olderThan(model.version, "1.5")) {
856
+ const introduced = new Set<string>(MURO_1_5_OPENING_STYLES);
857
+ const introducedAttrs = new Set<string>(MURO_1_5_OPENING_ATTRS);
858
+ for (const a of model.assets.values()) {
859
+ const style = a.attrs["style"];
860
+ const attr = Object.keys(a.attrs).find((key) => introducedAttrs.has(key));
861
+ if (typeof style === "string" && introduced.has(style)) {
862
+ emit(
863
+ "VER08",
864
+ `A muro ${model.version} file uses a 1.5 opening style: ${style} on asset ${a.name} — raise the version to muro 1.5`,
865
+ { line: a.line, file: a.file },
866
+ );
867
+ } else if (attr) {
868
+ emit(
869
+ "VER08",
870
+ `A muro ${model.version} file uses a 1.5 opening attribute: ${attr} on asset ${a.name} — raise the version to muro 1.5`,
871
+ { line: a.line, file: a.file },
872
+ );
873
+ }
874
+ }
875
+ for (const b of model.boundaries) {
876
+ for (const o of b.openings) {
877
+ const style = o.attrs["style"];
878
+ const inherited = o.ref === undefined ? undefined : model.assets.get(o.ref)?.attrs["style"];
879
+ const assetAttrs = o.ref === undefined ? undefined : model.assets.get(o.ref)?.attrs;
880
+ const attr = Object.keys(o.attrs).find(
881
+ (key) => introducedAttrs.has(key) && assetAttrs?.[key] !== o.attrs[key],
882
+ );
883
+ if (typeof style === "string" && introduced.has(style) && inherited !== style) {
884
+ emit(
885
+ "VER08",
886
+ `A muro ${model.version} file uses a 1.5 opening style: ${style} on ${o.kind} (${b.a} | ${b.b}) — raise the version to muro 1.5`,
887
+ { line: o.line, file: b.file, path: [b.a, b.b] },
888
+ );
889
+ } else if (attr) {
890
+ emit(
891
+ "VER08",
892
+ `A muro ${model.version} file uses a 1.5 opening attribute: ${attr} on ${o.kind} (${b.a} | ${b.b}) — raise the version to muro 1.5`,
893
+ { line: o.line, file: b.file, path: [b.a, b.b] },
894
+ );
895
+ }
896
+ }
897
+ }
898
+ const componentAreaAttrs = new Set<string>(MURO_1_5_COMPONENT_AREA_ATTRS);
899
+ for (const asset of model.assets.values()) {
900
+ if (asset.kind !== "component") continue;
901
+ emit(
902
+ "VER09",
903
+ `A muro ${model.version} file declares a 1.5 component asset: ${asset.name} — raise the version to muro 1.5`,
904
+ { line: asset.line, file: asset.file },
905
+ );
906
+ }
907
+ for (const space of model.spaces.values()) {
908
+ for (const area of space.areas) {
909
+ const attr = Object.keys(area.attrs).find((key) => componentAreaAttrs.has(key));
910
+ if (!attr) continue;
911
+ emit(
912
+ "VER09",
913
+ `A muro ${model.version} file uses a 1.5 component placement attribute: ${attr} on area (${space.path}) — raise the version to muro 1.5`,
914
+ { line: area.line, file: space.file, path: [space.path] },
915
+ );
916
+ }
917
+ }
918
+ }
919
+
767
920
  // A retired key is VER03/VER04 read from the other end. Those fire when a file declares an old
768
921
  // version and writes a word that version does not yet have; this one fires when a file declares
769
922
  // a new version and writes a word that version no longer has. Both say the same thing — the
@@ -987,6 +1140,31 @@ function checkOpenings(ctx: Ctx, b: Boundary): void {
987
1140
  }
988
1141
  const placedOnSeg: Array<{ o: (typeof b.openings)[number]; key: string; c: number }> = [];
989
1142
  for (const o of b.openings) {
1143
+ if (!olderThan(model.version, "1.5")) {
1144
+ const style = o.attrs["style"];
1145
+ if (typeof style === "string") {
1146
+ const owner = openingStyleOwner(o.kind, style);
1147
+ const inherited = o.ref === undefined ? undefined : model.assets.get(o.ref)?.attrs["style"];
1148
+ if (owner && inherited !== style) {
1149
+ emit(
1150
+ "OPN09",
1151
+ `style:${style} is a ${owner}-only operation and cannot be used on a ${o.kind}`,
1152
+ { line: o.line, file: b.file, path: [b.a, b.b] },
1153
+ );
1154
+ }
1155
+ }
1156
+ const panelIssue = curtainWallPanelIssue(o.kind, o.attrs);
1157
+ if (panelIssue) {
1158
+ const asset = o.ref === undefined ? undefined : model.assets.get(o.ref);
1159
+ const inheritedIssue = asset && asset.kind !== "component"
1160
+ ? curtainWallPanelIssue(asset.kind, asset.attrs)
1161
+ : undefined;
1162
+ const unchanged = asset?.attrs["style"] === o.attrs["style"] && asset?.attrs["panels"] === o.attrs["panels"];
1163
+ if (!(inheritedIssue === panelIssue && unchanged)) {
1164
+ emit("OPN10", panelIssue, { line: o.line, file: b.file, path: [b.a, b.b] });
1165
+ }
1166
+ }
1167
+ }
990
1168
  const placed = placeOpening(model, b, o);
991
1169
  if ("error" in placed && placed.error) {
992
1170
  emit(placed.code, placed.message, { line: placed.line, file: placed.file, path: [b.a, b.b] });
package/src/core/model.ts CHANGED
@@ -51,6 +51,11 @@ export const MURO_SUPPORT: readonly { muro: string; since: string; until: string
51
51
  // boundary to a region-less space was written, so a forgotten line was a silent hole; from 1.4
52
52
  // that face is a wall, and what is declared is which outside it looks at (ADR-0065).
53
53
  { muro: "1.4", since: "0.26.0", until: null },
54
+ // 1.5 gives opening operation styles explicit values and adds area-hosted component assets.
55
+ // A plan can distinguish opening operations without guessing from names or widths, and can
56
+ // place fixed furniture or equipment footprints while keeping SVG artwork out of Form
57
+ // (ADR-0068, ADR-0075).
58
+ { muro: "1.5", since: "0.28.0", until: null },
54
59
  ];
55
60
 
56
61
  /** The word a version line is written with from 1.2 on. */
@@ -77,7 +82,7 @@ export const LAST_KOYU_SPELLED_VERSION = "1.1";
77
82
  * `since` column is written in this vocabulary, and every surface that answers "which muro
78
83
  * does this build speak" needs both halves at once.
79
84
  */
80
- export const KOYU_VERSION = "0.26.0";
85
+ export const KOYU_VERSION = "0.28.0";
81
86
 
82
87
  /**
83
88
  * Whether `a` names a later language version than `b`.
@@ -346,13 +351,13 @@ export interface Zone {
346
351
  }
347
352
 
348
353
  /**
349
- * 建具アセット — RevitのFamily、USDのReferenceにあたる型の宣言 (ADR-0010)。
350
- * `asset SD1 door w:800 style:sliding` と宣言し、開口が `door SD1 ...` で参照する。
351
- * インスタンス側の属性が上書きする。別ファイル (アセット集) に置いて import できる
354
+ * A reusable asset definition. Door/window assets provide opening defaults; component assets
355
+ * provide a fixed footprint and a plan artwork reference to a named area. Definitions may live
356
+ * in an imported library layer.
352
357
  */
353
358
  export interface Asset {
354
359
  name: string;
355
- kind: "door" | "window";
360
+ kind: "door" | "window" | "component";
356
361
  attrs: Attrs;
357
362
  line: number;
358
363
  file?: string;
package/src/core/parse.ts CHANGED
@@ -382,14 +382,15 @@ function ingest(
382
382
  break;
383
383
  }
384
384
  case "asset": {
385
- // 建具アセット (RevitのFamily / USDのReference — ADR-0010)
385
+ // Referenced type. Door/window assets attach to boundaries; component assets attach to
386
+ // named uncounted areas and may carry external plan artwork.
386
387
  const aname = rest[0];
387
388
  const akind = rest[1];
388
389
  if (!aname || aname.includes(":") || aname.startsWith("/")) {
389
- throw new SourceError(ln, "asset takes the form asset <name> door|window [attributes...]");
390
+ throw new SourceError(ln, "asset takes the form asset <name> door|window|component [attributes...]");
390
391
  }
391
- if (akind !== "door" && akind !== "window") {
392
- throw new SourceError(ln, `An asset kind is door / window: ${akind}`);
392
+ if (akind !== "door" && akind !== "window" && akind !== "component") {
393
+ throw new SourceError(ln, `An asset kind is door / window / component: ${akind}`);
393
394
  }
394
395
  const prevA = model.assets.get(aname);
395
396
  if (prevA) {
@@ -56,6 +56,26 @@ export interface SectionSpec {
56
56
  look: Edge;
57
57
  }
58
58
 
59
+ /** A directed cutting line in plan. `u` starts at `(x1,y1)` and increases toward `(x2,y2)`. */
60
+ export interface SectionLine {
61
+ x1: number;
62
+ y1: number;
63
+ x2: number;
64
+ y2: number;
65
+ }
66
+
67
+ /**
68
+ * A vertical plane named by a directed line rather than a grid-parallel coordinate.
69
+ *
70
+ * The viewer looks toward the line's left side, so the line direction is left-to-right on the
71
+ * sheet. The two endpoints name the frame; the cutting plane itself is infinite.
72
+ */
73
+ export interface LineSectionSpec {
74
+ cut: SectionLine;
75
+ /** a caller-owned name for the cut, when there is one */
76
+ atRef?: string;
77
+ }
78
+
59
79
  export interface SectionEntity {
60
80
  class: SectionClass;
61
81
  of: SectionSubject;
@@ -81,6 +101,13 @@ export interface FormSection {
81
101
  entities: SectionEntity[];
82
102
  }
83
103
 
104
+ /** A section made by a directed line. Its entities have the same meaning as an axis section. */
105
+ export interface LineFormSection {
106
+ cut: SectionLine;
107
+ atRef?: string;
108
+ entities: SectionEntity[];
109
+ }
110
+
84
111
  /** The direction of view as a unit vector in plan. */
85
112
  function look(edge: Edge): Pt {
86
113
  return edge === "N"
@@ -160,6 +187,36 @@ function cutOf(body: FormBody, axis: SectionAxis, at: number, u: (p: Pt) => numb
160
187
  ];
161
188
  }
162
189
 
190
+ /** The polygon a body leaves on a directed line, in that line's `(u,z)` frame. */
191
+ function lineCutOf(
192
+ body: FormBody,
193
+ u: (p: Pt) => number,
194
+ behind: (p: Pt) => number,
195
+ ): SectionPt[] | undefined {
196
+ // `crossing` already owns the tolerance and the rules for a convex ring grazing a plane. Put
197
+ // the body into the line's orthonormal frame and ask the same axis question there, so an
198
+ // oblique cut cannot acquire a second intersection rule.
199
+ const local = body.poly.map((p) => ({ x: behind(p), y: u(p) }));
200
+ const met = crossing(local, "X", 0);
201
+ if (!met) return undefined;
202
+ const n = body.poly.length;
203
+ const at01 = (v: number[], c: { edge: number; t: number }): number =>
204
+ v[c.edge]! + c.t * (v[(c.edge + 1) % n]! - v[c.edge]!);
205
+ const ends = met.map((c) => ({
206
+ u: local[c.edge]!.y + c.t * (local[(c.edge + 1) % n]!.y - local[c.edge]!.y),
207
+ z0: at01(body.bottom, c),
208
+ z1: at01(body.top, c),
209
+ }));
210
+ const [a, b] = ends[0]!.u <= ends[1]!.u ? [ends[0]!, ends[1]!] : [ends[1]!, ends[0]!];
211
+ if (b.u - a.u <= EPS) return undefined;
212
+ return [
213
+ { u: a.u, z: a.z0 },
214
+ { u: b.u, z: b.z0 },
215
+ { u: b.u, z: b.z1 },
216
+ { u: a.u, z: a.z1 },
217
+ ];
218
+ }
219
+
163
220
  /**
164
221
  * The shape a body throws onto the plane, seen head-on.
165
222
  *
@@ -202,12 +259,44 @@ function shadowOf(body: FormBody, u: (p: Pt) => number): SectionPt[] | undefined
202
259
  return ring.length >= 3 ? ring.map((p) => ({ u: p.x, z: p.y })) : undefined;
203
260
  }
204
261
 
205
- function entitiesOf(bodies: FormBody[], spec: SectionSpec): SectionEntity[] {
262
+ interface SectionFrame {
263
+ u: (p: Pt) => number;
264
+ /** How far behind the plane a point stands. Positive is away from the viewer. */
265
+ behind: (p: Pt) => number;
266
+ cut: (body: FormBody) => SectionPt[] | undefined;
267
+ }
268
+
269
+ function axisFrame(spec: SectionSpec): SectionFrame {
206
270
  const d = look(spec.look);
207
271
  const r = rightOf(d);
208
272
  const u = (p: Pt): number => p.x * r.x + p.y * r.y;
209
- /** How far behind the plane a point stands. Positive is away from the viewer. */
210
273
  const behind = (p: Pt): number => (spec.axis === "X" ? (p.x - spec.at) * d.x : (p.y - spec.at) * d.y);
274
+ return { u, behind, cut: (body) => cutOf(body, spec.axis, spec.at, u) };
275
+ }
276
+
277
+ function lineFrame(spec: LineSectionSpec): SectionFrame {
278
+ const { x1, y1, x2, y2 } = spec.cut;
279
+ const dx = x2 - x1;
280
+ const dy = y2 - y1;
281
+ const length = Math.hypot(dx, dy);
282
+ if (length <= EPS) throw new Error("A section line needs two distinct points");
283
+ // q is right on the sheet. d points away from the viewer, toward the line's left side.
284
+ const q = { x: dx / length, y: dy / length };
285
+ const d = { x: -q.y, y: q.x };
286
+ const relative = (p: Pt): Pt => ({ x: p.x - x1, y: p.y - y1 });
287
+ const u = (p: Pt): number => {
288
+ const v = relative(p);
289
+ return v.x * q.x + v.y * q.y;
290
+ };
291
+ const behind = (p: Pt): number => {
292
+ const v = relative(p);
293
+ return v.x * d.x + v.y * d.y;
294
+ };
295
+ return { u, behind, cut: (body) => lineCutOf(body, u, behind) };
296
+ }
297
+
298
+ function entitiesOf(bodies: FormBody[], frame: SectionFrame): SectionEntity[] {
299
+ const { u, behind } = frame;
211
300
 
212
301
  const out: SectionEntity[] = [];
213
302
  for (const body of bodies) {
@@ -226,7 +315,7 @@ function entitiesOf(bodies: FormBody[], spec: SectionSpec): SectionEntity[] {
226
315
  const wholly = { behind: lo >= -EPS && hi > EPS, front: hi <= EPS && lo < -EPS };
227
316
  if (!wholly.behind && !wholly.front) {
228
317
  // It reaches both sides: the plane crossed it.
229
- const polygon = cutOf(body, spec.axis, spec.at, u);
318
+ const polygon = frame.cut(body);
230
319
  if (polygon) {
231
320
  out.push({ class: "cut", of: body.of, ref: body.ref, ...(body.kind ? { kind: body.kind } : {}), polygon, depth: 0 });
232
321
  }
@@ -256,10 +345,20 @@ function entitiesOf(bodies: FormBody[], spec: SectionSpec): SectionEntity[] {
256
345
  /**
257
346
  * The section a vertical plane makes of a `Form`.
258
347
  *
259
- * The plane is named by an axis and a coordinate; `look` says which way it is faced, and must
260
- * cross the plane rather than run along it.
348
+ * An axis spec names a coordinate and a facing. A line spec names the same frame by two directed
349
+ * plan points, with positive `u` running from the first to the second.
261
350
  */
262
- export function sectionForm(form: Form, spec: SectionSpec): FormSection {
351
+ export function sectionForm(form: Form, spec: SectionSpec): FormSection;
352
+ export function sectionForm(form: Form, spec: LineSectionSpec): LineFormSection;
353
+ export function sectionForm(form: Form, spec: SectionSpec | LineSectionSpec): FormSection | LineFormSection {
354
+ if ("cut" in spec) {
355
+ const frame = lineFrame(spec);
356
+ return {
357
+ cut: spec.cut,
358
+ ...(spec.atRef !== undefined ? { atRef: spec.atRef } : {}),
359
+ entities: entitiesOf(cuttableBodies(form), frame),
360
+ };
361
+ }
263
362
  if (axisOf(spec.look) !== spec.axis) {
264
363
  throw new Error(
265
364
  `Looking ${spec.look} runs along the ${spec.axis} plane rather than across it (an X plane is looked at from E or W, a Y plane from N or S)`,
@@ -270,7 +369,7 @@ export function sectionForm(form: Form, spec: SectionSpec): FormSection {
270
369
  at: spec.at,
271
370
  ...(spec.atRef !== undefined ? { atRef: spec.atRef } : {}),
272
371
  look: spec.look,
273
- entities: entitiesOf(cuttableBodies(form), spec),
372
+ entities: entitiesOf(cuttableBodies(form), axisFrame(spec)),
274
373
  };
275
374
  }
276
375
 
@@ -302,7 +401,7 @@ export function elevationForm(form: Form, face: Edge): FormSection {
302
401
  }
303
402
  }
304
403
  const spec: SectionSpec = { axis, at, look: from };
305
- return { axis, at, look: from, entities: entitiesOf(bodies, spec) };
404
+ return { axis, at, look: from, entities: entitiesOf(bodies, axisFrame(spec)) };
306
405
  }
307
406
 
308
407
  /** The area of a section polygon, mm². Used by the tests that hold the cut against the Form. */
@@ -71,6 +71,92 @@ const retired = (after: string, instead: string, base: AttrSpec = free()): AttrS
71
71
  */
72
72
  export const CARRY_NAMESPACE = /^[a-z][a-z0-9_-]*(\.[a-z0-9_-]+)+$/;
73
73
 
74
+ /** Opening operations introduced after the original hinged / sliding / auto set. */
75
+ export const MURO_1_5_OPENING_STYLES = [
76
+ "hinged-double",
77
+ "hinged-unequal",
78
+ "sliding-double",
79
+ "sliding-bypass",
80
+ "auto-single",
81
+ "auto-double",
82
+ "entrance",
83
+ "gate-hinged",
84
+ "gate-hinged-double",
85
+ "gate-sliding",
86
+ "rolling-shutter",
87
+ "overhead",
88
+ "fixed",
89
+ "projecting",
90
+ "curtain-wall",
91
+ ] as const;
92
+
93
+ /** Every interpreted value accepted by an opening's `style:` attribute. */
94
+ export const OPENING_STYLE_VALUES = [
95
+ "hinged",
96
+ "sliding",
97
+ "auto",
98
+ ...MURO_1_5_OPENING_STYLES,
99
+ ] as const;
100
+
101
+ /** Opening presentation attributes introduced in muro 1.5. */
102
+ export const MURO_1_5_OPENING_ATTRS = ["panels"] as const;
103
+
104
+ /** Area attributes introduced with component placement in muro 1.5. */
105
+ export const MURO_1_5_COMPONENT_AREA_ATTRS = [
106
+ "asset",
107
+ "align-x",
108
+ "align-y",
109
+ "offset-x",
110
+ "offset-y",
111
+ "rotate",
112
+ ] as const;
113
+
114
+ const DOOR_OPENING_STYLES = new Set<string>([
115
+ "hinged",
116
+ "hinged-double",
117
+ "hinged-unequal",
118
+ "sliding",
119
+ "sliding-double",
120
+ "sliding-bypass",
121
+ "auto",
122
+ "auto-single",
123
+ "auto-double",
124
+ "entrance",
125
+ "gate-hinged",
126
+ "gate-hinged-double",
127
+ "gate-sliding",
128
+ "rolling-shutter",
129
+ "overhead",
130
+ ]);
131
+
132
+ const WINDOW_OPENING_STYLES = new Set<string>([
133
+ "hinged",
134
+ "hinged-double",
135
+ "sliding",
136
+ "sliding-double",
137
+ "sliding-bypass",
138
+ "fixed",
139
+ "projecting",
140
+ "curtain-wall",
141
+ ]);
142
+
143
+ /**
144
+ * Whether a known opening operation applies to the declared opening kind.
145
+ *
146
+ * Unknown values return true because ATT02 owns that contradiction. This check only partitions
147
+ * the closed vocabulary and therefore never emits a second diagnostic for one misspelling.
148
+ */
149
+ export function openingStyleAppliesTo(kind: "door" | "window", style: string): boolean {
150
+ if (!(OPENING_STYLE_VALUES as readonly string[]).includes(style)) return true;
151
+ return (kind === "door" ? DOOR_OPENING_STYLES : WINDOW_OPENING_STYLES).has(style);
152
+ }
153
+
154
+ /** The other opening kind for a known operation that does not apply to `kind`. */
155
+ export function openingStyleOwner(kind: "door" | "window", style: string): "door" | "window" | undefined {
156
+ if (openingStyleAppliesTo(kind, style)) return undefined;
157
+ return kind === "door" ? "window" : "door";
158
+ }
159
+
74
160
  /** そのキーが名前空間つきの運搬層かどうか */
75
161
  export function isNamespaced(key: string): boolean {
76
162
  return CARRY_NAMESPACE.test(key);
@@ -174,12 +260,13 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
174
260
  hinge: structure(),
175
261
  swing: structure(),
176
262
 
177
- // 解釈
178
- style: one("hinged", "sliding", "auto"), // 平面の建具表現が変わる
179
- name: free(), // **境界の中で一意な名** — 開口の同一性の鍵 (docs/reference/scope.md)
263
+ // Interpreted.
264
+ style: one(...OPENING_STYLE_VALUES), // selects the plan opening symbol
265
+ panels: num(), // explicit equal panel count for a curtain wall
266
+ name: free(), // unique within the boundary: the opening's identity key
180
267
 
181
- // 運搬
182
- sill: carry(), // 窓台高
268
+ // Carried.
269
+ sill: carry(), // window sill height
183
270
  spec: carry(),
184
271
  fire: carry(),
185
272
  },
@@ -188,6 +275,23 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
188
275
  floor: carry(),
189
276
  name: free(),
190
277
  spec: carry(),
278
+ // A named uncounted area is the sole placement frame for a component asset. Position remains
279
+ // relative to the written extent, so changing the extent moves the component with it.
280
+ asset: free(),
281
+ "align-x": one("min", "center", "max"),
282
+ "align-y": one("min", "center", "max"),
283
+ "offset-x": free(),
284
+ "offset-y": free(),
285
+ rotate: free(),
286
+ },
287
+
288
+ component: {
289
+ w: num(),
290
+ d: num(),
291
+ "plan-svg": free(),
292
+ name: free(),
293
+ category: carry(),
294
+ spec: carry(),
191
295
  },
192
296
 
193
297
  seg: {
@@ -243,8 +347,10 @@ export function attrSpec(elem: string, key: string): AttrSpec | undefined {
243
347
  return ATTR_LEDGER[elem]?.[key];
244
348
  }
245
349
 
246
- /**
247
- * asset は開口の既定値の束なので、開口と同じ台帳で読む (ADR-0010)。
248
- * 「アセットに書けて開口に書けない属性」を作らないための同一視である。
249
- */
350
+ /** Door and window assets use the opening ledger unchanged. */
250
351
  export const ASSET_ELEM = "opening";
352
+
353
+ /** Door/window assets share the opening ledger; placed component assets have their own ledger. */
354
+ export function assetElem(kind: "door" | "window" | "component"): "opening" | "component" {
355
+ return kind === "component" ? "component" : ASSET_ELEM;
356
+ }
@@ -0,0 +1,36 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+
4
+ import { placedComponents } from "../core/components.js";
5
+ import type { Model } from "../core/model.js";
6
+
7
+ /**
8
+ * Read component plan artwork for a filesystem-backed model. The bytes enter drawing only: they
9
+ * are absent from Model, canonical JSON and Form. A composed override resolves relative to the
10
+ * layer that supplied the winning plan-svg value.
11
+ */
12
+ export function componentSvgFiles(model: Model, level?: string): Readonly<Record<string, string>> {
13
+ const sources: Record<string, string> = {};
14
+ const needed = new Set(
15
+ placedComponents(model).components
16
+ .filter((component) => level === undefined || component.level === level)
17
+ .map((component) => component.asset),
18
+ );
19
+ for (const asset of model.assets.values()) {
20
+ if (asset.kind !== "component" || !needed.has(asset.name)) continue;
21
+ const ref = asset.attrs["plan-svg"];
22
+ if (typeof ref !== "string" || (!ref.startsWith("./") && !ref.startsWith("../"))) continue;
23
+ const layer = model.attrSrc.get(`asset:${asset.name}:plan-svg`);
24
+ const from = layer === undefined ? asset.file : model.layers[layer] ?? asset.file;
25
+ if (!from) {
26
+ throw new Error(`Component asset ${asset.name} plan-svg cannot be resolved from a source file`);
27
+ }
28
+ const file = resolve(dirname(from), ref);
29
+ try {
30
+ sources[asset.name] = readFileSync(file, "utf8");
31
+ } catch {
32
+ throw new Error(`Cannot read plan SVG for component asset ${asset.name}: ${ref}`);
33
+ }
34
+ }
35
+ return sources;
36
+ }