nudge-ui 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -0
- package/bin/nudge-ui.mjs +7 -0
- package/dist/LICENSE +21 -0
- package/dist/client.mjs +261 -0
- package/dist/compiler/ast.d.ts +18 -0
- package/dist/compiler/ast.js +75 -0
- package/dist/compiler/componentContractTypes.d.ts +19 -0
- package/dist/compiler/componentContractTypes.js +1 -0
- package/dist/compiler/componentContracts.d.ts +2 -0
- package/dist/compiler/componentContracts.js +260 -0
- package/dist/compiler/componentInstrumentation.d.ts +32 -0
- package/dist/compiler/componentInstrumentation.js +140 -0
- package/dist/compiler/componentPolicyResolution.d.ts +71 -0
- package/dist/compiler/componentPolicyResolution.js +388 -0
- package/dist/compiler/index.d.ts +9 -0
- package/dist/compiler/index.js +9 -0
- package/dist/compiler/packageComponentContracts.d.ts +32 -0
- package/dist/compiler/packageComponentContracts.js +308 -0
- package/dist/compiler/reactComponentProtocols.d.ts +145 -0
- package/dist/compiler/reactComponentProtocols.js +47 -0
- package/dist/compiler/reactIdentity.d.ts +15 -0
- package/dist/compiler/reactIdentity.js +339 -0
- package/dist/compiler/sourcePaths.d.ts +12 -0
- package/dist/compiler/sourcePaths.js +27 -0
- package/dist/css/dialects/index.d.ts +62 -0
- package/dist/css/dialects/index.js +103 -0
- package/dist/css/dialects/tailwind.d.ts +46 -0
- package/dist/css/dialects/tailwind.js +119 -0
- package/dist/css/dialects/vanillaExtract.d.ts +20 -0
- package/dist/css/dialects/vanillaExtract.js +32 -0
- package/dist/css/index.d.ts +10 -0
- package/dist/css/index.js +10 -0
- package/dist/css/model/index.d.ts +190 -0
- package/dist/css/model/index.js +10 -0
- package/dist/css/token-inventory/index.d.ts +26 -0
- package/dist/css/token-inventory/index.js +24 -0
- package/dist/css/token-inventory/inventory.d.ts +8 -0
- package/dist/css/token-inventory/inventory.js +421 -0
- package/dist/css/token-inventory/parseStylesheet.d.ts +16 -0
- package/dist/css/token-inventory/parseStylesheet.js +155 -0
- package/dist/css/token-inventory/policy.d.ts +47 -0
- package/dist/css/token-inventory/policy.js +50 -0
- package/dist/css/token-inventory/types.d.ts +97 -0
- package/dist/css/token-inventory/types.js +1 -0
- package/dist/css/value-semantics/borderSemantics.d.ts +28 -0
- package/dist/css/value-semantics/borderSemantics.js +91 -0
- package/dist/css/value-semantics/boxSemantics.d.ts +37 -0
- package/dist/css/value-semantics/boxSemantics.js +71 -0
- package/dist/css/value-semantics/colorSemantics.d.ts +99 -0
- package/dist/css/value-semantics/colorSemantics.js +526 -0
- package/dist/css/value-semantics/cssSyntax.d.ts +19 -0
- package/dist/css/value-semantics/cssSyntax.js +111 -0
- package/dist/css/value-semantics/fontSemantics.d.ts +35 -0
- package/dist/css/value-semantics/fontSemantics.js +131 -0
- package/dist/css/value-semantics/index.d.ts +20 -0
- package/dist/css/value-semantics/index.js +15 -0
- package/dist/css/value-semantics/propertyPolicy.d.ts +118 -0
- package/dist/css/value-semantics/propertyPolicy.js +356 -0
- package/dist/css/value-semantics/stringMaps.d.ts +2 -0
- package/dist/css/value-semantics/stringMaps.js +1 -0
- package/dist/css/value-semantics/structuredValues.d.ts +64 -0
- package/dist/css/value-semantics/structuredValues.js +250 -0
- package/dist/css/value-semantics/tokenInterpretation.d.ts +90 -0
- package/dist/css/value-semantics/tokenInterpretation.js +193 -0
- package/dist/css/virtual-design-tokens.d.ts +17 -0
- package/dist/hosts/astro/astroRuntimeConfig.d.ts +12 -0
- package/dist/hosts/astro/astroRuntimeConfig.js +26 -0
- package/dist/hosts/astro/clientAsset.d.ts +12 -0
- package/dist/hosts/astro/clientAsset.js +51 -0
- package/dist/hosts/astro/clientTransport.d.ts +3 -0
- package/dist/hosts/astro/clientTransport.js +57 -0
- package/dist/hosts/astro/index.d.ts +3 -0
- package/dist/hosts/astro/index.js +2 -0
- package/dist/hosts/astro/integration.d.ts +35 -0
- package/dist/hosts/astro/integration.js +96 -0
- package/dist/hosts/astro/middleware.d.ts +13 -0
- package/dist/hosts/astro/middleware.js +22 -0
- package/dist/hosts/astro/projectContext.d.ts +11 -0
- package/dist/hosts/astro/projectContext.js +34 -0
- package/dist/hosts/astro/responseInstrumentation.d.ts +41 -0
- package/dist/hosts/astro/responseInstrumentation.js +80 -0
- package/dist/hosts/next/index.d.ts +4 -0
- package/dist/hosts/next/index.js +7 -0
- package/dist/hosts/next/loader.d.ts +66 -0
- package/dist/hosts/next/loader.js +346 -0
- package/dist/hosts/next/loaders/identity-loader.cjs +228257 -0
- package/dist/hosts/next/loaders/loader-plugin.cjs +228257 -0
- package/dist/hosts/next/manifest.d.ts +38 -0
- package/dist/hosts/next/manifest.js +30 -0
- package/dist/hosts/next/mount.d.ts +12 -0
- package/dist/hosts/next/mount.js +23 -0
- package/dist/hosts/next/repositoryScope.d.ts +20 -0
- package/dist/hosts/next/repositoryScope.js +33 -0
- package/dist/hosts/next/sidecar.d.ts +27 -0
- package/dist/hosts/next/sidecar.js +526 -0
- package/dist/hosts/next/wrapper.d.ts +67 -0
- package/dist/hosts/next/wrapper.js +310 -0
- package/dist/hosts/static/cli.d.ts +12 -0
- package/dist/hosts/static/cli.js +77 -0
- package/dist/hosts/static/html/bootstrap.d.ts +27 -0
- package/dist/hosts/static/html/bootstrap.js +93 -0
- package/dist/hosts/static/index.d.ts +4 -0
- package/dist/hosts/static/index.js +4 -0
- package/dist/hosts/static/manifest.d.ts +18 -0
- package/dist/hosts/static/manifest.js +51 -0
- package/dist/hosts/static/server.d.ts +72 -0
- package/dist/hosts/static/server.js +554 -0
- package/dist/hosts/vite/index.d.ts +20 -0
- package/dist/hosts/vite/index.js +48 -0
- package/dist/hosts/vite/react.d.ts +67 -0
- package/dist/hosts/vite/react.js +231 -0
- package/dist/hosts/vite/tokens/activeStylesheets.d.ts +28 -0
- package/dist/hosts/vite/tokens/activeStylesheets.js +70 -0
- package/dist/hosts/vite/tokens/fileMap.d.ts +2 -0
- package/dist/hosts/vite/tokens/fileMap.js +1 -0
- package/dist/hosts/vite/tokens/viteStylesheetArtifacts.d.ts +46 -0
- package/dist/hosts/vite/tokens/viteStylesheetArtifacts.js +104 -0
- package/dist/hosts/vite/virtual/design-tokens.d.ts +9 -0
- package/dist/hosts/vite/virtual/design-tokens.js +7 -0
- package/dist/hosts/vite/virtual-design-tokens.d.ts +1 -0
- package/dist/hosts/vite/vite.d.ts +62 -0
- package/dist/hosts/vite/vite.js +854 -0
- package/dist/html/dom.d.ts +13 -0
- package/dist/html/dom.js +46 -0
- package/dist/html/identity.d.ts +40 -0
- package/dist/html/identity.js +196 -0
- package/dist/html/insertions.d.ts +26 -0
- package/dist/html/insertions.js +59 -0
- package/dist/inspector/agent/McpConnectionDialog.d.ts +26 -0
- package/dist/inspector/agent/McpConnectionDialog.js +135 -0
- package/dist/inspector/agent/client.d.ts +98 -0
- package/dist/inspector/agent/client.js +728 -0
- package/dist/inspector/agent/connectionStatus.d.ts +13 -0
- package/dist/inspector/agent/connectionStatus.js +35 -0
- package/dist/inspector/agent/httpTransport.d.ts +21 -0
- package/dist/inspector/agent/httpTransport.js +347 -0
- package/dist/inspector/agent/protocol.d.ts +95 -0
- package/dist/inspector/agent/protocol.js +9 -0
- package/dist/inspector/agent/verification.d.ts +39 -0
- package/dist/inspector/agent/verification.js +207 -0
- package/dist/inspector/canvas/CanvasCard.d.ts +10 -0
- package/dist/inspector/canvas/CanvasCard.js +275 -0
- package/dist/inspector/canvas/CanvasElementOverlay.d.ts +2 -0
- package/dist/inspector/canvas/CanvasElementOverlay.js +301 -0
- package/dist/inspector/canvas/CanvasWorkspace.d.ts +2 -0
- package/dist/inspector/canvas/CanvasWorkspace.js +301 -0
- package/dist/inspector/canvas/LockedWorkspaceNotice.d.ts +6 -0
- package/dist/inspector/canvas/LockedWorkspaceNotice.js +17 -0
- package/dist/inspector/canvas/StaleChangeIndicator.d.ts +7 -0
- package/dist/inspector/canvas/StaleChangeIndicator.js +43 -0
- package/dist/inspector/canvas/agentPresentation.d.ts +87 -0
- package/dist/inspector/canvas/agentPresentation.js +421 -0
- package/dist/inspector/canvas/canvasGestures.d.ts +12 -0
- package/dist/inspector/canvas/canvasGestures.js +21 -0
- package/dist/inspector/canvas/canvasStore.d.ts +108 -0
- package/dist/inspector/canvas/canvasStore.js +448 -0
- package/dist/inspector/canvas/frameProtocol.d.ts +231 -0
- package/dist/inspector/canvas/frameProtocol.js +165 -0
- package/dist/inspector/canvas/linkEligibility.d.ts +8 -0
- package/dist/inspector/canvas/linkEligibility.js +68 -0
- package/dist/inspector/canvas/measurementProjection.d.ts +8 -0
- package/dist/inspector/canvas/measurementProjection.js +16 -0
- package/dist/inspector/canvas/normalizeUrl.d.ts +7 -0
- package/dist/inspector/canvas/normalizeUrl.js +27 -0
- package/dist/inspector/canvas/projection.d.ts +41 -0
- package/dist/inspector/canvas/projection.js +232 -0
- package/dist/inspector/canvas/rendererBootstrap.d.ts +4 -0
- package/dist/inspector/canvas/rendererBootstrap.js +410 -0
- package/dist/inspector/canvas/rendererCidIndex.d.ts +11 -0
- package/dist/inspector/canvas/rendererCidIndex.js +21 -0
- package/dist/inspector/canvas/rendererElementSelector.d.ts +2 -0
- package/dist/inspector/canvas/rendererElementSelector.js +378 -0
- package/dist/inspector/canvas/rendererSelectionProxy.d.ts +2 -0
- package/dist/inspector/canvas/rendererSelectionProxy.js +61 -0
- package/dist/inspector/canvas/rendererStylesheet.d.ts +16 -0
- package/dist/inspector/canvas/rendererStylesheet.js +221 -0
- package/dist/inspector/canvas/resizeHandleScale.d.ts +13 -0
- package/dist/inspector/canvas/resizeHandleScale.js +20 -0
- package/dist/inspector/canvas/roleDetection.d.ts +5 -0
- package/dist/inspector/canvas/roleDetection.js +21 -0
- package/dist/inspector/canvas/sessionStore.d.ts +71 -0
- package/dist/inspector/canvas/sessionStore.js +453 -0
- package/dist/inspector/canvas/staleChangeDetector.d.ts +11 -0
- package/dist/inspector/canvas/staleChangeDetector.js +217 -0
- package/dist/inspector/canvas/toolbarScale.d.ts +7 -0
- package/dist/inspector/canvas/toolbarScale.js +11 -0
- package/dist/inspector/canvas/workspaceLease.d.ts +26 -0
- package/dist/inspector/canvas/workspaceLease.js +214 -0
- package/dist/inspector/changes/changesLog.d.ts +46 -0
- package/dist/inspector/changes/changesLog.js +209 -0
- package/dist/inspector/changes/codecs.d.ts +98 -0
- package/dist/inspector/changes/codecs.js +389 -0
- package/dist/inspector/changes/editModel.d.ts +74 -0
- package/dist/inspector/changes/editModel.js +120 -0
- package/dist/inspector/changes/managedStyleProjection.d.ts +6 -0
- package/dist/inspector/changes/managedStyleProjection.js +109 -0
- package/dist/inspector/changes/model.d.ts +13 -0
- package/dist/inspector/changes/model.js +163 -0
- package/dist/inspector/changes/presentation.d.ts +14 -0
- package/dist/inspector/changes/presentation.js +81 -0
- package/dist/inspector/changes/previewDiagnostics.d.ts +39 -0
- package/dist/inspector/changes/previewDiagnostics.js +172 -0
- package/dist/inspector/changes/structuralTypes.d.ts +35 -0
- package/dist/inspector/changes/structuralTypes.js +1 -0
- package/dist/inspector/changes/types.d.ts +76 -0
- package/dist/inspector/changes/types.js +16 -0
- package/dist/inspector/changes/workspaceChanges.d.ts +43 -0
- package/dist/inspector/changes/workspaceChanges.js +239 -0
- package/dist/inspector/clientManifest.d.ts +24 -0
- package/dist/inspector/clientManifest.js +69 -0
- package/dist/inspector/componentSemantics/ComponentPropsSection.d.ts +5 -0
- package/dist/inspector/componentSemantics/ComponentPropsSection.js +44 -0
- package/dist/inspector/componentSemantics/adapterRegistry.d.ts +11 -0
- package/dist/inspector/componentSemantics/adapterRegistry.js +75 -0
- package/dist/inspector/componentSemantics/boundaries.d.ts +2 -0
- package/dist/inspector/componentSemantics/boundaries.js +10 -0
- package/dist/inspector/componentSemantics/changeAction.d.ts +3 -0
- package/dist/inspector/componentSemantics/changeAction.js +6 -0
- package/dist/inspector/componentSemantics/changeModel.d.ts +8 -0
- package/dist/inspector/componentSemantics/changeModel.js +60 -0
- package/dist/inspector/componentSemantics/index.d.ts +4 -0
- package/dist/inspector/componentSemantics/index.js +2 -0
- package/dist/inspector/componentSemantics/reactRuntime.d.ts +10 -0
- package/dist/inspector/componentSemantics/reactRuntime.js +186 -0
- package/dist/inspector/componentSemantics/runtimeBridge.d.ts +25 -0
- package/dist/inspector/componentSemantics/runtimeBridge.js +161 -0
- package/dist/inspector/componentSemantics/runtimeTypes.d.ts +2 -0
- package/dist/inspector/componentSemantics/runtimeTypes.js +1 -0
- package/dist/inspector/componentSemantics/textBinding.d.ts +69 -0
- package/dist/inspector/componentSemantics/textBinding.js +514 -0
- package/dist/inspector/componentSemantics/types.d.ts +96 -0
- package/dist/inspector/componentSemantics/types.js +5 -0
- package/dist/inspector/conformance/borderCases.d.ts +7 -0
- package/dist/inspector/conformance/borderCases.js +428 -0
- package/dist/inspector/conformance/colorCases.d.ts +8 -0
- package/dist/inspector/conformance/colorCases.js +470 -0
- package/dist/inspector/conformance/fixture.d.ts +68 -0
- package/dist/inspector/conformance/fixture.js +153 -0
- package/dist/inspector/conformance/projection.d.ts +2 -0
- package/dist/inspector/conformance/projection.js +3 -0
- package/dist/inspector/conformance/spacingCases.d.ts +6 -0
- package/dist/inspector/conformance/spacingCases.js +417 -0
- package/dist/inspector/conformance/typographyCases.d.ts +7 -0
- package/dist/inspector/conformance/typographyCases.js +174 -0
- package/dist/inspector/editScope.d.ts +4 -0
- package/dist/inspector/editScope.js +5 -0
- package/dist/inspector/index.d.ts +20 -0
- package/dist/inspector/index.js +236 -0
- package/dist/inspector/inline-text/inlineTextEditor.d.ts +74 -0
- package/dist/inspector/inline-text/inlineTextEditor.js +1207 -0
- package/dist/inspector/inline-text/inlineTextLifecycle.d.ts +2 -0
- package/dist/inspector/inline-text/inlineTextLifecycle.js +17 -0
- package/dist/inspector/inline-text/textChangeBoundary.d.ts +6 -0
- package/dist/inspector/inline-text/textChangeBoundary.js +1 -0
- package/dist/inspector/inspection/bridge.d.ts +72 -0
- package/dist/inspector/inspection/bridge.js +134 -0
- package/dist/inspector/inspection/browserCssInspection.d.ts +74 -0
- package/dist/inspector/inspection/browserCssInspection.js +317 -0
- package/dist/inspector/inspection/browserCssInspectionRegistry.d.ts +12 -0
- package/dist/inspector/inspection/browserCssInspectionRegistry.js +66 -0
- package/dist/inspector/inspection/selectionProperty.d.ts +32 -0
- package/dist/inspector/inspection/selectionProperty.js +33 -0
- package/dist/inspector/inspection/useBrowserCssInspection.d.ts +20 -0
- package/dist/inspector/inspection/useBrowserCssInspection.js +159 -0
- package/dist/inspector/overlay/DropGuideOverlay.d.ts +17 -0
- package/dist/inspector/overlay/DropGuideOverlay.js +17 -0
- package/dist/inspector/overlay/InspectorOverlay.d.ts +5 -0
- package/dist/inspector/overlay/InspectorOverlay.js +328 -0
- package/dist/inspector/overlay/MeasurementGuideOverlay.d.ts +19 -0
- package/dist/inspector/overlay/MeasurementGuideOverlay.js +40 -0
- package/dist/inspector/overlay/clickPolicy.d.ts +7 -0
- package/dist/inspector/overlay/clickPolicy.js +13 -0
- package/dist/inspector/overlay/dropGuide.d.ts +22 -0
- package/dist/inspector/overlay/dropGuide.js +48 -0
- package/dist/inspector/overlay/elementSelector.d.ts +1 -0
- package/dist/inspector/overlay/elementSelector.js +100 -0
- package/dist/inspector/overlay/frameThrottle.d.ts +10 -0
- package/dist/inspector/overlay/frameThrottle.js +38 -0
- package/dist/inspector/overlay/interactionStyles.d.ts +3 -0
- package/dist/inspector/overlay/interactionStyles.js +70 -0
- package/dist/inspector/overlay/measurementGeometry.d.ts +25 -0
- package/dist/inspector/overlay/measurementGeometry.js +104 -0
- package/dist/inspector/overlay/overlayGeometry.d.ts +40 -0
- package/dist/inspector/overlay/overlayGeometry.js +59 -0
- package/dist/inspector/overlay/selectedGeometry.d.ts +7 -0
- package/dist/inspector/overlay/selectedGeometry.js +51 -0
- package/dist/inspector/overlay/structuralGestures.d.ts +28 -0
- package/dist/inspector/overlay/structuralGestures.js +180 -0
- package/dist/inspector/projection/cssEscapes.d.ts +3 -0
- package/dist/inspector/projection/cssEscapes.js +20 -0
- package/dist/inspector/projection/managedStylesheet.d.ts +33 -0
- package/dist/inspector/projection/managedStylesheet.js +240 -0
- package/dist/inspector/projection/renderedInstance.d.ts +56 -0
- package/dist/inspector/projection/renderedInstance.js +306 -0
- package/dist/inspector/projection/structuralProjection.d.ts +93 -0
- package/dist/inspector/projection/structuralProjection.js +560 -0
- package/dist/inspector/projection/structuralProjectionBoundary.d.ts +5 -0
- package/dist/inspector/projection/structuralProjectionBoundary.js +65 -0
- package/dist/inspector/projection/textProjection.d.ts +53 -0
- package/dist/inspector/projection/textProjection.js +705 -0
- package/dist/inspector/projection/workspaceProjection.d.ts +43 -0
- package/dist/inspector/projection/workspaceProjection.js +58 -0
- package/dist/inspector/prompt/PromptSettingsDialog.d.ts +15 -0
- package/dist/inspector/prompt/PromptSettingsDialog.js +17 -0
- package/dist/inspector/prompt/clipboardHandoff.d.ts +34 -0
- package/dist/inspector/prompt/clipboardHandoff.js +212 -0
- package/dist/inspector/prompt/copyToClipboard.d.ts +1 -0
- package/dist/inspector/prompt/copyToClipboard.js +34 -0
- package/dist/inspector/prompt/detectFramework.d.ts +6 -0
- package/dist/inspector/prompt/detectFramework.js +4 -0
- package/dist/inspector/prompt/generatePrompt.d.ts +7 -0
- package/dist/inspector/prompt/generatePrompt.js +391 -0
- package/dist/inspector/prompt/promptSettings.d.ts +8 -0
- package/dist/inspector/prompt/promptSettings.js +28 -0
- package/dist/inspector/runtime/devFlag.d.ts +28 -0
- package/dist/inspector/runtime/devFlag.js +50 -0
- package/dist/inspector/runtime/documentStylesheetOrder.d.ts +19 -0
- package/dist/inspector/runtime/documentStylesheetOrder.js +89 -0
- package/dist/inspector/runtime/domRealm.d.ts +4 -0
- package/dist/inspector/runtime/domRealm.js +11 -0
- package/dist/inspector/runtime/runtimeConfig.d.ts +119 -0
- package/dist/inspector/runtime/runtimeConfig.js +276 -0
- package/dist/inspector/runtime/staticHtmlRuntimeIdentity.d.ts +32 -0
- package/dist/inspector/runtime/staticHtmlRuntimeIdentity.js +149 -0
- package/dist/inspector/runtime/useRuntimeConfig.d.ts +10 -0
- package/dist/inspector/runtime/useRuntimeConfig.js +13 -0
- package/dist/inspector/selection/editScope.d.ts +32 -0
- package/dist/inspector/selection/editScope.js +140 -0
- package/dist/inspector/selection/editTarget.d.ts +8 -0
- package/dist/inspector/selection/editTarget.js +11 -0
- package/dist/inspector/selection/hierarchy.d.ts +7 -0
- package/dist/inspector/selection/hierarchy.js +42 -0
- package/dist/inspector/selection/resolveSelection.d.ts +10 -0
- package/dist/inspector/selection/resolveSelection.js +60 -0
- package/dist/inspector/selection/selectionStore.d.ts +41 -0
- package/dist/inspector/selection/selectionStore.js +262 -0
- package/dist/inspector/selection/selectionTarget.d.ts +5 -0
- package/dist/inspector/selection/selectionTarget.js +50 -0
- package/dist/inspector/selection/sourceSite.d.ts +2 -0
- package/dist/inspector/selection/sourceSite.js +12 -0
- package/dist/inspector/selection/styleSelection.d.ts +22 -0
- package/dist/inspector/selection/styleSelection.js +104 -0
- package/dist/inspector/session/index.d.ts +3 -0
- package/dist/inspector/session/index.js +2 -0
- package/dist/inspector/session/lifecycle.d.ts +22 -0
- package/dist/inspector/session/lifecycle.js +63 -0
- package/dist/inspector/session/sessionContext.d.ts +21 -0
- package/dist/inspector/session/sessionContext.js +28 -0
- package/dist/inspector/session/sessionFactory.d.ts +29 -0
- package/dist/inspector/session/sessionFactory.js +73 -0
- package/dist/inspector/settings/SettingsDialog.d.ts +12 -0
- package/dist/inspector/settings/SettingsDialog.js +46 -0
- package/dist/inspector/shell/AppShell.d.ts +2 -0
- package/dist/inspector/shell/AppShell.js +9 -0
- package/dist/inspector/shell/ChangesLog.d.ts +6 -0
- package/dist/inspector/shell/ChangesLog.js +92 -0
- package/dist/inspector/shell/CopyPromptButton.d.ts +9 -0
- package/dist/inspector/shell/CopyPromptButton.js +159 -0
- package/dist/inspector/shell/DomNavigation.d.ts +8 -0
- package/dist/inspector/shell/DomNavigation.js +30 -0
- package/dist/inspector/shell/EmptyState.d.ts +2 -0
- package/dist/inspector/shell/EmptyState.js +15 -0
- package/dist/inspector/shell/InspectorShell.d.ts +11 -0
- package/dist/inspector/shell/InspectorShell.js +268 -0
- package/dist/inspector/shell/openStore.d.ts +6 -0
- package/dist/inspector/shell/openStore.js +29 -0
- package/dist/inspector/shell/panelLayout.d.ts +2 -0
- package/dist/inspector/shell/panelLayout.js +29 -0
- package/dist/inspector/shell/shortcuts.d.ts +3 -0
- package/dist/inspector/shell/shortcuts.js +25 -0
- package/dist/inspector/shell/stateValue.d.ts +3 -0
- package/dist/inspector/shell/stateValue.js +34 -0
- package/dist/inspector/shell/styleState.d.ts +7 -0
- package/dist/inspector/shell/styleState.js +13 -0
- package/dist/inspector/spacing/projection.d.ts +43 -0
- package/dist/inspector/spacing/projection.js +136 -0
- package/dist/inspector/styleEditors/AppearanceSection.d.ts +13 -0
- package/dist/inspector/styleEditors/AppearanceSection.js +6 -0
- package/dist/inspector/styleEditors/AspectRatioField.d.ts +17 -0
- package/dist/inspector/styleEditors/AspectRatioField.js +10 -0
- package/dist/inspector/styleEditors/BorderEditor.d.ts +13 -0
- package/dist/inspector/styleEditors/BorderEditor.js +295 -0
- package/dist/inspector/styleEditors/BorderRadiusEditor.d.ts +14 -0
- package/dist/inspector/styleEditors/BorderRadiusEditor.js +108 -0
- package/dist/inspector/styleEditors/BoxShadowEditor.d.ts +13 -0
- package/dist/inspector/styleEditors/BoxShadowEditor.js +13 -0
- package/dist/inspector/styleEditors/ColorPicker.d.ts +15 -0
- package/dist/inspector/styleEditors/ColorPicker.js +73 -0
- package/dist/inspector/styleEditors/GapField.d.ts +17 -0
- package/dist/inspector/styleEditors/GapField.js +12 -0
- package/dist/inspector/styleEditors/GridChildSection.d.ts +14 -0
- package/dist/inspector/styleEditors/GridChildSection.js +91 -0
- package/dist/inspector/styleEditors/GridPicker.d.ts +13 -0
- package/dist/inspector/styleEditors/GridPicker.js +179 -0
- package/dist/inspector/styleEditors/GridSection.d.ts +17 -0
- package/dist/inspector/styleEditors/GridSection.js +27 -0
- package/dist/inspector/styleEditors/GridValueField.d.ts +17 -0
- package/dist/inspector/styleEditors/GridValueField.js +70 -0
- package/dist/inspector/styleEditors/InsetSection.d.ts +15 -0
- package/dist/inspector/styleEditors/InsetSection.js +15 -0
- package/dist/inspector/styleEditors/LayoutBlockedIndicator.d.ts +6 -0
- package/dist/inspector/styleEditors/LayoutBlockedIndicator.js +6 -0
- package/dist/inspector/styleEditors/LayoutComboField.d.ts +18 -0
- package/dist/inspector/styleEditors/LayoutComboField.js +138 -0
- package/dist/inspector/styleEditors/LayoutDropdown.d.ts +14 -0
- package/dist/inspector/styleEditors/LayoutDropdown.js +34 -0
- package/dist/inspector/styleEditors/LayoutSection.d.ts +13 -0
- package/dist/inspector/styleEditors/LayoutSection.js +342 -0
- package/dist/inspector/styleEditors/OpacityEditor.d.ts +13 -0
- package/dist/inspector/styleEditors/OpacityEditor.js +34 -0
- package/dist/inspector/styleEditors/PositionInsets.d.ts +15 -0
- package/dist/inspector/styleEditors/PositionInsets.js +12 -0
- package/dist/inspector/styleEditors/SpacingBox.d.ts +29 -0
- package/dist/inspector/styleEditors/SpacingBox.js +189 -0
- package/dist/inspector/styleEditors/Typography.d.ts +13 -0
- package/dist/inspector/styleEditors/Typography.js +137 -0
- package/dist/inspector/styleEditors/completeCssValue.d.ts +8 -0
- package/dist/inspector/styleEditors/completeCssValue.js +34 -0
- package/dist/inspector/styleEditors/gridChildModel.d.ts +74 -0
- package/dist/inspector/styleEditors/gridChildModel.js +138 -0
- package/dist/inspector/styleEditors/layoutValue.d.ts +24 -0
- package/dist/inspector/styleEditors/layoutValue.js +103 -0
- package/dist/inspector/styleEditors/nudgeValue.d.ts +8 -0
- package/dist/inspector/styleEditors/nudgeValue.js +71 -0
- package/dist/inspector/styleEditors/rowLookup.d.ts +11 -0
- package/dist/inspector/styleEditors/rowLookup.js +13 -0
- package/dist/inspector/styleEditors/stringRecord.d.ts +4 -0
- package/dist/inspector/styleEditors/stringRecord.js +1 -0
- package/dist/inspector/styleEditors/valuePolicy.d.ts +20 -0
- package/dist/inspector/styleEditors/valuePolicy.js +82 -0
- package/dist/inspector/testing.d.ts +10 -0
- package/dist/inspector/testing.js +9 -0
- package/dist/inspector/tokens/TokenChip.d.ts +24 -0
- package/dist/inspector/tokens/TokenChip.js +23 -0
- package/dist/inspector/tokens/TokenDropdown.d.ts +13 -0
- package/dist/inspector/tokens/TokenDropdown.js +59 -0
- package/dist/inspector/tokens/TokenField.d.ts +68 -0
- package/dist/inspector/tokens/TokenField.js +485 -0
- package/dist/inspector/tokens/TokenLabel.d.ts +7 -0
- package/dist/inspector/tokens/TokenLabel.js +23 -0
- package/dist/inspector/tokens/TokensPanel.d.ts +5 -0
- package/dist/inspector/tokens/TokensPanel.js +47 -0
- package/dist/inspector/tokens/catalog.d.ts +51 -0
- package/dist/inspector/tokens/catalog.js +184 -0
- package/dist/inspector/tokens/editActions.d.ts +35 -0
- package/dist/inspector/tokens/editActions.js +164 -0
- package/dist/inspector/tokens/resolution/cascade.d.ts +14 -0
- package/dist/inspector/tokens/resolution/cascade.js +31 -0
- package/dist/inspector/tokens/resolution/cssomCollector.d.ts +43 -0
- package/dist/inspector/tokens/resolution/cssomCollector.js +528 -0
- package/dist/inspector/tokens/resolution/selectorSemantics.d.ts +12 -0
- package/dist/inspector/tokens/resolution/selectorSemantics.js +106 -0
- package/dist/inspector/tokens/resolution.d.ts +56 -0
- package/dist/inspector/tokens/resolution.js +1401 -0
- package/dist/inspector/tokens/tokenEdits.d.ts +3 -0
- package/dist/inspector/tokens/tokenEdits.js +22 -0
- package/dist/inspector/tokens/valueSemanticsAdapter.d.ts +6 -0
- package/dist/inspector/tokens/valueSemanticsAdapter.js +68 -0
- package/dist/inspector/ui/AtRuleContext.d.ts +18 -0
- package/dist/inspector/ui/AtRuleContext.js +54 -0
- package/dist/inspector/ui/Button.d.ts +9 -0
- package/dist/inspector/ui/Button.js +4 -0
- package/dist/inspector/ui/ColorSwatch.d.ts +7 -0
- package/dist/inspector/ui/ColorSwatch.js +6 -0
- package/dist/inspector/ui/ControlSurface.d.ts +14 -0
- package/dist/inspector/ui/ControlSurface.js +10 -0
- package/dist/inspector/ui/FieldRow.d.ts +14 -0
- package/dist/inspector/ui/FieldRow.js +15 -0
- package/dist/inspector/ui/IconButton.d.ts +14 -0
- package/dist/inspector/ui/IconButton.js +5 -0
- package/dist/inspector/ui/InspectorPopover.d.ts +17 -0
- package/dist/inspector/ui/InspectorPopover.js +13 -0
- package/dist/inspector/ui/PopoverListbox.d.ts +37 -0
- package/dist/inspector/ui/PopoverListbox.js +21 -0
- package/dist/inspector/ui/SegmentedControl.d.ts +24 -0
- package/dist/inspector/ui/SegmentedControl.js +16 -0
- package/dist/inspector/ui/Select.d.ts +25 -0
- package/dist/inspector/ui/Select.js +56 -0
- package/dist/inspector/ui/SideValuesField.d.ts +44 -0
- package/dist/inspector/ui/SideValuesField.js +76 -0
- package/dist/inspector/ui/StatusCallout.d.ts +9 -0
- package/dist/inspector/ui/StatusCallout.js +4 -0
- package/dist/inspector/ui/TextInput.d.ts +12 -0
- package/dist/inspector/ui/TextInput.js +5 -0
- package/dist/inspector/ui/ToggleButton.d.ts +11 -0
- package/dist/inspector/ui/ToggleButton.js +6 -0
- package/dist/inspector/ui/assets/grid.svg +14 -0
- package/dist/inspector/ui/css.d.ts +9 -0
- package/dist/inspector/ui/labels.d.ts +1 -0
- package/dist/inspector/ui/labels.js +7 -0
- package/dist/inspector/ui/styles.d.ts +1 -0
- package/dist/inspector/ui/styles.js +68 -0
- package/dist/inspector/virtual-modules.d.ts +7 -0
- package/dist/inspector/vite-env.d.ts +10 -0
- package/dist/internal/agent-protocol.d.ts +232 -0
- package/dist/internal/agent-protocol.js +237 -0
- package/dist/nudge-ui.mjs +15722 -0
- package/dist/project/files.d.ts +19 -0
- package/dist/project/files.js +226 -0
- package/dist/project/identity.d.ts +6 -0
- package/dist/project/identity.js +19 -0
- package/dist/project/pathPolicy.d.ts +8 -0
- package/dist/project/pathPolicy.js +12 -0
- package/dist/project/tokens.d.ts +36 -0
- package/dist/project/tokens.js +223 -0
- package/dist/transport/index.d.ts +8 -0
- package/dist/transport/index.js +8 -0
- package/dist/transport/routes.d.ts +13 -0
- package/dist/transport/routes.js +16 -0
- package/package.json +137 -0
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { basename, join, relative, resolve, sep, } from "node:path";
|
|
4
|
+
import { createTokenInventory, } from "../../css/token-inventory/index.js";
|
|
5
|
+
import { NUDGE_UI_CLIENT_PATH, NUDGE_UI_MANIFEST_PATH } from "../../transport/index.js";
|
|
6
|
+
import { discoverCssImportGraph, stripCssQuery } from "./tokens/activeStylesheets.js";
|
|
7
|
+
import { catalogSourcePath, createViteStylesheetArtifact, isHostApplicationSource, isPackageStylesheet, orderViteStylesheetGraph, } from "./tokens/viteStylesheetArtifacts.js";
|
|
8
|
+
import { interpretDialects } from "../../css/dialects/index.js";
|
|
9
|
+
import { detectStylingSystem, } from "../../inspector/clientManifest.js";
|
|
10
|
+
function isRecord(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
const VIRTUAL_TOKENS_ID = "virtual:design-tokens";
|
|
14
|
+
const RESOLVED_TOKENS_ID = "\0" + VIRTUAL_TOKENS_ID;
|
|
15
|
+
const VIRTUAL_INSPECTOR_ID = "virtual:nudge-ui-inspector";
|
|
16
|
+
const RESOLVED_INSPECTOR_ID = "\0" + VIRTUAL_INSPECTOR_ID;
|
|
17
|
+
const CSS_EXT = /\.css(?:$|[?#])/;
|
|
18
|
+
const CLIENT_PATH = NUDGE_UI_CLIENT_PATH;
|
|
19
|
+
const MANIFEST_PATH = NUDGE_UI_MANIFEST_PATH;
|
|
20
|
+
const packageRequire = createRequire(import.meta.url);
|
|
21
|
+
let inspectorClientPath;
|
|
22
|
+
const MOUNT_DIV = `<div id="nudge-ui-root"></div>`;
|
|
23
|
+
const DEBUG_MOUNT_DIV = `<div id="nudge-ui-root" data-nudge-ui-debug="true"></div>`;
|
|
24
|
+
const INSPECTOR_SCRIPT = `<script type="module" src="${CLIENT_PATH}" data-nudge-ui-client data-nudge-ui-manifest="${MANIFEST_PATH}"></script>`;
|
|
25
|
+
const LEGACY_INSPECTOR_SCRIPT = `<script type="module" src="/@id/__x00__virtual:nudge-ui-inspector"></script>`;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts the stylesheet string Vite embeds in dev CSS-module JS wrappers
|
|
28
|
+
* (`const __vite__css = "…"`). Returns null for anything that is not such a
|
|
29
|
+
* wrapper, so callers can feed the original code unchanged.
|
|
30
|
+
*/
|
|
31
|
+
export function extractViteModuleCss(code) {
|
|
32
|
+
const match = /(?:^|;)\s*(?:const|let|var)\s+__vite__css\s*=\s*("(?:[^"\\]|\\.)*")/m.exec(code);
|
|
33
|
+
if (!match)
|
|
34
|
+
return null;
|
|
35
|
+
try {
|
|
36
|
+
// SAFETY: match[1] is the quoted string literal captured by the regex above, and JSON.parse is wrapped in try/catch.
|
|
37
|
+
const value = JSON.parse(match[1]);
|
|
38
|
+
return typeof value === "string" ? value : null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function readInspectorClient() {
|
|
45
|
+
inspectorClientPath ??= packageRequire.resolve("nudge-ui/internal/client");
|
|
46
|
+
return readFileSync(inspectorClientPath);
|
|
47
|
+
}
|
|
48
|
+
function scanCssFiles(rootDir, files = [], dir = rootDir, ignoredDirectory) {
|
|
49
|
+
let entries;
|
|
50
|
+
try {
|
|
51
|
+
entries = readdirSync(dir);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return files;
|
|
55
|
+
}
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (entry === "node_modules"
|
|
58
|
+
|| entry === ".git"
|
|
59
|
+
|| entry === "build"
|
|
60
|
+
|| entry.startsWith("dist"))
|
|
61
|
+
continue;
|
|
62
|
+
const full = join(dir, entry);
|
|
63
|
+
try {
|
|
64
|
+
const st = statSync(full);
|
|
65
|
+
if (st.isDirectory()) {
|
|
66
|
+
if (ignoredDirectory && resolve(full) === ignoredDirectory)
|
|
67
|
+
continue;
|
|
68
|
+
scanCssFiles(rootDir, files, full, ignoredDirectory);
|
|
69
|
+
}
|
|
70
|
+
else if (CSS_EXT.test(entry))
|
|
71
|
+
files.push(full);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// ignore unreadable entries
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return files;
|
|
78
|
+
}
|
|
79
|
+
export function transformIndexHtmlHtml(html, command, { debug = false, demoBuild = false, demo = false } = {}) {
|
|
80
|
+
if (command === "build" && !demoBuild)
|
|
81
|
+
return null;
|
|
82
|
+
const script = demo || demoBuild ? LEGACY_INSPECTOR_SCRIPT : INSPECTOR_SCRIPT;
|
|
83
|
+
const inject = `\n${debug ? DEBUG_MOUNT_DIV : MOUNT_DIV}\n${script}\n`;
|
|
84
|
+
if (html.includes("</body>")) {
|
|
85
|
+
return html.replace("</body>", `${inject}</body>`);
|
|
86
|
+
}
|
|
87
|
+
return html + inject;
|
|
88
|
+
}
|
|
89
|
+
function invalidateHmrModules(server, modules, timestamp) {
|
|
90
|
+
const invalidated = new Set();
|
|
91
|
+
for (const module of modules) {
|
|
92
|
+
server.moduleGraph.invalidateModule(module, invalidated, timestamp, true);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Owns the build tool and nothing else: module graph, CSS observation, token
|
|
97
|
+
* inventory, transport middleware, bootstrap injection, HMR. Framework
|
|
98
|
+
* semantics arrive through `createFramework`; passing `null` is a supported
|
|
99
|
+
* composition, and `vite.noFramework.test.ts` exercises it to prove nothing
|
|
100
|
+
* here has grown a React assumption.
|
|
101
|
+
*/
|
|
102
|
+
export function createVitePlugins(options = {}, createFramework = null) {
|
|
103
|
+
const enabled = options.enabled ?? true;
|
|
104
|
+
let root;
|
|
105
|
+
let buildOutputDirectory;
|
|
106
|
+
let command = "serve";
|
|
107
|
+
let demoBuild = false;
|
|
108
|
+
let devServer;
|
|
109
|
+
let postTransformPromise = null;
|
|
110
|
+
const inventory = createTokenInventory();
|
|
111
|
+
const activeHostCssFiles = new Set();
|
|
112
|
+
// Belongs to the artifact, not one observation: a transform hook has no import-graph ordering.
|
|
113
|
+
const stylesheetOrdering = new Map();
|
|
114
|
+
// Detected from the authored graph: v3 also emits --tw-* helpers, so transformed output is not a safe signal.
|
|
115
|
+
const tailwindV4SourceFiles = new Set();
|
|
116
|
+
// Candidates that can supply a transformed first snapshot before Vite builds its module graph.
|
|
117
|
+
const discoveredHostCssFiles = new Set();
|
|
118
|
+
let activePackageCssFiles = new Set();
|
|
119
|
+
let publishedThemeContract = null;
|
|
120
|
+
let publishedThemeContractModuleId = null;
|
|
121
|
+
let publishedThemeContractLoaded = false;
|
|
122
|
+
let contractDiagnostics = [];
|
|
123
|
+
let activeGraphDiagnostics = [];
|
|
124
|
+
const sourceScanDiagnostics = new Map();
|
|
125
|
+
/** Generation of the last snapshot actually serialized into the virtual module. */
|
|
126
|
+
let lastPublishedGeneration = null;
|
|
127
|
+
/** Resolved at hook time: Vite's root and output directory are unknown when `nudgeUi()` is called. */
|
|
128
|
+
function sourceScope() {
|
|
129
|
+
return {
|
|
130
|
+
...(options.sourceRoots ? { sourceRoots: options.sourceRoots } : {}),
|
|
131
|
+
...(buildOutputDirectory ? { generatedRoots: [buildOutputDirectory] } : {}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function isHostSource(id) {
|
|
135
|
+
return isHostApplicationSource(id, root, sourceScope());
|
|
136
|
+
}
|
|
137
|
+
function isPackageSource(id) {
|
|
138
|
+
return isPackageStylesheet(id, root, sourceScope());
|
|
139
|
+
}
|
|
140
|
+
function catalogPath(id) {
|
|
141
|
+
return catalogSourcePath(id, root, sourceScope());
|
|
142
|
+
}
|
|
143
|
+
// Everything below reaches the framework through optional chaining, so `null` is a working configuration.
|
|
144
|
+
const frameworkModuleId = (id) => framework !== null && (id === framework.virtualModuleId || id === resolvedFrameworkModule());
|
|
145
|
+
const resolvedFrameworkModule = () => framework === null ? null : `\0${framework.virtualModuleId}`;
|
|
146
|
+
const framework = createFramework?.(options, {
|
|
147
|
+
root: () => root,
|
|
148
|
+
isHostSource,
|
|
149
|
+
catalogPath,
|
|
150
|
+
}) ?? null;
|
|
151
|
+
function createStylesheetArtifact(input) {
|
|
152
|
+
return createViteStylesheetArtifact({ ...input, ...sourceScope() });
|
|
153
|
+
}
|
|
154
|
+
function isGeneratedBuildOutput(id) {
|
|
155
|
+
if (!root || id.startsWith("\0"))
|
|
156
|
+
return false;
|
|
157
|
+
const fileId = id.split(/[?#]/, 1)[0] ?? id;
|
|
158
|
+
const absoluteFile = resolve(fileId);
|
|
159
|
+
if (buildOutputDirectory && (absoluteFile === buildOutputDirectory
|
|
160
|
+
|| absoluteFile.startsWith(`${buildOutputDirectory}${sep}`)))
|
|
161
|
+
return true;
|
|
162
|
+
const relativeFile = relative(root, absoluteFile);
|
|
163
|
+
return relativeFile === "build" || relativeFile.startsWith(`build${sep}`);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Authored and transformed observations of the same id are fed as two
|
|
167
|
+
* artifacts. The inventory keeps both: the transformed one is the
|
|
168
|
+
* browser-relevant fact set, while names authored in the same artifact keep
|
|
169
|
+
* project provenance.
|
|
170
|
+
*/
|
|
171
|
+
function feedCssArtifact(id, rawCode, stage, ordering = {}) {
|
|
172
|
+
if (!CSS_EXT.test(id))
|
|
173
|
+
return;
|
|
174
|
+
let code = rawCode;
|
|
175
|
+
const fileId = id.split(/[?#]/, 1)[0] ?? id;
|
|
176
|
+
// Astro compiles component <style> blocks into JS wrappers with no authored .css
|
|
177
|
+
// artifact, so unwrap the embedded stylesheet or the catalog never sees
|
|
178
|
+
// component-scoped custom properties (ADR-0011).
|
|
179
|
+
if (!CSS_EXT.test(fileId)) {
|
|
180
|
+
const unwrapped = extractViteModuleCss(code);
|
|
181
|
+
if (unwrapped !== null)
|
|
182
|
+
code = unwrapped;
|
|
183
|
+
}
|
|
184
|
+
if (isGeneratedBuildOutput(fileId))
|
|
185
|
+
return;
|
|
186
|
+
if (ordering.order !== undefined || ordering.discoveryOrder !== undefined) {
|
|
187
|
+
stylesheetOrdering.set(fileId, { ...ordering });
|
|
188
|
+
}
|
|
189
|
+
if (stage === "authored") {
|
|
190
|
+
if (/@import\s+["']tailwindcss["']|@theme\b/i.test(code))
|
|
191
|
+
tailwindV4SourceFiles.add(fileId);
|
|
192
|
+
else
|
|
193
|
+
tailwindV4SourceFiles.delete(fileId);
|
|
194
|
+
}
|
|
195
|
+
const artifact = createStylesheetArtifact({
|
|
196
|
+
id: fileId,
|
|
197
|
+
projectRoot: root,
|
|
198
|
+
stage,
|
|
199
|
+
...(stylesheetOrdering.get(fileId) ?? ordering),
|
|
200
|
+
content: code,
|
|
201
|
+
tailwindV4: tailwindV4SourceFiles.has(fileId),
|
|
202
|
+
});
|
|
203
|
+
inventory.apply(artifact);
|
|
204
|
+
sourceScanDiagnostics.delete(artifact.id);
|
|
205
|
+
}
|
|
206
|
+
/** Drop every observation and temporary provenance fact for one stylesheet. */
|
|
207
|
+
function feedCssRemoval(id) {
|
|
208
|
+
const fileId = id.split(/[?#]/, 1)[0] ?? id;
|
|
209
|
+
tailwindV4SourceFiles.delete(fileId);
|
|
210
|
+
stylesheetOrdering.delete(fileId);
|
|
211
|
+
discoveredHostCssFiles.delete(fileId);
|
|
212
|
+
const artifact = createStylesheetArtifact({
|
|
213
|
+
id: fileId,
|
|
214
|
+
projectRoot: root,
|
|
215
|
+
stage: "authored",
|
|
216
|
+
});
|
|
217
|
+
sourceScanDiagnostics.delete(artifact.id);
|
|
218
|
+
inventory.apply(artifact);
|
|
219
|
+
}
|
|
220
|
+
/** The inventory keeps the last valid authored observation and records a recoverable diagnostic. */
|
|
221
|
+
function feedCssTransformFailure(id) {
|
|
222
|
+
if (!CSS_EXT.test(id))
|
|
223
|
+
return;
|
|
224
|
+
const fileId = id.split(/[?#]/, 1)[0] ?? id;
|
|
225
|
+
if (isGeneratedBuildOutput(fileId))
|
|
226
|
+
return;
|
|
227
|
+
inventory.apply(createStylesheetArtifact({
|
|
228
|
+
id: fileId,
|
|
229
|
+
projectRoot: root,
|
|
230
|
+
stage: "transformed",
|
|
231
|
+
failed: true,
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
async function refreshPublishedThemeContract() {
|
|
235
|
+
const moduleSpecifier = options.vanillaExtract?.themeContractModule;
|
|
236
|
+
if (!moduleSpecifier || !devServer)
|
|
237
|
+
return;
|
|
238
|
+
const exportName = options.vanillaExtract?.themeContractExport ?? "vars";
|
|
239
|
+
publishedThemeContract = null;
|
|
240
|
+
publishedThemeContractModuleId = null;
|
|
241
|
+
contractDiagnostics = [];
|
|
242
|
+
let resolvedId = null;
|
|
243
|
+
try {
|
|
244
|
+
resolvedId = (await devServer.pluginContainer.resolveId(moduleSpecifier))?.id ?? null;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
// The diagnostic below explains it without making the CSS catalog unavailable.
|
|
248
|
+
}
|
|
249
|
+
if (!resolvedId) {
|
|
250
|
+
contractDiagnostics = [{
|
|
251
|
+
code: "vanilla-extract-contract-unresolved",
|
|
252
|
+
module: moduleSpecifier,
|
|
253
|
+
message: `Could not resolve vanilla-extract contract module ${moduleSpecifier}.`,
|
|
254
|
+
}];
|
|
255
|
+
publishedThemeContractLoaded = true;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
// Retained even for an invalid export, so HMR can recover if the package publishes it later.
|
|
259
|
+
publishedThemeContractModuleId = stripCssQuery(resolvedId);
|
|
260
|
+
let namespace;
|
|
261
|
+
try {
|
|
262
|
+
namespace = await devServer.ssrLoadModule(resolvedId);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
contractDiagnostics = [{
|
|
266
|
+
code: "vanilla-extract-contract-unresolved",
|
|
267
|
+
module: moduleSpecifier,
|
|
268
|
+
message: `Could not load vanilla-extract contract module ${moduleSpecifier}.`,
|
|
269
|
+
}];
|
|
270
|
+
publishedThemeContractLoaded = true;
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const exported = namespace[exportName];
|
|
274
|
+
if (exported === undefined) {
|
|
275
|
+
contractDiagnostics = [{
|
|
276
|
+
code: "vanilla-extract-contract-missing-export",
|
|
277
|
+
module: moduleSpecifier,
|
|
278
|
+
exportName,
|
|
279
|
+
message: `Vanilla-extract contract module ${moduleSpecifier} does not export ${exportName}.`,
|
|
280
|
+
}];
|
|
281
|
+
}
|
|
282
|
+
else if (!isRecord(exported)) {
|
|
283
|
+
contractDiagnostics = [{
|
|
284
|
+
code: "vanilla-extract-contract-unsupported-shape",
|
|
285
|
+
module: moduleSpecifier,
|
|
286
|
+
exportName,
|
|
287
|
+
message: `Vanilla-extract contract export ${exportName} from ${moduleSpecifier} must be an object.`,
|
|
288
|
+
}];
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
publishedThemeContract = exported;
|
|
292
|
+
}
|
|
293
|
+
publishedThemeContractLoaded = true;
|
|
294
|
+
}
|
|
295
|
+
async function ensurePublishedThemeContract() {
|
|
296
|
+
if (!options.vanillaExtract?.themeContractModule || publishedThemeContractLoaded)
|
|
297
|
+
return;
|
|
298
|
+
await refreshPublishedThemeContract();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Hands everything this host observed about CSS dialects to the interpreter
|
|
302
|
+
* and applies what comes back, so the snapshot carries final labels. Every
|
|
303
|
+
* contribution is id-keyed and replaceable, so repeating this with unchanged
|
|
304
|
+
* facts is a no-op and load() shares one path with the HMR exactly-once guard.
|
|
305
|
+
*/
|
|
306
|
+
function syncInventoryContributions() {
|
|
307
|
+
const { contributions } = interpretDialects({
|
|
308
|
+
...(options.tailwindV3 === undefined ? {} : { tailwindV3: options.tailwindV3 }),
|
|
309
|
+
tailwindV4Css: tailwindV4SourceFiles.size > 0,
|
|
310
|
+
...(options.vanillaExtract?.themeContract === undefined ? {} : {
|
|
311
|
+
inlineThemeContract: {
|
|
312
|
+
contract: options.vanillaExtract.themeContract,
|
|
313
|
+
...(options.vanillaExtract.cssValues === undefined
|
|
314
|
+
? {}
|
|
315
|
+
: { cssValues: options.vanillaExtract.cssValues }),
|
|
316
|
+
...(options.vanillaExtract.source === undefined
|
|
317
|
+
? {}
|
|
318
|
+
: { source: options.vanillaExtract.source }),
|
|
319
|
+
},
|
|
320
|
+
}),
|
|
321
|
+
publishedThemeContract: {
|
|
322
|
+
attempted: options.vanillaExtract?.themeContractModule !== undefined
|
|
323
|
+
&& publishedThemeContractLoaded,
|
|
324
|
+
contract: publishedThemeContract,
|
|
325
|
+
fromPackage: publishedThemeContractModuleId !== null
|
|
326
|
+
&& isPackageStylesheet(publishedThemeContractModuleId, root),
|
|
327
|
+
...(options.vanillaExtract?.themeContractPrefix === undefined
|
|
328
|
+
? {}
|
|
329
|
+
: { prefix: options.vanillaExtract.themeContractPrefix }),
|
|
330
|
+
source: options.vanillaExtract?.source ?? options.vanillaExtract?.themeContractModule ?? "",
|
|
331
|
+
diagnostics: contractDiagnostics,
|
|
332
|
+
},
|
|
333
|
+
diagnostics: [...sourceScanDiagnostics.values(), ...activeGraphDiagnostics],
|
|
334
|
+
});
|
|
335
|
+
for (const contribution of contributions)
|
|
336
|
+
inventory.applyContribution(contribution);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Publishes exactly once per observable snapshot change. Every HMR feed for
|
|
340
|
+
* an event settles first, so identical facts do not bump the generation, and
|
|
341
|
+
* contributions sync first so the guard compares what load() would serialize.
|
|
342
|
+
*/
|
|
343
|
+
function invalidateTokensIfChanged(server) {
|
|
344
|
+
const generation = currentTokenGeneration();
|
|
345
|
+
if (generation === lastPublishedGeneration)
|
|
346
|
+
return { changed: false, generation };
|
|
347
|
+
lastPublishedGeneration = generation;
|
|
348
|
+
const virtual = server.moduleGraph.getModuleById(RESOLVED_TOKENS_ID);
|
|
349
|
+
if (virtual)
|
|
350
|
+
server.moduleGraph.invalidateModule(virtual);
|
|
351
|
+
return virtual ? { changed: true, generation, virtual } : { changed: true, generation };
|
|
352
|
+
}
|
|
353
|
+
function currentTokenGeneration() {
|
|
354
|
+
syncInventoryContributions();
|
|
355
|
+
return inventory.snapshot().generation;
|
|
356
|
+
}
|
|
357
|
+
async function handleStylesheetWatchEvent(server, file, event) {
|
|
358
|
+
if (!enabled || command !== "serve" || !CSS_EXT.test(file))
|
|
359
|
+
return;
|
|
360
|
+
const previousGeneration = currentTokenGeneration();
|
|
361
|
+
postTransformPromise = null;
|
|
362
|
+
if (event === "unlink") {
|
|
363
|
+
server.moduleGraph.onFileDelete(file);
|
|
364
|
+
activeHostCssFiles.delete(stripCssQuery(file));
|
|
365
|
+
feedCssRemoval(file);
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
// Project CSS counts before import; package CSS only via the active graph refresh below.
|
|
369
|
+
if (isHostSource(file)) {
|
|
370
|
+
try {
|
|
371
|
+
feedCssArtifact(file, readFileSync(file, "utf8"), "authored");
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
const source = catalogPath(file);
|
|
375
|
+
sourceScanDiagnostics.set(source, {
|
|
376
|
+
code: "stylesheet-unreadable",
|
|
377
|
+
artifact: source,
|
|
378
|
+
message: `Could not read stylesheet ${source}.`,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
await refreshActiveStylesheetTokens();
|
|
384
|
+
if (event === "add" && activeHostCssFiles.has(stripCssQuery(file))) {
|
|
385
|
+
try {
|
|
386
|
+
await server.transformRequest(file);
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
if (existsSync(file))
|
|
390
|
+
feedCssTransformFailure(file);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const { generation } = invalidateTokensIfChanged(server);
|
|
394
|
+
if (generation !== previousGeneration) {
|
|
395
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async function refreshActiveStylesheetTokens() {
|
|
399
|
+
if (!devServer || !root)
|
|
400
|
+
return;
|
|
401
|
+
const graphModules = devServer.moduleGraph?.idToModuleMap;
|
|
402
|
+
if (graphModules) {
|
|
403
|
+
activeHostCssFiles.clear();
|
|
404
|
+
for (const module of graphModules.values()) {
|
|
405
|
+
const id = module.id && stripCssQuery(module.id);
|
|
406
|
+
if (id && CSS_EXT.test(id) && isHostSource(id)
|
|
407
|
+
&& module.importers.size > 0)
|
|
408
|
+
activeHostCssFiles.add(id);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
const graph = await discoverCssImportGraph([...activeHostCssFiles], {
|
|
412
|
+
read: (id) => readFileSync(id, "utf8"),
|
|
413
|
+
resolve: async (specifier, importer) => {
|
|
414
|
+
const resolved = await devServer.pluginContainer.resolveId(specifier, importer);
|
|
415
|
+
if (resolved?.id)
|
|
416
|
+
return resolved.id;
|
|
417
|
+
try {
|
|
418
|
+
return createRequire(importer).resolve(specifier);
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
});
|
|
425
|
+
const nextPackageFiles = new Set();
|
|
426
|
+
for (const { id, code, ...ordering } of orderViteStylesheetGraph(graph, activeHostCssFiles.size)) {
|
|
427
|
+
const fileId = stripCssQuery(id);
|
|
428
|
+
feedCssArtifact(fileId, code, "authored", ordering);
|
|
429
|
+
if (isPackageSource(fileId))
|
|
430
|
+
nextPackageFiles.add(fileId);
|
|
431
|
+
}
|
|
432
|
+
for (const previous of activePackageCssFiles) {
|
|
433
|
+
if (!nextPackageFiles.has(previous))
|
|
434
|
+
feedCssRemoval(previous);
|
|
435
|
+
}
|
|
436
|
+
activeGraphDiagnostics = [
|
|
437
|
+
...graph.unreadable.map((id) => ({
|
|
438
|
+
code: "stylesheet-unreadable",
|
|
439
|
+
artifact: catalogPath(id),
|
|
440
|
+
message: `Could not read stylesheet ${catalogPath(id)}.`,
|
|
441
|
+
})),
|
|
442
|
+
...graph.unresolved.map(({ importer, specifier }) => ({
|
|
443
|
+
code: "stylesheet-unresolved",
|
|
444
|
+
artifact: catalogPath(importer),
|
|
445
|
+
module: specifier,
|
|
446
|
+
message: `Could not resolve stylesheet import ${specifier} from ${catalogPath(importer)}.`,
|
|
447
|
+
})),
|
|
448
|
+
];
|
|
449
|
+
activePackageCssFiles = nextPackageFiles;
|
|
450
|
+
}
|
|
451
|
+
function ensurePostTransformCss() {
|
|
452
|
+
if (!devServer || !root || command !== "serve")
|
|
453
|
+
return Promise.resolve();
|
|
454
|
+
if (postTransformPromise)
|
|
455
|
+
return postTransformPromise;
|
|
456
|
+
// The module graph decides reachability: transforming only those entries drives
|
|
457
|
+
// them through the observer plugin below without activating dead CSS files.
|
|
458
|
+
postTransformPromise = (async () => {
|
|
459
|
+
await refreshActiveStylesheetTokens();
|
|
460
|
+
const cssPaths = activeHostCssFiles.size > 0
|
|
461
|
+
? activeHostCssFiles
|
|
462
|
+
: discoveredHostCssFiles;
|
|
463
|
+
await Promise.all([...cssPaths].map(async (cssPath) => {
|
|
464
|
+
try {
|
|
465
|
+
await devServer.transformRequest(cssPath);
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
if (existsSync(cssPath))
|
|
469
|
+
feedCssTransformFailure(cssPath);
|
|
470
|
+
}
|
|
471
|
+
}));
|
|
472
|
+
})();
|
|
473
|
+
return postTransformPromise;
|
|
474
|
+
}
|
|
475
|
+
async function buildClientManifest() {
|
|
476
|
+
await ensurePostTransformCss();
|
|
477
|
+
await ensurePublishedThemeContract();
|
|
478
|
+
return {
|
|
479
|
+
version: 1,
|
|
480
|
+
revision: 0,
|
|
481
|
+
runtime: buildRuntimeSnapshot(),
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function buildRuntimeSnapshot() {
|
|
485
|
+
syncInventoryContributions();
|
|
486
|
+
const snapshot = inventory.snapshot();
|
|
487
|
+
const tokenDiagnostics = snapshot.diagnostics.map((diagnostic) => ({
|
|
488
|
+
code: diagnostic.code,
|
|
489
|
+
message: diagnostic.message,
|
|
490
|
+
module: diagnostic.module ?? diagnostic.artifact ?? "token-inventory",
|
|
491
|
+
...(diagnostic.exportName !== undefined ? { exportName: diagnostic.exportName } : {}),
|
|
492
|
+
}));
|
|
493
|
+
return {
|
|
494
|
+
projectId: options.projectId ?? (root ? basename(root) : "vite"),
|
|
495
|
+
// Without a framework there are no component boundaries to describe, so the
|
|
496
|
+
// project is HTML and CSS as far as the inspector is concerned.
|
|
497
|
+
host: framework?.hostLabel ?? "static-html",
|
|
498
|
+
framework: framework?.framework ?? "HTML",
|
|
499
|
+
stylingSystem: detectStylingSystem(snapshot.tokens),
|
|
500
|
+
capabilities: { canvas: true, componentSemantics: framework !== null },
|
|
501
|
+
tokenCatalog: snapshot.definitions.map((definition) => ({
|
|
502
|
+
...definition,
|
|
503
|
+
declarations: definition.declarations.map((declaration) => ({ ...declaration })),
|
|
504
|
+
})),
|
|
505
|
+
tokens: snapshot.tokens,
|
|
506
|
+
tokenDiagnostics,
|
|
507
|
+
tokenGeneration: snapshot.generation,
|
|
508
|
+
componentContracts: componentContractCatalog(),
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function componentContractCatalog() {
|
|
512
|
+
return framework?.contracts() ?? [];
|
|
513
|
+
}
|
|
514
|
+
const plugin = {
|
|
515
|
+
name: "nudge-ui",
|
|
516
|
+
enforce: "pre",
|
|
517
|
+
config(userConfig, env) {
|
|
518
|
+
if (!enabled || env.command !== "serve")
|
|
519
|
+
return;
|
|
520
|
+
// Module resolution is a framework concern; without one this host asks nothing of the resolver.
|
|
521
|
+
return framework?.viteConfig({
|
|
522
|
+
projectRoot: userConfig.root ?? process.cwd(),
|
|
523
|
+
demo: options.demo === true,
|
|
524
|
+
existingDedupe: userConfig.resolve?.dedupe ?? [],
|
|
525
|
+
});
|
|
526
|
+
},
|
|
527
|
+
configResolved(config) {
|
|
528
|
+
root = config.root;
|
|
529
|
+
command = config.command;
|
|
530
|
+
demoBuild = options.demo === true && config.mode === "nudge-demo";
|
|
531
|
+
buildOutputDirectory = config.build?.outDir
|
|
532
|
+
? resolve(config.root, config.build.outDir)
|
|
533
|
+
: undefined;
|
|
534
|
+
},
|
|
535
|
+
configureServer(server) {
|
|
536
|
+
if (!enabled || command !== "serve")
|
|
537
|
+
return;
|
|
538
|
+
devServer = server;
|
|
539
|
+
const runtimeWarning = framework?.unresolvedRuntimeWarning();
|
|
540
|
+
if (runtimeWarning)
|
|
541
|
+
server.config.logger.warn(runtimeWarning);
|
|
542
|
+
server.middlewares?.use(async (request, response, next) => {
|
|
543
|
+
const pathname = new URL(request.url ?? "/", "http://nudge-ui.local").pathname;
|
|
544
|
+
if ((pathname === CLIENT_PATH || pathname === MANIFEST_PATH) && request.method !== "GET") {
|
|
545
|
+
response.statusCode = 405;
|
|
546
|
+
response.end();
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (pathname === CLIENT_PATH) {
|
|
550
|
+
try {
|
|
551
|
+
response.statusCode = 200;
|
|
552
|
+
response.setHeader("Content-Type", "text/javascript; charset=utf-8");
|
|
553
|
+
response.setHeader("Cache-Control", "no-cache");
|
|
554
|
+
response.end(readInspectorClient());
|
|
555
|
+
}
|
|
556
|
+
catch {
|
|
557
|
+
response.statusCode = 503;
|
|
558
|
+
response.end("Nudge UI client has not been built.");
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (pathname === MANIFEST_PATH) {
|
|
563
|
+
try {
|
|
564
|
+
response.statusCode = 200;
|
|
565
|
+
response.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
566
|
+
response.setHeader("Cache-Control", "no-store");
|
|
567
|
+
response.end(JSON.stringify(await buildClientManifest()));
|
|
568
|
+
}
|
|
569
|
+
catch (error) {
|
|
570
|
+
next(error);
|
|
571
|
+
}
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
next();
|
|
575
|
+
});
|
|
576
|
+
server.watcher?.on("add", (file) => handleStylesheetWatchEvent(server, file, "add"));
|
|
577
|
+
server.watcher?.on("unlink", (file) => handleStylesheetWatchEvent(server, file, "unlink"));
|
|
578
|
+
},
|
|
579
|
+
buildStart() {
|
|
580
|
+
// The browser imports virtual:design-tokens before styles.css is necessarily
|
|
581
|
+
// transformed, so transform-only collection would yield an empty first load.
|
|
582
|
+
if (!enabled || (command !== "serve" && !demoBuild) || !root)
|
|
583
|
+
return;
|
|
584
|
+
for (const cssPath of scanCssFiles(root, [], root, buildOutputDirectory)) {
|
|
585
|
+
try {
|
|
586
|
+
const code = readFileSync(cssPath, "utf8");
|
|
587
|
+
if (isHostSource(cssPath))
|
|
588
|
+
discoveredHostCssFiles.add(cssPath);
|
|
589
|
+
feedCssArtifact(cssPath, code, "authored");
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
const rel = catalogPath(cssPath);
|
|
593
|
+
sourceScanDiagnostics.set(rel, {
|
|
594
|
+
code: "stylesheet-unreadable",
|
|
595
|
+
artifact: rel,
|
|
596
|
+
message: `Could not read stylesheet ${rel}.`,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
framework?.warmUp();
|
|
601
|
+
},
|
|
602
|
+
resolveId(id) {
|
|
603
|
+
if (id === VIRTUAL_TOKENS_ID || id === RESOLVED_TOKENS_ID)
|
|
604
|
+
return RESOLVED_TOKENS_ID;
|
|
605
|
+
if (id === VIRTUAL_INSPECTOR_ID || id === RESOLVED_INSPECTOR_ID)
|
|
606
|
+
return RESOLVED_INSPECTOR_ID;
|
|
607
|
+
if (frameworkModuleId(id))
|
|
608
|
+
return resolvedFrameworkModule();
|
|
609
|
+
return null;
|
|
610
|
+
},
|
|
611
|
+
async load(id) {
|
|
612
|
+
if (id === RESOLVED_TOKENS_ID) {
|
|
613
|
+
// ADR-0002: production builds receive an empty token table.
|
|
614
|
+
if (command === "build" && !demoBuild) {
|
|
615
|
+
return `export const tokenCatalog = [];\nexport const tokens = [];\nexport const tokenDiagnostics = [];\nexport const tokenGeneration = "";\nexport const nudgeUiProjectId = "";\nexport default tokens;\n`;
|
|
616
|
+
}
|
|
617
|
+
await ensurePostTransformCss();
|
|
618
|
+
await ensurePublishedThemeContract();
|
|
619
|
+
// Contributions merge inside the inventory; load() serializes one immutable
|
|
620
|
+
// snapshot verbatim, so there is no post-snapshot enrichment or TOCTOU.
|
|
621
|
+
const runtime = buildRuntimeSnapshot();
|
|
622
|
+
lastPublishedGeneration = runtime.tokenGeneration;
|
|
623
|
+
return `export const tokenCatalog = ${JSON.stringify(runtime.tokenCatalog)};\nexport const tokens = ${JSON.stringify(runtime.tokens)};\nexport const tokenDiagnostics = ${JSON.stringify(runtime.tokenDiagnostics)};\nexport const tokenGeneration = ${JSON.stringify(runtime.tokenGeneration)};\nexport const nudgeUiProjectId = ${JSON.stringify(runtime.projectId)};\nexport default tokens;\n`;
|
|
624
|
+
}
|
|
625
|
+
if (id === RESOLVED_INSPECTOR_ID) {
|
|
626
|
+
// ADR-0002: normal production builds receive no inspector bootstrap.
|
|
627
|
+
if (command === "build" && !demoBuild) {
|
|
628
|
+
return `export {};\n`;
|
|
629
|
+
}
|
|
630
|
+
if (options.demo === true) {
|
|
631
|
+
const landingDemoExpression = demoBuild
|
|
632
|
+
? "true"
|
|
633
|
+
: '(import.meta.env.DEV && window.location.pathname === "/")';
|
|
634
|
+
// Taken from the composed framework, so the demo bootstrap cannot drift
|
|
635
|
+
// from the manifest the transport serves.
|
|
636
|
+
const identity = buildRuntimeSnapshot();
|
|
637
|
+
return [
|
|
638
|
+
'import { bootstrapNudgeUi, configureNudgeUiRuntime, detectFramework, setInspectorOpen } from "nudge-ui/internal/inspector";',
|
|
639
|
+
'import { tokenCatalog, tokens, tokenDiagnostics, tokenGeneration, nudgeUiProjectId } from "virtual:design-tokens";',
|
|
640
|
+
...(framework
|
|
641
|
+
? [`import { componentContracts } from ${JSON.stringify(framework.virtualModuleId)};`]
|
|
642
|
+
: []),
|
|
643
|
+
'const __nudge_ui_demo_frame = new URLSearchParams(window.location.search).get("nudgeDemo") === "1";',
|
|
644
|
+
`const __nudge_ui_landing_demo = ${landingDemoExpression};`,
|
|
645
|
+
'const __nudge_ui_demo_runtime = __nudge_ui_demo_frame || __nudge_ui_landing_demo;',
|
|
646
|
+
'if (__nudge_ui_demo_runtime || (import.meta.env.DEV && window.location.pathname !== "/demo")) {',
|
|
647
|
+
' configureNudgeUiRuntime({',
|
|
648
|
+
' projectId: nudgeUiProjectId,',
|
|
649
|
+
` host: ${JSON.stringify(identity.host)},`,
|
|
650
|
+
` framework: ${JSON.stringify(identity.framework)},`,
|
|
651
|
+
' stylingSystem: detectFramework(tokens).stylingSystem,',
|
|
652
|
+
' ...(__nudge_ui_demo_runtime ? { demo: true } : {}),',
|
|
653
|
+
` capabilities: { canvas: __nudge_ui_demo_runtime ? false : true, componentSemantics: ${String(framework !== null)} },`,
|
|
654
|
+
' tokenCatalog,',
|
|
655
|
+
' tokens,',
|
|
656
|
+
' tokenDiagnostics,',
|
|
657
|
+
' tokenGeneration,',
|
|
658
|
+
` componentContracts${framework ? "" : ": []"},`,
|
|
659
|
+
' });',
|
|
660
|
+
' const __dt_root = document.getElementById("nudge-ui-root");',
|
|
661
|
+
' if (__dt_root) {',
|
|
662
|
+
' bootstrapNudgeUi(__dt_root);',
|
|
663
|
+
' if (__nudge_ui_demo_runtime) {',
|
|
664
|
+
' setInspectorOpen(false);',
|
|
665
|
+
' window.addEventListener("nudge-ui:open", () => setInspectorOpen(true));',
|
|
666
|
+
' }',
|
|
667
|
+
' }',
|
|
668
|
+
'}',
|
|
669
|
+
].join("\n");
|
|
670
|
+
}
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
if (framework && id === resolvedFrameworkModule()) {
|
|
674
|
+
// ADR-0002: production builds receive an empty catalog.
|
|
675
|
+
const productionBuild = command === "build" && !demoBuild;
|
|
676
|
+
return framework.serializeVirtualModule(productionBuild ? [] : framework.contracts());
|
|
677
|
+
}
|
|
678
|
+
return null;
|
|
679
|
+
},
|
|
680
|
+
// React's Vite plugin is also `enforce: "pre"` with no explicit hook order, so
|
|
681
|
+
// hook-level `order: "pre"` is what parses authored TSX before Babel prepends
|
|
682
|
+
// refresh helpers and shifts the AST locations data-src depends on.
|
|
683
|
+
transform: {
|
|
684
|
+
order: "pre",
|
|
685
|
+
async handler(code, id) {
|
|
686
|
+
if (!enabled)
|
|
687
|
+
return null;
|
|
688
|
+
if (command === "build" && !demoBuild)
|
|
689
|
+
return null; // dev-only per ADR-0002; explicit demo builds are opt-in
|
|
690
|
+
if (CSS_EXT.test(id)) {
|
|
691
|
+
const fileId = stripCssQuery(id);
|
|
692
|
+
if (isHostSource(fileId)) {
|
|
693
|
+
activeHostCssFiles.add(fileId);
|
|
694
|
+
discoveredHostCssFiles.add(fileId);
|
|
695
|
+
}
|
|
696
|
+
feedCssArtifact(id, code, "authored");
|
|
697
|
+
return null; // let Vite's CSS pipeline handle the actual stylesheet
|
|
698
|
+
}
|
|
699
|
+
// Everything past CSS belongs to the framework; with none, source modules are untouched.
|
|
700
|
+
if (!framework)
|
|
701
|
+
return null;
|
|
702
|
+
return framework.transform({
|
|
703
|
+
resolve: async (specifier, importer) => {
|
|
704
|
+
const resolved = await this.resolve(specifier, importer, { skipSelf: true });
|
|
705
|
+
return resolved ? stripCssQuery(resolved.id) : null;
|
|
706
|
+
},
|
|
707
|
+
warn: (message) => this.warn(message),
|
|
708
|
+
}, code, id);
|
|
709
|
+
},
|
|
710
|
+
},
|
|
711
|
+
transformIndexHtml(html) {
|
|
712
|
+
// The landing app's static demo build imports the virtual module from the app
|
|
713
|
+
// entry, because Vite cannot preserve the dev HTML virtual-module URL.
|
|
714
|
+
if (!enabled || demoBuild)
|
|
715
|
+
return;
|
|
716
|
+
const out = transformIndexHtmlHtml(html, command, {
|
|
717
|
+
debug: options.debug === true,
|
|
718
|
+
demoBuild,
|
|
719
|
+
demo: options.demo === true,
|
|
720
|
+
});
|
|
721
|
+
return out === null ? undefined : out;
|
|
722
|
+
},
|
|
723
|
+
async handleHotUpdate(ctx) {
|
|
724
|
+
if (!enabled || command !== "serve")
|
|
725
|
+
return;
|
|
726
|
+
if (publishedThemeContractModuleId && stripCssQuery(ctx.file) === publishedThemeContractModuleId) {
|
|
727
|
+
const previousGeneration = currentTokenGeneration();
|
|
728
|
+
invalidateHmrModules(ctx.server, ctx.modules, ctx.timestamp);
|
|
729
|
+
publishedThemeContractLoaded = false;
|
|
730
|
+
await ensurePublishedThemeContract();
|
|
731
|
+
// Same exactly-once path as the CSS branch.
|
|
732
|
+
const { changed, generation, virtual } = invalidateTokensIfChanged(ctx.server);
|
|
733
|
+
if (changed && virtual)
|
|
734
|
+
return [...ctx.modules, virtual];
|
|
735
|
+
if (generation !== previousGeneration) {
|
|
736
|
+
ctx.server.ws.send({ type: "full-reload", path: "*" });
|
|
737
|
+
}
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if (framework?.owns(ctx.file)) {
|
|
741
|
+
const previousGeneration = currentTokenGeneration();
|
|
742
|
+
const previousContracts = JSON.stringify(componentContractCatalog());
|
|
743
|
+
try {
|
|
744
|
+
framework.observe(ctx.file, await ctx.read());
|
|
745
|
+
}
|
|
746
|
+
catch {
|
|
747
|
+
framework.forget(ctx.file);
|
|
748
|
+
}
|
|
749
|
+
// Vite must update importer edges first: a component can add or remove a
|
|
750
|
+
// stylesheet import while every CSS file remains on disk.
|
|
751
|
+
invalidateHmrModules(ctx.server, ctx.modules, ctx.timestamp);
|
|
752
|
+
try {
|
|
753
|
+
await ctx.server.transformRequest(ctx.file);
|
|
754
|
+
}
|
|
755
|
+
catch {
|
|
756
|
+
// Metadata still refreshes; the next successful transform rebuilds the roots.
|
|
757
|
+
}
|
|
758
|
+
postTransformPromise = null;
|
|
759
|
+
await ensurePostTransformCss();
|
|
760
|
+
const virtualComponents = ctx.server.moduleGraph.getModuleById(resolvedFrameworkModule());
|
|
761
|
+
const { changed, generation, virtual: virtualTokens } = invalidateTokensIfChanged(ctx.server);
|
|
762
|
+
const contractsChanged = JSON.stringify(componentContractCatalog()) !== previousContracts;
|
|
763
|
+
const modules = [...ctx.modules];
|
|
764
|
+
if (contractsChanged && virtualComponents) {
|
|
765
|
+
ctx.server.moduleGraph.invalidateModule(virtualComponents);
|
|
766
|
+
modules.push(virtualComponents);
|
|
767
|
+
}
|
|
768
|
+
if (changed && virtualTokens) {
|
|
769
|
+
modules.push(virtualTokens);
|
|
770
|
+
}
|
|
771
|
+
const tokensChanged = generation !== previousGeneration;
|
|
772
|
+
if ((contractsChanged && !virtualComponents) || (tokensChanged && !virtualTokens)) {
|
|
773
|
+
ctx.server.ws.send({ type: "full-reload", path: "*" });
|
|
774
|
+
}
|
|
775
|
+
return modules.length > 0 ? [...new Set(modules)] : undefined;
|
|
776
|
+
}
|
|
777
|
+
if (!CSS_EXT.test(ctx.file))
|
|
778
|
+
return;
|
|
779
|
+
const previousGeneration = currentTokenGeneration();
|
|
780
|
+
// So the next virtual-module load sees updated tokens; Vite's CSS reload runs in parallel.
|
|
781
|
+
let hasAuthoredObservation = false;
|
|
782
|
+
try {
|
|
783
|
+
const code = await ctx.read();
|
|
784
|
+
hasAuthoredObservation = true;
|
|
785
|
+
feedCssArtifact(ctx.file, code, "authored");
|
|
786
|
+
}
|
|
787
|
+
catch {
|
|
788
|
+
const fileId = stripCssQuery(ctx.file);
|
|
789
|
+
if (!existsSync(fileId)) {
|
|
790
|
+
feedCssRemoval(ctx.file);
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
const rel = catalogPath(fileId);
|
|
794
|
+
sourceScanDiagnostics.set(rel, {
|
|
795
|
+
code: "stylesheet-unreadable",
|
|
796
|
+
artifact: rel,
|
|
797
|
+
message: `Could not read stylesheet ${rel}. Keeping its last valid token inventory entry.`,
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
await refreshActiveStylesheetTokens();
|
|
802
|
+
// ctx.read() returns authored source, so re-run it through Vite to pick up
|
|
803
|
+
// Tailwind's generated stylesheet before invalidating below.
|
|
804
|
+
postTransformPromise = null;
|
|
805
|
+
try {
|
|
806
|
+
await ctx.server.transformRequest(ctx.file);
|
|
807
|
+
}
|
|
808
|
+
catch {
|
|
809
|
+
// Marks the transform failed so authored rows survive with a recoverable
|
|
810
|
+
// diagnostic. A deleted file has no authored read and is a removal instead.
|
|
811
|
+
if (hasAuthoredObservation)
|
|
812
|
+
feedCssTransformFailure(ctx.file);
|
|
813
|
+
}
|
|
814
|
+
// Every feed for this event has settled, so invalidate only on a real
|
|
815
|
+
// generation change. Vite's own CSS update below still runs either way.
|
|
816
|
+
const { changed, generation, virtual } = invalidateTokensIfChanged(ctx.server);
|
|
817
|
+
if (generation !== previousGeneration && !virtual) {
|
|
818
|
+
ctx.server.ws.send({ type: "full-reload", path: "*" });
|
|
819
|
+
}
|
|
820
|
+
const modules = [];
|
|
821
|
+
if (changed && virtual)
|
|
822
|
+
modules.push(virtual);
|
|
823
|
+
for (const m of ctx.modules) {
|
|
824
|
+
if (m)
|
|
825
|
+
modules.push(m);
|
|
826
|
+
}
|
|
827
|
+
// Deduplicate while preserving order.
|
|
828
|
+
const seen = new Set();
|
|
829
|
+
return modules.filter((m) => {
|
|
830
|
+
if (seen.has(m.id ?? ""))
|
|
831
|
+
return false;
|
|
832
|
+
seen.add(m.id ?? m.url);
|
|
833
|
+
return true;
|
|
834
|
+
});
|
|
835
|
+
},
|
|
836
|
+
};
|
|
837
|
+
// Tailwind's generator is a pre-transform hook, so this companion stays in Vite's
|
|
838
|
+
// normal group: after every pre plugin regardless of user order, and before Vite's
|
|
839
|
+
// CSS-post JavaScript wrapper. The main plugin stays pre-ordered for TSX locations.
|
|
840
|
+
const transformedCssObserver = {
|
|
841
|
+
name: "nudge-ui:transformed-css",
|
|
842
|
+
apply: "serve",
|
|
843
|
+
transform(code, id) {
|
|
844
|
+
if (!enabled || command !== "serve" || !CSS_EXT.test(id))
|
|
845
|
+
return null;
|
|
846
|
+
feedCssArtifact(id, code, "transformed");
|
|
847
|
+
const virtual = devServer?.moduleGraph.getModuleById(RESOLVED_TOKENS_ID);
|
|
848
|
+
if (virtual)
|
|
849
|
+
devServer?.moduleGraph.invalidateModule(virtual);
|
|
850
|
+
return null;
|
|
851
|
+
},
|
|
852
|
+
};
|
|
853
|
+
return [plugin, transformedCssObserver];
|
|
854
|
+
}
|