@linear_non/stellar-libs 1.0.12 → 1.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linear_non/stellar-libs",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Reusable JavaScript libraries for Non-Linear Studio projects.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -27,11 +27,13 @@ export default class SpritePlayer {
27
27
  alpha_path = null, // { mobile, desktop }
28
28
  fileAlpha = null,
29
29
  useAlpha = false,
30
+ useWorker = true,
30
31
  }) {
31
32
  const rect = bounds(container)
32
33
  this.progress = gsap.utils.clamp(0, 1, progress)
33
34
  this.persistent = persistent
34
35
  this.isAlpha = !!useAlpha
36
+ this.useWorker = useWorker
35
37
 
36
38
  this.dom = { container, reference: container, images: [], alphaImages: [] }
37
39
  this.canvas = {
@@ -90,7 +92,7 @@ export default class SpritePlayer {
90
92
  total,
91
93
  urls: Array.isArray(list) ? list : [],
92
94
  cache,
93
- useWorker: true,
95
+ useWorker: this.useWorker,
94
96
  })
95
97
  this._loaders.push(loader)
96
98
  return loader.load()
@@ -99,10 +101,20 @@ export default class SpritePlayer {
99
101
  const onProgress = e => emitter.emit("sprite:progress", { instance: this, ...e })
100
102
  emitter.on(ImageLoader.events.PROGRESS, onProgress)
101
103
 
104
+ const wantAlphaUrls = Array.isArray(alpha_urls) && alpha_urls.length > 0
105
+ const wantAlphaPath = !!(originAlpha && fileAlpha)
106
+
102
107
  const [images, alphaImages] = await Promise.all([
108
+ // base: urls[] wins; otherwise origin+file_name pattern
103
109
  make({ origin: originBase, fileName: file_name, list: urls }),
104
- originAlpha && (fileAlpha || (alpha_urls && alpha_urls.length))
105
- ? make({ origin: originAlpha, fileName: fileAlpha, list: alpha_urls })
110
+
111
+ // alpha: load if EITHER urls[] OR path+file is provided
112
+ wantAlphaUrls || wantAlphaPath
113
+ ? make({
114
+ origin: wantAlphaUrls ? null : originAlpha,
115
+ fileName: wantAlphaUrls ? null : fileAlpha,
116
+ list: wantAlphaUrls ? alpha_urls : null,
117
+ })
106
118
  : Promise.resolve([]),
107
119
  ])
108
120
 
@@ -142,6 +154,7 @@ export default class SpritePlayer {
142
154
  Object.assign(this.canvas, { width: rect.width, height: rect.height, rect, area, offset })
143
155
  }
144
156
 
157
+ // grayscale → alpha (returns a canvas)
145
158
  toAlphaFromLuma(img) {
146
159
  const w = img.naturalWidth || img.width
147
160
  const h = img.naturalHeight || img.height