@php-wasm/progress 1.0.29 → 1.1.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/LICENSE ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
package/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var b=(i,e,s)=>{if(!e.has(i))throw TypeError("Cannot "+s)};var n=(i,e,s)=>(b(i,e,"read from private field"),s?s.call(i):e.get(i)),d=(i,e,s)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,s)},_=(i,e,s,t)=>(b(i,e,"write to private field"),t?t.call(i,s):e.set(i,s),s);var P=(i,e,s,t)=>({set _(o){_(i,e,o,s)},get _(){return n(i,e,t)}}),v=(i,e,s)=>(b(i,e,"access private method"),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@php-wasm/node-polyfills");const I=require("@php-wasm/logger"),R=5*1024*1024;var h,l,m,O;class M extends EventTarget{constructor(){super(...arguments);d(this,m);d(this,h,{});d(this,l,{})}expectAssets(s){for(const[t,o]of Object.entries(s)){const r="http://example.com/",a=new URL(t,r).pathname.split("/").pop();a in n(this,h)||(n(this,h)[a]=o),a in n(this,l)||(n(this,l)[a]=0)}}async monitorFetch(s){const t=await s;return C(t,r=>{v(this,m,O).call(this,t.url,r.detail.loaded,r.detail.total)})}}h=new WeakMap,l=new WeakMap,m=new WeakSet,O=function(s,t,o){const r=new URL(s,"http://example.com").pathname.split("/").pop();o?r in n(this,h)||(n(this,h)[r]=o,n(this,l)[r]=t):o=n(this,h)[r],r in n(this,l)||I.logger.warn(`Registered a download #progress of an unregistered file "${r}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`),n(this,l)[r]=t,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:T(n(this,l)),total:T(n(this,h))}}))};function T(i){return Object.values(i).reduce((e,s)=>e+s,0)}function C(i,e){const s=i.headers.get("content-length")||"",t=parseInt(s,10)||R;function o(r,c){e(new CustomEvent("progress",{detail:{loaded:r,total:c}}))}return new Response(new ReadableStream({async start(r){if(!i.body){r.close();return}const c=i.body.getReader();let a=0;for(;;)try{const{done:p,value:E}=await c.read();if(E&&(a+=E.byteLength),p){o(a,a),r.close();break}else o(a,t),r.enqueue(E)}catch(p){I.logger.error({e:p}),r.error(p);break}}}),{status:i.status,statusText:i.statusText,headers:i.headers})}var g,f,u,y;class k extends EventTarget{constructor(){super(...arguments);d(this,u);d(this,g,void 0);d(this,f,void 0);_(this,g,{}),_(this,f,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(s,t=""){const o=++P(this,f)._;return n(this,g)[o]=0,r=>{const{loaded:c,total:a}=(r==null?void 0:r.detail)||{};n(this,g)[o]=c/a*s,v(this,u,y).call(this,this.totalProgress,"REAL_TIME",t)}}slowlyIncrementBy(s){const t=++P(this,f)._;n(this,g)[t]=s,v(this,u,y).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(n(this,g)).reduce((s,t)=>s+t,0)}}g=new WeakMap,f=new WeakMap,u=new WeakSet,y=function(s,t,o){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:s,mode:t,caption:o}}))};const L=1e-5;class w extends EventTarget{constructor({weight:e=1,caption:s="",fillTime:t=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=e,this._selfCaption=s,this._fillTime=t}stage(e,s=""){if(e||(e=this._selfWeight),this._selfWeight-e<-L)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const t=new w({caption:s,weight:e,fillTime:this._fillTime});return this._subTrackers.push(t),t.addEventListener("progress",()=>this.notifyProgress()),t.addEventListener("done",()=>{this.done&&this.notifyDone()}),t}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const s=100,t=this._fillTime/s;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},t)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+L>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),this._selfDone=!0,this._selfProgress=100,this._isFilling=!1,this._fillInterval=void 0,this.notifyProgress(),this.notifyDone()}get caption(){for(let e=this._subTrackers.length-1;e>=0;e--)if(!this._subTrackers[e].done){const s=this._subTrackers[e].caption;if(s)return s}return this._selfCaption}setCaption(e){this._selfCaption=e,this.notifyProgress()}get done(){return this.progress+L>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((s,t)=>s+t.progress*t.weight,this._selfProgress*this._selfWeight);return Math.round(e*1e4)/1e4}get weight(){return this._weight}get observer(){return this._progressObserver||(this._progressObserver=e=>{this.set(e)}),this._progressObserver}get loadingListener(){return this._loadingListener||(this._loadingListener=e=>{this.set(e.detail.loaded/e.detail.total*100)}),this._loadingListener}pipe(e){e.setProgress({progress:this.progress,caption:this.caption}),this.addEventListener("progress",s=>{e.setProgress({progress:s.detail.progress,caption:s.detail.caption})}),this.addEventListener("done",()=>{e.setLoaded()})}addEventListener(e,s){super.addEventListener(e,s)}removeEventListener(e,s){super.removeEventListener(e,s)}notifyProgress(){const e=this;this.dispatchEvent(new CustomEvent("progress",{detail:{get progress(){return e.progress},get caption(){return e.caption}}}))}notifyDone(){this.dispatchEvent(new CustomEvent("done"))}}exports.EmscriptenDownloadMonitor=M;exports.ProgressObserver=k;exports.ProgressTracker=w;exports.cloneResponseMonitorProgress=C;
1
+ "use strict";var w=r=>{throw TypeError(r)};var E=(r,e,s)=>e.has(r)||w("Cannot "+s);var o=(r,e,s)=>(E(r,e,"read from private field"),s?s.call(r):e.get(r)),c=(r,e,s)=>e.has(r)?w("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,s),p=(r,e,s,t)=>(E(r,e,"write to private field"),t?t.call(r,s):e.set(r,s),s),_=(r,e,s)=>(E(r,e,"access private method"),s);var P=(r,e,s,t)=>({set _(i){p(r,e,i,s)},get _(){return o(r,e,t)}});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@php-wasm/node-polyfills");const I=require("@php-wasm/logger"),R=5*1024*1024;var h,l,v,O;class k extends EventTarget{constructor(){super(...arguments);c(this,v);c(this,h,{});c(this,l,{})}expectAssets(s){for(const[t,i]of Object.entries(s)){const n="http://example.com/",a=new URL(t,n).pathname.split("/").pop();a in o(this,h)||(o(this,h)[a]=i),a in o(this,l)||(o(this,l)[a]=0)}}async monitorFetch(s){const t=await s;return C(t,n=>{_(this,v,O).call(this,t.url,n.detail.loaded,n.detail.total)})}}h=new WeakMap,l=new WeakMap,v=new WeakSet,O=function(s,t,i){const n=new URL(s,"http://example.com").pathname.split("/").pop();i?n in o(this,h)||(o(this,h)[n]=i,o(this,l)[n]=t):i=o(this,h)[n],n in o(this,l)||I.logger.warn(`Registered a download #progress of an unregistered file "${n}". This may cause a sudden **decrease** in the #progress percentage as the length number of bytes increases during the download.`),o(this,l)[n]=t,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:y(o(this,l)),total:y(o(this,h))}}))};function y(r){return Object.values(r).reduce((e,s)=>e+s,0)}function C(r,e){const s=r.headers.get("content-length")||"",t=parseInt(s,10)||R;return new Response(M(r.body,t,e),{status:r.status,statusText:r.statusText,headers:r.headers})}function M(r,e,s){function t(i,n){s(new CustomEvent("progress",{detail:{loaded:i,total:n}}))}return new ReadableStream({async start(i){if(!r){i.close();return}const n=r.getReader();let d=0;for(;;)try{const{done:a,value:m}=await n.read();if(m&&(d+=m.byteLength),a){t(d,d),i.close();break}else t(d,e),i.enqueue(m)}catch(a){I.logger.error({e:a}),i.error(a);break}}})}var g,f,u,b;class S extends EventTarget{constructor(){super(...arguments);c(this,u);c(this,g);c(this,f);p(this,g,{}),p(this,f,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(s,t=""){const i=++P(this,f)._;return o(this,g)[i]=0,n=>{const{loaded:d,total:a}=(n==null?void 0:n.detail)||{};o(this,g)[i]=d/a*s,_(this,u,b).call(this,this.totalProgress,"REAL_TIME",t)}}slowlyIncrementBy(s){const t=++P(this,f)._;o(this,g)[t]=s,_(this,u,b).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(o(this,g)).reduce((s,t)=>s+t,0)}}g=new WeakMap,f=new WeakMap,u=new WeakSet,b=function(s,t,i){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:s,mode:t,caption:i}}))};const T=1e-5;class L extends EventTarget{constructor({weight:e=1,caption:s="",fillTime:t=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=e,this._selfCaption=s,this._fillTime=t}stage(e,s=""){if(e||(e=this._selfWeight),this._selfWeight-e<-1e-5)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const t=new L({caption:s,weight:e,fillTime:this._fillTime});return this._subTrackers.push(t),t.addEventListener("progress",()=>this.notifyProgress()),t.addEventListener("done",()=>{this.done&&this.notifyDone()}),t}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const t=this._fillTime/100;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},t)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+T>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),this._selfDone=!0,this._selfProgress=100,this._isFilling=!1,this._fillInterval=void 0,this.notifyProgress(),this.notifyDone()}get caption(){for(let e=this._subTrackers.length-1;e>=0;e--)if(!this._subTrackers[e].done){const s=this._subTrackers[e].caption;if(s)return s}return this._selfCaption}setCaption(e){this._selfCaption=e,this.notifyProgress()}get done(){return this.progress+T>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((s,t)=>s+t.progress*t.weight,this._selfProgress*this._selfWeight);return Math.round(e*1e4)/1e4}get weight(){return this._weight}get observer(){return this._progressObserver||(this._progressObserver=e=>{this.set(e)}),this._progressObserver}get loadingListener(){return this._loadingListener||(this._loadingListener=e=>{this.set(e.detail.loaded/e.detail.total*100)}),this._loadingListener}pipe(e){e.setProgress({progress:this.progress,caption:this.caption}),this.addEventListener("progress",s=>{e.setProgress({progress:s.detail.progress,caption:s.detail.caption})}),this.addEventListener("done",()=>{e.setLoaded()})}addEventListener(e,s){super.addEventListener(e,s)}removeEventListener(e,s){super.removeEventListener(e,s)}notifyProgress(){const e=this;this.dispatchEvent(new CustomEvent("progress",{detail:{get progress(){return e.progress},get caption(){return e.caption}}}))}notifyDone(){this.dispatchEvent(new CustomEvent("done"))}}exports.EmscriptenDownloadMonitor=k;exports.ProgressObserver=S;exports.ProgressTracker=L;exports.cloneResponseMonitorProgress=C;exports.cloneStreamMonitorProgress=M;
2
2
  //# sourceMappingURL=index.cjs.map
