rn-remove-image-bg 0.0.18 → 0.0.19

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.
@@ -14,15 +14,15 @@ const WORKER_CODE = `
14
14
 
15
15
  try {
16
16
  if (type === 'init') {
17
- if (!removeBackground) {
18
- // Dynamic import from CDN
19
- // Using v1.3.0 which is stable
20
- const module = await import('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.3.0/+esm');
21
- removeBackground = module.removeBackground;
17
+ if (typeof self.imglyBackgroundRemoval === 'undefined' || !removeBackground) {
18
+ // Use importScripts (Classic Worker) - most robust for Blob URLs
19
+ importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
20
+
21
+ if (!self.imglyBackgroundRemoval) {
22
+ throw new Error('imglyBackgroundRemoval not loaded via importScripts');
23
+ }
22
24
 
23
- // Preload/Init logic could go here if exposed, but imgly inits on first run usually
24
- // Unless we want to preload the wasm.
25
- // self.postMessage({ id, type: 'progress', payload: { progress: 0.1 } });
25
+ removeBackground = self.imglyBackgroundRemoval.removeBackground;
26
26
  }
27
27
  self.postMessage({ id, type: 'success', payload: true });
28
28
  return;
@@ -32,15 +32,16 @@ const WORKER_CODE = `
32
32
  const { uri, config } = payload;
33
33
 
34
34
  if (!removeBackground) {
35
- const module = await import('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.3.0/+esm');
36
- removeBackground = module.removeBackground;
35
+ importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
36
+ removeBackground = self.imglyBackgroundRemoval.removeBackground;
37
37
  }
38
38
 
39
39
  // Run Inference
40
- // imgly config: { progress: (key, current, total) => ... }
40
+ // CRITICAL: Must point publicPath to CDN so it finds WASM/Models
41
+ // otherwise it tries to load from blob: URL
41
42
  const blob = await removeBackground(uri, {
43
+ publicPath: 'https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/',
42
44
  progress: (key, current, total) => {
43
- // Map progress roughly
44
45
  const p = current / total;
45
46
  self.postMessage({ id, type: 'progress', payload: { progress: p } });
46
47
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-remove-image-bg",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "rn-remove-image-bg",
5
5
  "homepage": "https://github.com/a-eid/rn-remove-image-bg",
6
6
  "main": "lib/index",
@@ -24,15 +24,15 @@ const WORKER_CODE = `
24
24
 
25
25
  try {
26
26
  if (type === 'init') {
27
- if (!removeBackground) {
28
- // Dynamic import from CDN
29
- // Using v1.3.0 which is stable
30
- const module = await import('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.3.0/+esm');
31
- removeBackground = module.removeBackground;
27
+ if (typeof self.imglyBackgroundRemoval === 'undefined' || !removeBackground) {
28
+ // Use importScripts (Classic Worker) - most robust for Blob URLs
29
+ importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
30
+
31
+ if (!self.imglyBackgroundRemoval) {
32
+ throw new Error('imglyBackgroundRemoval not loaded via importScripts');
33
+ }
32
34
 
33
- // Preload/Init logic could go here if exposed, but imgly inits on first run usually
34
- // Unless we want to preload the wasm.
35
- // self.postMessage({ id, type: 'progress', payload: { progress: 0.1 } });
35
+ removeBackground = self.imglyBackgroundRemoval.removeBackground;
36
36
  }
37
37
  self.postMessage({ id, type: 'success', payload: true });
38
38
  return;
@@ -42,15 +42,16 @@ const WORKER_CODE = `
42
42
  const { uri, config } = payload;
43
43
 
44
44
  if (!removeBackground) {
45
- const module = await import('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.3.0/+esm');
46
- removeBackground = module.removeBackground;
45
+ importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
46
+ removeBackground = self.imglyBackgroundRemoval.removeBackground;
47
47
  }
48
48
 
49
49
  // Run Inference
50
- // imgly config: { progress: (key, current, total) => ... }
50
+ // CRITICAL: Must point publicPath to CDN so it finds WASM/Models
51
+ // otherwise it tries to load from blob: URL
51
52
  const blob = await removeBackground(uri, {
53
+ publicPath: 'https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/',
52
54
  progress: (key, current, total) => {
53
- // Map progress roughly
54
55
  const p = current / total;
55
56
  self.postMessage({ id, type: 'progress', payload: { progress: p } });
56
57
  },