twiddle-panel 0.8.1 → 0.9.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/README.md +7 -7
- package/bin/init.js +15 -7
- package/dist/twiddle.js +154 -95
- package/dist/twiddle.mjs +1275 -1097
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Panel used to be published as `@theoldpixel/twiddle`; that package is deprecated
|
|
|
18
18
|
npx twiddle-panel init
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
It shows the line to add and where (your entry file, or `index.html` for plain pages), and changes nothing. Add `--write` to add it
|
|
21
|
+
It shows the line to add and where (your entry file, or `index.html` for plain pages), and changes nothing. Add `--write` to add it. With a build tool it loads the panel only while developing (the tokens always); add `--always` to keep it in production builds too, for example on shared preview links. For Next.js it prints a small client component to use instead.
|
|
22
22
|
|
|
23
23
|
**Projects with a build tool (Vite, Next.js…)**
|
|
24
24
|
|
|
@@ -43,7 +43,7 @@ if (import.meta.env.DEV) import('twiddle-panel');
|
|
|
43
43
|
**Plain HTML prototypes** (no install needed)
|
|
44
44
|
|
|
45
45
|
```html
|
|
46
|
-
<script src="https://cdn.jsdelivr.net/npm/twiddle-panel@0.
|
|
46
|
+
<script src="https://cdn.jsdelivr.net/npm/twiddle-panel@0.9.0/dist/twiddle.js" defer></script>
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
The prototype's CSS must use the `--twd-*` token variables
|
|
@@ -63,13 +63,13 @@ that use them can be re-pointed in **Spacing › Layout roles**.
|
|
|
63
63
|
|
|
64
64
|
Open it with the Panel button in the bottom-right corner, or Alt+T (Option+T on a Mac). The panel opens to the left of the button.
|
|
65
65
|
|
|
66
|
-
- **Tabs** along the
|
|
67
|
-
- **Pick** (
|
|
66
|
+
- **Tabs** along the top: **Overview** (the **Character** pad: up/down for spacing, Subtle ↔ Bold for weights, borders, corners and shadows; plus a summary of the current look), **Colour** (four themes, then fine-tune with the Tailwind palette: a colour family and shade for the primary, a grey family for the neutrals, or any custom hex; Light/Dark), **Type** (font pairings as tiles, base size, scale), **Spacing** (density, layout roles), **Shape** (button style, corners and size; card style, corners, fill and borders) and **Shadows**. Tabs stay in step: when the Character pad changes something another tab owns (corners, borders, shadows, weights), that tab shows the real value and says "from Character". Each tab ends with its tokens as rows you can set to a fixed value; an edited token shows **Custom** and its own reset. One row along the bottom holds every action (Undo, Redo, Pick, Compare, Copy link, Reset, Changes, Copy prompt); the Panel button opens and closes the panel. **Copy link** shares the exact version (`?twd=…`).
|
|
67
|
+
- **Pick** (arrow) starts selection mode: click an element and every tab now changes just that element (Character pad included), until you press **Pick** again. Choose **This element** or **All `.class` (n)** to set where the tweaks go. Add `data-twd="name"` to an element to control what counts as "all like this".
|
|
68
68
|
- **Compare** (half circle): hold it, or press Alt+C, to see the original page.
|
|
69
|
-
- **Minimise** (
|
|
69
|
+
- **Minimise** (the chevron at the end of the tabs) shrinks the panel to just its tabs, beside the Panel button; click a tab or the chevron to open it again.
|
|
70
70
|
- **Move it**: drag the Panel button to any spot; it attaches to the nearest corner, keeps its distance from the edges, and the panel opens on the side away from the edge. With the button focused, arrow keys nudge it 1px (Shift: 10px). Double-click it to put it back bottom-right. Remembered for the site in this browser.
|
|
71
|
-
- **Undo / Redo** in the
|
|
72
|
-
- **Changes**
|
|
71
|
+
- **Undo / Redo** in the bottom row, or ⌘Z / ⇧⌘Z while the panel has focus. Reset can be undone too.
|
|
72
|
+
- **Changes** (the number in a circle, bottom row) opens a side panel next to the main one, listing every tweak with the token values before and after. Use × on a row to remove it.
|
|
73
73
|
- **Copy prompt** turns the tweaks into a Markdown prompt for a coding agent, so they become permanent in the source. Use the arrow next to it to choose between *Preview before copying* and *Copy without preview*.
|
|
74
74
|
- Colour pairs that fall below WCAG AA show a warning in Colour, in Changes and in the prompt.
|
|
75
75
|
|
package/bin/init.js
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
npx twiddle-panel init show what to add, and where
|
|
9
9
|
npx twiddle-panel init --write add it
|
|
10
|
-
npx twiddle-panel init --
|
|
11
|
-
|
|
10
|
+
npx twiddle-panel init --always build tools: load the panel in every
|
|
11
|
+
build, e.g. for shared preview links
|
|
12
|
+
(default: development only, tokens
|
|
13
|
+
always)
|
|
12
14
|
npx twiddle-panel init --file <path> use this entry / HTML file
|
|
13
15
|
--------------------------------------------------------- */
|
|
14
16
|
|
|
@@ -20,7 +22,6 @@ const NAME = pkgSelf.name;
|
|
|
20
22
|
const VERSION = pkgSelf.version;
|
|
21
23
|
const SCRIPT_TAG = `<script src="https://cdn.jsdelivr.net/npm/${NAME}@${VERSION}/dist/twiddle.js" defer></script>`;
|
|
22
24
|
const IMPORT = `import '${NAME}';`;
|
|
23
|
-
const IMPORT_DEV = `import '${NAME}/tokens.css';\nif (import.meta.env.DEV) import('${NAME}');`;
|
|
24
25
|
const DOCS = 'https://panel.twiddle.in';
|
|
25
26
|
|
|
26
27
|
const args = process.argv.slice(2);
|
|
@@ -34,13 +35,17 @@ const say = (s = '') => process.stdout.write(`${s}\n`);
|
|
|
34
35
|
const indent = (s) => s.split('\n').map((l) => ` ${l}`).join('\n');
|
|
35
36
|
|
|
36
37
|
if (cmd !== 'init') {
|
|
37
|
-
say(`Panel by Twiddle ${VERSION}\n\nUsage:\n npx ${NAME} init show the line to add, and where\n npx ${NAME} init --write add it\n npx ${NAME} init --
|
|
38
|
+
say(`Panel by Twiddle ${VERSION}\n\nUsage:\n npx ${NAME} init show the line to add, and where\n npx ${NAME} init --write add it\n npx ${NAME} init --always load the panel in every build (shared previews)\n npx ${NAME} init --file <path> use this entry or HTML file\n\nGuide: ${DOCS}`);
|
|
38
39
|
process.exit(cmd && !['help', '--help', '-h'].includes(cmd) ? 1 : 0);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const readJSON = (p) => { try { return JSON.parse(readFileSync(p, 'utf8')); } catch (e) { return null; } };
|
|
42
43
|
const pkg = readJSON(join(cwd, 'package.json'));
|
|
43
44
|
const deps = pkg ? { ...pkg.dependencies, ...pkg.devDependencies } : {};
|
|
45
|
+
// Development only (the default for build tools). import.meta.env.DEV exists only
|
|
46
|
+
// in Vite; other bundlers (webpack, Create React App…) replace process.env.NODE_ENV.
|
|
47
|
+
const devCheck = deps.vite ? 'import.meta.env.DEV' : "process.env.NODE_ENV !== 'production'";
|
|
48
|
+
const IMPORT_DEV = `import '${NAME}/tokens.css';\nif (${devCheck}) import('${NAME}');`;
|
|
44
49
|
const first = (list) => list.map((p) => join(cwd, p)).find((p) => existsSync(p)) || null;
|
|
45
50
|
|
|
46
51
|
/** The JS file a Vite-style index.html loads (<script type="module" src="/src/main.ts">). */
|
|
@@ -81,13 +86,14 @@ if (plan.kind === 'next') {
|
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
if (plan.kind === 'unknown') {
|
|
84
|
-
say(`Couldn't find an entry file or index.html here.\n\nWith a build tool, add this to your app's entry file:\n${indent(
|
|
89
|
+
say(`Couldn't find an entry file or index.html here.\n\nWith a build tool, add this to your app's entry file (the panel loads only while developing):\n${indent(IMPORT_DEV)}\n (In a Vite project, use: if (import.meta.env.DEV) import('${NAME}');)\n\nIn a plain HTML page, add this inside <head>:\n${indent(SCRIPT_TAG)}\n\nOr point at a file: npx ${NAME} init --file <path>\nGuide: ${DOCS}`);
|
|
85
90
|
process.exit(1);
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
// ---- Show, then (with --write) add ----
|
|
89
94
|
const src = readFileSync(plan.file, 'utf8');
|
|
90
|
-
|
|
95
|
+
// --dev-only (0.8.0/0.8.1) is now the default and still accepted.
|
|
96
|
+
const lines = plan.kind === 'html' ? SCRIPT_TAG : (flag('--always') ? IMPORT : IMPORT_DEV);
|
|
91
97
|
const where = plan.kind === 'html' ? `inside <head> of ${rel(plan.file)}` : `at the top of ${rel(plan.file)}`;
|
|
92
98
|
|
|
93
99
|
if (src.includes(NAME) || src.includes('twiddle.js')) {
|
|
@@ -98,7 +104,8 @@ if (src.includes(NAME) || src.includes('twiddle.js')) {
|
|
|
98
104
|
if (!flag('--write')) {
|
|
99
105
|
say(`Add this ${where}:\n\n${indent(lines)}\n`);
|
|
100
106
|
if (plan.kind === 'build' && !deps[NAME]) say(`Install first:\n npm install -D ${NAME}\n`);
|
|
101
|
-
|
|
107
|
+
if (plan.kind === 'build') say(flag('--always') ? 'This loads the panel in every build, including production.\n' : 'This loads the panel only while developing (the tokens always). Add --always to keep it in production builds too, e.g. for shared preview links.\n');
|
|
108
|
+
say(`Run again with --write to add it for you.\nGuide: ${DOCS}`);
|
|
102
109
|
process.exit(0);
|
|
103
110
|
}
|
|
104
111
|
|
|
@@ -114,5 +121,6 @@ if (plan.kind === 'html') {
|
|
|
114
121
|
}
|
|
115
122
|
writeFileSync(plan.file, out);
|
|
116
123
|
say(`Added Panel ${where}.`);
|
|
124
|
+
if (plan.kind === 'build' && !flag('--always')) say('It loads only while developing. For shared preview links, use --always instead.');
|
|
117
125
|
if (plan.kind === 'build' && !deps[NAME]) say(`\nNow install it:\n npm install -D ${NAME}`);
|
|
118
126
|
say(`\nYour CSS needs the --twd-* tokens for the panel to change anything. Guide and agent prompt: ${DOCS}`);
|