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