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

pinch-type

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinch-type

Pinch to zoom text, not the page. Canvas-based text scaling for mobile web.

latest
Source
npmnpm
Version
0.2.6
Version published
Maintainers
1
Created
Source

pinch-type

Three canvas-based text effects for mobile web, built on @chenglou/pretext.

  • Pinch Type — intercepts pinch-to-zoom and scales text size instead of zooming the page
  • Scroll Morph — fisheye effect: text near the viewport center is large and bright, edges are small and dim
  • Combined — both effects together

Live Demo →

Install

npm install pinch-type @chenglou/pretext

Quick Start

import { createPinchType, createScrollMorph, createPinchMorph } from 'pinch-type';

// 1. Pinch Type — uniform text, pinch gestures scale all text
const pt = createPinchType(document.getElementById('reader'));
pt.setText('Your long article text here…');

// 2. Scroll Morph — fisheye effect, no pinch zoom
const sm = createScrollMorph(document.getElementById('reader'));
sm.setText('Your long article text here…');

// 3. Combined — fisheye + pinch-to-zoom (the original behavior)
const pm = createPinchMorph(document.getElementById('reader'));
pm.setText('Your long article text here…');

// Clean up when done:
instance.destroy();

The container element should have a defined width and height (e.g. 100vw × 100vh). Each function creates a fullscreen <canvas> inside it.

API

createPinchType(element, options?)

Uniform text rendering with pinch-to-zoom scaling.

OptionTypeDefaultDescription
fontSizenumber18Base font size
minFontSizenumber8Smallest size reachable via pinch
maxFontSizenumber60Largest size reachable via pinch
fontFamilystring"Inter", system-ui, sans-serifCSS font-family
lineHeightnumber1.57Line-height ratio
paddingnumber28Content padding (px)
backgroundstring#0a0a0aCanvas background color
frictionnumber0.95Scroll momentum friction (0–1)
onZoom(fontSize) => voidCallback after each pinch zoom

createScrollMorph(element, options?)

Fisheye scroll effect. No pinch-to-zoom.

OptionTypeDefaultDescription
centerFontSizenumber26Font size at viewport center
edgeFontSizenumber11Font size at viewport edges
morphRadiusnumber300Radius (px) of the center→edge gradient
fontFamilystring"Inter", system-ui, sans-serifCSS font-family
lineHeightnumber1.57Line-height ratio
paddingnumber28Content padding (px)
backgroundstring#0a0a0aCanvas background color
frictionnumber0.95Scroll momentum friction (0–1)

createPinchMorph(element, options?)

Combined: fisheye scroll effect + pinch-to-zoom.

OptionTypeDefaultDescription
centerFontSizenumber26Font size at viewport center
edgeFontSizenumber11Font size at viewport edges
minFontSizenumber8Smallest size reachable via pinch
maxFontSizenumber60Largest size reachable via pinch
morphRadiusnumber300Radius (px) of the center→edge gradient
fontFamilystring"Inter", system-ui, sans-serifCSS font-family
lineHeightnumber1.57Line-height ratio
paddingnumber28Content padding (px)
backgroundstring#0a0a0aCanvas background color
frictionnumber0.95Scroll momentum friction (0–1)
onZoom(center, edge) => voidCallback after each pinch zoom

Instance Methods (all three)

MethodDescription
setText(text)Update displayed text and re-layout
resize()Force re-layout (auto-called on window resize)
destroy()Remove canvas, listeners, and animation loop
canvasThe underlying <canvas> element (read-only)

Lightweight Mode

Just want pinch-to-zoom on your existing page? Use the lightweight API — no canvas, no dependencies, ~1KB. Want the full canvas rendering experience? Use createPinchType / createScrollMorph / createPinchMorph above.

pinchZoom(options?) — Vanilla JS

import { pinchZoom } from 'pinch-type';

const cleanup = pinchZoom({
  target: document.getElementById('article'),  // default: document.documentElement
  min: 12,        // min font size, default 12
  max: 32,        // max font size, default 32
  initial: 16,    // starting size, default 16
  step: 1,        // px per zoom step, default 1
  onZoom: (size) => console.log(size),
});

// Later: remove all listeners
cleanup();

Detects two-finger touch pinch and trackpad pinch (ctrl+wheel / meta+wheel). Single-finger scroll is unaffected. Applies font-size directly to the target element.

usePinchZoom(options?) — React Hook

Requires react as a peer dependency.

import { usePinchZoom } from 'pinch-type';

function Reader() {
  const { fontSize, ref } = usePinchZoom({ min: 12, max: 32 });
  return <article ref={ref} style={{ fontSize }}>...</article>;
}
OptionTypeDefaultDescription
minnumber12Minimum font size
maxnumber32Maximum font size
initialnumber16Starting font size
stepnumber1Pixels per zoom step
onZoom(size) => voidCallback after each zoom

How It Works

Text is measured and wrapped using @chenglou/pretext for accurate segment-aware line breaking. Each frame, lines are drawn to a canvas. For scroll morph, font size and opacity are interpolated based on distance from the viewport center (ease-out cubic). Touch events drive momentum scrolling with configurable friction, and two-finger pinch gestures scale the font size range in real time.

License

MIT — Lucas Crespo

Keywords

pinch-to-zoom

FAQs

Package last updated on 30 Mar 2026

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