@sharadox/web-library 0.11.1-trusted-publishing.41 → 0.12.0-development.49

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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  What changed in each version of `@sharadox/web-library`, newest first.
4
4
 
5
+ ## 0.12.0
6
+
7
+ newTab and leavesSite take the site's own domains: links to them and their subdomains stay in the same tab.
8
+
5
9
  ## 0.11.1
6
10
 
7
11
  Workflows from git-hub-action-library v0.2.2: npm Trusted Publishing only
package/README.md CHANGED
@@ -27,30 +27,30 @@ 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/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
- | `…/text/separated` | `separated(...parts)`: `separate` with the shared `SEPARATOR` | `separated("Contact", "Ana") // "Contact · Ana"` |
43
- | `…/identifier/uuid-version-7` | `uuidVersion7()`: a new UUID version 7, time first so identifiers sort by when they were made | `uuidVersion7() // "019a8f3c-6b2e-7c41-…"` |
44
- | `…/graphics/web-gl-support` | `supportsWebGl()`: whether the browser can create a WebGL context, to show a still fallback instead of a scene that would fail | `supportsWebGl() // true` |
45
- | `…/text/two-digit` | `twoDigits(count)`: a count as two digits | `twoDigits(3) // "03"` |
46
- | `…/request/client-address` | `clientAddress(headers)`: the visitor's address from `x-forwarded-for`, or `"unknown"` | `clientAddress(await headers())` |
47
- | `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
48
- | `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
49
- | `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
50
- | `…/assert/never` | `assertNever(value)`: exhaustive `switch` checks | `default: return assertNever(kind)` |
51
- | `…/navigation/soft-navigation` | `beginSoftNavigation()`, `isSoftNavigation()`, `markSoftNavigationDocument()`, `endSoftNavigationDocument()`: a page rebuilt in place (language switch) skips entrance effects | `const [skip] = useState(isSoftNavigation)` |
52
- | `…/navigation/new-tab` | `leavesSite(href)`, `newTab(href)`: links that leave the site (other sites, email, phone, messages, maps) open in a new tab | `<a href={href} {...newTab(href)}>` |
53
- | `…/layout/on-screen` | `isOnScreen(element)`: any part inside the viewport now | `if (isOnScreen(card)) …` |
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/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
+ | `…/text/separated` | `separated(...parts)`: `separate` with the shared `SEPARATOR` | `separated("Contact", "Ana") // "Contact · Ana"` |
43
+ | `…/identifier/uuid-version-7` | `uuidVersion7()`: a new UUID version 7, time first so identifiers sort by when they were made | `uuidVersion7() // "019a8f3c-6b2e-7c41-…"` |
44
+ | `…/graphics/web-gl-support` | `supportsWebGl()`: whether the browser can create a WebGL context, to show a still fallback instead of a scene that would fail | `supportsWebGl() // true` |
45
+ | `…/text/two-digit` | `twoDigits(count)`: a count as two digits | `twoDigits(3) // "03"` |
46
+ | `…/request/client-address` | `clientAddress(headers)`: the visitor's address from `x-forwarded-for`, or `"unknown"` | `clientAddress(await headers())` |
47
+ | `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
48
+ | `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
49
+ | `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
50
+ | `…/assert/never` | `assertNever(value)`: exhaustive `switch` checks | `default: return assertNever(kind)` |
51
+ | `…/navigation/soft-navigation` | `beginSoftNavigation()`, `isSoftNavigation()`, `markSoftNavigationDocument()`, `endSoftNavigationDocument()`: a page rebuilt in place (language switch) skips entrance effects | `const [skip] = useState(isSoftNavigation)` |
52
+ | `…/navigation/new-tab` | `leavesSite(href, { domains? })`, `newTab(href, { domains? })`: links that leave the site (other sites, email, phone, messages, maps) open in a new tab; the site's own `domains` and their subdomains stay | `<a href={href} {...newTab(href)}>` |
53
+ | `…/layout/on-screen` | `isOnScreen(element)`: any part inside the viewport now | `if (isOnScreen(card)) …` |
54
54
 
55
55
  ## Develop
56
56
 
@@ -1,22 +1,26 @@
1
+ import type { SameSiteOptions } from "@sharadox/web-library/navigation/new-tab/type";
1
2
  /**
2
- * Whether a link leaves the site: anything that isn't one of its own paths (`/…`), sections (`#…`) or relative
3
- * addresses. Other sites, and the apps that handle email, phones, messages and maps (`mailto:`, `tel:`, `sms:`, a map
4
- * link), all leave it.
3
+ * Whether a link leaves the site: anything that isn't one of its own paths (`/…`), sections (`#…`), relative
4
+ * addresses, or web addresses on its own `domains` (and their subdomains). Other sites, and the apps that handle
5
+ * email, phones, messages and maps (`mailto:`, `tel:`, `sms:`, a map link), all leave it.
5
6
  *
6
7
  * @example
7
8
  * leavesSite("mailto:ana@example.com"); // true
8
9
  * leavesSite("/en/privacy"); // false
10
+ * leavesSite("https://account.luispiresdecor.com", { domains: ["luispiresdecor.com"] }); // false
9
11
  */
10
- export declare function leavesSite(href: string): boolean;
12
+ export declare function leavesSite(href: string, { domains }?: SameSiteOptions): boolean;
11
13
  /**
12
14
  * The attributes that open a link in a new tab when it leaves the site (see `leavesSite`), so the visitor keeps the
13
15
  * page where they were while an email web app, a map or another site opens beside it; nothing for the site's own
14
- * links. `noopener noreferrer` keeps the new page from reaching back into this one.
16
+ * links, including those on its own `domains`. `noopener noreferrer` keeps the new page from reaching back into
17
+ * this one.
15
18
  *
16
19
  * @example
17
20
  * <a href={href} {...newTab(href)}>…</a>
21
+ * <a href={href} {...newTab(href, { domains: ["luispiresdecor.com"] })}>…</a>
18
22
  */
