samcan 0.0.1 → 0.0.2

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 (37) hide show
  1. package/dist/bundle.js +5888 -0
  2. package/dist/core/animation/animationtrack.d.ts.map +1 -1
  3. package/dist/core/animation/animationtrack.js +7 -0
  4. package/dist/core/animation/animationtrack.js.map +1 -1
  5. package/dist/core/math/color.d.ts.map +1 -1
  6. package/dist/core/math/color.js +4 -5
  7. package/dist/core/math/color.js.map +1 -1
  8. package/dist/core/math/matrix.d.ts.map +1 -1
  9. package/dist/core/math/matrix.js +6 -7
  10. package/dist/core/math/matrix.js.map +1 -1
  11. package/dist/core/math/rectangle.d.ts +10 -10
  12. package/dist/core/math/rectangle.d.ts.map +1 -1
  13. package/dist/core/math/rectangle.js +24 -24
  14. package/dist/core/math/rectangle.js.map +1 -1
  15. package/dist/core/math/vector2.d.ts.map +1 -1
  16. package/dist/core/math/vector2.js +2 -3
  17. package/dist/core/math/vector2.js.map +1 -1
  18. package/dist/core/renderer/dirtyregionmanager.js +2 -2
  19. package/dist/core/renderer/dirtyregionmanager.js.map +1 -1
  20. package/dist/core/scene/node.d.ts +5 -0
  21. package/dist/core/scene/node.d.ts.map +1 -1
  22. package/dist/core/scene/node.js +16 -5
  23. package/dist/core/scene/node.js.map +1 -1
  24. package/dist/wrapper/react/index.d.ts +5 -0
  25. package/dist/wrapper/react/index.d.ts.map +1 -0
  26. package/dist/wrapper/react/index.js +3 -0
  27. package/dist/wrapper/react/index.js.map +1 -0
  28. package/dist/wrapper/react/samcan-player.d.ts +26 -0
  29. package/dist/wrapper/react/samcan-player.d.ts.map +1 -0
  30. package/dist/wrapper/react/samcan-player.js +19 -0
  31. package/dist/wrapper/react/samcan-player.js.map +1 -0
  32. package/dist/wrapper/react/use-samcan-player.d.ts +33 -0
  33. package/dist/wrapper/react/use-samcan-player.d.ts.map +1 -0
  34. package/dist/wrapper/react/use-samcan-player.js +65 -0
  35. package/dist/wrapper/react/use-samcan-player.js.map +1 -0
  36. package/package.json +20 -6
  37. package/readme.md +89 -6
