antd-solid 0.0.11 → 0.0.13
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/css/index.css +10 -73
- package/dist/index.esm.js +7802 -2378
- package/dist/index.umd.js +1 -1
- package/es/Alert/index.d.ts +10 -0
- package/es/Alert/index.js +26 -0
- package/es/Button/index.d.ts +32 -0
- package/es/Button/index.js +123 -0
- package/es/Button/index.scss.js +6 -0
- package/es/Checkbox/Group.d.ts +19 -0
- package/es/Checkbox/Group.js +49 -0
- package/es/Checkbox/index.d.ts +15 -0
- package/es/Checkbox/index.js +60 -0
- package/es/CodeInput/index.d.ts +18 -0
- package/es/CodeInput/index.js +72 -0
- package/es/Collapse/Item.d.ts +46 -0
- package/es/Collapse/Item.js +130 -0
- package/es/Collapse/context.d.ts +5 -0
- package/es/Collapse/context.js +8 -0
- package/es/Collapse/index.d.ts +25 -10
- package/es/Collapse/index.js +95 -74
- package/es/Collapse/utils.d.ts +8 -0
- package/es/Collapse/utils.js +35 -0
- package/es/ColorPicker/ColorPickerInput.d.ts +3 -0
- package/es/ColorPicker/ColorPickerInput.js +250 -0
- package/es/ColorPicker/ColorPickerSelect.d.ts +3 -0
- package/es/ColorPicker/ColorPickerSelect.js +71 -0
- package/es/ColorPicker/ColorPickerSlider.d.ts +3 -0
- package/es/ColorPicker/ColorPickerSlider.js +115 -0
- package/es/ColorPicker/color.d.ts +24 -0
- package/es/ColorPicker/color.js +63 -0
- package/es/ColorPicker/context.d.ts +9 -0
- package/es/ColorPicker/context.js +5 -0
- package/es/ColorPicker/index.d.ts +31 -0
- package/es/ColorPicker/index.js +139 -0
- package/es/Command/context.d.ts +9 -0
- package/es/Command/context.js +11 -0
- package/es/Command/createCommand.d.ts +17 -0
- package/es/Command/createCommand.js +112 -0
- package/es/Command/index.d.ts +7 -0
- package/es/Command/index.js +9 -0
- package/es/Command/useCommandProps.d.ts +13 -0
- package/es/Command/useCommandProps.js +28 -0
- package/es/Compact/CompactContextIsolator.d.ts +3 -0
- package/es/Compact/CompactContextIsolator.js +15 -0
- package/es/Compact/context.d.ts +4 -0
- package/es/Compact/context.js +7 -0
- package/es/Compact/index.d.ts +14 -0
- package/es/Compact/index.js +32 -0
- package/es/Compact/index.scss.js +6 -0
- package/es/ConfigProvider/context.d.ts +11 -0
- package/es/ConfigProvider/context.js +15 -0
- package/es/ConfigProvider/dark/colorAlgorithm.d.ts +2 -0
- package/es/ConfigProvider/dark/colorAlgorithm.js +9 -0
- package/es/ConfigProvider/dark/colors.d.ts +3 -0
- package/es/ConfigProvider/dark/colors.js +47 -0
- package/es/ConfigProvider/dark/index.d.ts +2 -0
- package/es/ConfigProvider/dark/index.js +11 -0
- package/es/ConfigProvider/index.d.ts +32 -0
- package/es/ConfigProvider/index.js +44 -0
- package/es/ConfigProvider/light/colorAlgorithm.d.ts +2 -0
- package/es/ConfigProvider/light/colorAlgorithm.js +9 -0
- package/es/ConfigProvider/light/colors.d.ts +3 -0
- package/es/ConfigProvider/light/colors.js +45 -0
- package/es/ConfigProvider/light/index.d.ts +2 -0
- package/es/ConfigProvider/light/index.js +11 -0
- package/es/ConfigProvider/seed.d.ts +3 -0
- package/es/ConfigProvider/seed.js +22 -0
- package/es/ConfigProvider/types/index.d.ts +594 -0
- package/es/ConfigProvider/types/index.js +1 -0
- package/es/ConfigProvider/utils/genColorMapToken.d.ts +7 -0
- package/es/ConfigProvider/utils/genColorMapToken.js +85 -0
- package/es/ConfigProvider/utils/getAlphaColor.d.ts +2 -0
- package/es/ConfigProvider/utils/getAlphaColor.js +44 -0
- package/es/ConfigProvider/utils/index.d.ts +3 -0
- package/es/ConfigProvider/utils/index.js +181 -0
- package/es/ContextMenu/index.d.ts +8 -0
- package/es/ContextMenu/index.js +99 -0
- package/es/Cursor/index.d.ts +6 -0
- package/es/Cursor/index.js +71 -0
- package/es/DelayShow/index.d.ts +16 -0
- package/es/DelayShow/index.js +27 -0
- package/es/Divider/index.d.ts +17 -0
- package/es/Divider/index.js +71 -0
- package/es/Drawer/index.d.ts +20 -16
- package/es/Drawer/index.js +162 -112
- package/es/Drawer/index.scss.js +1 -1
- package/es/Dropdown/index.d.ts +16 -0
- package/es/Dropdown/index.js +47 -0
- package/es/Element/index.d.ts +10 -0
- package/es/Element/index.js +42 -0
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.d.ts +2 -1
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.js +25 -9
- package/es/Empty/assets/EmptySvg.js +1 -1
- package/es/Empty/assets/SimpleEmptySvg.js +1 -1
- package/es/Empty/index.d.ts +9 -3
- package/es/Empty/index.js +24 -9
- package/es/Form/Form.d.ts +8 -5
- package/es/Form/Form.js +50 -34
- package/es/Form/FormItem.d.ts +10 -5
- package/es/Form/FormItem.js +121 -104
- package/es/Form/context.d.ts +9 -9
- package/es/Form/context.js +4 -2
- package/es/Fragment/index.d.ts +4 -0
- package/es/Fragment/index.js +7 -0
- package/es/Image/index.d.ts +10 -0
- package/es/Image/index.js +37 -0
- package/es/Input/TextArea.d.ts +23 -0
- package/es/Input/TextArea.js +84 -0
- package/es/Input/index.d.ts +44 -0
- package/es/Input/index.js +213 -0
- package/es/Input/index.scss.js +6 -0
- package/es/InputNumber/index.d.ts +30 -0
- package/es/InputNumber/index.js +122 -0
- package/es/{InputNumber.test.js → InputNumber/index.test.js} +2 -1
- package/es/Menu/InternalMenu.d.ts +22 -0
- package/es/Menu/InternalMenu.js +196 -0
- package/es/Menu/index.d.ts +75 -0
- package/es/Menu/index.js +64 -0
- package/es/Message/Message.d.ts +9 -0
- package/es/Message/Message.js +34 -0
- package/es/Message/index.d.ts +12 -0
- package/es/Message/index.js +80 -0
- package/es/Message/index.scss.js +6 -0
- package/es/Message/useMessage.d.ts +6 -0
- package/es/Message/useMessage.js +54 -0
- package/es/Modal/index.d.ts +73 -0
- package/es/Modal/index.js +237 -0
- package/es/Modal/index.scss.js +6 -0
- package/es/Modal/useModal.d.ts +5 -0
- package/es/Modal/useModal.js +51 -0
- package/es/Modal/warning.d.ts +5 -0
- package/es/Modal/warning.js +43 -0
- package/es/{Popconfirm.d.ts → Popconfirm/index.d.ts} +2 -2
- package/es/Popconfirm/index.js +62 -0
- package/es/{Popover.d.ts → Popover/index.d.ts} +2 -2
- package/es/{Popover.js → Popover/index.js} +7 -12
- package/es/Progress/Circle.d.ts +16 -0
- package/es/Progress/Circle.js +122 -0
- package/es/Progress/index.d.ts +6 -4
- package/es/Progress/index.js +75 -60
- package/es/Radio/Button.d.ts +7 -0
- package/es/Radio/Button.js +72 -0
- package/es/Radio/Group.d.ts +18 -0
- package/es/Radio/Group.js +57 -0
- package/es/Radio/index.d.ts +14 -0
- package/es/Radio/index.js +68 -0
- package/es/RangeInput/index.d.ts +23 -0
- package/es/RangeInput/index.js +208 -0
- package/es/Result/index.js +49 -0
- package/es/Segmented/index.d.ts +10 -7
- package/es/Segmented/index.js +54 -53
- package/es/Select/index.d.ts +17 -0
- package/es/Select/index.js +75 -0
- package/es/SelectInput/index.d.ts +39 -0
- package/es/SelectInput/index.js +245 -0
- package/es/Slider/index.d.ts +47 -0
- package/es/Slider/index.js +177 -0
- package/es/Space/index.d.ts +13 -0
- package/es/Space/index.js +16 -0
- package/es/Spin/index.d.ts +19 -0
- package/es/Spin/index.js +82 -0
- package/es/{Switch.d.ts → Switch/index.d.ts} +9 -0
- package/es/Switch/index.js +41 -0
- package/es/{Table.d.ts → Table/index.d.ts} +6 -2
- package/es/Table/index.js +71 -0
- package/es/Tabs/index.d.ts +49 -0
- package/es/Tabs/index.js +256 -0
- package/es/Timeline/index.js +31 -0
- package/es/Tooltip/context.d.ts +5 -0
- package/es/Tooltip/context.js +5 -0
- package/es/Tooltip/index.d.ts +64 -0
- package/es/Tooltip/index.js +499 -0
- package/es/Transformer/index.d.ts +88 -0
- package/es/Transformer/index.js +882 -0
- package/es/Tree/SingleLevelTree.d.ts +28 -0
- package/es/Tree/SingleLevelTree.js +299 -0
- package/es/Tree/index.d.ts +83 -0
- package/es/Tree/index.js +197 -0
- package/es/TreeFor/index.d.ts +31 -0
- package/es/TreeFor/index.js +80 -0
- package/es/TreeSelect/index.d.ts +26 -0
- package/es/TreeSelect/index.js +98 -0
- package/es/Upload/index.d.ts +64 -0
- package/es/Upload/index.js +112 -0
- package/es/assets/svg/ColorPickUp.d.ts +4 -0
- package/es/assets/svg/ColorPickUp.js +25 -0
- package/es/assets/svg/Crosshair.d.ts +7 -0
- package/es/assets/svg/Crosshair.js +51 -0
- package/es/assets/svg/Resize.d.ts +4 -0
- package/es/assets/svg/Resize.js +25 -0
- package/es/assets/svg/Rotate.d.ts +4 -0
- package/es/assets/svg/Rotate.js +20 -0
- package/es/assets/svg/RotateArrow.d.ts +4 -0
- package/es/assets/svg/RotateArrow.js +21 -0
- package/es/assets/svg/common.d.ts +2 -0
- package/es/assets/svg/common.js +9 -0
- package/es/hooks/createControllableValue.d.ts +1 -1
- package/es/hooks/createControllableValue.js +16 -17
- package/es/hooks/createTransition.d.ts +6 -2
- package/es/hooks/createTransition.js +12 -8
- package/es/hooks/useClickAway.d.ts +1 -1
- package/es/hooks/useClickAway.js +4 -3
- package/es/hooks/useComponentSize.d.ts +3 -0
- package/es/hooks/useComponentSize.js +12 -0
- package/es/hooks/useCounter.d.ts +12 -0
- package/es/hooks/useCounter.js +30 -0
- package/es/hooks/useFocus.d.ts +2 -0
- package/es/hooks/useFocus.js +24 -0
- package/es/hooks/useHover.d.ts +2 -0
- package/es/hooks/useHover.js +33 -0
- package/es/hooks/useLocale.d.ts +1 -0
- package/es/hooks/useLocale.js +11 -0
- package/es/hooks/useMouse.d.ts +1 -0
- package/es/hooks/useMouse.js +18 -0
- package/es/hooks/useScroll.d.ts +2 -0
- package/es/hooks/useScroll.js +29 -0
- package/es/hooks/useSize.d.ts +8 -2
- package/es/hooks/useSize.js +25 -13
- package/es/hooks/useVirtualList.d.ts +14 -0
- package/es/hooks/useVirtualList.js +45 -0
- package/es/index.d.ts +59 -8
- package/es/index.js +53 -23
- package/es/locale/en_US.d.ts +3 -0
- package/es/locale/en_US.js +9 -0
- package/es/locale/index.d.ts +5 -0
- package/es/locale/index.js +1 -0
- package/es/locale/zh_CN.d.ts +3 -0
- package/es/locale/zh_CN.js +9 -0
- package/es/types/index.d.ts +11 -2
- package/es/utils/animation.d.ts +6 -0
- package/es/utils/animation.js +20 -0
- package/es/utils/array.d.ts +2 -1
- package/es/utils/array.js +5 -1
- package/es/utils/domPoint.d.ts +7 -0
- package/es/utils/domPoint.js +11 -0
- package/es/utils/math.d.ts +17 -0
- package/es/utils/math.js +25 -0
- package/es/utils/number.d.ts +1 -0
- package/es/utils/number.js +14 -0
- package/es/utils/setupGlobalDrag.d.ts +10 -0
- package/es/utils/setupGlobalDrag.js +38 -0
- package/es/utils/solid.d.ts +2 -2
- package/es/utils/solid.js +7 -8
- package/package.json +10 -11
- package/es/Button.d.ts +0 -19
- package/es/Button.js +0 -73
- package/es/ColorPicker.d.ts +0 -8
- package/es/ColorPicker.js +0 -6
- package/es/Compact.d.ts +0 -12
- package/es/Compact.js +0 -17
- package/es/DatePicker.d.ts +0 -19
- package/es/DatePicker.js +0 -9
- package/es/Image.d.ts +0 -9
- package/es/Image.js +0 -22
- package/es/Input.d.ts +0 -29
- package/es/Input.js +0 -144
- package/es/InputNumber.d.ts +0 -11
- package/es/InputNumber.js +0 -92
- package/es/Modal.d.ts +0 -48
- package/es/Modal.js +0 -209
- package/es/Popconfirm.js +0 -64
- package/es/Radio.d.ts +0 -27
- package/es/Radio.js +0 -93
- package/es/Result.js +0 -29
- package/es/Select.d.ts +0 -16
- package/es/Select.js +0 -113
- package/es/Skeleton.d.ts +0 -9
- package/es/Skeleton.js +0 -9
- package/es/Spin.d.ts +0 -9
- package/es/Spin.js +0 -22
- package/es/Switch.js +0 -30
- package/es/Table.js +0 -57
- package/es/Tabs.d.ts +0 -17
- package/es/Tabs.js +0 -117
- package/es/Timeline.js +0 -30
- package/es/Tooltip.d.ts +0 -34
- package/es/Tooltip.js +0 -302
- package/es/Tree.d.ts +0 -28
- package/es/Tree.js +0 -198
- package/es/Upload.d.ts +0 -11
- package/es/Upload.js +0 -6
- package/es/hooks/createUpdateEffect.d.ts +0 -5
- package/es/hooks/createUpdateEffect.js +0 -12
- package/es/utils/EventEmitter.d.ts +0 -7
- package/es/utils/EventEmitter.js +0 -13
- package/es/utils/ReactToSolid.d.ts +0 -8
- package/es/utils/ReactToSolid.js +0 -30
- package/es/utils/SolidToReact.d.ts +0 -8
- package/es/utils/SolidToReact.js +0 -23
- package/es/utils/component.d.ts +0 -31
- package/es/utils/component.js +0 -68
- package/es/utils/zh_CN.d.ts +0 -2
- package/es/utils/zh_CN.js +0 -236
- package/src/Button.tsx +0 -128
- package/src/Collapse/index.tsx +0 -86
- package/src/ColorPicker.tsx +0 -11
- package/src/Compact.tsx +0 -15
- package/src/DatePicker.tsx +0 -30
- package/src/Drawer/index.scss +0 -53
- package/src/Drawer/index.tsx +0 -212
- package/src/Empty/PRESENTED_IMAGE_SIMPLE.tsx +0 -15
- package/src/Empty/assets/EmptySvg.tsx +0 -43
- package/src/Empty/assets/SimpleEmptySvg.tsx +0 -16
- package/src/Empty/index.tsx +0 -20
- package/src/Form/Form.tsx +0 -94
- package/src/Form/FormItem.tsx +0 -141
- package/src/Form/context.ts +0 -16
- package/src/Form/index.ts +0 -13
- package/src/Image.tsx +0 -29
- package/src/Input.tsx +0 -202
- package/src/InputNumber.test.tsx +0 -46
- package/src/InputNumber.tsx +0 -125
- package/src/Modal.tsx +0 -220
- package/src/Popconfirm.tsx +0 -75
- package/src/Popover.tsx +0 -30
- package/src/Progress/index.tsx +0 -73
- package/src/Radio.tsx +0 -142
- package/src/Result.tsx +0 -38
- package/src/Segmented/index.tsx +0 -95
- package/src/Select.tsx +0 -128
- package/src/Skeleton.tsx +0 -14
- package/src/Spin.tsx +0 -23
- package/src/Switch.tsx +0 -34
- package/src/Table.tsx +0 -53
- package/src/Tabs.tsx +0 -131
- package/src/Timeline.tsx +0 -33
- package/src/Tooltip.tsx +0 -340
- package/src/Tree.tsx +0 -246
- package/src/Upload.tsx +0 -10
- package/src/hooks/createControllableValue.ts +0 -68
- package/src/hooks/createTransition.ts +0 -52
- package/src/hooks/createUpdateEffect.ts +0 -16
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useClickAway.ts +0 -18
- package/src/hooks/useSize.ts +0 -26
- package/src/index.ts +0 -47
- package/src/types/index.ts +0 -5
- package/src/utils/EventEmitter.ts +0 -15
- package/src/utils/ReactToSolid.tsx +0 -38
- package/src/utils/SolidToReact.tsx +0 -27
- package/src/utils/array.ts +0 -21
- package/src/utils/component.tsx +0 -85
- package/src/utils/solid.ts +0 -61
- package/src/utils/zh_CN.ts +0 -236
- /package/es/{InputNumber.test.d.ts → InputNumber/index.test.d.ts} +0 -0
- /package/es/{Result.d.ts → Result/index.d.ts} +0 -0
- /package/es/{Timeline.d.ts → Timeline/index.d.ts} +0 -0
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import { delegateEvents, createComponent, insert, memo, Portal, effect, setAttribute, spread, mergeProps, template } from 'solid-js/web';
|
|
2
|
+
import { createMemo, createSignal, Show } from 'solid-js';
|
|
3
|
+
import { inRange } from 'lodash-es';
|
|
4
|
+
import NP from 'number-precision';
|
|
5
|
+
import cs from 'classnames';
|
|
6
|
+
import createControllableValue from '../hooks/createControllableValue.js';
|
|
7
|
+
import Resize from '../assets/svg/Resize.js';
|
|
8
|
+
import Element from '../Element/index.js';
|
|
9
|
+
import { radToDeg } from '../utils/math.js';
|
|
10
|
+
import RotateArrowSvg from '../assets/svg/RotateArrow.js';
|
|
11
|
+
import CrosshairSvg from '../assets/svg/Crosshair.js';
|
|
12
|
+
import { setRef } from '../utils/solid.js';
|
|
13
|
+
import { setupGlobalDrag } from '../utils/setupGlobalDrag.js';
|
|
14
|
+
import { subDOMPoint } from '../utils/domPoint.js';
|
|
15
|
+
|
|
16
|
+
var _tmpl$ = /*#__PURE__*/template(`<svg><foreignObject class=overflow-visible></svg>`, false, true),
|
|
17
|
+
_tmpl$2 = /*#__PURE__*/template(`<svg><path class=pointer-events-initial opacity=0>`),
|
|
18
|
+
_tmpl$3 = /*#__PURE__*/template(`<svg><path stroke=var(--ant-color-primary) stroke-width=1></svg>`, false, true),
|
|
19
|
+
_tmpl$4 = /*#__PURE__*/template(`<svg><path class="pointer-events-initial cursor-none"opacity=0 stroke=var(--ant-color-primary) stroke-width=3></svg>`, false, true),
|
|
20
|
+
_tmpl$5 = /*#__PURE__*/template(`<svg><path class="pointer-events-initial cursor-none"opacity=0 fill=red></svg>`, false, true),
|
|
21
|
+
_tmpl$6 = /*#__PURE__*/template(`<svg><path class="pointer-events-initial cursor-none"fill=var(--ant-color-white) stroke=var(--ant-color-primary)></svg>`, false, true),
|
|
22
|
+
_tmpl$7 = /*#__PURE__*/template(`<svg><path class="pointer-events-initial cursor-none"opacity=0 fill=blue></svg>`, false, true);
|
|
23
|
+
// 判断是否鼠标左键触发
|
|
24
|
+
const isMainButton = e => e.button === 0;
|
|
25
|
+
const Transformer = props => {
|
|
26
|
+
let ref;
|
|
27
|
+
const adsorbGap = createMemo(() => props.adsorb ? props.adsorb.gap ?? 5 : 0);
|
|
28
|
+
const getTransform = (value, transformOrigin) => new DOMMatrix().translate(value.x, value.y).translate(transformOrigin.x, transformOrigin.y).rotate(value.rotate).translate(-transformOrigin.x, -transformOrigin.y);
|
|
29
|
+
const [_value, setValue] = createControllableValue(props);
|
|
30
|
+
const value = createMemo(() => _value() ?? {
|
|
31
|
+
x: 0,
|
|
32
|
+
y: 0,
|
|
33
|
+
width: 0,
|
|
34
|
+
height: 0,
|
|
35
|
+
rotate: 0
|
|
36
|
+
});
|
|
37
|
+
const parseTransformOrigin = (width, height) => {
|
|
38
|
+
if (typeof props.transformOrigin === 'function') {
|
|
39
|
+
return new DOMPoint(...props.transformOrigin(width, height));
|
|
40
|
+
}
|
|
41
|
+
const [x, y] = props.transformOrigin ?? ['50%', '50%'];
|
|
42
|
+
return new DOMPoint(typeof x === 'string' ? width * parseFloat(x) / 100 : x, typeof y === 'string' ? height * parseFloat(y) / 100 : y);
|
|
43
|
+
};
|
|
44
|
+
const localToParent = (point, transformValue, transformOrigin) => {
|
|
45
|
+
transformValue = transformValue ?? value();
|
|
46
|
+
transformOrigin = transformOrigin ?? parseTransformOrigin(transformValue.width, transformValue.height);
|
|
47
|
+
if (props.localToParentPoint) {
|
|
48
|
+
return props.localToParentPoint(point, transformValue, transformOrigin);
|
|
49
|
+
}
|
|
50
|
+
return point.matrixTransform(getTransform(transformValue, transformOrigin));
|
|
51
|
+
};
|
|
52
|
+
const worldToParent = point => {
|
|
53
|
+
if (ref) {
|
|
54
|
+
const rect = ref.getBoundingClientRect();
|
|
55
|
+
point = new DOMPoint(point.x - rect.x, point.y - rect.y);
|
|
56
|
+
}
|
|
57
|
+
if (props.worldToParentPoint) return props.worldToParentPoint(point);
|
|
58
|
+
return point;
|
|
59
|
+
};
|
|
60
|
+
const localToWorld = (point, transformValue, transformOrigin) => {
|
|
61
|
+
const newPoint = localToParent(point, transformValue, transformOrigin);
|
|
62
|
+
if (!newPoint) return;
|
|
63
|
+
return props.parentToWorldPoint ? props.parentToWorldPoint(newPoint) : newPoint;
|
|
64
|
+
};
|
|
65
|
+
const worldToLocal = (point, transformValue, transformOrigin) => {
|
|
66
|
+
transformValue = transformValue ?? value();
|
|
67
|
+
transformOrigin = transformOrigin ?? parseTransformOrigin(transformValue.width, transformValue.height);
|
|
68
|
+
const newPoint = worldToParent(point);
|
|
69
|
+
if (!newPoint) return;
|
|
70
|
+
if (props.parentToLocalPoint) {
|
|
71
|
+
return props.parentToLocalPoint(newPoint, transformValue, transformOrigin);
|
|
72
|
+
}
|
|
73
|
+
return newPoint.matrixTransform(getTransform(transformValue, transformOrigin).inverse());
|
|
74
|
+
};
|
|
75
|
+
const [adsorbLine, setAdsorbLine] = createSignal({});
|
|
76
|
+
const onMoveMouseDown = e => {
|
|
77
|
+
if (!isMainButton(e)) return;
|
|
78
|
+
e.stopPropagation();
|
|
79
|
+
const startValue = value();
|
|
80
|
+
const startPoint = worldToParent(new DOMPoint(e.clientX, e.clientY));
|
|
81
|
+
if (!startPoint) return;
|
|
82
|
+
setupGlobalDrag(
|
|
83
|
+
// eslint-disable-next-line solid/reactivity
|
|
84
|
+
_e => {
|
|
85
|
+
const currentMousePoint = worldToParent(new DOMPoint(_e.clientX, _e.clientY));
|
|
86
|
+
if (!currentMousePoint) return;
|
|
87
|
+
const changedValue = {
|
|
88
|
+
x: startValue.x + (currentMousePoint.x - startPoint.x),
|
|
89
|
+
y: startValue.y + (currentMousePoint.y - startPoint.y)
|
|
90
|
+
};
|
|
91
|
+
if (props.adsorb) {
|
|
92
|
+
const _adsorbLine = {};
|
|
93
|
+
// x 轴
|
|
94
|
+
const right = props.adsorb.width - value().width;
|
|
95
|
+
const centerX = right / 2;
|
|
96
|
+
if (inRange(changedValue.x, centerX - adsorbGap(), centerX + adsorbGap())) {
|
|
97
|
+
changedValue.x = centerX;
|
|
98
|
+
_adsorbLine.centerX = true;
|
|
99
|
+
} else if (inRange(changedValue.x, -adsorbGap(), adsorbGap())) {
|
|
100
|
+
changedValue.x = 0;
|
|
101
|
+
_adsorbLine.left = true;
|
|
102
|
+
} else if (inRange(changedValue.x, right - adsorbGap(), right + adsorbGap())) {
|
|
103
|
+
changedValue.x = right;
|
|
104
|
+
_adsorbLine.right = true;
|
|
105
|
+
}
|
|
106
|
+
// y 轴
|
|
107
|
+
const bottom = props.adsorb.height - value().height;
|
|
108
|
+
const centerY = bottom / 2;
|
|
109
|
+
if (inRange(changedValue.y, centerY - adsorbGap(), centerY + adsorbGap())) {
|
|
110
|
+
changedValue.y = centerY;
|
|
111
|
+
_adsorbLine.centerY = true;
|
|
112
|
+
} else if (inRange(changedValue.y, -adsorbGap(), adsorbGap())) {
|
|
113
|
+
changedValue.y = 0;
|
|
114
|
+
_adsorbLine.top = true;
|
|
115
|
+
} else if (inRange(changedValue.y, bottom - adsorbGap(), bottom + adsorbGap())) {
|
|
116
|
+
changedValue.y = bottom;
|
|
117
|
+
_adsorbLine.bottom = true;
|
|
118
|
+
}
|
|
119
|
+
setAdsorbLine(_adsorbLine);
|
|
120
|
+
}
|
|
121
|
+
setValue({
|
|
122
|
+
...value(),
|
|
123
|
+
...changedValue
|
|
124
|
+
});
|
|
125
|
+
props.onMove?.(changedValue);
|
|
126
|
+
},
|
|
127
|
+
// eslint-disable-next-line solid/reactivity
|
|
128
|
+
() => {
|
|
129
|
+
props.onTransformEnd?.();
|
|
130
|
+
setAdsorbLine({});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
let resizing = false;
|
|
134
|
+
const onResizeMouseDown = (e, direction) => {
|
|
135
|
+
if (!isMainButton(e)) return;
|
|
136
|
+
if (rotating) return;
|
|
137
|
+
e.stopPropagation();
|
|
138
|
+
const startValue = {
|
|
139
|
+
...value()
|
|
140
|
+
};
|
|
141
|
+
const startPoint = worldToLocal(new DOMPoint(e.clientX, e.clientY));
|
|
142
|
+
if (!startPoint) return;
|
|
143
|
+
const getVertex = (width, height) => new DOMPoint(direction === 'right' || direction === 'bottomRight' || direction === 'topRight' ? 0 : width, direction === 'bottom' || direction === 'bottomRight' || direction === 'bottomLeft' ? 0 : height);
|
|
144
|
+
const startVertex = localToParent(getVertex(value().width, value().height));
|
|
145
|
+
if (!startVertex) return;
|
|
146
|
+
const startTransformOrigin = parseTransformOrigin(value().width, value().height);
|
|
147
|
+
resizing = true;
|
|
148
|
+
setupGlobalDrag(
|
|
149
|
+
// eslint-disable-next-line solid/reactivity
|
|
150
|
+
_e => {
|
|
151
|
+
const changedValue = value();
|
|
152
|
+
const currentPoint = worldToLocal(new DOMPoint(_e.clientX, _e.clientY), startValue, startTransformOrigin);
|
|
153
|
+
if (!currentPoint) return;
|
|
154
|
+
const offsetX = currentPoint.x - startPoint.x;
|
|
155
|
+
const offsetY = currentPoint.y - startPoint.y;
|
|
156
|
+
const _adsorbLine = {};
|
|
157
|
+
if (direction === 'left' || direction === 'right' || direction === 'topLeft' || direction === 'topRight' || direction === 'bottomLeft' || direction === 'bottomRight') {
|
|
158
|
+
const isLeft = direction === 'left' || direction === 'topLeft' || direction === 'bottomLeft';
|
|
159
|
+
let widthOffset = isLeft ? -offsetX : offsetX;
|
|
160
|
+
widthOffset = Math.max(-startValue.width, widthOffset);
|
|
161
|
+
changedValue.width = startValue.width + widthOffset;
|
|
162
|
+
if (props.adsorb) {
|
|
163
|
+
if (isLeft) {
|
|
164
|
+
let xOffset = isLeft ? -widthOffset : 0;
|
|
165
|
+
if (inRange(startValue.x + xOffset, -adsorbGap(), +adsorbGap())) {
|
|
166
|
+
xOffset = -startValue.x;
|
|
167
|
+
changedValue.width = NP.minus(startValue.width, xOffset);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
if (inRange(startValue.x + changedValue.width, props.adsorb.width - adsorbGap(), props.adsorb.width + adsorbGap())) {
|
|
171
|
+
changedValue.width = NP.minus(props.adsorb.width, startValue.x);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (direction === 'top' || direction === 'bottom' || direction === 'topLeft' || direction === 'topRight' || direction === 'bottomLeft' || direction === 'bottomRight') {
|
|
177
|
+
const isTop = direction === 'top' || direction === 'topLeft' || direction === 'topRight';
|
|
178
|
+
let heightOffset = isTop ? -offsetY : offsetY;
|
|
179
|
+
heightOffset = Math.max(-startValue.height, heightOffset);
|
|
180
|
+
changedValue.height = startValue.height + heightOffset;
|
|
181
|
+
if (props.adsorb) {
|
|
182
|
+
if (isTop) {
|
|
183
|
+
let yOffset = isTop ? -heightOffset : 0;
|
|
184
|
+
if (inRange(startValue.y + yOffset, -adsorbGap(), +adsorbGap())) {
|
|
185
|
+
yOffset = -startValue.y;
|
|
186
|
+
changedValue.height = NP.minus(startValue.height, yOffset);
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
if (inRange(startValue.y + changedValue.height, props.adsorb.height - adsorbGap(), props.adsorb.height + adsorbGap())) {
|
|
190
|
+
changedValue.height = NP.minus(props.adsorb.height, startValue.y);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
setAdsorbLine(_adsorbLine);
|
|
196
|
+
const endWidth = changedValue.width ?? value().width;
|
|
197
|
+
const endHeight = changedValue.height ?? value().height;
|
|
198
|
+
const endTransformOrigin = parseTransformOrigin(endWidth, endHeight);
|
|
199
|
+
const endVertex = localToParent(getVertex(endWidth, endHeight), startValue, endTransformOrigin);
|
|
200
|
+
if (!endVertex) return;
|
|
201
|
+
changedValue.x = startValue.x + startVertex.x - endVertex.x;
|
|
202
|
+
changedValue.y = startValue.y + startVertex.y - endVertex.y;
|
|
203
|
+
setValue({
|
|
204
|
+
...value(),
|
|
205
|
+
...changedValue
|
|
206
|
+
});
|
|
207
|
+
props.onResize?.(changedValue);
|
|
208
|
+
updateResizeArrowPosition(_e);
|
|
209
|
+
},
|
|
210
|
+
// eslint-disable-next-line solid/reactivity
|
|
211
|
+
() => {
|
|
212
|
+
resizing = false;
|
|
213
|
+
setResizeDirection(false);
|
|
214
|
+
props.onTransformEnd?.();
|
|
215
|
+
}, 'none');
|
|
216
|
+
};
|
|
217
|
+
const getResizeHandlerProps = (direction, getMouseRotate) => {
|
|
218
|
+
return {
|
|
219
|
+
onMouseDown: e => {
|
|
220
|
+
onResizeMouseDown(e, direction);
|
|
221
|
+
},
|
|
222
|
+
onMouseEnter: e => {
|
|
223
|
+
if (resizing) return;
|
|
224
|
+
setResizeDirection(direction);
|
|
225
|
+
setMouseRotate(getMouseRotate());
|
|
226
|
+
updateResizeArrowPosition(e);
|
|
227
|
+
},
|
|
228
|
+
onMouseMove: e => {
|
|
229
|
+
if (resizing) return;
|
|
230
|
+
updateResizeArrowPosition(e);
|
|
231
|
+
},
|
|
232
|
+
onMouseLeave: () => {
|
|
233
|
+
if (resizing) return;
|
|
234
|
+
setResizeDirection(false);
|
|
235
|
+
setMouseRotate(0);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
let rotating = false;
|
|
240
|
+
const onRotateMouseDown = e => {
|
|
241
|
+
if (!isMainButton(e)) return;
|
|
242
|
+
e.stopPropagation();
|
|
243
|
+
rotating = true;
|
|
244
|
+
const transformOrigin = parseTransformOrigin(value().width, value().height);
|
|
245
|
+
const startPoint = worldToLocal(new DOMPoint(e.clientX, e.clientY));
|
|
246
|
+
if (!startPoint) return;
|
|
247
|
+
const startAngle = Math.atan2(startPoint.y - transformOrigin.y, startPoint.x - transformOrigin.x);
|
|
248
|
+
setupGlobalDrag(
|
|
249
|
+
// eslint-disable-next-line solid/reactivity
|
|
250
|
+
_e => {
|
|
251
|
+
const currentPoint = worldToLocal(new DOMPoint(_e.clientX, _e.clientY));
|
|
252
|
+
if (!currentPoint) return;
|
|
253
|
+
const angle = Math.atan2(currentPoint.y - transformOrigin.y, currentPoint.x - transformOrigin.x);
|
|
254
|
+
const rotate = value().rotate + radToDeg(angle - startAngle);
|
|
255
|
+
setValue({
|
|
256
|
+
...value(),
|
|
257
|
+
rotate
|
|
258
|
+
});
|
|
259
|
+
props.onRotate?.({
|
|
260
|
+
rotate
|
|
261
|
+
});
|
|
262
|
+
updateRotateArrowPosition(_e);
|
|
263
|
+
},
|
|
264
|
+
// eslint-disable-next-line solid/reactivity
|
|
265
|
+
() => {
|
|
266
|
+
rotating = false;
|
|
267
|
+
setRotateDirection(false);
|
|
268
|
+
props.onTransformEnd?.();
|
|
269
|
+
}, 'none');
|
|
270
|
+
};
|
|
271
|
+
const getRotateHandlerProps = (direction, getMouseRotate) => {
|
|
272
|
+
return {
|
|
273
|
+
onMouseDown: e => {
|
|
274
|
+
onRotateMouseDown(e);
|
|
275
|
+
},
|
|
276
|
+
onMouseEnter: e => {
|
|
277
|
+
if (rotating) return;
|
|
278
|
+
setRotateDirection(direction);
|
|
279
|
+
setMouseRotate(getMouseRotate());
|
|
280
|
+
updateRotateArrowPosition(e);
|
|
281
|
+
},
|
|
282
|
+
onMouseMove: e => {
|
|
283
|
+
if (rotating) return;
|
|
284
|
+
updateRotateArrowPosition(e);
|
|
285
|
+
},
|
|
286
|
+
onMouseLeave: () => {
|
|
287
|
+
if (rotating) return;
|
|
288
|
+
setRotateDirection(false);
|
|
289
|
+
setMouseRotate(0);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
const [mouseRotate, setMouseRotate] = createSignal(0);
|
|
294
|
+
const [resizeDirection, setResizeDirection] = createSignal(false);
|
|
295
|
+
const [resizeArrowPosition, setResizeArrowPosition] = createSignal({
|
|
296
|
+
x: 0,
|
|
297
|
+
y: 0
|
|
298
|
+
});
|
|
299
|
+
const updateResizeArrowPosition = e => {
|
|
300
|
+
setResizeArrowPosition({
|
|
301
|
+
x: e.pageX,
|
|
302
|
+
y: e.pageY
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
const [rotateDirection, setRotateDirection] = createSignal(false);
|
|
306
|
+
const [rotateArrowPosition, setRotateArrowPosition] = createSignal({
|
|
307
|
+
x: 0,
|
|
308
|
+
y: 0
|
|
309
|
+
});
|
|
310
|
+
const updateRotateArrowPosition = e => {
|
|
311
|
+
setRotateArrowPosition({
|
|
312
|
+
x: e.pageX,
|
|
313
|
+
y: e.pageY
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
const convertLayout = (width, height, convertPoint, _convertLayout) => {
|
|
317
|
+
const topLeftPoint = new DOMPoint(0, 0);
|
|
318
|
+
const topRightPoint = new DOMPoint(width, 0);
|
|
319
|
+
const bottomRightPoint = new DOMPoint(width, height);
|
|
320
|
+
const bottomLeftPoint = new DOMPoint(0, height);
|
|
321
|
+
const leftCenterPoint = new DOMPoint((topLeftPoint.x + bottomLeftPoint.x) / 2, (topLeftPoint.y + bottomLeftPoint.y) / 2);
|
|
322
|
+
const rightCenterPoint = new DOMPoint((topRightPoint.x + bottomRightPoint.x) / 2, (topRightPoint.y + bottomRightPoint.y) / 2);
|
|
323
|
+
const xCenterLine = [leftCenterPoint, rightCenterPoint];
|
|
324
|
+
const topCenterPoint = new DOMPoint((topLeftPoint.x + topRightPoint.x) / 2, (topLeftPoint.y + topRightPoint.y) / 2);
|
|
325
|
+
const bottomCenterPoint = new DOMPoint((bottomLeftPoint.x + bottomRightPoint.x) / 2, (bottomLeftPoint.y + bottomRightPoint.y) / 2);
|
|
326
|
+
const yCenterLine = [topCenterPoint, bottomCenterPoint];
|
|
327
|
+
const layoutValue = {
|
|
328
|
+
topLeftPoint,
|
|
329
|
+
topRightPoint,
|
|
330
|
+
bottomRightPoint,
|
|
331
|
+
bottomLeftPoint,
|
|
332
|
+
xCenterLine,
|
|
333
|
+
yCenterLine
|
|
334
|
+
};
|
|
335
|
+
if (_convertLayout) return _convertLayout(layoutValue);
|
|
336
|
+
return {
|
|
337
|
+
topLeftPoint: convertPoint(layoutValue.topLeftPoint),
|
|
338
|
+
topRightPoint: convertPoint(layoutValue.topRightPoint),
|
|
339
|
+
bottomRightPoint: convertPoint(layoutValue.bottomRightPoint),
|
|
340
|
+
bottomLeftPoint: convertPoint(layoutValue.bottomLeftPoint),
|
|
341
|
+
xCenterLine: xCenterLine.map(point => convertPoint(point)),
|
|
342
|
+
yCenterLine: yCenterLine.map(point => convertPoint(point))
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
const layoutInWorld = createMemo(() => {
|
|
346
|
+
const {
|
|
347
|
+
width,
|
|
348
|
+
height
|
|
349
|
+
} = value();
|
|
350
|
+
return convertLayout(width, height, localToWorld, props.localToWorldLayout);
|
|
351
|
+
});
|
|
352
|
+
const parentToWorld = point => {
|
|
353
|
+
return props.parentToWorldPoint ? props.parentToWorldPoint(point) : point;
|
|
354
|
+
};
|
|
355
|
+
const parentLayoutInWorld = createMemo(() => {
|
|
356
|
+
const {
|
|
357
|
+
width = 0,
|
|
358
|
+
height = 0
|
|
359
|
+
} = props.adsorb ?? {};
|
|
360
|
+
return convertLayout(width, height, parentToWorld, props.parentToWorldLayout);
|
|
361
|
+
});
|
|
362
|
+
const pathD = createMemo(() => {
|
|
363
|
+
const {
|
|
364
|
+
topLeftPoint,
|
|
365
|
+
topRightPoint,
|
|
366
|
+
bottomRightPoint,
|
|
367
|
+
bottomLeftPoint
|
|
368
|
+
} = layoutInWorld();
|
|
369
|
+
const points = [topLeftPoint, topRightPoint, bottomRightPoint, bottomLeftPoint].flatMap(p => (Array.isArray(p) ? p : [p]).filter(v => v));
|
|
370
|
+
return `${points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x},${p.y}`).join(' ')} Z`;
|
|
371
|
+
});
|
|
372
|
+
const resizeArrowRotate = mouseRotate;
|
|
373
|
+
const rotateArrowRotate = createMemo(() => {
|
|
374
|
+
return mouseRotate() + Math.PI / 4;
|
|
375
|
+
});
|
|
376
|
+
const transformOrigin = createMemo(() => localToWorld(parseTransformOrigin(value().width, value().height)));
|
|
377
|
+
setRef(props, {
|
|
378
|
+
enterMove: onMoveMouseDown,
|
|
379
|
+
enterResize: onResizeMouseDown,
|
|
380
|
+
enterRotate: onRotateMouseDown
|
|
381
|
+
});
|
|
382
|
+
const viewBoxStr = createMemo(() => {
|
|
383
|
+
if (!props.viewBox) return;
|
|
384
|
+
const {
|
|
385
|
+
x,
|
|
386
|
+
y,
|
|
387
|
+
width,
|
|
388
|
+
height
|
|
389
|
+
} = props.viewBox;
|
|
390
|
+
return [x, y, width, height].join(' ');
|
|
391
|
+
});
|
|
392
|
+
return createComponent(Element, {
|
|
393
|
+
ref(r$) {
|
|
394
|
+
var _ref$ = ref;
|
|
395
|
+
typeof _ref$ === "function" ? _ref$(r$) : ref = r$;
|
|
396
|
+
},
|
|
397
|
+
"class": "relative",
|
|
398
|
+
get children() {
|
|
399
|
+
var _el$ = _tmpl$2(),
|
|
400
|
+
_el$2 = _el$.firstChild;
|
|
401
|
+
_el$2.$$mousedown = onMoveMouseDown;
|
|
402
|
+
insert(_el$, createComponent(Edge, {
|
|
403
|
+
direction: "top",
|
|
404
|
+
get layout() {
|
|
405
|
+
return layoutInWorld();
|
|
406
|
+
},
|
|
407
|
+
get centerLine() {
|
|
408
|
+
return layoutInWorld().yCenterLine;
|
|
409
|
+
},
|
|
410
|
+
getResizeHandlerProps: getResizeHandlerProps
|
|
411
|
+
}), null);
|
|
412
|
+
insert(_el$, createComponent(Edge, {
|
|
413
|
+
direction: "bottom",
|
|
414
|
+
get layout() {
|
|
415
|
+
return layoutInWorld();
|
|
416
|
+
},
|
|
417
|
+
get centerLine() {
|
|
418
|
+
return layoutInWorld().yCenterLine;
|
|
419
|
+
},
|
|
420
|
+
getResizeHandlerProps: getResizeHandlerProps
|
|
421
|
+
}), null);
|
|
422
|
+
insert(_el$, createComponent(Edge, {
|
|
423
|
+
direction: "left",
|
|
424
|
+
get layout() {
|
|
425
|
+
return layoutInWorld();
|
|
426
|
+
},
|
|
427
|
+
get centerLine() {
|
|
428
|
+
return layoutInWorld().xCenterLine;
|
|
429
|
+
},
|
|
430
|
+
getResizeHandlerProps: getResizeHandlerProps
|
|
431
|
+
}), null);
|
|
432
|
+
insert(_el$, createComponent(Edge, {
|
|
433
|
+
direction: "right",
|
|
434
|
+
get layout() {
|
|
435
|
+
return layoutInWorld();
|
|
436
|
+
},
|
|
437
|
+
get centerLine() {
|
|
438
|
+
return layoutInWorld().xCenterLine;
|
|
439
|
+
},
|
|
440
|
+
getResizeHandlerProps: getResizeHandlerProps
|
|
441
|
+
}), null);
|
|
442
|
+
insert(_el$, createComponent(Show, {
|
|
443
|
+
get when() {
|
|
444
|
+
return layoutInWorld().topLeftPoint instanceof DOMPoint;
|
|
445
|
+
},
|
|
446
|
+
get children() {
|
|
447
|
+
return createComponent(Vertex, {
|
|
448
|
+
direction: "topLeft",
|
|
449
|
+
get layout() {
|
|
450
|
+
return layoutInWorld();
|
|
451
|
+
},
|
|
452
|
+
getResizeHandlerProps: getResizeHandlerProps,
|
|
453
|
+
getRotateHandlerProps: getRotateHandlerProps
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}), null);
|
|
457
|
+
insert(_el$, createComponent(Show, {
|
|
458
|
+
get when() {
|
|
459
|
+
return layoutInWorld().topRightPoint instanceof DOMPoint;
|
|
460
|
+
},
|
|
461
|
+
get children() {
|
|
462
|
+
return createComponent(Vertex, {
|
|
463
|
+
direction: "topRight",
|
|
464
|
+
get layout() {
|
|
465
|
+
return layoutInWorld();
|
|
466
|
+
},
|
|
467
|
+
getResizeHandlerProps: getResizeHandlerProps,
|
|
468
|
+
getRotateHandlerProps: getRotateHandlerProps
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}), null);
|
|
472
|
+
insert(_el$, createComponent(Show, {
|
|
473
|
+
get when() {
|
|
474
|
+
return layoutInWorld().bottomLeftPoint instanceof DOMPoint;
|
|
475
|
+
},
|
|
476
|
+
get children() {
|
|
477
|
+
return createComponent(Vertex, {
|
|
478
|
+
direction: "bottomLeft",
|
|
479
|
+
get layout() {
|
|
480
|
+
return layoutInWorld();
|
|
481
|
+
},
|
|
482
|
+
getResizeHandlerProps: getResizeHandlerProps,
|
|
483
|
+
getRotateHandlerProps: getRotateHandlerProps
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}), null);
|
|
487
|
+
insert(_el$, createComponent(Show, {
|
|
488
|
+
get when() {
|
|
489
|
+
return layoutInWorld().bottomRightPoint instanceof DOMPoint;
|
|
490
|
+
},
|
|
491
|
+
get children() {
|
|
492
|
+
return createComponent(Vertex, {
|
|
493
|
+
direction: "bottomRight",
|
|
494
|
+
get layout() {
|
|
495
|
+
return layoutInWorld();
|
|
496
|
+
},
|
|
497
|
+
getResizeHandlerProps: getResizeHandlerProps,
|
|
498
|
+
getRotateHandlerProps: getRotateHandlerProps
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}), null);
|
|
502
|
+
insert(_el$, createComponent(Show, {
|
|
503
|
+
get when() {
|
|
504
|
+
return adsorbLine()?.top;
|
|
505
|
+
},
|
|
506
|
+
get children() {
|
|
507
|
+
return createComponent(ParentEdge, {
|
|
508
|
+
direction: "top",
|
|
509
|
+
get layout() {
|
|
510
|
+
return parentLayoutInWorld();
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}), null);
|
|
515
|
+
insert(_el$, createComponent(Show, {
|
|
516
|
+
get when() {
|
|
517
|
+
return adsorbLine()?.bottom;
|
|
518
|
+
},
|
|
519
|
+
get children() {
|
|
520
|
+
return createComponent(ParentEdge, {
|
|
521
|
+
direction: "bottom",
|
|
522
|
+
get layout() {
|
|
523
|
+
return parentLayoutInWorld();
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}), null);
|
|
528
|
+
insert(_el$, createComponent(Show, {
|
|
529
|
+
get when() {
|
|
530
|
+
return adsorbLine()?.left;
|
|
531
|
+
},
|
|
532
|
+
get children() {
|
|
533
|
+
return createComponent(ParentEdge, {
|
|
534
|
+
direction: "left",
|
|
535
|
+
get layout() {
|
|
536
|
+
return parentLayoutInWorld();
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}), null);
|
|
541
|
+
insert(_el$, createComponent(Show, {
|
|
542
|
+
get when() {
|
|
543
|
+
return adsorbLine()?.right;
|
|
544
|
+
},
|
|
545
|
+
get children() {
|
|
546
|
+
return createComponent(ParentEdge, {
|
|
547
|
+
direction: "right",
|
|
548
|
+
get layout() {
|
|
549
|
+
return parentLayoutInWorld();
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
}), null);
|
|
554
|
+
insert(_el$, createComponent(Show, {
|
|
555
|
+
get when() {
|
|
556
|
+
return adsorbLine()?.centerX;
|
|
557
|
+
},
|
|
558
|
+
get children() {
|
|
559
|
+
return createComponent(ParentCenterLine, {
|
|
560
|
+
get line() {
|
|
561
|
+
return parentLayoutInWorld().xCenterLine;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
}), null);
|
|
566
|
+
insert(_el$, createComponent(Show, {
|
|
567
|
+
get when() {
|
|
568
|
+
return adsorbLine()?.centerY;
|
|
569
|
+
},
|
|
570
|
+
get children() {
|
|
571
|
+
return createComponent(ParentCenterLine, {
|
|
572
|
+
get line() {
|
|
573
|
+
return parentLayoutInWorld().yCenterLine;
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}), null);
|
|
578
|
+
insert(_el$, createComponent(Show, {
|
|
579
|
+
get when() {
|
|
580
|
+
return memo(() => !!props.transformOriginIcon)() && transformOrigin();
|
|
581
|
+
},
|
|
582
|
+
get children() {
|
|
583
|
+
var _el$3 = _tmpl$();
|
|
584
|
+
insert(_el$3, createComponent(CrosshairSvg, {
|
|
585
|
+
"class": "absolute [font-size:var(--size)] text-black pointer-events-none",
|
|
586
|
+
get style() {
|
|
587
|
+
return {
|
|
588
|
+
'--size': '14px',
|
|
589
|
+
top: `calc(${transformOrigin().y}px - var(--size) / 2)`,
|
|
590
|
+
left: `calc(${transformOrigin().x}px - var(--size) / 2)`
|
|
591
|
+
};
|
|
592
|
+
},
|
|
593
|
+
innerColor: "white",
|
|
594
|
+
outerColor: "black"
|
|
595
|
+
}));
|
|
596
|
+
return _el$3;
|
|
597
|
+
}
|
|
598
|
+
}), null);
|
|
599
|
+
insert(_el$, createComponent(Show, {
|
|
600
|
+
get when() {
|
|
601
|
+
return memo(() => !!!resizeDirection())() && rotateDirection();
|
|
602
|
+
},
|
|
603
|
+
get children() {
|
|
604
|
+
return createComponent(Portal, {
|
|
605
|
+
get children() {
|
|
606
|
+
return createComponent(RotateArrowSvg, {
|
|
607
|
+
"class": "absolute pointer-events-none text-24px",
|
|
608
|
+
get style() {
|
|
609
|
+
return {
|
|
610
|
+
top: `${rotateArrowPosition().y}px`,
|
|
611
|
+
left: `${rotateArrowPosition().x}px`,
|
|
612
|
+
transform: `translate(-50%, -50%) rotate(${rotateArrowRotate()}rad)`
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}), null);
|
|
620
|
+
insert(_el$, createComponent(Show, {
|
|
621
|
+
get when() {
|
|
622
|
+
return resizeDirection();
|
|
623
|
+
},
|
|
624
|
+
get children() {
|
|
625
|
+
return createComponent(Portal, {
|
|
626
|
+
get children() {
|
|
627
|
+
return createComponent(Resize, {
|
|
628
|
+
"class": "absolute pointer-events-none text-24px",
|
|
629
|
+
get style() {
|
|
630
|
+
return {
|
|
631
|
+
top: `${resizeArrowPosition().y}px`,
|
|
632
|
+
left: `${resizeArrowPosition().x}px`,
|
|
633
|
+
transform: `translate(-50%, -50%) rotate(${resizeArrowRotate()}rad)`
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
}), null);
|
|
641
|
+
effect(_p$ => {
|
|
642
|
+
var _v$ = cs('absolute pointer-events-none', !props.viewBox && 'overflow-visible w-1px h-1px'),
|
|
643
|
+
_v$2 = viewBoxStr(),
|
|
644
|
+
_v$3 = pathD();
|
|
645
|
+
_v$ !== _p$.e && setAttribute(_el$, "class", _p$.e = _v$);
|
|
646
|
+
_v$2 !== _p$.t && setAttribute(_el$, "viewBox", _p$.t = _v$2);
|
|
647
|
+
_v$3 !== _p$.a && setAttribute(_el$2, "d", _p$.a = _v$3);
|
|
648
|
+
return _p$;
|
|
649
|
+
}, {
|
|
650
|
+
e: undefined,
|
|
651
|
+
t: undefined,
|
|
652
|
+
a: undefined
|
|
653
|
+
});
|
|
654
|
+
return _el$;
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
/**
|
|
659
|
+
* 根据 point 获取 angle
|
|
660
|
+
* @param point
|
|
661
|
+
* @returns
|
|
662
|
+
*/
|
|
663
|
+
const getAngleOfDOMPoint = point => {
|
|
664
|
+
const angle = Math.atan2(point.y, point.x);
|
|
665
|
+
return angle < 0 ? Math.PI * 2 + angle : angle;
|
|
666
|
+
};
|
|
667
|
+
const Edge = props => {
|
|
668
|
+
const startPoint = createMemo(() => {
|
|
669
|
+
const layout = props.layout;
|
|
670
|
+
const p = {
|
|
671
|
+
top: layout.topLeftPoint,
|
|
672
|
+
right: layout.topRightPoint,
|
|
673
|
+
bottom: layout.bottomRightPoint,
|
|
674
|
+
left: layout.bottomLeftPoint
|
|
675
|
+
}[props.direction];
|
|
676
|
+
return (Array.isArray(p) ? p[1] : p) ?? new DOMPoint();
|
|
677
|
+
});
|
|
678
|
+
const endPoint = createMemo(() => {
|
|
679
|
+
const layout = props.layout;
|
|
680
|
+
const p = {
|
|
681
|
+
top: layout.topRightPoint,
|
|
682
|
+
right: layout.bottomRightPoint,
|
|
683
|
+
bottom: layout.bottomLeftPoint,
|
|
684
|
+
left: layout.topLeftPoint
|
|
685
|
+
}[props.direction];
|
|
686
|
+
return (Array.isArray(p) ? p[0] : p) ?? new DOMPoint();
|
|
687
|
+
});
|
|
688
|
+
const getMouseRotate = () => {
|
|
689
|
+
const centerLine = props.centerLine;
|
|
690
|
+
if (centerLine) {
|
|
691
|
+
return getAngleOfDOMPoint(subDOMPoint(centerLine[0], centerLine[1]));
|
|
692
|
+
}
|
|
693
|
+
return getAngleOfDOMPoint(subDOMPoint(endPoint(), startPoint()));
|
|
694
|
+
};
|
|
695
|
+
return [(() => {
|
|
696
|
+
var _el$4 = _tmpl$3();
|
|
697
|
+
effect(() => setAttribute(_el$4, "d", `M ${startPoint().x},${startPoint().y} L ${endPoint().x},${endPoint().y}`));
|
|
698
|
+
return _el$4;
|
|
699
|
+
})(), (() => {
|
|
700
|
+
var _el$5 = _tmpl$4();
|
|
701
|
+
spread(_el$5, mergeProps({
|
|
702
|
+
get d() {
|
|
703
|
+
return `M ${startPoint().x},${startPoint().y} L ${endPoint().x},${endPoint().y}`;
|
|
704
|
+
}
|
|
705
|
+
}, () => props.getResizeHandlerProps(props.direction, getMouseRotate)), true, false);
|
|
706
|
+
return _el$5;
|
|
707
|
+
})()];
|
|
708
|
+
};
|
|
709
|
+
const Vertex = props => {
|
|
710
|
+
const prevPoint = createMemo(() => {
|
|
711
|
+
const layout = props.layout;
|
|
712
|
+
const point = {
|
|
713
|
+
topLeft: layout.bottomLeftPoint,
|
|
714
|
+
topRight: layout.topLeftPoint,
|
|
715
|
+
bottomRight: layout.topRightPoint,
|
|
716
|
+
bottomLeft: layout.bottomRightPoint
|
|
717
|
+
}[props.direction];
|
|
718
|
+
return (Array.isArray(point) ? point[1] : point) ?? new DOMPoint();
|
|
719
|
+
});
|
|
720
|
+
const nextPoint = createMemo(() => {
|
|
721
|
+
const layout = props.layout;
|
|
722
|
+
const point = {
|
|
723
|
+
topLeft: layout.topRightPoint,
|
|
724
|
+
topRight: layout.bottomRightPoint,
|
|
725
|
+
bottomRight: layout.bottomLeftPoint,
|
|
726
|
+
bottomLeft: layout.topLeftPoint
|
|
727
|
+
}[props.direction];
|
|
728
|
+
return (Array.isArray(point) ? point[0] : point) ?? new DOMPoint();
|
|
729
|
+
});
|
|
730
|
+
const currentPoint = createMemo(() => {
|
|
731
|
+
const layout = props.layout;
|
|
732
|
+
const point = {
|
|
733
|
+
topLeft: layout.topLeftPoint,
|
|
734
|
+
topRight: layout.topRightPoint,
|
|
735
|
+
bottomRight: layout.bottomRightPoint,
|
|
736
|
+
bottomLeft: layout.bottomLeftPoint
|
|
737
|
+
}[props.direction];
|
|
738
|
+
// 如果 point 不是 DOMPoint 对象,则本组件不需要显示
|
|
739
|
+
return point instanceof DOMPoint ? point : new DOMPoint();
|
|
740
|
+
});
|
|
741
|
+
const startAngle = createMemo(() => getAngleOfDOMPoint(subDOMPoint(nextPoint(), currentPoint())));
|
|
742
|
+
const _endAngle = createMemo(() => getAngleOfDOMPoint(subDOMPoint(prevPoint(), currentPoint())));
|
|
743
|
+
const endAngle = createMemo(() => {
|
|
744
|
+
return _endAngle() < startAngle() ? _endAngle() + Math.PI * 2 : _endAngle();
|
|
745
|
+
});
|
|
746
|
+
const centerAngle = createMemo(() => (startAngle() + endAngle()) / 2);
|
|
747
|
+
const getLayout = size => {
|
|
748
|
+
const gap = endAngle() - startAngle();
|
|
749
|
+
let _size = gap > Math.PI / 2 ? size / Math.tan(gap / 2) : size;
|
|
750
|
+
let translate = {
|
|
751
|
+
x: Math.cos(centerAngle()) * _size,
|
|
752
|
+
y: Math.sin(centerAngle()) * _size
|
|
753
|
+
};
|
|
754
|
+
const {
|
|
755
|
+
x,
|
|
756
|
+
y
|
|
757
|
+
} = currentPoint();
|
|
758
|
+
const topLeftPoint = new DOMPoint(x + translate.x, y + translate.y);
|
|
759
|
+
const bottomRightPoint = new DOMPoint(x - translate.x, y - translate.y);
|
|
760
|
+
_size = gap > Math.PI / 2 ? size : size * Math.tan(gap / 2);
|
|
761
|
+
const angle = centerAngle() + Math.PI / 2;
|
|
762
|
+
translate = {
|
|
763
|
+
x: Math.cos(angle) * _size,
|
|
764
|
+
y: Math.sin(angle) * _size
|
|
765
|
+
};
|
|
766
|
+
const topRightPoint = new DOMPoint(x + translate.x, y + translate.y);
|
|
767
|
+
const bottomLeftPoint = new DOMPoint(x - translate.x, y - translate.y);
|
|
768
|
+
return {
|
|
769
|
+
topLeftPoint,
|
|
770
|
+
topRightPoint,
|
|
771
|
+
bottomRightPoint,
|
|
772
|
+
bottomLeftPoint
|
|
773
|
+
};
|
|
774
|
+
};
|
|
775
|
+
const layoutToPathD = _layout => {
|
|
776
|
+
const {
|
|
777
|
+
topLeftPoint,
|
|
778
|
+
topRightPoint,
|
|
779
|
+
bottomRightPoint,
|
|
780
|
+
bottomLeftPoint
|
|
781
|
+
} = _layout;
|
|
782
|
+
return `M ${topLeftPoint.x},${topLeftPoint.y} L ${topRightPoint.x},${topRightPoint.y} L ${bottomRightPoint.x},${bottomRightPoint.y} L ${bottomLeftPoint.x},${bottomLeftPoint.y} Z`;
|
|
783
|
+
};
|
|
784
|
+
const rotateSize = 24;
|
|
785
|
+
// 旋转部份的 layout
|
|
786
|
+
const rotateLayout = createMemo(() => getLayout(rotateSize));
|
|
787
|
+
// 显示部份的 layout
|
|
788
|
+
const displayLayout = createMemo(() => getLayout(8));
|
|
789
|
+
// 调整尺寸部份的 layout
|
|
790
|
+
const reseizLayout = createMemo(() => {
|
|
791
|
+
const {
|
|
792
|
+
topLeftPoint,
|
|
793
|
+
topRightPoint,
|
|
794
|
+
bottomRightPoint,
|
|
795
|
+
bottomLeftPoint
|
|
796
|
+
} = getLayout(rotateSize / 2);
|
|
797
|
+
const _rotateLayout = rotateLayout();
|
|
798
|
+
const translate = subDOMPoint(_rotateLayout.bottomRightPoint, bottomRightPoint);
|
|
799
|
+
return {
|
|
800
|
+
topLeftPoint: subDOMPoint(topLeftPoint, translate),
|
|
801
|
+
topRightPoint: subDOMPoint(topRightPoint, translate),
|
|
802
|
+
bottomRightPoint: subDOMPoint(bottomRightPoint, translate),
|
|
803
|
+
bottomLeftPoint: subDOMPoint(bottomLeftPoint, translate)
|
|
804
|
+
};
|
|
805
|
+
});
|
|
806
|
+
const getMouseRotate = () => {
|
|
807
|
+
const layout = props.layout;
|
|
808
|
+
// 相对的点
|
|
809
|
+
const oppositePoint = {
|
|
810
|
+
topLeft: layout.bottomRightPoint,
|
|
811
|
+
topRight: layout.bottomLeftPoint,
|
|
812
|
+
bottomRight: layout.topLeftPoint,
|
|
813
|
+
bottomLeft: layout.topRightPoint
|
|
814
|
+
}[props.direction];
|
|
815
|
+
if (oppositePoint instanceof DOMPoint) {
|
|
816
|
+
return getAngleOfDOMPoint(subDOMPoint(oppositePoint, currentPoint())) + Math.PI / 2;
|
|
817
|
+
}
|
|
818
|
+
return centerAngle() + Math.PI / 2;
|
|
819
|
+
};
|
|
820
|
+
return [(() => {
|
|
821
|
+
var _el$6 = _tmpl$5();
|
|
822
|
+
spread(_el$6, mergeProps({
|
|
823
|
+
get d() {
|
|
824
|
+
return layoutToPathD(rotateLayout());
|
|
825
|
+
}
|
|
826
|
+
}, () => props.getRotateHandlerProps(props.direction, getMouseRotate)), true, false);
|
|
827
|
+
return _el$6;
|
|
828
|
+
})(), (() => {
|
|
829
|
+
var _el$7 = _tmpl$6();
|
|
830
|
+
spread(_el$7, mergeProps({
|
|
831
|
+
get d() {
|
|
832
|
+
return layoutToPathD(displayLayout());
|
|
833
|
+
}
|
|
834
|
+
}, () => props.getResizeHandlerProps(props.direction, getMouseRotate)), true, false);
|
|
835
|
+
return _el$7;
|
|
836
|
+
})(), (() => {
|
|
837
|
+
var _el$8 = _tmpl$7();
|
|
838
|
+
spread(_el$8, mergeProps({
|
|
839
|
+
get d() {
|
|
840
|
+
return layoutToPathD(reseizLayout());
|
|
841
|
+
}
|
|
842
|
+
}, () => props.getResizeHandlerProps(props.direction, getMouseRotate)), true, false);
|
|
843
|
+
return _el$8;
|
|
844
|
+
})()];
|
|
845
|
+
};
|
|
846
|
+
const ParentEdge = props => {
|
|
847
|
+
const startPoint = createMemo(() => {
|
|
848
|
+
const layout = props.layout;
|
|
849
|
+
const p = {
|
|
850
|
+
top: layout.topLeftPoint,
|
|
851
|
+
right: layout.topRightPoint,
|
|
852
|
+
bottom: layout.bottomRightPoint,
|
|
853
|
+
left: layout.bottomLeftPoint
|
|
854
|
+
}[props.direction];
|
|
855
|
+
return (Array.isArray(p) ? p[1] : p) ?? new DOMPoint();
|
|
856
|
+
});
|
|
857
|
+
const endPoint = createMemo(() => {
|
|
858
|
+
const layout = props.layout;
|
|
859
|
+
const p = {
|
|
860
|
+
top: layout.topRightPoint,
|
|
861
|
+
right: layout.bottomRightPoint,
|
|
862
|
+
bottom: layout.bottomLeftPoint,
|
|
863
|
+
left: layout.topLeftPoint
|
|
864
|
+
}[props.direction];
|
|
865
|
+
return (Array.isArray(p) ? p[0] : p) ?? new DOMPoint();
|
|
866
|
+
});
|
|
867
|
+
return (() => {
|
|
868
|
+
var _el$9 = _tmpl$3();
|
|
869
|
+
effect(() => setAttribute(_el$9, "d", `M ${startPoint().x},${startPoint().y} L ${endPoint().x},${endPoint().y}`));
|
|
870
|
+
return _el$9;
|
|
871
|
+
})();
|
|
872
|
+
};
|
|
873
|
+
const ParentCenterLine = props => {
|
|
874
|
+
return memo(() => memo(() => !!props.line)() ? (() => {
|
|
875
|
+
var _el$10 = _tmpl$3();
|
|
876
|
+
effect(() => setAttribute(_el$10, "d", `M ${props.line[0].x},${props.line[0].y} L ${props.line[1].x},${props.line[1].y}`));
|
|
877
|
+
return _el$10;
|
|
878
|
+
})() : null);
|
|
879
|
+
};
|
|
880
|
+
delegateEvents(["mousedown"]);
|
|
881
|
+
|
|
882
|
+
export { Transformer as default };
|