1.9.0 • Published 4 months ago

panzoom-core v1.9.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

panzoom-core

Library for pan and zoom with possibility to moving, resizing and selecting elements inside.

"Preview"

Demo

https://codesandbox.io/s/quiet-snow-qldnic https://codesandbox.io/s/black-sound-vn77k9 (map with pin) https://codesandbox.io/s/young-darkness-igcf67 (example from above) https://codesandbox.io/s/gifted-pine-dhw9m6 (selecting elements) https://codesandbox.io/s/festive-matsumoto-ccskw0 (Tic Tac Toe) Library react-web-builder Library react-grid-panzoom Library @sasza/react-panzoom Library react-drawing

Installation

npm install panzoom-core

Options

NameDefaultDescription
boundary{ top, right, bottom left, parent } \| boolfalsetop, right, bottom, left - numbers in px.can be used as expression like: { top: 'childHeight - containerHeight - 100px' }
disabledUserSelectboolfalseprevent css select as text etc
disabledboolfalsedisabling pan and zoom
disabledElementsboolfalsedisabling moving elements
disabledMoveboolfalsedisabling move
disabledZoomboolfalsedisabling zoom
heightstring/number100%height of child container
onContainerChangefuncnullevent on move/zoom
onContainerClickfuncnullevent on mousedown/touchdown
onContainerPositionChangefuncnullevent on position change
onContainerZoomChangefuncnullevent on zoom change
onElementsChangefuncnullcallback invoked when elements change position
selectingboolfalseswitches to selecting mode, see selecting
widthstring/number100%width of child container
zoomInitialnumber1initial zoom value
zoomMaxnumber5maximum zoom
zoomMinnumber0.3minimum zoom
zoomSpeednumber1zoom speed on wheel event

API

import initializePanZoom from 'panzoom-core'

const node = document.querySelector('[data-id="panzoom"]')
const panZoom = initializePanZoom(node, options)
<div>
  <div data-id="panzoom"> </div>
</div>

panzoom methods:

FunctionDescription
setOptions(options)Setting options for panzoom
addElement(node: HTMLDivElement, elementOptions: ElementOptions) => ElementApiAdding new element to moving
move(x:number, y:number)Add x and y in px to current offset. Returns current position {x, y}
getElements()Returns map of elements
getPosition()Returns current position {x, y}
setPosition(x:number, y:number)Set offset position of pan
getZoom():numberReturns current zoom
setZoom(zoom:number)Sets zoom
zoomIn(zoom:number)Add to current zoom, could be also negative number (it will work like zoomOut)
zoomOut(zoom:number)Sub from current zoom
childNodeReturns passed node
reset()Reset to (0, 0, 0)
destroy()Unmounting panzoom element

Elements

"Preview"

import initializePanZoom from 'panzoom-core'

const node = document.querySelector('[data-id="panzoom"]')
const panZoom = initializePanZoom(node, options)

const elementA = panZoom.addElement(
  document.querySelector('[data-id="element-a"]'),
  { id: 'a' },
)
const elementB = panZoom.addElement(
  document.querySelector('[data-id="element-b"]'),
  { id: 'b', x: 100, y: 100 },
)
<div>
  <div data-id="panzoom">
    <div data-id="element-a">test</div>
    <div data-id="element-b">move me</div>
  </div>
</div>

Element properties

NameDefaultDescription
id *string/idundefinedUnique ID of element
classNamestringundefinedClass name for element
disabledboolfalseDisabling element
draggableSelectorstringundefinedSelector for dragging element
familystringundefinedName of element's family, all of elements are connected during moving
followersArray\<string/id>[]Similar to family, but for specified ids of elements
onClickfuncnullEvent on element's click
onMouseUpfuncnullEvent on element's mouse up
xnumber0x position of element
ynumber0y position of element

* - is required

Selecting

import initializePanZoom from 'panzoom-core'

// ...
const panZoom = initializePanZoom(node, { selecting: true })

// to disable:
panZoom.setOptions({ selecting: false })

"Preview"

Installing for development

pnpm i

Testing

pnpm test

Examples

pnpm dev
1.8.2

4 months ago

1.9.0

4 months ago

1.8.1

8 months ago

1.8.0

1 year ago

1.7.0

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.3.3

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.2.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.2.5

2 years ago

1.1.6

2 years ago

1.2.4

2 years ago

1.1.5

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.10

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago