improve code and readme

This commit is contained in:
Rene
2022-08-08 10:23:51 +02:00
parent b001f5ac61
commit 1a204fb064
4 changed files with 102 additions and 31 deletions
+16 -17
View File
@@ -23,7 +23,7 @@ export type ScrollbarAutoHideBehavior = 'never' | 'scroll' | 'leave' | 'move';
export interface Options {
paddingAbsolute: boolean;
showNativeOverlaidScrollbars: boolean;
updating: {
update: {
elementEvents: Array<[elementSelector: string, eventNames: string]> | null;
attributes: string[] | null;
debounce: [timeout: number, maxWait: number] | number | null; // (if tuple: [timeout: 0, maxWait: 33], if number: [timeout: number, maxWait: false]) debounce for content Changes
@@ -47,27 +47,26 @@ export interface Options {
export type ReadonlyOptions = DeepReadonly<Options>;
export const defaultOptions: Options = {
// resize: 'none', // none || both || horizontal || vertical || n || b || h || v
paddingAbsolute: false, // true || false
showNativeOverlaidScrollbars: false, // true || false
updating: {
elementEvents: [['img', 'load']], // array of tuples || null
debounce: [0, 33], // number || number array || null
attributes: null, // string array || null
ignoreMutation: null, // () => any || null
paddingAbsolute: false,
showNativeOverlaidScrollbars: false,
update: {
elementEvents: [['img', 'load']],
debounce: [0, 33],
attributes: null,
ignoreMutation: null,
},
overflow: {
x: 'scroll', // visible-hidden || visible-scroll || hidden || scroll || v-h || v-s || h || s
y: 'scroll', // visible-hidden || visible-scroll || hidden || scroll || v-h || v-s || h || s
x: 'scroll',
y: 'scroll',
},
scrollbars: {
theme: 'os-theme-dark',
visibility: 'auto', // visible || hidden || auto || v || h || a
autoHide: 'never', // never || scroll || leave || move || n || s || l || m
autoHideDelay: 1300, // number
dragScroll: true, // true || false
clickScroll: false, // true || false
pointers: ['mouse', 'touch', 'pen'], // null || array of supported pointers: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType
visibility: 'auto',
autoHide: 'never',
autoHideDelay: 1300,
dragScroll: true,
clickScroll: false,
pointers: ['mouse', 'touch', 'pen'],
},
};
@@ -27,7 +27,7 @@ const optionsTemplate: OptionsTemplate<Options> = {
// resize: resizeAllowedValues, // none || both || horizontal || vertical || n || b ||
paddingAbsolute: booleanAllowedValues, // true || false
showNativeOverlaidScrollbars: booleanAllowedValues, // true || false
updating: {
update: {
elementEvents: arrayNullValues, // array of tuples || null
attributes: arrayNullValues,
debounce: [oTypes.number, oTypes.array, oTypes.null], // number || number array || null
@@ -296,13 +296,13 @@ export const createStructureSetupObservers = (
return updateHints;
},
(checkOption) => {
const [ignoreMutation] = checkOption<string[] | null>('updating.ignoreMutation');
const [attributes, attributesChanged] = checkOption<string[] | null>('updating.attributes');
const [ignoreMutation] = checkOption<string[] | null>('update.ignoreMutation');
const [attributes, attributesChanged] = checkOption<string[] | null>('update.attributes');
const [elementEvents, elementEventsChanged] = checkOption<Array<[string, string]> | null>(
'updating.elementEvents'
'update.elementEvents'
);
const [debounceValue, debounceChanged] = checkOption<Array<number> | number | null>(
'updating.debounce'
'update.debounce'
);
const updateContentMutationObserver = elementEventsChanged || attributesChanged;
const ignoreMutationFromOptions = (mutation: MutationRecord) =>
@@ -343,8 +343,8 @@ export const createStructureSetupObservers = (
if (isArray(debounceValue)) {
const timeout = debounceValue[0];
const maxWait = debounceValue[1];
debounceTimeout = isNumber(timeout) ? timeout : false;
debounceMaxDelay = isNumber(maxWait) ? maxWait : false;
debounceTimeout = isNumber(timeout) && timeout;
debounceMaxDelay = isNumber(maxWait) && maxWait;
} else if (isNumber(debounceValue)) {
debounceTimeout = debounceValue;
debounceMaxDelay = false;