heic-to 1.1.5 → 1.1.6

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/esbuild.mjs CHANGED
@@ -1,11 +1,24 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import fs from 'fs'
3
3
 
4
+ fs.mkdirSync("tmp/src/csp", { recursive: true });
5
+
6
+ const copyAndReplace = (sourceFilePath, destinationFilePath, regexPattern, replacementText) => {
7
+ const content = fs.readFileSync(sourceFilePath, 'utf-8');
8
+ const modifiedContent = content.replace(regexPattern, replacementText);
9
+ fs.writeFileSync(destinationFilePath, modifiedContent);
10
+ }
11
+
12
+ copyAndReplace("src/worker.js", "tmp/src/worker.js", /LIB_HEIF_PATH/, '"../../src/lib/libheif"')
13
+ copyAndReplace("src/worker.js", "tmp/src/csp/worker.js", /LIB_HEIF_PATH/, '"../../../src/lib/libheif-without-unsafe-eval"')
14
+
15
+ // ################
4
16
  // Build heic-to.js
17
+ // ################
5
18
 
6
19
  await esbuild.build({
7
20
  entryPoints: [
8
- 'src/worker.js'
21
+ 'tmp/src/worker.js'
9
22
  ],
10
23
  bundle: true,
11
24
  minify: false,
@@ -32,11 +45,13 @@ esbuild.build({
32
45
  }
33
46
  });
34
47
 
48
+ // ################
35
49
  // Build heic-to.min.js
50
+ // ################
36
51
 
37
52
  await esbuild.build({
38
53
  entryPoints: [
39
- 'src/worker.js'
54
+ 'tmp/src/worker.js'
40
55
  ],
41
56
  bundle: true,
42
57
  minify: true,
@@ -61,4 +76,70 @@ esbuild.build({
61
76
  define: {
62
77
  WORKER_FILE_CONTENT: JSON.stringify(workerFileMinifyContent)
63
78
  }
64
- });
79
+ });
80
+
81
+ // ################
82
+ // Build csp/heic-to.js
83
+ // ################
84
+
85
+ await esbuild.build({
86
+ entryPoints: [
87
+ 'tmp/src/csp/worker.js'
88
+ ],
89
+ bundle: true,
90
+ minify: false,
91
+ target: 'es6',
92
+ platform: 'browser',
93
+ outfile: 'tmp/csp/worker.js',
94
+ external: ['fs', 'path'],
95
+ });
96
+
97
+ const cspWorkerFileContent = fs.readFileSync('tmp/csp/worker.js', 'utf8')
98
+
99
+ esbuild.build({
100
+ entryPoints: [
101
+ 'src/index.js'
102
+ ],
103
+ bundle: true,
104
+ minify: false,
105
+ target: 'es6',
106
+ platform: 'browser',
107
+ outfile: 'dist/csp/heic-to.js',
108
+ format: 'esm',
109
+ define: {
110
+ WORKER_FILE_CONTENT: JSON.stringify(cspWorkerFileContent)
111
+ }
112
+ });
113
+
114
+ // ################
115
+ // Build csp/heic-to.min.js
116
+ // ################
117
+
118
+ await esbuild.build({
119
+ entryPoints: [
120
+ 'tmp/src/csp/worker.js'
121
+ ],
122
+ bundle: true,
123
+ minify: true,
124
+ target: 'es6',
125
+ platform: 'browser',
126
+ outfile: 'tmp/csp/worker.min.js',
127
+ external: ['fs', 'path']
128
+ });
129
+
130
+ const cspWorkerFileMinifyContent = fs.readFileSync('tmp/csp/worker.min.js', 'utf8')
131
+
132
+ esbuild.build({
133
+ entryPoints: [
134
+ 'src/index.js'
135
+ ],
136
+ bundle: true,
137
+ minify: true,
138
+ target: 'es6',
139
+ platform: 'browser',
140
+ outfile: 'dist/csp/heic-to.min.js',
141
+ format: 'esm',
142
+ define: {
143
+ WORKER_FILE_CONTENT: JSON.stringify(cspWorkerFileMinifyContent)
144
+ }
145
+ });
package/example/app.js ADDED
@@ -0,0 +1,28 @@
1
+ import {heicTo, isHeic} from '../dist/heic-to.js'
2
+
3
+ const imagesContainer = document.querySelector(".images")
4
+ const messageLabel = document.querySelector("label")
5
+ const field = document.querySelector("input")
6
+
7
+ field.addEventListener('change', async (event) => {
8
+
9
+ let imageDom = document.querySelector("img")
10
+ if (!imageDom) {
11
+ imageDom = document.createElement('img')
12
+ imagesContainer.appendChild(imageDom)
13
+ }
14
+ imageDom.src = ''
15
+ imageDom.alt = "Loading..."
16
+ messageLabel.textContent = "Loading..."
17
+
18
+ const image = field.files[0]
19
+ if (await isHeic(image)) {
20
+ messageLabel.textContent = "It's a HEIC image"
21
+ const heifImage = await heicTo({blob: image, type: 'image/jpeg', quality: 0.5})
22
+ imageDom.src = URL.createObjectURL(heifImage)
23
+ } else {
24
+ messageLabel.textContent = "It's not a HEIC image"
25
+ imageDom.src = URL.createObjectURL(image)
26
+ }
27
+
28
+ })
@@ -0,0 +1,28 @@
1
+ import {heicTo, isHeic} from '../../dist/csp/heic-to.js'
2
+
3
+ const imagesContainer = document.querySelector(".images")
4
+ const messageLabel = document.querySelector("label")
5
+ const field = document.querySelector("input")
6
+
7
+ field.addEventListener('change', async (event) => {
8
+
9
+ let imageDom = document.querySelector("img")
10
+ if (!imageDom) {
11
+ imageDom = document.createElement('img')
12
+ imagesContainer.appendChild(imageDom)
13
+ }
14
+ imageDom.src = ''
15
+ imageDom.alt = "Loading..."
16
+ messageLabel.textContent = "Loading..."
17
+
18
+ const image = field.files[0]
19
+ if (await isHeic(image)) {
20
+ messageLabel.textContent = "It's a HEIC image"
21
+ const heifImage = await heicTo({blob: image, type: 'image/jpeg', quality: 0.5})
22
+ imageDom.src = URL.createObjectURL(heifImage)
23
+ } else {
24
+ messageLabel.textContent = "It's not a HEIC image"
25
+ imageDom.src = URL.createObjectURL(image)
26
+ }
27
+
28
+ })
@@ -0,0 +1,48 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>heic-to</title>
7
+ <style>
8
+ body {
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ flex-direction: column;
13
+ height: 100vh;
14
+ }
15
+ input {
16
+ border: 1px solid black;
17
+ padding: 10px;
18
+ }
19
+ label {
20
+ display: block;;
21
+ padding-top: 20px;
22
+ padding-bottom: 20px;
23
+ color: red;
24
+ }
25
+ .images {
26
+ width: 200px;
27
+ height: 200px;
28
+ }
29
+ img {
30
+ display: block;
31
+ width: 100%;
32
+ }
33
+ </style>
34
+ <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, post-check=0, pre-check=0">
35
+ <meta http-equiv="Content-Security-Policy" content="script-src 'self'; worker-src blob:;">
36
+ <script src="./app.js" type="module"></script>
37
+ </head>
38
+ <body>
39
+
40
+ <h1>heic-to</h1>
41
+
42
+ <main>
43
+ <input type="file">
44
+ <label></label>
45
+ <div class="images"></div>
46
+ </main>
47
+ </body>
48
+ </html>
@@ -31,6 +31,7 @@
31
31
  width: 100%;
32
32
  }
