kei-lisp-plugin-graphics 1.0.1 → 2.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/dist/index.d.ts CHANGED
@@ -5,17 +5,23 @@ import { Cons, InterpretedSymbol, KeiLispPlugin, LispValue, PluginContext } from
5
5
  * @class
6
6
  * @classdesc Canvas2D drawing plugin for the kei-lisp interpreter. Implements
7
7
  * the `KeiLispPlugin` contract (`name` / `has` / `apply`) and
8
- * exposes 43 `g…` Lisp functions that proxy to a 2D rendering
8
+ * exposes 45 `g…` Lisp functions that proxy to a 2D rendering
9
9
  * context.
10
10
  * @author Keisuke Ikeda
11
11
  * @this {GraphicsPlugin}
12
12
  */
13
13
  declare class GraphicsPlugin extends Object implements KeiLispPlugin {
14
+ #private;
14
15
  /**
15
16
  * Dispatch map from a Lisp function name (InterpretedSymbol) to the name of
16
17
  * the GraphicsPlugin method that implements it.
17
18
  */
18
19
  static readonly buildInFunctions: Map<InterpretedSymbol, string>;
20
+ /**
21
+ * Builds the dispatch table.
22
+ * @return the dispatch table
23
+ */
24
+ static setup(): Map<InterpretedSymbol, string>;
19
25
  /**
20
26
  * Plugin identifier, used for diagnostics.
21
27
  */
@@ -38,18 +44,18 @@ declare class GraphicsPlugin extends Object implements KeiLispPlugin {
38
44
  /**
39
45
  * Dispatches the given symbol to the matching `g…` method.
40
46
  * @param aSymbol - the call symbol
41
- * @param args - the evaluated argument list
42
- * @param _ctx - the interpreter context (unused by this plugin)
47
+ * @param arguments_ - the evaluated argument list
48
+ * @param _context - the interpreter context (unused by this plugin)
43
49
  * @return the method's result, or `Cons.nil` if dispatch fails
44
50
  */
45
- apply(aSymbol: InterpretedSymbol, args: Cons, _ctx: PluginContext): LispValue;
51
+ apply(aSymbol: InterpretedSymbol, arguments_: Cons, _context: PluginContext): LispValue;
46
52
  /**
47
53
  * Resolves the procedure name and invokes the matching method.
48
54
  * @param procedure - the Lisp symbol
49
- * @param args - the evaluated argument list
55
+ * @param arguments_ - the evaluated argument list
50
56
  * @return the method's result, or `Cons.nil` if not registered
51
57
  */
52
- selectProcedure(procedure: InterpretedSymbol, args: Cons): LispValue;
58
+ selectProcedure(procedure: InterpretedSymbol, arguments_: Cons): LispValue;
53
59
  /**
54
60
  * Looks up and invokes the JS method that implements the given Lisp symbol.
55
61
  * Throws `TypeError` when the dispatch table points to a method that does
@@ -57,10 +63,10 @@ declare class GraphicsPlugin extends Object implements KeiLispPlugin {
57
63
  * Ramda `R.invoker(1, methodName)(args, this)` call would surface the same
58
64
  * error by attempting to call `undefined`.
59
65
  * @param procedure - the Lisp symbol
60
- * @param args - the evaluated argument list
66
+ * @param arguments_ - the evaluated argument list
61
67
  * @return the method's result
62
68
  */
63
- buildInFunction(procedure: InterpretedSymbol, args: Cons): LispValue;
69
+ buildInFunction(procedure: InterpretedSymbol, arguments_: Cons): LispValue;
64
70
  /**
65
71
  * Checks whether the canvas exposes a usable 2D context, and narrows
66
72
  * `this.ctx` to non-null for the caller when it returns true.
@@ -69,72 +75,82 @@ declare class GraphicsPlugin extends Object implements KeiLispPlugin {
69
75
  checkSupport(): this is GraphicsPlugin & {
70
76
  ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
71
77
  };
72
- /**
73
- * Writes a diagnostic line directly to `process.stderr`, matching the
74
- * convention used by kei-lisp itself (`Applier.format` writes to
75
- * `process.stdout`). In a Node runtime this hits the real stderr; in a
76
- * browser kei-lisp host (e.g. kei-lisp-web) the host typically swaps
77
- * `process.stderr.write` for a sink that routes to the REPL output panel,
78
- * so the same call reaches the user via the host's normal output channel.
79
- * @param line - the line to write
80
- */
81
- _print(line: string): void;
82
- gAlpha(args: Cons): LispValue;
83
- gArc(args: Cons): LispValue;
84
- gArcTo(args: Cons): LispValue;
85
- gBezCurveTo(args: Cons): LispValue;
78
+ gAlpha(arguments_: Cons): LispValue;
79
+ gArc(arguments_: Cons): LispValue;
80
+ gArcTo(arguments_: Cons): LispValue;
81
+ gBezCurveTo(arguments_: Cons): LispValue;
86
82
  gClear(): LispValue;
87
83
  gClose(): LispValue;
88
- gColor(args: Cons): LispValue;
84
+ gColor(arguments_: Cons): LispValue;
89
85
  gFill(): LispValue;
90
- gFillColor(args: Cons): LispValue;
91
- gFillRect(args: Cons): LispValue;
92
- gFillText(args: Cons): LispValue;
93
- gFillTri(args: Cons): LispValue;
86
+ gFillColor(arguments_: Cons): LispValue;
87
+ gFillRect(arguments_: Cons): LispValue;
88
+ gFillText(arguments_: Cons): LispValue;
89
+ gFillTri(arguments_: Cons): LispValue;
94
90
  gFinishPath(): LispValue;
95
- gImage(args: Cons): LispValue;
96
- gLineTo(args: Cons): LispValue;
97
- gLineCap(args: Cons): LispValue;
98
- gLineJoin(args: Cons): LispValue;
99
- gLineWidth(args: Cons): LispValue;
100
- gMoveTo(args: Cons): LispValue;
91
+ gImage(arguments_: Cons): LispValue;
92
+ gLineTo(arguments_: Cons): LispValue;
93
+ gLineCap(arguments_: Cons): LispValue;
94
+ gLineJoin(arguments_: Cons): LispValue;
95
+ gLineWidth(arguments_: Cons): LispValue;
96
+ gMoveTo(arguments_: Cons): LispValue;
101
97
  gOpen(): LispValue;
102
- gPattern(args: Cons): LispValue;
103
- gQuadCurveTo(args: Cons): LispValue;
104
- gSaveJpeg(): LispValue;
105
- gSavePng(): LispValue;
106
- gScale(args: Cons): LispValue;
107
- gShadowBlur(args: Cons): LispValue;
108
- gShadowColor(args: Cons): LispValue;
109
- gShadowOffsetX(args: Cons): LispValue;
110
- gShadowOffsetY(args: Cons): LispValue;
111
- gSleep(args: Cons): LispValue;
98
+ gPattern(arguments_: Cons): LispValue;
99
+ gQuadCurveTo(arguments_: Cons): LispValue;
100
+ gSaveJpeg(arguments_: Cons): LispValue;
101
+ gSavePng(arguments_: Cons): LispValue;
102
+ /**
103
+ * Shared implementation of `gsave-jpeg` / `gsave-png`. With no argument it
104
+ * triggers a browser download; with a single string argument it writes the
105
+ * encoded image to that file path on Node.js.
106
+ * @param arguments_ - the evaluated argument list (empty, or one path string)
107
+ * @param mimeType - the image MIME type to encode
108
+ * @param label - the format name used in diagnostics ("jpeg" / "png")
109
+ * @return `t` on success, `Cons.nil` otherwise
110
+ */
111
+ saveCanvas(arguments_: Cons, mimeType: string, label: string): LispValue;
112
+ gScale(arguments_: Cons): LispValue;
113
+ gShadowBlur(arguments_: Cons): LispValue;
114
+ gShadowColor(arguments_: Cons): LispValue;
115
+ gShadowOffsetX(arguments_: Cons): LispValue;
116
+ gShadowOffsetY(arguments_: Cons): LispValue;
117
+ gSleep(arguments_: Cons): LispValue;
112
118
  gStartPath(): LispValue;
113
119
  gStroke(): LispValue;
114
- gStrokeColor(args: Cons): LispValue;
115
- gStrokeRect(args: Cons): LispValue;
116
- gStrokeText(args: Cons): LispValue;
117
- gStrokeTri(args: Cons): LispValue;
118
- gTextAlign(args: Cons): LispValue;
119
- gTextBaseline(args: Cons): LispValue;
120
- gTextDirection(args: Cons): LispValue;
121
- gTextFont(args: Cons): LispValue;
122
- gTranslate(args: Cons): LispValue;
123
- gRect(args: Cons): LispValue;
124
- gRotate(args: Cons): LispValue;
120
+ gStrokeColor(arguments_: Cons): LispValue;
121
+ gStrokeRect(arguments_: Cons): LispValue;
122
+ gStrokeText(arguments_: Cons): LispValue;
123
+ gStrokeTri(arguments_: Cons): LispValue;
124
+ gTextAlign(arguments_: Cons): LispValue;
125
+ gTextBaseline(arguments_: Cons): LispValue;
126
+ gTextDirection(arguments_: Cons): LispValue;
127
+ gTextFont(arguments_: Cons): LispValue;
128
+ gTranslate(arguments_: Cons): LispValue;
129
+ gRect(arguments_: Cons): LispValue;
130
+ gRotate(arguments_: Cons): LispValue;
131
+ /**
132
+ * Pushes the current drawing state (styles, transform, clip) onto the
133
+ * context's state stack. Pairs with `gRestore` to let Lisp callers manage
134
+ * state explicitly. Replaces the legacy per-method `ctx.save()` calls, which
135
+ * pushed state on every draw with no matching `restore()` and grew the stack
136
+ * unbounded.
137
+ * @return `t` on success, `Cons.nil` otherwise
138
+ */
139
+ gSave(): LispValue;
140
+ /**
141
+ * Pops the most recently saved drawing state off the context's state stack.
142
+ * Pairs with `gSave`. Popping an empty stack is a no-op per the Canvas spec.
143
+ * @return `t` on success, `Cons.nil` otherwise
144
+ */
145
+ gRestore(): LispValue;
125
146
  /**
126
147
  * Parses a color spec from the head of the argument Cons. Accepts
127
148
  * (1 string), (3 numbers — rgb), or (4 numbers — rgba); falls back to
128
149
  * `'black'` on anything else (legacy behavior).
129
- * @param args - the argument Cons to parse
150
+ * @param arguments_ - the argument Cons to parse
130
151
  * @return CSS color string
131
152
  */
132
- selectColor(args: Cons): string;
133
- /**
134
- * Builds the dispatch table.
135
- * @return the dispatch table
136
- */
137
- static setup(): Map<InterpretedSymbol, string>;
153
+ selectColor(arguments_: Cons): string;
138
154
  }
139
155
  //#endregion
140
156
  //#region src/index.d.ts