@pie-lib/tools 2.0.2 → 2.0.3-next.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/_virtual/_rolldown/runtime.js +11 -0
- package/dist/anchor-utils.d.ts +60 -0
- package/dist/anchor-utils.js +87 -0
- package/dist/anchor.d.ts +13 -0
- package/dist/anchor.js +17 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +5 -0
- package/dist/node_modules/.bun/assert@1.5.1/node_modules/assert/assert.js +174 -0
- package/dist/node_modules/.bun/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/actualApply.js +13 -0
- package/dist/node_modules/.bun/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/functionApply.js +8 -0
- package/dist/node_modules/.bun/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/functionCall.js +8 -0
- package/dist/node_modules/.bun/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/index.js +16 -0
- package/dist/node_modules/.bun/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/reflectApply.js +8 -0
- package/dist/node_modules/.bun/call-bound@1.0.4/node_modules/call-bound/index.js +14 -0
- package/dist/node_modules/.bun/degrees-radians@1.0.3/node_modules/degrees-radians/index.js +12 -0
- package/dist/node_modules/.bun/dunder-proto@1.0.1/node_modules/dunder-proto/get.js +19 -0
- package/dist/node_modules/.bun/es-define-property@1.0.1/node_modules/es-define-property/index.js +14 -0
- package/dist/node_modules/.bun/es-errors@1.3.0/node_modules/es-errors/eval.js +8 -0
- package/dist/node_modules/.bun/es-errors@1.3.0/node_modules/es-errors/index.js +8 -0
- package/dist/node_modules/.bun/es-errors@1.3.0/node_modules/es-errors/range.js +8 -0
- package/dist/node_modules/.bun/es-errors@1.3.0/node_modules/es-errors/ref.js +8 -0
- package/dist/node_modules/.bun/es-errors@1.3.0/node_modules/es-errors/syntax.js +8 -0
- package/dist/node_modules/.bun/es-errors@1.3.0/node_modules/es-errors/type.js +8 -0
- package/dist/node_modules/.bun/es-errors@1.3.0/node_modules/es-errors/uri.js +8 -0
- package/dist/node_modules/.bun/es-object-atoms@1.1.2/node_modules/es-object-atoms/index.js +8 -0
- package/dist/node_modules/.bun/function-bind@1.1.2/node_modules/function-bind/implementation.js +34 -0
- package/dist/node_modules/.bun/function-bind@1.1.2/node_modules/function-bind/index.js +10 -0
- package/dist/node_modules/.bun/get-intrinsic@1.3.0/node_modules/get-intrinsic/index.js +283 -0
- package/dist/node_modules/.bun/get-proto@1.0.1/node_modules/get-proto/Object.getPrototypeOf.js +9 -0
- package/dist/node_modules/.bun/get-proto@1.0.1/node_modules/get-proto/Reflect.getPrototypeOf.js +8 -0
- package/dist/node_modules/.bun/get-proto@1.0.1/node_modules/get-proto/index.js +19 -0
- package/dist/node_modules/.bun/gopd@1.2.0/node_modules/gopd/gOPD.js +8 -0
- package/dist/node_modules/.bun/gopd@1.2.0/node_modules/gopd/index.js +15 -0
- package/dist/node_modules/.bun/has-symbols@1.1.0/node_modules/has-symbols/index.js +12 -0
- package/dist/node_modules/.bun/has-symbols@1.1.0/node_modules/has-symbols/shams.js +23 -0
- package/dist/node_modules/.bun/hasown@2.0.4/node_modules/hasown/index.js +10 -0
- package/dist/node_modules/.bun/inherits@2.0.3/node_modules/inherits/inherits_browser.js +19 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/abs.js +8 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/floor.js +8 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/isNaN.js +10 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/max.js +8 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/min.js +8 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/pow.js +8 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/round.js +8 -0
- package/dist/node_modules/.bun/math-intrinsics@1.1.0/node_modules/math-intrinsics/sign.js +12 -0
- package/dist/node_modules/.bun/object-keys@1.1.1/node_modules/object-keys/implementation.js +77 -0
- package/dist/node_modules/.bun/object-keys@1.1.1/node_modules/object-keys/index.js +20 -0
- package/dist/node_modules/.bun/object-keys@1.1.1/node_modules/object-keys/isArguments.js +12 -0
- package/dist/node_modules/.bun/object.assign@4.1.7/node_modules/object.assign/implementation.js +29 -0
- package/dist/node_modules/.bun/object.assign@4.1.7/node_modules/object.assign/polyfill.js +27 -0
- package/dist/node_modules/.bun/radians-degrees@1.0.0/node_modules/radians-degrees/index.js +11 -0
- package/dist/node_modules/.bun/react-portal@4.3.0_6dbf9a050bc9aadb/node_modules/react-portal/es/LegacyPortal.js +77 -0
- package/dist/node_modules/.bun/react-portal@4.3.0_6dbf9a050bc9aadb/node_modules/react-portal/es/Portal.js +55 -0
- package/dist/node_modules/.bun/react-portal@4.3.0_6dbf9a050bc9aadb/node_modules/react-portal/es/PortalCompat.js +9 -0
- package/dist/node_modules/.bun/react-portal@4.3.0_6dbf9a050bc9aadb/node_modules/react-portal/es/utils.js +4 -0
- package/dist/node_modules/.bun/trigonometry-calculator@2.0.0/node_modules/trigonometry-calculator/lib/index.js +53 -0
- package/dist/node_modules/.bun/trigonometry-equations@2.0.1/node_modules/trigonometry-equations/lib/index.js +129 -0
- package/dist/node_modules/.bun/util@0.10.4/node_modules/util/support/isBufferBrowser.js +10 -0
- package/dist/node_modules/.bun/util@0.10.4/node_modules/util/util.js +262 -0
- package/dist/protractor/graphic.d.ts +13 -0
- package/dist/protractor/graphic.js +85 -0
- package/dist/protractor/index.d.ts +29 -0
- package/dist/protractor/index.js +56 -0
- package/dist/rotatable.d.ts +56 -0
- package/dist/rotatable.js +210 -0
- package/dist/ruler/graphic.d.ts +20 -0
- package/dist/ruler/graphic.js +53 -0
- package/dist/ruler/index.d.ts +32 -0
- package/dist/ruler/index.js +77 -0
- package/dist/ruler/unit-type.d.ts +30 -0
- package/dist/ruler/unit-type.js +38 -0
- package/dist/ruler/unit.d.ts +21 -0
- package/dist/ruler/unit.js +69 -0
- package/dist/style-utils.d.ts +12 -0
- package/dist/style-utils.js +5 -0
- package/dist/transform-origin.d.ts +18 -0
- package/dist/transform-origin.js +21 -0
- package/package.json +31 -25
- package/CHANGELOG.json +0 -1
- package/CHANGELOG.md +0 -626
- package/LICENSE.md +0 -5
- package/lib/anchor-utils.js +0 -193
- package/lib/anchor-utils.js.map +0 -1
- package/lib/anchor.js +0 -33
- package/lib/anchor.js.map +0 -1
- package/lib/index.js +0 -33
- package/lib/index.js.map +0 -1
- package/lib/protractor/graphic.js +0 -147
- package/lib/protractor/graphic.js.map +0 -1
- package/lib/protractor/index.js +0 -90
- package/lib/protractor/index.js.map +0 -1
- package/lib/rotatable.js +0 -335
- package/lib/rotatable.js.map +0 -1
- package/lib/ruler/graphic.js +0 -89
- package/lib/ruler/graphic.js.map +0 -1
- package/lib/ruler/index.js +0 -114
- package/lib/ruler/index.js.map +0 -1
- package/lib/ruler/unit-type.js +0 -55
- package/lib/ruler/unit-type.js.map +0 -1
- package/lib/ruler/unit.js +0 -124
- package/lib/ruler/unit.js.map +0 -1
- package/lib/style-utils.js +0 -21
- package/lib/style-utils.js.map +0 -1
- package/lib/transform-origin.js +0 -71
- package/lib/transform-origin.js.map +0 -1
- package/src/__tests__/anchor-utils.test.js +0 -131
- package/src/__tests__/rotatable.test.jsx +0 -263
- package/src/__tests__/transform-origin.test.jsx +0 -24
- package/src/anchor-utils.js +0 -153
- package/src/anchor.jsx +0 -20
- package/src/index.js +0 -6
- package/src/protractor/__tests__/graphic.test.jsx +0 -64
- package/src/protractor/__tests__/index.test.jsx +0 -65
- package/src/protractor/graphic.jsx +0 -82
- package/src/protractor/index.jsx +0 -67
- package/src/rotatable.jsx +0 -290
- package/src/ruler/__tests__/graphic.test.jsx +0 -64
- package/src/ruler/__tests__/index.test.jsx +0 -85
- package/src/ruler/__tests__/unit-type.test.jsx +0 -66
- package/src/ruler/__tests__/unit.test.jsx +0 -68
- package/src/ruler/graphic.jsx +0 -48
- package/src/ruler/index.jsx +0 -78
- package/src/ruler/unit-type.jsx +0 -39
- package/src/ruler/unit.jsx +0 -83
- package/src/style-utils.js +0 -7
- package/src/transform-origin.jsx +0 -60
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { noSelect as e, strokeColor as t } from "../style-utils.js";
|
|
2
|
+
import n from "react";
|
|
3
|
+
import { styled as r } from "@mui/material/styles";
|
|
4
|
+
import { range as i } from "@pie-element/shared-lodash";
|
|
5
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
6
|
+
//#region src/protractor/graphic.tsx
|
|
7
|
+
var s = r("line")(({ theme: e }) => ({
|
|
8
|
+
strokeWidth: "0.2",
|
|
9
|
+
stroke: t(e)
|
|
10
|
+
})), c = ({ angle: e, major: t, minor: n }) => /* @__PURE__ */ a(s, {
|
|
11
|
+
transform: `rotate(${e}, 50.5,50)`,
|
|
12
|
+
style: {},
|
|
13
|
+
x1: "1",
|
|
14
|
+
x2: t ? 10 : n ? 6 : 3,
|
|
15
|
+
y1: "50",
|
|
16
|
+
y2: "50"
|
|
17
|
+
}), l = r("line")(({ theme: e }) => ({
|
|
18
|
+
strokeWidth: "0.2",
|
|
19
|
+
stroke: t(e)
|
|
20
|
+
})), u = ({ angle: e }) => /* @__PURE__ */ a(l, {
|
|
21
|
+
transform: `rotate(${e}, 50.5,50)`,
|
|
22
|
+
style: {},
|
|
23
|
+
x1: "15",
|
|
24
|
+
x2: "46",
|
|
25
|
+
y1: "50",
|
|
26
|
+
y2: "50"
|
|
27
|
+
}), d = r("text")(({ theme: n }) => ({
|
|
28
|
+
fontSize: "2.5px",
|
|
29
|
+
textAnchor: "middle",
|
|
30
|
+
fill: t(n),
|
|
31
|
+
...e()
|
|
32
|
+
})), f = ({ angle: e }) => /* @__PURE__ */ a(d, {
|
|
33
|
+
transform: `rotate(${e - 90}, 50.5, 50)`,
|
|
34
|
+
x: "50",
|
|
35
|
+
y: "12.5",
|
|
36
|
+
children: e
|
|
37
|
+
}), p = r("path")(({ theme: e }) => ({
|
|
38
|
+
strokeWidth: "0.2",
|
|
39
|
+
stroke: t(e)
|
|
40
|
+
})), m = r("line")(({ theme: e }) => ({
|
|
41
|
+
strokeWidth: "0.2",
|
|
42
|
+
stroke: t(e)
|
|
43
|
+
})), h = r("circle")(({ theme: e }) => ({
|
|
44
|
+
strokeWidth: "0.2",
|
|
45
|
+
stroke: t(e),
|
|
46
|
+
fill: "none"
|
|
47
|
+
})), g = class extends n.PureComponent {
|
|
48
|
+
render() {
|
|
49
|
+
return /* @__PURE__ */ o("svg", {
|
|
50
|
+
viewBox: "0 0 102 61",
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ a(p, {
|
|
53
|
+
d: "M 1,50 A 1,1 0 0 1 100,50 L 100,60 L 1,60 Z",
|
|
54
|
+
fill: "none"
|
|
55
|
+
}),
|
|
56
|
+
i(0, 181).map((e) => /* @__PURE__ */ a(c, {
|
|
57
|
+
minor: e % 5 == 0,
|
|
58
|
+
major: e % 10 == 0,
|
|
59
|
+
angle: e
|
|
60
|
+
}, e)),
|
|
61
|
+
i(0, 181, 10).map((e) => /* @__PURE__ */ o(n.Fragment, { children: [/* @__PURE__ */ a(u, { angle: e }), /* @__PURE__ */ a(f, { angle: e })] }, e)),
|
|
62
|
+
/* @__PURE__ */ a(h, {
|
|
63
|
+
r: "4",
|
|
64
|
+
cx: "50.5",
|
|
65
|
+
cy: "50"
|
|
66
|
+
}),
|
|
67
|
+
/* @__PURE__ */ a(m, {
|
|
68
|
+
x1: "48.5",
|
|
69
|
+
x2: "52.5",
|
|
70
|
+
y1: "50",
|
|
71
|
+
y2: "50"
|
|
72
|
+
}),
|
|
73
|
+
/* @__PURE__ */ a(m, {
|
|
74
|
+
transform: "rotate(90 50.5 50)",
|
|
75
|
+
x1: "48.5",
|
|
76
|
+
x2: "52.5",
|
|
77
|
+
y1: "50",
|
|
78
|
+
y2: "50"
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { g as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/tools/src/protractor/index.jsx
|
|
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 React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
export declare class Protractor extends React.Component {
|
|
12
|
+
static propTypes: {
|
|
13
|
+
width: PropTypes.Validator<number>;
|
|
14
|
+
className: PropTypes.Requireable<string>;
|
|
15
|
+
startPosition: PropTypes.Requireable<PropTypes.InferProps<{
|
|
16
|
+
left: PropTypes.Requireable<number>;
|
|
17
|
+
top: PropTypes.Requireable<number>;
|
|
18
|
+
}>>;
|
|
19
|
+
};
|
|
20
|
+
static defaultProps: {
|
|
21
|
+
width: number;
|
|
22
|
+
startPosition: {
|
|
23
|
+
left: number;
|
|
24
|
+
top: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
render(): React.JSX.Element;
|
|
28
|
+
}
|
|
29
|
+
export default Protractor;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import e from "./graphic.js";
|
|
2
|
+
import t from "../anchor.js";
|
|
3
|
+
import n from "../rotatable.js";
|
|
4
|
+
import r from "react";
|
|
5
|
+
import { styled as i } from "@mui/material/styles";
|
|
6
|
+
import a from "prop-types";
|
|
7
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
8
|
+
//#region src/protractor/index.tsx
|
|
9
|
+
var c = i("div")(() => ({ position: "relative" })), l = i(t)(() => ({
|
|
10
|
+
position: "absolute",
|
|
11
|
+
left: 0,
|
|
12
|
+
bottom: 0
|
|
13
|
+
})), u = i(t)(() => ({
|
|
14
|
+
position: "absolute",
|
|
15
|
+
right: 0,
|
|
16
|
+
bottom: 0
|
|
17
|
+
})), d = class extends r.Component {
|
|
18
|
+
static propTypes = {
|
|
19
|
+
width: a.number.isRequired,
|
|
20
|
+
className: a.string,
|
|
21
|
+
startPosition: a.shape({
|
|
22
|
+
left: a.number,
|
|
23
|
+
top: a.number
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
static defaultProps = {
|
|
27
|
+
width: 450,
|
|
28
|
+
startPosition: {
|
|
29
|
+
left: 0,
|
|
30
|
+
top: 0
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
render() {
|
|
34
|
+
let { width: t, startPosition: r } = this.props;
|
|
35
|
+
return /* @__PURE__ */ o(n, {
|
|
36
|
+
startPosition: r,
|
|
37
|
+
handle: [{
|
|
38
|
+
class: "leftAnchor",
|
|
39
|
+
origin: `${t * .495}px ${t * .49}px`
|
|
40
|
+
}, {
|
|
41
|
+
class: "rightAnchor",
|
|
42
|
+
origin: `${t * .495}px ${t * .49}px`
|
|
43
|
+
}],
|
|
44
|
+
children: /* @__PURE__ */ s(c, {
|
|
45
|
+
style: { width: `${t}px` },
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ o(e, {}),
|
|
48
|
+
/* @__PURE__ */ o(l, { className: "leftAnchor" }),
|
|
49
|
+
/* @__PURE__ */ o(u, { className: "rightAnchor" })
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { d as default };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/tools/src/rotatable.jsx
|
|
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 React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
export declare class Rotatable extends React.Component {
|
|
12
|
+
static propTypes: {
|
|
13
|
+
children: PropTypes.Validator<NonNullable<NonNullable<PropTypes.ReactNodeLike>>>;
|
|
14
|
+
showAnchor: PropTypes.Requireable<boolean>;
|
|
15
|
+
handle: PropTypes.Requireable<(PropTypes.InferProps<{
|
|
16
|
+
class: PropTypes.Validator<string>;
|
|
17
|
+
origin: PropTypes.Requireable<string>;
|
|
18
|
+
}> | null | undefined)[]>;
|
|
19
|
+
startPosition: PropTypes.Requireable<PropTypes.InferProps<{
|
|
20
|
+
left: PropTypes.Requireable<number>;
|
|
21
|
+
top: PropTypes.Requireable<number>;
|
|
22
|
+
}>>;
|
|
23
|
+
};
|
|
24
|
+
static defaultProps: {
|
|
25
|
+
showAnchor: boolean;
|
|
26
|
+
startPosition: {
|
|
27
|
+
left: number;
|
|
28
|
+
top: number;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
constructor(props: any);
|
|
32
|
+
componentWillUnmount(): void;
|
|
33
|
+
componentDidMount(): void;
|
|
34
|
+
initHandles: any;
|
|
35
|
+
addMouseUpHandler: any;
|
|
36
|
+
originToXY: any;
|
|
37
|
+
/**
|
|
38
|
+
* Get the anchor point for the given element, origin and rotation.
|
|
39
|
+
* @returns {{left:number, top: number}} - the co-ordinates of the anchor point relative to the whole page.
|
|
40
|
+
*/
|
|
41
|
+
getAnchor: any;
|
|
42
|
+
rotateStart: (origin: any) => (e: any) => void;
|
|
43
|
+
rotateStop: any;
|
|
44
|
+
getAngle(anchor: any, e: any): {
|
|
45
|
+
angle: number;
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
};
|
|
49
|
+
rotate: any;
|
|
50
|
+
mouseDown: any;
|
|
51
|
+
dragStart: any;
|
|
52
|
+
drag: any;
|
|
53
|
+
mouseUp: any;
|
|
54
|
+
render(): React.JSX.Element;
|
|
55
|
+
}
|
|
56
|
+
export default Rotatable;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { parse as e } from "./transform-origin.js";
|
|
2
|
+
import { arctangent as t, distanceBetween as n, getAnchor as r } from "./anchor-utils.js";
|
|
3
|
+
import i from "./node_modules/.bun/react-portal@4.3.0_6dbf9a050bc9aadb/node_modules/react-portal/es/PortalCompat.js";
|
|
4
|
+
import a from "react";
|
|
5
|
+
import { styled as o } from "@mui/material/styles";
|
|
6
|
+
import s from "prop-types";
|
|
7
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
8
|
+
import u from "@mapbox/point-geometry";
|
|
9
|
+
//#region src/rotatable.tsx
|
|
10
|
+
var d = o("svg")({
|
|
11
|
+
position: "absolute",
|
|
12
|
+
zIndex: 100,
|
|
13
|
+
width: "200px",
|
|
14
|
+
height: "80px"
|
|
15
|
+
}), f = ({ left: e, top: t, color: n, fill: r }) => (n ||= "green", r ||= "white", /* @__PURE__ */ c(i, { children: /* @__PURE__ */ c(d, {
|
|
16
|
+
style: {
|
|
17
|
+
left: e - 10,
|
|
18
|
+
top: t - 10
|
|
19
|
+
},
|
|
20
|
+
children: /* @__PURE__ */ c("circle", {
|
|
21
|
+
cx: 10,
|
|
22
|
+
cy: 10,
|
|
23
|
+
r: 8,
|
|
24
|
+
strokeWidth: 1,
|
|
25
|
+
stroke: n,
|
|
26
|
+
fill: r
|
|
27
|
+
})
|
|
28
|
+
}) })), p = o("div")({
|
|
29
|
+
position: "relative",
|
|
30
|
+
display: "inline-block",
|
|
31
|
+
cursor: "move"
|
|
32
|
+
}), m = class extends a.Component {
|
|
33
|
+
static propTypes = {
|
|
34
|
+
children: s.oneOfType([s.arrayOf(s.node), s.node]).isRequired,
|
|
35
|
+
showAnchor: s.bool,
|
|
36
|
+
handle: s.arrayOf(s.shape({
|
|
37
|
+
class: s.string.isRequired,
|
|
38
|
+
origin: s.string
|
|
39
|
+
})),
|
|
40
|
+
startPosition: s.shape({
|
|
41
|
+
left: s.number,
|
|
42
|
+
top: s.number
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
static defaultProps = {
|
|
46
|
+
showAnchor: !1,
|
|
47
|
+
startPosition: {
|
|
48
|
+
left: 0,
|
|
49
|
+
top: 0
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
constructor(e) {
|
|
53
|
+
super(e), this.state = {
|
|
54
|
+
isRotating: !1,
|
|
55
|
+
rotation: 0,
|
|
56
|
+
startAngle: 0,
|
|
57
|
+
angle: 0,
|
|
58
|
+
position: {
|
|
59
|
+
left: e.startPosition.left,
|
|
60
|
+
top: e.startPosition.top
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
componentWillUnmount() {
|
|
65
|
+
document.removeEventListener("mouseup", this.rotateStop), document.removeEventListener("mousemove", this.drag), document.removeEventListener("mousemove", this.rotate), this.handles.forEach((e) => {
|
|
66
|
+
e.el.removeEventListener("mousedown", e.mousedownHandler), e.el.removeEventListener("mouseup", this.rotateStop);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
componentDidMount() {
|
|
70
|
+
this.addMouseUpHandler(), this.initHandles();
|
|
71
|
+
}
|
|
72
|
+
initHandles = () => {
|
|
73
|
+
let { handle: e } = this.props;
|
|
74
|
+
Array.isArray(e) && (this.handles = [], e.forEach((e) => {
|
|
75
|
+
let t = this.rotatable.querySelector(`.${e.class}`);
|
|
76
|
+
if (t) {
|
|
77
|
+
let n = this.rotateStart(e.origin);
|
|
78
|
+
t.addEventListener("mousedown", n), t.addEventListener("mouseup", this.rotateStop), this.handles.push({
|
|
79
|
+
el: t,
|
|
80
|
+
mousedownHandler: n
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
};
|
|
85
|
+
addMouseUpHandler = () => {
|
|
86
|
+
document.addEventListener("mouseup", this.rotateStop);
|
|
87
|
+
};
|
|
88
|
+
originToXY = (t) => {
|
|
89
|
+
let { clientWidth: n, clientHeight: r } = this.rotatable;
|
|
90
|
+
return e({
|
|
91
|
+
width: n,
|
|
92
|
+
height: r
|
|
93
|
+
}, t);
|
|
94
|
+
};
|
|
95
|
+
getAnchor = (e) => {
|
|
96
|
+
let { rotation: t } = this.state, { clientWidth: n, clientHeight: i } = this.rotatable, { top: a, left: o } = this.rotatable.getBoundingClientRect(), s = this.originToXY(e), { top: c, left: l } = r({
|
|
97
|
+
width: n,
|
|
98
|
+
height: i
|
|
99
|
+
}, s, t);
|
|
100
|
+
return {
|
|
101
|
+
top: a + c,
|
|
102
|
+
left: o + l
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
rotateStart = (e) => (t) => {
|
|
106
|
+
let { isRotating: r } = this.state;
|
|
107
|
+
if (r) return;
|
|
108
|
+
t.preventDefault();
|
|
109
|
+
let i = this.getAnchor(e), { rotation: a } = this.state, { angle: o } = this.getAngle(i, t), s = {
|
|
110
|
+
x: 0,
|
|
111
|
+
y: 0
|
|
112
|
+
};
|
|
113
|
+
if (e !== this.state.origin) {
|
|
114
|
+
let { clientWidth: t, clientHeight: r } = this.rotatable;
|
|
115
|
+
s = n({
|
|
116
|
+
width: t,
|
|
117
|
+
height: r
|
|
118
|
+
}, a, this.state.origin, e);
|
|
119
|
+
}
|
|
120
|
+
this.setState({
|
|
121
|
+
origin: e,
|
|
122
|
+
isRotating: !0,
|
|
123
|
+
startAngle: o,
|
|
124
|
+
anchor: i,
|
|
125
|
+
position: {
|
|
126
|
+
left: this.state.position.left + s.x,
|
|
127
|
+
top: this.state.position.top + s.y
|
|
128
|
+
}
|
|
129
|
+
}, () => {
|
|
130
|
+
document.addEventListener("mousemove", this.rotate);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
rotateStop = (e) => {
|
|
134
|
+
let { isRotating: t } = this.state;
|
|
135
|
+
t && (e.preventDefault(), this.setState({
|
|
136
|
+
isRotating: !1,
|
|
137
|
+
angle: this.state.rotation,
|
|
138
|
+
anchor: null,
|
|
139
|
+
current: null
|
|
140
|
+
}, () => {
|
|
141
|
+
document.removeEventListener("mousemove", this.rotate), document.removeEventListener("mousemove", this.drag);
|
|
142
|
+
}));
|
|
143
|
+
};
|
|
144
|
+
getAngle(e, n) {
|
|
145
|
+
let r = n.clientX - e.left, i = (n.clientY - e.top) * -1;
|
|
146
|
+
return {
|
|
147
|
+
angle: t(r, i),
|
|
148
|
+
x: r,
|
|
149
|
+
y: i
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
rotate = (e) => {
|
|
153
|
+
let { isRotating: t } = this.state;
|
|
154
|
+
if (!t) return;
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
let { startAngle: n, angle: r, anchor: i } = this.state, { angle: a, x: o, y: s } = this.getAngle(i, e), c = {
|
|
157
|
+
x: o,
|
|
158
|
+
y: s
|
|
159
|
+
}, l = a - n, u = r + l;
|
|
160
|
+
this.setState({
|
|
161
|
+
rotation: u,
|
|
162
|
+
diff: l,
|
|
163
|
+
current: a,
|
|
164
|
+
computedAnchor: c
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
mouseDown = (e) => {
|
|
168
|
+
this.handles.find((t) => t.el === e.target) || this.dragStart(e);
|
|
169
|
+
};
|
|
170
|
+
dragStart = (e) => {
|
|
171
|
+
let t = new u(e.pageX, e.pageY);
|
|
172
|
+
this.setState({ dragPoint: t }, () => {
|
|
173
|
+
document.addEventListener("mousemove", this.drag);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
drag = (e) => {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
let t = new u(e.pageX, e.pageY).sub(this.state.dragPoint);
|
|
179
|
+
this.setState({ translate: t });
|
|
180
|
+
};
|
|
181
|
+
mouseUp = () => {
|
|
182
|
+
if (!this.state.translate) return;
|
|
183
|
+
let { position: e, translate: t } = this.state, n = {
|
|
184
|
+
left: e.left + t.x,
|
|
185
|
+
top: e.top + t.y
|
|
186
|
+
};
|
|
187
|
+
document.removeEventListener("mousemove", this.drag), this.setState({
|
|
188
|
+
position: n,
|
|
189
|
+
dragPoint: null,
|
|
190
|
+
translate: null
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
render() {
|
|
194
|
+
let { children: e, showAnchor: t } = this.props, { rotation: n, anchor: r, origin: i, translate: a, position: o } = this.state, s = a ? `translate(${a.x}px, ${a.y}px)` : "";
|
|
195
|
+
return /* @__PURE__ */ l(p, {
|
|
196
|
+
style: {
|
|
197
|
+
left: o.left,
|
|
198
|
+
top: o.top,
|
|
199
|
+
transformOrigin: i,
|
|
200
|
+
transform: `${s} rotate(${n}deg)`
|
|
201
|
+
},
|
|
202
|
+
ref: (e) => this.rotatable = e,
|
|
203
|
+
onMouseDown: this.mouseDown,
|
|
204
|
+
onMouseUp: this.mouseUp,
|
|
205
|
+
children: [r && t && /* @__PURE__ */ c(f, { ...r }), e]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
210
|
+
export { m as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/tools/src/ruler/graphic.jsx
|
|
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 React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
export declare class Graphic extends React.PureComponent {
|
|
12
|
+
static propTypes: {
|
|
13
|
+
width: PropTypes.Validator<number>;
|
|
14
|
+
height: PropTypes.Validator<number>;
|
|
15
|
+
units: PropTypes.Validator<number>;
|
|
16
|
+
unit: PropTypes.Validator<object>;
|
|
17
|
+
};
|
|
18
|
+
render(): React.JSX.Element;
|
|
19
|
+
}
|
|
20
|
+
export default Graphic;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { fillColor as e, strokeColor as t } from "../style-utils.js";
|
|
2
|
+
import n from "./unit-type.js";
|
|
3
|
+
import r from "./unit.js";
|
|
4
|
+
import i from "react";
|
|
5
|
+
import { styled as a } from "@mui/material/styles";
|
|
6
|
+
import o from "prop-types";
|
|
7
|
+
import { range as s } from "@pie-element/shared-lodash";
|
|
8
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
9
|
+
//#region src/ruler/graphic.tsx
|
|
10
|
+
var u = a("rect")(({ theme: n }) => ({
|
|
11
|
+
stroke: t(n),
|
|
12
|
+
strokeWidth: "2px",
|
|
13
|
+
fill: e(n)
|
|
14
|
+
})), d = ({ width: e, height: t }) => /* @__PURE__ */ c(u, {
|
|
15
|
+
width: e,
|
|
16
|
+
height: t,
|
|
17
|
+
cx: 0,
|
|
18
|
+
cy: 0
|
|
19
|
+
});
|
|
20
|
+
d.propTypes = {
|
|
21
|
+
width: o.number.isRequired,
|
|
22
|
+
height: o.number.isRequired
|
|
23
|
+
};
|
|
24
|
+
var f = class extends i.PureComponent {
|
|
25
|
+
static propTypes = {
|
|
26
|
+
width: o.number.isRequired,
|
|
27
|
+
height: o.number.isRequired,
|
|
28
|
+
units: o.number.isRequired,
|
|
29
|
+
unit: o.object.isRequired
|
|
30
|
+
};
|
|
31
|
+
render() {
|
|
32
|
+
let { width: e, height: t, units: i, unit: a } = this.props, o = `0 0 ${e} ${t}`, u = e / i, f = t;
|
|
33
|
+
return /* @__PURE__ */ l("svg", {
|
|
34
|
+
viewBox: o,
|
|
35
|
+
children: [
|
|
36
|
+
/* @__PURE__ */ c(d, {
|
|
37
|
+
width: e,
|
|
38
|
+
height: t
|
|
39
|
+
}),
|
|
40
|
+
/* @__PURE__ */ c(n, { label: a.type }),
|
|
41
|
+
s(1, i + 1).map((e) => /* @__PURE__ */ c(r, {
|
|
42
|
+
width: u,
|
|
43
|
+
height: f,
|
|
44
|
+
index: e,
|
|
45
|
+
config: a,
|
|
46
|
+
last: e === i
|
|
47
|
+
}, e))
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { f as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/tools/src/ruler/index.jsx
|
|
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 React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
export declare class Ruler extends React.Component {
|
|
12
|
+
static propTypes: {
|
|
13
|
+
width: PropTypes.Requireable<number>;
|
|
14
|
+
height: PropTypes.Requireable<number>;
|
|
15
|
+
units: PropTypes.Validator<number>;
|
|
16
|
+
measure: PropTypes.Validator<string>;
|
|
17
|
+
startPosition: PropTypes.Requireable<PropTypes.InferProps<{
|
|
18
|
+
left: PropTypes.Validator<number>;
|
|
19
|
+
top: PropTypes.Validator<number>;
|
|
20
|
+
}>>;
|
|
21
|
+
label: PropTypes.Requireable<string>;
|
|
22
|
+
tickCount: PropTypes.Requireable<number>;
|
|
23
|
+
};
|
|
24
|
+
static defaultProps: {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
measure: string;
|
|
28
|
+
units: number;
|
|
29
|
+
};
|
|
30
|
+
render(): React.JSX.Element;
|
|
31
|
+
}
|
|
32
|
+
export default Ruler;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import e from "../anchor.js";
|
|
2
|
+
import t from "../rotatable.js";
|
|
3
|
+
import n from "./graphic.js";
|
|
4
|
+
import r from "react";
|
|
5
|
+
import { styled as i } from "@mui/material/styles";
|
|
6
|
+
import a from "prop-types";
|
|
7
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
8
|
+
//#region src/ruler/index.tsx
|
|
9
|
+
var c = i("div")(({ theme: e }) => ({
|
|
10
|
+
cursor: "move",
|
|
11
|
+
position: "relative",
|
|
12
|
+
backgroundColor: e.palette.secondary.light,
|
|
13
|
+
opacity: 1,
|
|
14
|
+
border: `solid 0px ${e.palette.primary.main}`
|
|
15
|
+
})), l = i(e)(() => ({
|
|
16
|
+
left: "-10px",
|
|
17
|
+
top: "40%"
|
|
18
|
+
})), u = i(e)(() => ({
|
|
19
|
+
right: "-10px",
|
|
20
|
+
top: "40%"
|
|
21
|
+
})), d = class extends r.Component {
|
|
22
|
+
static propTypes = {
|
|
23
|
+
width: a.number,
|
|
24
|
+
height: a.number,
|
|
25
|
+
units: a.number.isRequired,
|
|
26
|
+
measure: a.oneOf(["imperial", "metric"]).isRequired,
|
|
27
|
+
startPosition: a.shape({
|
|
28
|
+
left: a.number.isRequired,
|
|
29
|
+
top: a.number.isRequired
|
|
30
|
+
}),
|
|
31
|
+
label: a.string,
|
|
32
|
+
tickCount: a.number
|
|
33
|
+
};
|
|
34
|
+
static defaultProps = {
|
|
35
|
+
width: 480,
|
|
36
|
+
height: 60,
|
|
37
|
+
measure: "imperial",
|
|
38
|
+
units: 12
|
|
39
|
+
};
|
|
40
|
+
render() {
|
|
41
|
+
let { width: e, height: r, units: i, measure: a, startPosition: d, label: f, tickCount: p } = this.props, m = a === "imperial" ? {
|
|
42
|
+
type: f,
|
|
43
|
+
ticks: p && p % 4 == 0 ? p : 16
|
|
44
|
+
} : {
|
|
45
|
+
type: f,
|
|
46
|
+
ticks: 10
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ o(t, {
|
|
49
|
+
startPosition: d,
|
|
50
|
+
handle: [{
|
|
51
|
+
class: "leftAnchor",
|
|
52
|
+
origin: "bottom right"
|
|
53
|
+
}, {
|
|
54
|
+
class: "rightAnchor",
|
|
55
|
+
origin: "bottom left"
|
|
56
|
+
}],
|
|
57
|
+
children: /* @__PURE__ */ s(c, {
|
|
58
|
+
style: {
|
|
59
|
+
width: `${e}px`,
|
|
60
|
+
height: `${r}px`
|
|
61
|
+
},
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ o(n, {
|
|
64
|
+
width: e,
|
|
65
|
+
height: r,
|
|
66
|
+
units: i,
|
|
67
|
+
unit: m
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ o(l, { className: "leftAnchor" }),
|
|
70
|
+
/* @__PURE__ */ o(u, { className: "rightAnchor" })
|
|
71
|
+
]
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
export { d as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/tools/src/ruler/unit-type.jsx
|
|
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 React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
export declare const UnitType: {
|
|
12
|
+
(props: any): React.JSX.Element;
|
|
13
|
+
propTypes: {
|
|
14
|
+
label: PropTypes.Validator<string>;
|
|
15
|
+
x: PropTypes.Requireable<number>;
|
|
16
|
+
y: PropTypes.Requireable<number>;
|
|
17
|
+
textAlign: PropTypes.Requireable<string>;
|
|
18
|
+
fill: PropTypes.Requireable<string>;
|
|
19
|
+
fontSize: PropTypes.Requireable<number>;
|
|
20
|
+
stroke: PropTypes.Requireable<string>;
|
|
21
|
+
};
|
|
22
|
+
defaultProps: {
|
|
23
|
+
textAnchor: string;
|
|
24
|
+
fontSize: number;
|
|
25
|
+
stroke: string;
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export default UnitType;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { noSelect as e, strokeColor as t } from "../style-utils.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import { styled as n } from "@mui/material/styles";
|
|
4
|
+
import r from "prop-types";
|
|
5
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
6
|
+
//#region src/ruler/unit-type.tsx
|
|
7
|
+
var a = n("text")(({ theme: n }) => ({
|
|
8
|
+
...e(),
|
|
9
|
+
fill: t(n)
|
|
10
|
+
})), o = (e) => {
|
|
11
|
+
let { label: t, x: n, y: r, textAlign: o, fill: s, fontSize: c, stroke: l } = e;
|
|
12
|
+
return /* @__PURE__ */ i(a, {
|
|
13
|
+
x: n,
|
|
14
|
+
y: r,
|
|
15
|
+
textAnchor: o,
|
|
16
|
+
stroke: l,
|
|
17
|
+
fill: s,
|
|
18
|
+
fontSize: c,
|
|
19
|
+
children: t
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
o.propTypes = {
|
|
23
|
+
label: r.string.isRequired,
|
|
24
|
+
x: r.number,
|
|
25
|
+
y: r.number,
|
|
26
|
+
textAlign: r.string,
|
|
27
|
+
fill: r.string,
|
|
28
|
+
fontSize: r.number,
|
|
29
|
+
stroke: r.string
|
|
30
|
+
}, o.defaultProps = {
|
|
31
|
+
textAnchor: "start",
|
|
32
|
+
fontSize: 11,
|
|
33
|
+
stroke: "none",
|
|
34
|
+
x: 8,
|
|
35
|
+
y: 14
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { o as default };
|