@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.
- package/assets/plan/README.md +18 -0
- package/assets/plan/catalog.muro +87 -0
- package/assets/plan/library.muro +26 -0
- package/assets/plan/svg/bathtub.svg +9 -0
- package/assets/plan/svg/bed-double.svg +9 -0
- package/assets/plan/svg/bed-single.svg +8 -0
- package/assets/plan/svg/cabinet.svg +9 -0
- package/assets/plan/svg/chair.svg +8 -0
- package/assets/plan/svg/desk.svg +9 -0
- package/assets/plan/svg/hedge-2m.svg +7 -0
- package/assets/plan/svg/kitchen-sink.svg +10 -0
- package/assets/plan/svg/locker.svg +9 -0
- package/assets/plan/svg/office-chair.svg +25 -0
- package/assets/plan/svg/potted-plant.svg +14 -0
- package/assets/plan/svg/refrigerator.svg +10 -0
- package/assets/plan/svg/shelf.svg +9 -0
- package/assets/plan/svg/shrub-1m.svg +7 -0
- package/assets/plan/svg/sofa-2.svg +9 -0
- package/assets/plan/svg/sofa-3.svg +9 -0
- package/assets/plan/svg/table-rect.svg +7 -0
- package/assets/plan/svg/table-round.svg +7 -0
- package/assets/plan/svg/tree-3m.svg +8 -0
- package/assets/plan/svg/urinal.svg +9 -0
- package/assets/plan/svg/washing-machine-pan.svg +13 -0
- package/assets/plan/svg/washing-machine.svg +10 -0
- package/assets/plan/svg/washstand-500.svg +12 -0
- package/assets/plan/svg/washstand.svg +12 -0
- package/assets/plan/svg/wc-cabinet.svg +14 -0
- package/assets/plan/svg/wc.svg +9 -0
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/core/components.d.ts +31 -0
- package/dist/core/components.d.ts.map +1 -0
- package/dist/core/components.js +167 -0
- package/dist/core/components.js.map +1 -0
- package/dist/core/derive.d.ts +9 -1
- package/dist/core/derive.d.ts.map +1 -1
- package/dist/core/derive.js +33 -3
- package/dist/core/derive.js.map +1 -1
- package/dist/core/diagnose.d.ts +6 -0
- package/dist/core/diagnose.d.ts.map +1 -1
- package/dist/core/diagnose.js +137 -4
- package/dist/core/diagnose.js.map +1 -1
- package/dist/core/model.d.ts +5 -5
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/model.js +6 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/parse.d.ts.map +1 -1
- package/dist/core/parse.js +5 -4
- package/dist/core/parse.js.map +1 -1
- package/dist/core/vocabulary.d.ts +20 -4
- package/dist/core/vocabulary.d.ts.map +1 -1
- package/dist/core/vocabulary.js +107 -9
- package/dist/core/vocabulary.js.map +1 -1
- package/dist/draw/component-files.d.ts +8 -0
- package/dist/draw/component-files.d.ts.map +1 -0
- package/dist/draw/component-files.js +35 -0
- package/dist/draw/component-files.js.map +1 -0
- package/dist/draw/component-svg.d.ts +14 -0
- package/dist/draw/component-svg.d.ts.map +1 -0
- package/dist/draw/component-svg.js +67 -0
- package/dist/draw/component-svg.js.map +1 -0
- package/dist/draw/conventions/architectural.d.ts +32 -0
- package/dist/draw/conventions/architectural.d.ts.map +1 -0
- package/dist/draw/conventions/architectural.js +29 -0
- package/dist/draw/conventions/architectural.js.map +1 -0
- package/dist/draw/index.d.ts +1 -1
- package/dist/draw/index.d.ts.map +1 -1
- package/dist/draw/index.js +1 -1
- package/dist/draw/index.js.map +1 -1
- package/dist/draw/marks.d.ts +37 -12
- package/dist/draw/marks.d.ts.map +1 -1
- package/dist/draw/marks.js +508 -38
- package/dist/draw/marks.js.map +1 -1
- package/dist/draw/plan.d.ts +3 -1
- package/dist/draw/plan.d.ts.map +1 -1
- package/dist/draw/plan.js +247 -85
- package/dist/draw/plan.js.map +1 -1
- package/dist/form.d.ts +1 -1
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp.js +21 -3
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -0
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +1 -0
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/builtin/index.d.ts +4 -2
- package/dist/validate/builtin/index.d.ts.map +1 -1
- package/dist/validate/builtin/index.js +9 -2
- package/dist/validate/builtin/index.js.map +1 -1
- package/dist/validate/builtin/opening-operations.d.ts +63 -0
- package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
- package/dist/validate/builtin/opening-operations.js +406 -0
- package/dist/validate/builtin/opening-operations.js.map +1 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +3 -3
- package/examples/basement/main.muro +3 -3
- package/examples/complex/L1.muro +1 -1
- package/examples/complex/assets.muro +2 -2
- package/examples/complex/main.muro +1 -1
- package/examples/house/L1.muro +3 -3
- package/examples/house/L2.muro +2 -2
- package/examples/house/assets.muro +8 -8
- package/examples/house/main.muro +1 -1
- package/examples/house/site.muro +2 -2
- package/examples/house.muro +6 -6
- package/examples/mansion.muro +1 -1
- package/examples/office.muro +1 -1
- package/examples/steps/06-finished.muro +1 -1
- package/examples/tower/assets.muro +1 -1
- package/examples/tower/main.muro +1 -1
- package/examples/twin/assets.muro +2 -2
- package/examples/twin/main.muro +1 -1
- package/examples/two-rooms.canonical.json +1 -1
- package/examples/two-rooms.muro +1 -1
- package/package.json +7 -4
- package/src/cli.ts +2 -2
- package/src/core/components.ts +224 -0
- package/src/core/derive.ts +47 -4
- package/src/core/diagnose.ts +182 -4
- package/src/core/model.ts +10 -5
- package/src/core/parse.ts +5 -4
- package/src/core/vocabulary.ts +115 -9
- package/src/draw/component-files.ts +36 -0
- package/src/draw/component-svg.ts +79 -0
- package/src/draw/conventions/architectural.ts +60 -0
- package/src/draw/index.ts +1 -1
- package/src/draw/marks.ts +564 -44
- package/src/draw/plan.ts +253 -88
- package/src/form.ts +1 -0
- package/src/index.ts +1 -1
- package/src/mcp.ts +21 -3
- package/src/parse-file.ts +1 -0
- package/src/validate/builtin/index.ts +14 -2
- package/src/validate/builtin/opening-operations.ts +519 -0
package/src/core/diagnose.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
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
|
-
/**
|
|
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
|
-
//
|
|
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.
|
|
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
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
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
|
-
//
|
|
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) {
|
package/src/core/vocabulary.ts
CHANGED
|
@@ -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(
|
|
179
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Asset } from "../core/model.js";
|
|
2
|
+
|
|
3
|
+
export interface ComponentSvg {
|
|
4
|
+
dataUri: string;
|
|
5
|
+
viewBox: { width: number; height: number };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validate an SVG before it is embedded as an isolated image. Isolation preserves Figma-style
|
|
10
|
+
* defs, masks and clip paths without letting IDs collide with the plan sheet.
|
|
11
|
+
*/
|
|
12
|
+
export function componentSvg(asset: Asset, source: string): ComponentSvg {
|
|
13
|
+
const text = source.trim();
|
|
14
|
+
const root = /<svg\b([^>]*)>/i.exec(text);
|
|
15
|
+
if (!root) throw new Error(`Component asset ${asset.name} plan-svg does not contain an svg root`);
|
|
16
|
+
const number = "[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?";
|
|
17
|
+
const viewBox = new RegExp(
|
|
18
|
+
`\\bviewBox\\s*=\\s*["']\\s*(${number})\\s+(${number})\\s+(${number})\\s+(${number})\\s*["']`,
|
|
19
|
+
"i",
|
|
20
|
+
).exec(root[1]!);
|
|
21
|
+
if (!viewBox) throw new Error(`Component asset ${asset.name} plan-svg requires a positive viewBox`);
|
|
22
|
+
const width = Number(viewBox[3]);
|
|
23
|
+
const height = Number(viewBox[4]);
|
|
24
|
+
if (!(width > 0 && height > 0)) throw new Error(`Component asset ${asset.name} plan-svg requires a positive viewBox`);
|
|
25
|
+
|
|
26
|
+
const forbidden = [
|
|
27
|
+
/<!DOCTYPE/i,
|
|
28
|
+
/<!ENTITY/i,
|
|
29
|
+
/<script\b/i,
|
|
30
|
+
/<foreignObject\b/i,
|
|
31
|
+
/<(?:animate|animateMotion|animateTransform|set)\b/i,
|
|
32
|
+
/\s(?:[A-Za-z_][\w.-]*:)?on[a-z]+\s*=/i,
|
|
33
|
+
/javascript\s*:/i,
|
|
34
|
+
/@import\b/i,
|
|
35
|
+
];
|
|
36
|
+
if (forbidden.some((pattern) => pattern.test(text))) {
|
|
37
|
+
throw new Error(`Component asset ${asset.name} plan-svg contains active or external content`);
|
|
38
|
+
}
|
|
39
|
+
for (const match of text.matchAll(/\b(?:href|src)\s*=\s*["']([^"']+)["']/gi)) {
|
|
40
|
+
const value = match[1]!;
|
|
41
|
+
if (!safeReference(value)) {
|
|
42
|
+
throw new Error(`Component asset ${asset.name} plan-svg contains an external reference: ${value}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const match of text.matchAll(/url\(\s*([^)]+?)\s*\)/gi)) {
|
|
46
|
+
const value = match[1]!.replace(/^["']|["']$/g, "").trim();
|
|
47
|
+
if (!safeReference(value)) {
|
|
48
|
+
throw new Error(`Component asset ${asset.name} plan-svg contains an external reference: ${value}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const w = asset.attrs["w"];
|
|
53
|
+
const d = asset.attrs["d"];
|
|
54
|
+
if (typeof w !== "number" || !(w > 0) || typeof d !== "number" || !(d > 0)) {
|
|
55
|
+
throw new Error(`Component asset ${asset.name} requires positive w: and d:`);
|
|
56
|
+
}
|
|
57
|
+
const sourceRatio = width / height;
|
|
58
|
+
const physicalRatio = w / d;
|
|
59
|
+
const ratioError = Math.abs(sourceRatio - physicalRatio) / physicalRatio;
|
|
60
|
+
if (ratioError > 0.001) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Component asset ${asset.name} plan-svg viewBox ratio ${round(sourceRatio)} does not match w:d ratio ${round(physicalRatio)}`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
dataUri: `data:image/svg+xml,${encodeURIComponent(text).replace(/'/g, "%27").replace(/"/g, "%22")}`,
|
|
68
|
+
viewBox: { width, height },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function safeReference(value: string): boolean {
|
|
73
|
+
if (value.startsWith("#")) return true;
|
|
74
|
+
return /^data:image\/(?:png|jpeg|webp|gif);base64,/i.test(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function round(value: number): number {
|
|
78
|
+
return Math.round(value * 10000) / 10000;
|
|
79
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Shared architectural plan conventions.
|
|
2
|
+
//
|
|
3
|
+
// These values describe paper symbols, never building geometry. They live outside core and Form
|
|
4
|
+
// so another drawing convention can replace them without changing a `.muro` file, canonical JSON,
|
|
5
|
+
// circulation, area or validation. The current set is broadly shared architectural practice; a
|
|
6
|
+
// jurisdiction module should override only a convention that is actually different.
|
|
7
|
+
|
|
8
|
+
export interface ArchitecturalPlanConvention {
|
|
9
|
+
readonly openings: {
|
|
10
|
+
/** Clear paper distance from the wall face to a sliding panel, in model millimetres. */
|
|
11
|
+
readonly slidingGapMm: number;
|
|
12
|
+
/** Extra overlap used to make two bypass leaves legible as separate panels. */
|
|
13
|
+
readonly bypassOverlapRatio: number;
|
|
14
|
+
/** Length of an automatic-door direction chevron relative to the aperture width. */
|
|
15
|
+
readonly automaticDirectionRatio: number;
|
|
16
|
+
/** Meeting point of the larger leaf in an unequal pair, measured from the first jamb. */
|
|
17
|
+
readonly unequalLeafMeetingRatio: number;
|
|
18
|
+
};
|
|
19
|
+
readonly stairs: {
|
|
20
|
+
/** How far an arrow enters a landing, relative to the narrower adjoining flight. */
|
|
21
|
+
readonly landingOffsetFlightWidthRatio: number;
|
|
22
|
+
readonly breakGlyph: {
|
|
23
|
+
/** Rotation from the line that crosses the flight. */
|
|
24
|
+
readonly angleDegrees: number;
|
|
25
|
+
/** Source-glyph proportions. The glyph is scaled to the flight width. */
|
|
26
|
+
readonly width: number;
|
|
27
|
+
readonly height: number;
|
|
28
|
+
readonly notch: number;
|
|
29
|
+
};
|
|
30
|
+
readonly arrowHead: {
|
|
31
|
+
/** SVG-space sizes: legibility belongs to paper, not to the building model. */
|
|
32
|
+
readonly length: number;
|
|
33
|
+
readonly halfWidth: number;
|
|
34
|
+
readonly startRadius: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ARCHITECTURAL_PLAN_CONVENTION: ArchitecturalPlanConvention = {
|
|
40
|
+
openings: {
|
|
41
|
+
slidingGapMm: 60,
|
|
42
|
+
bypassOverlapRatio: 0.12,
|
|
43
|
+
automaticDirectionRatio: 0.08,
|
|
44
|
+
unequalLeafMeetingRatio: 2 / 3,
|
|
45
|
+
},
|
|
46
|
+
stairs: {
|
|
47
|
+
landingOffsetFlightWidthRatio: 0.5,
|
|
48
|
+
breakGlyph: {
|
|
49
|
+
angleDegrees: 30,
|
|
50
|
+
width: 10,
|
|
51
|
+
height: 40,
|
|
52
|
+
notch: 3.5,
|
|
53
|
+
},
|
|
54
|
+
arrowHead: {
|
|
55
|
+
length: 8,
|
|
56
|
+
halfWidth: 3.5,
|
|
57
|
+
startRadius: 2.8,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|