@mark1russell7/room-view 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/build/{anchors-J6mcUeJn.js → anchors-Ba3OUmhF.js} +57 -3
- package/build/anchors-Ba3OUmhF.js.map +1 -0
- package/build/index.d.ts +5 -8
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -6
- package/build/index.js.map +1 -1
- package/build/layers-B5nL_lVW.js +247 -0
- package/build/layers-B5nL_lVW.js.map +1 -0
- package/build/layers-BO_MMtQJ.d.ts +294 -0
- package/build/layers-BO_MMtQJ.d.ts.map +1 -0
- package/build/{level-5Nb9rq5L.js → level-CXCIX08K.js} +125 -22
- package/build/level-CXCIX08K.js.map +1 -0
- package/build/{level-Bmz-H5iH.d.ts → level-Cjcf3u20.d.ts} +89 -6
- package/build/level-Cjcf3u20.d.ts.map +1 -0
- package/build/{loads-Bp8aH2HJ.d.ts → loads-Diy6-Ekz.d.ts} +2 -2
- package/build/{loads-Bp8aH2HJ.d.ts.map → loads-Diy6-Ekz.d.ts.map} +1 -1
- package/build/marks.d.ts +2 -3
- package/build/marks.d.ts.map +1 -1
- package/build/marks.js +2 -2
- package/build/sample.d.ts +2 -2
- package/build/schema.d.ts +3 -3
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +9 -6
- package/build/schema.js.map +1 -1
- package/build/solids-S_j17vFJ.d.ts +313 -0
- package/build/solids-S_j17vFJ.d.ts.map +1 -0
- package/build/three.d.ts +2 -3
- package/build/three.d.ts.map +1 -1
- package/build/three.js +1 -2
- package/build/three.js.map +1 -1
- package/package.json +1 -1
- package/build/anchors-BEnxNnSV.d.ts +0 -75
- package/build/anchors-BEnxNnSV.d.ts.map +0 -1
- package/build/anchors-J6mcUeJn.js.map +0 -1
- package/build/frames-BYMK5ZId.d.ts +0 -39
- package/build/frames-BYMK5ZId.d.ts.map +0 -1
- package/build/layers-CtgTEnmt.js +0 -90
- package/build/layers-CtgTEnmt.js.map +0 -1
- package/build/layers-D_HqUjYu.d.ts +0 -148
- package/build/layers-D_HqUjYu.d.ts.map +0 -1
- package/build/level-5Nb9rq5L.js.map +0 -1
- package/build/level-Bmz-H5iH.d.ts.map +0 -1
- package/build/room-DrXMmX_h.js +0 -29
- package/build/room-DrXMmX_h.js.map +0 -1
- package/build/room-NREa6vXr.d.ts +0 -163
- package/build/room-NREa6vXr.d.ts.map +0 -1
- package/build/solids-BHLnvDVu.d.ts +0 -120
- package/build/solids-BHLnvDVu.d.ts.map +0 -1
- package/build/units-BZmvVyu4.js +0 -30
- package/build/units-BZmvVyu4.js.map +0 -1
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/plan.ts","../src/form.ts"],"sourcesContent":["import { transformPoint3, type Ring } from \"@mark1russell7/layout-contract\";\nimport type { Scene } from \"./room.ts\";\nimport { sceneSolids, type Solid, type SolidKind, type SolidOptions } from \"./solids.ts\";\n\n/** The outline of one solid in the plan of a room: the solid as a camera above the room sees it. */\nexport interface PlanShape {\n /** The `id` of the solid. */\n readonly solid: string;\n readonly kind: SolidKind;\n /** The `id` of the record that the solid comes from. */\n readonly source: string;\n /** The outline in the plan, in meters. */\n readonly ring: Ring;\n /** The height of the bottom of the solid above the floor, in meters. */\n readonly bottom: number;\n /** The height of the top of the solid above the floor, in meters. */\n readonly top: number;\n}\n\n/**\n * This function gives the outline of a solid in the plan.\n * Each box of a model stands on its bottom face, so the outline of a box is that face.\n */\nexport function planShape(solid: Solid): PlanShape {\n const { id, kind, source, shape } = solid;\n if (shape.kind === \"prism\") return { solid: id, kind, source, ring: shape.ring, bottom: shape.z, top: shape.z + shape.d };\n const { box, transform } = shape;\n const face = [\n { x: box.x, y: box.y, z: box.z },\n { x: box.x + box.w, y: box.y, z: box.z },\n { x: box.x + box.w, y: box.y + box.h, z: box.z },\n { x: box.x, y: box.y + box.h, z: box.z },\n ].map((corner) => transformPoint3(transform, corner));\n const bottom = face[0]!.z;\n const top = transformPoint3(transform, { x: box.x, y: box.y, z: box.z + box.d }).z;\n return { solid: id, kind, source, ring: face.map((corner) => [corner.x, corner.y] as const), bottom: Math.min(bottom, top), top: Math.max(bottom, top) };\n}\n\n/** The options of a plan. */\nexport interface PlanOptions extends SolidOptions {\n /**\n * The height of the cut of the plan above the floor, in meters. The plan has only the solids with a bottom below the cut.\n * Thus a cut below the top of a door shows the door as a gap in its wall. Without a cut, the plan has each solid.\n */\n readonly cut?: number | undefined;\n}\n\n/**\n * This function gives the plan of a scene: the outline of each solid of its model.\n * The sequence goes from the solid with the lowest top to the solid with the highest top.\n * Thus a drawing in this sequence shows the room as a camera above it sees the room.\n */\nexport function planShapes(scene: Scene, options: PlanOptions = {}): readonly PlanShape[] {\n const cut = options.cut ?? Infinity;\n return sceneSolids(scene, options)\n .map((solid) => planShape(solid))\n .filter((shape) => shape.bottom < cut)\n .map((shape, index) => ({ shape, index }))\n .sort((a, b) => a.shape.top - b.shape.top || a.index - b.index)\n .map(({ shape }) => shape);\n}\n","import type { Anchor, AnchorSurface } from \"./anchors.ts\";\nimport { isLayerName } from \"./room.ts\";\n\n// The form of a layer: the collections of its records and the fields of each record, as data.\n// A page makes the inputs of an add-on from this data, so the page has no code of a topic.\n// The functions of this file give a layer from the records of a form, and the records of a form from a layer.\n// A record of a layer has this shape: its `id`, its `anchor` when it has a place, and one value for each field.\n\n/** These are the systems of units of a person. A usual value has one number for each system. */\nexport const FORM_SYSTEMS: readonly [\"metric\", \"imperial\"] = [\"metric\", \"imperial\"];\n\n/** A system of units of a person. */\nexport type FormSystem = (typeof FORM_SYSTEMS)[number];\n\n/** The usual value of a number for each system of units. A page shows it in a field that has no value. */\nexport type FormUsual = Readonly<Record<FormSystem, number>>;\n\n/** These are the kinds of a field of a record. */\nexport const FORM_FIELD_KINDS: readonly [\"text\", \"number\", \"record\", \"object\"] = [\"text\", \"number\", \"record\", \"object\"];\n\n/** The kind of a field of a record. */\nexport type FormFieldKind = (typeof FORM_FIELD_KINDS)[number];\n\n/** The parts that each field of a record has. */\nexport interface FormFieldPart {\n /** The name of the field in a record of the layer, for example `breaker`. */\n readonly name: string;\n /** The name of the field in a page, for example `Breaker`. */\n readonly label: string;\n /** This value is true when a record needs a value of the field. A record with no value of it is not in the layer. */\n readonly needed?: boolean | undefined;\n}\n\n/** A field with a text, for example the name of a circuit. */\nexport interface FormTextField extends FormFieldPart {\n readonly kind: \"text\";\n}\n\n/** A field with a number in a fixed unit, for example the rating of a breaker in amperes. */\nexport interface FormNumberField extends FormFieldPart {\n readonly kind: \"number\";\n /** The text of the unit in a page, for example `A`. */\n readonly unit?: string | undefined;\n /** The value of a record that has no value of the field. */\n readonly usual?: FormUsual | undefined;\n /** A valid value is above this number. */\n readonly above?: number | undefined;\n /** A valid value is this number or more. */\n readonly least?: number | undefined;\n /** The sentence of a page for a value that is not valid. It tells the person the value to type. */\n readonly fault?: string | undefined;\n}\n\n/** A field with the `id` of a record of a collection of the same layer, for example the circuit of an outlet. */\nexport interface FormRecordField extends FormFieldPart {\n readonly kind: \"record\";\n /** The name of the collection of the record. */\n readonly of: string;\n /** The text of a page for no record, for example `No circuit`. */\n readonly none?: string | undefined;\n /** The sentence of help of a page when the collection has no record. It tells the way to the first record. */\n readonly aid?: string | undefined;\n}\n\n/** A field with the `id` of a placed object of the scene, for example the object of a power feed. */\nexport interface FormObjectField extends FormFieldPart {\n readonly kind: \"object\";\n}\n\n/** A field of a record of a form. */\nexport type FormField = FormTextField | FormNumberField | FormRecordField | FormObjectField;\n\n/**\n * A collection of a form: the records of one field of a layer, for example the circuits.\n *\n * - A collection with `on` has records with a place. A page shows them with the surface of their anchor.\n * - A collection with `owner` has records of an owner. A page shows them with their owner.\n * - Each other collection is a list of the level.\n */\nexport interface FormCollection {\n /** The name of the field of the layer that has the records, for example `circuits`. */\n readonly name: string;\n /** The word of one record for its `id`. For example, `circuit` gives the `id` `circuit-1`. */\n readonly word: string;\n /** The name of one record in a page, for example `Circuit`. */\n readonly label: string;\n /** The title of the records in a page, for example `Circuits`. */\n readonly title: string;\n /** The surfaces of the anchor of a record. A collection with no surfaces has records with no place. */\n readonly on?: readonly AnchorSurface[] | undefined;\n /** The usual height of a record on a wall above the floor, in meters. */\n readonly height?: FormUsual | undefined;\n /** The fields of a record, in the sequence of a page. */\n readonly fields: readonly FormField[];\n /** The name of the text field that gives the words of the `id` of a record. Without it, the `id` has the word and a number. */\n readonly idFrom?: string | undefined;\n /** The name of the field that names the owner of a record. It is a necessary field of the kind `object` or `record`. */\n readonly owner?: string | undefined;\n /** The largest number of records of one owner. */\n readonly most?: number | undefined;\n}\n\n/** The form of a layer. The add-on of the layer gives it as data. */\nexport interface LayerForm {\n /** The name of the format of the layer, for example `electrical/1`. */\n readonly schema: string;\n /** The collections of the layer, in the sequence of a page. */\n readonly collections: readonly FormCollection[];\n}\n\n/** These are the codes of the faults of a form. */\nexport const FORM_CODES: readonly [\"form-schema\", \"form-collection\", \"form-field\"] = [\"form-schema\", \"form-collection\", \"form-field\"];\n\n/** The code of a fault of a form. */\nexport type FormCode = (typeof FORM_CODES)[number];\n\n/** A fault of a form. */\nexport interface FormFault {\n readonly code: FormCode;\n /** The name of the collection, or the names of the collection and of the field with a point between them. For the form, it is empty. */\n readonly at: string;\n /** The fault in plain words, with the values. */\n readonly message: string;\n}\n\n/** The names that a field cannot have: the parts of each record, and a name that changes an object of JavaScript. */\nconst RESERVED: ReadonlySet<string> = new Set([\"id\", \"anchor\", \"__proto__\"]);\n\n/** This function tells if a number is a valid value of a number field. */\nfunction numberFits(field: FormNumberField, value: number): boolean {\n return Number.isFinite(value) && (field.above === undefined || value > field.above) && (field.least === undefined || value >= field.least);\n}\n\n/** This function gives the names that are in a list two times or more. */\nfunction repeated(names: readonly string[]): ReadonlySet<string> {\n const seen = new Set<string>();\n const twice = new Set<string>();\n for (const name of names) (seen.has(name) ? twice : seen).add(name);\n return twice;\n}\n\n/**\n * This function gives the faults of a form. A form with no fault is safe for `formLayer` and `formRecords`.\n * The test of an add-on examines its form with this function.\n */\nexport function checkForm(form: LayerForm): readonly FormFault[] {\n const faults: FormFault[] = [];\n if (!isLayerName(form.schema)) {\n faults.push({ code: \"form-schema\", at: \"\", message: `The form has the name \"${form.schema}\", which is not a word, a slash and a version, for example \"electrical/1\".` });\n }\n const names = new Set(form.collections.map((collection) => collection.name));\n const twice = repeated(form.collections.map((collection) => collection.name));\n for (const collection of form.collections) {\n const at = collection.name;\n const fault = (message: string): void => {\n faults.push({ code: \"form-collection\", at, message: `The collection \"${at}\" ${message}` });\n };\n if (at === \"\" || at === \"schema\" || at === \"__proto__\") fault(\"has a name that a layer cannot have.\");\n if (twice.has(at)) fault(\"is in the form two times.\");\n if (collection.word === \"\") fault(\"has no word for the ids of its records.\");\n if (collection.on !== undefined && (collection.on.length === 0 || repeated(collection.on).size > 0)) fault(\"has a list of surfaces that is empty, or that has a surface two times.\");\n if (collection.height !== undefined && !(collection.on ?? []).includes(\"wall\")) fault(\"has a usual height, and its records are not on a wall.\");\n if (collection.height !== undefined && !FORM_SYSTEMS.every((system) => Number.isFinite(collection.height?.[system]))) fault(\"has a usual height that is not a number.\");\n if (collection.most !== undefined && (!Number.isInteger(collection.most) || collection.most < 1)) fault(`has the largest number ${String(collection.most)}, which is not an integer of 1 or more.`);\n if (collection.most !== undefined && collection.owner === undefined) fault(\"has a largest number of records of one owner, and it has no owner.\");\n const fields = new Map(collection.fields.map((field) => [field.name, field]));\n if (collection.owner !== undefined) {\n const owner = fields.get(collection.owner);\n if (owner === undefined || owner.needed !== true || (owner.kind !== \"object\" && owner.kind !== \"record\")) {\n fault(`has the owner \"${collection.owner}\", which is not a necessary field of the kind \"object\" or \"record\".`);\n }\n }\n if (collection.idFrom !== undefined && fields.get(collection.idFrom)?.kind !== \"text\") fault(`takes its ids from \"${collection.idFrom}\", which is not a text field.`);\n const twiceFields = repeated(collection.fields.map((field) => field.name));\n for (const field of collection.fields) {\n const place = `${at}.${field.name}`;\n const fieldFault = (message: string): void => {\n faults.push({ code: \"form-field\", at: place, message: `The field \"${field.name}\" of the collection \"${at}\" ${message}` });\n };\n if (field.name === \"\" || RESERVED.has(field.name)) fieldFault(\"has a name that a field cannot have.\");\n if (twiceFields.has(field.name)) fieldFault(\"is in the collection two times.\");\n if (field.kind === \"record\" && !names.has(field.of)) fieldFault(`names the collection \"${field.of}\", which the form does not have.`);\n if (field.kind === \"number\") {\n if ((field.above !== undefined && !Number.isFinite(field.above)) || (field.least !== undefined && !Number.isFinite(field.least))) fieldFault(\"has a limit that is not a number.\");\n if (field.usual !== undefined && !FORM_SYSTEMS.every((system) => numberFits(field, field.usual?.[system] ?? Number.NaN))) fieldFault(\"has a usual value that is not a valid value.\");\n }\n }\n }\n return faults;\n}\n\n/** A value of a field: a text, a number, or the `id` of a record or of a placed object. */\nexport type FormValue = string | number;\n\n/** A record of a form: the values that a person gave. */\nexport interface FormRecord {\n readonly id: string;\n /** The place of the record, for a collection with surfaces. */\n readonly anchor?: Anchor | undefined;\n /** The value of each field, by the name of the field. A field with no value is absent. */\n readonly values: Readonly<Record<string, FormValue>>;\n}\n\n/** The records of a form, by the name of each collection. */\nexport type FormRecords = Readonly<Record<string, readonly FormRecord[]>>;\n\n/**\n * The read of a record: its valid values, or the first field that stops the record.\n * The state `empty` tells a necessary field with no value, and the state `bad` tells a value that is not valid. The field of the place is `anchor`.\n */\nexport type FormReading = { readonly state: \"ok\"; readonly values: Readonly<Record<string, FormValue>> } | { readonly state: \"empty\" | \"bad\"; readonly field: string };\n\n/** This function gives the value of a field in the values of a record. A field that the values do not have gives `undefined`. */\nfunction valueOf(values: Readonly<Record<string, FormValue>>, name: string): FormValue | undefined {\n return Object.hasOwn(values, name) ? values[name] : undefined;\n}\n\n/**\n * This function reads the values of a record of a collection.\n *\n * - A number field with no value gets its usual value for the system.\n * - A text loses the spaces at its ends. An empty text is no value.\n * - A number that is not valid, or a value of a different type, stops the record.\n * - A necessary field with no value stops the record. A collection with surfaces needs an anchor on one of them.\n *\n * The function does not examine if a record or an object of a field is there. `formLayer` examines it.\n */\nexport function readFormRecord(collection: FormCollection, record: FormRecord, system: FormSystem): FormReading {\n if (collection.on !== undefined) {\n if (record.anchor === undefined) return { state: \"empty\", field: \"anchor\" };\n if (!collection.on.includes(record.anchor.on)) return { state: \"bad\", field: \"anchor\" };\n }\n const values: [string, FormValue][] = [];\n for (const field of collection.fields) {\n const given = valueOf(record.values, field.name);\n if (field.kind === \"number\") {\n const value = given ?? field.usual?.[system];\n if (value === undefined) {\n if (field.needed === true) return { state: \"empty\", field: field.name };\n continue;\n }\n if (typeof value !== \"number\" || !numberFits(field, value)) return { state: \"bad\", field: field.name };\n values.push([field.name, value]);\n continue;\n }\n if (given !== undefined && typeof given !== \"string\") return { state: \"bad\", field: field.name };\n const text = field.kind === \"text\" ? (given ?? \"\").trim() : (given ?? \"\");\n if (text === \"\") {\n if (field.needed === true) return { state: \"empty\", field: field.name };\n continue;\n }\n values.push([field.name, text]);\n }\n return { state: \"ok\", values: Object.fromEntries(values) };\n}\n\n/** A record that a layer can have: its values are valid. */\ninterface Kept {\n readonly id: string;\n readonly anchor: Anchor | undefined;\n /** The values of the record. `settle` removes a value that names a record that is not there. */\n values: Readonly<Record<string, FormValue>>;\n}\n\n/**\n * This function removes each part that names a record or an object that is not there, one time. It gives true when it removed a part.\n *\n * - A field of a record that is not in its collection loses its value. A field of an object that is not in `objects` loses its value too.\n * - A record with no value of a necessary field goes away.\n * - A record after the largest number of records of its owner goes away.\n */\nfunction settleOnce(form: LayerForm, kept: Map<string, Kept[]>, objects: ReadonlySet<string> | undefined): boolean {\n let changed = false;\n const ids = new Map<string, ReadonlySet<string>>();\n for (const collection of form.collections) ids.set(collection.name, new Set((kept.get(collection.name) ?? []).map((record) => record.id)));\n for (const collection of form.collections) {\n const counts = new Map<string, number>();\n const list: Kept[] = [];\n for (const record of kept.get(collection.name) ?? []) {\n let stays = true;\n for (const field of collection.fields) {\n const value = valueOf(record.values, field.name);\n if (typeof value !== \"string\" || field.kind === \"text\" || field.kind === \"number\") continue;\n const there = field.kind === \"record\" ? ids.get(field.of)?.has(value) === true : objects === undefined || objects.has(value);\n if (there) continue;\n changed = true;\n if (field.needed === true) stays = false;\n else record.values = Object.fromEntries(Object.entries(record.values).filter(([name]) => name !== field.name));\n }\n if (stays && collection.owner !== undefined && collection.most !== undefined) {\n const owner = String(valueOf(record.values, collection.owner) ?? \"\");\n const count = (counts.get(owner) ?? 0) + 1;\n counts.set(owner, count);\n if (count > collection.most) {\n changed = true;\n stays = false;\n }\n }\n if (stays) list.push(record);\n }\n kept.set(collection.name, list);\n }\n return changed;\n}\n\n/**\n * This function removes each part that names a record or an object that is not there. It gives true when it removed a part.\n * A record that goes away can be the record of a field, so the function repeats `settleOnce` until nothing changes.\n */\nfunction settle(form: LayerForm, kept: Map<string, Kept[]>, objects: ReadonlySet<string> | undefined): boolean {\n let removed = false;\n while (settleOnce(form, kept, objects)) removed = true;\n return removed;\n}\n\n/** The options of `formLayer`. */\nexport interface FormLayerOptions {\n /** The system of units of the person, for the usual value of each number. */\n readonly system: FormSystem;\n /** The ids of the placed objects of the scene. With it, a field of the kind `object` keeps only an `id` of the set. */\n readonly objects?: ReadonlySet<string> | undefined;\n}\n\n/** A layer from the records of a form: its name, and the records of each collection that has records. */\nexport type FormLayer = Readonly<Record<string, unknown>> & { readonly schema: string };\n\n/**\n * This function makes the layer of the records of a form. It is total: a record that the layer cannot have is not in the layer.\n *\n * - `readFormRecord` reads each record. A record that it stops is not in the layer.\n * - The ids of a layer are unique. The first record of an `id` stays, in the sequence of the collections.\n * - A field that names a record that is not in the layer has no value. A record with no value of a necessary field is not in the layer.\n * - A collection with no record is not in the layer.\n *\n * A record of the layer has its `id`, then its `anchor`, then its values in the sequence of the fields. Thus equal records give equal JSON.\n * The add-on of the layer reads the result with its `parse`, and `checkLayers` examines it.\n */\nexport function formLayer(form: LayerForm, records: FormRecords, options: FormLayerOptions): FormLayer {\n const kept = new Map<string, Kept[]>();\n const seen = new Set<string>();\n for (const collection of form.collections) {\n const list: Kept[] = [];\n for (const record of Object.hasOwn(records, collection.name) ? (records[collection.name] ?? []) : []) {\n if (record.id === \"\" || seen.has(record.id)) continue;\n const reading = readFormRecord(collection, record, options.system);\n if (reading.state !== \"ok\") continue;\n seen.add(record.id);\n list.push({ id: record.id, anchor: collection.on === undefined ? undefined : record.anchor, values: reading.values });\n }\n kept.set(collection.name, list);\n }\n settle(form, kept, options.objects);\n const layer: [string, unknown][] = [[\"schema\", form.schema]];\n for (const collection of form.collections) {\n const list = kept.get(collection.name) ?? [];\n if (list.length === 0) continue;\n layer.push([\n collection.name,\n list.map((record) => {\n const item: [string, unknown][] = [[\"id\", record.id]];\n if (record.anchor !== undefined) item.push([\"anchor\", record.anchor]);\n for (const field of collection.fields) {\n const value = valueOf(record.values, field.name);\n if (value !== undefined) item.push([field.name, value]);\n }\n return Object.fromEntries(item);\n }),\n ]);\n }\n return Object.fromEntries(layer) as FormLayer;\n}\n\n/** The records of a form from a layer. */\nexport interface FormRecordsRead {\n /** The records of each collection of the form. A collection with no record has an empty list. */\n readonly records: FormRecords;\n /** This value is true when the layer has data that the form does not keep. */\n readonly more: boolean;\n}\n\nconst isObject = (value: unknown): value is Readonly<Record<string, unknown>> => typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/**\n * This function gives the records of a form from a layer. Give it a layer that its add-on read: the function does not examine the form of an anchor.\n *\n * The form does not keep these data, and `more` tells them:\n *\n * - a field of the layer or of a record that the form does not have\n * - a record with no `id`, or with the `id` of an earlier record\n * - a record of a collection with surfaces that has no anchor on one of them\n * - a value that is not a valid value of its field\n * - a field that names a record that the layer does not have\n * - a record after the largest number of records of its owner\n *\n * The records of a layer of `formLayer` are the records that the layer has, and `more` is false for them.\n */\nexport function formRecords(form: LayerForm, layer: unknown): FormRecordsRead {\n const kept = new Map<string, Kept[]>();\n for (const collection of form.collections) kept.set(collection.name, []);\n let more = false;\n if (isObject(layer)) {\n const names = new Set(form.collections.map((collection) => collection.name));\n if (Object.keys(layer).some((key) => key !== \"schema\" && !names.has(key))) more = true;\n const seen = new Set<string>();\n for (const collection of form.collections) {\n const given = Object.hasOwn(layer, collection.name) ? layer[collection.name] : undefined;\n if (given === undefined) continue;\n if (!Array.isArray(given)) {\n more = true;\n continue;\n }\n const known = new Set([\"id\", ...(collection.on === undefined ? [] : [\"anchor\"]), ...collection.fields.map((field) => field.name)]);\n const list: Kept[] = [];\n for (const item of given as readonly unknown[]) {\n const id = isObject(item) ? item[\"id\"] : undefined;\n if (!isObject(item) || typeof id !== \"string\" || id === \"\" || seen.has(id)) {\n more = true;\n continue;\n }\n const anchor = item[\"anchor\"];\n const surfaces: readonly string[] = collection.on ?? [];\n if (collection.on !== undefined && !(isObject(anchor) && typeof anchor[\"on\"] === \"string\" && surfaces.includes(anchor[\"on\"]))) {\n more = true;\n continue;\n }\n if (Object.keys(item).some((key) => !known.has(key))) more = true;\n const values: [string, FormValue][] = [];\n for (const field of collection.fields) {\n const value = Object.hasOwn(item, field.name) ? item[field.name] : undefined;\n if (value === undefined) continue;\n if (field.kind === \"number\") {\n if (typeof value === \"number\" && numberFits(field, value)) values.push([field.name, value]);\n else more = true;\n } else if (typeof value !== \"string\") more = true;\n else if (field.kind === \"text\") {\n // The spaces at the ends of a text are not data, and an empty text is no value.\n if (value.trim() !== \"\") values.push([field.name, value.trim()]);\n } else if (value === \"\") more = true;\n else values.push([field.name, value]);\n }\n seen.add(id);\n list.push({ id, anchor: collection.on === undefined ? undefined : (anchor as Anchor), values: Object.fromEntries(values) });\n }\n kept.set(collection.name, list);\n }\n // A record with no value of a necessary field is not a record of the form.\n for (const collection of form.collections) {\n const needed = collection.fields.filter((field) => field.needed === true);\n // A number with a usual value has a value in each layer of `formLayer`, so it does not stop a record.\n const has = (record: Kept, field: FormField): boolean => valueOf(record.values, field.name) !== undefined || (field.kind === \"number\" && field.usual !== undefined);\n const list = (kept.get(collection.name) ?? []).filter((record) => needed.every((field) => has(record, field)));\n if (list.length !== (kept.get(collection.name) ?? []).length) more = true;\n kept.set(collection.name, list);\n }\n if (settle(form, kept, undefined)) more = true;\n } else if (layer !== undefined) more = true;\n const records: [string, readonly FormRecord[]][] = form.collections.map((collection) => [\n collection.name,\n (kept.get(collection.name) ?? []).map((record): FormRecord => ({ id: record.id, ...(record.anchor === undefined ? {} : { anchor: record.anchor }), values: record.values })),\n ]);\n return { records: Object.fromEntries(records), more };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,SAAgB,UAAU,OAAyB;CACjD,MAAM,EAAE,IAAI,MAAM,QAAQ,UAAU;CACpC,IAAI,MAAM,SAAS,SAAS,OAAO;EAAE,OAAO;EAAI;EAAM;EAAQ,MAAM,MAAM;EAAM,QAAQ,MAAM;EAAG,KAAK,MAAM,IAAI,MAAM;CAAE;CACxH,MAAM,EAAE,KAAK,cAAc;CAC3B,MAAM,OAAO;EACX;GAAE,GAAG,IAAI;GAAG,GAAG,IAAI;GAAG,GAAG,IAAI;EAAE;EAC/B;GAAE,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI;GAAG,GAAG,IAAI;EAAE;EACvC;GAAE,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI;EAAE;EAC/C;GAAE,GAAG,IAAI;GAAG,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI;EAAE;CACzC,CAAC,CAAC,KAAK,WAAW,gBAAgB,WAAW,MAAM,CAAC;CACpD,MAAM,SAAS,KAAK,EAAE,CAAE;CACxB,MAAM,MAAM,gBAAgB,WAAW;EAAE,GAAG,IAAI;EAAG,GAAG,IAAI;EAAG,GAAG,IAAI,IAAI,IAAI;CAAE,CAAC,CAAC,CAAC;CACjF,OAAO;EAAE,OAAO;EAAI;EAAM;EAAQ,MAAM,KAAK,KAAK,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC,CAAU;EAAG,QAAQ,KAAK,IAAI,Q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O,OAAO,UAAU,IAAI,QAAQ,KAAK,CAAC,CAAC;GAC7G,IAAI,KAAK,YAAY,KAAK,IAAI,WAAW,IAAI,KAAK,CAAC,EAAA,CAAG,QAAQ,OAAO;GACrE,KAAK,IAAI,WAAW,MAAM,IAAI;EAChC;EACA,IAAI,OAAO,MAAM,MAAM,KAAA,CAAS,GAAG,OAAO;CAC5C,OAAO,IAAI,UAAU,KAAA,GAAW,OAAO;CACvC,MAAM,UAA6C,KAAK,YAAY,KAAK,eAAe,CACtF,WAAW,OACV,KAAK,IAAI,WAAW,IAAI,KAAK,CAAC,EAAA,CAAG,KAAK,YAAwB;EAAE,IAAI,OAAO;EAAI,GAAI,OAAO,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,OAAO,OAAO;EAAI,QAAQ,OAAO;CAAO,EAAE,CAC7K,CAAC;CACD,OAAO;EAAE,SAAS,OAAO,YAAY,OAAO;EAAG;CAAK;AACtD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/plan.ts","../src/form.ts"],"sourcesContent":["import { transformPoint3, type Ring } from \"@mark1russell7/layout-contract\";\nimport type { Scene } from \"./room.ts\";\nimport { sceneSolids, type Solid, type SolidKind, type SolidOptions } from \"./solids.ts\";\n\n/** The outline of one solid in the plan of a room: the solid as a camera above the room sees it. */\nexport interface PlanShape {\n /** The `id` of the solid. */\n readonly solid: string;\n readonly kind: SolidKind;\n /** The `id` of the record that the solid comes from. */\n readonly source: string;\n /** The outline in the plan, in meters. */\n readonly ring: Ring;\n /** The height of the bottom of the solid above the floor, in meters. */\n readonly bottom: number;\n /** The height of the top of the solid above the floor, in meters. */\n readonly top: number;\n}\n\n/**\n * This function gives the outline of a solid in the plan.\n * Each box of a model stands on its bottom face, so the outline of a box is that face.\n */\nexport function planShape(solid: Solid): PlanShape {\n const { id, kind, source, shape } = solid;\n if (shape.kind === \"prism\") return { solid: id, kind, source, ring: shape.ring, bottom: shape.z, top: shape.z + shape.d };\n const { box, transform } = shape;\n const face = [\n { x: box.x, y: box.y, z: box.z },\n { x: box.x + box.w, y: box.y, z: box.z },\n { x: box.x + box.w, y: box.y + box.h, z: box.z },\n { x: box.x, y: box.y + box.h, z: box.z },\n ].map((corner) => transformPoint3(transform, corner));\n const bottom = face[0]!.z;\n const top = transformPoint3(transform, { x: box.x, y: box.y, z: box.z + box.d }).z;\n return { solid: id, kind, source, ring: face.map((corner) => [corner.x, corner.y] as const), bottom: Math.min(bottom, top), top: Math.max(bottom, top) };\n}\n\n/** The options of a plan. */\nexport interface PlanOptions extends SolidOptions {\n /**\n * The height of the cut of the plan above the floor, in meters. The plan has only the solids with a bottom below the cut.\n * Thus a cut below the top of a door shows the door as a gap in its wall. Without a cut, the plan has each solid.\n */\n readonly cut?: number | undefined;\n}\n\n/**\n * This function gives the plan of a scene: the outline of each solid of its model.\n * The sequence goes from the solid with the lowest top to the solid with the highest top.\n * Thus a drawing in this sequence shows the room as a camera above it sees the room.\n */\nexport function planShapes(scene: Scene, options: PlanOptions = {}): readonly PlanShape[] {\n const cut = options.cut ?? Infinity;\n return sceneSolids(scene, options)\n .map((solid) => planShape(solid))\n .filter((shape) => shape.bottom < cut)\n .map((shape, index) => ({ shape, index }))\n .sort((a, b) => a.shape.top - b.shape.top || a.index - b.index)\n .map(({ shape }) => shape);\n}\n","import type { Anchor, AnchorSurface } from \"./anchors.ts\";\nimport { isLayerName } from \"./room.ts\";\n\n// The form of a layer: the collections of its records and the fields of each record, as data.\n// A page makes the inputs of an add-on from this data, so the page has no code of a topic.\n// The functions of this file give a layer from the records of a form, and the records of a form from a layer.\n// A record of a layer has this shape: its `id`, its `anchor` when it has a place, and one value for each field.\n\n/** These are the systems of units of a person. A usual value has one number for each system. */\nexport const FORM_SYSTEMS: readonly [\"metric\", \"imperial\"] = [\"metric\", \"imperial\"];\n\n/** A system of units of a person. */\nexport type FormSystem = (typeof FORM_SYSTEMS)[number];\n\n/** The usual value of a number for each system of units. A page shows it in a field that has no value. */\nexport type FormUsual = Readonly<Record<FormSystem, number>>;\n\n/** These are the kinds of a field of a record. */\nexport const FORM_FIELD_KINDS: readonly [\"text\", \"number\", \"record\", \"object\"] = [\"text\", \"number\", \"record\", \"object\"];\n\n/** The kind of a field of a record. */\nexport type FormFieldKind = (typeof FORM_FIELD_KINDS)[number];\n\n/** The parts that each field of a record has. */\nexport interface FormFieldPart {\n /** The name of the field in a record of the layer, for example `breaker`. */\n readonly name: string;\n /** The name of the field in a page, for example `Breaker`. */\n readonly label: string;\n /** This value is true when a record needs a value of the field. A record with no value of it is not in the layer. */\n readonly needed?: boolean | undefined;\n}\n\n/** A field with a text, for example the name of a circuit. */\nexport interface FormTextField extends FormFieldPart {\n readonly kind: \"text\";\n}\n\n/** A field with a number in a fixed unit, for example the rating of a breaker in amperes. */\nexport interface FormNumberField extends FormFieldPart {\n readonly kind: \"number\";\n /** The text of the unit in a page, for example `A`. */\n readonly unit?: string | undefined;\n /** The value of a record that has no value of the field. */\n readonly usual?: FormUsual | undefined;\n /** A valid value is above this number. */\n readonly above?: number | undefined;\n /** A valid value is this number or more. */\n readonly least?: number | undefined;\n /** The sentence of a page for a value that is not valid. It tells the person the value to type. */\n readonly fault?: string | undefined;\n}\n\n/** A field with the `id` of a record of a collection of the same layer, for example the circuit of an outlet. */\nexport interface FormRecordField extends FormFieldPart {\n readonly kind: \"record\";\n /** The name of the collection of the record. */\n readonly of: string;\n /** The text of a page for no record, for example `No circuit`. */\n readonly none?: string | undefined;\n /** The sentence of help of a page when the collection has no record. It tells the way to the first record. */\n readonly aid?: string | undefined;\n}\n\n/** A field with the `id` of a placed object of the scene, for example the object of a power feed. */\nexport interface FormObjectField extends FormFieldPart {\n readonly kind: \"object\";\n}\n\n/** A field of a record of a form. */\nexport type FormField = FormTextField | FormNumberField | FormRecordField | FormObjectField;\n\n/**\n * A collection of a form: the records of one field of a layer, for example the circuits.\n *\n * - A collection with `on` has records with a place. A page shows them with the surface of their anchor.\n * - A collection with `owner` has records of an owner. A page shows them with their owner.\n * - Each other collection is a list of the level.\n */\nexport interface FormCollection {\n /** The name of the field of the layer that has the records, for example `circuits`. */\n readonly name: string;\n /** The word of one record for its `id`. For example, `circuit` gives the `id` `circuit-1`. */\n readonly word: string;\n /** The name of one record in a page, for example `Circuit`. */\n readonly label: string;\n /** The title of the records in a page, for example `Circuits`. */\n readonly title: string;\n /** The surfaces of the anchor of a record. A collection with no surfaces has records with no place. */\n readonly on?: readonly AnchorSurface[] | undefined;\n /** The usual height of a record on a wall above the floor, in meters. */\n readonly height?: FormUsual | undefined;\n /** The fields of a record, in the sequence of a page. */\n readonly fields: readonly FormField[];\n /** The name of the text field that gives the words of the `id` of a record. Without it, the `id` has the word and a number. */\n readonly idFrom?: string | undefined;\n /** The name of the field that names the owner of a record. It is a necessary field of the kind `object` or `record`. */\n readonly owner?: string | undefined;\n /** The largest number of records of one owner. */\n readonly most?: number | undefined;\n}\n\n/** The form of a layer. The add-on of the layer gives it as data. */\nexport interface LayerForm {\n /** The name of the format of the layer, for example `electrical/1`. */\n readonly schema: string;\n /** The collections of the layer, in the sequence of a page. */\n readonly collections: readonly FormCollection[];\n}\n\n/** These are the codes of the faults of a form. */\nexport const FORM_CODES: readonly [\"form-schema\", \"form-collection\", \"form-field\"] = [\"form-schema\", \"form-collection\", \"form-field\"];\n\n/** The code of a fault of a form. */\nexport type FormCode = (typeof FORM_CODES)[number];\n\n/** A fault of a form. */\nexport interface FormFault {\n readonly code: FormCode;\n /** The name of the collection, or the names of the collection and of the field with a point between them. For the form, it is empty. */\n readonly at: string;\n /** The fault in plain words, with the values. */\n readonly message: string;\n}\n\n/** The names that a field cannot have: the parts of each record, and a name that changes an object of JavaScript. */\nconst RESERVED: ReadonlySet<string> = new Set([\"id\", \"anchor\", \"__proto__\"]);\n\n/** This function tells if a number is a valid value of a number field. */\nfunction numberFits(field: FormNumberField, value: number): boolean {\n return Number.isFinite(value) && (field.above === undefined || value > field.above) && (field.least === undefined || value >= field.least);\n}\n\n/** This function gives the names that are in a list two times or more. */\nfunction repeated(names: readonly string[]): ReadonlySet<string> {\n const seen = new Set<string>();\n const twice = new Set<string>();\n for (const name of names) (seen.has(name) ? twice : seen).add(name);\n return twice;\n}\n\n/**\n * This function gives the faults of a form. A form with no fault is safe for `formLayer` and `formRecords`.\n * The test of an add-on examines its form with this function.\n */\nexport function checkForm(form: LayerForm): readonly FormFault[] {\n const faults: FormFault[] = [];\n if (!isLayerName(form.schema)) {\n faults.push({ code: \"form-schema\", at: \"\", message: `The form has the name \"${form.schema}\", which is not a word, a slash and a version, for example \"electrical/1\".` });\n }\n const names = new Set(form.collections.map((collection) => collection.name));\n const twice = repeated(form.collections.map((collection) => collection.name));\n for (const collection of form.collections) {\n const at = collection.name;\n const fault = (message: string): void => {\n faults.push({ code: \"form-collection\", at, message: `The collection \"${at}\" ${message}` });\n };\n if (at === \"\" || at === \"schema\" || at === \"__proto__\") fault(\"has a name that a layer cannot have.\");\n if (twice.has(at)) fault(\"is in the form two times.\");\n if (collection.word === \"\") fault(\"has no word for the ids of its records.\");\n if (collection.on !== undefined && (collection.on.length === 0 || repeated(collection.on).size > 0)) fault(\"has a list of surfaces that is empty, or that has a surface two times.\");\n if (collection.height !== undefined && !(collection.on ?? []).includes(\"wall\")) fault(\"has a usual height, and its records are not on a wall.\");\n if (collection.height !== undefined && !FORM_SYSTEMS.every((system) => Number.isFinite(collection.height?.[system]))) fault(\"has a usual height that is not a number.\");\n if (collection.most !== undefined && (!Number.isInteger(collection.most) || collection.most < 1)) fault(`has the largest number ${String(collection.most)}, which is not an integer of 1 or more.`);\n if (collection.most !== undefined && collection.owner === undefined) fault(\"has a largest number of records of one owner, and it has no owner.\");\n const fields = new Map(collection.fields.map((field) => [field.name, field]));\n if (collection.owner !== undefined) {\n const owner = fields.get(collection.owner);\n if (owner === undefined || owner.needed !== true || (owner.kind !== \"object\" && owner.kind !== \"record\")) {\n fault(`has the owner \"${collection.owner}\", which is not a necessary field of the kind \"object\" or \"record\".`);\n }\n }\n if (collection.idFrom !== undefined && fields.get(collection.idFrom)?.kind !== \"text\") fault(`takes its ids from \"${collection.idFrom}\", which is not a text field.`);\n const twiceFields = repeated(collection.fields.map((field) => field.name));\n for (const field of collection.fields) {\n const place = `${at}.${field.name}`;\n const fieldFault = (message: string): void => {\n faults.push({ code: \"form-field\", at: place, message: `The field \"${field.name}\" of the collection \"${at}\" ${message}` });\n };\n if (field.name === \"\" || RESERVED.has(field.name)) fieldFault(\"has a name that a field cannot have.\");\n if (twiceFields.has(field.name)) fieldFault(\"is in the collection two times.\");\n if (field.kind === \"record\" && !names.has(field.of)) fieldFault(`names the collection \"${field.of}\", which the form does not have.`);\n if (field.kind === \"number\") {\n if ((field.above !== undefined && !Number.isFinite(field.above)) || (field.least !== undefined && !Number.isFinite(field.least))) fieldFault(\"has a limit that is not a number.\");\n if (field.usual !== undefined && !FORM_SYSTEMS.every((system) => numberFits(field, field.usual?.[system] ?? Number.NaN))) fieldFault(\"has a usual value that is not a valid value.\");\n }\n }\n }\n return faults;\n}\n\n/** A value of a field: a text, a number, or the `id` of a record or of a placed object. */\nexport type FormValue = string | number;\n\n/** A record of a form: the values that a person gave. */\nexport interface FormRecord {\n readonly id: string;\n /** The place of the record, for a collection with surfaces. */\n readonly anchor?: Anchor | undefined;\n /** The value of each field, by the name of the field. A field with no value is absent. */\n readonly values: Readonly<Record<string, FormValue>>;\n}\n\n/** The records of a form, by the name of each collection. */\nexport type FormRecords = Readonly<Record<string, readonly FormRecord[]>>;\n\n/**\n * The read of a record: its valid values, or the first field that stops the record.\n * The state `empty` tells a necessary field with no value, and the state `bad` tells a value that is not valid. The field of the place is `anchor`.\n */\nexport type FormReading = { readonly state: \"ok\"; readonly values: Readonly<Record<string, FormValue>> } | { readonly state: \"empty\" | \"bad\"; readonly field: string };\n\n/** This function gives the value of a field in the values of a record. A field that the values do not have gives `undefined`. */\nfunction valueOf(values: Readonly<Record<string, FormValue>>, name: string): FormValue | undefined {\n return Object.hasOwn(values, name) ? values[name] : undefined;\n}\n\n/**\n * This function reads the values of a record of a collection.\n *\n * - A number field with no value gets its usual value for the system.\n * - A text loses the spaces at its ends. An empty text is no value.\n * - A number that is not valid, or a value of a different type, stops the record.\n * - A necessary field with no value stops the record. A collection with surfaces needs an anchor on one of them.\n *\n * The function does not examine if a record or an object of a field is there. `formLayer` examines it.\n */\nexport function readFormRecord(collection: FormCollection, record: FormRecord, system: FormSystem): FormReading {\n if (collection.on !== undefined) {\n if (record.anchor === undefined) return { state: \"empty\", field: \"anchor\" };\n if (!collection.on.includes(record.anchor.on)) return { state: \"bad\", field: \"anchor\" };\n }\n const values: [string, FormValue][] = [];\n for (const field of collection.fields) {\n const given = valueOf(record.values, field.name);\n if (field.kind === \"number\") {\n const value = given ?? field.usual?.[system];\n if (value === undefined) {\n if (field.needed === true) return { state: \"empty\", field: field.name };\n continue;\n }\n if (typeof value !== \"number\" || !numberFits(field, value)) return { state: \"bad\", field: field.name };\n values.push([field.name, value]);\n continue;\n }\n if (given !== undefined && typeof given !== \"string\") return { state: \"bad\", field: field.name };\n const text = field.kind === \"text\" ? (given ?? \"\").trim() : (given ?? \"\");\n if (text === \"\") {\n if (field.needed === true) return { state: \"empty\", field: field.name };\n continue;\n }\n values.push([field.name, text]);\n }\n return { state: \"ok\", values: Object.fromEntries(values) };\n}\n\n/** A record that a layer can have: its values are valid. */\ninterface Kept {\n readonly id: string;\n readonly anchor: Anchor | undefined;\n /** The values of the record. `settle` removes a value that names a record that is not there. */\n values: Readonly<Record<string, FormValue>>;\n}\n\n/**\n * This function removes each part that names a record or an object that is not there, one time. It gives true when it removed a part.\n *\n * - A field of a record that is not in its collection loses its value. A field of an object that is not in `objects` loses its value too.\n * - A record with no value of a necessary field goes away.\n * - A record after the largest number of records of its owner goes away.\n */\nfunction settleOnce(form: LayerForm, kept: Map<string, Kept[]>, objects: ReadonlySet<string> | undefined): boolean {\n let changed = false;\n const ids = new Map<string, ReadonlySet<string>>();\n for (const collection of form.collections) ids.set(collection.name, new Set((kept.get(collection.name) ?? []).map((record) => record.id)));\n for (const collection of form.collections) {\n const counts = new Map<string, number>();\n const list: Kept[] = [];\n for (const record of kept.get(collection.name) ?? []) {\n let stays = true;\n for (const field of collection.fields) {\n const value = valueOf(record.values, field.name);\n if (typeof value !== \"string\" || field.kind === \"text\" || field.kind === \"number\") continue;\n const there = field.kind === \"record\" ? ids.get(field.of)?.has(value) === true : objects === undefined || objects.has(value);\n if (there) continue;\n changed = true;\n if (field.needed === true) stays = false;\n else record.values = Object.fromEntries(Object.entries(record.values).filter(([name]) => name !== field.name));\n }\n if (stays && collection.owner !== undefined && collection.most !== undefined) {\n const owner = String(valueOf(record.values, collection.owner) ?? \"\");\n const count = (counts.get(owner) ?? 0) + 1;\n counts.set(owner, count);\n if (count > collection.most) {\n changed = true;\n stays = false;\n }\n }\n if (stays) list.push(record);\n }\n kept.set(collection.name, list);\n }\n return changed;\n}\n\n/**\n * This function removes each part that names a record or an object that is not there. It gives true when it removed a part.\n * A record that goes away can be the record of a field, so the function repeats `settleOnce` until nothing changes.\n */\nfunction settle(form: LayerForm, kept: Map<string, Kept[]>, objects: ReadonlySet<string> | undefined): boolean {\n let removed = false;\n while (settleOnce(form, kept, objects)) removed = true;\n return removed;\n}\n\n/** The options of `formLayer`. */\nexport interface FormLayerOptions {\n /** The system of units of the person, for the usual value of each number. */\n readonly system: FormSystem;\n /** The ids of the placed objects of the scene. With it, a field of the kind `object` keeps only an `id` of the set. */\n readonly objects?: ReadonlySet<string> | undefined;\n}\n\n/** A layer from the records of a form: its name, and the records of each collection that has records. */\nexport type FormLayer = Readonly<Record<string, unknown>> & { readonly schema: string };\n\n/**\n * This function makes the layer of the records of a form. It is total: a record that the layer cannot have is not in the layer.\n *\n * - `readFormRecord` reads each record. A record that it stops is not in the layer.\n * - The ids of a layer are unique. The first record of an `id` stays, in the sequence of the collections.\n * - A field that names a record that is not in the layer has no value. A record with no value of a necessary field is not in the layer.\n * - A collection with no record is not in the layer.\n *\n * A record of the layer has its `id`, then its `anchor`, then its values in the sequence of the fields. Thus equal records give equal JSON.\n * The add-on of the layer reads the result with its `parse`, and `checkLayers` examines it.\n */\nexport function formLayer(form: LayerForm, records: FormRecords, options: FormLayerOptions): FormLayer {\n const kept = new Map<string, Kept[]>();\n const seen = new Set<string>();\n for (const collection of form.collections) {\n const list: Kept[] = [];\n for (const record of Object.hasOwn(records, collection.name) ? (records[collection.name] ?? []) : []) {\n if (record.id === \"\" || seen.has(record.id)) continue;\n const reading = readFormRecord(collection, record, options.system);\n if (reading.state !== \"ok\") continue;\n seen.add(record.id);\n list.push({ id: record.id, anchor: collection.on === undefined ? undefined : record.anchor, values: reading.values });\n }\n kept.set(collection.name, list);\n }\n settle(form, kept, options.objects);\n const layer: [string, unknown][] = [[\"schema\", form.schema]];\n for (const collection of form.collections) {\n const list = kept.get(collection.name) ?? [];\n if (list.length === 0) continue;\n layer.push([\n collection.name,\n list.map((record) => {\n const item: [string, unknown][] = [[\"id\", record.id]];\n if (record.anchor !== undefined) item.push([\"anchor\", record.anchor]);\n for (const field of collection.fields) {\n const value = valueOf(record.values, field.name);\n if (value !== undefined) item.push([field.name, value]);\n }\n return Object.fromEntries(item);\n }),\n ]);\n }\n return Object.fromEntries(layer) as FormLayer;\n}\n\n/** The records of a form from a layer. */\nexport interface FormRecordsRead {\n /** The records of each collection of the form. A collection with no record has an empty list. */\n readonly records: FormRecords;\n /** This value is true when the layer has data that the form does not keep. */\n readonly more: boolean;\n}\n\nconst isObject = (value: unknown): value is Readonly<Record<string, unknown>> => typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/**\n * This function gives the records of a form from a layer. Give it a layer that its add-on read: the function does not examine the form of an anchor.\n *\n * The form does not keep these data, and `more` tells them:\n *\n * - a field of the layer or of a record that the form does not have\n * - a record with no `id`, or with the `id` of an earlier record\n * - a record of a collection with surfaces that has no anchor on one of them\n * - a value that is not a valid value of its field\n * - a field that names a record that the layer does not have\n * - a record after the largest number of records of its owner\n *\n * The records of a layer of `formLayer` are the records that the layer has, and `more` is false for them.\n */\nexport function formRecords(form: LayerForm, layer: unknown): FormRecordsRead {\n const kept = new Map<string, Kept[]>();\n for (const collection of form.collections) kept.set(collection.name, []);\n let more = false;\n if (isObject(layer)) {\n const names = new Set(form.collections.map((collection) => collection.name));\n if (Object.keys(layer).some((key) => key !== \"schema\" && !names.has(key))) more = true;\n const seen = new Set<string>();\n for (const collection of form.collections) {\n const given = Object.hasOwn(layer, collection.name) ? layer[collection.name] : undefined;\n if (given === undefined) continue;\n if (!Array.isArray(given)) {\n more = true;\n continue;\n }\n const known = new Set([\"id\", ...(collection.on === undefined ? [] : [\"anchor\"]), ...collection.fields.map((field) => field.name)]);\n const list: Kept[] = [];\n for (const item of given as readonly unknown[]) {\n const id = isObject(item) ? item[\"id\"] : undefined;\n if (!isObject(item) || typeof id !== \"string\" || id === \"\" || seen.has(id)) {\n more = true;\n continue;\n }\n const anchor = item[\"anchor\"];\n const surfaces: readonly string[] = collection.on ?? [];\n if (collection.on !== undefined && !(isObject(anchor) && typeof anchor[\"on\"] === \"string\" && surfaces.includes(anchor[\"on\"]))) {\n more = true;\n continue;\n }\n if (Object.keys(item).some((key) => !known.has(key))) more = true;\n const values: [string, FormValue][] = [];\n for (const field of collection.fields) {\n const value = Object.hasOwn(item, field.name) ? item[field.name] : undefined;\n if (value === undefined) continue;\n if (field.kind === \"number\") {\n if (typeof value === \"number\" && numberFits(field, value)) values.push([field.name, value]);\n else more = true;\n } else if (typeof value !== \"string\") more = true;\n else if (field.kind === \"text\") {\n // The spaces at the ends of a text are not data, and an empty text is no value.\n if (value.trim() !== \"\") values.push([field.name, value.trim()]);\n } else if (value === \"\") more = true;\n else values.push([field.name, value]);\n }\n seen.add(id);\n list.push({ id, anchor: collection.on === undefined ? undefined : (anchor as Anchor), values: Object.fromEntries(values) });\n }\n kept.set(collection.name, list);\n }\n // A record with no value of a necessary field is not a record of the form.\n for (const collection of form.collections) {\n const needed = collection.fields.filter((field) => field.needed === true);\n // A number with a usual value has a value in each layer of `formLayer`, so it does not stop a record.\n const has = (record: Kept, field: FormField): boolean => valueOf(record.values, field.name) !== undefined || (field.kind === \"number\" && field.usual !== undefined);\n const list = (kept.get(collection.name) ?? []).filter((record) => needed.every((field) => has(record, field)));\n if (list.length !== (kept.get(collection.name) ?? []).length) more = true;\n kept.set(collection.name, list);\n }\n if (settle(form, kept, undefined)) more = true;\n } else if (layer !== undefined) more = true;\n const records: [string, readonly FormRecord[]][] = form.collections.map((collection) => [\n collection.name,\n (kept.get(collection.name) ?? []).map((record): FormRecord => ({ id: record.id, ...(record.anchor === undefined ? {} : { anchor: record.anchor }), values: record.values })),\n ]);\n return { records: Object.fromEntries(records), more };\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgB,UAAU,OAAyB;CACjD,MAAM,EAAE,IAAI,MAAM,QAAQ,UAAU;CACpC,IAAI,MAAM,SAAS,SAAS,OAAO;EAAE,OAAO;EAAI;EAAM;EAAQ,MAAM,MAAM;EAAM,QAAQ,MAAM;EAAG,KAAK,MAAM,IAAI,MAAM;CAAE;CACxH,MAAM,EAAE,KAAK,cAAc;CAC3B,MAAM,OAAO;EACX;GAAE,GAAG,IAAI;GAAG,GAAG,IAAI;GAAG,GAAG,IAAI;EAAE;EAC/B;GAAE,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI;GAAG,GAAG,IAAI;EAAE;EACvC;GAAE,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI;EAAE;EAC/C;GAAE,GAAG,IAAI;GAAG,GAAG,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI;EAAE;CACzC,CAAC,CAAC,KAAK,WAAW,gBAAgB,WAAW,MAAM,CAAC;CACpD,MAAM,SAAS,KAAK,EAAE,CAAE;CACxB,MAAM,MAAM,gBAAgB,WAAW;EAAE,GAAG,IAAI;EAAG,GAAG,IAAI;EAAG,GAAG,IAAI,IAAI,IAAI;CAAE,CAAC,CAAC,CAA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AAA,KAAc,MAAM,SAAS,YAAY,MAAM,UAAU,KAAA;GACzJ,MAAM,QAAQ,KAAK,IAAI,WAAW,IAAI,KAAK,CAAC,EAAA,CAAG,QAAQ,WAAW,OAAO,OAAO,UAAU,IAAI,QAAQ,KAAK,CAAC,CAAC;GAC7G,IAAI,KAAK,YAAY,KAAK,IAAI,WAAW,IAAI,KAAK,CAAC,EAAA,CAAG,QAAQ,OAAO;GACrE,KAAK,IAAI,WAAW,MAAM,IAAI;EAChC;EACA,IAAI,OAAO,MAAM,MAAM,KAAA,CAAS,GAAG,OAAO;CAC5C,OAAO,IAAI,UAAU,KAAA,GAAW,OAAO;CACvC,MAAM,UAA6C,KAAK,YAAY,KAAK,eAAe,CACtF,WAAW,OACV,KAAK,IAAI,WAAW,IAAI,KAAK,CAAC,EAAA,CAAG,KAAK,YAAwB;EAAE,IAAI,OAAO;EAAI,GAAI,OAAO,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,OAAO,OAAO;EAAI,QAAQ,OAAO;CAAO,EAAE,CAC7K,CAAC;CACD,OAAO;EAAE,SAAS,OAAO,YAAY,OAAO;EAAG;CAAK;AACtD"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { c as checkAnchor, r as sceneSpace } from "./anchors-Ba3OUmhF.js";
|
|
2
|
+
// src/room.ts
|
|
3
|
+
/** The name of the format of a room record. */
|
|
4
|
+
const ROOM_SCHEMA = "room/1";
|
|
5
|
+
/** The name of the format of a scene record. */
|
|
6
|
+
const SCENE_SCHEMA = "scene/1";
|
|
7
|
+
/**
|
|
8
|
+
* This function tells if a text is the name of a layer: a word, a slash and a version, for example `electrical/1`.
|
|
9
|
+
* The word has lowercase letters, digits and hyphens. Thus a layer name has no colon, and `recordName` gives each record one name.
|
|
10
|
+
*/
|
|
11
|
+
function isLayerName(text) {
|
|
12
|
+
return /^[a-z][a-z0-9-]*\/[0-9]+$/.test(text);
|
|
13
|
+
}
|
|
14
|
+
/** These are the sides of the line of a wall that can have the wall. */
|
|
15
|
+
const WALL_SIDES = [
|
|
16
|
+
"center",
|
|
17
|
+
"left",
|
|
18
|
+
"right"
|
|
19
|
+
];
|
|
20
|
+
/** These are the faces of a wall, for a person who looks from `from` to `to`. */
|
|
21
|
+
const WALL_FACES = ["left", "right"];
|
|
22
|
+
/** These are the kinds of an opening. A window has glass. A door and a gap are empty. */
|
|
23
|
+
const OPENING_KINDS = [
|
|
24
|
+
"door",
|
|
25
|
+
"window",
|
|
26
|
+
"gap"
|
|
27
|
+
];
|
|
28
|
+
// src/order.ts
|
|
29
|
+
/** This function compares two texts by their code points, so the order does not change with the language of a computer. */
|
|
30
|
+
function compareText(a, b) {
|
|
31
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
// src/layers.ts
|
|
34
|
+
/**
|
|
35
|
+
* This function gives the name in a level of a record of a room. The name is the `id` of the room, a slash and the `id` in the survey.
|
|
36
|
+
* `expandLevel` gives each wall, each opening and each placed object such a name. The function `join` of an add-on gives it to the records of a room.
|
|
37
|
+
*/
|
|
38
|
+
function roomName(room, id) {
|
|
39
|
+
return `${room}/${id}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* This function makes one part of the layers of a level. With no room, the part is the layer of the level record.
|
|
43
|
+
* Its function `name` has the rule of `roomName`, so an add-on does not write that rule again.
|
|
44
|
+
*/
|
|
45
|
+
function layerPart(layer, room) {
|
|
46
|
+
return room === void 0 ? {
|
|
47
|
+
layer,
|
|
48
|
+
name: (id) => id
|
|
49
|
+
} : {
|
|
50
|
+
room,
|
|
51
|
+
layer,
|
|
52
|
+
name: (id) => roomName(room, id)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** These are the codes of the faults of a layer that the core finds. */
|
|
56
|
+
const LAYER_CODES = [
|
|
57
|
+
"layer-name",
|
|
58
|
+
"layer-unknown",
|
|
59
|
+
"layer-form"
|
|
60
|
+
];
|
|
61
|
+
/** This function gives the add-on of each schema name. The first add-on of a name is used. */
|
|
62
|
+
function addOnsByName(addOns) {
|
|
63
|
+
const byName = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const addOn of addOns) if (!byName.has(addOn.schema)) byName.set(addOn.schema, addOn);
|
|
65
|
+
return byName;
|
|
66
|
+
}
|
|
67
|
+
/** This function reads the layer of an add-on in a scene. It gives `undefined` when the scene has no layer of the add-on. */
|
|
68
|
+
function readLayer(scene, addOn) {
|
|
69
|
+
const layers = scene.layers ?? {};
|
|
70
|
+
return Object.hasOwn(layers, addOn.schema) ? addOn.parse(layers[addOn.schema]) : void 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* This function gives the findings of the layers of a scene, with a list of add-ons.
|
|
74
|
+
* Each layer gets the faults of its form, of each anchor and of the meaning of its records. A layer of no add-on of the list gets a warning.
|
|
75
|
+
* The findings are in the order of the layer keys, then of the record keys. Thus equal inputs give equal findings.
|
|
76
|
+
*
|
|
77
|
+
* The name of the record of a finding is `recordName(finding.layer, finding.at)`, so a finding selects its mark.
|
|
78
|
+
* `checkScene` examines the core, and this function examines the layers.
|
|
79
|
+
*/
|
|
80
|
+
function checkLayers(scene, addOns) {
|
|
81
|
+
const byName = addOnsByName(addOns);
|
|
82
|
+
const layers = scene.layers ?? {};
|
|
83
|
+
const findings = [];
|
|
84
|
+
let space;
|
|
85
|
+
for (const name of Object.keys(layers).sort(compareText)) {
|
|
86
|
+
if (!isLayerName(name)) {
|
|
87
|
+
findings.push({
|
|
88
|
+
level: "error",
|
|
89
|
+
code: "layer-name",
|
|
90
|
+
layer: name,
|
|
91
|
+
at: "",
|
|
92
|
+
message: `The layer "${name}" has a name that is not a word, a slash and a version, for example "electrical/1".`
|
|
93
|
+
});
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const addOn = byName.get(name);
|
|
97
|
+
if (addOn === void 0) {
|
|
98
|
+
findings.push({
|
|
99
|
+
level: "warning",
|
|
100
|
+
code: "layer-unknown",
|
|
101
|
+
layer: name,
|
|
102
|
+
at: "",
|
|
103
|
+
message: `The scene has the layer "${name}", and no add-on of the check reads it. The scene keeps the layer.`
|
|
104
|
+
});
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const read = addOn.parse(layers[name]);
|
|
108
|
+
if (!read.ok) {
|
|
109
|
+
for (const message of read.errors) findings.push({
|
|
110
|
+
level: "error",
|
|
111
|
+
code: "layer-form",
|
|
112
|
+
layer: name,
|
|
113
|
+
at: "",
|
|
114
|
+
message
|
|
115
|
+
});
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
space ??= sceneSpace(scene);
|
|
119
|
+
const own = [];
|
|
120
|
+
for (const [key, anchor] of addOn.anchors(read.layer)) for (const fault of checkAnchor(anchor, space, `The anchor "${key}" of the layer "${name}"`)) own.push({
|
|
121
|
+
...fault,
|
|
122
|
+
layer: name,
|
|
123
|
+
at: key
|
|
124
|
+
});
|
|
125
|
+
for (const fault of addOn.check(read.layer, space)) own.push({
|
|
126
|
+
...fault,
|
|
127
|
+
layer: name
|
|
128
|
+
});
|
|
129
|
+
own.sort((a, b) => compareText(a.at, b.at));
|
|
130
|
+
findings.push(...own);
|
|
131
|
+
}
|
|
132
|
+
return findings;
|
|
133
|
+
}
|
|
134
|
+
/** This function reads one layer with the add-on of its name. `room` is the `id` of the room of the layer, in a level. */
|
|
135
|
+
function readForChange(name, value, byName, room) {
|
|
136
|
+
const where = room === void 0 ? {} : { room };
|
|
137
|
+
const of = room === void 0 ? "" : ` of the room "${room}"`;
|
|
138
|
+
const finding = (code, message) => ({
|
|
139
|
+
level: "error",
|
|
140
|
+
code,
|
|
141
|
+
layer: name,
|
|
142
|
+
at: "",
|
|
143
|
+
message,
|
|
144
|
+
...where
|
|
145
|
+
});
|
|
146
|
+
if (!isLayerName(name)) return [finding("layer-name", `The layer "${name}"${of} has a name that is not a word, a slash and a version, for example "electrical/1". The result does not have the layer.`)];
|
|
147
|
+
const addOn = byName.get(name);
|
|
148
|
+
if (addOn === void 0) return [finding("layer-unknown", `No add-on of the list reads the layer "${name}"${of}. The result does not have the layer.`)];
|
|
149
|
+
const read = addOn.parse(value);
|
|
150
|
+
if (!read.ok) return read.errors.map((message) => finding("layer-form", message));
|
|
151
|
+
return {
|
|
152
|
+
addOn,
|
|
153
|
+
layer: read.layer
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* This function gives layers with each anchor changed by `move`. The add-on of each layer comes from the list.
|
|
158
|
+
* `expandSurvey` uses it to put the layers of a survey on the room record. A host uses it when it moves the records of a room.
|
|
159
|
+
*
|
|
160
|
+
* A layer that the function cannot read is not in the result, because its anchors are in the old space. A finding tells each such layer:
|
|
161
|
+
*
|
|
162
|
+
* - `layer-name`: the name is not a layer name.
|
|
163
|
+
* - `layer-unknown`: no add-on of the list has the name.
|
|
164
|
+
* - `layer-form`: the add-on found a fault in the form of the layer.
|
|
165
|
+
*
|
|
166
|
+
* `room` is the `id` of the room of the layers, in a level. Each finding gets it.
|
|
167
|
+
*/
|
|
168
|
+
function moveLayers(layers, addOns, move, room) {
|
|
169
|
+
const byName = addOnsByName(addOns);
|
|
170
|
+
const given = layers ?? {};
|
|
171
|
+
const moved = [];
|
|
172
|
+
const findings = [];
|
|
173
|
+
for (const name of Object.keys(given).sort(compareText)) {
|
|
174
|
+
const read = readForChange(name, given[name], byName, room);
|
|
175
|
+
if ("addOn" in read) {
|
|
176
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
177
|
+
for (const [key, anchor] of read.addOn.anchors(read.layer)) anchors.set(key, move(anchor));
|
|
178
|
+
moved.push([name, read.addOn.withAnchors(read.layer, anchors)]);
|
|
179
|
+
} else findings.push(...read);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
layers: Object.fromEntries(moved),
|
|
183
|
+
findings
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* This function gives the layers of a level. Each name gets one layer, from the layer of the level record and the layers of the rooms.
|
|
188
|
+
* The function `join` of the add-on of each name makes that layer. `expandLevel` uses this function.
|
|
189
|
+
*
|
|
190
|
+
* - A layer that only the level record has stays as it is, because its anchors are on the room record of the level already.
|
|
191
|
+
* `checkLayers` examines it.
|
|
192
|
+
* - The layer of a room needs an add-on of its name with the function `join`. Without it, a finding tells the layer of each room,
|
|
193
|
+
* and the layer of the level record stays as it is. The codes are the codes of `moveLayers`.
|
|
194
|
+
* An add-on with no function `join` gives the code `layer-unknown`.
|
|
195
|
+
* - With such an add-on, a part with a fault in its form is not in the layer of the result. A finding tells the part.
|
|
196
|
+
*/
|
|
197
|
+
function joinLayers(own, rooms, addOns) {
|
|
198
|
+
const byName = addOnsByName(addOns);
|
|
199
|
+
const level = own ?? {};
|
|
200
|
+
const names = new Set(Object.keys(level));
|
|
201
|
+
for (const room of rooms) for (const name of Object.keys(room.layers ?? {})) names.add(name);
|
|
202
|
+
const joined = [];
|
|
203
|
+
const findings = [];
|
|
204
|
+
for (const name of [...names].sort(compareText)) {
|
|
205
|
+
const inLevel = Object.hasOwn(level, name);
|
|
206
|
+
const inRooms = rooms.filter((room) => room.layers !== void 0 && Object.hasOwn(room.layers, name));
|
|
207
|
+
const addOn = isLayerName(name) ? byName.get(name) : void 0;
|
|
208
|
+
const join = addOn?.join?.bind(addOn);
|
|
209
|
+
if (join === void 0 || inRooms.length === 0) {
|
|
210
|
+
if (inLevel) joined.push([name, level[name]]);
|
|
211
|
+
for (const { room, layers } of inRooms) if (addOn === void 0) {
|
|
212
|
+
const read = readForChange(name, layers?.[name], byName, room);
|
|
213
|
+
if (!("addOn" in read)) findings.push(...read);
|
|
214
|
+
} else {
|
|
215
|
+
const message = `The add-on of the layer "${name}" has no function "join", so the result does not have the layer of the room "${room}".`;
|
|
216
|
+
findings.push({
|
|
217
|
+
level: "error",
|
|
218
|
+
code: "layer-unknown",
|
|
219
|
+
layer: name,
|
|
220
|
+
at: "",
|
|
221
|
+
message,
|
|
222
|
+
room
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const parts = [];
|
|
228
|
+
if (inLevel) {
|
|
229
|
+
const read = readForChange(name, level[name], byName);
|
|
230
|
+
if ("addOn" in read) parts.push(layerPart(read.layer));
|
|
231
|
+
else findings.push(...read);
|
|
232
|
+
}
|
|
233
|
+
for (const { room, layers } of inRooms) {
|
|
234
|
+
const read = readForChange(name, layers?.[name], byName, room);
|
|
235
|
+
if ("addOn" in read) parts.push(layerPart(read.layer, room));
|
|
236
|
+
else findings.push(...read);
|
|
237
|
+
}
|
|
238
|
+
if (parts.length > 0) joined.push([name, join(parts)]);
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
layers: Object.fromEntries(joined),
|
|
242
|
+
findings
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
export { moveLayers as a, compareText as c, SCENE_SCHEMA as d, WALL_FACES as f, layerPart as i, OPENING_KINDS as l, isLayerName as m, checkLayers as n, readLayer as o, WALL_SIDES as p, joinLayers as r, roomName as s, LAYER_CODES as t, ROOM_SCHEMA as u };
|
|
246
|
+
|
|
247
|
+
//# sourceMappingURL=layers-B5nL_lVW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layers-B5nL_lVW.js","names":[],"sources":["../src/room.ts","../src/order.ts","../src/layers.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\nimport type { LengthUnit } from \"./units.ts\";\n\n/** A point of the plan: `[x, y]`. The plan is the view from above, and the z axis points up. */\nexport type PlanPoint = readonly [number, number];\n\n/** The name of the format of a room record. */\nexport const ROOM_SCHEMA = \"room/1\";\n\n/** The name of the format of a scene record. */\nexport const SCENE_SCHEMA = \"scene/1\";\n\n/**\n * This function tells if a text is the name of a layer: a word, a slash and a version, for example `electrical/1`.\n * The word has lowercase letters, digits and hyphens. Thus a layer name has no colon, and `recordName` gives each record one name.\n */\nexport function isLayerName(text: string): boolean {\n return /^[a-z][a-z0-9-]*\\/[0-9]+$/.test(text);\n}\n\n/** These are the sides of the line of a wall that can have the wall. */\nexport const WALL_SIDES: readonly [\"center\", \"left\", \"right\"] = [\"center\", \"left\", \"right\"];\n\n/**\n * The side of the line of a wall that has the wall, for a person who looks from `from` to `to`.\n * With `center`, the line is the middle of the wall. With `left` or `right`, the line is one face of the wall.\n */\nexport type WallSide = (typeof WALL_SIDES)[number];\n\n/** These are the faces of a wall, for a person who looks from `from` to `to`. */\nexport const WALL_FACES: readonly [\"left\", \"right\"] = [\"left\", \"right\"];\n\n/** A face of a wall. */\nexport type WallFace = (typeof WALL_FACES)[number];\n\n/**\n * A wall: a straight line in the plan, with a thickness and a height.\n * A tape measure gives the faces of a wall, so `side` lets the line be a face. Two walls with a common end make a corner.\n */\nexport interface Wall {\n readonly id: string;\n readonly from: PlanPoint;\n readonly to: PlanPoint;\n /** The thickness of the wall. The default is `wallThickness` of the room. */\n readonly thickness?: number | undefined;\n /** The height of the wall. The default is `height` of the room. */\n readonly height?: number | undefined;\n /** The side of the line that has the wall. The default is `center`. */\n readonly side?: WallSide | undefined;\n}\n\n/** These are the kinds of an opening. A window has glass. A door and a gap are empty. */\nexport const OPENING_KINDS: readonly [\"door\", \"window\", \"gap\"] = [\"door\", \"window\", \"gap\"];\n\n/** A kind of opening. */\nexport type OpeningKind = (typeof OPENING_KINDS)[number];\n\n/** An opening: a hole through a wall. */\nexport interface Opening {\n readonly id: string;\n /** The `id` of the wall. */\n readonly wall: string;\n readonly kind: OpeningKind;\n /** The distance along the line of the wall, from `from` to the near edge of the opening. */\n readonly offset: number;\n readonly width: number;\n /** The height of the bottom of the opening above the floor. The default is 0. */\n readonly sill?: number | undefined;\n readonly height: number;\n}\n\n/** A floor: one area of the plan, for example one room of an apartment. The ring is the line where the floor touches the walls. */\nexport interface Floor {\n readonly id: string;\n readonly name?: string | undefined;\n readonly ring: Ring;\n}\n\n/** An outlet: a point on a face of a wall. */\nexport interface Outlet {\n readonly id: string;\n /** The `id` of the wall. */\n readonly wall: string;\n /** The face of the wall that has the outlet. */\n readonly face: WallFace;\n /** The distance along the line of the wall, from `from` to the center of the outlet. */\n readonly offset: number;\n /** The height of the center of the outlet above the floor. */\n readonly height: number;\n /** The `id` of the circuit of the outlet. */\n readonly circuit?: string | undefined;\n}\n\n/** A circuit: it gives power to outlets, and it has a limit. */\nexport interface Circuit {\n readonly id: string;\n readonly name?: string | undefined;\n /** The rating of the breaker of the circuit, in amperes, for example 15. The record keeps it as a fact. The limit does not change with it. */\n readonly breaker?: number | undefined;\n /** The voltage of the circuit, in volts, for example 120. The record keeps it as a fact. The limit does not change with it. */\n readonly voltage?: number | undefined;\n /**\n * The largest continuous load, in watts.\n * For example, a breaker of 15 A at 120 V carries 1800 W, and 80% of that for a continuous load is 1440 W.\n */\n readonly limit: number;\n}\n\n/** A room: the walls, the openings, the floors, the outlets and the circuits of one room or one apartment. */\nexport interface Room {\n readonly schema: typeof ROOM_SCHEMA;\n readonly name?: string | undefined;\n /** The unit of each length of the record. */\n readonly unit: LengthUnit;\n /** The height of each wall that has no height of its own. */\n readonly height: number;\n /** The thickness of each wall that has no thickness of its own. */\n readonly wallThickness: number;\n readonly walls: readonly Wall[];\n readonly openings?: readonly Opening[] | undefined;\n readonly floors?: readonly Floor[] | undefined;\n readonly outlets?: readonly Outlet[] | undefined;\n readonly circuits?: readonly Circuit[] | undefined;\n}\n\n/**\n * A placed object: a box in the room, for example a desk, a rack or a computer.\n * With a `parent`, the position and the turn are relative to that object, whose origin is the center of its bottom.\n */\nexport interface PlacedObject {\n readonly id: string;\n /** The class of the object, for example `desk`, `rack` or `computer`. A viewer gives each class a color. */\n readonly kind: string;\n readonly name?: string | undefined;\n /** The size before the turn: along x, along y, and the height. */\n readonly size: readonly [number, number, number];\n /** The point of the plan below the center of the object. */\n readonly at: PlanPoint;\n /** The height of the bottom of the object above the floor, or above the bottom of its parent. The default is 0. */\n readonly lift?: number | undefined;\n /** The turn about the vertical axis in degrees, counter-clockwise from above. The default is 0. */\n readonly turn?: number | undefined;\n /** The `id` of the object that holds this object. */\n readonly parent?: string | undefined;\n /** The `id` of the outlet that gives power to the object. */\n readonly outlet?: string | undefined;\n}\n\n/** A load on a circuit, in watts. A circuit can have many loads: their sum is the load of the circuit. */\nexport interface CircuitLoad {\n /** The `id` of the circuit. */\n readonly circuit: string;\n readonly watts: number;\n}\n\n/** A scene: one room with its placed objects and the loads of its circuits. Two scenes of one room can be compared. */\nexport interface Scene {\n readonly schema: typeof SCENE_SCHEMA;\n readonly name?: string | undefined;\n readonly room: Room;\n readonly objects?: readonly PlacedObject[] | undefined;\n readonly loads?: readonly CircuitLoad[] | undefined;\n /**\n * The records of each add-on, by the name of its layer, for example `electrical/1`. `isLayerName` tells the form of a name.\n * The core keeps each layer and does not read it. `checkLayers` examines the layers with a list of add-ons.\n */\n readonly layers?: Readonly<Record<string, unknown>> | undefined;\n}\n","// The order of texts in the results of the core. The entries do not export this module.\n\n/** This function compares two texts by their code points, so the order does not change with the language of a computer. */\nexport function compareText(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n","import { sceneSpace, type Anchor, type SceneSpace } from \"./anchors.ts\";\nimport { checkAnchor, type FindingLevel } from \"./check.ts\";\nimport { compareText } from \"./order.ts\";\nimport { isLayerName, type Scene } from \"./room.ts\";\n\n// The layers of a scene: the records of the add-ons. The core keeps each layer, and it does not read one.\n// An add-on reads its layer, gives the anchors of its records, and examines the meaning of its records.\n// The core examines the anchors. Thus each add-on composes on the core, and the add-ons do not know each other.\n\n/** The result of the read of a layer: the layer, or the faults of its form. */\nexport type LayerParse<Layer> = { readonly ok: true; readonly layer: Layer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/** A fault that an add-on finds in its layer. */\nexport interface AddOnFault {\n readonly level: FindingLevel;\n /** The code of the fault. The add-on gives its own codes. */\n readonly code: string;\n /** The `id` of the record with the fault. For the layer, it is empty. */\n readonly at: string;\n /** The fault in plain words, with the values. */\n readonly message: string;\n /** The `id` of the second record of the fault. A fault of one record has none. */\n readonly other?: string | undefined;\n}\n\n/**\n * An add-on: one topic on the core, for example electrical, plumbing or light.\n * A host gives a list of add-ons to `checkLayers`. The core knows only this type.\n */\nexport interface AddOn<Layer> {\n /** The name of the format of the layer, for example `electrical/1`. It is the key of the layer in `Scene.layers`. */\n readonly schema: string;\n /** This function reads the JSON of a layer. */\n parse(value: unknown): LayerParse<Layer>;\n /**\n * This function gives the anchors of the records of a layer, by a key.\n * The key is the `id` of a record, or the `id` and a position for a record with many anchors.\n */\n anchors(layer: Layer): ReadonlyMap<string, Anchor>;\n /** This function gives the layer with new anchors, by the keys of `anchors`. The core uses it when it moves the records of a room. */\n withAnchors(layer: Layer, anchors: ReadonlyMap<string, Anchor>): Layer;\n /** This function gives the faults of the meaning of a layer. The core examines the anchors, so this function does not. */\n check(layer: Layer, space: SceneSpace): readonly AddOnFault[];\n /**\n * This function gives one layer from the parts of a level: the layer of the level record, then the layer of each room.\n *\n * - A record of a part gets the name `part.name(id)`. Each `id` of the layer that names such a record or a placed object gets it too.\n * - A record that all the rooms share keeps its `id`, for example a circuit of an apartment. The first record of an `id` stays.\n * - The core changes the anchors before this function, so the function does not change an anchor.\n *\n * `expandLevel` does not carry the layer of a room when its add-on has no such function.\n */\n join?(parts: readonly LayerPart<Layer>[]): Layer;\n}\n\n/** One part of the layers of a level, for the function `join` of an add-on. `layerPart` makes it. */\nexport interface LayerPart<Layer> {\n /** The `id` of the room of the layer. The layer of the level record has no room. */\n readonly room?: string | undefined;\n readonly layer: Layer;\n /**\n * This function gives the name in the level of a record of the part, from its `id` in the part.\n * A record of a room gets the name that `roomName` gives, and a record of the level record keeps its `id`.\n * The function also gives the name of a record of the core that the part names, for example a placed object.\n */\n readonly name: (id: string) => string;\n}\n\n/**\n * This function gives the name in a level of a record of a room. The name is the `id` of the room, a slash and the `id` in the survey.\n * `expandLevel` gives each wall, each opening and each placed object such a name. The function `join` of an add-on gives it to the records of a room.\n */\nexport function roomName(room: string, id: string): string {\n return `${room}/${id}`;\n}\n\n/**\n * This function makes one part of the layers of a level. With no room, the part is the layer of the level record.\n * Its function `name` has the rule of `roomName`, so an add-on does not write that rule again.\n */\nexport function layerPart<Layer>(layer: Layer, room?: string): LayerPart<Layer> {\n return room === undefined ? { layer, name: (id) => id } : { room, layer, name: (id) => roomName(room, id) };\n}\n\n/** These are the codes of the faults of a layer that the core finds. */\nexport const LAYER_CODES: readonly [\"layer-name\", \"layer-unknown\", \"layer-form\"] = [\"layer-name\", \"layer-unknown\", \"layer-form\"];\n\n/** A finding of a layer: a fault of its form, of an anchor or of the meaning of its records. */\nexport interface LayerFinding {\n readonly level: FindingLevel;\n /** A code of `LAYER_CODES` or `ANCHOR_CODES`, or a code of the add-on. */\n readonly code: string;\n /** The key of the layer in `Scene.layers`. */\n readonly layer: string;\n /** The key of the anchor, or the `id` of the record with the fault. For the layer, it is empty. */\n readonly at: string;\n /** The fault in plain words, with the values. */\n readonly message: string;\n /** The `id` of the second record of the fault. A fault of one record has none. */\n readonly other?: string | undefined;\n /** The `id` of the room of the layer. Only a finding of `expandLevel` about the layer of a room has it. */\n readonly room?: string | undefined;\n}\n\n/** This function gives the add-on of each schema name. The first add-on of a name is used. */\nfunction addOnsByName(addOns: readonly AddOn<unknown>[]): ReadonlyMap<string, AddOn<unknown>> {\n const byName = new Map<string, AddOn<unknown>>();\n for (const addOn of addOns) if (!byName.has(addOn.schema)) byName.set(addOn.schema, addOn);\n return byName;\n}\n\n/** This function reads the layer of an add-on in a scene. It gives `undefined` when the scene has no layer of the add-on. */\nexport function readLayer<Layer>(scene: Scene, addOn: AddOn<Layer>): LayerParse<Layer> | undefined {\n const layers = scene.layers ?? {};\n return Object.hasOwn(layers, addOn.schema) ? addOn.parse(layers[addOn.schema]) : undefined;\n}\n\n/**\n * This function gives the findings of the layers of a scene, with a list of add-ons.\n * Each layer gets the faults of its form, of each anchor and of the meaning of its records. A layer of no add-on of the list gets a warning.\n * The findings are in the order of the layer keys, then of the record keys. Thus equal inputs give equal findings.\n *\n * The name of the record of a finding is `recordName(finding.layer, finding.at)`, so a finding selects its mark.\n * `checkScene` examines the core, and this function examines the layers.\n */\nexport function checkLayers(scene: Scene, addOns: readonly AddOn<unknown>[]): readonly LayerFinding[] {\n const byName = addOnsByName(addOns);\n const layers = scene.layers ?? {};\n const findings: LayerFinding[] = [];\n let space: SceneSpace | undefined;\n for (const name of Object.keys(layers).sort(compareText)) {\n if (!isLayerName(name)) {\n findings.push({ level: \"error\", code: \"layer-name\", layer: name, at: \"\", message: `The layer \"${name}\" has a name that is not a word, a slash and a version, for example \"electrical/1\".` });\n continue;\n }\n const addOn = byName.get(name);\n if (addOn === undefined) {\n findings.push({ level: \"warning\", code: \"layer-unknown\", layer: name, at: \"\", message: `The scene has the layer \"${name}\", and no add-on of the check reads it. The scene keeps the layer.` });\n continue;\n }\n const read = addOn.parse(layers[name]);\n if (!read.ok) {\n for (const message of read.errors) findings.push({ level: \"error\", code: \"layer-form\", layer: name, at: \"\", message });\n continue;\n }\n space ??= sceneSpace(scene);\n const own: LayerFinding[] = [];\n for (const [key, anchor] of addOn.anchors(read.layer)) {\n for (const fault of checkAnchor(anchor, space, `The anchor \"${key}\" of the layer \"${name}\"`)) own.push({ ...fault, layer: name, at: key });\n }\n for (const fault of addOn.check(read.layer, space)) own.push({ ...fault, layer: name });\n // The sort is stable, so the faults of one record keep their order.\n own.sort((a, b) => compareText(a.at, b.at));\n findings.push(...own);\n }\n return findings;\n}\n\n/** The result of a change of layers: the layers that the function carried, and a finding for each layer that it did not carry. */\nexport interface LayersMove {\n /** The layers of the result, in the order of their names. */\n readonly layers: Readonly<Record<string, unknown>>;\n /** One finding or more for each layer that is not in the result. Each finding has the level `error`. */\n readonly findings: readonly LayerFinding[];\n}\n\n/** The read of one layer for a change: the add-on and the layer, or the findings that tell why the layer has no read. */\ntype LayerRead = { readonly addOn: AddOn<unknown>; readonly layer: unknown } | readonly LayerFinding[];\n\n/** This function reads one layer with the add-on of its name. `room` is the `id` of the room of the layer, in a level. */\nfunction readForChange(name: string, value: unknown, byName: ReadonlyMap<string, AddOn<unknown>>, room?: string): LayerRead {\n const where = room === undefined ? {} : { room };\n const of = room === undefined ? \"\" : ` of the room \"${room}\"`;\n const finding = (code: (typeof LAYER_CODES)[number], message: string): LayerFinding => ({ level: \"error\", code, layer: name, at: \"\", message, ...where });\n if (!isLayerName(name)) {\n return [finding(\"layer-name\", `The layer \"${name}\"${of} has a name that is not a word, a slash and a version, for example \"electrical/1\". The result does not have the layer.`)];\n }\n const addOn = byName.get(name);\n if (addOn === undefined) return [finding(\"layer-unknown\", `No add-on of the list reads the layer \"${name}\"${of}. The result does not have the layer.`)];\n const read = addOn.parse(value);\n if (!read.ok) return read.errors.map((message) => finding(\"layer-form\", message));\n return { addOn, layer: read.layer };\n}\n\n/**\n * This function gives layers with each anchor changed by `move`. The add-on of each layer comes from the list.\n * `expandSurvey` uses it to put the layers of a survey on the room record. A host uses it when it moves the records of a room.\n *\n * A layer that the function cannot read is not in the result, because its anchors are in the old space. A finding tells each such layer:\n *\n * - `layer-name`: the name is not a layer name.\n * - `layer-unknown`: no add-on of the list has the name.\n * - `layer-form`: the add-on found a fault in the form of the layer.\n *\n * `room` is the `id` of the room of the layers, in a level. Each finding gets it.\n */\nexport function moveLayers(\n layers: Readonly<Record<string, unknown>> | undefined,\n addOns: readonly AddOn<unknown>[],\n move: (anchor: Anchor) => Anchor,\n room?: string,\n): LayersMove {\n const byName = addOnsByName(addOns);\n const given = layers ?? {};\n const moved: [string, unknown][] = [];\n const findings: LayerFinding[] = [];\n for (const name of Object.keys(given).sort(compareText)) {\n const read = readForChange(name, given[name], byName, room);\n if (\"addOn\" in read) {\n const anchors = new Map<string, Anchor>();\n for (const [key, anchor] of read.addOn.anchors(read.layer)) anchors.set(key, move(anchor));\n moved.push([name, read.addOn.withAnchors(read.layer, anchors)]);\n } else findings.push(...read);\n }\n return { layers: Object.fromEntries(moved), findings };\n}\n\n/** The layers of one room of a level, for `joinLayers`. The anchors have the names of the level already. */\nexport interface RoomLayers {\n /** The `id` of the room. */\n readonly room: string;\n readonly layers: Readonly<Record<string, unknown>> | undefined;\n}\n\n/**\n * This function gives the layers of a level. Each name gets one layer, from the layer of the level record and the layers of the rooms.\n * The function `join` of the add-on of each name makes that layer. `expandLevel` uses this function.\n *\n * - A layer that only the level record has stays as it is, because its anchors are on the room record of the level already.\n * `checkLayers` examines it.\n * - The layer of a room needs an add-on of its name with the function `join`. Without it, a finding tells the layer of each room,\n * and the layer of the level record stays as it is. The codes are the codes of `moveLayers`.\n * An add-on with no function `join` gives the code `layer-unknown`.\n * - With such an add-on, a part with a fault in its form is not in the layer of the result. A finding tells the part.\n */\nexport function joinLayers(own: Readonly<Record<string, unknown>> | undefined, rooms: readonly RoomLayers[], addOns: readonly AddOn<unknown>[]): LayersMove {\n const byName = addOnsByName(addOns);\n const level = own ?? {};\n const names = new Set(Object.keys(level));\n for (const room of rooms) for (const name of Object.keys(room.layers ?? {})) names.add(name);\n const joined: [string, unknown][] = [];\n const findings: LayerFinding[] = [];\n for (const name of [...names].sort(compareText)) {\n const inLevel = Object.hasOwn(level, name);\n const inRooms = rooms.filter((room) => room.layers !== undefined && Object.hasOwn(room.layers, name));\n const addOn = isLayerName(name) ? byName.get(name) : undefined;\n const join = addOn?.join?.bind(addOn);\n if (join === undefined || inRooms.length === 0) {\n if (inLevel) joined.push([name, level[name]]);\n for (const { room, layers } of inRooms) {\n if (addOn === undefined) {\n const read = readForChange(name, layers?.[name], byName, room);\n if (!(\"addOn\" in read)) findings.push(...read);\n } else {\n const message = `The add-on of the layer \"${name}\" has no function \"join\", so the result does not have the layer of the room \"${room}\".`;\n findings.push({ level: \"error\", code: \"layer-unknown\", layer: name, at: \"\", message, room });\n }\n }\n continue;\n }\n const parts: LayerPart<unknown>[] = [];\n if (inLevel) {\n const read = readForChange(name, level[name], byName);\n if (\"addOn\" in read) parts.push(layerPart(read.layer));\n else findings.push(...read);\n }\n for (const { room, layers } of inRooms) {\n const read = readForChange(name, layers?.[name], byName, room);\n if (\"addOn\" in read) parts.push(layerPart(read.layer, room));\n else findings.push(...read);\n }\n if (parts.length > 0) joined.push([name, join(parts)]);\n }\n return { layers: Object.fromEntries(joined), findings };\n}\n"],"mappings":";;;AAOA,MAAa,cAAc;;AAG3B,MAAa,eAAe;;;;;AAM5B,SAAgB,YAAY,MAAuB;CACjD,OAAO,4BAA4B,KAAK,IAAI;AAC9C;;AAGA,MAAa,aAAmD;CAAC;CAAU;CAAQ;AAAO;;AAS1F,MAAa,aAAyC,CAAC,QAAQ,OAAO;;AAsBtE,MAAa,gBAAoD;CAAC;CAAQ;CAAU;AAAK;;;ACjDzF,SAAgB,YAAY,GAAW,GAAmB;CACxD,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;;;;;;ACmEA,SAAgB,SAAS,MAAc,IAAoB;CACzD,OAAO,GAAG,KAAK,GAAG;AACpB;;;;;AAMA,SAAgB,UAAiB,OAAc,MAAiC;CAC9E,OAAO,SAAS,KAAA,IAAY;EAAE;EAAO,OAAO,OAAO;CAAG,IAAI;EAAE;EAAM;EAAO,OAAO,OAAO,SAAS,MAAM,EAAE;CAAE;AAC5G;;AAGA,MAAa,cAAsE;CAAC;CAAc;CAAiB;AAAY;;AAoB/H,SAAS,aAAa,QAAwE;CAC5F,MAAM,yBAAS,IAAI,IAA4B;CAC/C,KAAK,MAAM,SAAS,QAAQ,IAAI,CAAC,OAAO,IAAI,MAAM,MAAM,GAAG,OAAO,IAAI,MAAM,QAAQ,KAAK;CACzF,OAAO;AACT;;AAGA,SAAgB,UAAiB,OAAc,OAAoD;CACjG,MAAM,SAAS,MAAM,UAAU,CAAC;CAChC,OAAO,OAAO,OAAO,QAAQ,MAAM,MAAM,IAAI,MAAM,MAAM,OAAO,MAAM,OAAO,IAAI,KAAA;AACnF;;;;;;;;;AAUA,SAAgB,YAAY,OAAc,QAA4D;CACpG,MAAM,SAAS,aAAa,MAAM;CAClC,MAAM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