@multiplatform.one/node-graph 9.0.10 → 9.1.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/dist/cjs/graphLayout/GraphDots.cjs +60 -0
- package/dist/cjs/graphLayout/GraphDots.native.js +66 -0
- package/dist/cjs/graphLayout/GraphDots.native.js.map +1 -0
- package/dist/cjs/graphLayout/GraphLayout.cjs +153 -0
- package/dist/cjs/graphLayout/GraphLayout.native.js +163 -0
- package/dist/cjs/graphLayout/GraphLayout.native.js.map +1 -0
- package/dist/cjs/graphLayout/GraphSvg.cjs +68 -0
- package/dist/cjs/graphLayout/GraphSvg.native.js +73 -0
- package/dist/cjs/graphLayout/GraphSvg.native.js.map +1 -0
- package/dist/cjs/graphLayout/GraphViewport.cjs +263 -0
- package/dist/cjs/graphLayout/GraphViewport.native.js +279 -0
- package/dist/cjs/graphLayout/GraphViewport.native.js.map +1 -0
- package/dist/cjs/graphLayout/index.cjs +51 -0
- package/dist/cjs/graphLayout/index.native.js +54 -0
- package/dist/cjs/graphLayout/index.native.js.map +1 -0
- package/dist/cjs/graphLayout/ogden.fixture.cjs +30 -0
- package/dist/cjs/graphLayout/ogden.fixture.native.js +33 -0
- package/dist/cjs/graphLayout/ogden.fixture.native.js.map +1 -0
- package/dist/cjs/graphLayout/plan.cjs +263 -0
- package/dist/cjs/graphLayout/plan.native.js +372 -0
- package/dist/cjs/graphLayout/plan.native.js.map +1 -0
- package/dist/cjs/graphLayout/viewMath.cjs +142 -0
- package/dist/cjs/graphLayout/viewMath.native.js +147 -0
- package/dist/cjs/graphLayout/viewMath.native.js.map +1 -0
- package/dist/esm/graphLayout/GraphDots.mjs +35 -0
- package/dist/esm/graphLayout/GraphDots.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphDots.native.js +38 -0
- package/dist/esm/graphLayout/GraphDots.native.js.map +1 -0
- package/dist/esm/graphLayout/GraphLayout.mjs +127 -0
- package/dist/esm/graphLayout/GraphLayout.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphLayout.native.js +134 -0
- package/dist/esm/graphLayout/GraphLayout.native.js.map +1 -0
- package/dist/esm/graphLayout/GraphSvg.mjs +42 -0
- package/dist/esm/graphLayout/GraphSvg.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphSvg.native.js +44 -0
- package/dist/esm/graphLayout/GraphSvg.native.js.map +1 -0
- package/dist/esm/graphLayout/GraphViewport.mjs +238 -0
- package/dist/esm/graphLayout/GraphViewport.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphViewport.native.js +251 -0
- package/dist/esm/graphLayout/GraphViewport.native.js.map +1 -0
- package/dist/esm/graphLayout/index.mjs +7 -0
- package/dist/esm/graphLayout/index.mjs.map +1 -0
- package/dist/esm/graphLayout/index.native.js +7 -0
- package/dist/esm/graphLayout/index.native.js.map +1 -0
- package/dist/esm/graphLayout/ogden.fixture.mjs +4 -0
- package/dist/esm/graphLayout/ogden.fixture.mjs.map +1 -0
- package/dist/esm/graphLayout/ogden.fixture.native.js +4 -0
- package/dist/esm/graphLayout/ogden.fixture.native.js.map +1 -0
- package/dist/esm/graphLayout/plan.mjs +235 -0
- package/dist/esm/graphLayout/plan.mjs.map +1 -0
- package/dist/esm/graphLayout/plan.native.js +341 -0
- package/dist/esm/graphLayout/plan.native.js.map +1 -0
- package/dist/esm/graphLayout/viewMath.mjs +105 -0
- package/dist/esm/graphLayout/viewMath.mjs.map +1 -0
- package/dist/esm/graphLayout/viewMath.native.js +107 -0
- package/dist/esm/graphLayout/viewMath.native.js.map +1 -0
- package/dist/jsx/graphLayout/GraphDots.mjs +35 -0
- package/dist/jsx/graphLayout/GraphDots.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphDots.native.js +66 -0
- package/dist/jsx/graphLayout/GraphDots.native.js.map +1 -0
- package/dist/jsx/graphLayout/GraphLayout.mjs +127 -0
- package/dist/jsx/graphLayout/GraphLayout.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphLayout.native.js +163 -0
- package/dist/jsx/graphLayout/GraphLayout.native.js.map +1 -0
- package/dist/jsx/graphLayout/GraphSvg.mjs +42 -0
- package/dist/jsx/graphLayout/GraphSvg.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphSvg.native.js +73 -0
- package/dist/jsx/graphLayout/GraphSvg.native.js.map +1 -0
- package/dist/jsx/graphLayout/GraphViewport.mjs +238 -0
- package/dist/jsx/graphLayout/GraphViewport.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphViewport.native.js +279 -0
- package/dist/jsx/graphLayout/GraphViewport.native.js.map +1 -0
- package/dist/jsx/graphLayout/index.mjs +7 -0
- package/dist/jsx/graphLayout/index.mjs.map +1 -0
- package/dist/jsx/graphLayout/index.native.js +54 -0
- package/dist/jsx/graphLayout/index.native.js.map +1 -0
- package/dist/jsx/graphLayout/ogden.fixture.mjs +4 -0
- package/dist/jsx/graphLayout/ogden.fixture.mjs.map +1 -0
- package/dist/jsx/graphLayout/ogden.fixture.native.js +33 -0
- package/dist/jsx/graphLayout/ogden.fixture.native.js.map +1 -0
- package/dist/jsx/graphLayout/plan.mjs +235 -0
- package/dist/jsx/graphLayout/plan.mjs.map +1 -0
- package/dist/jsx/graphLayout/plan.native.js +372 -0
- package/dist/jsx/graphLayout/plan.native.js.map +1 -0
- package/dist/jsx/graphLayout/viewMath.mjs +105 -0
- package/dist/jsx/graphLayout/viewMath.mjs.map +1 -0
- package/dist/jsx/graphLayout/viewMath.native.js +147 -0
- package/dist/jsx/graphLayout/viewMath.native.js.map +1 -0
- package/graph-layout.ts +1 -0
- package/package.json +21 -6
- package/src/graphLayout/GraphDots.tsx +32 -0
- package/src/graphLayout/GraphLayout.stories.tsx +86 -0
- package/src/graphLayout/GraphLayout.tsx +152 -0
- package/src/graphLayout/GraphSvg.native.tsx +31 -0
- package/src/graphLayout/GraphSvg.tsx +45 -0
- package/src/graphLayout/GraphViewport.native.tsx +231 -0
- package/src/graphLayout/GraphViewport.tsx +246 -0
- package/src/graphLayout/index.ts +31 -0
- package/src/graphLayout/ogden.fixture.ts +120 -0
- package/src/graphLayout/plan.spec.ts +202 -0
- package/src/graphLayout/plan.ts +223 -0
- package/src/graphLayout/purity.spec.ts +67 -0
- package/src/graphLayout/viewMath.spec.ts +185 -0
- package/src/graphLayout/viewMath.ts +151 -0
- package/types/graphLayout/GraphDots.d.ts +9 -0
- package/types/graphLayout/GraphDots.d.ts.map +1 -0
- package/types/graphLayout/GraphLayout.d.ts +22 -0
- package/types/graphLayout/GraphLayout.d.ts.map +1 -0
- package/types/graphLayout/GraphSvg.d.ts +17 -0
- package/types/graphLayout/GraphSvg.d.ts.map +1 -0
- package/types/graphLayout/GraphSvg.native.d.ts +5 -0
- package/types/graphLayout/GraphSvg.native.d.ts.map +1 -0
- package/types/graphLayout/GraphViewport.d.ts +11 -0
- package/types/graphLayout/GraphViewport.d.ts.map +1 -0
- package/types/graphLayout/GraphViewport.native.d.ts +4 -0
- package/types/graphLayout/GraphViewport.native.d.ts.map +1 -0
- package/types/graphLayout/index.d.ts +11 -0
- package/types/graphLayout/index.d.ts.map +1 -0
- package/types/graphLayout/ogden.fixture.d.ts +3 -0
- package/types/graphLayout/ogden.fixture.d.ts.map +1 -0
- package/types/graphLayout/plan.d.ts +52 -0
- package/types/graphLayout/plan.d.ts.map +1 -0
- package/types/graphLayout/viewMath.d.ts +47 -0
- package/types/graphLayout/viewMath.d.ts.map +1 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
function GraphSvg({
|
|
3
|
+
width,
|
|
4
|
+
height,
|
|
5
|
+
children
|
|
6
|
+
}) {
|
|
7
|
+
return /* @__PURE__ */jsx("svg", {
|
|
8
|
+
width,
|
|
9
|
+
height,
|
|
10
|
+
"aria-hidden": true,
|
|
11
|
+
style: {
|
|
12
|
+
position: "absolute",
|
|
13
|
+
left: 0,
|
|
14
|
+
top: 0,
|
|
15
|
+
overflow: "visible",
|
|
16
|
+
pointerEvents: "none"
|
|
17
|
+
},
|
|
18
|
+
children
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function GraphPath({
|
|
22
|
+
d,
|
|
23
|
+
stroke,
|
|
24
|
+
strokeWidth,
|
|
25
|
+
dash,
|
|
26
|
+
fill,
|
|
27
|
+
round
|
|
28
|
+
}) {
|
|
29
|
+
return /* @__PURE__ */jsx("path", {
|
|
30
|
+
d,
|
|
31
|
+
style: {
|
|
32
|
+
fill: fill ?? "none",
|
|
33
|
+
stroke: stroke ?? "none",
|
|
34
|
+
strokeWidth,
|
|
35
|
+
strokeDasharray: dash,
|
|
36
|
+
strokeLinecap: round ? "round" : "butt",
|
|
37
|
+
strokeLinejoin: "round"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export { GraphPath, GraphSvg };
|
|
42
|
+
//# sourceMappingURL=GraphSvg.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["jsx","GraphSvg","width","height","children","style","position","left","top","overflow","pointerEvents","GraphPath","d","stroke","strokeWidth","dash","fill","round","strokeDasharray","strokeLinecap","strokeLinejoin"],"sources":["../../../src/graphLayout/GraphSvg.tsx"],"sourcesContent":[null],"mappings":"AAmBI,SAAAA,GAAA;AAFG,SAASC,SAAS;EAAEC,KAAA;EAAOC,MAAA;EAAQC;AAAS,GAAkB;EACnE,OACE,eAAAJ,GAAA,CAAC;IACCE,KAAA;IACAC,MAAA;IACA,eAAW;IACXE,KAAA,EAAO;MAAEC,QAAA,EAAU;MAAYC,IAAA,EAAM;MAAGC,GAAA,EAAK;MAAGC,QAAA,EAAU;MAAWC,aAAA,EAAe;IAAO;IAE1FN;EAAA,CACH;AAEJ;AAEO,SAASO,UAAU;EAAEC,CAAA;EAAGC,MAAA;EAAQC,WAAA;EAAaC,IAAA;EAAMC,IAAA;EAAMC;AAAM,GAAmB;EACvF,OACE,eAAAjB,GAAA,CAAC;IACCY,CAAA;IACAP,KAAA,EAAO;MACLW,IAAA,EAAMA,IAAA,IAAQ;MACdH,MAAA,EAAQA,MAAA,IAAU;MAClBC,WAAA;MACAI,eAAA,EAAiBH,IAAA;MACjBI,aAAA,EAAeF,KAAA,GAAQ,UAAU;MACjCG,cAAA,EAAgB;IAClB;EAAA,CACF;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var GraphSvg_exports = {};
|
|
26
|
+
__export(GraphSvg_exports, {
|
|
27
|
+
GraphPath: () => GraphPath,
|
|
28
|
+
GraphSvg: () => GraphSvg
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(GraphSvg_exports);
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
function GraphSvg(param) {
|
|
33
|
+
var {
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
children
|
|
37
|
+
} = param;
|
|
38
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)("svg", {
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
"aria-hidden": true,
|
|
42
|
+
style: {
|
|
43
|
+
position: "absolute",
|
|
44
|
+
left: 0,
|
|
45
|
+
top: 0,
|
|
46
|
+
overflow: "visible",
|
|
47
|
+
pointerEvents: "none"
|
|
48
|
+
},
|
|
49
|
+
children
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function GraphPath(param) {
|
|
53
|
+
var {
|
|
54
|
+
d,
|
|
55
|
+
stroke,
|
|
56
|
+
strokeWidth,
|
|
57
|
+
dash,
|
|
58
|
+
fill,
|
|
59
|
+
round
|
|
60
|
+
} = param;
|
|
61
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)("path", {
|
|
62
|
+
d,
|
|
63
|
+
style: {
|
|
64
|
+
fill: fill !== null && fill !== void 0 ? fill : "none",
|
|
65
|
+
stroke: stroke !== null && stroke !== void 0 ? stroke : "none",
|
|
66
|
+
strokeWidth,
|
|
67
|
+
strokeDasharray: dash,
|
|
68
|
+
strokeLinecap: round ? "round" : "butt",
|
|
69
|
+
strokeLinejoin: "round"
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=GraphSvg.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","GraphSvg_exports","GraphPath","GraphSvg","module","exports","import_jsx_runtime","require","param","width","height","children","jsx"],"sources":["../../../src/graphLayout/GraphSvg.tsx"],"sourcesContent":[null],"mappings":"AAmBI;;AAFG,IAAAA,SAAS,GAAAC,MAAW,CAAAC,cAAe;AACxC,IA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AAF,kBAAA,CAAAM,GAAA;IAEJH,KAAA","ignoreList":[]}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { ScrollView, View } from "tamagui";
|
|
3
|
+
import { GraphDots } from "./GraphDots.mjs";
|
|
4
|
+
import { dotArea, dotPitch, keyedView, leastScale, sameArea, toggledView, zoomAt } from "./viewMath.mjs";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function editable(target) {
|
|
7
|
+
const element = target;
|
|
8
|
+
return Boolean(element?.isContentEditable) || ["INPUT", "TEXTAREA", "SELECT"].includes(element?.tagName ?? "");
|
|
9
|
+
}
|
|
10
|
+
function onNode(target) {
|
|
11
|
+
const element = target;
|
|
12
|
+
return Boolean(element?.closest?.("[data-testid^='graph-node-']"));
|
|
13
|
+
}
|
|
14
|
+
function GraphViewport({
|
|
15
|
+
content,
|
|
16
|
+
viewport,
|
|
17
|
+
dots,
|
|
18
|
+
frozen,
|
|
19
|
+
children
|
|
20
|
+
}) {
|
|
21
|
+
const scroller = useRef(null);
|
|
22
|
+
const [scale, setScale] = useState(1);
|
|
23
|
+
const [scroll, setScroll] = useState({
|
|
24
|
+
x: 0,
|
|
25
|
+
y: 0
|
|
26
|
+
});
|
|
27
|
+
const offset = useRef({
|
|
28
|
+
x: 0,
|
|
29
|
+
y: 0
|
|
30
|
+
});
|
|
31
|
+
const pending = useRef(void 0);
|
|
32
|
+
const shown = Math.min(1, Math.max(leastScale(content, viewport), scale));
|
|
33
|
+
const wide = content.width * shown;
|
|
34
|
+
const tall = content.height * shown;
|
|
35
|
+
const pad = {
|
|
36
|
+
x: Math.max(0, (viewport.width - wide) / 2),
|
|
37
|
+
y: Math.max(0, (viewport.height - tall) / 2)
|
|
38
|
+
};
|
|
39
|
+
const live = useRef({
|
|
40
|
+
shown,
|
|
41
|
+
pad,
|
|
42
|
+
content,
|
|
43
|
+
viewport,
|
|
44
|
+
frozen
|
|
45
|
+
});
|
|
46
|
+
live.current = {
|
|
47
|
+
shown,
|
|
48
|
+
pad,
|
|
49
|
+
content,
|
|
50
|
+
viewport,
|
|
51
|
+
frozen
|
|
52
|
+
};
|
|
53
|
+
const node = () => scroller.current?.getScrollableNode?.() ?? void 0;
|
|
54
|
+
const now = () => ({
|
|
55
|
+
scale: live.current.shown,
|
|
56
|
+
x: live.current.pad.x - offset.current.x,
|
|
57
|
+
y: live.current.pad.y - offset.current.y
|
|
58
|
+
});
|
|
59
|
+
const apply = next => {
|
|
60
|
+
const {
|
|
61
|
+
content: size,
|
|
62
|
+
viewport: view
|
|
63
|
+
} = live.current;
|
|
64
|
+
const padX = Math.max(0, (view.width - size.width * next.scale) / 2);
|
|
65
|
+
const padY = Math.max(0, (view.height - size.height * next.scale) / 2);
|
|
66
|
+
pending.current = {
|
|
67
|
+
x: Math.max(0, padX - next.x),
|
|
68
|
+
y: Math.max(0, padY - next.y)
|
|
69
|
+
};
|
|
70
|
+
setScale(next.scale);
|
|
71
|
+
};
|
|
72
|
+
const applyRef = useRef(apply);
|
|
73
|
+
applyRef.current = apply;
|
|
74
|
+
const nowRef = useRef(now);
|
|
75
|
+
nowRef.current = now;
|
|
76
|
+
useLayoutEffect(() => {
|
|
77
|
+
const target = pending.current;
|
|
78
|
+
const element = node();
|
|
79
|
+
if (!target) return;
|
|
80
|
+
pending.current = void 0;
|
|
81
|
+
offset.current = target;
|
|
82
|
+
setScroll(target);
|
|
83
|
+
if (element) {
|
|
84
|
+
element.scrollLeft = target.x;
|
|
85
|
+
element.scrollTop = target.y;
|
|
86
|
+
}
|
|
87
|
+
}, [shown]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const element = node();
|
|
90
|
+
if (!element || typeof element.addEventListener !== "function") return;
|
|
91
|
+
element.style.touchAction = "pan-x pan-y";
|
|
92
|
+
element.tabIndex = 0;
|
|
93
|
+
const at = (clientX, clientY) => {
|
|
94
|
+
const box = element.getBoundingClientRect();
|
|
95
|
+
return {
|
|
96
|
+
x: clientX - box.left,
|
|
97
|
+
y: clientY - box.top
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const onWheel = event => {
|
|
101
|
+
if (live.current.frozen || !event.ctrlKey && !event.metaKey) return;
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
const current = nowRef.current();
|
|
104
|
+
const factor = 1.002 ** -event.deltaY;
|
|
105
|
+
applyRef.current(zoomAt(current, current.scale * factor, at(event.clientX, event.clientY), live.current.content, live.current.viewport));
|
|
106
|
+
};
|
|
107
|
+
const onDouble = event => {
|
|
108
|
+
if (live.current.frozen || onNode(event.target)) return;
|
|
109
|
+
applyRef.current(toggledView(nowRef.current(), at(event.clientX, event.clientY), live.current.content, live.current.viewport));
|
|
110
|
+
};
|
|
111
|
+
const onKey = event => {
|
|
112
|
+
if (live.current.frozen || event.ctrlKey || event.metaKey || event.altKey || editable(event.target)) return;
|
|
113
|
+
const next = keyedView(event.key, nowRef.current(), live.current.content, live.current.viewport);
|
|
114
|
+
if (!next) return;
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
applyRef.current(next);
|
|
117
|
+
};
|
|
118
|
+
let pinch;
|
|
119
|
+
const spread = touches => Math.hypot(touches[0].clientX - touches[1].clientX, touches[0].clientY - touches[1].clientY);
|
|
120
|
+
const middle = touches => at((touches[0].clientX + touches[1].clientX) / 2, (touches[0].clientY + touches[1].clientY) / 2);
|
|
121
|
+
const onTouchStart = event => {
|
|
122
|
+
pinch = event.touches.length === 2 ? {
|
|
123
|
+
distance: spread(event.touches),
|
|
124
|
+
scale: nowRef.current().scale
|
|
125
|
+
} : void 0;
|
|
126
|
+
};
|
|
127
|
+
const onTouchMove = event => {
|
|
128
|
+
if (live.current.frozen || !pinch || event.touches.length !== 2) return;
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
const ratio = spread(event.touches) / Math.max(1, pinch.distance);
|
|
131
|
+
applyRef.current(zoomAt(nowRef.current(), pinch.scale * ratio, middle(event.touches), live.current.content, live.current.viewport));
|
|
132
|
+
};
|
|
133
|
+
const onTouchEnd = event => {
|
|
134
|
+
if (event.touches.length < 2) pinch = void 0;
|
|
135
|
+
};
|
|
136
|
+
element.addEventListener("wheel", onWheel, {
|
|
137
|
+
passive: false
|
|
138
|
+
});
|
|
139
|
+
element.addEventListener("dblclick", onDouble);
|
|
140
|
+
element.addEventListener("keydown", onKey);
|
|
141
|
+
element.addEventListener("touchstart", onTouchStart, {
|
|
142
|
+
passive: true
|
|
143
|
+
});
|
|
144
|
+
element.addEventListener("touchmove", onTouchMove, {
|
|
145
|
+
passive: false
|
|
146
|
+
});
|
|
147
|
+
element.addEventListener("touchend", onTouchEnd);
|
|
148
|
+
return () => {
|
|
149
|
+
element.removeEventListener("wheel", onWheel);
|
|
150
|
+
element.removeEventListener("dblclick", onDouble);
|
|
151
|
+
element.removeEventListener("keydown", onKey);
|
|
152
|
+
element.removeEventListener("touchstart", onTouchStart);
|
|
153
|
+
element.removeEventListener("touchmove", onTouchMove);
|
|
154
|
+
element.removeEventListener("touchend", onTouchEnd);
|
|
155
|
+
};
|
|
156
|
+
}, []);
|
|
157
|
+
const spaced = dots ? dotPitch(dots.pitch, shown) : 1;
|
|
158
|
+
const chunk = spaced * 4;
|
|
159
|
+
const reach = {
|
|
160
|
+
width: viewport.width / shown,
|
|
161
|
+
height: viewport.height / shown
|
|
162
|
+
};
|
|
163
|
+
const area = dotArea({
|
|
164
|
+
x: scroll.x / shown,
|
|
165
|
+
y: scroll.y / shown
|
|
166
|
+
}, reach, content, chunk);
|
|
167
|
+
const follow = event => {
|
|
168
|
+
const {
|
|
169
|
+
x,
|
|
170
|
+
y
|
|
171
|
+
} = event.nativeEvent.contentOffset;
|
|
172
|
+
offset.current = {
|
|
173
|
+
x,
|
|
174
|
+
y
|
|
175
|
+
};
|
|
176
|
+
const next = dotArea({
|
|
177
|
+
x: x / shown,
|
|
178
|
+
y: y / shown
|
|
179
|
+
}, reach, content, chunk);
|
|
180
|
+
if (!sameArea(next, area)) setScroll({
|
|
181
|
+
x,
|
|
182
|
+
y
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
return /* @__PURE__ */jsx(ScrollView, {
|
|
186
|
+
ref: scroller,
|
|
187
|
+
flex: 1,
|
|
188
|
+
testID: "graph-viewport",
|
|
189
|
+
scrollEnabled: !frozen,
|
|
190
|
+
showsVerticalScrollIndicator: false,
|
|
191
|
+
showsHorizontalScrollIndicator: false,
|
|
192
|
+
scrollEventThrottle: 16,
|
|
193
|
+
onScroll: follow,
|
|
194
|
+
contentContainerStyle: {
|
|
195
|
+
alignSelf: "flex-start"
|
|
196
|
+
},
|
|
197
|
+
...{
|
|
198
|
+
style: {
|
|
199
|
+
overflowX: frozen ? "hidden" : "auto"
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
children: /* @__PURE__ */jsx(View, {
|
|
203
|
+
minWidth: viewport.width,
|
|
204
|
+
minHeight: viewport.height,
|
|
205
|
+
alignItems: "center",
|
|
206
|
+
justifyContent: "center",
|
|
207
|
+
children: /* @__PURE__ */jsx(View, {
|
|
208
|
+
width: wide,
|
|
209
|
+
height: tall,
|
|
210
|
+
overflow: "hidden",
|
|
211
|
+
testID: "graph-zoom",
|
|
212
|
+
children: /* @__PURE__ */jsxs(View, {
|
|
213
|
+
position: "absolute",
|
|
214
|
+
left: 0,
|
|
215
|
+
top: 0,
|
|
216
|
+
width: content.width,
|
|
217
|
+
height: content.height,
|
|
218
|
+
...{
|
|
219
|
+
style: {
|
|
220
|
+
transform: [{
|
|
221
|
+
scale: shown
|
|
222
|
+
}],
|
|
223
|
+
transformOrigin: "0 0"
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
children: [dots ? /* @__PURE__ */jsx(GraphDots, {
|
|
227
|
+
area,
|
|
228
|
+
pitch: spaced,
|
|
229
|
+
dot: dots.dot / shown,
|
|
230
|
+
color: dots.color
|
|
231
|
+
}) : null, children]
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
export { GraphViewport };
|
|
238
|
+
//# sourceMappingURL=GraphViewport.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useLayoutEffect","useRef","useState","ScrollView","View","GraphDots","dotArea","dotPitch","keyedView","leastScale","sameArea","toggledView","zoomAt","jsx","jsxs","editable","target","element","Boolean","isContentEditable","includes","tagName","onNode","closest","GraphViewport","content","viewport","dots","frozen","children","scroller","scale","setScale","scroll","setScroll","x","y","offset","pending","shown","Math","min","max","wide","width","tall","height","pad","live","current","node","getScrollableNode","now","apply","next","size","view","padX","padY","applyRef","nowRef","scrollLeft","scrollTop","addEventListener","style","touchAction","tabIndex","at","clientX","clientY","box","getBoundingClientRect","left","top","onWheel","event","ctrlKey","metaKey","preventDefault","factor","deltaY","onDouble","onKey","altKey","key","pinch","spread","touches","hypot","middle","onTouchStart","length","distance","onTouchMove","ratio","onTouchEnd","passive","removeEventListener","spaced","pitch","chunk","reach","area","follow","nativeEvent","contentOffset","ref","flex","testID","scrollEnabled","showsVerticalScrollIndicator","showsHorizontalScrollIndicator","scrollEventThrottle","onScroll","contentContainerStyle","alignSelf","overflowX","minWidth","minHeight","alignItems","justifyContent","overflow","position","transform","transformOrigin","dot","color"],"sources":["../../../src/graphLayout/GraphViewport.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,SAAA,EAAWC,eAAA,EAAiBC,MAAA,EAAQC,QAAA,QAAgB;AAG7D,SAASC,UAAA,EAAYC,IAAA,QAAY;AACjC,SAASC,SAAA,QAAiB;AAC1B,SACEC,OAAA,EACAC,QAAA,EACAC,SAAA,EACAC,UAAA,EACAC,QAAA,EACAC,WAAA,EACAC,MAAA,QACK;AAoNG,SAYIC,GAAA,EAZJC,IAAA;AAnMV,SAASC,SAASC,MAAA,EAAqC;EACrD,MAAMC,OAAA,GAAUD,MAAA;EAChB,OACEE,OAAA,CAAQD,OAAA,EAASE,iB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AAhB,GAAA,CAACT,IAAA;QAAKwC,KAAA,EAAOD,IAAA;QAAMG,MAAA,EAAQD,IAAA;QAAM4E,QAAA,EAAS;QAASb,MAAA,EAAO;QACxD/E,QAAA,iBAAAf,IAAA,CAACV,IAAA;UACCsH,QAAA,EAAS;UACTlD,IAAA,EAAM;UACNC,GAAA,EAAK;UACL7B,KAAA,EAAOnB,OAAA,CAAQmB,KAAA;UACfE,MAAA,EAAQrB,OAAA,CAAQqB,MAAA;UACf,GAAI;YAAEkB,KAAA,EAAO;cAAE2D,SAAA,EAAW,CAAC;gBAAE5F,KAAA,EAAOQ;cAAM,CAAC;cAAGqF,eAAA,EAAiB;YAAM;UAAE;UAKvE/F,QAAA,GAAAF,IAAA,GACC,eAAAd,GAAA,CAACR,SAAA;YAAUiG,IAAA;YAAYH,KAAA,EAAOD,MAAA;YAAQ2B,GAAA,EAAKlG,IAAA,CAAKkG,GAAA,GAAMtF,KAAA;YAAOuF,KAAA,EAAOnG,IAAA,CAAKmG;UAAA,CAAO,IAC9E,MACHjG,QAAA;QAAA,CACH;MAAA,CACF;IAAA,CACF;EAAA,CACF;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var GraphViewport_exports = {};
|
|
26
|
+
__export(GraphViewport_exports, {
|
|
27
|
+
GraphViewport: () => GraphViewport
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(GraphViewport_exports);
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var import_tamagui = require("tamagui");
|
|
33
|
+
var import_GraphDots = require("./GraphDots.native.js");
|
|
34
|
+
var import_viewMath = require("./viewMath.native.js");
|
|
35
|
+
function editable(target) {
|
|
36
|
+
var _ref;
|
|
37
|
+
var element = target;
|
|
38
|
+
return Boolean(element === null || element === void 0 ? void 0 : element.isContentEditable) || ["INPUT", "TEXTAREA", "SELECT"].includes((_ref = element === null || element === void 0 ? void 0 : element.tagName) !== null && _ref !== void 0 ? _ref : "");
|
|
39
|
+
}
|
|
40
|
+
function onNode(target) {
|
|
41
|
+
var _element_closest;
|
|
42
|
+
var element = target;
|
|
43
|
+
return Boolean(element === null || element === void 0 ? void 0 : (_element_closest = element.closest) === null || _element_closest === void 0 ? void 0 : _element_closest.call(element, "[data-testid^='graph-node-']"));
|
|
44
|
+
}
|
|
45
|
+
function GraphViewport(param) {
|
|
46
|
+
var {
|
|
47
|
+
content,
|
|
48
|
+
viewport,
|
|
49
|
+
dots,
|
|
50
|
+
frozen,
|
|
51
|
+
children
|
|
52
|
+
} = param;
|
|
53
|
+
var scroller = (0, import_react.useRef)(null);
|
|
54
|
+
var [scale, setScale] = (0, import_react.useState)(1);
|
|
55
|
+
var [scroll, setScroll] = (0, import_react.useState)({
|
|
56
|
+
x: 0,
|
|
57
|
+
y: 0
|
|
58
|
+
});
|
|
59
|
+
var offset = (0, import_react.useRef)({
|
|
60
|
+
x: 0,
|
|
61
|
+
y: 0
|
|
62
|
+
});
|
|
63
|
+
var pending = (0, import_react.useRef)(void 0);
|
|
64
|
+
var shown = Math.min(1, Math.max((0, import_viewMath.leastScale)(content, viewport), scale));
|
|
65
|
+
var wide = content.width * shown;
|
|
66
|
+
var tall = content.height * shown;
|
|
67
|
+
var pad = {
|
|
68
|
+
x: Math.max(0, (viewport.width - wide) / 2),
|
|
69
|
+
y: Math.max(0, (viewport.height - tall) / 2)
|
|
70
|
+
};
|
|
71
|
+
var live = (0, import_react.useRef)({
|
|
72
|
+
shown,
|
|
73
|
+
pad,
|
|
74
|
+
content,
|
|
75
|
+
viewport,
|
|
76
|
+
frozen
|
|
77
|
+
});
|
|
78
|
+
live.current = {
|
|
79
|
+
shown,
|
|
80
|
+
pad,
|
|
81
|
+
content,
|
|
82
|
+
viewport,
|
|
83
|
+
frozen
|
|
84
|
+
};
|
|
85
|
+
var node = function node2() {
|
|
86
|
+
var _ref;
|
|
87
|
+
var _scroller_current_getScrollableNode, _scroller_current;
|
|
88
|
+
return (_ref = (_scroller_current = scroller.current) === null || _scroller_current === void 0 ? void 0 : (_scroller_current_getScrollableNode = _scroller_current.getScrollableNode) === null || _scroller_current_getScrollableNode === void 0 ? void 0 : _scroller_current_getScrollableNode.call(_scroller_current)) !== null && _ref !== void 0 ? _ref : void 0;
|
|
89
|
+
};
|
|
90
|
+
var now = function now2() {
|
|
91
|
+
return {
|
|
92
|
+
scale: live.current.shown,
|
|
93
|
+
x: live.current.pad.x - offset.current.x,
|
|
94
|
+
y: live.current.pad.y - offset.current.y
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
var apply = function apply2(next) {
|
|
98
|
+
var {
|
|
99
|
+
content: size,
|
|
100
|
+
viewport: view
|
|
101
|
+
} = live.current;
|
|
102
|
+
var padX = Math.max(0, (view.width - size.width * next.scale) / 2);
|
|
103
|
+
var padY = Math.max(0, (view.height - size.height * next.scale) / 2);
|
|
104
|
+
pending.current = {
|
|
105
|
+
x: Math.max(0, padX - next.x),
|
|
106
|
+
y: Math.max(0, padY - next.y)
|
|
107
|
+
};
|
|
108
|
+
setScale(next.scale);
|
|
109
|
+
};
|
|
110
|
+
var applyRef = (0, import_react.useRef)(apply);
|
|
111
|
+
applyRef.current = apply;
|
|
112
|
+
var nowRef = (0, import_react.useRef)(now);
|
|
113
|
+
nowRef.current = now;
|
|
114
|
+
(0, import_react.useLayoutEffect)(function () {
|
|
115
|
+
var target = pending.current;
|
|
116
|
+
var element = node();
|
|
117
|
+
if (!target) return;
|
|
118
|
+
pending.current = void 0;
|
|
119
|
+
offset.current = target;
|
|
120
|
+
setScroll(target);
|
|
121
|
+
if (element) {
|
|
122
|
+
element.scrollLeft = target.x;
|
|
123
|
+
element.scrollTop = target.y;
|
|
124
|
+
}
|
|
125
|
+
}, [shown]);
|
|
126
|
+
(0, import_react.useEffect)(function () {
|
|
127
|
+
var element = node();
|
|
128
|
+
if (!element || typeof element.addEventListener !== "function") return;
|
|
129
|
+
element.style.touchAction = "pan-x pan-y";
|
|
130
|
+
element.tabIndex = 0;
|
|
131
|
+
var at = function at2(clientX, clientY) {
|
|
132
|
+
var box = element.getBoundingClientRect();
|
|
133
|
+
return {
|
|
134
|
+
x: clientX - box.left,
|
|
135
|
+
y: clientY - box.top
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
var onWheel = function onWheel2(event) {
|
|
139
|
+
if (live.current.frozen || !event.ctrlKey && !event.metaKey) return;
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
var current = nowRef.current();
|
|
142
|
+
var factor = Math.pow(1.002, -event.deltaY);
|
|
143
|
+
applyRef.current((0, import_viewMath.zoomAt)(current, current.scale * factor, at(event.clientX, event.clientY), live.current.content, live.current.viewport));
|
|
144
|
+
};
|
|
145
|
+
var onDouble = function onDouble2(event) {
|
|
146
|
+
if (live.current.frozen || onNode(event.target)) return;
|
|
147
|
+
applyRef.current((0, import_viewMath.toggledView)(nowRef.current(), at(event.clientX, event.clientY), live.current.content, live.current.viewport));
|
|
148
|
+
};
|
|
149
|
+
var onKey = function onKey2(event) {
|
|
150
|
+
if (live.current.frozen || event.ctrlKey || event.metaKey || event.altKey || editable(event.target)) return;
|
|
151
|
+
var next = (0, import_viewMath.keyedView)(event.key, nowRef.current(), live.current.content, live.current.viewport);
|
|
152
|
+
if (!next) return;
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
applyRef.current(next);
|
|
155
|
+
};
|
|
156
|
+
var pinch;
|
|
157
|
+
var spread = function spread2(touches) {
|
|
158
|
+
return Math.hypot(touches[0].clientX - touches[1].clientX, touches[0].clientY - touches[1].clientY);
|
|
159
|
+
};
|
|
160
|
+
var middle = function middle2(touches) {
|
|
161
|
+
return at((touches[0].clientX + touches[1].clientX) / 2, (touches[0].clientY + touches[1].clientY) / 2);
|
|
162
|
+
};
|
|
163
|
+
var onTouchStart = function onTouchStart2(event) {
|
|
164
|
+
pinch = event.touches.length === 2 ? {
|
|
165
|
+
distance: spread(event.touches),
|
|
166
|
+
scale: nowRef.current().scale
|
|
167
|
+
} : void 0;
|
|
168
|
+
};
|
|
169
|
+
var onTouchMove = function onTouchMove2(event) {
|
|
170
|
+
if (live.current.frozen || !pinch || event.touches.length !== 2) return;
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
var ratio = spread(event.touches) / Math.max(1, pinch.distance);
|
|
173
|
+
applyRef.current((0, import_viewMath.zoomAt)(nowRef.current(), pinch.scale * ratio, middle(event.touches), live.current.content, live.current.viewport));
|
|
174
|
+
};
|
|
175
|
+
var onTouchEnd = function onTouchEnd2(event) {
|
|
176
|
+
if (event.touches.length < 2) pinch = void 0;
|
|
177
|
+
};
|
|
178
|
+
element.addEventListener("wheel", onWheel, {
|
|
179
|
+
passive: false
|
|
180
|
+
});
|
|
181
|
+
element.addEventListener("dblclick", onDouble);
|
|
182
|
+
element.addEventListener("keydown", onKey);
|
|
183
|
+
element.addEventListener("touchstart", onTouchStart, {
|
|
184
|
+
passive: true
|
|
185
|
+
});
|
|
186
|
+
element.addEventListener("touchmove", onTouchMove, {
|
|
187
|
+
passive: false
|
|
188
|
+
});
|
|
189
|
+
element.addEventListener("touchend", onTouchEnd);
|
|
190
|
+
return function () {
|
|
191
|
+
element.removeEventListener("wheel", onWheel);
|
|
192
|
+
element.removeEventListener("dblclick", onDouble);
|
|
193
|
+
element.removeEventListener("keydown", onKey);
|
|
194
|
+
element.removeEventListener("touchstart", onTouchStart);
|
|
195
|
+
element.removeEventListener("touchmove", onTouchMove);
|
|
196
|
+
element.removeEventListener("touchend", onTouchEnd);
|
|
197
|
+
};
|
|
198
|
+
}, []);
|
|
199
|
+
var spaced = dots ? (0, import_viewMath.dotPitch)(dots.pitch, shown) : 1;
|
|
200
|
+
var chunk = spaced * 4;
|
|
201
|
+
var reach = {
|
|
202
|
+
width: viewport.width / shown,
|
|
203
|
+
height: viewport.height / shown
|
|
204
|
+
};
|
|
205
|
+
var area = (0, import_viewMath.dotArea)({
|
|
206
|
+
x: scroll.x / shown,
|
|
207
|
+
y: scroll.y / shown
|
|
208
|
+
}, reach, content, chunk);
|
|
209
|
+
var follow = function follow2(event) {
|
|
210
|
+
var {
|
|
211
|
+
x,
|
|
212
|
+
y
|
|
213
|
+
} = event.nativeEvent.contentOffset;
|
|
214
|
+
offset.current = {
|
|
215
|
+
x,
|
|
216
|
+
y
|
|
217
|
+
};
|
|
218
|
+
var next = (0, import_viewMath.dotArea)({
|
|
219
|
+
x: x / shown,
|
|
220
|
+
y: y / shown
|
|
221
|
+
}, reach, content, chunk);
|
|
222
|
+
if (!(0, import_viewMath.sameArea)(next, area)) setScroll({
|
|
223
|
+
x,
|
|
224
|
+
y
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.ScrollView, {
|
|
228
|
+
ref: scroller,
|
|
229
|
+
flex: 1,
|
|
230
|
+
testID: "graph-viewport",
|
|
231
|
+
scrollEnabled: !frozen,
|
|
232
|
+
showsVerticalScrollIndicator: false,
|
|
233
|
+
showsHorizontalScrollIndicator: false,
|
|
234
|
+
scrollEventThrottle: 16,
|
|
235
|
+
onScroll: follow,
|
|
236
|
+
contentContainerStyle: {
|
|
237
|
+
alignSelf: "flex-start"
|
|
238
|
+
},
|
|
239
|
+
...{
|
|
240
|
+
style: {
|
|
241
|
+
overflowX: frozen ? "hidden" : "auto"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
|
|
245
|
+
minWidth: viewport.width,
|
|
246
|
+
minHeight: viewport.height,
|
|
247
|
+
alignItems: "center",
|
|
248
|
+
justifyContent: "center",
|
|
249
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
|
|
250
|
+
width: wide,
|
|
251
|
+
height: tall,
|
|
252
|
+
overflow: "hidden",
|
|
253
|
+
testID: "graph-zoom",
|
|
254
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.View, {
|
|
255
|
+
position: "absolute",
|
|
256
|
+
left: 0,
|
|
257
|
+
top: 0,
|
|
258
|
+
width: content.width,
|
|
259
|
+
height: content.height,
|
|
260
|
+
...{
|
|
261
|
+
style: {
|
|
262
|
+
transform: [{
|
|
263
|
+
scale: shown
|
|
264
|
+
}],
|
|
265
|
+
transformOrigin: "0 0"
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
children: [dots ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_GraphDots.GraphDots, {
|
|
269
|
+
area,
|
|
270
|
+
pitch: spaced,
|
|
271
|
+
dot: dots.dot / shown,
|
|
272
|
+
color: dots.color
|
|
273
|
+
}) : null, children]
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
})
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=GraphViewport.native.js.map
|