@@ -0,0 +1,33 @@
1
+ import type { RefObject } from "react";
2
+ import { type AnimationPlayer, type LoadOptions, type PlayerConfig } from "../../core/api";
3
+ export interface UseSamcanPlayerOptions {
4
+ /**
5
+ * URL of the animation to load. If omitted, the
6
+ * hook only creates the player and leaves loading
7
+ * to the caller via the returned instance.
8
+ */
9
+ src?: string;
10
+ /**
11
+ * Whether to start playing immediately after load.
12
+ * Overrides `config.autoplay` if provided.
13
+ */
14
+ autoplay?: boolean;
15
+ /**
16
+ * Options forwarded to `AnimationPlayer.load`.
17
+ */
18
+ loadOptions?: LoadOptions;
19
+ /**
20
+ * Additional player configuration. The `canvas`
21
+ * property is managed by the hook and ignored.
22
+ */
23
+ config?: Omit<PlayerConfig, "canvas">;
24
+ }
25
+ interface UseSamcanPlayerResult {
26
+ canvasRef: RefObject<HTMLCanvasElement>;
27
+ player: AnimationPlayer | null;
28
+ isLoading: boolean;
29
+ error: Error | null;
30
+ }
31
+ export declare function useSamcanPlayer(options?: UseSamcanPlayerOptions): UseSamcanPlayerResult;
32
+ export {};
33
+ //# sourceMappingURL=use-samcan-player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-samcan-player.d.ts","sourceRoot":"","sources":["../../../wrapper/react/use-samcan-player.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,EACH,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EAEpB,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,sBAAsB;IACnC;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IAEzB;;;OAGG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;CACxC;AAED,UAAU,qBAAqB;IAC3B,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAA;IACvC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAA;IAC9B,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACtB;AAED,wBAAgB,eAAe,CAC3B,OAAO,GAAE,sBAA2B,GACrC,qBAAqB,CAwEvB"}
@@ -0,0 +1,65 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { createPlayer, } from "../../core/api";
3
+ export function useSamcanPlayer(options = {}) {
4
+ const { src, autoplay, loadOptions, config } = options;
5
+ const canvasRef = useRef(null);
6
+ const [player, setPlayer] = useState(null);
7
+ const [isLoading, setIsLoading] = useState(false);
8
+ const [error, setError] = useState(null);
9
+ // Keep latest options in refs to avoid re-creating
10
+ // the player unnecessarily.
11
+ const latestOptionsRef = useRef(options);
12
+ latestOptionsRef.current = options;
13
+ useEffect(() => {
14
+ const canvas = canvasRef.current;
15
+ if (!canvas) {
16
+ return;
17
+ }
18
+ let cancelled = false;
19
+ let currentPlayer = null;
20
+ async function setup() {
21
+ setIsLoading(true);
22
+ setError(null);
23
+ try {
24
+ const baseConfig = {
25
+ canvas: canvas,
26
+ ...(config ?? {}),
27
+ };
28
+ const createdPlayer = await createPlayer(baseConfig);
29
+ if (cancelled) {
30
+ createdPlayer.destroy();
31
+ return;
32
+ }
33
+ currentPlayer = createdPlayer;
34
+ setPlayer(createdPlayer);
35
+ const effectiveAutoplay = autoplay ?? config?.autoplay ?? false;
36
+ if (src) {
37
+ await createdPlayer.load(src, loadOptions);
38
+ if (effectiveAutoplay) {
39
+ createdPlayer.play();
40
+ }
41
+ }
42
+ }
43
+ catch (err) {
44
+ if (cancelled) {
45
+ return;
46
+ }
47
+ setError(err instanceof Error ? err : new Error(String(err)));
48
+ }
49
+ finally {
50
+ if (!cancelled) {
51
+ setIsLoading(false);
52
+ }
53
+ }
54
+ }
55
+ void setup();
56
+ return () => {
57
+ cancelled = true;
58
+ if (currentPlayer) {
59
+ currentPlayer.destroy();
60
+ }
61
+ };
62
+ }, [src, autoplay, loadOptions, config]);
63
+ return { canvasRef, player, isLoading, error };
64
+ }
65
+ //# sourceMappingURL=use-samcan-player.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-samcan-player.js","sourceRoot":"","sources":["../../../wrapper/react/use-samcan-player.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAIH,YAAY,GACf,MAAM,gBAAgB,CAAA;AAmCvB,MAAM,UAAU,eAAe,CAC3B,UAAkC,EAAE;IAEpC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAEtD,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAA;IACjD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAyB,IAAI,CAAC,CAAA;IAClE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACjD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAA;IAEtD,mDAAmD;IACnD,4BAA4B;IAC5B,MAAM,gBAAgB,GAAG,MAAM,CAAyB,OAAO,CAAC,CAAA;IAChE,gBAAgB,CAAC,OAAO,GAAG,OAAO,CAAA;IAElC,SAAS,CAAC,GAAG,EAAE;QACX,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAA;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAM;QACV,CAAC;QAED,IAAI,SAAS,GAAG,KAAK,CAAA;QACrB,IAAI,aAAa,GAA2B,IAAI,CAAA;QAEhD,KAAK,UAAU,KAAK;YACh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AAC,CAAA;IACL,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAA;IAExC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;AAClD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samcan",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "canvas",
5
5
  "license": "MIT",
6
6
  "author": "aquaticcalf",
@@ -17,6 +17,11 @@
17
17
  "types": "./dist/index.d.ts",
18
18
  "import": "./dist/index.js",
19
19
  "default": "./dist/index.js"
20
+ },
21
+ "./react": {
22
+ "types": "./dist/wrapper/react/index.d.ts",
23
+ "import": "./dist/wrapper/react/index.js",
24
+ "default": "./dist/wrapper/react/index.js"
20
25
  }
21
26
  },
22
27
  "files": [
@@ -25,27 +30,36 @@
25
30
  "scripts": {
26
31
  "dev": "bun index.ts",
27
32
  "build": "bun x tsc -p tsconfig.build.json",
33
+ "bundle": "bun build ./index.ts --outfile ./dist/bundle.js --target browser --format esm",
28
34
  "tsc": "tsc --noEmit",
29
35
  "fix": "biome format --write",
30
36
  "loc": "bun .scripts/cloc.ts",
31
- "prepare": "husky"
37
+ "bench": "bun .scripts/benchmark.ts",
38
+ "prepare": "husky",
39
+ "demo": "bun run build && bun run bundle && bun demo-server.ts",
40
+ "test": "bun test"
32
41
  },
33
42
  "devDependencies": {
34
- "@biomejs/biome": "^2.3.5",
35
- "@playwright/test": "^1.56.1",
43
+ "@biomejs/biome": "^2.3.6",
36
44
  "@types/bun": "^1.3.2",
37
45
  "@types/earcut": "^3.0.0",
38
46
  "@types/jsdom": "^27.0.0",
47
+ "@types/react": "18.3.1",
48
+ "@types/react-dom": "18.3.1",
39
49
  "canvas": "^3.2.0",
40
50
  "cloc": "^2.6.0-cloc",
41
51
  "husky": "^9.1.7",
42
52
  "jsdom": "^27.2.0",
43
53
  "mcp-fetch-server": "^1.0.2",
44
- "playwright": "^1.56.1",
45
54
  "typescript": "^5.9.3"
46
55
  },
56
+ "peerDependencies": {
57
+ "react": "^18.3.1",
58
+ "react-dom": "^18.3.1"
59
+ },
47
60
  "dependencies": {
48
61
  "earcut": "^3.0.2",
49
- "paper": "^0.12.18"
62
+ "paper": "^0.12.18",
63
+ "tinybench": "^5.1.0"
50
64
  }
51
65
  }
