{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hypochlorite-generator",
  "type": "registry:component",
  "title": "Electrochlorination (hypochlorite) package",
  "description": "Seawater electrochlorination skid: inlet ball valve, motorised auto-backwash strainer with DP gauges and flush valve, electromagnetic flowmeter (low-flow trip), a rack of tubular electrolyser cells in series with U-bends, DC terminals and busbars fed from a louvred transformer-rectifier cabinet, a GRP degassing tank with level instruments, manway and H2 / air vent stack, duty / standby hydrogen-dilution blowers with ducts, and duty / standby dosing pumps to the hypochlorite outlet. LCP and cable tray. `cells` sets the stack height.",
  "dependencies": [
    "three",
    "@react-three/fiber",
    "@react-three/drei"
  ],
  "registryDependencies": [
    "https://deck-twin-library.demoareeb.workers.dev/r/core.json"
  ],
  "files": [
    {
      "path": "packages/hypochlorite-generator.tsx",
      "type": "registry:file",
      "target": "components/deck-twin/packages/hypochlorite-generator.tsx",
      "content": "// Seawater electrochlorination (hypochlorite generator) package: auto-backwash strainer, electrolyser cell stack, transformer-rectifier, degassing tank with H2 dilution blowers, dosing pumps. NORSOK / ISO 15589-2 style, ASME B16.5.\nimport { useEffect, useMemo } from 'react'\nimport * as THREE from 'three'\nimport { Kit, type MatKey, type V3 } from '../lib/kit'\nimport { KitMesh, type GroupProps } from '../lib/mesh'\nimport { paint } from '../lib/materials'\nimport { gauge, member, motor, motorSize, pipeRun, skid, tagPlate } from '../lib/parts'\nimport { port, type Port } from '../lib/ports'\nimport { Rotors, cowlFan, type RotorSpec } from '../lib/rotors'\nimport { SECTIONS, flange as flangeDims, pipeOD, type Rating } from '../lib/standards'\nimport { louvreMaterial, textMaterial } from '../lib/textures'\nimport { addv, blFlange, cableTray, earthBoss, localPanel, padeyeShackles, pipeSupport, shellLabel, smallValve, spoolJoint, transmitter, valve, valveSpan } from './_skid'\n\nexport interface HypochloriteGeneratorProps {\n  /** electrolyser cells in series */\n  cells?: number\n  /** degassing tank diameter, m */\n  tankDiameter?: number\n  /** degassing tank height, m */\n  tankHeight?: number\n  seawaterNps?: number\n  hypoNps?: number\n  tag?: string\n  running?: boolean\n}\n\nexport const defaults = {\n  cells: 4,\n  tankDiameter: 1.2,\n  tankHeight: 1.8,\n  seawaterNps: 3,\n  hypoNps: 2,\n  tag: 'X-6500',\n  running: true,\n}\n\ntype P = typeof defaults\n\nconst SKID = 'HEB 160'\nconst R150: Rating = 150\nconst GRP: MatKey = paint('#cdbf8e', { metalness: 0.05, roughness: 0.6, clearcoat: 0 })\nconst CELL: MatKey = paint('#8d9399', { metalness: 0.7, roughness: 0.35, clearcoat: 0 })\nconst PVC: MatKey = paint('#6f747a', { metalness: 0.05, roughness: 0.5, clearcoat: 0 })\n\nfunction layout(p: P) {\n  const Nc = Math.max(2, Math.min(8, Math.round(p.cells)))\n  const Rt = p.tankDiameter / 2\n  const L = 4.6 + 2 * Rt + 0.4\n  const W = Math.max(2.6, 2 * Rt + 1.6)\n  const a = -L / 2\n  const y0 = SECTIONS[SKID].d + 0.008\n  const cp = 0.3 // cell pitch (vertical)\n  return { Nc, Rt, L, W, a, y0, cp, xS: a + 0.9, xM: a + 1.55, xc: a + 2.85, Lc: 1.3, zc: -W / 2 + 0.55, yc0: y0 + 0.45, xT: a + 4.25 + Rt, zT: -W / 2 + 0.35 + Rt, ySw: y0 + 0.6, yHy: y0 + 0.75, zHy: W / 2 - 0.45, yVent: y0 + p.tankHeight + 1.55 }\n}\n\nexport function ports(props: HypochloriteGeneratorProps = {}): Port[] {\n  const p = { ...defaults, ...props }\n  const g = layout(p)\n  return [\n    port('seawater-in', 'Seawater in', [-g.L / 2, g.ySw, g.zc], [-1, 0, 0], p.seawaterNps, R150),\n    port('hypo-out', 'Hypochlorite out', [g.L / 2, g.yHy, g.zHy], [1, 0, 0], p.hypoNps, R150),\n    port('vent', 'H2 / air vent', [g.xT, g.yVent, g.zT], [0, 1, 0], 4, R150, 'vent'),\n  ]\n}\n\nexport function HypochloriteGenerator(props: HypochloriteGeneratorProps & GroupProps) {\n  const { cells, tankDiameter, tankHeight, seawaterNps, hypoNps, tag, running, ...group } = { ...defaults, ...props }\n  const p = { cells, tankDiameter, tankHeight, seawaterNps, hypoNps, tag, running }\n  const { built, rotors } = useMemo(() => build(p), [cells, tankDiameter, tankHeight, seawaterNps, hypoNps, tag]) // eslint-disable-line react-hooks/exhaustive-deps\n  useEffect(() => () => [built, ...rotors.map((r) => r.built)].forEach((b) => b.geometry.dispose()), [built, rotors])\n  return (\n    <group {...group}>\n      <KitMesh data={built} />\n      <Rotors rotors={rotors} running={running} />\n    </group>\n  )\n}\n\nexport default HypochloriteGenerator\n\nfunction build(p: P) {\n  const k = new Kit()\n  const g = layout(p)\n  const { L, W, y0, a, zc, xc, Lc, Rt, xT, zT } = g\n  const sn = p.seawaterNps\n  const sod = pipeOD(sn)\n  const rotors: RotorSpec[] = []\n  skid(k, L, W, SKID)\n  padeyeShackles(k, L, W, y0)\n  tagPlate(k, p.tag, [a + 0.8, SECTIONS[SKID].d * 0.5, W / 2 + 0.002], 'z', 0.3)\n  earthBoss(k, [-a - 0.4, SECTIONS[SKID].d * 0.5, W / 2], [0, 0, 1])\n\n  // seawater inlet: BL → ball valve → auto-backwash strainer → mag flowmeter (low-flow trip) → cells\n  const iw = blFlange(k, [-L / 2, g.ySw, zc], [-1, 0, 0], sn, R150)\n  const Sv = valveSpan('ball', sn, R150)\n  const xv = a + 0.25 + Sv / 2\n  pipeRun(k, [iw, [xv - Sv / 2, g.ySw, zc]], sn)\n  valve(k, 'ball', [xv, g.ySw, zc], [1, 0, 0], sn, R150)\n  const fj = flangeDims(sn, R150).hubLength + flangeDims(sn, R150).raisedFaceHeight + 0.00225\n  const xs0 = g.xS - 0.22\n  const xs1 = g.xS + 0.22\n  pipeRun(k, [[xv + Sv / 2, g.ySw, zc], [xs0 - fj, g.ySw, zc]], sn)\n  for (const x of [xs0, xs1]) spoolJoint(k, [x, g.ySw, zc], [1, 0, 0], sn, R150)\n  k.cyl(PVC, 0.17, 0.75, [g.xS, g.ySw + 0.12, zc], 'y', 28)\n  k.dome(PVC, 0.17, [g.xS, g.ySw - 0.255, zc], '-y', Math.PI / 2, 0.5, 28)\n  k.cyl(PVC, 0.2, 0.05, [g.xS, g.ySw + 0.52, zc], 'y', 28)\n  k.around(10, 0.185, [g.xS, g.ySw + 0.55, zc], 'y', (q) => k.hex('nut', 0.022, 0.014, q))\n  for (const s of [-1, 1]) k.pipe(PVC, [g.xS + s * 0.15, g.ySw, zc], [g.xS + s * (0.22 - fj), g.ySw, zc], sod, 0.006)\n  const ms = motorSize(0.37, 4)\n  k.cyl('actuatorBlue', 0.06, 0.12, [g.xS, g.ySw + 0.61, zc], 'y', 16) // backwash drive gearbox\n  k.cyl('motorPaint', ms.R, ms.L * 0.8, [g.xS, g.ySw + 0.67 + ms.L * 0.4, zc], 'y', 22)\n  k.tube('pipePaint', [[g.xS, g.ySw - 0.33, zc], [g.xS, y0 + 0.12, zc], [g.xS, y0 + 0.12, zc + 0.35]], 0.024, 10, 0.05) // backwash drain\n  k.rbox('valveBody', [0.1, 0.09, 0.09], 0.01, [g.xS, y0 + 0.12, zc + 0.2])\n  k.rbox('actuatorYellow', [0.12, 0.1, 0.1], 0.01, [g.xS, y0 + 0.23, zc + 0.2])\n  for (const s of [-1, 1]) gauge(k, [g.xS + s * 0.15, g.ySw + 0.2, zc + 0.04], 'z', 0.07, 'bar', 10)\n  k.tube('tubing', [[g.xS - 0.15, g.ySw + 0.05, zc], [g.xS - 0.15, g.ySw + 0.16, zc]], 0.004, 6)\n  k.tube('tubing', [[g.xS + 0.15, g.ySw + 0.05, zc], [g.xS + 0.15, g.ySw + 0.16, zc]], 0.004, 6)\n  // electromagnetic flowmeter between flanges\n  const xm0 = g.xM - 0.18\n  const xm1 = g.xM + 0.18\n  pipeRun(k, [[xs1 + fj, g.ySw, zc], [xm0 - fj, g.ySw, zc]], sn)\n  for (const x of [xm0, xm1]) spoolJoint(k, [x, g.ySw, zc], [1, 0, 0], sn, R150)\n  k.cyl('actuatorBlue', sod / 2 + 0.05, 0.3, [g.xM, g.ySw, zc], 'x', 28)\n  k.rbox('actuatorBlue', [0.14, 0.12, 0.12], 0.02, [g.xM, g.ySw + sod / 2 + 0.12, zc])\n  k.disc('glass', 0.04, [g.xM, g.ySw + sod / 2 + 0.12, zc + 0.061], 'z', 18)\n  transmitter(k, [g.xM + 0.4, g.ySw + sod / 2, zc], [0, 1, 0], 0.06)\n\n  // ---------------------------------------------------------------- electrolyser cell stack (series, U-bends alternate ends)\n  const cx0 = xc - Lc / 2\n  const cx1 = xc + Lc / 2\n  const rC = 0.085\n  const fx = (end: number) => (end ? cx1 + 0.06 : cx0 - 0.06)\n  for (let i = 0; i < g.Nc; i++) {\n    const y = g.yc0 + i * g.cp\n    k.cyl(CELL, rC, Lc - 0.12, [xc, y, zc], 'x', 28)\n    for (const s of [-1, 1]) {\n      k.cyl('aluminium', rC + 0.04, 0.05, [xc + s * (Lc / 2 - 0.03), y, zc], 'x', 28)\n      k.around(8, rC + 0.025, [xc + s * (Lc / 2 - 0.06), y, zc], 'x', (q) => k.hex('nut', 0.022, 0.03, q, 'x'))\n      k.box('copper', [0.03, 0.05, 0.16], [xc + s * (Lc / 2 - 0.03), y + rC + 0.03, zc]) // DC terminal\n      k.cyl('aluminium', rC * 0.5, 0.06, [xc + s * (Lc / 2 + 0.02), y, zc], 'x', 18)\n    }\n    k.plane(textMaterial(`CELL ${i + 1}`, '#2a5d8a', '#fff', 256, 48), 0.18, 0.034, [xc, y, zc + rC + 0.002])\n    if (i < g.Nc - 1) {\n      const end = i % 2 === 0 ? 1 : 0\n      const x = fx(end)\n      const sgn = end ? 1 : -1\n      const pts: V3[] = []\n      for (let j = 0; j <= 10; j++) {\n        const t = (j / 10) * Math.PI\n        pts.push([x + sgn * Math.sin(t) * g.cp * 0.5, y + g.cp * 0.5 - Math.cos(t) * g.cp * 0.5, zc])\n      }\n      k.tube(PVC, pts, rC * 0.45, 12, 0.02)\n    }\n  }\n  // cell rack and copper busbars to the transformer-rectifier\n  const yTop = g.yc0 + (g.Nc - 1) * g.cp + 0.2\n  for (const x of [cx0 + 0.15, cx1 - 0.15]) for (const z of [zc - 0.18, zc + 0.18]) {\n    member(k, [x, y0, z], [x, yTop, z], 'L50x50x5', 'galvanised', [1, 0, 0])\n    k.box('galvanised', [0.1, 0.012, 0.1], [x, y0 + 0.006, z])\n  }\n  for (let i = 0; i < g.Nc; i++) for (const x of [cx0 + 0.15, cx1 - 0.15]) k.box('rubberBlack', [0.05, 0.04, 0.36], [x, g.yc0 + i * g.cp - rC - 0.02, zc])\n  // seawater into the bottom cell (-X end), product out of the top cell\n  pipeRun(k, [[xm1 + fj, g.ySw, zc], [cx0 - 0.25, g.ySw, zc], [cx0 - 0.25, g.yc0, zc], [cx0 - 0.04, g.yc0, zc]], sn, { mat: PVC })\n  const topEnd = (g.Nc - 1) % 2 === 0 ? 1 : 0\n  const yLast = g.yc0 + (g.Nc - 1) * g.cp\n  const yIn = y0 + p.tankHeight - 0.25\n  const xTin = xT - Rt\n  pipeRun(k, [[fx(topEnd) - (topEnd ? 0.02 : -0.02), yLast, zc], [topEnd ? cx1 + 0.2 : cx0 - 0.4, yLast, zc], [topEnd ? cx1 + 0.2 : cx0 - 0.4, yIn, zc], [topEnd ? cx1 + 0.2 : cx0 - 0.4, yIn, zT], [xTin + 0.01, yIn, zT]], sn, { mat: PVC })\n\n  // ---------------------------------------------------------------- transformer-rectifier cabinet (front) with DC cables\n  const trx = xc\n  const trz = W / 2 - 0.5\n  const trW = 1.2\n  const trH = 1.9\n  const trD = 0.7\n  k.box('equipmentPaintDark', [trW + 0.06, 0.1, trD + 0.06], [trx, y0 + 0.05, trz])\n  k.rbox('equipmentPaint', [trW, trH, trD], 0.015, [trx, y0 + 0.1 + trH / 2, trz])\n  for (const s of [-1, 1]) {\n    k.box('equipmentPaintDark', [0.008, trH - 0.1, 0.004], [trx + s * 0.002, y0 + 0.1 + trH / 2, trz + trD / 2 + 0.002])\n    const lv = new THREE.PlaneGeometry(trW * 0.35, 0.5)\n    const uv = lv.getAttribute('uv') as THREE.BufferAttribute\n    for (let i = 0; i < uv.count; i++) uv.setY(i, uv.getY(i) * 8)\n    k.add(louvreMaterial('#c9ccc8'), lv, new THREE.Matrix4().makeTranslation(trx + s * trW * 0.25, y0 + 0.45, trz + trD / 2 + 0.003))\n    k.box('nut', [0.02, 0.14, 0.03], [trx + s * 0.08, y0 + 1.1, trz + trD / 2 + 0.015])\n  }\n  k.box('rubberBlack', [0.3, 0.2, 0.01], [trx - trW * 0.25, y0 + 1.5, trz + trD / 2 + 0.005])\n  k.plane(textMaterial('DC 450 A', '#1d2b1d', '#7fe08a', 256, 128), 0.26, 0.15, [trx - trW * 0.25, y0 + 1.5, trz + trD / 2 + 0.011])\n  for (const [i, c] of (['safetyGreen', 'actuatorRed', 'actuatorYellow'] as MatKey[]).entries()) k.cyl(c, 0.015, 0.02, [trx + trW * 0.12 + i * 0.07, y0 + 1.5, trz + trD / 2 + 0.01], 'z', 12)\n  k.plane(textMaterial('TRANSFORMER RECTIFIER', '#f2f2ee', '#111', 512, 64), trW * 0.6, trW * 0.075, [trx, y0 + 1.82, trz + trD / 2 + 0.004])\n  k.box('equipmentPaint', [trW * 0.6, 0.16, trD * 0.6], [trx, y0 + 0.1 + trH + 0.08, trz]) // roof fan housing\n  for (const s of [-1, 1]) {\n    const tx = s > 0 ? cx1 - 0.03 : cx0 + 0.03\n    k.spline('cable', [[trx + s * 0.2, y0 + 0.1 + trH, trz - 0.1], [trx + s * 0.25, y0 + trH + 0.45, trz - 0.3], [tx, yTop + 0.3, zc + 0.05], [tx, g.yc0 + rC + 0.05, zc + 0.05]], 0.022, 8, 28)\n  }\n  for (let i = 0; i < g.Nc - 1; i++) {\n    const end = i % 2 === 0 ? 1 : 0\n    const x = end ? cx1 - 0.03 : cx0 + 0.03\n    k.box('copper', [0.025, g.cp - 0.04, 0.02], [x, g.yc0 + (i + 0.5) * g.cp + rC * 0.4, zc + 0.07]) // inter-cell busbar\n  }\n\n  // ---------------------------------------------------------------- degassing tank, H2 dilution blowers, vent stack\n  k.cyl('equipmentPaintDark', Rt + 0.05, 0.12, [xT, y0 + 0.06, zT], 'y', 40)\n  k.cyl(GRP, Rt, p.tankHeight, [xT, y0 + 0.12 + p.tankHeight / 2, zT], 'y', 40)\n  k.cyl(GRP, Rt + 0.02, 0.04, [xT, y0 + 0.12 + p.tankHeight, zT], 'y', 40)\n  k.dome(GRP, Rt + 0.02, [xT, y0 + 0.14 + p.tankHeight, zT], 'y', Math.PI / 2, 0.15, 40)\n  for (const f of [0.33, 0.66]) k.torus(GRP, Rt + 0.004, 0.012, [xT, y0 + 0.12 + p.tankHeight * f, zT], 'y', 6, 40)\n  shellLabel(k, 'HYPOCHLORITE DEGASSING TANK', xT, y0 + 0.12 + p.tankHeight * 0.5, zT, Rt, Rt * 0.12, 1.4, '#f5c400', '#111')\n  const yRoof = y0 + 0.14 + p.tankHeight + (Rt + 0.02) * 0.15\n  const vf = flangeDims(4, R150)\n  const vw = addv([xT, g.yVent, zT], [0, -1, 0], vf.hubLength + vf.raisedFaceHeight)\n  k.pipe(GRP, [xT, yRoof - 0.04, zT], vw, pipeOD(4) + 0.01, 0.008)\n  k.disc('pipeBore', pipeOD(4) / 2 - 0.004, [xT, yRoof - 0.035, zT], 'y', 20)\n  blFlange(k, [xT, g.yVent, zT], [0, 1, 0], 4, R150)\n  k.box('galvanised', [0.05, g.yVent - 0.35 - yRoof, 0.05], [xT + 0.1, (g.yVent - 0.35 + yRoof) / 2, zT])\n  // level transmitter and gauge, manway\n  k.cyl(GRP, 0.06, 0.15, [xT - Rt * 0.5, yRoof, zT + Rt * 0.3], 'y', 16)\n  k.cyl('actuatorBlue', 0.055, 0.12, [xT - Rt * 0.5, yRoof + 0.15, zT + Rt * 0.3], 'y', 16)\n  k.cyl(GRP, 0.28, 0.08, [xT + Rt * 0.4, yRoof - 0.01, zT - Rt * 0.2], 'y', 28)\n  k.around(10, 0.25, [xT + Rt * 0.4, yRoof + 0.035, zT - Rt * 0.2], 'y', (q) => k.hex('nut', 0.022, 0.012, q))\n  const lgx = xT + Rt * 0.7\n  const lgz = zT + Rt * 0.71 + 0.08\n  k.cyl('glass', 0.025, p.tankHeight * 0.75, [lgx, y0 + 0.12 + p.tankHeight * 0.45, lgz], 'y', 14)\n  for (const f of [0.1, 0.8]) k.rod(PVC, [lgx, y0 + 0.12 + p.tankHeight * f, lgz], [lgx - 0.05, y0 + 0.12 + p.tankHeight * f, lgz - 0.08], 0.014, 8)\n  // twin H2 dilution blowers with ducts into the tank roof space\n  const bz = zT + Rt + 0.55\n  const mb = motorSize(2.2, 2)\n  const Hb = Math.max(mb.H, mb.R * 1.25)\n  for (const [i, bx] of [xT - 0.45, xT + 0.45].entries()) {\n    k.box('equipmentPaintDark', [0.6, 0.08, 0.4], [bx, y0 + 0.04, bz])\n    k.cyl('actuatorYellow', 0.22, 0.14, [bx + 0.15, y0 + 0.08 + 0.26, bz], 'x', 32) // scroll\n    k.box('actuatorYellow', [0.14, 0.24, 0.16], [bx + 0.15, y0 + 0.08 + 0.4, bz - 0.12])\n    k.disc(louvreMaterial('#666'), 0.1, [bx + 0.225, y0 + 0.34, bz], 'x', 20)\n    k.at([bx + 0.06, y0 + 0.08 + Hb, bz], undefined, () => k.at([0, 0, 0], new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI), () => motor(k, { R: mb.R, L: mb.L, H: Hb, tbox: 'top', fins: 20 })))\n    const fan = cowlFan(mb.R, mb.L, 290)\n    const fp = new THREE.Vector3(...fan.pos).applyQuaternion(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI)).add(new THREE.Vector3(bx + 0.06, y0 + 0.08 + Hb, bz))\n    rotors.push({ ...fan, pos: fp.toArray() as V3, rot: [0, Math.PI, 0] })\n    const ductTop = yRoof - 0.15 - i * 0.12\n    k.tube(PVC, [[bx + 0.15, y0 + 0.08 + 0.52, bz - 0.12], [bx + 0.15, ductTop, bz - 0.12], [bx + 0.15, ductTop, zT + Rt * Math.cos(Math.asin(Math.min(0.9, Math.abs(bx + 0.15 - xT) / Rt))) - 0.02]], 0.06, 14, 0.12)\n    smallValve(k, 'ball', [bx + 0.15, ductTop - 0.4, bz - 0.12], [0, 1, 0], 0.03, [1, 0, 0])\n  }\n  k.rbox('stainless', [0.12, 0.15, 0.08], 0.01, [xT, y0 + 0.9, bz - 0.1]) // airflow switch\n\n  // dosing pumps: tank bottom → duty / standby pumps → hypo header → BL\n  const hn = p.hypoNps\n  const yPs = y0 + 0.35\n  const zs = zT + Rt * 0.3\n  const xpA = xT + Rt + 0.35\n  const mp = motorSize(1.5, 4)\n  const Hp = Math.max(mp.H, mp.R * 1.25)\n  pipeRun(k, [[xT + Rt - 0.02, yPs, zs], [xpA - 0.3, yPs, zs], [xpA - 0.3, yPs, g.zHy - 0.55]], hn, { mat: PVC })\n  for (const [i, zz] of [zs - 0.1, g.zHy - 0.55].entries()) {\n    const x = xpA + 0.12\n    const z = i === 0 ? zz : zz\n    k.box('equipmentPaintDark', [0.7, 0.06, 0.3], [x + 0.05, y0 + 0.03, z])\n    k.cyl('machineryGreen', 0.1, 0.1, [x + 0.25, yPs, z], 'x', 24)\n    k.cyl('machineryGreen', 0.05, 0.12, [x + 0.25, yPs + 0.13, z], 'y', 14)\n    k.at([x + 0.18, yPs, z], undefined, () => motor(k, { R: mp.R, L: mp.L, H: Hp, tbox: 'top', fins: 18 }))\n    k.tube(PVC, [[xpA - 0.3, yPs, i === 0 ? zs : g.zHy - 0.55], [xpA - 0.3, yPs, z], [x + 0.32, yPs, z]], pipeOD(hn) / 2, 10, 0.05)\n    k.tube(PVC, [[x + 0.25, yPs + 0.19, z], [x + 0.25, g.yHy, z], [x + 0.25, g.yHy, g.zHy]], pipeOD(hn) / 2, 10, 0.06)\n    smallValve(k, 'ball', [x + 0.25, (yPs + g.yHy) / 2 + 0.05, z], [0, 1, 0], 0.016, [1, 0, 0])\n    k.hex(PVC, 0.06, 0.08, [x + 0.25, (yPs + g.yHy) / 2 - 0.08, z], 'y') // check valve\n  }\n  const hw = blFlange(k, [L / 2, g.yHy, g.zHy], [1, 0, 0], hn, R150)\n  pipeRun(k, [[xpA + 0.37 - 0.05, g.yHy, g.zHy], hw], hn, { mat: PVC })\n  k.dome(PVC, pipeOD(hn) / 2, [xpA + 0.32, g.yHy, g.zHy], '-x', Math.PI / 2, 0.5, 20)\n  gauge(k, [L / 2 - 0.3, g.yHy + pipeOD(hn) / 2 + 0.12, g.zHy + 0.02], 'z', 0.08, 'bar', 10)\n  k.rod('stainless', [L / 2 - 0.3, g.yHy + pipeOD(hn) / 2 - 0.01, g.zHy], [L / 2 - 0.3, g.yHy + pipeOD(hn) / 2 + 0.08, g.zHy], 0.007, 8)\n  pipeSupport(k, [L / 2 - 0.45, g.yHy, g.zHy], pipeOD(hn), y0, 'x')\n  pipeSupport(k, [cx0 - 0.25, g.ySw * 0.5 + g.yc0 * 0.5, zc], sod, y0, 'z')\n\n  // ---------------------------------------------------------------- LCP and cable tray\n  const lx = a + 0.55\n  const gl = localPanel(k, [lx, y0, W / 2 - 0.3], [0, 0, 1], { w: 0.5, h: 0.6, top: 1.85, title: 'ELECTROCHLORINATION LCP', buttons: 4 })\n  const tz = W / 2 - 0.12\n  cableTray(k, [[lx, gl[1] - 0.04, gl[2]], [lx, y0 + 0.22, gl[2]], [lx, y0 + 0.22, tz], [xpA + 0.2, y0 + 0.22, tz]], [1, 0, 0], 0.15, 3)\n  k.spline('cable', [[trx - trW / 2 - 0.05, y0 + 0.24, tz], [trx - trW / 2 + 0.05, y0 + 0.3, trz], [trx - trW / 2 + 0.15, y0 + 0.12, trz]], 0.015, 6, 12)\n  return { built: k.build(), rotors }\n}\n"
    },
    {
      "path": "packages/_skid.ts",
      "type": "registry:file",
      "target": "components/deck-twin/packages/_skid.ts",
      "content": "// Shared package-skid parts: battery-limit flanges, in-kit valves, instruments, local panels, cable tray, supports, vessels, drip pans.\nimport * as THREE from 'three'\nimport { Kit, type MatKey, type V3 } from '../lib/kit'\nimport { flange, flangedJoint, gasket, gauge, member } from '../lib/parts'\nimport { faceToFace, flange as flangeDims, handwheelDia, headDepth, pipeOD, pipeWall, type Rating } from '../lib/standards'\nimport { lcdMaterial, textMaterial } from '../lib/textures'\n\nconst V = (v: V3) => new THREE.Vector3(...v)\nconst arr = (v: THREE.Vector3) => v.toArray() as V3\nexport const addv = (a: V3, d: V3, s = 1): V3 => [a[0] + d[0] * s, a[1] + d[1] * s, a[2] + d[2] * s]\n\n/** Local frame with +X along `dir` and +Y as close to `up` as possible, origin at `pos`. */\nexport function frame(pos: V3, dir: V3, up: V3 = [0, 1, 0]) {\n  const x = V(dir).normalize()\n  let u = V(up).normalize()\n  if (Math.abs(u.dot(x)) > 0.99) u = Math.abs(x.y) > 0.9 ? new THREE.Vector3(0, 0, 1) : new THREE.Vector3(0, 1, 0)\n  const z = new THREE.Vector3().crossVectors(x, u).normalize()\n  const y = new THREE.Vector3().crossVectors(z, x).normalize()\n  return new THREE.Matrix4().makeBasis(x, y, z).setPosition(V(pos))\n}\n\n/** Battery-limit weld-neck flange with studs, face at `face` pointing along `dir`. Returns the weld end for the neck pipe. */\nexport function blFlange(k: Kit, face: V3, dir: V3, nps: number, rating: Rating, studs = true): V3 {\n  const L = flange(k, nps, rating, face, dir, studs)\n  liner(k, nps, face, dir, L)\n  return addv(face, dir, -L)\n}\n\n/** Bore lining through a weld-neck flange (face to weld end) so a flange reads hollow when looked into. */\nexport function liner(k: Kit, nps: number, face: V3, dir: V3, len: number) {\n  const ro = pipeOD(nps) / 2\n  const ri = ro - pipeWall(nps, 'STD')\n  k.lathe('machined', [[ro * 0.88, 0], [ri, 0]], face, dir, 24)\n  k.lathe('pipeBore', [[ri, 0], [ri, -len]], face, dir, 24)\n}\n\nexport type ValveKind = 'ball' | 'gate' | 'globe' | 'check'\n\n/** Overall length of an in-kit flanged valve including both mating pipe flanges (weld end to weld end). */\nexport function valveSpan(kind: ValveKind, nps: number, rating: Rating) {\n  const f = flangeDims(nps, rating)\n  const fam = kind === 'ball' ? 'ball-full' : kind === 'check' ? 'swing-check' : kind\n  return faceToFace(fam, nps, rating) + 2 * (0.0045 + f.hubLength + f.raisedFaceHeight)\n}\n\n/**\n * Flanged valve centred at `pos` on a line along `dir`, operator towards `up`. Both mating pipe flanges, gaskets\n * and studs are included, so the line pipe stops at pos ± dir·valveSpan/2.\n */\nexport function valve(k: Kit, kind: ValveKind, pos: V3, dir: V3, nps: number, rating: Rating, up: V3 = [0, 1, 0], body: MatKey = 'valveBody', open = 1, op: 'manual' | 'mov' | 'diaphragm' = 'manual') {\n  const fam = kind === 'ball' ? 'ball-full' : kind === 'check' ? 'swing-check' : kind\n  const L = faceToFace(fam, nps, rating)\n  const f = flangeDims(nps, rating)\n  const D = pipeOD(nps)\n  const fl = f.thickness + f.raisedFaceHeight\n  k.with(frame(pos, dir, up), () => {\n    spoolJoint(k, [L / 2 + 0.00225, 0, 0], [1, 0, 0], nps, rating)\n    spoolJoint(k, [-L / 2 - 0.00225, 0, 0], [-1, 0, 0], nps, rating)\n    const inner = L / 2 - fl\n    const ri = D / 2 - pipeWall(nps, 'STD')\n    k.pipe(body, [-inner - 0.002, 0, 0], [inner + 0.002, 0, 0], D * 1.24, D * 0.62 - ri + 0.003, 28)\n    if (kind === 'ball') {\n      k.sphere(body, D * 0.82, [0, 0, 0], [1.05, 1, 1], 28)\n      for (const s of [-1, 1]) k.cyl(body, D * 0.78, 0.012, [s * D * 0.55, 0, 0], 'x', 28)\n      k.around(8, D * 0.7, [D * 0.55, 0, 0], 'x', (p) => k.hex('nut', 0.016, 0.01, addv(p, [0.008, 0, 0])))\n      const yTop = D * 0.95\n      k.cyl(body, D * 0.3, yTop - D * 0.6, [0, (yTop + D * 0.6) / 2, 0], 'y', 16)\n      k.cyl(body, D * 0.36, 0.012, [0, yTop, 0], 'y', 16)\n      if (op === 'mov') movActuator(k, yTop, D, body)\n      else if (nps <= 4) {\n        const lever = Math.max(0.15, handwheelDia('ball-full', nps, rating))\n        const a = (1 - open) * (Math.PI / 2)\n        k.cyl('nut', D * 0.12, 0.04, [0, yTop + 0.02, 0], 'y', 10)\n        k.box('actuatorRed', [lever, 0.012, 0.03], [(Math.cos(a) * lever) / 2 - Math.cos(a) * 0.02, yTop + 0.045, (-Math.sin(a) * lever) / 2], new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), a))\n      } else {\n        const gb = Math.max(0.12, D * 0.7)\n        k.rbox(body, [gb, gb * 0.6, gb * 0.8], gb * 0.08, [0, yTop + gb * 0.3, 0])\n        k.cyl(body, gb * 0.15, gb * 0.5, [0, yTop + gb * 0.3, gb * 0.6], 'z', 12)\n        k.handwheel('handwheel', Math.max(0.3, gb * 1.8), [0, yTop + gb * 0.3, gb * 0.85], 'z', 5)\n      }\n    } else if (kind === 'check') {\n      k.sphere(body, D * 0.78, [0, 0, 0], [1.25, 1, 0.95], 24)\n      const yc = D * 0.72\n      k.cyl(body, D * 0.62, 0.04, [0, yc, 0], 'y', 24)\n      k.cyl(body, D * 0.66, 0.025, [0, yc + 0.032, 0], 'y', 24)\n      k.around(8, D * 0.58, [0, yc + 0.045, 0], 'y', (p) => k.hex('nut', 0.018, 0.012, p))\n      k.box('stainless', [D * 0.5, 0.002, D * 0.25], [0, 0, D * 0.79])\n    } else {\n      // gate / globe: bolted bonnet, yoke, rising stem, handwheel\n      if (kind === 'globe') k.sphere(body, D * 0.85, [0, 0, 0], [1.2, 1, 0.95], 24)\n      else k.add(body, new THREE.CylinderGeometry(1, 1, D * 1.5, 28), new THREE.Matrix4().compose(new THREE.Vector3(0, D * 0.15, 0), new THREE.Quaternion(), new THREE.Vector3(D * 0.62, 1, D * 0.72)))\n      const yb = kind === 'globe' ? D * 0.8 : D * 0.9\n      k.cyl(body, D * 0.62, 0.03, [0, yb, 0], 'y', 24)\n      k.around(8, D * 0.55, [0, yb + 0.02, 0], 'y', (p) => k.hex('nut', 0.018, 0.012, p))\n      const hB = Math.max(0.08, D * 0.9)\n      k.cyl(body, D * 0.3, hB, [0, yb + hB / 2, 0], 'y', 16, D * 0.22)\n      const yoke = Math.max(0.12, D * 1.3)\n      const y0 = yb + hB\n      for (const s of [-1, 1]) k.box(body, [Math.max(0.012, D * 0.12), yoke, Math.max(0.012, D * 0.1)], [s * D * 0.28, y0 + yoke / 2, 0])\n      k.box(body, [D * 0.7, Math.max(0.016, D * 0.12), D * 0.2], [0, y0 + yoke, 0])\n      if (op === 'diaphragm') {\n        // spring-opposed diaphragm actuator with positioner\n        const Ra = THREE.MathUtils.clamp(D * 1.6, 0.14, 0.3)\n        const ya = y0 + yoke + 0.02\n        k.cyl('stainless', Math.max(0.006, D * 0.05), yoke * 0.8, [0, y0 + yoke * 0.5, 0], 'y', 10)\n        k.lathe('actuatorBlue', [[0.02, 0], [Ra * 0.9, 0], [Ra, Ra * 0.12], [Ra, Ra * 0.18], [Ra * 0.9, Ra * 0.2]], [0, ya, 0], 'y', 32)\n        k.lathe('actuatorBlue', [[Ra * 0.9, Ra * 0.2], [Ra, Ra * 0.22], [Ra, Ra * 0.28], [Ra * 0.7, Ra * 0.55], [0.02, Ra * 0.6]], [0, ya, 0], 'y', 32)\n        k.around(12, Ra * 0.95, [0, ya + Ra * 0.2, 0], 'y', (p) => k.hex('nut', 0.014, 0.012, p))\n        k.rbox('aluminium', [0.1, 0.12, 0.06], 0.01, [D * 0.35 + 0.05, y0 + yoke * 0.5, 0.04])\n        k.tube('tubing', [[D * 0.35 + 0.05, y0 + yoke * 0.5 + 0.06, 0.04], [D * 0.35 + 0.05, ya + Ra * 0.4, 0.04], [0.02, ya + Ra * 0.62, 0.04]], 0.004, 6, 0.02)\n      } else {\n        const stemTop = y0 + yoke + 0.04 + open * D * 0.6\n        k.cyl('stainless', Math.max(0.006, D * 0.05), stemTop - y0, [0, (stemTop + y0) / 2, 0], 'y', 10)\n        k.handwheel('handwheel', Math.max(0.16, handwheelDia(kind, nps, rating)), [0, y0 + yoke + 0.04, 0], 'y', 4)\n      }\n    }\n    k.box('stainless', [D * 0.45, D * 0.2, 0.002], [0, -D * 0.2, D * 0.63])\n  })\n  return valveSpan(kind, nps, rating)\n}\n\n/** Electric multi-turn actuator on a gearbox (valve-local frame, stem +Y from `y`). */\nfunction movActuator(k: Kit, y: number, D: number, body: MatKey) {\n  const s = THREE.MathUtils.clamp(D * 1.8, 0.45, 1.2)\n  k.cyl(body, D * 0.36, 0.06 * s, [0, y + 0.03 * s, 0], 'y', 20)\n  k.rbox(body, [0.24 * s, 0.2 * s, 0.26 * s], 0.02 * s, [0, y + 0.16 * s, 0])\n  k.rbox('actuatorBlue', [0.2 * s, 0.26 * s, 0.22 * s], 0.025 * s, [0, y + 0.39 * s, 0])\n  k.cyl('actuatorBlue', 0.08 * s, 0.28 * s, [0, y + 0.37 * s, 0.24 * s], 'z', 20)\n  k.cyl('actuatorBlue', 0.085 * s, 0.03 * s, [0, y + 0.37 * s, 0.38 * s], 'z', 20)\n  k.rbox('actuatorBlue', [0.16 * s, 0.1 * s, 0.14 * s], 0.015 * s, [0, y + 0.57 * s, 0])\n  k.disc('glass', 0.035 * s, [0, y + 0.39 * s, 0.111 * s], 'z', 18)\n  k.handwheel('handwheel', 0.3 * s, [-0.16 * s, y + 0.39 * s, 0], '-x', 4)\n  for (const dx of [-0.05, 0.05]) k.cyl('brass', 0.012 * s, 0.04 * s, [dx * s, y + 0.25 * s, -0.12 * s], 'z', 8)\n}\n\n/** Small-bore instrument / tubing valve (needle or ball) on a line along `dir`, handle towards `up`. Body length ≈ 8 r. */\nexport function smallValve(k: Kit, kind: 'needle' | 'ball', pos: V3, dir: V3, r: number, up: V3 = [0, 1, 0], mat: MatKey = 'stainless') {\n  const b = Math.max(0.012, r * 2.2)\n  k.with(frame(pos, dir, up), () => {\n    k.box(mat, [b * 2.6, b * 1.4, b * 1.4], [0, 0, 0])\n    for (const s of [-1, 1]) k.hex(mat, b * 1.25, b * 0.8, [s * b * 1.6, 0, 0], 'x')\n    if (kind === 'needle') {\n      k.cyl(mat, b * 0.45, b * 1.6, [0, b * 1.4, 0], 'y', 10)\n      k.hex(mat, b * 1.1, b * 0.5, [0, b * 1.1, 0], 'y')\n      k.box('handwheel', [b * 2.2, b * 0.35, b * 0.4], [0, b * 2.25, 0])\n    } else {\n      k.cyl(mat, b * 0.35, b * 0.8, [0, b * 1.0, 0], 'y', 10)\n      k.box('actuatorRed', [b * 4, b * 0.25, b * 0.6], [b * 1.6, b * 1.45, 0])\n    }\n  })\n}\n\n/** Small conventional relief valve: inlet at `inlet` going up (+Y), outlet towards `out`. Returns the outlet connection point. */\nexport function smallPsv(k: Kit, inlet: V3, out: V3, size = 0.025, body: MatKey = 'stainless', bonnet: MatKey = 'actuatorRed') {\n  const s = size\n  const o = V(out).normalize()\n  const c = addv(inlet, [0, 1, 0], s * 2.2)\n  k.hex(body, s * 1.6, s * 0.9, addv(inlet, [0, 1, 0], s * 0.45))\n  k.cyl(body, s * 1.0, s * 2.4, addv(c, [0, -1, 0], s * 0.3), 'y', 16)\n  k.sphere(body, s * 1.15, c, undefined, 14)\n  const oc = addv(c, arr(o), s * 1.4)\n  k.rod(body, c, oc, s * 0.7, 12)\n  k.hex(body, s * 1.6, s * 0.9, addv(c, arr(o), s * 1.9), arr(o))\n  k.cyl(bonnet, s * 0.75, s * 3.2, addv(c, [0, 1, 0], s * 2.4), 'y', 14, s * 0.55)\n  k.cyl(bonnet, s * 0.6, s * 0.9, addv(c, [0, 1, 0], s * 4.4), 'y', 12, s * 0.4)\n  k.box('nut', [s * 2.2, s * 0.2, s * 0.35], addv(c, [0, 1, 0], s * 4.2))\n  k.box('stainless', [s * 0.03 + 0.012, s * 1.2, 0.0015], addv(addv(c, [0, 1, 0], s * 2.4), [0, 0, 1], s * 0.8))\n  return addv(c, arr(o), s * 2.35)\n}\n\n/** Pressure transmitter (coplanar, 2-valve manifold) on an impulse stub from `tap` along `n`; dual-compartment head with LCD. */\nexport function transmitter(k: Kit, tap: V3, n: V3, standoff = 0.1, housing: MatKey = 'actuatorBlue') {\n  const d = V(n).normalize()\n  const m = addv(tap, arr(d), standoff)\n  k.rod('tubing', tap, m, 0.007, 8)\n  k.with(frame(m, arr(d)), () => {\n    k.box('stainless', [0.05, 0.05, 0.07], [0.025, 0, 0])\n    for (const s of [-1, 1]) k.cyl('handwheel', 0.006, 0.04, [0.025, 0, s * 0.055], 'z', 6)\n    k.box('stainless', [0.03, 0.06, 0.06], [0.065, 0.01, 0])\n    k.cyl('stainless', 0.03, 0.07, [0.07, 0.075, 0], 'y', 16)\n    k.cyl(housing, 0.042, 0.1, [0.07, 0.15, 0], 'x', 20)\n    for (const s of [-1, 1]) k.cyl(housing, 0.046, 0.022, [0.07 + s * 0.06, 0.15, 0], 'x', 20)\n    k.disc(lcdMaterial(), 0.03, [0.132, 0.15, 0], 'x', 20)\n    k.disc('glass', 0.034, [0.133, 0.15, 0], 'x', 20)\n    k.cyl('brass', 0.011, 0.03, [0.07, 0.15, 0.055], 'z', 8)\n  })\n}\n\n/** Thermowell with transmitter head, inserted at `at` on a pipe, head out along `n`. */\nexport function tempElement(k: Kit, at: V3, n: V3, od: number) {\n  const d = V(n).normalize()\n  const base = addv(at, arr(d), od / 2)\n  k.with(frame(base, arr(d)), () => {\n    k.cyl('stainless', 0.02, 0.04, [0.02, 0, 0], 'x', 12)\n    k.hex('stainless', 0.032, 0.02, [0.05, 0, 0], 'x')\n    k.cyl('stainless', 0.008, 0.06, [0.09, 0, 0], 'x', 8)\n    k.cyl('aluminium', 0.04, 0.06, [0.15, 0, 0], 'x', 18)\n    k.cyl('aluminium', 0.043, 0.015, [0.185, 0, 0], 'x', 18)\n    k.cyl('brass', 0.009, 0.025, [0.15, -0.045, 0], 'y', 8)\n  })\n}\n\n/** Instrument tapping with root valve and pressure gauge, from `tap` along `n`. */\nexport function gaugeTap(k: Kit, tap: V3, n: V3, max = 100, d = 0.1, unit: 'bar' | '°C' = 'bar') {\n  const v = V(n).normalize()\n  const a = addv(tap, arr(v), 0.05)\n  k.rod('tubing', tap, addv(tap, arr(v), 0.12), 0.007, 8)\n  smallValve(k, 'needle', a, arr(v), 0.006, Math.abs(v.y) > 0.9 ? [0, 0, 1] : [0, 1, 0])\n  const g = addv(tap, arr(v), 0.12 + d * 0.16)\n  const face: V3 = Math.abs(v.y) > 0.9 ? [0, 0, 1] : arr(v)\n  if (Math.abs(v.y) > 0.9) {\n    k.rod('tubing', addv(tap, arr(v), 0.12), addv(addv(tap, arr(v), 0.12), [0, 0, 1], 0.001), 0.007, 8)\n    gauge(k, addv(tap, arr(v), 0.12 + d / 2), face, d, unit, max)\n  } else gauge(k, g, face, d, unit, max)\n}\n\n/** Ladder cable tray along a polyline. Horizontal runs lie flat; vertical runs use `side` (horizontal) as the width direction. */\nexport function cableTray(k: Kit, pts: V3[], side: V3, w = 0.15, cables = 3) {\n  const sv = V(side).normalize()\n  const UP = new THREE.Vector3(0, 1, 0)\n  const sideOf = (d: THREE.Vector3) => (Math.abs(d.y) > 0.9 ? sv.clone() : new THREE.Vector3().crossVectors(UP, d).normalize())\n  const segs: { a: THREE.Vector3; d: THREE.Vector3; L: number; s: THREE.Vector3; n: THREE.Vector3 }[] = []\n  for (let i = 0; i < pts.length - 1; i++) {\n    const a = V(pts[i])\n    const d = V(pts[i + 1]).sub(a)\n    const L = d.length()\n    if (L < 1e-4) continue\n    d.normalize()\n    const s = sideOf(d)\n    let n = new THREE.Vector3().crossVectors(s, d).normalize()\n    if (Math.abs(d.y) < 0.9 && n.y < 0) n = n.negate()\n    segs.push({ a, d, L, s, n })\n  }\n  for (const { a, d, L, s, n } of segs) {\n    const q = new THREE.Quaternion().setFromRotationMatrix(new THREE.Matrix4().makeBasis(d, n, new THREE.Vector3().crossVectors(d, n)))\n    const mid = a.clone().addScaledVector(d, L / 2)\n    for (const sg of [-1, 1]) k.box('cableTray', [L + 0.01, 0.05, 0.003], arr(mid.clone().addScaledVector(s, (sg * w) / 2).addScaledVector(n, 0.02)), q)\n    const nr = Math.max(1, Math.floor(L / 0.25))\n    for (let j = 0; j <= nr; j++) k.box('cableTray', [0.02, 0.006, w], arr(a.clone().addScaledVector(d, (j / nr) * L).addScaledVector(n, 0.003)), q)\n  }\n  for (let c = 0; c < cables; c++) {\n    const off = ((c + 0.5) / cables - 0.5) * w * 0.7\n    const P: V3[] = []\n    segs.forEach(({ a, d, L, s, n }, i) => {\n      if (i === 0) P.push(arr(a.clone().addScaledVector(s, off).addScaledVector(n, 0.014)))\n      P.push(arr(a.clone().addScaledVector(d, L).addScaledVector(s, off).addScaledVector(n, 0.014)))\n    })\n    k.tube('cable', P, 0.008, 6, 0.08)\n  }\n}\n\n/**\n * Local control panel on two posts, door facing `n` (±X or ±Z), standing on the deck at `base`.\n * Returns the cable-gland point under the enclosure (for a tray run).\n */\nexport function localPanel(k: Kit, base: V3, n: V3, opts: { w?: number; h?: number; top?: number; title?: string; screen?: boolean; buttons?: number } = {}) {\n  const w = opts.w ?? 0.6\n  const h = opts.h ?? 0.7\n  const top = opts.top ?? 1.75\n  const dep = 0.25\n  const nn = V(n).normalize()\n  const side = new THREE.Vector3(0, 1, 0).cross(nn).normalize()\n  const q = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, 1), nn)\n  const at = (x: number, y: number, z: number) => arr(V(base).addScaledVector(side, x).add(new THREE.Vector3(0, y, 0)).addScaledVector(nn, z))\n  for (const s of [-1, 1]) {\n    member(k, at(s * (w / 2 - 0.05), 0, -0.05), at(s * (w / 2 - 0.05), top + 0.15, -0.05), 'UPN 80', 'galvanised', arr(nn))\n    k.box('galvanised', [0.16, 0.012, 0.16], at(s * (w / 2 - 0.05), 0.006, -0.05), q)\n  }\n  for (const y of [0.35, top - h - 0.05]) member(k, at(-w / 2, y, -0.03), at(w / 2, y, -0.03), 'L50x50x5', 'galvanised', [0, 1, 0])\n  const yc = top - h / 2\n  k.rbox('stainless', [w, h, dep], 0.015, at(0, yc, dep / 2), q)\n  k.rbox('stainless', [w - 0.03, h - 0.03, 0.012], 0.006, at(0, yc, dep + 0.006), q)\n  for (const s of [-0.3, 0.3]) k.box('nut', [0.02, 0.06, 0.012], at(w / 2 - 0.04, yc + s * h, dep + 0.016), q)\n  k.box('stainless', [w + 0.12, 0.01, dep + 0.2], at(0, top + 0.1, dep / 2 + 0.03), new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, 1), nn).multiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1, 0, 0), 0.12)))\n  const fz = dep + 0.013\n  if (opts.screen !== false) {\n    k.box('rubberBlack', [w * 0.5, h * 0.3, 0.006], at(0, yc + h * 0.18, fz), q)\n    k.plane(lcdMaterial(), w * 0.45, h * 0.26, at(0, yc + h * 0.18, fz + 0.0035), q)\n  }\n  const nb = opts.buttons ?? 3\n  const mats: MatKey[] = ['safetyGreen', 'actuatorRed', 'actuatorYellow', 'lampLens', 'safetyGreen', 'actuatorRed']\n  for (let i = 0; i < nb; i++) k.cyl(mats[i % mats.length], 0.016, 0.02, at(-w * 0.3 + (i * w * 0.6) / Math.max(1, nb - 1), yc - h * 0.18, fz + 0.01), arr(nn), 14)\n  k.cyl('actuatorYellow', 0.04, 0.004, at(w * 0.3, yc - h * 0.36, fz), arr(nn), 20)\n  k.dome('actuatorRed', 0.025, at(w * 0.3, yc - h * 0.36, fz + 0.01), arr(nn), Math.PI / 2, 0.7, 16)\n  if (opts.title) k.plane(textMaterial(opts.title, '#f2f2ee', '#111', 512, 96), w * 0.7, w * 0.13, at(0, yc + h * 0.42, fz + 0.001), q)\n  for (let i = 0; i < 4; i++) k.cyl('brass', 0.012, 0.035, at(-w * 0.3 + i * w * 0.2, top - h - 0.015, dep / 2), 'y', 8)\n  return at(0, top - h - 0.04, dep / 2)\n}\n\n/** Pipe stanchion from the deck to under a pipe centred at `at`, with saddle plate and U-bolt. Pipe runs along `along`. */\nexport function pipeSupport(k: Kit, at: V3, od: number, deckY: number, along: 'x' | 'z', mat: MatKey = 'galvanised') {\n  const top = at[1] - od / 2 - 0.006\n  if (top - deckY < 0.05) return\n  const big = od > 0.12\n  const sec = big ? 'HEB 100' : 'L50x50x5'\n  member(k, [at[0], deckY, at[2]], [at[0], top - 0.01, at[2]], sec, mat, along === 'x' ? [1, 0, 0] : [0, 0, 1])\n  const w = Math.max(0.1, od + 0.06)\n  k.box(mat, along === 'x' ? [0.1, 0.012, w] : [w, 0.012, 0.1], [at[0], top - 0.004, at[2]])\n  k.box(mat, [0.16, 0.012, 0.16], [at[0], deckY + 0.006, at[2]])\n  k.torus('boltXylan', od / 2 + 0.006, Math.max(0.004, od * 0.03), [at[0], at[1], at[2]], along === 'x' ? 'x' : 'z', 6, 20, Math.PI)\n  for (const s of [-1, 1]) {\n    const p: V3 = along === 'x' ? [at[0], top + 0.004, at[2] + s * (od / 2 + 0.006)] : [at[0] + s * (od / 2 + 0.006), top + 0.004, at[2]]\n    k.hex('nut', Math.max(0.014, od * 0.12), 0.01, p)\n  }\n}\n\nexport interface VesselDims {\n  Ro: number\n  hd: number\n  /** bottom of the lower head */\n  yBot: number\n  /** top of the upper head */\n  yTop: number\n}\n\n/** Vertical 2:1 ellipsoidal-head vessel, bottom tangent line at `yTL`, with girth seams. */\nexport function vVessel(k: Kit, x: number, z: number, yTL: number, id: number, tt: number, wall: number, mat: MatKey = 'equipmentPaint', seg = 48): VesselDims {\n  const Ro = id / 2 + wall\n  const hd = headDepth('2:1-ellipsoidal', id) + wall\n  const prof: [number, number][] = [[0, -hd]]\n  for (let i = 1; i <= 12; i++) {\n    const t = (i / 12) * (Math.PI / 2)\n    prof.push([Ro * Math.sin(t), -hd * Math.cos(t)])\n  }\n  for (let i = 0; i <= 12; i++) {\n    const t = (i / 12) * (Math.PI / 2)\n    prof.push([Ro * Math.cos(t), tt + hd * Math.sin(t)])\n  }\n  k.lathe(mat, prof, [x, yTL, z], 'y', seg)\n  for (const y of [0, tt]) k.torus(mat, Ro + 0.0008, Math.max(0.003, Ro * 0.008), [x, yTL + y, z], 'y', 6, seg)\n  return { Ro, hd, yBot: yTL - hd, yTop: yTL + tt + hd }\n}\n\n/** Angle or pipe legs welded to a vertical shell, with base plates and anchor nuts. */\nexport function vesselLegs(k: Kit, x: number, z: number, Ro: number, yAttach: number, deckY: number, n = 4, mat: MatKey = 'equipmentPaint', phase = Math.PI / 4) {\n  const lr = Math.max(0.03, Ro * 0.12)\n  for (let i = 0; i < n; i++) {\n    const a = phase + (i / n) * Math.PI * 2\n    const px = x + Math.cos(a) * (Ro + lr * 0.6)\n    const pz = z + Math.sin(a) * (Ro + lr * 0.6)\n    k.cyl(mat, lr, yAttach - deckY, [px, (yAttach + deckY) / 2, pz], 'y', 12)\n    k.box(mat, [0.01, Math.min(0.3, (yAttach - deckY) * 0.3), lr * 2.4], [x + Math.cos(a) * (Ro + 0.005), yAttach - 0.1, z + Math.sin(a) * (Ro + 0.005)], new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), -a))\n    const bp = lr * 3.2\n    k.box(mat, [bp, 0.014, bp], [px, deckY + 0.007, pz])\n    for (const s of [-1, 1]) k.hex('nut', 0.026, 0.016, [px + s * bp * 0.32, deckY + 0.022, pz + s * bp * 0.32])\n  }\n}\n\n/** Bunded drip tray: floor plate, upstand rim and a drain coupling on the -X end. */\nexport function dripPan(k: Kit, cx: number, cz: number, sx: number, sz: number, y: number, rim = 0.06, mat: MatKey = 'stainless') {\n  k.box(mat, [sx, 0.005, sz], [cx, y + 0.0025, cz])\n  for (const s of [-1, 1]) {\n    k.box(mat, [sx, rim, 0.004], [cx, y + rim / 2, cz + s * (sz / 2 - 0.002)])\n    k.box(mat, [0.004, rim, sz], [cx + s * (sx / 2 - 0.002), y + rim / 2, cz])\n  }\n  k.cyl(mat, 0.016, 0.06, [cx - sx / 2 - 0.02, y + 0.02, cz], 'x', 10)\n  k.hex('nut', 0.03, 0.02, [cx - sx / 2 - 0.05, y + 0.02, cz], 'x')\n}\n\n/** Brass earth boss on a steel face. */\nexport function earthBoss(k: Kit, pos: V3, n: V3) {\n  k.cyl('brass', 0.014, 0.025, pos, n, 10)\n  k.hex('brass', 0.024, 0.008, addv(pos, n, 0.012), n)\n}\n\n/** Flanged spool joint inside the skid piping (both flanges, gasket, studs), centred at `pos` along `dir`. */\nexport function spoolJoint(k: Kit, pos: V3, dir: V3, nps: number, rating: Rating) {\n  flangedJoint(k, nps, rating, pos, dir)\n  const f = flangeDims(nps, rating)\n  const L = f.hubLength + f.raisedFaceHeight\n  liner(k, nps, addv(pos, dir, -0.00225), dir, L)\n  liner(k, nps, addv(pos, dir, 0.00225), [-dir[0], -dir[1], -dir[2]], L)\n}\n\n/** Curved painted label band on a vertical shell (axis +Y at x, z), centred on the +Z side, `h` tall over `arc` radians. */\nexport function shellLabel(k: Kit, text: string, x: number, y: number, z: number, Ro: number, h: number, arc = 1.1, bg = '#1f5fa0', fg = '#ffffff') {\n  k.add(textMaterial(text, bg, fg, 512, Math.round((512 * h) / (Ro * arc))), new THREE.CylinderGeometry(Ro + 0.003, Ro + 0.003, h, 24, 1, true, -arc / 2, arc), new THREE.Matrix4().makeTranslation(x, y, z))\n}\n\n/** Open mouth where a branch meets a run or shell: dark bore disc on the surface at `at` facing `dir`, plus the fillet weld. */\nexport function branchMouth(k: Kit, at: V3, dir: V3, nps: number, wall = 0.006) {\n  const r = pipeOD(nps) / 2\n  k.disc('pipeBore', r - wall, addv(at, dir, 0.0012), dir, 24)\n  k.torus('flangeSteel', r + 0.001, Math.max(0.003, r * 0.06), addv(at, dir, 0.002), dir, 6, 24)\n}\n\n/** Bow shackles with screw pins through the four lib `skid()` padeyes (skid of length L, width W, deck top `deckY`). */\nexport function padeyeShackles(k: Kit, L: number, W: number, deckY: number) {\n  for (const sx of [-1, 1])\n    for (const sz of [-1, 1]) {\n      const x = sx * (L / 2 - 0.25)\n      const z = sz * (W / 2 - 0.03)\n      const hy = deckY + 0.078\n      k.rod('galvanised', [x, hy, z - 0.05], [x, hy, z + 0.05], 0.011, 10)\n      k.hex('nut', 0.03, 0.016, [x, hy, z - 0.055], 'z')\n      k.cyl('galvanised', 0.02, 0.012, [x, hy, z + 0.055], 'z', 12)\n      k.tube('actuatorRed', [[x, hy, z - 0.042], [x, hy + 0.11, z - 0.042], [x, hy + 0.11, z + 0.042], [x, hy, z + 0.042]], 0.011, 8, 0.04)\n    }\n}\n\n/** Basket strainer on a line along +X centred at `pos` (flanged ends are spool joints at ±len/2), with pot, cover, drain and DP gauge. */\nexport function basketStrainer(k: Kit, pos: V3, nps: number, rating: Rating, len: number, mat: MatKey = 'valveBody') {\n  const D = pipeOD(nps)\n  const f = flangeDims(nps, rating)\n  const fl = f.hubLength + f.raisedFaceHeight\n  const [x, y, z] = pos\n  for (const s of [-1, 1]) spoolJoint(k, [x + (s * len) / 2, y, z], [s, 0, 0], nps, rating)\n  const inner = len / 2 - fl\n  k.pipe(mat, [x - inner - 0.002, y, z], [x + inner + 0.002, y, z], D * 1.1, D * 0.05 + 0.004, 28)\n  const R = D * 0.85\n  k.cyl(mat, R, D * 1.9, [x, y + D * 0.15, z], 'y', 32)\n  k.dome(mat, R, [x, y - D * 0.8, z], '-y', Math.PI / 2, 0.6, 32)\n  const yc = y + D * 1.1\n  k.cyl(mat, R + 0.05, 0.05, [x, yc, z], 'y', 32)\n  k.cyl(mat, R + 0.05, 0.04, [x, yc + 0.045, z], 'y', 32)\n  k.around(12, R + 0.025, [x, yc + 0.07, z], 'y', (p) => k.hex('nut', 0.03, 0.02, p))\n  k.box('handwheel', [R * 1.2, 0.025, 0.03], [x, yc + 0.08, z])\n  k.cyl('stainless', 0.012, 0.08, [x, y - D * 0.8 - R * 0.6 - 0.03, z], 'y', 10)\n  k.hex('nut', 0.03, 0.02, [x, y - D * 0.8 - R * 0.6 - 0.08, z])\n  k.tube('tubing', [[x - R * 0.7, y + D * 0.3, z + R * 0.75], [x - R * 0.7, yc + 0.15, z + R + 0.08], [x + R * 0.7, yc + 0.15, z + R + 0.08], [x + R * 0.7, y + D * 0.3, z + R * 0.75]], 0.005, 6, 0.03)\n  gauge(k, [x, yc + 0.2, z + R + 0.1], 'z', 0.1, 'bar', 2)\n}\n\n/** Spring-loaded back-pressure / thermal relief valve body on a line point, bonnet towards `up`. */\nexport function reliefBody(k: Kit, pos: V3, up: V3, s = 0.02) {\n  k.sphere('valveBody', s * 1.2, pos, undefined, 14)\n  k.cyl('actuatorRed', s * 0.7, s * 3, addv(pos, up, s * 2.4), up, 12, s * 0.5)\n  k.cyl('actuatorRed', s * 0.5, s * 0.8, addv(pos, up, s * 4.2), up, 10)\n}\n\n/**\n * Mating pipe flange bolted to a nozzle face that points along `dir` (nozzle drawn with studs: false): gasket, flange\n * facing back, bore liner and through-studs with two nuts. Returns the weld end of the mating flange.\n */\nexport function mateFlange(k: Kit, face: V3, dir: V3, nps: number, rating: Rating): V3 {\n  const f = flangeDims(nps, rating)\n  const g = 0.0045\n  gasket(k, nps, rating, addv(face, dir, g / 2), dir, g)\n  const mf = addv(face, dir, g)\n  const back: V3 = [-dir[0], -dir[1], -dir[2]]\n  blFlange(k, mf, back, nps, rating, false)\n  const span = 2 * (f.thickness + f.raisedFaceHeight) + g\n  const studL = span + f.boltDia * 3\n  k.boltCircle('boltXylan', 'nut', f.bolts, f.boltCircle / 2, addv(addv(face, dir, g / 2), dir, -studL / 2), dir, f.boltDia, studL, [f.boltDia * 0.95, studL - f.boltDia * 0.95])\n  return addv(mf, dir, f.hubLength + f.raisedFaceHeight)\n}\n\n/** Weld-to-weld length of an in-kit wafer butterfly valve between two weld-neck flanges. */\nexport function butterflySpan(nps: number, rating: Rating) {\n  const f = flangeDims(nps, rating)\n  return faceToFace('butterfly-wafer', nps, rating) + 2 * (0.003 + f.hubLength + f.raisedFaceHeight)\n}\n\n/** Wafer butterfly valve clamped between two pipe flanges, centred at `pos` on a line along `dir`; lever, gear or pneumatic rack-and-pinion actuator towards `up`. */\nexport function butterflyValve(k: Kit, pos: V3, dir: V3, nps: number, rating: Rating, up: V3 = [0, 1, 0], op: 'lever' | 'gear' | 'pneumatic' = 'pneumatic') {\n  const f = flangeDims(nps, rating)\n  const w = faceToFace('butterfly-wafer', nps, rating)\n  const D = pipeOD(nps)\n  const fl = f.hubLength + f.raisedFaceHeight\n  k.with(frame(pos, dir, up), () => {\n    for (const s of [-1, 1]) {\n      const face: V3 = [s * (w / 2 + 0.003), 0, 0]\n      flange(k, nps, rating, face, [-s, 0, 0], false)\n      liner(k, nps, face, [-s, 0, 0], fl)\n      gasket(k, nps, rating, [s * (w / 2 + 0.0015), 0, 0], 'x', 0.003)\n    }\n    const ri = D / 2 - 0.004\n    k.lathe('valveBody', [[ri, -w / 2], [f.raisedFace / 2 + 0.01, -w / 2], [f.raisedFace / 2 + 0.01, w / 2], [ri, w / 2]], [0, 0, 0], 'x', 32)\n    k.lathe('pipeBore', [[ri, w / 2], [ri, -w / 2]], [0, 0, 0], 'x', 24)\n    k.box('stainless', [0.006, 2 * ri, 2 * ri * 0.15], [0, 0, 0]) // disc edge-on (open)\n    const studL = w + 2 * (f.thickness + f.raisedFaceHeight) + f.boltDia * 3.2\n    k.boltCircle('boltXylan', 'nut', f.bolts, f.boltCircle / 2, [-studL / 2, 0, 0], 'x', f.boltDia, studL, [f.boltDia * 0.95, studL - f.boltDia * 0.95])\n    const yN = f.raisedFace / 2 + 0.01\n    k.cyl('valveBody', Math.max(0.018, D * 0.14), 0.09 + D * 0.2, [0, yN + (0.09 + D * 0.2) / 2, 0], 'y', 16)\n    const yT = yN + 0.09 + D * 0.2\n    k.box('valveBody', [0.1 + D * 0.3, 0.012, 0.1 + D * 0.3], [0, yT, 0])\n    if (op === 'pneumatic') {\n      const s = THREE.MathUtils.clamp(D * 2.2, 0.18, 0.6)\n      k.rbox('actuatorYellow', [s * 0.45, s * 0.4, s * 1.2], s * 0.06, [0, yT + s * 0.2 + 0.006, 0])\n      for (const sz of [-1, 1]) k.cyl('actuatorYellow', s * 0.22, s * 0.03, [0, yT + s * 0.2 + 0.006, sz * s * 0.6], 'z', 18)\n      k.rbox('aluminium', [s * 0.3, s * 0.2, s * 0.3], s * 0.03, [0, yT + s * 0.5, 0]) // limit switch box\n      k.cyl('actuatorRed', s * 0.08, s * 0.05, [0, yT + s * 0.62, 0], 'y', 12)\n    } else if (op === 'gear') {\n      const gb = Math.max(0.1, D * 0.6)\n      k.rbox('valveBody', [gb, gb * 0.6, gb * 0.8], gb * 0.08, [0, yT + gb * 0.3, 0])\n      k.handwheel('handwheel', Math.max(0.25, gb * 1.8), [0, yT + gb * 0.3, gb * 0.7], 'z', 5)\n    } else k.box('actuatorRed', [0.04, 0.02, Math.max(0.2, D * 1.6)], [0, yT + 0.02, Math.max(0.1, D * 0.8) - 0.03])\n  })\n  return w + 2 * (0.003 + fl)\n}\n"
    }
  ],
  "categories": [
    "packages"
  ],
  "meta": {
    "export": "HypochloriteGenerator",
    "anchor": "base",
    "standards": [
      "NORSOK M-001 (materials)",
      "ASME B16.5",
      "IEC 60146 (rectifiers)"
    ]
  }
}