Skip to content

Commit a62c6ae

Browse files
committed
build: prepared working component and demo app
1 parent be1588e commit a62c6ae

File tree

8 files changed

+65
-170
lines changed

8 files changed

+65
-170
lines changed

apps/lit/dev/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
</style>
1414
</head>
1515
<body>
16-
<lit-particles />
16+
<lit-particles options='{ "background": { "color": "#000" }, "particles": { "number": { "value": 100 } } }' />
1717
</body>
1818
</html>

apps/lit/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "lit-analyzer && eslint 'src/**/*.ts'",
1212
"format": "prettier src/* --write",
1313
"analyze": "wca analyze \"src/**/*.ts\" --outFile custom-elements.json",
14-
"serve": "es-dev-server",
14+
"serve": "web-dev-server",
1515
"checksize": "rollup -c ; cat my-element.bundled.js | gzip -9 | wc -c ; rm my-element.bundled.js"
1616
},
1717
"keywords": [
@@ -23,9 +23,9 @@
2323
"license": "BSD-3-Clause",
2424
"dependencies": {
2525
"lit": "^2.6.1",
26-
"lit-element": "^3.2.2",
2726
"lit-tsparticles": "^2.9.3",
28-
"tsparticles": "^2.9.3"
27+
"tsparticles": "^2.9.3",
28+
"tsparticles-engine": "^2.9.3"
2929
},
3030
"devDependencies": {
3131
"@11ty/eleventy": "^2.0.0",
@@ -37,18 +37,19 @@
3737
"@types/mocha": "^10.0.0",
3838
"@typescript-eslint/eslint-plugin": "^5.0.0",
3939
"@typescript-eslint/parser": "^5.0.0",
40+
"@web/dev-server": "^0.1.35",
4041
"chai": "^4.2.0",
4142
"deepmerge": "^4.2.2",
42-
"es-dev-server": "^2.0.0",
4343
"eslint": "^8.0.0",
4444
"karma": "^6.0.0",
4545
"karma-chai": "^0.1.0",
4646
"karma-mocha": "^2.0.0",
4747
"lit-analyzer": "^1.1.9",
4848
"mocha": "^10.0.0",
49+
"node-resolve": "^1.3.4",
4950
"prettier": "^2.0.0",
5051
"rimraf": "^4.0.0",
51-
"rollup": "^3.0.0",
52+
"rollup": "^2.79.1",
5253
"rollup-plugin-filesize": "^10.0.0",
5354
"rollup-plugin-node-resolve": "^5.2.0",
5455
"rollup-plugin-terser": "^7.0.0",

apps/lit/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
import "lit-tsparticles";
1+
import 'lit-tsparticles';
2+
import {loadFull} from 'tsparticles';
3+
import {tsParticles} from 'tsparticles-engine';
4+
5+
(async () => {
6+
await loadFull(tsParticles);
7+
})();

apps/lit/web-dev-server.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default {
22
open: true,
33
watch: true,
44
nodeResolve: true,
5-
appIndex: 'demo/index.html',
5+
appIndex: 'dev/index.html',
66
// in a monorepo you need to set the root dir to resolve modules
77
rootDir: '../../',
88
};

components/lit/demo/index.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

components/lit/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "2.9.3",
44
"description": "Official tsParticles Lit Component - Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for Web Components, Angular, React, Vue.js (2.x and 3.x), Svelte, jQuery, Preact, Riot.js, Solid.js, Inferno.",
55
"type": "module",
6-
"main": "lib/lit-tsparticles.js",
6+
"main": "./lib/lit-tsparticles.js",
77
"scripts": {
88
"serve": "wds --node-resolve -nwo demo",
99
"build": "tsc",
@@ -18,17 +18,13 @@
1818
],
1919
"dependencies": {
2020
"lit": "^2.6.1",
21-
"lit-element": "^3.2.2",
2221
"tsparticles-engine": "^2.9.3"
2322
},
2423
"devDependencies": {
25-
"@web/dev-server": "^0.1.32",
2624
"typescript": "^4.9.5"
2725
},
2826
"exports": {
29-
"./lib/lit-tsparticles.js": {
30-
"default": "./lib/lit-tsparticles.js"
31-
}
27+
".": "./lib/lit-tsparticles.js"
3228
},
3329
"files": [
3430
"/lib"

components/lit/src/lit-tsparticles.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { LitElement, html, PropertyValues } from "lit";
22
import { property, customElement } from "lit/decorators.js";
3-
import { Container, Engine, tsParticles } from "tsparticles-engine";
3+
import {
4+
Container,
5+
Engine,
6+
ISourceOptions,
7+
tsParticles,
8+
} from "tsparticles-engine";
49

510
/**
611
* The LitParticles element.
@@ -19,43 +24,31 @@ export class LitParticles extends LitElement {
1924
* The options
2025
*/
2126
@property({ type: Object })
22-
options = {};
27+
options?: ISourceOptions;
2328

24-
container?: Container;
25-
26-
initialized = false;
27-
28-
@property({ type: Function })
29-
particlesInit?: (engine: Engine) => Promise<void>;
30-
31-
@property({ type: Function })
32-
particlesLoaded?: (container?: Container) => Promise<void>;
33-
34-
connectedCallback() {
35-
super.connectedCallback();
29+
/**
30+
* The url
31+
*/
32+
@property({ type: String })
33+
url?: string;
3634

37-
this.particlesInit?.(tsParticles).then(() => {
38-
this.initialized = true;
39-
});
40-
}
35+
container?: Container;
4136

4237
update(changedProperties: PropertyValues) {
4338
super.update(changedProperties);
4439

45-
if (this.initialized) {
46-
tsParticles.load(this.id, this.options).then((container) => {
47-
this.container = container;
40+
const id = this.id ?? "tsparticles";
4841

49-
this.particlesLoaded?.(container);
50-
});
42+
if (this.options) {
43+
tsParticles.load(id, this.options);
44+
} else if (this.url) {
45+
tsParticles.loadJSON(id, this.url);
46+
} else {
47+
throw new Error("No options or url provided");
5148
}
5249
}
5350

5451
render() {
55-
if (!this.initialized) {
56-
return html``;
57-
}
58-
5952
return html`<div id=${this.id}>
6053
<canvas></canvas>
6154
</div>`;

0 commit comments

Comments
 (0)