package/readme.md CHANGED
@@ -1,13 +1,96 @@
1
1
  ## samcan
2
2
 
3
+ ### what?
4
+
5
+ samcan is an animation runtime for the web, my attempt at resurrecting [Flash](https://en.wikipedia.org/wiki/Adobe_Flash)
6
+
7
+ ### install
8
+
9
+ <details open>
10
+ <summary>npm</summary>
11
+
12
+ ```bash
13
+ npm install samcan
14
+ ```
15
+ </details>
16
+
17
+ <details>
18
+ <summary>bun</summary>
19
+
20
+ ```bash
21
+ bun add samcan
22
+ ```
23
+ </details>
24
+
25
+ <details>
26
+ <summary>yarn</summary>
27
+
28
+ ```bash
29
+ yarn add samcan
30
+ ```
31
+ </details>
32
+
33
+ <details>
34
+ <summary>pnpm</summary>
35
+
36
+ ```bash
37
+ pnpm add samcan
38
+ ```
39
+ </details>
40
+
41
+ ### import
42
+
43
+ ```ts
44
+ import { AnimationRuntime } from "samcan"
45
+ ```
3
46
 
4
47
  ### lines of code
5
48
 
6
- |folder |code |empty |comments |total |
49
+ |x |code |comments |empty |total |
7
50
  |-------------|-------------|-------------|-------------|-------------|
8
- |core |8178 |1601 |3328 |13107 |
9
- |editor |0 |0 |0 |0 |
10
- |test |6204 |1594 |130 |7928 |
11
- |**total** |**14382** |**3195** |**3458** |**21035** |
51
+ |core |8187 |3333 |1604 |13124 |
52
+ |test |6383 |143 |1634 |8160 |
53
+ |**total** |**14570** |**3476** |**3238** |**21284** |
54
+
55
+ ### benchmarks
56
+
57
+ <details>
58
+ <summary>timeline</summary>
59
+
60
+ |name |ops/s |latency avg (ns) |samples |
61
+ |--------------------------------|--------------------------------|--------------------------------|--------------------------------|
62
+ |timeline-eval-10-tracks |1402671 ± 0.02% |728.05 ± 0.46% |686770 |
63
+ |timeline-eval-100-tracks |152697 ± 0.07% |6664.4 ± 0.34% |75026 |
64
+ |timeline-eval-500-tracks |33008 ± 0.13% |30691 ± 0.40% |16292 |
65
+
66
+ </details>
67
+
68
+ <details>
69
+ <summary>scene graph</summary>
70
+
71
+ |name |ops/s |latency avg (ns) |samples |
72
+ |--------------------------------|--------------------------------|--------------------------------|--------------------------------|
73
+ |scene-world-transform-1k-nodes |673175 ± 0.06% |1574.9 ± 0.70% |317474 |
74
+ |scene-world-transform-5k-nodes |821988 ± 0.05% |1284.5 ± 0.57% |389245 |
75
+
76
+ </details>
77
+
78
+ ### star history
79
+
80
+ <a href="https://www.star-history.com/#aquaticcalf/samcan&legend=bottom-right">
81
+ <picture>
82
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=aquaticcalf/samcan&theme=dark&legend=bottom-right" />
83
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=aquaticcalf/samcan&legend=bottom-right" />
84
+ <img alt="star history chart" src="https://api.star-history.com/svg?repos=aquaticcalf/samcan&legend=bottom-right" />
85
+ </picture>
86
+ </a>
87
+
88
+ ### badges
89
+
90
+ [![npm](https://img.shields.io/npm/v/samcan?style=for-the-badge&color=000000&labelColor=000000)](https://www.npmjs.com/package/samcan/)
91
+ [![license](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge&color=000000&labelColor=000000)](https://github.com/aquaticcalf/samcan/tree/dev?tab=MIT-1-ov-file)
92
+ [![typescript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&color=000000)](https://www.npmjs.com/package/samcan/)
93
+
94
+ <br/>
12
95
 
13
- ### another heading
96
+ <p align="center">built with &nbsp;<img src="https://raw.githubusercontent.com/kirodotdev/Kiro/c18e8771341281fb8c4ca46bbc41e0b2a29b5313/assets/kiro-icon.png" alt="kiro" width="20" height="20" style="vertical-align: middle;"></p>