@sharadox/web-library 0.5.1 → 0.6.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 CHANGED
@@ -27,21 +27,22 @@ pnpm add @sharadox/web-library
27
27
 
28
28
  Import each utility by its path:
29
29
 
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>") // "&lt;b&gt;"` |
40
- | `…/text/separate` | `separate(separator, ...parts)` | `separate("•", "Contact", "Ana") // "Contact • Ana"` |
41
- | `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
42
- | `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
43
- | `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
44
- | `…/assert/never` | `assertNever(value)`: exhaustive `switch` checks | `default: return assertNever(kind)` |
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>") // "&lt;b&gt;"` |
40
+ | `…/text/separate` | `separate(separator, ...parts)` | `separate("•", "Contact", "Ana") // "Contact • Ana"` |
41
+ | `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
42
+ | `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
43
+ | `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
44
+ | `…/assert/never` | `assertNever(value)`: exhaustive `switch` checks | `default: return assertNever(kind)` |
45
+ | `…/navigation/soft-navigation` | `beginSoftNavigation()`, `isSoftNavigation()`, `markSoftNavigationDocument()`: a page rebuilt in place (language switch) skips entrance effects | `const [skip] = useState(isSoftNavigation)` |
45
46
 
46
47
  ## Develop
47
48
 
@@ -0,0 +1,29 @@
1
+ /** The attribute a document gets when it was rendered by a soft navigation. */
2
+ export declare const SOFT_NAVIGATION_ATTRIBUTE = "data-soft-navigation";
3
+ /**
4
+ * Announces that the page is about to be rebuilt in place (for example switching language), so components that
5
+ * mount in the next `durationMilliseconds` show their final state instead of replaying entrance effects.
6
+ *
7
+ * @example
8
+ * beginSoftNavigation();
9
+ * router.push("/pt", { scroll: false });
10
+ */
11
+ export declare function beginSoftNavigation(durationMilliseconds?: number): void;
12
+ /**
13
+ * Whether a soft navigation is under way: components read it when they mount to skip entrance animations. Always
14
+ * false on the server and on a first visit.
15
+ *
16
+ * @example
17
+ * const [skipEntrance] = useState(isSoftNavigation);
18
+ */
19
+ export declare function isSoftNavigation(): boolean;
20
+ /**
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: `:root[data-soft-navigation] .hero { animation: none }`. Does nothing
23
+ * outside a browser.
24
+ *
25
+ * @example
26
+ * markSoftNavigationDocument();
27
+ */
28
+ export declare function markSoftNavigationDocument(): void;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAMhE;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,SAAO,GAAG,IAAI,CAErE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD"}
@@ -0,0 +1,37 @@
1
+ /** Where the flag lives: on `globalThis` under a registered symbol, so every copy of this library shares it. */
2
+ const KEY = Symbol.for("@sharadox/web-library/soft-navigation");
3
+ /** The attribute a document gets when it was rendered by a soft navigation. */
4
+ export const SOFT_NAVIGATION_ATTRIBUTE = "data-soft-navigation";
5
+ /**
6
+ * Announces that the page is about to be rebuilt in place (for example switching language), so components that
7
+ * mount in the next `durationMilliseconds` show their final state instead of replaying entrance effects.
8
+ *
9
+ * @example
10
+ * beginSoftNavigation();
11
+ * router.push("/pt", { scroll: false });
12
+ */
13
+ export function beginSoftNavigation(durationMilliseconds = 2000) {
14
+ globalThis[KEY] = Date.now() + durationMilliseconds;
15
+ }
16
+ /**
17
+ * Whether a soft navigation is under way: components read it when they mount to skip entrance animations. Always
18
+ * false on the server and on a first visit.
19
+ *
20
+ * @example
21
+ * const [skipEntrance] = useState(isSoftNavigation);
22
+ */
23
+ export function isSoftNavigation() {
24
+ return Date.now() < (globalThis[KEY] ?? 0);
25
+ }
26
+ /**
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: `:root[data-soft-navigation] .hero { animation: none }`. Does nothing
29
+ * outside a browser.
30
+ *
31
+ * @example
32
+ * markSoftNavigationDocument();
33
+ */
34
+ export function markSoftNavigationDocument() {
35
+ globalThis.document?.documentElement.setAttribute(SOFT_NAVIGATION_ATTRIBUTE, "");
36
+ }
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AAMhE;;;;;;;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;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B;IACvC,UAA2B,CAAC,QAAQ,EAAE,eAAe,CAAC,YAAY,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;AACrG,CAAC"}
package/llms.txt CHANGED
@@ -15,3 +15,4 @@
15
15
  - assert/never → assertNever(value): throws; for exhaustive switches
16
16
  - Import by path: `import { isString } from "@sharadox/web-library/type-guard/is-string";`
17
17
  - License: Sharadox Open Source License 0.1.0
18
+ - 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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharadox/web-library",
3
- "version": "0.5.1",
3
+ "version": "0.6.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",