@tamagui/language-service 0.0.0-bootstrap.0 → 3.0.0-beta.643.1

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 (80) hide show
  1. package/README.md +140 -1
  2. package/dist/cjs/check.cjs +173 -0
  3. package/dist/cjs/check.native.cjs +369 -0
  4. package/dist/cjs/check.native.js +371 -0
  5. package/dist/cjs/check.native.js.map +1 -0
  6. package/dist/cjs/core.cjs +221 -0
  7. package/dist/cjs/core.native.cjs +305 -0
  8. package/dist/cjs/core.native.js +307 -0
  9. package/dist/cjs/core.native.js.map +1 -0
  10. package/dist/cjs/document.cjs +82 -0
  11. package/dist/cjs/document.native.cjs +158 -0
  12. package/dist/cjs/document.native.js +160 -0
  13. package/dist/cjs/document.native.js.map +1 -0
  14. package/dist/cjs/extract-estree.cjs +193 -0
  15. package/dist/cjs/extract-estree.native.cjs +296 -0
  16. package/dist/cjs/extract-estree.native.js +298 -0
  17. package/dist/cjs/extract-estree.native.js.map +1 -0
  18. package/dist/cjs/extract-sucrase.cjs +222 -0
  19. package/dist/cjs/extract-sucrase.native.cjs +256 -0
  20. package/dist/cjs/extract-sucrase.native.js +258 -0
  21. package/dist/cjs/extract-sucrase.native.js.map +1 -0
  22. package/dist/cjs/host.cjs +38 -0
  23. package/dist/cjs/host.native.cjs +61 -0
  24. package/dist/cjs/host.native.js +63 -0
  25. package/dist/cjs/host.native.js.map +1 -0
  26. package/dist/cjs/index.cjs +301 -0
  27. package/dist/cjs/index.native.cjs +414 -0
  28. package/dist/cjs/index.native.js +416 -0
  29. package/dist/cjs/index.native.js.map +1 -0
  30. package/dist/esm/check.mjs +148 -0
  31. package/dist/esm/check.mjs.map +1 -0
  32. package/dist/esm/check.native.js +342 -0
  33. package/dist/esm/check.native.js.map +1 -0
  34. package/dist/esm/core.mjs +198 -0
  35. package/dist/esm/core.mjs.map +1 -0
  36. package/dist/esm/core.native.js +280 -0
  37. package/dist/esm/core.native.js.map +1 -0
  38. package/dist/esm/document.mjs +61 -0
  39. package/dist/esm/document.mjs.map +1 -0
  40. package/dist/esm/document.native.js +135 -0
  41. package/dist/esm/document.native.js.map +1 -0
  42. package/dist/esm/extract-estree.mjs +172 -0
  43. package/dist/esm/extract-estree.mjs.map +1 -0
  44. package/dist/esm/extract-estree.native.js +273 -0
  45. package/dist/esm/extract-estree.native.js.map +1 -0
  46. package/dist/esm/extract-sucrase.mjs +201 -0
  47. package/dist/esm/extract-sucrase.mjs.map +1 -0
  48. package/dist/esm/extract-sucrase.native.js +233 -0
  49. package/dist/esm/extract-sucrase.native.js.map +1 -0
  50. package/dist/esm/host.mjs +17 -0
  51. package/dist/esm/host.mjs.map +1 -0
  52. package/dist/esm/host.native.js +38 -0
  53. package/dist/esm/host.native.js.map +1 -0
  54. package/dist/esm/index.mjs +281 -0
  55. package/dist/esm/index.mjs.map +1 -0
  56. package/dist/esm/index.native.js +392 -0
  57. package/dist/esm/index.native.js.map +1 -0
  58. package/index.cjs +1 -0
  59. package/package.json +79 -7
  60. package/src/check.ts +204 -0
  61. package/src/core.ts +355 -0
  62. package/src/document.ts +140 -0
  63. package/src/extract-estree.ts +251 -0
  64. package/src/extract-sucrase.ts +308 -0
  65. package/src/host.ts +32 -0
  66. package/src/index.ts +452 -0
  67. package/types/check.d.ts +31 -0
  68. package/types/check.d.ts.map +11 -0
  69. package/types/core.d.ts +68 -0
  70. package/types/core.d.ts.map +11 -0
  71. package/types/document.d.ts +42 -0
  72. package/types/document.d.ts.map +11 -0
  73. package/types/extract-estree.d.ts +19 -0
  74. package/types/extract-estree.d.ts.map +11 -0
  75. package/types/extract-sucrase.d.ts +26 -0
  76. package/types/extract-sucrase.d.ts.map +11 -0
  77. package/types/host.d.ts +10 -0
  78. package/types/host.d.ts.map +11 -0
  79. package/types/index.d.ts +9 -0
  80. package/types/index.d.ts.map +11 -0
