megane-viewer 0.5.0 → 0.6.1
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 +23 -18
- package/dist/assets/decode.worker-COS7O5zc.js +1 -0
- package/dist/gif-BOhv0bDx.js +284 -0
- package/dist/lib-D3sqoP7c.js +19601 -0
- package/dist/lib.js +38 -0
- package/dist/megane-viewer.css +1 -0
- package/dist/megane_wasm-DYYN-xjH.js +464 -0
- package/dist/widget.js +9705 -9266
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -96,23 +96,21 @@ npm install megane-viewer
|
|
|
96
96
|
### Jupyter Notebook
|
|
97
97
|
|
|
98
98
|
```python
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
# Display in notebook
|
|
111
|
-
viewer = MolecularViewer()
|
|
112
|
-
viewer.set_pipeline(pipe)
|
|
113
|
-
viewer
|
|
99
|
+
import megane
|
|
100
|
+
|
|
101
|
+
viewer = megane.view("protein.pdb")
|
|
102
|
+
viewer # displays in notebook
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
With a trajectory:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
viewer = megane.view_traj("protein.pdb", xtc="trajectory.xtc")
|
|
109
|
+
viewer.frame_index = 50 # jump to frame 50
|
|
114
110
|
```
|
|
115
111
|
|
|
112
|
+
For advanced usage (filtering, multi-layer rendering, custom pipelines), see the [Pipeline API](https://hodakamori.github.io/megane/guide/pipeline#python-pipeline-api).
|
|
113
|
+
|
|
116
114
|
### CLI (Docker)
|
|
117
115
|
|
|
118
116
|
```bash
|
|
@@ -132,7 +130,7 @@ docker run --rm -p 8080:8080 -v ./mydata:/data megane \
|
|
|
132
130
|
### React
|
|
133
131
|
|
|
134
132
|
```tsx
|
|
135
|
-
import { MeganeViewer, parseStructureFile } from "megane-viewer";
|
|
133
|
+
import { MeganeViewer, parseStructureFile } from "megane-viewer/lib";
|
|
136
134
|
|
|
137
135
|
function App() {
|
|
138
136
|
const [snapshot, setSnapshot] = useState(null);
|
|
@@ -148,15 +146,22 @@ function App() {
|
|
|
148
146
|
|
|
149
147
|
## Supported File Formats
|
|
150
148
|
|
|
149
|
+
### Structure formats (`LoadStructure` node)
|
|
150
|
+
|
|
151
151
|
| Format | Extension | Description |
|
|
152
152
|
|--------|-----------|-------------|
|
|
153
153
|
| PDB | `.pdb` | Protein Data Bank |
|
|
154
154
|
| GRO | `.gro` | GROMACS structure file |
|
|
155
155
|
| XYZ | `.xyz` | Cartesian coordinate format |
|
|
156
156
|
| MOL/SDF | `.mol`, `.sdf` | MDL Molfile (V2000) |
|
|
157
|
-
| XTC | `.xtc` | GROMACS compressed trajectory |
|
|
158
|
-
| CIF | `.cif` | Crystallographic Information File |
|
|
159
157
|
| LAMMPS data | `.data`, `.lammps` | LAMMPS data file |
|
|
158
|
+
| CIF | `.cif` | Crystallographic Information File |
|
|
159
|
+
|
|
160
|
+
### Trajectory formats (`LoadTrajectory` node)
|
|
161
|
+
|
|
162
|
+
| Format | Extension | Description |
|
|
163
|
+
|--------|-----------|-------------|
|
|
164
|
+
| XTC | `.xtc` | GROMACS compressed trajectory |
|
|
160
165
|
| ASE .traj | `.traj` | ASE trajectory (ULM binary format) |
|
|
161
166
|
| LAMMPS dump | `.lammpstrj` | LAMMPS dump trajectory |
|
|
162
167
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";function d(r){const s=new DataView(r),e=s.getUint32(0,!0);if(e!==1313293645)throw new Error(`Invalid magic: 0x${e.toString(16)}, expected 0x4e47454d`);return{msgType:s.getUint8(4),flags:s.getUint8(5)}}function f(r){const s=new DataView(r),e=s.getUint8(5);let n=8;const t=s.getUint32(n,!0);n+=4;const o=s.getUint32(n,!0);n+=4;const A=new Float32Array(r,n,t*3);n+=t*3*4;const g=new Uint8Array(r,n,t);n+=t,n+=(4-n%4)%4;const m=new Uint32Array(r,n,o*2);n+=o*2*4;let a=null;e&1&&(a=new Uint8Array(r,n,o),n+=o,n+=(4-n%4)%4);let c=null;return e&2&&(c=new Float32Array(r,n,9),n+=36),{nAtoms:t,nBonds:o,nFileBonds:o,positions:A,elements:g,bonds:m,bondOrders:a,box:c}}function l(r){const s=new DataView(r);let e=8;const n=s.getUint32(e,!0);e+=4;const t=s.getUint32(e,!0);e+=4;const o=new Float32Array(r,e,t*3);return{frameId:n,nAtoms:t,positions:o}}const i=self;i.onmessage=r=>{const{id:s,buffer:e}=r.data;try{const{msgType:n}=d(e);if(n===0){const t=f(e),o=[t.positions.buffer,t.elements.buffer,t.bonds.buffer];t.bondOrders&&o.push(t.bondOrders.buffer),t.box&&o.push(t.box.buffer),i.postMessage({id:s,type:"snapshot",data:{nAtoms:t.nAtoms,nBonds:t.nBonds,nFileBonds:t.nFileBonds,positions:t.positions,elements:t.elements,bonds:t.bonds,bondOrders:t.bondOrders,box:t.box}},o)}else if(n===1){const t=l(e),o=[t.positions.buffer];i.postMessage({id:s,type:"frame",data:{frameId:t.frameId,nAtoms:t.nAtoms,positions:t.positions}},o)}}catch(n){i.postMessage({id:s,type:"error",error:n instanceof Error?n.message:String(n)})}}})();
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { g as A } from "./lib-D3sqoP7c.js";
|
|
2
|
+
function j(_, E) {
|
|
3
|
+
for (var m = 0; m < E.length; m++) {
|
|
4
|
+
const p = E[m];
|
|
5
|
+
if (typeof p != "string" && !Array.isArray(p)) {
|
|
6
|
+
for (const v in p)
|
|
7
|
+
if (v !== "default" && !(v in _)) {
|
|
8
|
+
const o = Object.getOwnPropertyDescriptor(p, v);
|
|
9
|
+
o && Object.defineProperty(_, v, o.get ? o : {
|
|
10
|
+
enumerable: !0,
|
|
11
|
+
get: () => p[v]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return Object.freeze(Object.defineProperty(_, Symbol.toStringTag, { value: "Module" }));
|
|
17
|
+
}
|
|
18
|
+
function L(_) {
|
|
19
|
+
throw new Error('Could not dynamically require "' + _ + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
20
|
+
}
|
|
21
|
+
var D = { exports: {} }, R;
|
|
22
|
+
function M() {
|
|
23
|
+
return R || (R = 1, (function(_, E) {
|
|
24
|
+
(function(m) {
|
|
25
|
+
_.exports = m();
|
|
26
|
+
})(function() {
|
|
27
|
+
return (function m(p, v, o) {
|
|
28
|
+
function l(u, t) {
|
|
29
|
+
if (!v[u]) {
|
|
30
|
+
if (!p[u]) {
|
|
31
|
+
var s = typeof L == "function" && L;
|
|
32
|
+
if (!t && s) return s(u, !0);
|
|
33
|
+
if (x) return x(u, !0);
|
|
34
|
+
var n = new Error("Cannot find module '" + u + "'");
|
|
35
|
+
throw n.code = "MODULE_NOT_FOUND", n;
|
|
36
|
+
}
|
|
37
|
+
var f = v[u] = { exports: {} };
|
|
38
|
+
p[u][0].call(f.exports, function(c) {
|
|
39
|
+
var a = p[u][1][c];
|
|
40
|
+
return l(a || c);
|
|
41
|
+
}, f, f.exports, m, p, v, o);
|
|
42
|
+
}
|
|
43
|
+
return v[u].exports;
|
|
44
|
+
}
|
|
45
|
+
for (var x = typeof L == "function" && L, g = 0; g < o.length; g++) l(o[g]);
|
|
46
|
+
return l;
|
|
47
|
+
})({ 1: [function(m, p, v) {
|
|
48
|
+
function o() {
|
|
49
|
+
this._events = this._events || {}, this._maxListeners = this._maxListeners || void 0;
|
|
50
|
+
}
|
|
51
|
+
p.exports = o, o.EventEmitter = o, o.prototype._events = void 0, o.prototype._maxListeners = void 0, o.defaultMaxListeners = 10, o.prototype.setMaxListeners = function(t) {
|
|
52
|
+
if (!x(t) || t < 0 || isNaN(t)) throw TypeError("n must be a positive number");
|
|
53
|
+
return this._maxListeners = t, this;
|
|
54
|
+
}, o.prototype.emit = function(t) {
|
|
55
|
+
var s, n, f, c, a, e;
|
|
56
|
+
if (this._events || (this._events = {}), t === "error" && (!this._events.error || g(this._events.error) && !this._events.error.length)) {
|
|
57
|
+
if (s = arguments[1], s instanceof Error)
|
|
58
|
+
throw s;
|
|
59
|
+
var r = new Error('Uncaught, unspecified "error" event. (' + s + ")");
|
|
60
|
+
throw r.context = s, r;
|
|
61
|
+
}
|
|
62
|
+
if (n = this._events[t], u(n)) return !1;
|
|
63
|
+
if (l(n))
|
|
64
|
+
switch (arguments.length) {
|
|
65
|
+
case 1:
|
|
66
|
+
n.call(this);
|
|
67
|
+
break;
|
|
68
|
+
case 2:
|
|
69
|
+
n.call(this, arguments[1]);
|
|
70
|
+
break;
|
|
71
|
+
case 3:
|
|
72
|
+
n.call(this, arguments[1], arguments[2]);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
c = Array.prototype.slice.call(arguments, 1), n.apply(this, c);
|
|
76
|
+
}
|
|
77
|
+
else if (g(n))
|
|
78
|
+
for (c = Array.prototype.slice.call(arguments, 1), e = n.slice(), f = e.length, a = 0; a < f; a++) e[a].apply(this, c);
|
|
79
|
+
return !0;
|
|
80
|
+
}, o.prototype.addListener = function(t, s) {
|
|
81
|
+
var n;
|
|
82
|
+
if (!l(s)) throw TypeError("listener must be a function");
|
|
83
|
+
return this._events || (this._events = {}), this._events.newListener && this.emit("newListener", t, l(s.listener) ? s.listener : s), this._events[t] ? g(this._events[t]) ? this._events[t].push(s) : this._events[t] = [this._events[t], s] : this._events[t] = s, g(this._events[t]) && !this._events[t].warned && (u(this._maxListeners) ? n = o.defaultMaxListeners : n = this._maxListeners, n && n > 0 && this._events[t].length > n && (this._events[t].warned = !0, console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.", this._events[t].length), typeof console.trace == "function" && console.trace())), this;
|
|
84
|
+
}, o.prototype.on = o.prototype.addListener, o.prototype.once = function(t, s) {
|
|
85
|
+
if (!l(s)) throw TypeError("listener must be a function");
|
|
86
|
+
var n = !1;
|
|
87
|
+
function f() {
|
|
88
|
+
this.removeListener(t, f), n || (n = !0, s.apply(this, arguments));
|
|
89
|
+
}
|
|
90
|
+
return f.listener = s, this.on(t, f), this;
|
|
91
|
+
}, o.prototype.removeListener = function(t, s) {
|
|
92
|
+
var n, f, c, a;
|
|
93
|
+
if (!l(s)) throw TypeError("listener must be a function");
|
|
94
|
+
if (!this._events || !this._events[t]) return this;
|
|
95
|
+
if (n = this._events[t], c = n.length, f = -1, n === s || l(n.listener) && n.listener === s)
|
|
96
|
+
delete this._events[t], this._events.removeListener && this.emit("removeListener", t, s);
|
|
97
|
+
else if (g(n)) {
|
|
98
|
+
for (a = c; a-- > 0; )
|
|
99
|
+
if (n[a] === s || n[a].listener && n[a].listener === s) {
|
|
100
|
+
f = a;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
if (f < 0) return this;
|
|
104
|
+
n.length === 1 ? (n.length = 0, delete this._events[t]) : n.splice(f, 1), this._events.removeListener && this.emit("removeListener", t, s);
|
|
105
|
+
}
|
|
106
|
+
return this;
|
|
107
|
+
}, o.prototype.removeAllListeners = function(t) {
|
|
108
|
+
var s, n;
|
|
109
|
+
if (!this._events) return this;
|
|
110
|
+
if (!this._events.removeListener)
|
|
111
|
+
return arguments.length === 0 ? this._events = {} : this._events[t] && delete this._events[t], this;
|
|
112
|
+
if (arguments.length === 0) {
|
|
113
|
+
for (s in this._events)
|
|
114
|
+
s !== "removeListener" && this.removeAllListeners(s);
|
|
115
|
+
return this.removeAllListeners("removeListener"), this._events = {}, this;
|
|
116
|
+
}
|
|
117
|
+
if (n = this._events[t], l(n))
|
|
118
|
+
this.removeListener(t, n);
|
|
119
|
+
else if (n)
|
|
120
|
+
for (; n.length; ) this.removeListener(t, n[n.length - 1]);
|
|
121
|
+
return delete this._events[t], this;
|
|
122
|
+
}, o.prototype.listeners = function(t) {
|
|
123
|
+
var s;
|
|
124
|
+
return !this._events || !this._events[t] ? s = [] : l(this._events[t]) ? s = [this._events[t]] : s = this._events[t].slice(), s;
|
|
125
|
+
}, o.prototype.listenerCount = function(t) {
|
|
126
|
+
if (this._events) {
|
|
127
|
+
var s = this._events[t];
|
|
128
|
+
if (l(s)) return 1;
|
|
129
|
+
if (s) return s.length;
|
|
130
|
+
}
|
|
131
|
+
return 0;
|
|
132
|
+
}, o.listenerCount = function(t, s) {
|
|
133
|
+
return t.listenerCount(s);
|
|
134
|
+
};
|
|
135
|
+
function l(t) {
|
|
136
|
+
return typeof t == "function";
|
|
137
|
+
}
|
|
138
|
+
function x(t) {
|
|
139
|
+
return typeof t == "number";
|
|
140
|
+
}
|
|
141
|
+
function g(t) {
|
|
142
|
+
return typeof t == "object" && t !== null;
|
|
143
|
+
}
|
|
144
|
+
function u(t) {
|
|
145
|
+
return t === void 0;
|
|
146
|
+
}
|
|
147
|
+
}, {}], 2: [function(m, p, v) {
|
|
148
|
+
var o, l, x, g, u;
|
|
149
|
+
u = navigator.userAgent.toLowerCase(), g = navigator.platform.toLowerCase(), o = u.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, "unknown", 0], x = o[1] === "ie" && document.documentMode, l = { name: o[1] === "version" ? o[3] : o[1], version: x || parseFloat(o[1] === "opera" && o[4] ? o[4] : o[2]), platform: { name: u.match(/ip(?:ad|od|hone)/) ? "ios" : (u.match(/(?:webos|android)/) || g.match(/mac|win|linux/) || ["other"])[0] } }, l[l.name] = !0, l[l.name + parseInt(l.version, 10)] = !0, l.platform[l.platform.name] = !0, p.exports = l;
|
|
150
|
+
}, {}], 3: [function(m, p, v) {
|
|
151
|
+
var o, l, x, g = function(n, f) {
|
|
152
|
+
for (var c in f)
|
|
153
|
+
u.call(f, c) && (n[c] = f[c]);
|
|
154
|
+
function a() {
|
|
155
|
+
this.constructor = n;
|
|
156
|
+
}
|
|
157
|
+
return a.prototype = f.prototype, n.prototype = new a(), n.__super__ = f.prototype, n;
|
|
158
|
+
}, u = {}.hasOwnProperty, t = [].indexOf || function(n) {
|
|
159
|
+
for (var f = 0, c = this.length; f < c; f++)
|
|
160
|
+
if (f in this && this[f] === n) return f;
|
|
161
|
+
return -1;
|
|
162
|
+
}, s = [].slice;
|
|
163
|
+
o = m("events").EventEmitter, x = m("./browser.coffee"), l = (function(n) {
|
|
164
|
+
var f, c;
|
|
165
|
+
g(a, n), f = { workerScript: "gif.worker.js", workers: 2, repeat: 0, background: "#fff", quality: 10, width: null, height: null, transparent: null, debug: !1, dither: !1 }, c = { delay: 500, copy: !1 };
|
|
166
|
+
function a(e) {
|
|
167
|
+
var r, i, h;
|
|
168
|
+
this.running = !1, this.options = {}, this.frames = [], this.freeWorkers = [], this.activeWorkers = [], this.setOptions(e);
|
|
169
|
+
for (i in f)
|
|
170
|
+
h = f[i], (r = this.options)[i] == null && (r[i] = h);
|
|
171
|
+
}
|
|
172
|
+
return a.prototype.setOption = function(e, r) {
|
|
173
|
+
if (this.options[e] = r, this._canvas != null && (e === "width" || e === "height"))
|
|
174
|
+
return this._canvas[e] = r;
|
|
175
|
+
}, a.prototype.setOptions = function(e) {
|
|
176
|
+
var r, i, h;
|
|
177
|
+
i = [];
|
|
178
|
+
for (r in e)
|
|
179
|
+
u.call(e, r) && (h = e[r], i.push(this.setOption(r, h)));
|
|
180
|
+
return i;
|
|
181
|
+
}, a.prototype.addFrame = function(e, r) {
|
|
182
|
+
var i, h;
|
|
183
|
+
r == null && (r = {}), i = {}, i.transparent = this.options.transparent;
|
|
184
|
+
for (h in c)
|
|
185
|
+
i[h] = r[h] || c[h];
|
|
186
|
+
if (this.options.width == null && this.setOption("width", e.width), this.options.height == null && this.setOption("height", e.height), typeof ImageData < "u" && ImageData !== null && e instanceof ImageData)
|
|
187
|
+
i.data = e.data;
|
|
188
|
+
else if (typeof CanvasRenderingContext2D < "u" && CanvasRenderingContext2D !== null && e instanceof CanvasRenderingContext2D || typeof WebGLRenderingContext < "u" && WebGLRenderingContext !== null && e instanceof WebGLRenderingContext)
|
|
189
|
+
r.copy ? i.data = this.getContextData(e) : i.context = e;
|
|
190
|
+
else if (e.childNodes != null)
|
|
191
|
+
r.copy ? i.data = this.getImageData(e) : i.image = e;
|
|
192
|
+
else
|
|
193
|
+
throw new Error("Invalid image");
|
|
194
|
+
return this.frames.push(i);
|
|
195
|
+
}, a.prototype.render = function() {
|
|
196
|
+
var e, r, i;
|
|
197
|
+
if (this.running)
|
|
198
|
+
throw new Error("Already running");
|
|
199
|
+
if (this.options.width == null || this.options.height == null)
|
|
200
|
+
throw new Error("Width and height must be set prior to rendering");
|
|
201
|
+
if (this.running = !0, this.nextFrame = 0, this.finishedFrames = 0, this.imageParts = (function() {
|
|
202
|
+
var h, w, d;
|
|
203
|
+
for (d = [], h = 0, w = this.frames.length; 0 <= w ? h < w : h > w; 0 <= w ? ++h : --h)
|
|
204
|
+
d.push(null);
|
|
205
|
+
return d;
|
|
206
|
+
}).call(this), r = this.spawnWorkers(), this.options.globalPalette === !0)
|
|
207
|
+
this.renderNextFrame();
|
|
208
|
+
else
|
|
209
|
+
for (e = 0, i = r; 0 <= i ? e < i : e > i; 0 <= i ? ++e : --e)
|
|
210
|
+
this.renderNextFrame();
|
|
211
|
+
return this.emit("start"), this.emit("progress", 0);
|
|
212
|
+
}, a.prototype.abort = function() {
|
|
213
|
+
for (var e; e = this.activeWorkers.shift(), e != null; )
|
|
214
|
+
this.log("killing active worker"), e.terminate();
|
|
215
|
+
return this.running = !1, this.emit("abort");
|
|
216
|
+
}, a.prototype.spawnWorkers = function() {
|
|
217
|
+
var e, r, i;
|
|
218
|
+
return e = Math.min(this.options.workers, this.frames.length), (function() {
|
|
219
|
+
i = [];
|
|
220
|
+
for (var h = r = this.freeWorkers.length; r <= e ? h < e : h > e; r <= e ? h++ : h--)
|
|
221
|
+
i.push(h);
|
|
222
|
+
return i;
|
|
223
|
+
}).apply(this).forEach(/* @__PURE__ */ (function(h) {
|
|
224
|
+
return function(w) {
|
|
225
|
+
var d;
|
|
226
|
+
return h.log("spawning worker " + w), d = new Worker(h.options.workerScript), d.onmessage = function(y) {
|
|
227
|
+
return h.activeWorkers.splice(h.activeWorkers.indexOf(d), 1), h.freeWorkers.push(d), h.frameFinished(y.data);
|
|
228
|
+
}, h.freeWorkers.push(d);
|
|
229
|
+
};
|
|
230
|
+
})(this)), e;
|
|
231
|
+
}, a.prototype.frameFinished = function(e) {
|
|
232
|
+
var r, i;
|
|
233
|
+
if (this.log("frame " + e.index + " finished - " + this.activeWorkers.length + " active"), this.finishedFrames++, this.emit("progress", this.finishedFrames / this.frames.length), this.imageParts[e.index] = e, this.options.globalPalette === !0 && (this.options.globalPalette = e.globalPalette, this.log("global palette analyzed"), this.frames.length > 2))
|
|
234
|
+
for (r = 1, i = this.freeWorkers.length; 1 <= i ? r < i : r > i; 1 <= i ? ++r : --r)
|
|
235
|
+
this.renderNextFrame();
|
|
236
|
+
return t.call(this.imageParts, null) >= 0 ? this.renderNextFrame() : this.finishRendering();
|
|
237
|
+
}, a.prototype.finishRendering = function() {
|
|
238
|
+
var e, r, i, h, w, d, y, b, O, P, I, k, N, C, W, F;
|
|
239
|
+
for (b = 0, C = this.imageParts, w = 0, O = C.length; w < O; w++)
|
|
240
|
+
r = C[w], b += (r.data.length - 1) * r.pageSize + r.cursor;
|
|
241
|
+
for (b += r.pageSize - r.cursor, this.log("rendering finished - filesize " + Math.round(b / 1e3) + "kb"), e = new Uint8Array(b), k = 0, W = this.imageParts, d = 0, P = W.length; d < P; d++)
|
|
242
|
+
for (r = W[d], F = r.data, i = y = 0, I = F.length; y < I; i = ++y)
|
|
243
|
+
N = F[i], e.set(N, k), i === r.data.length - 1 ? k += r.cursor : k += r.pageSize;
|
|
244
|
+
return h = new Blob([e], { type: "image/gif" }), this.emit("finished", h, e);
|
|
245
|
+
}, a.prototype.renderNextFrame = function() {
|
|
246
|
+
var e, r, i;
|
|
247
|
+
if (this.freeWorkers.length === 0)
|
|
248
|
+
throw new Error("No free workers");
|
|
249
|
+
if (!(this.nextFrame >= this.frames.length))
|
|
250
|
+
return e = this.frames[this.nextFrame++], i = this.freeWorkers.shift(), r = this.getTask(e), this.log("starting frame " + (r.index + 1) + " of " + this.frames.length), this.activeWorkers.push(i), i.postMessage(r);
|
|
251
|
+
}, a.prototype.getContextData = function(e) {
|
|
252
|
+
return e.getImageData(0, 0, this.options.width, this.options.height).data;
|
|
253
|
+
}, a.prototype.getImageData = function(e) {
|
|
254
|
+
var r;
|
|
255
|
+
return this._canvas == null && (this._canvas = document.createElement("canvas"), this._canvas.width = this.options.width, this._canvas.height = this.options.height), r = this._canvas.getContext("2d"), r.setFill = this.options.background, r.fillRect(0, 0, this.options.width, this.options.height), r.drawImage(e, 0, 0), this.getContextData(r);
|
|
256
|
+
}, a.prototype.getTask = function(e) {
|
|
257
|
+
var r, i;
|
|
258
|
+
if (r = this.frames.indexOf(e), i = { index: r, last: r === this.frames.length - 1, delay: e.delay, transparent: e.transparent, width: this.options.width, height: this.options.height, quality: this.options.quality, dither: this.options.dither, globalPalette: this.options.globalPalette, repeat: this.options.repeat, canTransfer: x.name === "chrome" }, e.data != null)
|
|
259
|
+
i.data = e.data;
|
|
260
|
+
else if (e.context != null)
|
|
261
|
+
i.data = this.getContextData(e.context);
|
|
262
|
+
else if (e.image != null)
|
|
263
|
+
i.data = this.getImageData(e.image);
|
|
264
|
+
else
|
|
265
|
+
throw new Error("Invalid frame");
|
|
266
|
+
return i;
|
|
267
|
+
}, a.prototype.log = function() {
|
|
268
|
+
var e;
|
|
269
|
+
if (e = 1 <= arguments.length ? s.call(arguments, 0) : [], !!this.options.debug)
|
|
270
|
+
return console.log.apply(console, e);
|
|
271
|
+
}, a;
|
|
272
|
+
})(o), p.exports = l;
|
|
273
|
+
}, { "./browser.coffee": 2, events: 1 }] }, {}, [3])(3);
|
|
274
|
+
});
|
|
275
|
+
})(D)), D.exports;
|
|
276
|
+
}
|
|
277
|
+
var q = M();
|
|
278
|
+
const T = /* @__PURE__ */ A(q), S = /* @__PURE__ */ j({
|
|
279
|
+
__proto__: null,
|
|
280
|
+
default: T
|
|
281
|
+
}, [q]);
|
|
282
|
+
export {
|
|
283
|
+
S as g
|
|
284
|
+
};
|