pixi-solid 0.0.10 → 0.0.13
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/dist/index.js +35 -9
- package/dist/index.js.map +1 -0
- package/dist/pixi-application.js +42 -68
- package/dist/pixi-application.js.map +1 -1
- package/dist/pixi-canvas.js +34 -63
- package/dist/pixi-canvas.js.map +1 -1
- package/dist/pixi-components.js +48 -117
- package/dist/pixi-components.js.map +1 -1
- package/dist/pixi-events.js +73 -72
- package/dist/pixi-events.js.map +1 -1
- package/dist/pixi-stage.js +10 -27
- package/dist/pixi-stage.js.map +1 -1
- package/dist/renderer.js +82 -58
- package/dist/renderer.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pixi-application.d.ts +1 -1
- package/dist/types/pixi-components.d.ts +4 -1
- package/dist/types/pixi-events.d.ts +2 -2
- package/dist/types/use-ticker.d.ts +0 -3
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/object-fit.d.ts +12 -0
- package/dist/use-resize.js +13 -26
- package/dist/use-resize.js.map +1 -1
- package/dist/use-ticker.js +14 -43
- package/dist/use-ticker.js.map +1 -1
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/object-fit.js +37 -0
- package/dist/utils/object-fit.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const g = (i, t, r) => {
|
|
2
|
+
const s = i.width / i.scale.x, n = i.height / i.scale.y;
|
|
3
|
+
if (s === 0 || n === 0 || t.width === 0 || t.height === 0)
|
|
4
|
+
return;
|
|
5
|
+
const c = t.width / s, l = t.height / n;
|
|
6
|
+
let e = 1, h = 1;
|
|
7
|
+
switch (r) {
|
|
8
|
+
case "cover": {
|
|
9
|
+
const a = Math.max(c, l);
|
|
10
|
+
e = a, h = a;
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case "contain": {
|
|
14
|
+
const a = Math.min(c, l);
|
|
15
|
+
e = a, h = a;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case "fill": {
|
|
19
|
+
e = c, h = l;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case "scale-down": {
|
|
23
|
+
if (s <= t.width && n <= t.height)
|
|
24
|
+
e = 1, h = 1;
|
|
25
|
+
else {
|
|
26
|
+
const a = Math.min(c, l);
|
|
27
|
+
e = a, h = a;
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
i.scale.set(e, h), i.x = (t.width - i.width) / 2, i.y = (t.height - i.height) / 2;
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
g as objectFit
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=object-fit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-fit.js","sources":["../../src/utils/object-fit.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\n\nexport type ObjectFitMode = \"cover\" | \"contain\" | \"fill\" | \"scale-down\";\n\n/**\n * Scale an object to fit within the given bounds according to the specified fit mode.\n * @param object The object to be scaled.\n * @param bounds The bounds it should fit within.\n * @param fitMode The object fit mode to apply.\n */\nexport const objectFit = (\n object: Pixi.Container,\n bounds: { width: number; height: number },\n fitMode: ObjectFitMode,\n): void => {\n const originalWidth = object.width / object.scale.x;\n const originalHeight = object.height / object.scale.y;\n\n if (originalWidth === 0 || originalHeight === 0 || bounds.width === 0 || bounds.height === 0)\n return;\n\n const widthRatio = bounds.width / originalWidth;\n const heightRatio = bounds.height / originalHeight;\n\n let scaleX = 1;\n let scaleY = 1;\n\n switch (fitMode) {\n case \"cover\": {\n const coverScale = Math.max(widthRatio, heightRatio);\n scaleX = coverScale;\n scaleY = coverScale;\n break;\n }\n case \"contain\": {\n const containScale = Math.min(widthRatio, heightRatio);\n scaleX = containScale;\n scaleY = containScale;\n break;\n }\n case \"fill\": {\n scaleX = widthRatio;\n scaleY = heightRatio;\n break;\n }\n case \"scale-down\": {\n // If the object is smaller than the container, it's 'none' (no scaling up).\n // Otherwise, it's 'contain'.\n if (originalWidth <= bounds.width && originalHeight <= bounds.height) {\n scaleX = 1;\n scaleY = 1;\n } else {\n const scaleDown = Math.min(widthRatio, heightRatio);\n scaleX = scaleDown;\n scaleY = scaleDown;\n }\n break;\n }\n default:\n // Default to no scaling if an unknown fitMode is provided\n break;\n }\n\n object.scale.set(scaleX, scaleY);\n\n // Center the object\n object.x = (bounds.width - object.width) / 2;\n object.y = (bounds.height - object.height) / 2;\n};\n"],"names":["objectFit","object","bounds","fitMode","originalWidth","originalHeight","widthRatio","heightRatio","scaleX","scaleY","coverScale","containScale","scaleDown"],"mappings":"AAUO,MAAMA,IAAY,CACvBC,GACAC,GACAC,MACS;AACT,QAAMC,IAAgBH,EAAO,QAAQA,EAAO,MAAM,GAC5CI,IAAiBJ,EAAO,SAASA,EAAO,MAAM;AAEpD,MAAIG,MAAkB,KAAKC,MAAmB,KAAKH,EAAO,UAAU,KAAKA,EAAO,WAAW;AACzF;AAEF,QAAMI,IAAaJ,EAAO,QAAQE,GAC5BG,IAAcL,EAAO,SAASG;AAEpC,MAAIG,IAAS,GACTC,IAAS;AAEb,UAAQN,GAAA;AAAA,IACN,KAAK,SAAS;AACZ,YAAMO,IAAa,KAAK,IAAIJ,GAAYC,CAAW;AACnD,MAAAC,IAASE,GACTD,IAASC;AACT;AAAA,IACF;AAAA,IACA,KAAK,WAAW;AACd,YAAMC,IAAe,KAAK,IAAIL,GAAYC,CAAW;AACrD,MAAAC,IAASG,GACTF,IAASE;AACT;AAAA,IACF;AAAA,IACA,KAAK,QAAQ;AACX,MAAAH,IAASF,GACTG,IAASF;AACT;AAAA,IACF;AAAA,IACA,KAAK,cAAc;AAGjB,UAAIH,KAAiBF,EAAO,SAASG,KAAkBH,EAAO;AAC5D,QAAAM,IAAS,GACTC,IAAS;AAAA,WACJ;AACL,cAAMG,IAAY,KAAK,IAAIN,GAAYC,CAAW;AAClD,QAAAC,IAASI,GACTH,IAASG;AAAA,MACX;AACA;AAAA,IACF;AAAA,EAGE;AAGJ,EAAAX,EAAO,MAAM,IAAIO,GAAQC,CAAM,GAG/BR,EAAO,KAAKC,EAAO,QAAQD,EAAO,SAAS,GAC3CA,EAAO,KAAKC,EAAO,SAASD,EAAO,UAAU;AAC/C;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixi-solid",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.13",
|
|
5
5
|
"description": "A library to write PixiJS applications with SolidJS",
|
|
6
6
|
"author": "Luke Thompson",
|
|
7
7
|
"license": "MIT",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
".": {
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"types": "./dist/types/index.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./utils": {
|
|
20
|
+
"import": "./dist/utils/index.js",
|
|
21
|
+
"types": "./dist/types/utils/index.d.ts"
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
24
|
"files": [
|