@ogabrielluiz/patchflow 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ogabrielluiz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # patchflow
2
+
3
+ Eurorack patch diagram renderer. Patchbook-compatible notation to skeuomorphic SVG block diagrams.
4
+
5
+ ## Examples
6
+
7
+ The diagrams below are regenerated on every push to `main` — they reflect the current output of the library.
8
+
9
+ ### Bouncing ball (self-patching feedback)
10
+
11
+ ```
12
+ MATHS:
13
+ * CH 1: Cycle ON
14
+ * CH 2: Attenuverter ~2 o'clock
15
+
16
+ - MATHS.CH 1 (OUT) >> MATHS.CH 2 (In)
17
+ - MATHS.CH 2 (Out) >> MATHS.CH 1 (Fall CV) // shortens fall each cycle
18
+ ```
19
+
20
+ <picture>
21
+ <source media="(prefers-color-scheme: dark)" srcset="./samples/bouncing-ball-dark.svg">
22
+ <img alt="Bouncing ball diagram" src="./samples/bouncing-ball-light.svg">
23
+ </picture>
24
+
25
+ ### Quadrature LFOs (multi-module with feedback)
26
+
27
+ ```
28
+ MATHS:
29
+ * CH 1: Cycle OFF, Rise + Fall matched
30
+ * CH 4: Cycle OFF, Rise + Fall matched
31
+
32
+ - MATHS.CH 1 (EOR) g> MATHS.CH 4 (Trig)
33
+ - MATHS.CH 4 (EOC) g> MATHS.CH 1 (Trig)
34
+ - MATHS.CH 1 (OUT) >> Filter (Cutoff)
35
+ - MATHS.CH 4 (OUT) >> VCA (CV)
36
+ ```
37
+
38
+ <picture>
39
+ <source media="(prefers-color-scheme: dark)" srcset="./samples/quadrature-lfos-dark.svg">
40
+ <img alt="Quadrature LFOs diagram" src="./samples/quadrature-lfos-light.svg">
41
+ </picture>
42
+
43
+ ### Simple chain
44
+
45
+ ```
46
+ - Oscillator (Out) -> Filter (In)
47
+ - Envelope (Out) >> Filter (Cutoff)
48
+ - Filter (Out) -> VCA (In)
49
+ - LFO (Out) >> VCA (CV)
50
+ ```
51
+
52
+ <picture>
53
+ <source media="(prefers-color-scheme: dark)" srcset="./samples/simple-chain-dark.svg">
54
+ <img alt="Simple chain diagram" src="./samples/simple-chain-light.svg">
55
+ </picture>
56
+
57
+ ### Multi-voice patch
58
+
59
+ ```
60
+ VOICE 1:
61
+ - Osc1 (Out) -> Mixer (In1)
62
+ - Env1 (Out) >> VCA1 (CV)
63
+
64
+ VOICE 2:
65
+ - Osc2 (Out) -> Mixer (In2)
66
+ - Env2 (Out) >> VCA2 (CV)
67
+
68
+ - Mixer (Out) -> Filter (In)
69
+ - Filter (Out) -> Output (In)
70
+ ```
71
+
72
+ <picture>
73
+ <source media="(prefers-color-scheme: dark)" srcset="./samples/multi-voice-dark.svg">
74
+ <img alt="Multi-voice diagram" src="./samples/multi-voice-light.svg">
75
+ </picture>
76
+
77
+ ## Install
78
+
79
+ ```bash
80
+ npm install @ogabrielluiz/patchflow
81
+ ```
82
+
83
+ ## Usage
84
+
85
+ ```ts
86
+ import { render } from '@ogabrielluiz/patchflow';
87
+
88
+ const svg = render(`
89
+ MATHS:
90
+ * CH 1: Cycle ON
91
+ * CH 2: Attenuverter ~2 o'clock
92
+
93
+ - MATHS.CH 1 (OUT) >> MATHS.CH 2 (In)
94
+ - MATHS.CH 2 (Out) >> MATHS.CH 1 (Fall CV) // shortens fall each cycle
95
+ `);
96
+ ```
97
+
98
+ ## Signal Operators
99
+
100
+ | Operator | Signal Type |
101
+ |----------|-------------|
102
+ | `->` | Audio |
103
+ | `>>` | CV |
104
+ | `p>` | Pitch / 1V/oct |
105
+ | `g>` | Gate |
106
+ | `t>` | Trigger |
107
+ | `c>` | Clock |
108
+
109
+ ## API
110
+
111
+ - `render(notation, options?)` — notation to SVG string
112
+ - `parse(notation)` — notation to PatchGraph
113
+ - `layout(graph, options?)` — PatchGraph to LayoutResult
114
+ - `renderSvg(layoutResult, theme)` — LayoutResult + Theme to SVG
115
+ - `createTheme(overrides)` — factory with deep partial merge
116
+
117
+ ## License
118
+
119
+ MIT
@@ -0,0 +1,42 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // src/types.ts
28
+ var SIGNAL_OPERATORS = {
29
+ "->": "audio",
30
+ ">>": "cv",
31
+ "p>": "pitch",
32
+ "g>": "gate",
33
+ "t>": "trigger",
34
+ "c>": "clock"
35
+ };
36
+
37
+ export {
38
+ __commonJS,
39
+ __toESM,
40
+ SIGNAL_OPERATORS
41
+ };
42
+ //# sourceMappingURL=chunk-B7DUSPQH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["// ── Signal Types ──\n\nexport type SignalType = 'audio' | 'cv' | 'pitch' | 'gate' | 'trigger' | 'clock';\n\nexport const SIGNAL_OPERATORS: Record<string, SignalType> = {\n '->': 'audio',\n '>>': 'cv',\n 'p>': 'pitch',\n 'g>': 'gate',\n 't>': 'trigger',\n 'c>': 'clock',\n};\n\n// ── Graph Primitives ──\n\nexport interface Port {\n id: string; // normalized key (lowercase, trimmed)\n display: string; // original form for rendering\n direction: 'in' | 'out';\n}\n\nexport interface Param {\n key: string;\n value: string;\n}\n\nexport interface Block {\n id: string;\n label: string;\n subLabel: string | null;\n params: Param[];\n ports: Port[];\n parentModule: string | null; // null for top-level modules, module name for sections\n voice: string | null;\n}\n\nexport interface ConnectionEndpoint {\n blockId: string;\n portId: string; // normalized key\n portDisplay: string; // original form\n}\n\nexport interface Connection {\n id: string;\n source: ConnectionEndpoint;\n target: ConnectionEndpoint;\n signalType: SignalType;\n annotation: string | null;\n graphvizExtras: Record<string, string> | null;\n}\n\n// ── Patch Graph (Parser Output) ──\n\nexport interface PatchGraph {\n declaredBlocks: Block[];\n stubBlocks: Block[];\n connections: Connection[];\n feedbackEdges: Connection[];\n signalTypeStats: Partial<Record<SignalType, number>>;\n voices: string[];\n}\n\n// ── Layout Types ──\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport interface LayoutPort extends Port {\n position: Point;\n signalType: SignalType | null;\n}\n\nexport interface LayoutBlock {\n id: string;\n label: string;\n subLabel: string | null;\n params: Param[];\n ports: LayoutPort[];\n parentModule: string | null;\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface LayoutConnection {\n id: string;\n source: ConnectionEndpoint;\n target: ConnectionEndpoint;\n signalType: SignalType;\n annotation: string | null;\n path: string; // SVG path d attribute\n isFeedback: boolean;\n sourcePoint: Point;\n targetPoint: Point;\n}\n\nexport interface LayoutResult {\n blocks: LayoutBlock[];\n connections: LayoutConnection[];\n width: number;\n height: number;\n signalTypeStats: Partial<Record<SignalType, number>>;\n}\n\n// ── Theme Types ──\n\nexport interface CableColor {\n stroke: string;\n plugTip: string;\n}\n\nexport interface SocketColors {\n bezel: string;\n bezelStroke: string;\n ring: string;\n hole: string;\n pin: string;\n}\n\nexport interface Theme {\n background: string;\n panel: {\n fill: string;\n stroke: string;\n highlight: string;\n shadow: string;\n cornerRadius: number;\n shadowBlur: number;\n shadowOpacity: number;\n bevelWidth: number;\n };\n label: {\n fontFamily: string;\n color: string;\n subColor: string;\n plateFill: string;\n plateStroke: string;\n };\n param: {\n plateFill: string;\n plateStroke: string;\n textColor: string;\n };\n port: {\n fontFamily: string;\n fontSize: number;\n colors: SocketColors;\n hideSocket: boolean;\n labelColor: string;\n pill: {\n show: boolean;\n fontSize: number;\n textColor: string;\n cornerRadius: number;\n };\n };\n cable: {\n width: number;\n colors: Record<SignalType, CableColor>;\n plugTipRadius: number;\n };\n annotation: {\n fontFamily: string;\n fontSize: number;\n color: string;\n haloColor: string;\n };\n grid: {\n dotColor: string;\n dotRadius: number;\n spacing: number;\n opacity: number;\n } | null;\n}\n\n// ── Options ──\n\nexport interface RenderOptions {\n theme?: DeepPartial<Theme>;\n maxWidth?: number;\n padding?: number;\n legend?: boolean | 'auto';\n}\n\nexport interface LayoutOptions {\n direction?: 'LR' | 'TB';\n nodeSep?: number;\n rankSep?: number;\n feedbackSide?: 'top' | 'bottom';\n}\n\n// ── Parse Result ──\n\nexport type ErrorCode =\n | 'SYNTAX_ERROR'\n | 'UNKNOWN_OPERATOR'\n | 'MISSING_PORT'\n | 'UNCLOSED_PAREN'\n | 'DUPLICATE_MODULE'\n | 'UNKNOWN_MODULE'\n | 'INVALID_PORT';\n\nexport type ErrorSeverity = 'error' | 'warning';\n\nexport interface ParseDiagnostic {\n code: ErrorCode;\n message: string;\n line: number;\n column: number;\n length: number;\n severity: ErrorSeverity;\n}\n\nexport interface ParseResult {\n graph: PatchGraph;\n errors: ParseDiagnostic[];\n warnings: ParseDiagnostic[];\n}\n\n// ── Utility Types ──\n\nexport type DeepPartial<T> = {\n [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,mBAA+C;AAAA,EAC1D,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;","names":[]}