@ablogcms/lib 3.2.28-beta.0 → 3.2.29
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/README.md +4 -4
- package/dist/acms.d.ts +0 -2
- package/dist/geolocation.mjs +9 -5
- package/dist/geolocation.mjs.map +1 -1
- package/dist/select2/index.mjs +1 -1
- package/dist/select2/index.mjs.map +1 -1
- package/package.json +13 -72
- package/dist/chunk-AMZYQ4DG.mjs +0 -344
- package/dist/chunk-AMZYQ4DG.mjs.map +0 -1
- package/dist/command.d.ts +0 -5
- package/dist/command.mjs +0 -63
- package/dist/command.mjs.map +0 -1
- package/dist/create-pdf.d.ts +0 -1
- package/dist/create-pdf.mjs +0 -27
- package/dist/create-pdf.mjs.map +0 -1
- package/dist/htmx/geolocation.d.ts +0 -1
- package/dist/htmx/geolocation.mjs +0 -40
- package/dist/htmx/geolocation.mjs.map +0 -1
- package/dist/icons.d.ts +0 -2
- package/dist/icons.mjs +0 -181
- package/dist/icons.mjs.map +0 -1
- package/dist/pdf2image.d.ts +0 -21
- package/dist/pdf2image.mjs +0 -115
- package/dist/pdf2image.mjs.map +0 -1
- package/dist/polyfill/index.d.ts +0 -1
- package/dist/polyfill/index.mjs +0 -40
- package/dist/polyfill/index.mjs.map +0 -1
- package/dist/read-files.d.ts +0 -14
- package/dist/read-files.mjs +0 -62
- package/dist/read-files.mjs.map +0 -1
- package/dist/resize-image/resize-image.d.ts +0 -71
- package/dist/resize-image/resize-image.mjs +0 -308
- package/dist/resize-image/resize-image.mjs.map +0 -1
- package/dist/resize-image/util.d.ts +0 -134
- package/dist/resize-image/util.mjs +0 -7
- package/dist/resize-image/util.mjs.map +0 -1
- package/dist/wysiwyg.d.ts +0 -2
- package/dist/wysiwyg.mjs +0 -21
- package/dist/wysiwyg.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -6,24 +6,24 @@
|
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
import { resizeImage } from '@ablogcms/lib/resize-image';
|
|
9
|
-
import
|
|
9
|
+
import setupAtable from '@ablogcms/lib/a-table';
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
モジュール単位で import する(バレル export はない)。主なモジュール:
|
|
13
13
|
|
|
14
14
|
| sub-path | 内容 |
|
|
15
15
|
|---|---|
|
|
16
|
-
| `./read-files` | ファイル読み込みユーティリティ |
|
|
17
16
|
| `./resize-image` / `./resize-image-util` | 画像リサイズ |
|
|
18
17
|
| `./google-maps` / `./google-maps-picker` / `./google-maps-street-view` | Google Maps 連携 |
|
|
19
18
|
| `./open-street-map` / `./open-street-map-picker` | OpenStreetMap 連携 |
|
|
20
19
|
| `./a-table` | 表組みライブラリのラッパー |
|
|
21
20
|
| `./lite-editor` / `./lite-editor-field` | リッチテキストエディタ |
|
|
22
21
|
| `./flatpicker-date-picker` / `./flatpicker-time-picker` | 日時ピッカー |
|
|
23
|
-
| `./wysiwyg` | WYSIWYG エディタ |
|
|
24
22
|
| `./pdf2image` / `./create-pdf` | PDF 変換 |
|
|
25
23
|
| `./lazy-load` / `./loader` | 遅延読み込み |
|
|
26
24
|
| `./select2` / `./zxcvbn` / `./polyfill` | 各種ライブラリラッパー |
|
|
27
25
|
|
|
28
26
|
複数パッケージから共有されるランタイムインフラのみを収容する。単一パッケージ専用のヘルパーは
|
|
29
|
-
|
|
27
|
+
各パッケージ側に置く。ファイル読み込み(`@ablogcms/read-files`)、キーボード修飾キー表記
|
|
28
|
+
(`@ablogcms/command`)、アイコン一覧(`@ablogcms/acms-icons`)、WYSIWYG エディタ
|
|
29
|
+
(`@ablogcms/wysiwyg-editor`)は依存の軽量化のため独立パッケージに切り出している。
|
package/dist/acms.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type ResizeImage from './resize-image/resize-image.js';
|
|
2
1
|
import type geolocation from './geolocation.js';
|
|
3
2
|
declare module '@ablogcms/types/acms' {
|
|
4
3
|
interface AcmsLibrary {
|
|
5
|
-
ResizeImage: (elm: HTMLElement) => ResizeImage;
|
|
6
4
|
geolocation: typeof geolocation;
|
|
7
5
|
}
|
|
8
6
|
}
|
package/dist/geolocation.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/geolocation.ts
|
|
2
|
+
var translate = (key, fallback) => typeof ACMS !== "undefined" && ACMS.i18n ? ACMS.i18n(key) : fallback;
|
|
2
3
|
function geolocation(successCallable, errorCallable) {
|
|
3
4
|
if (!navigator.geolocation) {
|
|
4
|
-
errorCallable(
|
|
5
|
+
errorCallable(translate("geo_location.not_supported", "\u3054\u5229\u7528\u306E\u7AEF\u672B\u3067\u306F\u4F4D\u7F6E\u60C5\u5831\u53D6\u5F97\u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093\u3002"));
|
|
5
6
|
return;
|
|
6
7
|
}
|
|
7
8
|
window.navigator.geolocation.getCurrentPosition(
|
|
@@ -10,10 +11,13 @@ function geolocation(successCallable, errorCallable) {
|
|
|
10
11
|
},
|
|
11
12
|
(error) => {
|
|
12
13
|
const errorMessage = {
|
|
13
|
-
0:
|
|
14
|
-
1:
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
0: translate("geo_location.unknown_error", "\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002"),
|
|
15
|
+
1: translate(
|
|
16
|
+
"geo_location.user_denied",
|
|
17
|
+
"\u3053\u306E\u30DA\u30FC\u30B8\u306B\u306F\u30A2\u30AF\u30BB\u30B9\u8A31\u53EF\u304C\u306A\u3044\u305F\u3081\u3001\u4F4D\u7F6E\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002"
|
|
18
|
+
),
|
|
19
|
+
2: translate("geo_location.information_error", "\u4F4D\u7F6E\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002"),
|
|
20
|
+
3: translate("geo_location.timed_out", "\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u306B\u3088\u308A\u4F4D\u7F6E\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002")
|
|
17
21
|
};
|
|
18
22
|
errorCallable(errorMessage[error.code]);
|
|
19
23
|
},
|
package/dist/geolocation.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/geolocation.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/geolocation.ts"],"sourcesContent":["// acms.js未読込のページ(匿名訪問者向けのhtmx単体配信等)でも使えるようフォールバックする\nconst translate = (key: string, fallback: string): string =>\n typeof ACMS !== 'undefined' && ACMS.i18n ? ACMS.i18n(key) : fallback;\n\nexport default function geolocation(\n successCallable: (latitude: number, longitude: number) => void,\n errorCallable: (message: string) => void\n): void {\n if (!navigator.geolocation) {\n errorCallable(translate('geo_location.not_supported', 'ご利用の端末では位置情報取得に対応していません。'));\n return;\n }\n window.navigator.geolocation.getCurrentPosition(\n (position) => {\n successCallable(position.coords.latitude, position.coords.longitude);\n },\n (error) => {\n const errorMessage: Record<number, string> = {\n 0: translate('geo_location.unknown_error', '不明なエラーが発生しました。'),\n 1: translate(\n 'geo_location.user_denied',\n 'このページにはアクセス許可がないため、位置情報の取得に失敗しました。'\n ),\n 2: translate('geo_location.information_error', '位置情報の取得に失敗しました。'),\n 3: translate('geo_location.timed_out', 'タイムアウトにより位置情報の取得に失敗しました。'),\n };\n errorCallable(errorMessage[error.code]);\n },\n {\n enableHighAccuracy: true,\n timeout: 30000,\n maximumAge: 10000,\n }\n );\n}\n"],"mappings":";AACA,IAAM,YAAY,CAAC,KAAa,aAC9B,OAAO,SAAS,eAAe,KAAK,OAAO,KAAK,KAAK,GAAG,IAAI;AAE/C,SAAR,YACL,iBACA,eACM;AACN,MAAI,CAAC,UAAU,aAAa;AAC1B,kBAAc,UAAU,8BAA8B,kJAA0B,CAAC;AACjF;AAAA,EACF;AACA,SAAO,UAAU,YAAY;AAAA,IAC3B,CAAC,aAAa;AACZ,sBAAgB,SAAS,OAAO,UAAU,SAAS,OAAO,SAAS;AAAA,IACrE;AAAA,IACA,CAAC,UAAU;AACT,YAAM,eAAuC;AAAA,QAC3C,GAAG,UAAU,8BAA8B,sFAAgB;AAAA,QAC3D,GAAG;AAAA,UACD;AAAA,UACA;AAAA,QACF;AAAA,QACA,GAAG,UAAU,kCAAkC,4FAAiB;AAAA,QAChE,GAAG,UAAU,0BAA0B,kJAA0B;AAAA,MACnE;AACA,oBAAc,aAAa,MAAM,IAAI,CAAC;AAAA,IACxC;AAAA,IACA;AAAA,MACE,oBAAoB;AAAA,MACpB,SAAS;AAAA,MACT,YAAY;AAAA,IACd;AAAA,EACF;AACF;","names":[]}
|
package/dist/select2/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import "select2/dist/js/select2.full";
|
|
3
3
|
import "select2/dist/css/select2.css";
|
|
4
4
|
var defaultOption = {
|
|
5
|
-
|
|
5
|
+
selectionCssClass: "acms-admin-selectbox",
|
|
6
6
|
dropdownCssClass: "acms-admin-select-dropdown"
|
|
7
7
|
};
|
|
8
8
|
function setupSelect2(element, option = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/select2/index.js"],"sourcesContent":["import 'select2/dist/js/select2.full';\nimport 'select2/dist/css/select2.css';\n\nconst defaultOption = {\n
|
|
1
|
+
{"version":3,"sources":["../../src/select2/index.js"],"sourcesContent":["import 'select2/dist/js/select2.full';\nimport 'select2/dist/css/select2.css';\n\nconst defaultOption = {\n selectionCssClass: 'acms-admin-selectbox',\n dropdownCssClass: 'acms-admin-select-dropdown',\n};\n\nexport default function setupSelect2(element, option = {}) {\n const options = { ...defaultOption, ...option };\n const $element = $(element);\n $element\n .select2(options)\n .on('select2:open', () => {\n const positionY = element.getBoundingClientRect().top;\n let margin = window.innerHeight - positionY;\n if (positionY > margin) {\n margin = positionY;\n }\n margin -= 150;\n if (margin < 200) {\n margin = 200;\n }\n $('.select2-results__options').css('max-height', `${margin}px`);\n })\n .on('select2:select', () => {\n $(element).trigger('change');\n element.dispatchEvent(new Event('change', { bubbles: true }));\n });\n if (element.closest('.acms-admin-modal-dialog')) {\n $(element).data('select2').$dropdown.addClass('select2-in-modal');\n }\n}\n"],"mappings":";AAAA,OAAO;AACP,OAAO;AAEP,IAAM,gBAAgB;AAAA,EACpB,mBAAmB;AAAA,EACnB,kBAAkB;AACpB;AAEe,SAAR,aAA8B,SAAS,SAAS,CAAC,GAAG;AACzD,QAAM,UAAU,EAAE,GAAG,eAAe,GAAG,OAAO;AAC9C,QAAM,WAAW,EAAE,OAAO;AAC1B,WACG,QAAQ,OAAO,EACf,GAAG,gBAAgB,MAAM;AACxB,UAAM,YAAY,QAAQ,sBAAsB,EAAE;AAClD,QAAI,SAAS,OAAO,cAAc;AAClC,QAAI,YAAY,QAAQ;AACtB,eAAS;AAAA,IACX;AACA,cAAU;AACV,QAAI,SAAS,KAAK;AAChB,eAAS;AAAA,IACX;AACA,MAAE,2BAA2B,EAAE,IAAI,cAAc,GAAG,MAAM,IAAI;AAAA,EAChE,CAAC,EACA,GAAG,kBAAkB,MAAM;AAC1B,MAAE,OAAO,EAAE,QAAQ,QAAQ;AAC3B,YAAQ,cAAc,IAAI,MAAM,UAAU,EAAE,SAAS,KAAK,CAAC,CAAC;AAAA,EAC9D,CAAC;AACH,MAAI,QAAQ,QAAQ,0BAA0B,GAAG;AAC/C,MAAE,OAAO,EAAE,KAAK,SAAS,EAAE,UAAU,SAAS,kBAAkB;AAAA,EAClE;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ablogcms/lib",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.29",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Shared runtime infrastructure for the a-blog cms admin frontend",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://www.a-blogcms.jp",
|
|
8
8
|
"repository": {
|
|
@@ -12,39 +12,30 @@
|
|
|
12
12
|
},
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"**/*.css",
|
|
15
|
-
"**/polyfill/**",
|
|
16
15
|
"**/select2/**",
|
|
17
16
|
"**/lite-editor-field/**"
|
|
18
17
|
],
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"a-table": "^1.
|
|
21
|
-
"canvas-toBlob": "^1.0.0",
|
|
22
|
-
"core-js": "^3.38.1",
|
|
23
|
-
"exif-js": "^2.3.0",
|
|
19
|
+
"a-table": "^1.6.0",
|
|
24
20
|
"flatpickr": "^4.6.13",
|
|
25
21
|
"google-maps": "^4.3.3",
|
|
26
|
-
"heic-to": "^1.2.2",
|
|
27
|
-
"htmx.org": "^2.0.8",
|
|
28
22
|
"leaflet": "^1.9.4",
|
|
29
|
-
"leaflet-geosearch": "^4.
|
|
23
|
+
"leaflet-geosearch": "^4.4.0",
|
|
30
24
|
"leaflet-gesture-handling": "^1.2.2",
|
|
31
|
-
"lite-editor": "^2.
|
|
25
|
+
"lite-editor": "^2.2.0",
|
|
32
26
|
"lite-editor-emoji-picker-plugin": "^4.0.1",
|
|
33
27
|
"lozad": "^1.16.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"qs": "^6.14.0",
|
|
37
|
-
"select2": "^4.0.13",
|
|
38
|
-
"trumbowyg": "2.27.3",
|
|
28
|
+
"qs": "^6.15.3",
|
|
29
|
+
"select2": "^4.1.0",
|
|
39
30
|
"zxcvbn": "^4.4.2",
|
|
40
|
-
"@ablogcms/events": "3.2.
|
|
41
|
-
"@ablogcms/
|
|
42
|
-
"@ablogcms/
|
|
43
|
-
"@ablogcms/types": "3.2.
|
|
31
|
+
"@ablogcms/events": "3.2.29",
|
|
32
|
+
"@ablogcms/utils": "3.2.29",
|
|
33
|
+
"@ablogcms/validator": "3.2.29",
|
|
34
|
+
"@ablogcms/types": "3.2.29"
|
|
44
35
|
},
|
|
45
36
|
"devDependencies": {
|
|
46
|
-
"@types/leaflet": "^1.9.
|
|
47
|
-
"vitest": "^4.1.
|
|
37
|
+
"@types/leaflet": "^1.9.22",
|
|
38
|
+
"vitest": "^4.1.10"
|
|
48
39
|
},
|
|
49
40
|
"exports": {
|
|
50
41
|
"./a-table": {
|
|
@@ -57,16 +48,6 @@
|
|
|
57
48
|
"import": "./dist/acms.mjs",
|
|
58
49
|
"default": "./dist/acms.mjs"
|
|
59
50
|
},
|
|
60
|
-
"./command": {
|
|
61
|
-
"types": "./dist/command.d.ts",
|
|
62
|
-
"import": "./dist/command.mjs",
|
|
63
|
-
"default": "./dist/command.mjs"
|
|
64
|
-
},
|
|
65
|
-
"./create-pdf": {
|
|
66
|
-
"types": "./dist/create-pdf.d.ts",
|
|
67
|
-
"import": "./dist/create-pdf.mjs",
|
|
68
|
-
"default": "./dist/create-pdf.mjs"
|
|
69
|
-
},
|
|
70
51
|
"./flatpickr-date-picker": {
|
|
71
52
|
"types": "./dist/flatpicker/date-picker.d.ts",
|
|
72
53
|
"import": "./dist/flatpicker/date-picker.mjs",
|
|
@@ -102,16 +83,6 @@
|
|
|
102
83
|
"import": "./dist/google-maps/street-view.mjs",
|
|
103
84
|
"default": "./dist/google-maps/street-view.mjs"
|
|
104
85
|
},
|
|
105
|
-
"./htmx-geolocation": {
|
|
106
|
-
"types": "./dist/htmx/geolocation.d.ts",
|
|
107
|
-
"import": "./dist/htmx/geolocation.mjs",
|
|
108
|
-
"default": "./dist/htmx/geolocation.mjs"
|
|
109
|
-
},
|
|
110
|
-
"./icons": {
|
|
111
|
-
"types": "./dist/icons.d.ts",
|
|
112
|
-
"import": "./dist/icons.mjs",
|
|
113
|
-
"default": "./dist/icons.mjs"
|
|
114
|
-
},
|
|
115
86
|
"./lazy-load": {
|
|
116
87
|
"types": "./dist/lazy-load/index.d.ts",
|
|
117
88
|
"import": "./dist/lazy-load/index.mjs",
|
|
@@ -147,31 +118,6 @@
|
|
|
147
118
|
"import": "./dist/open-street-map/picker/open-street-map-picker.mjs",
|
|
148
119
|
"default": "./dist/open-street-map/picker/open-street-map-picker.mjs"
|
|
149
120
|
},
|
|
150
|
-
"./pdf2image": {
|
|
151
|
-
"types": "./dist/pdf2image.d.ts",
|
|
152
|
-
"import": "./dist/pdf2image.mjs",
|
|
153
|
-
"default": "./dist/pdf2image.mjs"
|
|
154
|
-
},
|
|
155
|
-
"./polyfill": {
|
|
156
|
-
"types": "./dist/polyfill/index.d.ts",
|
|
157
|
-
"import": "./dist/polyfill/index.mjs",
|
|
158
|
-
"default": "./dist/polyfill/index.mjs"
|
|
159
|
-
},
|
|
160
|
-
"./read-files": {
|
|
161
|
-
"types": "./dist/read-files.d.ts",
|
|
162
|
-
"import": "./dist/read-files.mjs",
|
|
163
|
-
"default": "./dist/read-files.mjs"
|
|
164
|
-
},
|
|
165
|
-
"./resize-image": {
|
|
166
|
-
"types": "./dist/resize-image/resize-image.d.ts",
|
|
167
|
-
"import": "./dist/resize-image/resize-image.mjs",
|
|
168
|
-
"default": "./dist/resize-image/resize-image.mjs"
|
|
169
|
-
},
|
|
170
|
-
"./resize-image-util": {
|
|
171
|
-
"types": "./dist/resize-image/util.d.ts",
|
|
172
|
-
"import": "./dist/resize-image/util.mjs",
|
|
173
|
-
"default": "./dist/resize-image/util.mjs"
|
|
174
|
-
},
|
|
175
121
|
"./select2": {
|
|
176
122
|
"types": "./dist/select2/index.d.ts",
|
|
177
123
|
"import": "./dist/select2/index.mjs",
|
|
@@ -180,11 +126,6 @@
|
|
|
180
126
|
"./trumbowyg": {
|
|
181
127
|
"types": "./dist/trumbowyg.d.ts"
|
|
182
128
|
},
|
|
183
|
-
"./wysiwyg": {
|
|
184
|
-
"types": "./dist/wysiwyg.d.ts",
|
|
185
|
-
"import": "./dist/wysiwyg.mjs",
|
|
186
|
-
"default": "./dist/wysiwyg.mjs"
|
|
187
|
-
},
|
|
188
129
|
"./zxcvbn": {
|
|
189
130
|
"types": "./dist/zxcvbn/index.d.ts",
|
|
190
131
|
"import": "./dist/zxcvbn/index.mjs",
|
package/dist/chunk-AMZYQ4DG.mjs
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
// src/resize-image/util.ts
|
|
2
|
-
import { dataUrlToBlob } from "@ablogcms/utils/file";
|
|
3
|
-
var ResizeImageUtil = class {
|
|
4
|
-
/**
|
|
5
|
-
* URLからBASE64画像でリサイズ画像を取得
|
|
6
|
-
*
|
|
7
|
-
* @param url
|
|
8
|
-
* @param resizeType (null=long side, width, height)
|
|
9
|
-
* @param resizeSize (length)
|
|
10
|
-
* @param callback
|
|
11
|
-
*/
|
|
12
|
-
async getDataUrlFromUrl(url, resizeType, resizeSize, callback) {
|
|
13
|
-
const Mime = await import(
|
|
14
|
-
/* webpackChunkName: "mime-types" */
|
|
15
|
-
"mime-types"
|
|
16
|
-
);
|
|
17
|
-
const mimeType = Mime.lookup(url) || "image/png";
|
|
18
|
-
const image = new Image();
|
|
19
|
-
image.crossOrigin = "anonymous";
|
|
20
|
-
image.src = url;
|
|
21
|
-
const res = await this.getDataURL(image, mimeType, resizeType, resizeSize, callback);
|
|
22
|
-
return res;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* URLからBLOBデータでリサイズ画像を取得
|
|
26
|
-
*
|
|
27
|
-
* @param url
|
|
28
|
-
* @param resizeType
|
|
29
|
-
* @param resizeSize
|
|
30
|
-
* @param callback
|
|
31
|
-
*/
|
|
32
|
-
async getBlobFromUrl(url, resizeType, resizeSize, callback) {
|
|
33
|
-
const Mime = await import(
|
|
34
|
-
/* webpackChunkName: "mime-types" */
|
|
35
|
-
"mime-types"
|
|
36
|
-
);
|
|
37
|
-
const mimeType = Mime.lookup(url) || "image/png";
|
|
38
|
-
const image = new Image();
|
|
39
|
-
image.crossOrigin = "anonymous";
|
|
40
|
-
image.src = url;
|
|
41
|
-
const res = await this.getBlob(image, mimeType, resizeType, resizeSize, callback);
|
|
42
|
-
return res;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* FileからBASE64画像でリサイズ画像を取得
|
|
46
|
-
*
|
|
47
|
-
* @param file
|
|
48
|
-
* @param resizeType
|
|
49
|
-
* @param resizeSize
|
|
50
|
-
* @param callback
|
|
51
|
-
* @returns {Promise}
|
|
52
|
-
*/
|
|
53
|
-
async getDataUrlFromFile(file, resizeType, resizeSize, callback) {
|
|
54
|
-
const mimeType = file.type || "image/png";
|
|
55
|
-
const image = new Image();
|
|
56
|
-
image.src = this._createObjectURL(file);
|
|
57
|
-
const res = await this.getDataURL(image, mimeType, resizeType, resizeSize, callback);
|
|
58
|
-
return res;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* FileからBLOBデータでリサイズ画像を取得
|
|
62
|
-
*
|
|
63
|
-
* @param file
|
|
64
|
-
* @param resizeType
|
|
65
|
-
* @param resizeSize
|
|
66
|
-
* @param callback
|
|
67
|
-
* @returns {Promise}
|
|
68
|
-
*/
|
|
69
|
-
async getBlobFromFile(file, resizeType, resizeSize, callback) {
|
|
70
|
-
const mimeType = file.type || "image/png";
|
|
71
|
-
const image = new Image();
|
|
72
|
-
image.src = this._createObjectURL(file);
|
|
73
|
-
const res = await this.getBlob(image, mimeType, resizeType, resizeSize, callback);
|
|
74
|
-
return res;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* BASE64画像を取得
|
|
78
|
-
*
|
|
79
|
-
* @param image
|
|
80
|
-
* @param mimeType
|
|
81
|
-
* @param resizeType
|
|
82
|
-
* @param resizeSize
|
|
83
|
-
* @param callback
|
|
84
|
-
* @returns {Promise}
|
|
85
|
-
*/
|
|
86
|
-
getDataURL(image, mimeType, resizeType, resizeSize, callback) {
|
|
87
|
-
return new Promise((resolve) => {
|
|
88
|
-
const onload = () => {
|
|
89
|
-
const canvas = document.createElement("canvas");
|
|
90
|
-
if (!resizeSize) {
|
|
91
|
-
resizeSize = image.width;
|
|
92
|
-
}
|
|
93
|
-
const destinationSize = this._getDestinationSize(image, resizeType, resizeSize);
|
|
94
|
-
const drawInfo = {
|
|
95
|
-
rad: 0,
|
|
96
|
-
dx: 0,
|
|
97
|
-
dy: 0
|
|
98
|
-
};
|
|
99
|
-
canvas.width = destinationSize.width;
|
|
100
|
-
canvas.height = destinationSize.height;
|
|
101
|
-
this._drawImage(image, canvas, destinationSize, drawInfo);
|
|
102
|
-
const dataUrl = canvas.toDataURL(mimeType);
|
|
103
|
-
resolve({
|
|
104
|
-
dataUrl,
|
|
105
|
-
resize: destinationSize.resize
|
|
106
|
-
});
|
|
107
|
-
if (typeof callback === "function") {
|
|
108
|
-
callback(dataUrl, destinationSize.resize);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
if (image.width) {
|
|
112
|
-
onload();
|
|
113
|
-
} else {
|
|
114
|
-
image.onload = onload;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* リサイズした上で、Blobデータを取得
|
|
120
|
-
*
|
|
121
|
-
* @param image
|
|
122
|
-
* @param mimeType
|
|
123
|
-
* @param resizeType
|
|
124
|
-
* @param resizeSize
|
|
125
|
-
* @param callback
|
|
126
|
-
* @returns {Promise}
|
|
127
|
-
*/
|
|
128
|
-
getBlob(image, mimeType, resizeType, resizeSize, callback) {
|
|
129
|
-
return new Promise((resolve, reject) => {
|
|
130
|
-
const onload = () => {
|
|
131
|
-
const canvas = document.createElement("canvas");
|
|
132
|
-
if (!resizeSize) {
|
|
133
|
-
resizeSize = image.width;
|
|
134
|
-
}
|
|
135
|
-
const destinationSize = this._getDestinationSize(image, resizeType, resizeSize);
|
|
136
|
-
const drawInfo = {
|
|
137
|
-
rad: 0,
|
|
138
|
-
dx: 0,
|
|
139
|
-
dy: 0
|
|
140
|
-
};
|
|
141
|
-
canvas.width = destinationSize.width;
|
|
142
|
-
canvas.height = destinationSize.height;
|
|
143
|
-
this._drawImage(image, canvas, destinationSize, drawInfo);
|
|
144
|
-
canvas.toBlob(
|
|
145
|
-
(blob) => {
|
|
146
|
-
if (blob === null) {
|
|
147
|
-
reject(new Error("Failed to create Blob"));
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
resolve({
|
|
151
|
-
blob,
|
|
152
|
-
resize: destinationSize.resize
|
|
153
|
-
});
|
|
154
|
-
if (typeof callback === "function") {
|
|
155
|
-
callback(blob, destinationSize.resize);
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
mimeType,
|
|
159
|
-
1
|
|
160
|
-
);
|
|
161
|
-
};
|
|
162
|
-
if (image.width) {
|
|
163
|
-
onload();
|
|
164
|
-
} else {
|
|
165
|
-
image.onload = onload;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* データUrlをBlobに変換
|
|
171
|
-
*
|
|
172
|
-
* @param dataUrl
|
|
173
|
-
* @returns {*}
|
|
174
|
-
*/
|
|
175
|
-
dataUrlToBlob(dataUrl) {
|
|
176
|
-
return dataUrlToBlob(dataUrl);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* fileからデータURL作成
|
|
180
|
-
*
|
|
181
|
-
* @param file
|
|
182
|
-
* @returns {*}
|
|
183
|
-
* @private
|
|
184
|
-
*/
|
|
185
|
-
_createObjectURL(file) {
|
|
186
|
-
const createObjectURL = window.URL && window.URL.createObjectURL;
|
|
187
|
-
return createObjectURL(file);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* リサイズ画像の書き出し
|
|
191
|
-
*
|
|
192
|
-
* @param image
|
|
193
|
-
* @param canvas
|
|
194
|
-
* @param destinationSize
|
|
195
|
-
* @param drawInfo
|
|
196
|
-
* @returns {*}
|
|
197
|
-
*/
|
|
198
|
-
_drawImage(image, canvas, destinationSize, drawInfo) {
|
|
199
|
-
const ctx = canvas.getContext("2d");
|
|
200
|
-
ctx.imageSmoothingEnabled = true;
|
|
201
|
-
ctx.imageSmoothingQuality = "high";
|
|
202
|
-
const { rad, dx, dy } = drawInfo;
|
|
203
|
-
const diff = 0.5;
|
|
204
|
-
if (image.width * diff > destinationSize.width) {
|
|
205
|
-
let oc = document.createElement("canvas");
|
|
206
|
-
const octx = oc.getContext("2d");
|
|
207
|
-
octx.imageSmoothingEnabled = true;
|
|
208
|
-
octx.imageSmoothingQuality = "high";
|
|
209
|
-
oc.width = image.width * diff;
|
|
210
|
-
oc.height = image.height * diff;
|
|
211
|
-
octx.drawImage(image, 0, 0, oc.width, oc.height);
|
|
212
|
-
let { width } = oc;
|
|
213
|
-
let { height } = oc;
|
|
214
|
-
while (width * diff > destinationSize.width) {
|
|
215
|
-
const tmp = document.createElement("canvas");
|
|
216
|
-
tmp.width = Math.max(Math.floor(width * diff), destinationSize.width);
|
|
217
|
-
tmp.height = Math.max(Math.floor(height * diff), destinationSize.height);
|
|
218
|
-
const tmpCtx = tmp.getContext("2d");
|
|
219
|
-
tmpCtx.imageSmoothingEnabled = true;
|
|
220
|
-
tmpCtx.imageSmoothingQuality = "high";
|
|
221
|
-
tmpCtx.drawImage(oc, 0, 0, width, height, 0, 0, tmp.width, tmp.height);
|
|
222
|
-
oc = tmp;
|
|
223
|
-
width = oc.width;
|
|
224
|
-
height = oc.height;
|
|
225
|
-
}
|
|
226
|
-
if (drawInfo.rad !== 0) {
|
|
227
|
-
ctx.setTransform(Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), dx, dy);
|
|
228
|
-
}
|
|
229
|
-
ctx.drawImage(oc, 0, 0, width, height, 0, 0, destinationSize.width, destinationSize.height);
|
|
230
|
-
} else {
|
|
231
|
-
if (drawInfo.rad !== 0) {
|
|
232
|
-
ctx.setTransform(Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), dx, dy);
|
|
233
|
-
}
|
|
234
|
-
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, destinationSize.width, destinationSize.height);
|
|
235
|
-
}
|
|
236
|
-
return canvas;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* リサイズサイズの取得
|
|
240
|
-
*
|
|
241
|
-
* @param image
|
|
242
|
-
* @param resizeType
|
|
243
|
-
* @param resizeSize
|
|
244
|
-
* @returns {{width: number, height: number}}
|
|
245
|
-
*/
|
|
246
|
-
_getDestinationSize = (image, resizeType, resizeSize) => {
|
|
247
|
-
const destinationSize = {
|
|
248
|
-
width: 0,
|
|
249
|
-
height: 0,
|
|
250
|
-
resize: true
|
|
251
|
-
};
|
|
252
|
-
if (!resizeType) {
|
|
253
|
-
if (image.width > image.height) {
|
|
254
|
-
resizeType = "width";
|
|
255
|
-
} else {
|
|
256
|
-
resizeType = "height";
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (resizeType.substring(0, 1) === "h") {
|
|
260
|
-
if (image.height < resizeSize) {
|
|
261
|
-
destinationSize.width = image.width;
|
|
262
|
-
destinationSize.height = image.height;
|
|
263
|
-
destinationSize.resize = false;
|
|
264
|
-
} else {
|
|
265
|
-
destinationSize.width = image.width * (resizeSize / image.height);
|
|
266
|
-
destinationSize.height = resizeSize;
|
|
267
|
-
}
|
|
268
|
-
} else if (image.width < resizeSize) {
|
|
269
|
-
destinationSize.width = image.width;
|
|
270
|
-
destinationSize.height = image.height;
|
|
271
|
-
destinationSize.resize = false;
|
|
272
|
-
} else {
|
|
273
|
-
destinationSize.width = resizeSize;
|
|
274
|
-
destinationSize.height = image.height * (resizeSize / image.width);
|
|
275
|
-
}
|
|
276
|
-
return destinationSize;
|
|
277
|
-
};
|
|
278
|
-
/**
|
|
279
|
-
* 画像のローテーション対応
|
|
280
|
-
*
|
|
281
|
-
* @param image
|
|
282
|
-
* @param canvas
|
|
283
|
-
* @param destinationSize
|
|
284
|
-
* @returns {Promise}
|
|
285
|
-
*/
|
|
286
|
-
_fixImageRotation(image, canvas, destinationSize) {
|
|
287
|
-
return new Promise((resolve) => {
|
|
288
|
-
this._getExifData(image).then((exif) => {
|
|
289
|
-
const drawInfo = {
|
|
290
|
-
rad: 0,
|
|
291
|
-
dx: 0,
|
|
292
|
-
dy: 0
|
|
293
|
-
};
|
|
294
|
-
switch (exif.Orientation) {
|
|
295
|
-
case 8:
|
|
296
|
-
canvas.width = destinationSize.height;
|
|
297
|
-
canvas.height = destinationSize.width;
|
|
298
|
-
drawInfo.rad = -90 * Math.PI / 180;
|
|
299
|
-
drawInfo.dy = canvas.height;
|
|
300
|
-
break;
|
|
301
|
-
case 3:
|
|
302
|
-
drawInfo.rad = 180 * Math.PI / 180;
|
|
303
|
-
drawInfo.dx = canvas.width;
|
|
304
|
-
drawInfo.dy = canvas.height;
|
|
305
|
-
break;
|
|
306
|
-
case 6:
|
|
307
|
-
canvas.width = destinationSize.height;
|
|
308
|
-
canvas.height = destinationSize.width;
|
|
309
|
-
drawInfo.rad = 90 * Math.PI / 180;
|
|
310
|
-
drawInfo.dx = canvas.width;
|
|
311
|
-
break;
|
|
312
|
-
default:
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
resolve(drawInfo);
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Exif情報の取得
|
|
321
|
-
*
|
|
322
|
-
* @param image
|
|
323
|
-
* @returns {Promise}
|
|
324
|
-
*/
|
|
325
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
326
|
-
_getExifData(image) {
|
|
327
|
-
return new Promise((resolve) => {
|
|
328
|
-
import(
|
|
329
|
-
/* webpackChunkName: "exif-js" */
|
|
330
|
-
"exif-js"
|
|
331
|
-
).then((Exif) => {
|
|
332
|
-
Exif.getData(image, () => {
|
|
333
|
-
const res = Exif.getAllTags(image);
|
|
334
|
-
resolve(res);
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
export {
|
|
342
|
-
ResizeImageUtil
|
|
343
|
-
};
|
|
344
|
-
//# sourceMappingURL=chunk-AMZYQ4DG.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/resize-image/util.ts"],"sourcesContent":["import { dataUrlToBlob } from '@ablogcms/utils/file';\n\ninterface DrawInfo {\n rad: number;\n dx: number;\n dy: number;\n}\n\ninterface DestinationSize {\n width: number;\n height: number;\n resize: boolean;\n}\n\ninterface DataUrlRes {\n dataUrl: string;\n resize: boolean;\n}\n\ninterface BlobRes {\n blob: Blob;\n resize: boolean;\n}\n\nexport default class ResizeImageUtil {\n /**\n * URLからBASE64画像でリサイズ画像を取得\n *\n * @param url\n * @param resizeType (null=long side, width, height)\n * @param resizeSize (length)\n * @param callback\n */\n async getDataUrlFromUrl(\n url: string,\n resizeType: string,\n resizeSize: number,\n callback: () => void\n ): Promise<DataUrlRes> {\n const Mime = await import(/* webpackChunkName: \"mime-types\" */ 'mime-types');\n const mimeType = Mime.lookup(url) || 'image/png';\n const image = new Image();\n image.crossOrigin = 'anonymous';\n image.src = url;\n\n const res = await this.getDataURL(image, mimeType, resizeType, resizeSize, callback);\n return res;\n }\n\n /**\n * URLからBLOBデータでリサイズ画像を取得\n *\n * @param url\n * @param resizeType\n * @param resizeSize\n * @param callback\n */\n async getBlobFromUrl(url: string, resizeType: string, resizeSize: number, callback: () => void): Promise<BlobRes> {\n const Mime = await import(/* webpackChunkName: \"mime-types\" */ 'mime-types');\n const mimeType = Mime.lookup(url) || 'image/png';\n const image = new Image();\n image.crossOrigin = 'anonymous';\n image.src = url;\n\n const res = await this.getBlob(image, mimeType, resizeType, resizeSize, callback);\n return res;\n }\n\n /**\n * FileからBASE64画像でリサイズ画像を取得\n *\n * @param file\n * @param resizeType\n * @param resizeSize\n * @param callback\n * @returns {Promise}\n */\n async getDataUrlFromFile(\n file: File,\n resizeType: string,\n resizeSize: number,\n callback: () => void\n ): Promise<DataUrlRes> {\n const mimeType = file.type || 'image/png';\n const image = new Image();\n image.src = this._createObjectURL(file);\n\n const res = await this.getDataURL(image, mimeType, resizeType, resizeSize, callback);\n return res;\n }\n\n /**\n * FileからBLOBデータでリサイズ画像を取得\n *\n * @param file\n * @param resizeType\n * @param resizeSize\n * @param callback\n * @returns {Promise}\n */\n async getBlobFromFile(file: File, resizeType: string, resizeSize: number, callback?: () => void): Promise<BlobRes> {\n const mimeType = file.type || 'image/png';\n const image = new Image();\n image.src = this._createObjectURL(file);\n const res = await this.getBlob(image, mimeType, resizeType, resizeSize, callback);\n return res;\n }\n\n /**\n * BASE64画像を取得\n *\n * @param image\n * @param mimeType\n * @param resizeType\n * @param resizeSize\n * @param callback\n * @returns {Promise}\n */\n getDataURL(\n image: HTMLImageElement,\n mimeType: string,\n resizeType: string,\n resizeSize: number,\n callback: (dataUrl: string, resize: boolean) => void\n ): Promise<DataUrlRes> {\n return new Promise((resolve) => {\n const onload = () => {\n const canvas = document.createElement('canvas');\n if (!resizeSize) {\n resizeSize = image.width;\n }\n const destinationSize = this._getDestinationSize(image, resizeType, resizeSize);\n const drawInfo = {\n rad: 0,\n dx: 0,\n dy: 0,\n };\n\n canvas.width = destinationSize.width;\n canvas.height = destinationSize.height;\n\n this._drawImage(image, canvas, destinationSize, drawInfo);\n const dataUrl = canvas.toDataURL(mimeType);\n resolve({\n dataUrl,\n resize: destinationSize.resize,\n });\n if (typeof callback === 'function') {\n callback(dataUrl, destinationSize.resize);\n }\n };\n if (image.width) {\n onload();\n } else {\n image.onload = onload;\n }\n });\n }\n\n /**\n * リサイズした上で、Blobデータを取得\n *\n * @param image\n * @param mimeType\n * @param resizeType\n * @param resizeSize\n * @param callback\n * @returns {Promise}\n */\n getBlob(\n image: HTMLImageElement,\n mimeType: string,\n resizeType: string,\n resizeSize: number,\n callback?: (blob: Blob | null, resize: boolean) => void\n ): Promise<BlobRes> {\n return new Promise((resolve, reject) => {\n const onload = () => {\n const canvas = document.createElement('canvas');\n if (!resizeSize) {\n resizeSize = image.width;\n }\n const destinationSize = this._getDestinationSize(image, resizeType, resizeSize);\n const drawInfo = {\n rad: 0,\n dx: 0,\n dy: 0,\n };\n canvas.width = destinationSize.width;\n canvas.height = destinationSize.height;\n\n this._drawImage(image, canvas, destinationSize, drawInfo);\n canvas.toBlob(\n (blob) => {\n if (blob === null) {\n reject(new Error('Failed to create Blob'));\n return;\n }\n resolve({\n blob,\n resize: destinationSize.resize,\n });\n if (typeof callback === 'function') {\n callback(blob, destinationSize.resize);\n }\n },\n mimeType,\n 1\n );\n };\n if (image.width) {\n onload();\n } else {\n image.onload = onload;\n }\n });\n }\n\n /**\n * データUrlをBlobに変換\n *\n * @param dataUrl\n * @returns {*}\n */\n dataUrlToBlob(dataUrl: string): Blob {\n return dataUrlToBlob(dataUrl);\n }\n\n /**\n * fileからデータURL作成\n *\n * @param file\n * @returns {*}\n * @private\n */\n _createObjectURL(file: File): string {\n const createObjectURL = window.URL && window.URL.createObjectURL;\n return createObjectURL(file);\n }\n\n /**\n * リサイズ画像の書き出し\n *\n * @param image\n * @param canvas\n * @param destinationSize\n * @param drawInfo\n * @returns {*}\n */\n _drawImage(\n image: HTMLImageElement,\n canvas: HTMLCanvasElement,\n destinationSize: { width: number; height: number },\n drawInfo: DrawInfo\n ): HTMLCanvasElement {\n const ctx = canvas.getContext('2d')!;\n // 高品質補間を有効化\n ctx.imageSmoothingEnabled = true;\n ctx.imageSmoothingQuality = 'high';\n const { rad, dx, dy } = drawInfo;\n const diff = 0.5;\n\n if (image.width * diff > destinationSize.width) {\n // スムーズ処理を入れて、リサイズ\n let oc = document.createElement('canvas');\n const octx = oc.getContext('2d')!;\n // 高品質補間を有効化\n octx.imageSmoothingEnabled = true;\n octx.imageSmoothingQuality = 'high';\n\n // step 1 we reduce the image to half by using an off-screen canvas\n oc.width = image.width * diff;\n oc.height = image.height * diff;\n octx.drawImage(image, 0, 0, oc.width, oc.height);\n\n let { width } = oc;\n let { height } = oc;\n\n // step 2 reuses the off-screen canvas and draws the image reduced to half again\n while (width * diff > destinationSize.width) {\n const tmp = document.createElement('canvas');\n tmp.width = Math.max(Math.floor(width * diff), destinationSize.width);\n tmp.height = Math.max(Math.floor(height * diff), destinationSize.height);\n\n const tmpCtx = tmp.getContext('2d')!;\n tmpCtx.imageSmoothingEnabled = true;\n tmpCtx.imageSmoothingQuality = 'high';\n tmpCtx.drawImage(oc, 0, 0, width, height, 0, 0, tmp.width, tmp.height);\n\n oc = tmp;\n width = oc.width;\n height = oc.height;\n }\n // step 3 we draw once more to main canvas, again reduced to half but to the final size\n if (drawInfo.rad !== 0) {\n ctx.setTransform(Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), dx, dy);\n }\n ctx.drawImage(oc, 0, 0, width, height, 0, 0, destinationSize.width, destinationSize.height);\n } else {\n // 一気にリサイズ\n if (drawInfo.rad !== 0) {\n ctx.setTransform(Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), dx, dy);\n }\n ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, destinationSize.width, destinationSize.height);\n }\n return canvas;\n }\n\n /**\n * リサイズサイズの取得\n *\n * @param image\n * @param resizeType\n * @param resizeSize\n * @returns {{width: number, height: number}}\n */\n _getDestinationSize = (image: HTMLImageElement, resizeType: string, resizeSize: number): DestinationSize => {\n const destinationSize: DestinationSize = {\n width: 0,\n height: 0,\n resize: true,\n };\n\n // Long side\n if (!resizeType) {\n if (image.width > image.height) {\n resizeType = 'width';\n } else {\n resizeType = 'height';\n }\n }\n\n if (resizeType.substring(0, 1) === 'h') {\n // Portrait\n if (image.height < resizeSize) {\n destinationSize.width = image.width;\n destinationSize.height = image.height;\n destinationSize.resize = false;\n } else {\n destinationSize.width = image.width * (resizeSize / image.height);\n destinationSize.height = resizeSize;\n }\n\n // Landscape\n } else if (image.width < resizeSize) {\n destinationSize.width = image.width;\n destinationSize.height = image.height;\n destinationSize.resize = false;\n } else {\n destinationSize.width = resizeSize;\n destinationSize.height = image.height * (resizeSize / image.width);\n }\n\n return destinationSize;\n };\n\n /**\n * 画像のローテーション対応\n *\n * @param image\n * @param canvas\n * @param destinationSize\n * @returns {Promise}\n */\n _fixImageRotation(\n image: HTMLImageElement,\n canvas: HTMLCanvasElement,\n destinationSize: DestinationSize\n ): Promise<DrawInfo> {\n return new Promise((resolve) => {\n this._getExifData(image).then((exif) => {\n const drawInfo = {\n rad: 0,\n dx: 0,\n dy: 0,\n };\n\n switch (exif.Orientation) {\n case 8:\n canvas.width = destinationSize.height;\n canvas.height = destinationSize.width;\n drawInfo.rad = (-90 * Math.PI) / 180;\n drawInfo.dy = canvas.height;\n break;\n case 3:\n drawInfo.rad = (180 * Math.PI) / 180;\n drawInfo.dx = canvas.width;\n drawInfo.dy = canvas.height;\n break;\n case 6:\n canvas.width = destinationSize.height;\n canvas.height = destinationSize.width;\n drawInfo.rad = (90 * Math.PI) / 180;\n drawInfo.dx = canvas.width;\n break;\n default:\n break;\n }\n resolve(drawInfo);\n });\n });\n }\n\n /**\n * Exif情報の取得\n *\n * @param image\n * @returns {Promise}\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _getExifData(image: HTMLImageElement): Promise<any> {\n return new Promise((resolve) => {\n import(/* webpackChunkName: \"exif-js\" */ 'exif-js').then((Exif) => {\n // @ts-expect-error type definition is not correct\n Exif.getData(image, () => {\n const res = Exif.getAllTags(image);\n resolve(res);\n });\n });\n });\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAwB9B,IAAqB,kBAArB,MAAqC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASnC,MAAM,kBACJ,KACA,YACA,YACA,UACqB;AACrB,UAAM,OAAO,MAAM;AAAA;AAAA,MAA4C;AAAA,IAAY;AAC3E,UAAM,WAAW,KAAK,OAAO,GAAG,KAAK;AACrC,UAAM,QAAQ,IAAI,MAAM;AACxB,UAAM,cAAc;AACpB,UAAM,MAAM;AAEZ,UAAM,MAAM,MAAM,KAAK,WAAW,OAAO,UAAU,YAAY,YAAY,QAAQ;AACnF,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