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