@dazl/shorthands-opener 4.2.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.
Files changed (237) hide show
  1. package/README.md +3 -0
  2. package/dist/compounds/compound-css-data.d.ts +22 -0
  3. package/dist/compounds/compound-css-data.d.ts.map +1 -0
  4. package/dist/compounds/compound-css-data.js +2 -0
  5. package/dist/compounds/compound-css-data.js.map +1 -0
  6. package/dist/compounds/compound-mapper.d.ts +4 -0
  7. package/dist/compounds/compound-mapper.d.ts.map +1 -0
  8. package/dist/compounds/compound-mapper.js +10 -0
  9. package/dist/compounds/compound-mapper.js.map +1 -0
  10. package/dist/compounds/compound-parser-utils.d.ts +3 -0
  11. package/dist/compounds/compound-parser-utils.d.ts.map +1 -0
  12. package/dist/compounds/compound-parser-utils.js +33 -0
  13. package/dist/compounds/compound-parser-utils.js.map +1 -0
  14. package/dist/compounds/compound-types.d.ts +26 -0
  15. package/dist/compounds/compound-types.d.ts.map +1 -0
  16. package/dist/compounds/compound-types.js +2 -0
  17. package/dist/compounds/compound-types.js.map +1 -0
  18. package/dist/compounds/compound-value-parsers.d.ts +6 -0
  19. package/dist/compounds/compound-value-parsers.d.ts.map +1 -0
  20. package/dist/compounds/compound-value-parsers.js +5 -0
  21. package/dist/compounds/compound-value-parsers.js.map +1 -0
  22. package/dist/compounds/index.d.ts +6 -0
  23. package/dist/compounds/index.d.ts.map +1 -0
  24. package/dist/compounds/index.js +6 -0
  25. package/dist/compounds/index.js.map +1 -0
  26. package/dist/compounds/parsers/index.d.ts +2 -0
  27. package/dist/compounds/parsers/index.d.ts.map +1 -0
  28. package/dist/compounds/parsers/index.js +2 -0
  29. package/dist/compounds/parsers/index.js.map +1 -0
  30. package/dist/compounds/parsers/shadow-compound.d.ts +5 -0
  31. package/dist/compounds/parsers/shadow-compound.d.ts.map +1 -0
  32. package/dist/compounds/parsers/shadow-compound.js +39 -0
  33. package/dist/compounds/parsers/shadow-compound.js.map +1 -0
  34. package/dist/css-data-types/data-types-consts.d.ts +212 -0
  35. package/dist/css-data-types/data-types-consts.d.ts.map +1 -0
  36. package/dist/css-data-types/data-types-consts.js +790 -0
  37. package/dist/css-data-types/data-types-consts.js.map +1 -0
  38. package/dist/css-data-types/data-types-predicates.d.ts +32 -0
  39. package/dist/css-data-types/data-types-predicates.d.ts.map +1 -0
  40. package/dist/css-data-types/data-types-predicates.js +353 -0
  41. package/dist/css-data-types/data-types-predicates.js.map +1 -0
  42. package/dist/css-data-types/data-types-state-machines.d.ts +14 -0
  43. package/dist/css-data-types/data-types-state-machines.d.ts.map +1 -0
  44. package/dist/css-data-types/data-types-state-machines.js +129 -0
  45. package/dist/css-data-types/data-types-state-machines.js.map +1 -0
  46. package/dist/css-data-types/data-types-types.d.ts +26 -0
  47. package/dist/css-data-types/data-types-types.d.ts.map +1 -0
  48. package/dist/css-data-types/data-types-types.js +2 -0
  49. package/dist/css-data-types/data-types-types.js.map +1 -0
  50. package/dist/css-data-types/data-types-utils.d.ts +31 -0
  51. package/dist/css-data-types/data-types-utils.d.ts.map +1 -0
  52. package/dist/css-data-types/data-types-utils.js +176 -0
  53. package/dist/css-data-types/data-types-utils.js.map +1 -0
  54. package/dist/css-data-types/data-types.d.ts +64 -0
  55. package/dist/css-data-types/data-types.d.ts.map +1 -0
  56. package/dist/css-data-types/data-types.js +304 -0
  57. package/dist/css-data-types/data-types.js.map +1 -0
  58. package/dist/css-data-types/index.d.ts +7 -0
  59. package/dist/css-data-types/index.d.ts.map +1 -0
  60. package/dist/css-data-types/index.js +7 -0
  61. package/dist/css-data-types/index.js.map +1 -0
  62. package/dist/index.d.ts +5 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +5 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/shorthands/index.d.ts +8 -0
  67. package/dist/shorthands/index.d.ts.map +1 -0
  68. package/dist/shorthands/index.js +8 -0
  69. package/dist/shorthands/index.js.map +1 -0
  70. package/dist/shorthands/openers/background-position-shorthand.d.ts +5 -0
  71. package/dist/shorthands/openers/background-position-shorthand.d.ts.map +1 -0
  72. package/dist/shorthands/openers/background-position-shorthand.js +173 -0
  73. package/dist/shorthands/openers/background-position-shorthand.js.map +1 -0
  74. package/dist/shorthands/openers/background-shorthand.d.ts +5 -0
  75. package/dist/shorthands/openers/background-shorthand.d.ts.map +1 -0
  76. package/dist/shorthands/openers/background-shorthand.js +88 -0
  77. package/dist/shorthands/openers/background-shorthand.js.map +1 -0
  78. package/dist/shorthands/openers/border-image-shorthand.d.ts +5 -0
  79. package/dist/shorthands/openers/border-image-shorthand.d.ts.map +1 -0
  80. package/dist/shorthands/openers/border-image-shorthand.js +16 -0
  81. package/dist/shorthands/openers/border-image-shorthand.js.map +1 -0
  82. package/dist/shorthands/openers/border-radius-shorthand.d.ts +5 -0
  83. package/dist/shorthands/openers/border-radius-shorthand.d.ts.map +1 -0
  84. package/dist/shorthands/openers/border-radius-shorthand.js +61 -0
  85. package/dist/shorthands/openers/border-radius-shorthand.js.map +1 -0
  86. package/dist/shorthands/openers/border-shorthand.d.ts +20 -0
  87. package/dist/shorthands/openers/border-shorthand.d.ts.map +1 -0
  88. package/dist/shorthands/openers/border-shorthand.js +90 -0
  89. package/dist/shorthands/openers/border-shorthand.js.map +1 -0
  90. package/dist/shorthands/openers/flex-flow-shorthand.d.ts +5 -0
  91. package/dist/shorthands/openers/flex-flow-shorthand.d.ts.map +1 -0
  92. package/dist/shorthands/openers/flex-flow-shorthand.js +13 -0
  93. package/dist/shorthands/openers/flex-flow-shorthand.js.map +1 -0
  94. package/dist/shorthands/openers/flex-shorthand.d.ts +5 -0
  95. package/dist/shorthands/openers/flex-shorthand.d.ts.map +1 -0
  96. package/dist/shorthands/openers/flex-shorthand.js +55 -0
  97. package/dist/shorthands/openers/flex-shorthand.js.map +1 -0
  98. package/dist/shorthands/openers/font-shorthand.d.ts +5 -0
  99. package/dist/shorthands/openers/font-shorthand.d.ts.map +1 -0
  100. package/dist/shorthands/openers/font-shorthand.js +60 -0
  101. package/dist/shorthands/openers/font-shorthand.js.map +1 -0
  102. package/dist/shorthands/openers/gap-shorthand.d.ts +5 -0
  103. package/dist/shorthands/openers/gap-shorthand.d.ts.map +1 -0
  104. package/dist/shorthands/openers/gap-shorthand.js +28 -0
  105. package/dist/shorthands/openers/gap-shorthand.js.map +1 -0
  106. package/dist/shorthands/openers/grid-axis-shorthand.d.ts +6 -0
  107. package/dist/shorthands/openers/grid-axis-shorthand.d.ts.map +1 -0
  108. package/dist/shorthands/openers/grid-axis-shorthand.js +36 -0
  109. package/dist/shorthands/openers/grid-axis-shorthand.js.map +1 -0
  110. package/dist/shorthands/openers/grid-gap-shorthand.d.ts +5 -0
  111. package/dist/shorthands/openers/grid-gap-shorthand.d.ts.map +1 -0
  112. package/dist/shorthands/openers/grid-gap-shorthand.js +21 -0
  113. package/dist/shorthands/openers/grid-gap-shorthand.js.map +1 -0
  114. package/dist/shorthands/openers/grid-shorthand.d.ts +8 -0
  115. package/dist/shorthands/openers/grid-shorthand.d.ts.map +1 -0
  116. package/dist/shorthands/openers/grid-shorthand.js +145 -0
  117. package/dist/shorthands/openers/grid-shorthand.js.map +1 -0
  118. package/dist/shorthands/openers/grid-template-shorthand.d.ts +10 -0
  119. package/dist/shorthands/openers/grid-template-shorthand.d.ts.map +1 -0
  120. package/dist/shorthands/openers/grid-template-shorthand.js +113 -0
  121. package/dist/shorthands/openers/grid-template-shorthand.js.map +1 -0
  122. package/dist/shorthands/openers/index.d.ts +22 -0
  123. package/dist/shorthands/openers/index.d.ts.map +1 -0
  124. package/dist/shorthands/openers/index.js +22 -0
  125. package/dist/shorthands/openers/index.js.map +1 -0
  126. package/dist/shorthands/openers/list-style-shorthand.d.ts +5 -0
  127. package/dist/shorthands/openers/list-style-shorthand.d.ts.map +1 -0
  128. package/dist/shorthands/openers/list-style-shorthand.js +15 -0
  129. package/dist/shorthands/openers/list-style-shorthand.js.map +1 -0
  130. package/dist/shorthands/openers/margin-shorthand.d.ts +5 -0
  131. package/dist/shorthands/openers/margin-shorthand.d.ts.map +1 -0
  132. package/dist/shorthands/openers/margin-shorthand.js +11 -0
  133. package/dist/shorthands/openers/margin-shorthand.js.map +1 -0
  134. package/dist/shorthands/openers/outline-shorthand.d.ts +5 -0
  135. package/dist/shorthands/openers/outline-shorthand.d.ts.map +1 -0
  136. package/dist/shorthands/openers/outline-shorthand.js +14 -0
  137. package/dist/shorthands/openers/outline-shorthand.js.map +1 -0
  138. package/dist/shorthands/openers/overflow-shorthand.d.ts +5 -0
  139. package/dist/shorthands/openers/overflow-shorthand.d.ts.map +1 -0
  140. package/dist/shorthands/openers/overflow-shorthand.js +21 -0
  141. package/dist/shorthands/openers/overflow-shorthand.js.map +1 -0
  142. package/dist/shorthands/openers/padding-shorthand.d.ts +5 -0
  143. package/dist/shorthands/openers/padding-shorthand.d.ts.map +1 -0
  144. package/dist/shorthands/openers/padding-shorthand.js +11 -0
  145. package/dist/shorthands/openers/padding-shorthand.js.map +1 -0
  146. package/dist/shorthands/openers/place-content-shorthand.d.ts +5 -0
  147. package/dist/shorthands/openers/place-content-shorthand.d.ts.map +1 -0
  148. package/dist/shorthands/openers/place-content-shorthand.js +29 -0
  149. package/dist/shorthands/openers/place-content-shorthand.js.map +1 -0
  150. package/dist/shorthands/openers/place-items-shorthand.d.ts +5 -0
  151. package/dist/shorthands/openers/place-items-shorthand.d.ts.map +1 -0
  152. package/dist/shorthands/openers/place-items-shorthand.js +23 -0
  153. package/dist/shorthands/openers/place-items-shorthand.js.map +1 -0
  154. package/dist/shorthands/openers/text-decoration-shorthand.d.ts +5 -0
  155. package/dist/shorthands/openers/text-decoration-shorthand.d.ts.map +1 -0
  156. package/dist/shorthands/openers/text-decoration-shorthand.js +14 -0
  157. package/dist/shorthands/openers/text-decoration-shorthand.js.map +1 -0
  158. package/dist/shorthands/shorthand-css-data.d.ts +120 -0
  159. package/dist/shorthands/shorthand-css-data.d.ts.map +1 -0
  160. package/dist/shorthands/shorthand-css-data.js +48 -0
  161. package/dist/shorthands/shorthand-css-data.js.map +1 -0
  162. package/dist/shorthands/shorthand-mapper.d.ts +6 -0
  163. package/dist/shorthands/shorthand-mapper.d.ts.map +1 -0
  164. package/dist/shorthands/shorthand-mapper.js +72 -0
  165. package/dist/shorthands/shorthand-mapper.js.map +1 -0
  166. package/dist/shorthands/shorthand-parser-errors.d.ts +25 -0
  167. package/dist/shorthands/shorthand-parser-errors.d.ts.map +1 -0
  168. package/dist/shorthands/shorthand-parser-errors.js +41 -0
  169. package/dist/shorthands/shorthand-parser-errors.js.map +1 -0
  170. package/dist/shorthands/shorthand-parser-utils.d.ts +24 -0
  171. package/dist/shorthands/shorthand-parser-utils.d.ts.map +1 -0
  172. package/dist/shorthands/shorthand-parser-utils.js +398 -0
  173. package/dist/shorthands/shorthand-parser-utils.js.map +1 -0
  174. package/dist/shorthands/shorthand-types.d.ts +64 -0
  175. package/dist/shorthands/shorthand-types.d.ts.map +1 -0
  176. package/dist/shorthands/shorthand-types.js +2 -0
  177. package/dist/shorthands/shorthand-types.js.map +1 -0
  178. package/dist/shorthands/shorthands-ast-evaluation.d.ts +5 -0
  179. package/dist/shorthands/shorthands-ast-evaluation.d.ts.map +1 -0
  180. package/dist/shorthands/shorthands-ast-evaluation.js +19 -0
  181. package/dist/shorthands/shorthands-ast-evaluation.js.map +1 -0
  182. package/dist/tokenizers/css-value-tokenizer.d.ts +43 -0
  183. package/dist/tokenizers/css-value-tokenizer.d.ts.map +1 -0
  184. package/dist/tokenizers/css-value-tokenizer.js +154 -0
  185. package/dist/tokenizers/css-value-tokenizer.js.map +1 -0
  186. package/dist/tokenizers/index.d.ts +2 -0
  187. package/dist/tokenizers/index.d.ts.map +1 -0
  188. package/dist/tokenizers/index.js +2 -0
  189. package/dist/tokenizers/index.js.map +1 -0
  190. package/package.json +54 -0
  191. package/src/compounds/compound-css-data.ts +24 -0
  192. package/src/compounds/compound-mapper.ts +21 -0
  193. package/src/compounds/compound-parser-utils.ts +47 -0
  194. package/src/compounds/compound-types.ts +35 -0
  195. package/src/compounds/compound-value-parsers.ts +12 -0
  196. package/src/compounds/index.ts +5 -0
  197. package/src/compounds/parsers/index.ts +1 -0
  198. package/src/compounds/parsers/shadow-compound.ts +56 -0
  199. package/src/css-data-types/data-types-consts.ts +877 -0
  200. package/src/css-data-types/data-types-predicates.ts +477 -0
  201. package/src/css-data-types/data-types-state-machines.ts +169 -0
  202. package/src/css-data-types/data-types-types.ts +43 -0
  203. package/src/css-data-types/data-types-utils.ts +258 -0
  204. package/src/css-data-types/data-types.ts +435 -0
  205. package/src/css-data-types/index.ts +6 -0
  206. package/src/index.ts +4 -0
  207. package/src/shorthands/index.ts +7 -0
  208. package/src/shorthands/openers/background-position-shorthand.ts +180 -0
  209. package/src/shorthands/openers/background-shorthand.ts +161 -0
  210. package/src/shorthands/openers/border-image-shorthand.ts +35 -0
  211. package/src/shorthands/openers/border-radius-shorthand.ts +93 -0
  212. package/src/shorthands/openers/border-shorthand.ts +198 -0
  213. package/src/shorthands/openers/flex-flow-shorthand.ts +24 -0
  214. package/src/shorthands/openers/flex-shorthand.ts +79 -0
  215. package/src/shorthands/openers/font-shorthand.ts +85 -0
  216. package/src/shorthands/openers/gap-shorthand.ts +47 -0
  217. package/src/shorthands/openers/grid-axis-shorthand.ts +61 -0
  218. package/src/shorthands/openers/grid-gap-shorthand.ts +40 -0
  219. package/src/shorthands/openers/grid-shorthand.ts +260 -0
  220. package/src/shorthands/openers/grid-template-shorthand.ts +176 -0
  221. package/src/shorthands/openers/index.ts +21 -0
  222. package/src/shorthands/openers/list-style-shorthand.ts +33 -0
  223. package/src/shorthands/openers/margin-shorthand.ts +20 -0
  224. package/src/shorthands/openers/outline-shorthand.ts +27 -0
  225. package/src/shorthands/openers/overflow-shorthand.ts +40 -0
  226. package/src/shorthands/openers/padding-shorthand.ts +21 -0
  227. package/src/shorthands/openers/place-content-shorthand.ts +49 -0
  228. package/src/shorthands/openers/place-items-shorthand.ts +43 -0
  229. package/src/shorthands/openers/text-decoration-shorthand.ts +27 -0
  230. package/src/shorthands/shorthand-css-data.ts +210 -0
  231. package/src/shorthands/shorthand-mapper.ts +157 -0
  232. package/src/shorthands/shorthand-parser-errors.ts +47 -0
  233. package/src/shorthands/shorthand-parser-utils.ts +602 -0
  234. package/src/shorthands/shorthand-types.ts +107 -0
  235. package/src/shorthands/shorthands-ast-evaluation.ts +38 -0
  236. package/src/tokenizers/css-value-tokenizer.ts +220 -0
  237. package/src/tokenizers/index.ts +1 -0
