@reladraw/studio 0.0.0-stage → 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,17 @@
1
+ reladraw studio
2
+ Copyright (c) 2026 Joe Walsh. All rights reserved.
3
+
4
+ This license covers reladraw studio version 0.1.0. You may install and
5
+ use that version free of charge, for any purpose, including commercial
6
+ use. Other versions are covered by the license published with them. The
7
+ terms of a version you already have will not change.
8
+
9
+ You may not copy, redistribute, sublicense, modify, or reverse-engineer
10
+ this software, except as permitted by applicable law.
11
+
12
+ reladraw studio includes or depends on third-party software, including
13
+ reladraw (Apache-2.0) and Electron (MIT), each under its own license.
14
+
15
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES
17
+ OR OTHER LIABILITY ARISING FROM THE USE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,27 @@
1
- # Temporary Holding Version
1
+ # reladraw studio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A desktop app for working with [reladraw](https://github.com/reladraw/reladraw) diagrams: viewing, editing and checking them, in a window of their own, while an agent edits the files beside you.
4
+
5
+ ```
6
+ npm install -g @reladraw/studio
7
+ reladraw-studio arch.reladraw
8
+ ```
9
+
10
+ The first run downloads Electron, which the app runs in (about 100 MB, once). It needs Node 20 or later, and runs on macOS and Linux.
11
+
12
+ ## What it opens
13
+
14
+ - **A diagram:** `reladraw-studio arch.reladraw`. It redraws whenever the file changes on disk, so an agent's edits show as they are saved.
15
+ - **A folder:** `reladraw-studio docs/` opens on a tree of the diagrams in it, with the one picked drawn large beside it.
16
+ - **A page of several diagrams:** a `.reladraw-page` spec, or several files at once.
17
+ - **Nothing:** `reladraw-studio` on its own opens a start window, with the files you opened lately and ways to open more or start a new diagram.
18
+
19
+ Everything the page from `reladraw serve` does works here too: editing the source, checking, formatting, versions and exports. Running `reladraw-studio` again while it is open opens the file in the running app, in a new tab. Ctrl-T opens a tab, Ctrl-Shift-N a window (Cmd on macOS).
20
+
21
+ ## Updates
22
+
23
+ Studio follows reladraw: each reladraw release is followed by a studio release that draws with it, so the latest of each work together. Once a day studio asks npm for its latest version number, and nothing else. When a newer studio is out, or the `reladraw` you have installed is older than the one studio draws with, it says so, with the command that updates it.
24
+
25
+ ## License
26
+
27
+ Each version is free to install and use for any purpose, commercial use included, under the license that comes with it; see `LICENSE`. reladraw itself is open source, under the Apache License 2.0.
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
2
+ // Starts the app: runs the Electron binary that the `electron` dependency
3
+ // downloaded at install time, pointed at this package.
4
+ 'use strict';
5
+
6
+ const { spawn } = require('node:child_process');
7
+ const path = require('node:path');
8
+
9
+ /** Where the electron package keeps its download, to name in a message. */
10
+ function electronFolder() {
11
+ try {
12
+ return path.dirname(require.resolve('electron/package.json'));
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+
18
+ let electron;
19
+ try {
20
+ // Required from Node, the electron package returns the path to its binary,
21
+ // downloading it first if this is the first run (about 100 MB, once).
22
+ electron = require('electron');
23
+ } catch {
24
+ // The download tries again on every run, so running again is the fix. The
25
+ // download's own error is printed above this; the electron package's message
26
+ // (delete node_modules/electron) is left out, since nothing needs deleting.
27
+ console.error(
28
+ '\nreladraw-studio: could not download Electron, which the app runs in (about\n' +
29
+ '100 MB, once). This is usually a network blocking the download from GitHub.\n' +
30
+ 'Run reladraw-studio again once the network allows it. Behind a firewall that\n' +
31
+ 'only allows a mirror, set ELECTRON_MIRROR to the mirror first.',
32
+ );
33
+ process.exit(1);
34
+ }
35
+
36
+ const NAME = 'reladraw studio';
37
+
38
+ /**
39
+ * On macOS, the menu bar, the Dock and Cmd-Tab name an app from its bundle's
40
+ * Info.plist, which nothing inside the running app can change. So the app runs
41
+ * from its own copy of Electron's bundle, named for it: a clone (nearly free on
42
+ * APFS) in the user's caches, made once per app and Electron version, and
43
+ * signed ad hoc, as Electron's own bundle already is. If making it fails, the
44
+ * app runs as Electron, which works and is only named wrong.
45
+ */
46
+ function namedForMac(binary) {
47
+ const fs = require('node:fs');
48
+ const os = require('node:os');
49
+ const { execFileSync } = require('node:child_process');
50
+ const quiet = { stdio: 'ignore' };
51
+ try {
52
+ const bundle = path.resolve(binary, '..', '..', '..');
53
+ const icon = path.join(__dirname, '..', 'dist', 'icon.icns');
54
+ const iconStat = fs.existsSync(icon) ? fs.statSync(icon) : null;
55
+ const made =
56
+ `${require('../package.json').version} electron ${require('electron/package.json').version}` +
57
+ (iconStat ? ` icon ${iconStat.size} ${iconStat.mtimeMs}` : '');
58
+ const cache = path.join(os.homedir(), 'Library', 'Caches', 'reladraw-studio');
59
+ const copy = path.join(cache, `${NAME}.app`);
60
+ const stamp = path.join(cache, 'made-from');
61
+ const inCopy = path.join(copy, 'Contents', 'MacOS', path.basename(binary));
62
+ if (fs.existsSync(inCopy) && fs.existsSync(stamp) && fs.readFileSync(stamp, 'utf8') === made) return inCopy;
63
+
64
+ fs.rmSync(copy, { recursive: true, force: true });
65
+ fs.rmSync(stamp, { force: true });
66
+ fs.mkdirSync(cache, { recursive: true });
67
+ try {
68
+ execFileSync('cp', ['-cR', bundle, copy], quiet);
69
+ } catch {
70
+ fs.rmSync(copy, { recursive: true, force: true });
71
+ execFileSync('cp', ['-R', bundle, copy], quiet);
72
+ }
73
+ const plist = path.join(copy, 'Contents', 'Info.plist');
74
+ for (const [key, value] of [
75
+ ['CFBundleName', NAME],
76
+ ['CFBundleDisplayName', NAME],
77
+ ['CFBundleIdentifier', 'dev.reladraw.studio'],
78
+ ]) {
79
+ execFileSync('plutil', ['-replace', key, '-string', value, plist], quiet);
80
+ }
81
+ // Electron's own icon file is overwritten, so the plist's CFBundleIconFile
82
+ // still names it.
83
+ if (iconStat) fs.copyFileSync(icon, path.join(copy, 'Contents', 'Resources', 'electron.icns'));
84
+ execFileSync('codesign', ['--force', '--sign', '-', copy], quiet);
85
+ // The Dock and Finder cache icons by bundle; a fresh date tells them to look again.
86
+ const now = new Date();
87
+ fs.utimesSync(copy, now, now);
88
+ fs.writeFileSync(stamp, made);
89
+ return inCopy;
90
+ } catch {
91
+ return binary;
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Whether Chromium's sandbox can't start here, which makes Electron abort at
97
+ * launch. On Linux it needs unprivileged user namespaces, which Ubuntu 24.04
98
+ * and later restrict through AppArmor (and some kernels turn off), or else a
99
+ * chrome-sandbox helper owned by root with the setuid bit, which an npm install
100
+ * can't make. With neither, the app runs unsandboxed: its window loads only the
101
+ * app's own page from its own localhost server.
102
+ */
103
+ function sandboxUnavailable(binary) {
104
+ const fs = require('node:fs');
105
+ const read = (file) => {
106
+ try {
107
+ return fs.readFileSync(file, 'utf8').trim();
108
+ } catch {
109
+ return null;
110
+ }
111
+ };
112
+ const restricted =
113
+ read('/proc/sys/kernel/apparmor_restrict_unprivileged_userns') === '1' ||
114
+ read('/proc/sys/kernel/unprivileged_userns_clone') === '0';
115
+ if (!restricted) return false;
116
+ try {
117
+ const helper = fs.statSync(path.join(path.dirname(binary), 'chrome-sandbox'));
118
+ return !(helper.uid === 0 && helper.mode & 0o4000);
119
+ } catch {
120
+ return true;
121
+ }
122
+ }
123
+
124
+ if (process.platform === 'darwin') electron = namedForMac(electron);
125
+ // The Node running this, which the app's Linux menu entry runs this command with.
126
+ const env = { ...process.env, RELADRAW_STUDIO_NODE: process.execPath };
127
+ if (process.platform === 'linux' && sandboxUnavailable(electron)) env.ELECTRON_DISABLE_SANDBOX = '1';
128
+
129
+ const app = path.join(__dirname, '..');
130
+ const child = spawn(electron, [app, ...process.argv.slice(2)], { stdio: 'inherit', env });
131
+ // Electron's binary there but unable to run: most often a download cut off
132
+ // partway, which the electron package doesn't notice. Deleting its download
133
+ // makes the next run fetch it whole.
134
+ // A binary cut off partway may fail to start, or start and crash at once.
135
+ function brokenDownload(what) {
136
+ const folder = electronFolder();
137
+ console.error(
138
+ `reladraw-studio: ${what}\n` +
139
+ 'Its download may be incomplete. ' +
140
+ (folder
141
+ ? `Delete this folder, then run reladraw-studio again to download it afresh:\n\n ${path.join(folder, 'dist')}\n`
142
+ : 'Reinstall with npm install -g @reladraw/studio, then run reladraw-studio again.\n'),
143
+ );
144
+ }
145
+ const started = Date.now();
146
+ child.on('error', (err) => {
147
+ brokenDownload(`could not start Electron, which the app runs in (${err.code || err.message}).`);
148
+ process.exit(1);
149
+ });
150
+ // A stop sent to this command goes to the app, which quits as from its own menu,
151
+ // saving where its window was; this command ends when the app has.
152
+ for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => child.kill(signal));
153
+ child.on('close', (code, signal) => {
154
+ const crash = ['SIGSEGV', 'SIGBUS', 'SIGILL', 'SIGABRT'].includes(signal);
155
+ if (crash && Date.now() - started < 5000) brokenDownload(`Electron, which the app runs in, crashed as it started (${signal}).`);
156
+ if (signal) process.exit(128 + (require('node:os').constants.signals[signal] ?? 0));
157
+ else process.exit(code ?? 0);
158
+ });
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/ask/preload.ts
17
+ var preload_exports = {};
18
+ module.exports = __toCommonJS(preload_exports);
19
+ var import_electron = require("electron");
20
+ import_electron.contextBridge.exposeInMainWorld("reladrawAsk", {
21
+ onQuestion: (draw) => import_electron.ipcRenderer.on("ask:question", (_event, question) => draw(question)),
22
+ answer: (choice) => import_electron.ipcRenderer.send("ask:answer", choice)
23
+ });
package/dist/ask.html ADDED
@@ -0,0 +1,81 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'">
6
+ <title>question</title>
7
+ <style>
8
+ /* A card over the dimmed window, asking about edits that aren't saved. */
9
+ :root {
10
+ --card: #1a1c22; --line: #3a3e48; --text: #d8dae0; --strong: #eeeff2; --dim: #8a8f9c; --button: #24262d;
11
+ --accent: #7aa2f7; --accent-fill: #3d5fae; --red: #b84a4a; --red-text: #f0a0a0; --red-fill: #2a1616;
12
+ }
13
+ @media (prefers-color-scheme: light) {
14
+ :root {
15
+ --card: #ffffff; --line: #c8ccd4; --text: #1d2026; --strong: #111318; --dim: #6a707c; --button: #f4f5f7;
16
+ --accent: #3864d6; --accent-fill: #3864d6; --red: #c43c3c; --red-text: #b02a2a; --red-fill: #fdf0f0;
17
+ }
18
+ }
19
+ * { box-sizing: border-box; }
20
+ html, body { height: 100%; margin: 0; }
21
+ body { background: rgba(0, 0, 0, 0.55); font: 14px/1.45 system-ui, sans-serif; display: flex; align-items: center; justify-content: center; }
22
+ .card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; width: min(420px, calc(100% - 32px)); padding: 18px 20px 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6); color: var(--text); }
23
+ h1 { font-size: 15px; font-weight: 600; color: var(--strong); margin: 0 0 4px; overflow-wrap: anywhere; }
24
+ p { margin: 0 0 16px; color: var(--dim); font-size: 13px; }
25
+ ul { margin: -8px 0 16px; padding-left: 18px; color: var(--text); font-size: 13px; }
26
+ ul:empty { display: none; }
27
+ .buttons { display: flex; gap: 8px; }
28
+ .buttons .gap { flex: 1; }
29
+ button { font: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 7px; padding: 5px 12px; color: var(--text); background: var(--button); cursor: pointer; }
30
+ button kbd { font: 11px system-ui; margin-left: 6px; opacity: 0.7; }
31
+ button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
32
+ /* Losing the edits warns without being the brightest thing on the card; Save, which Enter presses, is. */
33
+ #discard { border-color: var(--red); color: var(--red-text); background: var(--red-fill); }
34
+ #save { border-color: var(--accent); background: var(--accent-fill); color: #fff; }
35
+ </style>
36
+ </head>
37
+ <body>
38
+ <div class="card" role="alertdialog" aria-labelledby="title" aria-describedby="detail">
39
+ <h1 id="title"></h1>
40
+ <p id="detail"></p>
41
+ <ul id="files"></ul>
42
+ <div class="buttons">
43
+ <button id="discard" type="button">Don’t save</button>
44
+ <span class="gap"></span>
45
+ <button id="cancel" type="button">Cancel<kbd>Esc</kbd></button>
46
+ <button id="save" type="button">Save<kbd>Enter</kbd></button>
47
+ </div>
48
+ </div>
49
+ <script>
50
+ const ask = window.reladrawAsk;
51
+ let answered = false;
52
+ const answer = (choice) => {
53
+ if (answered) return;
54
+ answered = true;
55
+ ask.answer(choice);
56
+ };
57
+ ask.onQuestion((question) => {
58
+ document.getElementById('title').textContent = question.title;
59
+ document.getElementById('detail').textContent = question.detail;
60
+ const files = document.getElementById('files');
61
+ files.replaceChildren(...question.files.map((name) => Object.assign(document.createElement('li'), { textContent: name })));
62
+ document.getElementById('save').focus();
63
+ });
64
+ document.getElementById('discard').addEventListener('click', () => answer('discard'));
65
+ document.getElementById('cancel').addEventListener('click', () => answer('cancel'));
66
+ document.getElementById('save').addEventListener('click', () => answer('save'));
67
+ // A click on the dimmed window outside the card is Cancel.
68
+ document.body.addEventListener('mousedown', (event) => { if (event.target === document.body) answer('cancel'); });
69
+ document.addEventListener('keydown', (event) => {
70
+ if (event.key === 'Escape') { event.preventDefault(); answer('cancel'); }
71
+ // Enter presses the focused button, Save unless Tab has moved on.
72
+ else if (event.key === 'Enter') {
73
+ event.preventDefault();
74
+ const focused = document.activeElement;
75
+ if (focused && focused.tagName === 'BUTTON') focused.click();
76
+ else answer('save');
77
+ }
78
+ });
79
+ </script>
80
+ </body>
81
+ </html>
package/dist/icon.icns ADDED
Binary file
package/dist/icon.png ADDED
Binary file