@tmagic/stage 1.0.0-beta.1 → 1.0.0-beta.12
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/LICENSE +5432 -0
- package/README.md +1 -0
- package/dist/tmagic-stage.es.js +663 -17594
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +668 -17601
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/Rule.d.ts +32 -0
- package/dist/types/src/StageCore.d.ts +21 -10
- package/dist/types/src/StageDragResize.d.ts +18 -12
- package/dist/types/src/StageHighlight.d.ts +25 -0
- package/dist/types/src/StageMask.d.ts +38 -35
- package/dist/types/src/StageRender.d.ts +1 -0
- package/dist/types/src/const.d.ts +20 -0
- package/dist/types/src/types.d.ts +10 -10
- package/dist/types/src/util.d.ts +9 -5
- package/package.json +12 -9
- package/src/Rule.ts +150 -0
- package/src/StageCore.ts +152 -104
- package/src/StageDragResize.ts +214 -182
- package/src/StageHighlight.ts +70 -0
- package/src/StageMask.ts +170 -166
- package/src/StageRender.ts +25 -9
- package/src/const.ts +26 -0
- package/src/types.ts +28 -28
- package/src/util.ts +57 -7
package/src/util.ts
CHANGED
|
@@ -16,14 +16,9 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import { Mode, SELECTED_CLASS } from './const';
|
|
19
20
|
import type { Offset } from './types';
|
|
20
21
|
|
|
21
|
-
export enum Mode {
|
|
22
|
-
ABSOLUTE = 'absolute',
|
|
23
|
-
FIXED = 'fixed',
|
|
24
|
-
SORTABLE = 'sortable',
|
|
25
|
-
}
|
|
26
|
-
|
|
27
22
|
export const getOffset = (el: HTMLElement): Offset => {
|
|
28
23
|
const { transform } = getComputedStyle(el);
|
|
29
24
|
const { offsetParent } = el;
|
|
@@ -113,8 +108,63 @@ export const isFixed = (el?: HTMLElement): boolean => {
|
|
|
113
108
|
return getComputedStyle(el).position === 'fixed';
|
|
114
109
|
};
|
|
115
110
|
|
|
111
|
+
export const isFixedParent = (el: HTMLElement) => {
|
|
112
|
+
let fixed = false;
|
|
113
|
+
let dom = el;
|
|
114
|
+
while (dom) {
|
|
115
|
+
fixed = isFixed(dom);
|
|
116
|
+
if (fixed) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
const { parentElement } = dom;
|
|
120
|
+
if (!parentElement || parentElement.tagName === 'BODY') {
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
dom = parentElement;
|
|
124
|
+
}
|
|
125
|
+
return fixed;
|
|
126
|
+
};
|
|
127
|
+
|
|
116
128
|
export const getMode = (el: HTMLElement): Mode => {
|
|
117
|
-
if (
|
|
129
|
+
if (isFixedParent(el)) return Mode.FIXED;
|
|
118
130
|
if (isStatic(el) || isRelative(el)) return Mode.SORTABLE;
|
|
119
131
|
return Mode.ABSOLUTE;
|
|
120
132
|
};
|
|
133
|
+
|
|
134
|
+
export const getScrollParent = (element: HTMLElement, includeHidden = false): HTMLElement | null => {
|
|
135
|
+
let style = getComputedStyle(element);
|
|
136
|
+
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
|
137
|
+
|
|
138
|
+
if (isFixed(element)) return null;
|
|
139
|
+
for (let parent = element; parent.parentElement; ) {
|
|
140
|
+
parent = parent.parentElement;
|
|
141
|
+
style = getComputedStyle(parent);
|
|
142
|
+
if (isAbsolute(element) && isStatic(element)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return null;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const createDiv = ({ className, cssText }: { className: string; cssText: string }) => {
|
|
152
|
+
const el = globalThis.document.createElement('div');
|
|
153
|
+
el.className = className;
|
|
154
|
+
el.style.cssText = cssText;
|
|
155
|
+
return el;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const removeSelectedClassName = (doc: Document) => {
|
|
159
|
+
const oldEl = doc.querySelector(`.${SELECTED_CLASS}`);
|
|
160
|
+
|
|
161
|
+
if (oldEl) {
|
|
162
|
+
oldEl.classList.remove(SELECTED_CLASS);
|
|
163
|
+
(oldEl.parentNode as HTMLDivElement)?.classList.remove(`${SELECTED_CLASS}-parent`);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const addSelectedClassName = (el: Element) => {
|
|
168
|
+
el.classList.add(SELECTED_CLASS);
|
|
169
|
+
(el.parentNode as Element)?.classList.add(`${SELECTED_CLASS}-parent`);
|
|
170
|
+
};
|