@@ -0,0 +1,38 @@
1
+ import type { CSSCodeAst } from '../tokenizers/index.js';
2
+ import type { CSSAstNode, ParseShorthandAPI, EvaluatedAst, AstEvaluator } from './shorthand-types.js';
3
+
4
+ const createEvaluateAst =
5
+ <V, T>(
6
+ handleExpression: (node: V, api: ParseShorthandAPI<V>) => T[],
7
+ handleNonExpression: (node: CSSCodeAst) => T,
8
+ ): AstEvaluator<V, T> =>
9
+ (ast, api) => {
10
+ const res: T[] = [];
11
+ for (const node of ast) {
12
+ if (api.isExpression(node)) {
13
+ res.push(...handleExpression(node, api));
14
+ } else {
15
+ res.push(handleNonExpression(node));
16
+ }
17
+ }
18
+ return res;
19
+ };
20
+
21
+ const evaluateExpression = <V>(node: V, api: ParseShorthandAPI<V>) => evaluateAstInner(api.getValue(node), api);
22
+
23
+ const evaluateAstInner = <V>(ast: CSSCodeAst[], api: ParseShorthandAPI<V>): CSSCodeAst[] =>
24
+ createEvaluateAst<V, CSSCodeAst>(
25
+ (node, api) => evaluateExpression(node, api),
26
+ (node) => node,
27
+ )(ast, api);
28
+
29
+ const evaluateCodeNode = <V>(value: CSSCodeAst): EvaluatedAst<V> => ({ value });
30
+ export const codeToEvaluatedAst = <V>(ast: CSSCodeAst[]): EvaluatedAst<V>[] =>
31
+ ast.map((value) => evaluateCodeNode<V>(value));
32
+
33
+ // TODO: Always have origin to values that don't come from an initial value (that are specified directly)
34
+ export const evaluateAst = <V>(ast: CSSAstNode<V>[], api: ParseShorthandAPI<V>): EvaluatedAst<V>[] =>
35
+ createEvaluateAst<V, EvaluatedAst<V>>(
36
+ (origin, api) => evaluateExpression(origin, api).map((value) => ({ value, origin })),
37
+ evaluateCodeNode,
38
+ )(ast, api);
@@ -0,0 +1,220 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
2
+
3
+ import {
4
+ type Token,
5
+ type Descriptors,
6
+ tokenize,
7
+ isStringDelimiter,
8
+ isWhitespace,
9
+ getJSCommentStartType,
10
+ getMultilineCommentStartType,
11
+ isCommentEnd,
12
+ createToken,
13
+ getText,
14
+ getUnclosedComment,
15
+ } from '@tokey/core';
16
+
17
+ export type { Descriptors };
18
+ export type Delimiters = '(' | ')' | ',' | '/';
19
+ export type SeparatorTokens = 'line-comment' | 'multi-comment' | 'space';
20
+ export type CSSValueCodeToken = Token<Descriptors | Delimiters>;
21
+ export type CSSSeparatorTokens = Token<SeparatorTokens>;
22
+ export type CSSCodeAst = StringNode | MethodCall | TextNode | CommaNode | SlashNode;
23
+ export interface ASTNode<Types = Descriptors> {
24
+ type: Types;
25
+ text: string;
26
+ start: number;
27
+ end: number;
28
+ before: CSSSeparatorTokens[];
29
+ after: CSSSeparatorTokens[];
30
+ }
31
+
32
+ export interface MethodCall extends ASTNode<'call'> {
33
+ name: string;
34
+ args: CSSCodeAst[];
35
+ }
36
+
37
+ export interface StringNode extends ASTNode<'string'> {}
38
+ export interface TextNode extends ASTNode<'text'> {}
39
+ export interface CommaNode extends ASTNode<','> {}
40
+ export interface SlashNode extends ASTNode<'/'> {}
41
+
42
+ export const DEFAULT_POSITION = -1;
43
+ export const URL_CALL_TOKEN = 'url';
44
+
45
+ export const isSeparatorToken = (token: CSSValueCodeToken): token is CSSSeparatorTokens => {
46
+ const { type } = token;
47
+ return type === 'line-comment' || type === 'multi-comment' || type === 'space';
48
+ };
49
+
50
+ export const isCSSCodeAst = (ast: unknown): ast is CSSCodeAst => {
51
+ const node = ast as CSSCodeAst;
52
+ return (
53
+ node.text !== undefined &&
54
+ node.type !== undefined &&
55
+ (node.type === 'string' ||
56
+ node.type === 'call' ||
57
+ node.type === 'text' ||
58
+ node.type === ',' ||
59
+ node.type === '/')
60
+ );
61
+ };
62
+
63
+ export function createCssValueAST(source: string, parseLineComments = false): CSSCodeAst[] {
64
+ return parseDeclValueTokens(
65
+ source,
66
+ tokenize<CSSValueCodeToken>(source, {
67
+ isDelimiter,
68
+ isStringDelimiter,
69
+ isWhitespace,
70
+ shouldAddToken,
71
+ createToken,
72
+ getCommentStartType: parseLineComments ? getJSCommentStartType : getMultilineCommentStartType,
73
+ isCommentEnd,
74
+ getUnclosedComment,
75
+ }),
76
+ ).ast;
77
+ }
78
+
79
+ const isDelimiter = (char: string) => char === '(' || char === ')' || char === ',' || char === '/';
80
+
81
+ const shouldAddToken = () => true;
82
+
83
+ function parseDeclValueTokens(
84
+ source: string,
85
+ tokens: CSSValueCodeToken[],
86
+ startAtIdx = 0,
87
+ ): { ast: CSSCodeAst[]; stoppedAtIdx: number } {
88
+ const ast: CSSCodeAst[] = [];
89
+ let before: CSSSeparatorTokens[] = [];
90
+ for (let i = startAtIdx; i < tokens.length; i++) {
91
+ const token = tokens[i]!;
92
+ if (token.type === ')') {
93
+ const lastAst = ast[ast.length - 1];
94
+ if (lastAst && before.length) {
95
+ lastAst.after = before;
96
+ before = [];
97
+ }
98
+ return {
99
+ ast,
100
+ stoppedAtIdx: i,
101
+ };
102
+ } else if (isSeparatorToken(token)) {
103
+ before.push(token);
104
+ } else if (token.type === 'text' && tokens[i + 1]?.type === '(') {
105
+ const res = parseDeclValueTokens(source, tokens, i + 2);
106
+ const methodText = getText(tokens, i, res.stoppedAtIdx + 1, source);
107
+ i = res.stoppedAtIdx;
108
+ res.ast = getUrlTokensAst(token, res.ast);
109
+ ast.push({
110
+ type: 'call',
111
+ text: methodText,
112
+ start: token.start,
113
+ end: token.start + methodText.length,
114
+ before,
115
+ after: [],
116
+ name: token.value,
117
+ args: res.ast,
118
+ });
119
+ before = [];
120
+ } else {
121
+ ast.push({
122
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
123
+ type: token.type as any, // eslint-disable-line @typescript-eslint/no-explicit-any
124
+ text: token.value,
125
+ start: token.start,
126
+ end: token.end,
127
+ before,
128
+ after: [],
129
+ });
130
+ before = [];
131
+ }
132
+ }
133
+
134
+ return {
135
+ ast,
136
+ stoppedAtIdx: tokens.length,
137
+ };
138
+ }
139
+
140
+ function getUrlTokensAst(token: CSSValueCodeToken, ast: CSSCodeAst[]): CSSCodeAst[] {
141
+ if (token.value !== URL_CALL_TOKEN || ast.length === 0) {
142
+ return ast;
143
+ }
144
+
145
+ const pushFixedTextNodeToFixedAst = () => {
146
+ if (fixedTextNode) {
147
+ fixedTextNode.end = fixedTextNode.start + fixedTextNode.text.length;
148
+ fixedAst.push(fixedTextNode);
149
+ fixedTextNode = null;
150
+ }
151
+ };
152
+
153
+ let fixedTextNode: TextNode | null = null;
154
+ const fixedAst: CSSCodeAst[] = [];
155
+ for (const node of ast) {
156
+ if (node.type === '/' || node.type === 'text') {
157
+ if (!fixedTextNode) {
158
+ fixedTextNode = {
159
+ type: 'text',
160
+ text: '',
161
+ before: node.before,
162
+ after: [],
163
+ start: node.start,
164
+ end: DEFAULT_POSITION,
165
+ };
166
+ }
167
+ fixedTextNode.text += node.text;
168
+ } else {
169
+ pushFixedTextNodeToFixedAst();
170
+ fixedAst.push(node);
171
+ }
172
+ }
173
+
174
+ pushFixedTextNodeToFixedAst();
175
+
176
+ return fixedAst;
177
+ }
178
+
179
+ export interface NodePositions {
180
+ beforeStart: number;
181
+ beforeEnd: number;
182
+ start: number;
183
+ end: number;
184
+ }
185
+
186
+ export const getNodePositions = (text: string, pos?: number, spaceBefore?: string): NodePositions => ({
187
+ beforeStart: !spaceBefore || pos === undefined ? DEFAULT_POSITION : pos - spaceBefore.length,
188
+ beforeEnd: !spaceBefore || pos === undefined ? DEFAULT_POSITION : pos,
189
+ start: pos === undefined ? DEFAULT_POSITION : pos,
190
+ end: pos === undefined ? DEFAULT_POSITION : pos + text.length,
191
+ });
192
+
193
+ export const valueTextNode = (text: string, pos?: number, spaceBefore?: string): TextNode => {
194
+ const { start, end, beforeEnd, beforeStart } = getNodePositions(text, pos, spaceBefore);
195
+ return {
196
+ type: 'text',
197
+ start,
198
+ end,
199
+ before: spaceBefore
200
+ ? [
201
+ {
202
+ type: 'space',
203
+ start: beforeStart,
204
+ end: beforeEnd,
205
+ value: spaceBefore,
206
+ },
207
+ ]
208
+ : [],
209
+ after: [],
210
+ text,
211
+ };
212
+ };
213
+
214
+ export const getTokensText = (tokens: CSSSeparatorTokens[]): string => {
215
+ return tokens.map((token) => token.value).join('');
216
+ };
217
+
218
+ export const getFullText = (ast: CSSCodeAst): string => {
219
+ return getTokensText(ast.before) + ast.text + getTokensText(ast.after);
220
+ };
@@ -0,0 +1 @@
1
+ export * from './css-value-tokenizer.js';