gum-jsx 1.5.0 → 1.5.1

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 CHANGED
@@ -1,23 +1,25 @@
1
1
  <div align="center">
2
- <img src="image/logo.png" alt="logo" width="500" />
2
+ <img src="images/logo.svg" alt="logo" width="500" />
3
3
  <br/>
4
4
  </div>
5
5
 
6
6
  <div align="center">
7
- <img src="image/nexus.svg" alt="nexus" width="250" />
7
+ <img src="images/nexus.svg" alt="nexus" width="250" />
8
8
  <br/><br/>
9
9
  </div>
10
10
 
11
- A language for creating visualizations using a React-like JSX dialect that evaluates to SVG. Designed for general graphics, plots, graphs, and network diagrams.
11
+ Gum is a JSX language for creating visualizations that evaluates to SVG. It's designed for general graphics, plots, graphs, and network diagrams.
12
12
 
13
13
  Head to **[compendiumlabs.ai/gum](https://compendiumlabs.ai/gum)** for a live demo and documentation. For Python bindings, see [gum.py](https://github.com/CompendiumLabs/gum.py).
14
14
 
15
15
  # Installation
16
16
 
17
17
  ```bash
18
- bun i gum-jsx
18
+ bun i -g gum-jsx
19
19
  ```
20
20
 
21
+ To download the skill file (which is just a zip), click on the release on the right or use `skills/gum-jsx.skill`.
22
+
21
23
  # Usage
22
24
 
23
25
  Write some `gum.jsx` code:
@@ -38,7 +40,7 @@ const svg = elem.svg()
38
40
 
39
41
  Which will produce the following:
40
42
 
41
- <img src="image/plot.png" alt="sine wave plot" width="750" />
43
+ <img src="images/plot.svg" alt="sine wave plot" width="750" />
42
44
 
43
45
  You can also use JavaScript directly:
44
46
 
@@ -58,25 +60,25 @@ You can use the `gum` command to convert `gum.jsx` into SVG text or PNG data. Yo
58
60
  Generate an SVG from a `gum.jsx` file:
59
61
 
60
62
  ```bash
61
- cat input.jsx | bun run cli -f svg > output.svg
63
+ cat input.jsx | gum -f svg > output.svg
62
64
  ```
63
65
 
64
66
  Generate a PNG from a `gum.jsx` file:
65
67
 
66
68
  ```bash
67
- cat input.jsx | bun run cli -f png > output.png
69
+ cat input.jsx | gum -f png > output.png
68
70
  ```
69
71
 
70
72
  Display a `gum.jsx` file in the terminal:
71
73
  ```bash
72
- cat input.jsx | bun run cli
74
+ cat input.jsx | gum
73
75
  ```
74
76
 
75
77
  CLI options:
76
78
 
77
79
  | Option | Description | Default |
78
80
  |--------|-------------|---------|
79
- | `-s, --size <size>` | Image size in pixels | 500 |
81
+ | `-s, --size <size>` | Image size in pixels | 1000 |
80
82
  | `-t, --theme <theme>` | Theme: `light` or `dark` | light |
81
83
  | `-w, --width <width>` | Width of the PNG | null |
82
84
  | `-h, --height <height>` | Height of the PNG | null |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gum-jsx",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Language for vector graphics generation.",
5
5
  "type": "module",
6
6
  "author": "Douglas Hanley",
package/prompt/gen.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Using CLI commands
2
2
 
3
- To test the output of a particular `gum.jsx` snippet or file, you can pipe it to the `gum` command, which is assumed to be installed globally. If you have vision capabilities, this can be useful for see the actual output of the code, either in SVG or PNG format. Even without vision, one can infer properties of the output by reading the SVG output directly.
3
+ To test the output of a particular Gum JSX snippet or file, you can pipe it to the `gum` command, which is assumed to be installed globally. If you have vision capabilities, this can be useful for see the actual output of the code, either in SVG or PNG format. Even without vision, one can infer properties of the output by reading the SVG output directly.
4
4
 
5
5
  For one off tests, pipe the code using `echo`. It is recommended that you use single quotes as the outer delimiter, to accommodate code that includes double quotes for component properties (e.g. `justify="left"`).
6
6
 
@@ -10,10 +10,10 @@ In general, it makes a lot of sense to write a draft to a file, view its output,
10
10
 
11
11
  **Examples:**
12
12
  ```bash
13
- # Generate SVG from a gum.jsx snippet
13
+ # Generate SVG from a Gum JSX snippet
14
14
  echo '<Rectangle rounded fill={blue} />' | gum -f svg > output.svg
15
15
 
16
- # Generate PNG from a gum.jsx snippet
16
+ # Generate PNG from a Gum JSX snippet
17
17
  echo '<Rectangle rounded fill={blue} />' | gum -f png > output.png
18
18
 
19
19
  # Generate SVG from a .jsx file
@@ -30,7 +30,7 @@ gum test.jsx -o output.png
30
30
  ```
31
31
 
32
32
  **CLI options:**
33
- - `file`: gum.jsx file to render (reads from stdin if not provided)
33
+ - `file`: Gum JSX file to render (reads from stdin if not provided)
34
34
  - `-t, --theme <theme>`: theme to use (default: light)
35
35
  - `-b, --background <color>`: background color (default: white)
36
36
  - `-i, --input <input>`: input format (default: jsx)
@@ -41,9 +41,9 @@ gum test.jsx -o output.png
41
41
  - `-h, --height <height>`: height of the PNG (default: auto)
42
42
  - `-u, --update`: enable live update display
43
43
 
44
- # Using in TypeScript
44
+ # Using Gum in TypeScript
45
45
 
46
- You can use gum.jsx directly in TypeScript/JavaScript code by importing from the `gum-jsx` package. This is useful for programmatic generation, integration into other tools, or when you want to avoid the CLI.
46
+ There are a couple of ways to use Gum in TypeScript. You can evaluate JSX strings directly, or you can construct Gum components directly. If you want to use Gum components in React, you can use the `react-gum-jsx` package.
47
47
 
48
48
  ## Evaluating JSX strings
49
49
 
@@ -77,7 +77,7 @@ const tree = evaluateGum(code, {
77
77
 
78
78
  ## Using components directly
79
79
 
80
- You can also construct components directly by importing them from `gum-jsx` and calling their constructors. Each component takes a single args object.
80
+ You can also construct Gum components directly by importing them from `gum-jsx` and calling their constructors. Each component takes a single args object.
81
81
 
82
82
  ```typescript
83
83
  import { Svg, Rectangle, Circle, HStack, Text, blue, red, white } from 'gum-jsx'
@@ -99,3 +99,38 @@ When constructing manually, note that:
99
99
  - Utility functions like `range`, `linspace`, `zip` are also available from `gum-jsx`
100
100
  - Call `.svg()` on the top-level `Svg` element to get the SVG string output
101
101
  - The realized size of the SVG is available on the `Svg` element as `size`
102
+
103
+ ## Using in React with `react-gum-jsx`
104
+
105
+ You can use Gum components directly in React components by importing from the `react-gum-jsx` package. This is useful for creating interactive visualizations in React.
106
+
107
+ Here's an example of how to use Gum in a React component. It's basically the same as what you would pass to `evaluateGum` but as a default export:
108
+
109
+ ```tsx
110
+ import { blue, red } from 'gum-jsx'
111
+ import { GUM } from 'react-gum-jsx'
112
+ const { Frame, HStack, Square, Circle, Text } = GUM
113
+
114
+ export default function Demo() {
115
+ return <Frame padding margin rounded>
116
+ <HStack padding>
117
+ <Square fill={blue} />
118
+ <Circle fill={red} />
119
+ <Text>Hello</Text>
120
+ </HStack>
121
+ </Frame>
122
+ }
123
+ ```
124
+
125
+ To run this in a CLI setting, just pass a file with a default export to the `gum-react` command that comes with the `react-gum-jsx` package. This takes very similar arguments to the regular `gum` command.
126
+
127
+ If you are in a web setting, you'll need to wrap this export in a `<Gum>` component, which takes roughly the same arguments as `evaluateGum`. This would look like:
128
+
129
+ ```tsx
130
+ import { Gum } from 'react-gum-jsx'
131
+ <Gum size={[640, 360]}>
132
+ <Demo />
133
+ </Gum>
134
+ ```
135
+
136
+ If the inner component has an `aspect` it will be embedded inside the given size bounds. If it is aspectless, it will be stretched to fill the given size bounds.
@@ -401,7 +401,7 @@ There is a gallery of more complex examples available. Each is a single markdown
401
401
 
402
402
  # Using CLI commands
403
403
 
404
- To test the output of a particular `gum.jsx` snippet or file, you can pipe it to the `gum` command, which is assumed to be installed globally. If you have vision capabilities, this can be useful for see the actual output of the code, either in SVG or PNG format. Even without vision, one can infer properties of the output by reading the SVG output directly.
404
+ To test the output of a particular Gum JSX snippet or file, you can pipe it to the `gum` command, which is assumed to be installed globally. If you have vision capabilities, this can be useful for see the actual output of the code, either in SVG or PNG format. Even without vision, one can infer properties of the output by reading the SVG output directly.
405
405
 
406
406
  For one off tests, pipe the code using `echo`. It is recommended that you use single quotes as the outer delimiter, to accommodate code that includes double quotes for component properties (e.g. `justify="left"`).
407
407
 
@@ -411,10 +411,10 @@ In general, it makes a lot of sense to write a draft to a file, view its output,
411
411
 
412
412
  **Examples:**
413
413
  ```bash
414
- # Generate SVG from a gum.jsx snippet
414
+ # Generate SVG from a Gum JSX snippet
415
415
  echo '<Rectangle rounded fill={blue} />' | gum -f svg > output.svg
416
416
 
417
- # Generate PNG from a gum.jsx snippet
417
+ # Generate PNG from a Gum JSX snippet
418
418
  echo '<Rectangle rounded fill={blue} />' | gum -f png > output.png
419
419
 
420
420
  # Generate SVG from a .jsx file
@@ -431,7 +431,7 @@ gum test.jsx -o output.png
431
431
  ```
432
432
 
433
433
  **CLI options:**
434
- - `file`: gum.jsx file to render (reads from stdin if not provided)
434
+ - `file`: Gum JSX file to render (reads from stdin if not provided)
435
435
  - `-t, --theme <theme>`: theme to use (default: light)
436
436
  - `-b, --background <color>`: background color (default: white)
437
437
  - `-i, --input <input>`: input format (default: jsx)
@@ -442,9 +442,9 @@ gum test.jsx -o output.png
442
442
  - `-h, --height <height>`: height of the PNG (default: auto)
443
443
  - `-u, --update`: enable live update display
444
444
 
445
- # Using in TypeScript
445
+ # Using Gum in TypeScript
446
446
 
447
- You can use gum.jsx directly in TypeScript/JavaScript code by importing from the `gum-jsx` package. This is useful for programmatic generation, integration into other tools, or when you want to avoid the CLI.
447
+ There are a couple of ways to use Gum in TypeScript. You can evaluate JSX strings directly, or you can construct Gum components directly. If you want to use Gum components in React, you can use the `react-gum-jsx` package.
448
448
 
449
449
  ## Evaluating JSX strings
450
450
 
@@ -478,7 +478,7 @@ const tree = evaluateGum(code, {
478
478
 
479
479
  ## Using components directly
480
480
 
481
- You can also construct components directly by importing them from `gum-jsx` and calling their constructors. Each component takes a single args object.
481
+ You can also construct Gum components directly by importing them from `gum-jsx` and calling their constructors. Each component takes a single args object.
482
482
 
483
483
  ```typescript
484
484
  import { Svg, Rectangle, Circle, HStack, Text, blue, red, white } from 'gum-jsx'
@@ -500,3 +500,38 @@ When constructing manually, note that:
500
500
  - Utility functions like `range`, `linspace`, `zip` are also available from `gum-jsx`
501
501
  - Call `.svg()` on the top-level `Svg` element to get the SVG string output
502
502
  - The realized size of the SVG is available on the `Svg` element as `size`
503
+
504
+ ## Using in React with `react-gum-jsx`
505
+
506
+ You can use Gum components directly in React components by importing from the `react-gum-jsx` package. This is useful for creating interactive visualizations in React.
507
+
508
+ Here's an example of how to use Gum in a React component. It's basically the same as what you would pass to `evaluateGum` but as a default export:
509
+
510
+ ```tsx
511
+ import { blue, red } from 'gum-jsx'
512
+ import { GUM } from 'react-gum-jsx'
513
+ const { Frame, HStack, Square, Circle, Text } = GUM
514
+
515
+ export default function Demo() {
516
+ return <Frame padding margin rounded>
517
+ <HStack padding>
518
+ <Square fill={blue} />
519
+ <Circle fill={red} />
520
+ <Text>Hello</Text>
521
+ </HStack>
522
+ </Frame>
523
+ }
524
+ ```
525
+
526
+ To run this in a CLI setting, just pass a file with a default export to the `gum-react` command that comes with the `react-gum-jsx` package. This takes very similar arguments to the regular `gum` command.
527
+
528
+ If you are in a web setting, you'll need to wrap this export in a `<Gum>` component, which takes roughly the same arguments as `evaluateGum`. This would look like:
529
+
530
+ ```tsx
531
+ import { Gum } from 'react-gum-jsx'
532
+ <Gum size={[640, 360]}>
533
+ <Demo />
534
+ </Gum>
535
+ ```
536
+
537
+ If the inner component has an `aspect` it will be embedded inside the given size bounds. If it is aspectless, it will be stretched to fill the given size bounds.
package/src/elems/core.ts CHANGED
@@ -245,7 +245,8 @@ function props_repr(d: Attrs, prec: number): string {
245
245
  // reserved keys
246
246
  const SPEC_KEYS = [ 'rect', 'aspect', 'expand', 'align', 'upright', 'rotate', 'rotate_adjust', 'invar', 'coord' ]
247
247
  const HELP_KEYS = [ 'pos', 'size', 'xsize', 'ysize', 'flex', 'spin', 'orient' ]
248
- const RESERVED_KEYS = [ ...SPEC_KEYS, ...HELP_KEYS ]
248
+ const EXTR_KEYS = [ 'stack_size', 'stack_expand' ]
249
+ const RESERVED_KEYS = [ ...SPEC_KEYS, ...HELP_KEYS, ...EXTR_KEYS ]
249
250
 
250
251
  function spec_split(attr: Attrs, extended: boolean = true): [Attrs, Attrs] {
251
252
  const SPLIT_KEYS = extended ? RESERVED_KEYS : SPEC_KEYS
package/src/elems/plot.ts CHANGED
@@ -134,7 +134,7 @@ class Scale extends Group {
134
134
  const ticks = ticks0.map((t: Element) => {
135
135
  const { tick_loc, tick_span } = t.args
136
136
  const rect = join_limits({ [direc]: [tick_loc, tick_loc], [tick_dir]: tick_span })
137
- return t.clone({ rect, expand: true, ...tick_attr })
137
+ return t.clone({ rect, expand: true, tick_loc: undefined, tick_span: undefined, ...tick_attr })
138
138
  })
139
139
 
140
140
  // set coordinate system
@@ -307,7 +307,7 @@ class Axis extends Group {
307
307
  locs: number[]
308
308
 
309
309
  constructor(args: AxisArgs = {}) {
310
- const { children, lim = D.lim, direc = 'h', ticks: ticks0, tick_side = 'inner', label_side = 'outer', label_size = 1.35, label_offset = 0, label_justify: label_justify0, label_loc, discrete = false, prec = D.prec, debug, ...attr0 } = THEME(args, 'Axis')
310
+ const { children, lim = D.lim, direc = 'h', ticks: ticks0, tick_side = 'inner', label_side = 'outer', label_size = 1.5, label_offset = 0, label_justify: label_justify0, label_loc, discrete = false, prec = D.prec, debug, ...attr0 } = THEME(args, 'Axis')
311
311
  const [ label_attr, tick_attr, line_attr, attr ] = prefix_split([ 'label', 'tick', 'line' ], attr0)
312
312
  const tick_lim = get_tick_lim(tick_side)
313
313
  const [ tick_lo, tick_hi ] = tick_lim