hascii 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/Makefile +19 -0
- package/README.md +185 -0
- package/carts/draw.yaml +69 -0
- package/carts/hello.yaml +22 -0
- package/carts/move.yaml +68 -0
- package/carts/pong.yaml +185 -0
- package/carts/rain.yaml +69 -0
- package/carts/snake.yaml +292 -0
- package/carts/tracker.yaml +1838 -0
- package/carts/wave.yaml +56 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +6105 -0
- package/dist/index.d.mts +489 -0
- package/dist/index.mjs +3 -0
- package/dist/run-mrITeQUl.mjs +1750 -0
- package/hascii.schema.json +1023 -0
- package/package.json +39 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { ZodIssue, z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/compiler/ansi.d.ts
|
|
4
|
+
declare const ANSI: Readonly<{
|
|
5
|
+
RESET: "\u001B[0m";
|
|
6
|
+
BOLD: "\u001B[1m";
|
|
7
|
+
DIM: "\u001B[2m";
|
|
8
|
+
RED: "\u001B[31m";
|
|
9
|
+
GREEN: "\u001B[32m";
|
|
10
|
+
YELLOW: "\u001B[33m";
|
|
11
|
+
BLUE: "\u001B[34m";
|
|
12
|
+
MAGENTA: "\u001B[35m";
|
|
13
|
+
CYAN: "\u001B[36m";
|
|
14
|
+
BRIGHT_RED: "\u001B[91m";
|
|
15
|
+
BRIGHT_BLUE: "\u001B[94m";
|
|
16
|
+
}>;
|
|
17
|
+
declare const COLORS: Readonly<{
|
|
18
|
+
error: "\u001B[1m\u001B[91m";
|
|
19
|
+
category: "\u001B[1m\u001B[36m";
|
|
20
|
+
location: "\u001B[94m";
|
|
21
|
+
lineNumber: "\u001B[94m";
|
|
22
|
+
gutter: "\u001B[94m";
|
|
23
|
+
arrow: "\u001B[91m";
|
|
24
|
+
hint: "\u001B[33m";
|
|
25
|
+
help: "\u001B[32m";
|
|
26
|
+
expected: "\u001B[32m";
|
|
27
|
+
received: "\u001B[31m";
|
|
28
|
+
note: "\u001B[36m";
|
|
29
|
+
emphasis: "\u001B[1m\u001B[35m";
|
|
30
|
+
}>;
|
|
31
|
+
declare const BOX: Readonly<{
|
|
32
|
+
TOP: "┌";
|
|
33
|
+
VERT: "│";
|
|
34
|
+
BOTTOM: "└";
|
|
35
|
+
HORIZ: "─";
|
|
36
|
+
CROSS: "┼";
|
|
37
|
+
}>;
|
|
38
|
+
declare function supportsColor(): boolean;
|
|
39
|
+
declare function stripAnsi(text: string): string;
|
|
40
|
+
declare function line(char: string, length: number): string;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/compiler/error-codes.d.ts
|
|
43
|
+
type HasciiErrorCode = {
|
|
44
|
+
readonly code: string;
|
|
45
|
+
readonly title: string;
|
|
46
|
+
readonly hint: string;
|
|
47
|
+
};
|
|
48
|
+
declare const ERROR_CODES: Readonly<{
|
|
49
|
+
E001: HasciiErrorCode;
|
|
50
|
+
E101: HasciiErrorCode;
|
|
51
|
+
E102: HasciiErrorCode;
|
|
52
|
+
E103: HasciiErrorCode;
|
|
53
|
+
E104: HasciiErrorCode;
|
|
54
|
+
E201: HasciiErrorCode;
|
|
55
|
+
E301: HasciiErrorCode;
|
|
56
|
+
E302: HasciiErrorCode;
|
|
57
|
+
E303: HasciiErrorCode;
|
|
58
|
+
E304: HasciiErrorCode;
|
|
59
|
+
E305: HasciiErrorCode;
|
|
60
|
+
E401: HasciiErrorCode;
|
|
61
|
+
}>;
|
|
62
|
+
declare function mapZodCodeToErrorCode(zodCode: string, path: readonly (string | number)[]): HasciiErrorCode;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/core/types.d.ts
|
|
65
|
+
type HasciiValueObject = {
|
|
66
|
+
readonly [key: string]: HasciiValue;
|
|
67
|
+
};
|
|
68
|
+
type HasciiValue = number | string | boolean | readonly HasciiValue[] | HasciiValueObject;
|
|
69
|
+
type HasciiButtonState = {
|
|
70
|
+
readonly left: number;
|
|
71
|
+
readonly right: number;
|
|
72
|
+
readonly up: number;
|
|
73
|
+
readonly down: number;
|
|
74
|
+
readonly a: number;
|
|
75
|
+
readonly b: number;
|
|
76
|
+
};
|
|
77
|
+
type HasciiProgram = {
|
|
78
|
+
readonly init: Record<string, HasciiValue>;
|
|
79
|
+
readonly update: readonly HasciiStatement[];
|
|
80
|
+
readonly draw: readonly HasciiStatement[];
|
|
81
|
+
};
|
|
82
|
+
type HasciiExpression = number | string | {
|
|
83
|
+
readonly add: readonly [HasciiExpression, HasciiExpression];
|
|
84
|
+
} | {
|
|
85
|
+
readonly sub: readonly [HasciiExpression, HasciiExpression];
|
|
86
|
+
} | {
|
|
87
|
+
readonly mul: readonly [HasciiExpression, HasciiExpression];
|
|
88
|
+
} | {
|
|
89
|
+
readonly div: readonly [HasciiExpression, HasciiExpression];
|
|
90
|
+
} | {
|
|
91
|
+
readonly mod: readonly [HasciiExpression, HasciiExpression];
|
|
92
|
+
} | {
|
|
93
|
+
readonly pow: readonly [HasciiExpression, HasciiExpression];
|
|
94
|
+
} | {
|
|
95
|
+
readonly abs: HasciiExpression;
|
|
96
|
+
} | {
|
|
97
|
+
readonly neg: HasciiExpression;
|
|
98
|
+
} | {
|
|
99
|
+
readonly floor: HasciiExpression;
|
|
100
|
+
} | {
|
|
101
|
+
readonly ceil: HasciiExpression;
|
|
102
|
+
} | {
|
|
103
|
+
readonly round: HasciiExpression;
|
|
104
|
+
} | {
|
|
105
|
+
readonly sqrt: HasciiExpression;
|
|
106
|
+
} | {
|
|
107
|
+
readonly sin: HasciiExpression;
|
|
108
|
+
} | {
|
|
109
|
+
readonly cos: HasciiExpression;
|
|
110
|
+
} | {
|
|
111
|
+
readonly min: readonly [HasciiExpression, HasciiExpression];
|
|
112
|
+
} | {
|
|
113
|
+
readonly max: readonly [HasciiExpression, HasciiExpression];
|
|
114
|
+
} | {
|
|
115
|
+
readonly rnd: readonly [HasciiExpression, HasciiExpression];
|
|
116
|
+
} | {
|
|
117
|
+
readonly eq: readonly [HasciiExpression, HasciiExpression];
|
|
118
|
+
} | {
|
|
119
|
+
readonly lt: readonly [HasciiExpression, HasciiExpression];
|
|
120
|
+
} | {
|
|
121
|
+
readonly lte: readonly [HasciiExpression, HasciiExpression];
|
|
122
|
+
} | {
|
|
123
|
+
readonly gt: readonly [HasciiExpression, HasciiExpression];
|
|
124
|
+
} | {
|
|
125
|
+
readonly gte: readonly [HasciiExpression, HasciiExpression];
|
|
126
|
+
} | {
|
|
127
|
+
readonly and: readonly HasciiExpression[];
|
|
128
|
+
} | {
|
|
129
|
+
readonly or: readonly HasciiExpression[];
|
|
130
|
+
} | {
|
|
131
|
+
readonly not: HasciiExpression;
|
|
132
|
+
} | {
|
|
133
|
+
readonly at: readonly [HasciiExpression, HasciiExpression];
|
|
134
|
+
} | {
|
|
135
|
+
readonly len: HasciiExpression;
|
|
136
|
+
};
|
|
137
|
+
type HasciiSetStatement = {
|
|
138
|
+
readonly set: Record<string, HasciiExpression>;
|
|
139
|
+
};
|
|
140
|
+
type HasciiIfStatement = {
|
|
141
|
+
readonly if: HasciiExpression;
|
|
142
|
+
readonly then?: readonly HasciiStatement[];
|
|
143
|
+
readonly else?: readonly HasciiStatement[];
|
|
144
|
+
readonly set?: Record<string, HasciiExpression>;
|
|
145
|
+
};
|
|
146
|
+
type HasciiEachStatement = {
|
|
147
|
+
readonly each: string;
|
|
148
|
+
readonly as: string;
|
|
149
|
+
readonly index?: string;
|
|
150
|
+
readonly do: readonly HasciiStatement[];
|
|
151
|
+
};
|
|
152
|
+
type HasciiPushStatement = {
|
|
153
|
+
readonly push: {
|
|
154
|
+
readonly to: string;
|
|
155
|
+
readonly item: HasciiExpression;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
type HasciiFilterStatement = {
|
|
159
|
+
readonly filter: {
|
|
160
|
+
readonly list: string;
|
|
161
|
+
readonly as: string;
|
|
162
|
+
readonly cond: HasciiExpression;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
type StrokeStyle = "light" | "heavy" | "double" | "round";
|
|
166
|
+
type HasciiFillStatement = {
|
|
167
|
+
readonly fill: HasciiExpression;
|
|
168
|
+
};
|
|
169
|
+
type HasciiStrokeStatement = {
|
|
170
|
+
readonly stroke: HasciiExpression;
|
|
171
|
+
};
|
|
172
|
+
type HasciiNoFillStatement = {
|
|
173
|
+
readonly noFill?: true;
|
|
174
|
+
};
|
|
175
|
+
type HasciiNoStrokeStatement = {
|
|
176
|
+
readonly noStroke?: true;
|
|
177
|
+
};
|
|
178
|
+
type HasciiStrokeStyleStatement = {
|
|
179
|
+
readonly strokeStyle: StrokeStyle;
|
|
180
|
+
};
|
|
181
|
+
type HasciiClsStatement = {
|
|
182
|
+
readonly cls?: true;
|
|
183
|
+
};
|
|
184
|
+
type HasciiRectStatement = {
|
|
185
|
+
readonly rect: readonly [HasciiExpression, HasciiExpression, HasciiExpression, HasciiExpression];
|
|
186
|
+
};
|
|
187
|
+
type HasciiPrintStatement = {
|
|
188
|
+
readonly print: readonly [HasciiExpression, HasciiExpression, HasciiExpression];
|
|
189
|
+
};
|
|
190
|
+
type WaveType = "tri" | "saw" | "sqr" | "pls" | "org" | "noi" | "pha" | "sin";
|
|
191
|
+
type EffectType = "pitchUp" | "vibrato" | "pitchDown" | "fadeIn" | "fadeOut";
|
|
192
|
+
type HasciiSfxStatement = {
|
|
193
|
+
readonly sfx: {
|
|
194
|
+
readonly wave: WaveType;
|
|
195
|
+
readonly freq: HasciiExpression;
|
|
196
|
+
readonly length: HasciiExpression;
|
|
197
|
+
readonly volume: HasciiExpression;
|
|
198
|
+
readonly effect?: EffectType;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
type HasciiStatement = HasciiSetStatement | HasciiIfStatement | HasciiEachStatement | HasciiPushStatement | HasciiFilterStatement | HasciiFillStatement | HasciiStrokeStatement | HasciiNoFillStatement | HasciiNoStrokeStatement | HasciiStrokeStyleStatement | HasciiClsStatement | HasciiRectStatement | HasciiPrintStatement | HasciiSfxStatement;
|
|
202
|
+
type SfxNote = {
|
|
203
|
+
readonly pitch: number;
|
|
204
|
+
readonly waveform: number;
|
|
205
|
+
readonly volume: number;
|
|
206
|
+
readonly effect: number;
|
|
207
|
+
};
|
|
208
|
+
type Sfx = {
|
|
209
|
+
readonly notes: readonly SfxNote[];
|
|
210
|
+
readonly speed: number;
|
|
211
|
+
readonly loopStart: number;
|
|
212
|
+
readonly loopEnd: number;
|
|
213
|
+
};
|
|
214
|
+
type MusicPattern = {
|
|
215
|
+
readonly ch0: number;
|
|
216
|
+
readonly ch1: number;
|
|
217
|
+
readonly ch2: number;
|
|
218
|
+
readonly ch3: number;
|
|
219
|
+
readonly flags: number;
|
|
220
|
+
};
|
|
221
|
+
type HasciiMusic = {
|
|
222
|
+
readonly sfx: readonly Sfx[];
|
|
223
|
+
readonly patterns: readonly MusicPattern[];
|
|
224
|
+
};
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/compiler/evaluate.d.ts
|
|
227
|
+
type HasciiState$2 = Record<string, HasciiValue>;
|
|
228
|
+
declare function evaluate(expr: HasciiExpression, state: HasciiState$2, depth?: number): HasciiValue;
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/core/errors.d.ts
|
|
231
|
+
declare class HasciiError extends Error {
|
|
232
|
+
constructor(message: string);
|
|
233
|
+
}
|
|
234
|
+
declare class HasciiParseError extends HasciiError {
|
|
235
|
+
readonly source: string;
|
|
236
|
+
constructor(message: string, source?: string);
|
|
237
|
+
}
|
|
238
|
+
declare class HasciiValidationError extends HasciiError {
|
|
239
|
+
readonly issues: readonly ZodIssue[];
|
|
240
|
+
readonly source: string;
|
|
241
|
+
constructor(message: string, issues?: readonly ZodIssue[], source?: string);
|
|
242
|
+
}
|
|
243
|
+
declare class HasciiRuntimeError extends HasciiError {
|
|
244
|
+
constructor(message: string);
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/compiler/parser.d.ts
|
|
248
|
+
type HasciiCompileError = HasciiParseError | HasciiValidationError;
|
|
249
|
+
declare function compile(source: string): HasciiProgram | HasciiCompileError;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/compiler/formatter.d.ts
|
|
252
|
+
declare function formatError(error: HasciiCompileError): string;
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/compiler/source-map/types.d.ts
|
|
255
|
+
type SourceLocation = {
|
|
256
|
+
readonly line: number;
|
|
257
|
+
readonly column: number;
|
|
258
|
+
readonly offset: number;
|
|
259
|
+
readonly length: number;
|
|
260
|
+
};
|
|
261
|
+
type SourceMapEntry = {
|
|
262
|
+
readonly path: readonly (string | number)[];
|
|
263
|
+
readonly location: SourceLocation;
|
|
264
|
+
};
|
|
265
|
+
type SourceMap = {
|
|
266
|
+
readonly entries: readonly SourceMapEntry[];
|
|
267
|
+
readonly source: string;
|
|
268
|
+
readonly lines: readonly string[];
|
|
269
|
+
};
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/compiler/source-map/create.d.ts
|
|
272
|
+
declare function createSourceMap(source: string): SourceMap;
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/compiler/source-map/query.d.ts
|
|
275
|
+
declare function findLocation(sourceMap: SourceMap, path: readonly (string | number)[]): SourceLocation | null;
|
|
276
|
+
declare function getSourceLine(sourceMap: SourceMap, lineNumber: number): string;
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/core/models.d.ts
|
|
279
|
+
declare const hasciiProgramSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
280
|
+
meta: z.ZodObject<{
|
|
281
|
+
title: z.ZodString;
|
|
282
|
+
frame: z.ZodNumber;
|
|
283
|
+
bg: z.ZodNumber;
|
|
284
|
+
art: z.ZodArray<z.ZodString>;
|
|
285
|
+
description: z.ZodOptional<z.ZodString>;
|
|
286
|
+
type: z.ZodLiteral<"tracker">;
|
|
287
|
+
}, z.core.$strip>;
|
|
288
|
+
tracker: z.ZodObject<{
|
|
289
|
+
bpm: z.ZodOptional<z.ZodNumber>;
|
|
290
|
+
items: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
291
|
+
steps: z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
292
|
+
pitch: z.ZodNumber;
|
|
293
|
+
octave: z.ZodOptional<z.ZodNumber>;
|
|
294
|
+
volume: z.ZodOptional<z.ZodNumber>;
|
|
295
|
+
effect: z.ZodOptional<z.ZodNumber>;
|
|
296
|
+
}, z.core.$strip>>>;
|
|
297
|
+
}, z.core.$strip>>>;
|
|
298
|
+
}, z.core.$strip>;
|
|
299
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
300
|
+
meta: z.ZodObject<{
|
|
301
|
+
title: z.ZodString;
|
|
302
|
+
frame: z.ZodNumber;
|
|
303
|
+
bg: z.ZodNumber;
|
|
304
|
+
art: z.ZodArray<z.ZodString>;
|
|
305
|
+
description: z.ZodOptional<z.ZodString>;
|
|
306
|
+
type: z.ZodLiteral<"music">;
|
|
307
|
+
}, z.core.$strip>;
|
|
308
|
+
music: z.ZodArray<z.ZodObject<{
|
|
309
|
+
name: z.ZodOptional<z.ZodString>;
|
|
310
|
+
bpm: z.ZodOptional<z.ZodNumber>;
|
|
311
|
+
tracks: z.ZodArray<z.ZodObject<{
|
|
312
|
+
channel: z.ZodOptional<z.ZodNumber>;
|
|
313
|
+
wave: z.ZodOptional<z.ZodEnum<{
|
|
314
|
+
tri: "tri";
|
|
315
|
+
saw: "saw";
|
|
316
|
+
sqr: "sqr";
|
|
317
|
+
pls: "pls";
|
|
318
|
+
org: "org";
|
|
319
|
+
noi: "noi";
|
|
320
|
+
pha: "pha";
|
|
321
|
+
sin: "sin";
|
|
322
|
+
}>>;
|
|
323
|
+
notes: z.ZodArray<z.ZodObject<{
|
|
324
|
+
time: z.ZodNumber;
|
|
325
|
+
pitch: z.ZodNumber;
|
|
326
|
+
octave: z.ZodOptional<z.ZodNumber>;
|
|
327
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
328
|
+
volume: z.ZodOptional<z.ZodNumber>;
|
|
329
|
+
}, z.core.$strip>>;
|
|
330
|
+
}, z.core.$strip>>;
|
|
331
|
+
}, z.core.$strip>>;
|
|
332
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
333
|
+
meta: z.ZodOptional<z.ZodObject<{
|
|
334
|
+
title: z.ZodString;
|
|
335
|
+
frame: z.ZodNumber;
|
|
336
|
+
bg: z.ZodNumber;
|
|
337
|
+
art: z.ZodArray<z.ZodString>;
|
|
338
|
+
description: z.ZodOptional<z.ZodString>;
|
|
339
|
+
type: z.ZodLiteral<"game">;
|
|
340
|
+
}, z.core.$strip>>;
|
|
341
|
+
init: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
|
|
342
|
+
update: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
|
|
343
|
+
draw: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
|
|
344
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
345
|
+
meta: z.ZodOptional<z.ZodObject<{
|
|
346
|
+
title: z.ZodString;
|
|
347
|
+
frame: z.ZodNumber;
|
|
348
|
+
bg: z.ZodNumber;
|
|
349
|
+
art: z.ZodArray<z.ZodString>;
|
|
350
|
+
description: z.ZodOptional<z.ZodString>;
|
|
351
|
+
}, z.core.$strip>>;
|
|
352
|
+
init: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
|
|
353
|
+
update: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
|
|
354
|
+
draw: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
|
|
355
|
+
}, z.core.$strip>]>;
|
|
356
|
+
type HasciiProgramParsed = z.infer<typeof hasciiProgramSchema>;
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/core/safe-key.d.ts
|
|
359
|
+
declare function isSafeKey(key: string): boolean;
|
|
360
|
+
declare function isSafePath(path: string): boolean;
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/runtime/button-state.d.ts
|
|
363
|
+
type KeyTimestamps = {
|
|
364
|
+
readonly left: number;
|
|
365
|
+
readonly right: number;
|
|
366
|
+
readonly up: number;
|
|
367
|
+
readonly down: number;
|
|
368
|
+
readonly a: number;
|
|
369
|
+
readonly b: number;
|
|
370
|
+
};
|
|
371
|
+
declare function createButtonState(): HasciiButtonState;
|
|
372
|
+
declare function createKeyTimestamps(): KeyTimestamps;
|
|
373
|
+
declare function updateKeyTimestamps(timestamps: KeyTimestamps, btn: HasciiButtonState, now: number): KeyTimestamps;
|
|
374
|
+
declare function getActiveButtons(timestamps: KeyTimestamps, now: number, holdMs: number): HasciiButtonState;
|
|
375
|
+
declare function getPressedButtons(prev: HasciiButtonState, curr: HasciiButtonState): HasciiButtonState;
|
|
376
|
+
declare function isValidKey(key: string): boolean;
|
|
377
|
+
declare function processKeyInput(key: Buffer): HasciiButtonState;
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/runtime/interpreter/types.d.ts
|
|
380
|
+
type DrawState = {
|
|
381
|
+
readonly fill: number | null;
|
|
382
|
+
readonly stroke: number | null;
|
|
383
|
+
readonly strokeStyle: StrokeStyle;
|
|
384
|
+
};
|
|
385
|
+
type HasciiDrawCommand = {
|
|
386
|
+
type: "cls";
|
|
387
|
+
bg: number;
|
|
388
|
+
} | {
|
|
389
|
+
type: "rect";
|
|
390
|
+
x: number;
|
|
391
|
+
y: number;
|
|
392
|
+
w: number;
|
|
393
|
+
h: number;
|
|
394
|
+
fill: number | null;
|
|
395
|
+
stroke: number | null;
|
|
396
|
+
strokeStyle: StrokeStyle;
|
|
397
|
+
} | {
|
|
398
|
+
type: "print";
|
|
399
|
+
text: string;
|
|
400
|
+
x: number;
|
|
401
|
+
y: number;
|
|
402
|
+
fg: number;
|
|
403
|
+
bg: number | null;
|
|
404
|
+
} | {
|
|
405
|
+
type: "sfx";
|
|
406
|
+
wave: WaveType;
|
|
407
|
+
freq: number;
|
|
408
|
+
length: number;
|
|
409
|
+
volume: number;
|
|
410
|
+
effect: EffectType | null;
|
|
411
|
+
};
|
|
412
|
+
type HasciiState = Record<string, HasciiValue>;
|
|
413
|
+
type ExecuteResult = {
|
|
414
|
+
readonly state: HasciiState;
|
|
415
|
+
readonly commands: readonly HasciiDrawCommand[];
|
|
416
|
+
readonly drawState: DrawState;
|
|
417
|
+
};
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/runtime/game.d.ts
|
|
420
|
+
type GameInstance = {
|
|
421
|
+
readonly program: HasciiProgram;
|
|
422
|
+
readonly gameState: Record<string, HasciiValue>;
|
|
423
|
+
readonly btn: HasciiButtonState;
|
|
424
|
+
readonly prevBtn: HasciiButtonState;
|
|
425
|
+
};
|
|
426
|
+
type TickResult = {
|
|
427
|
+
readonly game: GameInstance;
|
|
428
|
+
readonly commands: readonly HasciiDrawCommand[];
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Create a new game instance from a program
|
|
432
|
+
*/
|
|
433
|
+
declare function createGame(program: HasciiProgram): GameInstance;
|
|
434
|
+
/**
|
|
435
|
+
* Tick the game: update state and generate draw commands
|
|
436
|
+
* This is a pure function - no side effects
|
|
437
|
+
*/
|
|
438
|
+
declare function tick(game: GameInstance, btn: HasciiButtonState): TickResult;
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/runtime/interpreter/execute.d.ts
|
|
441
|
+
declare function createDrawState(): DrawState;
|
|
442
|
+
declare function executeStatements(statements: readonly HasciiStatement[], state: HasciiState, drawState?: DrawState): ExecuteResult;
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/runtime/raw-mode.d.ts
|
|
445
|
+
declare function enableRawMode(): void;
|
|
446
|
+
declare function disableRawMode(): void;
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/runtime/render/index.d.ts
|
|
449
|
+
declare function render(commands: readonly HasciiDrawCommand[], canvasWidth: number, canvasHeight: number): void;
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/runtime/render/canvas.d.ts
|
|
452
|
+
type CanvasRegion = {
|
|
453
|
+
readonly x: number;
|
|
454
|
+
readonly y: number;
|
|
455
|
+
readonly width: number;
|
|
456
|
+
readonly height: number;
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* Render draw commands to an ANSI string.
|
|
460
|
+
* Pure function - no side effects.
|
|
461
|
+
*
|
|
462
|
+
* @param commands - Draw commands from game tick
|
|
463
|
+
* @param region - Where to render the canvas (screen coordinates)
|
|
464
|
+
* @returns ANSI escape sequence string
|
|
465
|
+
*/
|
|
466
|
+
declare function renderCanvas(commands: readonly HasciiDrawCommand[], region: CanvasRegion): string;
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/runtime/run.d.ts
|
|
469
|
+
type RunOptions = {
|
|
470
|
+
readonly onEscape?: () => void;
|
|
471
|
+
};
|
|
472
|
+
declare function run(program: HasciiProgram): void;
|
|
473
|
+
declare function runWithCallback(program: HasciiProgram, options: RunOptions): void;
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/runtime/set-variable.d.ts
|
|
476
|
+
type HasciiState$1 = Record<string, HasciiValue>;
|
|
477
|
+
declare function setVariable(state: HasciiState$1, path: string, value: HasciiValue): HasciiState$1;
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region src/runtime/state.d.ts
|
|
480
|
+
type HasciiRuntimeState = {
|
|
481
|
+
readonly gameState: Record<string, HasciiValue>;
|
|
482
|
+
readonly btn: HasciiButtonState;
|
|
483
|
+
readonly prevBtn: HasciiButtonState;
|
|
484
|
+
};
|
|
485
|
+
declare function createInitialState(program: HasciiProgram): HasciiRuntimeState;
|
|
486
|
+
declare function updateGameState(program: HasciiProgram, state: HasciiRuntimeState, btn: HasciiButtonState): HasciiRuntimeState;
|
|
487
|
+
declare function renderFrame(program: HasciiProgram, state: HasciiRuntimeState): void;
|
|
488
|
+
//#endregion
|
|
489
|
+
export { ANSI, BOX, COLORS, CanvasRegion, DrawState, ERROR_CODES, EffectType, ExecuteResult, GameInstance, HasciiButtonState, HasciiClsStatement, HasciiCompileError, HasciiDrawCommand, HasciiEachStatement, HasciiError, HasciiErrorCode, HasciiExpression, HasciiFillStatement, HasciiFilterStatement, HasciiIfStatement, HasciiMusic, HasciiNoFillStatement, HasciiNoStrokeStatement, HasciiParseError, HasciiPrintStatement, HasciiProgram, HasciiProgramParsed, HasciiPushStatement, HasciiRectStatement, HasciiRuntimeError, HasciiRuntimeState, HasciiSetStatement, HasciiSfxStatement, HasciiState, HasciiStatement, HasciiStrokeStatement, HasciiStrokeStyleStatement, HasciiValidationError, HasciiValue, KeyTimestamps, MusicPattern, RunOptions, Sfx, SfxNote, SourceLocation, SourceMap, SourceMapEntry, StrokeStyle, TickResult, WaveType, compile, createButtonState, createDrawState, createGame, createInitialState, createKeyTimestamps, createSourceMap, disableRawMode, enableRawMode, evaluate, executeStatements, findLocation, formatError, getActiveButtons, getPressedButtons, getSourceLine, hasciiProgramSchema, isSafeKey, isSafePath, isValidKey, line, mapZodCodeToErrorCode, processKeyInput, render, renderCanvas, renderFrame, run, runWithCallback, setVariable, stripAnsi, supportsColor, tick, updateGameState, updateKeyTimestamps };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { $ as line, A as getActiveButtons, B as HasciiRuntimeError, F as compile, G as evaluate, H as findLocation, I as hasciiProgramSchema, J as ERROR_CODES, K as isSafeKey, L as formatError, M as isValidKey, N as processKeyInput, O as createButtonState, P as updateKeyTimestamps, Q as COLORS, R as HasciiError, U as getSourceLine, V as HasciiValidationError, W as createSourceMap, X as ANSI, Y as mapZodCodeToErrorCode, Z as BOX, _ as createDrawState, a as updateGameState, d as renderCanvas, et as stripAnsi, f as render, g as tick, h as createGame, i as renderFrame, j as getPressedButtons, k as createKeyTimestamps, m as enableRawMode, n as runWithCallback, p as disableRawMode, q as isSafePath, r as createInitialState, t as run, tt as supportsColor, v as executeStatements, y as setVariable, z as HasciiParseError } from "./run-mrITeQUl.mjs";
|
|
2
|
+
|
|
3
|
+
export { ANSI, BOX, COLORS, ERROR_CODES, HasciiError, HasciiParseError, HasciiRuntimeError, HasciiValidationError, compile, createButtonState, createDrawState, createGame, createInitialState, createKeyTimestamps, createSourceMap, disableRawMode, enableRawMode, evaluate, executeStatements, findLocation, formatError, getActiveButtons, getPressedButtons, getSourceLine, hasciiProgramSchema, isSafeKey, isSafePath, isValidKey, line, mapZodCodeToErrorCode, processKeyInput, render, renderCanvas, renderFrame, run, runWithCallback, setVariable, stripAnsi, supportsColor, tick, updateGameState, updateKeyTimestamps };
|