@tsparticles/shape-spiral 3.0.0-alpha.0 → 3.0.0-beta.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.
@@ -4,22 +4,54 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
7
+ * v3.0.0-beta.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
11
- module.exports = factory();
11
+ module.exports = factory(require("@tsparticles/engine"));
12
12
  else if(typeof define === 'function' && define.amd)
13
- define([], factory);
13
+ define(["@tsparticles/engine"], factory);
14
14
  else {
15
- var a = factory();
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
16
  for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
17
  }
18
- })(this, () => {
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
19
19
  return /******/ (() => { // webpackBootstrap
20
20
  /******/ "use strict";
21
- /******/ // The require scope
22
- /******/ var __webpack_require__ = {};
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ })
29
+
30
+ /******/ });
31
+ /************************************************************************/
32
+ /******/ // The module cache
33
+ /******/ var __webpack_module_cache__ = {};
34
+ /******/
35
+ /******/ // The require function
36
+ /******/ function __webpack_require__(moduleId) {
37
+ /******/ // Check if module is in cache
38
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
39
+ /******/ if (cachedModule !== undefined) {
40
+ /******/ return cachedModule.exports;
41
+ /******/ }
42
+ /******/ // Create a new module (and put it into the cache)
43
+ /******/ var module = __webpack_module_cache__[moduleId] = {
44
+ /******/ // no module.id needed
45
+ /******/ // no module.loaded needed
46
+ /******/ exports: {}
47
+ /******/ };
48
+ /******/
49
+ /******/ // Execute the module function
50
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/
52
+ /******/ // Return the exports of the module
53
+ /******/ return module.exports;
54
+ /******/ }
23
55
  /******/
24
56
  /************************************************************************/
25
57
  /******/ /* webpack/runtime/define property getters */
