Skip to content

Commit

Permalink
feat: fixed export plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed Jul 10, 2023
1 parent 8ba8a01 commit 775e7bd
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
3 changes: 3 additions & 0 deletions demo/vanilla/app.ts
Expand Up @@ -104,6 +104,9 @@ app.use("/plugin-easing-quad", express.static("./node_modules/tsparticles-plugin
app.use("/plugin-easing-quart", express.static("./node_modules/tsparticles-plugin-easing-quart"));
app.use("/plugin-easing-quint", express.static("./node_modules/tsparticles-plugin-easing-quint"));
app.use("/plugin-easing-sine", express.static("./node_modules/tsparticles-plugin-easing-sine"));
app.use("/plugin-export-image", express.static("./node_modules/tsparticles-plugin-export-image"));

Check warning

Code scanning / CodeQL

Exposure of private files Medium

Serves the folder "./node_modules/tsparticles-plugin-export-image", which can contain private information.
app.use("/plugin-export-json", express.static("./node_modules/tsparticles-plugin-export-json"));

Check warning

Code scanning / CodeQL

Exposure of private files Medium

Serves the folder "./node_modules/tsparticles-plugin-export-json", which can contain private information.
app.use("/plugin-export-video", express.static("./node_modules/tsparticles-plugin-export-video"));

Check warning

Code scanning / CodeQL

Exposure of private files Medium

Serves the folder "./node_modules/tsparticles-plugin-export-video", which can contain private information.
app.use("/plugin-hsv-color", express.static("./node_modules/tsparticles-plugin-hsv-color"));
app.use("/plugin-infection", express.static("./node_modules/tsparticles-plugin-infection"));
app.use("/plugin-motion", express.static("./node_modules/tsparticles-plugin-motion"));
Expand Down
3 changes: 3 additions & 0 deletions demo/vanilla/package.json
Expand Up @@ -88,6 +88,9 @@
"tsparticles-plugin-easing-quint": "^2.10.1",
"tsparticles-plugin-easing-sine": "^2.10.1",
"tsparticles-plugin-emitters": "^2.10.1",
"tsparticles-plugin-export-image": "^2.10.1",
"tsparticles-plugin-export-json": "^2.10.1",
"tsparticles-plugin-export-video": "^2.10.1",
"tsparticles-plugin-hsv-color": "^2.10.1",
"tsparticles-plugin-infection": "^2.10.1",
"tsparticles-plugin-motion": "^2.10.1",
Expand Down
19 changes: 13 additions & 6 deletions demo/vanilla/public/javascripts/demo.js
Expand Up @@ -150,6 +150,9 @@
await loadMotionPlugin(tsParticles);
await loadPolygonMaskPlugin(tsParticles);
await loadSoundsPlugin(tsParticles);
await loadExportImagePlugin(tsParticles);
await loadExportJSONPlugin(tsParticles);
await loadExportVideoPlugin(tsParticles);
await loadLightInteraction(tsParticles);
await loadParticlesRepulseInteraction(tsParticles);
await loadGradientUpdater(tsParticles);
Expand Down Expand Up @@ -248,7 +251,7 @@
const container = tsParticles.domItem(0);

if (container) {
container.exportImage(function(blob) {
container.export("image").then(function(blob) {
const modalBody = document.body.querySelector("#exportModal .modal-body .modal-body-content");

modalBody.innerHTML = "";
Expand All @@ -262,7 +265,7 @@

image.className = "img-fluid";
image.onload = () => URL.revokeObjectURL(image.src);
image.source = URL.createObjectURL(blob);
image.src = URL.createObjectURL(blob);

modalBody.appendChild(image);

Expand All @@ -277,13 +280,17 @@
const container = tsParticles.domItem(0);

if (container) {
const modalBody = document.body.querySelector("#exportModal .modal-body .modal-body-content");
container.export("json").then(function(blob) {
blob.text().then(function(json) {
const modalBody = document.body.querySelector("#exportModal .modal-body .modal-body-content");

modalBody.innerHTML = `<pre>${container.exportConfiguration()}</pre>`;
modalBody.innerHTML = `<pre>${json}</pre>`;

const exportModal = new bootstrap.Modal(document.getElementById("exportModal"));
const exportModal = new bootstrap.Modal(document.getElementById("exportModal"));

exportModal.show();
exportModal.show();
});
});
}
});

Expand Down
3 changes: 3 additions & 0 deletions demo/vanilla/views/index.pug
Expand Up @@ -151,6 +151,9 @@ html(lang="en")
script(src="/plugin-easing-quart/tsparticles.plugin.easing.quart.js")
script(src="/plugin-easing-quint/tsparticles.plugin.easing.quint.js")
script(src="/plugin-easing-sine/tsparticles.plugin.easing.sine.js")
script(src="/plugin-export-image/tsparticles.plugin.export.image.js")
script(src="/plugin-export-json/tsparticles.plugin.export.json.js")
script(src="/plugin-export-video/tsparticles.plugin.export.video.js")
script(src="/plugin-hsv-color/tsparticles.plugin.hsvColor.js")
script(src="/plugin-infection/tsparticles.plugin.infection.js")
script(src="/plugin-motion/tsparticles.plugin.motion.js")
Expand Down
2 changes: 1 addition & 1 deletion engine/src/Core/Container.ts
Expand Up @@ -423,7 +423,7 @@ export class Container {
});
}

async export(type: string, options: Record<string, unknown>): Promise<Blob | undefined> {
async export(type: string, options: Record<string, unknown> = {}): Promise<Blob | undefined> {
for (const [, plugin] of this.plugins) {
if (!plugin.export) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion plugins/exports/image/src/index.ts
Expand Up @@ -9,7 +9,7 @@ class ExportImagePlugin implements IPlugin {
private readonly _engine;

constructor(engine: Engine) {
this.id = "sounds";
this.id = "export-image";

this._engine = engine;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/exports/json/src/index.ts
Expand Up @@ -9,7 +9,7 @@ class ExportJSONPlugin implements IPlugin {
private readonly _engine;

constructor(engine: Engine) {
this.id = "sounds";
this.id = "export-json";

this._engine = engine;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/exports/video/src/index.ts
Expand Up @@ -9,7 +9,7 @@ class ExportVideoPlugin implements IPlugin {
private readonly _engine;

constructor(engine: Engine) {
this.id = "sounds";
this.id = "export-video";

this._engine = engine;
}
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 775e7bd

Please sign in to comment.