@pie-lib/plot 4.0.4-next.3 → 4.0.4-next.30

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.
Files changed (59) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +20 -0
  2. package/dist/draggable.d.ts +13 -0
  3. package/dist/draggable.js +13 -0
  4. package/dist/graph-props.d.ts +22 -0
  5. package/dist/graph-props.js +29 -0
  6. package/dist/grid-draggable.d.ts +91 -0
  7. package/dist/grid-draggable.js +168 -0
  8. package/dist/index.d.ts +16 -0
  9. package/dist/index.js +8 -0
  10. package/dist/label.d.ts +30 -0
  11. package/dist/label.js +132 -0
  12. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  13. package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +28 -0
  14. package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/chunk-D5BXCJ5G.js +503 -0
  15. package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/cjs.js +5 -0
  16. package/dist/root.d.ts +68 -0
  17. package/dist/root.js +302 -0
  18. package/dist/trig.d.ts +41 -0
  19. package/dist/trig.js +47 -0
  20. package/dist/types.d.ts +125 -0
  21. package/dist/types.js +46 -0
  22. package/dist/utils.d.ts +44 -0
  23. package/dist/utils.js +82 -0
  24. package/package.json +35 -25
  25. package/CHANGELOG.json +0 -17
  26. package/CHANGELOG.md +0 -838
  27. package/LICENSE.md +0 -5
  28. package/lib/draggable.js +0 -44
  29. package/lib/draggable.js.map +0 -1
  30. package/lib/graph-props.js +0 -46
  31. package/lib/graph-props.js.map +0 -1
  32. package/lib/grid-draggable.js +0 -361
  33. package/lib/grid-draggable.js.map +0 -1
  34. package/lib/index.js +0 -44
  35. package/lib/index.js.map +0 -1
  36. package/lib/label.js +0 -173
  37. package/lib/label.js.map +0 -1
  38. package/lib/root.js +0 -474
  39. package/lib/root.js.map +0 -1
  40. package/lib/trig.js +0 -149
  41. package/lib/trig.js.map +0 -1
  42. package/lib/types.js +0 -40
  43. package/lib/types.js.map +0 -1
  44. package/lib/utils.js +0 -165
  45. package/lib/utils.js.map +0 -1
  46. package/src/__tests__/draggable.test.jsx +0 -41
  47. package/src/__tests__/grid-draggable.test.jsx +0 -487
  48. package/src/__tests__/root.test.jsx +0 -277
  49. package/src/__tests__/trig.test.js +0 -163
  50. package/src/__tests__/utils.test.js +0 -229
  51. package/src/draggable.jsx +0 -11
  52. package/src/graph-props.js +0 -34
  53. package/src/grid-draggable.jsx +0 -332
  54. package/src/index.js +0 -9
  55. package/src/label.jsx +0 -199
  56. package/src/root.jsx +0 -485
  57. package/src/trig.js +0 -151
  58. package/src/types.js +0 -41
  59. package/src/utils.js +0 -167
