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

@xlou/viewport

v1.0.0

Published

Tools for Adapting Pages Based on Screen Size in Front-End Development, such as Mobile Responsiveness.

Downloads

3

Readme

Languages

Introduction

  • Solve the problem of page adaptation in H5 development, especially mobile development
  • Excellent performance, the page don't need to be re-rendered

Principle

  • 1rem is equal to the "font-size" of the html root element, the default is 16px
  • Dynamically changing the font-size of the root can change the size of the rem

Usage

Using the Script Tag

<script src="https://unpkg.com/@xlou/[email protected]/dist/umd/viewport.min.js"></script>
<!-- It's recommended to download and use the file locally -->
<script>
  /* After including this JS file, the viewport object will be available on the window */
  vp.init({/* options */})
</script>

In a Node.js Project

Installation

npm i @xlou/viewport -S

In main.js or main.ts

/* Using the entire package */
import vp from '@xlou/viewport'

/* Recommended configuration on the mobile */
vp.init({
  width: 375, // The design draft here is 375px, and if it's 750px, then set it to 750.
  fontSize: '0.14rem'
})

/* PC recommended configuration (design draft is 1920px)  */
vp.init({
  width: 1920,
  metaViewport: false,
  fontSize: '0.14rem'
})

API

vp

|Key|Type|Description| |----|----|----| |init|function|Init the viewport| |info|object|Return the informations of viewport that current page used|

interface Options {
  width?: number;
  mobile?: boolean;
  fontSize?: string;
  metaViewport?: boolean;
  userScalable?: string | null;
  initialScale?: string | null;
  minimumScale?: string | null;
  maximumScale?: string | null;
}
interface StoreOptions {
  options: Options;
  docInfo: {
    meta: Element;
    rootSize: string;
  };
}
const vp: {
  init(options: Options): void;
  readonly info: StoreOptions;
}

Introduction to init options

|Key|Type|Default|Supported values|Description| |----|----|----|----|----| |width|number|375|number|The width of the target window (the number of window units)| |mobile|boolean|true|boolean|Whether to open the mobile compatibility mode, compatible with the browsers of WeChat and QQ| |fontSize|String|"0.16rem"|string|The default font-size of the page, set on the body tag, defaults to "0.16rem" in mobile compatibility mode| |metaViewport|boolean|true|boolean|Whether to use the <meta name="viewport"> tag| |userScalable|string | null|"no"|"yes","no",null|Meta tag related, whether to support user scalable| |initialScalable|string | null|"1.0"|string,null|Meta tag related, initial scaling value| |minimumScale|string|null|string,null|Meta tag related, min scaling value| |maximumScale|string|null|string,null|Meta tag related, max scaling value|

If the attribute that supports "null" is set to null, the "meta" tag will not configure the attribute.

When "mobile" is set to false, for example, the width of the target in the design is 20px, then set 20rem in the code.
When "mobile" is set to true (use the mobile compatibility mode), if the width of the target in the design is 20px, then set 0.2rem in the code (that is, divide the design value by 100).

Introduction to info attributes

docInfo:

  • meta: HTMLMetaElement, return meta tag of this page

  • rootSize: string, return the font-size of root

options: object, return the options of "vp" this page