@tsparticles/shape-cards 4.0.0-alpha.8 → 4.0.0-beta.1
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/27.min.js +1 -0
- package/453.min.js +1 -0
- package/555.min.js +1 -0
- package/691.min.js +1 -0
- package/959.min.js +1 -0
- package/browser/cards/CardDrawer.js +8 -4
- package/browser/cards/index.js +6 -4
- package/browser/clubs/ClubDrawer.js +0 -3
- package/browser/clubs/index.js +6 -4
- package/browser/diamonds/DiamondDrawer.js +0 -3
- package/browser/diamonds/index.js +6 -4
- package/browser/hearts/HeartDrawer.js +0 -3
- package/browser/hearts/index.js +6 -4
- package/browser/index.js +20 -11
- package/browser/spades/SpadeDrawer.js +0 -3
- package/browser/spades/index.js +6 -4
- package/browser/utils.js +28 -18
- package/cjs/cards/CardDrawer.js +8 -4
- package/cjs/cards/index.js +6 -4
- package/cjs/clubs/ClubDrawer.js +0 -3
- package/cjs/clubs/index.js +6 -4
- package/cjs/diamonds/DiamondDrawer.js +0 -3
- package/cjs/diamonds/index.js +6 -4
- package/cjs/hearts/HeartDrawer.js +0 -3
- package/cjs/hearts/index.js +6 -4
- package/cjs/index.js +20 -11
- package/cjs/spades/SpadeDrawer.js +0 -3
- package/cjs/spades/index.js +6 -4
- package/cjs/utils.js +28 -18
- package/dist_browser_cards_CardDrawer_js.js +5 -5
- package/dist_browser_clubs_ClubDrawer_js.js +4 -4
- package/dist_browser_diamonds_DiamondDrawer_js.js +4 -4
- package/dist_browser_hearts_HeartDrawer_js.js +4 -4
- package/dist_browser_spades_SpadeDrawer_js.js +4 -4
- package/esm/cards/CardDrawer.js +8 -4
- package/esm/cards/index.js +6 -4
- package/esm/clubs/ClubDrawer.js +0 -3
- package/esm/clubs/index.js +6 -4
- package/esm/diamonds/DiamondDrawer.js +0 -3
- package/esm/diamonds/index.js +6 -4
- package/esm/hearts/HeartDrawer.js +0 -3
- package/esm/hearts/index.js +6 -4
- package/esm/index.js +20 -11
- package/esm/spades/SpadeDrawer.js +0 -3
- package/esm/spades/index.js +6 -4
- package/esm/utils.js +28 -18
- package/package.json +3 -3
- package/report.html +84 -29
- package/tsparticles.shape.cards.js +47 -35
- package/tsparticles.shape.cards.min.js +2 -2
- package/types/cards/CardDrawer.d.ts +2 -1
- package/types/clubs/ClubDrawer.d.ts +0 -1
- package/types/diamonds/DiamondDrawer.d.ts +0 -1
- package/types/hearts/HeartDrawer.d.ts +0 -1
- package/types/spades/SpadeDrawer.d.ts +0 -1
- package/types/utils.d.ts +2 -1
- package/umd/cards/CardDrawer.js +8 -4
- package/umd/cards/index.js +6 -4
- package/umd/clubs/ClubDrawer.js +0 -3
- package/umd/clubs/index.js +6 -4
- package/umd/diamonds/DiamondDrawer.js +0 -3
- package/umd/diamonds/index.js +6 -4
- package/umd/hearts/HeartDrawer.js +0 -3
- package/umd/hearts/index.js +6 -4
- package/umd/index.js +20 -11
- package/umd/spades/SpadeDrawer.js +0 -3
- package/umd/spades/index.js +6 -4
- package/umd/utils.js +27 -17
- package/35.min.js +0 -2
- package/35.min.js.LICENSE.txt +0 -1
- package/475.min.js +0 -2
- package/475.min.js.LICENSE.txt +0 -1
- package/505.min.js +0 -2
- package/505.min.js.LICENSE.txt +0 -1
- package/657.min.js +0 -2
- package/657.min.js.LICENSE.txt +0 -1
- package/741.min.js +0 -2
- package/741.min.js.LICENSE.txt +0 -1
- package/tsparticles.shape.cards.min.js.LICENSE.txt +0 -1
package/esm/index.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
export async function loadCardSuitsShape(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
3
|
-
await engine.register(async (e) => {
|
|
4
|
-
const { loadClubsSuitShape }
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.1");
|
|
3
|
+
await engine.pluginManager.register(async (e) => {
|
|
4
|
+
const [{ loadClubsSuitShape }, { loadDiamondsSuitShape }, { loadHeartsSuitShape }, { loadSpadesSuitShape },] = await Promise.all([
|
|
5
|
+
import("./clubs/index.js"),
|
|
6
|
+
import("./diamonds/index.js"),
|
|
7
|
+
import("./hearts/index.js"),
|
|
8
|
+
import("./spades/index.js"),
|
|
9
|
+
]);
|
|
10
|
+
await Promise.all([
|
|
11
|
+
loadClubsSuitShape(e),
|
|
12
|
+
loadDiamondsSuitShape(e),
|
|
13
|
+
loadHeartsSuitShape(e),
|
|
14
|
+
loadSpadesSuitShape(e),
|
|
15
|
+
]);
|
|
9
16
|
});
|
|
10
17
|
}
|
|
11
18
|
export async function loadCardsShape(engine) {
|
|
12
|
-
engine.checkVersion("4.0.0-
|
|
13
|
-
await engine.register(async (e) => {
|
|
19
|
+
engine.checkVersion("4.0.0-beta.1");
|
|
20
|
+
await engine.pluginManager.register(async (e) => {
|
|
14
21
|
const { loadFullCardsShape } = await import("./cards/index.js");
|
|
15
|
-
await
|
|
16
|
-
|
|
22
|
+
await Promise.all([
|
|
23
|
+
loadFullCardsShape(e),
|
|
24
|
+
loadCardSuitsShape(e),
|
|
25
|
+
]);
|
|
17
26
|
});
|
|
18
27
|
}
|
|
19
28
|
export * from "./cards/index.js";
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { drawPath } from "@tsparticles/path-utils";
|
|
2
2
|
import { paths } from "../paths.js";
|
|
3
3
|
export class SpadeDrawer {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.validTypes = ["spade", "spades"];
|
|
6
|
-
}
|
|
7
4
|
draw(data) {
|
|
8
5
|
const { context, radius } = data;
|
|
9
6
|
drawPath(context, radius, paths.spades);
|
package/esm/spades/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export async function loadSpadesSuitShape(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
3
|
-
await engine.register(
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.1");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addShape(["spade", "spades"], async () => {
|
|
5
|
+
const { SpadeDrawer } = await import("./SpadeDrawer.js");
|
|
6
|
+
return new SpadeDrawer();
|
|
7
|
+
});
|
|
6
8
|
});
|
|
7
9
|
}
|
package/esm/utils.js
CHANGED
|
@@ -1,39 +1,50 @@
|
|
|
1
|
-
import { double, doublePI, getStyleFromRgb, half, originPoint, triple } from "@tsparticles/engine";
|
|
1
|
+
import { double, doublePI, getStyleFromRgb, half, originPoint, safeDocument, triple, } from "@tsparticles/engine";
|
|
2
2
|
import { SuitType } from "./SuitType.js";
|
|
3
3
|
import { drawPath } from "@tsparticles/path-utils";
|
|
4
4
|
import { paths } from "./paths.js";
|
|
5
|
-
const cardWidthRatio = (double * double) / triple, cardHeightRatio = double, cornerRadiusRatio = 0.2, cornerFontRatio = 0.4, cornerSuitRatio = 0.3, centerSuitRatio = 0.
|
|
6
|
-
export function drawRoundedCard(ctx, radius, cardData, hdr, flipped) {
|
|
5
|
+
const cardWidthRatio = (double * double) / triple, cardHeightRatio = 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 };
|
|
6
|
+
export function drawRoundedCard(ctx, radius, cardData, hdr, flipped, canvasSettings) {
|
|
7
7
|
if (flipped) {
|
|
8
8
|
drawRoundedCardBack(ctx, radius);
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
|
-
const cacheKey = getCacheKey(radius, cardData), cardWidth = radius * cardWidthRatio, cardHeight = radius * cardHeightRatio, halfWidth = cardWidth * half, halfHeight = cardHeight * half;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const cacheKey = getCacheKey(radius, hdr, cardData), cardWidth = radius * cardWidthRatio, cardHeight = radius * cardHeightRatio, halfWidth = cardWidth * half, halfHeight = cardHeight * half;
|
|
12
|
+
let cachedData = cardsCache.get(cacheKey);
|
|
13
|
+
if (!cachedData) {
|
|
14
|
+
let cacheCanvas, cacheCtx;
|
|
15
|
+
if (typeof OffscreenCanvas === "undefined") {
|
|
16
|
+
cacheCanvas = safeDocument().createElement("canvas");
|
|
17
|
+
cacheCanvas.width = cardWidth;
|
|
18
|
+
cacheCanvas.height = cardHeight;
|
|
19
|
+
cacheCtx = cacheCanvas.getContext("2d", canvasSettings);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
cacheCanvas = new OffscreenCanvas(cardWidth, cardHeight);
|
|
23
|
+
cacheCtx = cacheCanvas.getContext("2d", canvasSettings);
|
|
24
|
+
}
|
|
25
|
+
if (cacheCtx) {
|
|
26
|
+
cacheCtx.translate(halfWidth, halfHeight);
|
|
27
|
+
drawRoundedCardFront(cacheCtx, radius, cardData, hdr);
|
|
28
|
+
cachedData = cacheCanvas instanceof HTMLCanvasElement ? cacheCanvas : cacheCanvas.transferToImageBitmap();
|
|
29
|
+
cardsCache.set(cacheKey, cachedData);
|
|
18
30
|
}
|
|
19
31
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ctx.drawImage(cachedCanvas, -halfWidth, -halfHeight, cardWidth, cardHeight);
|
|
32
|
+
if (cachedData) {
|
|
33
|
+
ctx.drawImage(cachedData, -halfWidth, -halfHeight, cardWidth, cardHeight);
|
|
23
34
|
}
|
|
24
35
|
else {
|
|
25
36
|
drawRoundedCardFront(ctx, radius, cardData, hdr);
|
|
26
37
|
}
|
|
27
38
|
}
|
|
28
39
|
}
|
|
29
|
-
function getCacheKey(radius, cardData) {
|
|
30
|
-
return `${radius.toFixed(fixedCacheKey)}-${cardData.suit}-${cardData.value}`;
|
|
40
|
+
function getCacheKey(radius, hdr, cardData) {
|
|
41
|
+
return `${radius.toFixed(fixedCacheKey)}-${hdr ? "hdr" : "sdr"}-${cardData.suit}-${cardData.value}`;
|
|
31
42
|
}
|
|
32
43
|
function drawRoundedCardBack(ctx, radius) {
|
|
33
44
|
drawCardBody(ctx, radius);
|
|
34
45
|
}
|
|
35
46
|
function drawRoundedCardFront(ctx, radius, cardData, hdr) {
|
|
36
|
-
const { suit, value } = cardData, cardWidth = radius * cardWidthRatio, cardHeight = radius * cardHeightRatio, halfWidth = cardWidth * half, halfHeight = cardHeight * half, cornerPadding = radius * cornerPaddingRatio, cornerFontSize = radius * cornerFontRatio, cornerSuitSize = radius * cornerSuitRatio, centerSuitSize = radius * centerSuitRatio, textOffset = radius * textHorizontalOffsetRatio, suitEdgeBuffer = radius * suitEdgeBufferFactor, isRed = suit === SuitType.hearts || suit === SuitType.diamonds, color = isRed ? getStyleFromRgb(
|
|
47
|
+
const { suit, value } = cardData, cardWidth = radius * cardWidthRatio, cardHeight = radius * cardHeightRatio, halfWidth = cardWidth * half, halfHeight = cardHeight * half, cornerPadding = radius * cornerPaddingRatio, cornerFontSize = radius * cornerFontRatio, cornerSuitSize = radius * cornerSuitRatio, centerSuitSize = radius * centerSuitRatio, textOffset = radius * textHorizontalOffsetRatio, suitEdgeBuffer = radius * suitEdgeBufferFactor, isRed = suit === SuitType.hearts || suit === SuitType.diamonds, color = isRed ? getStyleFromRgb(redSuitColor, hdr) : getStyleFromRgb(blackSuitColor, hdr);
|
|
37
48
|
ctx.save();
|
|
38
49
|
drawCardBody(ctx, radius);
|
|
39
50
|
ctx.fillStyle = getStyleFromRgb({ r: 255, g: 255, b: 255 }, hdr);
|
|
@@ -44,8 +55,7 @@ function drawRoundedCardFront(ctx, radius, cardData, hdr) {
|
|
|
44
55
|
ctx.font = `bold ${cornerFontSize.toString()}px Arial, serif`;
|
|
45
56
|
ctx.textAlign = "left";
|
|
46
57
|
ctx.textBaseline = "middle";
|
|
47
|
-
const topLeftX = -halfWidth + cornerPadding + suitEdgeBuffer;
|
|
48
|
-
const topLeftY = -halfHeight + cornerPadding + cornerFontSize * half;
|
|
58
|
+
const topLeftX = -halfWidth + cornerPadding + suitEdgeBuffer, topLeftY = -halfHeight + cornerPadding + cornerFontSize * half;
|
|
49
59
|
ctx.save();
|
|
50
60
|
ctx.translate(topLeftX, topLeftY);
|
|
51
61
|
ctx.beginPath();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/shape-cards",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "tsParticles cards shape",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
"./package.json": "./package.json"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@tsparticles/engine": "4.0.0-
|
|
104
|
-
"@tsparticles/path-utils": "4.0.0-
|
|
103
|
+
"@tsparticles/engine": "4.0.0-beta.1",
|
|
104
|
+
"@tsparticles/path-utils": "4.0.0-beta.1"
|
|
105
105
|
},
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|