@simpludify/web 0.1.0 → 0.1.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.
- package/LICENSE +21 -21
- package/README.md +22 -22
- package/dist/game.d.ts +7 -0
- package/dist/index.js +78 -9
- package/dist/index.js.map +1 -1
- package/dist/style.css +192 -192
- package/package.json +57 -57
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 oz-coden
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 oz-coden
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
# @simpludify/web
|
|
2
|
-
|
|
3
|
-
Experimental v0.1.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install @simpludify/web@0.1.
|
|
9
|
-
npm install --save-dev vite typescript
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
import { Game, Character } from "@simpludify/web";
|
|
14
|
-
const game = new Game();
|
|
15
|
-
game.add(Character());
|
|
16
|
-
await game.run();
|
|
17
|
-
// Call game.dispose() when removing the game.
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Use a browser bundler such as Vite, with an HTML module entry and a parent with an explicit height. The entry automatically imports scoped CSS. It can also be imported explicitly with `import "@simpludify/web/style.css"`. Do not configure CSS as side-effect-free. No repository CLI, example assets or global stylesheet reset is included.
|
|
21
|
-
|
|
22
|
-
ESM only, ES2022. Tooling requires Node >=22.12; Chromium/WebGL is the automated rendering target. This browser package is not a Node/SSR entry; use `@simpludify/core` for headless execution. Source maps embed original sources. [Complete Vite setup](https://github.oz-coden.com/Simpludify/guides/npm.html) · [Repository/API](https://github.com/oz-coden/Simpludify). MIT.
|
|
1
|
+
# @simpludify/web
|
|
2
|
+
|
|
3
|
+
Experimental v0.1.2 browser SDK for Simpludify, a code-first TypeScript 2D engine. APIs may change between 0.x releases. Includes Game, PixiJS rendering, browser input and Canvas/DOM UI adapters; re-exports the host-independent Core API. Core and PixiJS are installed as runtime dependencies, not bundled into this package.
|
|
4
|
+
|
|
5
|
+
Registry installation (check availability with `npm view @simpludify/web@0.1.2 version`):
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @simpludify/web@0.1.2
|
|
9
|
+
npm install --save-dev vite typescript
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { Game, Character } from "@simpludify/web";
|
|
14
|
+
const game = new Game();
|
|
15
|
+
game.add(Character());
|
|
16
|
+
await game.run();
|
|
17
|
+
// Call game.dispose() when removing the game.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Use a browser bundler such as Vite, with an HTML module entry and a parent with an explicit height. The entry automatically imports scoped CSS. It can also be imported explicitly with `import "@simpludify/web/style.css"`. Do not configure CSS as side-effect-free. No repository CLI, example assets or global stylesheet reset is included.
|
|
21
|
+
|
|
22
|
+
ESM only, ES2022. Tooling requires Node >=22.12; Chromium/WebGL is the automated rendering target. This browser package is not a Node/SSR entry; use `@simpludify/core` for headless execution. Source maps embed original sources. [Complete Vite setup](https://github.oz-coden.com/Simpludify/guides/npm.html) · [Repository/API](https://github.com/oz-coden/Simpludify). MIT.
|
package/dist/game.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ export declare class Game<SceneId extends string = string> {
|
|
|
44
44
|
private canvas;
|
|
45
45
|
private canvasPresentation;
|
|
46
46
|
private defaultCanvas;
|
|
47
|
+
private readonly ownedCanvas;
|
|
48
|
+
private readonly viewportBindings;
|
|
47
49
|
get pointer(): ScenePointer;
|
|
48
50
|
get pointerDiagnostics(): {
|
|
49
51
|
captures: number;
|
|
@@ -119,6 +121,11 @@ export declare class Game<SceneId extends string = string> {
|
|
|
119
121
|
private present;
|
|
120
122
|
get viewport(): Viewport;
|
|
121
123
|
get view(): ViewTransform;
|
|
124
|
+
/** Bind the mounted UI's resolved region to the world viewport. UI units become CSS pixels.
|
|
125
|
+
* One binding per UI; replacement/unbind restores the manual viewport. UI/node disposal unbinds.
|
|
126
|
+
* A collapsed/hidden region clips all world rendering and pointer input. No extra frame/observer.
|
|
127
|
+
*/
|
|
128
|
+
bindViewport(ui: CanvasUI, node: CanvasNode): () => void;
|
|
122
129
|
setViewport(viewport?: Viewport): void;
|
|
123
130
|
worldToScreen(point: WorldPoint): ScreenPoint;
|
|
124
131
|
screenToWorld(point: ScreenPoint): WorldPoint;
|
package/dist/index.js
CHANGED
|
@@ -372,6 +372,11 @@ var CanvasNativeText = class extends NativeControl {
|
|
|
372
372
|
this.source = "pointer";
|
|
373
373
|
this.begin();
|
|
374
374
|
}), options);
|
|
375
|
+
el.addEventListener("blur", () => {
|
|
376
|
+
this.composing = false;
|
|
377
|
+
this.session = void 0;
|
|
378
|
+
this.source = "keyboard";
|
|
379
|
+
}, options);
|
|
375
380
|
el.addEventListener("focus", () => this.run(() => this.begin()), options);
|
|
376
381
|
el.addEventListener("compositionstart", () => this.run(() => {
|
|
377
382
|
this.composing = true;
|
|
@@ -2297,6 +2302,8 @@ var Game = class {
|
|
|
2297
2302
|
canvas;
|
|
2298
2303
|
canvasPresentation;
|
|
2299
2304
|
defaultCanvas;
|
|
2305
|
+
ownedCanvas = /* @__PURE__ */ new WeakSet();
|
|
2306
|
+
viewportBindings = /* @__PURE__ */ new WeakMap();
|
|
2300
2307
|
get pointer() {
|
|
2301
2308
|
this.assertAlive();
|
|
2302
2309
|
return this.channelFor(this.engine.scene);
|
|
@@ -2498,6 +2505,7 @@ var Game = class {
|
|
|
2498
2505
|
this.assertAlive();
|
|
2499
2506
|
if (this.startPromise || this.defaultCanvas) throw new EngineError("UI_ALREADY_STARTED", "Define one default Canvas UI before run");
|
|
2500
2507
|
this.defaultCanvas = new CanvasUI(this.engine.scene, root, options);
|
|
2508
|
+
this.ownedCanvas.add(this.defaultCanvas);
|
|
2501
2509
|
return this.defaultCanvas;
|
|
2502
2510
|
}
|
|
2503
2511
|
uiOverlay(...nodes) {
|
|
@@ -2581,6 +2589,7 @@ var Game = class {
|
|
|
2581
2589
|
canvasUI: (root, options) => {
|
|
2582
2590
|
if (canvas) throw new EngineError("UI_OWNERSHIP", "A Scene has one Canvas UI root");
|
|
2583
2591
|
canvas = new CanvasUI(scene, root, options);
|
|
2592
|
+
this.ownedCanvas.add(canvas);
|
|
2584
2593
|
return canvas;
|
|
2585
2594
|
},
|
|
2586
2595
|
actions: (actions, bindings) => new ActionController(actions, {
|
|
@@ -2690,6 +2699,31 @@ var Game = class {
|
|
|
2690
2699
|
this.updateProjection();
|
|
2691
2700
|
return this.projection;
|
|
2692
2701
|
}
|
|
2702
|
+
/** Bind the mounted UI's resolved region to the world viewport. UI units become CSS pixels.
|
|
2703
|
+
* One binding per UI; replacement/unbind restores the manual viewport. UI/node disposal unbinds.
|
|
2704
|
+
* A collapsed/hidden region clips all world rendering and pointer input. No extra frame/observer.
|
|
2705
|
+
*/
|
|
2706
|
+
bindViewport(ui, node) {
|
|
2707
|
+
this.assertAlive();
|
|
2708
|
+
if (!this.ownedCanvas.has(ui) || ui.disposed || node.disposed || node.ui !== ui) throw new EngineError("UI_OWNERSHIP", "Viewport region must belong to this Game's Canvas UI");
|
|
2709
|
+
this.viewportBindings.get(ui)?.dispose();
|
|
2710
|
+
let removed = false;
|
|
2711
|
+
const off = [];
|
|
2712
|
+
const binding = {
|
|
2713
|
+
node,
|
|
2714
|
+
dispose: () => {
|
|
2715
|
+
if (removed) return;
|
|
2716
|
+
removed = true;
|
|
2717
|
+
if (this.viewportBindings.get(ui) === binding) this.viewportBindings.delete(ui);
|
|
2718
|
+
for (const unregister of off) unregister();
|
|
2719
|
+
this.projectionDirty = true;
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
this.viewportBindings.set(ui, binding);
|
|
2723
|
+
off.push(ui.onDispose(binding.dispose), node.onDispose(binding.dispose));
|
|
2724
|
+
this.projectionDirty = true;
|
|
2725
|
+
return binding.dispose;
|
|
2726
|
+
}
|
|
2693
2727
|
setViewport(viewport) {
|
|
2694
2728
|
this.assertAlive();
|
|
2695
2729
|
const next = viewport ? { ...viewport } : void 0;
|
|
@@ -2732,23 +2766,59 @@ var Game = class {
|
|
|
2732
2766
|
this.render();
|
|
2733
2767
|
}
|
|
2734
2768
|
updateProjection() {
|
|
2735
|
-
|
|
2736
|
-
|
|
2769
|
+
this.canvasPresentation?.update(this.width, this.height);
|
|
2770
|
+
const ui = this.canvas;
|
|
2771
|
+
const region = ui ? this.viewportBindings.get(ui)?.node : void 0;
|
|
2772
|
+
let v = this.requestedViewport;
|
|
2773
|
+
let empty = false;
|
|
2774
|
+
if (ui && region) {
|
|
2775
|
+
const b = region.bounds, scale = ui.scale;
|
|
2776
|
+
const x = Math.max(0, Math.min(this.width, b.x * scale));
|
|
2777
|
+
const y = Math.max(0, Math.min(this.height, b.y * scale));
|
|
2778
|
+
const right = Math.max(x, Math.min(this.width, (b.x + b.width) * scale));
|
|
2779
|
+
const bottom = Math.max(y, Math.min(this.height, (b.y + b.height) * scale));
|
|
2780
|
+
let visible = region.ui === ui;
|
|
2781
|
+
for (let node = region; node; node = node.parent) if (node.disposed || !node.visible || !node.enabled) visible = false;
|
|
2782
|
+
empty = !visible || right <= x || bottom <= y;
|
|
2783
|
+
v = {
|
|
2784
|
+
x,
|
|
2785
|
+
y,
|
|
2786
|
+
width: empty ? 0 : right - x,
|
|
2787
|
+
height: empty ? 0 : bottom - y
|
|
2788
|
+
};
|
|
2789
|
+
}
|
|
2790
|
+
const viewport = v ?? {
|
|
2791
|
+
x: 0,
|
|
2792
|
+
y: 0,
|
|
2793
|
+
width: this.width,
|
|
2794
|
+
height: this.height
|
|
2795
|
+
};
|
|
2796
|
+
const previous = this.projection.viewport;
|
|
2797
|
+
const c = this.camera;
|
|
2798
|
+
if (!this.projectionDirty && previous.x === viewport.x && previous.y === viewport.y && previous.width === viewport.width && previous.height === viewport.height && this.cameraX === c.x && this.cameraY === c.y && this.cameraZoom === c.zoom) return;
|
|
2737
2799
|
this.projectionDirty = false;
|
|
2738
2800
|
this.cameraX = c.x;
|
|
2739
2801
|
this.cameraY = c.y;
|
|
2740
2802
|
this.cameraZoom = c.zoom;
|
|
2741
2803
|
this.projection = createViewTransform({
|
|
2742
|
-
viewport:
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
},
|
|
2804
|
+
viewport: empty ? {
|
|
2805
|
+
...viewport,
|
|
2806
|
+
width: 1,
|
|
2807
|
+
height: 1
|
|
2808
|
+
} : viewport,
|
|
2748
2809
|
resolution: this.resolution,
|
|
2749
2810
|
aspect: this.aspect,
|
|
2750
2811
|
camera: c
|
|
2751
2812
|
});
|
|
2813
|
+
if (empty) this.projection = {
|
|
2814
|
+
...this.projection,
|
|
2815
|
+
viewport,
|
|
2816
|
+
clip: {
|
|
2817
|
+
...viewport,
|
|
2818
|
+
width: 0,
|
|
2819
|
+
height: 0
|
|
2820
|
+
}
|
|
2821
|
+
};
|
|
2752
2822
|
}
|
|
2753
2823
|
resize() {
|
|
2754
2824
|
if (this.dead || !this.rendererReady) return;
|
|
@@ -2767,7 +2837,6 @@ var Game = class {
|
|
|
2767
2837
|
}
|
|
2768
2838
|
render() {
|
|
2769
2839
|
this.updateProjection();
|
|
2770
|
-
this.canvasPresentation?.update(this.width, this.height);
|
|
2771
2840
|
this.prepared?.render(this.projection);
|
|
2772
2841
|
}
|
|
2773
2842
|
tick = (time) => {
|