aboutsummaryrefslogtreecommitdiff
path: root/src/ClientUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/ClientUtils.ts')
-rw-r--r--src/ClientUtils.ts24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/ClientUtils.ts b/src/ClientUtils.ts
index 630d7edbc..fc415d589 100644
--- a/src/ClientUtils.ts
+++ b/src/ClientUtils.ts
@@ -7,11 +7,11 @@ import { CollectionViewType, DocumentType } from './client/documents/DocumentTyp
import { Colors } from './client/views/global/globalEnums';
import { CreateImage } from './client/views/nodes/WebBoxRenderer';
-export function DashColor(color: string) {
+export function DashColor(color: string | undefined) {
try {
return color ? Color(color.toLowerCase()) : Color('transparent');
} catch (e) {
- if (color.includes('gradient')) console.log("using color 'white' in place of :" + color);
+ if (color?.includes('gradient')) console.log("using color 'white' in place of :" + color);
else console.log('COLOR error:', e);
return Color('white');
}
@@ -455,7 +455,7 @@ export function addStyleSheet() {
const sheets = document.head.appendChild(style);
return sheets.sheet;
}
-export function addStyleSheetRule(sheet: CSSStyleSheet | null, selector: string, css: string | {[key:string]: string}, selectorPrefix = '.') {
+export function addStyleSheetRule(sheet: CSSStyleSheet | null, selector: string, css: string | { [key: string]: string }, selectorPrefix = '.') {
const propText =
typeof css === 'string'
? css
@@ -464,14 +464,14 @@ export function addStyleSheetRule(sheet: CSSStyleSheet | null, selector: string,
.join(';');
return sheet?.insertRule(selectorPrefix + selector + '{' + propText + '}', sheet.cssRules.length);
}
-export function removeStyleSheetRule(sheet: CSSStyleSheet|null, rule: number) {
+export function removeStyleSheetRule(sheet: CSSStyleSheet | null, rule: number) {
if (sheet?.rules.length) {
sheet.removeRule(rule);
return true;
}
return false;
}
-export function clearStyleSheetRules(sheet: CSSStyleSheet|null) {
+export function clearStyleSheetRules(sheet: CSSStyleSheet | null) {
if (sheet?.rules.length) {
numberRange(sheet.rules.length).map(() => sheet.removeRule(0));
return true;
@@ -479,10 +479,16 @@ export function clearStyleSheetRules(sheet: CSSStyleSheet|null) {
return false;
}
+export class simPointerEvent extends PointerEvent {
+ dash?: boolean;
+}
+export class simMouseEvent extends MouseEvent {
+ dash?: boolean;
+}
export function simulateMouseClick(element: Element | null | undefined, x: number, y: number, sx: number, sy: number, rightClick = true) {
if (!element) return;
['pointerdown', 'pointerup'].forEach(event => {
- const me = new PointerEvent(event, {
+ const me = new simPointerEvent(event, {
view: window,
bubbles: true,
cancelable: true,
@@ -493,12 +499,12 @@ export function simulateMouseClick(element: Element | null | undefined, x: numbe
screenX: sx,
screenY: sy,
});
- (me as any).dash = true;
+ me.dash = true;
element.dispatchEvent(me);
});
if (rightClick) {
- const me = new MouseEvent('contextmenu', {
+ const me = new simMouseEvent('contextmenu', {
view: window,
bubbles: true,
cancelable: true,
@@ -510,7 +516,7 @@ export function simulateMouseClick(element: Element | null | undefined, x: numbe
screenX: sx,
screenY: sy,
});
- (me as any).dash = true;
+ me.dash = true;
element.dispatchEvent(me);
}
}