pts 0.12.9 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/_script.ts ADDED
@@ -0,0 +1,94 @@
1
+ import * as Canvas from "./Canvas";
2
+ import * as Create from "./Create";
3
+ import * as Form from "./Form";
4
+ import * as LinearAlgebra from "./LinearAlgebra";
5
+ import * as Num from "./Num";
6
+ import * as Op from "./Op";
7
+ import * as Pt from "./Pt";
8
+ import * as Space from "./Space";
9
+ import * as Color from "./Color";
10
+ import * as Util from "./Util";
11
+ import * as Dom from "./Dom";
12
+ import * as Svg from "./Svg";
13
+ import * as Typography from "./Typography";
14
+ import * as Physics from "./Physics";
15
+ import * as UI from "./UI";
16
+ import * as Play from "./Play";
17
+ import * as Image from "./Image";
18
+ import * as Types from "./Types";
19
+
20
+ declare global {
21
+ // the browser bundle mounts the whole library on globalThis.Pts
22
+
23
+ var Pts: Record<string, any>;
24
+ }
25
+
26
+ globalThis.Pts = {
27
+ ...Canvas,
28
+ ...Create,
29
+ ...Form,
30
+ ...LinearAlgebra,
31
+ ...Num,
32
+ ...Op,
33
+ ...Pt,
34
+ ...Space,
35
+ ...Color,
36
+ ...Util,
37
+ ...Dom,
38
+ ...Svg,
39
+ ...Typography,
40
+ ...Physics,
41
+ ...UI,
42
+ ...Play,
43
+ ...Image,
44
+ };
45
+
46
+ // A function to switch scope for Pts library. eg, Pts.namespace( window );
47
+ globalThis.Pts.namespace = (scope: any) => {
48
+ let lib = globalThis.Pts;
49
+ for (let k in lib) {
50
+ if (k != "namespace") {
51
+ scope[k] = lib[k];
52
+ }
53
+ }
54
+ };
55
+
56
+ globalThis.Pts.quickStart = (id: string | Element, bg: string = "#9ab") => {
57
+ if (!window) return;
58
+
59
+ let s: any = globalThis;
60
+ globalThis.Pts.namespace(s);
61
+
62
+ // pick the rendering backend from the mount element: an <svg> element (or a
63
+ // container holding one) gets an SVGSpace, anything else a CanvasSpace —
64
+ // so a sketch can swap renderers by changing only its HTML
65
+ // Preserve CanvasSpace's bare-ID shorthand for both rendering backends.
66
+ const mount =
67
+ typeof id === "string" && id[0] !== "#" && id[0] !== "." ? `#${id}` : id;
68
+ const elem =
69
+ typeof mount === "string" ? document.querySelector(mount) : mount;
70
+ const isSVG =
71
+ elem &&
72
+ ((elem as Element).nodeName.toLowerCase() === "svg" ||
73
+ !!(elem as Element).querySelector(":scope > svg"));
74
+
75
+ s.space = isSVG
76
+ ? new Svg.SVGSpace(mount).setup({ bgcolor: bg, resize: true })
77
+ : new Canvas.CanvasSpace(mount).setup({
78
+ bgcolor: bg,
79
+ resize: true,
80
+ retina: true,
81
+ });
82
+ s.form = s.space.getForm();
83
+
84
+ return function (animate = null, start = null, action = null, resize = null) {
85
+ s.space.add({
86
+ start: start,
87
+ animate: animate,
88
+ resize: resize,
89
+ action: action,
90
+ });
91
+
92
+ s.space.bindMouse().bindTouch().play();
93
+ };
94
+ };