canvasengine 2.0.1-beta.1 → 2.0.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 (212) hide show
  1. package/dist/DebugRenderer-DkjTAc48.js +1384 -0
  2. package/dist/DebugRenderer-DkjTAc48.js.map +1 -0
  3. package/dist/components/Button.d.ts +185 -0
  4. package/dist/components/Button.d.ts.map +1 -0
  5. package/dist/components/Canvas.d.ts +17 -0
  6. package/dist/components/Canvas.d.ts.map +1 -0
  7. package/dist/components/Container.d.ts +25 -0
  8. package/dist/components/Container.d.ts.map +1 -0
  9. package/dist/components/DOMContainer.d.ts +28 -0
  10. package/dist/components/DOMContainer.d.ts.map +1 -0
  11. package/dist/components/DOMElement.d.ts +54 -0
  12. package/dist/components/DOMElement.d.ts.map +1 -0
  13. package/dist/components/DOMSprite.d.ts +127 -0
  14. package/dist/components/DOMSprite.d.ts.map +1 -0
  15. package/dist/components/DisplayObject.d.ts +18 -0
  16. package/dist/components/DisplayObject.d.ts.map +1 -0
  17. package/dist/components/FocusContainer.d.ts +129 -0
  18. package/dist/components/FocusContainer.d.ts.map +1 -0
  19. package/dist/components/Graphic.d.ts +64 -0
  20. package/dist/components/Graphic.d.ts.map +1 -0
  21. package/dist/components/Joystick.d.ts +37 -0
  22. package/dist/components/Joystick.d.ts.map +1 -0
  23. package/dist/components/Mesh.d.ts +138 -0
  24. package/dist/components/Mesh.d.ts.map +1 -0
  25. package/dist/components/NineSliceSprite.d.ts +16 -0
  26. package/dist/components/NineSliceSprite.d.ts.map +1 -0
  27. package/dist/components/ParticleEmitter.d.ts +4 -0
  28. package/dist/components/ParticleEmitter.d.ts.map +1 -0
  29. package/dist/components/Scene.d.ts +2 -0
  30. package/dist/components/Scene.d.ts.map +1 -0
  31. package/dist/components/Sprite.d.ts +182 -0
  32. package/dist/components/Sprite.d.ts.map +1 -0
  33. package/dist/components/Text.d.ts +24 -0
  34. package/dist/components/Text.d.ts.map +1 -0
  35. package/dist/components/TilingSprite.d.ts +17 -0
  36. package/dist/components/TilingSprite.d.ts.map +1 -0
  37. package/dist/components/Video.d.ts +14 -0
  38. package/dist/components/Video.d.ts.map +1 -0
  39. package/dist/components/Viewport.d.ts +52 -0
  40. package/dist/components/Viewport.d.ts.map +1 -0
  41. package/dist/components/index.d.ts +20 -0
  42. package/dist/components/index.d.ts.map +1 -0
  43. package/dist/components/types/DisplayObject.d.ts +127 -0
  44. package/dist/components/types/DisplayObject.d.ts.map +1 -0
  45. package/dist/components/types/MouseEvent.d.ts +4 -0
  46. package/dist/components/types/MouseEvent.d.ts.map +1 -0
  47. package/dist/components/types/Spritesheet.d.ts +248 -0
  48. package/dist/components/types/Spritesheet.d.ts.map +1 -0
  49. package/dist/components/types/index.d.ts +4 -0
  50. package/dist/components/types/index.d.ts.map +1 -0
  51. package/dist/directives/Controls.d.ts +112 -0
  52. package/dist/directives/Controls.d.ts.map +1 -0
  53. package/dist/directives/ControlsBase.d.ts +199 -0
  54. package/dist/directives/ControlsBase.d.ts.map +1 -0
  55. package/dist/directives/Drag.d.ts +69 -0
  56. package/dist/directives/Drag.d.ts.map +1 -0
  57. package/dist/directives/Flash.d.ts +116 -0
  58. package/dist/directives/Flash.d.ts.map +1 -0
  59. package/dist/directives/FocusNavigation.d.ts +52 -0
  60. package/dist/directives/FocusNavigation.d.ts.map +1 -0
  61. package/dist/directives/FogVisibility.d.ts +47 -0
  62. package/dist/directives/FogVisibility.d.ts.map +1 -0
  63. package/dist/directives/GamepadControls.d.ts +224 -0
  64. package/dist/directives/GamepadControls.d.ts.map +1 -0
  65. package/dist/directives/JoystickControls.d.ts +171 -0
  66. package/dist/directives/JoystickControls.d.ts.map +1 -0
  67. package/dist/directives/KeyboardControls.d.ts +219 -0
  68. package/dist/directives/KeyboardControls.d.ts.map +1 -0
  69. package/dist/directives/Scheduler.d.ts +36 -0
  70. package/dist/directives/Scheduler.d.ts.map +1 -0
  71. package/dist/directives/Shake.d.ts +98 -0
  72. package/dist/directives/Shake.d.ts.map +1 -0
  73. package/dist/directives/Sound.d.ts +25 -0
  74. package/dist/directives/Sound.d.ts.map +1 -0
  75. package/dist/directives/SpriteEffects.d.ts +70 -0
  76. package/dist/directives/SpriteEffects.d.ts.map +1 -0
  77. package/dist/directives/Transition.d.ts +10 -0
  78. package/dist/directives/Transition.d.ts.map +1 -0
  79. package/dist/directives/ViewportCull.d.ts +11 -0
  80. package/dist/directives/ViewportCull.d.ts.map +1 -0
  81. package/dist/directives/ViewportFollow.d.ts +18 -0
  82. package/dist/directives/ViewportFollow.d.ts.map +1 -0
  83. package/dist/directives/index.d.ts +15 -0
  84. package/dist/directives/index.d.ts.map +1 -0
  85. package/dist/dist-BOOc43Qm.js +778 -0
  86. package/dist/dist-BOOc43Qm.js.map +1 -0
  87. package/dist/engine/FocusManager.d.ts +174 -0
  88. package/dist/engine/FocusManager.d.ts.map +1 -0
  89. package/dist/engine/animation.d.ts +72 -0
  90. package/dist/engine/animation.d.ts.map +1 -0
  91. package/dist/engine/bootstrap.d.ts +52 -0
  92. package/dist/engine/bootstrap.d.ts.map +1 -0
  93. package/dist/engine/directive.d.ts +13 -0
  94. package/dist/engine/directive.d.ts.map +1 -0
  95. package/dist/engine/reactive.d.ts +139 -0
  96. package/dist/engine/reactive.d.ts.map +1 -0
  97. package/dist/engine/signal.d.ts +74 -0
  98. package/dist/engine/signal.d.ts.map +1 -0
  99. package/dist/engine/trigger.d.ts +54 -0
  100. package/dist/engine/trigger.d.ts.map +1 -0
  101. package/dist/engine/utils.d.ts +89 -0
  102. package/dist/engine/utils.d.ts.map +1 -0
  103. package/dist/hooks/addContext.d.ts +2 -0
  104. package/dist/hooks/addContext.d.ts.map +1 -0
  105. package/dist/hooks/useFocus.d.ts +60 -0
  106. package/dist/hooks/useFocus.d.ts.map +1 -0
  107. package/dist/hooks/useProps.d.ts +53 -0
  108. package/dist/hooks/useProps.d.ts.map +1 -0
  109. package/dist/hooks/useRef.d.ts +4 -0
  110. package/dist/hooks/useRef.d.ts.map +1 -0
  111. package/dist/index.d.ts +19 -844
  112. package/dist/index.d.ts.map +1 -0
  113. package/dist/index.global.js +189 -0
  114. package/dist/index.global.js.map +1 -0
  115. package/dist/index.js +15156 -3287
  116. package/dist/index.js.map +1 -1
  117. package/dist/utils/Ease.d.ts +17 -0
  118. package/dist/utils/Ease.d.ts.map +1 -0
  119. package/dist/utils/GlobalAssetLoader.d.ts +141 -0
  120. package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
  121. package/dist/utils/RadialGradient.d.ts +57 -0
  122. package/dist/utils/RadialGradient.d.ts.map +1 -0
  123. package/dist/utils/functions.d.ts +2 -0
  124. package/dist/utils/functions.d.ts.map +1 -0
  125. package/dist/utils/tabindex.d.ts +16 -0
  126. package/dist/utils/tabindex.d.ts.map +1 -0
  127. package/index.d.ts +1 -3
  128. package/package.json +19 -52
  129. package/src/components/Button.ts +406 -0
  130. package/src/components/Canvas.ts +82 -51
  131. package/src/components/Container.ts +31 -4
  132. package/src/components/DOMContainer.ts +387 -0
  133. package/src/components/DOMElement.ts +556 -0
  134. package/src/components/DOMSprite.ts +1044 -0
  135. package/src/components/DisplayObject.ts +423 -202
  136. package/src/components/FocusContainer.ts +368 -0
  137. package/src/components/Graphic.ts +255 -68
  138. package/src/components/Joystick.ts +269 -0
  139. package/src/components/Mesh.ts +239 -0
  140. package/src/components/NineSliceSprite.ts +4 -1
  141. package/src/components/ParticleEmitter.ts +12 -8
  142. package/src/components/Sprite.ts +441 -54
  143. package/src/components/Text.ts +270 -26
  144. package/src/components/Video.ts +110 -0
  145. package/src/components/Viewport.ts +122 -63
  146. package/src/components/index.ts +12 -5
  147. package/src/components/types/DisplayObject.ts +64 -5
  148. package/src/components/types/Spritesheet.ts +0 -118
  149. package/src/directives/Controls.ts +254 -0
  150. package/src/directives/ControlsBase.ts +267 -0
  151. package/src/directives/Drag.ts +357 -52
  152. package/src/directives/Flash.ts +419 -0
  153. package/src/directives/FocusNavigation.ts +113 -0
  154. package/src/directives/FogVisibility.ts +273 -0
  155. package/src/directives/GamepadControls.ts +537 -0
  156. package/src/directives/JoystickControls.ts +396 -0
  157. package/src/directives/KeyboardControls.ts +86 -431
  158. package/src/directives/Scheduler.ts +21 -16
  159. package/src/directives/Shake.ts +298 -0
  160. package/src/directives/Sound.ts +94 -31
  161. package/src/directives/SpriteEffects.ts +461 -0
  162. package/src/directives/ViewportFollow.ts +40 -9
  163. package/src/directives/index.ts +14 -6
  164. package/src/engine/FocusManager.ts +510 -0
  165. package/src/engine/animation.ts +175 -21
  166. package/src/engine/bootstrap.ts +140 -6
  167. package/src/engine/directive.ts +4 -4
  168. package/src/engine/reactive.ts +1266 -167
  169. package/src/engine/signal.ts +335 -47
  170. package/src/engine/trigger.ts +95 -12
  171. package/src/engine/utils.ts +101 -9
  172. package/src/hooks/useFocus.ts +91 -0
  173. package/src/hooks/useProps.ts +92 -7
  174. package/src/index.ts +13 -6
  175. package/src/types/pixi-cull.d.ts +7 -0
  176. package/src/utils/GlobalAssetLoader.ts +257 -0
  177. package/src/utils/RadialGradient.ts +29 -0
  178. package/src/utils/functions.ts +7 -0
  179. package/src/utils/tabindex.ts +70 -0
  180. package/testing/index.ts +42 -0
  181. package/tsconfig.json +15 -25
  182. package/vite.config.ts +39 -0
  183. package/.cursorrules +0 -0
  184. package/.github/workflows/ci.yml +0 -29
  185. package/README.md +0 -79
  186. package/dist/compiler/vite.js +0 -119
  187. package/dist/compiler/vite.js.map +0 -1
  188. package/logo.png +0 -0
  189. package/src/compiler/grammar.pegjs +0 -180
  190. package/src/compiler/vite.ts +0 -166
  191. package/src/components/DrawMap/index.ts +0 -65
  192. package/src/components/Tilemap/Tile.ts +0 -79
  193. package/src/components/Tilemap/TileGroup.ts +0 -207
  194. package/src/components/Tilemap/TileLayer.ts +0 -163
  195. package/src/components/Tilemap/TileSet.ts +0 -41
  196. package/src/components/Tilemap/index.ts +0 -80
  197. package/src/presets/Bar.ts +0 -89
  198. package/src/presets/Button.ts +0 -0
  199. package/src/presets/Joystick.ts +0 -286
  200. package/src/presets/NightAmbiant.ts +0 -122
  201. package/src/presets/Particle.ts +0 -53
  202. package/starter/assets/logo.png +0 -0
  203. package/starter/components/app.ce +0 -18
  204. package/starter/components/hello.ce +0 -35
  205. package/starter/index.html +0 -21
  206. package/starter/main.ts +0 -6
  207. package/starter/package.json +0 -20
  208. package/starter/tsconfig.json +0 -32
  209. package/starter/vite.config.ts +0 -12
  210. package/tsconfig.node.json +0 -10
  211. package/tsup.config.ts +0 -28
  212. package/vitest.config.ts +0 -12
