@adaptive-ds/solid-ui 0.11.0 → 0.12.2
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/LICENSE +1 -1
- package/README.md +219 -0
- package/dist/demo_pages/LinkBlock.js +1 -1
- package/dist/demo_pages/generateDemoRoutes.js +3 -3
- package/dist/generate_demo_list/generateDemoList.js +1 -1
- package/dist/generate_demo_list/parts/formatGeneratedCodeFile.d.ts +1 -1
- package/dist/generate_demo_list/parts/formatGeneratedCodeFile.js +1 -1
- package/dist/input/check/CheckBoolean.js +1 -1
- package/dist/input/check/CheckBooleanSingle.js +1 -1
- package/dist/input/check/CheckMultiple.js +1 -1
- package/dist/input/check/CheckSingle.js +1 -1
- package/dist/input/check/Checkbox.js +1 -1
- package/dist/input/fieldset/Fieldset.js +1 -1
- package/dist/input/input/Input.js +1 -1
- package/dist/input/input/InputDatalist.js +2 -2
- package/dist/input/label/Label.js +1 -1
- package/dist/input/label/LabelAsterix.js +1 -1
- package/dist/input/label/LabelPseudo.js +1 -1
- package/dist/input/label/LabelWithInfo.js +1 -1
- package/dist/input/label/LabelWithSubtitle.js +1 -1
- package/dist/input/number/NumberInputS.js +2 -2
- package/dist/input/select/SelectMultiple.js +1 -1
- package/dist/input/select/SelectSingleNative.js +1 -1
- package/dist/input/switch/SwitchSingle.js +1 -1
- package/dist/input/textarea/Textarea.js +1 -1
- package/dist/interactive/button/Button.js +1 -1
- package/dist/interactive/button/ButtonIcon1.js +1 -1
- package/dist/interactive/button/ButtonIconOnly.js +1 -1
- package/dist/interactive/details/Details.js +1 -1
- package/dist/interactive/dialog/CorvuDialog.js +1 -1
- package/dist/interactive/dialog/CorvuDialogIcon.js +1 -1
- package/dist/interactive/layout/SidebarLayout.js +1 -1
- package/dist/interactive/link/LinkButton.js +1 -1
- package/dist/interactive/link/LinkButtonIconOnly.js +1 -1
- package/dist/interactive/link/LinkText.js +1 -1
- package/dist/interactive/list/BulletLinks.js +1 -1
- package/dist/interactive/tabs/TabsTop.js +1 -1
- package/dist/interactive/theme/themeSignal.js +1 -1
- package/dist/interactive/toast/Toast.js +1 -1
- package/dist/interactive/toast/Toaster.js +1 -1
- package/dist/interactive/toggle/ToggleButtonIconOnly.js +1 -1
- package/dist/node_modules/@adaptive-ds/utils/dist/bun/runCmdAsync.js +45 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/bun/runCmdAsync.js.map +1 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/int/safeParseInt.js +10 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/int/safeParseInt.js.map +1 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/json/jsonStringifyPretty.js +7 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/json/jsonStringifyPretty.js.map +1 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/obj/objectEntries.js +5 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/obj/objectEntries.js.map +1 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/obj/objectKeys.js +5 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/obj/objectKeys.js.map +1 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/ran/generateId12.js +9 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/ran/generateId12.js.map +1 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/ran/generateReadableId.js +29 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/ran/generateReadableId.js.map +1 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/ran/urlAlphabet32.js +5 -0
- package/dist/node_modules/@adaptive-ds/utils/dist/ran/urlAlphabet32.js.map +1 -0
- package/dist/node_modules/@corvu/dialog/dist/index.js +537 -0
- package/dist/node_modules/@corvu/dialog/dist/index.js.map +1 -0
- package/dist/node_modules/@corvu/popover/dist/index.js +267 -0
- package/dist/node_modules/@corvu/popover/dist/index.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/74BWZKBI.js +7 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/74BWZKBI.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/NVYXOAAC.js +22 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/NVYXOAAC.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/U42ECMND.js +16 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/U42ECMND.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/UKBPAEF5.js +23 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/UKBPAEF5.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/WR7IK7QK.js +41 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/chunk/WR7IK7QK.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/components/FloatingArrow.js +72 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/components/FloatingArrow.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/create/floating.js +132 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/create/floating.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/create/keyedContext.js +20 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/create/keyedContext.js.map +1 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/create/once.js +18 -0
- package/dist/node_modules/@corvu/popover/node_modules/@corvu/utils/dist/create/once.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/74BWZKBI.js +18 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/74BWZKBI.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/GZJAOTUE.js +45 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/GZJAOTUE.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/U42ECMND.js +20 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/U42ECMND.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/UKBPAEF5.js +52 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/UKBPAEF5.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/XJFCWSNS.js +11 -0
- package/dist/node_modules/@corvu/utils/dist/chunk/XJFCWSNS.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/create/controllableSignal.js +29 -0
- package/dist/node_modules/@corvu/utils/dist/create/controllableSignal.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/create/keyedContext.js +20 -0
- package/dist/node_modules/@corvu/utils/dist/create/keyedContext.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/create/once.js +18 -0
- package/dist/node_modules/@corvu/utils/dist/create/once.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/create/register.js +22 -0
- package/dist/node_modules/@corvu/utils/dist/create/register.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/create/style.js +51 -0
- package/dist/node_modules/@corvu/utils/dist/create/style.js.map +1 -0
- package/dist/node_modules/@corvu/utils/dist/scroll/index.js +39 -0
- package/dist/node_modules/@corvu/utils/dist/scroll/index.js.map +1 -0
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +878 -0
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js.map +1 -0
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +628 -0
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js.map +1 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +174 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js.map +1 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +159 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js.map +1 -0
- package/dist/node_modules/image-size/dist/index.js +942 -0
- package/dist/node_modules/image-size/dist/index.js.map +1 -0
- package/dist/node_modules/solid-dismissible/dist/index.js +253 -0
- package/dist/node_modules/solid-dismissible/dist/index.js.map +1 -0
- package/dist/node_modules/solid-focus-trap/dist/index.js +164 -0
- package/dist/node_modules/solid-focus-trap/dist/index.js.map +1 -0
- package/dist/node_modules/solid-presence/dist/index.js +73 -0
- package/dist/node_modules/solid-presence/dist/index.js.map +1 -0
- package/dist/node_modules/solid-prevent-scroll/dist/index.js +160 -0
- package/dist/node_modules/solid-prevent-scroll/dist/index.js.map +1 -0
- package/dist/static/badge/Badge.js +1 -1
- package/dist/static/container/CardWrapper.js +1 -1
- package/dist/static/dev/TailwindIndicator.js +1 -1
- package/dist/static/grid/FeatureGridSection.js +1 -1
- package/dist/static/icon/Icon.js +1 -1
- package/dist/static/icon/IconGoogle.js +1 -1
- package/dist/static/icons/iconApple.d.ts +2 -0
- package/dist/static/icons/iconApple.d.ts.map +1 -0
- package/dist/static/icons/iconApple.js +5 -0
- package/dist/static/icons/iconApple.js.map +1 -0
- package/dist/static/icons/iconGooglePlay.d.ts +2 -0
- package/dist/static/icons/iconGooglePlay.d.ts.map +1 -0
- package/dist/static/icons/iconGooglePlay.js +5 -0
- package/dist/static/icons/iconGooglePlay.js.map +1 -0
- package/dist/static/img/Img.js +1 -1
- package/dist/static/lists/BlackBulletPoint.js +1 -1
- package/dist/static/lists/BlueBulletPoint.js +1 -1
- package/dist/static/loaders/LoaderShuffle4Dots.js +1 -1
- package/dist/static/loaders/LoaderShuffle9Squares.js +1 -1
- package/dist/static/loaders/LoaderSpin4Square.js +1 -1
- package/dist/static/loaders/LoadingPage.js +1 -1
- package/dist/static/logo/LogoImageText.js +1 -1
- package/dist/static/page/PageWrapper.js +1 -1
- package/dist/static/pages/ErrorPage.js +1 -1
- package/dist/static/pages/SuccessPage.js +1 -1
- package/dist/static/separator/SeparatorOr.js +1 -1
- package/dist/static/separator/SeparatorWithText.js +1 -1
- package/dist/static/timeline/Timeline.js +1 -1
- package/dist/table/Table.js +1 -1
- package/dist/table/table1/Table1D.js +1 -1
- package/dist/table/table1/Table1M.js +1 -1
- package/dist/table/table1/Table1MEntry.js +1 -1
- package/dist/table/table2/Table2D.js +1 -1
- package/dist/table/table2/Table2M.js +1 -1
- package/dist/table/table2/Table2MEntry.js +1 -1
- package/package.json +16 -18
|
@@ -0,0 +1,942 @@
|
|
|
1
|
+
var decoder = new TextDecoder();
|
|
2
|
+
var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
|
|
3
|
+
var toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + `0${i.toString(16)}`.slice(-2), "");
|
|
4
|
+
var getView = (input, offset) => new DataView(input.buffer, input.byteOffset + offset);
|
|
5
|
+
var readInt16LE = (input, offset = 0) => getView(input, offset).getInt16(0, true);
|
|
6
|
+
var readUInt16BE = (input, offset = 0) => getView(input, offset).getUint16(0, false);
|
|
7
|
+
var readUInt16LE = (input, offset = 0) => getView(input, offset).getUint16(0, true);
|
|
8
|
+
var readUInt24LE = (input, offset = 0) => {
|
|
9
|
+
const view = getView(input, offset);
|
|
10
|
+
return view.getUint16(0, true) + (view.getUint8(2) << 16);
|
|
11
|
+
};
|
|
12
|
+
var readInt32LE = (input, offset = 0) => getView(input, offset).getInt32(0, true);
|
|
13
|
+
var readUInt32BE = (input, offset = 0) => getView(input, offset).getUint32(0, false);
|
|
14
|
+
var readUInt32LE = (input, offset = 0) => getView(input, offset).getUint32(0, true);
|
|
15
|
+
var readUInt64 = (input, offset, isBigEndian) => getView(input, offset).getBigUint64(0, !isBigEndian);
|
|
16
|
+
var methods = {
|
|
17
|
+
readUInt16BE,
|
|
18
|
+
readUInt16LE,
|
|
19
|
+
readUInt32BE,
|
|
20
|
+
readUInt32LE
|
|
21
|
+
};
|
|
22
|
+
function readUInt(input, bits, offset = 0, isBigEndian = false) {
|
|
23
|
+
const endian = isBigEndian ? "BE" : "LE";
|
|
24
|
+
const methodName = `readUInt${bits}${endian}`;
|
|
25
|
+
return methods[methodName](input, offset);
|
|
26
|
+
}
|
|
27
|
+
function readBox(input, offset) {
|
|
28
|
+
if (input.length - offset < 4) return;
|
|
29
|
+
const boxSize = readUInt32BE(input, offset);
|
|
30
|
+
if (input.length - offset < boxSize) return;
|
|
31
|
+
return {
|
|
32
|
+
name: toUTF8String(input, 4 + offset, 8 + offset),
|
|
33
|
+
offset,
|
|
34
|
+
size: boxSize
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function findBox(input, boxName, currentOffset) {
|
|
38
|
+
while (currentOffset < input.length) {
|
|
39
|
+
const box = readBox(input, currentOffset);
|
|
40
|
+
if (!box) break;
|
|
41
|
+
if (box.name === boxName) return box;
|
|
42
|
+
currentOffset += box.size > 0 ? box.size : 8;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var BMP = {
|
|
46
|
+
validate: (input) => toUTF8String(input, 0, 2) === "BM",
|
|
47
|
+
calculate: (input) => ({
|
|
48
|
+
height: Math.abs(readInt32LE(input, 22)),
|
|
49
|
+
width: readUInt32LE(input, 18)
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
var TYPE_ICON = 1;
|
|
53
|
+
var SIZE_HEADER = 2 + 2 + 2;
|
|
54
|
+
var SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4;
|
|
55
|
+
function getSizeFromOffset(input, offset) {
|
|
56
|
+
const value = input[offset];
|
|
57
|
+
return value === 0 ? 256 : value;
|
|
58
|
+
}
|
|
59
|
+
function getImageSize(input, imageIndex) {
|
|
60
|
+
const offset = SIZE_HEADER + imageIndex * SIZE_IMAGE_ENTRY;
|
|
61
|
+
return {
|
|
62
|
+
height: getSizeFromOffset(input, offset + 1),
|
|
63
|
+
width: getSizeFromOffset(input, offset)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var ICO = {
|
|
67
|
+
validate(input) {
|
|
68
|
+
const reserved = readUInt16LE(input, 0);
|
|
69
|
+
const imageCount = readUInt16LE(input, 4);
|
|
70
|
+
if (reserved !== 0 || imageCount === 0) return false;
|
|
71
|
+
const imageType = readUInt16LE(input, 2);
|
|
72
|
+
return imageType === TYPE_ICON;
|
|
73
|
+
},
|
|
74
|
+
calculate(input) {
|
|
75
|
+
const nbImages = readUInt16LE(input, 4);
|
|
76
|
+
const imageSize2 = getImageSize(input, 0);
|
|
77
|
+
if (nbImages === 1) return imageSize2;
|
|
78
|
+
const images = [];
|
|
79
|
+
for (let imageIndex = 0; imageIndex < nbImages; imageIndex += 1) {
|
|
80
|
+
images.push(getImageSize(input, imageIndex));
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
width: imageSize2.width,
|
|
84
|
+
height: imageSize2.height,
|
|
85
|
+
images
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var TYPE_CURSOR = 2;
|
|
90
|
+
var CUR = {
|
|
91
|
+
validate(input) {
|
|
92
|
+
const reserved = readUInt16LE(input, 0);
|
|
93
|
+
const imageCount = readUInt16LE(input, 4);
|
|
94
|
+
if (reserved !== 0 || imageCount === 0) return false;
|
|
95
|
+
const imageType = readUInt16LE(input, 2);
|
|
96
|
+
return imageType === TYPE_CURSOR;
|
|
97
|
+
},
|
|
98
|
+
calculate: (input) => ICO.calculate(input)
|
|
99
|
+
};
|
|
100
|
+
var DDS = {
|
|
101
|
+
validate: (input) => readUInt32LE(input, 0) === 542327876,
|
|
102
|
+
calculate: (input) => ({
|
|
103
|
+
height: readUInt32LE(input, 12),
|
|
104
|
+
width: readUInt32LE(input, 16)
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
var gifRegexp = /^GIF8[79]a/;
|
|
108
|
+
var GIF = {
|
|
109
|
+
validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)),
|
|
110
|
+
calculate: (input) => ({
|
|
111
|
+
height: readUInt16LE(input, 8),
|
|
112
|
+
width: readUInt16LE(input, 6)
|
|
113
|
+
})
|
|
114
|
+
};
|
|
115
|
+
var brandMap = {
|
|
116
|
+
avif: "avif",
|
|
117
|
+
mif1: "heif",
|
|
118
|
+
msf1: "heif",
|
|
119
|
+
// heif-sequence
|
|
120
|
+
heic: "heic",
|
|
121
|
+
heix: "heic",
|
|
122
|
+
hevc: "heic",
|
|
123
|
+
// heic-sequence
|
|
124
|
+
hevx: "heic"
|
|
125
|
+
// heic-sequence
|
|
126
|
+
};
|
|
127
|
+
var HEIF = {
|
|
128
|
+
validate(input) {
|
|
129
|
+
const boxType = toUTF8String(input, 4, 8);
|
|
130
|
+
if (boxType !== "ftyp") return false;
|
|
131
|
+
const ftypBox = findBox(input, "ftyp", 0);
|
|
132
|
+
if (!ftypBox) return false;
|
|
133
|
+
const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12);
|
|
134
|
+
return brand in brandMap;
|
|
135
|
+
},
|
|
136
|
+
calculate(input) {
|
|
137
|
+
const metaBox = findBox(input, "meta", 0);
|
|
138
|
+
const iprpBox = metaBox && findBox(input, "iprp", metaBox.offset + 12);
|
|
139
|
+
const ipcoBox = iprpBox && findBox(input, "ipco", iprpBox.offset + 8);
|
|
140
|
+
if (!ipcoBox) {
|
|
141
|
+
throw new TypeError("Invalid HEIF, no ipco box found");
|
|
142
|
+
}
|
|
143
|
+
const type = toUTF8String(input, 8, 12);
|
|
144
|
+
const images = [];
|
|
145
|
+
let currentOffset = ipcoBox.offset + 8;
|
|
146
|
+
while (currentOffset < ipcoBox.offset + ipcoBox.size) {
|
|
147
|
+
const ispeBox = findBox(input, "ispe", currentOffset);
|
|
148
|
+
if (!ispeBox) break;
|
|
149
|
+
const rawWidth = readUInt32BE(input, ispeBox.offset + 12);
|
|
150
|
+
const rawHeight = readUInt32BE(input, ispeBox.offset + 16);
|
|
151
|
+
const clapBox = findBox(input, "clap", currentOffset);
|
|
152
|
+
let width = rawWidth;
|
|
153
|
+
let height = rawHeight;
|
|
154
|
+
if (clapBox && clapBox.offset < ipcoBox.offset + ipcoBox.size) {
|
|
155
|
+
const cropRight = readUInt32BE(input, clapBox.offset + 12);
|
|
156
|
+
width = rawWidth - cropRight;
|
|
157
|
+
}
|
|
158
|
+
images.push({ height, width });
|
|
159
|
+
currentOffset = ispeBox.offset + ispeBox.size;
|
|
160
|
+
}
|
|
161
|
+
if (images.length === 0) {
|
|
162
|
+
throw new TypeError("Invalid HEIF, no sizes found");
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
width: images[0].width,
|
|
166
|
+
height: images[0].height,
|
|
167
|
+
type,
|
|
168
|
+
...images.length > 1 ? { images } : {}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var SIZE_HEADER2 = 4 + 4;
|
|
173
|
+
var FILE_LENGTH_OFFSET = 4;
|
|
174
|
+
var ENTRY_LENGTH_OFFSET = 4;
|
|
175
|
+
var ICON_TYPE_SIZE = {
|
|
176
|
+
ICON: 32,
|
|
177
|
+
"ICN#": 32,
|
|
178
|
+
// m => 16 x 16
|
|
179
|
+
"icm#": 16,
|
|
180
|
+
icm4: 16,
|
|
181
|
+
icm8: 16,
|
|
182
|
+
// s => 16 x 16
|
|
183
|
+
"ics#": 16,
|
|
184
|
+
ics4: 16,
|
|
185
|
+
ics8: 16,
|
|
186
|
+
is32: 16,
|
|
187
|
+
s8mk: 16,
|
|
188
|
+
icp4: 16,
|
|
189
|
+
// l => 32 x 32
|
|
190
|
+
icl4: 32,
|
|
191
|
+
icl8: 32,
|
|
192
|
+
il32: 32,
|
|
193
|
+
l8mk: 32,
|
|
194
|
+
icp5: 32,
|
|
195
|
+
ic11: 32,
|
|
196
|
+
// h => 48 x 48
|
|
197
|
+
ich4: 48,
|
|
198
|
+
ich8: 48,
|
|
199
|
+
ih32: 48,
|
|
200
|
+
h8mk: 48,
|
|
201
|
+
// . => 64 x 64
|
|
202
|
+
icp6: 64,
|
|
203
|
+
ic12: 32,
|
|
204
|
+
// t => 128 x 128
|
|
205
|
+
it32: 128,
|
|
206
|
+
t8mk: 128,
|
|
207
|
+
ic07: 128,
|
|
208
|
+
// . => 256 x 256
|
|
209
|
+
ic08: 256,
|
|
210
|
+
ic13: 256,
|
|
211
|
+
// . => 512 x 512
|
|
212
|
+
ic09: 512,
|
|
213
|
+
ic14: 512,
|
|
214
|
+
// . => 1024 x 1024
|
|
215
|
+
ic10: 1024
|
|
216
|
+
};
|
|
217
|
+
function readImageHeader(input, imageOffset) {
|
|
218
|
+
const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET;
|
|
219
|
+
return [
|
|
220
|
+
toUTF8String(input, imageOffset, imageLengthOffset),
|
|
221
|
+
readUInt32BE(input, imageLengthOffset)
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
function getImageSize2(type) {
|
|
225
|
+
const size = ICON_TYPE_SIZE[type];
|
|
226
|
+
return { width: size, height: size, type };
|
|
227
|
+
}
|
|
228
|
+
var ICNS = {
|
|
229
|
+
validate: (input) => toUTF8String(input, 0, 4) === "icns",
|
|
230
|
+
calculate(input) {
|
|
231
|
+
const inputLength = input.length;
|
|
232
|
+
const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET);
|
|
233
|
+
let imageOffset = SIZE_HEADER2;
|
|
234
|
+
const images = [];
|
|
235
|
+
while (imageOffset < fileLength && imageOffset < inputLength) {
|
|
236
|
+
const imageHeader = readImageHeader(input, imageOffset);
|
|
237
|
+
const imageSize2 = getImageSize2(imageHeader[0]);
|
|
238
|
+
images.push(imageSize2);
|
|
239
|
+
imageOffset += imageHeader[1];
|
|
240
|
+
}
|
|
241
|
+
if (images.length === 0) {
|
|
242
|
+
throw new TypeError("Invalid ICNS, no sizes found");
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
width: images[0].width,
|
|
246
|
+
height: images[0].height,
|
|
247
|
+
...images.length > 1 ? { images } : {}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var J2C = {
|
|
252
|
+
// TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
|
|
253
|
+
validate: (input) => readUInt32BE(input, 0) === 4283432785,
|
|
254
|
+
calculate: (input) => ({
|
|
255
|
+
height: readUInt32BE(input, 12),
|
|
256
|
+
width: readUInt32BE(input, 8)
|
|
257
|
+
})
|
|
258
|
+
};
|
|
259
|
+
var JP2 = {
|
|
260
|
+
validate(input) {
|
|
261
|
+
const boxType = toUTF8String(input, 4, 8);
|
|
262
|
+
if (boxType !== "jP ") return false;
|
|
263
|
+
const ftypBox = findBox(input, "ftyp", 0);
|
|
264
|
+
if (!ftypBox) return false;
|
|
265
|
+
const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12);
|
|
266
|
+
return brand === "jp2 ";
|
|
267
|
+
},
|
|
268
|
+
calculate(input) {
|
|
269
|
+
const jp2hBox = findBox(input, "jp2h", 0);
|
|
270
|
+
const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8);
|
|
271
|
+
if (ihdrBox) {
|
|
272
|
+
return {
|
|
273
|
+
height: readUInt32BE(input, ihdrBox.offset + 8),
|
|
274
|
+
width: readUInt32BE(input, ihdrBox.offset + 12)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
throw new TypeError("Unsupported JPEG 2000 format");
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
var EXIF_MARKER = "45786966";
|
|
281
|
+
var APP1_DATA_SIZE_BYTES = 2;
|
|
282
|
+
var EXIF_HEADER_BYTES = 6;
|
|
283
|
+
var TIFF_BYTE_ALIGN_BYTES = 2;
|
|
284
|
+
var BIG_ENDIAN_BYTE_ALIGN = "4d4d";
|
|
285
|
+
var LITTLE_ENDIAN_BYTE_ALIGN = "4949";
|
|
286
|
+
var IDF_ENTRY_BYTES = 12;
|
|
287
|
+
var NUM_DIRECTORY_ENTRIES_BYTES = 2;
|
|
288
|
+
function isEXIF(input) {
|
|
289
|
+
return toHexString(input, 2, 6) === EXIF_MARKER;
|
|
290
|
+
}
|
|
291
|
+
function extractSize(input, index) {
|
|
292
|
+
return {
|
|
293
|
+
height: readUInt16BE(input, index),
|
|
294
|
+
width: readUInt16BE(input, index + 2)
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function extractOrientation(exifBlock, isBigEndian) {
|
|
298
|
+
const idfOffset = 8;
|
|
299
|
+
const offset = EXIF_HEADER_BYTES + idfOffset;
|
|
300
|
+
const idfDirectoryEntries = readUInt(exifBlock, 16, offset, isBigEndian);
|
|
301
|
+
for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) {
|
|
302
|
+
const start = offset + NUM_DIRECTORY_ENTRIES_BYTES + directoryEntryNumber * IDF_ENTRY_BYTES;
|
|
303
|
+
const end = start + IDF_ENTRY_BYTES;
|
|
304
|
+
if (start > exifBlock.length) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const block = exifBlock.slice(start, end);
|
|
308
|
+
const tagNumber = readUInt(block, 16, 0, isBigEndian);
|
|
309
|
+
if (tagNumber === 274) {
|
|
310
|
+
const dataFormat = readUInt(block, 16, 2, isBigEndian);
|
|
311
|
+
if (dataFormat !== 3) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const numberOfComponents = readUInt(block, 32, 4, isBigEndian);
|
|
315
|
+
if (numberOfComponents !== 1) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
return readUInt(block, 16, 8, isBigEndian);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function validateExifBlock(input, index) {
|
|
323
|
+
const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index);
|
|
324
|
+
const byteAlign = toHexString(
|
|
325
|
+
exifBlock,
|
|
326
|
+
EXIF_HEADER_BYTES,
|
|
327
|
+
EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES
|
|
328
|
+
);
|
|
329
|
+
const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN;
|
|
330
|
+
const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN;
|
|
331
|
+
if (isBigEndian || isLittleEndian) {
|
|
332
|
+
return extractOrientation(exifBlock, isBigEndian);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function validateInput(input, index) {
|
|
336
|
+
if (index > input.length) {
|
|
337
|
+
throw new TypeError("Corrupt JPG, exceeded buffer limits");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
var JPG = {
|
|
341
|
+
validate: (input) => toHexString(input, 0, 2) === "ffd8",
|
|
342
|
+
calculate(_input) {
|
|
343
|
+
let input = _input.slice(4);
|
|
344
|
+
let orientation;
|
|
345
|
+
let next;
|
|
346
|
+
while (input.length) {
|
|
347
|
+
const i = readUInt16BE(input, 0);
|
|
348
|
+
validateInput(input, i);
|
|
349
|
+
if (input[i] !== 255) {
|
|
350
|
+
input = input.slice(1);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (isEXIF(input)) {
|
|
354
|
+
orientation = validateExifBlock(input, i);
|
|
355
|
+
}
|
|
356
|
+
next = input[i + 1];
|
|
357
|
+
if (next === 192 || next === 193 || next === 194) {
|
|
358
|
+
const size = extractSize(input, i + 5);
|
|
359
|
+
if (!orientation) {
|
|
360
|
+
return size;
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
height: size.height,
|
|
364
|
+
orientation,
|
|
365
|
+
width: size.width
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
input = input.slice(i + 2);
|
|
369
|
+
}
|
|
370
|
+
throw new TypeError("Invalid JPG, no size found");
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
var BitReader = class {
|
|
374
|
+
constructor(input, endianness) {
|
|
375
|
+
this.input = input;
|
|
376
|
+
this.endianness = endianness;
|
|
377
|
+
this.byteOffset = 2;
|
|
378
|
+
this.bitOffset = 0;
|
|
379
|
+
}
|
|
380
|
+
/** Reads a specified number of bits, and move the offset */
|
|
381
|
+
getBits(length = 1) {
|
|
382
|
+
let result = 0;
|
|
383
|
+
let bitsRead = 0;
|
|
384
|
+
while (bitsRead < length) {
|
|
385
|
+
if (this.byteOffset >= this.input.length) {
|
|
386
|
+
throw new Error("Reached end of input");
|
|
387
|
+
}
|
|
388
|
+
const currentByte = this.input[this.byteOffset];
|
|
389
|
+
const bitsLeft = 8 - this.bitOffset;
|
|
390
|
+
const bitsToRead = Math.min(length - bitsRead, bitsLeft);
|
|
391
|
+
if (this.endianness === "little-endian") {
|
|
392
|
+
const mask = (1 << bitsToRead) - 1;
|
|
393
|
+
const bits = currentByte >> this.bitOffset & mask;
|
|
394
|
+
result |= bits << bitsRead;
|
|
395
|
+
} else {
|
|
396
|
+
const mask = (1 << bitsToRead) - 1 << 8 - this.bitOffset - bitsToRead;
|
|
397
|
+
const bits = (currentByte & mask) >> 8 - this.bitOffset - bitsToRead;
|
|
398
|
+
result = result << bitsToRead | bits;
|
|
399
|
+
}
|
|
400
|
+
bitsRead += bitsToRead;
|
|
401
|
+
this.bitOffset += bitsToRead;
|
|
402
|
+
if (this.bitOffset === 8) {
|
|
403
|
+
this.byteOffset++;
|
|
404
|
+
this.bitOffset = 0;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return result;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
function calculateImageDimension(reader, isSmallImage) {
|
|
411
|
+
if (isSmallImage) {
|
|
412
|
+
return 8 * (1 + reader.getBits(5));
|
|
413
|
+
}
|
|
414
|
+
const sizeClass = reader.getBits(2);
|
|
415
|
+
const extraBits = [9, 13, 18, 30][sizeClass];
|
|
416
|
+
return 1 + reader.getBits(extraBits);
|
|
417
|
+
}
|
|
418
|
+
function calculateImageWidth(reader, isSmallImage, widthMode, height) {
|
|
419
|
+
if (isSmallImage && widthMode === 0) {
|
|
420
|
+
return 8 * (1 + reader.getBits(5));
|
|
421
|
+
}
|
|
422
|
+
if (widthMode === 0) {
|
|
423
|
+
return calculateImageDimension(reader, false);
|
|
424
|
+
}
|
|
425
|
+
const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2];
|
|
426
|
+
return Math.floor(height * aspectRatios[widthMode - 1]);
|
|
427
|
+
}
|
|
428
|
+
var JXLStream = {
|
|
429
|
+
validate: (input) => {
|
|
430
|
+
return toHexString(input, 0, 2) === "ff0a";
|
|
431
|
+
},
|
|
432
|
+
calculate(input) {
|
|
433
|
+
const reader = new BitReader(input, "little-endian");
|
|
434
|
+
const isSmallImage = reader.getBits(1) === 1;
|
|
435
|
+
const height = calculateImageDimension(reader, isSmallImage);
|
|
436
|
+
const widthMode = reader.getBits(3);
|
|
437
|
+
const width = calculateImageWidth(reader, isSmallImage, widthMode, height);
|
|
438
|
+
return { width, height };
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
function extractCodestream(input) {
|
|
442
|
+
const jxlcBox = findBox(input, "jxlc", 0);
|
|
443
|
+
if (jxlcBox) {
|
|
444
|
+
return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size);
|
|
445
|
+
}
|
|
446
|
+
const partialStreams = extractPartialStreams(input);
|
|
447
|
+
if (partialStreams.length > 0) {
|
|
448
|
+
return concatenateCodestreams(partialStreams);
|
|
449
|
+
}
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
function extractPartialStreams(input) {
|
|
453
|
+
const partialStreams = [];
|
|
454
|
+
let offset = 0;
|
|
455
|
+
while (offset < input.length) {
|
|
456
|
+
const jxlpBox = findBox(input, "jxlp", offset);
|
|
457
|
+
if (!jxlpBox) break;
|
|
458
|
+
partialStreams.push(
|
|
459
|
+
input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size)
|
|
460
|
+
);
|
|
461
|
+
offset = jxlpBox.offset + jxlpBox.size;
|
|
462
|
+
}
|
|
463
|
+
return partialStreams;
|
|
464
|
+
}
|
|
465
|
+
function concatenateCodestreams(partialCodestreams) {
|
|
466
|
+
const totalLength = partialCodestreams.reduce(
|
|
467
|
+
(acc, curr) => acc + curr.length,
|
|
468
|
+
0
|
|
469
|
+
);
|
|
470
|
+
const codestream = new Uint8Array(totalLength);
|
|
471
|
+
let position = 0;
|
|
472
|
+
for (const partial of partialCodestreams) {
|
|
473
|
+
codestream.set(partial, position);
|
|
474
|
+
position += partial.length;
|
|
475
|
+
}
|
|
476
|
+
return codestream;
|
|
477
|
+
}
|
|
478
|
+
var JXL = {
|
|
479
|
+
validate: (input) => {
|
|
480
|
+
const boxType = toUTF8String(input, 4, 8);
|
|
481
|
+
if (boxType !== "JXL ") return false;
|
|
482
|
+
const ftypBox = findBox(input, "ftyp", 0);
|
|
483
|
+
if (!ftypBox) return false;
|
|
484
|
+
const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12);
|
|
485
|
+
return brand === "jxl ";
|
|
486
|
+
},
|
|
487
|
+
calculate(input) {
|
|
488
|
+
const codestream = extractCodestream(input);
|
|
489
|
+
if (codestream) return JXLStream.calculate(codestream);
|
|
490
|
+
throw new Error("No codestream found in JXL container");
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var KTX = {
|
|
494
|
+
validate: (input) => {
|
|
495
|
+
const signature = toUTF8String(input, 1, 7);
|
|
496
|
+
return ["KTX 11", "KTX 20"].includes(signature);
|
|
497
|
+
},
|
|
498
|
+
calculate: (input) => {
|
|
499
|
+
const type = input[5] === 49 ? "ktx" : "ktx2";
|
|
500
|
+
const offset = type === "ktx" ? 36 : 20;
|
|
501
|
+
return {
|
|
502
|
+
height: readUInt32LE(input, offset + 4),
|
|
503
|
+
width: readUInt32LE(input, offset),
|
|
504
|
+
type
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
var pngSignature = "PNG\r\n\n";
|
|
509
|
+
var pngImageHeaderChunkName = "IHDR";
|
|
510
|
+
var pngFriedChunkName = "CgBI";
|
|
511
|
+
var PNG = {
|
|
512
|
+
validate(input) {
|
|
513
|
+
if (pngSignature === toUTF8String(input, 1, 8)) {
|
|
514
|
+
let chunkName = toUTF8String(input, 12, 16);
|
|
515
|
+
if (chunkName === pngFriedChunkName) {
|
|
516
|
+
chunkName = toUTF8String(input, 28, 32);
|
|
517
|
+
}
|
|
518
|
+
if (chunkName !== pngImageHeaderChunkName) {
|
|
519
|
+
throw new TypeError("Invalid PNG");
|
|
520
|
+
}
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
return false;
|
|
524
|
+
},
|
|
525
|
+
calculate(input) {
|
|
526
|
+
if (toUTF8String(input, 12, 16) === pngFriedChunkName) {
|
|
527
|
+
return {
|
|
528
|
+
height: readUInt32BE(input, 36),
|
|
529
|
+
width: readUInt32BE(input, 32)
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
height: readUInt32BE(input, 20),
|
|
534
|
+
width: readUInt32BE(input, 16)
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
var PNMTypes = {
|
|
539
|
+
P1: "pbm/ascii",
|
|
540
|
+
P2: "pgm/ascii",
|
|
541
|
+
P3: "ppm/ascii",
|
|
542
|
+
P4: "pbm",
|
|
543
|
+
P5: "pgm",
|
|
544
|
+
P6: "ppm",
|
|
545
|
+
P7: "pam",
|
|
546
|
+
PF: "pfm"
|
|
547
|
+
};
|
|
548
|
+
var handlers = {
|
|
549
|
+
default: (lines) => {
|
|
550
|
+
let dimensions = [];
|
|
551
|
+
while (lines.length > 0) {
|
|
552
|
+
const line = lines.shift();
|
|
553
|
+
if (line[0] === "#") {
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
dimensions = line.split(" ");
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
if (dimensions.length === 2) {
|
|
560
|
+
return {
|
|
561
|
+
height: Number.parseInt(dimensions[1], 10),
|
|
562
|
+
width: Number.parseInt(dimensions[0], 10)
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
throw new TypeError("Invalid PNM");
|
|
566
|
+
},
|
|
567
|
+
pam: (lines) => {
|
|
568
|
+
const size = {};
|
|
569
|
+
while (lines.length > 0) {
|
|
570
|
+
const line = lines.shift();
|
|
571
|
+
if (line.length > 16 || line.charCodeAt(0) > 128) {
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
const [key, value] = line.split(" ");
|
|
575
|
+
if (key && value) {
|
|
576
|
+
size[key.toLowerCase()] = Number.parseInt(value, 10);
|
|
577
|
+
}
|
|
578
|
+
if (size.height && size.width) {
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (size.height && size.width) {
|
|
583
|
+
return {
|
|
584
|
+
height: size.height,
|
|
585
|
+
width: size.width
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
throw new TypeError("Invalid PAM");
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
var PNM = {
|
|
592
|
+
validate: (input) => toUTF8String(input, 0, 2) in PNMTypes,
|
|
593
|
+
calculate(input) {
|
|
594
|
+
const signature = toUTF8String(input, 0, 2);
|
|
595
|
+
const type = PNMTypes[signature];
|
|
596
|
+
const lines = toUTF8String(input, 3).split(/[\r\n]+/);
|
|
597
|
+
const handler = handlers[type] || handlers.default;
|
|
598
|
+
return handler(lines);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
var PSD = {
|
|
602
|
+
validate: (input) => toUTF8String(input, 0, 4) === "8BPS",
|
|
603
|
+
calculate: (input) => ({
|
|
604
|
+
height: readUInt32BE(input, 14),
|
|
605
|
+
width: readUInt32BE(input, 18)
|
|
606
|
+
})
|
|
607
|
+
};
|
|
608
|
+
var svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/;
|
|
609
|
+
var extractorRegExps = {
|
|
610
|
+
height: /\sheight=(['"])([^%]+?)\1/,
|
|
611
|
+
root: svgReg,
|
|
612
|
+
viewbox: /\sviewBox=(['"])(.+?)\1/i,
|
|
613
|
+
width: /\swidth=(['"])([^%]+?)\1/
|
|
614
|
+
};
|
|
615
|
+
var INCH_CM = 2.54;
|
|
616
|
+
var units = {
|
|
617
|
+
in: 96,
|
|
618
|
+
cm: 96 / INCH_CM,
|
|
619
|
+
em: 16,
|
|
620
|
+
ex: 8,
|
|
621
|
+
m: 96 / INCH_CM * 100,
|
|
622
|
+
mm: 96 / INCH_CM / 10,
|
|
623
|
+
pc: 96 / 72 / 12,
|
|
624
|
+
pt: 96 / 72,
|
|
625
|
+
px: 1
|
|
626
|
+
};
|
|
627
|
+
var unitsReg = new RegExp(
|
|
628
|
+
`^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$`
|
|
629
|
+
);
|
|
630
|
+
function parseLength(len) {
|
|
631
|
+
const m = unitsReg.exec(len);
|
|
632
|
+
if (!m) {
|
|
633
|
+
return void 0;
|
|
634
|
+
}
|
|
635
|
+
return Math.round(Number(m[1]) * (units[m[2]] || 1));
|
|
636
|
+
}
|
|
637
|
+
function parseViewbox(viewbox) {
|
|
638
|
+
const bounds = viewbox.split(" ");
|
|
639
|
+
return {
|
|
640
|
+
height: parseLength(bounds[3]),
|
|
641
|
+
width: parseLength(bounds[2])
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
function parseAttributes(root) {
|
|
645
|
+
const width = root.match(extractorRegExps.width);
|
|
646
|
+
const height = root.match(extractorRegExps.height);
|
|
647
|
+
const viewbox = root.match(extractorRegExps.viewbox);
|
|
648
|
+
return {
|
|
649
|
+
height: height && parseLength(height[2]),
|
|
650
|
+
viewbox: viewbox && parseViewbox(viewbox[2]),
|
|
651
|
+
width: width && parseLength(width[2])
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function calculateByDimensions(attrs) {
|
|
655
|
+
return {
|
|
656
|
+
height: attrs.height,
|
|
657
|
+
width: attrs.width
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function calculateByViewbox(attrs, viewbox) {
|
|
661
|
+
const ratio = viewbox.width / viewbox.height;
|
|
662
|
+
if (attrs.width) {
|
|
663
|
+
return {
|
|
664
|
+
height: Math.floor(attrs.width / ratio),
|
|
665
|
+
width: attrs.width
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
if (attrs.height) {
|
|
669
|
+
return {
|
|
670
|
+
height: attrs.height,
|
|
671
|
+
width: Math.floor(attrs.height * ratio)
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
return {
|
|
675
|
+
height: viewbox.height,
|
|
676
|
+
width: viewbox.width
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
var SVG = {
|
|
680
|
+
// Scan only the first kilo-byte to speed up the check on larger files
|
|
681
|
+
validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)),
|
|
682
|
+
calculate(input) {
|
|
683
|
+
const root = toUTF8String(input).match(extractorRegExps.root);
|
|
684
|
+
if (root) {
|
|
685
|
+
const attrs = parseAttributes(root[0]);
|
|
686
|
+
if (attrs.width && attrs.height) {
|
|
687
|
+
return calculateByDimensions(attrs);
|
|
688
|
+
}
|
|
689
|
+
if (attrs.viewbox) {
|
|
690
|
+
return calculateByViewbox(attrs, attrs.viewbox);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
throw new TypeError("Invalid SVG");
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
var TGA = {
|
|
697
|
+
validate(input) {
|
|
698
|
+
return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0;
|
|
699
|
+
},
|
|
700
|
+
calculate(input) {
|
|
701
|
+
return {
|
|
702
|
+
height: readUInt16LE(input, 14),
|
|
703
|
+
width: readUInt16LE(input, 12)
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
var CONSTANTS = {
|
|
708
|
+
TAG: {
|
|
709
|
+
WIDTH: 256,
|
|
710
|
+
HEIGHT: 257,
|
|
711
|
+
COMPRESSION: 259
|
|
712
|
+
},
|
|
713
|
+
TYPE: {
|
|
714
|
+
SHORT: 3,
|
|
715
|
+
LONG: 4,
|
|
716
|
+
LONG8: 16
|
|
717
|
+
},
|
|
718
|
+
ENTRY_SIZE: {
|
|
719
|
+
STANDARD: 12,
|
|
720
|
+
BIG: 20
|
|
721
|
+
},
|
|
722
|
+
COUNT_SIZE: {
|
|
723
|
+
STANDARD: 2,
|
|
724
|
+
BIG: 8
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
function readIFD(input, { isBigEndian, isBigTiff }) {
|
|
728
|
+
const ifdOffset = isBigTiff ? Number(readUInt64(input, 8, isBigEndian)) : readUInt(input, 32, 4, isBigEndian);
|
|
729
|
+
const entryCountSize = isBigTiff ? CONSTANTS.COUNT_SIZE.BIG : CONSTANTS.COUNT_SIZE.STANDARD;
|
|
730
|
+
return input.slice(ifdOffset + entryCountSize);
|
|
731
|
+
}
|
|
732
|
+
function readTagValue(input, type, offset, isBigEndian) {
|
|
733
|
+
switch (type) {
|
|
734
|
+
case CONSTANTS.TYPE.SHORT:
|
|
735
|
+
return readUInt(input, 16, offset, isBigEndian);
|
|
736
|
+
case CONSTANTS.TYPE.LONG:
|
|
737
|
+
return readUInt(input, 32, offset, isBigEndian);
|
|
738
|
+
case CONSTANTS.TYPE.LONG8: {
|
|
739
|
+
const value = Number(readUInt64(input, offset, isBigEndian));
|
|
740
|
+
if (value > Number.MAX_SAFE_INTEGER) {
|
|
741
|
+
throw new TypeError("Value too large");
|
|
742
|
+
}
|
|
743
|
+
return value;
|
|
744
|
+
}
|
|
745
|
+
default:
|
|
746
|
+
return 0;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function nextTag(input, isBigTiff) {
|
|
750
|
+
const entrySize = isBigTiff ? CONSTANTS.ENTRY_SIZE.BIG : CONSTANTS.ENTRY_SIZE.STANDARD;
|
|
751
|
+
if (input.length > entrySize) {
|
|
752
|
+
return input.slice(entrySize);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function extractTags(input, { isBigEndian, isBigTiff }) {
|
|
756
|
+
const tags = {};
|
|
757
|
+
let temp = input;
|
|
758
|
+
while (temp?.length) {
|
|
759
|
+
const code = readUInt(temp, 16, 0, isBigEndian);
|
|
760
|
+
const type = readUInt(temp, 16, 2, isBigEndian);
|
|
761
|
+
const length = isBigTiff ? Number(readUInt64(temp, 4, isBigEndian)) : readUInt(temp, 32, 4, isBigEndian);
|
|
762
|
+
if (code === 0) break;
|
|
763
|
+
if (length === 1 && (type === CONSTANTS.TYPE.SHORT || type === CONSTANTS.TYPE.LONG || isBigTiff && type === CONSTANTS.TYPE.LONG8)) {
|
|
764
|
+
const valueOffset = isBigTiff ? 12 : 8;
|
|
765
|
+
tags[code] = readTagValue(temp, type, valueOffset, isBigEndian);
|
|
766
|
+
}
|
|
767
|
+
temp = nextTag(temp, isBigTiff);
|
|
768
|
+
}
|
|
769
|
+
return tags;
|
|
770
|
+
}
|
|
771
|
+
function determineFormat(input) {
|
|
772
|
+
const signature = toUTF8String(input, 0, 2);
|
|
773
|
+
const version = readUInt(input, 16, 2, signature === "MM");
|
|
774
|
+
return {
|
|
775
|
+
isBigEndian: signature === "MM",
|
|
776
|
+
isBigTiff: version === 43
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function validateBigTIFFHeader(input, isBigEndian) {
|
|
780
|
+
const byteSize = readUInt(input, 16, 4, isBigEndian);
|
|
781
|
+
const reserved = readUInt(input, 16, 6, isBigEndian);
|
|
782
|
+
if (byteSize !== 8 || reserved !== 0) {
|
|
783
|
+
throw new TypeError("Invalid BigTIFF header");
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
var signatures = /* @__PURE__ */ new Set([
|
|
787
|
+
"49492a00",
|
|
788
|
+
// Little Endian
|
|
789
|
+
"4d4d002a",
|
|
790
|
+
// Big Endian
|
|
791
|
+
"49492b00",
|
|
792
|
+
// BigTIFF Little Endian
|
|
793
|
+
"4d4d002b"
|
|
794
|
+
// BigTIFF Big Endian
|
|
795
|
+
]);
|
|
796
|
+
var TIFF = {
|
|
797
|
+
validate: (input) => {
|
|
798
|
+
const signature = toHexString(input, 0, 4);
|
|
799
|
+
return signatures.has(signature);
|
|
800
|
+
},
|
|
801
|
+
calculate(input) {
|
|
802
|
+
const format = determineFormat(input);
|
|
803
|
+
if (format.isBigTiff) {
|
|
804
|
+
validateBigTIFFHeader(input, format.isBigEndian);
|
|
805
|
+
}
|
|
806
|
+
const ifdBuffer = readIFD(input, format);
|
|
807
|
+
const tags = extractTags(ifdBuffer, format);
|
|
808
|
+
const info = {
|
|
809
|
+
height: tags[CONSTANTS.TAG.HEIGHT],
|
|
810
|
+
width: tags[CONSTANTS.TAG.WIDTH],
|
|
811
|
+
type: format.isBigTiff ? "bigtiff" : "tiff"
|
|
812
|
+
};
|
|
813
|
+
if (tags[CONSTANTS.TAG.COMPRESSION]) {
|
|
814
|
+
info.compression = tags[CONSTANTS.TAG.COMPRESSION];
|
|
815
|
+
}
|
|
816
|
+
if (!info.width || !info.height) {
|
|
817
|
+
throw new TypeError("Invalid Tiff. Missing tags");
|
|
818
|
+
}
|
|
819
|
+
return info;
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
function calculateExtended(input) {
|
|
823
|
+
return {
|
|
824
|
+
height: 1 + readUInt24LE(input, 7),
|
|
825
|
+
width: 1 + readUInt24LE(input, 4)
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function calculateLossless(input) {
|
|
829
|
+
return {
|
|
830
|
+
height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6),
|
|
831
|
+
width: 1 + ((input[2] & 63) << 8 | input[1])
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
function calculateLossy(input) {
|
|
835
|
+
return {
|
|
836
|
+
height: readInt16LE(input, 8) & 16383,
|
|
837
|
+
width: readInt16LE(input, 6) & 16383
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
var WEBP = {
|
|
841
|
+
validate(input) {
|
|
842
|
+
const riffHeader = "RIFF" === toUTF8String(input, 0, 4);
|
|
843
|
+
const webpHeader = "WEBP" === toUTF8String(input, 8, 12);
|
|
844
|
+
const vp8Header = "VP8" === toUTF8String(input, 12, 15);
|
|
845
|
+
return riffHeader && webpHeader && vp8Header;
|
|
846
|
+
},
|
|
847
|
+
calculate(_input) {
|
|
848
|
+
const chunkHeader = toUTF8String(_input, 12, 16);
|
|
849
|
+
const input = _input.slice(20, 30);
|
|
850
|
+
if (chunkHeader === "VP8X") {
|
|
851
|
+
const extendedHeader = input[0];
|
|
852
|
+
const validStart = (extendedHeader & 192) === 0;
|
|
853
|
+
const validEnd = (extendedHeader & 1) === 0;
|
|
854
|
+
if (validStart && validEnd) {
|
|
855
|
+
return calculateExtended(input);
|
|
856
|
+
}
|
|
857
|
+
throw new TypeError("Invalid WebP");
|
|
858
|
+
}
|
|
859
|
+
if (chunkHeader === "VP8 " && input[0] !== 47) {
|
|
860
|
+
return calculateLossy(input);
|
|
861
|
+
}
|
|
862
|
+
const signature = toHexString(input, 3, 6);
|
|
863
|
+
if (chunkHeader === "VP8L" && signature !== "9d012a") {
|
|
864
|
+
return calculateLossless(input);
|
|
865
|
+
}
|
|
866
|
+
throw new TypeError("Invalid WebP");
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
var typeHandlers = /* @__PURE__ */ new Map([
|
|
870
|
+
["bmp", BMP],
|
|
871
|
+
["cur", CUR],
|
|
872
|
+
["dds", DDS],
|
|
873
|
+
["gif", GIF],
|
|
874
|
+
["heif", HEIF],
|
|
875
|
+
["icns", ICNS],
|
|
876
|
+
["ico", ICO],
|
|
877
|
+
["j2c", J2C],
|
|
878
|
+
["jp2", JP2],
|
|
879
|
+
["jpg", JPG],
|
|
880
|
+
["jxl", JXL],
|
|
881
|
+
["jxl-stream", JXLStream],
|
|
882
|
+
["ktx", KTX],
|
|
883
|
+
["png", PNG],
|
|
884
|
+
["pnm", PNM],
|
|
885
|
+
["psd", PSD],
|
|
886
|
+
["svg", SVG],
|
|
887
|
+
["tga", TGA],
|
|
888
|
+
["tiff", TIFF],
|
|
889
|
+
["webp", WEBP]
|
|
890
|
+
]);
|
|
891
|
+
var types = Array.from(typeHandlers.keys());
|
|
892
|
+
var firstBytes = /* @__PURE__ */ new Map([
|
|
893
|
+
[0, "heif"],
|
|
894
|
+
[56, "psd"],
|
|
895
|
+
[66, "bmp"],
|
|
896
|
+
[68, "dds"],
|
|
897
|
+
[71, "gif"],
|
|
898
|
+
[73, "tiff"],
|
|
899
|
+
[77, "tiff"],
|
|
900
|
+
[82, "webp"],
|
|
901
|
+
[105, "icns"],
|
|
902
|
+
[137, "png"],
|
|
903
|
+
[255, "jpg"]
|
|
904
|
+
]);
|
|
905
|
+
function detector(input) {
|
|
906
|
+
const byte = input[0];
|
|
907
|
+
const type = firstBytes.get(byte);
|
|
908
|
+
if (type && typeHandlers.get(type).validate(input)) {
|
|
909
|
+
return type;
|
|
910
|
+
}
|
|
911
|
+
return types.find((type2) => typeHandlers.get(type2).validate(input));
|
|
912
|
+
}
|
|
913
|
+
var globalOptions = {
|
|
914
|
+
disabledTypes: []
|
|
915
|
+
};
|
|
916
|
+
function imageSize(input) {
|
|
917
|
+
const type = detector(input);
|
|
918
|
+
if (typeof type !== "undefined") {
|
|
919
|
+
if (globalOptions.disabledTypes.indexOf(type) > -1) {
|
|
920
|
+
throw new TypeError(`disabled file type: ${type}`);
|
|
921
|
+
}
|
|
922
|
+
const size = typeHandlers.get(type).calculate(input);
|
|
923
|
+
if (size !== void 0) {
|
|
924
|
+
size.type = size.type ?? type;
|
|
925
|
+
if (size.images && size.images.length > 1) {
|
|
926
|
+
const largestImage = size.images.reduce((largest, current) => {
|
|
927
|
+
return current.width * current.height > largest.width * largest.height ? current : largest;
|
|
928
|
+
}, size.images[0]);
|
|
929
|
+
size.width = largestImage.width;
|
|
930
|
+
size.height = largestImage.height;
|
|
931
|
+
}
|
|
932
|
+
return size;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
throw new TypeError(`unsupported file type: ${type}`);
|
|
936
|
+
}
|
|
937
|
+
export {
|
|
938
|
+
imageSize as default,
|
|
939
|
+
imageSize,
|
|
940
|
+
types
|
|
941
|
+
};
|
|
942
|
+
//# sourceMappingURL=index.js.map
|