@@ -52,41 +84,52 @@ return /******/ (() => { // webpackBootstrap
52
84
  /******/
53
85
  /************************************************************************/
54
86
  var __webpack_exports__ = {};
87
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
+ (() => {
55
89
  // ESM COMPAT FLAG
56
90
  __webpack_require__.r(__webpack_exports__);
57
91
 
58
92
  // EXPORTS
59
93
  __webpack_require__.d(__webpack_exports__, {
60
- "loadSpiralShape": () => (/* binding */ loadSpiralShape)
94
+ loadSpiralShape: () => (/* binding */ loadSpiralShape)
61
95
  });
62
96
 
97
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
98
+ var engine_root_window_ = __webpack_require__(533);
63
99
  ;// CONCATENATED MODULE: ./dist/browser/SpiralDrawer.js
100
+
64
101
  class SpiralDrawer {
65
102
  draw(context, particle, radius) {
66
- const spiral = particle,
67
- realWidth = (radius - spiral.spiralInnerRadius) / spiral.spiralLineSpacing;
68
- for (let i = 0; i < realWidth * 10; i++) {
69
- const angle = 0.1 * i,
70
- positionFactor = spiral.spiralInnerRadius + spiral.spiralLineSpacing * angle,
71
- x = positionFactor * Math.cos(angle),
72
- y = positionFactor * Math.sin(angle);
73
- context.lineTo(x, y);
103
+ if (particle.spiralInnerRadius === undefined || particle.spiralLineSpacing === undefined || particle.spiralWidthFactor === undefined) {
104
+ return;
105
+ }
106
+ const realWidth = (radius - particle.spiralInnerRadius) / particle.spiralLineSpacing,
107
+ widthFactor = 10;
108
+ for (let i = 0; i < realWidth * widthFactor; i++) {
109
+ const angle = i / widthFactor,
110
+ factor = particle.spiralInnerRadius + particle.spiralLineSpacing * angle,
111
+ pos = {
112
+ x: factor * Math.cos(angle),
113
+ y: factor * Math.sin(angle)
114
+ };
115
+ context.lineTo(pos.x, pos.y);
74
116
  }
75
117
  }
76
118
  particleInit(container, particle) {
77
- var _a, _b;
78
119
  const pixelRatio = container.retina.pixelRatio,
79
- shapeData = particle.shapeData,
80
- spiral = particle;
81
- spiral.spiralInnerRadius = ((_a = shapeData.innerRadius) !== null && _a !== void 0 ? _a : 1) * pixelRatio;
82
- spiral.spiralLineSpacing = ((_b = shapeData.lineSpacing) !== null && _b !== void 0 ? _b : 1) * pixelRatio;
120
+ shapeData = particle.shapeData;
121
+ particle.spiralInnerRadius = (0,engine_root_window_.getRangeValue)(shapeData.innerRadius ?? 1) * pixelRatio;
122
+ particle.spiralLineSpacing = (0,engine_root_window_.getRangeValue)(shapeData.lineSpacing ?? 1) * pixelRatio;
123
+ particle.spiralWidthFactor = (0,engine_root_window_.getRangeValue)(shapeData.widthFactor ?? 10);
83
124
  }
84
125
  }
85
126
  ;// CONCATENATED MODULE: ./dist/browser/index.js
86
127
 
87
- function loadSpiralShape(engine) {
88
- engine.addShape("spiral", new SpiralDrawer());
128
+ async function loadSpiralShape(engine, refresh = true) {
129
+ await engine.addShape("spiral", new SpiralDrawer(), refresh);
89
130
  }
131
+ })();
132
+
90
133
  /******/ return __webpack_exports__;
91
134
  /******/ })()
92
135
  ;
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.shape.spiral.min.js.LICENSE.txt */
2
- !function(e,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i();else if("function"==typeof define&&define.amd)define([],i);else{var n=i();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,(()=>(()=>{"use strict";var e={d:(i,n)=>{for(var o in n)e.o(n,o)&&!e.o(i,o)&&Object.defineProperty(i,o,{enumerable:!0,get:n[o]})},o:(e,i)=>Object.prototype.hasOwnProperty.call(e,i),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},i={};e.r(i),e.d(i,{loadSpiralShape:()=>o});class n{draw(e,i,n){const o=i,t=(n-o.spiralInnerRadius)/o.spiralLineSpacing;for(let i=0;i<10*t;i++){const n=.1*i,t=o.spiralInnerRadius+o.spiralLineSpacing*n,r=t*Math.cos(n),a=t*Math.sin(n);e.lineTo(r,a)}}particleInit(e,i){var n,o;const t=e.retina.pixelRatio,r=i.shapeData,a=i;a.spiralInnerRadius=(null!==(n=r.innerRadius)&&void 0!==n?n:1)*t,a.spiralLineSpacing=(null!==(o=r.lineSpacing)&&void 0!==o?o:1)*t}}function o(e){e.addShape("spiral",new n)}return i})()));
2
+ !function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],r);else{var i="object"==typeof exports?r(require("@tsparticles/engine")):r(e.window);for(var t in i)("object"==typeof exports?exports:e)[t]=i[t]}}(this,(e=>(()=>{"use strict";var r={533:r=>{r.exports=e}},i={};function t(e){var a=i[e];if(void 0!==a)return a.exports;var n=i[e]={exports:{}};return r[e](n,n.exports,t),n.exports}t.d=(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{t.r(a),t.d(a,{loadSpiralShape:()=>i});var e=t(533);class r{draw(e,r,i){if(void 0===r.spiralInnerRadius||void 0===r.spiralLineSpacing||void 0===r.spiralWidthFactor)return;const t=(i-r.spiralInnerRadius)/r.spiralLineSpacing;for(let i=0;i<10*t;i++){const t=i/10,a=r.spiralInnerRadius+r.spiralLineSpacing*t,n={x:a*Math.cos(t),y:a*Math.sin(t)};e.lineTo(n.x,n.y)}}particleInit(r,i){const t=r.retina.pixelRatio,a=i.shapeData;i.spiralInnerRadius=(0,e.getRangeValue)(a.innerRadius??1)*t,i.spiralLineSpacing=(0,e.getRangeValue)(a.lineSpacing??1)*t,i.spiralWidthFactor=(0,e.getRangeValue)(a.widthFactor??10)}}async function i(e,i=!0){await e.addShape("spiral",new r,i)}})(),a})()));
@@ -1,8 +1 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
8
- */
1
+ /*! tsParticles Spiral Shape v3.0.0-beta.0 by Matteo Bruni */
@@ -1,5 +1,6 @@
1
- import type { IShapeValues } from "@tsparticles/engine";
1
+ import type { IShapeValues, RangeValue } from "@tsparticles/engine";
2
2
  export interface ISpiralData extends IShapeValues {
3
- innerRadius: number;
4
- lineSpacing: number;
3
+ innerRadius: RangeValue;
4
+ lineSpacing: RangeValue;
5
+ widthFactor: RangeValue;
5
6
  }
