@astryxdesign/core 0.6.3-canary.f22695a → 0.6.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.
Files changed (118) hide show
  1. package/dist/Button/Button.d.ts.map +1 -1
  2. package/dist/Button/Button.js +28 -13
  3. package/dist/Chat/ChatLayout.d.ts +0 -19
  4. package/dist/Chat/ChatLayout.d.ts.map +1 -1
  5. package/dist/Chat/ChatLayout.js +0 -19
  6. package/dist/Chat/ChatLayoutScrollButton.d.ts.map +1 -1
  7. package/dist/Chat/ChatLayoutScrollButton.js +34 -44
  8. package/dist/Citation/Citation.d.ts +1 -1
  9. package/dist/Citation/Citation.d.ts.map +1 -1
  10. package/dist/Citation/Citation.js +2 -3
  11. package/dist/CodeBlock/highlightRanges.d.ts.map +1 -1
  12. package/dist/CodeBlock/highlightRanges.js +3 -14
  13. package/dist/Icon/Icon.d.ts +31 -6
  14. package/dist/Icon/Icon.d.ts.map +1 -1
  15. package/dist/Icon/Icon.js +71 -8
  16. package/dist/Link/useLinkComponent.d.ts +15 -5
  17. package/dist/Link/useLinkComponent.d.ts.map +1 -1
  18. package/dist/Link/useLinkComponent.js +51 -34
  19. package/dist/Markdown/Markdown.js +2 -2
  20. package/dist/Markdown/url.d.ts +0 -2
  21. package/dist/Markdown/url.d.ts.map +1 -1
  22. package/dist/Markdown/url.js +2 -8
  23. package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
  24. package/dist/PowerSearch/PowerSearchValueEditor.js +0 -5
  25. package/dist/TopNav/TopNavMenu.d.ts +1 -1
  26. package/dist/TopNav/TopNavMenu.d.ts.map +1 -1
  27. package/dist/TopNav/TopNavMenu.js +2 -3
  28. package/dist/astryx.css +4 -2
  29. package/dist/hooks/useClickableContainer.d.ts +1 -10
  30. package/dist/hooks/useClickableContainer.d.ts.map +1 -1
  31. package/dist/hooks/useClickableContainer.js +4 -15
  32. package/dist/index.d.ts +0 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +0 -3
  35. package/dist/theme/generateThemeRules.d.ts +7 -13
  36. package/dist/theme/generateThemeRules.d.ts.map +1 -1
  37. package/dist/theme/generateThemeRules.js +35 -131
  38. package/package.json +4 -9
  39. package/src/Button/Button.doc.mjs +5 -5
  40. package/src/Button/Button.tsx +13 -15
  41. package/src/Chat/ChatLayout.doc.mjs +4 -12
  42. package/src/Chat/ChatLayout.test.tsx +0 -28
  43. package/src/Chat/ChatLayout.tsx +0 -19
  44. package/src/Chat/ChatLayoutScrollButton.test.tsx +0 -31
  45. package/src/Chat/ChatLayoutScrollButton.tsx +14 -31
  46. package/src/Citation/Citation.doc.mjs +2 -2
  47. package/src/Citation/Citation.test.tsx +0 -17
  48. package/src/Citation/Citation.tsx +2 -4
  49. package/src/ClickableCard/ClickableCard.doc.mjs +2 -2
  50. package/src/CodeBlock/highlightRanges.test.ts +1 -143
  51. package/src/CodeBlock/highlightRanges.ts +5 -15
  52. package/src/Icon/Icon.doc.mjs +5 -7
  53. package/src/Icon/Icon.spec.md +40 -81
  54. package/src/Icon/Icon.test.tsx +3 -6
  55. package/src/Icon/Icon.tsx +68 -20
  56. package/src/IconButton/IconButton.doc.mjs +3 -3
  57. package/src/IconButton/IconButton.test.tsx +0 -40
  58. package/src/Item/Item.doc.mjs +2 -2
  59. package/src/Link/Link.doc.mjs +4 -6
  60. package/src/Link/LinkProvider.doc.mjs +2 -2
  61. package/src/Link/useLinkComponent.test.tsx +0 -333
  62. package/src/Link/useLinkComponent.ts +57 -29
  63. package/src/List/ListItem.doc.mjs +2 -2
  64. package/src/Markdown/Markdown.doc.mjs +2 -2
  65. package/src/Markdown/Markdown.spec.md +15 -19
  66. package/src/Markdown/Markdown.test.tsx +0 -52
  67. package/src/Markdown/Markdown.tsx +2 -2
  68. package/src/Markdown/parser.test.ts +0 -20
  69. package/src/Markdown/url.ts +3 -9
  70. package/src/PowerSearch/PowerSearchValueEditor.test.tsx +0 -51
  71. package/src/PowerSearch/PowerSearchValueEditor.tsx +0 -4
  72. package/src/Token/Token.doc.mjs +2 -2
  73. package/src/TopNav/TopNavMenu.doc.mjs +2 -2
  74. package/src/TopNav/TopNavMenu.test.tsx +0 -30
  75. package/src/TopNav/TopNavMenu.tsx +2 -7
  76. package/src/hooks/useClickableContainer.ts +4 -20
  77. package/src/index.ts +0 -3
  78. package/src/tailwind-theme.css +6 -0
  79. package/src/theme/Theme.test.tsx +0 -32
  80. package/src/theme/generateThemeRules.test.ts +2 -470
  81. package/src/theme/generateThemeRules.ts +51 -219
  82. package/src/theme/tokenValueCompat.test.ts +1 -4
  83. package/dist/Icon/IconDefaultSizeContext.d.ts +0 -4
  84. package/dist/Icon/IconDefaultSizeContext.d.ts.map +0 -1
  85. package/dist/Icon/IconDefaultSizeContext.js +0 -18
  86. package/dist/Icon/IconSize.stylex.d.ts +0 -65
  87. package/dist/Icon/IconSize.stylex.d.ts.map +0 -1
  88. package/dist/Icon/IconSize.stylex.js +0 -75
  89. package/dist/Timer/Timer.d.ts +0 -49
  90. package/dist/Timer/Timer.d.ts.map +0 -1
  91. package/dist/Timer/Timer.js +0 -158
  92. package/dist/Timer/index.d.ts +0 -9
  93. package/dist/Timer/index.d.ts.map +0 -1
  94. package/dist/Timer/index.js +0 -10
  95. package/dist/theme/declarationBoundary.d.ts +0 -17
  96. package/dist/theme/declarationBoundary.d.ts.map +0 -1
  97. package/dist/theme/declarationBoundary.js +0 -343
  98. package/dist/utils/safeUrl.d.ts +0 -11
  99. package/dist/utils/safeUrl.d.ts.map +0 -1
  100. package/dist/utils/safeUrl.js +0 -78
  101. package/src/Chat/ChatLayout.spec.md +0 -271
  102. package/src/Chat/ChatLayoutScrollButton.spec.md +0 -338
  103. package/src/Chat/__tests__/ChatLayoutScrollButton.a11y.chromium.spec.ts +0 -514
  104. package/src/Chat/__tests__/ChatLayoutScrollButtonSurface.a11y.chromium.spec.ts +0 -740
  105. package/src/Icon/IconDefaultSizeContext.ts +0 -23
  106. package/src/Icon/IconSize.stylex.ts +0 -70
  107. package/src/Link/__tests__/Link.navigation.a11y.chromium.spec.ts +0 -261
  108. package/src/Markdown/Markdown.renderBoundary.test.tsx +0 -72
  109. package/src/Timer/Timer.doc.mjs +0 -183
  110. package/src/Timer/Timer.spec.md +0 -215
  111. package/src/Timer/Timer.test.tsx +0 -302
  112. package/src/Timer/Timer.tsx +0 -258
  113. package/src/Timer/index.ts +0 -11
  114. package/src/hooks/useClickableContainer.test.tsx +0 -236
  115. package/src/theme/declarationBoundary.test.ts +0 -126
  116. package/src/theme/declarationBoundary.ts +0 -347
  117. package/src/utils/safeUrl.test.ts +0 -88
  118. package/src/utils/safeUrl.ts +0 -85