package/dist/root.js ADDED
@@ -0,0 +1,302 @@
1
+ import { ChildrenType as e, GraphPropsType as t } from "./types.js";
2
+ import { extractTextFromHTML as n, isEmptyObject as r, isEmptyString as i } from "./utils.js";
3
+ import a from "./label.js";
4
+ import o from "react";
5
+ import { styled as s } from "@mui/material/styles";
6
+ import c from "prop-types";
7
+ import { pointer as l, select as u } from "d3-selection";
8
+ import * as d from "@pie-lib/render-ui";
9
+ import { Readable as f, color as p } from "@pie-lib/render-ui";
10
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
11
+ import g from "@pie-lib/editable-html-tip-tap";
12
+ //#region src/root.tsx
13
+ function _(e) {
14
+ return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
15
+ }
16
+ function v(e, t) {
17
+ return !e || _(e) ? e : _(e.default) ? e.default : t && _(e[t]) ? e[t] : t && _(e[t]?.default) ? e[t].default : e;
18
+ }
19
+ var y = v(f, "Readable") || v(S.Readable, "Readable"), b = d, x = b.default, S = x && typeof x == "object" ? x : b, C = { "& .ProseMirror p.is-editor-empty::before, & .ProseMirror div.is-editor-empty::before": {
20
+ left: 0,
21
+ right: 0,
22
+ width: "100%",
23
+ textAlign: "center"
24
+ } }, w = s("div")(({ theme: e }) => ({
25
+ border: `solid 1px ${p.primaryLight()}`,
26
+ color: p.defaults.TEXT,
27
+ backgroundColor: e.palette.common.white,
28
+ touchAction: "none",
29
+ position: "relative",
30
+ boxSizing: "unset"
31
+ })), T = s("div")({
32
+ display: "flex",
33
+ position: "relative"
34
+ }), E = s("svg")({
35
+ paddingLeft: "50px",
36
+ overflow: "visible",
37
+ boxSizing: "content-box"
38
+ }), D = s("svg")({
39
+ overflow: "visible",
40
+ boxSizing: "content-box"
41
+ }), O = s("g")({
42
+ cursor: "pointer",
43
+ userSelect: "none"
44
+ }), k = s("div")(({ theme: e }) => ({
45
+ color: p.defaults.TEXT,
46
+ fontSize: e.typography.fontSize + 2,
47
+ padding: `${e.spacing(1.5)} ${e.spacing(.5)} 0`,
48
+ textAlign: "center",
49
+ "&.disabled": { pointerEvents: "none" },
50
+ "&.rightMargin": { marginRight: "74px" },
51
+ "& p": { margin: 0 },
52
+ ...C
53
+ })), A = s("div")(({ theme: e }) => ({
54
+ color: p.defaults.TEXT,
55
+ fontSize: e.typography.fontSize + 4,
56
+ padding: `${e.spacing(1.5)} ${e.spacing(.5)} 0`,
57
+ textAlign: "center",
58
+ "&.disabled": { pointerEvents: "none" },
59
+ "&.rightMargin": { marginRight: "74px" },
60
+ "& p": { margin: 0 },
61
+ ...C
62
+ })), j = s("div")({
63
+ display: "flex",
64
+ paddingTop: "6px"
65
+ }), M = s("div")({
66
+ display: "flex",
67
+ flexDirection: "column",
68
+ alignItems: "center",
69
+ width: "100px",
70
+ pointerEvents: "none",
71
+ userSelect: "none"
72
+ }), N = s("div")({
73
+ width: "70px",
74
+ display: "flex",
75
+ flexDirection: "column",
76
+ marginRight: "6px"
77
+ }), P = s("div")({
78
+ textAlign: "right",
79
+ height: "20px",
80
+ pointerEvents: "none",
81
+ userSelect: "none",
82
+ "&:not(:last-child)": { marginBottom: "80px" }
83
+ }), F = class extends o.Component {
84
+ constructor(e) {
85
+ super(e), this.state = { titleHeight: 0 }, this.resizeObserver = null;
86
+ }
87
+ static propTypes = {
88
+ title: c.string,
89
+ children: e,
90
+ defineChart: c.bool,
91
+ disabledLabels: c.bool,
92
+ disabledTitle: c.bool,
93
+ graphProps: t.isRequired,
94
+ isChart: c.bool,
95
+ labels: c.object,
96
+ labelsPlaceholders: c.object,
97
+ onChangeTitle: c.func,
98
+ onMouseMove: c.func,
99
+ showLabels: c.bool,
100
+ showTitle: c.bool,
101
+ showPixelGuides: c.bool,
102
+ rootRef: c.func,
103
+ onChangeLabels: c.func,
104
+ titlePlaceholder: c.string,
105
+ mathMlOptions: c.object,
106
+ labelsCharactersLimit: c.number
107
+ };
108
+ mouseMove = (e, t) => {
109
+ let { graphProps: n, onMouseMove: r } = this.props;
110
+ if (!r) return;
111
+ let { scale: i, snap: a } = n, o = l(t, e.node()), s = i.x.invert(o[0]), c = i.y.invert(o[1]);
112
+ r({
113
+ x: a.x(s),
114
+ y: a.y(c)
115
+ });
116
+ };
117
+ componentDidMount() {
118
+ let e = u(this.g);
119
+ e.on("mousemove", this.mouseMove.bind(this, e)), this.measureTitleHeight(), this.setupVisibilityObserver();
120
+ }
121
+ componentWillUnmount() {
122
+ u(this.g).on("mousemove", null), this.cleanupVisibilityObserver();
123
+ }
124
+ componentDidUpdate(e) {
125
+ e.title !== this.props.title && this.measureTitleHeight();
126
+ }
127
+ onChangeLabel = (e, t) => {
128
+ let { labels: n, onChangeLabels: r, isChart: i } = this.props;
129
+ if (r) {
130
+ if (i) {
131
+ r(t === "left" ? "range" : "domain", e);
132
+ return;
133
+ }
134
+ r({
135
+ ...n,
136
+ [t]: e
137
+ });
138
+ }
139
+ };
140
+ measureTitleHeight = () => {
141
+ let e = this.titleRef;
142
+ if (e) {
143
+ let t = e.clientHeight;
144
+ this.setState({
145
+ titleHeight: t,
146
+ prevTitle: this.props.title
147
+ }), !this.resizeObserver && typeof ResizeObserver < "u" && this.setupVisibilityObserver();
148
+ }
149
+ };
150
+ handleKeyDown = () => {
151
+ setTimeout(() => {
152
+ this.measureTitleHeight();
153
+ }, 0);
154
+ };
155
+ setupVisibilityObserver = () => {
156
+ typeof ResizeObserver < "u" && this.titleRef && (this.resizeObserver = new ResizeObserver((e) => {
157
+ for (let t of e) {
158
+ let { width: e, height: n } = t.contentRect;
159
+ if (e > 0 && n > 0) {
160
+ setTimeout(() => {
161
+ this.measureTitleHeight();
162
+ }, 10);
163
+ break;
164
+ }
165
+ }
166
+ }), this.resizeObserver.observe(this.titleRef));
167
+ };
168
+ cleanupVisibilityObserver = () => {
169
+ this.resizeObserver &&= (this.resizeObserver.disconnect(), null);
170
+ };
171
+ render() {
172
+ let { disabledTitle: e, disabledLabels: t, labels: o, labelsPlaceholders: s, titlePlaceholder: c, graphProps: l, children: u, defineChart: d, onChangeTitle: f, isChart: p, showLabels: _, showPixelGuides: v, showTitle: b, title: x, rootRef: S, mathMlOptions: C = {}, labelsCharactersLimit: F } = this.props, { size: { width: I = 500, height: L = 500 }, domain: R, range: z } = l, B = i(n(o?.left)) && r(s) ? 48 : 70, V = i(n(o?.right)) && r(s) ? 48 : 70, H = I + B + V + (R.padding || 0) * 2, U = L + 80 + (z.padding || 0) * 2, W = [
173
+ "bold",
174
+ "italic",
175
+ "underline",
176
+ "superscript",
177
+ "subscript",
178
+ "strikethrough",
179
+ "math"
180
+ ], G = d && v ? L - 160 : L, K = parseInt(I / 100), q = parseInt(G / 100), J = parseInt(G % 100), { titleHeight: Y } = this.state;
181
+ return /* @__PURE__ */ h(w, { children: [
182
+ v && /* @__PURE__ */ m(j, {
183
+ style: { marginLeft: p ? 80 : _ ? 30 : 10 },
184
+ children: [...Array(K + 1).keys()].map((e) => /* @__PURE__ */ m(y, {
185
+ false: !0,
186
+ children: /* @__PURE__ */ h(M, { children: [/* @__PURE__ */ h("div", { children: [e * 100, "px"] }), /* @__PURE__ */ m("div", { children: "|" })] })
187
+ }, `top-guide-${e}`))
188
+ }),
189
+ b && (e ? /* @__PURE__ */ m("div", {
190
+ ref: (e) => this.titleRef = e,
191
+ style: {
192
+ ...p && { width: H },
193
+ ...i(n(x)) && { display: "none" }
194
+ },
195
+ children: m(p ? A : k, {
196
+ className: "disabled",
197
+ dangerouslySetInnerHTML: { __html: x || "" }
198
+ })
199
+ }) : /* @__PURE__ */ m("div", {
200
+ ref: (e) => this.titleRef = e,
201
+ children: m(p ? A : k, {
202
+ className: v ? "rightMargin" : "",
203
+ children: /* @__PURE__ */ m(g, {
204
+ ...p && { width: H },
205
+ markup: x || "",
206
+ onChange: f,
207
+ placeholder: d && c || !e && "Click here to add a title for this graph",
208
+ toolbarOpts: {
209
+ noPadding: !0,
210
+ noBorder: !0
211
+ },
212
+ activePlugins: W,
213
+ disableScrollbar: !0,
214
+ onKeyDown: this.handleKeyDown
215
+ })
216
+ })
217
+ })),
218
+ _ && !p && /* @__PURE__ */ m(a, {
219
+ side: "top",
220
+ text: o.top,
221
+ disabledLabel: t,
222
+ placeholder: s?.top,
223
+ graphHeight: U,
224
+ graphWidth: H,
225
+ onChange: (e) => this.onChangeLabel(e, "top"),
226
+ mathMlOptions: C,
227
+ preventNewLines: !0,
228
+ charactersLimit: F
229
+ }),
230
+ /* @__PURE__ */ h(T, { children: [
231
+ _ && /* @__PURE__ */ m(a, {
232
+ side: "left",
233
+ text: o.left,
234
+ disabledLabel: t,
235
+ placeholder: s?.left,
236
+ graphHeight: U,
237
+ graphWidth: H,
238
+ isChartLeftLabel: p && !d,
239
+ isDefineChartLeftLabel: p && d,
240
+ onChange: (e) => this.onChangeLabel(e, "left"),
241
+ mathMlOptions: C,
242
+ preventNewLines: !0,
243
+ charactersLimit: F
244
+ }),
245
+ m(d ? E : D, {
246
+ width: H,
247
+ height: U,
248
+ children: /* @__PURE__ */ m(O, {
249
+ ref: (e) => {
250
+ this.g = e, S && S(e);
251
+ },
252
+ transform: `translate(${B + (R.padding || 0)}, ${40 + (z.padding || 0)})`,
253
+ children: u
254
+ })
255
+ }),
256
+ _ && !p && /* @__PURE__ */ m(a, {
257
+ side: "right",
258
+ text: o.right,
259
+ disabledLabel: t,
260
+ placeholder: s?.right,
261
+ graphHeight: U,
262
+ graphWidth: H,
263
+ onChange: (e) => this.onChangeLabel(e, "right"),
264
+ mathMlOptions: C,
265
+ preventNewLines: !0,
266
+ charactersLimit: F
267
+ }),
268
+ v && /* @__PURE__ */ m(N, {
269
+ style: {
270
+ paddingTop: J,
271
+ marginTop: 31
272
+ },
273
+ children: [...Array(q + 1).keys()].reverse().map((e) => /* @__PURE__ */ m(y, {
274
+ false: !0,
275
+ children: /* @__PURE__ */ h(P, { children: [
276
+ "━ ",
277
+ e * 100,
278
+ "px"
279
+ ] })
280
+ }, `top-guide-${e}`))
281
+ })
282
+ ] }),
283
+ _ && /* @__PURE__ */ m(a, {
284
+ side: "bottom",
285
+ text: o.bottom,
286
+ disabledLabel: t,
287
+ placeholder: s?.bottom,
288
+ graphHeight: U,
289
+ graphWidth: H,
290
+ titleHeight: Y,
291
+ isChartBottomLabel: p && !d,
292
+ isDefineChartBottomLabel: p && d,
293
+ onChange: (e) => this.onChangeLabel(e, "bottom"),
294
+ mathMlOptions: C,
295
+ preventNewLines: !0,
296
+ charactersLimit: F
297
+ })
298
+ ] });
299
+ }
300
+ };
301
+ //#endregion
302
+ export { F as default };
package/dist/trig.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/plot/src/trig.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ import Point from '@mapbox/point-geometry';
10
+ export declare const toDegrees: (radians: any) => number;
11
+ export declare const toRadians: (degrees: any) => number;
12
+ /**
13
+ * return angle in radians between 2 points using counting degrees counter clockwise
14
+ *
15
+ * 0,0 + 1,1 = 45 in radians
16
+ * 1,1 + 0,0 = 45?
17
+ * @param {Point} a
18
+ * @param {Point} b
19
+ */
20
+ export declare const angle: (a: any, b: any) => number;
21
+ export declare const acuteXAngle: (a: any) => any;
22
+ export declare const acuteYAngle: (a: any) => number;
23
+ export declare const hypotenuse: (a: any, alpha: any) => number;
24
+ /**
25
+ * return 2 edge points for a,b within domain + range.
26
+ * - one edge is from following a -> b to the bounds
27
+ * - one edge is from following b -> a to the bounds
28
+ * @param {{min: number, max: number}} domain
29
+ * @param {{min: number, max: number}} range
30
+ * @param {{x: number, y: number}} a
31
+ * @param {{x: number, y: number}} b
32
+ * @returns [{x: number, y: number}, {x: number, y: number}]
33
+ */
34
+ export declare const edges: (domain: any, range: any) => (a: any, b: any) => Point[];
35
+ /** get length of side A of a triangle from H and angle Alpha */
36
+ export declare const getOpposingSide: (hyp: any, angle: any) => number;
37
+ /**
38
+ * return the difference between bounds and a as a Point
39
+ * @param {*} bounds
40
+ */
41
+ export declare const diffEdge: (bounds: any, a: any, b: any) => Point;
package/dist/trig.js ADDED
@@ -0,0 +1,47 @@
1
+ import { __exportAll as e } from "./_virtual/_rolldown/runtime.js";
2
+ import { xy as t } from "./utils.js";
3
+ import n from "@mapbox/point-geometry";
4
+ import r from "debug";
5
+ //#region src/trig.ts
6
+ var i = /* @__PURE__ */ e({
7
+ acuteXAngle: () => f,
8
+ acuteYAngle: () => p,
9
+ angle: () => c,
10
+ diffEdge: () => v,
11
+ edges: () => h,
12
+ getOpposingSide: () => g,
13
+ hypotenuse: () => m,
14
+ toDegrees: () => o,
15
+ toRadians: () => s
16
+ }), a = r("pie-lib:plot:trig"), o = (e) => 180 / Math.PI * e, s = (e) => Math.PI / 180 * e, c = (e, t) => {
17
+ let n = t.y - e.y, r = t.x - e.x;
18
+ a(e, t, "vd: ", n, "hd: ", r);
19
+ let i = Math.atan2(n, r);
20
+ return i < 0 ? i + Math.PI * 2 : i;
21
+ }, l = Math.PI / 2, u = Math.PI, d = u + l, f = (e) => (a(o(e)), e < l ? e : Math.abs(e < u || e < d ? u - e : Math.PI * 2 - e)), p = (e) => l - f(e), m = (e, t) => Math.abs(e / Math.sin(t)), h = (e, n) => (r, i) => [v(t(r.x < i.x ? e.max : e.min, r.y < i.y ? n.max : n.min), r, i), v(t(i.x < r.x ? e.max : e.min, i.y < r.y ? n.max : n.min), i, r)], g = (e, t) => (a("[getOpposingSide] hyp: ", e, "angle:", t), Math.abs(e * Math.sin(t))), _ = (e, t) => {
22
+ if (Number.isFinite(e) && Number.isFinite(t)) return e === 0 && t > 0 ? "y" : t === 0 && e > 0 || e < t ? "x" : "y";
23
+ if (isNaN(e) && !isNaN(t)) return "y";
24
+ if (!isNaN(e) && isNaN(t)) return "x";
25
+ if (e === Infinity) return "y";
26
+ if (t === Infinity) return "x";
27
+ console.warn("hypotenuse - which is shorter? x:", e, "y:", t);
28
+ }, v = (e, t, r) => {
29
+ let i = a.enabled ? a.bind(a, `diffEdge: [${t.x},${t.y} -> ${r.x},${r.y}]`) : () => {}, l = c(t, r);
30
+ i("x angle", o(l));
31
+ let u = Math.abs(l - s(90));
32
+ i("y angle", o(u));
33
+ let d = Math.abs(t.x - e.x), f = m(d, u), p = Math.abs(t.y - e.y), h = m(p, l);
34
+ i("x: side", d, "h:", f), i("y: side", p, "h:", h);
35
+ let v = _(f, h);
36
+ if (v !== "x" && v !== "y") throw Error("Cant decide which hypotenuse to use");
37
+ let y = v === "x" ? new n(d, g(f, l)) : new n(g(h, u), p);
38
+ i("point:", y);
39
+ let b = new n(r.x < t.x ? -1 : 1, r.y < t.y ? -1 : 1);
40
+ i("multiplier:", b);
41
+ let x = y.multByPoint(b);
42
+ i("out:", x);
43
+ let S = x.add(new n(t.x, t.y));
44
+ return i("normalized:", S), S;
45
+ };
46
+ //#endregion
47
+ export { i as trig_exports };
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/plot/src/types.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ import PropTypes from 'prop-types';
10
+ export declare const BaseDomainRangeType: {
11
+ min: PropTypes.Validator<number>;
12
+ max: PropTypes.Validator<number>;
13
+ step: PropTypes.Requireable<number>;
14
+ };
15
+ export declare const DomainType: PropTypes.Requireable<PropTypes.InferProps<{
16
+ min: PropTypes.Validator<number>;
17
+ max: PropTypes.Validator<number>;
18
+ step: PropTypes.Requireable<number>;
19
+ }>>;
20
+ export declare const RangeType: PropTypes.Requireable<PropTypes.InferProps<{
21
+ min: PropTypes.Validator<number>;
22
+ max: PropTypes.Validator<number>;
23
+ step: PropTypes.Requireable<number>;
24
+ }>>;
25
+ export declare const SizeType: PropTypes.Requireable<PropTypes.InferProps<{
26
+ width: PropTypes.Validator<number>;
27
+ height: PropTypes.Validator<number>;
28
+ }>>;
29
+ export declare const PointType: PropTypes.Requireable<PropTypes.InferProps<{
30
+ x: PropTypes.Validator<number>;
31
+ y: PropTypes.Validator<number>;
32
+ }>>;
33
+ export declare const ChildrenType: PropTypes.Validator<NonNullable<NonNullable<PropTypes.ReactNodeLike>>>;
34
+ export declare const ScaleType: PropTypes.Requireable<PropTypes.InferProps<{
35
+ x: PropTypes.Validator<(...args: any[]) => any>;
36
+ y: PropTypes.Validator<(...args: any[]) => any>;
37
+ }>>;
38
+ export declare const SnapType: PropTypes.Requireable<PropTypes.InferProps<{
39
+ x: PropTypes.Validator<(...args: any[]) => any>;
40
+ y: PropTypes.Validator<(...args: any[]) => any>;
41
+ }>>;
42
+ export declare const GraphPropsType: PropTypes.Requireable<PropTypes.InferProps<{
43
+ scale: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
44
+ x: PropTypes.Validator<(...args: any[]) => any>;
45
+ y: PropTypes.Validator<(...args: any[]) => any>;
46
+ }>>>;
47
+ snap: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
48
+ x: PropTypes.Validator<(...args: any[]) => any>;
49
+ y: PropTypes.Validator<(...args: any[]) => any>;
50
+ }>>>;
51
+ domain: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
52
+ min: PropTypes.Validator<number>;
53
+ max: PropTypes.Validator<number>;
54
+ step: PropTypes.Requireable<number>;
55
+ }>>>;
56
+ range: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
57
+ min: PropTypes.Validator<number>;
58
+ max: PropTypes.Validator<number>;
59
+ step: PropTypes.Requireable<number>;
60
+ }>>>;
61
+ size: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
62
+ width: PropTypes.Validator<number>;
63
+ height: PropTypes.Validator<number>;
64
+ }>>>;
65
+ }>>;
66
+ export declare const ToolPropTypeFields: {
67
+ graphProps: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
68
+ scale: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
69
+ x: PropTypes.Validator<(...args: any[]) => any>;
70
+ y: PropTypes.Validator<(...args: any[]) => any>;
71
+ }>>>;
72
+ snap: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
73
+ x: PropTypes.Validator<(...args: any[]) => any>;
74
+ y: PropTypes.Validator<(...args: any[]) => any>;
75
+ }>>>;
76
+ domain: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
77
+ min: PropTypes.Validator<number>;
78
+ max: PropTypes.Validator<number>;
79
+ step: PropTypes.Requireable<number>;
80
+ }>>>;
81
+ range: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
82
+ min: PropTypes.Validator<number>;
83
+ max: PropTypes.Validator<number>;
84
+ step: PropTypes.Requireable<number>;
85
+ }>>>;
86
+ size: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
87
+ width: PropTypes.Validator<number>;
88
+ height: PropTypes.Validator<number>;
89
+ }>>>;
90
+ }>>>;
91
+ mark: PropTypes.Requireable<object>;
92
+ onChange: PropTypes.Requireable<(...args: any[]) => any>;
93
+ onDelete: PropTypes.Requireable<(...args: any[]) => any>;
94
+ onClick: PropTypes.Requireable<(...args: any[]) => any>;
95
+ };
96
+ export declare const ToolPropType: PropTypes.Requireable<PropTypes.InferProps<{
97
+ graphProps: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
98
+ scale: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
99
+ x: PropTypes.Validator<(...args: any[]) => any>;
100
+ y: PropTypes.Validator<(...args: any[]) => any>;
101
+ }>>>;
102
+ snap: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
103
+ x: PropTypes.Validator<(...args: any[]) => any>;
104
+ y: PropTypes.Validator<(...args: any[]) => any>;
105
+ }>>>;
106
+ domain: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
107
+ min: PropTypes.Validator<number>;
108
+ max: PropTypes.Validator<number>;
109
+ step: PropTypes.Requireable<number>;
110
+ }>>>;
111
+ range: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
112
+ min: PropTypes.Validator<number>;
113
+ max: PropTypes.Validator<number>;
114
+ step: PropTypes.Requireable<number>;
115
+ }>>>;
116
+ size: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
117
+ width: PropTypes.Validator<number>;
118
+ height: PropTypes.Validator<number>;
119
+ }>>>;
120
+ }>>>;
121
+ mark: PropTypes.Requireable<object>;
122
+ onChange: PropTypes.Requireable<(...args: any[]) => any>;
123
+ onDelete: PropTypes.Requireable<(...args: any[]) => any>;
124
+ onClick: PropTypes.Requireable<(...args: any[]) => any>;
125
+ }>>;
package/dist/types.js ADDED
@@ -0,0 +1,46 @@
1
+ import { __exportAll as e } from "./_virtual/_rolldown/runtime.js";
2
+ import t from "prop-types";
3
+ //#region src/types.ts
4
+ var n = /* @__PURE__ */ e({
5
+ BaseDomainRangeType: () => r,
6
+ ChildrenType: () => c,
7
+ DomainType: () => i,
8
+ GraphPropsType: () => d,
9
+ PointType: () => s,
10
+ RangeType: () => a,
11
+ ScaleType: () => l,
12
+ SizeType: () => o,
13
+ SnapType: () => u,
14
+ ToolPropType: () => p,
15
+ ToolPropTypeFields: () => f
16
+ }), r = {
17
+ min: t.number.isRequired,
18
+ max: t.number.isRequired,
19
+ step: t.number
20
+ }, i = t.shape(r), a = t.shape(r), o = t.shape({
21
+ width: t.number.isRequired,
22
+ height: t.number.isRequired
23
+ }), s = t.shape({
24
+ x: t.number.isRequired,
25
+ y: t.number.isRequired
26
+ }), c = t.oneOfType([t.arrayOf(t.node), t.node]).isRequired, l = t.shape({
27
+ x: t.func.isRequired,
28
+ y: t.func.isRequired
29
+ }), u = t.shape({
30
+ x: t.func.isRequired,
31
+ y: t.func.isRequired
32
+ }), d = t.shape({
33
+ scale: l.isRequired,
34
+ snap: u.isRequired,
35
+ domain: i.isRequired,
36
+ range: a.isRequired,
37
+ size: o.isRequired
38
+ }), f = {
39
+ graphProps: d.isRequired,
40
+ mark: t.object,
41
+ onChange: t.func,
42
+ onDelete: t.func,
43
+ onClick: t.func
44
+ }, p = t.shape(f);
45
+ //#endregion
46
+ export { c as ChildrenType, d as GraphPropsType, n as types_exports };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/plot/src/utils.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ import Point from '@mapbox/point-geometry';
10
+ export declare const xy: (x: any, y: any) => {
11
+ x: any;
12
+ y: any;
13
+ };
14
+ export declare const buildSizeArray: (size: any, padding: any) => number[];
15
+ export declare const tickCount: (min: any, max: any, step: any) => number;
16
+ export declare function getInterval(domain: any, ticks: any): number;
17
+ export declare function snapTo(min: any, max: any, interval: any, value: any): any;
18
+ export declare function buildTickModel(domain: any, ticks: any, interval: any, scaleFn: any): {
19
+ value: number;
20
+ major: boolean;
21
+ x: any;
22
+ }[];
23
+ export declare const polygonToArea: (points: any) => unknown;
24
+ export declare const lineToArea: (from: any, to: any) => {
25
+ left: number;
26
+ top: number;
27
+ bottom: number;
28
+ right: number;
29
+ };
30
+ export declare const bounds: (area: any, domain: any, range: any) => {
31
+ left: number;
32
+ right: number;
33
+ top: number;
34
+ bottom: number;
35
+ };
36
+ export declare const point: (o: any) => Point;
37
+ export declare const getDelta: (from: any, to: any) => Point;
38
+ export declare const bandKey: (d: any, index: any) => string;
39
+ export declare const isDomainRangeEqual: (graphProps: any, nextGraphProps: any) => boolean;
40
+ export declare const findLongestWord: (label: any) => any;
41
+ export declare const amountToIncreaseWidth: (longestWord: any) => number;
42
+ export declare const extractTextFromHTML: (htmlString: any) => string;
43
+ export declare const isEmptyObject: (obj: any) => any;
44
+ export declare const isEmptyString: (str: any) => boolean;
package/dist/utils.js ADDED
@@ -0,0 +1,82 @@
1
+ import { __exportAll as e, __toESM as t } from "./_virtual/_rolldown/runtime.js";
2
+ import { require_browser as n } from "./node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js";
3
+ import { head as r, isEqual as i, range as a, tail as o } from "@pie-element/shared-lodash";
4
+ import s from "@mapbox/point-geometry";
5
+ //#region src/utils.ts
6
+ var c = /* @__PURE__ */ e({
7
+ amountToIncreaseWidth: () => T,
8
+ bandKey: () => S,
9
+ bounds: () => y,
10
+ buildSizeArray: () => d,
11
+ buildTickModel: () => g,
12
+ extractTextFromHTML: () => E,
13
+ findLongestWord: () => w,
14
+ getDelta: () => x,
15
+ getInterval: () => p,
16
+ isDomainRangeEqual: () => C,
17
+ isEmptyObject: () => D,
18
+ isEmptyString: () => O,
19
+ lineToArea: () => v,
20
+ point: () => b,
21
+ polygonToArea: () => _,
22
+ snapTo: () => h,
23
+ tickCount: () => f,
24
+ xy: () => u
25
+ }), l = /* @__PURE__ */ t(n(), 1), u = (e, t) => ({
26
+ x: e,
27
+ y: t
28
+ }), d = (e, t) => {
29
+ t = Number.isFinite(t) ? Math.max(t, 0) : 0, (0, l.default)(t < e, "padding must be less than size");
30
+ let n = Math.round(t * .5);
31
+ return [n, e - n];
32
+ }, f = (e, t, n) => {
33
+ (0, l.default)(e < t, "min must be less than max");
34
+ let r = Math.abs(e - t);
35
+ return Math.round(r / n);
36
+ };
37
+ function p(e, t) {
38
+ let { min: n, max: r } = e, { major: i, minor: a } = t;
39
+ if (n >= r) throw Error(`min is > max: ${n} > ${r}`);
40
+ let o = r - n, s = a > 0 ? a + 1 : 1, c = i - 1;
41
+ if (isNaN(c) || c <= 0) throw Error("Tick Frequency must be 2 or higher");
42
+ let l = o / (c * s);
43
+ return parseFloat(Number(l).toFixed(4));
44
+ }
45
+ var m = (e, t, n) => {
46
+ let r = a(e, t, n);
47
+ return r.splice(r.length, 1, t), r;
48
+ };
49
+ function h(e, t, n, r) {
50
+ if (r >= t) return t;
51
+ if (r <= e) return e;
52
+ let i = m(e, t, n);
53
+ return i = i.filter((e) => Math.abs(r - e) <= n), i.length && i.reduce((e, t) => Math.abs(t - r) <= Math.abs(e - r) ? t : e);
54
+ }
55
+ function g(e, t, n, r) {
56
+ return m(e.min, e.max, n).map((e, n) => ({
57
+ value: e,
58
+ major: n % (t.minor + 1) === 0,
59
+ x: r(e)
60
+ }));
61
+ }
62
+ var _ = (e) => {
63
+ let t = r(e), n = {
64
+ left: t.x,
65
+ top: t.y,
66
+ bottom: t.y,
67
+ right: t.x
68
+ };
69
+ return o(e).reduce((e, t) => (e.left = Math.min(e.left, t.x), e.top = Math.max(e.top, t.y), e.bottom = Math.min(e.bottom, t.y), e.right = Math.max(e.right, t.x), e), n);
70
+ }, v = (e, t) => ({
71
+ left: Math.min(e.x, t.x),
72
+ top: Math.max(e.y, t.y),
73
+ bottom: Math.min(e.y, t.y),
74
+ right: Math.max(e.x, t.x)
75
+ }), y = (e, t, n) => ({
76
+ left: t.min - e.left,
77
+ right: Math.abs(e.right - t.max),
78
+ top: Math.abs(e.top - n.max),
79
+ bottom: n.min - e.bottom
80
+ }), b = (e) => new s(e.x, e.y), x = (e, t) => b(t).sub(b(e)), S = (e, t) => `${t}-${e.label || "-"}`, C = (e, t) => i(e.domain, t.domain) && i(e.range, t.range), w = (e) => (e || "").replace(/<[^>]+>/g, "").split(" ").sort((e, t) => t.length - e.length)[0].length, T = (e) => e ? e * 20 : 0, E = (e) => (new DOMParser()?.parseFromString(e, "text/html"))?.body?.textContent || "", D = (e) => e && Object.keys(e).length === 0 && e.constructor === Object, O = (e) => typeof e == "string" && e.trim() === "";
81
+ //#endregion
82
+ export { E as extractTextFromHTML, x as getDelta, D as isEmptyObject, O as isEmptyString, h as snapTo, c as utils_exports, u as xy };