adaptable-text
Advanced tools
Comparing version 2.1.1 to 3.0.0
{ | ||
"name": "adaptable-text", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"description": "Adapt font size to a specified width.", | ||
"main": "lib/adaptable-text.js", | ||
"jsnext:main": "lib/adaptable-text.module.js", | ||
"module": "lib/adaptable-text.module.js", | ||
"license": "MIT", | ||
"repository": "https://github.com/dmnsgn/adaptable-text", | ||
"author": { | ||
"name": "Damien Seguin", | ||
"url": "https://dmnsgn.me" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"keywords": [ | ||
@@ -22,28 +10,31 @@ "responsive", | ||
], | ||
"scripts": { | ||
"dev": "rollup -c -w -m inline", | ||
"clean": "rm -rf lib", | ||
"build": "rollup -c", | ||
"test": "budo test/index.js --open --live", | ||
"prepublishOnly": "npm run build" | ||
"homepage": "https://github.com/dmnsgn/adaptable-text", | ||
"bugs": "https://github.com/dmnsgn/adaptable-text/issues", | ||
"repository": "dmnsgn/adaptable-text", | ||
"funding": [ | ||
{ | ||
"type": "individual", | ||
"url": "https://paypal.me/dmnsgn" | ||
}, | ||
{ | ||
"type": "individual", | ||
"url": "https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3" | ||
} | ||
], | ||
"license": "MIT", | ||
"author": "Damien Seguin (https://github.com/dmnsgn)", | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "types/index.d.ts", | ||
"dependencies": { | ||
"clamp": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.25.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-latest": "^6.24.1", | ||
"budo": "^10.0.4", | ||
"prettier": "^1.5.3", | ||
"regenerator-runtime": "^0.10.5", | ||
"rollup": "^0.43.1", | ||
"rollup-plugin-babel": "^3.0.1", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-watch": "^4.3.1", | ||
"uglify-js": "^3.0.23" | ||
"es-module-shims": "^0.10.3" | ||
}, | ||
"dependencies": { | ||
"clamp": "^1.0.1" | ||
"engines": { | ||
"node": ">=15.0.0", | ||
"npm": ">=7.0.0" | ||
} | ||
} |
131
README.md
# adaptable-text | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
[![npm version](https://img.shields.io/npm/v/adaptable-text)](https://www.npmjs.com/package/adaptable-text) | ||
[![stability-stable](https://img.shields.io/badge/stability-stable-green.svg)](https://www.npmjs.com/package/adaptable-text) | ||
[![npm minzipped size](https://img.shields.io/bundlephobia/minzip/adaptable-text)](https://www.npmjs.com/package/adaptable-text) | ||
[![dependencies](https://img.shields.io/david/dmnsgn/adaptable-text)](https://github.com/dmnsgn/adaptable-text/blob/main/package.json) | ||
[![types](https://img.shields.io/npm/types/adaptable-text)](https://github.com/microsoft/TypeScript) | ||
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-fa6673.svg)](https://conventionalcommits.org) | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-Prettier-f8bc45.svg?logo=prettier)](https://github.com/prettier/prettier) | ||
[![linted with eslint](https://img.shields.io/badge/linted_with-ES_Lint-4B32C3.svg?logo=eslint)](https://github.com/eslint/eslint) | ||
[![license](https://img.shields.io/github/license/dmnsgn/adaptable-text)](https://github.com/dmnsgn/adaptable-text/blob/main/LICENSE.md) | ||
Adapt font size to a specified width. | ||
> Adapt font size to a specified width. | ||
[![paypal](https://img.shields.io/badge/donate-paypal-informational?logo=paypal)](https://paypal.me/dmnsgn) | ||
[![coinbase](https://img.shields.io/badge/donate-coinbase-informational?logo=coinbase)](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3) | ||
[![twitter](https://img.shields.io/twitter/follow/dmnsgn?style=social)](https://twitter.com/dmnsgn) | ||
## Install | ||
![](https://raw.githubusercontent.com/dmnsgn/adaptable-text/main/screenshot.gif) | ||
## Installation | ||
```bash | ||
npm install adaptable-text | ||
``` | ||
$ npm install --save adaptable-text | ||
``` | ||
@@ -17,51 +30,85 @@ ## Usage | ||
```js | ||
const textToAdapt = new AdaptableText(document.querySelector(".textToAdapt"), { | ||
step: 0.1, | ||
minFontSize: 10, | ||
width: null | ||
}); | ||
textToAdapt.init(); | ||
import adaptableText from "adaptable-text"; | ||
console.log(adaptableText); | ||
``` | ||
// Adapt | ||
const adapt = () => { | ||
textToAdapt.setWidth(); | ||
textToAdapt.adapt(); | ||
}; | ||
## API | ||
// Listen for a resize event | ||
window.addEventListener("resize", adapt); | ||
<!-- api-start --> | ||
// Kick off | ||
requestIdleCallback(() => { | ||
adapt(); | ||
}); | ||
``` | ||
## Classes | ||
|Key|Description | ||
|:---------|:---------| | ||
|**step**|The step used by the generator to calculate the width of the element| | ||
|**minFontSize**|A minimum font size for the element (max would be the size defined in a stylesheet retrieved by `window.getComputedStyle(this.element)`)| | ||
|**width**|A maximum widht for the container.| | ||
<dl> | ||
<dt><a href="#AdaptableText">AdaptableText</a></dt> | ||
<dd></dd> | ||
</dl> | ||
## Scripts | ||
### Dev | ||
## Typedefs | ||
```bash | ||
npm run dev | ||
``` | ||
<dl> | ||
<dt><a href="#Options">Options</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
</dl> | ||
### Test | ||
<a name="AdaptableText"></a> | ||
```bash | ||
npm run test | ||
``` | ||
## AdaptableText | ||
### Build | ||
**Kind**: global class | ||
```bash | ||
npm run build | ||
``` | ||
- [AdaptableText](#AdaptableText) | ||
- [new AdaptableText(element, [options])](#new_AdaptableText_new) | ||
- [.init()](#AdaptableText+init) | ||
- [.setWidth()](#AdaptableText+setWidth) | ||
- [.adapt()](#AdaptableText+adapt) | ||
<a name="new_AdaptableText_new"></a> | ||
### new AdaptableText(element, [options]) | ||
Creates an instance of AdaptableText. | ||
| Param | Type | | ||
| --------- | -------------------------------- | | ||
| element | <code>HTMLElement</code> | | ||
| [options] | [<code>Options</code>](#Options) | | ||
<a name="AdaptableText+init"></a> | ||
### adaptableText.init() | ||
Initialise the adaptor. | ||
**Kind**: instance method of [<code>AdaptableText</code>](#AdaptableText) | ||
<a name="AdaptableText+setWidth"></a> | ||
### adaptableText.setWidth() | ||
Set the desired width for adaptation from options.width or getBoundingClientRect().width | ||
**Kind**: instance method of [<code>AdaptableText</code>](#AdaptableText) | ||
<a name="AdaptableText+adapt"></a> | ||
### adaptableText.adapt() | ||
Adapt font size to a specified width | ||
**Kind**: instance method of [<code>AdaptableText</code>](#AdaptableText) | ||
<a name="Options"></a> | ||
## Options : <code>Object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | Default | Description | | ||
| ------------- | ------------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | ||
| [step] | <code>number</code> | <code>0.5</code> | The step used by the generator to calculate the width of the element. | | ||
| [minFontSize] | <code>number</code> | <code>0</code> | A minimum font size for the element (max would be the size defined in a stylesheet retrieved by `window.getComputedStyle(this.element)`). | | ||
| [width] | <code>number</code> | <code></code> | A maximum widht for the container.. | | ||
<!-- api-end --> | ||
## License | ||
MIT © [Damien Seguin](https://github.com/dmnsgn) | ||
MIT. See [license file](https://github.com/dmnsgn/adaptable-text/blob/main/LICENSE.md). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
0
114
Yes
12915
6
195
1