@litfamily/litgrok 1.0.26 → 1.0.28

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.
Files changed (235) hide show
  1. package/.grok/hooks/lit-mark.mjs +42 -0
  2. package/.grok/hooks/lit-status-line.mjs +174 -21
  3. package/.grok/hooks/plan-gate.mjs +13 -3
  4. package/.grok/hooks/record-passive-event.mjs +40 -6
  5. package/.grok/hooks/session-end.json +15 -0
  6. package/.grok/hooks/session-end.mjs +6 -0
  7. package/.grok/hooks/session-liveness.mjs +102 -0
  8. package/.grok/hooks/session-rows.mjs +57 -0
  9. package/.grok/hooks/session-start.mjs +17 -0
  10. package/.grok/hooks/workflow-stage.mjs +5 -2
  11. package/.grok/rules/00-litgrok.md +14 -0
  12. package/.grok/skills/frontend-ui-ux/ATTRIBUTION.md +23 -0
  13. package/.grok/skills/frontend-ui-ux/SKILL.md +4 -1
  14. package/.grok/skills/frontend-ui-ux/examples/phase-3-readme-ab/README.md +9 -0
  15. package/.grok/skills/frontend-ui-ux/kit/components.css +414 -0
  16. package/.grok/skills/frontend-ui-ux/kit/fonts.json +22 -0
  17. package/.grok/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
  18. package/.grok/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
  19. package/.grok/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
  20. package/.grok/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
  21. package/.grok/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
  22. package/.grok/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
  23. package/.grok/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
  24. package/.grok/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
  25. package/.grok/skills/frontend-ui-ux/kit/ui.js +226 -0
  26. package/.grok/skills/frontend-ui-ux/references/adaptive-layout.md +10 -4
  27. package/.grok/skills/frontend-ui-ux/references/brand-and-imagery.md +11 -7
  28. package/.grok/skills/frontend-ui-ux/references/complete-contract.md +21 -0
  29. package/.grok/skills/frontend-ui-ux/references/composition.md +10 -6
  30. package/.grok/skills/frontend-ui-ux/references/craft-floor.md +256 -93
  31. package/.grok/skills/frontend-ui-ux/references/creative-directions.md +9 -6
  32. package/.grok/skills/frontend-ui-ux/references/default-editorial-pixel.json +28 -0
  33. package/.grok/skills/frontend-ui-ux/references/house-styles.md +234 -0
  34. package/.grok/skills/frontend-ui-ux/references/implementation-platforms.md +10 -6
  35. package/.grok/skills/frontend-ui-ux/references/inclusive-interface.md +11 -5
  36. package/.grok/skills/frontend-ui-ux/references/interaction-motion.md +34 -78
  37. package/.grok/skills/frontend-ui-ux/references/motion-guide.md +10 -7
  38. package/.grok/skills/frontend-ui-ux/references/performance-delivery.md +11 -8
  39. package/.grok/skills/frontend-ui-ux/references/probe-loop.md +1 -1
  40. package/.grok/skills/frontend-ui-ux/references/product-direction.md +9 -4
  41. package/.grok/skills/frontend-ui-ux/references/production-interview.md +17 -0
  42. package/.grok/skills/frontend-ui-ux/references/redesign-playbook.md +10 -6
  43. package/.grok/skills/frontend-ui-ux/references/slop-register.md +148 -73
  44. package/.grok/skills/frontend-ui-ux/references/system-foundations.md +10 -4
  45. package/.grok/skills/frontend-ui-ux/references/visual-language.md +10 -4
  46. package/.grok/skills/frontend-ui-ux/references/visual-reconstruction.md +39 -72
  47. package/.grok/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
  48. package/.grok/skills/frontend-ui-ux/scripts/interface-probe-driver.mjs +33 -0
  49. package/.grok/skills/frontend-ui-ux/scripts/interface-probe-lock.mjs +196 -0
  50. package/.grok/skills/frontend-ui-ux/scripts/interface-probe-page.mjs +1555 -0
  51. package/.grok/skills/frontend-ui-ux/scripts/interface-probe-rules.mjs +153 -0
  52. package/.grok/skills/frontend-ui-ux/scripts/interface-probe-server.mjs +57 -0
  53. package/.grok/skills/frontend-ui-ux/scripts/interface-probe-static.mjs +139 -0
  54. package/.grok/skills/frontend-ui-ux/scripts/interface-probe.mjs +363 -0
  55. package/.grok/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
  56. package/.grok/skills/lit-adhd/SKILL.md +155 -0
  57. package/.grok/skills/lit-adhd/references/card-examples.md +131 -0
  58. package/.grok/skills/lit-adhd/references/status-taxonomy.md +50 -0
  59. package/.grok/skills/lit-adhd/scripts/lib/brief.mjs +421 -0
  60. package/.grok/skills/lit-adhd/scripts/lib/collect.mjs +395 -0
  61. package/.grok/skills/lit-adhd/scripts/lib/gauge.mjs +87 -0
  62. package/.grok/skills/lit-adhd/scripts/lib/next-step.mjs +22 -0
  63. package/.grok/skills/lit-adhd/scripts/lib/plan-task-rows.mjs +32 -0
  64. package/.grok/skills/lit-adhd/scripts/lib/project-state-root.mjs +55 -0
  65. package/.grok/skills/lit-adhd/scripts/lib/redact.mjs +64 -0
  66. package/.grok/skills/lit-adhd/scripts/lib/suggest.mjs +140 -0
  67. package/.grok/skills/lit-adhd/scripts/lib/transcripts.mjs +232 -0
  68. package/.grok/skills/lit-adhd/scripts/rewind.mjs +6 -0
  69. package/.grok/skills/lit-diagram-drawer/SKILL.md +17 -5
  70. package/.grok/skills/lit-diagram-drawer/references/output-spec.md +2 -2
  71. package/.grok/skills/lit-diagram-drawer/references/style-guide.md +20 -11
  72. package/.grok/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
  73. package/.grok/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
  74. package/.grok/skills/lit-diagram-drawer/references/type-tree.md +3 -3
  75. package/.grok/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
  76. package/.grok/skills/lit-diagram-drawer/references/verifier-guide.md +4 -0
  77. package/.grok/skills/lit-diagram-drawer/scripts/visual-quality.mjs +2 -2
  78. package/.grok/skills/lit-handoff/SKILL.md +2 -0
  79. package/.grok/skills/lit-hijack/SKILL.md +459 -0
  80. package/.grok/skills/lit-hijack/references/capture-and-provenance.md +124 -0
  81. package/.grok/skills/lit-hijack/references/clean-room-build.md +130 -0
  82. package/.grok/skills/lit-hijack/references/distil-and-licence.md +128 -0
  83. package/.grok/skills/lit-hijack/references/gap-and-port-design.md +150 -0
  84. package/.grok/skills/lit-hijack/references/parity-and-report.md +130 -0
  85. package/.grok/skills/lit-hijack/scripts/hijack.mjs +890 -0
  86. package/.grok/skills/lit-hijack/scripts/lib/safe-fetch.mjs +213 -0
  87. package/.grok/skills/lit-plan/SKILL.md +3 -1
  88. package/.grok/skills/lit-plan/references/plan-schema.md +4 -0
  89. package/.grok/skills/lit-plan/scripts/scaffold-plan.mjs +9 -2
  90. package/.grok/skills/lit-plan/scripts/scope-roots.mjs +83 -0
  91. package/.grok/skills/lit-pptx/SKILL.md +10 -5
  92. package/.grok/skills/lit-pptx/examples/13-engineering-review-computational-brutalism-ko.md +173 -0
  93. package/.grok/skills/lit-pptx/examples/14-launch-pitch-neo-brutalism-ko.md +154 -0
  94. package/.grok/skills/lit-pptx/examples/15-design-lecture-bauhaus-ko.md +139 -0
  95. package/.grok/skills/lit-pptx/examples/16-community-programme-riso-ko.md +158 -0
  96. package/.grok/skills/lit-pptx/examples/17-public-data-briefing-newsroom-ko.md +179 -0
  97. package/.grok/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
  98. package/.grok/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
  99. package/.grok/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
  100. package/.grok/skills/lit-pptx/fonts/jetbrains-mono/provenance.json +1 -0
  101. package/.grok/skills/lit-pptx/references/direction-step.md +34 -8
  102. package/.grok/skills/lit-pptx/references/tonalities/bauhaus.md +140 -0
  103. package/.grok/skills/lit-pptx/references/tonalities/computational-brutalism.md +150 -0
  104. package/.grok/skills/lit-pptx/references/tonalities/neo-brutalism.md +161 -0
  105. package/.grok/skills/lit-pptx/references/tonalities/newsroom.md +144 -0
  106. package/.grok/skills/lit-pptx/references/tonalities/riso.md +137 -0
  107. package/.grok/skills/lit-pptx/scripts/compile-deck.js +1 -1
  108. package/.grok/skills/lit-pptx/scripts/craft_extras.py +61 -3
  109. package/.grok/skills/lit-pptx/scripts/deck_output.py +76 -62
  110. package/.grok/skills/lit-pptx/scripts/embed_fonts.py +14 -1
  111. package/.grok/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
  112. package/.grok/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
  113. package/.grok/skills/lit-pptx/scripts/lib/render-pack.js +389 -582
  114. package/.grok/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
  115. package/.grok/skills/lit-pptx/scripts/lib/template-registry.js +60 -8
  116. package/.grok/skills/lit-pptx/scripts/qa_deck.py +4 -4
  117. package/.grok/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +2 -0
  118. package/.grok/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
  119. package/.grok/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +2 -0
  120. package/.grok/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +99 -0
  121. package/.grok/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +2 -0
  122. package/.grok/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +2 -0
  123. package/.grok/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
  124. package/.grok/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
  125. package/.grok/skills/lit-pptx/templates/tonalities/night/pack.yaml +2 -0
  126. package/.grok/skills/lit-pptx/templates/tonalities/paper/pack.yaml +2 -0
  127. package/.grok/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
  128. package/.grok/skills/lit-pptx/templates/tonalities/signal/pack.yaml +3 -0
  129. package/.grok/skills/lit-pptx/templates/tonalities/studio/pack.yaml +2 -0
  130. package/.grok/skills/lit-recap/SKILL.md +1 -1
  131. package/.grok/skills/lit-schematic/SKILL.md +140 -0
  132. package/.grok/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
  133. package/.grok/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
  134. package/.grok/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
  135. package/.grok/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
  136. package/.grok/skills/lit-schematic/references/cutaway-outputs.md +70 -0
  137. package/.grok/skills/lit-schematic/references/isometric-craft.md +101 -0
  138. package/.grok/skills/lit-schematic/references/journal-figures.md +72 -0
  139. package/.grok/skills/lit-schematic/references/kit-api.md +134 -0
  140. package/.grok/skills/lit-schematic/references/pfd-and-layout.md +53 -0
  141. package/.grok/skills/lit-schematic/references/pid-drafting.md +103 -0
  142. package/.grok/skills/lit-schematic/references/pid-symbols.md +163 -0
  143. package/.grok/skills/lit-schematic/references/verification.md +100 -0
  144. package/.grok/skills/lit-schematic/scripts/doctor.mjs +57 -0
  145. package/.grok/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
  146. package/.grok/skills/lit-schematic/scripts/lib/fonts.mjs +27 -0
  147. package/.grok/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
  148. package/.grok/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
  149. package/.grok/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
  150. package/.grok/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
  151. package/.grok/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
  152. package/.grok/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
  153. package/.grok/skills/lit-schematic/scripts/lib/png.mjs +132 -0
  154. package/.grok/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
  155. package/.grok/skills/lit-schematic/scripts/lib/route.mjs +218 -0
  156. package/.grok/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
  157. package/.grok/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
  158. package/.grok/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
  159. package/.grok/skills/lit-schematic/scripts/motion.mjs +129 -0
  160. package/.grok/skills/lit-schematic/scripts/qa.mjs +92 -0
  161. package/.grok/skills/lit-schematic/scripts/render.mjs +233 -0
  162. package/.grok/skills/lit-schematic/scripts/scaffold.mjs +60 -0
  163. package/.grok/skills/lit-scientific-visualization/SKILL.md +36 -12
  164. package/.grok/skills/lit-typographic-motion/SKILL.md +7 -4
  165. package/.grok/skills/lit-typographic-motion/THIRD_PARTY_NOTICES +11 -0
  166. package/.grok/skills/lit-typographic-motion/recipes/hero-3d/expected.json +62 -0
  167. package/.grok/skills/lit-typographic-motion/recipes/hero-3d/index.html +82 -0
  168. package/.grok/skills/lit-typographic-motion/references/choice-first.md +30 -0
  169. package/.grok/skills/lit-typographic-motion/references/cover.md +10 -1
  170. package/.grok/skills/lit-typographic-motion/references/depth.md +119 -0
  171. package/.grok/skills/lit-typographic-motion/references/treatment.md +9 -1
  172. package/.grok/skills/lit-typographic-motion/scripts/blender/runner.py +218 -0
  173. package/.grok/skills/lit-typographic-motion/scripts/lib/assets.mjs +230 -0
  174. package/.grok/skills/lit-typographic-motion/scripts/lib/blender.mjs +136 -0
  175. package/.grok/skills/lit-typographic-motion/scripts/lib/board.mjs +153 -0
  176. package/.grok/skills/lit-typographic-motion/scripts/lib/chrome.mjs +61 -32
  177. package/.grok/skills/lit-typographic-motion/scripts/lib/constants.mjs +4 -2
  178. package/.grok/skills/lit-typographic-motion/scripts/lib/cover-capture.mjs +20 -11
  179. package/.grok/skills/lit-typographic-motion/scripts/lib/cover-treatment.mjs +26 -2
  180. package/.grok/skills/lit-typographic-motion/scripts/lib/cover.mjs +12 -5
  181. package/.grok/skills/lit-typographic-motion/scripts/lib/frame-pool.mjs +78 -1
  182. package/.grok/skills/lit-typographic-motion/scripts/lib/gallery.mjs +160 -0
  183. package/.grok/skills/lit-typographic-motion/scripts/lib/house.mjs +43 -0
  184. package/.grok/skills/lit-typographic-motion/scripts/lib/look.mjs +39 -1
  185. package/.grok/skills/lit-typographic-motion/scripts/lib/scaffold.mjs +174 -0
  186. package/.grok/skills/lit-typographic-motion/scripts/lib/score.mjs +640 -0
  187. package/.grok/skills/lit-typographic-motion/scripts/lib/sound.mjs +143 -0
  188. package/.grok/skills/lit-typographic-motion/scripts/lib/soundtrack.mjs +12 -3
  189. package/.grok/skills/lit-typographic-motion/scripts/lib/stage-gate.mjs +44 -0
  190. package/.grok/skills/lit-typographic-motion/scripts/lib/stage-qa.mjs +132 -3
  191. package/.grok/skills/lit-typographic-motion/scripts/lib/stage-session.mjs +51 -3
  192. package/.grok/skills/lit-typographic-motion/scripts/lib/stage.mjs +74 -9
  193. package/.grok/skills/lit-typographic-motion/scripts/lib/styles.mjs +224 -0
  194. package/.grok/skills/lit-typographic-motion/scripts/lib/treatment.mjs +198 -4
  195. package/.grok/skills/lit-typographic-motion/scripts/lib/vendor/three/LICENSE +21 -0
  196. package/.grok/skills/lit-typographic-motion/scripts/lib/vendor/three/addons/environments/RoomEnvironment.js +144 -0
  197. package/.grok/skills/lit-typographic-motion/scripts/lib/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
  198. package/.grok/skills/lit-typographic-motion/scripts/lib/vendor/three/three.module.js +54571 -0
  199. package/.grok/skills/lit-typographic-motion/scripts/motion.mjs +56 -6
  200. package/.grok/skills/lit-typographic-motion/scripts/stage/cover-init.js +20 -8
  201. package/.grok/skills/lit-typographic-motion/scripts/stage/loop-kit.js +2 -2
  202. package/.grok/skills/lit-typographic-motion/scripts/stage/stage-kit.js +25 -0
  203. package/.grok/skills/lit-typographic-motion/styles/paper.json +1 -0
  204. package/.grok/skills/lit-typographic-motion/styles/swiss-signal.json +1 -0
  205. package/.grok/skills/lit-typographic-motion/styles/terminalcore.json +1 -0
  206. package/.grok/skills/lit-typographic-motion/styles/tidal.json +1 -0
  207. package/.grok/skills/litgrok/SKILL.md +1 -1
  208. package/.grok/skills/litresearch/SKILL.md +2 -0
  209. package/.grok/skills/readme-studio/SKILL.md +14 -12
  210. package/.grok/skills/readme-studio/references/choice-first.md +24 -0
  211. package/.grok/skills/start-work/SKILL.md +8 -1
  212. package/.grok-plugin/plugin.json +4 -1
  213. package/CHANGELOG.md +18 -0
  214. package/README.md +11 -11
  215. package/README_ko-KR.md +11 -11
  216. package/TRADEMARK.md +12 -0
  217. package/bin/litgrok.mjs +2 -0
  218. package/docs/assets/readme/badge-version.svg +1 -1
  219. package/docs/assets/showcase/brief.webp +0 -0
  220. package/docs/assets/showcase/deck.webp +0 -0
  221. package/docs/assets/showcase/page.webp +0 -0
  222. package/docs/assets/showcase/pid.webp +0 -0
  223. package/docs/assets/skills/lit-adhd.webp +0 -0
  224. package/docs/assets/skills/lit-hijack.webp +0 -0
  225. package/docs/assets/skills/lit-schematic.webp +0 -0
  226. package/docs/reference.md +11 -7
  227. package/docs/reference_ko-KR.md +11 -7
  228. package/hooks/hooks.json +11 -0
  229. package/package.json +6 -1
  230. package/plugin.json +1 -1
  231. package/.grok/skills/frontend-ui-ux/scripts/page-probe.mjs +0 -105
  232. package/.grok/skills/frontend-ui-ux/scripts/probe.mjs +0 -91
  233. package/.grok/skills/frontend-ui-ux/scripts/rule-data.mjs +0 -56
  234. package/.grok/skills/frontend-ui-ux/scripts/static-probe.mjs +0 -27
  235. package/.grok/skills/frontend-ui-ux/scripts/static-server.mjs +0 -19
@@ -0,0 +1,162 @@
1
+ // The "P&ID symbols and abbreviations" sheet a drawing set opens with, built from the library
2
+ // itself so it can never drift from what the kit draws: every line class, equipment, valve,
3
+ // actuator, relief device, piping item and flow element, the ISA-5.1 instrument shape and
4
+ // location matrix, the identification letters, fail positions, line-number format and
5
+ // equipment prefixes, on one sheet with the usual frame and title block.
6
+
7
+ import { EQUIPMENT_CLASS, FUNCTION_MODIFIER, MEASURED, OUTPUT, READOUT, VARIABLE_MODIFIER } from "./isa.mjs";
8
+ import { FAIL_POSITIONS, FUNCTIONS, LOCATIONS, describeKind } from "./pid.mjs";
9
+ import { LINE_KINDS, createSheet, legendGlyph, legendLine } from "./sheet.mjs";
10
+ import { el, esc, textWidthEm } from "./svg.mjs";
11
+ import { FONT_LATIN, PID } from "./theme.mjs";
12
+
13
+ const SYMBOL_GROUPS = Object.freeze([
14
+ ["EQUIPMENT", [
15
+ "vessel.vertical", "vessel.horizontal", "vessel.jacketed", "vessel.reactor", "vessel.column", "vessel.tank", "gas.cylinder",
16
+ "pump.centrifugal", "pump.positive", "pump.metering", "compressor.centrifugal", "compressor.reciprocating",
17
+ "exchanger.general", "exchanger.shelltube", "exchanger.floating", "exchanger.utube", "exchanger.plate", "exchanger.aircooler",
18
+ "package.unit", "drive.motor",
19
+ ]],
20
+ ["VALVES", [
21
+ "valve.gate", "valve.globe", "valve.ball", "valve.butterfly", "valve.plug", "valve.needle", "valve.diaphragm",
22
+ "valve.check", "valve.threeway", "valve.angle",
23
+ ]],
24
+ ["ACTUATORS (SHOWN ON A GLOBE BODY)", [
25
+ "valve.globe.diaphragm", "valve.globe.piston", "valve.globe.motor", "valve.globe.solenoid", "valve.globe.hand",
26
+ ]],
27
+ ["SELF-ACTING AND RELIEF DEVICES", ["valve.regulator", "valve.backpressure", "valve.safety", "relief.rupture"]],
28
+ ["PIPING ITEMS", ["line.reducer", "line.reducer-eccentric", "line.flange", "line.blind", "line.blind-open", "line.filter", "line.sightglass"]],
29
+ ["FLOW ELEMENTS", ["flow.orifice", "flow.venturi", "flow.magnetic", "flow.coriolis", "flow.vortex", "flow.turbine", "flow.ultrasonic", "flow.thermal", "flow.rotameter", "flow.mfc"]],
30
+ ["CONNECTIONS AND LOGIC", ["terminal.offpage", "terminal.utility", "terminal.vent", "terminal.drain", "terminal.sample", "logic.interlock"]],
31
+ ]);
32
+
33
+ const LOCATION_HEADS = Object.freeze({ field: ["Field"], main: ["Main", "room"], "main-rear": ["Main,", "behind"], aux: ["Local", "panel"], "aux-rear": ["Local,", "behind"] });
34
+ const FUNCTION_HEADS = Object.freeze({ discrete: "Discrete", shared: "Shared (DCS)", computer: "Computer", plc: "PLC / SIS" });
35
+
36
+ export function createLegendSheet({
37
+ size = "A2", title = "P&ID symbols and abbreviations", number = "LEG-001", rev = "0", date = "", scale = "NTS",
38
+ project = "", owner = "", drawn = "", checked = "", approved = "", sheet = "1 OF 1",
39
+ } = {}) {
40
+ const notes = [
41
+ "Instrument shapes, location lines, signal lines, actuators and identification letters after ANSI/ISA-5.1-2009 (Tables 4.1, 5.1.1, 5.2.2, 5.3.1, 5.3.2, 5.4.1 to 5.4.4).",
42
+ "Equipment, valve and piping symbols after ISO 10628-2:2012 (Table 2 subject groups) and common US practice (PIP PIC001).",
43
+ "A symbol drawn on a P&ID of this set without a row on this sheet is defined in the legend column of that P&ID.",
44
+ ];
45
+ const s = createSheet({ mode: "pid", size, title, number, rev, date, scale, project, owner, drawn, checked, approved, sheet, notes, legendColumn: false, headerBand: false });
46
+ const [x0, y0, x1, y1] = s.drawing;
47
+ const small = PID.text.small;
48
+ const head = PID.text.label;
49
+ const gutter = 8;
50
+ const columns = 5;
51
+ const colW = (x1 - x0 - gutter * (columns - 1)) / columns;
52
+ const text = (x, ty, content, sz = small, extra = {}) => el("text", { x, y: ty, "font-family": FONT_LATIN, "font-size": sz, fill: PID.ink, "data-label": "legend", ...extra }, esc(content));
53
+ const wrap = (content, width) => {
54
+ const words = content.split(/\s+/u);
55
+ const lines = [];
56
+ let line = "";
57
+ for (const word of words) {
58
+ const next = line ? `${line} ${word}` : word;
59
+ if (line && textWidthEm(next) * small > width) { lines.push(line); line = word; } else line = next;
60
+ }
61
+ if (line) lines.push(line);
62
+ return lines;
63
+ };
64
+
65
+ // First collect sections of rows (each row knows its height and draws at a given x and top),
66
+ // then lay them out in columns: a section that fits in one column is never split; a longer
67
+ // one continues in the next column under a "(cont.)" heading.
68
+ const sections = [];
69
+ const section = (title) => { const sec = { title, rows: [] }; sections.push(sec); return sec; };
70
+ const sampleRow = (sec, key, draw, label, sampleHeight = 4) => {
71
+ const lines = wrap(label, colW - 22);
72
+ const h = Math.max(7.4, sampleHeight + 2.6, lines.length * 2.6 + 2.2);
73
+ sec.rows.push({ h, draw: (x, top) => {
74
+ const cy = top + h / 2;
75
+ return el("g", { "data-legend-item": key }, draw(x, cy), lines.map((t, i) => text(x + 20, cy + 0.8 + (i - (lines.length - 1) / 2) * 2.6, t)));
76
+ } });
77
+ };
78
+ const pairRow = (sec, key, code, meaning, indent = 7) => {
79
+ sec.rows.push({ h: 3.3, draw: (x, top) => el("g", { "data-legend-item": key }, text(x, top + 2.6, code, small, { "font-weight": "bold" }), text(x + indent, top + 2.6, meaning)) });
80
+ };
81
+
82
+ const lineSection = section("LINES");
83
+ for (const kind of Object.keys(LINE_KINDS).filter((k) => k !== "stream")) {
84
+ sampleRow(lineSection, `line:${kind}`, (x, cy) => legendLine(kind, x + 1, x + 16, cy), LINE_KINDS[kind].label, 3);
85
+ }
86
+ for (const [name, kinds] of SYMBOL_GROUPS) {
87
+ const sec = section(name);
88
+ for (const kind of kinds) {
89
+ const probe = legendGlyph(kind, 0, 0, { maxW: 16, maxH: 11 });
90
+ sampleRow(sec, kind, (x, cy) => legendGlyph(kind, x + 8.5, cy, { maxW: 16, maxH: 11 }).svg, describeKind(kind), probe.h);
91
+ }
92
+ }
93
+
94
+ // ISA-5.1 Table 5.1.1 as a matrix: function down the side, location across the top.
95
+ const matrix = section("INSTRUMENT SHAPE AND LOCATION");
96
+ const cell = Math.min(16, (colW - 24) / 5);
97
+ const labelW = colW - cell * 5;
98
+ matrix.rows.push({ h: small * 2 + 3 + Object.keys(FUNCTIONS).length * 10, draw: (gx, top) => {
99
+ const out = [];
100
+ Object.values(LOCATION_HEADS).forEach((heads, j) => {
101
+ heads.forEach((t, i) => out.push(text(gx + labelW + cell * j + cell / 2, top + small + i * (small + 0.6), t, small, { "text-anchor": "middle" })));
102
+ });
103
+ Object.keys(FUNCTIONS).forEach((fn, i) => {
104
+ const cy = top + small * 2 + 3 + i * 10 + 5;
105
+ out.push(text(gx, cy + 0.8, FUNCTION_HEADS[fn]));
106
+ Object.keys(LOCATIONS).forEach((loc, j) => {
107
+ const kind = `instrument.${fn}-${loc}`;
108
+ out.push(el("g", { "data-legend-item": kind }, legendGlyph(kind, gx + labelW + cell * j + cell / 2, cy).svg));
109
+ });
110
+ });
111
+ return out.join("");
112
+ } });
113
+
114
+ // ISA-5.1 Table 4.1, one list per letter position.
115
+ for (const [key, title, entries] of [
116
+ ["letters", "FIRST LETTER: MEASURED OR INITIATING VARIABLE", MEASURED],
117
+ ["modifier", "VARIABLE MODIFIERS (SECOND LETTER)", VARIABLE_MODIFIER],
118
+ ["readout", "READOUT OR PASSIVE FUNCTION", READOUT],
119
+ ["output", "OUTPUT FUNCTION", OUTPUT],
120
+ ["function-modifier", "FUNCTION MODIFIERS", FUNCTION_MODIFIER],
121
+ ]) {
122
+ const sec = section(title);
123
+ for (const [letter, meaning] of Object.entries(entries)) pairRow(sec, `${key}:${letter}`, letter, meaning);
124
+ }
125
+ const fail = section("FAIL POSITION OF ACTUATED VALVES");
126
+ for (const [code, meaning] of Object.entries(FAIL_POSITIONS)) pairRow(fail, `fail:${code}`, code, meaning, 9);
127
+ const lineNumber = section("LINE NUMBER");
128
+ pairRow(lineNumber, "line-number:example", '2"-P-1001-A1A-IH', "");
129
+ pairRow(lineNumber, "line-number:parts", "", "size - fluid code - sequence - piping class", 0);
130
+ pairRow(lineNumber, "line-number:optional", "", "- insulation or tracing code (optional)", 0);
131
+ const prefixes = section("EQUIPMENT TAG PREFIXES");
132
+ for (const [code, meaning] of Object.entries(EQUIPMENT_CLASS)) pairRow(prefixes, `equipment:${code}`, code, meaning, 9);
133
+
134
+ const out = [];
135
+ const headH = head + 3.4;
136
+ const colHeight = y1 - y0 - 4;
137
+ let col = 0;
138
+ let y = y0 + 4;
139
+ const left = () => x0 + col * (colW + gutter);
140
+ const nextColumn = () => {
141
+ col++;
142
+ y = y0 + 4;
143
+ if (col >= columns) throw new Error(`createLegendSheet: the symbols do not fit on ${size}; use a larger sheet`);
144
+ };
145
+ const heading = (title) => { out.push(text(left(), y + head, title, head, { "font-weight": "bold", "data-label": "legend-title" })); y += headH; };
146
+ for (const sec of sections) {
147
+ const total = headH + sec.rows.reduce((sum, r) => sum + r.h, 0);
148
+ const gap = y > y0 + 4 ? 4 : 0;
149
+ if (y + gap + total > y1 - 1 && total <= colHeight) nextColumn();
150
+ else if (y + gap + headH + sec.rows[0].h > y1 - 1) nextColumn();
151
+ else y += gap;
152
+ heading(sec.title);
153
+ for (const r of sec.rows) {
154
+ if (y + r.h > y1 - 1) { nextColumn(); heading(`${sec.title} (cont.)`); }
155
+ out.push(r.draw(left(), y));
156
+ y += r.h;
157
+ }
158
+ }
159
+
160
+ s.raw(el("g", { "data-legend-sheet": "1" }, out));
161
+ return s.render({ desc: "Legend sheet: every symbol, line class, instrument shape and abbreviation the drawings of this set use." });
162
+ }