chrome-devtools-mcp-for-extension 0.5.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 (410) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +268 -0
  3. package/build/node_modules/chrome-devtools-frontend/LICENSE +27 -0
  4. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/App.js +4 -0
  5. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/AppProvider.js +17 -0
  6. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Base64.js +43 -0
  7. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/CharacterIdMap.js +27 -0
  8. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Color.js +2029 -0
  9. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/ColorConverter.js +330 -0
  10. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/ColorUtils.js +221 -0
  11. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Console.js +86 -0
  12. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Debouncer.js +14 -0
  13. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/EventTarget.js +14 -0
  14. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Gzip.js +64 -0
  15. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/JavaScriptMetaData.js +4 -0
  16. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Lazy.js +29 -0
  17. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Linkifier.js +34 -0
  18. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/MapWithDefault.js +20 -0
  19. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Mutex.js +49 -0
  20. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Object.js +86 -0
  21. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/ParsedURL.js +459 -0
  22. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Progress.js +144 -0
  23. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/QueryParamHandler.js +4 -0
  24. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/ResolverBase.js +69 -0
  25. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/ResourceType.js +506 -0
  26. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/ReturnToPanel.js +13 -0
  27. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Revealer.js +159 -0
  28. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Runnable.js +24 -0
  29. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/SegmentedRange.js +79 -0
  30. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/SettingRegistration.js +164 -0
  31. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Settings.js +1252 -0
  32. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/SimpleHistoryManager.js +97 -0
  33. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/StringOutputStream.js +17 -0
  34. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/TextDictionary.js +40 -0
  35. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Throttler.js +71 -0
  36. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Trie.js +127 -0
  37. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Worker.js +44 -0
  38. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/common.js +44 -0
  39. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/AidaClient.js +415 -0
  40. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/GdpClient.js +186 -0
  41. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/InspectorFrontendHost.js +510 -0
  42. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/InspectorFrontendHostAPI.js +66 -0
  43. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/Platform.js +59 -0
  44. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/ResourceLoader.js +232 -0
  45. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/UserMetrics.js +957 -0
  46. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/host.js +12 -0
  47. package/build/node_modules/chrome-devtools-frontend/front_end/core/i18n/i18n.js +60 -0
  48. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/ArrayUtilities.js +199 -0
  49. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/Brand.js +4 -0
  50. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/Constructor.js +4 -0
  51. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/DOMUtilities.js +122 -0
  52. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/DateUtilities.js +13 -0
  53. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/DevToolsPath.js +27 -0
  54. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/KeyboardUtilities.js +21 -0
  55. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/MapUtilities.js +79 -0
  56. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/MimeType.js +143 -0
  57. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/NumberUtilities.js +72 -0
  58. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/StringUtilities.js +536 -0
  59. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/Timing.js +9 -0
  60. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/TypedArrayUtilities.js +157 -0
  61. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/TypescriptUtilities.js +24 -0
  62. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/UIString.js +4 -0
  63. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/UserVisibleError.js +22 -0
  64. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/platform.js +26 -0
  65. package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/InspectorBackend.js +802 -0
  66. package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/NodeURL.js +31 -0
  67. package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/protocol_client.js +13 -0
  68. package/build/node_modules/chrome-devtools-frontend/front_end/core/root/Runtime.js +4 -0
  69. package/build/node_modules/chrome-devtools-frontend/front_end/core/root/root.js +5 -0
  70. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/AccessibilityModel.js +281 -0
  71. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/AnimationModel.js +846 -0
  72. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/AutofillModel.js +155 -0
  73. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CPUProfilerModel.js +99 -0
  74. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CPUThrottlingManager.js +220 -0
  75. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSContainerQuery.js +98 -0
  76. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSFontFace.js +31 -0
  77. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSLayer.js +22 -0
  78. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMatchedStyles.js +1284 -0
  79. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMedia.js +100 -0
  80. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMetadata.js +1518 -0
  81. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSModel.js +902 -0
  82. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSProperty.js +315 -0
  83. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSPropertyParser.js +572 -0
  84. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSPropertyParserMatchers.js +1336 -0
  85. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSQuery.js +53 -0
  86. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSRule.js +361 -0
  87. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSScope.js +22 -0
  88. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSStyleDeclaration.js +275 -0
  89. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSStyleSheetHeader.js +166 -0
  90. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSSupports.js +24 -0
  91. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CategorizedBreakpoint.js +29 -0
  92. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ChildTargetManager.js +232 -0
  93. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CompilerSourceMappingContentProvider.js +47 -0
  94. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Connections.js +242 -0
  95. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ConsoleModel.js +629 -0
  96. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ConsoleModelTypes.js +14 -0
  97. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Cookie.js +241 -0
  98. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CookieModel.js +198 -0
  99. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CookieParser.js +163 -0
  100. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DOMDebuggerModel.js +597 -0
  101. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DOMModel.js +1610 -0
  102. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DebuggerModel.js +1231 -0
  103. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/EmulationModel.js +527 -0
  104. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/EnhancedTracesParser.js +350 -0
  105. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/EventBreakpointsModel.js +125 -0
  106. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/FrameAssociated.js +4 -0
  107. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/FrameManager.js +199 -0
  108. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/HeapProfilerModel.js +130 -0
  109. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/HttpReasonPhraseStrings.js +73 -0
  110. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/IOModel.js +83 -0
  111. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/IsolateManager.js +208 -0
  112. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/IssuesModel.js +41 -0
  113. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/LayerTreeBase.js +95 -0
  114. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/LogModel.js +34 -0
  115. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js +1916 -0
  116. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkRequest.js +1668 -0
  117. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/OverlayColorGenerator.js +48 -0
  118. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/OverlayModel.js +765 -0
  119. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/OverlayPersistentHighlighter.js +384 -0
  120. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PageLoad.js +25 -0
  121. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PageResourceLoader.js +300 -0
  122. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PaintProfiler.js +67 -0
  123. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PerformanceMetricsModel.js +62 -0
  124. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PreloadingModel.js +563 -0
  125. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RehydratingConnection.js +286 -0
  126. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RehydratingObject.js +4 -0
  127. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RemoteObject.js +905 -0
  128. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Resource.js +163 -0
  129. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ResourceTreeModel.js +922 -0
  130. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RuntimeModel.js +535 -0
  131. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SDKModel.js +45 -0
  132. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ScreenCaptureModel.js +174 -0
  133. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Script.js +395 -0
  134. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SecurityOriginManager.js +54 -0
  135. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ServerSentEvents.js +67 -0
  136. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ServerSentEventsProtocol.js +110 -0
  137. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ServerTiming.js +216 -0
  138. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ServiceWorkerCacheModel.js +271 -0
  139. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ServiceWorkerManager.js +511 -0
  140. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMap.js +651 -0
  141. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapCache.js +41 -0
  142. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapFunctionRanges.js +132 -0
  143. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapManager.js +189 -0
  144. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapScopeChainEntry.js +156 -0
  145. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapScopesInfo.js +276 -0
  146. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/StorageBucketsModel.js +143 -0
  147. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/StorageKeyManager.js +53 -0
  148. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Target.js +262 -0
  149. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/TargetManager.js +386 -0
  150. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/TraceObject.js +52 -0
  151. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/WebAuthnModel.js +66 -0
  152. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/sdk-meta.js +1117 -0
  153. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/sdk.js +89 -0
  154. package/build/node_modules/chrome-devtools-frontend/front_end/generated/ARIAProperties.js +1513 -0
  155. package/build/node_modules/chrome-devtools-frontend/front_end/generated/Deprecation.js +339 -0
  156. package/build/node_modules/chrome-devtools-frontend/front_end/generated/InspectorBackendCommands.js +1561 -0
  157. package/build/node_modules/chrome-devtools-frontend/front_end/generated/SupportedCSSProperties.js +7514 -0
  158. package/build/node_modules/chrome-devtools-frontend/front_end/generated/protocol.js +4 -0
  159. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/NetworkRequestFormatter.js +262 -0
  160. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.js +979 -0
  161. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js +613 -0
  162. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/UnitFormatters.js +139 -0
  163. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AICallTree.js +372 -0
  164. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js +132 -0
  165. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIQueries.js +105 -0
  166. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/CSSWorkspaceBinding.js +243 -0
  167. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/CompilerScriptMapping.js +407 -0
  168. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ContentProviderBasedProject.js +130 -0
  169. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DebuggerLanguagePlugins.js +992 -0
  170. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DebuggerWorkspaceBinding.js +574 -0
  171. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DefaultScriptMapping.js +112 -0
  172. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/FileUtils.js +186 -0
  173. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/LiveLocation.js +60 -0
  174. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/NetworkProject.js +107 -0
  175. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/PresentationConsoleMessageHelper.js +244 -0
  176. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceMapping.js +473 -0
  177. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceScriptMapping.js +399 -0
  178. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceUtils.js +87 -0
  179. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/SASSSourceMapping.js +181 -0
  180. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/StylesSourceMapping.js +268 -0
  181. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/TempFile.js +55 -0
  182. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/bindings.js +20 -0
  183. package/build/node_modules/chrome-devtools-frontend/front_end/models/cpu_profile/CPUProfileDataModel.js +514 -0
  184. package/build/node_modules/chrome-devtools-frontend/front_end/models/cpu_profile/ProfileTreeModel.js +90 -0
  185. package/build/node_modules/chrome-devtools-frontend/front_end/models/cpu_profile/cpu_profile.js +6 -0
  186. package/build/node_modules/chrome-devtools-frontend/front_end/models/crux-manager/CrUXManager.js +283 -0
  187. package/build/node_modules/chrome-devtools-frontend/front_end/models/crux-manager/crux-manager.js +4 -0
  188. package/build/node_modules/chrome-devtools-frontend/front_end/models/emulation/DeviceModeModel.js +775 -0
  189. package/build/node_modules/chrome-devtools-frontend/front_end/models/emulation/EmulatedDevices.js +1706 -0
  190. package/build/node_modules/chrome-devtools-frontend/front_end/models/emulation/emulation.js +6 -0
  191. package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/FormatterWorkerPool.js +131 -0
  192. package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/ScriptFormatter.js +77 -0
  193. package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/formatter.js +6 -0
  194. package/build/node_modules/chrome-devtools-frontend/front_end/models/geometry/GeometryImpl.js +347 -0
  195. package/build/node_modules/chrome-devtools-frontend/front_end/models/geometry/geometry.js +4 -0
  196. package/build/node_modules/chrome-devtools-frontend/front_end/models/logs/LogManager.js +67 -0
  197. package/build/node_modules/chrome-devtools-frontend/front_end/models/logs/NetworkLog.js +494 -0
  198. package/build/node_modules/chrome-devtools-frontend/front_end/models/logs/RequestResolver.js +49 -0
  199. package/build/node_modules/chrome-devtools-frontend/front_end/models/logs/logs-meta.js +73 -0
  200. package/build/node_modules/chrome-devtools-frontend/front_end/models/logs/logs.js +7 -0
  201. package/build/node_modules/chrome-devtools-frontend/front_end/models/network_time_calculator/Calculator.js +4 -0
  202. package/build/node_modules/chrome-devtools-frontend/front_end/models/network_time_calculator/NetworkTimeCalculator.js +256 -0
  203. package/build/node_modules/chrome-devtools-frontend/front_end/models/network_time_calculator/RequestTimeRanges.js +120 -0
  204. package/build/node_modules/chrome-devtools-frontend/front_end/models/network_time_calculator/network_time_calculator.js +6 -0
  205. package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/NamesResolver.js +626 -0
  206. package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/ScopeChainModel.js +59 -0
  207. package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/ScopeTreeCache.js +32 -0
  208. package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/source_map_scopes.js +7 -0
  209. package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/StackTrace.js +4 -0
  210. package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/StackTraceImpl.js +67 -0
  211. package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/StackTraceModel.js +97 -0
  212. package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/Trie.js +113 -0
  213. package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/stack_trace.js +5 -0
  214. package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/stack_trace_impl.js +7 -0
  215. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/CodeMirrorUtils.js +32 -0
  216. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/ContentData.js +173 -0
  217. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/ContentProvider.js +30 -0
  218. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/StaticContentProvider.js +32 -0
  219. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/StreamingContentData.js +79 -0
  220. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/Text.js +69 -0
  221. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/TextCursor.js +35 -0
  222. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/TextRange.js +231 -0
  223. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/TextUtils.js +355 -0
  224. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/WasmDisassembly.js +68 -0
  225. package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/text_utils.js +14 -0
  226. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/EntityMapper.js +122 -0
  227. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/EventsSerializer.js +81 -0
  228. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/LanternComputationData.js +370 -0
  229. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/ModelImpl.js +166 -0
  230. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/Name.js +114 -0
  231. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/Processor.js +555 -0
  232. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/Styles.js +815 -0
  233. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/FilmStrip.js +44 -0
  234. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/MainThreadActivity.js +76 -0
  235. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/ScriptDuplication.js +162 -0
  236. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/StackTraceForEvent.js +191 -0
  237. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/ThirdParties.js +118 -0
  238. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/TraceFilter.js +50 -0
  239. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/TraceTree.js +592 -0
  240. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/extras.js +10 -0
  241. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/AnimationFramesHandler.js +109 -0
  242. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/AnimationHandler.js +26 -0
  243. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/AsyncJSCallsHandler.js +187 -0
  244. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/AuctionWorkletsHandler.js +162 -0
  245. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/DOMStatsHandler.js +21 -0
  246. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/ExtensionTraceDataHandler.js +263 -0
  247. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/FlowsHandler.js +148 -0
  248. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/FramesHandler.js +483 -0
  249. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/GPUHandler.js +35 -0
  250. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/ImagePaintingHandler.js +147 -0
  251. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/InitiatorsHandler.js +180 -0
  252. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/InvalidationsHandler.js +126 -0
  253. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/LargestImagePaintHandler.js +85 -0
  254. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/LargestTextPaintHandler.js +27 -0
  255. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/LayerTreeHandler.js +103 -0
  256. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/LayoutShiftsHandler.js +445 -0
  257. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/MemoryHandler.js +21 -0
  258. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/MetaHandler.js +401 -0
  259. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/ModelHandlers.js +33 -0
  260. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/NetworkRequestsHandler.js +540 -0
  261. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/PageFramesHandler.js +42 -0
  262. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/PageLoadMetricsHandler.js +349 -0
  263. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/RendererHandler.js +346 -0
  264. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/SamplesHandler.js +207 -0
  265. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/ScreenshotsHandler.js +97 -0
  266. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/ScriptsHandler.js +251 -0
  267. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/SelectorStatsHandler.js +71 -0
  268. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/Threads.js +101 -0
  269. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/UserInteractionsHandler.js +317 -0
  270. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/UserTimingsHandler.js +183 -0
  271. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/WarningsHandler.js +134 -0
  272. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/WorkersHandler.js +33 -0
  273. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/handlers.js +7 -0
  274. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/helpers.js +163 -0
  275. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/types.js +1 -0
  276. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Extensions.js +41 -0
  277. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Network.js +102 -0
  278. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/SamplesIntegrator.js +495 -0
  279. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/SyntheticEvents.js +74 -0
  280. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Timing.js +184 -0
  281. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Trace.js +806 -0
  282. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/TreeHelpers.js +254 -0
  283. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/helpers.js +10 -0
  284. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/CLSCulprits.js +488 -0
  285. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/Cache.js +208 -0
  286. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/Common.js +340 -0
  287. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DOMSize.js +180 -0
  288. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DocumentLatency.js +257 -0
  289. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DuplicatedJavaScript.js +89 -0
  290. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/FontDisplay.js +81 -0
  291. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ForcedReflow.js +160 -0
  292. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/INPBreakdown.js +117 -0
  293. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ImageDelivery.js +262 -0
  294. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LCPBreakdown.js +188 -0
  295. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LCPDiscovery.js +182 -0
  296. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LegacyJavaScript.js +88 -0
  297. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/Models.js +21 -0
  298. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ModernHTTP.js +199 -0
  299. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/NetworkDependencyTree.js +544 -0
  300. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/RenderBlocking.js +191 -0
  301. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/SlowCSSSelector.js +135 -0
  302. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/Statistics.js +92 -0
  303. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ThirdParties.js +97 -0
  304. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/Viewport.js +101 -0
  305. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/insights.js +9 -0
  306. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/types.js +18 -0
  307. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/core/LanternError.js +6 -0
  308. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/core/NetworkAnalyzer.js +488 -0
  309. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/core/core.js +5 -0
  310. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/graph/BaseNode.js +276 -0
  311. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/graph/CPUNode.js +63 -0
  312. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/graph/NetworkNode.js +82 -0
  313. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/graph/PageDependencyGraph.js +551 -0
  314. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/graph/graph.js +7 -0
  315. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/lantern.js +9 -0
  316. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/FirstContentfulPaint.js +136 -0
  317. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/Interactive.js +67 -0
  318. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/LargestContentfulPaint.js +68 -0
  319. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/MaxPotentialFID.js +48 -0
  320. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/Metric.js +68 -0
  321. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/SpeedIndex.js +101 -0
  322. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/TBTUtils.js +64 -0
  323. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/TotalBlockingTime.js +78 -0
  324. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/metrics/metrics.js +11 -0
  325. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/simulation/ConnectionPool.js +115 -0
  326. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/simulation/Constants.js +42 -0
  327. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/simulation/DNSCache.js +47 -0
  328. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/simulation/SimulationTimingMap.js +134 -0
  329. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/simulation/Simulator.js +450 -0
  330. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/simulation/TCPConnection.js +154 -0
  331. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/simulation/simulation.js +9 -0
  332. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/types/Lantern.js +24 -0
  333. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/lantern/types/types.js +4 -0
  334. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/trace.js +17 -0
  335. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/Configuration.js +18 -0
  336. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/Extensions.js +37 -0
  337. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/File.js +57 -0
  338. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/Overlays.js +4 -0
  339. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/Timing.js +15 -0
  340. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/TraceEvents.js +574 -0
  341. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/types.js +9 -0
  342. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/SourceMapsResolver.js +201 -0
  343. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/trace_source_maps_resolver.js +4 -0
  344. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/FileManager.js +64 -0
  345. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/IgnoreListManager.js +511 -0
  346. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/SearchConfig.js +113 -0
  347. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/UISourceCode.js +563 -0
  348. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/WorkspaceImpl.js +204 -0
  349. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/workspace.js +9 -0
  350. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/codemirror.next/codemirror.next.js +1 -0
  351. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/legacy-javascript/LICENSE +202 -0
  352. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/legacy-javascript/legacy-javascript.js +2 -0
  353. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/legacy-javascript/lib/legacy-javascript.js +940 -0
  354. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/LICENSE +26 -0
  355. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.js +196 -0
  356. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.js +226 -0
  357. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/codec.js +4 -0
  358. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.js +394 -0
  359. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.js +24 -0
  360. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.js +283 -0
  361. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/mod.js +7 -0
  362. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/util.js +9 -0
  363. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/package/src/vlq.js +84 -0
  364. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec/source-map-scopes-codec.js +4 -0
  365. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/LICENSE +20 -0
  366. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/lib/nostats-subset.js +146 -0
  367. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/httparchive-nostats-subset.js +2 -0
  368. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/httparchive-subset.js +2 -0
  369. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.js +118 -0
  370. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.test.js +40 -0
  371. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/entities.test.js +26 -0
  372. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/index.js +4 -0
  373. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/index.test.js +215 -0
  374. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/subsets/httparchive-nostats.js +4 -0
  375. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/subsets/httparchive.js +4 -0
  376. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/lib/subsets/nostats.js +4 -0
  377. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/package/nostats-subset.js +2 -0
  378. package/build/node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web/third-party-web.js +2 -0
  379. package/build/src/McpContext.js +283 -0
  380. package/build/src/McpResponse.js +223 -0
  381. package/build/src/Mutex.js +40 -0
  382. package/build/src/PageCollector.js +68 -0
  383. package/build/src/WaitForHelper.js +134 -0
  384. package/build/src/browser.js +493 -0
  385. package/build/src/cli.js +156 -0
  386. package/build/src/formatters/consoleFormatter.js +73 -0
  387. package/build/src/formatters/networkFormatter.js +34 -0
  388. package/build/src/formatters/snapshotFormatter.js +75 -0
  389. package/build/src/index.js +13 -0
  390. package/build/src/logger.js +27 -0
  391. package/build/src/main.js +139 -0
  392. package/build/src/system-profile.js +181 -0
  393. package/build/src/tools/ToolDefinition.js +9 -0
  394. package/build/src/tools/bookmarks.js +310 -0
  395. package/build/src/tools/categories.js +15 -0
  396. package/build/src/tools/console.js +19 -0
  397. package/build/src/tools/emulation.js +61 -0
  398. package/build/src/tools/extensions.js +184 -0
  399. package/build/src/tools/input.js +201 -0
  400. package/build/src/tools/network.js +77 -0
  401. package/build/src/tools/pages.js +188 -0
  402. package/build/src/tools/performance.js +145 -0
  403. package/build/src/tools/screenshot.js +65 -0
  404. package/build/src/tools/script.js +57 -0
  405. package/build/src/tools/snapshot.js +42 -0
  406. package/build/src/tools/webstore-auto-screenshot.js +159 -0
  407. package/build/src/tools/webstore-submission.js +332 -0
  408. package/build/src/trace-processing/parse.js +93 -0
  409. package/build/src/utils/pagination.js +49 -0
  410. package/package.json +79 -0
