sketchmark 1.1.2 → 1.1.3

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.

Potentially problematic release.


This version of sketchmark might be problematic. Click here for more details.

@@ -9249,11 +9249,13 @@ var AIDiagram = (function (exports) {
9249
9249
  this._config = _config;
9250
9250
  this._step = -1;
9251
9251
  this._pendingStepTimers = new Set();
9252
+ this._pendingNarrationTimers = new Set();
9252
9253
  this._transforms = new Map();
9253
9254
  this._listeners = [];
9254
9255
  // ── Narration caption ──
9255
9256
  this._captionEl = null;
9256
9257
  this._captionTextEl = null;
9258
+ this._narrationRunId = 0;
9257
9259
  // ── Annotations ──
9258
9260
  this._annotationLayer = null;
9259
9261
  this._annotations = [];
@@ -9516,20 +9518,30 @@ var AIDiagram = (function (exports) {
9516
9518
  }
9517
9519
  this.emit("step-change");
9518
9520
  }
9521
+ _clearTimerBucket(bucket) {
9522
+ bucket.forEach((id) => window.clearTimeout(id));
9523
+ bucket.clear();
9524
+ }
9519
9525
  _clearPendingStepTimers() {
9520
- this._pendingStepTimers.forEach((id) => window.clearTimeout(id));
9521
- this._pendingStepTimers.clear();
9526
+ this._clearTimerBucket(this._pendingStepTimers);
9522
9527
  }
9523
- _scheduleStep(fn, delayMs) {
9528
+ _cancelNarrationTyping() {
9529
+ this._narrationRunId += 1;
9530
+ this._clearTimerBucket(this._pendingNarrationTimers);
9531
+ }
9532
+ _scheduleTimer(fn, delayMs, bucket = this._pendingStepTimers) {
9524
9533
  if (delayMs <= 0) {
9525
9534
  fn();
9526
9535
  return;
9527
9536
  }
9528
9537
  const id = window.setTimeout(() => {
9529
- this._pendingStepTimers.delete(id);
9538
+ bucket.delete(id);
9530
9539
  fn();
9531
9540
  }, delayMs);
9532
- this._pendingStepTimers.add(id);
9541
+ bucket.add(id);
9542
+ }
9543
+ _scheduleStep(fn, delayMs) {
9544
+ this._scheduleTimer(fn, delayMs, this._pendingStepTimers);
9533
9545
  }
9534
9546
  _stepWaitMs(step, fallbackMs) {
9535
9547
  const delay = Math.max(0, step.delay ?? 0);
@@ -9573,6 +9585,7 @@ var AIDiagram = (function (exports) {
9573
9585
  }
9574
9586
  _clearAll() {
9575
9587
  this._clearPendingStepTimers();
9588
+ this._cancelNarrationTyping();
9576
9589
  this._cancelSpeech();
9577
9590
  this._transforms.clear();
9578
9591
  // Nodes
@@ -10127,6 +10140,7 @@ var AIDiagram = (function (exports) {
10127
10140
  _doNarrate(text, silent) {
10128
10141
  if (!this._captionEl || !this._captionTextEl)
10129
10142
  return;
10143
+ this._cancelNarrationTyping();
10130
10144
  this._captionEl.style.opacity = "1";
10131
10145
  if (silent || !text) {
10132
10146
  this._captionTextEl.textContent = text;
@@ -10137,12 +10151,16 @@ var AIDiagram = (function (exports) {
10137
10151
  this._speak(text);
10138
10152
  // Typing effect
10139
10153
  this._captionTextEl.textContent = "";
10154
+ const narrationRunId = this._narrationRunId;
10140
10155
  let charIdx = 0;
10141
10156
  const typeNext = () => {
10157
+ if (this._narrationRunId !== narrationRunId || !this._captionTextEl)
10158
+ return;
10142
10159
  if (charIdx < text.length) {
10143
10160
  this._captionTextEl.textContent += text[charIdx++];
10144
- const id = window.setTimeout(typeNext, ANIMATION.narrationTypeMs);
10145
- this._pendingStepTimers.add(id);
10161
+ if (charIdx < text.length) {
10162
+ this._scheduleTimer(typeNext, ANIMATION.narrationTypeMs, this._pendingNarrationTimers);
10163
+ }
10146
10164
  }
10147
10165
  };
10148
10166
  typeNext();
@@ -10252,12 +10270,11 @@ var AIDiagram = (function (exports) {
10252
10270
  requestAnimationFrame(animate);
10253
10271
  }
10254
10272
  // After guide finishes: reveal rough.js element, remove guide
10255
- const id = window.setTimeout(() => {
10273
+ this._scheduleTimer(() => {
10256
10274
  roughEl.style.transition = `opacity 120ms ease`;
10257
10275
  roughEl.style.opacity = "1";
10258
10276
  guide.remove();
10259
10277
  }, dur + 30);
10260
- this._pendingStepTimers.add(id);
10261
10278
  }));
10262
10279
  }
10263
10280
  _doAnnotationCircle(target, silent) {
package/package.json CHANGED
@@ -1,72 +1,71 @@
1
- {
2
- "name": "sketchmark",
3
- "version": "1.1.2",
4
- "description": "A plain-text DSL for hand-drawn diagrams. Write boxes, edges, and groups as code — renders sketchy SVG/Canvas via rough.js with a built-in step-by-step animation system.",
5
- "keywords": [
6
- "diagram",
7
- "dsl",
8
- "rough.js",
9
- "hand-drawn",
10
- "ai",
11
- "llm",
12
- "visualization",
13
- "animation",
14
- "svg"
15
- ],
16
- "author": "sketchmark contributors",
17
- "license": "MIT",
18
- "type": "module",
19
- "main": "./dist/index.cjs",
20
- "module": "./dist/index.js",
21
- "types": "./dist/index.d.ts",
22
- "exports": {
23
- ".": {
24
- "import": "./dist/index.js",
25
- "require": "./dist/index.cjs",
26
- "types": "./dist/index.d.ts"
27
- }
28
- },
29
- "files": [
30
- "dist",
31
- "README.md",
32
- "LICENSE"
33
- ],
34
- "scripts": {
35
- "build": "rollup -c rollup.config.js",
36
- "build:watch": "rollup -c rollup.config.js --watch",
37
- "typecheck": "tsc --noEmit",
38
- "lint": "eslint src --ext .ts",
39
- "prepublishOnly": "npm run typecheck && npm run build",
40
- "deploy": "wrangler deploy",
41
- "preview": "wrangler dev"
42
- },
43
- "dependencies": {
44
- "@chenglou/pretext": "^0.0.4"
45
- },
46
- "peerDependencies": {
47
- "roughjs": "^4.6.0"
48
- },
49
- "devDependencies": {
50
- "@rollup/plugin-node-resolve": "^15.2.3",
51
- "@rollup/plugin-typescript": "^11.1.6",
52
- "@types/node": "^20.0.0",
53
- "@typescript-eslint/eslint-plugin": "^7.0.0",
54
- "@typescript-eslint/parser": "^7.0.0",
55
- "eslint": "^8.56.0",
56
- "happy-dom": "^13.6.0",
57
- "rollup": "^4.9.0",
58
- "tslib": "^2.6.2",
59
- "typescript": "^5.3.3",
60
- "vitest": "^1.2.0",
61
- "wrangler": "^4.76.0"
62
- },
63
- "sideEffects": false,
64
- "repository": {
65
- "type": "git",
66
- "url": "https://github.com/anmism/sketchmark"
67
- },
68
- "bugs": {
69
- "url": "https://github.com/anmism/sketchmark/issues"
70
- },
71
- "homepage": "https://github.com/anmism/sketchmark#readme"
72
- }
1
+ {
2
+ "name": "sketchmark",
3
+ "version": "1.1.3",
4
+ "description": "A plain-text DSL for hand-drawn diagrams. Write boxes, edges, and groups as code — renders sketchy SVG/Canvas via rough.js with a built-in step-by-step animation system.",
5
+ "keywords": [
6
+ "diagram",
7
+ "dsl",
8
+ "rough.js",
9
+ "hand-drawn",
10
+ "ai",
11
+ "llm",
12
+ "visualization",
13
+ "animation",
14
+ "svg"
15
+ ],
16
+ "author": "sketchmark contributors",
17
+ "license": "MIT",
18
+ "type": "module",
19
+ "main": "./dist/index.cjs",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./dist/index.js",
25
+ "require": "./dist/index.cjs",
26
+ "types": "./dist/index.d.ts"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "scripts": {
35
+ "build": "rollup -c rollup.config.js",
36
+ "build:watch": "rollup -c rollup.config.js --watch",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint src --ext .ts",
39
+ "prepublishOnly": "npm run typecheck && npm run build",
40
+ "deploy": "wrangler deploy",
41
+ "preview": "wrangler dev"
42
+ },
43
+ "dependencies": {
44
+ "@chenglou/pretext": "^0.0.4"
45
+ },
46
+ "peerDependencies": {
47
+ "roughjs": "^4.6.0"
48
+ },
49
+ "devDependencies": {
50
+ "@rollup/plugin-node-resolve": "^15.2.3",
51
+ "@rollup/plugin-typescript": "^11.1.6",
52
+ "@types/node": "^20.0.0",
53
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
54
+ "@typescript-eslint/parser": "^7.0.0",
55
+ "eslint": "^8.56.0",
56
+ "happy-dom": "^13.6.0",
57
+ "rollup": "^4.9.0",
58
+ "tslib": "^2.6.2",
59
+ "typescript": "^5.3.3",
60
+ "vitest": "^1.2.0"
61
+ },
62
+ "sideEffects": false,
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "https://github.com/anmism/sketchmark"
66
+ },
67
+ "bugs": {
68
+ "url": "https://github.com/anmism/sketchmark/issues"
69
+ },
70
+ "homepage": "https://github.com/anmism/sketchmark#readme"
71
+ }