@altano/textfit 0.0.1 → 0.0.3
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.
- package/dist/textFit.d.ts +3 -4
- package/dist/textFit.js +10 -6
- package/package.json +19 -13
package/dist/textFit.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Uses binary search to fit text with minimal layout calls.
|
|
12
12
|
* Version 2.0 does not use jQuery.
|
|
13
13
|
*/
|
|
14
|
-
interface Options {
|
|
14
|
+
export interface Options {
|
|
15
15
|
/**
|
|
16
16
|
* if true, textFit will not set white-space: no-wrap
|
|
17
17
|
*/
|
|
@@ -41,6 +41,5 @@ interface Options {
|
|
|
41
41
|
*/
|
|
42
42
|
sizeMultipleOf?: number;
|
|
43
43
|
}
|
|
44
|
-
declare function textFit(elements: HTMLElement | HTMLElement[], options?: Options): void;
|
|
45
|
-
|
|
46
|
-
export { Options, textFit };
|
|
44
|
+
export declare function textFit(elements: HTMLElement | HTMLElement[], options?: Options): void;
|
|
45
|
+
//# sourceMappingURL=textFit.d.ts.map
|
package/dist/textFit.js
CHANGED
|
@@ -12,9 +12,9 @@ var defaultSettings = {
|
|
|
12
12
|
function textFit(elements, options = {}) {
|
|
13
13
|
const settings = Object.assign({}, defaultSettings, options);
|
|
14
14
|
const els = Array.isArray(elements) ? elements : [elements];
|
|
15
|
-
|
|
16
|
-
processItem(
|
|
17
|
-
}
|
|
15
|
+
els.forEach((el) => {
|
|
16
|
+
processItem(el, settings);
|
|
17
|
+
});
|
|
18
18
|
}
|
|
19
19
|
function processItem(el, settings) {
|
|
20
20
|
if (!isElement(el) || !settings.reProcess && el.getAttribute("textFitted")) {
|
|
@@ -30,9 +30,13 @@ function processItem(el, settings) {
|
|
|
30
30
|
originalHeight = innerHeight(el);
|
|
31
31
|
if (!originalWidth || !settings.widthOnly && !originalHeight) {
|
|
32
32
|
if (!settings.widthOnly)
|
|
33
|
-
throw new Error(
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Set a static height and width on the target element " + el.outerHTML + " before using textFit!"
|
|
35
|
+
);
|
|
34
36
|
else
|
|
35
|
-
throw new Error(
|
|
37
|
+
throw new Error(
|
|
38
|
+
"Set a static width on the target element " + el.outerHTML + " before using textFit!"
|
|
39
|
+
);
|
|
36
40
|
}
|
|
37
41
|
if (originalHTML.indexOf("textFitted") === -1) {
|
|
38
42
|
innerSpan = document.createElement("span");
|
|
@@ -77,7 +81,7 @@ function processItem(el, settings) {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
if (settings.sizeMultipleOf > 1) {
|
|
80
|
-
size = size % settings.sizeMultipleOf;
|
|
84
|
+
size = size - size % settings.sizeMultipleOf;
|
|
81
85
|
}
|
|
82
86
|
if (innerSpan.style.fontSize != size + "px")
|
|
83
87
|
innerSpan.style.fontSize = size + "px";
|
package/package.json
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/textfit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A fast, jQuery-free text sizing component that quickly fits single and multi-line text to the width (and optionally height) of its container.",
|
|
5
5
|
"directories": {
|
|
6
6
|
"example": "examples"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist/**/*.js",
|
|
10
|
+
"dist/**/*.d.ts"
|
|
10
11
|
],
|
|
11
12
|
"type": "module",
|
|
12
13
|
"sideEffects": false,
|
|
13
14
|
"exports": "./dist/textFit.js",
|
|
14
15
|
"types": "./dist/textFit.d.ts",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
17
|
-
"build": "tsup src/textFit.ts --format esm --dts",
|
|
18
|
-
"dev": "tsup src/textFit.ts --watch --format esm --dts",
|
|
19
|
-
"format": "prettier --write src",
|
|
20
|
-
"build-example": "sh examples/mk-examples.sh",
|
|
21
|
-
"prepublish": "npm run build"
|
|
22
|
-
},
|
|
23
16
|
"repository": {
|
|
24
17
|
"type": "git",
|
|
25
18
|
"url": "https://github.com/altano/npm-packages",
|
|
26
19
|
"directory": "packages/textFit"
|
|
27
20
|
},
|
|
21
|
+
"homepage": "https://github.com/altano/npm-packages/tree/main/packages/textFit",
|
|
28
22
|
"keywords": [
|
|
29
23
|
"textfit",
|
|
30
24
|
"fit",
|
|
@@ -35,10 +29,22 @@
|
|
|
35
29
|
"Alan Norbauer <altano@gmail.com> (https://alan.norbauer.com/)"
|
|
36
30
|
],
|
|
37
31
|
"license": "MIT",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.0.2",
|
|
34
|
+
"typescript": "^5.4.2",
|
|
35
|
+
"vitest": "^1.3.1",
|
|
36
|
+
"@altano/tsconfig": "0.0.0"
|
|
37
|
+
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/textFit.ts --format esm --onSuccess \"pnpm build:types\"",
|
|
43
|
+
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
44
|
+
"dev": "tsup src/textFit.ts --watch --format esm --dts",
|
|
45
|
+
"format": "prettier --check src",
|
|
46
|
+
"format:fix": "prettier --write src",
|
|
47
|
+
"build-example": "sh examples/mk-examples.sh",
|
|
48
|
+
"prepublish": "pnpm build"
|
|
43
49
|
}
|
|
44
|
-
}
|
|
50
|
+
}
|