@frontfactory/readmore 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Front Factory
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @frontfactory/readmore
2
+
3
+ Lightweight, framework-agnostic plugin to clamp text to N lines with an ellipsis and a `Read more` / `Read less` toggle
4
+ button.
5
+
6
+ - Zero dependencies, ~1 KB
7
+ - TypeScript types included
8
+ - CSS-driven clamping via `-webkit-line-clamp` and a CSS custom property (`--readmore-lines`)
9
+ - The toggle button is only created when the text actually overflows
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @frontfactory/readmore
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { ReadMore } from '@frontfactory/readmore';
21
+ import '@frontfactory/readmore/style.css';
22
+
23
+ ReadMore.init('.excerpt', {
24
+ lines: 3
25
+ });
26
+ ```
27
+
28
+ Or instantiate against a single element:
29
+
30
+ ```ts
31
+ const el = document.querySelector<HTMLElement>('#bio');
32
+
33
+ if (el) new ReadMore(el, {
34
+ lines: 4
35
+ });
36
+ ```
37
+
38
+ ## Options
39
+
40
+ | Option | Type | Default | Description |
41
+ |-----------------|----------|------------------|-----------------------------------------------------|
42
+ | `lines` | `number` | `3` | Number of lines to clamp to. |
43
+ | `moreText` | `string` | `'Read more'` | Label of the button when the text is collapsed. |
44
+ | `lessText` | `string` | `'Read less'` | Label of the button when the text is expanded. |
45
+ | `buttonClass` | `string` | `'readmore-btn'` | Class applied to the toggle button. |
46
+ | `expandedClass` | `string` | `'is-expanded'` | Class applied to the target element while expanded. |
47
+
48
+ ## API
49
+
50
+ ```ts
51
+ const instance = new ReadMore(element, options);
52
+
53
+ instance.toggle(); // expand / collapse programmatically
54
+ instance.expanded; // boolean getter
55
+ instance.destroy(); // remove button, classes and listeners
56
+
57
+ ReadMore.init(selector, options); // returns ReadMore[]
58
+ ```
59
+
60
+ ## How it works
61
+
62
+ The plugin sets the CSS custom property `--readmore-lines` on the target element and toggles the `.readmore-clamp`
63
+ class. The bundled stylesheet uses that variable in a `-webkit-line-clamp` rule, so the ellipsis appears at the end of
64
+ the requested line. The toggle button is mounted right after the element only when the content actually overflows, and
65
+ unmounted again on resize if the text ends up fitting.
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@frontfactory/readmore",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight plugin to clamp text to N lines with ellipsis and a read more action.",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview",
10
+ "typecheck": "tsc --noEmit",
11
+ "prepare": "husky",
12
+ "release": "semantic-release"
13
+ },
14
+ "engines": {
15
+ "node": ">=20.19"
16
+ },
17
+ "main": "./dist/readmore.js",
18
+ "module": "./dist/readmore.js",
19
+ "types": "./dist/readmore.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/readmore.d.ts",
23
+ "import": "./dist/readmore.js"
24
+ },
25
+ "./style.css": "./dist/readmore.css",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "devDependencies": {
29
+ "@commitlint/cli": "^20.5.3",
30
+ "@commitlint/config-conventional": "^20.5.3",
31
+ "@semantic-release/changelog": "^6.0.3",
32
+ "@semantic-release/git": "^10.0.1",
33
+ "@semantic-release/github": "^12.0.6",
34
+ "conventional-changelog-conventionalcommits": "^9.3.1",
35
+ "husky": "^9.1.7",
36
+ "semantic-release": "^25.0.3",
37
+ "typescript": "^5.4.0",
38
+ "vite": "^8.0.11",
39
+ "vite-plugin-dts": "^5.0.0",
40
+ "vite-plugin-static-copy": "^4.1.0"
41
+ },
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "keywords": [
46
+ "readmore",
47
+ "expand",
48
+ "collapse",
49
+ "front-end"
50
+ ],
51
+ "license": "MIT",
52
+ "homepage": "https://github.com/front-factory/readmore",
53
+ "bugs": {
54
+ "url": "https://github.com/front-factory/readmore/issues"
55
+ },
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/front-factory/readmore.git"
59
+ },
60
+ "publishConfig": {
61
+ "access": "public"
62
+ }
63
+ }