diff --git a/README.md b/README.md index 208fc7d9..37b1297b 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ setTimeout(() => panzoom.pan(100, 100)) ▸ **Panzoom**(`elem`: HTMLElement | SVGElement, `options?`: Omit‹[PanzoomOptions](#PanzoomOptions), "force"›): _[PanzoomObject](#PanzoomObject)_ -_Defined in [panzoom.ts:49](https://github.com/timmywil/panzoom/blob/d0b9505/src/panzoom.ts#L49)_ +_Defined in [panzoom.ts:49](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L49)_ **Parameters:** @@ -161,7 +161,7 @@ Includes `MiscOptions`, `PanOptions`, and `ZoomOptions` • **animate**? : _boolean_ (Default: **false**) -_Defined in [types.ts:13](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L13)_ +_Defined in [types.ts:13](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L13)_ Whether to animate transitions @@ -171,7 +171,7 @@ Whether to animate transitions • **duration**? : _number_ (Default: **200**) -_Defined in [types.ts:15](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L15)_ +_Defined in [types.ts:15](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L15)_ Duration of the transition (ms) @@ -181,7 +181,7 @@ Duration of the transition (ms) • **easing**? : _string_ (Default: **"ease-in-out"**) -_Defined in [types.ts:17](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L17)_ +_Defined in [types.ts:17](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L17)_ CSS Easing used for transitions @@ -191,7 +191,7 @@ CSS Easing used for transitions • **exclude**? : _Element[]_ -_Defined in [types.ts:24](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L24)_ +_Defined in [types.ts:24](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L24)_ Add elements to this array that should be excluded from Panzoom handling. @@ -204,7 +204,7 @@ e.g. links and buttons that should not propagate the click event. • **excludeClass**? : _string_ (Default: **"panzoom-exclude"**) -_Defined in [types.ts:31](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L31)_ +_Defined in [types.ts:31](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L31)_ Add this class to any element within the Panzoom element that you want to exclude from Panzoom handling. That @@ -217,7 +217,7 @@ e.g. links and buttons that should not propagate the click event. • **force**? : _boolean_ -_Defined in [types.ts:47](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L47)_ +_Defined in [types.ts:47](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L47)_ `force` should be used sparingly to temporarily override and ignore options such as disablePan, @@ -239,7 +239,7 @@ panzoom.zoom(1, { force: true }) • **handleStartEvent**? : _function_ -_Defined in [types.ts:71](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L71)_ +_Defined in [types.ts:71](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L71)_ On the first pointer event, when panning starts, the default Panzoom behavior is to call @@ -279,7 +279,7 @@ Panzoom(elem, { • **origin**? : _string_ -_Defined in [types.ts:85](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L85)_ +_Defined in [types.ts:85](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L85)_ **Change this at your own risk.** The `transform-origin` is the origin from which transforms are applied. @@ -299,7 +299,7 @@ And again, changing this for SVG in IE doesn't work at all. • **overflow**? : _string_ (Default: **"hidden"**) -_Defined in [types.ts:87](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L87)_ +_Defined in [types.ts:87](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L87)_ The overflow CSS value for the parent. Defaults to 'hidden' @@ -309,7 +309,7 @@ The overflow CSS value for the parent. Defaults to 'hidden' • **setTransform**? : _setTransform_ -_Defined in [types.ts:105](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L105)_ +_Defined in [types.ts:105](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L105)_ Override the transform setter. This is exposed mostly so the user could @@ -333,7 +333,7 @@ const panzoom = Panzoom(elem, { • **silent**? : _boolean_ -_Defined in [types.ts:107](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L107)_ +_Defined in [types.ts:107](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L107)_ Silence all events @@ -343,7 +343,7 @@ Silence all events • **startScale**? : _number_ (Default: **1**) -_Defined in [types.ts:113](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L113)_ +_Defined in [types.ts:113](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L113)_ Scale used to set the beginning transform @@ -353,7 +353,7 @@ Scale used to set the beginning transform • **startX**? : _number_ (Default: **0**) -_Defined in [types.ts:109](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L109)_ +_Defined in [types.ts:109](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L109)_ X Value used to set the beginning transform @@ -363,7 +363,7 @@ X Value used to set the beginning transform • **startY**? : _number_ (Default: **0**) -_Defined in [types.ts:111](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L111)_ +_Defined in [types.ts:111](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L111)_ Y Value used to set the beginning transform @@ -377,7 +377,7 @@ Includes `MiscOptions` • **contain**? : _"inside" | "outside"_ -_Defined in [types.ts:130](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L130)_ +_Defined in [types.ts:130](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L130)_ Contain the panzoom element either inside or outside the parent. @@ -395,7 +395,7 @@ empty space around the element will be shown. • **cursor**? : _string_ (Default: **"move"**) -_Defined in [types.ts:132](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L132)_ +_Defined in [types.ts:132](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L132)_ The cursor style to set on the panzoom element @@ -405,7 +405,7 @@ The cursor style to set on the panzoom element • **disablePan**? : _boolean_ (Default: **false**) -_Defined in [types.ts:138](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L138)_ +_Defined in [types.ts:138](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L138)_ Disable panning functionality. Note: disablePan does not affect focal point zooming or the constrain option. @@ -417,7 +417,7 @@ The element will still pan accordingly. • **disableXAxis**? : _boolean_ (Default: **false**) -_Defined in [types.ts:140](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L140)_ +_Defined in [types.ts:140](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L140)_ Pan only on the Y axis @@ -427,7 +427,7 @@ Pan only on the Y axis • **disableYAxis**? : _boolean_ (Default: **false**) -_Defined in [types.ts:142](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L142)_ +_Defined in [types.ts:142](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L142)_ Pan only on the X axis @@ -437,7 +437,7 @@ Pan only on the X axis • **panOnlyWhenZoomed**? : _boolean_ (Default: **false**) -_Defined in [types.ts:146](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L146)_ +_Defined in [types.ts:146](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L146)_ Disable panning while the scale is equal to the starting value @@ -447,7 +447,7 @@ Disable panning while the scale is equal to the starting value • **relative**? : _boolean_ (Default: **false**) -_Defined in [types.ts:144](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L144)_ +_Defined in [types.ts:144](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L144)_ When passing x and y values to .pan(), treat the values as relative to their current values @@ -461,7 +461,7 @@ Includes `MiscOptions` • **disableZoom**? : _boolean_ (Default: **false**) -_Defined in [types.ts:151](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L151)_ +_Defined in [types.ts:151](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L151)_ Disable zooming functionality @@ -471,7 +471,7 @@ Disable zooming functionality • **focal**? : _object_ -_Defined in [types.ts:158](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L158)_ +_Defined in [types.ts:158](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L158)_ Zoom to the given point on the panzoom element. This point is expected to be relative to @@ -490,7 +490,7 @@ to the parent dimensions. • **maxScale**? : _number_ (Default: **4**) -_Defined in [types.ts:162](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L162)_ +_Defined in [types.ts:162](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L162)_ The maximum scale when zooming @@ -500,7 +500,7 @@ The maximum scale when zooming • **minScale**? : _number_ (Default: **0.125**) -_Defined in [types.ts:160](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L160)_ +_Defined in [types.ts:160](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L160)_ The minimum scale when zooming @@ -510,7 +510,7 @@ The minimum scale when zooming • **step**? : _number_ (Default: **0.3**) -_Defined in [types.ts:164](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L164)_ +_Defined in [types.ts:164](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L164)_ The step affects zoom calculation when zooming with a mouse wheel, when pinch zooming, or when using zoomIn/zoomOut @@ -524,7 +524,7 @@ These methods are available after initializing Panzoom • **destroy**: _function_ -_Defined in [types.ts:179](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L179)_ +_Defined in [types.ts:179](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L179)_ Remove all event listeners bind to the the Panzoom element @@ -538,7 +538,7 @@ Remove all event listeners bind to the the Panzoom element • **getOptions**: _function_ -_Defined in [types.ts:185](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L185)_ +_Defined in [types.ts:185](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L185)_ Returns a _copy_ of the current options object @@ -552,7 +552,7 @@ Returns a _copy_ of the current options object • **getPan**: _function_ -_Defined in [types.ts:181](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L181)_ +_Defined in [types.ts:181](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L181)_ Get the current x/y translation @@ -570,7 +570,7 @@ Get the current x/y translation • **getScale**: _function_ -_Defined in [types.ts:183](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L183)_ +_Defined in [types.ts:183](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L183)_ Get the current scale @@ -584,7 +584,7 @@ Get the current scale • **pan**: _function_ -_Defined in [types.ts:196](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L196)_ +_Defined in [types.ts:196](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L196)_ Pan the Panzoom element to the given x and y coordinates @@ -613,7 +613,7 @@ panzoom.pan(10, 10, { relative: true }) • **reset**: _function_ -_Defined in [types.ts:207](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L207)_ +_Defined in [types.ts:207](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L207)_ Reset the pan and zoom to startX, startY, and startScale. Animates by default, ignoring the global option. @@ -640,7 +640,7 @@ panzoom.reset({ animate: false }) • **setOptions**: _function_ -_Defined in [types.ts:209](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L209)_ +_Defined in [types.ts:209](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L209)_ Change options for the Panzoom instance @@ -660,7 +660,7 @@ Change options for the Panzoom instance • **setStyle**: _function_ -_Defined in [types.ts:211](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L211)_ +_Defined in [types.ts:211](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L211)_ A convenience method for setting prefixed styles on the Panzoom element @@ -681,7 +681,7 @@ A convenience method for setting prefixed styles on the Panzoom element • **zoom**: _function_ -_Defined in [types.ts:220](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L220)_ +_Defined in [types.ts:220](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L220)_ Zoom the Panzoom element to the given scale @@ -707,7 +707,7 @@ panzoom.zoom(2.2, { animate: true }) • **zoomIn**: _function_ -_Defined in [types.ts:231](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L231)_ +_Defined in [types.ts:231](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L231)_ Zoom in using the predetermined increment set in options. Animates by default, ignoring the global option. @@ -734,7 +734,7 @@ panzoom.zoomIn({ animate: false }) • **zoomOut**: _function_ -_Defined in [types.ts:242](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L242)_ +_Defined in [types.ts:242](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L242)_ Zoom out using the predetermined increment set in options. Animates by default, ignoring the global option. @@ -761,7 +761,7 @@ panzoom.zoomOut({ animate: false }) • **zoomToPoint**: _function_ -_Defined in [types.ts:253](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L253)_ +_Defined in [types.ts:253](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L253)_ Zoom the Panzoom element to a focal point using the given pointer/touch/mouse event or constructed point. @@ -795,7 +795,7 @@ panzoom.zoomToPoint(1.2, pointerEvent) • **zoomWithWheel**: _function_ -_Defined in [types.ts:282](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L282)_ +_Defined in [types.ts:282](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L282)_ Zoom the Panzoom element to a focal point using the given WheelEvent @@ -839,7 +839,7 @@ elem.parentElement.addEventListener('wheel', function(event) { • **scale**: _number_ -_Defined in [types.ts:174](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L174)_ +_Defined in [types.ts:174](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L174)_ --- @@ -847,7 +847,7 @@ _Defined in [types.ts:174](https://github.com/timmywil/panzoom/blob/d0b9505/src/ • **x**: _number_ -_Defined in [types.ts:172](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L172)_ +_Defined in [types.ts:172](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L172)_ --- @@ -855,7 +855,7 @@ _Defined in [types.ts:172](https://github.com/timmywil/panzoom/blob/d0b9505/src/ • **y**: _number_ -_Defined in [types.ts:173](https://github.com/timmywil/panzoom/blob/d0b9505/src/types.ts#L173)_ +_Defined in [types.ts:173](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L173)_ ## Events diff --git a/dist/demo/Code.d.ts b/dist/demo/Code.d.ts new file mode 100644 index 00000000..eea2bf30 --- /dev/null +++ b/dist/demo/Code.d.ts @@ -0,0 +1,8 @@ +/// +import 'prismjs/themes/prism-tomorrow.css'; +interface Props { + language?: string; + children: string; +} +export default function Code({ children, language }: Props): JSX.Element; +export {}; diff --git a/dist/demo/Demo.d.ts b/dist/demo/Demo.d.ts new file mode 100644 index 00000000..0be06018 --- /dev/null +++ b/dist/demo/Demo.d.ts @@ -0,0 +1,8 @@ +import React from 'react'; +interface Props { + title: string; + code: React.ReactNode; + children: React.ReactNode; +} +export default function Demo({ title, code, children }: Props): JSX.Element; +export {}; diff --git a/dist/demo/examples/ContainInside.d.ts b/dist/demo/examples/ContainInside.d.ts new file mode 100644 index 00000000..c2df5d65 --- /dev/null +++ b/dist/demo/examples/ContainInside.d.ts @@ -0,0 +1,2 @@ +/// +export default function ContainInside(): JSX.Element; diff --git a/dist/demo/examples/ContainOutside.d.ts b/dist/demo/examples/ContainOutside.d.ts new file mode 100644 index 00000000..134ff4e8 --- /dev/null +++ b/dist/demo/examples/ContainOutside.d.ts @@ -0,0 +1,2 @@ +/// +export default function ContainOutside(): JSX.Element; diff --git a/dist/demo/examples/DisabledYAxis.d.ts b/dist/demo/examples/DisabledYAxis.d.ts new file mode 100644 index 00000000..c2df5d65 --- /dev/null +++ b/dist/demo/examples/DisabledYAxis.d.ts @@ -0,0 +1,2 @@ +/// +export default function ContainInside(): JSX.Element; diff --git a/dist/demo/examples/Exclude.d.ts b/dist/demo/examples/Exclude.d.ts new file mode 100644 index 00000000..db570b76 --- /dev/null +++ b/dist/demo/examples/Exclude.d.ts @@ -0,0 +1,2 @@ +/// +export default function Exclude(): JSX.Element; diff --git a/dist/demo/examples/Focal.d.ts b/dist/demo/examples/Focal.d.ts new file mode 100644 index 00000000..f267e4dc --- /dev/null +++ b/dist/demo/examples/Focal.d.ts @@ -0,0 +1,2 @@ +/// +export default function Focal(): JSX.Element; diff --git a/dist/demo/examples/SVG.d.ts b/dist/demo/examples/SVG.d.ts new file mode 100644 index 00000000..45587b1d --- /dev/null +++ b/dist/demo/examples/SVG.d.ts @@ -0,0 +1,2 @@ +/// +export default function SVG(): JSX.Element; diff --git a/dist/demo/examples/Standard.d.ts b/dist/demo/examples/Standard.d.ts new file mode 100644 index 00000000..d264f89e --- /dev/null +++ b/dist/demo/examples/Standard.d.ts @@ -0,0 +1,2 @@ +/// +export default function Buttons(): JSX.Element; diff --git a/dist/demo/global-panzoom.d.ts b/dist/demo/global-panzoom.d.ts new file mode 100644 index 00000000..cf448d39 --- /dev/null +++ b/dist/demo/global-panzoom.d.ts @@ -0,0 +1,6 @@ +import Panzoom from '../src/panzoom'; +declare global { + interface Window { + Panzoom: typeof Panzoom; + } +} diff --git a/dist/demo/index.d.ts b/dist/demo/index.d.ts new file mode 100644 index 00000000..1b443e33 --- /dev/null +++ b/dist/demo/index.d.ts @@ -0,0 +1,2 @@ +import './demo.css'; +import './global-panzoom'; diff --git a/dist/panzoom.js b/dist/panzoom.js new file mode 100644 index 00000000..532e8b52 --- /dev/null +++ b/dist/panzoom.js @@ -0,0 +1,691 @@ +/** + * Panzoom for panning and zooming elements using CSS transforms + * Copyright Timmy Willison and other contributors + * https://github.com/timmywil/panzoom/blob/master/MIT-License.txt + */ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.Panzoom = factory()); +}(this, (function () { 'use strict'; + + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. All rights reserved. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of the + License at http://www.apache.org/licenses/LICENSE-2.0 + + THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + MERCHANTABLITY OR NON-INFRINGEMENT. + + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** */ + + var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); + }; + + /* eslint-disable no-var */ + // Support: IE11 only + if (window.NodeList && !NodeList.prototype.forEach) { + NodeList.prototype.forEach = Array.prototype.forEach; + } + // Support: IE11 only + // CustomEvent is an object instead of a constructor + if (typeof window.CustomEvent !== 'function') { + window.CustomEvent = function CustomEvent(event, params) { + params = params || { bubbles: false, cancelable: false, detail: null }; + var evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + return evt + }; + } + + /** + * Utilites for working with multiple pointer events + */ + function findEventIndex(pointers, event) { + var i = pointers.length; + while (i--) { + if (pointers[i].pointerId === event.pointerId) { + return i; + } + } + return -1; + } + function addPointer(pointers, event) { + var i; + // Add touches if applicable + if (event.touches) { + i = 0; + for (var _i = 0, _a = event.touches; _i < _a.length; _i++) { + var touch = _a[_i]; + touch.pointerId = i++; + addPointer(pointers, touch); + } + return; + } + i = findEventIndex(pointers, event); + // Update if already present + if (i > -1) { + pointers.splice(i, 1); + } + pointers.push(event); + } + function removePointer(pointers, event) { + // Add touches if applicable + if (event.touches) { + // Remove all touches + while (pointers.length) { + pointers.pop(); + } + return; + } + var i = findEventIndex(pointers, event); + if (i > -1) { + pointers.splice(i, 1); + } + } + /** + * Calculates a center point between + * the given pointer events, for panning + * with multiple pointers. + */ + function getMiddle(pointers) { + // Copy to avoid changing by reference + pointers = pointers.slice(0); + var event1 = pointers.pop(); + var event2; + while ((event2 = pointers.pop())) { + event1 = { + clientX: (event2.clientX - event1.clientX) / 2 + event1.clientX, + clientY: (event2.clientY - event1.clientY) / 2 + event1.clientY + }; + } + return event1; + } + /** + * Calculates the distance between two points + * for pinch zooming. + * Limits to the first 2 + */ + function getDistance(pointers) { + if (pointers.length < 2) { + return 0; + } + var event1 = pointers[0]; + var event2 = pointers[1]; + return Math.sqrt(Math.pow(Math.abs(event2.clientX - event1.clientX), 2) + + Math.pow(Math.abs(event2.clientY - event1.clientY), 2)); + } + + var events; + if (typeof window.PointerEvent === 'function') { + events = { + down: 'pointerdown', + move: 'pointermove', + up: 'pointerup pointerleave pointercancel' + }; + } + else if (typeof window.TouchEvent === 'function') { + events = { + down: 'touchstart', + move: 'touchmove', + up: 'touchend touchcancel' + }; + } + else { + events = { + down: 'mousedown', + move: 'mousemove', + up: 'mouseup mouseleave' + }; + } + function onPointer(event, elem, handler, eventOpts) { + events[event].split(' ').forEach(function (name) { + elem.addEventListener(name, handler, eventOpts); + }); + } + function destroyPointer(event, elem, handler) { + events[event].split(' ').forEach(function (name) { + elem.removeEventListener(name, handler); + }); + } + + /** + * Proper prefixing for cross-browser compatibility + */ + var divStyle = document.createElement('div').style; + var prefixes = ['webkit', 'moz', 'ms']; + var prefixCache = {}; + function getPrefixedName(name) { + if (prefixCache[name]) { + return prefixCache[name]; + } + if (name in divStyle) { + return (prefixCache[name] = name); + } + var capName = name[0].toUpperCase() + name.slice(1); + var i = prefixes.length; + while (i--) { + var prefixedName = "" + prefixes[i] + capName; + if (prefixedName in divStyle) { + return (prefixCache[name] = prefixedName); + } + } + } + /** + * Gets a style value expected to be a number + */ + function getCSSNum(name, style) { + return parseFloat(style[getPrefixedName(name)]) || 0; + } + function getBoxStyle(elem, name, style) { + if (style === void 0) { style = window.getComputedStyle(elem); } + // Support: FF 68+ + // Firefox requires specificity for border + var suffix = name === 'border' ? 'Width' : ''; + return { + left: getCSSNum(name + "Left" + suffix, style), + right: getCSSNum(name + "Right" + suffix, style), + top: getCSSNum(name + "Top" + suffix, style), + bottom: getCSSNum(name + "Bottom" + suffix, style) + }; + } + /** + * Set a style using the properly prefixed name + */ + function setStyle(elem, name, value) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + elem.style[getPrefixedName(name)] = value; + } + /** + * Constructs the transition from panzoom options + * and takes care of prefixing the transition and transform + */ + function setTransition(elem, options) { + var transition = getPrefixedName('transition'); + var transform = getPrefixedName('transform'); + setStyle(elem, transition, transform + " " + options.duration + "ms " + options.easing); + } + /** + * Set the transform using the proper prefix + */ + function setTransform(elem, _a, options) { + var x = _a.x, y = _a.y, scale = _a.scale; + if (options === void 0) { options = {}; } + if (typeof options.animate === 'boolean') { + if (options.animate) { + setTransition(elem, options); + } + else { + setStyle(elem, 'transition', 'none'); + } + } + requestAnimationFrame(function () { + setStyle(elem, 'transform', "scale(" + scale + ") translate(" + x + "px, " + y + "px)"); + }); + } + /** + * Dimensions used in containment and focal point zooming + */ + function getDimensions(elem) { + var parent = elem.parentElement; + var style = window.getComputedStyle(elem); + var parentStyle = window.getComputedStyle(parent); + var rectElem = elem.getBoundingClientRect(); + var rectParent = parent.getBoundingClientRect(); + return { + elem: { + style: style, + width: rectElem.width, + height: rectElem.height, + top: rectElem.top, + bottom: rectElem.bottom, + left: rectElem.left, + right: rectElem.right, + margin: getBoxStyle(elem, 'margin', style), + border: getBoxStyle(elem, 'border', style) + }, + parent: { + style: parentStyle, + width: rectParent.width, + height: rectParent.height, + top: rectParent.top, + bottom: rectParent.bottom, + left: rectParent.left, + right: rectParent.right, + padding: getBoxStyle(parent, 'padding', parentStyle), + border: getBoxStyle(parent, 'border', parentStyle) + } + }; + } + + /** + * Determine if an element is attached to the DOM + * Panzoom requires this so events work properly + */ + function isAttached(elem) { + var doc = elem.ownerDocument; + var parent = elem.parentElement; + return doc && parent && doc.nodeType === 9 && parent.nodeType === 1 && doc.contains(parent); + } + + function isExcluded(elem, options) { + for (var cur = elem; cur != null; cur = cur.parentElement) { + if (cur.classList.contains(options.excludeClass) || options.exclude.indexOf(cur) > -1) { + return true; + } + } + return false; + } + + /** + * Determine if an element is SVG by checking the namespace + * Exception: the element itself should be treated like HTML + */ + var rsvg = /^http:[\w\.\/]+svg$/; + function isSVGElement(elem) { + return rsvg.test(elem.namespaceURI) && elem.nodeName.toLowerCase() !== 'svg'; + } + + function shallowClone(obj) { + var clone = {}; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + clone[key] = obj[key]; + } + } + return clone; + } + + var defaultOptions = { + animate: false, + cursor: 'move', + disablePan: false, + disableZoom: false, + disableXAxis: false, + disableYAxis: false, + duration: 200, + easing: 'ease-in-out', + exclude: [], + excludeClass: 'panzoom-exclude', + handleStartEvent: function (e) { + e.preventDefault(); + e.stopPropagation(); + }, + maxScale: 4, + minScale: 0.125, + overflow: 'hidden', + panOnlyWhenZoomed: false, + relative: false, + setTransform: setTransform, + startX: 0, + startY: 0, + startScale: 1, + step: 0.3 + }; + function Panzoom(elem, options) { + if (!elem) { + throw new Error('Panzoom requires an element as an argument'); + } + if (elem.nodeType !== 1) { + throw new Error('Panzoom requires an element with a nodeType of 1'); + } + if (!isAttached(elem)) { + throw new Error('Panzoom should be called on elements that have been attached to the DOM'); + } + options = __assign(__assign({}, defaultOptions), options); + var isSVG = isSVGElement(elem); + // Set overflow on the parent + var parent = elem.parentElement; + parent.style.overflow = options.overflow; + parent.style.userSelect = 'none'; + // This is important for mobile to + // prevent scrolling while panning + parent.style.touchAction = 'none'; + // Set some default styles on the panzoom element + elem.style.cursor = options.cursor; + elem.style.userSelect = 'none'; + elem.style.touchAction = 'none'; + // The default for HTML is '50% 50%' + // The default for SVG is '0 0' + // SVG can't be changed in IE + setStyle(elem, 'transformOrigin', typeof options.origin === 'string' ? options.origin : isSVG ? '0 0' : '50% 50%'); + function setOptions(opts) { + if (opts === void 0) { opts = {}; } + for (var key in opts) { + if (opts.hasOwnProperty(key)) { + options[key] = opts[key]; + } + } + // Handle option side-effects + if (opts.hasOwnProperty('cursor')) { + elem.style.cursor = opts.cursor; + } + if (opts.hasOwnProperty('overflow')) { + parent.style.overflow = opts.overflow; + } + if (opts.hasOwnProperty('minScale') || + opts.hasOwnProperty('maxScale') || + opts.hasOwnProperty('contain')) { + setMinMax(); + } + } + var x = 0; + var y = 0; + var scale = 1; + var isPanning = false; + zoom(options.startScale, { animate: false }); + // Wait for scale to update + // for accurate dimensions + // to constrain initial values + setTimeout(function () { + setMinMax(); + pan(options.startX, options.startY, { animate: false }); + }); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + function trigger(eventName, detail, opts) { + if (opts.silent) { + return; + } + var event = new CustomEvent(eventName, { detail: detail }); + elem.dispatchEvent(event); + } + function setTransformWithEvent(eventName, opts) { + var value = { x: x, y: y, scale: scale }; + opts.setTransform(elem, value, opts); + trigger(eventName, value, opts); + trigger('panzoomchange', value, opts); + return value; + } + function setMinMax() { + if (options.contain) { + var dims = getDimensions(elem); + var parentWidth = dims.parent.width - dims.parent.border.left - dims.parent.border.right; + var parentHeight = dims.parent.height - dims.parent.border.top - dims.parent.border.bottom; + var elemWidth = dims.elem.width / scale; + var elemHeight = dims.elem.height / scale; + var elemScaledWidth = parentWidth / elemWidth; + var elemScaledHeight = parentHeight / elemHeight; + if (options.contain === 'inside') { + options.maxScale = Math.min(elemScaledWidth, elemScaledHeight); + } + else if (options.contain === 'outside') { + options.minScale = Math.max(elemScaledWidth, elemScaledHeight); + } + } + } + function constrainXY(toX, toY, toScale, panOptions) { + var opts = __assign(__assign({}, options), panOptions); + var result = { x: x, y: y, opts: opts }; + if (!opts.force && (opts.disablePan || (opts.panOnlyWhenZoomed && scale === opts.startScale))) { + return result; + } + toX = parseFloat(toX); + toY = parseFloat(toY); + if (!opts.disableXAxis) { + result.x = (opts.relative ? x : 0) + toX; + } + if (!opts.disableYAxis) { + result.y = (opts.relative ? y : 0) + toY; + } + if (opts.contain === 'inside') { + var dims = getDimensions(elem); + result.x = Math.max(-dims.elem.margin.left - dims.parent.padding.left, Math.min(dims.parent.width - + dims.elem.width / toScale - + dims.parent.padding.left - + dims.elem.margin.left - + dims.parent.border.left - + dims.parent.border.right, result.x)); + result.y = Math.max(-dims.elem.margin.top - dims.parent.padding.top, Math.min(dims.parent.height - + dims.elem.height / toScale - + dims.parent.padding.top - + dims.elem.margin.top - + dims.parent.border.top - + dims.parent.border.bottom, result.y)); + } + else if (opts.contain === 'outside') { + var dims = getDimensions(elem); + var realWidth = dims.elem.width / scale; + var realHeight = dims.elem.height / scale; + var scaledWidth = realWidth * toScale; + var scaledHeight = realHeight * toScale; + var diffHorizontal = (scaledWidth - realWidth) / 2; + var diffVertical = (scaledHeight - realHeight) / 2; + var minX = (-(scaledWidth - dims.parent.width) - + dims.parent.padding.left - + dims.parent.border.left - + dims.parent.border.right + + diffHorizontal) / + toScale; + var maxX = (diffHorizontal - dims.parent.padding.left) / toScale; + result.x = Math.max(Math.min(result.x, maxX), minX); + var minY = (-(scaledHeight - dims.parent.height) - + dims.parent.padding.top - + dims.parent.border.top - + dims.parent.border.bottom + + diffVertical) / + toScale; + var maxY = (diffVertical - dims.parent.padding.top) / toScale; + result.y = Math.max(Math.min(result.y, maxY), minY); + } + return result; + } + function constrainScale(toScale, zoomOptions) { + var opts = __assign(__assign({}, options), zoomOptions); + var result = { scale: scale, opts: opts }; + if (!opts.force && opts.disableZoom) { + return result; + } + result.scale = Math.min(Math.max(toScale, opts.minScale), opts.maxScale); + return result; + } + function pan(toX, toY, panOptions) { + var result = constrainXY(toX, toY, scale, panOptions); + var opts = result.opts; + x = result.x; + y = result.y; + return setTransformWithEvent('panzoompan', opts); + } + function zoom(toScale, zoomOptions) { + var result = constrainScale(toScale, zoomOptions); + var opts = result.opts; + if (!opts.force && opts.disableZoom) { + return; + } + toScale = result.scale; + var toX = x; + var toY = y; + if (opts.focal) { + // The difference between the point after the scale and the point before the scale + // plus the current translation after the scale + // neutralized to no scale (as the transform scale will apply to the translation) + var focal = opts.focal; + toX = (focal.x / toScale - focal.x / scale + x * toScale) / toScale; + toY = (focal.y / toScale - focal.y / scale + y * toScale) / toScale; + } + var panResult = constrainXY(toX, toY, toScale, { relative: false, force: true }); + x = panResult.x; + y = panResult.y; + scale = toScale; + return setTransformWithEvent('panzoomzoom', opts); + } + function zoomInOut(isIn, zoomOptions) { + var opts = __assign(__assign(__assign({}, options), { animate: true }), zoomOptions); + return zoom(scale * Math.exp((isIn ? 1 : -1) * opts.step), opts); + } + function zoomIn(zoomOptions) { + return zoomInOut(true, zoomOptions); + } + function zoomOut(zoomOptions) { + return zoomInOut(false, zoomOptions); + } + function zoomToPoint(toScale, point, zoomOptions) { + var dims = getDimensions(elem); + // Instead of thinking of operating on the panzoom element, + // think of operating on the area inside the panzoom + // element's parent + // Subtract padding and border + var effectiveArea = { + width: dims.parent.width - + dims.parent.padding.left - + dims.parent.padding.right - + dims.parent.border.left - + dims.parent.border.right, + height: dims.parent.height - + dims.parent.padding.top - + dims.parent.padding.bottom - + dims.parent.border.top - + dims.parent.border.bottom + }; + // Adjust the clientX/clientY to ignore the area + // outside the effective area + var clientX = point.clientX - + dims.parent.left - + dims.parent.padding.left - + dims.parent.border.left - + dims.elem.margin.left; + var clientY = point.clientY - + dims.parent.top - + dims.parent.padding.top - + dims.parent.border.top - + dims.elem.margin.top; + // Adjust the clientX/clientY for HTML elements, + // because they have a transform-origin of 50% 50% + if (!isSVG) { + clientX -= dims.elem.width / scale / 2; + clientY -= dims.elem.height / scale / 2; + } + // Convert the mouse point from it's position over the + // effective area before the scale to the position + // over the effective area after the scale. + var focal = { + x: (clientX / effectiveArea.width) * (effectiveArea.width * toScale), + y: (clientY / effectiveArea.height) * (effectiveArea.height * toScale) + }; + return zoom(toScale, __assign(__assign({}, zoomOptions), { focal: focal, animate: false })); + } + function zoomWithWheel(event, zoomOptions) { + // Need to prevent the default here + // or it conflicts with regular page scroll + event.preventDefault(); + var opts = __assign(__assign({}, options), zoomOptions); + // Normalize to deltaX in case shift modifier is used on Mac + var delta = event.deltaY === 0 && event.deltaX ? event.deltaX : event.deltaY; + var wheel = delta < 0 ? 1 : -1; + var toScale = constrainScale(scale * Math.exp((wheel * opts.step) / 3), opts).scale; + return zoomToPoint(toScale, event, opts); + } + function reset(resetOptions) { + var opts = __assign(__assign(__assign({}, options), { animate: true }), resetOptions); + scale = constrainScale(opts.startScale, opts).scale; + var panResult = constrainXY(opts.startX, opts.startY, scale, opts); + x = panResult.x; + y = panResult.y; + return setTransformWithEvent('panzoomreset', opts); + } + var origX; + var origY; + var startClientX; + var startClientY; + var startScale; + var startDistance; + var pointers = []; + function handleDown(event) { + // Don't handle this event if the target is excluded + if (isExcluded(event.target, options)) { + return; + } + addPointer(pointers, event); + isPanning = true; + options.handleStartEvent(event); + origX = x; + origY = y; + trigger('panzoomstart', { x: x, y: y, scale: scale }, options); + // This works whether there are multiple + // pointers or not + var point = getMiddle(pointers); + startClientX = point.clientX; + startClientY = point.clientY; + startScale = scale; + startDistance = getDistance(pointers); + } + function move(event) { + if (!isPanning || + origX === undefined || + origY === undefined || + startClientX === undefined || + startClientY === undefined) { + return; + } + addPointer(pointers, event); + var current = getMiddle(pointers); + if (pointers.length > 1) { + // Use the distance between the first 2 pointers + // to determine the current scale + var diff = getDistance(pointers) - startDistance; + var toScale = constrainScale((diff * options.step) / 80 + startScale).scale; + zoomToPoint(toScale, current); + } + pan(origX + (current.clientX - startClientX) / scale, origY + (current.clientY - startClientY) / scale, { + animate: false + }); + } + function handleUp(event) { + // Don't call panzoomend when panning with 2 touches + // until both touches end + if (pointers.length === 1) { + trigger('panzoomend', { x: x, y: y, scale: scale }, options); + } + // Note: don't remove all pointers + // Can restart without having to reinitiate all of them + // Remove the pointer regardless of the isPanning state + removePointer(pointers, event); + if (!isPanning) { + return; + } + isPanning = false; + origX = origY = startClientX = startClientY = undefined; + } + if (!options.disablePan) { + onPointer('down', elem, handleDown); + onPointer('move', document, move, { passive: true }); + onPointer('up', document, handleUp, { passive: true }); + } + function destroy() { + destroyPointer('down', elem, handleDown); + destroyPointer('move', document, move); + destroyPointer('up', document, handleUp); + } + return { + destroy: destroy, + getPan: function () { return ({ x: x, y: y }); }, + getScale: function () { return scale; }, + getOptions: function () { return shallowClone(options); }, + pan: pan, + reset: reset, + setOptions: setOptions, + setStyle: function (name, value) { return setStyle(elem, name, value); }, + zoom: zoom, + zoomIn: zoomIn, + zoomOut: zoomOut, + zoomToPoint: zoomToPoint, + zoomWithWheel: zoomWithWheel + }; + } + Panzoom.defaultOptions = defaultOptions; + + return Panzoom; + +}))); diff --git a/dist/panzoom.min.js b/dist/panzoom.min.js new file mode 100644 index 00000000..875d5b5b --- /dev/null +++ b/dist/panzoom.min.js @@ -0,0 +1,6 @@ +/** + * Panzoom for panning and zooming elements using CSS transforms + * Copyright Timmy Willison and other contributors + * https://github.com/timmywil/panzoom/blob/master/MIT-License.txt + */ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Panzoom=t()}(this,function(){"use strict";var r,T=function(){return(T=Object.assign||function(e){for(var t,n=1,o=arguments.length;n void, eventOpts?: any): void; +export declare function destroyPointer(event: 'down' | 'move' | 'up', elem: HTMLElement | SVGElement | Document, handler: (event: PointerEvent) => void): void; diff --git a/dist/src/isAttached.d.ts b/dist/src/isAttached.d.ts new file mode 100644 index 00000000..e76e856e --- /dev/null +++ b/dist/src/isAttached.d.ts @@ -0,0 +1,5 @@ +/** + * Determine if an element is attached to the DOM + * Panzoom requires this so events work properly + */ +export default function isAttached(elem: HTMLElement | SVGElement): boolean; diff --git a/dist/src/isExcluded.d.ts b/dist/src/isExcluded.d.ts new file mode 100644 index 00000000..dbf1676f --- /dev/null +++ b/dist/src/isExcluded.d.ts @@ -0,0 +1,2 @@ +import { PanzoomOptions } from './types'; +export default function isExcluded(elem: Element, options: PanzoomOptions): boolean; diff --git a/dist/src/isSVGElement.d.ts b/dist/src/isSVGElement.d.ts new file mode 100644 index 00000000..965bcf54 --- /dev/null +++ b/dist/src/isSVGElement.d.ts @@ -0,0 +1 @@ +export default function isSVGElement(elem: HTMLElement | SVGElement): boolean; diff --git a/dist/src/panzoom.d.ts b/dist/src/panzoom.d.ts new file mode 100644 index 00000000..8f7bcbe5 --- /dev/null +++ b/dist/src/panzoom.d.ts @@ -0,0 +1,16 @@ +/** + * Panzoom for panning and zooming elements using CSS transforms + * https://github.com/timmywil/panzoom + * + * Copyright Timmy Willison and other contributors + * Released under the MIT license + * https://github.com/timmywil/panzoom/blob/master/MIT-License.txt + * + */ +import './polyfills'; +import { PanzoomObject, PanzoomOptions } from './types'; +declare function Panzoom(elem: HTMLElement | SVGElement, options?: Omit): PanzoomObject; +declare namespace Panzoom { + var defaultOptions: PanzoomOptions; +} +export default Panzoom; diff --git a/dist/src/pointers.d.ts b/dist/src/pointers.d.ts new file mode 100644 index 00000000..7a1526c8 --- /dev/null +++ b/dist/src/pointers.d.ts @@ -0,0 +1,17 @@ +/** + * Utilites for working with multiple pointer events + */ +export declare function addPointer(pointers: PointerEvent[], event: PointerEvent): void; +export declare function removePointer(pointers: PointerEvent[], event: PointerEvent): void; +/** + * Calculates a center point between + * the given pointer events, for panning + * with multiple pointers. + */ +export declare function getMiddle(pointers: PointerEvent[]): Pick; +/** + * Calculates the distance between two points + * for pinch zooming. + * Limits to the first 2 + */ +export declare function getDistance(pointers: PointerEvent[]): number; diff --git a/dist/src/shallowClone.d.ts b/dist/src/shallowClone.d.ts new file mode 100644 index 00000000..76570a92 --- /dev/null +++ b/dist/src/shallowClone.d.ts @@ -0,0 +1 @@ +export default function shallowClone(obj: any): any; diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts new file mode 100644 index 00000000..6d215a4b --- /dev/null +++ b/dist/src/types.d.ts @@ -0,0 +1,276 @@ +import { setTransform } from './css'; +export declare type PanzoomEvent = 'panzoomstart' | 'panzoomchange' | 'panzoompan' | 'panzoomzoom' | 'panzoomreset' | 'panzoomend'; +interface MiscOptions { + /** Whether to animate transitions */ + animate?: boolean; + /** Duration of the transition (ms) */ + duration?: number; + /** CSS Easing used for transitions */ + easing?: string; + /** + * Add elements to this array that should be excluded + * from Panzoom handling. + * Ancestors of event targets are also checked. + * e.g. links and buttons that should not propagate the click event. + */ + exclude?: Element[]; + /** + * Add this class to any element within the Panzoom element + * that you want to exclude from Panzoom handling. That + * element's children will also be excluded. + * e.g. links and buttons that should not propagate the click event. + */ + excludeClass?: string; + /** + * `force` should be used sparingly to temporarily + * override and ignore options such as disablePan, + * disableZoom, and panOnlyWhenZoomed. + * This option cannot be passed to the + * Panzoom constructor or setOptions (to avoid + * setting this option globally). + * + * ```js + * // Overrides disablePan and panOnlyWhenZoomed + * panzoom.pan(50, 100, { force: true }) + * // Overrides disableZoom + * panzoom.zoom(1, { force: true }) + * ``` + */ + force?: boolean; + /** + * On the first pointer event, when panning starts, + * the default Panzoom behavior is to call + * `event.preventDefault()` and `event.stopPropagation()` + * on that event. The former is almost certainly a necesity, + * the latter enables Panzoom elements within Panzoom elements. + * + * But there are some cases where the default is + * not the desired behavior. Set this option to override that behavior. + * + * ```js + * // Only call preventDefault() + * Panzoom(elem, { + * handleStartEvent: (event) => { + * event.preventDefault() + * } + * }) + * // Do nothing (this probably breaks things on mobile tho) + * Panzoom(elem, { + * handleStartEvent: () => {} + * }) + * ``` + */ + handleStartEvent?: (event: Event) => void; + /** + * **Change this at your own risk.** + * The `transform-origin` is the origin from which transforms are applied. + * Default: `'50% 50%'` for HTML and `'0 0'` for SVG. + * The defaults are set because changing the `transform-origin` on + * SVG elements doesn't work in IE. + * + * Changing this should work with many things, but + * it will break focal point zooming, which assumes the + * defaults are set to do the more complicated calculations. + * + * And again, changing this for SVG in IE doesn't work at all. + */ + origin?: string; + /** The overflow CSS value for the parent. Defaults to 'hidden' */ + overflow?: string; + /** + * Override the transform setter. + * This is exposed mostly so the user could + * set other parts of a transform + * aside from scale and translate. + * Default is defined in src/css.ts. + * + * ```js + * // This example always sets a rotation + * // when setting the scale and translation + * const panzoom = Panzoom(elem, { + * setTransform: (elem, { scale, x, y }) => { + * panzoom.setStyle('transform', `rotate(0.5turn) scale(${scale}) translate(${x}px, ${y}px)`) + * } + * }) + * ``` + */ + setTransform?: typeof setTransform; + /** Silence all events */ + silent?: boolean; + /** X Value used to set the beginning transform */ + startX?: number; + /** Y Value used to set the beginning transform */ + startY?: number; + /** Scale used to set the beginning transform */ + startScale?: number; + /** Pass through any options like data */ + [key: string]: any; +} +interface PanSpecificOptions { + /** + * Contain the panzoom element either + * inside or outside the parent. + * Inside: The panzoom element is smaller + * than its parent and cannot be panned + * to the outside. + * Outside: The panzoom element is larger + * than its parent and cannot be panned + * to the inside. In other words, no + * empty space around the element will be shown. + */ + contain?: 'inside' | 'outside'; + /** The cursor style to set on the panzoom element */ + cursor?: string; + /** + * Disable panning functionality. + * Note: disablePan does not affect focal point zooming or the constrain option. + * The element will still pan accordingly. + */ + disablePan?: boolean; + /** Pan only on the Y axis */ + disableXAxis?: boolean; + /** Pan only on the X axis */ + disableYAxis?: boolean; + /** When passing x and y values to .pan(), treat the values as relative to their current values */ + relative?: boolean; + /** Disable panning while the scale is equal to the starting value */ + panOnlyWhenZoomed?: boolean; +} +interface ZoomSpecificOptions { + /** Disable zooming functionality */ + disableZoom?: boolean; + /** + * Zoom to the given point on the panzoom element. + * This point is expected to be relative to + * the panzoom element's dimensions and is unrelated + * to the parent dimensions. + */ + focal?: { + x: number; + y: number; + }; + /** The minimum scale when zooming */ + minScale?: number; + /** The maximum scale when zooming */ + maxScale?: number; + /** The step affects zoom calculation when zooming with a mouse wheel, when pinch zooming, or when using zoomIn/zoomOut */ + step?: number; +} +export declare type PanOptions = MiscOptions & PanSpecificOptions; +export declare type ZoomOptions = MiscOptions & ZoomSpecificOptions; +export declare type PanzoomOptions = PanOptions & ZoomOptions & MiscOptions; +export interface CurrentValues { + x: number; + y: number; + scale: number; +} +export interface PanzoomObject { + /** Remove all event listeners bind to the the Panzoom element */ + destroy: () => void; + /** Get the current x/y translation */ + getPan: () => { + x: number; + y: number; + }; + /** Get the current scale */ + getScale: () => number; + /** Returns a _copy_ of the current options object */ + getOptions: () => PanzoomOptions; + /** + * Pan the Panzoom element to the given x and y coordinates + * + * ```js + * // Translates the element to 50px, 100px + * panzoom.pan(50, 100) + * // Pans the element right 10px and down 10px from its current position + * panzoom.pan(10, 10, { relative: true }) + * ``` + */ + pan: (x: number | string, y: number | string, panOptions?: PanOptions) => CurrentValues; + /** + * Reset the pan and zoom to startX, startY, and startScale. + * Animates by default, ignoring the global option. + * Pass `{ animate: false }` to override. + * + * ```js + * panzoom.reset() + * panzoom.reset({ animate: false }) + * ``` + */ + reset: (resetOptions?: PanzoomOptions) => CurrentValues; + /** Change options for the Panzoom instance */ + setOptions: (options?: PanzoomOptions) => void; + /** A convenience method for setting prefixed styles on the Panzoom element */ + setStyle: (name: string, value: string) => void; + /** + * Zoom the Panzoom element to the given scale + * + * ```js + * panzoom.zoom(2.2) + * panzoom.zoom(2.2, { animate: true }) + * ``` + */ + zoom: (scale: number, zoomOptions?: ZoomOptions) => CurrentValues; + /** + * Zoom in using the predetermined increment set in options. + * Animates by default, ignoring the global option. + * Pass `{ animate: false }` to override. + * + * ```js + * panzoom.zoomIn() + * panzoom.zoomIn({ animate: false }) + * ``` + */ + zoomIn: (zoomOptions?: ZoomOptions) => CurrentValues; + /** + * Zoom out using the predetermined increment set in options. + * Animates by default, ignoring the global option. + * Pass `{ animate: false }` to override. + * + * ```js + * panzoom.zoomOut() + * panzoom.zoomOut({ animate: false }) + * ``` + */ + zoomOut: (zoomOptions?: ZoomOptions) => CurrentValues; + /** + * Zoom the Panzoom element to a focal point using + * the given pointer/touch/mouse event or constructed point. + * The clientX/clientY values should be calculated + * the same way as a `pointermove` event on the Panzoom element's parent. + * + * ```js + * panzoom.zoomToPoint(1.2, pointerEvent) + * ``` + */ + zoomToPoint: (scale: number, point: { + clientX: number; + clientY: number; + }, zoomOptions?: ZoomOptions) => CurrentValues; + /** + * Zoom the Panzoom element to a focal point using the given WheelEvent + * + * `disablePan` will prevent the focal point adjustment and will only zoom. + * + * `zoomWithWheel` normally uses `deltaY` to determine the scale, + * but will fall back to `deltaX` in case the shift modifier is used with + * the wheel event. On a mac, that usually translates to horizontal scrolling, + * but this method assumes the desired behavior is zooming. + * + * This is a convenience function that may not handle all use cases. + * Other cases should handroll solutions using the `zoomToPoint` + * method or the `zoom` method's focal option. + * + * ```js + * // Bind to mousewheel + * elem.parentElement.addEventListener('wheel', panzoom.zoomWithWheel) + * // Bind to shift+mousewheel + * elem.parentElement.addEventListener('wheel', function(event) { + * if (!event.shiftKey) return + * panzoom.zoomWithWheel(event) + * }) + * ``` + */ + zoomWithWheel: (event: WheelEvent, zoomOptions?: ZoomOptions) => CurrentValues; +} +export {}; diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..5657af76 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,11 @@ + +# @panzoom/panzoom + +## Index + +### External modules + +* ["events"](modules/_events_.md) +* ["isExcluded"](modules/_isexcluded_.md) +* ["panzoom"](modules/_panzoom_.md) +* ["types"](modules/_types_.md) diff --git a/docs/interfaces/_types_.currentvalues.md b/docs/interfaces/_types_.currentvalues.md new file mode 100644 index 00000000..f09cbae7 --- /dev/null +++ b/docs/interfaces/_types_.currentvalues.md @@ -0,0 +1,38 @@ + +# Interface: CurrentValues + +## Hierarchy + +* **CurrentValues** + +## Index + +### Properties + +* [scale](_types_.currentvalues.md#scale) +* [x](_types_.currentvalues.md#x) +* [y](_types_.currentvalues.md#y) + +## Properties + +### scale + +• **scale**: *number* + +*Defined in [types.ts:174](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L174)* + +___ + +### x + +• **x**: *number* + +*Defined in [types.ts:172](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L172)* + +___ + +### y + +• **y**: *number* + +*Defined in [types.ts:173](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L173)* diff --git a/docs/interfaces/_types_.miscoptions.md b/docs/interfaces/_types_.miscoptions.md new file mode 100644 index 00000000..5b869889 --- /dev/null +++ b/docs/interfaces/_types_.miscoptions.md @@ -0,0 +1,243 @@ + +# Interface: MiscOptions + +## Hierarchy + +* **MiscOptions** + +## Indexable + +* \[ **key**: *string*\]: any + +Pass through any options like data + +## Index + +### Properties + +* [animate](_types_.miscoptions.md#optional-animate) +* [duration](_types_.miscoptions.md#optional-duration) +* [easing](_types_.miscoptions.md#optional-easing) +* [exclude](_types_.miscoptions.md#optional-exclude) +* [excludeClass](_types_.miscoptions.md#optional-excludeclass) +* [force](_types_.miscoptions.md#optional-force) +* [handleStartEvent](_types_.miscoptions.md#optional-handlestartevent) +* [origin](_types_.miscoptions.md#optional-origin) +* [overflow](_types_.miscoptions.md#optional-overflow) +* [setTransform](_types_.miscoptions.md#optional-settransform) +* [silent](_types_.miscoptions.md#optional-silent) +* [startScale](_types_.miscoptions.md#optional-startscale) +* [startX](_types_.miscoptions.md#optional-startx) +* [startY](_types_.miscoptions.md#optional-starty) + +## Properties + +### `Optional` animate + +• **animate**? : *boolean* + +*Defined in [types.ts:13](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L13)* + +Whether to animate transitions + +___ + +### `Optional` duration + +• **duration**? : *number* + +*Defined in [types.ts:15](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L15)* + +Duration of the transition (ms) + +___ + +### `Optional` easing + +• **easing**? : *string* + +*Defined in [types.ts:17](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L17)* + +CSS Easing used for transitions + +___ + +### `Optional` exclude + +• **exclude**? : *Element[]* + +*Defined in [types.ts:24](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L24)* + +Add elements to this array that should be excluded +from Panzoom handling. +Ancestors of event targets are also checked. +e.g. links and buttons that should not propagate the click event. + +___ + +### `Optional` excludeClass + +• **excludeClass**? : *string* + +*Defined in [types.ts:31](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L31)* + +Add this class to any element within the Panzoom element +that you want to exclude from Panzoom handling. That +element's children will also be excluded. +e.g. links and buttons that should not propagate the click event. + +___ + +### `Optional` force + +• **force**? : *boolean* + +*Defined in [types.ts:47](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L47)* + +`force` should be used sparingly to temporarily +override and ignore options such as disablePan, +disableZoom, and panOnlyWhenZoomed. +This option cannot be passed to the +Panzoom constructor or setOptions (to avoid +setting this option globally). + +```js +// Overrides disablePan and panOnlyWhenZoomed +panzoom.pan(50, 100, { force: true }) +// Overrides disableZoom +panzoom.zoom(1, { force: true }) +``` + +___ + +### `Optional` handleStartEvent + +• **handleStartEvent**? : *function* + +*Defined in [types.ts:71](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L71)* + +On the first pointer event, when panning starts, +the default Panzoom behavior is to call +`event.preventDefault()` and `event.stopPropagation()` +on that event. The former is almost certainly a necesity, +the latter enables Panzoom elements within Panzoom elements. + +But there are some cases where the default is +not the desired behavior. Set this option to override that behavior. + +```js +// Only call preventDefault() +Panzoom(elem, { + handleStartEvent: (event) => { + event.preventDefault() + } +}) +// Do nothing (this probably breaks things on mobile tho) +Panzoom(elem, { + handleStartEvent: () => {} +}) +``` + +#### Type declaration: + +▸ (`event`: Event): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`event` | Event | + +___ + +### `Optional` origin + +• **origin**? : *string* + +*Defined in [types.ts:85](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L85)* + +**Change this at your own risk.** +The `transform-origin` is the origin from which transforms are applied. +Default: `'50% 50%'` for HTML and `'0 0'` for SVG. +The defaults are set because changing the `transform-origin` on +SVG elements doesn't work in IE. + +Changing this should work with many things, but +it will break focal point zooming, which assumes the +defaults are set to do the more complicated calculations. + +And again, changing this for SVG in IE doesn't work at all. + +___ + +### `Optional` overflow + +• **overflow**? : *string* + +*Defined in [types.ts:87](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L87)* + +The overflow CSS value for the parent. Defaults to 'hidden' + +___ + +### `Optional` setTransform + +• **setTransform**? : *setTransform* + +*Defined in [types.ts:105](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L105)* + +Override the transform setter. +This is exposed mostly so the user could +set other parts of a transform +aside from scale and translate. +Default is defined in src/css.ts. + +```js +// This example always sets a rotation +// when setting the scale and translation +const panzoom = Panzoom(elem, { + setTransform: (elem, { scale, x, y }) => { + panzoom.setStyle('transform', `rotate(0.5turn) scale(${scale}) translate(${x}px, ${y}px)`) + } +}) +``` + +___ + +### `Optional` silent + +• **silent**? : *boolean* + +*Defined in [types.ts:107](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L107)* + +Silence all events + +___ + +### `Optional` startScale + +• **startScale**? : *number* + +*Defined in [types.ts:113](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L113)* + +Scale used to set the beginning transform + +___ + +### `Optional` startX + +• **startX**? : *number* + +*Defined in [types.ts:109](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L109)* + +X Value used to set the beginning transform + +___ + +### `Optional` startY + +• **startY**? : *number* + +*Defined in [types.ts:111](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L111)* + +Y Value used to set the beginning transform diff --git a/docs/interfaces/_types_.panspecificoptions.md b/docs/interfaces/_types_.panspecificoptions.md new file mode 100644 index 00000000..5f9ce957 --- /dev/null +++ b/docs/interfaces/_types_.panspecificoptions.md @@ -0,0 +1,98 @@ + +# Interface: PanSpecificOptions + +## Hierarchy + +* **PanSpecificOptions** + +## Index + +### Properties + +* [contain](_types_.panspecificoptions.md#optional-contain) +* [cursor](_types_.panspecificoptions.md#optional-cursor) +* [disablePan](_types_.panspecificoptions.md#optional-disablepan) +* [disableXAxis](_types_.panspecificoptions.md#optional-disablexaxis) +* [disableYAxis](_types_.panspecificoptions.md#optional-disableyaxis) +* [panOnlyWhenZoomed](_types_.panspecificoptions.md#optional-panonlywhenzoomed) +* [relative](_types_.panspecificoptions.md#optional-relative) + +## Properties + +### `Optional` contain + +• **contain**? : *"inside" | "outside"* + +*Defined in [types.ts:130](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L130)* + +Contain the panzoom element either +inside or outside the parent. +Inside: The panzoom element is smaller + than its parent and cannot be panned + to the outside. +Outside: The panzoom element is larger + than its parent and cannot be panned + to the inside. In other words, no + empty space around the element will be shown. + +___ + +### `Optional` cursor + +• **cursor**? : *string* + +*Defined in [types.ts:132](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L132)* + +The cursor style to set on the panzoom element + +___ + +### `Optional` disablePan + +• **disablePan**? : *boolean* + +*Defined in [types.ts:138](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L138)* + +Disable panning functionality. +Note: disablePan does not affect focal point zooming or the constrain option. + The element will still pan accordingly. + +___ + +### `Optional` disableXAxis + +• **disableXAxis**? : *boolean* + +*Defined in [types.ts:140](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L140)* + +Pan only on the Y axis + +___ + +### `Optional` disableYAxis + +• **disableYAxis**? : *boolean* + +*Defined in [types.ts:142](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L142)* + +Pan only on the X axis + +___ + +### `Optional` panOnlyWhenZoomed + +• **panOnlyWhenZoomed**? : *boolean* + +*Defined in [types.ts:146](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L146)* + +Disable panning while the scale is equal to the starting value + +___ + +### `Optional` relative + +• **relative**? : *boolean* + +*Defined in [types.ts:144](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L144)* + +When passing x and y values to .pan(), treat the values as relative to their current values diff --git a/docs/interfaces/_types_.panzoomobject.md b/docs/interfaces/_types_.panzoomobject.md new file mode 100644 index 00000000..6f0af8e7 --- /dev/null +++ b/docs/interfaces/_types_.panzoomobject.md @@ -0,0 +1,337 @@ + +# Interface: PanzoomObject + +## Hierarchy + +* **PanzoomObject** + +## Index + +### Properties + +* [destroy](_types_.panzoomobject.md#destroy) +* [getOptions](_types_.panzoomobject.md#getoptions) +* [getPan](_types_.panzoomobject.md#getpan) +* [getScale](_types_.panzoomobject.md#getscale) +* [pan](_types_.panzoomobject.md#pan) +* [reset](_types_.panzoomobject.md#reset) +* [setOptions](_types_.panzoomobject.md#setoptions) +* [setStyle](_types_.panzoomobject.md#setstyle) +* [zoom](_types_.panzoomobject.md#zoom) +* [zoomIn](_types_.panzoomobject.md#zoomin) +* [zoomOut](_types_.panzoomobject.md#zoomout) +* [zoomToPoint](_types_.panzoomobject.md#zoomtopoint) +* [zoomWithWheel](_types_.panzoomobject.md#zoomwithwheel) + +## Properties + +### destroy + +• **destroy**: *function* + +*Defined in [types.ts:179](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L179)* + +Remove all event listeners bind to the the Panzoom element + +#### Type declaration: + +▸ (): *void* + +___ + +### getOptions + +• **getOptions**: *function* + +*Defined in [types.ts:185](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L185)* + +Returns a _copy_ of the current options object + +#### Type declaration: + +▸ (): *[PanzoomOptions](../modules/_types_.md#panzoomoptions)* + +___ + +### getPan + +• **getPan**: *function* + +*Defined in [types.ts:181](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L181)* + +Get the current x/y translation + +#### Type declaration: + +▸ (): *object* + +* **x**: *number* + +* **y**: *number* + +___ + +### getScale + +• **getScale**: *function* + +*Defined in [types.ts:183](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L183)* + +Get the current scale + +#### Type declaration: + +▸ (): *number* + +___ + +### pan + +• **pan**: *function* + +*Defined in [types.ts:196](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L196)* + +Pan the Panzoom element to the given x and y coordinates + +```js +// Translates the element to 50px, 100px +panzoom.pan(50, 100) +// Pans the element right 10px and down 10px from its current position +panzoom.pan(10, 10, { relative: true }) +``` + +#### Type declaration: + +▸ (`x`: number | string, `y`: number | string, `panOptions?`: [PanOptions](../modules/_types_.md#panoptions)): *[CurrentValues](_types_.currentvalues.md)* + +**Parameters:** + +Name | Type | +------ | ------ | +`x` | number | string | +`y` | number | string | +`panOptions?` | [PanOptions](../modules/_types_.md#panoptions) | + +___ + +### reset + +• **reset**: *function* + +*Defined in [types.ts:207](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L207)* + +Reset the pan and zoom to startX, startY, and startScale. +Animates by default, ignoring the global option. +Pass `{ animate: false }` to override. + +```js +panzoom.reset() +panzoom.reset({ animate: false }) +``` + +#### Type declaration: + +▸ (`resetOptions?`: [PanzoomOptions](../modules/_types_.md#panzoomoptions)): *[CurrentValues](_types_.currentvalues.md)* + +**Parameters:** + +Name | Type | +------ | ------ | +`resetOptions?` | [PanzoomOptions](../modules/_types_.md#panzoomoptions) | + +___ + +### setOptions + +• **setOptions**: *function* + +*Defined in [types.ts:209](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L209)* + +Change options for the Panzoom instance + +#### Type declaration: + +▸ (`options?`: [PanzoomOptions](../modules/_types_.md#panzoomoptions)): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`options?` | [PanzoomOptions](../modules/_types_.md#panzoomoptions) | + +___ + +### setStyle + +• **setStyle**: *function* + +*Defined in [types.ts:211](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L211)* + +A convenience method for setting prefixed styles on the Panzoom element + +#### Type declaration: + +▸ (`name`: string, `value`: string): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`name` | string | +`value` | string | + +___ + +### zoom + +• **zoom**: *function* + +*Defined in [types.ts:220](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L220)* + +Zoom the Panzoom element to the given scale + +```js +panzoom.zoom(2.2) +panzoom.zoom(2.2, { animate: true }) +``` + +#### Type declaration: + +▸ (`scale`: number, `zoomOptions?`: [ZoomOptions](../modules/_types_.md#zoomoptions)): *[CurrentValues](_types_.currentvalues.md)* + +**Parameters:** + +Name | Type | +------ | ------ | +`scale` | number | +`zoomOptions?` | [ZoomOptions](../modules/_types_.md#zoomoptions) | + +___ + +### zoomIn + +• **zoomIn**: *function* + +*Defined in [types.ts:231](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L231)* + +Zoom in using the predetermined increment set in options. +Animates by default, ignoring the global option. +Pass `{ animate: false }` to override. + +```js +panzoom.zoomIn() +panzoom.zoomIn({ animate: false }) +``` + +#### Type declaration: + +▸ (`zoomOptions?`: [ZoomOptions](../modules/_types_.md#zoomoptions)): *[CurrentValues](_types_.currentvalues.md)* + +**Parameters:** + +Name | Type | +------ | ------ | +`zoomOptions?` | [ZoomOptions](../modules/_types_.md#zoomoptions) | + +___ + +### zoomOut + +• **zoomOut**: *function* + +*Defined in [types.ts:242](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L242)* + +Zoom out using the predetermined increment set in options. +Animates by default, ignoring the global option. +Pass `{ animate: false }` to override. + +```js +panzoom.zoomOut() +panzoom.zoomOut({ animate: false }) +``` + +#### Type declaration: + +▸ (`zoomOptions?`: [ZoomOptions](../modules/_types_.md#zoomoptions)): *[CurrentValues](_types_.currentvalues.md)* + +**Parameters:** + +Name | Type | +------ | ------ | +`zoomOptions?` | [ZoomOptions](../modules/_types_.md#zoomoptions) | + +___ + +### zoomToPoint + +• **zoomToPoint**: *function* + +*Defined in [types.ts:253](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L253)* + +Zoom the Panzoom element to a focal point using +the given pointer/touch/mouse event or constructed point. +The clientX/clientY values should be calculated +the same way as a `pointermove` event on the Panzoom element's parent. + +```js +panzoom.zoomToPoint(1.2, pointerEvent) +``` + +#### Type declaration: + +▸ (`scale`: number, `point`: object, `zoomOptions?`: [ZoomOptions](../modules/_types_.md#zoomoptions)): *[CurrentValues](_types_.currentvalues.md)* + +**Parameters:** + +▪ **scale**: *number* + +▪ **point**: *object* + +Name | Type | +------ | ------ | +`clientX` | number | +`clientY` | number | + +▪`Optional` **zoomOptions**: *[ZoomOptions](../modules/_types_.md#zoomoptions)* + +___ + +### zoomWithWheel + +• **zoomWithWheel**: *function* + +*Defined in [types.ts:282](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L282)* + +Zoom the Panzoom element to a focal point using the given WheelEvent + +`disablePan` will prevent the focal point adjustment and will only zoom. + +`zoomWithWheel` normally uses `deltaY` to determine the scale, +but will fall back to `deltaX` in case the shift modifier is used with +the wheel event. On a mac, that usually translates to horizontal scrolling, +but this method assumes the desired behavior is zooming. + +This is a convenience function that may not handle all use cases. +Other cases should handroll solutions using the `zoomToPoint` +method or the `zoom` method's focal option. + +```js +// Bind to mousewheel +elem.parentElement.addEventListener('wheel', panzoom.zoomWithWheel) +// Bind to shift+mousewheel +elem.parentElement.addEventListener('wheel', function(event) { + if (!event.shiftKey) return + panzoom.zoomWithWheel(event) +}) +``` + +#### Type declaration: + +▸ (`event`: WheelEvent, `zoomOptions?`: [ZoomOptions](../modules/_types_.md#zoomoptions)): *[CurrentValues](_types_.currentvalues.md)* + +**Parameters:** + +Name | Type | +------ | ------ | +`event` | WheelEvent | +`zoomOptions?` | [ZoomOptions](../modules/_types_.md#zoomoptions) | diff --git a/docs/interfaces/_types_.zoomspecificoptions.md b/docs/interfaces/_types_.zoomspecificoptions.md new file mode 100644 index 00000000..76788dae --- /dev/null +++ b/docs/interfaces/_types_.zoomspecificoptions.md @@ -0,0 +1,75 @@ + +# Interface: ZoomSpecificOptions + +## Hierarchy + +* **ZoomSpecificOptions** + +## Index + +### Properties + +* [disableZoom](_types_.zoomspecificoptions.md#optional-disablezoom) +* [focal](_types_.zoomspecificoptions.md#optional-focal) +* [maxScale](_types_.zoomspecificoptions.md#optional-maxscale) +* [minScale](_types_.zoomspecificoptions.md#optional-minscale) +* [step](_types_.zoomspecificoptions.md#optional-step) + +## Properties + +### `Optional` disableZoom + +• **disableZoom**? : *boolean* + +*Defined in [types.ts:151](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L151)* + +Disable zooming functionality + +___ + +### `Optional` focal + +• **focal**? : *object* + +*Defined in [types.ts:158](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L158)* + +Zoom to the given point on the panzoom element. +This point is expected to be relative to +the panzoom element's dimensions and is unrelated +to the parent dimensions. + +#### Type declaration: + +* **x**: *number* + +* **y**: *number* + +___ + +### `Optional` maxScale + +• **maxScale**? : *number* + +*Defined in [types.ts:162](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L162)* + +The maximum scale when zooming + +___ + +### `Optional` minScale + +• **minScale**? : *number* + +*Defined in [types.ts:160](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L160)* + +The minimum scale when zooming + +___ + +### `Optional` step + +• **step**? : *number* + +*Defined in [types.ts:164](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L164)* + +The step affects zoom calculation when zooming with a mouse wheel, when pinch zooming, or when using zoomIn/zoomOut diff --git a/docs/modules/_events_.md b/docs/modules/_events_.md new file mode 100644 index 00000000..16d757e1 --- /dev/null +++ b/docs/modules/_events_.md @@ -0,0 +1,83 @@ + +# External module: "events" + +## Index + +### Variables + +* [events](_events_.md#let-events) + +### Functions + +* [destroyPointer](_events_.md#destroypointer) +* [onPointer](_events_.md#onpointer) + +## Variables + +### `Let` events + +• **events**: *object* + +*Defined in [events.ts:1](https://github.com/timmywil/panzoom/blob/b082b5a/src/events.ts#L1)* + +#### Type declaration: + +* **down**: *string* + +* **move**: *string* + +* **up**: *string* + +## Functions + +### destroyPointer + +▸ **destroyPointer**(`event`: "down" | "move" | "up", `elem`: HTMLElement | SVGElement | Document, `handler`: function): *void* + +*Defined in [events.ts:35](https://github.com/timmywil/panzoom/blob/b082b5a/src/events.ts#L35)* + +**Parameters:** + +▪ **event**: *"down" | "move" | "up"* + +▪ **elem**: *HTMLElement | SVGElement | Document* + +▪ **handler**: *function* + +▸ (`event`: PointerEvent): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`event` | PointerEvent | + +**Returns:** *void* + +___ + +### onPointer + +▸ **onPointer**(`event`: "down" | "move" | "up", `elem`: HTMLElement | SVGElement | Document, `handler`: function, `eventOpts?`: any): *void* + +*Defined in [events.ts:22](https://github.com/timmywil/panzoom/blob/b082b5a/src/events.ts#L22)* + +**Parameters:** + +▪ **event**: *"down" | "move" | "up"* + +▪ **elem**: *HTMLElement | SVGElement | Document* + +▪ **handler**: *function* + +▸ (`event`: PointerEvent): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`event` | PointerEvent | + +▪`Optional` **eventOpts**: *any* + +**Returns:** *void* diff --git a/docs/modules/_isexcluded_.md b/docs/modules/_isexcluded_.md new file mode 100644 index 00000000..3eed07da --- /dev/null +++ b/docs/modules/_isexcluded_.md @@ -0,0 +1,25 @@ + +# External module: "isExcluded" + +## Index + +### Functions + +* [isExcluded](_isexcluded_.md#isexcluded) + +## Functions + +### isExcluded + +▸ **isExcluded**(`elem`: Element, `options`: [PanzoomOptions](_types_.md#panzoomoptions)): *boolean* + +*Defined in [isExcluded.ts:3](https://github.com/timmywil/panzoom/blob/b082b5a/src/isExcluded.ts#L3)* + +**Parameters:** + +Name | Type | +------ | ------ | +`elem` | Element | +`options` | [PanzoomOptions](_types_.md#panzoomoptions) | + +**Returns:** *boolean* diff --git a/docs/modules/_panzoom_.md b/docs/modules/_panzoom_.md new file mode 100644 index 00000000..c75e3e15 --- /dev/null +++ b/docs/modules/_panzoom_.md @@ -0,0 +1,171 @@ + +# External module: "panzoom" + +## Index + +### Functions + +* [Panzoom](_panzoom_.md#panzoom) + +### Object literals + +* [defaultOptions](_panzoom_.md#const-defaultoptions) + +## Functions + +### Panzoom + +▸ **Panzoom**(`elem`: HTMLElement | SVGElement, `options?`: Omit‹[PanzoomOptions](_types_.md#panzoomoptions), "force"›): *[PanzoomObject](../interfaces/_types_.panzoomobject.md)* + +*Defined in [panzoom.ts:49](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L49)* + +**Parameters:** + +Name | Type | +------ | ------ | +`elem` | HTMLElement | SVGElement | +`options?` | Omit‹[PanzoomOptions](_types_.md#panzoomoptions), "force"› | + +**Returns:** *[PanzoomObject](../interfaces/_types_.panzoomobject.md)* + +## Object literals + +### `Const` defaultOptions + +### ▪ **defaultOptions**: *object* + +*Defined in [panzoom.ts:22](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L22)* + +### animate + +• **animate**: *false* = false + +*Defined in [panzoom.ts:23](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L23)* + +### cursor + +• **cursor**: *string* = "move" + +*Defined in [panzoom.ts:24](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L24)* + +### disablePan + +• **disablePan**: *false* = false + +*Defined in [panzoom.ts:25](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L25)* + +### disableXAxis + +• **disableXAxis**: *false* = false + +*Defined in [panzoom.ts:27](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L27)* + +### disableYAxis + +• **disableYAxis**: *false* = false + +*Defined in [panzoom.ts:28](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L28)* + +### disableZoom + +• **disableZoom**: *false* = false + +*Defined in [panzoom.ts:26](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L26)* + +### duration + +• **duration**: *number* = 200 + +*Defined in [panzoom.ts:29](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L29)* + +### easing + +• **easing**: *string* = "ease-in-out" + +*Defined in [panzoom.ts:30](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L30)* + +### exclude + +• **exclude**: *undefined[]* = [] + +*Defined in [panzoom.ts:31](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L31)* + +### excludeClass + +• **excludeClass**: *string* = "panzoom-exclude" + +*Defined in [panzoom.ts:32](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L32)* + +### maxScale + +• **maxScale**: *number* = 4 + +*Defined in [panzoom.ts:37](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L37)* + +### minScale + +• **minScale**: *number* = 0.125 + +*Defined in [panzoom.ts:38](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L38)* + +### overflow + +• **overflow**: *string* = "hidden" + +*Defined in [panzoom.ts:39](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L39)* + +### panOnlyWhenZoomed + +• **panOnlyWhenZoomed**: *false* = false + +*Defined in [panzoom.ts:40](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L40)* + +### relative + +• **relative**: *false* = false + +*Defined in [panzoom.ts:41](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L41)* + +### setTransform + +• **setTransform**: *setTransform* + +*Defined in [panzoom.ts:42](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L42)* + +### startScale + +• **startScale**: *number* = 1 + +*Defined in [panzoom.ts:45](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L45)* + +### startX + +• **startX**: *number* = 0 + +*Defined in [panzoom.ts:43](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L43)* + +### startY + +• **startY**: *number* = 0 + +*Defined in [panzoom.ts:44](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L44)* + +### step + +• **step**: *number* = 0.3 + +*Defined in [panzoom.ts:46](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L46)* + +### handleStartEvent + +▸ **handleStartEvent**(`e`: Event): *void* + +*Defined in [panzoom.ts:33](https://github.com/timmywil/panzoom/blob/b082b5a/src/panzoom.ts#L33)* + +**Parameters:** + +Name | Type | +------ | ------ | +`e` | Event | + +**Returns:** *void* diff --git a/docs/modules/_types_.md b/docs/modules/_types_.md new file mode 100644 index 00000000..e79ea150 --- /dev/null +++ b/docs/modules/_types_.md @@ -0,0 +1,51 @@ + +# External module: "types" + +## Index + +### Interfaces + +* [CurrentValues](../interfaces/_types_.currentvalues.md) +* [MiscOptions](../interfaces/_types_.miscoptions.md) +* [PanSpecificOptions](../interfaces/_types_.panspecificoptions.md) +* [PanzoomObject](../interfaces/_types_.panzoomobject.md) +* [ZoomSpecificOptions](../interfaces/_types_.zoomspecificoptions.md) + +### Type aliases + +* [PanOptions](_types_.md#panoptions) +* [PanzoomEvent](_types_.md#panzoomevent) +* [PanzoomOptions](_types_.md#panzoomoptions) +* [ZoomOptions](_types_.md#zoomoptions) + +## Type aliases + +### PanOptions + +Ƭ **PanOptions**: *[MiscOptions](../interfaces/_types_.miscoptions.md) & [PanSpecificOptions](../interfaces/_types_.panspecificoptions.md)* + +*Defined in [types.ts:167](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L167)* + +___ + +### PanzoomEvent + +Ƭ **PanzoomEvent**: *"panzoomstart" | "panzoomchange" | "panzoompan" | "panzoomzoom" | "panzoomreset" | "panzoomend"* + +*Defined in [types.ts:3](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L3)* + +___ + +### PanzoomOptions + +Ƭ **PanzoomOptions**: *[PanOptions](_types_.md#panoptions) & [ZoomOptions](_types_.md#zoomoptions) & [MiscOptions](../interfaces/_types_.miscoptions.md)* + +*Defined in [types.ts:169](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L169)* + +___ + +### ZoomOptions + +Ƭ **ZoomOptions**: *[MiscOptions](../interfaces/_types_.miscoptions.md) & [ZoomSpecificOptions](../interfaces/_types_.zoomspecificoptions.md)* + +*Defined in [types.ts:168](https://github.com/timmywil/panzoom/blob/b082b5a/src/types.ts#L168)* diff --git a/package.json b/package.json index 11451096..3406305d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@panzoom/panzoom", - "version": "4.0.0-pre", + "version": "4.0.0", "description": "Pan and zoom elements anywhere using native transformations", "main": "dist/panzoom.js", "scripts": {