canvasengine 1.3.0 → 2.0.1-beta.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 (125) hide show
  1. package/.cursorrules +0 -0
  2. package/.github/workflows/ci.yml +29 -0
  3. package/README.md +79 -0
  4. package/dist/compiler/vite.js +119 -0
  5. package/dist/compiler/vite.js.map +1 -0
  6. package/dist/index.d.ts +846 -0
  7. package/dist/index.js +3340 -0
  8. package/dist/index.js.map +1 -0
  9. package/index.d.ts +6 -0
  10. package/logo.png +0 -0
  11. package/package.json +84 -18
  12. package/src/compiler/grammar.pegjs +180 -0
  13. package/src/compiler/vite.ts +166 -0
  14. package/src/components/Canvas.ts +134 -0
  15. package/src/components/Container.ts +46 -0
  16. package/src/components/DisplayObject.ts +458 -0
  17. package/src/components/DrawMap/index.ts +65 -0
  18. package/src/components/Graphic.ts +147 -0
  19. package/src/components/NineSliceSprite.ts +46 -0
  20. package/src/components/ParticleEmitter.ts +39 -0
  21. package/src/components/Scene.ts +6 -0
  22. package/src/components/Sprite.ts +493 -0
  23. package/src/components/Text.ts +145 -0
  24. package/src/components/Tilemap/Tile.ts +79 -0
  25. package/src/components/Tilemap/TileGroup.ts +207 -0
  26. package/src/components/Tilemap/TileLayer.ts +163 -0
  27. package/src/components/Tilemap/TileSet.ts +41 -0
  28. package/src/components/Tilemap/index.ts +80 -0
  29. package/src/components/TilingSprite.ts +39 -0
  30. package/src/components/Viewport.ts +159 -0
  31. package/src/components/index.ts +12 -0
  32. package/src/components/types/DisplayObject.ts +68 -0
  33. package/src/components/types/MouseEvent.ts +3 -0
  34. package/src/components/types/Spritesheet.ts +389 -0
  35. package/src/components/types/index.ts +4 -0
  36. package/src/directives/Drag.ts +84 -0
  37. package/src/directives/KeyboardControls.ts +922 -0
  38. package/src/directives/Scheduler.ts +112 -0
  39. package/src/directives/Sound.ts +91 -0
  40. package/src/directives/Transition.ts +45 -0
  41. package/src/directives/ViewportCull.ts +40 -0
  42. package/src/directives/ViewportFollow.ts +26 -0
  43. package/src/directives/index.ts +7 -0
  44. package/src/engine/animation.ts +113 -0
  45. package/src/engine/bootstrap.ts +19 -0
  46. package/src/engine/directive.ts +23 -0
  47. package/src/engine/reactive.ts +379 -0
  48. package/src/engine/signal.ts +138 -0
  49. package/src/engine/trigger.ts +40 -0
  50. package/src/engine/utils.ts +135 -0
  51. package/src/hooks/addContext.ts +6 -0
  52. package/src/hooks/useProps.ts +155 -0
  53. package/src/hooks/useRef.ts +21 -0
  54. package/src/index.ts +14 -0
  55. package/src/presets/Bar.ts +89 -0
  56. package/src/presets/Button.ts +0 -0
  57. package/src/presets/Joystick.ts +286 -0
  58. package/src/presets/NightAmbiant.ts +122 -0
  59. package/src/presets/Particle.ts +53 -0
  60. package/src/utils/Ease.ts +33 -0
  61. package/src/utils/RadialGradient.ts +86 -0
  62. package/starter/assets/logo.png +0 -0
  63. package/starter/components/app.ce +18 -0
  64. package/starter/components/hello.ce +35 -0
  65. package/starter/index.html +21 -0
  66. package/starter/main.ts +6 -0
  67. package/starter/package.json +20 -0
  68. package/starter/tsconfig.json +32 -0
  69. package/starter/vite.config.ts +12 -0
  70. package/tsconfig.json +32 -0
  71. package/tsconfig.node.json +10 -0
  72. package/tsup.config.ts +28 -0
  73. package/vitest.config.ts +12 -0
  74. package/.gitattributes +0 -22
  75. package/.npmignore +0 -163
  76. package/canvasengine-1.3.0.all.min.js +0 -21
  77. package/canvasengine.js +0 -5802
  78. package/core/DB.js +0 -24
  79. package/core/ModelServer.js +0 -348
  80. package/core/Users.js +0 -190
  81. package/core/engine-common.js +0 -952
  82. package/doc/cocoonjs.md +0 -36
  83. package/doc/doc-lang.yml +0 -43
  84. package/doc/doc-router.yml +0 -14
  85. package/doc/doc-tuto.yml +0 -9
  86. package/doc/doc.yml +0 -39
  87. package/doc/element.md +0 -37
  88. package/doc/entity.md +0 -90
  89. package/doc/extend.md +0 -47
  90. package/doc/get_started.md +0 -19
  91. package/doc/images/entity.png +0 -0
  92. package/doc/multitouch.md +0 -58
  93. package/doc/nodejs.md +0 -142
  94. package/doc/scene.md +0 -44
  95. package/doc/text.md +0 -156
  96. package/examples/server/client.html +0 -31
  97. package/examples/server/server.js +0 -16
  98. package/examples/tiled_server/client.html +0 -52
  99. package/examples/tiled_server/images/tiles_spritesheet.png +0 -0
  100. package/examples/tiled_server/server/map.json +0 -50
  101. package/examples/tiled_server/server/map.tmx +0 -16
  102. package/examples/tiled_server/server/server.js +0 -16
  103. package/extends/Animation.js +0 -910
  104. package/extends/Effect.js +0 -252
  105. package/extends/Gleed2d.js +0 -252
  106. package/extends/Hit.js +0 -1509
  107. package/extends/Input.js +0 -699
  108. package/extends/Marshal.js +0 -716
  109. package/extends/Scrolling.js +0 -388
  110. package/extends/Soundmanager2.js +0 -5466
  111. package/extends/Spritesheet.js +0 -196
  112. package/extends/Text.js +0 -366
  113. package/extends/Tiled.js +0 -403
  114. package/extends/Window.js +0 -575
  115. package/extends/gamepad.js +0 -397
  116. package/extends/socket.io.min.js +0 -2
  117. package/extends/swf/soundmanager2.swf +0 -0
  118. package/extends/swf/soundmanager2_debug.swf +0 -0
  119. package/extends/swf/soundmanager2_flash9.swf +0 -0
  120. package/extends/swf/soundmanager2_flash9_debug.swf +0 -0
  121. package/extends/swf/soundmanager2_flash_xdomain.zip +0 -0
  122. package/extends/workers/transition.js +0 -43
  123. package/index.js +0 -46
  124. package/license.txt +0 -19
  125. package/readme.md +0 -483
