@xignature/docx-editor 1.0.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.
@@ -0,0 +1,61 @@
1
+ // src/core/utils/units.ts
2
+ var STANDARD_DPI = 96;
3
+ var TWIPS_PER_INCH = 1440;
4
+ var EMUS_PER_INCH = 914400;
5
+ var POINTS_PER_INCH = 72;
6
+ var HALF_POINTS_PER_INCH = 144;
7
+ var EIGHTHS_PER_INCH = 576;
8
+ var PIXELS_PER_INCH = STANDARD_DPI;
9
+ function twipsToPixels(twips) {
10
+ return twips / TWIPS_PER_INCH * PIXELS_PER_INCH;
11
+ }
12
+ function pixelsToTwips(px) {
13
+ return px / PIXELS_PER_INCH * TWIPS_PER_INCH;
14
+ }
15
+ function emuToPixels(emu) {
16
+ if (emu == null || isNaN(emu)) return 0;
17
+ return Math.round(emu * PIXELS_PER_INCH / EMUS_PER_INCH);
18
+ }
19
+ function pixelsToEmu(px) {
20
+ return px / PIXELS_PER_INCH * EMUS_PER_INCH;
21
+ }
22
+ function emuToTwips(emu) {
23
+ return emu / EMUS_PER_INCH * TWIPS_PER_INCH;
24
+ }
25
+ function twipsToEmu(twips) {
26
+ return twips / TWIPS_PER_INCH * EMUS_PER_INCH;
27
+ }
28
+ function pointsToPixels(points) {
29
+ return points / POINTS_PER_INCH * PIXELS_PER_INCH;
30
+ }
31
+ function halfPointsToPixels(halfPoints) {
32
+ return halfPoints / HALF_POINTS_PER_INCH * PIXELS_PER_INCH;
33
+ }
34
+ function halfPointsToPoints(halfPoints) {
35
+ return halfPoints / 2;
36
+ }
37
+ function eighthsToPixels(eighths) {
38
+ return eighths / EIGHTHS_PER_INCH * PIXELS_PER_INCH;
39
+ }
40
+ function roundPixels(px, decimalPlaces = 2) {
41
+ const factor = Math.pow(10, decimalPlaces);
42
+ return Math.round(px * factor) / factor;
43
+ }
44
+ function formatPx(px) {
45
+ return `${roundPixels(px)}px`;
46
+ }
47
+
48
+ export {
49
+ TWIPS_PER_INCH,
50
+ twipsToPixels,
51
+ pixelsToTwips,
52
+ emuToPixels,
53
+ pixelsToEmu,
54
+ emuToTwips,
55
+ twipsToEmu,
56
+ pointsToPixels,
57
+ halfPointsToPixels,
58
+ halfPointsToPoints,
59
+ eighthsToPixels,
60
+ formatPx
61
+ };