@@ -1,122 +0,0 @@
1
- import { Container, Graphics } from "../components";
2
- import { h, mount } from "../engine/signal";
3
- import { animatedSignal } from "../engine/animation";
4
- import { RadialGradient } from "../utils/RadialGradient";
5
- import { effect, isSignal, signal } from "@signe/reactive";
6
- import { useProps } from "../hooks/useProps";
7
- import { isObservable } from "rxjs";
8
-
9
- export function LightSpot(opts) {
10
- const { radius } = useProps(opts);
11
- const scale = animatedSignal(1);
12
-
13
- const minScale = 1;
14
- const maxScale = 2; // Reduced max scale for subtler effect
15
- const scintillationSpeed = 0.001; // Significantly reduced for slower scintillation
16
-
17
- const animate = () => {
18
- // Use time-based animation for smoother, slower scintillation
19
- const time = Date.now() * scintillationSpeed;
20
-
21
- // Combine multiple sine waves for a more natural, less predictable effect
22
- const scintillationFactor =
23
- (Math.sin(time) + Math.sin(time * 1.3) + Math.sin(time * 0.7)) / 3;
24
-
25
- // Map the scintillation factor to the scale range
26
- const newScale =
27
- minScale + (maxScale - minScale) * (scintillationFactor * 0.5 + 0.5);
28
-
29
- scale.update(() => newScale);
30
-
31
- requestAnimationFrame(animate);
32
- };
33
-
34
- animate();
35
-
36
- const draw = (g) => {
37
- const size = radius() * 2;
38
- const gradient = new RadialGradient(size, size, 0, size, size, 0);
39
- gradient.addColorStop(0, "rgba(255, 255, 0, 1)");
40
- gradient.addColorStop(0.5, "rgba(255, 255, 0, 0.3)");
41
- gradient.addColorStop(0.8, "rgba(255, 255, 0, 0)");
42
-
43
- const translate = size / 2;
44
-
45
- g.rect(-translate, -translate, size, size).fill(
46
- gradient.render({ translate: { x: translate, y: translate } })
47
- );
48
- };
49
-
50
- return h(Graphics, {
51
- draw,
52
- ...opts,
53
- scale,
54
- });
55
- }
56
-
57
- export function NightAmbiant(props) {
58
- const { children } = props;
59
- let el
60
- const width = signal(0);
61
- const height = signal(0);
62
- let subscription
63
- const draw = (rectAndHole) => {
64
- const margin = 80
65
- rectAndHole.rect(-margin, -margin, width() + margin*2, height() + margin*2);
66
- rectAndHole.fill(0x000000);
67
- const applyChildren = (child) => {
68
- const x = isSignal(child.propObservables.x)
69
- ? child.propObservables.x()
70
- : child.props.x;
71
- const y = isSignal(child.propObservables.y)
72
- ? child.propObservables.y()
73
- : child.props.y;
74
- const radius = isSignal(child.propObservables.radius)
75
- ? child.propObservables.radius()
76
- : child.props.radius;
77
- rectAndHole.circle(x, y, radius);
78
- rectAndHole.cut();
79
- }
80
- for (let child of children) {
81
- if (isObservable(child)) {
82
- if (subscription) {
83
- subscription.unsubscribe()
84
- }
85
- subscription = child.subscribe((event) => {
86
- for (let child of event.fullElements) {
87
- applyChildren(child)
88
- }
89
- })
90
- return
91
- }
92
- applyChildren(child)
93
- }
94
- };
95
-
96
- mount((el) => {
97
- effect(() => {
98
- const { displayWidth, displayHeight } = el.componentInstance
99
- const w = +displayWidth()
100
- const h = +displayHeight()
101
- setTimeout(() => {
102
- width.update(() => w)
103
- height.update(() => h)
104
- }, 0) // hack
105
- });
106
- });
107
-
108
- return h(
109
- Container,
110
- {
111
- width: "100%",
112
- height: "100%",
113
- ...props,
114
- },
115
- h(Graphics, {
116
- draw,
117
- alpha: 0.8,
118
- blur: 80,
119
- }),
120
- ...children
121
- );
122
- }
@@ -1,53 +0,0 @@
1
- import * as PIXI from "pixi.js";
2
- import { FX } from "revolt-fx";
3
- import { h, mount, tick } from "../engine/signal";
4
- import { Container } from "../components";
5
- import { on } from "../engine/trigger";
6
- import { useProps } from "../hooks/useProps";
7
-
8
- export function Particle(options) {
9
- const { emit, settings = {} } = options;
10
- const { name } = useProps(options);
11
- const fx = new FX();
12
- let element;
13
-
14
- PIXI.Assets.add({ alias: "fx_settings", src: "/default-bundle.json" });
15
- PIXI.Assets.add({
16
- alias: "fx_spritesheet",
17
- src: "/revoltfx-spritesheet.json",
18
- });
19
-
20
- tick(({deltaRatio}) => {
21
- fx.update(deltaRatio);
22
- });
23
-
24
- mount(async (_element) => {
25
- element = _element;
26
-
27
- const data = await PIXI.Assets.load(["fx_settings", "fx_spritesheet"]);
28
- let fxSettings = {...data.fx_settings};
29
-
30
- if (settings.emitters) {
31
- const lastId = 10000;
32
- const emittersWithIds = settings.emitters.map((emitter, index) => ({
33
- ...emitter,
34
- id: lastId + index
35
- }));
36
-
37
- fxSettings.emitters = [
38
- ...fxSettings.emitters,
39
- ...emittersWithIds,
40
- ];
41
-
42
- }
43
-
44
- fx.initBundle(fxSettings, true);
45
- });
46
-
47
- on(emit, () => {
48
- const emitter = fx.getParticleEmitter(name());
49
- emitter.init(element.componentInstance);
50
- });
51
-
52
- return h(Container);
53
- }
Binary file
@@ -1,18 +0,0 @@
1
- <Canvas
2
- backgroundColor="#fff"
3
- width="100%"
4
- height="100%"
5
- antialias="true"
6
- >
7
- <Container
8
- width="100%"
9
- height="100%"
10
- justifyContent="center"
11
- alignItems="center">
12
- <HelloWorld text="CanvasEngine" />
13
- </Container>
14
- </Canvas>
15
-
16
- <script>
17
- import HelloWorld from "./hello.ce";
18
- </script>
@@ -1,35 +0,0 @@
1
- <Container flexDirection="column" width="500px">
2
- <Sprite
3
- image={imgUrl}
4
- anchor="0.5"
5
- rotation
6
- scale
7
- @pointerenter={onEnter}
8
- @pointerleave={onLeave}
9
- />
10
- <Text text size="70" fontFamily="Helvetica" x="90" y="-30" />
11
- </Container>
12
-
13
- <script>
14
- import imgUrl from '../assets/logo.png'
15
- import { signal, tick, animatedSignal, Easing } from "canvasengine";
16
-
17
- const { text } = defineProps();
18
- const rotation = signal(0);
19
- const scale = animatedSignal(1, {
20
- duration: 300,
21
- ease: Easing.easeInOut,
22
- });
23
-
24
- tick(() => {
25
- rotation.update(rotation => rotation + 0.01);
26
- });
27
-
28
- const onEnter = () => {
29
- scale.set(1.5);
30
- };
31
-
32
- const onLeave = () => {
33
- scale.set(1);
34
- };
35
- </script>
@@ -1,21 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>Canvas Engine</title>
7
- <style>
8
- body, html, #root {
9
- margin: 0;
10
- padding: 0;
11
- height: 100vh;
12
- width: 100vw;
13
- overflow: hidden;
14
- }
15
- </style>
16
- </head>
17
- <body>
18
- <div id="root"></div>
19
- <script type="module" src="/main.ts"></script>
20
- </body>
21
- </html>
package/starter/main.ts DELETED
@@ -1,6 +0,0 @@
1
- import App from './components/app.ce'
2
- import { bootstrapCanvas } from 'canvasengine';
3
-
4
- bootstrapCanvas(document.getElementById("root"), App).then(() => {
5
- console.log("CanvasEngine initialized");
6
- });
@@ -1,20 +0,0 @@
1
- {
2
- "name": "canvasengine-starter",
3
- "version": "1.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vite build"
9
- },
10
- "keywords": [],
11
- "author": "",
12
- "license": "ISC",
13
- "type": "module",
14
- "dependencies": {
15
- "canvasengine": "2.0.1-beta.1"
16
- },
17
- "devDependencies": {
18
- "vite": "^6.0.3"
19
- }
20
- }
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2020",
4
- "module": "esnext",
5
- "outDir": "dist",
6
- "strict": true,
7
- "sourceMap": true,
8
- "strictNullChecks": true,
9
- "strictPropertyInitialization": false,
10
- "moduleResolution": "node",
11
- "esModuleInterop": true,
12
- "removeComments": false,
13
- "noUnusedParameters": false,
14
- "noUnusedLocals": false,
15
- "noImplicitThis": false,
16
- "noImplicitAny": false,
17
- "noImplicitReturns": false,
18
- "declaration": false,
19
- "experimentalDecorators": true,
20
- "emitDecoratorMetadata": true,
21
- "types": [
22
- "node",
23
- "vite/client"
24
- ],
25
- "resolveJsonModule": true
26
- },
27
- "include": [
28
- ".",
29
- "index.d.ts",
30
- "node_modules/canvasengine/index.d.ts"
31
- ]
32
- }
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'vite'
2
- import vitePluginCe from 'canvasengine/compiler'
3
-
4
- // https://vitejs.dev/config/
5
- export default defineConfig({
6
- plugins: [vitePluginCe()],
7
- resolve: {
8
- alias: {
9
- path: 'rollup-plugin-node-polyfills/polyfills/path',
10
- }
11
- }
12
- });
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "skipLibCheck": true,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "allowSyntheticDefaultImports": true
8
- },
9
- "include": ["vite.config.ts"]
10
- }
package/tsup.config.ts DELETED
@@ -1,28 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default [
4
- defineConfig({
5
- format: ['esm'],
6
- target: 'es2020',
7
- splitting: true,
8
- clean: true,
9
- shims: false,
10
- dts: true,
11
- sourcemap: true,
12
- entry: ['src/index.ts'],
13
- outDir: 'dist'
14
- }),
15
-
16
- defineConfig({
17
- format: ['esm'],
18
- target: 'node20',
19
- splitting: true,
20
- clean: false,
21
- shims: false,
22
- dts: true,
23
- sourcemap: true,
24
- entry: ['src/compiler/vite.ts'],
25
- outDir: 'dist/compiler',
26
- external: ['vite', 'acorn', 'peggy', 'typescript'],
27
- })
28
- ]
package/vitest.config.ts DELETED
@@ -1,12 +0,0 @@
1
- /// <reference types="vitest" />
2
- import { defineConfig } from 'vite'
3
-
4
- export default defineConfig(async () => {
5
- return {
6
- test: {
7
- environment: 'jsdom',
8
- pool: 'forks',
9
- setupFiles: ['./tests/setup/canvas.ts']
10
- }
11
- }
12
- })