kei-lisp-plugin-graphics 1.0.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 +21 -0
- package/README.md +106 -0
- package/dist/index.cjs +1088 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +1086 -0
- package/dist/index.js.map +1 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keisuke Ikeda
|
|
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,106 @@
|
|
|
1
|
+
# kei-lisp-plugin-graphics
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/kei-lisp-plugin-graphics)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
|
|
7
|
+
A Canvas2D drawing plugin for the [kei-lisp](https://github.com/ike-keichan/kei-lisp)
|
|
8
|
+
interpreter. Register it on a `LispInterpreter` and call drawing primitives
|
|
9
|
+
(`gopen`, `gline-to`, `gfill-rect`, ...) directly from Lisp source.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add kei-lisp-plugin-graphics kei-lisp
|
|
15
|
+
# or: npm install kei-lisp-plugin-graphics kei-lisp
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`kei-lisp` is a **peer dependency**; install both into your project. Requires
|
|
19
|
+
**Node.js >= 24** for the build toolchain (the plugin itself targets any
|
|
20
|
+
environment that exposes a `CanvasRenderingContext2D`).
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { LispInterpreter } from 'kei-lisp';
|
|
26
|
+
import { createGraphicsPlugin } from 'kei-lisp-plugin-graphics';
|
|
27
|
+
|
|
28
|
+
const canvas = document.querySelector<HTMLCanvasElement>('#stage')!;
|
|
29
|
+
|
|
30
|
+
const interpreter = new LispInterpreter();
|
|
31
|
+
interpreter.use(createGraphicsPlugin({ canvas }));
|
|
32
|
+
|
|
33
|
+
interpreter.evalString(`
|
|
34
|
+
(gopen)
|
|
35
|
+
(gfill-color "tomato")
|
|
36
|
+
(gfill-rect 10 10 120 80)
|
|
37
|
+
(gstroke-color "black")
|
|
38
|
+
(gline-width 2)
|
|
39
|
+
(gstroke-rect 10 10 120 80)
|
|
40
|
+
(gclose)
|
|
41
|
+
`);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`HTMLCanvasElement` and `OffscreenCanvas` are both accepted.
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import type { KeiLispPlugin } from 'kei-lisp';
|
|
50
|
+
|
|
51
|
+
export function createGraphicsPlugin(options: {
|
|
52
|
+
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
53
|
+
}): KeiLispPlugin;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The returned plugin implements the [`KeiLispPlugin`](https://github.com/ike-keichan/kei-lisp/blob/main/docs/plugins.md)
|
|
57
|
+
interface and registers a fixed set of `g…` symbols that proxy to the
|
|
58
|
+
canvas's 2D rendering context.
|
|
59
|
+
|
|
60
|
+
## Provided Lisp functions
|
|
61
|
+
|
|
62
|
+
| Category | Symbols |
|
|
63
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
64
|
+
| Lifecycle | `gopen`, `gclose`, `gclear`, `gsleep` |
|
|
65
|
+
| Path | `gstart-path`, `gfinish-path`, `gmove-to`, `gline-to`, `gquadcurve-to`, `gbezcurve-to`, `garc`, `garc-to`, `grect` |
|
|
66
|
+
| Fill / stroke | `gfill`, `gstroke`, `gfill-rect`, `gstroke-rect`, `gfill-tri`, `gstroke-tri`, `gfill-text`, `gstroke-text` |
|
|
67
|
+
| Style | `gcolor`, `gfill-color`, `gstroke-color`, `gline-width`, `gline-cap`, `gline-join`, `galpha`, `gpattern` |
|
|
68
|
+
| Shadow | `gshadow-color`, `gshadow-blur`, `gshadow-offsetx`, `gshadow-offsety` |
|
|
69
|
+
| Text | `gtext-font`, `gtext-align`, `gtext-line`, `gtext-dire` |
|
|
70
|
+
| Transform | `gtranslate`, `gscale`, `grotate` |
|
|
71
|
+
| Image / export | `gimage`, `gsave-png`, `gsave-jpeg` |
|
|
72
|
+
|
|
73
|
+
Each function returns `t` on success. See [`docs/graphics.md`](./docs/graphics.md)
|
|
74
|
+
for argument signatures and side effects.
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
- [API Reference](./docs/api.md) — TypeScript / JavaScript API
|
|
79
|
+
- [Graphics Reference](./docs/graphics.md) — every `g…` Lisp function
|
|
80
|
+
- [kei-lisp Plugin Guide](https://github.com/ike-keichan/kei-lisp/blob/main/docs/plugins.md) — how plugins integrate with the interpreter
|
|
81
|
+
|
|
82
|
+
## Development
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
git clone https://github.com/ike-keichan/kei-lisp-plugin-graphics.git
|
|
86
|
+
cd kei-lisp-plugin-graphics
|
|
87
|
+
pnpm install
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Requires [pnpm](https://pnpm.io/) and Node.js 24+
|
|
91
|
+
(see [`.node-version`](./.node-version) for the exact version).
|
|
92
|
+
|
|
93
|
+
| Command | Description |
|
|
94
|
+
| ----------------- | ------------------------------------------ |
|
|
95
|
+
| `pnpm build` | Build for distribution (CJS + ESM + types) |
|
|
96
|
+
| `pnpm test` | Run tests |
|
|
97
|
+
| `pnpm test:watch` | Run tests in watch mode |
|
|
98
|
+
| `pnpm typecheck` | Type check (`tsc --noEmit`) |
|
|
99
|
+
| `pnpm check` | Run all checks (format, lint, spell, ...) |
|
|
100
|
+
| `pnpm fix` | Auto-fix format and lint issues |
|
|
101
|
+
|
|
102
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for the branch policy and PR flow.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
[MIT](./LICENSE)
|