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

@livelybone/rem-init

v3.3.0

Published

rem, pixel, viewport, for adapting various interfaces

Downloads

28

Readme

@livelybone/rem-init

NPM Version Download Month gzip with dependencies: .8kb pkg.module

pkg.module supported, which means that you can apply tree-shaking in you project

rem, pixel, viewport, for adapting various interfaces

Intro

px with rem conversion depends on the font-size of html tag, when the font-size of html is 625%, 1rem is equal to 100px

You can use rem everywhere, include font-size.

This solution isn't compatible with ie8

If your client is pc, the function will set 1rem to be 100px

If your client is mobile, the function will set 1rem to be (100 * (window.devicePixelRatio || 1))px

For adapting various interfaces, you can use vw vh vmin vmax simultaneously

repository

https://github.com/livelybone/rem-init.git

Demo

http://github.com/livelybone/rem-init#readme

Installation

npm i -S @livelybone/rem-init

Global name

RemInit

Usage

import RemInit from '@livelybone/rem-init';

Use in html, see what your can use in CDN: unpkg

<-- use what you want -->
<script src="https://unpkg.com/@livelybone/rem-init/lib/umd/<--module-->.js"></script>

Params

| Name | Type | DefaultValue | Description | | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------ | | options | Object<{ pageNoScale: Boolean, pageScalable: Boolean, pageScaleMiddleware: Function, pageScaleMaxFactor: Number }> | { pageNoScale: false, pageScalable: false, pageScaleMiddleware: null, pageScaleMaxFactor: 1 } | |

pageNoScale: When it is equal to true, the tool will force to set the initial-scale value of viewport to 1

pageScalable: When it is equal to true, the tool will remove the user-scalable field of viewport, which means that you can scale your pages on the range depends on minimum-scale and maximum-scale

pageScaleMiddleware: (fontScale: Number, isMobile: Boolean) => pageScale You can rewrite the pageScale value which is default to be 1 / fontScale on your own will by this function. It only works when pageNoScale is not equal to true

pageScaleMaxFactor: It only works when pageScalable is equal to true. When pageScaleMaxFactor == false, the tool will remove the maximum-scale field of viewport, otherwise, the function will set the maximum-scale value to Math.max(1, +options.pageScaleMaxFactor || 0) * initialScale

Example

// assume
window.devicePixelRatio = 2
window.isMobile = true

// results
RemInit({pageNoScale: true}) // => viewport: width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no

RemInit({pageScalable: true, pageScaleMaxFactor: true}) // => viewport: width=device-width, initial-scale=0.5, minimum-scale=0.5

RemInit({pageScalable: true, pageScaleMaxFactor: 1}) // => viewport: width=device-width, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5

RemInit({pageScalable: true, pageScaleMaxFactor: 0.5}) // => viewport: width=device-width, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5

RemInit({pageScalable: true, pageScaleMaxFactor: 4}) // => viewport: width=device-width, initial-scale=0.5, minimum-scale=0.5, maximum-scale=2

RemInit({pageScaleMaxFactor: 4}) // => viewport: width=device-width, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, user-scalable=no

RemInit({pageScaleMiddleware: (fontScale, isMobile) => (isMobile ? 1 / fontScale / fontScale : 1)}) // => viewport: width=device-width, initial-scale=0.25, minimum-scale=0.25, maximum-scale=0.25

RemInit({pageScalable: true, pageScaleMaxFactor: 4, pageScaleMiddleware: (fontScale, isMobile) => (isMobile ? 1 / fontScale / fontScale : 1)}) // => viewport: width=device-width, initial-scale=0.25, minimum-scale=0.25, maximum-scale=1

Extra

The function will add isMobile field to window if isMobile is not exist in window

The function will add rootSize field to window, you can use it to convert rem with px

var rootSize = {
  value: Number, // means: 1rem = [value]px
  unit: 'px/rem',
  rem2px: Function,
  px2rem: Function,
}