From 9b2fb4c3e7e48b76feee42340b23caf6717261b8 Mon Sep 17 00:00:00 2001 From: Valexr Date: Sun, 18 Sep 2022 18:11:56 +0300 Subject: [PATCH] @sidy/core - fix default options --- packages/core/src/lib/dom.ts | 2 +- packages/core/src/slidy.ts | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/core/src/lib/dom.ts b/packages/core/src/lib/dom.ts index 81eeb76a..00eea09d 100644 --- a/packages/core/src/lib/dom.ts +++ b/packages/core/src/lib/dom.ts @@ -47,7 +47,7 @@ export function dom(node: HTMLElement, options: Options): Dom { function pos(index: number, snap?: Options['snap']): number { const indented = child(index)[size] + gap * 2 < node[size]; - const indent = indented ? (options.indent || 0) : offset(index) / 2 / gap; + const indent = indented ? (options.indent ?? 1) : offset(index) / 2 / gap; const part = snap === 'start' ? 0 : snap === 'end' ? 1 : 0.5; const edge = snap === 'start' ? -indent : snap === 'end' ? indent : 0; return child(index)[coord] - offset(index) * part + gap * edge; diff --git a/packages/core/src/slidy.ts b/packages/core/src/slidy.ts index aeabd7f2..c01f765b 100644 --- a/packages/core/src/slidy.ts +++ b/packages/core/src/slidy.ts @@ -17,13 +17,13 @@ export function slidy(node: HTMLElement, options: Partial = {}): SlidyI track = 0, clamped: number | boolean, wst: NodeJS.Timeout | undefined, - INDEX = hix = options.index ||= 0, - POSITION = options.position ||= 0, - DIRECTION = options.direction ||= 0, - DURATION = (options.duration ||= 450) / 2, - SENSITY = options.sensity ||= 2.5, - GRAVITY = options.gravity ||= 1.2, - CLAMP = options.clamp; + INDEX = hix = options.index ??= 0, + POSITION = options.position ??= 0, + DIRECTION = options.direction ??= 0, + DURATION = (options.duration ??= 450) / 2, + SENSITY = options.sensity ??= 2.5, + GRAVITY = options.gravity ??= 1.2, + CLAMP = options.clamp ??= 0; const WINDOW_EVENTS: EventMap = [ ['touchmove', onMove as EventListener, { passive: false }], @@ -44,8 +44,8 @@ export function slidy(node: HTMLElement, options: Partial = {}): SlidyI ]; const RO = new ResizeObserver((ROE) => { - to(INDEX); POSITION = options.position = $().position(); + to(INDEX); dispatch(node, 'resize', { ROE, options }); }); @@ -65,12 +65,12 @@ export function slidy(node: HTMLElement, options: Partial = {}): SlidyI const instance = { init, update, destroy, to } + init(); + loop(options.plugins || [], (plugin, i, array) => { array[i] = plugin({ node, options, instance }) }) - init(); - function init() { mount(node).then(() => {