@tsparticles/shape-cards 4.0.0-beta.1 → 4.0.0-beta.3

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.
Files changed (50) hide show
  1. package/browser/cards/index.js +2 -1
  2. package/browser/clubs/index.js +2 -1
  3. package/browser/diamonds/index.js +2 -1
  4. package/browser/hearts/index.js +2 -1
  5. package/browser/index.js +7 -23
  6. package/browser/spades/index.js +2 -1
  7. package/browser/suits.js +22 -0
  8. package/cjs/cards/index.js +2 -1
  9. package/cjs/clubs/index.js +2 -1
  10. package/cjs/diamonds/index.js +2 -1
  11. package/cjs/hearts/index.js +2 -1
  12. package/cjs/index.js +7 -23
  13. package/cjs/spades/index.js +2 -1
  14. package/cjs/suits.js +22 -0
  15. package/dist_browser_cards_CardDrawer_js.js +1 -1
  16. package/dist_browser_clubs_ClubDrawer_js.js +1 -1
  17. package/dist_browser_diamonds_DiamondDrawer_js.js +1 -1
  18. package/dist_browser_hearts_HeartDrawer_js.js +1 -1
  19. package/dist_browser_spades_SpadeDrawer_js.js +1 -1
  20. package/esm/cards/index.js +2 -1
  21. package/esm/clubs/index.js +2 -1
  22. package/esm/diamonds/index.js +2 -1
  23. package/esm/hearts/index.js +2 -1
  24. package/esm/index.js +7 -23
  25. package/esm/spades/index.js +2 -1
  26. package/esm/suits.js +22 -0
  27. package/package.json +45 -4
  28. package/report.html +1 -1
  29. package/tsparticles.shape.cards.js +17 -7
  30. package/tsparticles.shape.cards.min.js +2 -2
  31. package/types/index.d.ts +1 -5
  32. package/types/suits.d.ts +6 -0
  33. package/umd/CardParticle.js +0 -12
  34. package/umd/CardValue.js +0 -29
  35. package/umd/ICardData.js +0 -12
  36. package/umd/ICardSuitsPath.js +0 -12
  37. package/umd/SuitType.js +0 -20
  38. package/umd/cards/CardDrawer.js +0 -39
  39. package/umd/cards/index.js +0 -56
  40. package/umd/clubs/ClubDrawer.js +0 -22
  41. package/umd/clubs/index.js +0 -56
  42. package/umd/diamonds/DiamondDrawer.js +0 -22
  43. package/umd/diamonds/index.js +0 -56
  44. package/umd/hearts/HeartDrawer.js +0 -22
  45. package/umd/hearts/index.js +0 -56
  46. package/umd/index.js +0 -83
  47. package/umd/paths.js +0 -187
  48. package/umd/spades/SpadeDrawer.js +0 -22
  49. package/umd/spades/index.js +0 -56
  50. package/umd/utils.js +0 -113
