canvasengine 2.0.1-beta.2 → 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.
- package/dist/DebugRenderer-DkjTAc48.js +1384 -0
- package/dist/DebugRenderer-DkjTAc48.js.map +1 -0
- package/dist/components/Button.d.ts +185 -0
- package/dist/components/Button.d.ts.map +1 -0
- package/dist/components/Canvas.d.ts +17 -0
- package/dist/components/Canvas.d.ts.map +1 -0
- package/dist/components/Container.d.ts +25 -0
- package/dist/components/Container.d.ts.map +1 -0
- package/dist/components/DOMContainer.d.ts +28 -0
- package/dist/components/DOMContainer.d.ts.map +1 -0
- package/dist/components/DOMElement.d.ts +54 -0
- package/dist/components/DOMElement.d.ts.map +1 -0
- package/dist/components/DOMSprite.d.ts +127 -0
- package/dist/components/DOMSprite.d.ts.map +1 -0
- package/dist/components/DisplayObject.d.ts +18 -0
- package/dist/components/DisplayObject.d.ts.map +1 -0
- package/dist/components/FocusContainer.d.ts +129 -0
- package/dist/components/FocusContainer.d.ts.map +1 -0
- package/dist/components/Graphic.d.ts +64 -0
- package/dist/components/Graphic.d.ts.map +1 -0
- package/dist/components/Joystick.d.ts +37 -0
- package/dist/components/Joystick.d.ts.map +1 -0
- package/dist/components/Mesh.d.ts +138 -0
- package/dist/components/Mesh.d.ts.map +1 -0
- package/dist/components/NineSliceSprite.d.ts +16 -0
- package/dist/components/NineSliceSprite.d.ts.map +1 -0
- package/dist/components/ParticleEmitter.d.ts +4 -0
- package/dist/components/ParticleEmitter.d.ts.map +1 -0
- package/dist/components/Scene.d.ts +2 -0
- package/dist/components/Scene.d.ts.map +1 -0
- package/dist/components/Sprite.d.ts +182 -0
- package/dist/components/Sprite.d.ts.map +1 -0
- package/dist/components/Text.d.ts +24 -0
- package/dist/components/Text.d.ts.map +1 -0
- package/dist/components/TilingSprite.d.ts +17 -0
- package/dist/components/TilingSprite.d.ts.map +1 -0
- package/dist/components/Video.d.ts +14 -0
- package/dist/components/Video.d.ts.map +1 -0
- package/dist/components/Viewport.d.ts +52 -0
- package/dist/components/Viewport.d.ts.map +1 -0
- package/dist/components/index.d.ts +20 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/types/DisplayObject.d.ts +127 -0
- package/dist/components/types/DisplayObject.d.ts.map +1 -0
- package/dist/components/types/MouseEvent.d.ts +4 -0
- package/dist/components/types/MouseEvent.d.ts.map +1 -0
- package/dist/components/types/Spritesheet.d.ts +248 -0
- package/dist/components/types/Spritesheet.d.ts.map +1 -0
- package/dist/components/types/index.d.ts +4 -0
- package/dist/components/types/index.d.ts.map +1 -0
- package/dist/directives/Controls.d.ts +112 -0
- package/dist/directives/Controls.d.ts.map +1 -0
- package/dist/directives/ControlsBase.d.ts +199 -0
- package/dist/directives/ControlsBase.d.ts.map +1 -0
- package/dist/directives/Drag.d.ts +69 -0
- package/dist/directives/Drag.d.ts.map +1 -0
- package/dist/directives/Flash.d.ts +116 -0
- package/dist/directives/Flash.d.ts.map +1 -0
- package/dist/directives/FocusNavigation.d.ts +52 -0
- package/dist/directives/FocusNavigation.d.ts.map +1 -0
- package/dist/directives/FogVisibility.d.ts +47 -0
- package/dist/directives/FogVisibility.d.ts.map +1 -0
- package/dist/directives/GamepadControls.d.ts +224 -0
- package/dist/directives/GamepadControls.d.ts.map +1 -0
- package/dist/directives/JoystickControls.d.ts +171 -0
- package/dist/directives/JoystickControls.d.ts.map +1 -0
- package/dist/directives/KeyboardControls.d.ts +219 -0
- package/dist/directives/KeyboardControls.d.ts.map +1 -0
- package/dist/directives/Scheduler.d.ts +36 -0
- package/dist/directives/Scheduler.d.ts.map +1 -0
- package/dist/directives/Shake.d.ts +98 -0
- package/dist/directives/Shake.d.ts.map +1 -0
- package/dist/directives/Sound.d.ts +25 -0
- package/dist/directives/Sound.d.ts.map +1 -0
- package/dist/directives/SpriteEffects.d.ts +70 -0
- package/dist/directives/SpriteEffects.d.ts.map +1 -0
- package/dist/directives/Transition.d.ts +10 -0
- package/dist/directives/Transition.d.ts.map +1 -0
- package/dist/directives/ViewportCull.d.ts +11 -0
- package/dist/directives/ViewportCull.d.ts.map +1 -0
- package/dist/directives/ViewportFollow.d.ts +18 -0
- package/dist/directives/ViewportFollow.d.ts.map +1 -0
- package/dist/directives/index.d.ts +15 -0
- package/dist/directives/index.d.ts.map +1 -0
- package/dist/dist-BOOc43Qm.js +778 -0
- package/dist/dist-BOOc43Qm.js.map +1 -0
- package/dist/engine/FocusManager.d.ts +174 -0
- package/dist/engine/FocusManager.d.ts.map +1 -0
- package/dist/engine/animation.d.ts +72 -0
- package/dist/engine/animation.d.ts.map +1 -0
- package/dist/engine/bootstrap.d.ts +52 -0
- package/dist/engine/bootstrap.d.ts.map +1 -0
- package/dist/engine/directive.d.ts +13 -0
- package/dist/engine/directive.d.ts.map +1 -0
- package/dist/engine/reactive.d.ts +139 -0
- package/dist/engine/reactive.d.ts.map +1 -0
- package/dist/engine/signal.d.ts +74 -0
- package/dist/engine/signal.d.ts.map +1 -0
- package/dist/engine/trigger.d.ts +54 -0
- package/dist/engine/trigger.d.ts.map +1 -0
- package/dist/engine/utils.d.ts +89 -0
- package/dist/engine/utils.d.ts.map +1 -0
- package/dist/hooks/addContext.d.ts +2 -0
- package/dist/hooks/addContext.d.ts.map +1 -0
- package/dist/hooks/useFocus.d.ts +60 -0
- package/dist/hooks/useFocus.d.ts.map +1 -0
- package/dist/hooks/useProps.d.ts +53 -0
- package/dist/hooks/useProps.d.ts.map +1 -0
- package/dist/hooks/useRef.d.ts +4 -0
- package/dist/hooks/useRef.d.ts.map +1 -0
- package/dist/index.d.ts +19 -844
- package/dist/index.d.ts.map +1 -0
- package/dist/index.global.js +189 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +15156 -3279
- package/dist/index.js.map +1 -1
- package/dist/utils/Ease.d.ts +17 -0
- package/dist/utils/Ease.d.ts.map +1 -0
- package/dist/utils/GlobalAssetLoader.d.ts +141 -0
- package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
- package/dist/utils/RadialGradient.d.ts +57 -0
- package/dist/utils/RadialGradient.d.ts.map +1 -0
- package/dist/utils/functions.d.ts +2 -0
- package/dist/utils/functions.d.ts.map +1 -0
- package/dist/utils/tabindex.d.ts +16 -0
- package/dist/utils/tabindex.d.ts.map +1 -0
- package/index.d.ts +1 -3
- package/package.json +17 -46
- package/src/components/Button.ts +406 -0
- package/src/components/Canvas.ts +82 -51
- package/src/components/Container.ts +31 -4
- package/src/components/DOMContainer.ts +387 -0
- package/src/components/DOMElement.ts +556 -0
- package/src/components/DOMSprite.ts +1044 -0
- package/src/components/DisplayObject.ts +423 -202
- package/src/components/FocusContainer.ts +368 -0
- package/src/components/Graphic.ts +255 -68
- package/src/components/Joystick.ts +269 -0
- package/src/components/Mesh.ts +239 -0
- package/src/components/NineSliceSprite.ts +4 -1
- package/src/components/ParticleEmitter.ts +12 -8
- package/src/components/Sprite.ts +441 -54
- package/src/components/Text.ts +270 -26
- package/src/components/Video.ts +110 -0
- package/src/components/Viewport.ts +122 -63
- package/src/components/index.ts +12 -5
- package/src/components/types/DisplayObject.ts +64 -5
- package/src/components/types/Spritesheet.ts +0 -118
- package/src/directives/Controls.ts +254 -0
- package/src/directives/ControlsBase.ts +267 -0
- package/src/directives/Drag.ts +357 -52
- package/src/directives/Flash.ts +419 -0
- package/src/directives/FocusNavigation.ts +113 -0
- package/src/directives/FogVisibility.ts +273 -0
- package/src/directives/GamepadControls.ts +537 -0
- package/src/directives/JoystickControls.ts +396 -0
- package/src/directives/KeyboardControls.ts +86 -431
- package/src/directives/Scheduler.ts +21 -5
- package/src/directives/Shake.ts +298 -0
- package/src/directives/Sound.ts +94 -31
- package/src/directives/SpriteEffects.ts +461 -0
- package/src/directives/ViewportFollow.ts +40 -9
- package/src/directives/index.ts +14 -6
- package/src/engine/FocusManager.ts +510 -0
- package/src/engine/animation.ts +175 -21
- package/src/engine/bootstrap.ts +140 -6
- package/src/engine/directive.ts +4 -4
- package/src/engine/reactive.ts +1266 -167
- package/src/engine/signal.ts +335 -47
- package/src/engine/trigger.ts +95 -12
- package/src/engine/utils.ts +101 -9
- package/src/hooks/useFocus.ts +91 -0
- package/src/hooks/useProps.ts +92 -7
- package/src/index.ts +13 -6
- package/src/types/pixi-cull.d.ts +7 -0
- package/src/utils/GlobalAssetLoader.ts +257 -0
- package/src/utils/RadialGradient.ts +29 -0
- package/src/utils/functions.ts +7 -0
- package/src/utils/tabindex.ts +70 -0
- package/testing/index.ts +42 -0
- package/tsconfig.json +18 -23
- package/vite.config.ts +39 -0
- package/README.md +0 -79
- package/compiler/dist/index.d.ts +0 -9
- package/compiler/dist/index.js +0 -119
- package/compiler/dist/index.js.map +0 -1
- package/compiler/grammar.pegjs +0 -180
- package/compiler/index.ts +0 -166
- package/compiler/package-lock.json +0 -1850
- package/compiler/package.json +0 -27
- package/compiler/tsconfig.json +0 -29
- package/compiler/tsup.config.ts +0 -14
- package/src/components/DrawMap/index.ts +0 -65
- package/src/components/Tilemap/Tile.ts +0 -79
- package/src/components/Tilemap/TileGroup.ts +0 -207
- package/src/components/Tilemap/TileLayer.ts +0 -163
- package/src/components/Tilemap/TileSet.ts +0 -41
- package/src/components/Tilemap/index.ts +0 -80
- package/src/presets/Bar.ts +0 -89
- package/src/presets/Button.ts +0 -0
- package/src/presets/Joystick.ts +0 -286
- package/src/presets/NightAmbiant.ts +0 -122
- package/src/presets/Particle.ts +0 -53
- package/tsconfig.node.json +0 -10
- package/tsup.config.ts +0 -13
- package/vitest.config.ts +0 -12
package/compiler/index.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createFilter } from "vite";
|
|
2
|
-
import { parse } from "acorn";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import pkg from "peggy";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import * as ts from "typescript";
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
|
-
|
|
9
|
-
const { generate } = pkg;
|
|
10
|
-
|
|
11
|
-
const DEV_SRC = "../../src"
|
|
12
|
-
|
|
13
|
-
export default function canvasengine() {
|
|
14
|
-
const filter = createFilter("**/*.ce");
|
|
15
|
-
|
|
16
|
-
// Convert import.meta.url to a file path
|
|
17
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
-
const __dirname = path.dirname(__filename);
|
|
19
|
-
|
|
20
|
-
const grammar = fs.readFileSync(
|
|
21
|
-
path.join(__dirname, "grammar.pegjs").replace("dist/grammar.pegjs", "grammar.pegjs"),
|
|
22
|
-
"utf8");
|
|
23
|
-
const parser = generate(grammar);
|
|
24
|
-
const isDev = process.env.NODE_ENV === "dev";
|
|
25
|
-
const FLAG_COMMENT = "/*--[TPL]--*/";
|
|
26
|
-
|
|
27
|
-
const PRIMITIVE_COMPONENTS = [
|
|
28
|
-
"Canvas",
|
|
29
|
-
"Sprite",
|
|
30
|
-
"Text",
|
|
31
|
-
"Joystick",
|
|
32
|
-
"Viewport",
|
|
33
|
-
"Graphics",
|
|
34
|
-
"Container",
|
|
35
|
-
"ImageMap",
|
|
36
|
-
"NineSliceSprite",
|
|
37
|
-
"Rect",
|
|
38
|
-
"Circle",
|
|
39
|
-
"svg"
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
name: "vite-plugin-ce",
|
|
44
|
-
transform(code: string, id: string) {
|
|
45
|
-
if (!filter(id)) return;
|
|
46
|
-
|
|
47
|
-
// Extract the script content
|
|
48
|
-
const scriptMatch = code.match(/<script>([\s\S]*?)<\/script>/);
|
|
49
|
-
let scriptContent = scriptMatch ? scriptMatch[1].trim() : "";
|
|
50
|
-
|
|
51
|
-
// Transform SVG tags to Svg components
|
|
52
|
-
let template = code.replace(/<script>[\s\S]*?<\/script>/, "")
|
|
53
|
-
.replace(/^\s+|\s+$/g, '');
|
|
54
|
-
|
|
55
|
-
// Add SVG transformation
|
|
56
|
-
template = template.replace(/<svg>([\s\S]*?)<\/svg>/g, (match, content) => {
|
|
57
|
-
return `<Svg content="${content.trim()}" />`;
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const parsedTemplate = parser.parse(template);
|
|
61
|
-
|
|
62
|
-
// trick to avoid typescript remove imports in scriptContent
|
|
63
|
-
scriptContent += FLAG_COMMENT + parsedTemplate
|
|
64
|
-
|
|
65
|
-
let transpiledCode = ts.transpileModule(scriptContent, {
|
|
66
|
-
compilerOptions: {
|
|
67
|
-
module: ts.ModuleKind.Preserve,
|
|
68
|
-
},
|
|
69
|
-
}).outputText;
|
|
70
|
-
|
|
71
|
-
// remove code after /*---*/
|
|
72
|
-
transpiledCode = transpiledCode.split(FLAG_COMMENT)[0]
|
|
73
|
-
|
|
74
|
-
// Use Acorn to parse the script content
|
|
75
|
-
const parsed = parse(transpiledCode, {
|
|
76
|
-
sourceType: "module",
|
|
77
|
-
ecmaVersion: 2020,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Extract imports
|
|
81
|
-
const imports = parsed.body.filter(
|
|
82
|
-
(node) => node.type === "ImportDeclaration"
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// Extract non-import statements from scriptContent
|
|
86
|
-
const nonImportCode = parsed.body
|
|
87
|
-
.filter((node) => node.type !== "ImportDeclaration")
|
|
88
|
-
.map((node) => transpiledCode.slice(node.start, node.end))
|
|
89
|
-
.join("\n");
|
|
90
|
-
|
|
91
|
-
let importsCode = imports
|
|
92
|
-
.map((imp) => {
|
|
93
|
-
let importCode = transpiledCode.slice(imp.start, imp.end);
|
|
94
|
-
if (isDev && importCode.includes("from 'canvasengine'")) {
|
|
95
|
-
importCode = importCode.replace(
|
|
96
|
-
"from 'canvasengine'",
|
|
97
|
-
`from '${DEV_SRC}'`
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
return importCode;
|
|
101
|
-
})
|
|
102
|
-
.join("\n");
|
|
103
|
-
|
|
104
|
-
// Define an array for required imports
|
|
105
|
-
const requiredImports = ["h", "computed", "cond", "loop"];
|
|
106
|
-
|
|
107
|
-
// Check for missing imports
|
|
108
|
-
const missingImports = requiredImports.filter(
|
|
109
|
-
(importName) =>
|
|
110
|
-
!imports.some(
|
|
111
|
-
(imp) =>
|
|
112
|
-
imp.specifiers &&
|
|
113
|
-
imp.specifiers.some(
|
|
114
|
-
(spec) =>
|
|
115
|
-
spec.type === "ImportSpecifier" &&
|
|
116
|
-
spec.imported &&
|
|
117
|
-
'name' in spec.imported &&
|
|
118
|
-
spec.imported.name === importName
|
|
119
|
-
)
|
|
120
|
-
)
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
// Add missing imports
|
|
124
|
-
if (missingImports.length > 0) {
|
|
125
|
-
const additionalImportCode = `import { ${missingImports.join(
|
|
126
|
-
", "
|
|
127
|
-
)} } from ${isDev ? `'${DEV_SRC}'` : "'canvasengine'"};`;
|
|
128
|
-
importsCode = `${additionalImportCode}\n${importsCode}`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Check for primitive components in parsedTemplate
|
|
132
|
-
const primitiveImports = PRIMITIVE_COMPONENTS.filter((component) =>
|
|
133
|
-
parsedTemplate.includes(`h(${component}`)
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
// Add missing imports for primitive components
|
|
137
|
-
primitiveImports.forEach((component) => {
|
|
138
|
-
const importStatement = `import { ${component} } from ${
|
|
139
|
-
isDev ? `'${DEV_SRC}'` : "'canvasengine'"
|
|
140
|
-
};`;
|
|
141
|
-
if (!importsCode.includes(importStatement)) {
|
|
142
|
-
importsCode = `${importStatement}\n${importsCode}`;
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Generate the output
|
|
147
|
-
const output = String.raw`
|
|
148
|
-
${importsCode}
|
|
149
|
-
import { useProps, useDefineProps } from ${isDev ? `'${DEV_SRC}'` : "'canvasengine'"}
|
|
150
|
-
|
|
151
|
-
export default function component($$props) {
|
|
152
|
-
const $props = useProps($$props)
|
|
153
|
-
const defineProps = useDefineProps($$props)
|
|
154
|
-
${nonImportCode}
|
|
155
|
-
let $this = ${parsedTemplate}
|
|
156
|
-
return $this
|
|
157
|
-
}
|
|
158
|
-
`;
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
code: output,
|
|
162
|
-
map: null,
|
|
163
|
-
};
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|