@markdy/core 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +30 -3
  2. package/package.json +8 -5
package/dist/index.js CHANGED
@@ -10,22 +10,27 @@ var ParseError = class extends Error {
10
10
  function stripComment(line) {
11
11
  let depth = 0;
12
12
  let inString = false;
13
+ let lastNonSpace = "";
13
14
  for (let i = 0; i < line.length; i++) {
14
15
  const ch = line[i];
15
16
  if (ch === '"') {
16
17
  inString = !inString;
18
+ lastNonSpace = ch;
17
19
  continue;
18
20
  }
19
21
  if (inString) continue;
20
22
  if (ch === "(") {
21
23
  depth++;
24
+ lastNonSpace = ch;
22
25
  continue;
23
26
  }
24
27
  if (ch === ")") {
25
28
  depth--;
29
+ lastNonSpace = ch;
26
30
  continue;
27
31
  }
28
- if (ch === "#" && depth === 0) return line.slice(0, i);
32
+ if (ch === "#" && depth === 0 && lastNonSpace !== "=") return line.slice(0, i);
33
+ if (ch !== " " && ch !== " ") lastNonSpace = ch;
29
34
  }
30
35
  return line;
31
36
  }
@@ -120,6 +125,18 @@ var DEFAULTS = {
120
125
  fps: 30,
121
126
  bg: "white"
122
127
  };
128
+ function validateMoveTarget(action, params, meta, actor, line) {
129
+ if (action !== "move") return;
130
+ const to = params.to;
131
+ if (!Array.isArray(to) || to.length < 2) return;
132
+ const [x, y] = to;
133
+ if (x < 0 || x > meta.width || y < 0 || y > meta.height) {
134
+ throw new ParseError(
135
+ `Actor "${actor}" move target (${x}, ${y}) is outside scene bounds (0\u2013${meta.width}, 0\u2013${meta.height})`,
136
+ line
137
+ );
138
+ }
139
+ }
123
140
  function parse(source) {
124
141
  const ast = {
125
142
  meta: { ...DEFAULTS },
@@ -283,11 +300,19 @@ function parse(source) {
283
300
  throw new ParseError(`Unknown actor type or template: "${typeName}"`, lineNum);
284
301
  }
285
302
  const modifiers = parseModifiers(modifiersRaw);
303
+ const x = Number(xStr);
304
+ const y = Number(yStr);
305
+ if (x < 0 || x > ast.meta.width || y < 0 || y > ast.meta.height) {
306
+ throw new ParseError(
307
+ `Actor "${name}" position (${x}, ${y}) is outside scene bounds (0\u2013${ast.meta.width}, 0\u2013${ast.meta.height})`,
308
+ lineNum
309
+ );
310
+ }
286
311
  ast.actors[name] = {
287
312
  type: resolvedType,
288
313
  args: resolvedArgs,
289
- x: Number(xStr),
290
- y: Number(yStr),
314
+ x,
315
+ y,
291
316
  ...modifiers
292
317
  };
293
318
  continue;
@@ -332,6 +357,7 @@ function parse(source) {
332
357
  const expandedParams = interpolate(sev.paramsRaw, playVars);
333
358
  const absTime = Math.round((time + sev.offset) * 1e3) / 1e3;
334
359
  const params2 = parseActionParams(sev.action, expandedParams);
360
+ validateMoveTarget(sev.action, params2, ast.meta, actor, lineNum);
335
361
  ast.events.push({
336
362
  time: absTime,
337
363
  actor,
@@ -343,6 +369,7 @@ function parse(source) {
343
369
  continue;
344
370
  }
345
371
  const params = parseActionParams(action, paramsRaw);
372
+ validateMoveTarget(action, params, ast.meta, actor, lineNum);
346
373
  ast.events.push({ time, actor, action, params, line: lineNum });
347
374
  continue;
348
375
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MarkdyScript parser and AST types — zero runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,7 +24,10 @@
24
24
  "animation",
25
25
  "dsl",
26
26
  "parser",
27
- "ast"
27
+ "ast",
28
+ "declarative-animation",
29
+ "mermaid-alternative",
30
+ "markdown-animation"
28
31
  ],
29
32
  "author": "Hoang Yell <hoangyell@gmail.com> (https://hoangyell.com)",
30
33
  "homepage": "https://markdy.com",
@@ -40,9 +43,9 @@
40
43
  "access": "public"
41
44
  },
42
45
  "devDependencies": {
43
- "tsup": "^8.3.0",
44
- "typescript": "^5.4.0",
45
- "vitest": "^1.6.0"
46
+ "tsup": "^8.5.1",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.1.4"
46
49
  },
47
50
  "scripts": {
48
51
  "build": "tsup",