@margoengine/worker 0.1.0 → 1.0.0
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 +201 -201
- package/NOTICE +4 -4
- package/README.md +275 -84
- package/dist/canvas.js +2 -2
- package/package.json +61 -61
package/LICENSE
CHANGED
|
@@ -1,201 +1,201 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2026 Scott Campbell
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Scott Campbell
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Margo Engine
|
|
2
|
-
Copyright 2026 Scott Campbell
|
|
3
|
-
|
|
4
|
-
This product includes Margo Engine (https://margoengine.com) by Scott Campbell.
|
|
1
|
+
Margo Engine
|
|
2
|
+
Copyright 2026 Scott Campbell
|
|
3
|
+
|
|
4
|
+
This product includes Margo Engine (https://margoengine.com) by Scott Campbell.
|
package/README.md
CHANGED
|
@@ -1,84 +1,275 @@
|
|
|
1
|
-
# @margoengine/worker
|
|
2
|
-
|
|
3
|
-
Runs the engine inside a Web Worker on an `OffscreenCanvas`, so a heavy scene never blocks the page's main thread and a busy page never stalls the scene. The helper moves the canvas and keeps the worker told of the page's canvas: its size, position, pixel ratio and visibility, and the input events the worker listens for. Core needs no change and no option: `Engine.create`, `engine.pick`, the frame loop, control packages and the `@margoengine/webgl2-compat/preview` fallback run on the received canvas as they do on the page.
|
|
4
|
-
|
|
5
|
-
Two entries, one per side. `@margoengine/worker` goes in the page and `@margoengine/worker/canvas` in the worker, so neither side downloads the other's code.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
// page.ts
|
|
9
|
-
import { transferCanvas, workerCanvasSupported } from '@margoengine/worker';
|
|
10
|
-
|
|
11
|
-
const canvas = document.querySelector('canvas')!;
|
|
12
|
-
if (!workerCanvasSupported()) throw new Error('Run the scene on the page here');
|
|
13
|
-
const worker = new Worker(new URL('./scene-worker.js', import.meta.url), { type: 'module' });
|
|
14
|
-
const view = await transferCanvas(canvas, worker, { data: { level: 'plaza' } });
|
|
15
|
-
|
|
16
|
-
// Later: `view.dispose()` disposes the engine in the worker, then the worker is yours to end.
|
|
17
|
-
addEventListener('pagehide', () => {
|
|
18
|
-
view.dispose();
|
|
19
|
-
worker.terminate();
|
|
20
|
-
});
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
// scene-worker.ts
|
|
25
|
-
import { box, Engine, PbrMaterial } from '@margoengine/core';
|
|
26
|
-
import { OrbitControls } from '@margoengine/controls';
|
|
27
|
-
import { receiveCanvas } from '@margoengine/worker/canvas';
|
|
28
|
-
|
|
29
|
-
const received = await receiveCanvas();
|
|
30
|
-
const engine = await Engine.create(received.canvas);
|
|
31
|
-
received.attach(engine);
|
|
32
|
-
engine.createMesh().setGeometry(box()).setMaterial(new PbrMaterial({ color: '#84d6bd' }));
|
|
33
|
-
const controls = new OrbitControls(engine.camera, received.canvas);
|
|
34
|
-
engine.onFrame((_, delta) => controls.update(delta));
|
|
35
|
-
engine.start();
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Page side
|
|
39
|
-
|
|
40
|
-
`transferCanvas(canvas, worker, options)` resolves with a `WorkerCanvas` once the worker holds the canvas. Either side may start first.
|
|
41
|
-
|
|
42
|
-
| Option | Default | Meaning |
|
|
43
|
-
| --- | --- | --- |
|
|
44
|
-
| `data` | `undefined` | Anything structured clone accepts, read in the worker as `received.data`. |
|
|
45
|
-
| `transfer` | `[]` | Objects in `data` to transfer instead of copy. |
|
|
46
|
-
| `signal` | none | Aborts the wait. A canvas that had not moved yet stays usable. |
|
|
47
|
-
| `timeout` | `30000` | Milliseconds to wait for the worker to call `receiveCanvas`. |
|
|
48
|
-
|
|
49
|
-
It rejects with a `MargoError` whose `code` is `unsupported` (the browser cannot move a canvas), `state` (the canvas has a context or already moved), `failed` (the worker's script failed) or `timeout`.
|
|
50
|
-
|
|
51
|
-
`view.dispose()`, or `using`, stops forwarding, aborts `received.signal` and disposes an engine that used `received`. A canvas cannot come back from a worker, and the worker keeps running until you call `worker.terminate()`. `workerCanvasSupported()` says whether the browser can do this at all.
|
|
52
|
-
|
|
53
|
-
Your own `worker.postMessage` traffic is left alone: the link runs on a `MessageChannel` of its own after a short handshake whose messages carry the key `margo-worker-canvas`. Errors in the worker reach `worker.addEventListener('error', ...)`; the engine's default `onError` reports them there.
|
|
54
|
-
|
|
55
|
-
## Worker side
|
|
56
|
-
|
|
57
|
-
`receiveCanvas({signal, timeout})` resolves with a `ReceivedCanvas`:
|
|
58
|
-
|
|
59
|
-
| Member | Meaning |
|
|
60
|
-
| --- | --- |
|
|
61
|
-
| `canvas` | The `OffscreenCanvas`, with `clientWidth`, `clientHeight`, `getBoundingClientRect`, `style` and the pointer capture methods of the page's canvas. Typed as an element, so it passes to `Engine.create` and to controls. |
|
|
62
|
-
| `data` | The page's `data` option. |
|
|
63
|
-
| `hidden` | True while the page is hidden. |
|
|
64
|
-
| `signal` | Aborts when the page disposes its end. |
|
|
65
|
-
|
|
66
|
-
`received.attach(engine)` makes the first frame after a background tab step 0, as on the page, and lets the page dispose the engine.
|
|
67
|
-
|
|
68
|
-
The page posts a size only when it differs from what the worker holds, so an unchanged resize costs no message; the frame loop runs in the worker and the page does no work per frame.
|
|
69
|
-
|
|
70
|
-
Because `clientWidth` follows the page and the page's `devicePixelRatio` and `margoLow` are copied to the worker, the engine picks the same drawing-buffer size as on the page, and `engine.pick` takes CSS pixels. With `exactSize` the worker owns `canvas.width` and `canvas.height`.
|
|
71
|
-
|
|
72
|
-
Input events arrive on `received.canvas`, as plain events with the values of the real ones (`clientX`, `pointerId`, `deltaY`, `key`, ...). The page only forwards a type once something in the worker listens for it. Pointer, mouse, wheel, click, context menu and focus events come from the canvas; key events come from the document, since an unfocused canvas gets none, and they land on `received.canvas`, which is where controls listen when an element has no document. A `style` written in the worker (`touchAction`, `cursor`) is set on the page's canvas.
|
|
73
|
-
|
|
74
|
-
## What differs from the page
|
|
75
|
-
|
|
76
|
-
- `event.preventDefault()` in a worker comes too late to change anything. The page stops the default of `wheel` and `contextmenu` for you once the worker listens for them, and of nothing else, so keys keep their browser meaning.
|
|
77
|
-
- The page captures the pointer on every `pointerdown` the worker listens for, so a drag goes on outside the canvas. `setPointerCapture` in the worker only records it.
|
|
78
|
-
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
# @margoengine/worker
|
|
2
|
+
|
|
3
|
+
Runs the engine inside a Web Worker on an `OffscreenCanvas`, so a heavy scene never blocks the page's main thread and a busy page never stalls the scene. The helper moves the canvas and keeps the worker told of the page's canvas: its size, position, pixel ratio and visibility, and the input events the worker listens for. Core needs no change and no option: `Engine.create`, `engine.pick`, the frame loop, control packages and the `@margoengine/webgl2-compat/preview` fallback run on the received canvas as they do on the page.
|
|
4
|
+
|
|
5
|
+
Two entries, one per side. `@margoengine/worker` goes in the page and `@margoengine/worker/canvas` in the worker, so neither side downloads the other's code.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
// page.ts
|
|
9
|
+
import { transferCanvas, workerCanvasSupported } from '@margoengine/worker';
|
|
10
|
+
|
|
11
|
+
const canvas = document.querySelector('canvas')!;
|
|
12
|
+
if (!workerCanvasSupported()) throw new Error('Run the scene on the page here');
|
|
13
|
+
const worker = new Worker(new URL('./scene-worker.js', import.meta.url), { type: 'module' });
|
|
14
|
+
const view = await transferCanvas(canvas, worker, { data: { level: 'plaza' } });
|
|
15
|
+
|
|
16
|
+
// Later: `view.dispose()` disposes the engine in the worker, then the worker is yours to end.
|
|
17
|
+
addEventListener('pagehide', () => {
|
|
18
|
+
view.dispose();
|
|
19
|
+
worker.terminate();
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// scene-worker.ts
|
|
25
|
+
import { box, Engine, PbrMaterial } from '@margoengine/core';
|
|
26
|
+
import { OrbitControls } from '@margoengine/controls';
|
|
27
|
+
import { receiveCanvas } from '@margoengine/worker/canvas';
|
|
28
|
+
|
|
29
|
+
const received = await receiveCanvas();
|
|
30
|
+
const engine = await Engine.create(received.canvas);
|
|
31
|
+
received.attach(engine);
|
|
32
|
+
engine.createMesh().setGeometry(box()).setMaterial(new PbrMaterial({ color: '#84d6bd' }));
|
|
33
|
+
const controls = new OrbitControls(engine.camera, received.canvas);
|
|
34
|
+
engine.onFrame((_, delta) => controls.update(delta));
|
|
35
|
+
engine.start();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Page side
|
|
39
|
+
|
|
40
|
+
`transferCanvas(canvas, worker, options)` resolves with a `WorkerCanvas` once the worker holds the canvas. Either side may start first.
|
|
41
|
+
|
|
42
|
+
| Option | Default | Meaning |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| `data` | `undefined` | Anything structured clone accepts, read in the worker as `received.data`. |
|
|
45
|
+
| `transfer` | `[]` | Objects in `data` to transfer instead of copy. |
|
|
46
|
+
| `signal` | none | Aborts the wait. A canvas that had not moved yet stays usable. |
|
|
47
|
+
| `timeout` | `30000` | Milliseconds to wait for the worker to call `receiveCanvas`. |
|
|
48
|
+
|
|
49
|
+
It rejects with a `MargoError` whose `code` is `unsupported` (the browser cannot move a canvas), `state` (the canvas has a context or already moved), `failed` (the worker's script failed) or `timeout`.
|
|
50
|
+
|
|
51
|
+
`view.dispose()`, or `using`, stops forwarding, aborts `received.signal` and disposes an engine that used `received`. A canvas cannot come back from a worker, and the worker keeps running until you call `worker.terminate()`. `workerCanvasSupported()` says whether the browser can do this at all.
|
|
52
|
+
|
|
53
|
+
Your own `worker.postMessage` traffic is left alone: the link runs on a `MessageChannel` of its own after a short handshake whose messages carry the key `margo-worker-canvas`. Errors in the worker reach `worker.addEventListener('error', ...)`; the engine's default `onError` reports them there.
|
|
54
|
+
|
|
55
|
+
## Worker side
|
|
56
|
+
|
|
57
|
+
`receiveCanvas({signal, timeout})` resolves with a `ReceivedCanvas`:
|
|
58
|
+
|
|
59
|
+
| Member | Meaning |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `canvas` | The `OffscreenCanvas`, with `clientWidth`, `clientHeight`, `getBoundingClientRect`, `style` and the pointer capture methods of the page's canvas. Typed as an element, so it passes to `Engine.create` and to controls. |
|
|
62
|
+
| `data` | The page's `data` option. |
|
|
63
|
+
| `hidden` | True while the page is hidden. |
|
|
64
|
+
| `signal` | Aborts when the page disposes its end. |
|
|
65
|
+
|
|
66
|
+
`received.attach(engine)` makes the first frame after a background tab step 0, as on the page, and lets the page dispose the engine.
|
|
67
|
+
|
|
68
|
+
The page posts a size only when it differs from what the worker holds, so an unchanged resize costs no message; the frame loop runs in the worker and the page does no work per frame.
|
|
69
|
+
|
|
70
|
+
Because `clientWidth` follows the page and the page's `devicePixelRatio` and `margoLow` are copied to the worker, the engine picks the same drawing-buffer size as on the page, and `engine.pick` takes CSS pixels. With `exactSize` the worker owns `canvas.width` and `canvas.height`.
|
|
71
|
+
|
|
72
|
+
Input events arrive on `received.canvas`, as plain events with the values of the real ones (`clientX`, `pointerId`, `deltaY`, `key`, ...). The page only forwards a type once something in the worker listens for it. Pointer, mouse, wheel, click, context menu and focus events come from the canvas; key events come from the document, since an unfocused canvas gets none, and they land on `received.canvas`, which is where controls listen when an element has no document. A `style` written in the worker (`touchAction`, `cursor`) is set on the page's canvas.
|
|
73
|
+
|
|
74
|
+
## What differs from the page
|
|
75
|
+
|
|
76
|
+
- `event.preventDefault()` in a worker comes too late to change anything. The page stops the default of `wheel` and `contextmenu` for you once the worker listens for them, and of nothing else, so keys keep their browser meaning.
|
|
77
|
+
- The page captures the pointer on every `pointerdown` the worker listens for, so a drag goes on outside the canvas. `setPointerCapture` in the worker only records it.
|
|
78
|
+
- `document` and the rest of the DOM stay on the page. Pointer lock works from the worker; see below.
|
|
79
|
+
|
|
80
|
+
## Pointer lock from the worker
|
|
81
|
+
|
|
82
|
+
The received canvas has `requestPointerLock(options)`, `exitPointerLock()` and `pointerLockElement`, and fires
|
|
83
|
+
`pointerlockchange` and `pointerlockerror`, so `PointerLockControls` from `@margoengine/controls` works on it as it
|
|
84
|
+
does on a page canvas: the worker asks, and the page takes the lock on the real canvas.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
// lock-page.ts
|
|
88
|
+
import { transferCanvas } from '@margoengine/worker';
|
|
89
|
+
|
|
90
|
+
const canvas = document.createElement('canvas');
|
|
91
|
+
document.body.append(canvas);
|
|
92
|
+
const worker = new Worker(new URL('./lock-worker.js', import.meta.url), { type: 'module' });
|
|
93
|
+
using view = await transferCanvas(canvas, worker); // nothing else to do on the page for pointer lock
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
// lock-worker.ts
|
|
98
|
+
import { receiveCanvas } from '@margoengine/worker/canvas';
|
|
99
|
+
import { Engine } from 'margoengine/core';
|
|
100
|
+
import { PointerLockControls } from 'margoengine/controls';
|
|
101
|
+
|
|
102
|
+
const view = await receiveCanvas();
|
|
103
|
+
const engine = await Engine.create(view.canvas, { backend: 'webgpu' });
|
|
104
|
+
view.attach(engine);
|
|
105
|
+
const controls = new PointerLockControls(engine.camera, view.canvas);
|
|
106
|
+
view.canvas.addEventListener('click', () => controls.lock()); // a forwarded click asks the page for the lock
|
|
107
|
+
view.canvas.addEventListener('pointerlockchange', () => console.log('locked:', view.pointerLocked));
|
|
108
|
+
view.canvas.addEventListener('keydown', async (event) => {
|
|
109
|
+
if ((event as KeyboardEvent).code !== 'KeyL') return;
|
|
110
|
+
try {
|
|
111
|
+
await view.requestPointerLock({ unadjustedMovement: true, timeout: 5000 }); // raw mouse, where offered
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.log('no lock:', (error as { code?: string }).code); // failed, timeout or unsupported
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
engine.start();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- **Activation.** Browsers lock only shortly after a real user gesture on the page (transient activation). Ask from
|
|
120
|
+
a forwarded `click`, `pointerdown` or `keydown` listener, so the request reaches the page while that gesture still
|
|
121
|
+
counts; a request without one is refused with `pointerlockerror`, and the promise rejects with code `failed`. A
|
|
122
|
+
browser without pointer lock rejects with `unsupported`.
|
|
123
|
+
- **State.** `view.pointerLocked` (and `pointerLockElement`) follows the page's native lock events, so it turns false
|
|
124
|
+
when the user presses Escape. `exitPointerLock()` releases this canvas's lock only.
|
|
125
|
+
- **Raw input.** `unadjustedMovement: true` asks for mouse movement without OS acceleration where the browser offers
|
|
126
|
+
it; a browser that refuses it rejects, and nothing retries without it.
|
|
127
|
+
- **Deadlines and cancellation.** `timeout` (default 10,000 ms) and `signal` bound the wait for an answer from the
|
|
128
|
+
page (code `timeout`, or the signal's reason); they do not withdraw a permission prompt the browser is showing.
|
|
129
|
+
The same request on the page side is `workerCanvas.requestPointerLock(options)`, from `transferCanvas`.
|
|
130
|
+
- **Disposal.** When either end is disposed, waiting requests reject and the worker sends no more lock messages.
|
|
131
|
+
|
|
132
|
+
Tested in `tests/pointer-lock.test.js` and the worker browser check (`npm run test:gpu`).
|
|
133
|
+
- `mount` from `@margoengine/stage` builds its canvas in a page. In a worker create the engine and pass it to `new Stage(engine)`.
|
|
134
|
+
- Input reaches the worker one message later, and a worker stuck in a long task reads it when the task ends.
|
|
135
|
+
|
|
136
|
+
## One scene, worker or page (`@margoengine/worker/auto`)
|
|
137
|
+
|
|
138
|
+
`runScene(canvas, moduleURL, options)` runs a scene module in a worker when the browser can draw there, and on the
|
|
139
|
+
page when it cannot, with the same code either way. The module exports `createScene(context)`; there is no page
|
|
140
|
+
script and worker script to keep in step.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
// spin-scene.ts
|
|
144
|
+
import { Engine } from 'margoengine/core';
|
|
145
|
+
import type { SceneContext } from 'margoengine/worker/auto';
|
|
146
|
+
|
|
147
|
+
export async function createScene({ canvas, data, signal, mode, attach }: SceneContext) {
|
|
148
|
+
const engine = await Engine.create(canvas, { backend: 'webgpu' });
|
|
149
|
+
attach(engine); // sizes, visibility and disposal follow the page's canvas
|
|
150
|
+
console.log(`running on the ${mode}`, (data as { level: string }).level);
|
|
151
|
+
engine.start();
|
|
152
|
+
return { dispose: () => engine.dispose() }; // called once; signal is aborted first
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
// page.ts
|
|
158
|
+
import { runScene } from 'margoengine/worker/auto';
|
|
159
|
+
|
|
160
|
+
const canvas = document.createElement('canvas');
|
|
161
|
+
document.body.append(canvas);
|
|
162
|
+
await using scene = await runScene(canvas, new URL('./spin-scene.js', import.meta.url), {
|
|
163
|
+
data: { level: 'plaza' },
|
|
164
|
+
signal: AbortSignal.timeout(60_000), // stops startup, and the scene, when it aborts
|
|
165
|
+
});
|
|
166
|
+
console.log(scene.mode, scene.fallbackReason); // 'worker' undefined, or 'page' and the reason the worker was refused
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
- **`SceneContext`** is the same on both threads: `canvas` (the page's canvas, or in a worker the forwarded
|
|
170
|
+
`OffscreenCanvas` with the size, events and visibility of the page's), `data`, `signal` (aborted when the scene
|
|
171
|
+
stops), `mode` (`'worker'` or `'page'`) and `attach(engine)`, which ties an engine to the canvas's lifetime so it
|
|
172
|
+
is disposed with the scene. `createScene` returns a `SceneInstance`, `{ dispose() }`, synchronous or async.
|
|
173
|
+
- **`mode`.** `'auto'` (default) probes a worker first and uses the page if it cannot draw; `'worker'` refuses
|
|
174
|
+
instead of falling back; `'page'` never starts a worker. `backend` (`'auto'`, `'webgpu'` or `'webgl2'`) is what the
|
|
175
|
+
worker probe asks for: it needs `OffscreenCanvas`, that renderer and `requestAnimationFrame` in the worker. The
|
|
176
|
+
probe runs before the canvas is transferred, so a refused worker leaves the page's canvas usable for the page
|
|
177
|
+
path, and `fallbackReason` keeps the refusal.
|
|
178
|
+
- **Module URL.** Pass a `URL` the browser can import from both the page and the worker, normally
|
|
179
|
+
`new URL('./scene.js', import.meta.url)`, which bundlers emit as its own chunk.
|
|
180
|
+
- **The generic worker.** The worker script ships inside this package (`dist/workers/scene.js`, started with
|
|
181
|
+
`new Worker(new URL(..., import.meta.url), { type: 'module' })`, so bundlers copy it) and loads only when a worker
|
|
182
|
+
is tried. A page whose Content-Security-Policy does not allow that URL as a worker can host a copy itself and pass
|
|
183
|
+
`worker: () => new Worker('/static/scene-worker.js', { type: 'module' })`; the scene owns that worker and
|
|
184
|
+
terminates it.
|
|
185
|
+
- **Data.** `data` is structured-cloned into a worker and passed as is on the page. `transfer` moves its buffers
|
|
186
|
+
into the worker instead of copying them (on the page path they stay yours, untouched).
|
|
187
|
+
- **Deadlines and cancellation.** `timeout` (milliseconds, default 30,000) bounds the startup, and each worker call
|
|
188
|
+
during cleanup; past it the start rejects with code `timeout`. `signal` cancels a startup that is still running
|
|
189
|
+
(everything made so far is cleaned up, even a scene that finishes starting after you left) and, once running,
|
|
190
|
+
disposes the scene; a cleanup failure then is sent to the canvas as an `error` event.
|
|
191
|
+
- **Disposal.** `await using`, or `await scene.dispose()`, aborts the scene's `signal`, runs its `dispose` once,
|
|
192
|
+
disposes attached engines and ends the worker even when cleanup throws. `disposed` tells whether that started.
|
|
193
|
+
- **Errors.** A module without `createScene` is refused with code `state`; an error thrown while the scene runs is
|
|
194
|
+
reported, never retried.
|
|
195
|
+
|
|
196
|
+
## Typed calls to a worker (`@margoengine/worker/rpc`)
|
|
197
|
+
|
|
198
|
+
For work that is not a scene (decoding, a navmesh build, a solver), `/rpc` turns a worker's functions into typed
|
|
199
|
+
promises. `exposeRpc(handlers, endpoint)` serves named functions on a worker, a `MessagePort` or the worker's own
|
|
200
|
+
global scope (the default); `RpcClient<T>` calls them by name with the argument and result types of `T`; `RpcPool<T>`
|
|
201
|
+
spreads calls over a fixed number of workers. It needs no build step and no second package.
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { exposeRpc, RpcClient, rpcTransfer, type RpcHandlers } from '@margoengine/worker/rpc';
|
|
205
|
+
|
|
206
|
+
interface Maths {
|
|
207
|
+
sum(values: Float64Array): number;
|
|
208
|
+
scaled(values: Float64Array, by: number): Float64Array;
|
|
209
|
+
}
|
|
210
|
+
// Here both ends share one page through a MessageChannel; in an app, `exposeRpc(handlers)` runs in the worker
|
|
211
|
+
// and `new RpcClient<Maths>(worker)` on the page.
|
|
212
|
+
const { port1, port2 } = new MessageChannel();
|
|
213
|
+
const handlers: RpcHandlers<Maths> = {
|
|
214
|
+
sum: (values, { progress }) => {
|
|
215
|
+
progress('started');
|
|
216
|
+
return values.reduce((a, b) => a + b, 0);
|
|
217
|
+
},
|
|
218
|
+
scaled: (values, by) => {
|
|
219
|
+
for (let i = 0; i < values.length; i++) values[i] *= by;
|
|
220
|
+
return rpcTransfer(values, [values.buffer]); // move the buffer back instead of copying it
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
using server = exposeRpc(handlers, port1);
|
|
224
|
+
using client = new RpcClient<Maths>(port2);
|
|
225
|
+
|
|
226
|
+
console.log(await client.call('sum', [new Float64Array([1, 2, 3])], { onProgress: console.log })); // started, then 6
|
|
227
|
+
const input = new Float64Array([1, 2]);
|
|
228
|
+
const out = await client.call('scaled', [input, 10], { transfer: [input.buffer] });
|
|
229
|
+
console.log([...out], input.length); // [10, 20] 0: the input buffer moved to the worker and back
|
|
230
|
+
port1.close();
|
|
231
|
+
port2.close();
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
- **Handlers.** Only the handlers object's own function properties can be called; any other name rejects with
|
|
235
|
+
MargoError code `state`. Each handler gets the call's arguments and then a context: `signal`, aborted when the
|
|
236
|
+
caller cancels or the server is disposed, and `progress(value, transfer?)`, which sends a message the caller's
|
|
237
|
+
`onProgress` receives in order before the result. A handler may return a value, a promise, or
|
|
238
|
+
`rpcTransfer(value, transferables)` to move buffers back instead of copying them. A thrown error reaches the caller
|
|
239
|
+
as an `Error` with the same `name`, `message`, `code` and `stack`; a result that cannot be cloned rejects that call
|
|
240
|
+
only.
|
|
241
|
+
- **Ownership.** `RpcClient` and `exposeRpc` never take the endpoint: disposing either removes its listeners and
|
|
242
|
+
leaves the worker or port to you. Many clients can share one endpoint; their call ids never collide. `RpcPool`
|
|
243
|
+
makes its workers with the factory you give it and terminates them on `dispose()`. Input buffers move only with
|
|
244
|
+
`transfer` in the call's options, and only when the call is sent: a pooled call cancelled while it waits keeps its
|
|
245
|
+
buffers on your side.
|
|
246
|
+
- **Cancellation.** `signal` in the call's options rejects with the signal's reason and tells the handler, whose
|
|
247
|
+
`signal` aborts. Cancellation is cooperative: a handler must look at its `signal` (or yield) to stop early. An
|
|
248
|
+
exception thrown by `onProgress` rejects the call and cancels it.
|
|
249
|
+
- **Deadlines.** `timeout` (milliseconds, default 30,000) is a hard limit per call. A client whose call misses it is
|
|
250
|
+
closed, every pending call rejects with code `timeout`, and you make a new client: a worker that does not answer in
|
|
251
|
+
time is treated as stuck. A worker `error` or `messageerror` closes the client the same way, with code `failed`.
|
|
252
|
+
- **Pool.** `new RpcPool<T>(index => new Worker(url, { type: 'module' }), { size, maxQueue })`: `size` workers
|
|
253
|
+
(default 2), first in first out, at most `maxQueue` waiting calls (default 1024; running calls do not count). A call
|
|
254
|
+
past that rejects at once with code `state`, so a producer can wait before adding more. A queued call's `timeout` counts
|
|
255
|
+
its time in the queue; one that waits too long rejects with `timeout`. A pooled worker that times out or fails
|
|
256
|
+
disposes the pool. `size` and `queued` report the pool. A cancelled running call keeps its worker busy until the
|
|
257
|
+
handler returns.
|
|
258
|
+
- **Disposal.** `client.dispose()` rejects pending calls with code `state` and asks their handlers to stop; the
|
|
259
|
+
server's `dispose()` aborts its running handlers and answers them with code `state`; `pool.dispose()` rejects queued
|
|
260
|
+
and running calls and ends its workers. All three are idempotent and work with `using`.
|
|
261
|
+
|
|
262
|
+
## Browser support
|
|
263
|
+
|
|
264
|
+
The worker needs `HTMLCanvasElement.transferControlToOffscreen`, and in the worker `OffscreenCanvas`, `requestAnimationFrame` and WebGPU or WebGL2. `@margoengine/worker/auto` checks all of them and draws on the page when one is missing, so keep your scene behind `runScene` (or a page path behind `workerCanvasSupported()`) and it runs everywhere.
|
|
265
|
+
|
|
266
|
+
| Browser (Windows 11, RTX A6000) | Canvas transfer, worker OffscreenCanvas, worker rAF | Worker WebGL2 | Worker WebGPU | What `runScene` did |
|
|
267
|
+
| --- | --- | --- | --- | --- |
|
|
268
|
+
| Chromium (bundled Playwright build) | yes | yes | yes | worker, WebGPU and WebGL2 (`npm run test:gpu`) |
|
|
269
|
+
| Playwright Firefox 157, default profile (2026-11-29) | yes | yes | no adapter | worker on WebGL2: buffer transferred, centre pixel [213, 26, 1, 255], disposed |
|
|
270
|
+
| Playwright WebKit 27.2 for Windows (2026-11-29) | no | no | no | page fallback (`fallbackReason.code` `'unsupported'`): buffer kept, same centre pixel, disposed |
|
|
271
|
+
| Safari on macOS or iOS | not run | not run | not run | not run |
|
|
272
|
+
|
|
273
|
+
- **How to run it.** `node packages/worker/tests/browser-matrix.mjs --browser=firefox` (or `webkit`, `chromium`) draws the shared WebGL2 scene through `runScene`, asserts the path it picked from the capabilities it found, the pixel and the disposal, and writes `test-results/worker-matrix-<browser>.json`. `--browser` names the engine exactly: an unknown name throws `TypeError('Unsupported browser')` before anything launches, and the receipt's `hardware.browserName` and `browserVersion` come from the launched browser, never from the user agent. `npm run test:browser:matrix` in this package runs it on Chromium.
|
|
274
|
+
- **Firefox WebGPU.** Playwright's Firefox build gives no WebGPU adapter in a worker or on the page with its default profile, so the full `browser-check.mjs --browser=firefox` suite stops at its required worker WebGPU step; its assertions are not loosened for it. Worker WebGL2 is proved on Firefox; worker WebGPU on Firefox is not.
|
|
275
|
+
- **WebKit is not Safari.** Playwright's WebKit for Windows is a separate build: its Safari user agent and `Apple GPU` renderer string do not make it Safari, and the receipt records `nativeSafari: false`. It proves the page fallback only. Native Safari on Apple hardware has not been run, so no Safari claim is made (`docs/limits.md`).
|
package/dist/canvas.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
4
|
import { n as e, t } from "./errors-CDgOgzCd.js";
|
|
@@ -118,7 +118,7 @@ var n = "margo-worker-canvas", r = () => globalThis, i = class {
|
|
|
118
118
|
this.dispose(), e && !e.disposed && e.dispose();
|
|
119
119
|
}
|
|
120
120
|
attach(e) {
|
|
121
|
-
return e.use({coreRequirement:/*@__PURE__*/__margoCoreRequirement("
|
|
121
|
+
return e.use({coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
|
|
122
122
|
name: "worker-canvas",
|
|
123
123
|
setup() {},
|
|
124
124
|
dispose: () => this.dispose()
|
package/package.json
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@margoengine/worker",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Runs Margo Engine in a Web Worker on an OffscreenCanvas: canvas transfer, resize, pixel ratio and input forwarding, so heavy scenes never block the page.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"margoengine",
|
|
7
|
-
"webgpu",
|
|
8
|
-
"worker",
|
|
9
|
-
"offscreencanvas",
|
|
10
|
-
"threads"
|
|
11
|
-
],
|
|
12
|
-
"homepage": "https://margoengine.com",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
19
|
-
"directory": "packages/worker"
|
|
20
|
-
},
|
|
21
|
-
"license": "Apache-2.0",
|
|
22
|
-
"author": "Scott Campbell",
|
|
23
|
-
"type": "module",
|
|
24
|
-
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "node ../../scripts/build-optional.js worker",
|
|
29
|
-
"test": "npm run build && node --test tests/*.test.js",
|
|
30
|
-
"test:gpu": "cd ../.. && node packages/worker/tests/browser-check.mjs",
|
|
31
|
-
"prepack": "npm run build",
|
|
32
|
-
"test:browser:matrix": "cd ../.. && node packages/worker/tests/browser-matrix.mjs --browser=chromium"
|
|
33
|
-
},
|
|
34
|
-
"sideEffects": false,
|
|
35
|
-
"exports": {
|
|
36
|
-
".": {
|
|
37
|
-
"types": "./dist/index.d.ts",
|
|
38
|
-
"import": "./dist/index.js"
|
|
39
|
-
},
|
|
40
|
-
"./canvas": {
|
|
41
|
-
"types": "./dist/canvas.d.ts",
|
|
42
|
-
"import": "./dist/canvas.js"
|
|
43
|
-
},
|
|
44
|
-
"./rpc": {
|
|
45
|
-
"types": "./dist/rpc.d.ts",
|
|
46
|
-
"import": "./dist/rpc.js"
|
|
47
|
-
},
|
|
48
|
-
"./auto": {
|
|
49
|
-
"types": "./dist/auto.d.ts",
|
|
50
|
-
"import": "./dist/auto.js"
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
"files": [
|
|
54
|
-
"dist",
|
|
55
|
-
"LICENSE",
|
|
56
|
-
"NOTICE"
|
|
57
|
-
],
|
|
58
|
-
"peerDependencies": {
|
|
59
|
-
"@margoengine/core": "^
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@margoengine/worker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Runs Margo Engine in a Web Worker on an OffscreenCanvas: canvas transfer, resize, pixel ratio and input forwarding, so heavy scenes never block the page.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"margoengine",
|
|
7
|
+
"webgpu",
|
|
8
|
+
"worker",
|
|
9
|
+
"offscreencanvas",
|
|
10
|
+
"threads"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://margoengine.com",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
19
|
+
"directory": "packages/worker"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"author": "Scott Campbell",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node ../../scripts/build-optional.js worker",
|
|
29
|
+
"test": "npm run build && node --test tests/*.test.js",
|
|
30
|
+
"test:gpu": "cd ../.. && node packages/worker/tests/browser-check.mjs",
|
|
31
|
+
"prepack": "npm run build",
|
|
32
|
+
"test:browser:matrix": "cd ../.. && node packages/worker/tests/browser-matrix.mjs --browser=chromium"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./canvas": {
|
|
41
|
+
"types": "./dist/canvas.d.ts",
|
|
42
|
+
"import": "./dist/canvas.js"
|
|
43
|
+
},
|
|
44
|
+
"./rpc": {
|
|
45
|
+
"types": "./dist/rpc.d.ts",
|
|
46
|
+
"import": "./dist/rpc.js"
|
|
47
|
+
},
|
|
48
|
+
"./auto": {
|
|
49
|
+
"types": "./dist/auto.d.ts",
|
|
50
|
+
"import": "./dist/auto.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"LICENSE",
|
|
56
|
+
"NOTICE"
|
|
57
|
+
],
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@margoengine/core": "^1.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|