Migration notes (
2.0.x→2.1.0):
- All existing
2.xinstance/session property names are preserved unmangled inhammer.jsandhammer.min.js(the_-prefixing and UglifyJSmangle.propertieschanges from2.1.0-rc.5were reverted for SemVer compatibility).session.curRecognizerhas been replaced by pairwise blocking (isBlockingRecognizer()/isBlocked()).Recognizer.requireFailure()is now strictly one-way (directed), andRecognizer.dropRecognizeWith()is symmetric (removes the link from both recognizers).- Velocity tracking now uses recency-weighted 1st-order least-squares (
LSQ1) withPointerEvent.getCoalescedEvents()sub-frame sampling, andSwipeRecognizerdefaults are updated (threshold: 30,maxVelocity: 80).Hammer.QuickScale(enable: false) is appended atHammer.defaults.preset[7], preserving2.0.xpreset indices0..6.- Coordinate
@types/hammerjs2.1definitions (QuickScale,STATE_PENDING,pointerTypes,maxVelocity,recognizers: false) when publishing2.1.0final.
SemVer Compatibility Restored
- Revert the 29
_-prefixed internal property renames and disable UglifyJSmangle.propertiesintroduced in2.1.0-rc.5, restoringdomHandler,handlers,oldCssProps,id,simultaneous,requireFail,pTime,pCenter,count,store,pressed,lastEv,targetIds,started,lastTouches,appliedNative,oldTouchAction,session.prevInput,firstMultiple,offsetDelta,prevDelta,stopped,prevented,startTime, andvelocitySamples(7f02714) - Move
[QuickScaleRecognizer, { enable: false }]fromHammer.defaults.preset[2]to index7so2.0.xpreset indices0..6remain unchanged
Security & Runtime Hardening
- QuickScale & non-native
touch-action(document/window): Defer non-passive → passive touch listener downgrades (_pendingTouchSync) untilisFinalso mid-sessionQuickScaledisarming never drops active pointers or swallows distant taps/Press; guard null_anchorinemit(),sensitivity === 0(returns scale1), and backwardtimeStampon the second tap - Recognizer linking & state machine: Restore
instanceof Recognizercheck ingetRecognizerByNameIfManager()(preventing unresolved strings on unattached recognizers from corruptingrequireFail/simultaneous); reject self-links (other !== this) inrecognizeWith()/requireFailure(); restorecanContinueEmit()checks acrossRecognizer.emit()andSwipeRecognizer.emit(); emit syntheticSTATE_CANCELLED(isFirst: false,isFinal: false, stripping the winner'sadditionalEvent) for active continuous_requiredBydependents before resetting, snapshotting_requiredBy.slice()against mutation - Re-entrancy & listener throws: Add
canContinueAfterCancel()guards after cancel emits inTouchMouseInputandPointerEventInputprimary-pointer purges; wrapisFinalrecognition andhammer.inputemits intry/finallyso throwing listeners still reset unvisited recognizers/timers (Press,QuickScale) and flush_pendingTouchSync; snapshotmanager/sessionaroundenablecallbacks andprocess()inRecognizer.recognize()and re-checkmanager/element/stoppedinisRecognizerActive() - Manager & UMD safety: Early-return on post-
destroy()set(),add(),on(), andemit(); guardundefinedarguments inon()/off(); guard missingtarget.dispatchEventintriggerDomEvent(); restoretry { window[exportName] = Hammer; } catch (e) {}and null-safewindow/document/module/navigatorchecks for frozen globals and non-browser SSR sandboxes - DOM clobbering & prototype pollution: Cache native DOM prototype getters (
nodeType,parentNode,ownerDocument,assignedSlot,defaultView,host) inhasParent()andgetWindowForElement()(handling slottedTextnodes and same-origin iframes); use null-prototype maps (Object.create(null)) forhandlers,oldCssProps,TOUCH_ACTION_MAP,TOUCH_INPUT_MAP,POINTER_INPUT_MAP,MOUSE_INPUT_MAP,targetIds, andactiveIds; reject''andObject.prototypekeys inprefixed() - Touch-action & velocity: Attach an auxiliary non-passive
touchmovefallback listener onPointerEventInputwhenSUPPORT_TOUCH && !appliedNative && _flags; prioritizepinch-zoomoverpan-x/pan-yincleanTouchActions()even without native support; schedule/cancel iOS WebKitrequestAnimationFramecommits on the element's owning window (getWindowForElement) with a function guard; restoredt < -VELOCITY_HORIZON_MSbackward-jump resets insrc/velocity.jsand non-negative wall-clock clamps (deltaTime,Tap,Press,QuickScale) - Manual test pages: Fix
nested.htmlcross-managerrequireFailure(), replaceinnerHTMLwith safe DOM APIs insimulator.html/input.html, and drop cleartexthttp://asset URLs - Built bundles:
hammer.js144.48 kB→hammer.min.js35.80 kB(12.31 kBgzip,11.11 kBbrotli);hammer.mjs146.42 kB→hammer.min.mjs37.15 kB(12.72 kBgzip,11.37 kBbrotli);hammer.node.mjs2.32 kB— all with unmangled2.xproperty names
CI/CD, Tooling & Testing
- Harden
.github/workflows/{ci,release,fuzz,ios}.ymlwithnpm ci --ignore-scripts, scopedpermissions, concurrency group infuzz.yml, 7-day artifact retention, and 7-day Dependabot cooldowns; pinios.ymltoappium@4.0.2,xcuitest@13.8.6, and SHA-256-verified prebuiltappium-webdriveragent@17.2.1plus afuzz_seedworkflow_dispatchinput (3369a4a) - Enable
"noUnusedLocals": trueintsconfig.json; reject non-numericFUZZ_SEEDvalues invitest.config.mjsandtests/ios/ios_safari.test.js; seednpm run test:coverage(FUZZ_SEED=${FUZZ_SEED:-20261204}); add"quickscale"and"zoom"package keywords - Fix
t=0timestamp clamping inrunSyntheticTouchTrace(),triggerSyntheticPoints(), and coalesced fuzz events (and forward-portrunSyntheticTracetimestamp fixes to3.0.0); stabilize CDP fast-swipe E2E test with explicit monotonic CDP timestamps; replace unconditional second-click retry inreal_pointer.test.jswith an explicit WebKit omitted-pointerdownresync; test all built UMD (hammer.js,hammer.min.js) and ESM (hammer.mjs,hammer.min.mjs) bundles across real browser gestures - Convert all 21 remaining
setTimeoutPromise unit tests (plusgestures.test.jsandnested_recognizers.test.js) to deterministic Vitest fake timers - Add standalone
hammer.mjsand minifiedhammer.min.mjs(+hammer.min.mjs.map) ES module bundles (default+ all static named exports, preservingwindow.Hammerfor2.ximport 'hammerjs'compatibility), plus a tinyhammer.node.mjswrapper underexports['.'].node.importeliminating Node mixedrequire/importdual-package instance splits, wired via"type": "commonjs","module", and a backwards-compatible"exports"map preserving legacy2.xsubpaths (./hammer,./hammer.js,./hammer.min.js,./src/*,./package.json) - Make build banner dates deterministic UTC with strict
SOURCE_DATE_EPOCHsupport inscripts/build.mjs, normalizerepository.urltogit+https://...(0publinterrors/warnings/suggestions), and declareviteexplicitly indevDependenciesfornpm run test:manual - Modernize
tests/manual/for iOS Safari & Android Chrome (addingindex.htmlhub,quick_scale.html,velocity_swipe.html,multitouch_edge.html,edge_cases.htmlwith live self-checks, bundle switcher forhammer.js/hammer.min.js/hammer.mjs/hammer.min.mjs, driver override, andnpm run test:manualVite LAN dev server withsrc/watch rebuilds) - Add
package-lock.jsonsync, unmangledhammer.min.js2.xproperty checks, frozen/null global UMD sandbox tests, andtests/unit/regressions.test.jscovering all hardening fixes and exact boundary/penconditions (c54da3c)
Full Changelog: v2.1.0-rc.5...v2.1.0-rc.6