update repo structure

This commit is contained in:
Rene Haas
2022-07-30 19:45:11 +02:00
parent 908f692569
commit 843d627715
158 changed files with 26998 additions and 9790 deletions
+28
View File
@@ -0,0 +1,28 @@
declare type ClassContainingElement = Node | Element | false | null | undefined;
declare type ClassName = string | false | null | undefined;
/**
* Check whether the given element has the given class name(s).
* @param elm The element.
* @param className The class name(s).
*/
export declare const hasClass: (elm: ClassContainingElement, className: ClassName) => boolean;
/**
* Removes the given class name(s) from the given element.
* @param elm The element.
* @param className The class name(s) which shall be removed. (separated by spaces)
*/
export declare const removeClass: (elm: ClassContainingElement, className: ClassName) => void;
/**
* Adds the given class name(s) to the given element.
* @param elm The element.
* @param className The class name(s) which shall be added. (separated by spaces)
* @returns A function which removes the added class name(s).
*/
export declare const addClass: (elm: ClassContainingElement, className: ClassName) => (() => void);
/**
* Takes two className strings, compares them and returns the difference as array.
* @param classNameA ClassName A.
* @param classNameB ClassName B.
*/
export declare const diffClass: (classNameA: ClassName, classNameB: ClassName) => string[];
export {};
+65
View File
@@ -0,0 +1,65 @@
import { isString } from '../utils/types';
import { each } from '../utils/array';
import { keys } from '../utils/object';
const rnothtmlwhite = /[^\x20\t\r\n\f]+/g;
const classListAction = (elm, className, action) => {
const classList = elm && elm.classList;
let clazz;
let i = 0;
let result = false;
if (classList && className && isString(className)) {
const classes = className.match(rnothtmlwhite) || [];
result = classes.length > 0;
while ((clazz = classes[i++])) {
result = !!action(classList, clazz) && result;
}
}
return result;
};
/**
* Check whether the given element has the given class name(s).
* @param elm The element.
* @param className The class name(s).
*/
export const hasClass = (elm, className) => classListAction(elm, className, (classList, clazz) => classList.contains(clazz));
/**
* Removes the given class name(s) from the given element.
* @param elm The element.
* @param className The class name(s) which shall be removed. (separated by spaces)
*/
export const removeClass = (elm, className) => {
classListAction(elm, className, (classList, clazz) => classList.remove(clazz));
};
/**
* Adds the given class name(s) to the given element.
* @param elm The element.
* @param className The class name(s) which shall be added. (separated by spaces)
* @returns A function which removes the added class name(s).
*/
export const addClass = (elm, className) => {
classListAction(elm, className, (classList, clazz) => classList.add(clazz));
return removeClass.bind(0, elm, className);
};
/**
* Takes two className strings, compares them and returns the difference as array.
* @param classNameA ClassName A.
* @param classNameB ClassName B.
*/
export const diffClass = (classNameA, classNameB) => {
const classNameASplit = classNameA && classNameA.split(' ');
const classNameBSplit = classNameB && classNameB.split(' ');
const tempObj = {};
each(classNameASplit, (className) => {
tempObj[className] = 1;
});
each(classNameBSplit, (className) => {
if (tempObj[className]) {
delete tempObj[className];
}
else {
tempObj[className] = 1;
}
});
return keys(tempObj);
};
//# sourceMappingURL=class.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"class.js","sourceRoot":"","sources":["../../../src/support/dom/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAC1C,MAAM,eAAe,GAAG,CACtB,GAA2B,EAC3B,SAAoB,EACpB,MAAqE,EAC5D,EAAE;IACX,MAAM,SAAS,GAAG,GAAG,IAAK,GAAe,CAAC,SAAS,CAAC;IACpD,IAAI,KAAa,CAAC;IAClB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,IAAI,SAAS,IAAI,SAAS,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE;QACjD,MAAM,OAAO,GAAkB,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;QACpE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QAC5B,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;YAC7B,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC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GAAG,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,eAAe,EAAE,CAAC,SAAS,EAAE,EAAE;QAClC,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;YACtB,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;SAC3B;aAAM;YACL,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SACxB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC,CAAC"}
+9
View File
@@ -0,0 +1,9 @@
/**
* Creates a div DOM node.
*/
export declare const createDiv: (classNames?: string) => HTMLDivElement;
/**
* Creates DOM nodes modeled after the passed html string and returns the root dom nodes as a array.
* @param html The html string after which the DOM nodes shall be created.
*/
export declare const createDOM: (html: string) => ReadonlyArray<Node>;
+23
View File
@@ -0,0 +1,23 @@
import { each } from '../utils/array';
import { contents } from './traversal';
import { removeElements } from './manipulation';
/**
* Creates a div DOM node.
*/
export const createDiv = (classNames) => {
const div = document.createElement('div');
if (classNames) {
div.setAttribute('class', classNames);
}
return div;
};
/**
* Creates DOM nodes modeled after the passed html string and returns the root dom nodes as a array.
* @param html The html string after which the DOM nodes shall be created.
*/
export const createDOM = (html) => {
const createdDiv = createDiv();
createdDiv.innerHTML = html.trim();
return each(contents(createdDiv), (elm) => removeElements(elm));
};
//# sourceMappingURL=create.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/support/dom/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,UAAmB,EAAkB,EAAE;IAC/D,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,UAAU,EAAE;QACd,GAAG,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;KACvC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAuB,EAAE;IAC7D,MAAM,UAAU,GAAG,SAAS,EAAE,CAAC;IAC/B,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAEnC,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC"}
+33
View File
@@ -0,0 +1,33 @@
export interface WH<T = number> {
w: T;
h: T;
}
/**
* Returns the window inner- width and height.
*/
export declare const windowSize: () => WH;
/**
* Returns the scroll- width and height of the passed element. If the element is null the width and height values are 0.
* @param elm The element of which the scroll- width and height shall be returned.
*/
export declare const offsetSize: (elm: HTMLElement | null | undefined) => WH;
/**
* Returns the client- width and height of the passed element. If the element is null the width and height values are 0.
* @param elm The element of which the client- width and height shall be returned.
*/
export declare const clientSize: (elm: HTMLElement | false | null | undefined) => WH;
/**
* Returns the client- width and height of the passed element. If the element is null the width and height values are 0.
* @param elm The element of which the client- width and height shall be returned.
*/
export declare const scrollSize: (elm: HTMLElement | false | null | undefined) => WH;
/**
* Returns the BoundingClientRect of the passed element.
* @param elm The element of which the BoundingClientRect shall be returned.
*/
export declare const getBoundingClientRect: (elm: HTMLElement) => DOMRect;
/**
* Determines whether the passed element has any dimensions.
* @param elm The element.
*/
export declare const hasDimensions: (elm: HTMLElement | false | null | undefined) => boolean;
+53
View File
@@ -0,0 +1,53 @@
const elementHasDimensions = (elm) => !!(elm.offsetWidth || elm.offsetHeight || elm.getClientRects().length);
const zeroObj = {
w: 0,
h: 0,
};
/**
* Returns the window inner- width and height.
*/
export const windowSize = () => ({
w: window.innerWidth,
h: window.innerHeight,
});
/**
* Returns the scroll- width and height of the passed element. If the element is null the width and height values are 0.
* @param elm The element of which the scroll- width and height shall be returned.
*/
export const offsetSize = (elm) => elm
? {
w: elm.offsetWidth,
h: elm.offsetHeight,
}
: zeroObj;
/**
* Returns the client- width and height of the passed element. If the element is null the width and height values are 0.
* @param elm The element of which the client- width and height shall be returned.
*/
export const clientSize = (elm) => elm
? {
w: elm.clientWidth,
h: elm.clientHeight,
}
: zeroObj;
/**
* Returns the client- width and height of the passed element. If the element is null the width and height values are 0.
* @param elm The element of which the client- width and height shall be returned.
*/
export const scrollSize = (elm) => elm
? {
w: elm.scrollWidth,
h: elm.scrollHeight,
}
: zeroObj;
/**
* Returns the BoundingClientRect of the passed element.
* @param elm The element of which the BoundingClientRect shall be returned.
*/
export const getBoundingClientRect = (elm) => elm.getBoundingClientRect();
/**
* Determines whether the passed element has any dimensions.
* @param elm The element.
*/
export const hasDimensions = (elm) => elm ? elementHasDimensions(elm) : false;
//# sourceMappingURL=dimensions.js.map
@@ -0,0 +1 @@
{"version":3,"file":"dimensions.js","sourceRoot":"","sources":["../../../src/support/dom/dimensions.ts"],"names":[],"mappings":"AAKA,MAAM,oBAAoB,GAAG,CAAC,GAAgB,EAAW,EAAE,CACzD,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC;AACzE,MAAM,OAAO,GAAO;IAClB,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;CACL,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAO,EAAE,CAAC,CAAC;IACnC,CAAC,EAAE,MAAM,CAAC,UAAU;IACpB,CAAC,EAAE,MAAM,CAAC,WAAW;CACtB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAmC,EAAM,EAAE,CACpE,GAAG;IACD,CAAC,CAAC;QACE,CAAC,EAAE,GAAG,CAAC,WAAW;QAClB,CAAC,EAAE,GAAG,CAAC,YAAY;KACpB;IACH,CAAC,CAAC,OAAO,CAAC;AAEd;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAA2C,EAAM,EAAE,CAC5E,GAAG;IACD,CAAC,CAAC;QACE,CAAC,EAAE,GAAG,CAAC,WAAW;QAClB,CAAC,EAAE,GAAG,CAAC,YAAY;KACpB;IACH,CAAC,CAAC,OAAO,CAAC;AAEd;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAA2C,EAAM,EAAE,CAC5E,GAAG;IACD,CAAC,CAAC;QACE,CAAC,EAAE,GAAG,CAAC,WAAW;QAClB,CAAC,EAAE,GAAG,CAAC,YAAY;KACpB;IACH,CAAC,CAAC,OAAO,CAAC;AAEd;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAgB,EAAW,EAAE,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;AAEhG;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAA2C,EAAW,EAAE,CACpF,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAkB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC"}
+36
View File
@@ -0,0 +1,36 @@
export interface OnOptions {
_capture?: boolean;
_passive?: boolean;
_once?: boolean;
}
/**
* Removes the passed event listener for the passed events with the passed options.
* @param target The element from which the listener shall be removed.
* @param eventNames The eventsnames for which the listener shall be removed.
* @param listener The listener which shall be removed.
* @param capture The options of the removed listener.
*/
export declare const off: <T extends Event = Event>(target: EventTarget, eventNames: string, listener: (event: T) => any, capture?: boolean) => void;
/**
* Adds the passed event listener for the passed eventnames with the passed options.
* @param target The element to which the listener shall be added.
* @param eventNames The eventsnames for which the listener shall be called.
* @param listener The listener which is called on the eventnames.
* @param options The options of the added listener.
*/
export declare const on: <T extends Event = Event>(target: EventTarget, eventNames: string, listener: (event: T) => any, options?: OnOptions) => (() => void);
/**
* Shorthand for the stopPropagation event Method.
* @param evt The event of which the stopPropagation method shall be called.
*/
export declare const stopPropagation: (evt: Event) => void;
/**
* Shorthand for the preventDefault event Method.
* @param evt The event of which the preventDefault method shall be called.
*/
export declare const preventDefault: (evt: Event) => void;
/**
* Shorthand for the stopPropagation and preventDefault event Method.
* @param evt The event of which the stopPropagation and preventDefault methods shall be called.
*/
export declare const stopAndPrevent: (evt: Event) => void;
+80
View File
@@ -0,0 +1,80 @@
import { isUndefined } from '../utils/types';
import { each, push, runEachAndClear } from '../utils/array';
let passiveEventsSupport;
const supportPassiveEvents = () => {
if (isUndefined(passiveEventsSupport)) {
passiveEventsSupport = false;
try {
/* eslint-disable */
// @ts-ignore
window.addEventListener('test', null, Object.defineProperty({}, 'passive', {
get() {
passiveEventsSupport = true;
},
}));
/* eslint-enable */
}
catch (e) { }
}
return passiveEventsSupport;
};
const splitEventNames = (eventNames) => eventNames.split(' ');
/**
* Removes the passed event listener for the passed events with the passed options.
* @param target The element from which the listener shall be removed.
* @param eventNames The eventsnames for which the listener shall be removed.
* @param listener The listener which shall be removed.
* @param capture The options of the removed listener.
*/
export const off = (target, eventNames, listener, capture) => {
each(splitEventNames(eventNames), (eventName) => {
target.removeEventListener(eventName, listener, capture);
});
};
/**
* Adds the passed event listener for the passed eventnames with the passed options.
* @param target The element to which the listener shall be added.
* @param eventNames The eventsnames for which the listener shall be called.
* @param listener The listener which is called on the eventnames.
* @param options The options of the added listener.
*/
export const on = (target, eventNames, listener, options) => {
const doSupportPassiveEvents = supportPassiveEvents();
const passive = (doSupportPassiveEvents && options && options._passive) ?? doSupportPassiveEvents;
const capture = (options && options._capture) || false;
const once = (options && options._once) || false;
const offListeners = [];
const nativeOptions = doSupportPassiveEvents
? {
passive,
capture,
}
: capture;
each(splitEventNames(eventNames), (eventName) => {
const finalListener = (once
? (evt) => {
target.removeEventListener(eventName, finalListener, capture);
listener && listener(evt);
}
: listener);
push(offListeners, off.bind(null, target, eventName, finalListener, capture));
target.addEventListener(eventName, finalListener, nativeOptions);
});
return runEachAndClear.bind(0, offListeners);
};
/**
* Shorthand for the stopPropagation event Method.
* @param evt The event of which the stopPropagation method shall be called.
*/
export const stopPropagation = (evt) => evt.stopPropagation();
/**
* Shorthand for the preventDefault event Method.
* @param evt The event of which the preventDefault method shall be called.
*/
export const preventDefault = (evt) => evt.preventDefault();
/**
* Shorthand for the stopPropagation and preventDefault event Method.
* @param evt The event of which the stopPropagation and preventDefault methods shall be called.
*/
export const stopAndPrevent = (evt) => stopPropagation(evt) || preventDefault(evt);
//# sourceMappingURL=events.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/support/dom/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE7D,IAAI,oBAA6B,CAAC;AAClC,MAAM,oBAAoB,GAAG,GAAY,EAAE;IACzC,IAAI,WAAW,CAAC,oBAAoB,CAAC,EAAE;QACrC,oBAAoB,GAAG,KAAK,CAAC;QAC7B,IAAI;YACF,oBAAoB;YACpB,aAAa;YACb,MAAM,CAAC,gBAAgB,CACrB,MAAM,EACN,IAAI,EACJ,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE;gBACnC,GAAG;oBACD,oBAAoB,GAAG,IAAI,CAAC;gBAC9B,CAAC;aACF,CAAC,CACH,CAAC;YACF,mBAAmB;SACpB;QAAC,OAAO,CAAC,EAAE,GAAE;KACf;IACD,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AACF,MAAM,eAAe,GAAG,CAAC,UAAkB,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAQtE;;;;;;GAM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,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9E,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAU,EAAQ,EAAE,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAU,EAAQ,EAAE,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAU,EAAQ,EAAE,CAChD,eAAe,CAAC,GAAG,CAAe,IAAK,cAAc,CAAC,GAAG,CAAe,CAAC"}
+8
View File
@@ -0,0 +1,8 @@
export * from './class';
export * from './create';
export * from './dimensions';
export * from './events';
export * from './style';
export * from './manipulation';
export * from './offset';
export * from './traversal';
+9
View File
@@ -0,0 +1,9 @@
export * from './class';
export * from './create';
export * from './dimensions';
export * from './events';
export * from './style';
export * from './manipulation';
export * from './offset';
export * from './traversal';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/support/dom/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,31 @@
declare type NodeCollection = ArrayLike<Node> | Node | false | null | undefined;
/**
* Appends the given children at the end of the given Node.
* @param node The Node to which the children shall be appended.
* @param children The Nodes which shall be appended.
*/
export declare const appendChildren: (node: Node | false | null | undefined, children: NodeCollection) => void;
/**
* Prepends the given children at the start of the given Node.
* @param node The Node to which the children shall be prepended.
* @param children The Nodes which shall be prepended.
*/
export declare const prependChildren: (node: Node | false | null | undefined, children: NodeCollection) => void;
/**
* Inserts the given Nodes before the given Node.
* @param node The Node before which the given Nodes shall be inserted.
* @param insertedNodes The Nodes which shall be inserted.
*/
export declare const insertBefore: (node: Node | false | null | undefined, insertedNodes: NodeCollection) => void;
/**
* Inserts the given Nodes after the given Node.
* @param node The Node after which the given Nodes shall be inserted.
* @param insertedNodes The Nodes which shall be inserted.
*/
export declare const insertAfter: (node: Node | false | null | undefined, insertedNodes: NodeCollection) => void;
/**
* Removes the given Nodes from their parent.
* @param nodes The Nodes which shall be removed.
*/
export declare const removeElements: (nodes: NodeCollection) => void;
export {};
+86
View File
@@ -0,0 +1,86 @@
import { isArrayLike } from '../utils/types';
import { each, from } from '../utils/array';
import { parent } from './traversal';
/**
* Inserts Nodes before the given preferredAnchor element.
* @param parentElm The parent of the preferredAnchor element or the element which shall be the parent of the inserted Nodes.
* @param preferredAnchor The element before which the Nodes shall be inserted or null if the elements shall be appended at the end.
* @param insertedElms The Nodes which shall be inserted.
*/
const before = (parentElm, preferredAnchor, insertedElms) => {
if (insertedElms && parentElm) {
let anchor = preferredAnchor;
let fragment;
if (isArrayLike(insertedElms)) {
fragment = document.createDocumentFragment();
// append all insertedElms to the fragment and if one of these is the anchor, change the anchor
each(insertedElms, (insertedElm) => {
if (insertedElm === anchor) {
anchor = insertedElm.previousSibling;
}
fragment.appendChild(insertedElm);
});
}
else {
fragment = insertedElms;
}
// if the preferred anchor isn't null set it to a valid anchor
if (preferredAnchor) {
if (!anchor) {
anchor = parentElm.firstChild;
}
else if (anchor !== preferredAnchor) {
anchor = anchor.nextSibling;
}
}
parentElm.insertBefore(fragment, anchor || null);
}
};
/**
* Appends the given children at the end of the given Node.
* @param node The Node to which the children shall be appended.
* @param children The Nodes which shall be appended.
*/
export const appendChildren = (node, children) => {
before(node, null, children);
};
/**
* Prepends the given children at the start of the given Node.
* @param node The Node to which the children shall be prepended.
* @param children The Nodes which shall be prepended.
*/
export const prependChildren = (node, children) => {
before(node, node && node.firstChild, children);
};
/**
* Inserts the given Nodes before the given Node.
* @param node The Node before which the given Nodes shall be inserted.
* @param insertedNodes The Nodes which shall be inserted.
*/
export const insertBefore = (node, insertedNodes) => {
before(parent(node), node, insertedNodes);
};
/**
* Inserts the given Nodes after the given Node.
* @param node The Node after which the given Nodes shall be inserted.
* @param insertedNodes The Nodes which shall be inserted.
*/
export const insertAfter = (node, insertedNodes) => {
before(parent(node), node && node.nextSibling, insertedNodes);
};
/**
* Removes the given Nodes from their parent.
* @param nodes The Nodes which shall be removed.
*/
export const removeElements = (nodes) => {
if (isArrayLike(nodes)) {
each(from(nodes), (e) => removeElements(e));
}
else if (nodes) {
const parentElm = parent(nodes);
if (parentElm) {
parentElm.removeChild(nodes);
}
}
};
//# sourceMappingURL=manipulation.js.map
@@ -0,0 +1 @@
{"version":3,"file":"manipulation.js","sourceRoot":"","sources":["../../../src/support/dom/manipulation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CACb,SAA0C,EAC1C,eAAgD,EAChD,YAA4B,EACtB,EAAE;IACR,IAAI,YAAY,IAAI,SAAS,EAAE;QAC7B,IAAI,MAAM,GAAoC,eAAe,CAAC;QAC9D,IAAI,QAAoD,CAAC;QAEzD,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE;YAC7B,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;YAE7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AC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAqB,EAAQ,EAAE;IAC5D,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;QACtB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7C;SAAM,IAAI,KAAK,EAAE;QAChB,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,SAAS,EAAE;YACb,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SAC9B;KACF;AACH,CAAC,CAAC"}
+14
View File
@@ -0,0 +1,14 @@
export interface XY<T = number> {
x: T;
y: T;
}
/**
* Returns the offset- left and top coordinates of the passed element relative to the document. If the element is null the top and left values are 0.
* @param elm The element of which the offset- top and left coordinates shall be returned.
*/
export declare const absoluteCoordinates: (elm: HTMLElement | null | undefined) => XY;
/**
* Returns the offset- left and top coordinates of the passed element. If the element is null the top and left values are 0.
* @param elm The element of which the offset- top and left coordinates shall be returned.
*/
export declare const offsetCoordinates: (elm: HTMLElement | null | undefined) => XY;
+29
View File
@@ -0,0 +1,29 @@
import { getBoundingClientRect } from './dimensions';
const zeroObj = {
x: 0,
y: 0,
};
/**
* Returns the offset- left and top coordinates of the passed element relative to the document. If the element is null the top and left values are 0.
* @param elm The element of which the offset- top and left coordinates shall be returned.
*/
export const absoluteCoordinates = (elm) => {
const rect = elm ? getBoundingClientRect(elm) : 0;
return rect
? {
x: rect.left + window.pageYOffset,
y: rect.top + window.pageXOffset,
}
: zeroObj;
};
/**
* Returns the offset- left and top coordinates of the passed element. If the element is null the top and left values are 0.
* @param elm The element of which the offset- top and left coordinates shall be returned.
*/
export const offsetCoordinates = (elm) => elm
? {
x: elm.offsetLeft,
y: elm.offsetTop,
}
: zeroObj;
//# sourceMappingURL=offset.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"offset.js","sourceRoot":"","sources":["../../../src/support/dom/offset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAOrD,MAAM,OAAO,GAAO;IAClB,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;CACL,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAmC,EAAM,EAAE;IAC7E,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,OAAO,IAAI;QACT,CAAC,CAAC;YACE,CAAC,EAAE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,WAAW;YACjC,CAAC,EAAE,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,WAAW;SACjC;QACH,CAAC,CAAC,OAAO,CAAC;AACd,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAmC,EAAM,EAAE,CAC3E,GAAG;IACD,CAAC,CAAC;QACE,CAAC,EAAE,GAAG,CAAC,UAAU;QACjB,CAAC,EAAE,GAAG,CAAC,SAAS;KACjB;IACH,CAAC,CAAC,OAAO,CAAC"}
+37
View File
@@ -0,0 +1,37 @@
export interface TRBL {
t: number;
r: number;
b: number;
l: number;
}
declare type StyleObject<CustomCssProps = ''> = {
[Key in keyof CSSStyleDeclaration | (CustomCssProps extends string ? CustomCssProps : '')]?: string | number;
};
/**
* Gets or sets the passed styles to the passed element.
* @param elm The element to which the styles shall be applied to / be read from.
* @param styles The styles which shall be set or read.
*/
export declare function style<CustomCssProps>(elm: HTMLElement | false | null | undefined, styles: StyleObject<CustomCssProps>): void;
export declare function style<CustomCssProps>(elm: HTMLElement | false | null | undefined, styles: string): string;
export declare function style<CustomCssProps>(elm: HTMLElement | false | null | undefined, styles: Array<string> | string): {
[key: string]: string;
};
/**
* Hides the passed element (display: none).
* @param elm The element which shall be hidden.
*/
export declare const hide: (elm: HTMLElement | false | null | undefined) => void;
/**
* Shows the passed element (display: block).
* @param elm The element which shall be shown.
*/
export declare const show: (elm: HTMLElement | false | null | undefined) => void;
/**
* Returns the top right bottom left values of the passed css property.
* @param elm The element of which the values shall be returned.
* @param propertyPrefix The css property prefix. (e.g. "border")
* @param propertySuffix The css property suffix. (e.g. "width")
*/
export declare const topRightBottomLeft: (elm?: HTMLElement | false | null | undefined, propertyPrefix?: string, propertySuffix?: string) => TRBL;
export {};
+96
View File
@@ -0,0 +1,96 @@
import { each, keys } from '../utils';
import { isString, isNumber, isArray, isUndefined } from '../utils/types';
const cssNumber = {
// animationiterationcount: 1,
// columncount: 1,
// fillopacity: 1,
// flexgrow: 1,
// flexshrink: 1,
// fontweight: 1,
// lineheight: 1,
// order: 1,
// orphans: 1,
// widows: 1,
// zoom: 1,
opacity: 1,
zindex: 1,
};
const parseToZeroOrNumber = (value, toFloat) => {
/* istanbul ignore next */
const num = toFloat ? parseFloat(value) : parseInt(value, 10);
// num === num means num is not NaN
/* istanbul ignore next */
return num === num ? num : 0; // eslint-disable-line no-self-compare
};
const adaptCSSVal = (prop, val) => !cssNumber[prop.toLowerCase()] && isNumber(val) ? `${val}px` : val;
const getCSSVal = (elm, computedStyle, prop) =>
/* istanbul ignore next */
computedStyle != null
? computedStyle[prop] || computedStyle.getPropertyValue(prop)
: elm.style[prop];
const setCSSVal = (elm, prop, val) => {
try {
const { style: elmStyle } = elm;
if (!isUndefined(elmStyle[prop])) {
elmStyle[prop] = adaptCSSVal(prop, val);
}
else {
elmStyle.setProperty(prop, val);
}
}
catch (e) { }
};
export function style(elm, styles) {
const getSingleStyle = isString(styles);
const getStyles = isArray(styles) || getSingleStyle;
if (getStyles) {
let getStylesResult = getSingleStyle ? '' : {};
if (elm) {
const computedStyle = window.getComputedStyle(elm, null);
getStylesResult = getSingleStyle
? getCSSVal(elm, computedStyle, styles)
: styles.reduce((result, key) => {
result[key] = getCSSVal(elm, computedStyle, key);
return result;
}, getStylesResult);
}
return getStylesResult;
}
elm && each(keys(styles), (key) => setCSSVal(elm, key, styles[key]));
}
/**
* Hides the passed element (display: none).
* @param elm The element which shall be hidden.
*/
export const hide = (elm) => {
style(elm, { display: 'none' });
};
/**
* Shows the passed element (display: block).
* @param elm The element which shall be shown.
*/
export const show = (elm) => {
style(elm, { display: 'block' });
};
/**
* Returns the top right bottom left values of the passed css property.
* @param elm The element of which the values shall be returned.
* @param propertyPrefix The css property prefix. (e.g. "border")
* @param propertySuffix The css property suffix. (e.g. "width")
*/
export const topRightBottomLeft = (elm, propertyPrefix, propertySuffix) => {
const finalPrefix = propertyPrefix ? `${propertyPrefix}-` : '';
const finalSuffix = propertySuffix ? `-${propertySuffix}` : '';
const top = `${finalPrefix}top${finalSuffix}`;
const right = `${finalPrefix}right${finalSuffix}`;
const bottom = `${finalPrefix}bottom${finalSuffix}`;
const left = `${finalPrefix}left${finalSuffix}`;
const result = style(elm, [top, right, bottom, left]);
return {
t: parseToZeroOrNumber(result[top]),
r: parseToZeroOrNumber(result[right]),
b: parseToZeroOrNumber(result[bottom]),
l: parseToZeroOrNumber(result[left]),
};
};
//# sourceMappingURL=style.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"style.js","sourceRoot":"","sources":["../../../src/support/dom/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAe1E,MAAM,SAAS,GAAG;IAChB,8BAA8B;IAC9B,kBAAkB;IAClB,kBAAkB;IAClB,eAAe;IACf,iBAAiB;IACjB,iBAAiB;IACjB,iBAAiB;IACjB,YAAY;IACZ,c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AGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAA2C,EAAQ,EAAE;IACxE,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,GAA4C,EAC5C,cAAuB,EACvB,cAAuB,EACjB,EAAE;IACR,MAAM,WAAW,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/D,MAAM,WAAW,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/D,MAAM,GAAG,GAAG,GAAG,WAAW,MAAM,WAAW,EAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,GAAG,WAAW,QAAQ,WAAW,EAAE,CAAC;IAClD,MAAM,MAAM,GAAG,GAAG,WAAW,SAAS,WAAW,EAAE,CAAC;IACpD,MAAM,IAAI,GAAG,GAAG,WAAW,OAAO,WAAW,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IACtD,OAAO;QACL,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KACrC,CAAC;AACJ,CAAC,CAAC"}
+45
View File
@@ -0,0 +1,45 @@
declare type InputElementType = Node | Element | Node | false | null | undefined;
declare type OutputElementType = Node | Element | null;
/**
* Find all elements with the passed selector, outgoing (and including) the passed element or the document if no element was provided.
* @param selector The selector which has to be searched by.
* @param elm The element from which the search shall be outgoing.
*/
declare const find: (selector: string, elm?: InputElementType) => Element[];
/**
* Find the first element with the passed selector, outgoing (and including) the passed element or the document if no element was provided.
* @param selector The selector which has to be searched by.
* @param elm The element from which the search shall be outgoing.
*/
declare const findFirst: (selector: string, elm?: InputElementType) => OutputElementType;
/**
* Determines whether the passed element is matching with the passed selector.
* @param elm The element which has to be compared with the passed selector.
* @param selector The selector which has to be compared with the passed element. Additional selectors: ':visible' and ':hidden'.
*/
declare const is: (elm: InputElementType, selector: string) => boolean;
/**
* Returns the children (no text-nodes or comments) of the passed element which are matching the passed selector. An empty array is returned if the passed element is null.
* @param elm The element of which the children shall be returned.
* @param selector The selector which must match with the children elements.
*/
declare const children: (elm: InputElementType, selector?: string) => ReadonlyArray<Element>;
/**
* Returns the childNodes (incl. text-nodes or comments etc.) of the passed element. An empty array is returned if the passed element is null.
* @param elm The element of which the childNodes shall be returned.
*/
declare const contents: (elm: InputElementType) => ReadonlyArray<ChildNode>;
/**
* Returns the parent element of the passed element, or null if the passed element is null.
* @param elm The element of which the parent element shall be returned.
*/
declare const parent: (elm: InputElementType) => OutputElementType;
declare const closest: (elm: InputElementType, selector: string) => OutputElementType;
/**
* Determines whether the given element lies between two selectors in the DOM.
* @param elm The element.
* @param highBoundarySelector The high boundary selector.
* @param deepBoundarySelector The deep boundary selector.
*/
declare const liesBetween: (elm: InputElementType, highBoundarySelector: string, deepBoundarySelector: string) => boolean;
export { find, findFirst, is, children, contents, parent, liesBetween, closest };
+93
View File
@@ -0,0 +1,93 @@
import { isElement } from '../utils/types';
import { push, from } from '../utils/array';
const elmPrototype = Element.prototype;
/**
* Find all elements with the passed selector, outgoing (and including) the passed element or the document if no element was provided.
* @param selector The selector which has to be searched by.
* @param elm The element from which the search shall be outgoing.
*/
const find = (selector, elm) => {
const arr = [];
const rootElm = elm ? (isElement(elm) ? elm : null) : document;
return rootElm ? push(arr, rootElm.querySelectorAll(selector)) : arr;
};
/**
* Find the first element with the passed selector, outgoing (and including) the passed element or the document if no element was provided.
* @param selector The selector which has to be searched by.
* @param elm The element from which the search shall be outgoing.
*/
const findFirst = (selector, elm) => {
const rootElm = elm ? (isElement(elm) ? elm : null) : document;
return rootElm ? rootElm.querySelector(selector) : null;
};
/**
* Determines whether the passed element is matching with the passed selector.
* @param elm The element which has to be compared with the passed selector.
* @param selector The selector which has to be compared with the passed element. Additional selectors: ':visible' and ':hidden'.
*/
const is = (elm, selector) => {
if (isElement(elm)) {
/* istanbul ignore next */
// eslint-disable-next-line
// @ts-ignore
const fn = elmPrototype.matches || elmPrototype.msMatchesSelector;
return fn.call(elm, selector);
}
return false;
};
/**
* Returns the children (no text-nodes or comments) of the passed element which are matching the passed selector. An empty array is returned if the passed element is null.
* @param elm The element of which the children shall be returned.
* @param selector The selector which must match with the children elements.
*/
const children = (elm, selector) => {
const childs = [];
return isElement(elm)
? push(childs, from(elm.children).filter((child) => (selector ? is(child, selector) : child)))
: childs;
};
/**
* Returns the childNodes (incl. text-nodes or comments etc.) of the passed element. An empty array is returned if the passed element is null.
* @param elm The element of which the childNodes shall be returned.
*/
const contents = (elm) => elm ? from(elm.childNodes) : [];
/**
* Returns the parent element of the passed element, or null if the passed element is null.
* @param elm The element of which the parent element shall be returned.
*/
const parent = (elm) => (elm ? elm.parentElement : null);
const closest = (elm, selector) => {
if (isElement(elm)) {
const closestFn = elmPrototype.closest;
if (closestFn) {
return closestFn.call(elm, selector);
}
do {
if (is(elm, selector)) {
return elm;
}
elm = parent(elm);
} while (elm);
}
return null;
};
/**
* Determines whether the given element lies between two selectors in the DOM.
* @param elm The element.
* @param highBoundarySelector The high boundary selector.
* @param deepBoundarySelector The deep boundary selector.
*/
const liesBetween = (elm, highBoundarySelector, deepBoundarySelector) => {
const closestHighBoundaryElm = elm && closest(elm, highBoundarySelector);
const closestDeepBoundaryElm = elm && findFirst(deepBoundarySelector, closestHighBoundaryElm);
const deepBoundaryIsValid = closest(closestDeepBoundaryElm, highBoundarySelector) === closestHighBoundaryElm;
return closestHighBoundaryElm && closestDeepBoundaryElm
? closestHighBoundaryElm === elm ||
closestDeepBoundaryElm === elm ||
(deepBoundaryIsValid &&
closest(closest(elm, deepBoundarySelector), highBoundarySelector) !==
closestHighBoundaryElm)
: false;
};
export { find, findFirst, is, children, contents, parent, liesBetween, closest };
//# sourceMappingURL=traversal.js.map
@@ -0,0 +1 @@
{"version":3,"file":"traversal.js","sourceRoot":"","sources":["../../../src/support/dom/traversal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAK5C,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC;AAEvC;;;;GAIG;AACH,MAAM,IAAI,GAAG,CAAC,QAAgB,EAAE,GAAsB,EAAa,EAAE;IACnE,MAAM,GAAG,GAAmB,EAAE,CAAC;IAC/B,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAE/D,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACvE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAE,GAAsB,EAAqB,EAAE;IAChF,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAE/D,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,Q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