@@ -1,49 +0,0 @@
1
- import type { BaseProps } from '../BaseProps';
2
- import type { TextColor, TextSize, TextType, TextWeight } from '../theme/types';
3
- export type TimerFormat = 'elapsed' | 'clock';
4
- export interface TimerProps extends Omit<BaseProps<HTMLTimeElement>, 'dateTime'> {
5
- /** Ref forwarded to the rendered `<time>` element. */
6
- ref?: React.Ref<HTMLTimeElement>;
7
- /**
8
- * Unix time in milliseconds when the measured operation began. Omit it to
9
- * start counting from this Timer's mount.
10
- */
11
- startTime?: number;
12
- /**
13
- * Standard duration representation.
14
- * @default 'elapsed'
15
- */
16
- format?: TimerFormat;
17
- /**
18
- * Semantic text type. Matches Timestamp typography behavior.
19
- * @default 'supporting'
20
- */
21
- type?: TextType;
22
- /** Explicit font size override. Overrides the size from `type`. */
23
- size?: TextSize;
24
- /**
25
- * Text color.
26
- * @default 'secondary'
27
- */
28
- color?: TextColor;
29
- /** Font weight override. */
30
- weight?: TextWeight;
31
- }
32
- /**
33
- * Displays a standardized elapsed duration without scheduling React tick renders.
34
- *
35
- * Timer writes changing text and its ISO 8601 duration directly to the owned
36
- * `<time>` node. Use `elapsed` for compact duration text or `clock` for a
37
- * stopwatch-like reading.
38
- *
39
- * @example
40
- * ```
41
- * <Timer />
42
- * <Timer format="clock" />
43
- * ```
44
- */
45
- export declare function Timer({ startTime, format, type, size, color, weight, ref, xstyle, className, style, ...rest }: TimerProps): import("react").JSX.Element;
46
- export declare namespace Timer {
47
- var displayName: string;
48
- }
49
- //# sourceMappingURL=Timer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Timer.d.ts","sourceRoot":"","sources":["../../src/Timer/Timer.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAsB9E,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AA8E9C,MAAM,WAAW,UAAW,SAAQ,IAAI,CACtC,SAAS,CAAC,eAAe,CAAC,EAC1B,UAAU,CACX;IACC,sDAAsD;IACtD,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,mEAAmE;IACnE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,EACpB,SAAS,EACT,MAAkB,EAClB,IAAmB,EACnB,IAAI,EACJ,KAAmB,EACnB,MAAM,EACN,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,UAAU,+BA0EZ;yBAtFe,KAAK"}
@@ -1,158 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- 'use client';
4
-
5
- /**
6
- * @file Timer.tsx
7
- * @input Uses an optional start time, standardized format, Timestamp typography, BaseProps, and React ref
8
- * @output Exports Timer, TimerProps, and TimerFormat with non-rendering elapsed-time updates
9
- * @position Core content primitive for elapsed duration in active operations
10
- *
11
- * SYNC: When modified, update these files to stay in sync:
12
- * - /packages/core/src/Timer/Timer.spec.md
13
- * - /packages/core/src/Timer/Timer.doc.mjs
14
- * - /packages/core/src/Timer/Timer.test.tsx
15
- * - /packages/core/src/Timer/index.ts
16
- * - /apps/storybook/stories/Timer.stories.tsx
17
- * - /packages/cli/assets/templates/blocks/components/Timer/
18
- */
19
- import { useEffect, useRef, useState } from 'react';
20
- import * as stylex from '@stylexjs/stylex';
21
- import { useMergedRefs } from "../hooks/useMergedRefs.js";
22
- import { Text } from "../Text/index.js";
23
- import { mergeProps } from "../utils/index.js";
24
- import { themeProps } from "../utils/themeProps.js";
25
- import { jsx as _jsx } from "react/jsx-runtime";
26
- const ONE_SECOND_MS = 1000;
27
- const ONE_MINUTE_MS = 60 * ONE_SECOND_MS;
28
- const ONE_HOUR_SECONDS = 60 * 60;
29
- const MAX_TIMEOUT_MS = 2_147_483_647;
30
- function pad(value) {
31
- return String(value).padStart(2, '0');
32
- }
33
- function resolveFormat(format) {
34
- return format === 'clock' ? 'clock' : 'elapsed';
35
- }
36
- function getElapsedMilliseconds(now, startTime) {
37
- return Math.max(0, now - startTime);
38
- }
39
- function getPresentation(elapsedMilliseconds, format) {
40
- const elapsedSeconds = Math.floor(elapsedMilliseconds / ONE_SECOND_MS);
41
- if (format === 'clock') {
42
- const hours = Math.floor(elapsedSeconds / ONE_HOUR_SECONDS);
43
- const minutes = Math.floor(elapsedSeconds % ONE_HOUR_SECONDS / 60);
44
- const seconds = elapsedSeconds % 60;
45
- return {
46
- dateTime: `PT${elapsedSeconds}S`,
47
- text: hours > 0 ? `${String(hours)}:${pad(minutes)}:${pad(seconds)}` : `${String(minutes)}:${pad(seconds)}`
48
- };
49
- }
50
- if (elapsedSeconds < 60) {
51
- return {
52
- dateTime: `PT${elapsedSeconds}S`,
53
- text: `${String(elapsedSeconds)}s`
54
- };
55
- }
56
- const totalMinutes = Math.floor(elapsedSeconds / 60);
57
- if (totalMinutes < 60) {
58
- return {
59
- dateTime: `PT${elapsedSeconds}S`,
60
- text: `${String(totalMinutes)}m ${pad(elapsedSeconds % 60)}s`
61
- };
62
- }
63
- const representedSeconds = totalMinutes * 60;
64
- return {
65
- dateTime: `PT${representedSeconds}S`,
66
- text: `${String(Math.floor(totalMinutes / 60))}h ${pad(totalMinutes % 60)}m`
67
- };
68
- }
69
- function getMillisecondsUntilNextChange(now, startTime, elapsedMilliseconds, format) {
70
- if (now < startTime) {
71
- return Math.min(startTime - now + ONE_SECOND_MS, MAX_TIMEOUT_MS);
72
- }
73
- const precision = format === 'elapsed' && elapsedMilliseconds >= ONE_HOUR_SECONDS * ONE_SECOND_MS ? ONE_MINUTE_MS : ONE_SECOND_MS;
74
- return precision - elapsedMilliseconds % precision;
75
- }
76
- /**
77
- * Displays a standardized elapsed duration without scheduling React tick renders.
78
- *
79
- * Timer writes changing text and its ISO 8601 duration directly to the owned
80
- * `<time>` node. Use `elapsed` for compact duration text or `clock` for a
81
- * stopwatch-like reading.
82
- *
83
- * @example
84
- * ```
85
- * <Timer />
86
- * <Timer format="clock" />
87
- * ```
88
- */
89
- export function Timer({
90
- startTime,
91
- format = 'elapsed',
92
- type = 'supporting',
93
- size,
94
- color = 'secondary',
95
- weight,
96
- ref,
97
- xstyle,
98
- className,
99
- style,
100
- ...rest
101
- }) {
102
- const [mountTime] = useState(() => Date.now());
103
- const timerRef = useRef(null);
104
- const mergedRef = useMergedRefs(ref, timerRef);
105
- const resolvedFormat = resolveFormat(format);
106
- const initialPresentation = getPresentation(0, resolvedFormat);
107
- useEffect(() => {
108
- const resolvedStartTime = startTime !== undefined && Number.isFinite(startTime) ? startTime : mountTime;
109
- let timeoutID;
110
- let previousDateTime;
111
- let previousText;
112
- const tick = () => {
113
- const now = Date.now();
114
- const elapsedMilliseconds = getElapsedMilliseconds(now, resolvedStartTime);
115
- const presentation = getPresentation(elapsedMilliseconds, resolvedFormat);
116
- const node = timerRef.current;
117
- if (node != null) {
118
- if (presentation.text !== previousText) {
119
- node.textContent = presentation.text;
120
- previousText = presentation.text;
121
- }
122
- if (presentation.dateTime !== previousDateTime) {
123
- node.dateTime = presentation.dateTime;
124
- previousDateTime = presentation.dateTime;
125
- }
126
- }
127
- timeoutID = setTimeout(tick, getMillisecondsUntilNextChange(now, resolvedStartTime, elapsedMilliseconds, resolvedFormat));
128
- };
129
- tick();
130
- return () => {
131
- if (timeoutID !== undefined) {
132
- clearTimeout(timeoutID);
133
- }
134
- };
135
- }, [mountTime, resolvedFormat, startTime]);
136
- const timerProps = mergeProps(themeProps('timer'), {
137
- className,
138
- style
139
- });
140
- return /*#__PURE__*/_jsx(Text, {
141
- type: type,
142
- size: size,
143
- color: color,
144
- weight: weight,
145
- xstyle: xstyle,
146
- ...timerProps,
147
- children: /*#__PURE__*/_jsx("time", {
148
- ...rest,
149
- ref: mergedRef,
150
- dateTime: "PT0S",
151
- ...{
152
- className: "x1heor9g xt0psk2 xjb2p0i x1qlqyl8 x1j61x8r xss6m8b x1pd3egz x15bjb6t"
153
- },
154
- children: initialPresentation.text
155
- })
156
- });
157
- }
158
- Timer.displayName = 'Timer';
@@ -1,9 +0,0 @@
1
- /**
2
- * @file index.ts
3
- * @input Imports Timer, TimerProps, and TimerFormat
4
- * @output Public Timer component barrel
5
- * @position Component subpath entry point for @astryxdesign/core/Timer
6
- */
7
- export { Timer } from './Timer';
8
- export type { TimerFormat, TimerProps } from './Timer';
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Timer/index.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,YAAY,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,SAAS,CAAC"}
@@ -1,10 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file index.ts
5
- * @input Imports Timer, TimerProps, and TimerFormat
6
- * @output Public Timer component barrel
7
- * @position Component subpath entry point for @astryxdesign/core/Timer
8
- */
9
-
10
- export { Timer } from "./Timer.js";
@@ -1,17 +0,0 @@
1
- /**
2
- * Why `value` cannot be emitted as the value of one declaration, or `null`
3
- * when it can. Valid CSS a browser keeps inside one declaration always
4
- * returns `null`; see the file header for the exact rules.
5
- */
6
- export declare function checkDeclarationValue(input: string): string | null;
7
- /**
8
- * Why `name` cannot be emitted as a declaration's property name, or `null`
9
- * when it can. A property name is one CSS ident sequence: a standard
10
- * property (`color`), a vendor-prefixed one (`-webkit-line-clamp`), or a
11
- * custom property (`--brand-accent`, `--_internal`). Escapes are allowed
12
- * because an ident allows them. Whether the name means anything to the
13
- * browser is not this check's concern; only that it cannot end the
14
- * declaration or leak a second one.
15
- */
16
- export declare function checkDeclarationName(input: string): string | null;
17
- //# sourceMappingURL=declarationBoundary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"declarationBoundary.d.ts","sourceRoot":"","sources":["../../src/theme/declarationBoundary.ts"],"names":[],"mappings":"AAgOA;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgGlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUjE"}
@@ -1,343 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Declaration boundary scanner
5
- *
6
- * Decides whether a consumer-supplied property name and value can be emitted
7
- * as exactly one CSS declaration, `name: value;`, without the value ending
8
- * the declaration early or swallowing what follows it. Theme definitions are
9
- * code, but apps assemble them from stored input (brand colors,
10
- * white-labeling), so the generated stylesheet must never extend beyond the
11
- * declarations it means to emit.
12
- *
13
- * The scanner follows the CSS Syntax Module Level 3 tokenizer for everything
14
- * that decides where a declaration ends: strings with backslash escapes and
15
- * line continuations, comments, `url()` with an unquoted body, escaped code
16
- * points outside strings, and `()`, `[]`, `{}` block nesting. Inside any of
17
- * those a `;` or a brace is inert, exactly as a browser reads it, so a `data:`
18
- * URI, `Gill\ Sans`, or a closed comment passes through byte-identically.
19
- * Only what a browser would read as the end of the declaration or rule is
20
- * rejected: an unnested `;`, `{` or `}`, an unbalanced closer, and anything
21
- * left open at the end of the value (a string, comment, block, or url whose
22
- * closer would then be the generator's own `;` or `}`). A `bad-string` or
23
- * `bad-url` token is rejected as well: the browser would discard the
24
- * declaration anyway, and a diagnostic beats a silent no-op.
25
- *
26
- * @input A property name or a declaration value as authored in a theme
27
- * @output `null` when it can be emitted, otherwise the reason it cannot
28
- * @position packages/core/src/theme/declarationBoundary.ts
29
- */
30
-
31
- /** Newline per CSS Syntax §4.2 (after preprocessing, CR and FF are newlines). */
32
- function isNewline(ch) {
33
- return ch === '\n' || ch === '\r' || ch === '\f';
34
- }
35
- function isWhitespace(ch) {
36
- return ch === ' ' || ch === '\t' || isNewline(ch);
37
- }
38
- function isHexDigit(ch) {
39
- return /^[0-9a-fA-F]$/.test(ch);
40
- }
41
-
42
- /** Name-start code point: letter, underscore, or any non-ASCII code point. */
43
- function isNameStart(ch) {
44
- return /^[A-Za-z_]$/.test(ch) || ch.charCodeAt(0) >= 0x80;
45
- }
46
- function isNameChar(ch) {
47
- return isNameStart(ch) || /^[0-9-]$/.test(ch);
48
- }
49
-
50
- /** CSS Syntax §3.3 preprocessing, for scanning only; emitted bytes stay intact. */
51
- function preprocess(input) {
52
- return input.replace(/\r\n?|\f/g, '\n').replace(/\0/g, '\uFFFD');
53
- }
54
-
55
- /** Non-printable code points make an unquoted url() a bad-url token. */
56
- // eslint-disable-next-line no-control-regex -- these code points are the subject
57
- const NON_PRINTABLE = /[\x01-\x08\x0b\x0e-\x1f\x7f]/;
58
-
59
- /** "Check if two code points are a valid escape" (§4.3.8). */
60
- function isValidEscape(input, pos) {
61
- return input[pos] === '\\' && pos + 1 < input.length && !isNewline(input[pos + 1]);
62
- }
63
-
64
- /** "Check if three code points would start an ident sequence" (§4.3.9). */
65
- function startsIdent(input, pos) {
66
- const ch = input[pos];
67
- if (ch === '-') {
68
- const next = input[pos + 1];
69
- return next !== undefined && (next === '-' || isNameStart(next) || isValidEscape(input, pos + 1));
70
- }
71
- if (ch === '\\') {
72
- return isValidEscape(input, pos);
73
- }
74
- return ch !== undefined && isNameStart(ch);
75
- }
76
-
77
- /**
78
- * "Consume an escaped code point" (§4.3.7), positioned after the backslash.
79
- * Returns the position after the escape. A hex escape takes up to six hex
80
- * digits plus one optional whitespace; anything else takes one code point.
81
- */
82
- function consumeEscape(input, pos) {
83
- if (isHexDigit(input[pos])) {
84
- let end = pos;
85
- while (end < input.length && end - pos < 6 && isHexDigit(input[end])) {
86
- end++;
87
- }
88
- if (end < input.length && isWhitespace(input[end])) {
89
- end++;
90
- }
91
- return end;
92
- }
93
- // A surrogate pair is one code point.
94
- const code = input.codePointAt(pos) ?? 0;
95
- return pos + (code > 0xffff ? 2 : 1);
96
- }
97
-
98
- /**
99
- * "Consume an ident sequence" (§4.3.11) starting at `pos`. Returns the
100
- * position after it and the decoded name (escapes resolved, for the
101
- * case-insensitive `url` check; hex escapes decode to their code point).
102
- */
103
- function consumeIdent(input, pos) {
104
- let name = '';
105
- let i = pos;
106
- while (i < input.length) {
107
- const ch = input[i];
108
- if (isNameChar(ch)) {
109
- name += ch;
110
- i++;
111
- } else if (isValidEscape(input, i)) {
112
- const end = consumeEscape(input, i + 1);
113
- if (isHexDigit(input[i + 1])) {
114
- const hex = input.slice(i + 1, end).trim();
115
- const code = parseInt(hex, 16);
116
- name += code === 0 || code > 0x10ffff || code >= 0xd800 && code <= 0xdfff ? '\uFFFD' : String.fromCodePoint(code);
117
- } else {
118
- name += input.slice(i + 1, end);
119
- }
120
- i = end;
121
- } else {
122
- break;
123
- }
124
- }
125
- return {
126
- end: i,
127
- name
128
- };
129
- }
130
-
131
- /**
132
- * "Consume a string token" (§4.3.5), positioned at the opening quote.
133
- * Returns the position after the closing quote, or a rejection reason.
134
- */
135
- function consumeString(input, pos) {
136
- const quote = input[pos];
137
- let i = pos + 1;
138
- while (i < input.length) {
139
- const ch = input[i];
140
- if (ch === quote) {
141
- return {
142
- end: i + 1
143
- };
144
- }
145
- if (isNewline(ch)) {
146
- // A raw newline ends the string as a bad-string token; the browser
147
- // discards the declaration, so a diagnostic is more useful than
148
- // reasoning about where that leaves the next `;`.
149
- return {
150
- reason: 'a newline inside a quoted string makes a bad string'
151
- };
152
- }
153
- if (ch === '\\') {
154
- if (i + 1 >= input.length) {
155
- break;
156
- }
157
- // Escaped newline is a line continuation; any other escape consumes
158
- // the escaped code point (so `\"` never closes the string).
159
- i = isNewline(input[i + 1]) ? i + 2 : consumeEscape(input, i + 1);
160
- continue;
161
- }
162
- i++;
163
- }
164
- return {
165
- reason: `an unclosed ${quote} string would swallow the rest of the rule`
166
- };
167
- }
168
-
169
- /**
170
- * "Consume a url token" (§4.3.6), positioned after `url(` and any leading
171
- * whitespace, with a non-quote next code point. Returns the position after
172
- * the closing `)`, or a rejection reason (bad-url or unclosed).
173
- */
174
- function consumeUrl(input, pos) {
175
- let i = pos;
176
- while (i < input.length) {
177
- const ch = input[i];
178
- if (ch === ')') {
179
- return {
180
- end: i + 1
181
- };
182
- }
183
- if (isWhitespace(ch)) {
184
- while (i < input.length && isWhitespace(input[i])) {
185
- i++;
186
- }
187
- if (i >= input.length) {
188
- break;
189
- }
190
- if (input[i] === ')') {
191
- return {
192
- end: i + 1
193
- };
194
- }
195
- return {
196
- reason: 'whitespace inside an unquoted url() makes a bad url'
197
- };
198
- }
199
- if (NON_PRINTABLE.test(ch)) {
200
- return {
201
- reason: 'a non-printable character inside url() makes a bad url'
202
- };
203
- }
204
- if (ch === '"' || ch === "'" || ch === '(') {
205
- return {
206
- reason: `"${ch}" inside an unquoted url() makes a bad url; quote the URL instead`
207
- };
208
- }
209
- if (ch === '\\') {
210
- if (!isValidEscape(input, i)) {
211
- return {
212
- reason: 'a stray backslash inside url() makes a bad url'
213
- };
214
- }
215
- i = consumeEscape(input, i + 1);
216
- continue;
217
- }
218
- i++;
219
- }
220
- return {
221
- reason: 'an unclosed url( would swallow the rest of the rule'
222
- };
223
- }
224
- const CLOSER = {
225
- '(': ')',
226
- '[': ']',
227
- '{': '}'
228
- };
229
-
230
- /**
231
- * Why `value` cannot be emitted as the value of one declaration, or `null`
232
- * when it can. Valid CSS a browser keeps inside one declaration always
233
- * returns `null`; see the file header for the exact rules.
234
- */
235
- export function checkDeclarationValue(input) {
236
- const value = preprocess(input);
237
- const open = [];
238
- let i = 0;
239
- while (i < value.length) {
240
- const ch = value[i];
241
- if (ch === '/' && value[i + 1] === '*') {
242
- const close = value.indexOf('*/', i + 2);
243
- if (close === -1) {
244
- return 'an unclosed /* comment would swallow the rest of the rule';
245
- }
246
- i = close + 2;
247
- continue;
248
- }
249
- if (ch === '"' || ch === "'") {
250
- const result = consumeString(value, i);
251
- if ('reason' in result) {
252
- return result.reason;
253
- }
254
- i = result.end;
255
- continue;
256
- }
257
- if (startsIdent(value, i)) {
258
- const ident = consumeIdent(value, i);
259
- i = ident.end;
260
- if (value[i] === '(' && ident.name.toLowerCase() === 'url') {
261
- let j = i + 1;
262
- while (j < value.length && isWhitespace(value[j])) {
263
- j++;
264
- }
265
- if (value[j] === '"' || value[j] === "'") {
266
- // `url("...")` is an ordinary function token; the string and the
267
- // closing paren are handled by the loop.
268
- open.push(')');
269
- i = i + 1;
270
- continue;
271
- }
272
- const result = consumeUrl(value, j);
273
- if ('reason' in result) {
274
- return result.reason;
275
- }
276
- i = result.end;
277
- }
278
- continue;
279
- }
280
- if (ch === '\\') {
281
- if (i + 1 >= value.length) {
282
- // `\` followed by the generator's own `;` would escape it.
283
- return 'a trailing backslash would escape the declaration terminator';
284
- }
285
- // `\` + newline is not an escape: the backslash is a delim and the
286
- // newline is whitespace. Anything else escapes the next code point.
287
- i = isNewline(value[i + 1]) ? i + 1 : consumeEscape(value, i + 1);
288
- continue;
289
- }
290
- if (ch === '(' || ch === '[' || ch === '{') {
291
- if (ch === '{' && open.length === 0) {
292
- return 'an unquoted "{" would open a nested block';
293
- }
294
- open.push(CLOSER[ch]);
295
- i++;
296
- continue;
297
- }
298
- if (ch === ')' || ch === ']' || ch === '}') {
299
- if (open.length === 0) {
300
- return ch === '}' ? 'an unquoted "}" would close the rule' : `an unbalanced "${ch}" has nothing to close`;
301
- }
302
- const expected = open.pop();
303
- if (expected !== ch) {
304
- return `"${ch}" does not close the open "${expected === ')' ? '(' : expected === ']' ? '[' : '{'}"`;
305
- }
306
- i++;
307
- continue;
308
- }
309
- if (ch === ';' && open.length === 0) {
310
- return 'an unquoted ";" would end the declaration';
311
- }
312
- i++;
313
- }
314
- if (open.length > 0) {
315
- const closer = open[open.length - 1];
316
- const opener = closer === ')' ? '(' : closer === ']' ? '[' : '{';
317
- return `an unclosed "${opener}" would swallow the rest of the rule`;
318
- }
319
- return null;
320
- }
321
-
322
- /**
323
- * Why `name` cannot be emitted as a declaration's property name, or `null`
324
- * when it can. A property name is one CSS ident sequence: a standard
325
- * property (`color`), a vendor-prefixed one (`-webkit-line-clamp`), or a
326
- * custom property (`--brand-accent`, `--_internal`). Escapes are allowed
327
- * because an ident allows them. Whether the name means anything to the
328
- * browser is not this check's concern; only that it cannot end the
329
- * declaration or leak a second one.
330
- */
331
- export function checkDeclarationName(input) {
332
- const name = preprocess(input);
333
- if (name.length === 0 || !startsIdent(name, 0)) {
334
- return 'a property name must be a CSS identifier';
335
- }
336
- const {
337
- end
338
- } = consumeIdent(name, 0);
339
- if (end !== name.length) {
340
- return `a property name must be one CSS identifier; "${name[end]}" cannot appear in one`;
341
- }
342
- return null;
343
- }
@@ -1,11 +0,0 @@
1
- /** Return a normalized navigation URL, or null for a blocked scheme. */
2
- export declare function sanitizeUrl(url: string): string | null;
3
- /** Inspect a navigation string without changing the value used by its sink. */
4
- export declare function isSafeUrl(url: string): boolean;
5
- /**
6
- * Inspect React Router paths, Next.js URL objects, and URL instances without
7
- * serializing or replacing the object handed to the router. Search/query/hash
8
- * are route-relative data, not schemes. Absent destinations remain absent.
9
- */
10
- export declare function isSafeDestination(destination: unknown): boolean;
11
- //# sourceMappingURL=safeUrl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"safeUrl.d.ts","sourceRoot":"","sources":["../../src/utils/safeUrl.ts"],"names":[],"mappings":"AAcA,wEAAwE;AACxE,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAWtD;AAED,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,CA8C/D"}