@sharadox/web-library 0.6.0 → 0.7.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.
- package/README.md +18 -16
- package/distribution/layout/on-screen/index.d.ts +20 -0
- package/distribution/layout/on-screen/index.d.ts.map +1 -0
- package/distribution/layout/on-screen/index.js +12 -0
- package/distribution/layout/on-screen/index.js.map +1 -0
- package/distribution/navigation/soft-navigation/index.d.ts +10 -1
- package/distribution/navigation/soft-navigation/index.d.ts.map +1 -1
- package/distribution/navigation/soft-navigation/index.js +12 -1
- package/distribution/navigation/soft-navigation/index.js.map +1 -1
- package/distribution/text/separate/index.d.ts +2 -2
- package/distribution/text/separate/index.js +2 -2
- package/distribution/text/separator/index.d.ts +9 -0
- package/distribution/text/separator/index.d.ts.map +1 -0
- package/distribution/text/separator/index.js +9 -0
- package/distribution/text/separator/index.js.map +1 -0
- package/llms.txt +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,22 +27,24 @@ pnpm add @sharadox/web-library
|
|
|
27
27
|
|
|
28
28
|
Import each utility by its path:
|
|
29
29
|
|
|
30
|
-
| Import | Export
|
|
31
|
-
| -------------------------------------------- |
|
|
32
|
-
| `@sharadox/web-library/type-guard/is-string` | `isString(value)`
|
|
33
|
-
| `…/type-guard/is-non-empty-string` | `isNonEmptyString(value)`
|
|
34
|
-
| `…/type-guard/is-number` | `isNumber(value)`: finite numbers only
|
|
35
|
-
| `…/type-guard/is-boolean` | `isBoolean(value)`
|
|
36
|
-
| `…/type-guard/is-record` | `isRecord(value)`: plain objects only
|
|
37
|
-
| `…/type-guard/is-defined` | `isDefined(value)`: not `null`/`undefined`
|
|
38
|
-
| `…/class-name` | `classNames(...names)`
|
|
39
|
-
| `…/html/escape` | `escapeHtml(text)`
|
|
40
|
-
| `…/text/
|
|
41
|
-
| `…/
|
|
42
|
-
| `…/math/
|
|
43
|
-
| `…/math/
|
|
44
|
-
| `…/
|
|
45
|
-
| `…/
|
|
30
|
+
| Import | Export | Example |
|
|
31
|
+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
|
|
32
|
+
| `@sharadox/web-library/type-guard/is-string` | `isString(value)` | `isString("a") // true` |
|
|
33
|
+
| `…/type-guard/is-non-empty-string` | `isNonEmptyString(value)` | `isNonEmptyString("") // false` |
|
|
34
|
+
| `…/type-guard/is-number` | `isNumber(value)`: finite numbers only | `isNumber(NaN) // false` |
|
|
35
|
+
| `…/type-guard/is-boolean` | `isBoolean(value)` | `isBoolean(false) // true` |
|
|
36
|
+
| `…/type-guard/is-record` | `isRecord(value)`: plain objects only | `isRecord([]) // false` |
|
|
37
|
+
| `…/type-guard/is-defined` | `isDefined(value)`: not `null`/`undefined` | `[1, undefined].filter(isDefined) // [1]` |
|
|
38
|
+
| `…/class-name` | `classNames(...names)` | `classNames("a", false, "b") // "a b"` |
|
|
39
|
+
| `…/html/escape` | `escapeHtml(text)` | `escapeHtml("<b>") // "<b>"` |
|
|
40
|
+
| `…/text/separator` | `SEPARATOR` ("·"), the separator every Sharadox text uses | `separate(SEPARATOR, "Contact", "Ana") // "Contact · Ana"` |
|
|
41
|
+
| `…/text/separate` | `separate(separator, ...parts)` | `separate(SEPARATOR, "Contact", "Ana") // "Contact · Ana"` |
|
|
42
|
+
| `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
|
|
43
|
+
| `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
|
|
44
|
+
| `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
|
|
45
|
+
| `…/assert/never` | `assertNever(value)`: exhaustive `switch` checks | `default: return assertNever(kind)` |
|
|
46
|
+
| `…/navigation/soft-navigation` | `beginSoftNavigation()`, `isSoftNavigation()`, `markSoftNavigationDocument()`, `endSoftNavigationDocument()`: a page rebuilt in place (language switch) skips entrance effects | `const [skip] = useState(isSoftNavigation)` |
|
|
47
|
+
| `…/layout/on-screen` | `isOnScreen(element)`: any part inside the viewport now | `if (isOnScreen(card)) …` |
|
|
46
48
|
|
|
47
49
|
## Develop
|
|
48
50
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The little of an element and a window this needs (this library runs without DOM types). */
|
|
2
|
+
type Measurable = {
|
|
3
|
+
getBoundingClientRect(): {
|
|
4
|
+
top: number;
|
|
5
|
+
left: number;
|
|
6
|
+
bottom: number;
|
|
7
|
+
right: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Whether any part of an element is inside the viewport right now.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* if (isOnScreen(card)) card.classList.add("shown");
|
|
17
|
+
*/
|
|
18
|
+
export declare function isOnScreen(element: Measurable): boolean;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/layout/on-screen/index.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,KAAK,UAAU,GAAG;IAChB,qBAAqB,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACtH,CAAC;AAGF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAMvD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether any part of an element is inside the viewport right now.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* if (isOnScreen(card)) card.classList.add("shown");
|
|
6
|
+
*/
|
|
7
|
+
export function isOnScreen(element) {
|
|
8
|
+
const box = element.getBoundingClientRect();
|
|
9
|
+
const { innerWidth = 0, innerHeight = 0 } = globalThis;
|
|
10
|
+
return (box.width > 0 && box.height > 0 && box.bottom > 0 && box.right > 0 && box.top < innerHeight && box.left < innerWidth);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/layout/on-screen/index.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,OAAmB;IAC5C,MAAM,GAAG,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC5C,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,WAAW,GAAG,CAAC,EAAE,GAAG,UAA0B,CAAC;IACvE,OAAO,CACL,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,WAAW,IAAI,GAAG,CAAC,IAAI,GAAG,UAAU,CACrH,CAAC;AACJ,CAAC"}
|
|
@@ -19,11 +19,20 @@ export declare function beginSoftNavigation(durationMilliseconds?: number): void
|
|
|
19
19
|
export declare function isSoftNavigation(): boolean;
|
|
20
20
|
/**
|
|
21
21
|
* Marks the current document as rendered by a soft navigation (`<html data-soft-navigation>`), so CSS can turn off
|
|
22
|
-
* time-based entrance animations for it
|
|
22
|
+
* time-based entrance animations for it while they would be playing (clear it with `endSoftNavigationDocument` once they
|
|
23
|
+
* are over, because the document can outlive the navigation): `:root[data-soft-navigation] .hero { animation: none }`. Does nothing
|
|
23
24
|
* outside a browser.
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
26
27
|
* markSoftNavigationDocument();
|
|
27
28
|
*/
|
|
28
29
|
export declare function markSoftNavigationDocument(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Clears the mark set by `markSoftNavigationDocument`, so entrance animations play again for content that appears
|
|
32
|
+
* later (call it once the entrances that were skipped would have finished). Does nothing outside a browser.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* setTimeout(endSoftNavigationDocument, 4000);
|
|
36
|
+
*/
|
|
37
|
+
export declare function endSoftNavigationDocument(): void;
|
|
29
38
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/navigation/soft-navigation/index.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/navigation/soft-navigation/index.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAUhE;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,SAAO,GAAG,IAAI,CAErE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD"}
|
|
@@ -25,7 +25,8 @@ export function isSoftNavigation() {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Marks the current document as rendered by a soft navigation (`<html data-soft-navigation>`), so CSS can turn off
|
|
28
|
-
* time-based entrance animations for it
|
|
28
|
+
* time-based entrance animations for it while they would be playing (clear it with `endSoftNavigationDocument` once they
|
|
29
|
+
* are over, because the document can outlive the navigation): `:root[data-soft-navigation] .hero { animation: none }`. Does nothing
|
|
29
30
|
* outside a browser.
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
@@ -34,4 +35,14 @@ export function isSoftNavigation() {
|
|
|
34
35
|
export function markSoftNavigationDocument() {
|
|
35
36
|
globalThis.document?.documentElement.setAttribute(SOFT_NAVIGATION_ATTRIBUTE, "");
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Clears the mark set by `markSoftNavigationDocument`, so entrance animations play again for content that appears
|
|
40
|
+
* later (call it once the entrances that were skipped would have finished). Does nothing outside a browser.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* setTimeout(endSoftNavigationDocument, 4000);
|
|
44
|
+
*/
|
|
45
|
+
export function endSoftNavigationDocument() {
|
|
46
|
+
globalThis.document?.documentElement.removeAttribute(SOFT_NAVIGATION_ATTRIBUTE);
|
|
47
|
+
}
|
|
37
48
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/navigation/soft-navigation/index.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAChE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/navigation/soft-navigation/index.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAChE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC;AAUhE;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,oBAAoB,GAAG,IAAI;IAC5D,UAAoB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,oBAAoB,CAAC;AACjE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,CAAE,UAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B;IACvC,UAA2B,CAAC,QAAQ,EAAE,eAAe,CAAC,YAAY,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;AACrG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB;IACtC,UAA2B,CAAC,QAAQ,EAAE,eAAe,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Joins the parts that are set with a separator surrounded by spaces, skipping `false`, `null`, `undefined` and empty
|
|
3
|
-
* strings.
|
|
3
|
+
* strings. Pass `SEPARATOR` (from `…/text/separator`), the one every Sharadox text uses.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* separate(
|
|
6
|
+
* separate(SEPARATOR, "Contact", "Ana", undefined); // "Contact · Ana"
|
|
7
7
|
*/
|
|
8
8
|
export declare function separate(separator: string, ...parts: (string | false | null | undefined)[]): string;
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Joins the parts that are set with a separator surrounded by spaces, skipping `false`, `null`, `undefined` and empty
|
|
3
|
-
* strings.
|
|
3
|
+
* strings. Pass `SEPARATOR` (from `…/text/separator`), the one every Sharadox text uses.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* separate(
|
|
6
|
+
* separate(SEPARATOR, "Contact", "Ana", undefined); // "Contact · Ana"
|
|
7
7
|
*/
|
|
8
8
|
export function separate(separator, ...parts) {
|
|
9
9
|
return parts.filter(Boolean).join(` ${separator} `);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The separator every Sharadox text uses between labels side by side: titles ("Sharadox · Simple"), footers, tags,
|
|
3
|
+
* email subjects. One constant, so it changes in one place for every site and library.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* separate(SEPARATOR, "Velvet", "Midnight"); // "Velvet · Midnight"
|
|
7
|
+
*/
|
|
8
|
+
export declare const SEPARATOR = "\u00B7";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/text/separator/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,WAAM,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The separator every Sharadox text uses between labels side by side: titles ("Sharadox · Simple"), footers, tags,
|
|
3
|
+
* email subjects. One constant, so it changes in one place for every site and library.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* separate(SEPARATOR, "Velvet", "Midnight"); // "Velvet · Midnight"
|
|
7
|
+
*/
|
|
8
|
+
export const SEPARATOR = "·";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/text/separator/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC"}
|
package/llms.txt
CHANGED
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
- type-guard/is-defined → isDefined(value): not null/undefined
|
|
11
11
|
- class-name → classNames(...names): joins truthy names
|
|
12
12
|
- html/escape → escapeHtml(text)
|
|
13
|
-
- text/
|
|
13
|
+
- text/separator → SEPARATOR "·", the one separator every Sharadox site and library uses
|
|
14
|
+
- text/separate → separate(separator, ...parts): "a · b", skipping empty parts (pass SEPARATOR)
|
|
14
15
|
- math/clamp, math/radians, math/pseudo-random
|
|
15
16
|
- assert/never → assertNever(value): throws; for exhaustive switches
|
|
16
17
|
- Import by path: `import { isString } from "@sharadox/web-library/type-guard/is-string";`
|
|
17
18
|
- License: Sharadox Open Source License 0.1.0
|
|
18
19
|
- navigation/soft-navigation: beginSoftNavigation(ms=2000), isSoftNavigation() (shared on globalThis), markSoftNavigationDocument() + SOFT_NAVIGATION_ATTRIBUTE ("data-soft-navigation") — lets components skip entrance effects when a page is rebuilt in place (language switch)
|
|
20
|
+
- navigation/soft-navigation endSoftNavigationDocument() clears the mark (the <html> element can outlive the navigation); layout/on-screen isOnScreen(element)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/web-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "General TypeScript utilities shared by every Sharadox library and application: type guards, class names, HTML escaping, text joining, math helpers and exhaustiveness checks.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|