
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
pressurize-js
Advanced tools
The First Open-Source JavaScript Pressure Detection Library for All Mobile Devices Without Specialized Hardware
pressurize.js is a groundbreaking JavaScript library that enables pressure detection on mobile devices without requiring built-in pressure sensors like 3D Touch. By leveraging the device's accelerometer and gyroscopic sensors, pressurize.js calculates the relative pressure exerted with each touch interaction, providing a new dimension of user input for web applications.
This library is the first of its kind, offering web developers the ability to detect pressure sensitivity on any modern mobile device (and even some laptops :D) equipped with motion sensors. pressurize.js opens up new possibilities for creating more intuitive and responsive user interfaces in web applications.
pressurize.js works by:
The library uses sophisticated algorithms to filter and process the sensor data, including averaging, median, and mode calculations to ensure accurate and stable pressure readings.
npm install pressurize-js
import { start, getPressure } from 'pressurize-js';
// Initialize the pressure detection
start();
// Get the current pressure value (0-1)
function update() {
const currentPressure = getPressure();
console.log(`Current pressure: ${currentPressure}`);
// Use the pressure value in your application
element.style.transform = `scale(${1 + currentPressure})`;
requestAnimationFrame(update);
}
update();
start(processingInterval = 75)
Initializes the pressure detection system and begins monitoring device motion.
Parameters:
processingInterval
(optional): Defines how frequently (in milliseconds) the pressure value is updated. The default value of 75ms is generally suitable for most applications.Note: When adjusting this parameter, try to optimize for accuracy by keeping the interval large enough to gather sufficient data, while maintaining a short enough interval to capture varying pressure values between user interactions. Higher values may provide more stable readings but less responsiveness, while lower values offer more immediate feedback but potentially less accuracy.
getPressure()
Returns the current calculated pressure value.
Returns:
pressurize.js requires devices with accelerometer and gyroscopic sensors. It works on most modern smartphones and tablets with these capabilities.
Your web application must request permission to access device motion and orientation events. This typically requires a user interaction (like a button click) before the following code:
requestAndStart
The requestAndStart
function is the recommended way to initialize pressurize.js because it handles the permission requirements for iOS devices while also starting the pressure detection system. Here's how it works and why it's important:
requestAndStart(processingInterval = 75)
This is the recommended function to initialize pressurize.js, as it handles device motion permissions properly.
Parameters:
processingInterval
(optional): Defines how frequently (in milliseconds) the pressure value is updated. Default is 75ms.Why use this function: iOS devices require explicit user permission before accessing device motion and orientation data. This function properly requests this permission and only starts the pressure detection if permission is granted.
Example usage:
import { requestAndStart, getPressure } from 'pressurize-js';
// Create a button for user interaction
const button = document.getElementById('start-button');
button.addEventListener('click', () => {
// Call requestAndStart when user interacts with the page
requestAndStart();
// Now you can start using the pressure values
updateUI();
});
function updateUI() {
const pressure = getPressure();
// Use pressure value in your application
requestAnimationFrame(updateUI);
}
Apple's iOS requires that DeviceMotionEvent permissions must be requested in response to a user gesture (like a button click). This is a security and privacy measure implemented by Apple to ensure users are aware when websites are accessing motion sensor data.
If you try to request these permissions without a user gesture:
This is why the demo page includes a button with the text "Request shig" that calls DeviceMotionEvent.requestPermission()
- it's demonstrating this required user interaction.
The requestAndStart
function should:
This approach ensures maximum compatibility across different devices and platforms while respecting user privacy.
if (typeof DeviceMotionEvent.requestPermission === 'function') {
DeviceMotionEvent.requestPermission()
.then(permissionState => {
if (permissionState === 'granted') {
start();
}
})
.catch(console.error);
} else {
// Handle regular non-iOS devices
start();
}
Check out the examples in the website for more detailed usage and implementation examples.
Contributions are welcome! Please feel free to submit a Pull Request.
Made with ❤️ by MaxDevv
FAQs
The First Open-Source JavaScript Pressure Detection Library for All Mobile Devices Without Specialized Hardware
The npm package pressurize-js receives a total of 8 weekly downloads. As such, pressurize-js popularity was classified as not popular.
We found that pressurize-js 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.