package/umd/paths.js DELETED
@@ -1,187 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/path-utils", "@tsparticles/engine", "./SuitType.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.paths = exports.spade = exports.heart = exports.diamond = exports.club = void 0;
13
- const path_utils_1 = require("@tsparticles/path-utils");
14
- const engine_1 = require("@tsparticles/engine");
15
- const SuitType_js_1 = require("./SuitType.js");
16
- const eighth = engine_1.quarter * engine_1.half, n = engine_1.half, halfN = n * engine_1.half, oppositeN = -n, oppositeHalfN = -halfN, eighthN = n * eighth, threeQuarterN = n * engine_1.threeQuarter;
17
- exports.club = {
18
- half: true,
19
- segments: [
20
- {
21
- type: path_utils_1.SegmentType.bezier,
22
- values: [
23
- { x: engine_1.empty, y: oppositeN },
24
- { x: engine_1.empty, y: oppositeN },
25
- { x: halfN, y: oppositeN },
26
- { x: halfN, y: oppositeHalfN },
27
- ],
28
- },
29
- {
30
- type: path_utils_1.SegmentType.bezier,
31
- values: [
32
- { x: halfN, y: oppositeHalfN },
33
- { x: halfN, y: oppositeHalfN },
34
- { x: n, y: oppositeHalfN },
35
- { x: n, y: engine_1.empty },
36
- ],
37
- },
38
- {
39
- type: path_utils_1.SegmentType.bezier,
40
- values: [
41
- { x: n, y: engine_1.empty },
42
- { x: n, y: engine_1.empty },
43
- { x: n, y: halfN },
44
- { x: halfN, y: halfN },
45
- ],
46
- },
47
- {
48
- type: path_utils_1.SegmentType.bezier,
49
- values: [
50
- { x: halfN, y: halfN },
51
- { x: halfN, y: halfN },
52
- { x: eighthN, y: halfN },
53
- { x: eighthN, y: eighthN },
54
- ],
55
- },
56
- {
57
- type: path_utils_1.SegmentType.bezier,
58
- values: [
59
- { x: eighthN, y: eighthN },
60
- { x: eighthN, y: halfN },
61
- { x: halfN, y: n },
62
- { x: halfN, y: n },
63
- ],
64
- },
65
- {
66
- type: path_utils_1.SegmentType.bezier,
67
- values: [
68
- { x: halfN, y: n },
69
- { x: halfN, y: n },
70
- { x: engine_1.empty, y: n },
71
- { x: engine_1.empty, y: n },
72
- ],
73
- },
74
- ],
75
- };
76
- exports.diamond = {
77
- half: true,
78
- segments: [
79
- {
80
- type: path_utils_1.SegmentType.bezier,
81
- values: [
82
- { x: engine_1.empty, y: n },
83
- { x: engine_1.empty, y: n },
84
- { x: threeQuarterN, y: engine_1.empty },
85
- { x: threeQuarterN, y: engine_1.empty },
86
- ],
87
- },
88
- {
89
- type: path_utils_1.SegmentType.bezier,
90
- values: [
91
- { x: threeQuarterN, y: engine_1.empty },
92
- { x: threeQuarterN, y: engine_1.empty },
93
- { x: engine_1.empty, y: oppositeN },
94
- { x: engine_1.empty, y: oppositeN },
95
- ],
96
- },
97
- ],
98
- };
99
- exports.heart = {
100
- half: true,
101
- segments: [
102
- {
103
- type: path_utils_1.SegmentType.bezier,
104
- values: [
105
- { x: engine_1.empty, y: n },
106
- { x: engine_1.empty, y: n },
107
- { x: n, y: engine_1.empty },
108
- { x: n, y: oppositeHalfN },
109
- ],
110
- },
111
- {
112
- type: path_utils_1.SegmentType.bezier,
113
- values: [
114
- { x: n, y: oppositeHalfN },
115
- { x: n, y: oppositeHalfN },
116
- { x: n, y: oppositeN },
117
- { x: halfN, y: oppositeN },
118
- ],
119
- },
120
- {
121
- type: path_utils_1.SegmentType.bezier,
122
- values: [
123
- { x: halfN, y: oppositeN },
124
- { x: halfN, y: oppositeN },
125
- { x: engine_1.empty, y: oppositeN },
126
- { x: engine_1.empty, y: oppositeHalfN },
127
- ],
128
- },
129
- ],
130
- };
131
- exports.spade = {
132
- half: true,
133
- segments: [
134
- {
135
- type: path_utils_1.SegmentType.bezier,
136
- values: [
137
- { x: engine_1.empty, y: oppositeN },
138
- { x: engine_1.empty, y: oppositeN },
139
- { x: n, y: oppositeHalfN },
140
- { x: n, y: engine_1.empty },
141
- ],
142
- },
143
- {
144
- type: path_utils_1.SegmentType.bezier,
145
- values: [
146
- { x: n, y: engine_1.empty },
147
- { x: n, y: engine_1.empty },
148
- { x: n, y: halfN },
149
- { x: halfN, y: halfN },
150
- ],
151
- },
152
- {
153
- type: path_utils_1.SegmentType.bezier,
154
- values: [
155
- { x: halfN, y: halfN },
156
- { x: halfN, y: halfN },
157
- { x: eighthN, y: halfN },
158
- { x: eighthN, y: eighthN },
159
- ],
160
- },
161
- {
162
- type: path_utils_1.SegmentType.bezier,
163
- values: [
164
- { x: eighthN, y: eighthN },
165
- { x: eighthN, y: halfN },
166
- { x: halfN, y: n },
167
- { x: halfN, y: n },
168
- ],
169
- },
170
- {
171
- type: path_utils_1.SegmentType.bezier,
172
- values: [
173
- { x: halfN, y: n },
174
- { x: halfN, y: n },
175
- { x: engine_1.empty, y: n },
176
- { x: engine_1.empty, y: n },
177
- ],
178
- },
179
- ],
180
- };
181
- exports.paths = {
182
- [SuitType_js_1.SuitType.hearts]: exports.heart,
183
- [SuitType_js_1.SuitType.diamonds]: exports.diamond,
184
- [SuitType_js_1.SuitType.clubs]: exports.club,
185
- [SuitType_js_1.SuitType.spades]: exports.spade,
186
- };
187
- });
@@ -1,22 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/path-utils", "../paths.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SpadeDrawer = void 0;
13
- const path_utils_1 = require("@tsparticles/path-utils");
14
- const paths_js_1 = require("../paths.js");
15
- class SpadeDrawer {
16
- draw(data) {
17
- const { context, radius } = data;
18
- (0, path_utils_1.drawPath)(context, radius, paths_js_1.paths.spades);
19
- }
20
- }
21
- exports.SpadeDrawer = SpadeDrawer;
22
- });
@@ -1,56 +0,0 @@
1
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
- if (k2 === undefined) k2 = k;
3
- var desc = Object.getOwnPropertyDescriptor(m, k);
4
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
- desc = { enumerable: true, get: function() { return m[k]; } };
6
- }
7
- Object.defineProperty(o, k2, desc);
8
- }) : (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- o[k2] = m[k];
11
- }));
12
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
- Object.defineProperty(o, "default", { enumerable: true, value: v });
14
- }) : function(o, v) {
15
- o["default"] = v;
16
- });
17
- var __importStar = (this && this.__importStar) || (function () {
18
- var ownKeys = function(o) {
19
- ownKeys = Object.getOwnPropertyNames || function (o) {
20
- var ar = [];
21
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
22
- return ar;
23
- };
24
- return ownKeys(o);
25
- };
26
- return function (mod) {
27
- if (mod && mod.__esModule) return mod;
28
- var result = {};
29
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
30
- __setModuleDefault(result, mod);
31
- return result;
32
- };
33
- })();
34
- (function (factory) {
35
- if (typeof module === "object" && typeof module.exports === "object") {
36
- var v = factory(require, exports);
37
- if (v !== undefined) module.exports = v;
38
- }
39
- else if (typeof define === "function" && define.amd) {
40
- define(["require", "exports"], factory);
41
- }
42
- })(function (require, exports) {
43
- "use strict";
44
- var __syncRequire = typeof module === "object" && typeof module.exports === "object";
45
- Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.loadSpadesSuitShape = loadSpadesSuitShape;
47
- async function loadSpadesSuitShape(engine) {
48
- engine.checkVersion("4.0.0-beta.1");
49
- await engine.pluginManager.register(e => {
50
- e.pluginManager.addShape(["spade", "spades"], async () => {
51
- const { SpadeDrawer } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./SpadeDrawer.js"))) : new Promise((resolve_1, reject_1) => { require(["./SpadeDrawer.js"], resolve_1, reject_1); }).then(__importStar));
52
- return new SpadeDrawer();
53
- });
54
- });
55
- }
56
- });
package/umd/utils.js DELETED
@@ -1,113 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "./SuitType.js", "@tsparticles/path-utils", "./paths.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.drawRoundedCard = drawRoundedCard;
13
- const engine_1 = require("@tsparticles/engine");
14
- const SuitType_js_1 = require("./SuitType.js");
15
- const path_utils_1 = require("@tsparticles/path-utils");
16
- const paths_js_1 = require("./paths.js");
17
- const cardWidthRatio = (engine_1.double * engine_1.double) / engine_1.triple, cardHeightRatio = engine_1.double, cornerRadiusRatio = 0.2, cornerFontRatio = 0.4, cornerSuitRatio = 0.3, centerSuitRatio = 0.7, cornerPaddingRatio = 0.2, textHorizontalOffsetRatio = 0.25, minRadius = 0, minAngle = 0, suitEdgeBufferFactor = 0.1, fixedCacheKey = 2, cardsCache = new Map(), redSuitColor = { r: 215, g: 20, b: 20 }, blackSuitColor = { r: 18, g: 18, b: 18 };
18
- function drawRoundedCard(ctx, radius, cardData, hdr, flipped, canvasSettings) {
19
- if (flipped) {
20
- drawRoundedCardBack(ctx, radius);
21
- }
22
- else {
23
- const cacheKey = getCacheKey(radius, hdr, cardData), cardWidth = radius * cardWidthRatio, cardHeight = radius * cardHeightRatio, halfWidth = cardWidth * engine_1.half, halfHeight = cardHeight * engine_1.half;
24
- let cachedData = cardsCache.get(cacheKey);
25
- if (!cachedData) {
26
- let cacheCanvas, cacheCtx;
27
- if (typeof OffscreenCanvas === "undefined") {
28
- cacheCanvas = (0, engine_1.safeDocument)().createElement("canvas");
29
- cacheCanvas.width = cardWidth;
30
- cacheCanvas.height = cardHeight;
31
- cacheCtx = cacheCanvas.getContext("2d", canvasSettings);
32
- }
33
- else {
34
- cacheCanvas = new OffscreenCanvas(cardWidth, cardHeight);
35
- cacheCtx = cacheCanvas.getContext("2d", canvasSettings);
36
- }
37
- if (cacheCtx) {
38
- cacheCtx.translate(halfWidth, halfHeight);
39
- drawRoundedCardFront(cacheCtx, radius, cardData, hdr);
40
- cachedData = cacheCanvas instanceof HTMLCanvasElement ? cacheCanvas : cacheCanvas.transferToImageBitmap();
41
- cardsCache.set(cacheKey, cachedData);
42
- }
43
- }
44
- if (cachedData) {
45
- ctx.drawImage(cachedData, -halfWidth, -halfHeight, cardWidth, cardHeight);
46
- }
47
- else {
48
- drawRoundedCardFront(ctx, radius, cardData, hdr);
49
- }
50
- }
51
- }
52
- function getCacheKey(radius, hdr, cardData) {
53
- return `${radius.toFixed(fixedCacheKey)}-${hdr ? "hdr" : "sdr"}-${cardData.suit}-${cardData.value}`;
54
- }
55
- function drawRoundedCardBack(ctx, radius) {
56
- drawCardBody(ctx, radius);
57
- }
58
- function drawRoundedCardFront(ctx, radius, cardData, hdr) {
59
- const { suit, value } = cardData, cardWidth = radius * cardWidthRatio, cardHeight = radius * cardHeightRatio, halfWidth = cardWidth * engine_1.half, halfHeight = cardHeight * engine_1.half, cornerPadding = radius * cornerPaddingRatio, cornerFontSize = radius * cornerFontRatio, cornerSuitSize = radius * cornerSuitRatio, centerSuitSize = radius * centerSuitRatio, textOffset = radius * textHorizontalOffsetRatio, suitEdgeBuffer = radius * suitEdgeBufferFactor, isRed = suit === SuitType_js_1.SuitType.hearts || suit === SuitType_js_1.SuitType.diamonds, color = isRed ? (0, engine_1.getStyleFromRgb)(redSuitColor, hdr) : (0, engine_1.getStyleFromRgb)(blackSuitColor, hdr);
60
- ctx.save();
61
- drawCardBody(ctx, radius);
62
- ctx.fillStyle = (0, engine_1.getStyleFromRgb)({ r: 255, g: 255, b: 255 }, hdr);
63
- ctx.fill();
64
- ctx.strokeStyle = (0, engine_1.getStyleFromRgb)({ r: 0, g: 0, b: 0 }, hdr);
65
- ctx.stroke();
66
- ctx.fillStyle = color;
67
- ctx.font = `bold ${cornerFontSize.toString()}px Arial, serif`;
68
- ctx.textAlign = "left";
69
- ctx.textBaseline = "middle";
70
- const topLeftX = -halfWidth + cornerPadding + suitEdgeBuffer, topLeftY = -halfHeight + cornerPadding + cornerFontSize * engine_1.half;
71
- ctx.save();
72
- ctx.translate(topLeftX, topLeftY);
73
- ctx.beginPath();
74
- (0, path_utils_1.drawPath)(ctx, cornerSuitSize, paths_js_1.paths[suit]);
75
- ctx.fill();
76
- ctx.restore();
77
- ctx.fillText(value, topLeftX + textOffset, topLeftY);
78
- ctx.save();
79
- ctx.translate(halfWidth - cornerPadding - suitEdgeBuffer, halfHeight - cornerPadding - cornerFontSize * engine_1.half);
80
- ctx.rotate(Math.PI);
81
- ctx.save();
82
- ctx.beginPath();
83
- (0, path_utils_1.drawPath)(ctx, cornerSuitSize, paths_js_1.paths[suit]);
84
- ctx.fill();
85
- ctx.restore();
86
- ctx.fillText(value, engine_1.originPoint.x + textOffset, engine_1.originPoint.y);
87
- ctx.restore();
88
- ctx.save();
89
- ctx.beginPath();
90
- (0, path_utils_1.drawPath)(ctx, centerSuitSize, paths_js_1.paths[suit]);
91
- ctx.fillStyle = color;
92
- ctx.fill();
93
- ctx.restore();
94
- ctx.beginPath();
95
- ctx.arc(engine_1.originPoint.x, engine_1.originPoint.y, minRadius, minAngle, engine_1.doublePI, false);
96
- ctx.closePath();
97
- ctx.restore();
98
- }
99
- function drawCardBody(ctx, radius) {
100
- const cardWidth = radius * cardWidthRatio, cardHeight = radius * cardHeightRatio, halfWidth = cardWidth * engine_1.half, halfHeight = cardHeight * engine_1.half, cornerRadius = radius * cornerRadiusRatio;
101
- ctx.beginPath();
102
- ctx.moveTo(-halfWidth + cornerRadius, -halfHeight);
103
- ctx.lineTo(halfWidth - cornerRadius, -halfHeight);
104
- ctx.quadraticCurveTo(halfWidth, -halfHeight, halfWidth, -halfHeight + cornerRadius);
105
- ctx.lineTo(halfWidth, halfHeight - cornerRadius);
106
- ctx.quadraticCurveTo(halfWidth, halfHeight, halfWidth - cornerRadius, halfHeight);
107
- ctx.lineTo(-halfWidth + cornerRadius, halfHeight);
108
- ctx.quadraticCurveTo(-halfWidth, halfHeight, -halfWidth, halfHeight - cornerRadius);
109
- ctx.lineTo(-halfWidth, -halfHeight + cornerRadius);
110
- ctx.quadraticCurveTo(-halfWidth, -halfHeight, -halfWidth + cornerRadius, -halfHeight);
111
- ctx.closePath();
112
- }
113
- });