@motionscript/plot 0.0.0-stage → 0.1.0-alpha.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/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/dist/browser/chunks/chunk-RCFWYW6O.js +2 -0
- package/dist/browser/chunks/chunk-RCFWYW6O.js.map +7 -0
- package/dist/browser/index.js +84 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +12 -0
- package/dist/engine.d.ts +14 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +14 -0
- package/dist/engine.js.map +1 -0
- package/dist/graph2d/curve-cache.d.ts +60 -0
- package/dist/graph2d/curve-cache.d.ts.map +1 -0
- package/dist/graph2d/curve-cache.js +79 -0
- package/dist/graph2d/curve-cache.js.map +1 -0
- package/dist/graph2d/curve-error.d.ts +12 -0
- package/dist/graph2d/curve-error.d.ts.map +1 -0
- package/dist/graph2d/curve-error.js +15 -0
- package/dist/graph2d/curve-error.js.map +1 -0
- package/dist/graph2d/curve.d.ts +104 -0
- package/dist/graph2d/curve.d.ts.map +1 -0
- package/dist/graph2d/curve.js +531 -0
- package/dist/graph2d/curve.js.map +1 -0
- package/dist/graph2d/graph2d.d.ts +164 -0
- package/dist/graph2d/graph2d.d.ts.map +1 -0
- package/dist/graph2d/graph2d.js +404 -0
- package/dist/graph2d/graph2d.js.map +1 -0
- package/dist/graph2d/index.d.ts +32 -0
- package/dist/graph2d/index.d.ts.map +1 -0
- package/dist/graph2d/index.js +32 -0
- package/dist/graph2d/index.js.map +1 -0
- package/dist/graph2d/plane-fill.d.ts +110 -0
- package/dist/graph2d/plane-fill.d.ts.map +1 -0
- package/dist/graph2d/plane-fill.js +248 -0
- package/dist/graph2d/plane-fill.js.map +1 -0
- package/dist/graph2d/plane.d.ts +179 -0
- package/dist/graph2d/plane.d.ts.map +1 -0
- package/dist/graph2d/plane.js +359 -0
- package/dist/graph2d/plane.js.map +1 -0
- package/dist/graph2d/shared.d.ts +40 -0
- package/dist/graph2d/shared.d.ts.map +1 -0
- package/dist/graph2d/shared.js +70 -0
- package/dist/graph2d/shared.js.map +1 -0
- package/dist/graph3d/expression.d.ts +30 -0
- package/dist/graph3d/expression.d.ts.map +1 -0
- package/dist/graph3d/expression.js +35 -0
- package/dist/graph3d/expression.js.map +1 -0
- package/dist/graph3d/graph3d.d.ts +186 -0
- package/dist/graph3d/graph3d.d.ts.map +1 -0
- package/dist/graph3d/graph3d.js +404 -0
- package/dist/graph3d/graph3d.js.map +1 -0
- package/dist/graph3d/index.d.ts +22 -0
- package/dist/graph3d/index.d.ts.map +1 -0
- package/dist/graph3d/index.js +22 -0
- package/dist/graph3d/index.js.map +1 -0
- package/dist/graph3d/shared.d.ts +61 -0
- package/dist/graph3d/shared.d.ts.map +1 -0
- package/dist/graph3d/shared.js +101 -0
- package/dist/graph3d/shared.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/equations.d.ts +56 -0
- package/dist/kit/equations.d.ts.map +1 -0
- package/dist/kit/equations.js +63 -0
- package/dist/kit/equations.js.map +1 -0
- package/dist/kit/expression.d.ts +60 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +268 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/index.d.ts +15 -0
- package/dist/kit/index.d.ts.map +1 -0
- package/dist/kit/index.js +13 -0
- package/dist/kit/index.js.map +1 -0
- package/dist/nodes.d.ts +19 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +19 -0
- package/dist/nodes.js.map +1 -0
- package/package.json +68 -3
- package/registry.json +34 -0
- package/src/engine.ts +13 -0
- package/src/graph2d/curve-cache.ts +103 -0
- package/src/graph2d/curve-error.ts +19 -0
- package/src/graph2d/curve.ts +657 -0
- package/src/graph2d/graph2d.ts +586 -0
- package/src/graph2d/index.ts +31 -0
- package/src/graph2d/plane-fill.ts +308 -0
- package/src/graph2d/plane.ts +457 -0
- package/src/graph2d/shared.ts +103 -0
- package/src/graph3d/expression.ts +51 -0
- package/src/graph3d/graph3d.ts +614 -0
- package/src/graph3d/index.ts +21 -0
- package/src/graph3d/shared.ts +143 -0
- package/src/index.ts +3 -0
- package/src/kit/equations.ts +102 -0
- package/src/kit/expression.ts +323 -0
- package/src/kit/index.ts +29 -0
- package/src/nodes.ts +19 -0
- package/README.md +0 -4
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +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 [yyyy] [name of copyright owner]
|
|
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.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{expressionOps as y}from"@motionscript/core";var h=["x","y"],M=["x"],u={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,sqrt:Math.sqrt,cbrt:Math.cbrt,abs:Math.abs,exp:Math.exp,log:Math.log,ln:Math.log,log2:Math.log2,log10:Math.log10,floor:Math.floor,ceil:Math.ceil,round:Math.round,sign:Math.sign,trunc:Math.trunc},E={atan2:Math.atan2,pow:Math.pow,hypot:Math.hypot,min:Math.min,max:Math.max,mod:(n,e)=>n%e},R={atan2:[2,2],pow:[2,2],mod:[2,2],hypot:[1,1/0],min:[1,1/0],max:[1,1/0]},A={pi:Math.PI,PI:Math.PI,e:Math.E,E:Math.E,tau:Math.PI*2,phi:(1+Math.sqrt(5))/2},x={functions:{...Object.fromEntries(Object.keys(u).map(n=>[n,{arity:[1,1]}])),...Object.fromEntries(Object.entries(R).map(([n,e])=>[n,{arity:e}]))},constants:A,refs:"bare",unknownName:n=>`Unknown identifier '${n}'`},g={functions:[...Object.keys(u),...Object.keys(E)].sort(),constants:["pi","e","tau","phi"]};function m(n){return{variables:n,...g}}var w=m(h),d=m(M);function l(n,e=h){for(let t of e)if(t in A)throw new Error(`'${t}' is a constant, so it cannot also be a free variable`);return p(y.parse(n,x).root,e)}function p(n,e){switch(n.kind){case"const":{let{value:t}=n;return()=>t}case"ref":{let t=e.indexOf(n.name);if(t===0)return a=>a;if(t===1)return(a,r)=>r;throw new Error(x.unknownName(n.name))}case"unary":{let t=p(n.operand,e);return(a,r)=>-t(a,r)}case"binary":{let t=p(n.left,e),a=p(n.right,e);switch(n.op){case"+":return(r,o)=>t(r,o)+a(r,o);case"-":return(r,o)=>t(r,o)-a(r,o);case"*":return(r,o)=>t(r,o)*a(r,o);case"/":return(r,o)=>t(r,o)/a(r,o);case"%":return(r,o)=>t(r,o)%a(r,o);case"^":return(r,o)=>Math.pow(t(r,o),a(r,o))}break}case"call":{let t=n.args.map(o=>p(o,e)),a=u[n.name];if(a){let[o]=t;return(c,s)=>a(o(c,s))}let r=E[n.name];if(t.length===2){let[o,c]=t;return(s,i)=>r(o(s,i),c(s,i))}return(o,c)=>r(...t.map(s=>s(o,c)))}}throw new Error("Unsupported expression node")}function O(n,e=h){let t=n.trim();if(t==="")return null;try{return l(t,e),null}catch(a){return a instanceof Error?a.message:String(a)}}var f=new Map;function S(n,e=h){let t=n.trim();if(t==="")return null;let a=e.join(","),r=f.get(a);r||(r=new Map,f.set(a,r));let o=r.get(t);if(o!==void 0)return o;let c;try{c=l(t,e)}catch{c=null}return r.set(t,c),c}import{lerpNumber as C}from"@motionscript/core";import{lerpColor3D as I}from"@motionscript/core/component";function V(n,e,t,a){if(t<=0)return n;if(t>=1)return e;let r=new Map(e.map(s=>[s.id,s])),o=n.map(s=>{let i=r.get(s.id);return i?N(s,i,t,a):{...s,opacity:s.opacity*(1-t)}}),c=new Set(n.map(s=>s.id));for(let s of e)c.has(s.id)||o.push({...s,opacity:s.opacity*t});return o}function N(n,e,t,a){return{id:e.id,sample:n.sample===e.sample?e.sample:a(n.sample,e.sample,t),color:I(n.color,e.color,t),opacity:C(n.opacity,e.opacity,t)}}export{h as a,M as b,m as c,w as d,d as e,l as f,O as g,S as h,V as i};
|
|
2
|
+
//# sourceMappingURL=chunk-RCFWYW6O.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/kit/expression.ts", "../../../src/kit/equations.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The little language every graph node's equation tiles are written in — the\n * one binding behind `z = f(x, y)` on the 3D graph and `y = f(x)` on the 2D one.\n *\n * **The grammar is not here.** It is `expressionOps.parse` in\n * `@motionscript/core`, shared with the `\"=4[g]+3\"` expressions a scene\n * document writes in props. There used to be two parsers, and they agreed on\n * every rule they documented while disagreeing everywhere they hadn't: this one\n * scanned `1.2.3` as a single token that `Number` turned into a `NaN` which\n * parsed, compiled and rendered an invisible surface with no diagnostic\n * anywhere; it treated `\\r` as an unexpected character; and it checked no arity\n * on its variadic functions, so `atan2(1)` was a silent `NaN` too.\n *\n * What is genuinely this language's own is a **dialect** and a back end:\n *\n * - {@link PLOT_DIALECT} — trig in **radians** (a plot of `sin(x)` is a plot of\n * `sin(x)`, where a document's `rotation` is in degrees like every other angle\n * in the library), the hyperbolics and log bases a plot wants, `phi`, and\n * references spelled as bare identifiers rather than `[id]`.\n * - {@link compileExpression} — the emitter, which turns the shared AST into a\n * two-argument closure rather than into the signal binding a document prop\n * needs.\n *\n * **Deliberately not `new Function(...)`.** An expression is a value typed into\n * the inspector, stored in a scene document and shared with whoever opens it\n * next; compiling it as JavaScript would make every scene file an execution\n * vector. The shared parser accepts a fixed grammar and can only ever produce\n * arithmetic.\n *\n * ## Which letters are variables is the caller's business\n *\n * What differs between the two graphs is *how many free variables there are*,\n * and that matters more than it sounds. A 2D curve compiled with `x` alone\n * rejects `y` as an unknown identifier, so typing `y = x + y` says so in the\n * tile instead of silently plotting `x` — and a caller cannot forget to check,\n * because the check is the same one that catches `alert(1)`.\n */\nimport { expressionOps } from \"@motionscript/core\"\nimport type { ExpressionDialect, ExpressionNode } from \"@motionscript/core\"\n\n/**\n * A compiled expression: pure, and safe to call thousands of times per frame.\n *\n * Always two arguments regardless of how many variables it was compiled with,\n * because the arity is a *parse-time* fact and the signature is a hot path — a\n * variadic form would allocate an array per sample. A one-variable expression\n * simply never reads the second, so a curve calls it as `sample(x, 0)`.\n */\nexport type CompiledExpression = (x: number, y: number) => number\n\n/** The two free variables a `z = f(x, y)` surface is sampled over. */\nexport const SURFACE_VARIABLES = [\"x\", \"y\"] as const\n\n/** The one free variable a `y = f(x)` curve is sampled over. */\nexport const CURVE_VARIABLES = [\"x\"] as const\n\n/**\n * The names bound to the two argument slots, in order.\n *\n * At most two, because {@link CompiledExpression} has two argument slots — see\n * the note there on why that is fixed rather than variadic.\n */\nexport type ExpressionVariables = readonly string[]\n\n/** Single-argument functions available to an expression. */\nconst UNARY_FNS: Record<string, (v: number) => number> = {\n sin: Math.sin,\n cos: Math.cos,\n tan: Math.tan,\n asin: Math.asin,\n acos: Math.acos,\n atan: Math.atan,\n sinh: Math.sinh,\n cosh: Math.cosh,\n tanh: Math.tanh,\n sqrt: Math.sqrt,\n cbrt: Math.cbrt,\n abs: Math.abs,\n exp: Math.exp,\n log: Math.log,\n ln: Math.log,\n log2: Math.log2,\n log10: Math.log10,\n floor: Math.floor,\n ceil: Math.ceil,\n round: Math.round,\n sign: Math.sign,\n trunc: Math.trunc,\n}\n\n/** Multi-argument functions. */\nconst NARY_FNS: Record<string, (...args: number[]) => number> = {\n atan2: Math.atan2,\n pow: Math.pow,\n hypot: Math.hypot,\n min: Math.min,\n max: Math.max,\n mod: (a, b) => a % b,\n}\n\n/**\n * How many arguments each of {@link NARY_FNS} takes.\n *\n * Written from what this language already accepts, not copied from core's table:\n * `hypot(3)` and `min(3)` are meaningful and have always compiled, so they stay\n * `[1, Infinity]` where the document dialect has `hypot: [2, Infinity]`. What\n * the arity check is actually for is the other end — `atan2(1)` and `min()`\n * used to compile to a silent `NaN` and an `Infinity`, which rendered as\n * nothing at all and said nothing about why.\n */\nconst NARY_ARITY: Record<string, [number, number]> = {\n atan2: [2, 2],\n pow: [2, 2],\n mod: [2, 2],\n hypot: [1, Infinity],\n min: [1, Infinity],\n max: [1, Infinity],\n}\n\nconst CONSTANTS: Record<string, number> = {\n pi: Math.PI,\n PI: Math.PI,\n e: Math.E,\n E: Math.E,\n tau: Math.PI * 2,\n phi: (1 + Math.sqrt(5)) / 2,\n}\n\n/** The equation language, as a dialect of the shared grammar. */\nexport const PLOT_DIALECT: ExpressionDialect = {\n functions: {\n ...Object.fromEntries(\n Object.keys(UNARY_FNS).map((name) => [name, { arity: [1, 1] as [number, number] }])\n ),\n ...Object.fromEntries(\n Object.entries(NARY_ARITY).map(([name, arity]) => [name, { arity }])\n ),\n },\n constants: CONSTANTS,\n refs: \"bare\",\n unknownName: (name) => `Unknown identifier '${name}'`,\n}\n\n/** Everything an expression may name, minus the variables. */\nconst NAMEABLE = {\n functions: [...Object.keys(UNARY_FNS), ...Object.keys(NARY_FNS)].sort(),\n /** Lower-case spellings only; `PI`/`E` are accepted but not advertised twice. */\n constants: [\"pi\", \"e\", \"tau\", \"phi\"] as const,\n}\n\n/** What a tile's help popover lists, for a node with these free variables. */\nexport interface ExpressionVocabulary {\n variables: readonly string[]\n functions: readonly string[]\n constants: readonly string[]\n}\n\n/**\n * Everything an expression over `variables` may name, for the inspector's\n * \"what can I write here\" hint.\n *\n * Derived from the parser's own tables rather than re-listed on the client, so\n * the help can never claim a function the grammar doesn't have — which is the\n * way this kind of reference always rots.\n */\nexport function expressionVocabulary(\n variables: ExpressionVariables\n): ExpressionVocabulary {\n return { variables, ...NAMEABLE }\n}\n\n/** {@link expressionVocabulary} for the 3D graph's `z = f(x, y)` surfaces. */\nexport const EXPRESSION_VOCABULARY = expressionVocabulary(SURFACE_VARIABLES)\n\n/** {@link expressionVocabulary} for the 2D graph's `y = f(x)` curves. */\nexport const CURVE_VOCABULARY = expressionVocabulary(CURVE_VARIABLES)\n\n/**\n * Compiles `source` into a callable over `variables`. Throws on a syntax error,\n * so a caller rendering user-typed text should catch and skip that equation —\n * see {@link compileExpressionCached}, which does exactly that.\n */\nexport function compileExpression(\n source: string,\n variables: ExpressionVariables = SURFACE_VARIABLES\n): CompiledExpression {\n // The parser folds a constant before it will yield a reference, so a name that\n // is both would silently stop being the variable it was passed as.\n for (const name of variables) {\n if (name in CONSTANTS) {\n throw new Error(`'${name}' is a constant, so it cannot also be a free variable`)\n }\n }\n return emit(expressionOps.parse(source, PLOT_DIALECT).root, variables)\n}\n\n/** The shared AST into this language's two-argument closure. */\nfunction emit(\n node: ExpressionNode,\n variables: ExpressionVariables\n): CompiledExpression {\n switch (node.kind) {\n case \"const\": {\n const { value } = node\n return () => value\n }\n case \"ref\": {\n // Which argument slot this name reads, or -1 for a name that isn't a\n // variable *here* — the whole point of taking the list: `y` in a curve is\n // an unknown identifier, not a silent zero.\n const slot = variables.indexOf(node.name)\n if (slot === 0) return (x) => x\n if (slot === 1) return (_x, y) => y\n throw new Error(PLOT_DIALECT.unknownName(node.name))\n }\n case \"unary\": {\n const operand = emit(node.operand, variables)\n return (x, y) => -operand(x, y)\n }\n case \"binary\": {\n const l = emit(node.left, variables)\n const r = emit(node.right, variables)\n switch (node.op) {\n case \"+\": return (x, y) => l(x, y) + r(x, y)\n case \"-\": return (x, y) => l(x, y) - r(x, y)\n case \"*\": return (x, y) => l(x, y) * r(x, y)\n case \"/\": return (x, y) => l(x, y) / r(x, y)\n case \"%\": return (x, y) => l(x, y) % r(x, y)\n case \"^\": return (x, y) => Math.pow(l(x, y), r(x, y))\n }\n break\n }\n case \"call\": {\n const args = node.args.map((arg) => emit(arg, variables))\n const unary = UNARY_FNS[node.name]\n if (unary) {\n const [a] = args\n return (x, y) => unary(a(x, y))\n }\n const nary = NARY_FNS[node.name]\n // Specialise the common arity so the hot path doesn't allocate an array\n // per sample.\n if (args.length === 2) {\n const [a, b] = args\n return (x, y) => nary(a(x, y), b(x, y))\n }\n return (x, y) => nary(...args.map((arg) => arg(x, y)))\n }\n }\n throw new Error(\"Unsupported expression node\")\n}\n\n/**\n * Why an expression won't compile, in the terms the tile shows: the message and\n * nothing else. `null` means it compiles.\n *\n * Separate from {@link compileExpressionCached} because the two callers want\n * opposite things — the renderer wants the function or nothing, the inspector\n * wants the *reason* — and both must agree, which they do by going through the\n * same parser.\n */\nexport function expressionError(\n source: string,\n variables: ExpressionVariables = SURFACE_VARIABLES\n): string | null {\n const trimmed = source.trim()\n // Empty is not an error: it is a tile nobody has filled in yet, which the\n // panel already shows as a placeholder rather than as a mistake.\n if (trimmed === \"\") return null\n try {\n compileExpression(trimmed, variables)\n return null\n } catch (error) {\n return error instanceof Error ? error.message : String(error)\n }\n}\n\n/**\n * Compiles with memoisation, returning `null` for anything that doesn't parse.\n *\n * Both halves matter here. A node's builder re-runs every frame, so an uncached\n * compile would re-parse every equation sixty times a second; and the inspector\n * commits on every keystroke, so half-typed source reaches the renderer\n * constantly and must be *skipped* rather than thrown out of the render pass.\n *\n * The cache is also what makes the equation tween cheap: equal source compiles\n * to the identical closure, so \"did this equation change\" is an `===`. Note it\n * stores a failure as `null` and tests `hit !== undefined`, so unparseable\n * source is not re-parsed on every frame either.\n *\n * Keyed by the variable list as well as the source, because the same text means\n * different things under different bindings — `x + y` compiles for a surface and\n * is an error for a curve, and one cache would hand the surface's answer to the\n * curve that asked second.\n */\nconst caches = new Map<string, Map<string, CompiledExpression | null>>()\n\nexport function compileExpressionCached(\n source: string,\n variables: ExpressionVariables = SURFACE_VARIABLES\n): CompiledExpression | null {\n const trimmed = source.trim()\n if (trimmed === \"\") return null\n\n const key = variables.join(\",\")\n let cache = caches.get(key)\n if (!cache) {\n cache = new Map()\n caches.set(key, cache)\n }\n\n const hit = cache.get(trimmed)\n if (hit !== undefined) return hit\n\n let compiled: CompiledExpression | null\n try {\n compiled = compileExpression(trimmed, variables)\n } catch {\n compiled = null\n }\n cache.set(trimmed, compiled)\n return compiled\n}\n", "/**\n * What a resolved equation is, and how a list of them interpolates — shared by\n * both graph nodes because the answer doesn't depend on how many dimensions the\n * marks are drawn in.\n *\n * The tween is the part worth sharing. Matching two lists by `id` is what makes\n * an equation that stays *morph* rather than pop, one that leaves fade out as\n * itself, and one that arrives fade in; getting that wrong is invisible until\n * somebody animates an equation list, at which point every surface deforms into\n * its neighbour. One implementation, one set of tests.\n *\n * What is *not* shared is how two sampled functions blend into one — a surface\n * blends `f(x, y)` and a curve blends `f(x)` — so that is the one thing a caller\n * passes in. See `graph3d/impl/shared` and `graph2d/impl/shared`, which are each\n * three lines because of it.\n */\n\nimport { lerpNumber, type NormalizedColor } from \"@motionscript/core\"\n\nimport { lerpColor3D } from \"@motionscript/core/component\"\n\n/**\n * One equation after a node's mapper has run: compiled, resolved and fully\n * defaulted, so the per-frame builder never re-derives anything and the tween\n * never tests for an absent field.\n *\n * Generic in the sampled function because that is the only part that differs:\n * `(x, y) => z` for a surface, `(x) => y` for a curve.\n */\nexport interface GraphEquationResolved<Sample> {\n id: string\n /** The compiled expression — compiled once at *write* time, not per sample. */\n sample: Sample\n color: NormalizedColor\n /** `enabled: false` is folded in here as 0, so hiding is a fade. */\n opacity: number\n}\n\n/**\n * How two sampled functions blend mid-tween.\n *\n * Handed in rather than inferred, and it must return a **fresh closure per\n * call** when the two differ: that freshness is what a node keyed on the\n * function's identity reads as \"this needs re-evaluating\" (see\n * `surfaceRevision`).\n */\nexport type BlendSample<Sample> = (a: Sample, b: Sample, t: number) => Sample\n\n/**\n * Tween for an equation list: match by `id`, then morph / fade in / fade out.\n *\n * Three outcomes, and each is the one that reads correctly:\n *\n * - present in both → the mark **morphs**, because its value is sampled from\n * both functions and blended, so it deforms into the new one rather than\n * popping;\n * - only in the old list → it fades out *still sampling its own expression*, so\n * it leaves as itself;\n * - only in the new list → it fades in.\n */\nexport function lerpGraphEquations<Sample>(\n from: GraphEquationResolved<Sample>[],\n to: GraphEquationResolved<Sample>[],\n t: number,\n blendSample: BlendSample<Sample>\n): GraphEquationResolved<Sample>[] {\n if (t <= 0) return from\n if (t >= 1) return to\n\n const arriving = new Map(to.map((equation) => [equation.id, equation]))\n const out: GraphEquationResolved<Sample>[] = from.map((a) => {\n const b = arriving.get(a.id)\n return b\n ? blendEquation(a, b, t, blendSample)\n : { ...a, opacity: a.opacity * (1 - t) }\n })\n\n const held = new Set(from.map((equation) => equation.id))\n for (const b of to) {\n if (!held.has(b.id)) out.push({ ...b, opacity: b.opacity * t })\n }\n return out\n}\n\n/** Interpolates one equation that exists on both sides of the tween. */\nfunction blendEquation<Sample>(\n a: GraphEquationResolved<Sample>,\n b: GraphEquationResolved<Sample>,\n t: number,\n blendSample: BlendSample<Sample>\n): GraphEquationResolved<Sample> {\n return {\n id: b.id,\n // Same id, different expression → morph the *geometry*. The double\n // evaluation is only paid mid-tween, and the identity check skips it\n // entirely when the source didn't change: the expression cache memoises by\n // source, so equal source is `===`.\n sample: a.sample === b.sample ? b.sample : blendSample(a.sample, b.sample, t),\n color: lerpColor3D(a.color, b.color, t),\n opacity: lerpNumber(a.opacity, b.opacity, t),\n }\n}\n"],
|
|
5
|
+
"mappings": "AAqCA,OAAS,iBAAAA,MAAqB,qBAcvB,IAAMC,EAAoB,CAAC,IAAK,GAAG,EAG7BC,EAAkB,CAAC,GAAG,EAW7BC,EAAmD,CACvD,IAAK,KAAK,IACV,IAAK,KAAK,IACV,IAAK,KAAK,IACV,KAAM,KAAK,KACX,KAAM,KAAK,KACX,KAAM,KAAK,KACX,KAAM,KAAK,KACX,KAAM,KAAK,KACX,KAAM,KAAK,KACX,KAAM,KAAK,KACX,KAAM,KAAK,KACX,IAAK,K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E,MAAOT,EAAYQ,EAAE,MAAOC,EAAE,MAAO,CAAC,EACtC,QAASV,EAAWS,EAAE,QAASC,EAAE,QAAS,CAAC,EAE/C",
|
|
6
|
+
"names": ["expressionOps", "SURFACE_VARIABLES", "CURVE_VARIABLES", "UNARY_FNS", "NARY_FNS", "a", "b", "NARY_ARITY", "CONSTANTS", "PLOT_DIALECT", "name", "arity", "NAMEABLE", "expressionVocabulary", "variables", "EXPRESSION_VOCABULARY", "CURVE_VOCABULARY", "compileExpression", "source", "emit", "node", "value", "slot", "x", "_x", "y", "operand", "l", "r", "args", "arg", "unary", "nary", "expressionError", "trimmed", "error", "caches", "compileExpressionCached", "key", "cache", "hit", "compiled", "lerpNumber", "lerpColor3D", "lerpGraphEquations", "from", "to", "blendSample", "arriving", "equation", "out", "a", "b", "blendEquation", "held"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import{a as F,b as R,d as Tt,f as ct,g as T,h as j,i as W}from"./chunks/chunk-RCFWYW6O.js";function K(){return{t:0,x:0,y:0,px:0,py:0,ok:!1}}var lt=[],N=0;function jt(){let t=lt[N];if(t!==void 0)return N++,t;let e=K();return lt.push(e),N++,e}function ht(t){return{remaining:12e4,pending:Math.max(1,t)}}function ft(t,e,o,n){let r=new J(o),i=o.left/e.scaleX,s=o.right/e.scaleX;if(!(s>i)||!(e.scaleX>0)||!(e.scaleY>0))return[];let a=Wt(o.right-o.left),c=(s-i)/a,u=n?Math.min(4e4,Math.max(2048,Math.floor(n.remaining/Math.max(1,n.pending)))):4e4,p=0,h=(l,f)=>{let d=e.centerX+f,M=t(d);p++;let y=Number.isFinite(M);return l.t=f,l.x=d,l.y=M,l.px=ut(f*e.scaleX),l.py=y?ut((M-e.centerY)*e.scaleY):0,l.ok=y,l},m=l=>h(jt(),l),E=(l,f)=>{let d=l,M=f.t;for(let y=0;y<60&&!(p>=u||Ut(d,o));y++){let z=(d.t+M)/2;if(z===d.t||z===M)break;let D=m(z);if(!D.ok){M=z;continue}let Rt=Math.abs(D.px-d.px)<.25&&Math.abs(D.py-d.py)<.25;if(d=D,Rt)break}return d},S=(l,f,d,M)=>{if(l.ok&&d.ok){if(M&&Ht(l,f,d,o)){r.break();return}r.draw(l,d);return}if(l.ok){let y=E(l,d);y.t!==l.t&&r.draw(l,y),r.break();return}if(d.ok){r.break();let y=E(d,l);y.t!==d.t?r.draw(y,d):r.start(d);return}r.break()},G=(l,f,d)=>{if(p>=u||r.points>=24e3){S(l,null,f,!1);return}let M=m((l.t+f.t)/2),y=d>=12||f.px-l.px<=.5;if(y||Yt(l,M,f)){S(l,M,f,y);return}G(l,M,d+1),G(M,f,d+1)},I=[K(),K()],X=h(I[0],i);for(let l=1;l<=a;l++){let f=h(I[l&1],l===a?s:i+l*c);N=0,G(X,f,0),X=f}return N=0,n&&(n.remaining=Math.max(0,n.remaining-p),n.pending=Math.max(0,n.pending-1)),r.finish()}function Wt(t){let e=Math.round(t/8);return Math.min(512,Math.max(64,e))}function Yt(t,e,o){if(t.ok!==e.ok||e.ok!==o.ok)return!1;if(!t.ok)return!0;let n=o.px-t.px,r=o.py-t.py,i=Math.hypot(n,r)||1;if(Math.abs((e.px-t.px)*r-(e.py-t.py)*n)/i>.25)return!1;let a=Math.atan2(e.py-t.py,e.px-t.px),c=Math.atan2(o.py-e.py,o.px-e.px),u=Math.abs(a-c);return u>Math.PI&&(u=2*Math.PI-u),u<.05}function Ht(t,e,o,n){return!Bt(t,o,n)||e===null?!1:e.ok?e.y<Math.min(t.y,o.y)||e.y>Math.max(t.y,o.y):!0}function Bt(t,e,o){return t.py>o.top&&e.py<o.bottom||t.py<o.bottom&&e.py>o.top}function Ut(t,e){return t.py>e.top||t.py<e.bottom}function ut(t){return t>16e3?16e3:t<-16e3?-16e3:t===0?0:t}var J=class{clip;runs=[];open=[];cursor=null;points=0;constructor(e){this.clip=e}draw(e,o){let n=$t(e.px,e.py,o.px,o.py,this.clip);if(!n){this.break();return}let[r,i]=n;this.cursor&&Vt(this.cursor,r)?this.push(i):(this.break(),this.push(r),this.push(i)),this.cursor=i}start(e){this.break(),Zt(e.px,e.py,this.clip)&&(this.push({x:e.px,y:e.py}),this.cursor={x:e.px,y:e.py})}break(){this.open.length>=2&&this.runs.push(this.open),this.open=[],this.cursor=null}finish(){return this.break(),this.runs}push(e){this.open.push(e),this.points++}};function Vt(t,e){return Math.abs(t.x-e.x)<.1&&Math.abs(t.y-e.y)<.1}function Zt(t,e,o){return t>=o.left&&t<=o.right&&e>=o.bottom&&e<=o.top}function $t(t,e,o,n,r){let i=o-t,s=n-e,a=0,c=1,u=[[-i,t-r.left],[i,r.right-t],[-s,e-r.bottom],[s,r.top-e]];for(let[p,h]of u){if(p===0){if(h<0)return null;continue}let m=h/p;if(p<0){if(m>c)return null;m>a&&(a=m)}else{if(m<a)return null;m<c&&(c=m)}}return[{x:t+a*i,y:e+a*s},{x:t+c*i,y:e+c*s}]}function dt(t,e){return`${t.centerX}|${t.centerY}|${t.scaleX}|${t.scaleY}|${e.left}|${e.right}|${e.bottom}|${e.top}`}var Y=class{entries=new Map;holds(e,o,n){let r=this.entries.get(e);return r!==void 0&&r.key===n&&r.sample===o}runs(e,o,n,r,i,s){let a=this.entries.get(e);if(a!==void 0&&a.key===n&&a.sample===o)return a.runs;let c=ft(o,r,i,s);return this.entries.set(e,{key:n,sample:o,runs:c}),c}retain(e){if(this.entries.size!==e.length)for(let o of this.entries.keys())e.includes(o)||this.entries.delete(o)}};function Ze(t){return T(t,R)}import{node as he,Clip as fe,Fills as rt,Graphics2D as nt,Node2D as de,clamp as st,lerpNumber as it,property as b}from"@motionscript/core";import{niceStep as qt}from"@motionscript/core/component";var pt=1e-200,Kt=1e200;function Mt(t,e,o){let n=Math.max(1,e),r=Math.max(1,o),i=O(t.xSpan),s=n/i,a=t.ySpan>0?O(t.ySpan):r/s,c=r/a;return{centerX:t.centerX,centerY:t.centerY,scaleX:s,scaleY:c,width:n,height:r,xMin:t.centerX-i/2,xMax:t.centerX+i/2,yMin:t.centerY-a/2,yMax:t.centerY+a/2,ySpan:a}}function O(t){return!Number.isFinite(t)||t<=0?pt:Math.min(Kt,Math.max(pt,t))}function yt(t){return{left:-t.width/2,right:t.width/2,bottom:-t.height/2,top:t.height/2}}function wt(t,e){return{left:t.left-e,right:t.right+e,bottom:t.bottom-e,top:t.top+e}}function Q(t,e){return(e-t.centerX)*t.scaleX}function tt(t,e){return(e-t.centerY)*t.scaleY}function Ke(t,e,o){return{...t,centerX:t.centerX+e,centerY:t.centerY+o}}function Je(t,e,o,n,r,i){let s=o===n&&t.ySpan<=0,a=O(e.xMax-e.xMin)*o,c=e.ySpan*n;return{centerX:t.centerX+(r-t.centerX)*(1-o),centerY:t.centerY+(i-t.centerY)*(1-n),xSpan:O(a),ySpan:s?0:O(c)}}var Jt=200,mt=Number.MAX_SAFE_INTEGER;function H(t){return Math.floor(Math.log10(t)+1e-12)}function B(t,e,o,n){if(!(e-t>0)||!(o>0))return{step:1,minorStep:1,divisions:1,major:[]};let i=qt(Math.max(n,1)/o),s=re(i);return{step:i,minorStep:i/s,divisions:s,major:ne(t,e,i)}}var Qt=.58,te=.8,ee=5;function _t(t,e,o,n){let r=n*ee,i=B(t,e,o,r),s=n*U(i);return s>r?B(t,e,o,s):i}function U(t){return Qt*oe(t)+te}function oe(t){let e=0;for(let o of t.major){let n=V(o,t.step).length;n>e&&(e=n)}return e}function re(t){let e=Math.pow(10,H(t));return Math.round(t/e)===2?4:5}function ne(t,e,o){let n=Math.ceil(t/o-1e-9),r=Math.floor(e/o+1e-9);if(!Number.isFinite(n)||!Number.isFinite(r))return[];if(Math.abs(n)>mt||Math.abs(r)>mt)return[];let i=r-n+1;if(i<=0||i>Jt)return[];let s=new Array(i);for(let a=0;a<i;a++)s[a]=(n+a)*o;return s}var ie=14,se=100;function V(t,e){if(t===0)return"0";if(!Number.isFinite(t))return"";if(!(e>0)||!Number.isFinite(e))return String(t);let o=H(Math.abs(t)),n=Math.max(1,o-H(e)+1);if((o>=6||o<=-5)&&n<=6)return xt(t.toExponential(n-1));if(n<=ie){let i=Math.min(se,Math.max(0,-H(e))),s=t.toFixed(i);return i>0?s.replace(/\.?0+$/,""):s}let r=Math.min(17,Math.max(0,n-1));return xt(t.toExponential(r))}function xt(t){let[e,o]=t.split("e");return`${e.replace(/\.?0+$/,"")}e${Number(o)}`}var St=`
|
|
2
|
+
uniform vec4 u_paper;
|
|
3
|
+
uniform vec4 u_minorColor;
|
|
4
|
+
uniform vec4 u_majorColor;
|
|
5
|
+
uniform vec4 u_axisColor;
|
|
6
|
+
uniform vec2 u_origin;
|
|
7
|
+
uniform vec2 u_pitch;
|
|
8
|
+
uniform vec2 u_phase;
|
|
9
|
+
uniform vec2 u_divisions;
|
|
10
|
+
uniform vec2 u_axisAt;
|
|
11
|
+
uniform float u_majorHalf;
|
|
12
|
+
uniform float u_minorHalf;
|
|
13
|
+
uniform float u_axisHalf;
|
|
14
|
+
uniform float u_scale;
|
|
15
|
+
|
|
16
|
+
// Coverage of a line \`d\` px away, of half-width \`w\`, ramped over \`feather\`.
|
|
17
|
+
//
|
|
18
|
+
// The zero test is not a shortcut. The ramp is centred on the line, so a line of
|
|
19
|
+
// no width still lands half a pixel of coverage on the pixels it runs through \u2014
|
|
20
|
+
// an order you switched off, drawn faintly. Answering it here rather than in the
|
|
21
|
+
// ramp is what lets one compiled program serve showGrid, showMinorGrid, showAxes
|
|
22
|
+
// and a grid width of zero.
|
|
23
|
+
float ink(float d, float w, float feather) {
|
|
24
|
+
if (w <= 0.0) return 0.0;
|
|
25
|
+
return clamp((w - d) / feather + 0.5, 0.0, 1.0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Distance from \`t\` to the nearest ruling. SkSL's mod is floor-based, so this
|
|
29
|
+
// is right on either side of the phase without a sign test.
|
|
30
|
+
float toRuling(float t, float pitch, float phase) {
|
|
31
|
+
float m = mod(t - phase, pitch);
|
|
32
|
+
return min(m, pitch - m);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// A straight colour under a coverage, premultiplied.
|
|
36
|
+
vec4 lay(vec4 color, float cover) {
|
|
37
|
+
float a = color.a * cover;
|
|
38
|
+
return vec4(color.rgb * a, a);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// \`src\` over \`dst\`, both premultiplied.
|
|
42
|
+
vec4 stack(vec4 src, vec4 dst) {
|
|
43
|
+
return src + dst * (1.0 - src.a);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
vec4 main(vec2 fragCoord) {
|
|
47
|
+
vec2 p = fragCoord - u_origin;
|
|
48
|
+
float feather = 1.0 / max(u_scale, 0.0001);
|
|
49
|
+
|
|
50
|
+
// Floored well above zero: a mod by zero paints garbage rather than nothing.
|
|
51
|
+
vec2 major = max(u_pitch, vec2(0.01));
|
|
52
|
+
vec2 minor = major / max(u_divisions, vec2(1.0));
|
|
53
|
+
|
|
54
|
+
vec2 dMajor = vec2(toRuling(p.x, major.x, u_phase.x),
|
|
55
|
+
toRuling(p.y, major.y, u_phase.y));
|
|
56
|
+
vec2 dMinor = vec2(toRuling(p.x, minor.x, u_phase.x),
|
|
57
|
+
toRuling(p.y, minor.y, u_phase.y));
|
|
58
|
+
|
|
59
|
+
float majorCover = max(ink(dMajor.x, u_majorHalf, feather),
|
|
60
|
+
ink(dMajor.y, u_majorHalf, feather));
|
|
61
|
+
|
|
62
|
+
// Every numbered ruling is also a faint one \u2014 the minor pitch divides the
|
|
63
|
+
// major exactly \u2014 so the faint order is cut away inside the numbered one's
|
|
64
|
+
// whole footprint, its ramp included. Drawing both would leave a hairline of
|
|
65
|
+
// the faint colour either side of every numbered line, where the numbered
|
|
66
|
+
// one's own ramp has not yet reached full coverage. The old ladder dropped
|
|
67
|
+
// coincident minors from a list; a shader has no list, so it subtracts.
|
|
68
|
+
float minorCover = max(
|
|
69
|
+
ink(dMinor.x, u_minorHalf, feather)
|
|
70
|
+
* (1.0 - ink(dMajor.x, u_majorHalf + feather, feather)),
|
|
71
|
+
ink(dMinor.y, u_minorHalf, feather)
|
|
72
|
+
* (1.0 - ink(dMajor.y, u_majorHalf + feather, feather)));
|
|
73
|
+
|
|
74
|
+
float axisCover = max(ink(abs(p.x - u_axisAt.x), u_axisHalf, feather),
|
|
75
|
+
ink(abs(p.y - u_axisAt.y), u_axisHalf, feather));
|
|
76
|
+
|
|
77
|
+
vec4 c = lay(u_paper, 1.0);
|
|
78
|
+
c = stack(lay(u_minorColor, minorCover), c);
|
|
79
|
+
c = stack(lay(u_majorColor, majorCover), c);
|
|
80
|
+
c = stack(lay(u_axisColor, axisCover), c);
|
|
81
|
+
return c;
|
|
82
|
+
}
|
|
83
|
+
`;var ae=.6666666666666666,ce=Number.MAX_SAFE_INTEGER;function vt(t){return t.paper[3]*Et(t.paperOpacity)>.001||t.showGrid&&t.lineWidth>0?!0:t.showAxes&&t.axisWidth>0}function bt(t,e,o,n){let r=e.showGrid&&e.lineWidth>0,i=r?e.lineWidth/2:0;return{u_paper:le(e.paper,Et(e.paperOpacity)),u_minorColor:et(e.colorMinorGrid),u_majorColor:et(e.colorGrid),u_axisColor:et(e.colorAxis),u_pitch:[ot(o.step,t.scaleX),ot(n.step,t.scaleY)],u_phase:[At(t.centerX,o.step,t.width/2,-t.scaleX),At(t.centerY,n.step,t.height/2,t.scaleY)],u_divisions:[Math.max(1,Math.round(o.divisions)),Math.max(1,Math.round(n.divisions))],u_axisAt:[e.showAxes&&t.xMin<=0&&0<=t.xMax?t.width/2-t.centerX*t.scaleX:-1e7,e.showAxes&&t.yMin<=0&&0<=t.yMax?t.height/2+t.centerY*t.scaleY:-1e7],u_majorHalf:i,u_minorHalf:r&&e.showMinorGrid?i*ae:0,u_axisHalf:e.showAxes?Math.max(0,e.axisWidth)/2:0}}function ot(t,e){let o=Math.abs(t*e);return Number.isFinite(o)&&o>.01?o:.01}function At(t,e,o,n){let r=ot(e,n),i=Math.round(t/e);if(!Number.isFinite(i)||Math.abs(i)>ce)return 0;let s=t-i*e,a=o+s*n;return Number.isFinite(a)?a-Math.floor(a/r)*r:0}function et(t){return[t[0],t[1],t[2],t[3]]}function le(t,e){return[t[0],t[1],t[2],t[3]*e]}function Et(t){return Number.isFinite(t)?t<0?0:t>1?1:t:1}import{resolveColor3D as g,lerpColor3D as L,lerpCount as no,snapFlag as k,snapValue as Lt}from"@motionscript/core/component";var gt=new Map;function Gt(t){let e=t.trim();if(e==="")return null;let o=gt.get(e);if(o!==void 0)return o;let n=j(e,R),r=n===null?null:i=>n(i,0);return gt.set(e,r),r}function Ct(t,e,o){return W(t,e,o,ue)}function ue(t,e,o){return n=>{let r=t(n);return r+(e(n)-r)*o}}var v=function(t,e,o,n){var r=arguments.length,i=r<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,o):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(i=(r<3?s(i):r>3?s(e,o,i):s(e,o))||i);return r>3&&i&&Object.defineProperty(e,o,i),i},pe={showGrid:!0,showMinorGrid:!0,showAxes:!0,showLabels:!0,colorGrid:g("#374151"),colorMinorGrid:g("#1f2937"),colorAxis:g("#6b7280"),colorLabel:g("#9ca3af"),lineWidth:2,axisWidth:3,fontSize:22,fontFamily:""},me=1,xe=2.6,Me=.45,It=6,w=class extends de{runs=new Y;get view(){return{centerX:this.centerX,centerY:this.centerY,xSpan:this.xSpan,ySpan:this.ySpan}}clipPathSelf(){let e=this.layoutBounds.width,o=this.layoutBounds.height;return e<=0||o<=0?null:new fe().rect({x:0,y:0,width:e,height:o})}renderSelf(e){let o=this.layoutBounds.width,n=this.layoutBounds.height;if(o<=0||n<=0)return;let r=Mt(this.view,o,n),i=this.grid,s=yt(r),a=_t(r.xMin,r.xMax,r.scaleX,i.fontSize),c=B(r.yMin,r.yMax,r.scaleY,i.fontSize*xe);this.drawPlane(e,r,i,a,c),i.showLabels&&this.drawLabels(e,r,s,i,a,c),this.drawCurves(e,r,s)}drawPlane(e,o,n,r,i){let s={paper:this.background,paperOpacity:Nt(this.backgroundOpacity),showGrid:n.showGrid,showMinorGrid:n.showMinorGrid,showAxes:n.showAxes,colorGrid:n.colorGrid,colorMinorGrid:n.colorMinorGrid,colorAxis:n.colorAxis,lineWidth:n.lineWidth,axisWidth:n.axisWidth};vt(s)&&e.draw(new nt().rect({x:0,y:0,width:o.width,height:o.height}).fill(rt.shader(St,{uniforms:bt(o,s,r,i),coords:"local"})))}drawLabels(e,o,n,r,i,s){let a=new nt,c=r.fontSize*Me,u=r.fontSize*Math.max(It,U(i)),p=r.fontSize*Math.max(It,U(s)),h={fontSize:r.fontSize,...r.fontFamily===""?{}:{fontFamily:r.fontFamily},wrap:!1},m=st(tt(o,0),n.bottom,n.top),S=m-c-r.fontSize>=n.bottom?m-c-r.fontSize/2:m+c+r.fontSize/2;for(let f of i.major)a.text({...h,text:V(f,i.step),x:Q(o,f),y:S,width:u,textAlign:"center"});let G=st(Q(o,0),n.left,n.right),I=G-c-r.fontSize*1.5>=n.left,X=I?G-c-p/2:G+c+p/2,l=o.xMin<=0&&0<=o.xMax;for(let f of s.major)f===0&&l||a.text({...h,text:V(f,s.step),x:X,y:tt(o,f),width:p,textAlign:I?"right":"left"});e.draw(a.fill(rt.color(r.colorLabel)))}drawCurves(e,o,n){let r=this.equations,i=Math.max(.1,this.lineWidth),s=wt(n,i*me),a=dt(o,s),c=[],u=0;for(let h of r)h.opacity<=.001||(c.push(h.id),this.runs.holds(h.id,h.sample,a)||u++);let p=u>0?ht(u):void 0;this.runs.retain(c);for(let h of r){if(h.opacity<=.001)continue;let m={weight:i,fill:rt.color(h.color,{opacity:Nt(h.opacity)}),cap:"round",join:"round"},E=this.runs.runs(h.id,h.sample,a,o,s,p);for(let S of E)S.length<2||e.draw(new nt().line({points:S,radius:0}).stroke(m))}}};v([b({default:[],mapper:ye,tween:Ct})],w.prototype,"equations",void 0);v([b({default:0})],w.prototype,"centerX",void 0);v([b({default:0})],w.prototype,"centerY",void 0);v([b({default:20})],w.prototype,"xSpan",void 0);v([b({default:0})],w.prototype,"ySpan",void 0);v([b({default:{},mapper:we,tween:_e})],w.prototype,"grid",void 0);v([b({default:"#111827",mapper:g,tween:L})],w.prototype,"background",void 0);v([b({default:1})],w.prototype,"backgroundOpacity",void 0);v([b({default:5})],w.prototype,"lineWidth",void 0);w=v([he({key:"graph2d",parentKey:"node",forkable:!0,layout:{children:"freeform",defaultWidthMode:"fixed",defaultHeightMode:"fixed",acceptsChildren:!0},seed:{width:960,height:540}})],w);function ye(t){if(!t)return[];let e=[];for(let o of t){let n=Gt(o.expression);n&&e.push({id:String(o.id),sample:n,color:g(o.color),opacity:o.visible===!1?0:o.opacity??1})}return e}function we(t,e){let o=e??pe;return{showGrid:t?.showGrid??o.showGrid,showMinorGrid:t?.showMinorGrid??o.showMinorGrid,showAxes:t?.showAxes??o.showAxes,showLabels:t?.showLabels??o.showLabels,colorGrid:Z(t?.colorGrid,o.colorGrid),colorMinorGrid:Z(t?.colorMinorGrid,o.colorMinorGrid),colorAxis:Z(t?.colorAxis,o.colorAxis),colorLabel:Z(t?.colorLabel,o.colorLabel),lineWidth:t?.lineWidth??o.lineWidth,axisWidth:t?.axisWidth??o.axisWidth,fontSize:t?.fontSize??o.fontSize,fontFamily:t?.fontFamily??o.fontFamily}}function Z(t,e){return t===void 0?e:g(t)}function _e(t,e,o){return{showGrid:k(t.showGrid,e.showGrid,o),showMinorGrid:k(t.showMinorGrid,e.showMinorGrid,o),showAxes:k(t.showAxes,e.showAxes,o),showLabels:k(t.showLabels,e.showLabels,o),colorGrid:L(t.colorGrid,e.colorGrid,o),colorMinorGrid:L(t.colorMinorGrid,e.colorMinorGrid,o),colorAxis:L(t.colorAxis,e.colorAxis,o),colorLabel:L(t.colorLabel,e.colorLabel,o),lineWidth:it(t.lineWidth,e.lineWidth,o),axisWidth:it(t.axisWidth,e.axisWidth,o),fontSize:it(t.fontSize,e.fontSize,o),fontFamily:Lt(t.fontFamily,e.fontFamily,o)}}function Nt(t){return Number.isFinite(t)?st(t,0,1):1}function mo(t){return ct(t,F)}function xo(t){return T(t,F)}function Ot(t){return j(t,F)}import{command as Ee,easeInOut as ge,node as Ge,Canvas3D as Ce,Fills as Le,Geo as Ie,Graphics3D as Ne,Mat as Oe,Scene3D as ke,lerpNumber as P,property as A}from"@motionscript/core";import{orbitProps as Pe}from"@motionscript/core/component";import{clamp as Ae}from"@motionscript/core";import{lerpColor3D as $,lerpCount as Dt,lerpFinite as at,cameraOrbit as Ft,resolveColor3D as C,snapFlag as q}from"@motionscript/core/component";function Pt(t,e){return Number.isFinite(t)?Ae(t,-e,e):0}function Xt(t,e,o){return W(t,e,o,Se)}function Se(t,e,o){return(n,r)=>{let i=t(n,r);return i+(e(n,r)-i)*o}}var kt=new WeakMap,ve=1;function be(t){let e=kt.get(t);return e===void 0&&(e=ve++,kt.set(t,e)),e}function zt(t,e,o){let n=`${be(t)}|${e}|${o}`,r=2166136261;for(let i=0;i<n.length;i++)r^=n.charCodeAt(i),r=Math.imul(r,16777619);return r>>>0}var _=function(t,e,o,n){var r=arguments.length,i=r<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,o):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(i=(r<3?s(i):r>3?s(e,o,i):s(e,o))||i);return r>3&&i&&Object.defineProperty(e,o,i),i},Xe={x:15,y:12,z:18},x=class extends Ce{constructor(e){super(e),this.applyCameraDefaults(e),e?.fill===void 0&&this.applyProp("fill",()=>this.transparentBackground?[]:Le.color(this.background))}orbitTo(e){return this.to({data:Pe(e.data?.target??{}),duration:e.duration,easing:e.easing??ge()})}applyCameraDefaults(e){let o=()=>We(this.camera.initialPosition);e?.orbit===void 0&&this.applyProp("orbit",()=>o().orbit),e?.elevation===void 0&&this.applyProp("elevation",()=>o().elevation),e?.zoom===void 0&&this.applyProp("zoom",()=>o().distance)}buildScene3D(){let e=new ke,o=new Ne,n=this.camera,r=this.grid,i=this.equations;e.perspective({fov:45,orbit:Ft(this.orbit),elevation:this.elevation,distance:Math.min(Math.max(this.zoom,n.minZoom),n.maxZoom)}),e.light({type:"ambient",intensity:.4}).light({type:"directional",intensity:.6},{position:[10,20,10]}).light({type:"directional",intensity:.4},{position:[-10,-20,-10]}),r.showGrid&&this.addGrid(o,r),r.showAxes&&this.addAxes(o,r.axesSize);let s=this.domain,a=Math.max(1,Math.round(this.segments)),c=this.maxHeight;return i.forEach((u,p)=>{this.addSurface(o,u,p,s,a,c)}),e.draw(o)}addSurface(e,o,n,r,i,s){if(o.opacity<=.001)return;let a=r*2,{sample:c,opacity:u}=o,p=u>=1;e.mesh(Ie.parametric({segments:i,vertex:(h,m)=>{let E=h*a-r,S=m*a-r;return{x:E,y:Pt(c(E,S),s),z:S}},computeNormals:!0,revision:zt(c,r,s)}),Oe.standard({color:o.color,faces:"both",roughness:.4,metalness:.1,opacity:u,depthWrite:p}),{key:`equation:${o.id}`,renderOrder:n})}addGrid(e,o){let n=Math.max(1,o.divisions),r=o.size/2,i=o.size/n,s=[],a=[];for(let c=0;c<=n;c++){let u=-r+c*i,h=Math.abs(u)<i/1e3?s:a;h.push([-r,0,u],[r,0,u]),h.push([u,0,-r],[u,0,r])}a.length>0&&e.line({points:a,segments:!0,stroke:{fill:o.colorGrid}}),s.length>0&&e.line({points:s,segments:!0,stroke:{fill:o.colorCenterLine}})}addAxes(e,o){let n=[[[o,0,0],"#ff4d4d"],[[0,o,0],"#4ade80"],[[0,0,o],"#60a5fa"]];for(let[r,i]of n)e.line({points:[[0,0,0],r],stroke:{fill:i}})}};_([A({default:[],mapper:ze,tween:Xt})],x.prototype,"equations",void 0);_([A({default:{},mapper:De,tween:Fe})],x.prototype,"camera",void 0);_([A({default:{},mapper:Te,tween:je})],x.prototype,"grid",void 0);_([A({default:10})],x.prototype,"domain",void 0);_([A({default:80})],x.prototype,"segments",void 0);_([A({default:20})],x.prototype,"maxHeight",void 0);_([A({default:"#111827",mapper:C,tween:$})],x.prototype,"background",void 0);_([A({default:!1,tween:q})],x.prototype,"transparentBackground",void 0);_([A()],x.prototype,"orbit",void 0);_([A()],x.prototype,"elevation",void 0);_([A()],x.prototype,"zoom",void 0);_([Ee({args:[{key:"target",kind:"orbit",properties:{orbit:{kind:"number",step:1,unit:"\xB0"},elevation:{kind:"number",min:-89,max:89,step:1,unit:"\xB0"},zoom:{kind:"number",min:.2,max:24,step:.1,unit:"\xD7"}}}]})],x.prototype,"orbitTo",null);x=_([Ge({key:"graph3d",parentKey:"node",forkable:!0,layout:{children:"freeform",defaultWidthMode:"fixed",defaultHeightMode:"fixed",acceptsChildren:!0},seed:{width:960,height:540}})],x);function ze(t){if(!t)return[];let e=[];for(let o of t){let n=Ot(o.expression);n&&e.push({id:String(o.id),sample:n,color:C(o.color),opacity:o.visible===!1?0:o.opacity??1})}return e}function De(t,e){let o=e??{initialPosition:Xe,minZoom:.1,maxZoom:Number.POSITIVE_INFINITY};return{initialPosition:t?.initialPosition??o.initialPosition,minZoom:t?.minZoom??o.minZoom,maxZoom:t?.maxZoom??o.maxZoom}}function Fe(t,e,o){return{initialPosition:{x:P(t.initialPosition.x,e.initialPosition.x,o),y:P(t.initialPosition.y,e.initialPosition.y,o),z:P(t.initialPosition.z,e.initialPosition.z,o)},minZoom:at(t.minZoom,e.minZoom,o),maxZoom:at(t.maxZoom,e.maxZoom,o)}}var Re={showGrid:!0,size:20,divisions:20,colorCenterLine:C("#4b5563"),colorGrid:C("#1f2937"),showAxes:!0,axesSize:10};function Te(t,e){let o=e??Re;return{showGrid:t?.showGrid??o.showGrid,size:t?.size??o.size,divisions:t?.divisions??o.divisions,colorCenterLine:t?.colorCenterLine===void 0?o.colorCenterLine:C(t.colorCenterLine),colorGrid:t?.colorGrid===void 0?o.colorGrid:C(t.colorGrid),showAxes:t?.showAxes??o.showAxes,axesSize:t?.axesSize??o.axesSize}}function je(t,e,o){return{showGrid:q(t.showGrid,e.showGrid,o),size:P(t.size,e.size,o),divisions:Dt(t.divisions,e.divisions,o),colorCenterLine:$(t.colorCenterLine,e.colorCenterLine,o),colorGrid:$(t.colorGrid,e.colorGrid,o),showAxes:q(t.showAxes,e.showAxes,o),axesSize:P(t.axesSize,e.axesSize,o)}}function We(t){let e=Math.hypot(t.x,t.y,t.z)||1,o=Math.min(1,Math.max(-1,t.y/e));return{orbit:Math.atan2(t.z,t.x)*(180/Math.PI),elevation:Math.asin(o)*(180/Math.PI),distance:e}}var Ye=[w,x];export{Y as CurveRunsCache,Tt as EXPRESSION_VOCABULARY,w as Graph2D,x as Graph3D,Kt as MAX_SPAN,pt as MIN_SPAN,Ye as NODES,St as PLANE_SOURCE,Ft as cameraOrbit,O as clampSpan,Gt as compileCurveCached,mo as compileExpression,Ot as compileExpressionCached,Ze as curveError,xo as expressionError,V as formatTick,wt as inflate,_t as labelLadder,U as labelWidthEm,L as lerpColor,$ as lerpColor3D,Ct as lerpCurves,Xt as lerpEquations,at as lerpFinite,Ke as panPlane,yt as planeBox,bt as planeUniforms,vt as planeVisible,g as resolveColor,C as resolveColor3D,Mt as resolvePlane,dt as runsKeyOf,ht as sampleBudget,ft as sampleCurve,Pt as sanitizeHeight,Lt as snapValue,zt as surfaceRevision,B as tickLadder,Q as toPx,tt as toPy,oe as widestLabel,Je as zoomPlane};
|
|
84
|
+
//# sourceMappingURL=index.js.map
|