{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "surge-arrester",
  "type": "registry:component",
  "title": "Surge arrester (station class)",
  "description": "Station-class metal-oxide surge arrester on a tubular support: one to four stacked housed units (by system voltage) with pressure-relief vents, top terminal and a hanging grading ring from 145 kV. It stands on an insulating base of four small post insulators, with an insulated lead to a surge counter / leakage monitor on the column and an earth lead to an inspection pit.",
  "dependencies": [
    "three",
    "@react-three/fiber",
    "@react-three/drei"
  ],
  "registryDependencies": [
    "https://deck-twin-library.demoareeb.workers.dev/r/core.json"
  ],
  "files": [
    {
      "path": "onshore/surge-arrester.tsx",
      "type": "registry:file",
      "target": "components/deck-twin/onshore/surge-arrester.tsx",
      "content": "// Station-class metal-oxide surge arrester on a support: stacked housed units, grading ring, insulating base, surge counter and earth lead. IEC 60099-4.\nimport type { Kit, MatKey } from '../lib/kit'\nimport { KitMesh, useKit, type GroupProps } from '../lib/mesh'\nimport { tagPlate } from '../lib/parts'\nimport { paint } from '../lib/materials'\nimport { dialMaterial } from '../lib/textures'\nimport { alu, gradingRing, hv, pad, tubeColumn } from './_hv'\nimport { earthLead, insulator, porcelain, silicone } from './_onshore'\n\nexport interface SurgeArresterProps {\n  /** system voltage, kV */\n  kv?: number\n  insulation?: 'porcelain' | 'composite'\n  tag?: string\n}\n\nexport const defaults = { kv: 145, insulation: 'composite' as 'porcelain' | 'composite', tag: '' }\n\nexport function SurgeArrester(props: SurgeArresterProps & GroupProps) {\n  const { kv, insulation, tag, ...group } = { ...defaults, ...props }\n  const data = useKit((k) => build(k, kv, insulation, tag), [kv, insulation, tag])\n  return (\n    <group {...group}>\n      <KitMesh data={data} />\n    </group>\n  )\n}\n\nexport default SurgeArrester\n\nfunction build(k: Kit, kv: number, insulation: string, tag: string) {\n  const d = hv(kv)\n  const ins: MatKey = insulation === 'composite' ? silicone() : porcelain()\n  const y0 = tubeColumn(k, 0, 0, d.sup, 0.273, false)\n  // insulating base: plate on four small post insulators, so the counter measures the leakage current\n  k.box('galvanised', [0.45, 0.02, 0.45], [0, y0 + 0.01, 0])\n  for (const a of [-1, 1]) for (const b of [-1, 1]) insulator(k, [a * 0.14, y0 + 0.02, b * 0.14], 0.12, 0.025, ins)\n  const yb = y0 + 0.14\n  k.cyl(alu(), 0.2, 0.04, [0, yb + 0.02, 0], 'y', 28)\n  // stacked units, typical one per ~70 kV system voltage\n  const n = d.kv >= 362 ? 4 : d.kv >= 200 ? 3 : d.kv >= 100 ? 2 : 1\n  const hu = 0.95 + (d.ins * 0.35) / n\n  let y = yb + 0.04\n  for (let i = 0; i < n; i++) {\n    insulator(k, [0, y, 0], hu, d.r * 1.1, ins)\n    // pressure-relief vent ports at the unit ends\n    for (const t of [0.05, hu - 0.05]) k.box(alu(), [0.06, 0.04, 0.05], [d.r * 1.35, y + t, 0])\n    y += hu\n    k.cyl(alu(), d.r * 1.5, 0.04, [0, y + 0.02, 0], 'y', 24)\n    y += 0.04\n  }\n  pad(k, [0, y, 0], [0, 1, 0], 1.2)\n  if (d.kv >= 100) {\n    // grading ring hung from the top flange\n    const R = 0.25 + 0.0015 * d.kv\n    for (let i = 0; i < 3; i++) {\n      const a = (i / 3) * Math.PI * 2\n      k.rod(alu(), [0, y - 0.02, 0], [Math.cos(a) * R, y - 0.35, Math.sin(a) * R], 0.012, 6)\n    }\n    gradingRing(k, [0, y - 0.35, 0], R, 'y', 0.035)\n  }\n  // insulated earth lead to the surge counter on the column, counter earthed to grade\n  const cz = 0.2\n  k.spline(paint('#1e1f21'), [[0.12, yb + 0.02, 0.1], [0.18, yb - 0.1, 0.18], [0.12, y0 - 0.45, cz]], 0.012, 6, 20)\n  k.cyl('galvanised', 0.11, 0.08, [0, y0 - 0.6, cz + 0.04], 'z', 28)\n  k.disc(dialMaterial('bar', 10), 0.09, [0, y0 - 0.6, cz + 0.081], 'z', 28)\n  k.disc('glass', 0.095, [0, y0 - 0.6, cz + 0.085], 'z', 28)\n  k.box('galvanised', [0.08, 0.2, 0.06], [0, y0 - 0.6, cz - 0.03])\n  k.spline(earthLead(), [[0, y0 - 0.7, cz], [0.05, y0 - 1.0, cz + 0.05], [0.1, 0.4, cz + 0.1], [0.25, 0.03, cz + 0.35]], 0.008, 6, 24)\n  k.cyl('concrete', 0.14, 0.05, [0.25, 0.025, cz + 0.35], 'y', 16)\n  if (tag) tagPlate(k, tag, [0, y0 - 0.85, 0.14], 'z', 0.14)\n}\n"
    },
    {
      "path": "onshore/_hv.ts",
      "type": "registry:file",
      "target": "components/deck-twin/onshore/_hv.ts",
      "content": "// Outdoor HV switchyard parts: insulation levels per rated voltage, piers, tubular supports, terminal pads, grading rings, disc insulator strings.\nimport * as THREE from 'three'\nimport type { Axis, Kit, MatKey, V3 } from '../lib/kit'\nimport { axisVec } from '../lib/kit'\nimport { paint } from '../lib/materials'\nimport { anchorBolt, earthBond, plinth } from './_onshore'\n\nexport const KV = [72.5, 145, 245, 420] as const\nexport type Kv = (typeof KV)[number]\n\n/**\n * IEC 62271-1 / IEC 60071 insulation levels and typical outdoor dimensions per rated voltage:\n * BIL (kV), post insulator height (IEC 60273 class), phase spacing, live-part support height (IEC 61936-1 ≥ 2.25 m), insulator core radius.\n */\nexport function hv(kv: number) {\n  const table: Record<number, { bil: number; ins: number; phase: number; r: number; ring: boolean }> = {\n    72.5: { bil: 325, ins: 0.77, phase: 1.6, r: 0.07, ring: false },\n    145: { bil: 650, ins: 1.5, phase: 2.5, r: 0.085, ring: false },\n    245: { bil: 1050, ins: 2.3, phase: 3.5, r: 0.1, ring: true },\n    420: { bil: 1425, ins: 3.65, phase: 5.5, r: 0.12, ring: true },\n  }\n  const key = KV.reduce((a, b) => (Math.abs(b - kv) < Math.abs(a - kv) ? b : a))\n  return { kv: key, sup: 2.5, ...table[key] }\n}\n\nexport const alu = () => paint('#c9ccce', { metalness: 0.85, roughness: 0.35, clearcoat: 0 })\nexport const cabinet = () => paint('#b9bdb8', { metalness: 0.4, roughness: 0.45, clearcoat: 0.2 })\n\n/** Galvanised tubular support column on a concrete pier: base plate, anchors, gussets, top plate. Returns the top y. */\nexport function tubeColumn(k: Kit, x: number, z: number, h: number, od = 0.273, earth = true) {\n  const pier = 0.3\n  plinth(k, x, z, od + 0.5, od + 0.5, pier)\n  k.box('galvanised', [od + 0.2, 0.025, od + 0.2], [x, pier + 0.0125, z])\n  for (const a of [-1, 1]) for (const b of [-1, 1]) anchorBolt(k, [x + a * (od / 2 + 0.06), pier + 0.025, z + b * (od / 2 + 0.06)], 0.024)\n  for (let i = 0; i < 4; i++) {\n    const q = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), (i * Math.PI) / 2)\n    const off = new THREE.Vector3(od / 2 + 0.04, 0, 0).applyQuaternion(q)\n    k.box('galvanised', [0.08, 0.18, 0.012], [x + off.x, pier + 0.115, z + off.z], q)\n  }\n  k.cyl('galvanised', od / 2, h - pier - 0.05, [x, (h + pier) / 2, z], 'y', 24)\n  k.box('galvanised', [od + 0.1, 0.025, od + 0.1], [x, h - 0.0125, z])\n  if (earth) earthBond(k, [x, pier + 0.45, z + od / 2], [0, 0, 1], 0, 0.45)\n  return h\n}\n\n/** Flat aluminium terminal pad (NEMA 4-hole) pointing along dir from pos. */\nexport function pad(k: Kit, pos: V3, dir: V3, s = 1) {\n  const d = new THREE.Vector3(...dir).normalize()\n  const q = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(1, 0, 0), d)\n  const c = new THREE.Vector3(...pos).addScaledVector(d, 0.07 * s)\n  k.box(alu(), [0.14 * s, 0.1 * s, 0.016 * s], c.toArray() as V3, q)\n  k.rod(alu(), pos, c.clone().addScaledVector(d, -0.04 * s).toArray() as V3, 0.025 * s, 10)\n  for (const a of [-1, 1]) for (const b of [-1, 1]) {\n    const h = c.clone().add(new THREE.Vector3(a * 0.03 * s, b * 0.025 * s, 0).applyQuaternion(q))\n    k.cyl('nut', 0.009 * s, 0.03 * s, h.toArray() as V3, new THREE.Vector3(0, 0, 1).applyQuaternion(q).toArray() as V3, 6)\n  }\n}\n\n/** Corona / grading ring (aluminium tube torus) around axis at pos. */\nexport function gradingRing(k: Kit, pos: V3, R: number, axis: Axis = 'y', r = 0.025) {\n  k.torus(alu(), R, r, pos, axis, 10, 40)\n  const v = axisVec(axis)\n  const [u] = [new THREE.Vector3(1, 0, 0).cross(v).lengthSq() > 0.01 ? new THREE.Vector3(1, 0, 0) : new THREE.Vector3(0, 0, 1)]\n  for (const s of [-1, 1]) {\n    const p = new THREE.Vector3(...pos).addScaledVector(u, s * R)\n    k.rod(alu(), new THREE.Vector3(...pos).addScaledVector(u, s * R * 0.25).toArray() as V3, p.toArray() as V3, 0.012, 6)\n  }\n}\n\n/** Cap-and-pin glass disc string from a (yoke at the structure) to b (dead-end clamp), discs at 146 mm pitch. */\nexport function discString(k: Kit, a: V3, b: V3, discD = 0.255, mat: MatKey = paint('#5d7f7a', { metalness: 0.1, roughness: 0.08, clearcoat: 0.8, transparent: true, opacity: 0.85 })) {\n  const A = new THREE.Vector3(...a)\n  const B = new THREE.Vector3(...b)\n  const d = B.clone().sub(A)\n  const L = d.length()\n  d.normalize()\n  const pitch = 0.146\n  const fit = 0.35\n  const n = Math.max(2, Math.floor((L - 2 * fit) / pitch))\n  const at = (t: number) => A.clone().addScaledVector(d, t).toArray() as V3\n  k.rod('galvanised', at(0), at(fit), 0.012, 8)\n  k.rod('galvanised', at(L - fit), at(L), 0.014, 8)\n  k.box('galvanised', [0.06, 0.12, 0.012], at(fit * 0.5), new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 1, 0), d))\n  const s0 = fit + (L - 2 * fit - (n - 1) * pitch) / 2\n  for (let i = 0; i < n; i++) {\n    const t = s0 + i * pitch\n    k.lathe(mat, [[0.02, 0], [discD / 2, 0.03], [discD / 2 * 0.98, 0.045], [discD * 0.18, 0.06], [0.03, 0.09]], at(t - 0.045), d.toArray() as V3, 20)\n    k.cyl('galvanised', 0.03, 0.05, at(t - 0.06), d.toArray() as V3, 10)\n  }\n  k.rod('galvanised', at(fit - 0.02), at(L - fit + 0.02), 0.008, 6)\n  return at(L)\n}\n\n/** Catenary conductor between a and b with sag at mid-span (twin optional). */\nexport function conductor(k: Kit, a: V3, b: V3, sag: number, r = 0.016, twin = 0) {\n  const A = new THREE.Vector3(...a)\n  const B = new THREE.Vector3(...b)\n  const across = new THREE.Vector3().subVectors(B, A).cross(new THREE.Vector3(0, 1, 0)).normalize()\n  for (const off of twin ? [-twin / 2, twin / 2] : [0]) {\n    const pts: THREE.Vector3[] = []\n    for (let i = 0; i <= 24; i++) {\n      const t = i / 24\n      pts.push(A.clone().lerp(B, t).addScaledVector(across, off).add(new THREE.Vector3(0, -4 * sag * t * (1 - t), 0)))\n    }\n    k.add(alu(), new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), 48, r, 6, false))\n  }\n}\n"
    },
    {
      "path": "onshore/_onshore.ts",
      "type": "registry:file",
      "target": "components/deck-twin/onshore/_onshore.ts",
      "content": "// Shared onshore parts: plinths, anchor bolts, earth bonds, ISO 14122 stairs, shedded insulators, lattice steel and swivel joints.\nimport * as THREE from 'three'\nimport { axisVec, type Axis, type Kit, type MatKey, type V3 } from '../lib/kit'\nimport { paint } from '../lib/materials'\nimport { grating, handrail, member } from '../lib/parts'\nimport { stairFlight } from '../lib/standards'\n\nexport const add = (a: V3, b: V3, s = 1): V3 => [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s]\nexport const deg = (d: number) => (d * Math.PI) / 180\nexport const clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v))\n\nexport const porcelain = () => paint('#6e3420', { metalness: 0.05, roughness: 0.12, clearcoat: 0.9, clearcoatRoughness: 0.1, weather: 0 })\nexport const silicone = () => paint('#8b9399', { metalness: 0, roughness: 0.55, clearcoat: 0.2, clearcoatRoughness: 0.5, weather: 0.3 })\nexport const earthLead = () => paint('#5c9e33', { metalness: 0, roughness: 0.6, clearcoat: 0, weather: 0 })\nexport const lightGrey = () => paint('#cfd2cf', { metalness: 0.2, roughness: 0.5, clearcoat: 0.25, weather: 1 })\n\n/** Concrete plinth from y0 up to y0 + h with a small arris, centred on (cx, cz). */\nexport function plinth(k: Kit, cx: number, cz: number, sx: number, sz: number, h: number, y0 = 0) {\n  const c = Math.min(0.025, h * 0.2)\n  k.box('concrete', [sx, h - c, sz], [cx, y0 + (h - c) / 2, cz])\n  k.box('concrete', [sx - 2 * c, c, sz - 2 * c], [cx, y0 + h - c / 2, cz])\n}\n\n/** Cast-in anchor bolt standing on a surface at p: washer, double nut, projecting thread. */\nexport function anchorBolt(k: Kit, p: V3, dia = 0.024) {\n  k.cyl('galvanised', dia * 1.1, 0.005, [p[0], p[1] + 0.0025, p[2]], 'y', 12)\n  k.hex('nut', dia * 1.85, dia * 0.9, [p[0], p[1] + 0.005 + dia * 0.45, p[2]])\n  k.hex('nut', dia * 1.85, dia * 0.9, [p[0], p[1] + 0.005 + dia * 1.4, p[2]])\n  k.cyl('boltXylan', dia / 2, dia * 2.6, [p[0], p[1] + dia * 1.3, p[2]], 'y', 8)\n}\n\n/** Steel base plate with its top at y, on a grout bed, anchored near each corner. */\nexport function basePlate(k: Kit, cx: number, y: number, cz: number, sx: number, sz: number, t = 0.025, dia = 0.024, mat: MatKey = 'galvanised') {\n  k.box(mat, [sx, t, sz], [cx, y - t / 2, cz])\n  const ix = sx / 2 - dia * 2.2\n  const iz = sz / 2 - dia * 2.2\n  for (const a of [-1, 1]) for (const b of [-1, 1]) anchorBolt(k, [cx + a * ix, y, cz + b * iz], dia)\n}\n\n/** Earth boss with a bolted lug and a green/yellow bonding lead down to an inspection pit at grade. */\nexport function earthBond(k: Kit, pos: V3, out: V3, ground = 0, pitOffset = 0.3) {\n  const o = new THREE.Vector3(...out).normalize().toArray() as V3\n  k.cyl('brass', 0.017, 0.03, add(pos, o, 0.015), o, 10)\n  k.box('copper', [0.03, 0.05, 0.004], add(add(pos, o, 0.032), [0, -0.012, 0]), o)\n  k.hex('nut', 0.022, 0.012, add(pos, o, 0.04), o)\n  const lug = add(add(pos, o, 0.035), [0, -0.035, 0])\n  const pit: V3 = [pos[0] + o[0] * pitOffset, ground, pos[2] + o[2] * pitOffset]\n  if (pos[1] - ground > 0.12) {\n    k.spline(earthLead(), [lug, add(lug, [0, -0.08, 0]), add([pit[0], ground + 0.25, pit[2]], o, -pitOffset * 0.3), [pit[0], ground + 0.1, pit[2]], [pit[0], ground + 0.03, pit[2]]], 0.0065, 6, 24)\n    k.cyl('concrete', 0.14, 0.05, [pit[0], ground + 0.025, pit[2]], 'y', 16)\n    k.cyl('castIron', 0.1, 0.008, [pit[0], ground + 0.054, pit[2]], 'y', 16)\n  }\n}\n\n/** ISO 14122-3 straight stair: first riser at `foot`, climbing along `dir` by `rise`. Channel stringers, grating treads, handrails. Returns the horizontal run. */\nexport function stair(k: Kit, foot: V3, dir: Axis, rise: number, width = 0.9, rails: 'both' | 'left' | 'right' | 'none' = 'both') {\n  const f = stairFlight(rise)\n  const n = f.steps\n  const g = f.going\n  const q = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(1, 0, 0), axisVec(dir).setY(0).normalize())\n  const w = width / 2\n  const slope = f.riser / g\n  k.with(new THREE.Matrix4().compose(new THREE.Vector3(...foot), q, new THREE.Vector3(1, 1, 1)), () => {\n    const sd = 0.18\n    const yAt = (x: number) => f.riser + x * slope - 0.07\n    const x0 = (sd * 0.45 + 0.07 - f.riser) / slope\n    const run = (n - 1) * g\n    for (const s of [-1, 1]) {\n      const z = s * (w + 0.04)\n      member(k, [x0, yAt(x0), z], [run, yAt(run), z], 'UPN 180', 'galvanised', [-slope, 1, 0])\n      k.box('galvanised', [0.22, 0.015, 0.16], [x0 + 0.06, 0.0075, z])\n    }\n    for (let i = 1; i < n; i++) {\n      const y = i * f.riser\n      grating(k, [(i - 1) * g + g / 2 + 0.0125, y, 0], g + 0.025, width)\n      k.box('safetyYellow', [0.03, 0.032, width], [(i - 1) * g + 0.015, y - 0.016, 0])\n    }\n    const pts = (z: number): V3[] => [[0, f.riser * 0.5, z], [run, rise, z]]\n    if (rails === 'both' || rails === 'left') handrail(k, pts(w + 0.04), 'safetyYellow')\n    if (rails === 'both' || rails === 'right') handrail(k, pts(-w - 0.04), 'safetyYellow')\n  })\n  return (n - 1) * g\n}\n\n/** Shedded post insulator from `base` along `axis` for L: galvanised end caps, alternating sheds of radius ~2.2 r. */\nexport function insulator(k: Kit, base: V3, L: number, r: number, mat: MatKey, axis: Axis = 'y') {\n  const v = axisVec(axis).toArray() as V3\n  const cap = Math.min(0.08, L * 0.08)\n  const prof: [number, number][] = [[0, cap], [r, cap]]\n  const body = L - 2 * cap\n  const n = Math.max(3, Math.round(body / Math.max(0.045, r * 0.75)))\n  const pitch = body / n\n  let y = cap\n  for (let i = 0; i < n; i++) {\n    const big = i % 2 === 0 ? 2.3 : 1.85\n    prof.push([r * 1.05, y + pitch * 0.15], [r * big, y + pitch * 0.42], [r * (big - 0.1), y + pitch * 0.55], [r, y + pitch * 0.62])\n    y += pitch\n    prof.push([r, y])\n  }\n  prof.push([0, L - cap])\n  k.lathe(mat, prof, base, v, 20)\n  for (const t of [cap / 2, L - cap / 2]) k.cyl('galvanised', r * 1.25, cap, add(base, v, t), v, 18)\n  for (const t of [0.006, L - 0.006]) k.cyl('galvanised', r * 1.9, 0.012, add(base, v, t), v, 18)\n}\n\n/** Square lattice column of four angle legs with zig-zag bracing on every face, (cx, cz) centre, from y0 to y1. */\nexport function latticeColumn(k: Kit, cx: number, cz: number, y0: number, y1: number, w: number, leg = 'L100x100x10', brace = 'L50x50x5', mat: MatKey = 'galvanised') {\n  const h = w / 2\n  const c: [number, number][] = [[-h, -h], [h, -h], [h, h], [-h, h]]\n  for (const [x, z] of c) member(k, [cx + x, y0, cz + z], [cx + x, y1, cz + z], leg, mat, [-x, 0, -z])\n  const H = y1 - y0\n  const nb = Math.max(1, Math.round(H / w))\n  const dy = H / nb\n  for (let f = 0; f < 4; f++) {\n    const [ax, az] = c[f]\n    const [bx, bz] = c[(f + 1) % 4]\n    for (let i = 0; i < nb; i++) {\n      const ya = y0 + i * dy\n      const flip = (i + f) % 2 === 0\n      const p0: V3 = [cx + (flip ? ax : bx), ya, cz + (flip ? az : bz)]\n      const p1: V3 = [cx + (flip ? bx : ax), ya + dy, cz + (flip ? bz : az)]\n      member(k, p0, p1, brace, mat, [ax + bx, 0, az + bz])\n    }\n    member(k, [cx + ax, y1 - 0.03, cz + az], [cx + bx, y1 - 0.03, cz + bz], brace, mat)\n  }\n}\n\n/** Swivel joint between a and b: two ball-race housings, seal ring, grease nipples and plug bolts. od = pipe OD. */\nexport function swivel(k: Kit, a: V3, b: V3, od: number, mat: MatKey = 'flangeSteel') {\n  const A = new THREE.Vector3(...a)\n  const d = new THREE.Vector3(...b).sub(A)\n  const L = d.length()\n  d.normalize()\n  const v = d.toArray() as V3\n  const at = (t: number) => A.clone().addScaledVector(d, t).toArray() as V3\n  const R = od * 0.82\n  const ri = od * 0.44\n  ring(k, mat, ri, od * 0.56, L, at(L / 2), v)\n  k.cyl('pipeBore', ri, L, at(L / 2), v, 32, undefined, true)\n  ring(k, mat, od * 0.55, R, L * 0.36, at(L * 0.3), v)\n  ring(k, 'machined', od * 0.55, R * 0.96, L * 0.04, at(L * 0.5), v)\n  ring(k, mat, od * 0.55, R * 0.92, L * 0.3, at(L * 0.69), v)\n  for (const t of [0.12, 0.88]) ring(k, mat, od * 0.55, od * 0.7, L * 0.06, at(L * t), v)\n  const [u, w] = perpOf(d)\n  for (let i = 0; i < 6; i++) {\n    const ang = (i / 6) * Math.PI * 2\n    const r = new THREE.Vector3().addScaledVector(u, Math.cos(ang) * R).addScaledVector(w, Math.sin(ang) * R)\n    const p = new THREE.Vector3(...at(L * 0.3)).add(r)\n    k.hex('nut', Math.max(0.018, od * 0.06), 0.012, p.toArray() as V3, r.clone().normalize().toArray() as V3)\n  }\n  const gp = new THREE.Vector3(...at(L * 0.69)).addScaledVector(u, R * 0.92)\n  k.cyl('brass', Math.max(0.006, od * 0.02), 0.03, gp.clone().addScaledVector(u, 0.012).toArray() as V3, u.toArray() as V3, 8)\n}\n\nfunction perpOf(d: THREE.Vector3): [THREE.Vector3, THREE.Vector3] {\n  const ref = Math.abs(d.y) > 0.9 ? new THREE.Vector3(1, 0, 0) : new THREE.Vector3(0, 1, 0)\n  const u = new THREE.Vector3().crossVectors(d, ref).normalize()\n  return [u, new THREE.Vector3().crossVectors(d, u).normalize()]\n}\n\n/** Annular ring (hollow short cylinder) centred on pos along axis, open through the middle. */\nexport function ring(k: Kit, mat: MatKey, ri: number, ro: number, h: number, pos: V3, axis: Axis = 'y', seg = 36) {\n  const v = axisVec(axis)\n  const base = new THREE.Vector3(...pos).addScaledVector(v, -h / 2).toArray() as V3\n  k.lathe(mat, [[ro, 0], [ro, h], [ri, h], [ri, 0], [ro, 0]], base, v.toArray() as V3, seg)\n}\n\n/** Hydraulic cylinder from a (barrel end clevis) to b (rod eye). */\nexport function hydraulicCylinder(k: Kit, a: V3, b: V3, bore: number, mat: MatKey = 'actuatorBlue') {\n  const A = new THREE.Vector3(...a)\n  const B = new THREE.Vector3(...b)\n  const L = A.distanceTo(B)\n  if (L < 1e-3) return\n  const d = B.clone().sub(A).normalize()\n  const bl = Math.min(L * 0.62, L - 0.1)\n  const p = (t: number) => A.clone().addScaledVector(d, t).toArray() as V3\n  k.rod(mat, p(0.04), p(bl), bore / 2, 16)\n  k.rod(mat, p(0.04), p(0.1), bore * 0.62, 16)\n  k.rod(mat, p(bl - 0.06), p(bl), bore * 0.62, 16)\n  k.rod('stainless', p(bl), p(L - 0.04), bore * 0.28, 12)\n  const side = Math.abs(d.x) > 0.9 ? 'z' : 'x'\n  for (const t of [0.02, L - 0.02]) k.cyl('flangeSteel', bore * 0.45, bore * 0.6, p(t), side, 12)\n  k.rod('tubing', add(p(0.12), [0, bore * 0.6, 0]), add(p(bl - 0.08), [0, bore * 0.6, 0]), 0.006, 6)\n}\n\n/**\n * Trapezoidal profiled sheet (wall or roof cladding): profile runs along `u` for `length`, ribs stand out along `n`,\n * extruded `height` along `w`; `origin` is the (0, 0, 0) corner. Typical 35 mm rib at 200 mm pitch.\n */\nexport function profiledSheet(k: Kit, mat: MatKey, length: number, height: number, origin: V3, u: V3, n: V3, w: V3, pitch = 0.2, depth = 0.035) {\n  const top = pitch * 0.2\n  const slope = pitch * 0.15\n  const pts: [number, number][] = [[0, 0]]\n  const ribs = Math.max(1, Math.round(length / pitch))\n  const sc = length / (ribs * pitch)\n  for (let i = 0; i < ribs; i++) {\n    const a = i * pitch * sc\n    const m = a + (pitch * sc) / 2\n    pts.push([m - (top / 2 + slope) * sc, 0], [m - (top / 2) * sc, depth], [m + (top / 2) * sc, depth], [m + (top / 2 + slope) * sc, 0])\n  }\n  pts.push([length, 0])\n  const sh = new THREE.Shape()\n  pts.forEach(([x, y], i) => (i ? sh.lineTo(x, y) : sh.moveTo(x, y)))\n  for (let i = pts.length - 1; i >= 0; i--) sh.lineTo(pts[i][0], pts[i][1] - 0.0015)\n  sh.closePath()\n  const m = new THREE.Matrix4().makeBasis(new THREE.Vector3(...u), new THREE.Vector3(...n), new THREE.Vector3(...w)).setPosition(...origin)\n  k.extrude(mat, sh, height, m, 1)\n}\n"
    }
  ],
  "categories": [
    "onshore"
  ],
  "meta": {
    "export": "SurgeArrester",
    "anchor": "base",
    "standards": [
      "IEC 60099-4",
      "IEC 60099-5",
      "IEC 61936-1"
    ]
  }
}