New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

panzoom-core

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

panzoom-core

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

latest
Source
npmnpm
Version
1.9.0
Version published
Maintainers
1
Created
Source

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

Keywords

pan

FAQs

Package last updated on 26 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts