@litfamily/litopencode 1.0.31 → 1.0.32

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 (267) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README-Ko-KR.md +6 -6
  3. package/README.md +6 -6
  4. package/dist/activation-probe.js +1 -0
  5. package/dist/activation-prompt-utils.d.ts +1 -1
  6. package/dist/activation-reentry.d.ts +20 -0
  7. package/dist/activation-reentry.js +110 -1
  8. package/dist/activation-routing.d.ts +2 -1
  9. package/dist/activation-routing.js +100 -11
  10. package/dist/activation-workflow-prompts.d.ts +4 -0
  11. package/dist/activation-workflow-prompts.js +30 -0
  12. package/dist/activation.d.ts +1 -1
  13. package/dist/activation.js +44 -5
  14. package/dist/adhd-next.d.ts +51 -0
  15. package/dist/adhd-next.js +150 -0
  16. package/dist/cli/managed-skill-assets.d.ts +1 -1
  17. package/dist/cli/managed-skill-assets.js +7 -1
  18. package/dist/cli/native-skill-integrity.js +1 -1
  19. package/dist/cli.js +7 -1
  20. package/dist/commands.d.ts +28 -1
  21. package/dist/commands.js +48 -1
  22. package/dist/features.d.ts +80 -1
  23. package/dist/features.js +105 -1
  24. package/dist/ledger.js +12 -1
  25. package/dist/secret-shapes.js +5 -5
  26. package/dist/skills.d.ts +22 -1
  27. package/dist/skills.js +36 -0
  28. package/dist/start-work-typed.d.ts +34 -0
  29. package/dist/start-work-typed.js +156 -0
  30. package/dist/state.d.ts +2 -0
  31. package/dist/state.js +2 -0
  32. package/dist/tools.js +22 -2
  33. package/dist/tui/mission-band.d.ts +20 -1
  34. package/dist/tui/mission-band.js +73 -16
  35. package/dist/tui/mission-looks.d.ts +38 -0
  36. package/dist/tui/mission-looks.js +73 -0
  37. package/dist/tui/mission-model.d.ts +2 -0
  38. package/dist/tui/mission-model.js +3 -1
  39. package/dist/tui/mission-rainbow.d.ts +33 -0
  40. package/dist/tui/mission-rainbow.js +90 -0
  41. package/dist/tui/mission-source.d.ts +48 -0
  42. package/dist/tui/mission-source.js +184 -2
  43. package/dist/tui/mission-text.d.ts +2 -0
  44. package/dist/tui/mission-text.js +9 -1
  45. package/dist/tui/mission-threads.d.ts +50 -0
  46. package/dist/tui/mission-threads.js +119 -0
  47. package/dist/tui.js +84 -6
  48. package/dist/uiux-visual-catalog.js +8 -1
  49. package/dist/v2/session-hooks.js +38 -5
  50. package/dist/workflow-stack.d.ts +53 -0
  51. package/dist/workflow-stack.js +196 -0
  52. package/docs/assets/readme/badge-version.svg +1 -1
  53. package/docs/assets/skills/lit-schematic.webp +0 -0
  54. package/docs/reference-Ko-KR.md +30 -2
  55. package/docs/reference.md +34 -2
  56. package/package.json +1 -1
  57. package/skills/frontend-ui-ux/SKILL.md +3 -2
  58. package/skills/frontend-ui-ux/kit/components.css +414 -0
  59. package/skills/frontend-ui-ux/kit/fonts.json +22 -0
  60. package/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
  61. package/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
  62. package/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
  63. package/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
  64. package/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
  65. package/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
  66. package/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
  67. package/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
  68. package/skills/frontend-ui-ux/kit/ui.js +226 -0
  69. package/skills/frontend-ui-ux/references/brand-and-imagery.md +2 -2
  70. package/skills/frontend-ui-ux/references/complete-contract.md +2 -1
  71. package/skills/frontend-ui-ux/references/craft-floor.md +6 -2
  72. package/skills/frontend-ui-ux/references/default-editorial-pixel.json +3 -0
  73. package/skills/frontend-ui-ux/references/house-styles.md +236 -0
  74. package/skills/frontend-ui-ux/references/motion-guide.md +2 -2
  75. package/skills/frontend-ui-ux/references/production.md +3 -1
  76. package/skills/frontend-ui-ux/references/slop-register.md +4 -4
  77. package/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
  78. package/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
  79. package/skills/frontend-ui-ux/scripts/probe-lock.mjs +235 -0
  80. package/skills/frontend-ui-ux/scripts/probe-page.mjs +34 -12
  81. package/skills/frontend-ui-ux/scripts/probe-static.mjs +16 -3
  82. package/skills/frontend-ui-ux/scripts/probe-thresholds.json +8 -2
  83. package/skills/frontend-ui-ux/scripts/probe.mjs +35 -7
  84. package/skills/lit-adhd/SKILL.md +208 -0
  85. package/skills/lit-adhd/references/brief-format.md +43 -0
  86. package/skills/lit-adhd/references/card-examples.md +82 -0
  87. package/skills/lit-adhd/references/status-taxonomy.md +29 -0
  88. package/skills/lit-adhd/scripts/rewind.mjs +835 -0
  89. package/skills/lit-diagram-drawer/SKILL.md +4 -3
  90. package/skills/lit-diagram-drawer/references/style-guide.md +20 -11
  91. package/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
  92. package/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
  93. package/skills/lit-diagram-drawer/references/type-tree.md +3 -3
  94. package/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
  95. package/skills/lit-diagram-drawer/references/verifier-guide.md +1 -0
  96. package/skills/lit-diagram-drawer/scripts/craft-thresholds.json +1 -2
  97. package/skills/lit-diagram-drawer/scripts/visual-quality.mjs +1 -2
  98. package/skills/lit-docx/SKILL.md +2 -1
  99. package/skills/lit-handoff/SKILL.md +2 -0
  100. package/skills/lit-hijack/SKILL.md +422 -0
  101. package/skills/lit-hijack/references/capture-and-provenance.md +87 -0
  102. package/skills/lit-hijack/references/clean-room-build.md +111 -0
  103. package/skills/lit-hijack/references/distil-and-licence.md +100 -0
  104. package/skills/lit-hijack/references/gap-and-port-design.md +126 -0
  105. package/skills/lit-hijack/references/parity-and-report.md +110 -0
  106. package/skills/lit-hijack/scripts/hijack.mjs +993 -0
  107. package/skills/lit-plan/SKILL.md +2 -0
  108. package/skills/lit-pptx/SKILL.md +27 -11
  109. package/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
  110. package/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
  111. package/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
  112. package/skills/lit-pptx/fonts/jetbrains-mono/SOURCE.md +17 -0
  113. package/skills/lit-pptx/references/density-and-fill.md +9 -3
  114. package/skills/lit-pptx/references/direction-step.md +21 -6
  115. package/skills/lit-pptx/references/examples/04-lecture-chalk-ko.md +3 -6
  116. package/skills/lit-pptx/references/examples/05-research-talk-paper-en.md +1 -5
  117. package/skills/lit-pptx/references/examples/08-reliability-keynote-night-en.md +0 -4
  118. package/skills/lit-pptx/references/examples/09-status-update-ledger-en.md +2 -2
  119. package/skills/lit-pptx/references/examples/11-forecast-review-night-ko.md +4 -7
  120. package/skills/lit-pptx/references/examples/13-engineering-review-computational-brutalism-ko.md +173 -0
  121. package/skills/lit-pptx/references/examples/14-launch-pitch-neo-brutalism-ko.md +154 -0
  122. package/skills/lit-pptx/references/examples/15-design-lecture-bauhaus-ko.md +139 -0
  123. package/skills/lit-pptx/references/examples/16-community-programme-riso-ko.md +158 -0
  124. package/skills/lit-pptx/references/examples/17-public-data-briefing-newsroom-ko.md +179 -0
  125. package/skills/lit-pptx/references/layout-families.md +65 -47
  126. package/skills/lit-pptx/references/title-treatments.md +83 -134
  127. package/skills/lit-pptx/references/tonalities/atlas.md +3 -3
  128. package/skills/lit-pptx/references/tonalities/bauhaus.md +140 -0
  129. package/skills/lit-pptx/references/tonalities/chalk.md +7 -6
  130. package/skills/lit-pptx/references/tonalities/computational-brutalism.md +150 -0
  131. package/skills/lit-pptx/references/tonalities/gazette.md +1 -1
  132. package/skills/lit-pptx/references/tonalities/ledger.md +1 -1
  133. package/skills/lit-pptx/references/tonalities/neo-brutalism.md +161 -0
  134. package/skills/lit-pptx/references/tonalities/newsroom.md +144 -0
  135. package/skills/lit-pptx/references/tonalities/night.md +1 -1
  136. package/skills/lit-pptx/references/tonalities/paper.md +2 -2
  137. package/skills/lit-pptx/references/tonalities/riso.md +137 -0
  138. package/skills/lit-pptx/references/tonalities/signal.md +3 -3
  139. package/skills/lit-pptx/references/tonalities/studio.md +7 -6
  140. package/skills/lit-pptx/run.mjs +2 -1
  141. package/skills/lit-pptx/scripts/compile-deck.js +1 -1
  142. package/skills/lit-pptx/scripts/craft-thresholds.json +4 -8
  143. package/skills/lit-pptx/scripts/craft_extras.py +56 -3
  144. package/skills/lit-pptx/scripts/deck_output.py +75 -90
  145. package/skills/lit-pptx/scripts/embed_fonts.py +13 -1
  146. package/skills/lit-pptx/scripts/layout_inventory.py +12 -5
  147. package/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
  148. package/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
  149. package/skills/lit-pptx/scripts/lib/render-pack.js +373 -566
  150. package/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
  151. package/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
  152. package/skills/lit-pptx/scripts/qa_deck.py +10 -11
  153. package/skills/lit-pptx/scripts/render_pages.py +118 -0
  154. package/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
  155. package/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
  156. package/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
  157. package/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +99 -0
  158. package/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
  159. package/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
  160. package/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
  161. package/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
  162. package/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
  163. package/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
  164. package/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
  165. package/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
  166. package/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
  167. package/skills/lit-recap/SKILL.md +4 -0
  168. package/skills/lit-schematic/SKILL.md +118 -0
  169. package/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
  170. package/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
  171. package/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
  172. package/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
  173. package/skills/lit-schematic/references/cutaway-outputs.md +70 -0
  174. package/skills/lit-schematic/references/isometric-craft.md +101 -0
  175. package/skills/lit-schematic/references/journal-figures.md +72 -0
  176. package/skills/lit-schematic/references/kit-api.md +134 -0
  177. package/skills/lit-schematic/references/pfd-and-layout.md +53 -0
  178. package/skills/lit-schematic/references/pid-drafting.md +103 -0
  179. package/skills/lit-schematic/references/pid-symbols.md +163 -0
  180. package/skills/lit-schematic/references/verification.md +100 -0
  181. package/skills/lit-schematic/scripts/doctor.mjs +57 -0
  182. package/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
  183. package/skills/lit-schematic/scripts/lib/fonts.mjs +25 -0
  184. package/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
  185. package/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
  186. package/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
  187. package/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
  188. package/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
  189. package/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
  190. package/skills/lit-schematic/scripts/lib/png.mjs +132 -0
  191. package/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
  192. package/skills/lit-schematic/scripts/lib/route.mjs +218 -0
  193. package/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
  194. package/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
  195. package/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
  196. package/skills/lit-schematic/scripts/motion.mjs +129 -0
  197. package/skills/lit-schematic/scripts/qa.mjs +92 -0
  198. package/skills/lit-schematic/scripts/render.mjs +233 -0
  199. package/skills/lit-schematic/scripts/scaffold.mjs +60 -0
  200. package/skills/lit-scientific-visualization/SKILL.md +27 -4
  201. package/skills/lit-typographic-motion/SKILL.md +19 -17
  202. package/skills/lit-typographic-motion/THIRD_PARTY_NOTICES +9 -0
  203. package/skills/lit-typographic-motion/engine/accents.mjs +6 -0
  204. package/skills/lit-typographic-motion/engine/assets.mjs +282 -0
  205. package/skills/lit-typographic-motion/engine/blender/runner.py +228 -0
  206. package/skills/lit-typographic-motion/engine/blender.mjs +126 -0
  207. package/skills/lit-typographic-motion/engine/board.mjs +138 -0
  208. package/skills/lit-typographic-motion/engine/cover/assets.mjs +11 -8
  209. package/skills/lit-typographic-motion/engine/cover/capture.mjs +6 -6
  210. package/skills/lit-typographic-motion/engine/cover/render.mjs +20 -7
  211. package/skills/lit-typographic-motion/engine/cover/treatment.mjs +30 -3
  212. package/skills/lit-typographic-motion/engine/fill.mjs +54 -0
  213. package/skills/lit-typographic-motion/engine/gallery.mjs +118 -0
  214. package/skills/lit-typographic-motion/engine/house.mjs +42 -0
  215. package/skills/lit-typographic-motion/engine/look.mjs +65 -8
  216. package/skills/lit-typographic-motion/engine/loudness.mjs +101 -0
  217. package/skills/lit-typographic-motion/engine/scaffold.mjs +219 -0
  218. package/skills/lit-typographic-motion/engine/score.mjs +594 -0
  219. package/skills/lit-typographic-motion/engine/sound.mjs +9 -57
  220. package/skills/lit-typographic-motion/engine/stage/capture.mjs +23 -9
  221. package/skills/lit-typographic-motion/engine/stage/clock.js +8 -2
  222. package/skills/lit-typographic-motion/engine/stage/cover-init.js +12 -1
  223. package/skills/lit-typographic-motion/engine/stage/frame-worker.mjs +15 -7
  224. package/skills/lit-typographic-motion/engine/stage/gate.mjs +48 -4
  225. package/skills/lit-typographic-motion/engine/stage/qa-page.js +16 -5
  226. package/skills/lit-typographic-motion/engine/stage/qa.mjs +148 -7
  227. package/skills/lit-typographic-motion/engine/stage/render.mjs +69 -7
  228. package/skills/lit-typographic-motion/engine/stage/scan.mjs +20 -1
  229. package/skills/lit-typographic-motion/engine/stage/stage-kit.js +85 -4
  230. package/skills/lit-typographic-motion/engine/stills.mjs +1 -1
  231. package/skills/lit-typographic-motion/engine/styles.mjs +221 -0
  232. package/skills/lit-typographic-motion/engine/text.mjs +1 -1
  233. package/skills/lit-typographic-motion/engine/treatment.mjs +190 -6
  234. package/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
  235. package/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
  236. package/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
  237. package/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
  238. package/skills/lit-typographic-motion/gate.mjs +18 -2
  239. package/skills/lit-typographic-motion/probe.mjs +13 -1
  240. package/skills/lit-typographic-motion/recipes/hero-3d/expected.json +64 -0
  241. package/skills/lit-typographic-motion/recipes/hero-3d/index.html +132 -0
  242. package/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +2 -0
  243. package/skills/lit-typographic-motion/recipes/painted-light/expected.json +2 -0
  244. package/skills/lit-typographic-motion/recipes/weight-tide/expected.json +2 -0
  245. package/skills/lit-typographic-motion/references/cover.md +56 -13
  246. package/skills/lit-typographic-motion/references/craft-loop.md +20 -7
  247. package/skills/lit-typographic-motion/references/depth.md +112 -0
  248. package/skills/lit-typographic-motion/references/runtime.md +21 -6
  249. package/skills/lit-typographic-motion/references/sound.md +76 -0
  250. package/skills/lit-typographic-motion/references/stage.md +50 -7
  251. package/skills/lit-typographic-motion/references/studio.md +162 -0
  252. package/skills/lit-typographic-motion/references/style-bibles.md +18 -0
  253. package/skills/lit-typographic-motion/references/treatment.md +108 -9
  254. package/skills/lit-typographic-motion/render.mjs +60 -3
  255. package/skills/lit-typographic-motion/styles/paper.json +185 -0
  256. package/skills/lit-typographic-motion/styles/swiss-signal.json +188 -0
  257. package/skills/lit-typographic-motion/styles/terminalcore.json +182 -0
  258. package/skills/lit-typographic-motion/styles/tidal.json +187 -0
  259. package/skills/litresearch/SKILL.md +2 -0
  260. package/skills/managed-skill-manifest.json +517 -88
  261. package/skills/readme-studio/SKILL.md +1 -1
  262. package/skills/review-work/SKILL.md +2 -0
  263. package/skills/start-work/SKILL.md +8 -0
  264. package/skills/workflow-loop/SKILL.md +4 -0
  265. package/tools/check-pack-payload.mjs +4 -2
  266. package/tools/payload-substance-parity.json +4 -3
  267. package/tools/qa-cover-recipes.mjs +4 -3
@@ -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
+ }