33
33
  </style>
34
+ <script src="./app.js" type="module"></script>
34
35
  </head>
35
36
  <body>
36
37
 
@@ -41,36 +42,5 @@
41
42
  <label></label>
42
43
  <div class="images"></div>
43
44
  </main>
44
-
45
- <script type="module">
46
- import {heicTo, isHeic} from '../dist/heic-to.js'
47
-
48
- const imagesContainer = document.querySelector(".images")
49
- const messageLabel = document.querySelector("label")
50
- const field = document.querySelector("input")
51
-
52
- field.addEventListener('change', async (event) => {
53
-
54
- let imageDom = document.querySelector("img")
55
- if (!imageDom) {
56
- imageDom = document.createElement('img')
57
- imagesContainer.appendChild(imageDom)
58
- }
59
- imageDom.src = ''
60
- imageDom.alt = "Loading..."
61
- messageLabel.textContent = "Loading..."
62
-
63
- const image = field.files[0]
64
- if (await isHeic(image)) {
65
- messageLabel.textContent = "It's a HEIC image"
66
- const heifImage = await heicTo({blob: image, type: 'image/jpeg', quality: 0.5})
67
- imageDom.src = URL.createObjectURL(heifImage)
68
- } else {
69
- messageLabel.textContent = "It's not a HEIC image"
70
- imageDom.src = URL.createObjectURL(image)
71
- }
72
-
73
- })
74
- </script>
75
45
  </body>
76
46
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heic-to",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Converting HEIF/HEIF image formats to PNG/JPEG in the browser",
5
5
  "main": "dist/heic-to.js",
6
6
  "scripts": {