@@ -0,0 +1,53 @@
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
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ linear,
3
+ easeIn,
4
+ easeInOut,
5
+ easeOut,
6
+ circIn,
7
+ circInOut,
8
+ circOut,
9
+ backIn,
10
+ backInOut,
11
+ backOut,
12
+ anticipate,
13
+ bounceIn,
14
+ bounceInOut,
15
+ bounceOut
16
+ } from "popmotion"
17
+
18
+ export const Easing = {
19
+ linear,
20
+ easeIn,
21
+ easeInOut,
22
+ easeOut,
23
+ circIn,
24
+ circInOut,
25
+ circOut,
26
+ backIn,
27
+ backInOut,
28
+ backOut,
29
+ anticipate,
30
+ bounceIn,
31
+ bounceInOut,
32
+ bounceOut
33
+ }
@@ -0,0 +1,86 @@
1
+ import { Texture, ImageSource, DOMAdapter, Matrix } from "pixi.js";
2
+
3
+ export class RadialGradient {
4
+ private canvas: HTMLCanvasElement;
5
+ private ctx: CanvasRenderingContext2D | null;
6
+ private gradient: CanvasGradient | null = null;
7
+ private texture: Texture | null = null;
8
+ public transform: Matrix;
9
+
10
+ public size = 600;
11
+
12
+ constructor(
13
+ private x0: number,
14
+ private y0: number,
15
+ private x1: number,
16
+ private y1: number,
17
+ private x2: number,
18
+ private y2: number,
19
+ private focalPoint: number = 0
20
+ ) {
21
+ this.size = x0;
22
+ const halfSize = this.size * 0.5;
23
+
24
+ this.canvas = DOMAdapter.get().createCanvas() as any;
25
+ this.canvas.width = this.size;
26
+ this.canvas.height = this.size;
27
+ this.ctx = this.canvas.getContext("2d");
28
+
29
+ if (this.ctx) {
30
+ this.gradient = this.ctx.createRadialGradient(
31
+ halfSize * (1 - focalPoint),
32
+ halfSize,
33
+ 0,
34
+ halfSize,
35
+ halfSize,
36
+ halfSize - 0.5
37
+ );
38
+ }
39
+ }
40
+
41
+ addColorStop(offset: number, color: string) {
42
+ if (this.gradient) {
43
+ this.gradient.addColorStop(offset, color);
44
+ }
45
+ }
46
+
47
+ render({ translate }: { translate?: { x: number; y: number } } = {}) {
48
+ const { x0, y0, x1, y1, x2, y2, focalPoint } = this;
49
+ const defaultSize = this.size;
50
+ if (this.ctx && this.gradient) {
51
+ this.ctx.fillStyle = this.gradient;
52
+ this.ctx.fillRect(0, 0, defaultSize, defaultSize);
53
+
54
+ this.texture = new Texture({
55
+ source: new ImageSource({
56
+ resource: this.canvas,
57
+ addressModeU: "clamp-to-edge",
58
+ addressModeV: "clamp-to-edge",
59
+ }),
60
+ });
61
+
62
+ const m = new Matrix();
63
+ const dx = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
64
+ const dy = Math.sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
65
+ const angle = Math.atan2(y1 - y0, x1 - x0);
66
+
67
+ // Calculate the scale factors correctly
68
+ const scaleX = dx / defaultSize;
69
+ const scaleY = dy / defaultSize;
70
+
71
+ // Apply transformations in the correct order
72
+ m.rotate(-angle);
73
+ m.scale(scaleX, scaleY);
74
+ if (translate) {
75
+ m.translate(translate.x, translate.y);
76
+ }
77
+
78
+ this.transform = m;
79
+ }
80
+
81
+ return {
82
+ texture: this.texture,
83
+ matrix: this.transform,
84
+ };
85
+ }
86
+ }
Binary file
@@ -0,0 +1,18 @@
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>
@@ -0,0 +1,35 @@
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>
@@ -0,0 +1,21 @@
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>
@@ -0,0 +1,6 @@
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
+ });
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,32 @@
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
+ }
@@ -0,0 +1,12 @@
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
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": ["dom", "esnext"],
5
+ "module": "ES2020",
6
+ "outDir": "./lib",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "sourceMap": true,
10
+ "strictNullChecks": true,
11
+ "strictPropertyInitialization": false,
12
+ "moduleResolution": "Bundler",
13
+ "esModuleInterop": true,
14
+ "removeComments": false,
15
+ "noUnusedParameters": false,
16
+ "noUnusedLocals": false,
17
+ "noImplicitThis": false,
18
+ "noImplicitAny": false,
19
+ "noImplicitReturns": false,
20
+ "declaration": true,
21
+ "experimentalDecorators": true,
22
+ "emitDecoratorMetadata": true,
23
+ "stripInternal": true,
24
+ "skipLibCheck": true,
25
+ "types": ["node"]
26
+ },
27
+ "include": [
28
+ "src",
29
+ "sample"
30
+ ],
31
+
32
+ }
@@ -0,0 +1,10 @@
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 ADDED
@@ -0,0 +1,28 @@
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
+ ]
@@ -0,0 +1,12 @@
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
+ })
package/.gitattributes DELETED
@@ -1,22 +0,0 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
3
-
4
- # Custom for Visual Studio
5
- *.cs diff=csharp
6
- *.sln merge=union
7
- *.csproj merge=union
8
- *.vbproj merge=union
9
- *.fsproj merge=union
10
- *.dbproj merge=union
11
-
12
- # Standard to msysgit
13
- *.doc diff=astextplain
14
- *.DOC diff=astextplain
15
- *.docx diff=astextplain
16
- *.DOCX diff=astextplain
17
- *.dot diff=astextplain
18
- *.DOT diff=astextplain
19
- *.pdf diff=astextplain
20
- *.PDF diff=astextplain
21
- *.rtf diff=astextplain
22
- *.RTF diff=astextplain
package/.npmignore DELETED
@@ -1,163 +0,0 @@
1
- #################
2
- ## Eclipse
3
- #################
4
-
5
- *.pydevproject
6
- .project
7
- .metadata
8
- bin/
9
- tmp/
10
- *.tmp
11
- *.bak
12
- *.swp
13
- *~.nib
14
- local.properties
15
- .classpath
16
- .settings/
17
- .loadpath
18
-
19
- # External tool builders
20
- .externalToolBuilders/
21
-
22
- # Locally stored "Eclipse launch configurations"
23
- *.launch
24
-
25
- # CDT-specific
26
- .cproject
27
-
28
- # PDT-specific
29
- .buildpath
30
-
31
-
32
- #################
33
- ## Visual Studio
34
- #################
35
-
36
- ## Ignore Visual Studio temporary files, build results, and
37
- ## files generated by popular Visual Studio add-ons.
38
-
39
- # User-specific files
40
- *.suo
41
- *.user
42
- *.sln.docstates
43
-
44
- # Build results
45
- [Dd]ebug/
46
- [Rr]elease/
47
- *_i.c
48
- *_p.c
49
- *.ilk
50
- *.meta
51
- *.obj
52
- *.pch
53
- *.pdb
54
- *.pgc
55
- *.pgd
56
- *.rsp
57
- *.sbr
58
- *.tlb
59
- *.tli
60
- *.tlh
61
- *.tmp
62
- *.vspscc
63
- .builds
64
- *.dotCover
65
-
66
- ## TODO: If you have NuGet Package Restore enabled, uncomment this
67
- #packages/
68
-
69
- # Visual C++ cache files
70
- ipch/
71
- *.aps
72
- *.ncb
73
- *.opensdf
74
- *.sdf
75
-
76
- # Visual Studio profiler
77
- *.psess
78
- *.vsp
79
-
80
- # ReSharper is a .NET coding add-in
81
- _ReSharper*
82
-
83
- # Installshield output folder
84
- [Ee]xpress
85
-
86
- # DocProject is a documentation generator add-in
87
- DocProject/buildhelp/
88
- DocProject/Help/*.HxT
89
- DocProject/Help/*.HxC
90
- DocProject/Help/*.hhc
91
- DocProject/Help/*.hhk
92
- DocProject/Help/*.hhp
93
- DocProject/Help/Html2
94
- DocProject/Help/html
95
-
96
- # Click-Once directory
97
- publish
98
-
99
- # Others
100
- [Bb]in
101
- [Oo]bj
102
- sql
103
- TestResults
104
- *.Cache
105
- ClientBin
106
- stylecop.*
107
- ~$*
108
- *.dbmdl
109
- Generated_Code #added for RIA/Silverlight projects
110
-
111
- # Backup & report files from converting an old project file to a newer
112
- # Visual Studio version. Backup files are not needed, because we have git ;-)
113
- _UpgradeReport_Files/
114
- Backup*/
115
- UpgradeLog*.XML
116
-
117
-
118
-
119
- ############
120
- ## Windows
121
- ############
122
-
123
- # Windows image file caches
124
- Thumbs.db
125
-
126
- # Folder config file
127
- Desktop.ini
128
-
129
-
130
- #############
131
- ## Python
132
- #############
133
-
134
- *.py[co]
135
-
136
- # Packages
137
- *.egg
138
- *.egg-info
139
- dist
140
- build
141
- eggs
142
- parts
143
- bin
144
- var
145
- sdist
146
- develop-eggs
147
- .installed.cfg
148
-
149
- # Installer logs
150
- pip-log.txt
151
-
152
- # Unit test / coverage reports
153
- .coverage
154
- .tox
155
-
156
- #Translations
157
- *.mo
158
-
159
- #Mr Developer
160
- .mr.developer.cfg
161
-
162
- # Mac crap
163
- .DS_Store