package/src/index.ts ADDED
@@ -0,0 +1,452 @@
1
+ import { isAbsolute, resolve } from 'node:path'
2
+
3
+ import type ts from 'typescript'
4
+ import {
5
+ completionSortText,
6
+ createStyleTooling,
7
+ type SerializedConfigFile,
8
+ type StyleTooling,
9
+ } from './core'
10
+ import { resolveTamaguiHost } from './host'
11
+
12
+ const completionSource = '@tamagui/language-service'
13
+ const diagnosticCode = 78711
14
+ const defaultConfigPath = '.tamagui/tamagui.config.json'
15
+ const flatStyledModules: ReadonlySet<string> = new Set([
16
+ 'tamagui',
17
+ 'tamagui/unstyled',
18
+ '@tamagui/core',
19
+ '@tamagui/ui',
20
+ '@tamagui/web',
21
+ ])
22
+
23
+ export interface TamaguiLanguageServicePluginConfig {
24
+ /** Path to the config JSON emitted by the Tamagui compiler. */
25
+ configPath?: string
26
+ }
27
+
28
+ type ImportedBindings = {
29
+ styled: ReadonlySet<string>
30
+ }
31
+
32
+ type LiteralSite = {
33
+ property: string
34
+ /** cooked value, identical to its authored source text */
35
+ value: string
36
+ /** file offset of the value's first character */
37
+ contentStart: number
38
+ literal: ts.StringLiteralLike
39
+ }
40
+
41
+ function loadTooling(
42
+ info: ts.server.PluginCreateInfo,
43
+ configPath: string
44
+ ): StyleTooling | null {
45
+ const contents = info.serverHost.readFile(configPath)
46
+ if (contents === undefined) return null
47
+ try {
48
+ return createStyleTooling(JSON.parse(contents) as SerializedConfigFile)
49
+ } catch {
50
+ return null
51
+ }
52
+ }
53
+
54
+ function findStringLiteralAtPosition(
55
+ typescript: typeof ts,
56
+ sourceFile: ts.SourceFile,
57
+ position: number
58
+ ): ts.StringLiteralLike | null {
59
+ let found: ts.StringLiteralLike | null = null
60
+ const visit = (node: ts.Node): void => {
61
+ if (position < node.getFullStart() || position > node.getEnd()) return
62
+ if (
63
+ typescript.isStringLiteralLike(node) &&
64
+ position >= node.getStart(sourceFile) + 1 &&
65
+ position <= node.getEnd() - 1
66
+ ) {
67
+ found = node
68
+ return
69
+ }
70
+ typescript.forEachChild(node, visit)
71
+ }
72
+ visit(sourceFile)
73
+ return found
74
+ }
75
+
76
+ function importedBindings(
77
+ typescript: typeof ts,
78
+ sourceFile: ts.SourceFile
79
+ ): ImportedBindings {
80
+ const styled = new Set<string>()
81
+
82
+ for (const statement of sourceFile.statements) {
83
+ if (
84
+ !typescript.isImportDeclaration(statement) ||
85
+ !typescript.isStringLiteral(statement.moduleSpecifier)
86
+ ) {
87
+ continue
88
+ }
89
+ const source = statement.moduleSpecifier.text
90
+ if (!flatStyledModules.has(source)) continue
91
+ const bindings = statement.importClause?.namedBindings
92
+ if (!bindings) continue
93
+ if (typescript.isNamespaceImport(bindings)) continue
94
+ for (const element of bindings.elements) {
95
+ const imported = element.propertyName?.text || element.name.text
96
+ if (imported === 'styled') styled.add(element.name.text)
97
+ }
98
+ }
99
+
100
+ return { styled }
101
+ }
102
+
103
+ function propertyName(typescript: typeof ts, name: ts.PropertyName): string | null {
104
+ if (typescript.isIdentifier(name) || typescript.isStringLiteral(name)) {
105
+ return name.text
106
+ }
107
+ return null
108
+ }
109
+
110
+ function completionProperty(
111
+ typescript: typeof ts,
112
+ literal: ts.StringLiteralLike,
113
+ tooling: StyleTooling,
114
+ checker: ts.TypeChecker,
115
+ bindings: ImportedBindings
116
+ ): { property: string } | null {
117
+ let parent = literal.parent
118
+
119
+ if (typescript.isJsxExpression(parent)) parent = parent.parent
120
+ if (typescript.isJsxAttribute(parent)) {
121
+ if (!typescript.isIdentifier(parent.name)) return null
122
+ const property = parent.name.text
123
+ if (!tooling.styleProps.has(property)) return null
124
+ const opening = parent.parent.parent
125
+ if (!typescript.isJsxOpeningLikeElement(opening)) return null
126
+ const host = resolveTamaguiHost(checker, opening.tagName)
127
+ if (!host?.accepts(property)) return null
128
+ return { property }
129
+ }
130
+
131
+ if (!typescript.isPropertyAssignment(parent)) return null
132
+ const property = propertyName(typescript, parent.name)
133
+ if (!property || !tooling.styleProps.has(property)) return null
134
+
135
+ let current: ts.Node = parent
136
+ while (current.parent && !typescript.isCallExpression(current.parent)) {
137
+ current = current.parent
138
+ }
139
+ if (!current.parent || !typescript.isCallExpression(current.parent)) return null
140
+ const call = current.parent
141
+ if (
142
+ call.arguments[1] !== current ||
143
+ !typescript.isIdentifier(call.expression) ||
144
+ !bindings.styled.has(call.expression.text)
145
+ ) {
146
+ return null
147
+ }
148
+ const component = call.arguments[0]
149
+ const host = component && resolveTamaguiHost(checker, component)
150
+ if (!host?.accepts(property)) return null
151
+ return { property }
152
+ }
153
+
154
+ /**
155
+ * The literal as a style value site, or null when it is not one: wrong parent
156
+ * shape, not a style prop, not a tamagui host, or authored with escapes that
157
+ * cook differently than they read (TypeScript exposes cooked values but no
158
+ * cooked-to-source offset map, so exact-raw literals only).
159
+ */
160
+ function siteForLiteral(
161
+ typescript: typeof ts,
162
+ sourceFile: ts.SourceFile,
163
+ literal: ts.StringLiteralLike,
164
+ tooling: StyleTooling,
165
+ checker: ts.TypeChecker,
166
+ bindings: ImportedBindings
167
+ ): LiteralSite | null {
168
+ const site = completionProperty(typescript, literal, tooling, checker, bindings)
169
+ if (!site) return null
170
+ const contentStart = literal.getStart(sourceFile) + 1
171
+ const contentEnd = literal.getEnd() - 1
172
+ const sourceInput = sourceFile.text.slice(contentStart, contentEnd)
173
+ if (literal.text !== sourceInput) return null
174
+ return { property: site.property, value: literal.text, contentStart, literal }
175
+ }
176
+
177
+ function collectLiteralSites(
178
+ typescript: typeof ts,
179
+ sourceFile: ts.SourceFile,
180
+ tooling: StyleTooling,
181
+ checker: ts.TypeChecker,
182
+ bindings: ImportedBindings
183
+ ): LiteralSite[] {
184
+ const sites: LiteralSite[] = []
185
+ const visit = (node: ts.Node): void => {
186
+ if (typescript.isStringLiteralLike(node)) {
187
+ const site = siteForLiteral(
188
+ typescript,
189
+ sourceFile,
190
+ node,
191
+ tooling,
192
+ checker,
193
+ bindings
194
+ )
195
+ if (site) sites.push(site)
196
+ return
197
+ }
198
+ typescript.forEachChild(node, visit)
199
+ }
200
+ visit(sourceFile)
201
+ return sites
202
+ }
203
+
204
+ function copyLanguageService(service: ts.LanguageService): ts.LanguageService {
205
+ const proxy = Object.create(null) as ts.LanguageService
206
+ for (const key of Object.keys(service) as Array<keyof ts.LanguageService>) {
207
+ const value = service[key]
208
+ ;(proxy as unknown as Record<string, unknown>)[key] =
209
+ typeof value === 'function' ? value.bind(service) : value
210
+ }
211
+ return proxy
212
+ }
213
+
214
+ const init: ts.server.PluginModuleFactory = ({ typescript }) => ({
215
+ create(info) {
216
+ const pluginConfig = info.config as TamaguiLanguageServicePluginConfig | undefined
217
+ const configuredPath = pluginConfig?.configPath || defaultConfigPath
218
+ const configPath = isAbsolute(configuredPath)
219
+ ? configuredPath
220
+ : resolve(info.project.getCurrentDirectory(), configuredPath)
221
+ let tooling = loadTooling(info, configPath)
222
+ const watcher = info.serverHost.watchFile(configPath, () => {
223
+ tooling = loadTooling(info, configPath)
224
+ })
225
+
226
+ const proxy = copyLanguageService(info.languageService)
227
+ const baseCompletions = info.languageService.getCompletionsAtPosition.bind(
228
+ info.languageService
229
+ )
230
+ const baseDetails = info.languageService.getCompletionEntryDetails.bind(
231
+ info.languageService
232
+ )
233
+ const baseSemanticDiagnostics = info.languageService.getSemanticDiagnostics.bind(
234
+ info.languageService
235
+ )
236
+ const baseQuickInfo = info.languageService.getQuickInfoAtPosition.bind(
237
+ info.languageService
238
+ )
239
+ const baseDispose = info.languageService.dispose.bind(info.languageService)
240
+ const bindingsBySourceFile = new WeakMap<ts.SourceFile, ImportedBindings>()
241
+
242
+ const fileContext = (
243
+ fileName: string
244
+ ): {
245
+ sourceFile: ts.SourceFile
246
+ checker: ts.TypeChecker
247
+ bindings: ImportedBindings
248
+ } | null => {
249
+ const program = info.languageService.getProgram()
250
+ const sourceFile = program?.getSourceFile(fileName)
251
+ if (!program || !sourceFile) return null
252
+ let bindings = bindingsBySourceFile.get(sourceFile)
253
+ if (!bindings) {
254
+ bindings = importedBindings(typescript, sourceFile)
255
+ bindingsBySourceFile.set(sourceFile, bindings)
256
+ }
257
+ return { sourceFile, checker: program.getTypeChecker(), bindings }
258
+ }
259
+
260
+ proxy.getCompletionsAtPosition = (
261
+ fileName,
262
+ position,
263
+ options,
264
+ formattingSettings
265
+ ) => {
266
+ const getBaseCompletions = () =>
267
+ baseCompletions(fileName, position, options, formattingSettings)
268
+ if (!tooling) return getBaseCompletions()
269
+ const context = fileContext(fileName)
270
+ if (!context) return getBaseCompletions()
271
+ const { sourceFile, checker, bindings } = context
272
+ const literal = findStringLiteralAtPosition(typescript, sourceFile, position)
273
+ if (!literal) return getBaseCompletions()
274
+ const site = siteForLiteral(
275
+ typescript,
276
+ sourceFile,
277
+ literal,
278
+ tooling,
279
+ checker,
280
+ bindings
281
+ )
282
+ if (!site) return getBaseCompletions()
283
+
284
+ const cursorCompletions = tooling.completions(
285
+ site.property,
286
+ site.value,
287
+ position - site.contentStart
288
+ )
289
+ if (!cursorCompletions) return getBaseCompletions()
290
+ const replacementSpan = {
291
+ start: site.contentStart + cursorCompletions.replaceStart,
292
+ length: cursorCompletions.replaceLength,
293
+ }
294
+ const entries: ts.CompletionEntry[] = []
295
+ let contextualType: ts.Type | undefined
296
+ for (const completion of cursorCompletions.completions) {
297
+ const insertText = completion.insertText || completion.value
298
+ const modifierKind =
299
+ completion.kind === 'modifier'
300
+ ? tooling.modifierKind(completion.value)
301
+ : undefined
302
+ if (completion.kind === 'keyword') {
303
+ contextualType ||= checker.getContextualType(literal)
304
+ if (
305
+ !contextualType ||
306
+ !checker.isTypeAssignableTo(
307
+ checker.getStringLiteralType(insertText),
308
+ contextualType
309
+ )
310
+ ) {
311
+ continue
312
+ }
313
+ }
314
+ entries.push({
315
+ name: completion.value,
316
+ kind: typescript.ScriptElementKind.string,
317
+ kindModifiers: '',
318
+ sortText: completionSortText(completion, modifierKind),
319
+ insertText,
320
+ replacementSpan,
321
+ source: completionSource,
322
+ labelDetails: {
323
+ description: modifierKind
324
+ ? `Tamagui ${modifierKind} modifier`
325
+ : completion.kind === 'configured'
326
+ ? 'Tamagui configured value'
327
+ : 'Tamagui style keyword',
328
+ },
329
+ })
330
+ }
331
+ if (entries.length === 0) return getBaseCompletions()
332
+ return {
333
+ isGlobalCompletion: false,
334
+ isMemberCompletion: false,
335
+ isNewIdentifierLocation: true,
336
+ // A completion requested immediately after whitespace has an empty
337
+ // replacement span. Ask the editor to request again as the modifier
338
+ // prefix grows instead of dismissing suggestions when the cursor
339
+ // moves beyond that initial span.
340
+ isIncomplete: true,
341
+ entries,
342
+ }
343
+ }
344
+
345
+ proxy.getCompletionEntryDetails = (
346
+ fileName,
347
+ position,
348
+ entryName,
349
+ formatOptions,
350
+ source,
351
+ preferences,
352
+ data
353
+ ) => {
354
+ if (source === completionSource) {
355
+ return {
356
+ name: entryName,
357
+ kind: typescript.ScriptElementKind.string,
358
+ kindModifiers: '',
359
+ displayParts: [
360
+ {
361
+ text: entryName,
362
+ kind: 'stringLiteral',
363
+ },
364
+ ],
365
+ documentation: [
366
+ {
367
+ text: 'Resolved from the active Tamagui config.',
368
+ kind: 'text',
369
+ },
370
+ ],
371
+ tags: [],
372
+ }
373
+ }
374
+ return baseDetails(
375
+ fileName,
376
+ position,
377
+ entryName,
378
+ formatOptions,
379
+ source,
380
+ preferences,
381
+ data
382
+ )
383
+ }
384
+
385
+ proxy.getSemanticDiagnostics = (fileName) => {
386
+ const diagnostics = [...baseSemanticDiagnostics(fileName)]
387
+ if (!tooling) return diagnostics
388
+ const context = fileContext(fileName)
389
+ if (!context) return diagnostics
390
+ const { sourceFile, checker, bindings } = context
391
+ for (const site of collectLiteralSites(
392
+ typescript,
393
+ sourceFile,
394
+ tooling,
395
+ checker,
396
+ bindings
397
+ )) {
398
+ for (const diagnostic of tooling.diagnostics(site.property, site.value)) {
399
+ diagnostics.push({
400
+ file: sourceFile,
401
+ start: site.contentStart + diagnostic.start,
402
+ length: Math.max(1, diagnostic.end - diagnostic.start),
403
+ messageText: diagnostic.message,
404
+ category: typescript.DiagnosticCategory.Error,
405
+ code: diagnosticCode,
406
+ source: completionSource,
407
+ })
408
+ }
409
+ }
410
+ return diagnostics
411
+ }
412
+
413
+ proxy.getQuickInfoAtPosition = (fileName, position) => {
414
+ const getBaseQuickInfo = () => baseQuickInfo(fileName, position)
415
+ if (!tooling) return getBaseQuickInfo()
416
+ const context = fileContext(fileName)
417
+ if (!context) return getBaseQuickInfo()
418
+ const { sourceFile, checker, bindings } = context
419
+ const literal = findStringLiteralAtPosition(typescript, sourceFile, position)
420
+ if (!literal) return getBaseQuickInfo()
421
+ const site = siteForLiteral(
422
+ typescript,
423
+ sourceFile,
424
+ literal,
425
+ tooling,
426
+ checker,
427
+ bindings
428
+ )
429
+ if (!site) return getBaseQuickInfo()
430
+ const hover = tooling.hover(site.property, site.value, position - site.contentStart)
431
+ if (!hover) return getBaseQuickInfo()
432
+ return {
433
+ kind: typescript.ScriptElementKind.string,
434
+ kindModifiers: '',
435
+ textSpan: {
436
+ start: site.contentStart + hover.start,
437
+ length: hover.end - hover.start,
438
+ },
439
+ displayParts: [{ text: hover.text, kind: 'stringLiteral' }],
440
+ documentation: [{ text: hover.markdown, kind: 'text' }],
441
+ }
442
+ }
443
+
444
+ proxy.dispose = () => {
445
+ watcher.close()
446
+ baseDispose()
447
+ }
448
+ return proxy
449
+ },
450
+ })
451
+
452
+ export default init
@@ -0,0 +1,31 @@
1
+ import { type DocumentDiagnostic, type ExtractStyleSites } from "./document";
2
+ export interface CheckStyleFilesOptions {
3
+ /** project root; file discovery and relative display paths anchor here */
4
+ root: string;
5
+ /** path to the compiler's config artifact; default `<root>/.tamagui/tamagui.config.json` */
6
+ configPath?: string;
7
+ /** explicit files to check instead of walking the root */
8
+ files?: readonly string[];
9
+ }
10
+ export interface CheckedFile {
11
+ /** root-relative display path */
12
+ file: string;
13
+ source: string;
14
+ diagnostics: readonly DocumentDiagnostic[];
15
+ }
16
+ export interface CheckStyleFilesResult {
17
+ files: readonly CheckedFile[];
18
+ checkedFileCount: number;
19
+ diagnosticCount: number;
20
+ }
21
+ export declare class MissingConfigArtifactError extends Error {
22
+ constructor(configPath: string);
23
+ }
24
+ export declare function createProjectExtractor(isStyleProp: (name: string) => boolean): ExtractStyleSites;
25
+ export declare function checkStyleFiles(options: CheckStyleFilesOptions): CheckStyleFilesResult;
26
+ /** human-readable report: one code frame per diagnostic, caret-underlined */
27
+ export declare function formatCheckResults(result: CheckStyleFilesResult, options?: {
28
+ color?: boolean;
29
+ }): string;
30
+
31
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAcA,cAEO,yBACA,yBACA;AAgBP,iBAAiB,uBAAuB;;CAEtC;;CAEA;;CAEA;;AAGF,iBAAiB,YAAY;;CAE3B;CACA;CACA,sBAAsB;;AAGxB,iBAAiB,sBAAsB;CACrC,gBAAgB;CAChB;CACA;;AAGF,OAAO,cAAM,mCAAmC,MAAM;CACpD,YAAY;;AAoBd,OAAO,iBAAS,uBACd,cAAc,2BACb;AAIH,OAAO,iBAAS,gBAAgB,SAAS,yBAAyB;;AAoFlE,OAAO,iBAAS,mBACd,QAAQ,uBACR,UAAS;CAAE",
3
+ "names": [],
4
+ "sources": [
5
+ "src/check.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "// The project checker behind `tamagui check`.\n//\n// Node-only entry: walks a project's source files, extracts every static flat\n// value site with the sucrase tokenizer, and reports the same diagnostics the\n// editor plugin and eslint rule produce, formatted as readable code frames.\n\nimport { readdirSync, readFileSync } from 'node:fs'\nimport { join, relative } from 'node:path'\n// deep paths, spelled down to the file: sucrase publishes no `exports` map, and\n// a bare `sucrase/dist/parser` is a directory import that ESM cannot resolve\nimport { parse } from 'sucrase/dist/parser/index.js'\nimport { TokenType } from 'sucrase/dist/parser/tokenizer/types.js'\n\nimport { createStyleTooling, type SerializedConfigFile } from './core'\nimport {\n createDocumentStyleTooling,\n type DocumentDiagnostic,\n type ExtractStyleSites,\n} from './document'\nimport { createSucraseStyleSiteExtractor } from './extract-sucrase'\n\nconst sourceExtensions = /\\.(tsx|jsx)$/\nconst skippedDirectories = new Set([\n 'node_modules',\n 'dist',\n 'build',\n 'out',\n 'coverage',\n '.git',\n '.next',\n '.expo',\n '.tamagui',\n])\n\nexport interface CheckStyleFilesOptions {\n /** project root; file discovery and relative display paths anchor here */\n root: string\n /** path to the compiler's config artifact; default `<root>/.tamagui/tamagui.config.json` */\n configPath?: string\n /** explicit files to check instead of walking the root */\n files?: readonly string[]\n}\n\nexport interface CheckedFile {\n /** root-relative display path */\n file: string\n source: string\n diagnostics: readonly DocumentDiagnostic[]\n}\n\nexport interface CheckStyleFilesResult {\n files: readonly CheckedFile[]\n checkedFileCount: number\n diagnosticCount: number\n}\n\nexport class MissingConfigArtifactError extends Error {\n constructor(configPath: string) {\n super(\n `no Tamagui config artifact at ${configPath} — run your dev server or \\`tamagui generate\\` once so the compiler emits it`\n )\n this.name = 'MissingConfigArtifactError'\n }\n}\n\nfunction walkSourceFiles(directory: string, results: string[]): void {\n for (const entry of readdirSync(directory, { withFileTypes: true })) {\n if (entry.isDirectory()) {\n if (!skippedDirectories.has(entry.name) && !entry.name.startsWith('.')) {\n walkSourceFiles(join(directory, entry.name), results)\n }\n continue\n }\n if (sourceExtensions.test(entry.name)) results.push(join(directory, entry.name))\n }\n}\n\nexport function createProjectExtractor(\n isStyleProp: (name: string) => boolean\n): ExtractStyleSites {\n return createSucraseStyleSiteExtractor({ parse, TokenType }, { isStyleProp })\n}\n\nexport function checkStyleFiles(options: CheckStyleFilesOptions): CheckStyleFilesResult {\n const configPath =\n options.configPath ?? join(options.root, '.tamagui', 'tamagui.config.json')\n let contents: string\n try {\n contents = readFileSync(configPath, 'utf8')\n } catch {\n throw new MissingConfigArtifactError(configPath)\n }\n const tooling = createStyleTooling(JSON.parse(contents) as SerializedConfigFile)\n if (!tooling) throw new MissingConfigArtifactError(configPath)\n\n const document = createDocumentStyleTooling(\n tooling,\n createProjectExtractor((name) => tooling.isStyleProp(name))\n )\n\n let files: string[]\n if (options.files) {\n files = [...options.files]\n } else {\n files = []\n walkSourceFiles(options.root, files)\n files.sort()\n }\n\n const checked: CheckedFile[] = []\n let diagnosticCount = 0\n for (const file of files) {\n let source: string\n try {\n source = readFileSync(file, 'utf8')\n } catch {\n continue\n }\n let diagnostics: readonly DocumentDiagnostic[]\n try {\n diagnostics = document.diagnostics(source)\n } catch {\n // a file sucrase cannot parse is a syntax error the real compiler will\n // report; the style checker stays quiet about it\n continue\n }\n if (diagnostics.length === 0) continue\n diagnosticCount += diagnostics.length\n checked.push({ file: relative(options.root, file), source, diagnostics })\n }\n\n return { files: checked, checkedFileCount: files.length, diagnosticCount }\n}\n\nconst ansi = {\n red: (text: string) => `\\x1b[31m${text}\\x1b[39m`,\n dim: (text: string) => `\\x1b[2m${text}\\x1b[22m`,\n bold: (text: string) => `\\x1b[1m${text}\\x1b[22m`,\n cyan: (text: string) => `\\x1b[36m${text}\\x1b[39m`,\n}\nconst plain = {\n red: (text: string) => text,\n dim: (text: string) => text,\n bold: (text: string) => text,\n cyan: (text: string) => text,\n}\n\nfunction lineStarts(source: string): number[] {\n const starts = [0]\n for (let index = 0; index < source.length; index++) {\n if (source.charCodeAt(index) === 10) starts.push(index + 1)\n }\n return starts\n}\n\nfunction positionOf(starts: number[], offset: number): { line: number; column: number } {\n let low = 0\n let high = starts.length - 1\n while (low < high) {\n const mid = (low + high + 1) >> 1\n if (starts[mid] <= offset) low = mid\n else high = mid - 1\n }\n return { line: low, column: offset - starts[low] }\n}\n\n/** human-readable report: one code frame per diagnostic, caret-underlined */\nexport function formatCheckResults(\n result: CheckStyleFilesResult,\n options: { color?: boolean } = {}\n): string {\n const paint = options.color === false ? plain : ansi\n const output: string[] = []\n\n for (const checked of result.files) {\n const starts = lineStarts(checked.source)\n const lines = checked.source.split('\\n')\n for (const diagnostic of checked.diagnostics) {\n const start = positionOf(starts, diagnostic.start)\n const end = positionOf(starts, diagnostic.end)\n output.push(\n `${paint.bold(checked.file)}${paint.dim(`:${start.line + 1}:${start.column + 1}`)} ${paint.red('error')} ${diagnostic.message}`\n )\n const line = lines[start.line] ?? ''\n const gutter = String(start.line + 1)\n output.push(` ${paint.dim(`${gutter} │`)} ${line}`)\n const underlineLength =\n end.line === start.line\n ? Math.max(1, end.column - start.column)\n : Math.max(1, line.length - start.column)\n output.push(\n ` ${paint.dim(`${' '.repeat(gutter.length)} │`)} ${' '.repeat(start.column)}${paint.red('^'.repeat(underlineLength))}`\n )\n output.push('')\n }\n }\n\n const summary =\n result.diagnosticCount === 0\n ? `${paint.bold('✓')} ${result.checkedFileCount} files, no flat value problems`\n : `${paint.red(paint.bold(`✗ ${result.diagnosticCount} problem${result.diagnosticCount === 1 ? '' : 's'}`))} in ${result.files.length} file${result.files.length === 1 ? '' : 's'} ${paint.dim(`(${result.checkedFileCount} checked)`)}`\n output.push(summary)\n return output.join('\\n')\n}\n"
10
+ ]
11
+ }
@@ -0,0 +1,68 @@
1
+ import { type DiagnoseStyleValueOptions, type ModifierKind, type SerializedGrammarSourceConfig, type StyleValueAnnotation, type StyleValueCompletion, type StyleValueCursorCompletions, type StyleValueDiagnostic } from "@tamagui/style-grammar/tooling";
2
+ export type { StyleValueAnnotation, StyleValueCompletion, StyleValueCursorCompletions, StyleValueDiagnostic };
3
+ /** the shape of the JSON artifact the Tamagui compiler writes */
4
+ export interface SerializedConfigFile {
5
+ tamaguiConfig?: SerializedGrammarSourceConfig;
6
+ tamaguiConfigMetadata?: unknown;
7
+ }
8
+ export interface RgbaColor {
9
+ r: number;
10
+ g: number;
11
+ b: number;
12
+ a: number;
13
+ }
14
+ export interface StyleValueColor {
15
+ /** character span within the authored value */
16
+ start: number;
17
+ end: number;
18
+ text: string;
19
+ color: RgbaColor;
20
+ /** the theme the preview value came from, when theme-resolved */
21
+ theme?: string;
22
+ }
23
+ export interface StyleValueHover {
24
+ /** character span within the authored value */
25
+ start: number;
26
+ end: number;
27
+ text: string;
28
+ /** markdown suitable for an editor hover */
29
+ markdown: string;
30
+ /** a representative color for colorish targets */
31
+ color?: RgbaColor;
32
+ }
33
+ /**
34
+ * The one sort key every host uses for completion entries, so ordering does
35
+ * not drift between tsserver, LSP, and in-browser consumers: states first in
36
+ * interaction order, then groups, media, containers, themes, platforms, then
37
+ * configured values, then keywords.
38
+ */
39
+ export declare function completionSortText(completion: StyleValueCompletion, modifierKind: ModifierKind | undefined): string;
40
+ export interface StyleTooling {
41
+ /** every prop name treated as a flat style value site */
42
+ styleProps: ReadonlySet<string>;
43
+ /** engine options, for hosts that call @tamagui/style-grammar directly */
44
+ engine: DiagnoseStyleValueOptions;
45
+ isStyleProp(name: string): boolean;
46
+ /** the longhand a prop resolves to through the configured shorthands */
47
+ targetProperty(name: string): string;
48
+ /**
49
+ * cursor completions for one value slot, or null when the property takes no
50
+ * flat program (unknown props, legacy part props)
51
+ */
52
+ completions(property: string, value: string, cursor: number): StyleValueCursorCompletions | null;
53
+ /** the complete static verdict for one authored value */
54
+ diagnostics(property: string, value: string): readonly StyleValueDiagnostic[];
55
+ /** classified spans: modifiers, tokens, keywords, literals */
56
+ annotations(property: string, value: string): readonly StyleValueAnnotation[];
57
+ /** hover content for the annotation under `offset`, or null */
58
+ hover(property: string, value: string, offset: number): StyleValueHover | null;
59
+ /** every span that resolves to a presentable color */
60
+ colors(property: string, value: string): readonly StyleValueColor[];
61
+ /** the modifier kind of a registered modifier name */
62
+ modifierKind(name: string): ModifierKind | undefined;
63
+ /** root theme names, preview themes first */
64
+ previewThemes: readonly string[];
65
+ }
66
+ export declare function createStyleTooling(file: SerializedConfigFile): StyleTooling | null;
67
+
68
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAaA,cAUO,gCACA,mBACA,oCACA,2BACA,2BACA,kCACA,4BACA;AAEP,cACE,sBACA,sBACA,6BACA;;AAIF,iBAAiB,qBAAqB;CACpC,gBAAgB;CAChB;;AAGF,iBAAiB,UAAU;CACzB;CACA;CACA;CACA;;AAGF,iBAAiB,gBAAgB;;CAE/B;CACA;CACA;CACA,OAAO;;CAEP;;AAGF,iBAAiB,gBAAgB;;CAE/B;CACA;CACA;;CAEA;;CAEA,QAAQ;;;;;;;;AA+BV,OAAO,iBAAS,mBACd,YAAY,sBACZ,cAAc;AA6BhB,iBAAiB,aAAa;;CAE5B,YAAY;;CAEZ,QAAQ;CACR,YAAY;;CAEZ,eAAe;;;;;CAKf,YACE,kBACA,eACA,iBACC;;CAEH,YAAY,kBAAkB,yBAAyB;;CAEvD,YAAY,kBAAkB,yBAAyB;;CAEvD,MAAM,kBAAkB,eAAe,iBAAiB;;CAExD,OAAO,kBAAkB,yBAAyB;;CAElD,aAAa,eAAe;;CAE5B;;AAGF,OAAO,iBAAS,mBAAmB,MAAM,uBAAuB",
3
+ "names": [],
4
+ "sources": [
5
+ "src/core.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "// The standalone Tamagui style tooling core.\n//\n// Browser-safe by contract: no node imports, no typescript imports. Everything\n// here works from the serialized config JSON the Tamagui compiler emits\n// (`.tamagui/tamagui.config.json`), so the same engine powers the tsserver\n// plugin, the VS Code extension, the CLI checker, and in-browser IDEs.\n//\n// The @tamagui/style-grammar engine owns candidate meaning; this module adds\n// the two things the engine's config view deliberately drops — token and theme\n// VALUES — and projects everything into editor-shaped results: completions,\n// diagnostics, hover, and color swatches.\n\nimport { normalizeCSSColor, rgba } from '@tamagui/normalize-css-color'\nimport {\n annotateStyleValue,\n completeStyleValueAtCursor,\n createCandidatePropertyVocabulary,\n createGrammarConfigViewFromSerializedConfig,\n createModifierRegistry,\n createStylePropSet,\n diagnoseStyleValueProgram,\n programEligibility,\n stateModifierNames,\n type DiagnoseStyleValueOptions,\n type ModifierKind,\n type SerializedGrammarSourceConfig,\n type StyleValueAnnotation,\n type StyleValueCompletion,\n type StyleValueCursorCompletions,\n type StyleValueDiagnostic,\n} from '@tamagui/style-grammar/tooling'\n\nexport type {\n StyleValueAnnotation,\n StyleValueCompletion,\n StyleValueCursorCompletions,\n StyleValueDiagnostic,\n}\n\n/** the shape of the JSON artifact the Tamagui compiler writes */\nexport interface SerializedConfigFile {\n tamaguiConfig?: SerializedGrammarSourceConfig\n tamaguiConfigMetadata?: unknown\n}\n\nexport interface RgbaColor {\n r: number\n g: number\n b: number\n a: number\n}\n\nexport interface StyleValueColor {\n /** character span within the authored value */\n start: number\n end: number\n text: string\n color: RgbaColor\n /** the theme the preview value came from, when theme-resolved */\n theme?: string\n}\n\nexport interface StyleValueHover {\n /** character span within the authored value */\n start: number\n end: number\n text: string\n /** markdown suitable for an editor hover */\n markdown: string\n /** a representative color for colorish targets */\n color?: RgbaColor\n}\n\nconst modifierKindLabel: Readonly<Record<ModifierKind, string>> = {\n state: 'state modifier',\n media: 'media modifier',\n theme: 'theme modifier',\n platform: 'platform modifier',\n group: 'group modifier',\n container: 'container modifier',\n}\n\nconst modifierKindSort: Readonly<Record<ModifierKind, string>> = {\n state: '00',\n group: '01',\n media: '02',\n container: '03',\n theme: '04',\n platform: '05',\n}\n\nconst stateModifierSort = new Map(\n stateModifierNames.map((name, index) => [name, index] as const)\n)\n\n/**\n * The one sort key every host uses for completion entries, so ordering does\n * not drift between tsserver, LSP, and in-browser consumers: states first in\n * interaction order, then groups, media, containers, themes, platforms, then\n * configured values, then keywords.\n */\nexport function completionSortText(\n completion: StyleValueCompletion,\n modifierKind: ModifierKind | undefined\n): string {\n if (modifierKind) {\n const stateOrder =\n modifierKind === 'state'\n ? `${String(stateModifierSort.get(completion.value) ?? 999).padStart(3, '0')}:`\n : ''\n return `${modifierKindSort[modifierKind]}:${stateOrder}${completion.value}`\n }\n return `${completion.kind === 'configured' ? '10' : '11'}:${completion.value}`\n}\n\n/** unwraps a compiler-serialized token variable to its raw value */\nfunction tokenValue(entry: unknown): unknown {\n if (entry && typeof entry === 'object' && 'val' in entry) {\n return (entry as { val: unknown }).val\n }\n return entry\n}\n\nfunction parseColor(value: unknown, opacity?: number): RgbaColor | null {\n if (typeof value !== 'string') return null\n const normalized = normalizeCSSColor(value)\n if (normalized === null) return null\n const color = rgba(normalized)\n if (opacity !== undefined) color.a = color.a * (opacity / 100)\n return color\n}\n\nexport interface StyleTooling {\n /** every prop name treated as a flat style value site */\n styleProps: ReadonlySet<string>\n /** engine options, for hosts that call @tamagui/style-grammar directly */\n engine: DiagnoseStyleValueOptions\n isStyleProp(name: string): boolean\n /** the longhand a prop resolves to through the configured shorthands */\n targetProperty(name: string): string\n /**\n * cursor completions for one value slot, or null when the property takes no\n * flat program (unknown props, legacy part props)\n */\n completions(\n property: string,\n value: string,\n cursor: number\n ): StyleValueCursorCompletions | null\n /** the complete static verdict for one authored value */\n diagnostics(property: string, value: string): readonly StyleValueDiagnostic[]\n /** classified spans: modifiers, tokens, keywords, literals */\n annotations(property: string, value: string): readonly StyleValueAnnotation[]\n /** hover content for the annotation under `offset`, or null */\n hover(property: string, value: string, offset: number): StyleValueHover | null\n /** every span that resolves to a presentable color */\n colors(property: string, value: string): readonly StyleValueColor[]\n /** the modifier kind of a registered modifier name */\n modifierKind(name: string): ModifierKind | undefined\n /** root theme names, preview themes first */\n previewThemes: readonly string[]\n}\n\nexport function createStyleTooling(file: SerializedConfigFile): StyleTooling | null {\n const serialized = file.tamaguiConfig\n if (!serialized) return null\n\n const config = createGrammarConfigViewFromSerializedConfig(\n serialized,\n file.tamaguiConfigMetadata\n )\n const registry = createModifierRegistry(config).registry\n const candidates = createCandidatePropertyVocabulary(config)\n const engine: DiagnoseStyleValueOptions = { config, registry, candidates }\n const styleProps = createStylePropSet(config)\n\n // themes and tokens keep their VALUES here; the grammar view keeps names only\n const themes = (serialized.themes || {}) as Readonly<\n Record<string, Readonly<Record<string, unknown>> | undefined>\n >\n const rootThemes = Object.keys(themes).filter((name) => !name.includes('_'))\n const previewThemes = [\n ...['light', 'dark'].filter((name) => rootThemes.includes(name)),\n ...rootThemes.filter((name) => name !== 'light' && name !== 'dark'),\n ]\n const tokens = (serialized.tokens || {}) as Readonly<\n Record<string, Readonly<Record<string, unknown>> | undefined>\n >\n const media = (serialized.media || {}) as Readonly<Record<string, unknown>>\n\n const targetProperty = (name: string): string => config.shorthands?.[name] || name\n\n const themeValue = (name: string): { theme: string; value: unknown } | null => {\n for (const theme of previewThemes) {\n const value = themes[theme]?.[name]\n if (value !== undefined) return { theme, value }\n }\n return null\n }\n\n const annotationColor = (\n annotation: StyleValueAnnotation\n ): { color: RgbaColor; theme?: string } | null => {\n if (annotation.kind === 'token' || annotation.kind === 'identifier') {\n const name =\n annotation.opacity !== undefined\n ? annotation.text.slice(0, annotation.text.lastIndexOf('/'))\n : annotation.text\n if (annotation.tokenCategory === 'color') {\n const themed = themeValue(name)\n if (themed) {\n const color = parseColor(themed.value, annotation.opacity)\n return color ? { color, theme: themed.theme } : null\n }\n const color = parseColor(tokenValue(tokens.color?.[name]), annotation.opacity)\n return color ? { color } : null\n }\n if (annotation.kind === 'identifier') {\n // literal CSS colors: hex, rgb()/hsl() never annotate (functions are\n // skipped), but hex runs and named colors do\n const color = parseColor(name)\n return color ? { color } : null\n }\n return null\n }\n if (annotation.kind === 'keyword' && annotation.text === 'transparent') {\n return { color: { r: 0, g: 0, b: 0, a: 0 } }\n }\n return null\n }\n\n const annotations = (property: string, value: string) =>\n annotateStyleValue(property, value, engine)\n\n const formatRgba = (color: RgbaColor): string =>\n color.a === 1\n ? `rgb(${color.r}, ${color.g}, ${color.b})`\n : `rgba(${color.r}, ${color.g}, ${color.b}, ${Number(color.a.toFixed(3))})`\n\n return {\n styleProps,\n engine,\n previewThemes,\n isStyleProp: (name) => styleProps.has(name),\n targetProperty,\n modifierKind: (name) => registry.get(name),\n\n completions(property, value, cursor) {\n const target = targetProperty(property)\n if (programEligibility(target) === 'legacy-part') return null\n if (!styleProps.has(property)) return null\n return completeStyleValueAtCursor(property, value, cursor, engine)\n },\n\n diagnostics(property, value) {\n if (!styleProps.has(property)) return []\n return diagnoseStyleValueProgram(property, value, engine)\n },\n\n annotations,\n\n colors(property, value) {\n if (!styleProps.has(property)) return []\n const results: StyleValueColor[] = []\n for (const annotation of annotations(property, value)) {\n const resolved = annotationColor(annotation)\n if (!resolved) continue\n results.push({\n start: annotation.start,\n end: annotation.end,\n text: annotation.text,\n color: resolved.color,\n ...(resolved.theme !== undefined && { theme: resolved.theme }),\n })\n }\n return results\n },\n\n hover(property, value, offset) {\n if (!styleProps.has(property)) return null\n const annotation = annotations(property, value).find(\n (entry) => offset >= entry.start && offset <= entry.end\n )\n if (!annotation) return null\n\n const lines: string[] = []\n let color: RgbaColor | undefined\n\n if (annotation.kind === 'modifier' && annotation.modifierKind) {\n lines.push(\n `**${annotation.text}** · Tamagui ${modifierKindLabel[annotation.modifierKind]}`\n )\n if (annotation.modifierKind === 'media') {\n const query = media[annotation.text]\n if (query !== undefined) {\n lines.push('```json\\n' + JSON.stringify(query) + '\\n```')\n }\n }\n } else if (annotation.kind === 'token') {\n const name =\n annotation.opacity !== undefined\n ? annotation.text.slice(0, annotation.text.lastIndexOf('/'))\n : annotation.text\n if (annotation.tokenCategory === 'color') {\n lines.push(`**${name}** · Tamagui color`)\n let shown = 0\n for (const theme of previewThemes) {\n const value = themes[theme]?.[name]\n if (value === undefined || shown >= 4) continue\n shown++\n lines.push(`- ${theme}: \\`${String(value)}\\``)\n }\n if (shown === 0) {\n const value = tokenValue(tokens.color?.[name])\n if (value !== undefined) lines.push(`- \\`${String(value)}\\``)\n }\n if (annotation.opacity !== undefined) {\n lines.push(`- opacity: ${annotation.opacity}%`)\n }\n } else {\n const value = tokenValue(tokens[annotation.tokenCategory || '']?.[name])\n lines.push(\n `**${name}** · Tamagui ${annotation.tokenCategory} token` +\n (value !== undefined ? ` = \\`${String(value)}\\`` : '')\n )\n }\n const resolved = annotationColor(annotation)\n if (resolved) {\n color = resolved.color\n lines.push(`- resolves: \\`${formatRgba(resolved.color)}\\``)\n }\n } else if (annotation.kind === 'keyword') {\n lines.push(\n `**${annotation.text}** · CSS keyword` +\n (annotation.property ? ` for \\`${annotation.property}\\`` : '')\n )\n } else {\n const resolved = annotationColor(annotation)\n if (!resolved) return null\n color = resolved.color\n lines.push(\n `**${annotation.text}** · CSS color = \\`${formatRgba(resolved.color)}\\``\n )\n }\n\n return {\n start: annotation.start,\n end: annotation.end,\n text: annotation.text,\n markdown: lines.join('\\n\\n'),\n ...(color !== undefined && { color }),\n }\n },\n }\n}\n"
10
+ ]
11
+ }
@@ -0,0 +1,42 @@
1
+ import type { StyleTooling, StyleValueColor, StyleValueDiagnostic, StyleValueHover } from "./core";
2
+ import type { StyleValueCursorCompletions } from "./core";
3
+ /** one static string style value in a source file */
4
+ export interface StyleSite {
5
+ /** the authored prop name (`bg`, `padding`) */
6
+ property: string;
7
+ /** the cooked string value */
8
+ value: string;
9
+ /** file offset of the value's first character (inside the quotes) */
10
+ start: number;
11
+ /** file offset just past the value's last character */
12
+ end: number;
13
+ /** how the site was authored, for hosts that filter */
14
+ kind: "jsx-attribute" | "styled-property";
15
+ }
16
+ export type ExtractStyleSites = (source: string, fileName?: string) => readonly StyleSite[];
17
+ export interface DocumentDiagnostic extends StyleValueDiagnostic {
18
+ site: StyleSite;
19
+ }
20
+ export interface DocumentColor extends StyleValueColor {
21
+ site: StyleSite;
22
+ }
23
+ export interface DocumentHover extends StyleValueHover {
24
+ site: StyleSite;
25
+ }
26
+ export interface DocumentCompletions extends StyleValueCursorCompletions {
27
+ site: StyleSite;
28
+ }
29
+ export interface DocumentStyleTooling {
30
+ sites(source: string, fileName?: string): readonly StyleSite[];
31
+ /** completions at a file offset, spans mapped to file offsets */
32
+ completionsAt(source: string, offset: number, fileName?: string): DocumentCompletions | null;
33
+ /** every diagnostic in the file, spans mapped to file offsets */
34
+ diagnostics(source: string, fileName?: string): readonly DocumentDiagnostic[];
35
+ /** hover at a file offset, span mapped to file offsets */
36
+ hoverAt(source: string, offset: number, fileName?: string): DocumentHover | null;
37
+ /** every color swatch in the file, spans mapped to file offsets */
38
+ colors(source: string, fileName?: string): readonly DocumentColor[];
39
+ }
40
+ export declare function createDocumentStyleTooling(tooling: StyleTooling, extract: ExtractStyleSites): DocumentStyleTooling;
41
+
42
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAUA,cACE,cACA,iBACA,sBACA,uBACK;AACP,cAAc,mCAAmC;;AAGjD,iBAAiB,UAAU;;CAEzB;;CAEA;;CAEA;;CAEA;;CAEA,MAAM,kBAAkB;;AAG1B,YAAY,qBACV,gBACA,+BACY;AAEd,iBAAiB,2BAA2B,qBAAqB;CAC/D,MAAM;;AAGR,iBAAiB,sBAAsB,gBAAgB;CACrD,MAAM;;AAGR,iBAAiB,sBAAsB,gBAAgB;CACrD,MAAM;;AAGR,iBAAiB,4BAA4B,4BAA4B;CACvE,MAAM;;AAGR,iBAAiB,qBAAqB;CACpC,MAAM,gBAAgB,6BAA6B;;CAEnD,cACE,gBACA,gBACA,oBACC;;CAEH,YAAY,gBAAgB,6BAA6B;;CAEzD,QAAQ,gBAAgB,gBAAgB,oBAAoB;;CAE5D,OAAO,gBAAgB,6BAA6B;;AAGtD,OAAO,iBAAS,2BACd,SAAS,cACT,SAAS,oBACR",
3
+ "names": [],
4
+ "sources": [
5
+ "src/document.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "// Document-level orchestration: an extractor locates the style value sites in\n// one source file, the core answers inside each site, and this module joins\n// the two so every host (browser IDE, LSP wrapper, CLI checker) gets\n// file-offset results from one code path.\n//\n// Extractors are pluggable because hosts already own a parse: the tsserver\n// plugin walks TypeScript's AST, the eslint rule walks ESTree, soot's bundler\n// holds sucrase tokens. Each adapter reduces its tree to the same StyleSite\n// contract; nothing downstream re-parses.\n\nimport type {\n StyleTooling,\n StyleValueColor,\n StyleValueDiagnostic,\n StyleValueHover,\n} from './core'\nimport type { StyleValueCursorCompletions } from './core'\n\n/** one static string style value in a source file */\nexport interface StyleSite {\n /** the authored prop name (`bg`, `padding`) */\n property: string\n /** the cooked string value */\n value: string\n /** file offset of the value's first character (inside the quotes) */\n start: number\n /** file offset just past the value's last character */\n end: number\n /** how the site was authored, for hosts that filter */\n kind: 'jsx-attribute' | 'styled-property'\n}\n\nexport type ExtractStyleSites = (\n source: string,\n fileName?: string\n) => readonly StyleSite[]\n\nexport interface DocumentDiagnostic extends StyleValueDiagnostic {\n site: StyleSite\n}\n\nexport interface DocumentColor extends StyleValueColor {\n site: StyleSite\n}\n\nexport interface DocumentHover extends StyleValueHover {\n site: StyleSite\n}\n\nexport interface DocumentCompletions extends StyleValueCursorCompletions {\n site: StyleSite\n}\n\nexport interface DocumentStyleTooling {\n sites(source: string, fileName?: string): readonly StyleSite[]\n /** completions at a file offset, spans mapped to file offsets */\n completionsAt(\n source: string,\n offset: number,\n fileName?: string\n ): DocumentCompletions | null\n /** every diagnostic in the file, spans mapped to file offsets */\n diagnostics(source: string, fileName?: string): readonly DocumentDiagnostic[]\n /** hover at a file offset, span mapped to file offsets */\n hoverAt(source: string, offset: number, fileName?: string): DocumentHover | null\n /** every color swatch in the file, spans mapped to file offsets */\n colors(source: string, fileName?: string): readonly DocumentColor[]\n}\n\nexport function createDocumentStyleTooling(\n tooling: StyleTooling,\n extract: ExtractStyleSites\n): DocumentStyleTooling {\n const siteAt = (sites: readonly StyleSite[], offset: number): StyleSite | undefined =>\n sites.find((site) => offset >= site.start && offset <= site.end)\n\n return {\n sites: (source, fileName) => extract(source, fileName),\n\n completionsAt(source, offset, fileName) {\n const site = siteAt(extract(source, fileName), offset)\n if (!site) return null\n const completions = tooling.completions(\n site.property,\n site.value,\n offset - site.start\n )\n if (!completions) return null\n return {\n ...completions,\n replaceStart: site.start + completions.replaceStart,\n site,\n }\n },\n\n diagnostics(source, fileName) {\n const results: DocumentDiagnostic[] = []\n for (const site of extract(source, fileName)) {\n for (const diagnostic of tooling.diagnostics(site.property, site.value)) {\n results.push({\n ...diagnostic,\n index: site.start + diagnostic.index,\n start: site.start + diagnostic.start,\n end: site.start + diagnostic.end,\n site,\n })\n }\n }\n return results\n },\n\n hoverAt(source, offset, fileName) {\n const site = siteAt(extract(source, fileName), offset)\n if (!site) return null\n const hover = tooling.hover(site.property, site.value, offset - site.start)\n if (!hover) return null\n return {\n ...hover,\n start: site.start + hover.start,\n end: site.start + hover.end,\n site,\n }\n },\n\n colors(source, fileName) {\n const results: DocumentColor[] = []\n for (const site of extract(source, fileName)) {\n for (const color of tooling.colors(site.property, site.value)) {\n results.push({\n ...color,\n start: site.start + color.start,\n end: site.start + color.end,\n site,\n })\n }\n }\n return results\n },\n }\n}\n"
10
+ ]
11
+ }