@@ -1,5 +1,6 @@
1
- import type { Container, IParticle, IShapeDrawer } from "@tsparticles/engine";
1
+ import { type Container, type IShapeDrawer } from "@tsparticles/engine";
2
+ import type { SpiralParticle } from "./SpiralParticle";
2
3
  export declare class SpiralDrawer implements IShapeDrawer {
3
- draw(context: CanvasRenderingContext2D, particle: IParticle, radius: number): void;
4
- particleInit(container: Container, particle: IParticle): void;
4
+ draw(context: CanvasRenderingContext2D, particle: SpiralParticle, radius: number): void;
5
+ particleInit(container: Container, particle: SpiralParticle): void;
5
6
  }
@@ -0,0 +1,6 @@
1
+ import type { Particle } from "@tsparticles/engine";
2
+ export type SpiralParticle = Particle & {
3
+ spiralInnerRadius?: number;
4
+ spiralLineSpacing?: number;
5
+ spiralWidthFactor?: number;
6
+ };
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadSpiralShape(engine: Engine): void;
2
+ export declare function loadSpiralShape(engine: Engine, refresh?: boolean): Promise<void>;
@@ -4,25 +4,34 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SpiralDrawer = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
13
14
  class SpiralDrawer {
14
15
  draw(context, particle, radius) {
15
- const spiral = particle, realWidth = (radius - spiral.spiralInnerRadius) / spiral.spiralLineSpacing;
16
- for (let i = 0; i < realWidth * 10; i++) {
17
- const angle = 0.1 * i, positionFactor = spiral.spiralInnerRadius + spiral.spiralLineSpacing * angle, x = positionFactor * Math.cos(angle), y = positionFactor * Math.sin(angle);
18
- context.lineTo(x, y);
16
+ if (particle.spiralInnerRadius === undefined ||
17
+ particle.spiralLineSpacing === undefined ||
18
+ particle.spiralWidthFactor === undefined) {
19
+ return;
20
+ }
21
+ const realWidth = (radius - particle.spiralInnerRadius) / particle.spiralLineSpacing, widthFactor = 10;
22
+ for (let i = 0; i < realWidth * widthFactor; i++) {
23
+ const angle = i / widthFactor, factor = particle.spiralInnerRadius + particle.spiralLineSpacing * angle, pos = {
24
+ x: factor * Math.cos(angle),
25
+ y: factor * Math.sin(angle),
26
+ };
27
+ context.lineTo(pos.x, pos.y);
19
28
  }
20
29
  }
21
30
  particleInit(container, particle) {
22
- var _a, _b;
23
- const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData, spiral = particle;
24
- spiral.spiralInnerRadius = ((_a = shapeData.innerRadius) !== null && _a !== void 0 ? _a : 1) * pixelRatio;
25
- spiral.spiralLineSpacing = ((_b = shapeData.lineSpacing) !== null && _b !== void 0 ? _b : 1) * pixelRatio;
31
+ const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData;
32
+ particle.spiralInnerRadius = (0, engine_1.getRangeValue)(shapeData.innerRadius ?? 1) * pixelRatio;
33
+ particle.spiralLineSpacing = (0, engine_1.getRangeValue)(shapeData.lineSpacing ?? 1) * pixelRatio;
34
+ particle.spiralWidthFactor = (0, engine_1.getRangeValue)(shapeData.widthFactor ?? 10);
26
35
  }
27
36
  }
28
37
  exports.SpiralDrawer = SpiralDrawer;
package/umd/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadSpiralShape = void 0;
13
13
  const SpiralDrawer_1 = require("./SpiralDrawer");
14
- function loadSpiralShape(engine) {
15
- engine.addShape("spiral", new SpiralDrawer_1.SpiralDrawer());
14
+ async function loadSpiralShape(engine, refresh = true) {
15
+ await engine.addShape("spiral", new SpiralDrawer_1.SpiralDrawer(), refresh);
16
16
  }
17
17
  exports.loadSpiralShape = loadSpiralShape;
18
18
  });
@@ -1,5 +0,0 @@
1
- import type { IParticle } from "@tsparticles/engine";
2
- export interface ISpiralParticle extends IParticle {
3
- spiralInnerRadius: number;
4
- spiralLineSpacing: number;
5
- }
File without changes
File without changes
File without changes