@@ -0,0 +1,1336 @@
1
+ // Copyright 2023 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ /* eslint-disable rulesdir/no-imperative-dom-api */
5
+ import * as Common from '../../core/common/common.js';
6
+ import { CSSMetadata, cssMetadata, CubicBezierKeywordValues, } from './CSSMetadata.js';
7
+ import { ASTUtils, matchDeclaration, matcherBase, tokenizeDeclaration } from './CSSPropertyParser.js';
8
+ export class BaseVariableMatch {
9
+ text;
10
+ node;
11
+ name;
12
+ fallback;
13
+ matching;
14
+ computedTextCallback;
15
+ constructor(text, node, name, fallback, matching, computedTextCallback) {
16
+ this.text = text;
17
+ this.node = node;
18
+ this.name = name;
19
+ this.fallback = fallback;
20
+ this.matching = matching;
21
+ this.computedTextCallback = computedTextCallback;
22
+ }
23
+ computedText() {
24
+ return this.computedTextCallback(this, this.matching);
25
+ }
26
+ fallbackValue() {
27
+ // Fallback can be missing but it can be also be empty: var(--v,)
28
+ if (!this.fallback) {
29
+ return null;
30
+ }
31
+ if (this.fallback.length === 0) {
32
+ return '';
33
+ }
34
+ if (this.matching.hasUnresolvedSubstitutionsRange(this.fallback[0], this.fallback[this.fallback.length - 1])) {
35
+ return null;
36
+ }
37
+ return this.matching.getComputedTextRange(this.fallback[0], this.fallback[this.fallback.length - 1]);
38
+ }
39
+ }
40
+ // This matcher provides matching for var() functions and basic computedText support. Computed text is resolved by a
41
+ // callback. This matcher is intended to be used directly only in environments where CSSMatchedStyles is not available.
42
+ // A more ergonomic version of this matcher exists in VariableMatcher, which uses CSSMatchedStyles to correctly resolve
43
+ // variable references automatically.
44
+ // clang-format off
45
+ export class BaseVariableMatcher extends matcherBase(BaseVariableMatch) {
46
+ // clang-format on
47
+ #computedTextCallback;
48
+ constructor(computedTextCallback) {
49
+ super();
50
+ this.#computedTextCallback = computedTextCallback;
51
+ }
52
+ matches(node, matching) {
53
+ const callee = node.getChild('Callee');
54
+ if (node.name !== 'CallExpression' || !callee || (matching.ast.text(callee) !== 'var')) {
55
+ return null;
56
+ }
57
+ const args = ASTUtils.callArgs(node).map(args => Array.from(ASTUtils.stripComments(args)));
58
+ if (args.length < 1 || args[0].length !== 1) {
59
+ return null;
60
+ }
61
+ const nameNode = args[0][0];
62
+ const fallback = args.length === 2 ? args[1] : undefined;
63
+ if (nameNode?.name !== 'VariableName') {
64
+ return null;
65
+ }
66
+ const varName = matching.ast.text(nameNode);
67
+ if (!varName.startsWith('--')) {
68
+ return null;
69
+ }
70
+ return new BaseVariableMatch(matching.ast.text(node), node, varName, fallback, matching, this.#computedTextCallback);
71
+ }
72
+ }
73
+ export class VariableMatch extends BaseVariableMatch {
74
+ matchedStyles;
75
+ style;
76
+ constructor(text, node, name, fallback, matching, matchedStyles, style) {
77
+ super(text, node, name, fallback, matching, () => this.resolveVariable()?.value ?? this.fallbackValue());
78
+ this.matchedStyles = matchedStyles;
79
+ this.style = style;
80
+ }
81
+ resolveVariable() {
82
+ return this.matchedStyles.computeCSSVariable(this.style, this.name);
83
+ }
84
+ }
85
+ // clang-format off
86
+ export class VariableMatcher extends matcherBase(VariableMatch) {
87
+ matchedStyles;
88
+ style;
89
+ // clang-format on
90
+ constructor(matchedStyles, style) {
91
+ super();
92
+ this.matchedStyles = matchedStyles;
93
+ this.style = style;
94
+ }
95
+ matches(node, matching) {
96
+ const match = new BaseVariableMatcher(() => null).matches(node, matching);
97
+ return match ?
98
+ new VariableMatch(match.text, match.node, match.name, match.fallback, match.matching, this.matchedStyles, this.style) :
99
+ null;
100
+ }
101
+ }
102
+ export class AttributeMatch extends BaseVariableMatch {
103
+ type;
104
+ isCSSTokens;
105
+ isValidType;
106
+ rawValue;
107
+ substitutionText;
108
+ matchedStyles;
109
+ style;
110
+ constructor(text, node, name, fallback, matching, type, isCSSTokens, isValidType, rawValue, substitutionText, matchedStyles, style, computedTextCallback) {
111
+ super(text, node, name, fallback, matching, (_, matching) => computedTextCallback(this, matching));
112
+ this.type = type;
113
+ this.isCSSTokens = isCSSTokens;
114
+ this.isValidType = isValidType;
115
+ this.rawValue = rawValue;
116
+ this.substitutionText = substitutionText;
117
+ this.matchedStyles = matchedStyles;
118
+ this.style = style;
119
+ }
120
+ rawAttributeValue() {
121
+ return this.rawValue;
122
+ }
123
+ cssType() {
124
+ return this.type ?? RAW_STRING_TYPE;
125
+ }
126
+ resolveAttributeValue() {
127
+ return this.matchedStyles.computeAttribute(this.style, this.name, { type: this.cssType(), isCSSTokens: this.isCSSTokens });
128
+ }
129
+ }
130
+ let cssEvaluationElement = null;
131
+ function getCssEvaluationElement() {
132
+ const id = 'css-evaluation-element';
133
+ if (!cssEvaluationElement) {
134
+ cssEvaluationElement = document.getElementById(id);
135
+ if (!cssEvaluationElement) {
136
+ cssEvaluationElement = document.createElement('div');
137
+ cssEvaluationElement.setAttribute('id', id);
138
+ cssEvaluationElement.setAttribute('style', 'hidden: true; --evaluation: attr(data-custom-expr type(*))');
139
+ document.body.appendChild(cssEvaluationElement);
140
+ }
141
+ }
142
+ return cssEvaluationElement;
143
+ }
144
+ // These functions use an element in the frontend to evaluate CSS. The advantage
145
+ // of this is that it is synchronous and doesn't require a CDP method. The
146
+ // disadvantage is it lacks context that would allow substitutions such as
147
+ // `var()` and `calc()` to be resolved correctly, and if the user is doing
148
+ // remote debugging there is a possibility that the CSS behavior is different
149
+ // between the two browser versions. We use it for type checking after
150
+ // substitutions (but not for actual evaluation) and for applying units.
151
+ export function localEvalCSS(value, type) {
152
+ const element = getCssEvaluationElement();
153
+ element.setAttribute('data-value', value);
154
+ element.setAttribute('data-custom-expr', `attr(data-value ${type})`);
155
+ return element.computedStyleMap().get('--evaluation')?.toString() ?? null;
156
+ }
157
+ // It is important to establish whether a type is valid, because if it is not,
158
+ // the current behavior of blink is to ignore the fallback and parse as a
159
+ // raw string, returning '' if the attribute is not set.
160
+ export function isValidCSSType(type) {
161
+ const element = getCssEvaluationElement();
162
+ element.setAttribute('data-custom-expr', `attr(data-nonexistent ${type}, "good")`);
163
+ return '"good"' === (element.computedStyleMap().get('--evaluation')?.toString() ?? null);
164
+ }
165
+ export function defaultValueForCSSType(type) {
166
+ const element = getCssEvaluationElement();
167
+ element.setAttribute('data-custom-expr', `attr(data-nonexistent ${type ?? ''})`);
168
+ return element.computedStyleMap().get('--evaluation')?.toString() ?? null;
169
+ }
170
+ export const RAW_STRING_TYPE = 'raw-string';
171
+ // This matcher provides matching for attr() functions and basic computedText support. Computed text is resolved by a
172
+ // callback.
173
+ // clang-format off
174
+ export class AttributeMatcher extends matcherBase(AttributeMatch) {
175
+ matchedStyles;
176
+ style;
177
+ computedTextCallback;
178
+ // clang-format on
179
+ constructor(matchedStyles, style, computedTextCallback) {
180
+ super();
181
+ this.matchedStyles = matchedStyles;
182
+ this.style = style;
183
+ this.computedTextCallback = computedTextCallback;
184
+ }
185
+ matches(node, matching) {
186
+ const callee = node.getChild('Callee');
187
+ if (node.name !== 'CallExpression' || !callee || (matching.ast.text(callee) !== 'attr')) {
188
+ return null;
189
+ }
190
+ const args = ASTUtils.callArgs(node).map(args => Array.from(ASTUtils.stripComments(args)));
191
+ if (args.length < 1) {
192
+ return null;
193
+ }
194
+ const nameNode = args[0][0];
195
+ if (args[0].length < 1 || args[0].length > 2 || nameNode?.name !== 'ValueName') {
196
+ return null;
197
+ }
198
+ const fallback = args.length === 2 ? args[1] : undefined;
199
+ let type = null;
200
+ let isCSSTokens = false;
201
+ if (args[0].length === 2) {
202
+ const typeNode = args[0][1];
203
+ type = matching.ast.text(typeNode);
204
+ if (typeNode.name === 'CallExpression') {
205
+ if (matching.ast.text(typeNode.getChild('Callee')) !== 'type') {
206
+ return null;
207
+ }
208
+ isCSSTokens = true;
209
+ }
210
+ else if (typeNode.name !== 'ValueName' && type !== '%') {
211
+ return null;
212
+ }
213
+ }
214
+ const isValidType = type === null || isValidCSSType(type);
215
+ isCSSTokens = isCSSTokens && isValidType;
216
+ const attrName = matching.ast.text(nameNode);
217
+ const rawValue = this.matchedStyles.rawAttributeValueFromStyle(this.style, attrName);
218
+ let substitutionText = null;
219
+ if (rawValue !== null) {
220
+ substitutionText = isCSSTokens ? rawValue : localEvalCSS(rawValue, type ?? RAW_STRING_TYPE);
221
+ }
222
+ else if (!fallback) {
223
+ // In the case of unspecified type, there is a default value
224
+ substitutionText = defaultValueForCSSType(type);
225
+ }
226
+ return new AttributeMatch(matching.ast.text(node), node, attrName, fallback, matching, type, isCSSTokens, isValidType, rawValue, substitutionText, this.matchedStyles, this.style, this.computedTextCallback ?? defaultComputeText);
227
+ function defaultComputeText(match, _matching) {
228
+ // Don't fall back if the type is invalid.
229
+ return match.resolveAttributeValue() ??
230
+ (isValidType ? match.fallbackValue() : defaultValueForCSSType(match.type));
231
+ }
232
+ }
233
+ }
234
+ export class BinOpMatch {
235
+ text;
236
+ node;
237
+ constructor(text, node) {
238
+ this.text = text;
239
+ this.node = node;
240
+ }
241
+ }
242
+ // clang-format off
243
+ export class BinOpMatcher extends matcherBase(BinOpMatch) {
244
+ // clang-format on
245
+ accepts() {
246
+ return true;
247
+ }
248
+ matches(node, matching) {
249
+ return node.name === 'BinaryExpression' ? new BinOpMatch(matching.ast.text(node), node) : null;
250
+ }
251
+ }
252
+ export class TextMatch {
253
+ text;
254
+ node;
255
+ computedText;
256
+ constructor(text, node) {
257
+ this.text = text;
258
+ this.node = node;
259
+ if (node.name === 'Comment') {
260
+ this.computedText = () => '';
261
+ }
262
+ }
263
+ render() {
264
+ const span = document.createElement('span');
265
+ span.appendChild(document.createTextNode(this.text));
266
+ return [span];
267
+ }
268
+ }
269
+ // clang-format off
270
+ export class TextMatcher extends matcherBase(TextMatch) {
271
+ // clang-format on
272
+ accepts() {
273
+ return true;
274
+ }
275
+ matches(node, matching) {
276
+ if (!node.firstChild || node.name === 'NumberLiteral' /* may have a Unit child */) {
277
+ // Leaf node, just emit text
278
+ const text = matching.ast.text(node);
279
+ if (text.length) {
280
+ return new TextMatch(text, node);
281
+ }
282
+ }
283
+ return null;
284
+ }
285
+ }
286
+ export class AngleMatch {
287
+ text;
288
+ node;
289
+ constructor(text, node) {
290
+ this.text = text;
291
+ this.node = node;
292
+ }
293
+ computedText() {
294
+ return this.text;
295
+ }
296
+ }
297
+ // clang-format off
298
+ export class AngleMatcher extends matcherBase(AngleMatch) {
299
+ // clang-format on
300
+ accepts(propertyName) {
301
+ return cssMetadata().isAngleAwareProperty(propertyName);
302
+ }
303
+ matches(node, matching) {
304
+ if (node.name !== 'NumberLiteral') {
305
+ return null;
306
+ }
307
+ const unit = node.getChild('Unit');
308
+ // TODO(crbug/1138628) handle unitless 0
309
+ if (!unit || !['deg', 'grad', 'rad', 'turn'].includes(matching.ast.text(unit))) {
310
+ return null;
311
+ }
312
+ return new AngleMatch(matching.ast.text(node), node);
313
+ }
314
+ }
315
+ function literalToNumber(node, ast) {
316
+ if (node.type.name !== 'NumberLiteral') {
317
+ return null;
318
+ }
319
+ const text = ast.text(node);
320
+ return Number(text.substring(0, text.length - ast.text(node.getChild('Unit')).length));
321
+ }
322
+ export class ColorMixMatch {
323
+ text;
324
+ node;
325
+ space;
326
+ color1;
327
+ color2;
328
+ constructor(text, node, space, color1, color2) {
329
+ this.text = text;
330
+ this.node = node;
331
+ this.space = space;
332
+ this.color1 = color1;
333
+ this.color2 = color2;
334
+ }
335
+ }
336
+ // clang-format off
337
+ export class ColorMixMatcher extends matcherBase(ColorMixMatch) {
338
+ // clang-format on
339
+ accepts(propertyName) {
340
+ return cssMetadata().isColorAwareProperty(propertyName);
341
+ }
342
+ matches(node, matching) {
343
+ if (node.name !== 'CallExpression' || matching.ast.text(node.getChild('Callee')) !== 'color-mix') {
344
+ return null;
345
+ }
346
+ const computedValueTree = tokenizeDeclaration('--property', matching.getComputedText(node));
347
+ if (!computedValueTree) {
348
+ return null;
349
+ }
350
+ const value = ASTUtils.declValue(computedValueTree.tree);
351
+ if (!value) {
352
+ return null;
353
+ }
354
+ const computedValueArgs = ASTUtils.callArgs(value);
355
+ if (computedValueArgs.length !== 3) {
356
+ return null;
357
+ }
358
+ const [space, color1, color2] = computedValueArgs;
359
+ // Verify that all arguments are there, and that the space starts with a literal `in`.
360
+ if (space.length < 2 || computedValueTree.text(ASTUtils.stripComments(space).next().value) !== 'in' ||
361
+ color1.length < 1 || color2.length < 1) {
362
+ return null;
363
+ }
364
+ // Verify there's at most one percentage value for each color.
365
+ const p1 = color1.filter(n => n.type.name === 'NumberLiteral' && computedValueTree.text(n.getChild('Unit')) === '%');
366
+ const p2 = color2.filter(n => n.type.name === 'NumberLiteral' && computedValueTree.text(n.getChild('Unit')) === '%');
367
+ if (p1.length > 1 || p2.length > 1) {
368
+ return null;
369
+ }
370
+ // Verify that if both colors carry percentages, they aren't both zero (which is an invalid property value).
371
+ if (p1[0] && p2[0] && (literalToNumber(p1[0], computedValueTree) ?? 0) === 0 &&
372
+ (literalToNumber(p2[0], computedValueTree) ?? 0) === 0) {
373
+ return null;
374
+ }
375
+ const args = ASTUtils.callArgs(node);
376
+ if (args.length !== 3) {
377
+ return null;
378
+ }
379
+ return new ColorMixMatch(matching.ast.text(node), node, args[0], args[1], args[2]);
380
+ }
381
+ }
382
+ // clang-format off
383
+ export class URLMatch {
384
+ url;
385
+ text;
386
+ node;
387
+ constructor(url, text, node) {
388
+ this.url = url;
389
+ this.text = text;
390
+ this.node = node;
391
+ }
392
+ }
393
+ // clang-format off
394
+ export class URLMatcher extends matcherBase(URLMatch) {
395
+ // clang-format on
396
+ matches(node, matching) {
397
+ if (node.name !== 'CallLiteral') {
398
+ return null;
399
+ }
400
+ const callee = node.getChild('CallTag');
401
+ if (!callee || matching.ast.text(callee) !== 'url') {
402
+ return null;
403
+ }
404
+ const [, lparenNode, urlNode, rparenNode] = ASTUtils.siblings(callee);
405
+ if (matching.ast.text(lparenNode) !== '(' ||
406
+ (urlNode.name !== 'ParenthesizedContent' && urlNode.name !== 'StringLiteral') ||
407
+ matching.ast.text(rparenNode) !== ')') {
408
+ return null;
409
+ }
410
+ const text = matching.ast.text(urlNode);
411
+ const url = (urlNode.name === 'StringLiteral' ? text.substr(1, text.length - 2) : text.trim());
412
+ return new URLMatch(url, matching.ast.text(node), node);
413
+ }
414
+ }
415
+ export class LinearGradientMatch {
416
+ text;
417
+ node;
418
+ constructor(text, node) {
419
+ this.text = text;
420
+ this.node = node;
421
+ }
422
+ }
423
+ // clang-format off
424
+ export class LinearGradientMatcher extends matcherBase(LinearGradientMatch) {
425
+ // clang-format on
426
+ matches(node, matching) {
427
+ const text = matching.ast.text(node);
428
+ if (node.name === 'CallExpression' && matching.ast.text(node.getChild('Callee')) === 'linear-gradient') {
429
+ return new LinearGradientMatch(text, node);
430
+ }
431
+ return null;
432
+ }
433
+ accepts(propertyName) {
434
+ return ['background', 'background-image', '-webkit-mask-image'].includes(propertyName);
435
+ }
436
+ }
437
+ export class ColorMatch {
438
+ text;
439
+ node;
440
+ currentColorCallback;
441
+ relativeColor;
442
+ computedText;
443
+ constructor(text, node, currentColorCallback, relativeColor) {
444
+ this.text = text;
445
+ this.node = node;
446
+ this.currentColorCallback = currentColorCallback;
447
+ this.relativeColor = relativeColor;
448
+ this.computedText = currentColorCallback;
449
+ }
450
+ }
451
+ // clang-format off
452
+ export class ColorMatcher extends matcherBase(ColorMatch) {
453
+ currentColorCallback;
454
+ constructor(currentColorCallback) {
455
+ super();
456
+ this.currentColorCallback = currentColorCallback;
457
+ }
458
+ // clang-format on
459
+ accepts(propertyName) {
460
+ return cssMetadata().isColorAwareProperty(propertyName);
461
+ }
462
+ matches(node, matching) {
463
+ const text = matching.ast.text(node);
464
+ if (node.name === 'ColorLiteral') {
465
+ return new ColorMatch(text, node);
466
+ }
467
+ if (node.name === 'ValueName') {
468
+ if (Common.Color.Nicknames.has(text)) {
469
+ return new ColorMatch(text, node);
470
+ }
471
+ if (text.toLowerCase() === 'currentcolor' && this.currentColorCallback) {
472
+ const callback = this.currentColorCallback;
473
+ return new ColorMatch(text, node, () => callback() ?? text);
474
+ }
475
+ }
476
+ if (node.name === 'CallExpression') {
477
+ const callee = node.getChild('Callee');
478
+ const colorFunc = matching.ast.text(callee).toLowerCase();
479
+ if (callee && colorFunc.match(/^(rgba?|hsla?|hwba?|lab|lch|oklab|oklch|color)$/)) {
480
+ const args = ASTUtils.children(node.getChild('ArgList'));
481
+ // args are the tokens for the parthesized expression following the function name, so in a well-formed case
482
+ // should at least contain the open and closing parens.
483
+ const colorText = args.length >= 2 ? matching.getComputedTextRange(args[0], args[args.length - 1]) : '';
484
+ // colorText holds the fully substituted parenthesized expression, so colorFunc + colorText is the color
485
+ // function call.
486
+ const isRelativeColorSyntax = Boolean(colorText.match(/^[^)]*\(\W*from\W+/) && !matching.hasUnresolvedSubstitutions(node) &&
487
+ CSS.supports('color', colorFunc + colorText));
488
+ if (!isRelativeColorSyntax) {
489
+ return new ColorMatch(text, node);
490
+ }
491
+ const tokenized = matchDeclaration('--color', '--colorFunc' + colorText, [new ColorMatcher()]);
492
+ if (!tokenized) {
493
+ return null;
494
+ }
495
+ const [colorArgs] = ASTUtils.callArgs(ASTUtils.declValue(tokenized.ast.tree));
496
+ // getComputedText already removed comments and such, so there must be 5 or 6 args:
497
+ // rgb(from red c0 c1 c2) or color(from yellow srgb c0 c1 c2)
498
+ // If any of the C is a calc expression that is a single root node. If the value contains an alpha channel that
499
+ // is parsed as a BinOp into c2.
500
+ if (colorArgs.length !== (colorFunc === 'color' ? 6 : 5)) {
501
+ return null;
502
+ }
503
+ const colorSpace = Common.Color.getFormat(colorFunc !== 'color' ? colorFunc : matching.ast.text(colorArgs[2]));
504
+ if (!colorSpace) {
505
+ return null;
506
+ }
507
+ const baseColor = tokenized.getMatch(colorArgs[1]);
508
+ if (tokenized.ast.text(colorArgs[0]) !== 'from' || !(baseColor instanceof ColorMatch)) {
509
+ return null;
510
+ }
511
+ return new ColorMatch(text, node, undefined, { colorSpace, baseColor });
512
+ }
513
+ }
514
+ return null;
515
+ }
516
+ }
517
+ function isRelativeColorChannelName(channel) {
518
+ const maybeChannel = channel;
519
+ switch (maybeChannel) {
520
+ case "a" /* Common.Color.ColorChannel.A */:
521
+ case "alpha" /* Common.Color.ColorChannel.ALPHA */:
522
+ case "b" /* Common.Color.ColorChannel.B */:
523
+ case "c" /* Common.Color.ColorChannel.C */:
524
+ case "g" /* Common.Color.ColorChannel.G */:
525
+ case "h" /* Common.Color.ColorChannel.H */:
526
+ case "l" /* Common.Color.ColorChannel.L */:
527
+ case "r" /* Common.Color.ColorChannel.R */:
528
+ case "s" /* Common.Color.ColorChannel.S */:
529
+ case "w" /* Common.Color.ColorChannel.W */:
530
+ case "x" /* Common.Color.ColorChannel.X */:
531
+ case "y" /* Common.Color.ColorChannel.Y */:
532
+ case "z" /* Common.Color.ColorChannel.Z */:
533
+ return true;
534
+ }
535
+ // This assignment catches missed values in the switch above.
536
+ const catchFallback = maybeChannel; // eslint-disable-line @typescript-eslint/no-unused-vars
537
+ return false;
538
+ }
539
+ export class RelativeColorChannelMatch {
540
+ text;
541
+ node;
542
+ constructor(text, node) {
543
+ this.text = text;
544
+ this.node = node;
545
+ }
546
+ getColorChannelValue(relativeColor) {
547
+ const color = Common.Color.parse(relativeColor.baseColor.text)?.as(relativeColor.colorSpace);
548
+ if (color instanceof Common.Color.ColorFunction) {
549
+ switch (this.text) {
550
+ case "r" /* Common.Color.ColorChannel.R */:
551
+ return color.isXYZ() ? null : color.p0;
552
+ case "g" /* Common.Color.ColorChannel.G */:
553
+ return color.isXYZ() ? null : color.p1;
554
+ case "b" /* Common.Color.ColorChannel.B */:
555
+ return color.isXYZ() ? null : color.p2;
556
+ case "x" /* Common.Color.ColorChannel.X */:
557
+ return color.isXYZ() ? color.p0 : null;
558
+ case "y" /* Common.Color.ColorChannel.Y */:
559
+ return color.isXYZ() ? color.p1 : null;
560
+ case "z" /* Common.Color.ColorChannel.Z */:
561
+ return color.isXYZ() ? color.p2 : null;
562
+ case "alpha" /* Common.Color.ColorChannel.ALPHA */:
563
+ return color.alpha;
564
+ }
565
+ }
566
+ else if (color instanceof Common.Color.Legacy) {
567
+ switch (this.text) {
568
+ case "r" /* Common.Color.ColorChannel.R */:
569
+ return color.rgba()[0];
570
+ case "g" /* Common.Color.ColorChannel.G */:
571
+ return color.rgba()[1];
572
+ case "b" /* Common.Color.ColorChannel.B */:
573
+ return color.rgba()[2];
574
+ case "alpha" /* Common.Color.ColorChannel.ALPHA */:
575
+ return color.rgba()[3];
576
+ }
577
+ }
578
+ else if (color && this.text in color) {
579
+ return color[this.text];
580
+ }
581
+ return null;
582
+ }
583
+ computedText() {
584
+ return this.text;
585
+ }
586
+ }
587
+ // clang-format off
588
+ export class RelativeColorChannelMatcher extends matcherBase(RelativeColorChannelMatch) {
589
+ // clang-format on
590
+ accepts(propertyName) {
591
+ return cssMetadata().isColorAwareProperty(propertyName);
592
+ }
593
+ matches(node, matching) {
594
+ const text = matching.ast.text(node);
595
+ if (node.name === 'ValueName' && isRelativeColorChannelName(text)) {
596
+ return new RelativeColorChannelMatch(text, node);
597
+ }
598
+ return null;
599
+ }
600
+ }
601
+ export class LightDarkColorMatch {
602
+ text;
603
+ node;
604
+ light;
605
+ dark;
606
+ style;
607
+ constructor(text, node, light, dark, style) {
608
+ this.text = text;
609
+ this.node = node;
610
+ this.light = light;
611
+ this.dark = dark;
612
+ this.style = style;
613
+ }
614
+ }
615
+ // clang-format off
616
+ export class LightDarkColorMatcher extends matcherBase(LightDarkColorMatch) {
617
+ style;
618
+ // clang-format on
619
+ constructor(style) {
620
+ super();
621
+ this.style = style;
622
+ }
623
+ accepts(propertyName) {
624
+ return cssMetadata().isColorAwareProperty(propertyName);
625
+ }
626
+ matches(node, matching) {
627
+ if (node.name !== 'CallExpression' || matching.ast.text(node.getChild('Callee')) !== 'light-dark') {
628
+ return null;
629
+ }
630
+ const args = ASTUtils.callArgs(node);
631
+ if (args.length !== 2 || args[0].length === 0 || args[1].length === 0) {
632
+ return null;
633
+ }
634
+ return new LightDarkColorMatch(matching.ast.text(node), node, args[0], args[1], this.style);
635
+ }
636
+ }
637
+ export class AutoBaseMatch {
638
+ text;
639
+ node;
640
+ auto;
641
+ base;
642
+ constructor(text, node, auto, base) {
643
+ this.text = text;
644
+ this.node = node;
645
+ this.auto = auto;
646
+ this.base = base;
647
+ }
648
+ }
649
+ // clang-format off
650
+ export class AutoBaseMatcher extends matcherBase(AutoBaseMatch) {
651
+ // clang-format on
652
+ matches(node, matching) {
653
+ if (node.name !== 'CallExpression' || matching.ast.text(node.getChild('Callee')) !== '-internal-auto-base') {
654
+ return null;
655
+ }
656
+ const args = ASTUtils.callArgs(node);
657
+ if (args.length !== 2 || args[0].length === 0 || args[1].length === 0) {
658
+ return null;
659
+ }
660
+ return new AutoBaseMatch(matching.ast.text(node), node, args[0], args[1]);
661
+ }
662
+ }
663
+ export class LinkableNameMatch {
664
+ text;
665
+ node;
666
+ propertyName;
667
+ constructor(text, node, propertyName) {
668
+ this.text = text;
669
+ this.node = node;
670
+ this.propertyName = propertyName;
671
+ }
672
+ }
673
+ // clang-format off
674
+ export class LinkableNameMatcher extends matcherBase(LinkableNameMatch) {
675
+ // clang-format on
676
+ static isLinkableNameProperty(propertyName) {
677
+ const names = [
678
+ "animation" /* LinkableNameProperties.ANIMATION */,
679
+ "animation-name" /* LinkableNameProperties.ANIMATION_NAME */,
680
+ "font-palette" /* LinkableNameProperties.FONT_PALETTE */,
681
+ "position-try-fallbacks" /* LinkableNameProperties.POSITION_TRY_FALLBACKS */,
682
+ "position-try" /* LinkableNameProperties.POSITION_TRY */,
683
+ ];
684
+ return names.includes(propertyName);
685
+ }
686
+ static identifierAnimationLonghandMap = new Map(Object.entries({
687
+ normal: "direction" /* AnimationLonghandPart.DIRECTION */,
688
+ alternate: "direction" /* AnimationLonghandPart.DIRECTION */,
689
+ reverse: "direction" /* AnimationLonghandPart.DIRECTION */,
690
+ 'alternate-reverse': "direction" /* AnimationLonghandPart.DIRECTION */,
691
+ none: "fill-mode" /* AnimationLonghandPart.FILL_MODE */,
692
+ forwards: "fill-mode" /* AnimationLonghandPart.FILL_MODE */,
693
+ backwards: "fill-mode" /* AnimationLonghandPart.FILL_MODE */,
694
+ both: "fill-mode" /* AnimationLonghandPart.FILL_MODE */,
695
+ running: "play-state" /* AnimationLonghandPart.PLAY_STATE */,
696
+ paused: "play-state" /* AnimationLonghandPart.PLAY_STATE */,
697
+ infinite: "iteration-count" /* AnimationLonghandPart.ITERATION_COUNT */,
698
+ linear: "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
699
+ ease: "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
700
+ 'ease-in': "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
701
+ 'ease-out': "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
702
+ 'ease-in-out': "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
703
+ steps: "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
704
+ 'step-start': "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
705
+ 'step-end': "easing-function" /* AnimationLonghandPart.EASING_FUNCTION */,
706
+ }));
707
+ matchAnimationNameInShorthand(node, matching) {
708
+ // Order is important within each animation definition for distinguishing <keyframes-name> values from other keywords.
709
+ // When parsing, keywords that are valid for properties other than animation-name
710
+ // whose values were not found earlier in the shorthand must be accepted for those properties rather than for animation-name.
711
+ // See the details in: https://w3c.github.io/csswg-drafts/css-animations/#animation.
712
+ const text = matching.ast.text(node);
713
+ // This is not a known identifier, so return it as `animation-name`.
714
+ if (!LinkableNameMatcher.identifierAnimationLonghandMap.has(text)) {
715
+ return new LinkableNameMatch(text, node, "animation" /* LinkableNameProperties.ANIMATION */);
716
+ }
717
+ // There can be multiple `animation` declarations splitted by a comma.
718
+ // So, we find the declaration nodes that are related to the node argument.
719
+ const declarations = ASTUtils.split(ASTUtils.siblings(ASTUtils.declValue(matching.ast.tree)));
720
+ const currentDeclarationNodes = declarations.find(declaration => declaration[0].from <= node.from && declaration[declaration.length - 1].to >= node.to);
721
+ if (!currentDeclarationNodes) {
722
+ return null;
723
+ }
724
+ // We reparse here until the node argument since a variable might be
725
+ // providing a meaningful value such as a timing keyword,
726
+ // that might change the meaning of the node.
727
+ const computedText = matching.getComputedTextRange(currentDeclarationNodes[0], node);
728
+ const tokenized = tokenizeDeclaration('--p', computedText);
729
+ if (!tokenized) {
730
+ return null;
731
+ }
732
+ const identifierCategory = LinkableNameMatcher.identifierAnimationLonghandMap.get(text); // The category of the node argument
733
+ for (let itNode = ASTUtils.declValue(tokenized.tree); itNode?.nextSibling; itNode = itNode.nextSibling) {
734
+ // Run through all the nodes that come before node argument
735
+ // and check whether a value in the same category is found.
736
+ // if so, it means our identifier is an `animation-name` keyword.
737
+ if (itNode.name === 'ValueName') {
738
+ const categoryValue = LinkableNameMatcher.identifierAnimationLonghandMap.get(tokenized.text(itNode));
739
+ if (categoryValue && categoryValue === identifierCategory) {
740
+ return new LinkableNameMatch(text, node, "animation" /* LinkableNameProperties.ANIMATION */);
741
+ }
742
+ }
743
+ }
744
+ return null;
745
+ }
746
+ matches(node, matching) {
747
+ const { propertyName } = matching.ast;
748
+ const text = matching.ast.text(node);
749
+ const parentNode = node.parent;
750
+ if (!parentNode) {
751
+ return null;
752
+ }
753
+ if (!(propertyName && LinkableNameMatcher.isLinkableNameProperty(propertyName))) {
754
+ return null;
755
+ }
756
+ const isParentADeclaration = parentNode.name === 'Declaration';
757
+ const isInsideVarCall = parentNode.name === 'ArgList' && parentNode.prevSibling?.name === 'Callee' &&
758
+ matching.ast.text(parentNode.prevSibling) === 'var';
759
+ const isAParentDeclarationOrVarCall = isParentADeclaration || isInsideVarCall;
760
+ // `position-try-fallbacks` and `position-try` only accept names with dashed ident.
761
+ const shouldMatchOnlyVariableName = propertyName === "position-try" /* LinkableNameProperties.POSITION_TRY */ ||
762
+ propertyName === "position-try-fallbacks" /* LinkableNameProperties.POSITION_TRY_FALLBACKS */;
763
+ // We only mark top level nodes or nodes that are inside `var()` expressions as linkable names.
764
+ if (!propertyName || (node.name !== 'ValueName' && node.name !== 'VariableName') ||
765
+ !isAParentDeclarationOrVarCall || (node.name === 'ValueName' && shouldMatchOnlyVariableName)) {
766
+ return null;
767
+ }
768
+ if (propertyName === 'animation') {
769
+ return this.matchAnimationNameInShorthand(node, matching);
770
+ }
771
+ // The assertion here is safe since this matcher only runs for
772
+ // properties with names inside `LinkableNameProperties` (See the `accepts` function.)
773
+ return new LinkableNameMatch(text, node, propertyName);
774
+ }
775
+ }
776
+ export class BezierMatch {
777
+ text;
778
+ node;
779
+ constructor(text, node) {
780
+ this.text = text;
781
+ this.node = node;
782
+ }
783
+ }
784
+ // clang-format off
785
+ export class BezierMatcher extends matcherBase(BezierMatch) {
786
+ // clang-format on
787
+ accepts(propertyName) {
788
+ return cssMetadata().isBezierAwareProperty(propertyName);
789
+ }
790
+ matches(node, matching) {
791
+ const text = matching.ast.text(node);
792
+ const isCubicBezierKeyword = node.name === 'ValueName' && CubicBezierKeywordValues.has(text);
793
+ const isCubicBezierOrLinearFunction = node.name === 'CallExpression' &&
794
+ ['cubic-bezier', 'linear'].includes(matching.ast.text(node.getChild('Callee')));
795
+ if (!isCubicBezierKeyword && !isCubicBezierOrLinearFunction) {
796
+ return null;
797
+ }
798
+ return new BezierMatch(text, node);
799
+ }
800
+ }
801
+ export class StringMatch {
802
+ text;
803
+ node;
804
+ constructor(text, node) {
805
+ this.text = text;
806
+ this.node = node;
807
+ }
808
+ }
809
+ // clang-format off
810
+ export class StringMatcher extends matcherBase(StringMatch) {
811
+ // clang-format on
812
+ matches(node, matching) {
813
+ return node.name === 'StringLiteral' ? new StringMatch(matching.ast.text(node), node) : null;
814
+ }
815
+ }
816
+ export class ShadowMatch {
817
+ text;
818
+ node;
819
+ shadowType;
820
+ constructor(text, node, shadowType) {
821
+ this.text = text;
822
+ this.node = node;
823
+ this.shadowType = shadowType;
824
+ }
825
+ }
826
+ // clang-format off
827
+ export class ShadowMatcher extends matcherBase(ShadowMatch) {
828
+ // clang-format on
829
+ accepts(propertyName) {
830
+ return cssMetadata().isShadowProperty(propertyName);
831
+ }
832
+ matches(node, matching) {
833
+ if (node.name !== 'Declaration') {
834
+ return null;
835
+ }
836
+ const valueNodes = ASTUtils.siblings(ASTUtils.declValue(node));
837
+ if (valueNodes.length === 0) {
838
+ return null;
839
+ }
840
+ const valueText = matching.ast.textRange(valueNodes[0], valueNodes[valueNodes.length - 1]);
841
+ return new ShadowMatch(valueText, node, matching.ast.propertyName === 'text-shadow' ? "textShadow" /* ShadowType.TEXT_SHADOW */ : "boxShadow" /* ShadowType.BOX_SHADOW */);
842
+ }
843
+ }
844
+ export class FontMatch {
845
+ text;
846
+ node;
847
+ constructor(text, node) {
848
+ this.text = text;
849
+ this.node = node;
850
+ }
851
+ }
852
+ // clang-format off
853
+ export class FontMatcher extends matcherBase(FontMatch) {
854
+ // clang-format on
855
+ accepts(propertyName) {
856
+ return cssMetadata().isFontAwareProperty(propertyName);
857
+ }
858
+ matches(node, matching) {
859
+ if (node.name !== 'Declaration') {
860
+ return null;
861
+ }
862
+ const valueNodes = ASTUtils.siblings(ASTUtils.declValue(node));
863
+ if (valueNodes.length === 0) {
864
+ return null;
865
+ }
866
+ const validNodes = matching.ast.propertyName === 'font-family' ? ['ValueName', 'StringLiteral', 'Comment', ','] :
867
+ ['Comment', 'ValueName', 'NumberLiteral'];
868
+ if (valueNodes.some(node => !validNodes.includes(node.name))) {
869
+ return null;
870
+ }
871
+ const valueText = matching.ast.textRange(valueNodes[0], valueNodes[valueNodes.length - 1]);
872
+ return new FontMatch(valueText, node);
873
+ }
874
+ }
875
+ export class LengthMatch {
876
+ text;
877
+ node;
878
+ unit;
879
+ constructor(text, node, unit) {
880
+ this.text = text;
881
+ this.node = node;
882
+ this.unit = unit;
883
+ }
884
+ }
885
+ // clang-format off
886
+ export class LengthMatcher extends matcherBase(LengthMatch) {
887
+ // clang-format on
888
+ static LENGTH_UNITS = new Set([
889
+ 'em', 'ex', 'ch', 'cap', 'ic', 'lh', 'rem', 'rex', 'rch', 'rlh', 'ric', 'rcap', 'pt', 'pc',
890
+ 'in', 'cm', 'mm', 'Q', 'vw', 'vh', 'vi', 'vb', 'vmin', 'vmax', 'dvw', 'dvh', 'dvi', 'dvb',
891
+ 'dvmin', 'dvmax', 'svw', 'svh', 'svi', 'svb', 'svmin', 'svmax', 'lvw', 'lvh', 'lvi', 'lvb', 'lvmin', 'lvmax',
892
+ 'cqw', 'cqh', 'cqi', 'cqb', 'cqmin', 'cqmax', 'cqem', 'cqlh', 'cqex', 'cqch', '%'
893
+ ]);
894
+ matches(node, matching) {
895
+ if (node.name !== 'NumberLiteral') {
896
+ return null;
897
+ }
898
+ const unit = matching.ast.text(node.getChild('Unit'));
899
+ if (!LengthMatcher.LENGTH_UNITS.has(unit)) {
900
+ return null;
901
+ }
902
+ const text = matching.ast.text(node);
903
+ return new LengthMatch(text, node, unit);
904
+ }
905
+ }
906
+ export class BaseFunctionMatch {
907
+ text;
908
+ node;
909
+ func;
910
+ args;
911
+ constructor(text, node, func, args) {
912
+ this.text = text;
913
+ this.node = node;
914
+ this.func = func;
915
+ this.args = args;
916
+ }
917
+ }
918
+ export class MathFunctionMatch extends BaseFunctionMatch {
919
+ isArithmeticFunctionCall() {
920
+ const func = this.func;
921
+ switch (func) {
922
+ case "calc" /* ArithmeticFunction.CALC */:
923
+ case "sibling-count" /* ArithmeticFunction.SIBLING_COUNT */:
924
+ case "sibling-index" /* ArithmeticFunction.SIBLING_INDEX */:
925
+ return true;
926
+ }
927
+ // This assignment catches missed values in the switch above.
928
+ const catchFallback = func; // eslint-disable-line @typescript-eslint/no-unused-vars
929
+ return false;
930
+ }
931
+ }
932
+ // clang-format off
933
+ export class MathFunctionMatcher extends matcherBase(MathFunctionMatch) {
934
+ // clang-format on
935
+ static getFunctionType(callee) {
936
+ const maybeFunc = callee;
937
+ switch (maybeFunc) {
938
+ case null:
939
+ case "min" /* SelectFunction.MIN */:
940
+ case "max" /* SelectFunction.MAX */:
941
+ case "clamp" /* SelectFunction.CLAMP */:
942
+ case "calc" /* ArithmeticFunction.CALC */:
943
+ case "sibling-count" /* ArithmeticFunction.SIBLING_COUNT */:
944
+ case "sibling-index" /* ArithmeticFunction.SIBLING_INDEX */:
945
+ return maybeFunc;
946
+ }
947
+ // This assignment catches missed values in the switch above.
948
+ const catchFallback = maybeFunc; // eslint-disable-line @typescript-eslint/no-unused-vars
949
+ return null;
950
+ }
951
+ matches(node, matching) {
952
+ if (node.name !== 'CallExpression') {
953
+ return null;
954
+ }
955
+ const callee = MathFunctionMatcher.getFunctionType(matching.ast.text(node.getChild('Callee')));
956
+ if (!callee) {
957
+ return null;
958
+ }
959
+ const args = ASTUtils.callArgs(node);
960
+ if (args.some(arg => arg.length === 0 || matching.hasUnresolvedSubstitutionsRange(arg[0], arg[arg.length - 1]))) {
961
+ return null;
962
+ }
963
+ const text = matching.ast.text(node);
964
+ const match = new MathFunctionMatch(text, node, callee, args);
965
+ if (!match.isArithmeticFunctionCall() && args.length === 0) {
966
+ return null;
967
+ }
968
+ return match;
969
+ }
970
+ }
971
+ export class CustomFunctionMatch extends BaseFunctionMatch {
972
+ }
973
+ // clang-format off
974
+ export class CustomFunctionMatcher extends matcherBase(CustomFunctionMatch) {
975
+ // clang-format on
976
+ matches(node, matching) {
977
+ if (node.name !== 'CallExpression') {
978
+ return null;
979
+ }
980
+ const callee = matching.ast.text(node.getChild('VariableName'));
981
+ if (!callee?.startsWith('--')) {
982
+ return null;
983
+ }
984
+ const args = ASTUtils.callArgs(node);
985
+ if (args.some(arg => arg.length === 0 || matching.hasUnresolvedSubstitutionsRange(arg[0], arg[arg.length - 1]))) {
986
+ return null;
987
+ }
988
+ const text = matching.ast.text(node);
989
+ return new CustomFunctionMatch(text, node, callee, args);
990
+ }
991
+ }
992
+ export class FlexGridMatch {
993
+ text;
994
+ node;
995
+ isFlex;
996
+ constructor(text, node, isFlex) {
997
+ this.text = text;
998
+ this.node = node;
999
+ this.isFlex = isFlex;
1000
+ }
1001
+ }
1002
+ // clang-format off
1003
+ export class FlexGridMatcher extends matcherBase(FlexGridMatch) {
1004
+ // clang-format on
1005
+ static FLEX = ['flex', 'inline-flex', 'block flex', 'inline flex'];
1006
+ static GRID = ['grid', 'inline-grid', 'block grid', 'inline grid'];
1007
+ accepts(propertyName) {
1008
+ return propertyName === 'display';
1009
+ }
1010
+ matches(node, matching) {
1011
+ if (node.name !== 'Declaration') {
1012
+ return null;
1013
+ }
1014
+ const valueNodes = ASTUtils.siblings(ASTUtils.declValue(node));
1015
+ if (valueNodes.length < 1) {
1016
+ return null;
1017
+ }
1018
+ const values = valueNodes.filter(node => node.name !== 'Important')
1019
+ .map(node => matching.getComputedText(node).trim())
1020
+ .filter(value => value);
1021
+ const text = values.join(' ');
1022
+ if (FlexGridMatcher.FLEX.includes(text)) {
1023
+ return new FlexGridMatch(matching.ast.text(node), node, true);
1024
+ }
1025
+ if (FlexGridMatcher.GRID.includes(text)) {
1026
+ return new FlexGridMatch(matching.ast.text(node), node, false);
1027
+ }
1028
+ return null;
1029
+ }
1030
+ }
1031
+ export class GridTemplateMatch {
1032
+ text;
1033
+ node;
1034
+ lines;
1035
+ constructor(text, node, lines) {
1036
+ this.text = text;
1037
+ this.node = node;
1038
+ this.lines = lines;
1039
+ }
1040
+ }
1041
+ // clang-format off
1042
+ export class GridTemplateMatcher extends matcherBase(GridTemplateMatch) {
1043
+ // clang-format on
1044
+ accepts(propertyName) {
1045
+ return cssMetadata().isGridAreaDefiningProperty(propertyName);
1046
+ }
1047
+ matches(node, matching) {
1048
+ if (node.name !== 'Declaration' || matching.hasUnresolvedSubstitutions(node)) {
1049
+ return null;
1050
+ }
1051
+ const lines = [];
1052
+ let curLine = [];
1053
+ // The following two states are designed to consume different cases of LineNames:
1054
+ // 1. no LineNames in between StringLiterals;
1055
+ // 2. one LineNames in between, which means the LineNames belongs to the current line;
1056
+ // 3. two LineNames in between, which means the second LineNames starts a new line.
1057
+ // `hasLeadingLineNames` tracks if the current row already starts with a LineNames and
1058
+ // with no following StringLiteral yet, which means that the next StringLiteral should
1059
+ // be appended to the same `curLine`, instead of creating a new line.
1060
+ let hasLeadingLineNames = false;
1061
+ // `needClosingLineNames` tracks if the current row can still consume an optional LineNames,
1062
+ // which will decide if we should start a new line or not when a LineNames is encountered.
1063
+ let needClosingLineNames = false;
1064
+ // Gather row definitions of [<line-names>? <string> <track-size>? <line-names>?], which
1065
+ // be rendered into separate lines.
1066
+ function parseNodes(nodes, varParsingMode = false) {
1067
+ for (const curNode of nodes) {
1068
+ if (matching.getMatch(curNode) instanceof BaseVariableMatch) {
1069
+ const computedValueTree = tokenizeDeclaration('--property', matching.getComputedText(curNode));
1070
+ if (!computedValueTree) {
1071
+ continue;
1072
+ }
1073
+ const varNodes = ASTUtils.siblings(ASTUtils.declValue(computedValueTree.tree));
1074
+ if (varNodes.length === 0) {
1075
+ continue;
1076
+ }
1077
+ if ((varNodes[0].name === 'StringLiteral' && !hasLeadingLineNames) ||
1078
+ (varNodes[0].name === 'BracketedValue' && !needClosingLineNames)) {
1079
+ // The variable value either starts with a string, or with a line name that belongs to a new row;
1080
+ // therefore we start a new line with the variable.
1081
+ lines.push(curLine);
1082
+ curLine = [curNode];
1083
+ }
1084
+ else {
1085
+ curLine.push(curNode);
1086
+ }
1087
+ // We parse computed nodes of this variable to correctly advance local states, but
1088
+ // these computed nodes won't be added to the lines.
1089
+ parseNodes(varNodes, true);
1090
+ }
1091
+ else if (curNode.name === 'BinaryExpression') {
1092
+ parseNodes(ASTUtils.siblings(curNode.firstChild));
1093
+ }
1094
+ else if (curNode.name === 'StringLiteral') {
1095
+ if (!varParsingMode) {
1096
+ if (hasLeadingLineNames) {
1097
+ curLine.push(curNode);
1098
+ }
1099
+ else {
1100
+ lines.push(curLine);
1101
+ curLine = [curNode];
1102
+ }
1103
+ }
1104
+ needClosingLineNames = true;
1105
+ hasLeadingLineNames = false;
1106
+ }
1107
+ else if (curNode.name === 'BracketedValue') {
1108
+ if (!varParsingMode) {
1109
+ if (needClosingLineNames) {
1110
+ curLine.push(curNode);
1111
+ }
1112
+ else {
1113
+ lines.push(curLine);
1114
+ curLine = [curNode];
1115
+ }
1116
+ }
1117
+ hasLeadingLineNames = !needClosingLineNames;
1118
+ needClosingLineNames = !needClosingLineNames;
1119
+ }
1120
+ else if (!varParsingMode) {
1121
+ curLine.push(curNode);
1122
+ }
1123
+ }
1124
+ }
1125
+ const valueNodes = ASTUtils.siblings(ASTUtils.declValue(node));
1126
+ if (valueNodes.length === 0) {
1127
+ return null;
1128
+ }
1129
+ parseNodes(valueNodes);
1130
+ lines.push(curLine);
1131
+ const valueText = matching.ast.textRange(valueNodes[0], valueNodes[valueNodes.length - 1]);
1132
+ return new GridTemplateMatch(valueText, node, lines.filter(line => line.length > 0));
1133
+ }
1134
+ }
1135
+ export class AnchorFunctionMatch {
1136
+ text;
1137
+ node;
1138
+ functionName;
1139
+ constructor(text, node, functionName) {
1140
+ this.text = text;
1141
+ this.node = node;
1142
+ this.functionName = functionName;
1143
+ }
1144
+ }
1145
+ // clang-format off
1146
+ export class AnchorFunctionMatcher extends matcherBase(AnchorFunctionMatch) {
1147
+ // clang-format on
1148
+ anchorFunction(node, matching) {
1149
+ if (node.name !== 'CallExpression') {
1150
+ return null;
1151
+ }
1152
+ const calleeText = matching.ast.text(node.getChild('Callee'));
1153
+ if (calleeText === 'anchor' || calleeText === 'anchor-size') {
1154
+ return calleeText;
1155
+ }
1156
+ return null;
1157
+ }
1158
+ matches(node, matching) {
1159
+ if (node.name === 'VariableName') {
1160
+ // Double-dashed anchor reference to be rendered with a link to its matching anchor.
1161
+ let parent = node.parent;
1162
+ if (!parent || parent.name !== 'ArgList') {
1163
+ return null;
1164
+ }
1165
+ parent = parent.parent;
1166
+ if (!parent || !this.anchorFunction(parent, matching)) {
1167
+ return null;
1168
+ }
1169
+ return new AnchorFunctionMatch(matching.ast.text(node), node, null);
1170
+ }
1171
+ const calleeText = this.anchorFunction(node, matching);
1172
+ if (!calleeText) {
1173
+ return null;
1174
+ }
1175
+ // Match if the anchor/anchor-size function implicitly references an anchor.
1176
+ const args = ASTUtils.children(node.getChild('ArgList'));
1177
+ if (calleeText === 'anchor' && args.length <= 2) {
1178
+ return null;
1179
+ }
1180
+ if (args.find(arg => arg.name === 'VariableName')) {
1181
+ // We have an explicit anchor reference, no need to render swatch.
1182
+ return null;
1183
+ }
1184
+ return new AnchorFunctionMatch(matching.ast.text(node), node, calleeText);
1185
+ }
1186
+ }
1187
+ // For linking `position-anchor: --anchor-name`.
1188
+ export class PositionAnchorMatch {
1189
+ text;
1190
+ matching;
1191
+ node;
1192
+ constructor(text, matching, node) {
1193
+ this.text = text;
1194
+ this.matching = matching;
1195
+ this.node = node;
1196
+ }
1197
+ }
1198
+ // clang-format off
1199
+ export class PositionAnchorMatcher extends matcherBase(PositionAnchorMatch) {
1200
+ // clang-format on
1201
+ accepts(propertyName) {
1202
+ return propertyName === 'position-anchor';
1203
+ }
1204
+ matches(node, matching) {
1205
+ if (node.name !== 'VariableName') {
1206
+ return null;
1207
+ }
1208
+ const dashedIdentifier = matching.ast.text(node);
1209
+ return new PositionAnchorMatch(dashedIdentifier, matching, node);
1210
+ }
1211
+ }
1212
+ export class CSSWideKeywordMatch {
1213
+ text;
1214
+ node;
1215
+ property;
1216
+ matchedStyles;
1217
+ constructor(text, node, property, matchedStyles) {
1218
+ this.text = text;
1219
+ this.node = node;
1220
+ this.property = property;
1221
+ this.matchedStyles = matchedStyles;
1222
+ }
1223
+ resolveProperty() {
1224
+ return this.matchedStyles.resolveGlobalKeyword(this.property, this.text);
1225
+ }
1226
+ computedText() {
1227
+ return this.resolveProperty()?.value ?? null;
1228
+ }
1229
+ }
1230
+ // clang-format off
1231
+ export class CSSWideKeywordMatcher extends matcherBase(CSSWideKeywordMatch) {
1232
+ property;
1233
+ matchedStyles;
1234
+ // clang-format on
1235
+ constructor(property, matchedStyles) {
1236
+ super();
1237
+ this.property = property;
1238
+ this.matchedStyles = matchedStyles;
1239
+ }
1240
+ matches(node, matching) {
1241
+ const parentNode = node.parent;
1242
+ if (node.name !== 'ValueName' || parentNode?.name !== 'Declaration') {
1243
+ return null;
1244
+ }
1245
+ if (Array.from(ASTUtils.stripComments(ASTUtils.siblings(ASTUtils.declValue(parentNode))))
1246
+ .some(child => !ASTUtils.equals(child, node))) {
1247
+ return null;
1248
+ }
1249
+ const text = matching.ast.text(node);
1250
+ if (!CSSMetadata.isCSSWideKeyword(text)) {
1251
+ return null;
1252
+ }
1253
+ return new CSSWideKeywordMatch(text, node, this.property, this.matchedStyles);
1254
+ }
1255
+ }
1256
+ export class PositionTryMatch {
1257
+ text;
1258
+ node;
1259
+ preamble;
1260
+ fallbacks;
1261
+ constructor(text, node, preamble, fallbacks) {
1262
+ this.text = text;
1263
+ this.node = node;
1264
+ this.preamble = preamble;
1265
+ this.fallbacks = fallbacks;
1266
+ }
1267
+ }
1268
+ // clang-format off
1269
+ export class PositionTryMatcher extends matcherBase(PositionTryMatch) {
1270
+ // clang-format on
1271
+ accepts(propertyName) {
1272
+ return propertyName === "position-try" /* LinkableNameProperties.POSITION_TRY */ ||
1273
+ propertyName === "position-try-fallbacks" /* LinkableNameProperties.POSITION_TRY_FALLBACKS */;
1274
+ }
1275
+ matches(node, matching) {
1276
+ if (node.name !== 'Declaration') {
1277
+ return null;
1278
+ }
1279
+ let preamble = [];
1280
+ const valueNodes = ASTUtils.siblings(ASTUtils.declValue(node));
1281
+ const fallbacks = ASTUtils.split(valueNodes);
1282
+ if (matching.ast.propertyName === "position-try" /* LinkableNameProperties.POSITION_TRY */) {
1283
+ for (const [i, n] of fallbacks[0].entries()) {
1284
+ const computedText = matching.getComputedText(n);
1285
+ if (CSSMetadata.isCSSWideKeyword(computedText)) {
1286
+ return null;
1287
+ }
1288
+ if (CSSMetadata.isPositionTryOrderKeyword(computedText)) {
1289
+ preamble = fallbacks[0].splice(0, i + 1);
1290
+ break;
1291
+ }
1292
+ }
1293
+ }
1294
+ const valueText = matching.ast.textRange(valueNodes[0], valueNodes[valueNodes.length - 1]);
1295
+ return new PositionTryMatch(valueText, node, preamble, fallbacks);
1296
+ }
1297
+ }
1298
+ export class EnvFunctionMatch {
1299
+ text;
1300
+ node;
1301
+ varName;
1302
+ value;
1303
+ varNameIsValid;
1304
+ constructor(text, node, varName, value, varNameIsValid) {
1305
+ this.text = text;
1306
+ this.node = node;
1307
+ this.varName = varName;
1308
+ this.value = value;
1309
+ this.varNameIsValid = varNameIsValid;
1310
+ }
1311
+ computedText() {
1312
+ return this.value;
1313
+ }
1314
+ }
1315
+ // clang-format off
1316
+ export class EnvFunctionMatcher extends matcherBase(EnvFunctionMatch) {
1317
+ matchedStyles;
1318
+ // clang-format on
1319
+ constructor(matchedStyles) {
1320
+ super();
1321
+ this.matchedStyles = matchedStyles;
1322
+ }
1323
+ matches(node, matching) {
1324
+ if (node.name !== 'CallExpression' || matching.ast.text(node.getChild('Callee')) !== 'env') {
1325
+ return null;
1326
+ }
1327
+ const [valueNodes, ...fallbackNodes] = ASTUtils.callArgs(node);
1328
+ if (!valueNodes?.length) {
1329
+ return null;
1330
+ }
1331
+ const fallbackValue = fallbackNodes.length > 0 ? matching.getComputedTextRange(...ASTUtils.range(fallbackNodes.flat())) : undefined;
1332
+ const varName = matching.getComputedTextRange(...ASTUtils.range(valueNodes)).trim();
1333
+ const value = this.matchedStyles.environmentVariable(varName);
1334
+ return new EnvFunctionMatch(matching.ast.text(node), node, varName, value ?? fallbackValue ?? null, Boolean(value));
1335
+ }
1336
+ }