19
- export declare function newTab(href: string): {
23
+ export declare function newTab(href: string, options?: SameSiteOptions): {
20
24
  target?: "_blank";
21
25
  rel?: "noopener noreferrer";
22
26
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/navigation/new-tab/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,QAAQ,CAAC;IAAC,GAAG,CAAC,EAAE,qBAAqB,CAAA;CAAE,CAEvF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/navigation/new-tab/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAcrF;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAY,EAAE,GAAE,eAAoB,GAAG,OAAO,CAGxF;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG;IAAE,MAAM,CAAC,EAAE,QAAQ,CAAC;IAAC,GAAG,CAAC,EAAE,qBAAqB,CAAA;CAAE,CAElH"}
@@ -1,24 +1,42 @@
1
+ /** Whether a web address is on one of the domains, or a subdomain of one. */
2
+ function onDomains(href, domains) {
3
+ if (domains.length === 0 || !/^(https?:)?\/\//i.test(href))
4
+ return false;
5
+ let host;
6
+ try {
7
+ host = new URL(href, "https://base.invalid").hostname.toLowerCase();
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ return domains.some((domain) => host === domain.toLowerCase() || host.endsWith(`.${domain.toLowerCase()}`));
13
+ }
1
14
  /**
2
- * Whether a link leaves the site: anything that isn't one of its own paths (`/…`), sections (`#…`) or relative
3
- * addresses. Other sites, and the apps that handle email, phones, messages and maps (`mailto:`, `tel:`, `sms:`, a map
4
- * link), all leave it.
15
+ * Whether a link leaves the site: anything that isn't one of its own paths (`/…`), sections (`#…`), relative
16
+ * addresses, or web addresses on its own `domains` (and their subdomains). Other sites, and the apps that handle
17
+ * email, phones, messages and maps (`mailto:`, `tel:`, `sms:`, a map link), all leave it.
5
18
  *
6
19
  * @example
7
20
  * leavesSite("mailto:ana@example.com"); // true
8
21
  * leavesSite("/en/privacy"); // false
22
+ * leavesSite("https://account.luispiresdecor.com", { domains: ["luispiresdecor.com"] }); // false
9
23
  */
10
- export function leavesSite(href) {
24
+ export function leavesSite(href, { domains = [] } = {}) {
25
+ if (onDomains(href, domains))
26
+ return false;
11
27
  return /^[a-z][a-z\d+.-]*:/i.test(href) || href.startsWith("//");
12
28
  }
13
29
  /**
14
30
  * The attributes that open a link in a new tab when it leaves the site (see `leavesSite`), so the visitor keeps the
15
31
  * page where they were while an email web app, a map or another site opens beside it; nothing for the site's own
16
- * links. `noopener noreferrer` keeps the new page from reaching back into this one.
32
+ * links, including those on its own `domains`. `noopener noreferrer` keeps the new page from reaching back into
33
+ * this one.
17
34
  *
18
35
  * @example
19
36
  * <a href={href} {...newTab(href)}>…</a>
37
+ * <a href={href} {...newTab(href, { domains: ["luispiresdecor.com"] })}>…</a>
20
38
  */
21
- export function newTab(href) {
22
- return leavesSite(href) ? { target: "_blank", rel: "noopener noreferrer" } : {};
39
+ export function newTab(href, options) {
40
+ return leavesSite(href, options) ? { target: "_blank", rel: "noopener noreferrer" } : {};
23
41
  }
24
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/navigation/new-tab/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,IA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EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,qBAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** The site's own domains: links to them, or to any of their subdomains, stay in the same tab. */
2
+ export interface SameSiteOptions {
3
+ /** `["luispiresdecor.com"]` also covers `account.luispiresdecor.com` and every preview under it. */
4
+ domains?: readonly string[];
5
+ }
6
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/navigation/new-tab/type.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,WAAW,eAAe;IAC9B,oGAAoG;IACpG,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/navigation/new-tab/type.ts"],"names":[],"mappings":""}
package/llms.txt CHANGED
@@ -22,5 +22,5 @@
22
22
  - Import by path: `import { isString } from "@sharadox/web-library/type-guard/is-string";`
23
23
  - License: Sharadox Open Source License 0.1.0
24
24
  - 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)
25
- - navigation/new-tab: leavesSite(href) (any scheme like https:, mailto:, tel:, sms:, or //host) and newTab(href) → { target: "_blank", rel: "noopener noreferrer" } or {} — every Sharadox site opens links that leave it in a new tab
25
+ - navigation/new-tab: leavesSite(href, { domains? }) (any scheme like https:, mailto:, tel:, sms:, or //host, except web addresses on `domains` or their subdomains) and newTab(href, { domains? }) → { target: "_blank", rel: "noopener noreferrer" } or {} — every Sharadox site opens links that leave it in a new tab
26
26
  - 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.11.1-trusted-publishing.41",
3
+ "version": "0.12.0-development.49",
4
4
  "description": "General TypeScript utilities shared by every Sharadox library and application: type guards, class names, HTML escaping, text joining, identifiers, math helpers and exhaustiveness checks.",
5
5
  "private": false,
6
6
  "license": "SEE LICENSE IN LICENCA.md",