Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
svg-pan-zoom-gesture
Advanced tools
Readme
Small JS library to add pan and zoom functionality to SVG (inline or image). It supports gestures for all types of devices:
intention | mouse | trackpad/touchpad | touchscren |
---|---|---|---|
pan | clik + move | click + move | two finger drag |
zoom | Ctrl + wheel | pinch | pinch |
reset | double click | double click | double tap |
scroll | wheel | two finger drag | one finger drag |
Pay attention:
pan(dx, dy)
and zoom(scale)
There are two flavors:
If you have container element in HTML:
import { SvgPanZoom } from "svg-pan-zoom-gesture";
document.querySelectorAll(".svg-pan-zoom").forEach((container) => {
const element = container.querySelector("svg,img");
if (!element) return;
new SvgPanZoom({ element, container }).on();
});
If you don't have container element in HTML:
import { SvgPanZoom } from "svg-pan-zoom-gesture";
document.querySelectorAll("svg").forEach((element) => {
const container = document.createElement("div");
container.className = "svg-pan-zoom";
element.replaceWith(container);
container.append(element);
new SvgPanZoom({ element, container }).on();
});
Additionally following CSS is required:
.svg-pan-zoom {
overflow: hidden;
touch-action: pan-x pan-y;
user-select: none;
cursor: grab;
}
.svg-pan-zoom svg,
.svg-pan-zoom img {
/* need to center smaller images or fix bug in zoom functionality */
margin: auto;
/* need to fit bigger images */
max-width: 100%;
height: auto;
}
.svg-pan-zoom img {
pointer-events: none;
}
Instance methods:
on()
- adds event listenersoff()
- removes event listenerspan(dx, dy)
- pans imagezoom(scale)
- zooms imagereset()
- resets pan and zoom valuesimport "svg-pan-zoom-gesture/css/SvgPanZoomUi.css";
import { SvgPanZoomUi } from "svg-pan-zoom-gesture";
document.querySelectorAll(".svg-pan-zoom").forEach((container) => {
const element = container.querySelector("svg,img");
if (!element) return;
new SvgPanZoomUi({ element, container }).on();
});
Additionally, CSS to style UI required (for example with Tailwind):
.svg-pan-zoom .buttons {
@apply inline-flex;
}
.svg-pan-zoom .zoom-in {
@apply bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded-l;
}
.svg-pan-zoom .reset {
@apply bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4;
}
.svg-pan-zoom .zoom-out {
@apply bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded-r;
}
You can configure HTML classes used by UI:
const classes = {
zoomIn: "zoom-in",
reset: "reset",
zoomOut: "zoom-out",
buttons: "buttons",
tsWarning: "touchscreen-warning",
tsWarningActive: "active",
};
new SvgPanZoomUi({ element, container, classes });
and message with instructions for the touchscreen:
const message = "Use two fingers to pan and zoom";
new SvgPanZoomUi({ element, container, message });
Be aware that some CSS will cause pixelation of SVG on zoom (bug in Safari), for example:
will-change: transform;
transform: matrix3d(...);
transition-property: transform;
(it setles after animation, though)There are a lot of solutions for this task:
FAQs
Pan and zoom for SVG images
The npm package svg-pan-zoom-gesture receives a total of 0 weekly downloads. As such, svg-pan-zoom-gesture popularity was classified as not popular.
We found that svg-pan-zoom-gesture demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.