@playcanvas/web-components 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 PlayCanvas
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 ADDED
@@ -0,0 +1,81 @@
1
+ # PlayCanvas Web Components
2
+
3
+ Unleash the power of PlayCanvas in your HTML. PlayCanvas Web Components allows you to write PlayCanvas scenes using only HTML, enabling a clear and concise structure, and making it easier than ever to integrate with other web technologies. Just add tags for entities, components, and assets, and watch your 3D scene come to life!
4
+
5
+ ## Usage 🚧
6
+
7
+ If you are using a bundler (e.g. Rollup), you can install PlayCanvas Web Components and the PlayCanvas Engine using NPM:
8
+
9
+ ```bash
10
+ npm install playcanvas @playcanvas/web-components --save-dev
11
+ ```
12
+
13
+ Or you can include it directly in your HTML file from a CDN.
14
+
15
+ ES Modules:
16
+
17
+ ```html
18
+ <script type="module" src="https://esm.run/@playcanvas/web-components@0.1.0"></script>
19
+ ```
20
+
21
+ UMD:
22
+
23
+ ```html
24
+ <script src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.0"></script>
25
+ ```
26
+
27
+ ## Example 📖
28
+
29
+ Below is a basic example of how to use PlayCanvas Web Components to create a simple 3D scene (a spinning cube):
30
+
31
+ ```html
32
+ <!DOCTYPE html>
33
+ <html lang="en">
34
+ <head>
35
+ <meta charset="UTF-8">
36
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
37
+ <title>PlayCanvas Web Components - Spinning Cube</title>
38
+ <script type="importmap">
39
+ {
40
+ "imports": {
41
+ "playcanvas": "https://esm.run/playcanvas@2.1.0"
42
+ }
43
+ }
44
+ </script>
45
+ <script type="module" src="https://esm.run/@playcanvas/web-components@0.1.0"></script>
46
+ <link rel="stylesheet" href="styles.css">
47
+ </head>
48
+ <body>
49
+ <pc-app>
50
+ <script type="module">
51
+ import { registerScript, Script } from 'playcanvas';
52
+
53
+ class Rotate extends Script {
54
+ update(dt) {
55
+ this.entity.rotate(10 * dt, 20 * dt, 30 * dt);
56
+ }
57
+ }
58
+
59
+ registerScript(Rotate, 'rotate');
60
+ </script>
61
+ <pc-scene>
62
+ <!-- Camera -->
63
+ <pc-entity name="camera" position="0,0,3">
64
+ <pc-camera></pc-camera>
65
+ </pc-entity>
66
+ <!-- Light -->
67
+ <pc-entity name="light" rotation="45,0,0">
68
+ <pc-light></pc-light>
69
+ </pc-entity>
70
+ <!-- Cube -->
71
+ <pc-entity name="cube">
72
+ <pc-render type="box"></pc-render>
73
+ <pc-scripts>
74
+ <pc-script name="rotate"></pc-script>
75
+ </pc-scripts>
76
+ </pc-entity>
77
+ </pc-scene>
78
+ </pc-app>
79
+ </body>
80
+ </html>
81
+ ```
package/dist/app.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { Application } from 'playcanvas';
2
+ /**
3
+ * The main application element.
4
+ */
5
+ declare class AppElement extends HTMLElement {
6
+ /**
7
+ * The canvas element.
8
+ */
9
+ private _canvas;
10
+ private appReadyPromise;
11
+ private appReadyResolve;
12
+ private _highResolution;
13
+ /**
14
+ * The PlayCanvas application instance.
15
+ */
16
+ app: Application | null;
17
+ /**
18
+ * Creates a new AppElement.
19
+ */
20
+ constructor();
21
+ connectedCallback(): Promise<void>;
22
+ disconnectedCallback(): void;
23
+ getApplication(): Promise<Application>;
24
+ _onWindowResize(): void;
25
+ set highResolution(value: boolean);
26
+ get highResolution(): boolean;
27
+ static get observedAttributes(): string[];
28
+ attributeChangedCallback(name: string, _oldValue: string, _newValue: string): void;
29
+ }
30
+ export { AppElement };
@@ -0,0 +1,28 @@
1
+ import { Asset } from 'playcanvas';
2
+ /**
3
+ * Loads an asset into the PlayCanvas engine.
4
+ */
5
+ declare class AssetElement extends HTMLElement {
6
+ private _preload;
7
+ /**
8
+ * The asset that is loaded.
9
+ */
10
+ asset: Asset | null;
11
+ connectedCallback(): Promise<void>;
12
+ disconnectedCallback(): void;
13
+ createAsset(): void;
14
+ destroyAsset(): void;
15
+ /**
16
+ * Sets the preload flag of the asset.
17
+ * @param value - The preload flag.
18
+ */
19
+ set preload(value: boolean);
20
+ /**
21
+ * Gets the preload flag of the asset.
22
+ * @returns The preload flag.
23
+ */
24
+ get preload(): boolean;
25
+ static get observedAttributes(): string[];
26
+ attributeChangedCallback(name: string, _oldValue: string, _newValue: string): void;
27
+ }
28
+ export { AssetElement };
@@ -0,0 +1,95 @@
1
+ import { CameraComponent, Color } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * Represents a camera component in the PlayCanvas engine.
5
+ *
6
+ * @category Components
7
+ */
8
+ declare class CameraComponentElement extends ComponentElement {
9
+ private _clearColor;
10
+ private _farClip;
11
+ private _fov;
12
+ private _nearClip;
13
+ private _orthographic;
14
+ private _orthoHeight;
15
+ /**
16
+ * Creates a new CameraComponentElement.
17
+ */
18
+ constructor();
19
+ getInitialComponentData(): {
20
+ clearColor: Color;
21
+ farClip: number;
22
+ fov: number;
23
+ nearClip: number;
24
+ projection: number;
25
+ orthoHeight: number;
26
+ };
27
+ /**
28
+ * Gets the camera component.
29
+ * @returns The camera component.
30
+ */
31
+ get component(): CameraComponent | null;
32
+ /**
33
+ * Sets the clear color of the camera.
34
+ * @param value - The clear color.
35
+ */
36
+ set clearColor(value: Color);
37
+ /**
38
+ * Gets the clear color of the camera.
39
+ * @returns The clear color.
40
+ */
41
+ get clearColor(): Color;
42
+ /**
43
+ * Sets the far clip distance of the camera.
44
+ * @param value - The far clip distance.
45
+ */
46
+ set farClip(value: number);
47
+ /**
48
+ * Gets the far clip distance of the camera.
49
+ * @returns The far clip distance.
50
+ */
51
+ get farClip(): number;
52
+ /**
53
+ * Sets the field of view of the camera.
54
+ * @param value - The field of view.
55
+ */
56
+ set fov(value: number);
57
+ /**
58
+ * Gets the field of view of the camera.
59
+ * @returns The field of view.
60
+ */
61
+ get fov(): number;
62
+ /**
63
+ * Sets the near clip distance of the camera.
64
+ * @param value - The near clip distance.
65
+ */
66
+ set nearClip(value: number);
67
+ /**
68
+ * Gets the near clip distance of the camera.
69
+ * @returns The near clip distance.
70
+ */
71
+ get nearClip(): number;
72
+ /**
73
+ * Sets the orthographic projection of the camera.
74
+ * @param value - The orthographic projection.
75
+ */
76
+ set orthographic(value: boolean);
77
+ /**
78
+ * Gets the orthographic projection of the camera.
79
+ * @returns The orthographic projection.
80
+ */
81
+ get orthographic(): boolean;
82
+ /**
83
+ * Sets the orthographic height of the camera.
84
+ * @param value - The orthographic height.
85
+ */
86
+ set orthoHeight(value: number);
87
+ /**
88
+ * Gets the orthographic height of the camera.
89
+ * @returns The orthographic height.
90
+ */
91
+ get orthoHeight(): number;
92
+ static get observedAttributes(): string[];
93
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
94
+ }
95
+ export { CameraComponentElement };
@@ -0,0 +1,47 @@
1
+ import { CollisionComponent, Vec3 } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * Represents a collision component in the PlayCanvas engine.
5
+ *
6
+ * @category Components
7
+ */
8
+ declare class CollisionComponentElement extends ComponentElement {
9
+ private _axis;
10
+ private _convexHull;
11
+ private _halfExtents;
12
+ private _height;
13
+ private _radius;
14
+ private _type;
15
+ /**
16
+ * Creates a new CollisionComponentElement.
17
+ */
18
+ constructor();
19
+ getInitialComponentData(): {
20
+ axis: number;
21
+ convexHull: boolean;
22
+ halfExtents: Vec3;
23
+ height: number;
24
+ radius: number;
25
+ type: string;
26
+ };
27
+ /**
28
+ * Gets the collision component.
29
+ * @returns The collision component.
30
+ */
31
+ get component(): CollisionComponent | null;
32
+ set axis(value: number);
33
+ get axis(): number;
34
+ set convexHull(value: boolean);
35
+ get convexHull(): boolean;
36
+ set halfExtents(value: Vec3);
37
+ get halfExtents(): Vec3;
38
+ set height(value: number);
39
+ get height(): number;
40
+ set radius(value: number);
41
+ get radius(): number;
42
+ set type(value: string);
43
+ get type(): string;
44
+ static get observedAttributes(): string[];
45
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
46
+ }
47
+ export { CollisionComponentElement };
@@ -0,0 +1,34 @@
1
+ import { Component } from 'playcanvas';
2
+ /**
3
+ * Represents a component in the PlayCanvas engine.
4
+ *
5
+ * @category Components
6
+ */
7
+ declare class ComponentElement extends HTMLElement {
8
+ private _componentName;
9
+ private _enabled;
10
+ private _component;
11
+ /**
12
+ * Constructor for the ComponentElement.
13
+ * @param componentName - The name of the component.
14
+ */
15
+ constructor(componentName: string);
16
+ getInitialComponentData(): {};
17
+ connectedCallback(): Promise<void>;
18
+ addComponent(): void;
19
+ disconnectedCallback(): void;
20
+ get component(): Component | null;
21
+ /**
22
+ * Sets the enabled state of the component.
23
+ * @param value - The enabled state of the component.
24
+ */
25
+ set enabled(value: boolean);
26
+ /**
27
+ * Gets the enabled state of the component.
28
+ * @returns The enabled state of the component.
29
+ */
30
+ get enabled(): boolean;
31
+ static get observedAttributes(): string[];
32
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
33
+ }
34
+ export { ComponentElement };
@@ -0,0 +1,74 @@
1
+ import { Color, ElementComponent, Vec2, Vec4 } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * Represents an element component in the PlayCanvas engine.
5
+ *
6
+ * @category Components
7
+ */
8
+ declare class ElementComponentElement extends ComponentElement {
9
+ private _anchor;
10
+ private _asset;
11
+ private _autoWidth;
12
+ private _color;
13
+ private _fontSize;
14
+ private _lineHeight;
15
+ private _pivot;
16
+ private _text;
17
+ private _type;
18
+ private _width;
19
+ private _wrapLines;
20
+ constructor();
21
+ connectedCallback(): Promise<void>;
22
+ getAsset(): import("playcanvas").Asset | null;
23
+ getInitialComponentData(): {
24
+ anchor: Vec4;
25
+ autoWidth: boolean;
26
+ color: Color;
27
+ fontAsset: number;
28
+ fontSize: number;
29
+ lineHeight: number;
30
+ pivot: Vec2;
31
+ type: "text" | "image" | "group";
32
+ text: string;
33
+ width: number;
34
+ wrapLines: boolean;
35
+ };
36
+ /**
37
+ * Gets the element component.
38
+ * @returns The element component.
39
+ */
40
+ get component(): ElementComponent | null;
41
+ set anchor(value: Vec4);
42
+ get anchor(): Vec4;
43
+ set asset(value: string);
44
+ get asset(): string;
45
+ set autoWidth(value: boolean);
46
+ get autoWidth(): boolean;
47
+ set color(value: Color);
48
+ get color(): Color;
49
+ set fontSize(value: number);
50
+ get fontSize(): number;
51
+ set lineHeight(value: number);
52
+ get lineHeight(): number;
53
+ set pivot(value: Vec2);
54
+ get pivot(): Vec2;
55
+ set text(value: string);
56
+ get text(): string;
57
+ /**
58
+ * Sets the type of the element component.
59
+ * @param value - The type.
60
+ */
61
+ set type(value: 'group' | 'image' | 'text');
62
+ /**
63
+ * Gets the type of the element component.
64
+ * @returns The type.
65
+ */
66
+ get type(): 'group' | 'image' | 'text';
67
+ set width(value: number);
68
+ get width(): number;
69
+ set wrapLines(value: boolean);
70
+ get wrapLines(): boolean;
71
+ static get observedAttributes(): string[];
72
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
73
+ }
74
+ export { ElementComponentElement };
@@ -0,0 +1,25 @@
1
+ import { GSplatComponent } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * Represents a gsplat component in the PlayCanvas engine.
5
+ *
6
+ * @category Components
7
+ */
8
+ declare class GSplatComponentElement extends ComponentElement {
9
+ private _asset;
10
+ constructor();
11
+ getAsset(): import("playcanvas").Asset | null;
12
+ getInitialComponentData(): {
13
+ asset: import("playcanvas").Asset | null;
14
+ };
15
+ /**
16
+ * Gets the gsplat component.
17
+ * @returns The gsplat component.
18
+ */
19
+ get component(): GSplatComponent | null;
20
+ set asset(value: string);
21
+ get asset(): string;
22
+ static get observedAttributes(): string[];
23
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
24
+ }
25
+ export { GSplatComponentElement };
@@ -0,0 +1,143 @@
1
+ import { Color, LightComponent } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * Represents a light component in the PlayCanvas engine.
5
+ *
6
+ * @category Components
7
+ */
8
+ declare class LightComponentElement extends ComponentElement {
9
+ private _castShadows;
10
+ private _color;
11
+ private _innerConeAngle;
12
+ private _intensity;
13
+ private _normalOffsetBias;
14
+ private _outerConeAngle;
15
+ private _range;
16
+ private _shadowBias;
17
+ private _shadowDistance;
18
+ private _type;
19
+ /**
20
+ * Creates a new LightComponentElement.
21
+ */
22
+ constructor();
23
+ getInitialComponentData(): {
24
+ castShadows: boolean;
25
+ color: Color;
26
+ innerConeAngle: number;
27
+ intensity: number;
28
+ normalOffsetBias: number;
29
+ outerConeAngle: number;
30
+ range: number;
31
+ shadowBias: number;
32
+ shadowDistance: number;
33
+ type: string;
34
+ };
35
+ /**
36
+ * Gets the light component.
37
+ * @returns The light component.
38
+ */
39
+ get component(): LightComponent | null;
40
+ /**
41
+ * Sets the cast shadows flag of the light.
42
+ * @param value - The cast shadows flag.
43
+ */
44
+ set castShadows(value: boolean);
45
+ /**
46
+ * Gets the cast shadows flag of the light.
47
+ * @returns The cast shadows flag.
48
+ */
49
+ get castShadows(): boolean;
50
+ /**
51
+ * Sets the color of the light.
52
+ * @param value - The color.
53
+ */
54
+ set color(value: Color);
55
+ /**
56
+ * Gets the color of the light.
57
+ * @returns The color.
58
+ */
59
+ get color(): Color;
60
+ /**
61
+ * Sets the inner cone angle of the light.
62
+ * @param value - The inner cone angle.
63
+ */
64
+ set innerConeAngle(value: number);
65
+ /**
66
+ * Gets the inner cone angle of the light.
67
+ * @returns The inner cone angle.
68
+ */
69
+ get innerConeAngle(): number;
70
+ /**
71
+ * Sets the intensity of the light.
72
+ * @param value - The intensity.
73
+ */
74
+ set intensity(value: number);
75
+ /**
76
+ * Gets the intensity of the light.
77
+ * @returns The intensity.
78
+ */
79
+ get intensity(): number;
80
+ /**
81
+ * Sets the normal offset bias of the light.
82
+ * @param value - The normal offset bias.
83
+ */
84
+ set normalOffsetBias(value: number);
85
+ /**
86
+ * Gets the normal offset bias of the light.
87
+ * @returns The normal offset bias.
88
+ */
89
+ get normalOffsetBias(): number;
90
+ /**
91
+ * Sets the outer cone angle of the light.
92
+ * @param value - The outer cone angle.
93
+ */
94
+ set outerConeAngle(value: number);
95
+ /**
96
+ * Gets the outer cone angle of the light.
97
+ * @returns The outer cone angle.
98
+ */
99
+ get outerConeAngle(): number;
100
+ /**
101
+ * Sets the range of the light.
102
+ * @param value - The range.
103
+ */
104
+ set range(value: number);
105
+ /**
106
+ * Gets the range of the light.
107
+ * @returns The range.
108
+ */
109
+ get range(): number;
110
+ /**
111
+ * Sets the shadow bias of the light.
112
+ * @param value - The shadow bias.
113
+ */
114
+ set shadowBias(value: number);
115
+ /**
116
+ * Gets the shadow bias of the light.
117
+ * @returns The shadow bias.
118
+ */
119
+ get shadowBias(): number;
120
+ /**
121
+ * Sets the shadow distance of the light.
122
+ * @param value - The shadow distance.
123
+ */
124
+ set shadowDistance(value: number);
125
+ /**
126
+ * Gets the shadow distance of the light.
127
+ * @returns The shadow distance.
128
+ */
129
+ get shadowDistance(): number;
130
+ /**
131
+ * Sets the type of the light.
132
+ * @param value - The type.
133
+ */
134
+ set type(value: string);
135
+ /**
136
+ * Gets the type of the light.
137
+ * @returns The type.
138
+ */
139
+ get type(): string;
140
+ static get observedAttributes(): string[];
141
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
142
+ }
143
+ export { LightComponentElement };
@@ -0,0 +1,16 @@
1
+ import { AudioListenerComponent } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * Represents a audio listener component in the PlayCanvas engine.
5
+ *
6
+ * @category Components
7
+ */
8
+ declare class ListenerComponentElement extends ComponentElement {
9
+ constructor();
10
+ /**
11
+ * Gets the audio listener component.
12
+ * @returns The audio listener component.
13
+ */
14
+ get component(): AudioListenerComponent | null;
15
+ }
16
+ export { ListenerComponentElement };
@@ -0,0 +1,56 @@
1
+ import { RenderComponent } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * Represents a render component in the PlayCanvas engine.
5
+ *
6
+ * @category Components
7
+ */
8
+ declare class RenderComponentElement extends ComponentElement {
9
+ private _type;
10
+ private _castShadows;
11
+ private _receiveShadows;
12
+ constructor();
13
+ getInitialComponentData(): {
14
+ type: "box" | "asset" | "capsule" | "cone" | "cylinder" | "plane" | "sphere";
15
+ castShadows: boolean;
16
+ receiveShadows: boolean;
17
+ };
18
+ /**
19
+ * Gets the render component.
20
+ * @returns The render component.
21
+ */
22
+ get component(): RenderComponent | null;
23
+ /**
24
+ * Sets the type of the render component.
25
+ * @param value - The type.
26
+ */
27
+ set type(value: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere');
28
+ /**
29
+ * Gets the type of the render component.
30
+ * @returns The type.
31
+ */
32
+ get type(): 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere';
33
+ /**
34
+ * Sets the cast shadows flag of the render component.
35
+ * @param value - The cast shadows flag.
36
+ */
37
+ set castShadows(value: boolean);
38
+ /**
39
+ * Gets the cast shadows flag of the render component.
40
+ * @returns The cast shadows flag.
41
+ */
42
+ get castShadows(): boolean;
43
+ /**
44
+ * Sets the receive shadows flag of the render component.
45
+ * @param value - The receive shadows flag.
46
+ */
47
+ set receiveShadows(value: boolean);
48
+ /**
49
+ * Gets the receive shadows flag of the render component.
50
+ * @returns The receive shadows flag.
51
+ */
52
+ get receiveShadows(): boolean;
53
+ static get observedAttributes(): string[];
54
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
55
+ }
56
+ export { RenderComponentElement };