npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monitor-text-zoom

v1.0.2

Published

Adds classes to the DOM at specified text zoom levels

Downloads

4

Readme

monitor-text-zoom

  • Adds classes to the DOM, at specified text zoom levels, to help with page layout.
  • Optionally stack Bootstrap columns when a specified text zoom level is reached.

Installation

1. Via file links

Download the code zip and extract dist/monitor-text-zoom.js and, if you want to stack Bootstrap columns, dist/monitor-text-zoom.css.

<script type="text/javascript" src="/path/to/monitor-text-zoom.js"></script>
<!--If you want to stack Bootstrap columns: -->
<link href="/path/to/monitor-text-zoom.css" rel="stylesheet" />

2. Via package installation

npm install monitor-text-zoom
import monitorTextZoom from "monitor-text-zoom";
// If you want to stack Bootstrap columns:
import "/path/to/node_modules/monitor-text-zoom/dist/monitor-text-zoom.css";

Initialize

Initialize with the size, in pixels, of 1 rem:

window.addEventListener("DOMContentLoaded", () => {
    monitorTextZoom.init({
        remSize: 16
    });
});

Stack bootstrap columns when a specified text zoom level is reached

monitorTextZoom.init({
    bootstrap: 5 // 3 | 4 | 5
});

Specify the class stack-tz-{value} to stack the columns if the text zoom percentage is ≥ {value}.

This example stacks the columns if the text zoom is ≥ 130%

<div class="row stack-tz-130">
    <div class="col-sm-6"></div>
    <div class="col-sm-6"></div>
</div>

Often, different styles are applied to the un-stacked columns which you may want to omit when the columns are stacked due to text zoom. When stacked, the class .bs{bootstrap version}-tz-query-match is attached to the row. You can used this to ensure that the additional styles are not applied:

@media (min-width: 768px) {
    .row:not(.bs5-tz-query-match) {
    }
}

Add classes to the body node at specific text zoom levels

monitorTextZoom.init({
    attachZoomLevels: [110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 250, 300, 350, 400, 450, 500]
});

For each specified text zoom level, the class tz-{value} is attached to the body node when the level is ≥ to {value}.

For instance, if the current text zoom level is 130, the body node will have the following classes attached: tz-110, tz-120 & tz-130.

body.tz-110 .my-node {}
body.tz-120 .my-node {}
body.tz-130 .some-other-node {}
...

Finer control at node level

1. Single query

Add a query to a node. When matched, the class tz-query-match is added to the node. In the following example, the query is matched if the current text zoom level ≥ 150%:

<div id="element-1" data-query-tz="gte:150"></div>
#element-1.tz-query-match {
}

As well as gte, you can specify gt, lt, lte and eq.

2. Specify more than one query per node

Specify multiple queries separated by a space. Append the subsequent queries with [{class name}]. You can also append a class name to the first query or omit to have the default tz-query-match attached.

<div id="element-1" data-query-tz="gte:150 gt:400[massive-zoom-amount]"></div>
#element-1.tz-query-match {
}
#element-1.massive-zoom-amount {
}

3. Complex queries

Use + and | to specify AND and OR operators. In the following example, the class tz-query-match is attached if the current text zoom level is (≥ 150% AND ≤ 200%) OR ≥ 300%:

<div data-query-tz="gte:150+lte:200|gte:300"></div>

Check the current text zoom level

const factor = monitorTextZoom.getZoom().factor;
const percentage = monitorTextZoom.getZoom().percentage;

Handle text zoom level change

1. Via init

monitorTextZoom.init({
    changed: e => {
        console.log(e.factor, e.percentage);
    }
});

2. Handle event

document.addEventListener("textzoom", e => {
    e = e.detail;
    console.log(e.factor, e.percentage);
});

To call changed and raise textzoom at initialization time:

monitorTextZoom.init({
    notifyLevelOnInit: true
});

Requery for dynamic content

If you add dynamic content with stack-tz-{value} or data-query-tz, a requery is required:

monitorTextZoom.requery();

Credits

  • Based on: https://github.com/zoltan-dulac/text-zoom-resize