@kruschdev/pascal-plugin-plumbing 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,194 @@
1
+ /**
2
+ * `plumbing:manifold` — PEX Home-Run Manifold, Copper Trunk Header, or CSST Fuel-Gas Manifold.
3
+ * Render-safe module: zero `@pascal-app/editor` imports.
4
+ */
5
+
6
+ import {
7
+ BaseNode,
8
+ type FloorplanGeometry,
9
+ type GeometryContext,
10
+ type NodeDefinition,
11
+ type NodePort,
12
+ nodeType,
13
+ objectId,
14
+ } from '@pascal-app/core'
15
+ import { Group } from 'three'
16
+ import { z } from 'zod'
17
+ import { buildManifoldCad } from '../cad/manifold-interior'
18
+ import type { ManifoldKind } from '../ipc/tables'
19
+
20
+ const Vec3Schema = z.tuple([z.number(), z.number(), z.number()])
21
+
22
+ export const ManifoldKindEnum = z.enum(['pex-homerun', 'copper-header', 'gas-csst'])
23
+
24
+ export const PlumbingManifoldNode = BaseNode.extend({
25
+ id: objectId('plumbman'),
26
+ type: nodeType('plumbing:manifold'),
27
+ position: Vec3Schema.default([0, 1.35, 0]),
28
+ rotation: z.number().default(0),
29
+ manifoldKind: ManifoldKindEnum.default('pex-homerun'),
30
+ portCount: z.number().int().min(4).max(36).default(12),
31
+ supplyMaterial: z
32
+ .enum(['pex-a', 'pex-b', 'copper-l', 'copper-m', 'cpvc', 'csst', 'black-iron'])
33
+ .default('pex-a'),
34
+ coverRemoved: z.boolean().default(false),
35
+ furnishingSourceId: z.string().optional(),
36
+ catalogSku: z.string().optional(),
37
+ roughInOnly: z.boolean().default(false),
38
+ })
39
+
40
+ export type PlumbingManifoldNode = z.infer<typeof PlumbingManifoldNode>
41
+
42
+ function rotateManifoldLocal2D(
43
+ cx: number,
44
+ cz: number,
45
+ lx: number,
46
+ lz: number,
47
+ rot: number,
48
+ ): [number, number] {
49
+ const cos = Math.cos(rot)
50
+ const sin = Math.sin(rot)
51
+ return [cx + lx * cos + lz * sin, cz - lx * sin + lz * cos]
52
+ }
53
+
54
+ export function getPlumbingManifoldPorts(node: PlumbingManifoldNode): NodePort[] {
55
+ const [x, y, zPos] = node.position
56
+ const rot = node.rotation ?? 0
57
+ const perSide = Math.max(4, Math.min(18, Math.ceil(node.portCount / 2)))
58
+ if (node.manifoldKind === 'gas-csst') {
59
+ const cabinetH = Math.max(0.56, 0.24 + Math.min(8, node.portCount) * 0.052)
60
+ const [gx, gz] = rotateManifoldLocal2D(x, zPos, 0, 0.02, rot)
61
+ return [
62
+ { id: 'gas-in', position: [gx, y - (cabinetH / 2 + 0.12), gz], direction: [0, -1, 0], diameter: 0.75, system: 'gas' },
63
+ ]
64
+ }
65
+ const cabinetH = Math.max(0.56, 0.22 + perSide * 0.048)
66
+ const [hx, hz] = rotateManifoldLocal2D(x, zPos, -0.085, 0.02, rot)
67
+ const [cx, cz] = rotateManifoldLocal2D(x, zPos, 0.085, 0.02, rot)
68
+ return [
69
+ { id: 'hot-in', position: [hx, y - (cabinetH / 2 + 0.14), hz], direction: [0, -1, 0], diameter: 0.75, system: 'water' },
70
+ { id: 'cold-in', position: [cx, y - (cabinetH / 2 + 0.14), cz], direction: [0, -1, 0], diameter: 0.75, system: 'water' },
71
+ ]
72
+ }
73
+
74
+ export function buildPlumbingManifoldGeometry(
75
+ node: PlumbingManifoldNode,
76
+ _ctx: GeometryContext,
77
+ ): Group {
78
+ const group = new Group()
79
+ group.name = `plumbing-manifold-${node.id}`
80
+ group.add(
81
+ buildManifoldCad({
82
+ manifoldKind: node.manifoldKind as ManifoldKind,
83
+ portCount: node.portCount,
84
+ coverRemoved: node.coverRemoved,
85
+ roughInOnly: node.roughInOnly,
86
+ }),
87
+ )
88
+ return group
89
+ }
90
+
91
+ export function buildPlumbingManifoldFloorplan(
92
+ node: PlumbingManifoldNode,
93
+ ctx: GeometryContext,
94
+ ): FloorplanGeometry {
95
+ const view = ctx.viewState
96
+ const selected = (view?.selected || view?.highlighted) ?? false
97
+ const [cx, , cz] = node.position
98
+ const rot = node.rotation ?? 0
99
+ const hw = node.manifoldKind === 'gas-csst' ? 0.18 : 0.22
100
+ const hd = 0.08
101
+ const baseStroke = node.manifoldKind === 'gas-csst' ? '#eab308' : '#0284c7'
102
+ const stroke = selected && view?.palette ? view.palette.selectedStroke : baseStroke
103
+
104
+ if (node.roughInOnly) {
105
+ const r = 0.08
106
+ const children: FloorplanGeometry[] = [
107
+ { kind: 'circle', cx, cy: cz, r, fill: baseStroke, fillOpacity: 0.25, stroke, strokeWidth: 0.02 },
108
+ { kind: 'line', x1: cx - r, y1: cz, x2: cx + r, y2: cz, stroke, strokeWidth: 0.015 },
109
+ { kind: 'line', x1: cx, y1: cz - r, x2: cx, y2: cz + r, stroke, strokeWidth: 0.015 },
110
+ ]
111
+ if (selected) {
112
+ children.push({ kind: 'move-handle', point: [cx, cz] })
113
+ }
114
+ return { kind: 'group', children }
115
+ }
116
+
117
+ const p0 = rotateManifoldLocal2D(cx, cz, -hw, -hd, rot)
118
+ const p1 = rotateManifoldLocal2D(cx, cz, hw, -hd, rot)
119
+ const p2 = rotateManifoldLocal2D(cx, cz, hw, hd, rot)
120
+ const p3 = rotateManifoldLocal2D(cx, cz, -hw, hd, rot)
121
+
122
+ const children: FloorplanGeometry[] = [
123
+ {
124
+ kind: 'polygon',
125
+ points: [p0, p1, p2, p3],
126
+ fill: baseStroke,
127
+ fillOpacity: 0.16,
128
+ stroke,
129
+ strokeWidth: 0.025,
130
+ },
131
+ ]
132
+ if (node.manifoldKind === 'gas-csst') {
133
+ const g0 = rotateManifoldLocal2D(cx, cz, -hw * 0.7, 0, rot)
134
+ const g1 = rotateManifoldLocal2D(cx, cz, hw * 0.7, 0, rot)
135
+ children.push({ kind: 'line', x1: g0[0], y1: g0[1], x2: g1[0], y2: g1[1], stroke: '#eab308', strokeWidth: 0.025 })
136
+ } else {
137
+ const h0 = rotateManifoldLocal2D(cx, cz, -hw * 0.45, -hd, rot)
138
+ const h1 = rotateManifoldLocal2D(cx, cz, -hw * 0.45, hd, rot)
139
+ const c0 = rotateManifoldLocal2D(cx, cz, hw * 0.45, -hd, rot)
140
+ const c1 = rotateManifoldLocal2D(cx, cz, hw * 0.45, hd, rot)
141
+ children.push(
142
+ { kind: 'line', x1: h0[0], y1: h0[1], x2: h1[0], y2: h1[1], stroke: '#dc2626', strokeWidth: 0.025 },
143
+ { kind: 'line', x1: c0[0], y1: c0[1], x2: c1[0], y2: c1[1], stroke: '#2563eb', strokeWidth: 0.025 },
144
+ )
145
+ }
146
+ if (selected) {
147
+ children.push({ kind: 'move-handle', point: [cx, cz] })
148
+ }
149
+ return { kind: 'group', children }
150
+ }
151
+
152
+ export const plumbingManifoldRenderDefinition: NodeDefinition<typeof PlumbingManifoldNode> = {
153
+ kind: 'plumbing:manifold',
154
+ schemaVersion: 1,
155
+ schema: PlumbingManifoldNode,
156
+ category: 'utility',
157
+ distributionRole: 'equipment',
158
+ facingIndicator: true,
159
+ defaults: () => ({
160
+ object: 'node',
161
+ parentId: null,
162
+ visible: true,
163
+ metadata: {},
164
+ name: 'PEX Home-Run Manifold (12-Port)',
165
+ position: [0, 1.35, 0],
166
+ rotation: 0,
167
+ manifoldKind: 'pex-homerun',
168
+ portCount: 12,
169
+ supplyMaterial: 'pex-a',
170
+ coverRemoved: false,
171
+ roughInOnly: false,
172
+ }),
173
+ capabilities: {
174
+ selectable: { hitVolume: 'bbox' },
175
+ movable: { axes: ['x', 'y', 'z'], gridSnap: true },
176
+ rotatable: { axes: ['y'], snapAngles: [Math.PI / 2] },
177
+ duplicable: true,
178
+ deletable: true,
179
+ snappable: {},
180
+ },
181
+ geometry: buildPlumbingManifoldGeometry,
182
+ geometryKey: (n) => JSON.stringify([n.manifoldKind, n.portCount, n.coverRemoved, n.roughInOnly ?? false]),
183
+ ports: getPlumbingManifoldPorts,
184
+ floorplan: buildPlumbingManifoldFloorplan,
185
+ presentation: {
186
+ label: 'Plumbing Manifold',
187
+ description: 'PEX home-run manifold with quarter-turn ball valves, copper trunk header, or CSST gas distribution block.',
188
+ icon: { kind: 'iconify', name: 'lucide:sliders-horizontal' },
189
+ paletteSection: 'structure',
190
+ },
191
+ mcp: {
192
+ description: 'Plumbing distribution manifold (PEX home-run, copper header, or CSST gas block).',
193
+ },
194
+ }
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Auto-derived Pascal Inspector Parametrics for all 4 `plumbing:*` node kinds.
3
+ */
4
+
5
+ import type { ParametricDescriptor } from '@pascal-app/core'
6
+ import { getEquipmentElectricalDemand, getFixtureElectricalDemand } from '../ipc/framing-interop'
7
+ import { type EquipmentKind, FIXTURE_SPECS, type FixtureKind, round2 } from '../ipc/tables'
8
+ import { EquipmentKindEnum, type PlumbingEquipmentNode } from './equipment'
9
+ import { FixtureKindEnum, PipeNominalSizeEnum, type PlumbingFixtureNode } from './fixture'
10
+ import { ManifoldKindEnum, type PlumbingManifoldNode } from './manifold'
11
+ import { PipeMaterialEnum, type PlumbingPipeRunNode, PlumbingSystemEnum } from './pipe-run'
12
+
13
+ export const plumbingEquipmentParametrics: ParametricDescriptor<PlumbingEquipmentNode> = {
14
+ groups: [
15
+ {
16
+ label: 'Equipment & Capacity',
17
+ fields: [
18
+ { key: 'equipmentKind', kind: 'enum', options: [...EquipmentKindEnum.options] },
19
+ { key: 'capacityGal', kind: 'number', unit: 'gal', min: 0, max: 500, step: 5 },
20
+ { key: 'gasBtuh', kind: 'number', unit: 'BTU/h', min: 0, max: 500000, step: 5000 },
21
+ { key: 'watts', kind: 'number', unit: 'W', min: 0, max: 50000, step: 500 },
22
+ { key: 'roomVolumeCuFt', kind: 'number', unit: 'cu ft', min: 0, max: 50000, step: 50, label: 'Room Volume (HPWH >= 700 cu ft)' },
23
+ ],
24
+ },
25
+ {
26
+ label: 'IPC Safety & Compliance',
27
+ fields: [
28
+ { key: 'hasDrainPan', kind: 'boolean', label: 'Safety Drain Pan (IPC 504.7)' },
29
+ { key: 'hasTpDischarge', kind: 'boolean', label: 'T&P Relief Pipe (IPC 504.6)' },
30
+ { key: 'hasExpansionTank', kind: 'boolean', label: 'Expansion Tank (IPC 607.3)' },
31
+ ],
32
+ },
33
+ ],
34
+ derive: (next, patch, previous) => {
35
+ const kind = next.equipmentKind as EquipmentKind
36
+ const kindChanged =
37
+ 'equipmentKind' in patch &&
38
+ patch.equipmentKind !== undefined &&
39
+ (!previous || patch.equipmentKind !== previous.equipmentKind)
40
+ const wattsChanged = 'watts' in patch && typeof patch.watts === 'number'
41
+
42
+ if (kindChanged && !wattsChanged) {
43
+ const demand = getEquipmentElectricalDemand(kind)
44
+ const defaultGasBtuh =
45
+ kind === 'water-heater-tank-gas'
46
+ ? 40000
47
+ : kind === 'water-heater-tankless-gas'
48
+ ? 199000
49
+ : 0
50
+ return {
51
+ watts: demand?.loadVa ?? 0,
52
+ electricalDemand: demand,
53
+ ...(!('gasBtuh' in patch) ? { gasBtuh: defaultGasBtuh } : {}),
54
+ }
55
+ }
56
+
57
+ if (kindChanged || wattsChanged) {
58
+ const customWatts = typeof next.watts === 'number' && next.watts > 0 ? next.watts : undefined
59
+ const demand = getEquipmentElectricalDemand(kind, customWatts)
60
+ return {
61
+ watts: demand ? (customWatts ?? demand.loadVa) : (wattsChanged ? next.watts : 0),
62
+ electricalDemand: demand,
63
+ }
64
+ }
65
+
66
+ return {}
67
+ },
68
+ }
69
+
70
+ export const plumbingManifoldParametrics: ParametricDescriptor<PlumbingManifoldNode> = {
71
+ groups: [
72
+ {
73
+ label: 'Manifold Configuration',
74
+ fields: [
75
+ { key: 'manifoldKind', kind: 'enum', options: [...ManifoldKindEnum.options], display: 'segmented' },
76
+ { key: 'portCount', kind: 'number', min: 4, max: 36, step: 2 },
77
+ { key: 'coverRemoved', kind: 'boolean', label: 'Expose Open Manifold Valves' },
78
+ ],
79
+ },
80
+ ],
81
+ }
82
+
83
+ export const plumbingFixtureParametrics: ParametricDescriptor<PlumbingFixtureNode> = {
84
+ groups: [
85
+ {
86
+ label: 'Fixture & IPC Units',
87
+ fields: [
88
+ { key: 'fixtureKind', kind: 'enum', options: [...FixtureKindEnum.options] },
89
+ { key: 'dfu', kind: 'number', unit: 'DFU', min: 0, max: 20, step: 0.5 },
90
+ { key: 'wsfuCold', kind: 'number', unit: 'WSFU', min: 0, max: 20, step: 0.5 },
91
+ { key: 'wsfuHot', kind: 'number', unit: 'WSFU', min: 0, max: 20, step: 0.5 },
92
+ ],
93
+ },
94
+ {
95
+ label: 'Rough-In Sizing & Protection',
96
+ fields: [
97
+ { key: 'hasPTrap', kind: 'boolean', label: 'P-Trap Installed (IPC 1002.1)' },
98
+ { key: 'hasVacuumBreaker', kind: 'boolean', label: 'Anti-Siphon Vacuum Breaker' },
99
+ ],
100
+ },
101
+ ],
102
+ derive: (next, patch, previous) => {
103
+ const kind = next.fixtureKind as FixtureKind
104
+ const spec = FIXTURE_SPECS[kind]
105
+ const kindChanged =
106
+ 'fixtureKind' in patch &&
107
+ patch.fixtureKind !== undefined &&
108
+ (!previous || patch.fixtureKind !== previous.fixtureKind)
109
+
110
+ if (kindChanged && spec) {
111
+ const wsfuCold = 'wsfuCold' in patch ? next.wsfuCold : spec.wsfuCold
112
+ const wsfuHot = 'wsfuHot' in patch ? next.wsfuHot : spec.wsfuHot
113
+ const wsfuTotal =
114
+ 'wsfuTotal' in patch
115
+ ? next.wsfuTotal
116
+ : 'wsfuCold' in patch || 'wsfuHot' in patch
117
+ ? round2(wsfuCold + wsfuHot)
118
+ : spec.wsfuTotal
119
+ return {
120
+ ...(!('dfu' in patch) ? { dfu: spec.dfuIpc } : {}),
121
+ wsfuCold,
122
+ wsfuHot,
123
+ wsfuTotal,
124
+ ...(!('trapSize' in patch) ? { trapSize: spec.minTrapIn } : {}),
125
+ ...(!('drainSize' in patch) ? { drainSize: spec.minDrainIn } : {}),
126
+ ...(!('ventSize' in patch) ? { ventSize: spec.minVentIn } : {}),
127
+ ...(!('supplySize' in patch) ? { supplySize: spec.supplySizeIn } : {}),
128
+ ...(!('hasPTrap' in patch) ? { hasPTrap: spec.needsPTrap } : {}),
129
+ ...(!('hasVacuumBreaker' in patch) ? { hasVacuumBreaker: kind === 'hose-bibb' } : {}),
130
+ electricalDemand: getFixtureElectricalDemand(kind),
131
+ }
132
+ }
133
+
134
+ if (('wsfuCold' in patch || 'wsfuHot' in patch) && !('wsfuTotal' in patch)) {
135
+ return {
136
+ wsfuTotal: round2(next.wsfuCold + next.wsfuHot),
137
+ }
138
+ }
139
+
140
+ return {}
141
+ },
142
+ }
143
+
144
+ export const plumbingPipeRunParametrics: ParametricDescriptor<PlumbingPipeRunNode> = {
145
+ groups: [
146
+ {
147
+ label: 'System & Material',
148
+ fields: [
149
+ { key: 'system', kind: 'enum', options: [...PlumbingSystemEnum.options] },
150
+ { key: 'material', kind: 'enum', options: [...PipeMaterialEnum.options] },
151
+ { key: 'nominalSize', kind: 'enum', options: [...PipeNominalSizeEnum.options] },
152
+ ],
153
+ },
154
+ {
155
+ label: 'Slope, Loads & Framing Bore Visualization',
156
+ fields: [
157
+ { key: 'slopeInPerFt', kind: 'number', unit: 'in/ft', min: 0, max: 2, step: 0.125 },
158
+ { key: 'trapArmLengthFt', kind: 'number', unit: 'ft', min: 0, max: 50, step: 0.5 },
159
+ { key: 'dfuLoad', kind: 'number', unit: 'DFU', min: 0, max: 1000, step: 1 },
160
+ { key: 'wsfuLoad', kind: 'number', unit: 'WSFU', min: 0, max: 1000, step: 0.5 },
161
+ { key: 'gasBtuh', kind: 'number', unit: 'BTU/h', min: 0, max: 2000000, step: 5000 },
162
+ { key: 'hasCleanout', kind: 'boolean', label: 'Cleanout Installed (IPC 708.1)' },
163
+ { key: 'hasSedimentTrap', kind: 'boolean', label: 'Gas Drip Leg (IFGC 408.4)' },
164
+ { key: 'isMainVentStack', kind: 'boolean', label: 'Main Vent Stack Through Roof (IPC 903.1)' },
165
+ { key: 'isHorizontalSanTee', kind: 'boolean', label: 'Horizontal Sanitary Tee (Flagged per IPC 706.3)' },
166
+ { key: 'showFramingPenetrations', kind: 'boolean', label: 'Show 3D Stud Bore Rings & Nail Plates' },
167
+ ],
168
+ },
169
+ ],
170
+ }