forgebook 0.1.3 → 0.1.5
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 +99 -6
- package/dist/bin/forgebook/agentClient.d.ts +17 -0
- package/dist/bin/forgebook/agentClient.d.ts.map +1 -1
- package/dist/bin/forgebook/agentClient.js +21 -0
- package/dist/bin/forgebook/agentClient.js.map +1 -1
- package/dist/bin/forgebook/agentLoopCommands.d.mts +9 -0
- package/dist/bin/forgebook/agentLoopCommands.d.mts.map +1 -0
- package/dist/bin/forgebook/agentLoopCommands.mjs +217 -0
- package/dist/bin/forgebook/agentLoopCommands.mjs.map +1 -0
- package/dist/bin/forgebook/agentText.d.ts +37 -1
- package/dist/bin/forgebook/agentText.d.ts.map +1 -1
- package/dist/bin/forgebook/agentText.js +49 -2
- package/dist/bin/forgebook/agentText.js.map +1 -1
- package/dist/bin/forgebook/agents.md +51 -0
- package/dist/bin/forgebook/agentsText.d.ts +29 -0
- package/dist/bin/forgebook/agentsText.d.ts.map +1 -0
- package/dist/bin/forgebook/agentsText.js +48 -0
- package/dist/bin/forgebook/agentsText.js.map +1 -0
- package/dist/bin/forgebook/catalogueCommands.d.ts +51 -0
- package/dist/bin/forgebook/catalogueCommands.d.ts.map +1 -0
- package/dist/bin/forgebook/catalogueCommands.js +90 -0
- package/dist/bin/forgebook/catalogueCommands.js.map +1 -0
- package/dist/bin/forgebook/errorsRun.d.ts +27 -0
- package/dist/bin/forgebook/errorsRun.d.ts.map +1 -0
- package/dist/bin/forgebook/errorsRun.js +60 -0
- package/dist/bin/forgebook/errorsRun.js.map +1 -0
- package/dist/bin/forgebook/forgebook.mjs +121 -86
- package/dist/bin/forgebook/forgebook.mjs.map +1 -1
- package/dist/bin/forgebook/importers/storybook.d.ts +53 -0
- package/dist/bin/forgebook/importers/storybook.d.ts.map +1 -0
- package/dist/bin/forgebook/importers/storybook.js +318 -0
- package/dist/bin/forgebook/importers/storybook.js.map +1 -0
- package/dist/bin/forgebook/initCommands.d.mts +9 -0
- package/dist/bin/forgebook/initCommands.d.mts.map +1 -0
- package/dist/bin/forgebook/initCommands.mjs +86 -0
- package/dist/bin/forgebook/initCommands.mjs.map +1 -0
- package/dist/bin/forgebook/initConfig.d.ts +22 -0
- package/dist/bin/forgebook/initConfig.d.ts.map +1 -0
- package/dist/bin/forgebook/initConfig.js +51 -0
- package/dist/bin/forgebook/initConfig.js.map +1 -0
- package/dist/bin/forgebook/mcpTools.d.ts +29 -3
- package/dist/bin/forgebook/mcpTools.d.ts.map +1 -1
- package/dist/bin/forgebook/mcpTools.js +130 -7
- package/dist/bin/forgebook/mcpTools.js.map +1 -1
- package/dist/bin/forgebook/newStories.d.ts +27 -0
- package/dist/bin/forgebook/newStories.d.ts.map +1 -0
- package/dist/bin/forgebook/newStories.js +109 -0
- package/dist/bin/forgebook/newStories.js.map +1 -0
- package/dist/bin/forgebook/newStoriesFile.d.ts +18 -0
- package/dist/bin/forgebook/newStoriesFile.d.ts.map +1 -0
- package/dist/bin/forgebook/newStoriesFile.js +58 -0
- package/dist/bin/forgebook/newStoriesFile.js.map +1 -0
- package/dist/bin/forgebook/storyCheckRun.d.ts +49 -0
- package/dist/bin/forgebook/storyCheckRun.d.ts.map +1 -0
- package/dist/bin/forgebook/storyCheckRun.js +178 -0
- package/dist/bin/forgebook/storyCheckRun.js.map +1 -0
- package/dist/bin/forgebook/touchWindowRun.d.ts +17 -0
- package/dist/bin/forgebook/touchWindowRun.d.ts.map +1 -0
- package/dist/bin/forgebook/touchWindowRun.js +21 -0
- package/dist/bin/forgebook/touchWindowRun.js.map +1 -0
- package/dist/bin/forgebook-docs/catalogueDocs.d.ts +24 -0
- package/dist/bin/forgebook-docs/catalogueDocs.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/catalogueDocs.js +71 -0
- package/dist/bin/forgebook-docs/catalogueDocs.js.map +1 -0
- package/dist/bin/forgebook-docs/catalogueDocs.types.d.ts +8 -0
- package/dist/bin/forgebook-docs/catalogueDocs.types.d.ts.map +1 -1
- package/dist/bin/forgebook-docs/catalogueMarkdown.d.ts +3 -1
- package/dist/bin/forgebook-docs/catalogueMarkdown.d.ts.map +1 -1
- package/dist/bin/forgebook-docs/catalogueMarkdown.js +62 -42
- package/dist/bin/forgebook-docs/catalogueMarkdown.js.map +1 -1
- package/dist/bin/forgebook-docs/catalogueOptions.d.ts +39 -0
- package/dist/bin/forgebook-docs/catalogueOptions.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/catalogueOptions.js +76 -0
- package/dist/bin/forgebook-docs/catalogueOptions.js.map +1 -0
- package/dist/bin/forgebook-docs/collectDocs.d.ts +3 -1
- package/dist/bin/forgebook-docs/collectDocs.d.ts.map +1 -1
- package/dist/bin/forgebook-docs/collectDocs.js +37 -13
- package/dist/bin/forgebook-docs/collectDocs.js.map +1 -1
- package/dist/bin/forgebook-docs/forgebook-docs.mjs +17 -80
- package/dist/bin/forgebook-docs/forgebook-docs.mjs.map +1 -1
- package/dist/bin/forgebook-docs/llmsText.d.ts +24 -0
- package/dist/bin/forgebook-docs/llmsText.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/llmsText.js +33 -0
- package/dist/bin/forgebook-docs/llmsText.js.map +1 -0
- package/dist/bin/forgebook-docs/sourceId.d.ts +9 -0
- package/dist/bin/forgebook-docs/sourceId.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/sourceId.js +45 -0
- package/dist/bin/forgebook-docs/sourceId.js.map +1 -0
- package/dist/bin/frameworkDocs.d.ts +10 -0
- package/dist/bin/frameworkDocs.d.ts.map +1 -0
- package/dist/bin/frameworkDocs.js +43 -0
- package/dist/bin/frameworkDocs.js.map +1 -0
- package/dist/src/argTypes.d.ts +23 -0
- package/dist/src/argTypes.d.ts.map +1 -1
- package/dist/src/argTypes.js +27 -0
- package/dist/src/argTypes.js.map +1 -1
- package/dist/src/catalogue.d.ts +70 -3
- package/dist/src/catalogue.d.ts.map +1 -1
- package/dist/src/catalogue.js +85 -3
- package/dist/src/catalogue.js.map +1 -1
- package/dist/src/controlKeys.d.ts +85 -0
- package/dist/src/controlKeys.d.ts.map +1 -0
- package/dist/src/controlKeys.js +118 -0
- package/dist/src/controlKeys.js.map +1 -0
- package/dist/src/frame/frame.css +33 -2
- package/dist/src/frame/frameView.d.ts +2 -2
- package/dist/src/frame/frameView.d.ts.map +1 -1
- package/dist/src/frame/frameView.js +7 -3
- package/dist/src/frame/frameView.js.map +1 -1
- package/dist/src/frame/mountFrame.d.ts.map +1 -1
- package/dist/src/frame/mountFrame.js +30 -2
- package/dist/src/frame/mountFrame.js.map +1 -1
- package/dist/src/frame/spillOutline.d.ts +10 -0
- package/dist/src/frame/spillOutline.d.ts.map +1 -0
- package/dist/src/frame/spillOutline.js +80 -0
- package/dist/src/frame/spillOutline.js.map +1 -0
- package/dist/src/frame/touchDots.d.ts +32 -0
- package/dist/src/frame/touchDots.d.ts.map +1 -0
- package/dist/src/frame/touchDots.js +52 -0
- package/dist/src/frame/touchDots.js.map +1 -0
- package/dist/src/frame/touchEvents.d.ts +66 -0
- package/dist/src/frame/touchEvents.d.ts.map +1 -0
- package/dist/src/frame/touchEvents.js +152 -0
- package/dist/src/frame/touchEvents.js.map +1 -0
- package/dist/src/frame/touchGesture.d.ts +80 -0
- package/dist/src/frame/touchGesture.d.ts.map +1 -0
- package/dist/src/frame/touchGesture.js +87 -0
- package/dist/src/frame/touchGesture.js.map +1 -0
- package/dist/src/frame/touchLayer.d.ts +7 -0
- package/dist/src/frame/touchLayer.d.ts.map +1 -0
- package/dist/src/frame/touchLayer.js +399 -0
- package/dist/src/frame/touchLayer.js.map +1 -0
- package/dist/src/frame/touchScroll.d.ts +51 -0
- package/dist/src/frame/touchScroll.d.ts.map +1 -0
- package/dist/src/frame/touchScroll.js +137 -0
- package/dist/src/frame/touchScroll.js.map +1 -0
- package/dist/src/liveErrors.d.ts +57 -0
- package/dist/src/liveErrors.d.ts.map +1 -0
- package/dist/src/liveErrors.js +52 -0
- package/dist/src/liveErrors.js.map +1 -0
- package/dist/src/messages.d.ts +12 -0
- package/dist/src/messages.d.ts.map +1 -1
- package/dist/src/messages.js +4 -0
- package/dist/src/messages.js.map +1 -1
- package/dist/src/namedViews.d.ts +80 -0
- package/dist/src/namedViews.d.ts.map +1 -0
- package/dist/src/namedViews.js +88 -0
- package/dist/src/namedViews.js.map +1 -0
- package/dist/src/realTouch.d.ts +21 -0
- package/dist/src/realTouch.d.ts.map +1 -0
- package/dist/src/realTouch.js +16 -0
- package/dist/src/realTouch.js.map +1 -0
- package/dist/src/shell/AppearanceMenu.d.ts +15 -0
- package/dist/src/shell/AppearanceMenu.d.ts.map +1 -0
- package/dist/src/shell/AppearanceMenu.js +28 -0
- package/dist/src/shell/AppearanceMenu.js.map +1 -0
- package/dist/src/shell/BoxWidth.d.ts +40 -0
- package/dist/src/shell/BoxWidth.d.ts.map +1 -0
- package/dist/src/shell/BoxWidth.js +56 -0
- package/dist/src/shell/BoxWidth.js.map +1 -0
- package/dist/src/shell/ComponentPage.d.ts +17 -1
- package/dist/src/shell/ComponentPage.d.ts.map +1 -1
- package/dist/src/shell/ComponentPage.js +19 -54
- package/dist/src/shell/ComponentPage.js.map +1 -1
- package/dist/src/shell/ControlKeyField.d.ts +21 -0
- package/dist/src/shell/ControlKeyField.d.ts.map +1 -0
- package/dist/src/shell/ControlKeyField.js +46 -0
- package/dist/src/shell/ControlKeyField.js.map +1 -0
- package/dist/src/shell/ControlRow.d.ts +31 -0
- package/dist/src/shell/ControlRow.d.ts.map +1 -0
- package/dist/src/shell/ControlRow.js +30 -0
- package/dist/src/shell/ControlRow.js.map +1 -0
- package/dist/src/shell/Example.d.ts +58 -0
- package/dist/src/shell/Example.d.ts.map +1 -0
- package/dist/src/shell/Example.js +89 -0
- package/dist/src/shell/Example.js.map +1 -0
- package/dist/src/shell/InfoTip.d.ts +23 -0
- package/dist/src/shell/InfoTip.d.ts.map +1 -0
- package/dist/src/shell/InfoTip.js +51 -0
- package/dist/src/shell/InfoTip.js.map +1 -0
- package/dist/src/shell/NamedViews.d.ts +23 -0
- package/dist/src/shell/NamedViews.d.ts.map +1 -0
- package/dist/src/shell/NamedViews.js +49 -0
- package/dist/src/shell/NamedViews.js.map +1 -0
- package/dist/src/shell/PinnedControl.d.ts +25 -0
- package/dist/src/shell/PinnedControl.d.ts.map +1 -0
- package/dist/src/shell/PinnedControl.js +82 -0
- package/dist/src/shell/PinnedControl.js.map +1 -0
- package/dist/src/shell/PropsTab.d.ts +5 -2
- package/dist/src/shell/PropsTab.d.ts.map +1 -1
- package/dist/src/shell/PropsTab.js +12 -15
- package/dist/src/shell/PropsTab.js.map +1 -1
- package/dist/src/shell/Shell.d.ts.map +1 -1
- package/dist/src/shell/Shell.js +27 -2
- package/dist/src/shell/Shell.js.map +1 -1
- package/dist/src/shell/Sidebar.d.ts +11 -9
- package/dist/src/shell/Sidebar.d.ts.map +1 -1
- package/dist/src/shell/Sidebar.js +48 -42
- package/dist/src/shell/Sidebar.js.map +1 -1
- package/dist/src/shell/SidebarEntries.d.ts +50 -0
- package/dist/src/shell/SidebarEntries.d.ts.map +1 -0
- package/dist/src/shell/SidebarEntries.js +51 -0
- package/dist/src/shell/SidebarEntries.js.map +1 -0
- package/dist/src/shell/Stage.d.ts.map +1 -1
- package/dist/src/shell/Stage.js +19 -2
- package/dist/src/shell/Stage.js.map +1 -1
- package/dist/src/shell/Toolbar.d.ts +7 -3
- package/dist/src/shell/Toolbar.d.ts.map +1 -1
- package/dist/src/shell/Toolbar.js +38 -68
- package/dist/src/shell/Toolbar.js.map +1 -1
- package/dist/src/shell/ToolbarControl.d.ts +47 -0
- package/dist/src/shell/ToolbarControl.d.ts.map +1 -0
- package/dist/src/shell/ToolbarControl.js +150 -0
- package/dist/src/shell/ToolbarControl.js.map +1 -0
- package/dist/src/shell/UsedIn.d.ts +38 -0
- package/dist/src/shell/UsedIn.d.ts.map +1 -0
- package/dist/src/shell/UsedIn.js +77 -0
- package/dist/src/shell/UsedIn.js.map +1 -0
- package/dist/src/shell/ViewMenu.d.ts +37 -0
- package/dist/src/shell/ViewMenu.d.ts.map +1 -0
- package/dist/src/shell/ViewMenu.js +219 -0
- package/dist/src/shell/ViewMenu.js.map +1 -0
- package/dist/src/shell/controlCycle.d.ts +28 -0
- package/dist/src/shell/controlCycle.d.ts.map +1 -0
- package/dist/src/shell/controlCycle.js +51 -0
- package/dist/src/shell/controlCycle.js.map +1 -0
- package/dist/src/shell/dockTabs.d.ts +3 -0
- package/dist/src/shell/dockTabs.d.ts.map +1 -1
- package/dist/src/shell/dockTabs.js +1 -1
- package/dist/src/shell/dockTabs.js.map +1 -1
- package/dist/src/shell/icons.d.ts +7 -0
- package/dist/src/shell/icons.d.ts.map +1 -1
- package/dist/src/shell/icons.js +8 -1
- package/dist/src/shell/icons.js.map +1 -1
- package/dist/src/shell/keyboard.d.ts +2 -1
- package/dist/src/shell/keyboard.d.ts.map +1 -1
- package/dist/src/shell/keyboard.js +5 -2
- package/dist/src/shell/keyboard.js.map +1 -1
- package/dist/src/shell/shell.css +876 -244
- package/dist/src/shell/strings.d.ts +46 -0
- package/dist/src/shell/strings.d.ts.map +1 -1
- package/dist/src/shell/strings.js +46 -0
- package/dist/src/shell/strings.js.map +1 -1
- package/dist/src/shell/useAppearance.d.ts +17 -0
- package/dist/src/shell/useAppearance.d.ts.map +1 -0
- package/dist/src/shell/useAppearance.js +36 -0
- package/dist/src/shell/useAppearance.js.map +1 -0
- package/dist/src/shell/useControlKeys.d.ts +23 -0
- package/dist/src/shell/useControlKeys.d.ts.map +1 -0
- package/dist/src/shell/useControlKeys.js +44 -0
- package/dist/src/shell/useControlKeys.js.map +1 -0
- package/dist/src/shell/useFold.d.ts +27 -0
- package/dist/src/shell/useFold.d.ts.map +1 -0
- package/dist/src/shell/useFold.js +87 -0
- package/dist/src/shell/useFold.js.map +1 -0
- package/dist/src/shell/useFrameMessages.d.ts +2 -0
- package/dist/src/shell/useFrameMessages.d.ts.map +1 -1
- package/dist/src/shell/useFrameMessages.js +3 -0
- package/dist/src/shell/useFrameMessages.js.map +1 -1
- package/dist/src/shell/useFullPage.d.ts +45 -0
- package/dist/src/shell/useFullPage.d.ts.map +1 -0
- package/dist/src/shell/useFullPage.js +149 -0
- package/dist/src/shell/useFullPage.js.map +1 -0
- package/dist/src/shell/usePopover.d.ts +17 -3
- package/dist/src/shell/usePopover.d.ts.map +1 -1
- package/dist/src/shell/usePopover.js +65 -4
- package/dist/src/shell/usePopover.js.map +1 -1
- package/dist/src/shell/useStored.d.ts +13 -2
- package/dist/src/shell/useStored.d.ts.map +1 -1
- package/dist/src/shell/useStored.js +1 -1
- package/dist/src/shell/useStored.js.map +1 -1
- package/dist/src/shell/useToolbarLayout.d.ts +39 -0
- package/dist/src/shell/useToolbarLayout.d.ts.map +1 -0
- package/dist/src/shell/useToolbarLayout.js +58 -0
- package/dist/src/shell/useToolbarLayout.js.map +1 -0
- package/dist/src/shell/useToolbarOverflow.d.ts +31 -0
- package/dist/src/shell/useToolbarOverflow.d.ts.map +1 -0
- package/dist/src/shell/useToolbarOverflow.js +62 -0
- package/dist/src/shell/useToolbarOverflow.js.map +1 -0
- package/dist/src/shell/useWorstCase.d.ts +46 -0
- package/dist/src/shell/useWorstCase.d.ts.map +1 -0
- package/dist/src/shell/useWorstCase.js +42 -0
- package/dist/src/shell/useWorstCase.js.map +1 -0
- package/dist/src/shell/worstArgs.d.ts +42 -0
- package/dist/src/shell/worstArgs.d.ts.map +1 -0
- package/dist/src/shell/worstArgs.js +47 -0
- package/dist/src/shell/worstArgs.js.map +1 -0
- package/dist/src/spills.d.ts +31 -0
- package/dist/src/spills.d.ts.map +1 -0
- package/dist/src/spills.js +65 -0
- package/dist/src/spills.js.map +1 -0
- package/dist/src/storyCheck.d.ts +105 -0
- package/dist/src/storyCheck.d.ts.map +1 -0
- package/dist/src/storyCheck.js +63 -0
- package/dist/src/storyCheck.js.map +1 -0
- package/dist/src/switches.d.ts +26 -4
- package/dist/src/switches.d.ts.map +1 -1
- package/dist/src/switches.js +50 -5
- package/dist/src/switches.js.map +1 -1
- package/dist/src/toolbarLayout.d.ts +119 -0
- package/dist/src/toolbarLayout.d.ts.map +1 -0
- package/dist/src/toolbarLayout.js +155 -0
- package/dist/src/toolbarLayout.js.map +1 -0
- package/dist/src/usedIn.d.ts +60 -0
- package/dist/src/usedIn.d.ts.map +1 -0
- package/dist/src/usedIn.js +92 -0
- package/dist/src/usedIn.js.map +1 -0
- package/dist/src/viewState.d.ts +9 -11
- package/dist/src/viewState.d.ts.map +1 -1
- package/dist/src/viewState.js +24 -20
- package/dist/src/viewState.js.map +1 -1
- package/dist/src/viewWords.d.ts +26 -0
- package/dist/src/viewWords.d.ts.map +1 -0
- package/dist/src/viewWords.js +29 -0
- package/dist/src/viewWords.js.map +1 -0
- package/dist/src/vite/adapter.d.ts +13 -4
- package/dist/src/vite/adapter.d.ts.map +1 -1
- package/dist/src/vite/adapter.js +4 -2
- package/dist/src/vite/adapter.js.map +1 -1
- package/dist/src/vite/agent.types.d.ts +32 -2
- package/dist/src/vite/agent.types.d.ts.map +1 -1
- package/dist/src/vite/agentApi.d.ts +15 -3
- package/dist/src/vite/agentApi.d.ts.map +1 -1
- package/dist/src/vite/agentApi.js +63 -9
- package/dist/src/vite/agentApi.js.map +1 -1
- package/dist/src/vite/agentRoutes.d.ts +8 -3
- package/dist/src/vite/agentRoutes.d.ts.map +1 -1
- package/dist/src/vite/agentRoutes.js +84 -23
- package/dist/src/vite/agentRoutes.js.map +1 -1
- package/dist/src/vite/configFile.d.ts +2 -1
- package/dist/src/vite/configFile.d.ts.map +1 -1
- package/dist/src/vite/configFile.js +29 -11
- package/dist/src/vite/configFile.js.map +1 -1
- package/dist/src/vite/docsExtractor.d.ts +26 -2
- package/dist/src/vite/docsExtractor.d.ts.map +1 -1
- package/dist/src/vite/docsExtractor.js +12 -9
- package/dist/src/vite/docsExtractor.js.map +1 -1
- package/dist/src/vite/docsWorker.js +18 -2
- package/dist/src/vite/docsWorker.js.map +1 -1
- package/dist/src/vite/forcedStates.d.ts +6 -2
- package/dist/src/vite/forcedStates.d.ts.map +1 -1
- package/dist/src/vite/forcedStates.js +20 -4
- package/dist/src/vite/forcedStates.js.map +1 -1
- package/dist/src/vite/forgebookPlugin.d.ts.map +1 -1
- package/dist/src/vite/forgebookPlugin.js +104 -16
- package/dist/src/vite/forgebookPlugin.js.map +1 -1
- package/dist/src/vite/indexStoryFile.d.ts +14 -0
- package/dist/src/vite/indexStoryFile.d.ts.map +1 -1
- package/dist/src/vite/indexStoryFile.js +13 -4
- package/dist/src/vite/indexStoryFile.js.map +1 -1
- package/dist/src/vite/mcpProtocol.d.ts +9 -0
- package/dist/src/vite/mcpProtocol.d.ts.map +1 -1
- package/dist/src/vite/mcpProtocol.js +6 -3
- package/dist/src/vite/mcpProtocol.js.map +1 -1
- package/dist/src/vite/storyFilesModule.d.ts +44 -1
- package/dist/src/vite/storyFilesModule.d.ts.map +1 -1
- package/dist/src/vite/storyFilesModule.js +49 -14
- package/dist/src/vite/storyFilesModule.js.map +1 -1
- package/dist/src/vite/touchMedia.d.ts +35 -0
- package/dist/src/vite/touchMedia.d.ts.map +1 -0
- package/dist/src/vite/touchMedia.js +187 -0
- package/dist/src/vite/touchMedia.js.map +1 -0
- package/dist/src/vite/usageGraph.d.ts +45 -0
- package/dist/src/vite/usageGraph.d.ts.map +1 -0
- package/dist/src/vite/usageGraph.js +246 -0
- package/dist/src/vite/usageGraph.js.map +1 -0
- package/dist/src/vite/usageModule.d.ts +33 -0
- package/dist/src/vite/usageModule.d.ts.map +1 -0
- package/dist/src/vite/usageModule.js +135 -0
- package/dist/src/vite/usageModule.js.map +1 -0
- package/dist/src/worstCase.d.ts +16 -0
- package/dist/src/worstCase.d.ts.map +1 -0
- package/dist/src/worstCase.js +16 -0
- package/dist/src/worstCase.js.map +1 -0
- package/package.json +18 -2
- package/dist/src/shell/SchemeSwitches.d.ts +0 -24
- package/dist/src/shell/SchemeSwitches.d.ts.map +0 -1
- package/dist/src/shell/SchemeSwitches.js +0 -36
- package/dist/src/shell/SchemeSwitches.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The module that answers a `?forgebook-files` import: every story file a pattern matches, as one module with each
|
|
3
|
-
* file's index (read from its source, never run)
|
|
3
|
+
* file's index (read from its source, never run), the loaders of its module, its component's docs and its code, and
|
|
4
|
+
* the group's "Used in" loader.
|
|
4
5
|
*
|
|
5
6
|
* @remarks
|
|
6
7
|
* One module per pattern, instead of an import per file: in development the browser fetched every index module one by
|
|
@@ -13,6 +14,21 @@ import { globSync, readFileSync } from "node:fs";
|
|
|
13
14
|
import { join, relative, resolve } from "node:path";
|
|
14
15
|
import { autoTitle, patternBase } from "./autoTitle.js";
|
|
15
16
|
import { indexStoryFile } from "./indexStoryFile.js";
|
|
17
|
+
/**
|
|
18
|
+
* The folder and the pattern a `?forgebook-files` import is read from: the pattern's leading `./` and `../` move into
|
|
19
|
+
* the folder. The catalogue's plugin keys the files this way (its modules' ids hold no `..`, which a URL path would
|
|
20
|
+
* collapse), and so does the testing package, so both list the same keys (`./src/x.stories.tsx`).
|
|
21
|
+
*
|
|
22
|
+
* @param folder - the importing module's folder.
|
|
23
|
+
* @param pattern - the pattern as the import writes it (`../src/**\/*.stories.tsx`).
|
|
24
|
+
*/
|
|
25
|
+
export const storyFilesGroup = (folder, pattern) => {
|
|
26
|
+
const segments = pattern.split("/");
|
|
27
|
+
const firstOwn = segments.findIndex((segment) => segment !== "." && segment !== "..");
|
|
28
|
+
const climbed = firstOwn === -1 ? segments : segments.slice(0, firstOwn);
|
|
29
|
+
const own = firstOwn === -1 ? [] : segments.slice(firstOwn);
|
|
30
|
+
return { root: resolve(folder, ...climbed), pattern: own.join("/") };
|
|
31
|
+
};
|
|
16
32
|
/**
|
|
17
33
|
* The story files patterns match, as paths relative to `root` starting with `./` or `../`, sorted.
|
|
18
34
|
*
|
|
@@ -26,6 +42,30 @@ export const storyFileKeys = (root, patterns) => patterns
|
|
|
26
42
|
return path.startsWith(".") ? path : `./${path}`;
|
|
27
43
|
})
|
|
28
44
|
.sort();
|
|
45
|
+
/**
|
|
46
|
+
* The id prefix of a group's "Used in" module: the pattern's folder and the pattern follow, as in a `?forgebook-files`
|
|
47
|
+
* module's id. The plugin answers it (`usageModule.ts`) only when a page asks.
|
|
48
|
+
*/
|
|
49
|
+
export const USAGE_PREFIX = "virtual:forgebook-usage:";
|
|
50
|
+
/** Between the folder and the pattern in a usage module's id: no path or pattern holds it. */
|
|
51
|
+
export const USAGE_SEPARATOR = "::";
|
|
52
|
+
/**
|
|
53
|
+
* Every story file a pattern matches, indexed.
|
|
54
|
+
*
|
|
55
|
+
* @param root - the declaring module's folder.
|
|
56
|
+
* @param pattern - the pattern.
|
|
57
|
+
* @param watch - adds a file whose edit renews the module that read it.
|
|
58
|
+
* @throws when a story file cannot be indexed.
|
|
59
|
+
*/
|
|
60
|
+
export const indexedStoryFiles = (root, pattern, watch) => storyFileKeys(root, [pattern]).map((key) => {
|
|
61
|
+
const file = resolve(root, key);
|
|
62
|
+
watch(file);
|
|
63
|
+
const title = autoTitle(patternBase(pattern), key);
|
|
64
|
+
const index = indexStoryFile(file, readFileSync(file, "utf8"), title === undefined ? {} : { autoTitle: title });
|
|
65
|
+
if (typeof index === "string")
|
|
66
|
+
throw new Error(index);
|
|
67
|
+
return { key, file, index };
|
|
68
|
+
});
|
|
29
69
|
/** An object literal of a key per file, each value written by `value`. */
|
|
30
70
|
const objectOf = (keys, value) => `{${keys.map((key) => `${JSON.stringify(key)}: ${value(key)}`).join(",\n")}}`;
|
|
31
71
|
/**
|
|
@@ -34,20 +74,14 @@ const objectOf = (keys, value) => `{${keys.map((key) => `${JSON.stringify(key)}:
|
|
|
34
74
|
* @param root - the declaring module's folder.
|
|
35
75
|
* @param pattern - the pattern before `?forgebook-files`.
|
|
36
76
|
* @param watch - adds a file whose edit renews the module (each story file: its index is in the module).
|
|
77
|
+
* @param hasUsage - whether the group offers its "Used in" loader (the catalogue did not turn it off).
|
|
37
78
|
* @returns the module's code, or a message saying which file cannot be indexed.
|
|
38
79
|
*/
|
|
39
|
-
export const storyFilesModule = (root, pattern, watch) => {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
watch(file);
|
|
45
|
-
const title = autoTitle(patternBase(pattern), key);
|
|
46
|
-
const entry = indexStoryFile(file, readFileSync(file, "utf8"), title === undefined ? {} : { autoTitle: title });
|
|
47
|
-
if (typeof entry === "string")
|
|
48
|
-
throw new Error(entry);
|
|
49
|
-
index[key] = entry;
|
|
50
|
-
}
|
|
80
|
+
export const storyFilesModule = (root, pattern, watch, hasUsage = true) => {
|
|
81
|
+
const files = indexedStoryFiles(root, pattern, watch);
|
|
82
|
+
const keys = files.map((file) => file.key);
|
|
83
|
+
const index = Object.fromEntries(files.map((file) => [file.key, file.index]));
|
|
84
|
+
const usage = JSON.stringify(`${USAGE_PREFIX}${root}${USAGE_SEPARATOR}${pattern}`);
|
|
51
85
|
// absolute paths: the module has no folder of its own; Vite serves them under /@fs/ in development
|
|
52
86
|
const path = (key) => JSON.stringify(resolve(root, key));
|
|
53
87
|
const query = (key, name) => JSON.stringify(`${resolve(root, key)}?${name}`);
|
|
@@ -57,7 +91,8 @@ export const storyFilesModule = (root, pattern, watch) => {
|
|
|
57
91
|
`stories: ${objectOf(keys, (key) => `() => import(${path(key)})`)},`,
|
|
58
92
|
`docs: ${objectOf(keys, (key) => `() => import(${query(key, "forgebook-docs")}).then((module) => module.default)`)},`,
|
|
59
93
|
`code: ${objectOf(keys, (key) => `() => import(${query(key, "forgebook-code")}).then((module) => module.default)`)},`,
|
|
60
|
-
`pages: ${objectOf(keys, (key) => `() => import(${query(key, "forgebook-page")}).then((module) => module.default)`)}`,
|
|
94
|
+
`pages: ${objectOf(keys, (key) => `() => import(${query(key, "forgebook-page")}).then((module) => module.default)`)}${hasUsage ? "," : ""}`,
|
|
95
|
+
...(hasUsage ? [`usage: () => import(${usage}).then((module) => module.default)`] : []),
|
|
61
96
|
"};"
|
|
62
97
|
].join("\n");
|
|
63
98
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storyFilesModule.js","sourceRoot":"","sources":["../../../src/vite/storyFilesModule.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"storyFilesModule.js","sourceRoot":"","sources":["../../../src/vite/storyFilesModule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAUrD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,OAAe,EAAmB,EAAE;IAClF,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC;IACtF,MAAM,OAAO,GAAG,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACzE,MAAM,GAAG,GAAG,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC5D,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC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IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACzE,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IACrG,OAAO;QACL,kBAAkB;QAClB,UAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG;QAClC,YAAY,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG;QACpE,SAAS,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,KAAK,CAAC,GAAG,EAAE,gBAAgB,CAAC,oCAAoC,CAAC,GAAG;QACrH,SAAS,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,KAAK,CAAC,GAAG,EAAE,gBAAgB,CAAC,oCAAoC,CAAC,GAAG;QACrH,UAAU,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,KAAK,CAAC,GAAG,EAAE,gBAAgB,CAAC,oCAAoC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC3I,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,uBAAuB,KAAK,oCAAoC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvF,IAAI;KACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rewrite that lets a story's CSS answer as a phone's while the catalogue simulates touch: the rules under the
|
|
3
|
+
* pointer's media features (`hover`, `any-hover`, `pointer`, `any-pointer`) follow `data-forgebook-touch` on the root.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The computer answers `hover: hover` and `pointer: fine`, and a page cannot change that. So each media rule that asks
|
|
7
|
+
* about the pointer is kept for the computer, its rules scoped to a root without the attribute, and copied once more
|
|
8
|
+
* as a phone would read it (`hover: none`, `pointer: coarse`, the rest of its query kept), its rules scoped to a root
|
|
9
|
+
* with the attribute. The scope is written in `:where()`, so no rule's specificity changes; a selector that starts at
|
|
10
|
+
* the root (`:root`, `html`) takes the condition on the root itself. On a real phone the attribute is never set, so
|
|
11
|
+
* its own media answer as before. The real mouse's `:hover` stops matching while touch is simulated: a finger does
|
|
12
|
+
* not hover (`NOT_UNDER_TOUCH`). Runs only in the catalogue's build, as a Lightning CSS visitor.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
import type { Rule, SelectorComponent } from "lightningcss";
|
|
17
|
+
/** The root's attribute the catalogue sets while it simulates touch (`touchSwitch` of `switches.ts`). */
|
|
18
|
+
export declare const TOUCH_ATTRIBUTE = "data-forgebook-touch";
|
|
19
|
+
/**
|
|
20
|
+
* A media rule as the computer and as a simulated phone read it: the rule for the computer, its rules scoped to a
|
|
21
|
+
* root without the attribute, then, when a phone can match it, its copy with the pointer answered as a phone's, its
|
|
22
|
+
* rules scoped to a root with the attribute. A media rule that asks nothing of the pointer is left as it is.
|
|
23
|
+
*
|
|
24
|
+
* @param rule - a media rule.
|
|
25
|
+
*/
|
|
26
|
+
export declare const touchMediaRules: (rule: Extract<Rule, {
|
|
27
|
+
type: "media";
|
|
28
|
+
}>) => Rule[] | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* `:where(:not(:root[data-forgebook-touch] *))`: an element outside a root that simulates touch. Written beside the
|
|
31
|
+
* real `:hover` (`forcedStates.ts`), so the mouse's hover stops matching while touch is simulated: a finger does not
|
|
32
|
+
* hover.
|
|
33
|
+
*/
|
|
34
|
+
export declare const NOT_UNDER_TOUCH: SelectorComponent;
|
|
35
|
+
//# sourceMappingURL=touchMedia.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touchMedia.d.ts","sourceRoot":"","sources":["../../../src/vite/touchMedia.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAGV,IAAI,EAEJ,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAEtB,yGAAyG;AACzG,eAAO,MAAM,eAAe,yBAAyB,CAAC;AAsJtD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,OAAO,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,KAAG,IAAI,EAAE,GAAG,SAkBjF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,iBAmB7B,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/** The root's attribute the catalogue sets while it simulates touch (`touchSwitch` of `switches.ts`). */
|
|
2
|
+
export const TOUCH_ATTRIBUTE = "data-forgebook-touch";
|
|
3
|
+
/** The pointer's media features, and what a phone answers to each. */
|
|
4
|
+
const PHONE_ANSWERS = {
|
|
5
|
+
hover: { value: "none", isPresent: false },
|
|
6
|
+
"any-hover": { value: "none", isPresent: false },
|
|
7
|
+
pointer: { value: "coarse", isPresent: true },
|
|
8
|
+
"any-pointer": { value: "coarse", isPresent: true }
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A feature as a phone answers it; another feature stays a condition.
|
|
12
|
+
*
|
|
13
|
+
* @param feature - the feature.
|
|
14
|
+
*/
|
|
15
|
+
const phoneFeature = (feature) => {
|
|
16
|
+
if (feature.type === "range" || feature.type === "interval")
|
|
17
|
+
return undefined;
|
|
18
|
+
const answer = PHONE_ANSWERS[feature.name];
|
|
19
|
+
if (answer === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (feature.type === "boolean")
|
|
22
|
+
return answer.isPresent;
|
|
23
|
+
return feature.value.type === "ident" && feature.value.value === answer.value;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A condition read as a phone would.
|
|
27
|
+
*
|
|
28
|
+
* @param condition - the condition.
|
|
29
|
+
*/
|
|
30
|
+
const phoneCondition = (condition) => {
|
|
31
|
+
if (condition.type === "feature")
|
|
32
|
+
return phoneFeature(condition.value) ?? condition;
|
|
33
|
+
if (condition.type === "not") {
|
|
34
|
+
const inner = phoneCondition(condition.value);
|
|
35
|
+
return typeof inner === "boolean" ? !inner : { type: "not", value: inner };
|
|
36
|
+
}
|
|
37
|
+
if (condition.type !== "operation")
|
|
38
|
+
return condition;
|
|
39
|
+
const isAnd = condition.operator === "and";
|
|
40
|
+
const parts = [];
|
|
41
|
+
for (const each of condition.conditions.map(phoneCondition)) {
|
|
42
|
+
// in an "and", false decides and true drops out; in an "or", the other way round
|
|
43
|
+
if (each === !isAnd)
|
|
44
|
+
return !isAnd;
|
|
45
|
+
if (typeof each !== "boolean")
|
|
46
|
+
parts.push(each);
|
|
47
|
+
}
|
|
48
|
+
if (parts.length === 0)
|
|
49
|
+
return isAnd;
|
|
50
|
+
return parts.length === 1 && parts[0] !== undefined ? parts[0] : { ...condition, conditions: parts };
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Whether a condition asks about the pointer anywhere.
|
|
54
|
+
*
|
|
55
|
+
* @param condition - the condition.
|
|
56
|
+
*/
|
|
57
|
+
const asksPointer = (condition) => {
|
|
58
|
+
if (condition.type === "feature")
|
|
59
|
+
return (condition.value.type !== "range" &&
|
|
60
|
+
condition.value.type !== "interval" &&
|
|
61
|
+
condition.value.name in PHONE_ANSWERS);
|
|
62
|
+
if (condition.type === "not")
|
|
63
|
+
return asksPointer(condition.value);
|
|
64
|
+
return condition.type === "operation" && condition.conditions.some(asksPointer);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* The queries a phone reads in a list: each query its pointer features answered; one a phone never matches dropped.
|
|
68
|
+
*
|
|
69
|
+
* @param queries - the media rule's queries.
|
|
70
|
+
* @returns the queries; none when a phone matches none of them.
|
|
71
|
+
*/
|
|
72
|
+
const phoneQueries = (queries) => queries.flatMap((query) => {
|
|
73
|
+
if (query.condition === null || query.condition === undefined)
|
|
74
|
+
return [query];
|
|
75
|
+
let reading = phoneCondition(query.condition);
|
|
76
|
+
if (query.qualifier === "not" && typeof reading === "boolean")
|
|
77
|
+
reading = !reading;
|
|
78
|
+
if (reading === false)
|
|
79
|
+
return [];
|
|
80
|
+
return [
|
|
81
|
+
reading === true ? { ...query, qualifier: null, condition: null } : { ...query, condition: reading }
|
|
82
|
+
];
|
|
83
|
+
});
|
|
84
|
+
/** `[data-forgebook-touch]`. */
|
|
85
|
+
const TOUCH = { type: "attribute", name: TOUCH_ATTRIBUTE };
|
|
86
|
+
/**
|
|
87
|
+
* The root's condition: with the attribute, or without it.
|
|
88
|
+
*
|
|
89
|
+
* @param isTouch - whether touch is simulated.
|
|
90
|
+
*/
|
|
91
|
+
const rootCondition = (isTouch) => isTouch ? TOUCH : { type: "pseudo-class", kind: "not", selectors: [[TOUCH]] };
|
|
92
|
+
/**
|
|
93
|
+
* A selector scoped to a root with touch simulated or without: the condition on the root itself when the selector
|
|
94
|
+
* starts there, a descendant of such a root otherwise, in `:where()` either way.
|
|
95
|
+
*
|
|
96
|
+
* @param selector - the selector.
|
|
97
|
+
* @param isTouch - whether touch is simulated.
|
|
98
|
+
*/
|
|
99
|
+
const scopedSelector = (selector, isTouch) => {
|
|
100
|
+
const condition = {
|
|
101
|
+
type: "pseudo-class",
|
|
102
|
+
kind: "where",
|
|
103
|
+
selectors: [[rootCondition(isTouch)]]
|
|
104
|
+
};
|
|
105
|
+
const firstCombinator = selector.findIndex((component) => component.type === "combinator");
|
|
106
|
+
const head = firstCombinator === -1 ? selector : selector.slice(0, firstCombinator);
|
|
107
|
+
const isAtRoot = head.some((component) => (component.type === "pseudo-class" && component.kind === "root") ||
|
|
108
|
+
(component.type === "type" && component.name === "html"));
|
|
109
|
+
if (isAtRoot)
|
|
110
|
+
return [...head, condition, ...selector.slice(head.length)];
|
|
111
|
+
const root = {
|
|
112
|
+
type: "pseudo-class",
|
|
113
|
+
kind: "where",
|
|
114
|
+
selectors: [[{ type: "pseudo-class", kind: "root" }, rootCondition(isTouch)]]
|
|
115
|
+
};
|
|
116
|
+
return [root, { type: "combinator", value: "descendant" }, ...selector];
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Rules scoped to a root with touch simulated or without, inside the rules that group them (`@supports`, `@layer`,
|
|
120
|
+
* `@container`, another `@media`); a nested rule keeps its own selectors, relative to its scoped parent.
|
|
121
|
+
*
|
|
122
|
+
* @param rules - the rules.
|
|
123
|
+
* @param isTouch - whether touch is simulated.
|
|
124
|
+
*/
|
|
125
|
+
const scopedRules = (rules, isTouch) => rules.map((rule) => {
|
|
126
|
+
if (rule.type === "style") {
|
|
127
|
+
return {
|
|
128
|
+
...rule,
|
|
129
|
+
value: { ...rule.value, selectors: rule.value.selectors.map((each) => scopedSelector(each, isTouch)) }
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (rule.type === "media" ||
|
|
133
|
+
rule.type === "supports" ||
|
|
134
|
+
rule.type === "container" ||
|
|
135
|
+
rule.type === "layer-block")
|
|
136
|
+
return { ...rule, value: { ...rule.value, rules: scopedRules(rule.value.rules, isTouch) } };
|
|
137
|
+
return rule;
|
|
138
|
+
});
|
|
139
|
+
/**
|
|
140
|
+
* A media rule as the computer and as a simulated phone read it: the rule for the computer, its rules scoped to a
|
|
141
|
+
* root without the attribute, then, when a phone can match it, its copy with the pointer answered as a phone's, its
|
|
142
|
+
* rules scoped to a root with the attribute. A media rule that asks nothing of the pointer is left as it is.
|
|
143
|
+
*
|
|
144
|
+
* @param rule - a media rule.
|
|
145
|
+
*/
|
|
146
|
+
export const touchMediaRules = (rule) => {
|
|
147
|
+
const queries = rule.value.query.mediaQueries;
|
|
148
|
+
if (!queries.some((query) => query.condition !== null && query.condition !== undefined && asksPointer(query.condition)))
|
|
149
|
+
return undefined;
|
|
150
|
+
const computer = { ...rule, value: { ...rule.value, rules: scopedRules(rule.value.rules, false) } };
|
|
151
|
+
const phone = phoneQueries(queries);
|
|
152
|
+
if (phone.length === 0)
|
|
153
|
+
return [computer];
|
|
154
|
+
return [
|
|
155
|
+
computer,
|
|
156
|
+
{
|
|
157
|
+
...rule,
|
|
158
|
+
value: { ...rule.value, query: { mediaQueries: phone }, rules: scopedRules(rule.value.rules, true) }
|
|
159
|
+
}
|
|
160
|
+
];
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* `:where(:not(:root[data-forgebook-touch] *))`: an element outside a root that simulates touch. Written beside the
|
|
164
|
+
* real `:hover` (`forcedStates.ts`), so the mouse's hover stops matching while touch is simulated: a finger does not
|
|
165
|
+
* hover.
|
|
166
|
+
*/
|
|
167
|
+
export const NOT_UNDER_TOUCH = {
|
|
168
|
+
type: "pseudo-class",
|
|
169
|
+
kind: "where",
|
|
170
|
+
selectors: [
|
|
171
|
+
[
|
|
172
|
+
{
|
|
173
|
+
type: "pseudo-class",
|
|
174
|
+
kind: "not",
|
|
175
|
+
selectors: [
|
|
176
|
+
[
|
|
177
|
+
{ type: "pseudo-class", kind: "root" },
|
|
178
|
+
TOUCH,
|
|
179
|
+
{ type: "combinator", value: "descendant" },
|
|
180
|
+
{ type: "universal" }
|
|
181
|
+
]
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
]
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=touchMedia.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touchMedia.js","sourceRoot":"","sources":["../../../src/vite/touchMedia.ts"],"names":[],"mappings":"AAuBA,yGAAyG;AACzG,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAKtD,sEAAsE;AACtE,MAAM,aAAa,GAAsF;IACvG,KAAK,EAAE,E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CAAC;QAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1C,OAAO;QACL,QAAQ;QACR;YACE,GAAG,IAAI;YACP,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;SACrG;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAsB;IAChD,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,OAAO;IACb,SAAS,EAAE;QACT;YACE;gBACE,IAAI,EAAE,cAAc;gBACpB,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE;oBACT;wBACE,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE;wBACtC,KAAK;wBACL,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE;wBAC3C,EAAE,IAAI,EAAE,WAAW,EAAE;qBACtB;iBACF;aACF;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** A component, by the file that declares it and its name there. */
|
|
2
|
+
export type ComponentRef = {
|
|
3
|
+
/** The declaring file's absolute path. */
|
|
4
|
+
readonly file: string;
|
|
5
|
+
/** Its name in that file (`default` for a default export). */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
};
|
|
8
|
+
/** What one story renders. */
|
|
9
|
+
export type StoryRenders = {
|
|
10
|
+
/** The story's export. */
|
|
11
|
+
readonly exportName: string;
|
|
12
|
+
/** The components its JSX names, or its meta's component when it has none; each once. */
|
|
13
|
+
readonly renders: readonly ComponentRef[];
|
|
14
|
+
};
|
|
15
|
+
/** One story file's facts. */
|
|
16
|
+
export type StoryFileUsage = {
|
|
17
|
+
/** The story file's absolute path. */
|
|
18
|
+
readonly storyFile: string;
|
|
19
|
+
/** Its meta's component, when the meta names one the checker resolves. */
|
|
20
|
+
readonly component?: ComponentRef;
|
|
21
|
+
/** Its stories. */
|
|
22
|
+
readonly stories: readonly StoryRenders[];
|
|
23
|
+
};
|
|
24
|
+
/** What the worker answers for a group of story files. */
|
|
25
|
+
export type UsageGraph = {
|
|
26
|
+
/** Each story file's facts, in the order asked; a file no program holds is left out. */
|
|
27
|
+
readonly files: readonly StoryFileUsage[];
|
|
28
|
+
/** Each module the rendered components reach, with the package's own modules it imports. */
|
|
29
|
+
readonly imports: Readonly<Record<string, readonly string[]>>;
|
|
30
|
+
};
|
|
31
|
+
/** A story file and the exports the index lists as its stories. */
|
|
32
|
+
export type UsageRequestFile = {
|
|
33
|
+
/** The story file's absolute path. */
|
|
34
|
+
readonly storyFile: string;
|
|
35
|
+
/** Its stories' exports. */
|
|
36
|
+
readonly exports: readonly string[];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The facts of a group of story files: what each story renders, and the import graph the rendered components reach.
|
|
40
|
+
*
|
|
41
|
+
* @param requests - the story files and their stories' exports.
|
|
42
|
+
* @returns the facts, or why a story file's program could not be read.
|
|
43
|
+
*/
|
|
44
|
+
export declare const usageGraph: (requests: readonly UsageRequestFile[]) => UsageGraph | string;
|
|
45
|
+
//# sourceMappingURL=usageGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usageGraph.d.ts","sourceRoot":"","sources":["../../../src/vite/usageGraph.ts"],"names":[],"mappings":"AAoBA,oEAAoE;AACpE,MAAM,MAAM,YAAY,GAAG;IACzB,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,8BAA8B;AAC9B,MAAM,MAAM,YAAY,GAAG;IACzB,0BAA0B;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,yFAAyF;IACzF,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C,CAAC;AAEF,8BAA8B;AAC9B,MAAM,MAAM,cAAc,GAAG;IAC3B,sCAAsC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC;IAClC,mBAAmB;IACnB,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C,CAAC;AAEF,0DAA0D;AAC1D,MAAM,MAAM,UAAU,GAAG;IACvB,wFAAwF;IACxF,QAAQ,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;IAC1C,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAC/D,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4BAA4B;IAC5B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,CAAC;AA0PF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,SAAS,gBAAgB,EAAE,KAAG,UAAU,GAAG,MAe/E,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each story renders and what each module imports, read from the TypeScript programs the docs already build:
|
|
3
|
+
* the facts "Used in" is joined from (`usageModule.ts`).
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Runs in the docs worker (`docsWorker.ts`), which holds the programs; a package's first read builds its program,
|
|
7
|
+
* the API tables reuse it. A story renders the components its JSX names, resolved by the type checker as its types are
|
|
8
|
+
* (a package-name import, an alias, `<Menu.Item>`); a component declared in the story file itself (a scene) is followed
|
|
9
|
+
* into its own JSX; a story without JSX renders its meta's component. A component is known by the file that declares
|
|
10
|
+
* it and its name there, so two imports of one component are one. The import graph holds the modules the rendered
|
|
11
|
+
* components reach through the package's own imports, never a dependency's (`node_modules`): "used through" follows
|
|
12
|
+
* those edges. A lowercase tag is an element (`<div>`), not a component. A component reached only through code the
|
|
13
|
+
* checker cannot follow (a computed lazy import, a component handed in as a prop) is not found.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import ts from "typescript-6";
|
|
18
|
+
import { programFor } from "./docsProgram.js";
|
|
19
|
+
/**
|
|
20
|
+
* The symbol a name stands for, through its imports and re-exports.
|
|
21
|
+
*
|
|
22
|
+
* @param symbol - the symbol at the name.
|
|
23
|
+
* @param checker - the program's checker.
|
|
24
|
+
*/
|
|
25
|
+
const declared = (symbol, checker) => symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0
|
|
26
|
+
? checker.getAliasedSymbol(symbol)
|
|
27
|
+
: symbol;
|
|
28
|
+
/**
|
|
29
|
+
* A component's reference from its symbol: the file of its first declaration, and its name.
|
|
30
|
+
*
|
|
31
|
+
* @param symbol - the component's symbol.
|
|
32
|
+
*/
|
|
33
|
+
const refOf = (symbol) => {
|
|
34
|
+
const declaration = symbol?.declarations?.[0];
|
|
35
|
+
if (symbol === undefined || declaration === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
return { file: declaration.getSourceFile().fileName, name: symbol.getName() };
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* An expression without the wrappers a meta is written with (`satisfies Meta<…>`, `as Meta`, parentheses).
|
|
41
|
+
*
|
|
42
|
+
* @param expression - the expression.
|
|
43
|
+
*/
|
|
44
|
+
const unwrap = (expression) => {
|
|
45
|
+
if (ts.isSatisfiesExpression(expression) ||
|
|
46
|
+
ts.isAsExpression(expression) ||
|
|
47
|
+
ts.isParenthesizedExpression(expression))
|
|
48
|
+
return unwrap(expression.expression);
|
|
49
|
+
return expression;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The meta's object: the default export, written inline or as a constant.
|
|
53
|
+
*
|
|
54
|
+
* @param source - the story file.
|
|
55
|
+
* @param checker - the program's checker.
|
|
56
|
+
*/
|
|
57
|
+
const metaObject = (source, checker) => {
|
|
58
|
+
const assignment = source.statements.find((statement) => ts.isExportAssignment(statement) && !statement.isExportEquals);
|
|
59
|
+
if (assignment === undefined)
|
|
60
|
+
return undefined;
|
|
61
|
+
let value = unwrap(assignment.expression);
|
|
62
|
+
if (ts.isIdentifier(value)) {
|
|
63
|
+
const declaration = declared(checker.getSymbolAtLocation(value), checker)?.valueDeclaration;
|
|
64
|
+
if (declaration !== undefined &&
|
|
65
|
+
ts.isVariableDeclaration(declaration) &&
|
|
66
|
+
declaration.initializer !== undefined)
|
|
67
|
+
value = unwrap(declaration.initializer);
|
|
68
|
+
}
|
|
69
|
+
return ts.isObjectLiteralExpression(value) ? value : undefined;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The meta's component, as the checker resolves its `component` property.
|
|
73
|
+
*
|
|
74
|
+
* @param meta - the meta's object.
|
|
75
|
+
* @param checker - the program's checker.
|
|
76
|
+
*/
|
|
77
|
+
const metaComponent = (meta, checker) => {
|
|
78
|
+
const property = meta.properties.find((each) => each.name !== undefined && each.name.getText() === "component");
|
|
79
|
+
if (property === undefined)
|
|
80
|
+
return undefined;
|
|
81
|
+
if (ts.isShorthandPropertyAssignment(property))
|
|
82
|
+
return refOf(declared(checker.getShorthandAssignmentValueSymbol(property), checker));
|
|
83
|
+
if (ts.isPropertyAssignment(property))
|
|
84
|
+
return refOf(declared(checker.getSymbolAtLocation(unwrap(property.initializer)), checker));
|
|
85
|
+
return undefined;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The symbol a JSX element's tag stands for; none for an element of the page (a lowercase name, `<div>`).
|
|
89
|
+
*
|
|
90
|
+
* @param element - the element's opening or self-closing tag.
|
|
91
|
+
* @param checker - the program's checker.
|
|
92
|
+
*/
|
|
93
|
+
const tagSymbol = (element, checker) => {
|
|
94
|
+
const tag = element.tagName;
|
|
95
|
+
if (ts.isIdentifier(tag) && /^[a-z]/.test(tag.text))
|
|
96
|
+
return undefined;
|
|
97
|
+
return declared(checker.getSymbolAtLocation(tag), checker);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The components a node's JSX names: those declared elsewhere as references, those declared in the story file followed
|
|
101
|
+
* into their own declarations, each declaration once.
|
|
102
|
+
*
|
|
103
|
+
* @param node - the story's node.
|
|
104
|
+
* @param source - the story file.
|
|
105
|
+
* @param checker - the program's checker.
|
|
106
|
+
* @param seen - the declarations already followed.
|
|
107
|
+
*/
|
|
108
|
+
const jsxRenders = (node, source, checker, seen) => {
|
|
109
|
+
const found = [];
|
|
110
|
+
const named = (symbol) => {
|
|
111
|
+
const declaration = symbol?.declarations?.[0];
|
|
112
|
+
const isLocal = declaration !== undefined && declaration.getSourceFile() === source;
|
|
113
|
+
if (!isLocal) {
|
|
114
|
+
const ref = refOf(symbol);
|
|
115
|
+
if (ref !== undefined)
|
|
116
|
+
found.push(ref);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (seen.has(declaration))
|
|
120
|
+
return;
|
|
121
|
+
seen.add(declaration);
|
|
122
|
+
found.push(...jsxRenders(declaration, source, checker, seen));
|
|
123
|
+
};
|
|
124
|
+
const visit = (current) => {
|
|
125
|
+
if (ts.isJsxOpeningElement(current) || ts.isJsxSelfClosingElement(current))
|
|
126
|
+
named(tagSymbol(current, checker));
|
|
127
|
+
ts.forEachChild(current, visit);
|
|
128
|
+
};
|
|
129
|
+
visit(node);
|
|
130
|
+
return found;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* References without repeats, in their first order.
|
|
134
|
+
*
|
|
135
|
+
* @param refs - the references.
|
|
136
|
+
*/
|
|
137
|
+
const unique = (refs) => {
|
|
138
|
+
const keys = new Set();
|
|
139
|
+
return refs.filter((ref) => {
|
|
140
|
+
const key = `${ref.file}#${ref.name}`;
|
|
141
|
+
if (keys.has(key))
|
|
142
|
+
return false;
|
|
143
|
+
keys.add(key);
|
|
144
|
+
return true;
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* One story file's facts, from the program that holds it.
|
|
149
|
+
*
|
|
150
|
+
* @param request - the story file and its stories' exports.
|
|
151
|
+
* @param program - the program.
|
|
152
|
+
*/
|
|
153
|
+
const fileUsage = (request, program) => {
|
|
154
|
+
const source = program.getSourceFile(request.storyFile);
|
|
155
|
+
if (source === undefined)
|
|
156
|
+
return undefined;
|
|
157
|
+
const checker = program.getTypeChecker();
|
|
158
|
+
const meta = metaObject(source, checker);
|
|
159
|
+
const component = meta === undefined ? undefined : metaComponent(meta, checker);
|
|
160
|
+
const moduleSymbol = checker.getSymbolAtLocation(source);
|
|
161
|
+
const exported = moduleSymbol === undefined ? [] : checker.getExportsOfModule(moduleSymbol);
|
|
162
|
+
const stories = request.exports.map((exportName) => {
|
|
163
|
+
const symbol = declared(exported.find((each) => each.getName() === exportName), checker);
|
|
164
|
+
const declaration = symbol?.declarations?.[0];
|
|
165
|
+
const named = declaration === undefined ? [] : jsxRenders(declaration, source, checker, new Set([declaration]));
|
|
166
|
+
const renders = named.length === 0 && component !== undefined ? [component] : unique(named);
|
|
167
|
+
return { exportName, renders };
|
|
168
|
+
});
|
|
169
|
+
return { storyFile: request.storyFile, ...(component === undefined ? {} : { component }), stories };
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* The package's own modules a module imports or re-exports from, resolved as its program resolves them.
|
|
173
|
+
*
|
|
174
|
+
* @param source - the module.
|
|
175
|
+
* @param program - its program.
|
|
176
|
+
* @param cache - the program's resolution cache.
|
|
177
|
+
*/
|
|
178
|
+
const importsOf = (source, program, cache) => {
|
|
179
|
+
const targets = [];
|
|
180
|
+
for (const statement of source.statements) {
|
|
181
|
+
const specifier = (ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) &&
|
|
182
|
+
statement.moduleSpecifier !== undefined &&
|
|
183
|
+
ts.isStringLiteral(statement.moduleSpecifier)
|
|
184
|
+
? statement.moduleSpecifier.text
|
|
185
|
+
: undefined;
|
|
186
|
+
if (specifier === undefined)
|
|
187
|
+
continue;
|
|
188
|
+
const resolved = ts.resolveModuleName(specifier, source.fileName, program.getCompilerOptions(), ts.sys, cache).resolvedModule;
|
|
189
|
+
if (resolved !== undefined && !resolved.isExternalLibraryImport)
|
|
190
|
+
targets.push(resolved.resolvedFileName);
|
|
191
|
+
}
|
|
192
|
+
return targets;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The import graph of the modules the given files reach, through the package's own imports.
|
|
196
|
+
*
|
|
197
|
+
* @param starts - the files to start from.
|
|
198
|
+
* @param programs - the programs that may hold them.
|
|
199
|
+
*/
|
|
200
|
+
const reachedImports = (starts, programs) => {
|
|
201
|
+
const caches = new Map(programs.map((program) => [
|
|
202
|
+
program,
|
|
203
|
+
ts.createModuleResolutionCache(program.getCurrentDirectory(), (name) => name, program.getCompilerOptions())
|
|
204
|
+
]));
|
|
205
|
+
const imports = {};
|
|
206
|
+
const queue = [...starts];
|
|
207
|
+
while (queue.length > 0) {
|
|
208
|
+
const file = queue.pop() ?? "";
|
|
209
|
+
if (file in imports)
|
|
210
|
+
continue;
|
|
211
|
+
const program = programs.find((candidate) => candidate.getSourceFile(file) !== undefined);
|
|
212
|
+
const source = program?.getSourceFile(file);
|
|
213
|
+
const cache = program === undefined ? undefined : caches.get(program);
|
|
214
|
+
const targets = program === undefined || source === undefined || cache === undefined
|
|
215
|
+
? []
|
|
216
|
+
: importsOf(source, program, cache);
|
|
217
|
+
imports[file] = targets;
|
|
218
|
+
queue.push(...targets);
|
|
219
|
+
}
|
|
220
|
+
return imports;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* The facts of a group of story files: what each story renders, and the import graph the rendered components reach.
|
|
224
|
+
*
|
|
225
|
+
* @param requests - the story files and their stories' exports.
|
|
226
|
+
* @returns the facts, or why a story file's program could not be read.
|
|
227
|
+
*/
|
|
228
|
+
export const usageGraph = (requests) => {
|
|
229
|
+
const files = [];
|
|
230
|
+
const programs = new Set();
|
|
231
|
+
for (const request of requests) {
|
|
232
|
+
const docsProgram = programFor(request.storyFile);
|
|
233
|
+
if (typeof docsProgram === "string")
|
|
234
|
+
return docsProgram;
|
|
235
|
+
programs.add(docsProgram.program);
|
|
236
|
+
const usage = fileUsage(request, docsProgram.program);
|
|
237
|
+
if (usage !== undefined)
|
|
238
|
+
files.push(usage);
|
|
239
|
+
}
|
|
240
|
+
const starts = files.flatMap((file) => [
|
|
241
|
+
...(file.component === undefined ? [] : [file.component.file]),
|
|
242
|
+
...file.stories.flatMap((story) => story.renders.map((ref) => ref.file))
|
|
243
|
+
]);
|
|
244
|
+
return { files, imports: reachedImports([...new Set(starts)], [...programs]) };
|
|
245
|
+
};
|
|
246
|
+
//# sourceMappingURL=usageGraph.js.map
|