@altano/textfit 0.0.3 → 0.0.4
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/README.md +1 -1
- package/dist/{textFit.d.ts → index.d.ts} +1 -1
- package/dist/{textFit.js → index.js} +11 -11
- package/package.json +18 -15
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/index.ts
|
|
2
2
|
var defaultSettings = {
|
|
3
3
|
multiLine: false,
|
|
4
4
|
detectMultiLine: true,
|
|
@@ -23,11 +23,11 @@ function processItem(el, settings) {
|
|
|
23
23
|
if (!settings.reProcess) {
|
|
24
24
|
el.setAttribute("textFitted", "1");
|
|
25
25
|
}
|
|
26
|
-
let innerSpan
|
|
26
|
+
let innerSpan;
|
|
27
27
|
let low, mid, high;
|
|
28
|
-
originalHTML = el.innerHTML;
|
|
29
|
-
originalWidth = innerWidth(el);
|
|
30
|
-
originalHeight = innerHeight(el);
|
|
28
|
+
const originalHTML = el.innerHTML;
|
|
29
|
+
const originalWidth = innerWidth(el);
|
|
30
|
+
const originalHeight = innerHeight(el);
|
|
31
31
|
if (!originalWidth || !settings.widthOnly && !originalHeight) {
|
|
32
32
|
if (!settings.widthOnly)
|
|
33
33
|
throw new Error(
|
|
@@ -59,7 +59,7 @@ function processItem(el, settings) {
|
|
|
59
59
|
el.className.replace("textFitAlignVertFlex", "");
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
let multiLine = settings.multiLine;
|
|
63
63
|
if (settings.detectMultiLine && !multiLine && innerSpan.getBoundingClientRect().height >= parseInt(window.getComputedStyle(innerSpan).fontSize, 10) * 2) {
|
|
64
64
|
multiLine = true;
|
|
65
65
|
}
|
|
@@ -68,11 +68,11 @@ function processItem(el, settings) {
|
|
|
68
68
|
}
|
|
69
69
|
low = settings.minFontSize;
|
|
70
70
|
high = settings.maxFontSize;
|
|
71
|
-
|
|
71
|
+
let size = low;
|
|
72
72
|
while (low <= high) {
|
|
73
73
|
mid = high + low >> 1;
|
|
74
74
|
innerSpan.style.fontSize = mid + "px";
|
|
75
|
-
|
|
75
|
+
const innerSpanBoundingClientRect = innerSpan.getBoundingClientRect();
|
|
76
76
|
if (innerSpanBoundingClientRect.width <= originalWidth && (settings.widthOnly || innerSpanBoundingClientRect.height <= originalHeight)) {
|
|
77
77
|
size = mid;
|
|
78
78
|
low = mid + 1;
|
|
@@ -87,15 +87,15 @@ function processItem(el, settings) {
|
|
|
87
87
|
innerSpan.style.fontSize = size + "px";
|
|
88
88
|
}
|
|
89
89
|
function innerHeight(el) {
|
|
90
|
-
|
|
90
|
+
const style = window.getComputedStyle(el, null);
|
|
91
91
|
return el.getBoundingClientRect().height - parseInt(style.getPropertyValue("padding-top"), 10) - parseInt(style.getPropertyValue("padding-bottom"), 10);
|
|
92
92
|
}
|
|
93
93
|
function innerWidth(el) {
|
|
94
|
-
|
|
94
|
+
const style = window.getComputedStyle(el, null);
|
|
95
95
|
return el.getBoundingClientRect().width - parseInt(style.getPropertyValue("padding-left"), 10) - parseInt(style.getPropertyValue("padding-right"), 10);
|
|
96
96
|
}
|
|
97
97
|
function isElement(o) {
|
|
98
|
-
return typeof HTMLElement === "object" ? o instanceof HTMLElement : o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string";
|
|
98
|
+
return typeof HTMLElement === "object" ? o instanceof HTMLElement : o != null && typeof o === "object" && o !== null && "nodeType" in o && o.nodeType === 1 && "nodeName" in o && typeof o.nodeName === "string";
|
|
99
99
|
}
|
|
100
100
|
function hasClass(element, cls) {
|
|
101
101
|
return (" " + element.className + " ").indexOf(" " + cls + " ") > -1;
|
package/package.json
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/textfit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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
|
-
"directories": {
|
|
6
|
-
"example": "examples"
|
|
7
|
-
},
|
|
8
5
|
"files": [
|
|
9
6
|
"dist/**/*.js",
|
|
10
7
|
"dist/**/*.d.ts"
|
|
11
8
|
],
|
|
12
9
|
"type": "module",
|
|
13
10
|
"sideEffects": false,
|
|
14
|
-
"exports": "./dist/
|
|
15
|
-
"types": "./dist/
|
|
11
|
+
"exports": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
16
13
|
"repository": {
|
|
17
14
|
"type": "git",
|
|
18
15
|
"url": "https://github.com/altano/npm-packages",
|
|
19
|
-
"directory": "packages/
|
|
16
|
+
"directory": "packages/textfit"
|
|
20
17
|
},
|
|
21
|
-
"homepage": "https://github.com/altano/npm-packages/tree/main/packages/
|
|
18
|
+
"homepage": "https://github.com/altano/npm-packages/tree/main/packages/textfit",
|
|
22
19
|
"keywords": [
|
|
23
20
|
"textfit",
|
|
24
21
|
"fit",
|
|
@@ -30,21 +27,27 @@
|
|
|
30
27
|
],
|
|
31
28
|
"license": "MIT",
|
|
32
29
|
"devDependencies": {
|
|
33
|
-
"
|
|
30
|
+
"@playwright/test": "1.40.0",
|
|
34
31
|
"typescript": "^5.4.2",
|
|
35
|
-
"
|
|
32
|
+
"vite": "^5.2.4",
|
|
36
33
|
"@altano/tsconfig": "0.0.0"
|
|
37
34
|
},
|
|
38
35
|
"publishConfig": {
|
|
39
36
|
"access": "public"
|
|
40
37
|
},
|
|
41
38
|
"scripts": {
|
|
42
|
-
"build": "tsup
|
|
43
|
-
"build:types": "tsc --
|
|
44
|
-
"dev": "
|
|
39
|
+
"build": "tsup --config build-config/tsup.config.browser.ts",
|
|
40
|
+
"build:types": "tsc --project tsconfig.declarations.json",
|
|
41
|
+
"dev": "pnpm run build --watch",
|
|
45
42
|
"format": "prettier --check src",
|
|
46
43
|
"format:fix": "prettier --write src",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
44
|
+
"lint": "eslint package.json src/**/*.ts*",
|
|
45
|
+
"lint:fix": "TIMING=1 pnpm lint --fix",
|
|
46
|
+
"lint:timing": "TIMING=1 pnpm lint",
|
|
47
|
+
"test:e2e": "playwright test",
|
|
48
|
+
"test:e2e:server": "vite --strictPort --port 8173 ./tests/e2e",
|
|
49
|
+
"test:e2e:ui": "playwright test --ui",
|
|
50
|
+
"typecheck:src": "tsc --noEmit",
|
|
51
|
+
"typecheck:test": "tsc --noEmit --project ./tests/tsconfig.json"
|
|
49
52
|
}
|
|
50
53
|
}
|