package/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../../packages/php-wasm/progress/src/lib/emscripten-download-monitor.ts","../../../../packages/php-wasm/progress/src/lib/progress-observer.ts","../../../../packages/php-wasm/progress/src/lib/progress-tracker.ts"],"sourcesContent":["import { logger } from '@php-wasm/logger';\n/*\n * An approximate total file size to use when the actual\n * total number of bytes is missing.\n *\n * This may happen when the files are compressed before transmission\n * and no content-length header is being sent.\n *\n * The approximation isn't accurate, but it's better than nothing.\n * It's not about being exact but about giving the user a rough sense\n * of #progress.\n */\nconst FALLBACK_FILE_SIZE = 5 * 1024 * 1024;\n\n/**\n * Monitors the download #progress of Emscripten modules\n *\n * Usage:\n *\n * ```js\n * const downloadMonitor = new EmscriptenDownloadMonitor();\n * \t const php = await startPHP(\n * phpLoaderModule,\n * 'web',\n * downloadMonitor.phpArgs\n * );\n * downloadMonitor.addEventListener('#progress', (e) => {\n * console.log( e.detail.#progress);\n * })\n * ```\n */\nexport class EmscriptenDownloadMonitor extends EventTarget {\n\t#assetsSizes: Record<string, number> = {};\n\t#progress: Record<string, number> = {};\n\n\texpectAssets(assets: Record<string, number>) {\n\t\tfor (const [urlLike, size] of Object.entries(assets)) {\n\t\t\tconst dummyBaseUrl = 'http://example.com/';\n\t\t\tconst pathname = new URL(urlLike, dummyBaseUrl).pathname;\n\t\t\tconst filename = pathname.split('/').pop()!;\n\t\t\tif (!(filename in this.#assetsSizes)) {\n\t\t\t\tthis.#assetsSizes[filename] = size;\n\t\t\t}\n\t\t\tif (!(filename in this.#progress)) {\n\t\t\t\tthis.#progress[filename] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync monitorFetch(fetchPromise: Promise<Response>): Promise<Response> {\n\t\tconst response = await fetchPromise;\n\t\tconst onProgress = (event: CustomEvent<DownloadProgress>) => {\n\t\t\tthis.#notify(response.url, event.detail.loaded, event.detail.total);\n\t\t};\n\t\treturn cloneResponseMonitorProgress(response, onProgress);\n\t}\n\n\t/**\n\t * Notifies about the download #progress of a file.\n\t *\n\t * @param file The file name.\n\t * @param loaded The number of bytes of that file loaded so far.\n\t * @param fileSize The total number of bytes in the loaded file.\n\t */\n\t#notify(file: string, loaded: number, fileSize: number) {\n\t\tconst fileName = new URL(file, 'http://example.com').pathname\n\t\t\t.split('/')\n\t\t\t.pop()!;\n\t\tif (!fileSize) {\n\t\t\tfileSize = this.#assetsSizes[fileName];\n\t\t} else if (!(fileName in this.#assetsSizes)) {\n\t\t\tthis.#assetsSizes[fileName] = fileSize;\n\t\t\tthis.#progress[fileName] = loaded;\n\t\t}\n\t\tif (!(fileName in this.#progress)) {\n\t\t\tlogger.warn(\n\t\t\t\t`Registered a download #progress of an unregistered file \"${fileName}\". ` +\n\t\t\t\t\t`This may cause a sudden **decrease** in the #progress percentage as the ` +\n\t\t\t\t\t`total number of bytes increases during the download.`\n\t\t\t);\n\t\t}\n\n\t\tthis.#progress[fileName] = loaded;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded: sumValues(this.#progress),\n\t\t\t\t\ttotal: sumValues(this.#assetsSizes),\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n\nfunction sumValues(obj: Record<string, number>) {\n\treturn Object.values(obj).reduce((total, value) => total + value, 0);\n}\n\nexport default EmscriptenDownloadMonitor;\n\nexport interface DownloadProgress {\n\t/**\n\t * The number of bytes loaded so far.\n\t */\n\tloaded: number;\n\t/**\n\t * The total number of bytes to load.\n\t */\n\ttotal: number;\n}\n\n/**\n * Clones a fetch Response object and returns a version\n * that calls the `onProgress` callback as the #progress\n * changes.\n *\n * @param response The fetch Response object to clone.\n * @param onProgress The callback to call when the download #progress changes.\n * @returns The cloned response\n */\nexport function cloneResponseMonitorProgress(\n\tresponse: Response,\n\tonProgress: (event: CustomEvent<DownloadProgress>) => void\n): Response {\n\tconst contentLength = response.headers.get('content-length') || '';\n\tconst total = parseInt(contentLength, 10) || FALLBACK_FILE_SIZE;\n\n\tfunction notify(loaded: number, total: number) {\n\t\tonProgress(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded,\n\t\t\t\t\ttotal,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\treturn new Response(\n\t\tnew ReadableStream({\n\t\t\tasync start(controller) {\n\t\t\t\tif (!response.body) {\n\t\t\t\t\tcontroller.close();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst reader = response.body.getReader();\n\t\t\t\tlet loaded = 0;\n\t\t\t\tfor (;;) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\t\tif (value) {\n\t\t\t\t\t\t\tloaded += value.byteLength;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (done) {\n\t\t\t\t\t\t\tnotify(loaded, loaded);\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnotify(loaded, total);\n\t\t\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tlogger.error({ e });\n\t\t\t\t\t\tcontroller.error(e);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t}),\n\t\t{\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\theaders: response.headers,\n\t\t}\n\t);\n}\n\nexport type DownloadProgressCallback = (progress: DownloadProgress) => void;\n","import { DownloadProgress } from './emscripten-download-monitor';\n\nexport type ProgressMode =\n\t/**\n\t * Real-time progress is used when we get real-time reports\n\t * about the progress.\n\t */\n\t| 'REAL_TIME'\n\n\t/**\n\t * Slowly increment progress is used when we don't know how long\n\t * an operation will take and just want to keep slowly incrementing\n\t * the progress bar.\n\t */\n\t| 'SLOWLY_INCREMENT';\n\nexport type ProgressObserverEvent = {\n\tprogress: number;\n\tmode: ProgressMode;\n\tcaption: string;\n};\n\nexport class ProgressObserver extends EventTarget {\n\t#observedProgresses: Record<number, number> = {};\n\t#lastObserverId = 0;\n\n\tprogress = 0;\n\tmode: ProgressMode = 'REAL_TIME';\n\tcaption = '';\n\n\tpartialObserver(progressBudget: number, caption = '') {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = 0;\n\t\treturn (progress: CustomEvent<DownloadProgress>) => {\n\t\t\tconst { loaded, total } = progress?.detail || {};\n\t\t\tthis.#observedProgresses[id] = (loaded / total) * progressBudget;\n\t\t\tthis.#onProgress(this.totalProgress, 'REAL_TIME', caption);\n\t\t};\n\t}\n\n\tslowlyIncrementBy(progress: number) {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = progress;\n\t\tthis.#onProgress(this.totalProgress, 'SLOWLY_INCREMENT');\n\t}\n\n\tget totalProgress() {\n\t\treturn Object.values(this.#observedProgresses).reduce(\n\t\t\t(total, progress) => total + progress,\n\t\t\t0\n\t\t);\n\t}\n\n\t#onProgress(progress: number, mode: ProgressMode, caption?: string) {\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tprogress,\n\t\t\t\t\tmode,\n\t\t\t\t\tcaption,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n","/**\n * Options for customizing the progress tracker.\n */\nexport interface ProgressTrackerOptions {\n\t/** The weight of the progress, a number between 0 and 1. */\n\tweight?: number;\n\t/** The caption to display during progress, a string. */\n\tcaption?: string;\n\t/** The time in milliseconds to fill the progress, a number. */\n\tfillTime?: number;\n}\n\n/**\n * Custom event providing information about a loading process.\n */\nexport type LoadingEvent = CustomEvent<{\n\t/** The number representing how much was loaded. */\n\tloaded: number;\n\t/** The number representing how much needs to loaded in total. */\n\ttotal: number;\n}>;\n\n/**\n * Custom event providing progress details.\n */\nexport type ProgressTrackerEvent = CustomEvent<ProgressDetails>;\n\n/**\n * Custom event providing progress details when the task is done.\n */\nexport type DoneEvent = CustomEvent<ProgressDetails>;\n\nexport interface ProgressDetails {\n\t/** The progress percentage as a number between 0 and 100. */\n\tprogress: number;\n\t/** The caption to display during progress, a string. */\n\tcaption: string;\n}\n\n/**\n * ProgressObserver A function that receives progress updates.\n *\n * @param progress The progress percentage as a number between 0 and 100.\n */\ntype ProgressObserver = (progress: number) => void;\n\n/**\n * Listener A function for handling specific event types.\n *\n * @param event The event of type T.\n */\nexport type Listener<T> = (event: T) => void;\n\nexport type TSCompatibleListener<T> =\n\t| EventListenerOrEventListenerObject\n\t| null\n\t| Listener<T>;\n\nexport interface ProgressReceiver {\n\tsetProgress(details: ProgressDetails): any;\n\tsetLoaded(): any;\n}\n\n/*\n * Like Number.EPSILON, but better tuned to tracking progress.\n *\n * With Number.EPSILON, progress like 99.99999999999997 is still\n * considered to be below 100 – this is highly undeisrable.\n */\nconst PROGRESS_EPSILON = 0.00001;\n\n/**\n * The ProgressTracker class is a tool for tracking progress in an operation\n * that is divided into multiple stages. It allows you to create sub-trackers\n * for each stage, with individual weights and captions. The main tracker\n * automatically calculates the progress based on the weighted sum of each\n * sub-tracker's progress. This makes it easy to keep track of a complex,\n * multi-stage process and report progress in a user-friendly way.\n *\n * After creating the sub-trackers, you can call the set() method to update the\n * progress of the current stage. You can also call the finish() method to mark\n * the current stage as complete and move on to the next one. Alternatively,\n * you can call the fillSlowly() method to simulate progress filling up slowly\n * to 100% before calling finish().\n *\n * @example\n * ```ts\n * const tracker = new ProgressTracker();\n * tracker.addEventListener('progress', (e) => {\n * \t\tconsole.log(\n * \t\t\t\te.detail.progress,\n * \t\t\t\te.detail.caption\n * \t\t);\n * });\n *\n * const stage1 = tracker.stage(0.5, 'Calculating pi digits');\n * const stage2 = tracker.stage(0.5, 'Downloading data');\n *\n * stage1.fillSlowly();\n * await calc100DigitsOfPi();\n * stage1.finish();\n *\n * await fetchWithProgress(function onProgress(loaded, total) {\n * \t\tstage2.set( loaded / total * 100);\n * });\n * stage2.finish();\n */\nexport class ProgressTracker extends EventTarget {\n\tprivate _selfWeight = 1;\n\tprivate _selfDone = false;\n\tprivate _selfProgress = 0;\n\tprivate _selfCaption = '';\n\tprivate _weight: number;\n\tprivate _progressObserver?: ProgressObserver;\n\tprivate _loadingListener?: Listener<LoadingEvent>;\n\tprivate _isFilling = false;\n\tprivate _fillTime: number;\n\tprivate _fillInterval?: any;\n\tprivate _subTrackers: ProgressTracker[] = [];\n\n\tconstructor({\n\t\tweight = 1,\n\t\tcaption = '',\n\t\tfillTime = 4,\n\t}: ProgressTrackerOptions = {}) {\n\t\tsuper();\n\t\tthis._weight = weight;\n\t\tthis._selfCaption = caption;\n\t\tthis._fillTime = fillTime;\n\t}\n\n\t/**\n\t * Creates a new sub-tracker with a specific weight.\n\t *\n\t * The weight determines what percentage of the overall progress\n\t * the sub-tracker represents. For example, if the main tracker is\n\t * monitoring a process that has two stages, and the first stage\n\t * is expected to take twice as long as the second stage, you could\n\t * create the first sub-tracker with a weight of 0.67 and the second\n\t * sub-tracker with a weight of 0.33.\n\t *\n\t * The caption is an optional string that describes the current stage\n\t * of the operation. If provided, it will be used as the progress caption\n\t * for the sub-tracker. If not provided, the main tracker will look for\n\t * the next sub-tracker with a non-empty caption and use that as the progress\n\t * caption instead.\n\t *\n\t * Returns the newly-created sub-tracker.\n\t *\n\t * @throws {Error} If the weight of the new stage would cause the total weight of all stages to exceed 1.\n\t *\n\t * @param weight The weight of the new stage, as a decimal value between 0 and 1.\n\t * @param caption The caption for the new stage, which will be used as the progress caption for the sub-tracker.\n\t *\n\t * @example\n\t * ```ts\n\t * const tracker = new ProgressTracker();\n\t * const subTracker1 = tracker.stage(0.67, 'Slow stage');\n\t * const subTracker2 = tracker.stage(0.33, 'Fast stage');\n\t *\n\t * subTracker2.set(50);\n\t * subTracker1.set(75);\n\t * subTracker2.set(100);\n\t * subTracker1.set(100);\n\t * ```\n\t */\n\tstage(weight?: number, caption = ''): ProgressTracker {\n\t\tif (!weight) {\n\t\t\tweight = this._selfWeight;\n\t\t}\n\t\tif (this._selfWeight - weight < -PROGRESS_EPSILON) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot add a stage with weight ${weight} as the total weight of registered stages would exceed 1.`\n\t\t\t);\n\t\t}\n\t\tthis._selfWeight -= weight;\n\n\t\tconst subTracker = new ProgressTracker({\n\t\t\tcaption,\n\t\t\tweight,\n\t\t\tfillTime: this._fillTime,\n\t\t});\n\t\tthis._subTrackers.push(subTracker);\n\t\tsubTracker.addEventListener('progress', () => this.notifyProgress());\n\t\tsubTracker.addEventListener('done', () => {\n\t\t\tif (this.done) {\n\t\t\t\tthis.notifyDone();\n\t\t\t}\n\t\t});\n\t\treturn subTracker;\n\t}\n\n\t/**\n\t * Fills the progress bar slowly over time, simulating progress.\n\t *\n\t * The progress bar is filled in a 100 steps, and each step, the progress\n\t * is increased by 1. If `stopBeforeFinishing` is true, the progress bar\n\t * will stop filling when it reaches 99% so that you can call `finish()`\n\t * explicitly.\n\t *\n\t * If the progress bar is filling or already filled, this method does nothing.\n\t *\n\t * @example\n\t * ```ts\n\t * const progress = new ProgressTracker({ caption: 'Processing...' });\n\t * progress.fillSlowly();\n\t * ```\n\t *\n\t * @param options Optional options.\n\t */\n\tfillSlowly({ stopBeforeFinishing = true } = {}): void {\n\t\tif (this._isFilling) {\n\t\t\treturn;\n\t\t}\n\t\tthis._isFilling = true;\n\t\tconst steps = 100;\n\t\tconst interval = this._fillTime / steps;\n\t\tthis._fillInterval = setInterval(() => {\n\t\t\tthis.set(this._selfProgress + 1);\n\t\t\tif (stopBeforeFinishing && this._selfProgress >= 99) {\n\t\t\t\tclearInterval(this._fillInterval);\n\t\t\t}\n\t\t}, interval);\n\t}\n\n\tset(value: number): void {\n\t\tthis._selfProgress = Math.min(value, 100);\n\t\tthis.notifyProgress();\n\t\tif (this._selfProgress + PROGRESS_EPSILON >= 100) {\n\t\t\tthis.finish();\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this._fillInterval) {\n\t\t\tclearInterval(this._fillInterval);\n\t\t}\n\t\tthis._selfDone = true;\n\t\tthis._selfProgress = 100;\n\t\tthis._isFilling = false;\n\t\tthis._fillInterval = undefined;\n\t\tthis.notifyProgress();\n\t\tthis.notifyDone();\n\t}\n\n\tget caption(): string {\n\t\tfor (let i = this._subTrackers.length - 1; i >= 0; i--) {\n\t\t\tif (!this._subTrackers[i].done) {\n\t\t\t\tconst captionMaybe = this._subTrackers[i].caption;\n\t\t\t\tif (captionMaybe) {\n\t\t\t\t\treturn captionMaybe;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this._selfCaption;\n\t}\n\n\tsetCaption(caption: string) {\n\t\tthis._selfCaption = caption;\n\t\tthis.notifyProgress();\n\t}\n\n\tget done(): boolean {\n\t\treturn this.progress + PROGRESS_EPSILON >= 100;\n\t}\n\n\tget progress(): number {\n\t\tif (this._selfDone) {\n\t\t\treturn 100;\n\t\t}\n\t\tconst sum = this._subTrackers.reduce(\n\t\t\t(sum, tracker) => sum + tracker.progress * tracker.weight,\n\t\t\tthis._selfProgress * this._selfWeight\n\t\t);\n\t\treturn Math.round(sum * 10000) / 10000;\n\t}\n\n\tget weight(): number {\n\t\treturn this._weight;\n\t}\n\n\tget observer() {\n\t\tif (!this._progressObserver) {\n\t\t\tthis._progressObserver = (progress: number) => {\n\t\t\t\tthis.set(progress);\n\t\t\t};\n\t\t}\n\t\treturn this._progressObserver;\n\t}\n\n\tget loadingListener() {\n\t\tif (!this._loadingListener) {\n\t\t\tthis._loadingListener = (event: LoadingEvent) => {\n\t\t\t\tthis.set((event.detail.loaded / event.detail.total) * 100);\n\t\t\t};\n\t\t}\n\t\treturn this._loadingListener;\n\t}\n\n\tpipe(receiver: ProgressReceiver) {\n\t\treceiver.setProgress({\n\t\t\tprogress: this.progress,\n\t\t\tcaption: this.caption,\n\t\t});\n\t\tthis.addEventListener('progress', (event: ProgressTrackerEvent) => {\n\t\t\treceiver.setProgress({\n\t\t\t\tprogress: event.detail.progress,\n\t\t\t\tcaption: event.detail.caption,\n\t\t\t});\n\t\t});\n\t\tthis.addEventListener('done', () => {\n\t\t\treceiver.setLoaded();\n\t\t});\n\t}\n\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.addEventListener(type, listener as any);\n\t}\n\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.removeEventListener(type, listener as any);\n\t}\n\n\tprivate notifyProgress() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tget progress() {\n\t\t\t\t\t\treturn self.progress;\n\t\t\t\t\t},\n\t\t\t\t\tget caption() {\n\t\t\t\t\t\treturn self.caption;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\tprivate notifyDone() {\n\t\tthis.dispatchEvent(new CustomEvent('done'));\n\t}\n}\n"],"names":["FALLBACK_FILE_SIZE","EmscriptenDownloadMonitor","__privateAdd","_notify","_assetsSizes","_progress","assets","urlLike","size","dummyBaseUrl","filename","__privateGet","fetchPromise","response","cloneResponseMonitorProgress","event","__privateMethod","notify_fn","file","loaded","fileSize","fileName","logger","sumValues","obj","total","value","onProgress","contentLength","notify","controller","reader","done","e","ProgressObserver","_onProgress","_observedProgresses","_lastObserverId","__privateSet","progressBudget","caption","id","__privateWrapper","progress","onProgress_fn","mode","PROGRESS_EPSILON","ProgressTracker","weight","fillTime","subTracker","stopBeforeFinishing","steps","interval","i","captionMaybe","sum","tracker","receiver","type","listener","self"],"mappings":"4lBAYMA,EAAqB,EAAI,KAAO,iBAmB/B,MAAMC,UAAkC,WAAY,CAApD,kCAiCNC,EAAA,KAAAC,GAhCAD,EAAA,KAAAE,EAAuC,CAAA,GACvCF,EAAA,KAAAG,EAAoC,CAAA,GAEpC,aAAaC,EAAgC,CAC5C,SAAW,CAACC,EAASC,CAAI,IAAK,OAAO,QAAQF,CAAM,EAAG,CACrD,MAAMG,EAAe,sBAEfC,EADW,IAAI,IAAIH,EAASE,CAAY,EAAE,SACtB,MAAM,GAAG,EAAE,IAAI,EACnCC,KAAYC,EAAA,KAAKP,KACjBO,EAAA,KAAAP,GAAaM,CAAQ,EAAIF,GAEzBE,KAAYC,EAAA,KAAKN,KACjBM,EAAA,KAAAN,GAAUK,CAAQ,EAAI,EAE7B,CACD,CAEA,MAAM,aAAaE,EAAoD,CACtE,MAAMC,EAAW,MAAMD,EAIhB,OAAAE,EAA6BD,EAHhBE,GAAyC,CACvDC,EAAA,KAAAb,EAAAc,GAAA,UAAQJ,EAAS,IAAKE,EAAM,OAAO,OAAQA,EAAM,OAAO,MAAK,CAEX,CACzD,CAqCD,CA5DCX,EAAA,YACAC,EAAA,YA+BAF,EAAA,YAAAc,EAAA,SAAQC,EAAcC,EAAgBC,EAAkB,CACjD,MAAAC,EAAW,IAAI,IAAIH,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AAK,OAAA,CACd,EACI,KAAA,iBAAiB,WAAa3C,GAAgC,CAClE2C,EAAS,YAAY,CACpB,SAAU3C,EAAM,OAAO,SACvB,QAASA,EAAM,OAAO,OAAA,CACtB,CAAA,CACD,EACI,KAAA,iBAAiB,OAAQ,IAAM,CACnC2C,EAAS,UAAU,CAAA,CACnB,CACF,CAES,iBACRC,EACAC,EACC,CACK,MAAA,iBAAiBD,EAAMC,CAAe,CAC7C,CAES,oBACRD,EACAC,EACC,CACK,MAAA,oBAAoBD,EAAMC,CAAe,CAChD,CAEQ,gBAAiB,CAExB,MAAMC,EAAO,KACR,KAAA,cACJ,IAAI,YAAY,WAAY,CAC3B,OAAQ,CACP,IAAI,UAAW,CACd,OAAOA,EAAK,QACb,EACA,IAAI,SAAU,CACb,OAAOA,EAAK,OACb,CACD,CAAA,CACA,CAAA,CAEH,CAEQ,YAAa,CACpB,KAAK,cAAc,IAAI,YAAY,MAAM,CAAC,CAC3C,CACD"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../../packages/php-wasm/progress/src/lib/emscripten-download-monitor.ts","../../../../packages/php-wasm/progress/src/lib/progress-observer.ts","../../../../packages/php-wasm/progress/src/lib/progress-tracker.ts"],"sourcesContent":["import { logger } from '@php-wasm/logger';\n/*\n * An approximate file length to use when the actual\n * length number of bytes is missing.\n *\n * This may happen when the files are compressed before transmission\n * and no content-length header is being sent.\n *\n * The approximation isn't accurate, but it's better than nothing.\n * It's not about being exact but about giving the user a rough sense\n * of #progress.\n */\nconst FALLBACK_FILE_SIZE = 5 * 1024 * 1024;\n\n/**\n * Monitors the download #progress of Emscripten modules\n *\n * Usage:\n *\n * ```js\n * const downloadMonitor = new EmscriptenDownloadMonitor();\n * \t const php = await startPHP(\n * phpLoaderModule,\n * 'web',\n * downloadMonitor.phpArgs\n * );\n * downloadMonitor.addEventListener('#progress', (e) => {\n * console.log( e.detail.#progress);\n * })\n * ```\n */\nexport class EmscriptenDownloadMonitor extends EventTarget {\n\t#assetsSizes: Record<string, number> = {};\n\t#progress: Record<string, number> = {};\n\n\texpectAssets(assets: Record<string, number>) {\n\t\tfor (const [urlLike, size] of Object.entries(assets)) {\n\t\t\tconst dummyBaseUrl = 'http://example.com/';\n\t\t\tconst pathname = new URL(urlLike, dummyBaseUrl).pathname;\n\t\t\tconst filename = pathname.split('/').pop()!;\n\t\t\tif (!(filename in this.#assetsSizes)) {\n\t\t\t\tthis.#assetsSizes[filename] = size;\n\t\t\t}\n\t\t\tif (!(filename in this.#progress)) {\n\t\t\t\tthis.#progress[filename] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync monitorFetch(fetchPromise: Promise<Response>): Promise<Response> {\n\t\tconst response = await fetchPromise;\n\t\tconst onProgress = (event: CustomEvent<DownloadProgress>) => {\n\t\t\tthis.#notify(response.url, event.detail.loaded, event.detail.total);\n\t\t};\n\t\treturn cloneResponseMonitorProgress(response, onProgress);\n\t}\n\n\t/**\n\t * Notifies about the download #progress of a file.\n\t *\n\t * @param file The file name.\n\t * @param loaded The number of bytes of that file loaded so far.\n\t * @param fileSize The length number of bytes in the loaded file.\n\t */\n\t#notify(file: string, loaded: number, fileSize: number) {\n\t\tconst fileName = new URL(file, 'http://example.com').pathname\n\t\t\t.split('/')\n\t\t\t.pop()!;\n\t\tif (!fileSize) {\n\t\t\tfileSize = this.#assetsSizes[fileName];\n\t\t} else if (!(fileName in this.#assetsSizes)) {\n\t\t\tthis.#assetsSizes[fileName] = fileSize;\n\t\t\tthis.#progress[fileName] = loaded;\n\t\t}\n\t\tif (!(fileName in this.#progress)) {\n\t\t\tlogger.warn(\n\t\t\t\t`Registered a download #progress of an unregistered file \"${fileName}\". ` +\n\t\t\t\t\t`This may cause a sudden **decrease** in the #progress percentage as the ` +\n\t\t\t\t\t`length number of bytes increases during the download.`\n\t\t\t);\n\t\t}\n\n\t\tthis.#progress[fileName] = loaded;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded: sumValues(this.#progress),\n\t\t\t\t\ttotal: sumValues(this.#assetsSizes),\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n\nfunction sumValues(obj: Record<string, number>) {\n\treturn Object.values(obj).reduce((length, value) => length + value, 0);\n}\n\nexport default EmscriptenDownloadMonitor;\n\nexport interface DownloadProgress {\n\t/**\n\t * The number of bytes loaded so far.\n\t */\n\tloaded: number;\n\t/**\n\t * The length number of bytes to load.\n\t */\n\ttotal: number;\n}\n\n/**\n * Clones a fetch Response object and returns a version\n * that calls the `onProgress` callback as the #progress\n * changes.\n *\n * @param response The fetch Response object to clone.\n * @param onProgress The callback to call when the download #progress changes.\n * @returns The cloned response\n */\nexport function cloneResponseMonitorProgress(\n\tresponse: Response,\n\tonProgress: (event: CustomEvent<DownloadProgress>) => void\n): Response {\n\tconst contentLength = response.headers.get('content-length') || '';\n\tconst length = parseInt(contentLength, 10) || FALLBACK_FILE_SIZE;\n\n\treturn new Response(\n\t\tcloneStreamMonitorProgress(response.body, length, onProgress),\n\t\t{\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\theaders: response.headers,\n\t\t}\n\t);\n}\n\n/**\n * Clones a ReadableStream and returns a version\n * that calls the `onProgress` callback as the #progress\n * changes.\n *\n * @param stream The ReadableStream to clone.\n * @param total The total number of bytes to load.\n * @param onProgress The callback to call when the download #progress changes.\n * @returns The cloned ReadableStream\n */\nexport function cloneStreamMonitorProgress(\n\tstream: ReadableStream<Uint8Array> | null,\n\ttotal: number,\n\tonProgress: (event: CustomEvent<DownloadProgress>) => void\n): ReadableStream<Uint8Array> {\n\tfunction notify(loaded: number, total: number) {\n\t\tonProgress(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded,\n\t\t\t\t\ttotal,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\treturn new ReadableStream({\n\t\tasync start(controller) {\n\t\t\tif (!stream) {\n\t\t\t\tcontroller.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst reader = stream.getReader();\n\t\t\tlet loaded = 0;\n\t\t\twhile (true) {\n\t\t\t\ttry {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tloaded += value.byteLength;\n\t\t\t\t\t}\n\t\t\t\t\tif (done) {\n\t\t\t\t\t\tnotify(loaded, loaded);\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnotify(loaded, total);\n\t\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tlogger.error({ e });\n\t\t\t\t\tcontroller.error(e);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n}\n\nexport type DownloadProgressCallback = (progress: DownloadProgress) => void;\n","import type { DownloadProgress } from './emscripten-download-monitor';\n\nexport type ProgressMode =\n\t/**\n\t * Real-time progress is used when we get real-time reports\n\t * about the progress.\n\t */\n\t| 'REAL_TIME'\n\n\t/**\n\t * Slowly increment progress is used when we don't know how long\n\t * an operation will take and just want to keep slowly incrementing\n\t * the progress bar.\n\t */\n\t| 'SLOWLY_INCREMENT';\n\nexport type ProgressObserverEvent = {\n\tprogress: number;\n\tmode: ProgressMode;\n\tcaption: string;\n};\n\nexport class ProgressObserver extends EventTarget {\n\t#observedProgresses: Record<number, number> = {};\n\t#lastObserverId = 0;\n\n\tprogress = 0;\n\tmode: ProgressMode = 'REAL_TIME';\n\tcaption = '';\n\n\tpartialObserver(progressBudget: number, caption = '') {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = 0;\n\t\treturn (progress: CustomEvent<DownloadProgress>) => {\n\t\t\tconst { loaded, total } = progress?.detail || {};\n\t\t\tthis.#observedProgresses[id] = (loaded / total) * progressBudget;\n\t\t\tthis.#onProgress(this.totalProgress, 'REAL_TIME', caption);\n\t\t};\n\t}\n\n\tslowlyIncrementBy(progress: number) {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = progress;\n\t\tthis.#onProgress(this.totalProgress, 'SLOWLY_INCREMENT');\n\t}\n\n\tget totalProgress() {\n\t\treturn Object.values(this.#observedProgresses).reduce(\n\t\t\t(total, progress) => total + progress,\n\t\t\t0\n\t\t);\n\t}\n\n\t#onProgress(progress: number, mode: ProgressMode, caption?: string) {\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tprogress,\n\t\t\t\t\tmode,\n\t\t\t\t\tcaption,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n","/**\n * Options for customizing the progress tracker.\n */\nexport interface ProgressTrackerOptions {\n\t/** The weight of the progress, a number between 0 and 1. */\n\tweight?: number;\n\t/** The caption to display during progress, a string. */\n\tcaption?: string;\n\t/** The time in milliseconds to fill the progress, a number. */\n\tfillTime?: number;\n}\n\n/**\n * Custom event providing information about a loading process.\n */\nexport type LoadingEvent = CustomEvent<{\n\t/** The number representing how much was loaded. */\n\tloaded: number;\n\t/** The number representing how much needs to loaded in total. */\n\ttotal: number;\n}>;\n\n/**\n * Custom event providing progress details.\n */\nexport type ProgressTrackerEvent = CustomEvent<ProgressDetails>;\n\n/**\n * Custom event providing progress details when the task is done.\n */\nexport type DoneEvent = CustomEvent<ProgressDetails>;\n\nexport interface ProgressDetails {\n\t/** The progress percentage as a number between 0 and 100. */\n\tprogress: number;\n\t/** The caption to display during progress, a string. */\n\tcaption: string;\n}\n\n/**\n * ProgressObserver A function that receives progress updates.\n *\n * @param progress The progress percentage as a number between 0 and 100.\n */\ntype ProgressObserver = (progress: number) => void;\n\n/**\n * Listener A function for handling specific event types.\n *\n * @param event The event of type T.\n */\nexport type Listener<T> = (event: T) => void;\n\nexport type TSCompatibleListener<T> =\n\t| EventListenerOrEventListenerObject\n\t| null\n\t| Listener<T>;\n\nexport interface ProgressReceiver {\n\tsetProgress(details: ProgressDetails): any;\n\tsetLoaded(): any;\n}\n\n/*\n * Like Number.EPSILON, but better tuned to tracking progress.\n *\n * With Number.EPSILON, progress like 99.99999999999997 is still\n * considered to be below 100 – this is highly undeisrable.\n */\nconst PROGRESS_EPSILON = 0.00001;\n\n/**\n * The ProgressTracker class is a tool for tracking progress in an operation\n * that is divided into multiple stages. It allows you to create sub-trackers\n * for each stage, with individual weights and captions. The main tracker\n * automatically calculates the progress based on the weighted sum of each\n * sub-tracker's progress. This makes it easy to keep track of a complex,\n * multi-stage process and report progress in a user-friendly way.\n *\n * After creating the sub-trackers, you can call the set() method to update the\n * progress of the current stage. You can also call the finish() method to mark\n * the current stage as complete and move on to the next one. Alternatively,\n * you can call the fillSlowly() method to simulate progress filling up slowly\n * to 100% before calling finish().\n *\n * @example\n * ```ts\n * const tracker = new ProgressTracker();\n * tracker.addEventListener('progress', (e) => {\n * \t\tconsole.log(\n * \t\t\t\te.detail.progress,\n * \t\t\t\te.detail.caption\n * \t\t);\n * });\n *\n * const stage1 = tracker.stage(0.5, 'Calculating pi digits');\n * const stage2 = tracker.stage(0.5, 'Downloading data');\n *\n * stage1.fillSlowly();\n * await calc100DigitsOfPi();\n * stage1.finish();\n *\n * await fetchWithProgress(function onProgress(loaded, total) {\n * \t\tstage2.set( loaded / total * 100);\n * });\n * stage2.finish();\n */\nexport class ProgressTracker extends EventTarget {\n\tprivate _selfWeight = 1;\n\tprivate _selfDone = false;\n\tprivate _selfProgress = 0;\n\tprivate _selfCaption = '';\n\tprivate _weight: number;\n\tprivate _progressObserver?: ProgressObserver;\n\tprivate _loadingListener?: Listener<LoadingEvent>;\n\tprivate _isFilling = false;\n\tprivate _fillTime: number;\n\tprivate _fillInterval?: any;\n\tprivate _subTrackers: ProgressTracker[] = [];\n\n\tconstructor({\n\t\tweight = 1,\n\t\tcaption = '',\n\t\tfillTime = 4,\n\t}: ProgressTrackerOptions = {}) {\n\t\tsuper();\n\t\tthis._weight = weight;\n\t\tthis._selfCaption = caption;\n\t\tthis._fillTime = fillTime;\n\t}\n\n\t/**\n\t * Creates a new sub-tracker with a specific weight.\n\t *\n\t * The weight determines what percentage of the overall progress\n\t * the sub-tracker represents. For example, if the main tracker is\n\t * monitoring a process that has two stages, and the first stage\n\t * is expected to take twice as long as the second stage, you could\n\t * create the first sub-tracker with a weight of 0.67 and the second\n\t * sub-tracker with a weight of 0.33.\n\t *\n\t * The caption is an optional string that describes the current stage\n\t * of the operation. If provided, it will be used as the progress caption\n\t * for the sub-tracker. If not provided, the main tracker will look for\n\t * the next sub-tracker with a non-empty caption and use that as the progress\n\t * caption instead.\n\t *\n\t * Returns the newly-created sub-tracker.\n\t *\n\t * @throws {Error} If the weight of the new stage would cause the total weight of all stages to exceed 1.\n\t *\n\t * @param weight The weight of the new stage, as a decimal value between 0 and 1.\n\t * @param caption The caption for the new stage, which will be used as the progress caption for the sub-tracker.\n\t *\n\t * @example\n\t * ```ts\n\t * const tracker = new ProgressTracker();\n\t * const subTracker1 = tracker.stage(0.67, 'Slow stage');\n\t * const subTracker2 = tracker.stage(0.33, 'Fast stage');\n\t *\n\t * subTracker2.set(50);\n\t * subTracker1.set(75);\n\t * subTracker2.set(100);\n\t * subTracker1.set(100);\n\t * ```\n\t */\n\tstage(weight?: number, caption = ''): ProgressTracker {\n\t\tif (!weight) {\n\t\t\tweight = this._selfWeight;\n\t\t}\n\t\tif (this._selfWeight - weight < -PROGRESS_EPSILON) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot add a stage with weight ${weight} as the total weight of registered stages would exceed 1.`\n\t\t\t);\n\t\t}\n\t\tthis._selfWeight -= weight;\n\n\t\tconst subTracker = new ProgressTracker({\n\t\t\tcaption,\n\t\t\tweight,\n\t\t\tfillTime: this._fillTime,\n\t\t});\n\t\tthis._subTrackers.push(subTracker);\n\t\tsubTracker.addEventListener('progress', () => this.notifyProgress());\n\t\tsubTracker.addEventListener('done', () => {\n\t\t\tif (this.done) {\n\t\t\t\tthis.notifyDone();\n\t\t\t}\n\t\t});\n\t\treturn subTracker;\n\t}\n\n\t/**\n\t * Fills the progress bar slowly over time, simulating progress.\n\t *\n\t * The progress bar is filled in a 100 steps, and each step, the progress\n\t * is increased by 1. If `stopBeforeFinishing` is true, the progress bar\n\t * will stop filling when it reaches 99% so that you can call `finish()`\n\t * explicitly.\n\t *\n\t * If the progress bar is filling or already filled, this method does nothing.\n\t *\n\t * @example\n\t * ```ts\n\t * const progress = new ProgressTracker({ caption: 'Processing...' });\n\t * progress.fillSlowly();\n\t * ```\n\t *\n\t * @param options Optional options.\n\t */\n\tfillSlowly({ stopBeforeFinishing = true } = {}): void {\n\t\tif (this._isFilling) {\n\t\t\treturn;\n\t\t}\n\t\tthis._isFilling = true;\n\t\tconst steps = 100;\n\t\tconst interval = this._fillTime / steps;\n\t\tthis._fillInterval = setInterval(() => {\n\t\t\tthis.set(this._selfProgress + 1);\n\t\t\tif (stopBeforeFinishing && this._selfProgress >= 99) {\n\t\t\t\tclearInterval(this._fillInterval);\n\t\t\t}\n\t\t}, interval);\n\t}\n\n\tset(value: number): void {\n\t\tthis._selfProgress = Math.min(value, 100);\n\t\tthis.notifyProgress();\n\t\tif (this._selfProgress + PROGRESS_EPSILON >= 100) {\n\t\t\tthis.finish();\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this._fillInterval) {\n\t\t\tclearInterval(this._fillInterval);\n\t\t}\n\t\tthis._selfDone = true;\n\t\tthis._selfProgress = 100;\n\t\tthis._isFilling = false;\n\t\tthis._fillInterval = undefined;\n\t\tthis.notifyProgress();\n\t\tthis.notifyDone();\n\t}\n\n\tget caption(): string {\n\t\tfor (let i = this._subTrackers.length - 1; i >= 0; i--) {\n\t\t\tif (!this._subTrackers[i].done) {\n\t\t\t\tconst captionMaybe = this._subTrackers[i].caption;\n\t\t\t\tif (captionMaybe) {\n\t\t\t\t\treturn captionMaybe;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this._selfCaption;\n\t}\n\n\tsetCaption(caption: string) {\n\t\tthis._selfCaption = caption;\n\t\tthis.notifyProgress();\n\t}\n\n\tget done(): boolean {\n\t\treturn this.progress + PROGRESS_EPSILON >= 100;\n\t}\n\n\tget progress(): number {\n\t\tif (this._selfDone) {\n\t\t\treturn 100;\n\t\t}\n\t\tconst sum = this._subTrackers.reduce(\n\t\t\t(sum, tracker) => sum + tracker.progress * tracker.weight,\n\t\t\tthis._selfProgress * this._selfWeight\n\t\t);\n\t\treturn Math.round(sum * 10000) / 10000;\n\t}\n\n\tget weight(): number {\n\t\treturn this._weight;\n\t}\n\n\tget observer() {\n\t\tif (!this._progressObserver) {\n\t\t\tthis._progressObserver = (progress: number) => {\n\t\t\t\tthis.set(progress);\n\t\t\t};\n\t\t}\n\t\treturn this._progressObserver;\n\t}\n\n\tget loadingListener() {\n\t\tif (!this._loadingListener) {\n\t\t\tthis._loadingListener = (event: LoadingEvent) => {\n\t\t\t\tthis.set((event.detail.loaded / event.detail.total) * 100);\n\t\t\t};\n\t\t}\n\t\treturn this._loadingListener;\n\t}\n\n\tpipe(receiver: ProgressReceiver) {\n\t\treceiver.setProgress({\n\t\t\tprogress: this.progress,\n\t\t\tcaption: this.caption,\n\t\t});\n\t\tthis.addEventListener('progress', (event: ProgressTrackerEvent) => {\n\t\t\treceiver.setProgress({\n\t\t\t\tprogress: event.detail.progress,\n\t\t\t\tcaption: event.detail.caption,\n\t\t\t});\n\t\t});\n\t\tthis.addEventListener('done', () => {\n\t\t\treceiver.setLoaded();\n\t\t});\n\t}\n\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.addEventListener(type, listener as any);\n\t}\n\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.removeEventListener(type, listener as any);\n\t}\n\n\tprivate notifyProgress() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tget progress() {\n\t\t\t\t\t\treturn self.progress;\n\t\t\t\t\t},\n\t\t\t\t\tget caption() {\n\t\t\t\t\t\treturn self.caption;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\tprivate notifyDone() {\n\t\tthis.dispatchEvent(new CustomEvent('done'));\n\t}\n}\n"],"names":["FALLBACK_FILE_SIZE","EmscriptenDownloadMonitor","__privateAdd","_EmscriptenDownloadMonitor_instances","_assetsSizes","_progress","assets","urlLike","size","dummyBaseUrl","filename","__privateGet","fetchPromise","response","cloneResponseMonitorProgress","event","__privateMethod","notify_fn","file","loaded","fileSize","fileName","logger","sumValues","obj","length","value","onProgress","contentLength","cloneStreamMonitorProgress","stream","total","notify","controller","reader","done","e","ProgressObserver","_ProgressObserver_instances","_observedProgresses","_lastObserverId","__privateSet","progressBudget","caption","id","__privateWrapper","progress","onProgress_fn","mode","PROGRESS_EPSILON","ProgressTracker","weight","fillTime","subTracker","stopBeforeFinishing","interval","i","captionMaybe","sum","tracker","receiver","type","listener","self"],"mappings":"olBAYMA,EAAqB,EAAI,KAAO,iBAmB/B,MAAMC,UAAkC,WAAY,CAApD,kCAAAC,EAAA,KAAAC,GACND,EAAA,KAAAE,EAAuC,CAAC,GACxCF,EAAA,KAAAG,EAAoC,CAAC,GAErC,aAAaC,EAAgC,CAC5C,SAAW,CAACC,EAASC,CAAI,IAAK,OAAO,QAAQF,CAAM,EAAG,CACrD,MAAMG,EAAe,sBAEfC,EADW,IAAI,IAAIH,EAASE,CAAY,EAAE,SACtB,MAAM,GAAG,EAAE,IAAI,EACnCC,KAAYC,EAAA,KAAKP,KACjBO,EAAA,KAAAP,GAAaM,CAAQ,EAAIF,GAEzBE,KAAYC,EAAA,KAAKN,KACjBM,EAAA,KAAAN,GAAUK,CAAQ,EAAI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lC,IAAI,QAAiB,CACpB,OAAO,KAAK,OAAA,CAGb,IAAI,UAAW,CACV,OAAC,KAAK,oBACJ,KAAA,kBAAqBZ,GAAqB,CAC9C,KAAK,IAAIA,CAAQ,CAClB,GAEM,KAAK,iBAAA,CAGb,IAAI,iBAAkB,CACjB,OAAC,KAAK,mBACJ,KAAA,iBAAoB/B,GAAwB,CAChD,KAAK,IAAKA,EAAM,OAAO,OAASA,EAAM,OAAO,MAAS,GAAG,CAC1D,GAEM,KAAK,gBAAA,CAGb,KAAK6C,EAA4B,CAChCA,EAAS,YAAY,CACpB,SAAU,KAAK,SACf,QAAS,KAAK,OAAA,CACd,EACI,KAAA,iBAAiB,WAAa7C,GAAgC,CAClE6C,EAAS,YAAY,CACpB,SAAU7C,EAAM,OAAO,SACvB,QAASA,EAAM,OAAO,OAAA,CACtB,CAAA,CACD,EACI,KAAA,iBAAiB,OAAQ,IAAM,CACnC6C,EAAS,UAAU,CAAA,CACnB,CAAA,CAGO,iBACRC,EACAC,EACC,CACK,MAAA,iBAAiBD,EAAMC,CAAe,CAAA,CAGpC,oBACRD,EACAC,EACC,CACK,MAAA,oBAAoBD,EAAMC,CAAe,CAAA,CAGxC,gBAAiB,CAExB,MAAMC,EAAO,KACR,KAAA,cACJ,IAAI,YAAY,WAAY,CAC3B,OAAQ,CACP,IAAI,UAAW,CACd,OAAOA,EAAK,QACb,EACA,IAAI,SAAU,CACb,OAAOA,EAAK,OAAA,CACb,CAED,CAAA,CACF,CAAA,CAGO,YAAa,CACpB,KAAK,cAAc,IAAI,YAAY,MAAM,CAAC,CAAA,CAE5C"}
package/index.js CHANGED
@@ -1,155 +1,154 @@
1
- var b = (i, t, e) => {
2
- if (!t.has(i))
3
- throw TypeError("Cannot " + e);
1
+ var P = (i) => {
2
+ throw TypeError(i);
4
3
  };
5
- var n = (i, t, e) => (b(i, t, "read from private field"), e ? e.call(i) : t.get(i)), g = (i, t, e) => {
6
- if (t.has(i))
7
- throw TypeError("Cannot add the same private member more than once");
8
- t instanceof WeakSet ? t.add(i) : t.set(i, e);
9
- }, _ = (i, t, e, s) => (b(i, t, "write to private field"), s ? s.call(i, e) : t.set(i, e), e);
10
- var L = (i, t, e, s) => ({
11
- set _(o) {
12
- _(i, t, o, e);
4
+ var E = (i, e, t) => e.has(i) || P("Cannot " + t);
5
+ var o = (i, e, t) => (E(i, e, "read from private field"), t ? t.call(i) : e.get(i)), c = (i, e, t) => e.has(i) ? P("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), p = (i, e, t, s) => (E(i, e, "write to private field"), s ? s.call(i, t) : e.set(i, t), t), _ = (i, e, t) => (E(i, e, "access private method"), t);
6
+ var b = (i, e, t, s) => ({
7
+ set _(r) {
8
+ p(i, e, r, t);
13
9
  },
14
10
  get _() {
15
- return n(i, t, s);
11
+ return o(i, e, s);
16
12
  }
17
- }), v = (i, t, e) => (b(i, t, "access private method"), e);
13
+ });
18
14
  import "@php-wasm/node-polyfills";
19
15
  import { logger as T } from "@php-wasm/logger";
20
16
  const O = 5 * 1024 * 1024;
21
- var h, l, m, I;
22
- class D extends EventTarget {
17
+ var h, l, v, I;
18
+ class F extends EventTarget {
23
19
  constructor() {
24
20
  super(...arguments);
25
- /**
26
- * Notifies about the download #progress of a file.
27
- *
28
- * @param file The file name.
29
- * @param loaded The number of bytes of that file loaded so far.
30
- * @param fileSize The total number of bytes in the loaded file.
31
- */
32
- g(this, m);
33
- g(this, h, {});
34
- g(this, l, {});
21
+ c(this, v);
22
+ c(this, h, {});
23
+ c(this, l, {});
35
24
  }
36
- expectAssets(e) {
37
- for (const [s, o] of Object.entries(e)) {
38
- const r = "http://example.com/", a = new URL(s, r).pathname.split("/").pop();
39
- a in n(this, h) || (n(this, h)[a] = o), a in n(this, l) || (n(this, l)[a] = 0);
25
+ expectAssets(t) {
26
+ for (const [s, r] of Object.entries(t)) {
27
+ const n = "http://example.com/", a = new URL(s, n).pathname.split("/").pop();
28
+ a in o(this, h) || (o(this, h)[a] = r), a in o(this, l) || (o(this, l)[a] = 0);
40
29
  }
41
30
  }
42
- async monitorFetch(e) {
43
- const s = await e;
44
- return R(s, (r) => {
45
- v(this, m, I).call(this, s.url, r.detail.loaded, r.detail.total);
31
+ async monitorFetch(t) {
32
+ const s = await t;
33
+ return R(s, (n) => {
34
+ _(this, v, I).call(this, s.url, n.detail.loaded, n.detail.total);
46
35
  });
47
36
  }
48
37
  }
49
- h = new WeakMap(), l = new WeakMap(), m = new WeakSet(), I = function(e, s, o) {
50
- const r = new URL(e, "http://example.com").pathname.split("/").pop();
51
- o ? r in n(this, h) || (n(this, h)[r] = o, n(this, l)[r] = s) : o = n(this, h)[r], r in n(this, l) || T.warn(
52
- `Registered a download #progress of an unregistered file "${r}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`
53
- ), n(this, l)[r] = s, this.dispatchEvent(
38
+ h = new WeakMap(), l = new WeakMap(), v = new WeakSet(), /**
39
+ * Notifies about the download #progress of a file.
40
+ *
41
+ * @param file The file name.
42
+ * @param loaded The number of bytes of that file loaded so far.
43
+ * @param fileSize The length number of bytes in the loaded file.
44
+ */
45
+ I = function(t, s, r) {
46
+ const n = new URL(t, "http://example.com").pathname.split("/").pop();
47
+ r ? n in o(this, h) || (o(this, h)[n] = r, o(this, l)[n] = s) : r = o(this, h)[n], n in o(this, l) || T.warn(
48
+ `Registered a download #progress of an unregistered file "${n}". This may cause a sudden **decrease** in the #progress percentage as the length number of bytes increases during the download.`
49
+ ), o(this, l)[n] = s, this.dispatchEvent(
54
50
  new CustomEvent("progress", {
55
51
  detail: {
56
- loaded: y(n(this, l)),
57
- total: y(n(this, h))
52
+ loaded: w(o(this, l)),
53
+ total: w(o(this, h))
58
54
  }
59
55
  })
60
56
  );
61
57
  };
62
- function y(i) {
63
- return Object.values(i).reduce((t, e) => t + e, 0);
58
+ function w(i) {
59
+ return Object.values(i).reduce((e, t) => e + t, 0);
64
60
  }
65
- function R(i, t) {
66
- const e = i.headers.get("content-length") || "", s = parseInt(e, 10) || O;
67
- function o(r, f) {
61
+ function R(i, e) {
62
+ const t = i.headers.get("content-length") || "", s = parseInt(t, 10) || O;
63
+ return new Response(
64
+ x(i.body, s, e),
65
+ {
66
+ status: i.status,
67
+ statusText: i.statusText,
68
+ headers: i.headers
69
+ }
70
+ );
71
+ }
72
+ function x(i, e, t) {
73
+ function s(r, n) {
68
74
  t(
69
75
  new CustomEvent("progress", {
70
76
  detail: {
71
77
  loaded: r,
72
- total: f
78
+ total: n
73
79
  }
74
80
  })
75
81
  );
76
82
  }
77
- return new Response(
78
- new ReadableStream({
79
- async start(r) {
80
- if (!i.body) {
81
- r.close();
82
- return;
83
- }
84
- const f = i.body.getReader();
85
- let a = 0;
86
- for (; ; )
87
- try {
88
- const { done: p, value: E } = await f.read();
89
- if (E && (a += E.byteLength), p) {
90
- o(a, a), r.close();
91
- break;
92
- } else
93
- o(a, s), r.enqueue(E);
94
- } catch (p) {
95
- T.error({ e: p }), r.error(p);
96
- break;
97
- }
83
+ return new ReadableStream({
84
+ async start(r) {
85
+ if (!i) {
86
+ r.close();
87
+ return;
98
88
  }
99
- }),
100
- {
101
- status: i.status,
102
- statusText: i.statusText,
103
- headers: i.headers
89
+ const n = i.getReader();
90
+ let d = 0;
91
+ for (; ; )
92
+ try {
93
+ const { done: a, value: m } = await n.read();
94
+ if (m && (d += m.byteLength), a) {
95
+ s(d, d), r.close();
96
+ break;
97
+ } else
98
+ s(d, e), r.enqueue(m);
99
+ } catch (a) {
100
+ T.error({ e: a }), r.error(a);
101
+ break;
102
+ }
104
103
  }
105
- );
104
+ });
106
105
  }
107
- var d, c, u, w;
108
- class F extends EventTarget {
106
+ var g, f, u, L;
107
+ class S extends EventTarget {
109
108
  constructor() {
110
109
  super(...arguments);
111
- g(this, u);
112
- g(this, d, void 0);
113
- g(this, c, void 0);
114
- _(this, d, {}), _(this, c, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
110
+ c(this, u);
111
+ c(this, g);
112
+ c(this, f);
113
+ p(this, g, {}), p(this, f, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
115
114
  }
116
- partialObserver(e, s = "") {
117
- const o = ++L(this, c)._;
118
- return n(this, d)[o] = 0, (r) => {
119
- const { loaded: f, total: a } = (r == null ? void 0 : r.detail) || {};
120
- n(this, d)[o] = f / a * e, v(this, u, w).call(this, this.totalProgress, "REAL_TIME", s);
115
+ partialObserver(t, s = "") {
116
+ const r = ++b(this, f)._;
117
+ return o(this, g)[r] = 0, (n) => {
118
+ const { loaded: d, total: a } = (n == null ? void 0 : n.detail) || {};
119
+ o(this, g)[r] = d / a * t, _(this, u, L).call(this, this.totalProgress, "REAL_TIME", s);
121
120
  };
122
121
  }
123
- slowlyIncrementBy(e) {
124
- const s = ++L(this, c)._;
125
- n(this, d)[s] = e, v(this, u, w).call(this, this.totalProgress, "SLOWLY_INCREMENT");
122
+ slowlyIncrementBy(t) {
123
+ const s = ++b(this, f)._;
124
+ o(this, g)[s] = t, _(this, u, L).call(this, this.totalProgress, "SLOWLY_INCREMENT");
126
125
  }
127
126
  get totalProgress() {
128
- return Object.values(n(this, d)).reduce(
129
- (e, s) => e + s,
127
+ return Object.values(o(this, g)).reduce(
128
+ (t, s) => t + s,
130
129
  0
131
130
  );
132
131
  }
133
132
  }
134
- d = new WeakMap(), c = new WeakMap(), u = new WeakSet(), w = function(e, s, o) {
133
+ g = new WeakMap(), f = new WeakMap(), u = new WeakSet(), L = function(t, s, r) {
135
134
  this.dispatchEvent(
136
135
  new CustomEvent("progress", {
137
136
  detail: {
138
- progress: e,
137
+ progress: t,
139
138
  mode: s,
140
- caption: o
139
+ caption: r
141
140
  }
142
141
  })
143
142
  );
144
143
  };
145
- const P = 1e-5;
144
+ const y = 1e-5;
146
145
  class C extends EventTarget {
147
146
  constructor({
148
- weight: t = 1,
149
- caption: e = "",
147
+ weight: e = 1,
148
+ caption: t = "",
150
149
  fillTime: s = 4
151
150
  } = {}) {
152
- super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = t, this._selfCaption = e, this._fillTime = s;
151
+ super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = e, this._selfCaption = t, this._fillTime = s;
153
152
  }
154
153
  /**
155
154
  * Creates a new sub-tracker with a specific weight.
@@ -186,15 +185,15 @@ class C extends EventTarget {
186
185
  * subTracker1.set(100);
187
186
  * ```
188
187
  */
189
- stage(t, e = "") {
190
- if (t || (t = this._selfWeight), this._selfWeight - t < -P)
188
+ stage(e, t = "") {
189
+ if (e || (e = this._selfWeight), this._selfWeight - e < -1e-5)
191
190
  throw new Error(
192
- `Cannot add a stage with weight ${t} as the total weight of registered stages would exceed 1.`
191
+ `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
193
192
  );
194
- this._selfWeight -= t;
193
+ this._selfWeight -= e;
195
194
  const s = new C({
196
- caption: e,
197
- weight: t,
195
+ caption: t,
196
+ weight: e,
198
197
  fillTime: this._fillTime
199
198
  });
200
199
  return this._subTrackers.push(s), s.addEventListener("progress", () => this.notifyProgress()), s.addEventListener("done", () => {
@@ -219,87 +218,87 @@ class C extends EventTarget {
219
218
  *
220
219
  * @param options Optional options.
221
220
  */
222
- fillSlowly({ stopBeforeFinishing: t = !0 } = {}) {
221
+ fillSlowly({ stopBeforeFinishing: e = !0 } = {}) {
223
222
  if (this._isFilling)
224
223
  return;
225
224
  this._isFilling = !0;
226
- const e = 100, s = this._fillTime / e;
225
+ const s = this._fillTime / 100;
227
226
  this._fillInterval = setInterval(() => {
228
- this.set(this._selfProgress + 1), t && this._selfProgress >= 99 && clearInterval(this._fillInterval);
227
+ this.set(this._selfProgress + 1), e && this._selfProgress >= 99 && clearInterval(this._fillInterval);
229
228
  }, s);
230
229
  }
231
- set(t) {
232
- this._selfProgress = Math.min(t, 100), this.notifyProgress(), this._selfProgress + P >= 100 && this.finish();
230
+ set(e) {
231
+ this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + y >= 100 && this.finish();
233
232
  }
234
233
  finish() {
235
234
  this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
236
235
  }
237
236
  get caption() {
238
- for (let t = this._subTrackers.length - 1; t >= 0; t--)
239
- if (!this._subTrackers[t].done) {
240
- const e = this._subTrackers[t].caption;
241
- if (e)
242
- return e;
237
+ for (let e = this._subTrackers.length - 1; e >= 0; e--)
238
+ if (!this._subTrackers[e].done) {
239
+ const t = this._subTrackers[e].caption;
240
+ if (t)
241
+ return t;
243
242
  }
244
243
  return this._selfCaption;
245
244
  }
246
- setCaption(t) {
247
- this._selfCaption = t, this.notifyProgress();
245
+ setCaption(e) {
246
+ this._selfCaption = e, this.notifyProgress();
248
247
  }
249
248
  get done() {
250
- return this.progress + P >= 100;
249
+ return this.progress + y >= 100;
251
250
  }
252
251
  get progress() {
253
252
  if (this._selfDone)
254
253
  return 100;
255
- const t = this._subTrackers.reduce(
256
- (e, s) => e + s.progress * s.weight,
254
+ const e = this._subTrackers.reduce(
255
+ (t, s) => t + s.progress * s.weight,
257
256
  this._selfProgress * this._selfWeight
258
257
  );
259
- return Math.round(t * 1e4) / 1e4;
258
+ return Math.round(e * 1e4) / 1e4;
260
259
  }
261
260
  get weight() {
262
261
  return this._weight;
263
262
  }
264
263
  get observer() {
265
- return this._progressObserver || (this._progressObserver = (t) => {
266
- this.set(t);
264
+ return this._progressObserver || (this._progressObserver = (e) => {
265
+ this.set(e);
267
266
  }), this._progressObserver;
268
267
  }
269
268
  get loadingListener() {
270
- return this._loadingListener || (this._loadingListener = (t) => {
271
- this.set(t.detail.loaded / t.detail.total * 100);
269
+ return this._loadingListener || (this._loadingListener = (e) => {
270
+ this.set(e.detail.loaded / e.detail.total * 100);
272
271
  }), this._loadingListener;
273
272
  }
274
- pipe(t) {
275
- t.setProgress({
273
+ pipe(e) {
274
+ e.setProgress({
276
275
  progress: this.progress,
277
276
  caption: this.caption
278
- }), this.addEventListener("progress", (e) => {
279
- t.setProgress({
280
- progress: e.detail.progress,
281
- caption: e.detail.caption
277
+ }), this.addEventListener("progress", (t) => {
278
+ e.setProgress({
279
+ progress: t.detail.progress,
280
+ caption: t.detail.caption
282
281
  });
283
282
  }), this.addEventListener("done", () => {
284
- t.setLoaded();
283
+ e.setLoaded();
285
284
  });
286
285
  }
287
- addEventListener(t, e) {
288
- super.addEventListener(t, e);
286
+ addEventListener(e, t) {
287
+ super.addEventListener(e, t);
289
288
  }
290
- removeEventListener(t, e) {
291
- super.removeEventListener(t, e);
289
+ removeEventListener(e, t) {
290
+ super.removeEventListener(e, t);
292
291
  }
293
292
  notifyProgress() {
294
- const t = this;
293
+ const e = this;
295
294
  this.dispatchEvent(
296
295
  new CustomEvent("progress", {
297
296
  detail: {
298
297
  get progress() {
299
- return t.progress;
298
+ return e.progress;
300
299
  },
301
300
  get caption() {
302
- return t.caption;
301
+ return e.caption;
303
302
  }
304
303
  }
305
304
  })
@@ -310,9 +309,10 @@ class C extends EventTarget {
310
309
  }
311
310
  }
312
311
  export {
313
- D as EmscriptenDownloadMonitor,
314
- F as ProgressObserver,
312
+ F as EmscriptenDownloadMonitor,
313
+ S as ProgressObserver,
315
314
  C as ProgressTracker,
316
- R as cloneResponseMonitorProgress
315
+ R as cloneResponseMonitorProgress,
316
+ x as cloneStreamMonitorProgress
317
317
  };
318
318
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../packages/php-wasm/progress/src/lib/emscripten-download-monitor.ts","../../../../packages/php-wasm/progress/src/lib/progress-observer.ts","../../../../packages/php-wasm/progress/src/lib/progress-tracker.ts"],"sourcesContent":["import { logger } from '@php-wasm/logger';\n/*\n * An approximate total file size to use when the actual\n * total number of bytes is missing.\n *\n * This may happen when the files are compressed before transmission\n * and no content-length header is being sent.\n *\n * The approximation isn't accurate, but it's better than nothing.\n * It's not about being exact but about giving the user a rough sense\n * of #progress.\n */\nconst FALLBACK_FILE_SIZE = 5 * 1024 * 1024;\n\n/**\n * Monitors the download #progress of Emscripten modules\n *\n * Usage:\n *\n * ```js\n * const downloadMonitor = new EmscriptenDownloadMonitor();\n * \t const php = await startPHP(\n * phpLoaderModule,\n * 'web',\n * downloadMonitor.phpArgs\n * );\n * downloadMonitor.addEventListener('#progress', (e) => {\n * console.log( e.detail.#progress);\n * })\n * ```\n */\nexport class EmscriptenDownloadMonitor extends EventTarget {\n\t#assetsSizes: Record<string, number> = {};\n\t#progress: Record<string, number> = {};\n\n\texpectAssets(assets: Record<string, number>) {\n\t\tfor (const [urlLike, size] of Object.entries(assets)) {\n\t\t\tconst dummyBaseUrl = 'http://example.com/';\n\t\t\tconst pathname = new URL(urlLike, dummyBaseUrl).pathname;\n\t\t\tconst filename = pathname.split('/').pop()!;\n\t\t\tif (!(filename in this.#assetsSizes)) {\n\t\t\t\tthis.#assetsSizes[filename] = size;\n\t\t\t}\n\t\t\tif (!(filename in this.#progress)) {\n\t\t\t\tthis.#progress[filename] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync monitorFetch(fetchPromise: Promise<Response>): Promise<Response> {\n\t\tconst response = await fetchPromise;\n\t\tconst onProgress = (event: CustomEvent<DownloadProgress>) => {\n\t\t\tthis.#notify(response.url, event.detail.loaded, event.detail.total);\n\t\t};\n\t\treturn cloneResponseMonitorProgress(response, onProgress);\n\t}\n\n\t/**\n\t * Notifies about the download #progress of a file.\n\t *\n\t * @param file The file name.\n\t * @param loaded The number of bytes of that file loaded so far.\n\t * @param fileSize The total number of bytes in the loaded file.\n\t */\n\t#notify(file: string, loaded: number, fileSize: number) {\n\t\tconst fileName = new URL(file, 'http://example.com').pathname\n\t\t\t.split('/')\n\t\t\t.pop()!;\n\t\tif (!fileSize) {\n\t\t\tfileSize = this.#assetsSizes[fileName];\n\t\t} else if (!(fileName in this.#assetsSizes)) {\n\t\t\tthis.#assetsSizes[fileName] = fileSize;\n\t\t\tthis.#progress[fileName] = loaded;\n\t\t}\n\t\tif (!(fileName in this.#progress)) {\n\t\t\tlogger.warn(\n\t\t\t\t`Registered a download #progress of an unregistered file \"${fileName}\". ` +\n\t\t\t\t\t`This may cause a sudden **decrease** in the #progress percentage as the ` +\n\t\t\t\t\t`total number of bytes increases during the download.`\n\t\t\t);\n\t\t}\n\n\t\tthis.#progress[fileName] = loaded;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded: sumValues(this.#progress),\n\t\t\t\t\ttotal: sumValues(this.#assetsSizes),\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n\nfunction sumValues(obj: Record<string, number>) {\n\treturn Object.values(obj).reduce((total, value) => total + value, 0);\n}\n\nexport default EmscriptenDownloadMonitor;\n\nexport interface DownloadProgress {\n\t/**\n\t * The number of bytes loaded so far.\n\t */\n\tloaded: number;\n\t/**\n\t * The total number of bytes to load.\n\t */\n\ttotal: number;\n}\n\n/**\n * Clones a fetch Response object and returns a version\n * that calls the `onProgress` callback as the #progress\n * changes.\n *\n * @param response The fetch Response object to clone.\n * @param onProgress The callback to call when the download #progress changes.\n * @returns The cloned response\n */\nexport function cloneResponseMonitorProgress(\n\tresponse: Response,\n\tonProgress: (event: CustomEvent<DownloadProgress>) => void\n): Response {\n\tconst contentLength = response.headers.get('content-length') || '';\n\tconst total = parseInt(contentLength, 10) || FALLBACK_FILE_SIZE;\n\n\tfunction notify(loaded: number, total: number) {\n\t\tonProgress(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded,\n\t\t\t\t\ttotal,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\treturn new Response(\n\t\tnew ReadableStream({\n\t\t\tasync start(controller) {\n\t\t\t\tif (!response.body) {\n\t\t\t\t\tcontroller.close();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst reader = response.body.getReader();\n\t\t\t\tlet loaded = 0;\n\t\t\t\tfor (;;) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\t\tif (value) {\n\t\t\t\t\t\t\tloaded += value.byteLength;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (done) {\n\t\t\t\t\t\t\tnotify(loaded, loaded);\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnotify(loaded, total);\n\t\t\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tlogger.error({ e });\n\t\t\t\t\t\tcontroller.error(e);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t}),\n\t\t{\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\theaders: response.headers,\n\t\t}\n\t);\n}\n\nexport type DownloadProgressCallback = (progress: DownloadProgress) => void;\n","import { DownloadProgress } from './emscripten-download-monitor';\n\nexport type ProgressMode =\n\t/**\n\t * Real-time progress is used when we get real-time reports\n\t * about the progress.\n\t */\n\t| 'REAL_TIME'\n\n\t/**\n\t * Slowly increment progress is used when we don't know how long\n\t * an operation will take and just want to keep slowly incrementing\n\t * the progress bar.\n\t */\n\t| 'SLOWLY_INCREMENT';\n\nexport type ProgressObserverEvent = {\n\tprogress: number;\n\tmode: ProgressMode;\n\tcaption: string;\n};\n\nexport class ProgressObserver extends EventTarget {\n\t#observedProgresses: Record<number, number> = {};\n\t#lastObserverId = 0;\n\n\tprogress = 0;\n\tmode: ProgressMode = 'REAL_TIME';\n\tcaption = '';\n\n\tpartialObserver(progressBudget: number, caption = '') {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = 0;\n\t\treturn (progress: CustomEvent<DownloadProgress>) => {\n\t\t\tconst { loaded, total } = progress?.detail || {};\n\t\t\tthis.#observedProgresses[id] = (loaded / total) * progressBudget;\n\t\t\tthis.#onProgress(this.totalProgress, 'REAL_TIME', caption);\n\t\t};\n\t}\n\n\tslowlyIncrementBy(progress: number) {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = progress;\n\t\tthis.#onProgress(this.totalProgress, 'SLOWLY_INCREMENT');\n\t}\n\n\tget totalProgress() {\n\t\treturn Object.values(this.#observedProgresses).reduce(\n\t\t\t(total, progress) => total + progress,\n\t\t\t0\n\t\t);\n\t}\n\n\t#onProgress(progress: number, mode: ProgressMode, caption?: string) {\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tprogress,\n\t\t\t\t\tmode,\n\t\t\t\t\tcaption,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n","/**\n * Options for customizing the progress tracker.\n */\nexport interface ProgressTrackerOptions {\n\t/** The weight of the progress, a number between 0 and 1. */\n\tweight?: number;\n\t/** The caption to display during progress, a string. */\n\tcaption?: string;\n\t/** The time in milliseconds to fill the progress, a number. */\n\tfillTime?: number;\n}\n\n/**\n * Custom event providing information about a loading process.\n */\nexport type LoadingEvent = CustomEvent<{\n\t/** The number representing how much was loaded. */\n\tloaded: number;\n\t/** The number representing how much needs to loaded in total. */\n\ttotal: number;\n}>;\n\n/**\n * Custom event providing progress details.\n */\nexport type ProgressTrackerEvent = CustomEvent<ProgressDetails>;\n\n/**\n * Custom event providing progress details when the task is done.\n */\nexport type DoneEvent = CustomEvent<ProgressDetails>;\n\nexport interface ProgressDetails {\n\t/** The progress percentage as a number between 0 and 100. */\n\tprogress: number;\n\t/** The caption to display during progress, a string. */\n\tcaption: string;\n}\n\n/**\n * ProgressObserver A function that receives progress updates.\n *\n * @param progress The progress percentage as a number between 0 and 100.\n */\ntype ProgressObserver = (progress: number) => void;\n\n/**\n * Listener A function for handling specific event types.\n *\n * @param event The event of type T.\n */\nexport type Listener<T> = (event: T) => void;\n\nexport type TSCompatibleListener<T> =\n\t| EventListenerOrEventListenerObject\n\t| null\n\t| Listener<T>;\n\nexport interface ProgressReceiver {\n\tsetProgress(details: ProgressDetails): any;\n\tsetLoaded(): any;\n}\n\n/*\n * Like Number.EPSILON, but better tuned to tracking progress.\n *\n * With Number.EPSILON, progress like 99.99999999999997 is still\n * considered to be below 100 – this is highly undeisrable.\n */\nconst PROGRESS_EPSILON = 0.00001;\n\n/**\n * The ProgressTracker class is a tool for tracking progress in an operation\n * that is divided into multiple stages. It allows you to create sub-trackers\n * for each stage, with individual weights and captions. The main tracker\n * automatically calculates the progress based on the weighted sum of each\n * sub-tracker's progress. This makes it easy to keep track of a complex,\n * multi-stage process and report progress in a user-friendly way.\n *\n * After creating the sub-trackers, you can call the set() method to update the\n * progress of the current stage. You can also call the finish() method to mark\n * the current stage as complete and move on to the next one. Alternatively,\n * you can call the fillSlowly() method to simulate progress filling up slowly\n * to 100% before calling finish().\n *\n * @example\n * ```ts\n * const tracker = new ProgressTracker();\n * tracker.addEventListener('progress', (e) => {\n * \t\tconsole.log(\n * \t\t\t\te.detail.progress,\n * \t\t\t\te.detail.caption\n * \t\t);\n * });\n *\n * const stage1 = tracker.stage(0.5, 'Calculating pi digits');\n * const stage2 = tracker.stage(0.5, 'Downloading data');\n *\n * stage1.fillSlowly();\n * await calc100DigitsOfPi();\n * stage1.finish();\n *\n * await fetchWithProgress(function onProgress(loaded, total) {\n * \t\tstage2.set( loaded / total * 100);\n * });\n * stage2.finish();\n */\nexport class ProgressTracker extends EventTarget {\n\tprivate _selfWeight = 1;\n\tprivate _selfDone = false;\n\tprivate _selfProgress = 0;\n\tprivate _selfCaption = '';\n\tprivate _weight: number;\n\tprivate _progressObserver?: ProgressObserver;\n\tprivate _loadingListener?: Listener<LoadingEvent>;\n\tprivate _isFilling = false;\n\tprivate _fillTime: number;\n\tprivate _fillInterval?: any;\n\tprivate _subTrackers: ProgressTracker[] = [];\n\n\tconstructor({\n\t\tweight = 1,\n\t\tcaption = '',\n\t\tfillTime = 4,\n\t}: ProgressTrackerOptions = {}) {\n\t\tsuper();\n\t\tthis._weight = weight;\n\t\tthis._selfCaption = caption;\n\t\tthis._fillTime = fillTime;\n\t}\n\n\t/**\n\t * Creates a new sub-tracker with a specific weight.\n\t *\n\t * The weight determines what percentage of the overall progress\n\t * the sub-tracker represents. For example, if the main tracker is\n\t * monitoring a process that has two stages, and the first stage\n\t * is expected to take twice as long as the second stage, you could\n\t * create the first sub-tracker with a weight of 0.67 and the second\n\t * sub-tracker with a weight of 0.33.\n\t *\n\t * The caption is an optional string that describes the current stage\n\t * of the operation. If provided, it will be used as the progress caption\n\t * for the sub-tracker. If not provided, the main tracker will look for\n\t * the next sub-tracker with a non-empty caption and use that as the progress\n\t * caption instead.\n\t *\n\t * Returns the newly-created sub-tracker.\n\t *\n\t * @throws {Error} If the weight of the new stage would cause the total weight of all stages to exceed 1.\n\t *\n\t * @param weight The weight of the new stage, as a decimal value between 0 and 1.\n\t * @param caption The caption for the new stage, which will be used as the progress caption for the sub-tracker.\n\t *\n\t * @example\n\t * ```ts\n\t * const tracker = new ProgressTracker();\n\t * const subTracker1 = tracker.stage(0.67, 'Slow stage');\n\t * const subTracker2 = tracker.stage(0.33, 'Fast stage');\n\t *\n\t * subTracker2.set(50);\n\t * subTracker1.set(75);\n\t * subTracker2.set(100);\n\t * subTracker1.set(100);\n\t * ```\n\t */\n\tstage(weight?: number, caption = ''): ProgressTracker {\n\t\tif (!weight) {\n\t\t\tweight = this._selfWeight;\n\t\t}\n\t\tif (this._selfWeight - weight < -PROGRESS_EPSILON) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot add a stage with weight ${weight} as the total weight of registered stages would exceed 1.`\n\t\t\t);\n\t\t}\n\t\tthis._selfWeight -= weight;\n\n\t\tconst subTracker = new ProgressTracker({\n\t\t\tcaption,\n\t\t\tweight,\n\t\t\tfillTime: this._fillTime,\n\t\t});\n\t\tthis._subTrackers.push(subTracker);\n\t\tsubTracker.addEventListener('progress', () => this.notifyProgress());\n\t\tsubTracker.addEventListener('done', () => {\n\t\t\tif (this.done) {\n\t\t\t\tthis.notifyDone();\n\t\t\t}\n\t\t});\n\t\treturn subTracker;\n\t}\n\n\t/**\n\t * Fills the progress bar slowly over time, simulating progress.\n\t *\n\t * The progress bar is filled in a 100 steps, and each step, the progress\n\t * is increased by 1. If `stopBeforeFinishing` is true, the progress bar\n\t * will stop filling when it reaches 99% so that you can call `finish()`\n\t * explicitly.\n\t *\n\t * If the progress bar is filling or already filled, this method does nothing.\n\t *\n\t * @example\n\t * ```ts\n\t * const progress = new ProgressTracker({ caption: 'Processing...' });\n\t * progress.fillSlowly();\n\t * ```\n\t *\n\t * @param options Optional options.\n\t */\n\tfillSlowly({ stopBeforeFinishing = true } = {}): void {\n\t\tif (this._isFilling) {\n\t\t\treturn;\n\t\t}\n\t\tthis._isFilling = true;\n\t\tconst steps = 100;\n\t\tconst interval = this._fillTime / steps;\n\t\tthis._fillInterval = setInterval(() => {\n\t\t\tthis.set(this._selfProgress + 1);\n\t\t\tif (stopBeforeFinishing && this._selfProgress >= 99) {\n\t\t\t\tclearInterval(this._fillInterval);\n\t\t\t}\n\t\t}, interval);\n\t}\n\n\tset(value: number): void {\n\t\tthis._selfProgress = Math.min(value, 100);\n\t\tthis.notifyProgress();\n\t\tif (this._selfProgress + PROGRESS_EPSILON >= 100) {\n\t\t\tthis.finish();\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this._fillInterval) {\n\t\t\tclearInterval(this._fillInterval);\n\t\t}\n\t\tthis._selfDone = true;\n\t\tthis._selfProgress = 100;\n\t\tthis._isFilling = false;\n\t\tthis._fillInterval = undefined;\n\t\tthis.notifyProgress();\n\t\tthis.notifyDone();\n\t}\n\n\tget caption(): string {\n\t\tfor (let i = this._subTrackers.length - 1; i >= 0; i--) {\n\t\t\tif (!this._subTrackers[i].done) {\n\t\t\t\tconst captionMaybe = this._subTrackers[i].caption;\n\t\t\t\tif (captionMaybe) {\n\t\t\t\t\treturn captionMaybe;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this._selfCaption;\n\t}\n\n\tsetCaption(caption: string) {\n\t\tthis._selfCaption = caption;\n\t\tthis.notifyProgress();\n\t}\n\n\tget done(): boolean {\n\t\treturn this.progress + PROGRESS_EPSILON >= 100;\n\t}\n\n\tget progress(): number {\n\t\tif (this._selfDone) {\n\t\t\treturn 100;\n\t\t}\n\t\tconst sum = this._subTrackers.reduce(\n\t\t\t(sum, tracker) => sum + tracker.progress * tracker.weight,\n\t\t\tthis._selfProgress * this._selfWeight\n\t\t);\n\t\treturn Math.round(sum * 10000) / 10000;\n\t}\n\n\tget weight(): number {\n\t\treturn this._weight;\n\t}\n\n\tget observer() {\n\t\tif (!this._progressObserver) {\n\t\t\tthis._progressObserver = (progress: number) => {\n\t\t\t\tthis.set(progress);\n\t\t\t};\n\t\t}\n\t\treturn this._progressObserver;\n\t}\n\n\tget loadingListener() {\n\t\tif (!this._loadingListener) {\n\t\t\tthis._loadingListener = (event: LoadingEvent) => {\n\t\t\t\tthis.set((event.detail.loaded / event.detail.total) * 100);\n\t\t\t};\n\t\t}\n\t\treturn this._loadingListener;\n\t}\n\n\tpipe(receiver: ProgressReceiver) {\n\t\treceiver.setProgress({\n\t\t\tprogress: this.progress,\n\t\t\tcaption: this.caption,\n\t\t});\n\t\tthis.addEventListener('progress', (event: ProgressTrackerEvent) => {\n\t\t\treceiver.setProgress({\n\t\t\t\tprogress: event.detail.progress,\n\t\t\t\tcaption: event.detail.caption,\n\t\t\t});\n\t\t});\n\t\tthis.addEventListener('done', () => {\n\t\t\treceiver.setLoaded();\n\t\t});\n\t}\n\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.addEventListener(type, listener as any);\n\t}\n\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.removeEventListener(type, listener as any);\n\t}\n\n\tprivate notifyProgress() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tget progress() {\n\t\t\t\t\t\treturn self.progress;\n\t\t\t\t\t},\n\t\t\t\t\tget caption() {\n\t\t\t\t\t\treturn self.caption;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\tprivate notifyDone() {\n\t\tthis.dispatchEvent(new CustomEvent('done'));\n\t}\n}\n"],"names":["FALLBACK_FILE_SIZE","EmscriptenDownloadMonitor","__privateAdd","_notify","_assetsSizes","_progress","assets","urlLike","size","dummyBaseUrl","filename","__privateGet","fetchPromise","response","cloneResponseMonitorProgress","event","__privateMethod","notify_fn","file","loaded","fileSize","fileName","logger","sumValues","obj","total","value","onProgress","contentLength","notify","controller","reader","done","e","ProgressObserver","_onProgress","_observedProgresses","_lastObserverId","__privateSet","progressBudget","caption","id","__privateWrapper","progress","onProgress_fn","mode","PROGRESS_EPSILON","ProgressTracker","weight","fillTime","subTracker","stopBeforeFinishing","steps","interval","i","captionMaybe","sum","tracker","receiver","type","listener","self"],"mappings":";;;;;;;;;;;;;;;;;;;AAYA,MAAMA,IAAqB,IAAI,OAAO;;AAmB/B,MAAMC,UAAkC,YAAY;AAAA,EAApD;AAAA;AAiCN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAC,EAAA,MAAAC;AAhCA,IAAAD,EAAA,MAAAE,GAAuC,CAAA;AACvC,IAAAF,EAAA,MAAAG,GAAoC,CAAA;AAAA;AAAA,EAEpC,aAAaC,GAAgC;AAC5C,eAAW,CAACC,GAASC,CAAI,KAAK,OAAO,QAAQF,CAAM,GAAG;AACrD,YAAMG,IAA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J,KAAA,oBAAoB,CAACb,MAAqB;AAC9C,WAAK,IAAIA,CAAQ;AAAA,IAAA,IAGZ,KAAK;AAAA,EACb;AAAA,EAEA,IAAI,kBAAkB;AACjB,WAAC,KAAK,qBACJ,KAAA,mBAAmB,CAAC5B,MAAwB;AAChD,WAAK,IAAKA,EAAM,OAAO,SAASA,EAAM,OAAO,QAAS,GAAG;AAAA,IAAA,IAGpD,KAAK;AAAA,EACb;AAAA,EAEA,KAAK2C,GAA4B;AAChC,IAAAA,EAAS,YAAY;AAAA,MACpB,UAAU,KAAK;AAAA,MACf,SAAS,KAAK;AAAA,IAAA,CACd,GACI,KAAA,iBAAiB,YAAY,CAAC3C,MAAgC;AAClE,MAAA2C,EAAS,YAAY;AAAA,QACpB,UAAU3C,EAAM,OAAO;AAAA,QACvB,SAASA,EAAM,OAAO;AAAA,MAAA,CACtB;AAAA,IAAA,CACD,GACI,KAAA,iBAAiB,QAAQ,MAAM;AACnC,MAAA2C,EAAS,UAAU;AAAA,IAAA,CACnB;AAAA,EACF;AAAA,EAES,iBACRC,GACAC,GACC;AACK,UAAA,iBAAiBD,GAAMC,CAAe;AAAA,EAC7C;AAAA,EAES,oBACRD,GACAC,GACC;AACK,UAAA,oBAAoBD,GAAMC,CAAe;AAAA,EAChD;AAAA,EAEQ,iBAAiB;AAExB,UAAMC,IAAO;AACR,SAAA;AAAA,MACJ,IAAI,YAAY,YAAY;AAAA,QAC3B,QAAQ;AAAA,UACP,IAAI,WAAW;AACd,mBAAOA,EAAK;AAAA,UACb;AAAA,UACA,IAAI,UAAU;AACb,mBAAOA,EAAK;AAAA,UACb;AAAA,QACD;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,EAEH;AAAA,EAEQ,aAAa;AACpB,SAAK,cAAc,IAAI,YAAY,MAAM,CAAC;AAAA,EAC3C;AACD;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../packages/php-wasm/progress/src/lib/emscripten-download-monitor.ts","../../../../packages/php-wasm/progress/src/lib/progress-observer.ts","../../../../packages/php-wasm/progress/src/lib/progress-tracker.ts"],"sourcesContent":["import { logger } from '@php-wasm/logger';\n/*\n * An approximate file length to use when the actual\n * length number of bytes is missing.\n *\n * This may happen when the files are compressed before transmission\n * and no content-length header is being sent.\n *\n * The approximation isn't accurate, but it's better than nothing.\n * It's not about being exact but about giving the user a rough sense\n * of #progress.\n */\nconst FALLBACK_FILE_SIZE = 5 * 1024 * 1024;\n\n/**\n * Monitors the download #progress of Emscripten modules\n *\n * Usage:\n *\n * ```js\n * const downloadMonitor = new EmscriptenDownloadMonitor();\n * \t const php = await startPHP(\n * phpLoaderModule,\n * 'web',\n * downloadMonitor.phpArgs\n * );\n * downloadMonitor.addEventListener('#progress', (e) => {\n * console.log( e.detail.#progress);\n * })\n * ```\n */\nexport class EmscriptenDownloadMonitor extends EventTarget {\n\t#assetsSizes: Record<string, number> = {};\n\t#progress: Record<string, number> = {};\n\n\texpectAssets(assets: Record<string, number>) {\n\t\tfor (const [urlLike, size] of Object.entries(assets)) {\n\t\t\tconst dummyBaseUrl = 'http://example.com/';\n\t\t\tconst pathname = new URL(urlLike, dummyBaseUrl).pathname;\n\t\t\tconst filename = pathname.split('/').pop()!;\n\t\t\tif (!(filename in this.#assetsSizes)) {\n\t\t\t\tthis.#assetsSizes[filename] = size;\n\t\t\t}\n\t\t\tif (!(filename in this.#progress)) {\n\t\t\t\tthis.#progress[filename] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync monitorFetch(fetchPromise: Promise<Response>): Promise<Response> {\n\t\tconst response = await fetchPromise;\n\t\tconst onProgress = (event: CustomEvent<DownloadProgress>) => {\n\t\t\tthis.#notify(response.url, event.detail.loaded, event.detail.total);\n\t\t};\n\t\treturn cloneResponseMonitorProgress(response, onProgress);\n\t}\n\n\t/**\n\t * Notifies about the download #progress of a file.\n\t *\n\t * @param file The file name.\n\t * @param loaded The number of bytes of that file loaded so far.\n\t * @param fileSize The length number of bytes in the loaded file.\n\t */\n\t#notify(file: string, loaded: number, fileSize: number) {\n\t\tconst fileName = new URL(file, 'http://example.com').pathname\n\t\t\t.split('/')\n\t\t\t.pop()!;\n\t\tif (!fileSize) {\n\t\t\tfileSize = this.#assetsSizes[fileName];\n\t\t} else if (!(fileName in this.#assetsSizes)) {\n\t\t\tthis.#assetsSizes[fileName] = fileSize;\n\t\t\tthis.#progress[fileName] = loaded;\n\t\t}\n\t\tif (!(fileName in this.#progress)) {\n\t\t\tlogger.warn(\n\t\t\t\t`Registered a download #progress of an unregistered file \"${fileName}\". ` +\n\t\t\t\t\t`This may cause a sudden **decrease** in the #progress percentage as the ` +\n\t\t\t\t\t`length number of bytes increases during the download.`\n\t\t\t);\n\t\t}\n\n\t\tthis.#progress[fileName] = loaded;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded: sumValues(this.#progress),\n\t\t\t\t\ttotal: sumValues(this.#assetsSizes),\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n\nfunction sumValues(obj: Record<string, number>) {\n\treturn Object.values(obj).reduce((length, value) => length + value, 0);\n}\n\nexport default EmscriptenDownloadMonitor;\n\nexport interface DownloadProgress {\n\t/**\n\t * The number of bytes loaded so far.\n\t */\n\tloaded: number;\n\t/**\n\t * The length number of bytes to load.\n\t */\n\ttotal: number;\n}\n\n/**\n * Clones a fetch Response object and returns a version\n * that calls the `onProgress` callback as the #progress\n * changes.\n *\n * @param response The fetch Response object to clone.\n * @param onProgress The callback to call when the download #progress changes.\n * @returns The cloned response\n */\nexport function cloneResponseMonitorProgress(\n\tresponse: Response,\n\tonProgress: (event: CustomEvent<DownloadProgress>) => void\n): Response {\n\tconst contentLength = response.headers.get('content-length') || '';\n\tconst length = parseInt(contentLength, 10) || FALLBACK_FILE_SIZE;\n\n\treturn new Response(\n\t\tcloneStreamMonitorProgress(response.body, length, onProgress),\n\t\t{\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\theaders: response.headers,\n\t\t}\n\t);\n}\n\n/**\n * Clones a ReadableStream and returns a version\n * that calls the `onProgress` callback as the #progress\n * changes.\n *\n * @param stream The ReadableStream to clone.\n * @param total The total number of bytes to load.\n * @param onProgress The callback to call when the download #progress changes.\n * @returns The cloned ReadableStream\n */\nexport function cloneStreamMonitorProgress(\n\tstream: ReadableStream<Uint8Array> | null,\n\ttotal: number,\n\tonProgress: (event: CustomEvent<DownloadProgress>) => void\n): ReadableStream<Uint8Array> {\n\tfunction notify(loaded: number, total: number) {\n\t\tonProgress(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tloaded,\n\t\t\t\t\ttotal,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\treturn new ReadableStream({\n\t\tasync start(controller) {\n\t\t\tif (!stream) {\n\t\t\t\tcontroller.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst reader = stream.getReader();\n\t\t\tlet loaded = 0;\n\t\t\twhile (true) {\n\t\t\t\ttry {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tloaded += value.byteLength;\n\t\t\t\t\t}\n\t\t\t\t\tif (done) {\n\t\t\t\t\t\tnotify(loaded, loaded);\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnotify(loaded, total);\n\t\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tlogger.error({ e });\n\t\t\t\t\tcontroller.error(e);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n}\n\nexport type DownloadProgressCallback = (progress: DownloadProgress) => void;\n","import type { DownloadProgress } from './emscripten-download-monitor';\n\nexport type ProgressMode =\n\t/**\n\t * Real-time progress is used when we get real-time reports\n\t * about the progress.\n\t */\n\t| 'REAL_TIME'\n\n\t/**\n\t * Slowly increment progress is used when we don't know how long\n\t * an operation will take and just want to keep slowly incrementing\n\t * the progress bar.\n\t */\n\t| 'SLOWLY_INCREMENT';\n\nexport type ProgressObserverEvent = {\n\tprogress: number;\n\tmode: ProgressMode;\n\tcaption: string;\n};\n\nexport class ProgressObserver extends EventTarget {\n\t#observedProgresses: Record<number, number> = {};\n\t#lastObserverId = 0;\n\n\tprogress = 0;\n\tmode: ProgressMode = 'REAL_TIME';\n\tcaption = '';\n\n\tpartialObserver(progressBudget: number, caption = '') {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = 0;\n\t\treturn (progress: CustomEvent<DownloadProgress>) => {\n\t\t\tconst { loaded, total } = progress?.detail || {};\n\t\t\tthis.#observedProgresses[id] = (loaded / total) * progressBudget;\n\t\t\tthis.#onProgress(this.totalProgress, 'REAL_TIME', caption);\n\t\t};\n\t}\n\n\tslowlyIncrementBy(progress: number) {\n\t\tconst id = ++this.#lastObserverId;\n\t\tthis.#observedProgresses[id] = progress;\n\t\tthis.#onProgress(this.totalProgress, 'SLOWLY_INCREMENT');\n\t}\n\n\tget totalProgress() {\n\t\treturn Object.values(this.#observedProgresses).reduce(\n\t\t\t(total, progress) => total + progress,\n\t\t\t0\n\t\t);\n\t}\n\n\t#onProgress(progress: number, mode: ProgressMode, caption?: string) {\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tprogress,\n\t\t\t\t\tmode,\n\t\t\t\t\tcaption,\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n}\n","/**\n * Options for customizing the progress tracker.\n */\nexport interface ProgressTrackerOptions {\n\t/** The weight of the progress, a number between 0 and 1. */\n\tweight?: number;\n\t/** The caption to display during progress, a string. */\n\tcaption?: string;\n\t/** The time in milliseconds to fill the progress, a number. */\n\tfillTime?: number;\n}\n\n/**\n * Custom event providing information about a loading process.\n */\nexport type LoadingEvent = CustomEvent<{\n\t/** The number representing how much was loaded. */\n\tloaded: number;\n\t/** The number representing how much needs to loaded in total. */\n\ttotal: number;\n}>;\n\n/**\n * Custom event providing progress details.\n */\nexport type ProgressTrackerEvent = CustomEvent<ProgressDetails>;\n\n/**\n * Custom event providing progress details when the task is done.\n */\nexport type DoneEvent = CustomEvent<ProgressDetails>;\n\nexport interface ProgressDetails {\n\t/** The progress percentage as a number between 0 and 100. */\n\tprogress: number;\n\t/** The caption to display during progress, a string. */\n\tcaption: string;\n}\n\n/**\n * ProgressObserver A function that receives progress updates.\n *\n * @param progress The progress percentage as a number between 0 and 100.\n */\ntype ProgressObserver = (progress: number) => void;\n\n/**\n * Listener A function for handling specific event types.\n *\n * @param event The event of type T.\n */\nexport type Listener<T> = (event: T) => void;\n\nexport type TSCompatibleListener<T> =\n\t| EventListenerOrEventListenerObject\n\t| null\n\t| Listener<T>;\n\nexport interface ProgressReceiver {\n\tsetProgress(details: ProgressDetails): any;\n\tsetLoaded(): any;\n}\n\n/*\n * Like Number.EPSILON, but better tuned to tracking progress.\n *\n * With Number.EPSILON, progress like 99.99999999999997 is still\n * considered to be below 100 – this is highly undeisrable.\n */\nconst PROGRESS_EPSILON = 0.00001;\n\n/**\n * The ProgressTracker class is a tool for tracking progress in an operation\n * that is divided into multiple stages. It allows you to create sub-trackers\n * for each stage, with individual weights and captions. The main tracker\n * automatically calculates the progress based on the weighted sum of each\n * sub-tracker's progress. This makes it easy to keep track of a complex,\n * multi-stage process and report progress in a user-friendly way.\n *\n * After creating the sub-trackers, you can call the set() method to update the\n * progress of the current stage. You can also call the finish() method to mark\n * the current stage as complete and move on to the next one. Alternatively,\n * you can call the fillSlowly() method to simulate progress filling up slowly\n * to 100% before calling finish().\n *\n * @example\n * ```ts\n * const tracker = new ProgressTracker();\n * tracker.addEventListener('progress', (e) => {\n * \t\tconsole.log(\n * \t\t\t\te.detail.progress,\n * \t\t\t\te.detail.caption\n * \t\t);\n * });\n *\n * const stage1 = tracker.stage(0.5, 'Calculating pi digits');\n * const stage2 = tracker.stage(0.5, 'Downloading data');\n *\n * stage1.fillSlowly();\n * await calc100DigitsOfPi();\n * stage1.finish();\n *\n * await fetchWithProgress(function onProgress(loaded, total) {\n * \t\tstage2.set( loaded / total * 100);\n * });\n * stage2.finish();\n */\nexport class ProgressTracker extends EventTarget {\n\tprivate _selfWeight = 1;\n\tprivate _selfDone = false;\n\tprivate _selfProgress = 0;\n\tprivate _selfCaption = '';\n\tprivate _weight: number;\n\tprivate _progressObserver?: ProgressObserver;\n\tprivate _loadingListener?: Listener<LoadingEvent>;\n\tprivate _isFilling = false;\n\tprivate _fillTime: number;\n\tprivate _fillInterval?: any;\n\tprivate _subTrackers: ProgressTracker[] = [];\n\n\tconstructor({\n\t\tweight = 1,\n\t\tcaption = '',\n\t\tfillTime = 4,\n\t}: ProgressTrackerOptions = {}) {\n\t\tsuper();\n\t\tthis._weight = weight;\n\t\tthis._selfCaption = caption;\n\t\tthis._fillTime = fillTime;\n\t}\n\n\t/**\n\t * Creates a new sub-tracker with a specific weight.\n\t *\n\t * The weight determines what percentage of the overall progress\n\t * the sub-tracker represents. For example, if the main tracker is\n\t * monitoring a process that has two stages, and the first stage\n\t * is expected to take twice as long as the second stage, you could\n\t * create the first sub-tracker with a weight of 0.67 and the second\n\t * sub-tracker with a weight of 0.33.\n\t *\n\t * The caption is an optional string that describes the current stage\n\t * of the operation. If provided, it will be used as the progress caption\n\t * for the sub-tracker. If not provided, the main tracker will look for\n\t * the next sub-tracker with a non-empty caption and use that as the progress\n\t * caption instead.\n\t *\n\t * Returns the newly-created sub-tracker.\n\t *\n\t * @throws {Error} If the weight of the new stage would cause the total weight of all stages to exceed 1.\n\t *\n\t * @param weight The weight of the new stage, as a decimal value between 0 and 1.\n\t * @param caption The caption for the new stage, which will be used as the progress caption for the sub-tracker.\n\t *\n\t * @example\n\t * ```ts\n\t * const tracker = new ProgressTracker();\n\t * const subTracker1 = tracker.stage(0.67, 'Slow stage');\n\t * const subTracker2 = tracker.stage(0.33, 'Fast stage');\n\t *\n\t * subTracker2.set(50);\n\t * subTracker1.set(75);\n\t * subTracker2.set(100);\n\t * subTracker1.set(100);\n\t * ```\n\t */\n\tstage(weight?: number, caption = ''): ProgressTracker {\n\t\tif (!weight) {\n\t\t\tweight = this._selfWeight;\n\t\t}\n\t\tif (this._selfWeight - weight < -PROGRESS_EPSILON) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot add a stage with weight ${weight} as the total weight of registered stages would exceed 1.`\n\t\t\t);\n\t\t}\n\t\tthis._selfWeight -= weight;\n\n\t\tconst subTracker = new ProgressTracker({\n\t\t\tcaption,\n\t\t\tweight,\n\t\t\tfillTime: this._fillTime,\n\t\t});\n\t\tthis._subTrackers.push(subTracker);\n\t\tsubTracker.addEventListener('progress', () => this.notifyProgress());\n\t\tsubTracker.addEventListener('done', () => {\n\t\t\tif (this.done) {\n\t\t\t\tthis.notifyDone();\n\t\t\t}\n\t\t});\n\t\treturn subTracker;\n\t}\n\n\t/**\n\t * Fills the progress bar slowly over time, simulating progress.\n\t *\n\t * The progress bar is filled in a 100 steps, and each step, the progress\n\t * is increased by 1. If `stopBeforeFinishing` is true, the progress bar\n\t * will stop filling when it reaches 99% so that you can call `finish()`\n\t * explicitly.\n\t *\n\t * If the progress bar is filling or already filled, this method does nothing.\n\t *\n\t * @example\n\t * ```ts\n\t * const progress = new ProgressTracker({ caption: 'Processing...' });\n\t * progress.fillSlowly();\n\t * ```\n\t *\n\t * @param options Optional options.\n\t */\n\tfillSlowly({ stopBeforeFinishing = true } = {}): void {\n\t\tif (this._isFilling) {\n\t\t\treturn;\n\t\t}\n\t\tthis._isFilling = true;\n\t\tconst steps = 100;\n\t\tconst interval = this._fillTime / steps;\n\t\tthis._fillInterval = setInterval(() => {\n\t\t\tthis.set(this._selfProgress + 1);\n\t\t\tif (stopBeforeFinishing && this._selfProgress >= 99) {\n\t\t\t\tclearInterval(this._fillInterval);\n\t\t\t}\n\t\t}, interval);\n\t}\n\n\tset(value: number): void {\n\t\tthis._selfProgress = Math.min(value, 100);\n\t\tthis.notifyProgress();\n\t\tif (this._selfProgress + PROGRESS_EPSILON >= 100) {\n\t\t\tthis.finish();\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this._fillInterval) {\n\t\t\tclearInterval(this._fillInterval);\n\t\t}\n\t\tthis._selfDone = true;\n\t\tthis._selfProgress = 100;\n\t\tthis._isFilling = false;\n\t\tthis._fillInterval = undefined;\n\t\tthis.notifyProgress();\n\t\tthis.notifyDone();\n\t}\n\n\tget caption(): string {\n\t\tfor (let i = this._subTrackers.length - 1; i >= 0; i--) {\n\t\t\tif (!this._subTrackers[i].done) {\n\t\t\t\tconst captionMaybe = this._subTrackers[i].caption;\n\t\t\t\tif (captionMaybe) {\n\t\t\t\t\treturn captionMaybe;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this._selfCaption;\n\t}\n\n\tsetCaption(caption: string) {\n\t\tthis._selfCaption = caption;\n\t\tthis.notifyProgress();\n\t}\n\n\tget done(): boolean {\n\t\treturn this.progress + PROGRESS_EPSILON >= 100;\n\t}\n\n\tget progress(): number {\n\t\tif (this._selfDone) {\n\t\t\treturn 100;\n\t\t}\n\t\tconst sum = this._subTrackers.reduce(\n\t\t\t(sum, tracker) => sum + tracker.progress * tracker.weight,\n\t\t\tthis._selfProgress * this._selfWeight\n\t\t);\n\t\treturn Math.round(sum * 10000) / 10000;\n\t}\n\n\tget weight(): number {\n\t\treturn this._weight;\n\t}\n\n\tget observer() {\n\t\tif (!this._progressObserver) {\n\t\t\tthis._progressObserver = (progress: number) => {\n\t\t\t\tthis.set(progress);\n\t\t\t};\n\t\t}\n\t\treturn this._progressObserver;\n\t}\n\n\tget loadingListener() {\n\t\tif (!this._loadingListener) {\n\t\t\tthis._loadingListener = (event: LoadingEvent) => {\n\t\t\t\tthis.set((event.detail.loaded / event.detail.total) * 100);\n\t\t\t};\n\t\t}\n\t\treturn this._loadingListener;\n\t}\n\n\tpipe(receiver: ProgressReceiver) {\n\t\treceiver.setProgress({\n\t\t\tprogress: this.progress,\n\t\t\tcaption: this.caption,\n\t\t});\n\t\tthis.addEventListener('progress', (event: ProgressTrackerEvent) => {\n\t\t\treceiver.setProgress({\n\t\t\t\tprogress: event.detail.progress,\n\t\t\t\tcaption: event.detail.caption,\n\t\t\t});\n\t\t});\n\t\tthis.addEventListener('done', () => {\n\t\t\treceiver.setLoaded();\n\t\t});\n\t}\n\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.addEventListener(type, listener as any);\n\t}\n\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: TSCompatibleListener<ProgressTrackerEvent>\n\t) {\n\t\tsuper.removeEventListener(type, listener as any);\n\t}\n\n\tprivate notifyProgress() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent('progress', {\n\t\t\t\tdetail: {\n\t\t\t\t\tget progress() {\n\t\t\t\t\t\treturn self.progress;\n\t\t\t\t\t},\n\t\t\t\t\tget caption() {\n\t\t\t\t\t\treturn self.caption;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t);\n\t}\n\n\tprivate notifyDone() {\n\t\tthis.dispatchEvent(new CustomEvent('done'));\n\t}\n}\n"],"names":["FALLBACK_FILE_SIZE","EmscriptenDownloadMonitor","__privateAdd","_EmscriptenDownloadMonitor_instances","_assetsSizes","_progress","assets","urlLike","size","dummyBaseUrl","filename","__privateGet","fetchPromise","response","cloneResponseMonitorProgress","event","__privateMethod","notify_fn","file","loaded","fileSize","fileName","logger","sumValues","obj","length","value","onProgress","contentLength","cloneStreamMonitorProgress","stream","total","notify","controller","reader","done","e","ProgressObserver","_ProgressObserver_instances","_observedProgresses","_lastObserverId","__privateSet","progressBudget","caption","id","__privateWrapper","progress","onProgress_fn","mode","PROGRESS_EPSILON","ProgressTracker","weight","fill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ACK,UAAA,oBAAoBD,GAAMC,CAAe;AAAA,EAAA;AAAA,EAGxC,iBAAiB;AAExB,UAAMC,IAAO;AACR,SAAA;AAAA,MACJ,IAAI,YAAY,YAAY;AAAA,QAC3B,QAAQ;AAAA,UACP,IAAI,WAAW;AACd,mBAAOA,EAAK;AAAA,UACb;AAAA,UACA,IAAI,UAAU;AACb,mBAAOA,EAAK;AAAA,UAAA;AAAA,QACb;AAAA,MAED,CAAA;AAAA,IACF;AAAA,EAAA;AAAA,EAGO,aAAa;AACpB,SAAK,cAAc,IAAI,YAAY,MAAM,CAAC;AAAA,EAAA;AAE5C;"}
@@ -27,7 +27,7 @@ export interface DownloadProgress {
27
27
  */
28
28
  loaded: number;
29
29
  /**
30
- * The total number of bytes to load.
30
+ * The length number of bytes to load.
31
31
  */
32
32
  total: number;
33
33
  }
@@ -41,4 +41,15 @@ export interface DownloadProgress {
41
41
  * @returns The cloned response
42
42
  */
43
43
  export declare function cloneResponseMonitorProgress(response: Response, onProgress: (event: CustomEvent<DownloadProgress>) => void): Response;
44
+ /**
45
+ * Clones a ReadableStream and returns a version
46
+ * that calls the `onProgress` callback as the #progress
47
+ * changes.
48
+ *
49
+ * @param stream The ReadableStream to clone.
50
+ * @param total The total number of bytes to load.
51
+ * @param onProgress The callback to call when the download #progress changes.
52
+ * @returns The cloned ReadableStream
53
+ */
54
+ export declare function cloneStreamMonitorProgress(stream: ReadableStream<Uint8Array> | null, total: number, onProgress: (event: CustomEvent<DownloadProgress>) => void): ReadableStream<Uint8Array>;
44
55
  export type DownloadProgressCallback = (progress: DownloadProgress) => void;
@@ -1,4 +1,4 @@
1
- import { DownloadProgress } from './emscripten-download-monitor';
1
+ import type { DownloadProgress } from './emscripten-download-monitor';
2
2
  export type ProgressMode =
3
3
  /**
4
4
  * Real-time progress is used when we get real-time reports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "1.0.29",
3
+ "version": "1.1.1",
4
4
  "description": "PHP.wasm – loading progress monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,21 +21,36 @@
21
21
  "displayName": "@php-wasm/progress",
22
22
  "tsconfig": "./tsconfig.lib.json"
23
23
  },
24
+ "exports": {
25
+ ".": {
26
+ "import": "./index.js",
27
+ "require": "./index.cjs"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
24
31
  "publishConfig": {
25
32
  "access": "public",
26
33
  "directory": "../../../dist/packages/php-wasm/progress"
27
34
  },
28
35
  "license": "GPL-2.0-or-later",
29
36
  "type": "module",
30
- "main": "index.js",
37
+ "main": "./index.cjs",
38
+ "module": "./index.js",
31
39
  "types": "index.d.ts",
32
- "gitHead": "173e69f62e1b43bd7353b875054bb1ef5e394de8",
40
+ "gitHead": "8bff9428d68d3c4a5e84c6cd633e82bf8512a4e3",
33
41
  "engines": {
34
- "node": ">=18.18.0",
35
- "npm": ">=8.11.0"
42
+ "node": ">=20.18.3",
43
+ "npm": ">=10.1.0"
44
+ },
45
+ "overrides": {
46
+ "rollup": "^4.34.6",
47
+ "react": "18.3.1",
48
+ "react-dom": "18.3.1",
49
+ "typescript": "5.4.5",
50
+ "ws": "^8.18.0"
36
51
  },
37
52
  "dependencies": {
38
- "@php-wasm/node-polyfills": "1.0.29",
39
- "@php-wasm/logger": "1.0.29"
53
+ "@php-wasm/node-polyfills": "1.1.1",
54
+ "@php-wasm/logger": "1.1.1"
40
55
  }
41
- }
56
+ }