├── .npmrc ├── packages ├── kitbook │ ├── .npmrc │ ├── .gitignore │ ├── .npmignore │ ├── src │ │ ├── lib │ │ │ ├── viewer │ │ │ │ ├── EdgeDraggable.md │ │ │ │ ├── focused │ │ │ │ │ ├── editor │ │ │ │ │ │ ├── ts │ │ │ │ │ │ │ ├── types.ts │ │ │ │ │ │ │ ├── autocomplete │ │ │ │ │ │ │ │ ├── ensureAnchor.ts │ │ │ │ │ │ │ │ └── symbols.ts │ │ │ │ │ │ │ ├── sync.ts │ │ │ │ │ │ │ └── linter.ts │ │ │ │ │ │ ├── CodeMirror.md │ │ │ │ │ │ ├── CodeMirror.variants.ts │ │ │ │ │ │ └── getComponentPropsType.ts │ │ │ │ │ ├── active.ts │ │ │ │ │ ├── Tabs.svelte │ │ │ │ │ ├── DocumentInPicture.onMount.composition │ │ │ │ │ ├── DocumentInPicture.md │ │ │ │ │ ├── Props.variants.ts │ │ │ │ │ ├── DocumentInPicture.composition │ │ │ │ │ └── LoadVariants.svelte │ │ │ │ ├── EdgeDraggable.composition │ │ │ │ ├── ConnectToTools.md │ │ │ │ ├── Viewer.md │ │ │ │ ├── tree │ │ │ │ │ ├── Element.svelte │ │ │ │ │ └── Tree.svelte │ │ │ │ ├── Viewer.variants.ts │ │ │ │ ├── load-viewer.ts │ │ │ │ └── ConnectToTools.variants2.ts │ │ │ ├── routes │ │ │ │ ├── [...file] │ │ │ │ │ ├── mockComponents │ │ │ │ │ │ ├── Hi.svelte │ │ │ │ │ │ ├── Hi.md │ │ │ │ │ │ └── Hi.variants.ts │ │ │ │ │ ├── Routes.md │ │ │ │ │ ├── +page.ts │ │ │ │ │ ├── MainPage.md │ │ │ │ │ ├── frame │ │ │ │ │ │ ├── sidebar │ │ │ │ │ │ │ ├── Sidebar.md │ │ │ │ │ │ │ ├── Page.variants.ts │ │ │ │ │ │ │ ├── Sidebar.variants.ts │ │ │ │ │ │ │ ├── Folder.variants.ts │ │ │ │ │ │ │ ├── Header.variants.ts │ │ │ │ │ │ │ ├── Page.svelte │ │ │ │ │ │ │ └── Header.svelte │ │ │ │ │ │ ├── frame.css │ │ │ │ │ │ ├── Frame.variants.ts │ │ │ │ │ │ ├── parseUpdatedPath.ts │ │ │ │ │ │ └── FramePanes.svelte │ │ │ │ │ ├── +page.svelte │ │ │ │ │ ├── Routes.svelte │ │ │ │ │ ├── Routes.variants.ts │ │ │ │ │ └── relative-names.ts │ │ │ │ ├── sandbox │ │ │ │ │ └── [...file] │ │ │ │ │ │ ├── +page.ts │ │ │ │ │ │ ├── mockComponents │ │ │ │ │ │ ├── IndividualComponent.svelte │ │ │ │ │ │ ├── NeedsPropsToNotError.svelte │ │ │ │ │ │ └── NeedsPropsToNotError.variants.ts │ │ │ │ │ │ ├── SandboxPage.md │ │ │ │ │ │ ├── +page.svelte │ │ │ │ │ │ ├── Composition.svelte │ │ │ │ │ │ ├── SandboxPage.variants.ts │ │ │ │ │ │ ├── SandboxPage.svelte │ │ │ │ │ │ └── Variant.svelte │ │ │ │ ├── tools │ │ │ │ │ ├── +page.svelte │ │ │ │ │ ├── Tools.variants.ts │ │ │ │ │ ├── _page.md │ │ │ │ │ └── ToolsPage.svelte │ │ │ │ ├── layoutLoad.ts │ │ │ │ └── +layout.ts │ │ │ ├── plugins │ │ │ │ ├── main │ │ │ │ │ ├── markdown │ │ │ │ │ │ ├── cases │ │ │ │ │ │ │ ├── js.md │ │ │ │ │ │ │ ├── twoslash.md │ │ │ │ │ │ │ ├── toc.md │ │ │ │ │ │ │ ├── index.md │ │ │ │ │ │ │ ├── link.md │ │ │ │ │ │ │ ├── js.html │ │ │ │ │ │ │ ├── index.html │ │ │ │ │ │ │ ├── toc.html │ │ │ │ │ │ │ ├── twoslash.html │ │ │ │ │ │ │ ├── gfm.md │ │ │ │ │ │ │ └── link.html │ │ │ │ │ │ ├── markdownToHtml.test.ts │ │ │ │ │ │ ├── remarkHighlighter.ts │ │ │ │ │ │ └── markdownToHtml.ts │ │ │ │ │ ├── kitbook-virtual-module.d.ts │ │ │ │ │ └── modifyViteConfigForKitbook.ts │ │ │ │ ├── utils │ │ │ │ │ ├── colors.ts │ │ │ │ │ └── immutableDeepMerge.ts │ │ │ │ ├── virtual │ │ │ │ │ ├── Template.svelte │ │ │ │ │ └── Template.variants.ts.txt │ │ │ │ ├── rpc │ │ │ │ │ ├── get-sfc-list.ts │ │ │ │ │ ├── get-svelte-modules.ts │ │ │ │ │ └── rpc.plugin.ts │ │ │ │ ├── context │ │ │ │ │ ├── copy-kitbook-routes.test.ts │ │ │ │ │ └── merge-user-settings-with-defaults.ts │ │ │ │ ├── constants.ts │ │ │ │ └── vite.ts │ │ │ ├── defineConfig.ts │ │ │ ├── modules │ │ │ │ ├── hmrUpdatedModules.ts │ │ │ │ ├── parseModules │ │ │ │ │ ├── utils │ │ │ │ │ │ └── removeInitialDigitAndHyphens.ts │ │ │ │ │ ├── putPagesIntoFolders.test.ts │ │ │ │ │ ├── putPagesIntoFolders.ts │ │ │ │ │ └── groupColocatedModulesIntoPages.ts │ │ │ │ └── rpc-client.ts │ │ │ ├── components │ │ │ │ ├── errorBoundary │ │ │ │ │ ├── ErrorBoundary.ts │ │ │ │ │ ├── CustomErrorBoundary.svelte │ │ │ │ │ └── createBoundary.ts │ │ │ │ ├── search │ │ │ │ │ ├── SearchResult.md │ │ │ │ │ ├── LaunchSearch.svelte │ │ │ │ │ ├── SearchModal.variants.ts │ │ │ │ │ ├── SearchResult.svelte │ │ │ │ │ ├── SearchResult.composition │ │ │ │ │ ├── filterPages.ts │ │ │ │ │ └── SearchResult.variants.ts │ │ │ │ ├── EditInGithub.svelte │ │ │ │ ├── EditInGithub.variants.ts │ │ │ │ ├── Toast.dismissable.composition │ │ │ │ ├── Toast.variants.ts │ │ │ │ └── Toast.svelte │ │ │ ├── test.ts │ │ │ ├── view │ │ │ │ ├── Iframe.svelte │ │ │ │ ├── ViewBody.variants.ts │ │ │ │ ├── Iframe.md │ │ │ │ └── ViewHeader.variants.ts │ │ │ ├── test │ │ │ │ ├── clearSnapshots.ts │ │ │ │ └── preparePath.ts │ │ │ ├── server-events.d.ts │ │ │ └── index.ts │ │ ├── docs │ │ │ ├── 1-variants │ │ │ │ ├── DefaultSlot.svelte │ │ │ │ ├── PassIntoDefaultSlot.svelte │ │ │ │ ├── SSR.svelte │ │ │ │ ├── DefaultSlot.md │ │ │ │ ├── DefaultSlot.variants.ts │ │ │ │ ├── SSR.variants.ts │ │ │ │ └── Rendering-Platform.md │ │ │ ├── 9-maintainer-notes │ │ │ │ ├── 3-release.md │ │ │ │ ├── 1-contributing.md │ │ │ │ └── 2-add-vitest.md │ │ │ ├── 6-easy-wikilinks.after.composition │ │ │ ├── 6-easy-wikilinks.composition │ │ │ ├── 3-customizations │ │ │ │ ├── 4-styles.md │ │ │ │ ├── 1-use-by-itself-(for-a-library).md │ │ │ │ └── 0-config.md │ │ │ ├── 4-component-compositions.composition │ │ │ ├── 8-i18n.composition │ │ │ ├── 2-viewer.md │ │ │ ├── 9-examples.md │ │ │ └── 7a-additional-component-tests.md │ │ ├── app.html │ │ └── app.d.ts │ ├── vitest.config.ts │ ├── uno.config.ts │ ├── static │ │ └── icons │ │ │ ├── orange-favicon.svg │ │ │ └── kitbook-editable-text.svg │ ├── .stackblitz.js │ ├── e2e │ │ └── kitbook.spec.ts │ ├── playwright.config.ts │ ├── tsconfig.json │ ├── vite.config.ts │ ├── svelte.config.js │ ├── LICENSE │ ├── kitbook.config.ts │ └── README.md ├── mdsvex-shiki-twoslash │ ├── .gitignore │ ├── src │ │ ├── fixtures │ │ │ ├── no-codefence.txt │ │ │ ├── lang-no-meta.txt │ │ │ ├── cut.txt │ │ │ ├── highlight-normal.txt │ │ │ ├── title.txt │ │ │ ├── highlight-twoslash.txt │ │ │ ├── basic.txt │ │ │ ├── has-error.txt │ │ │ ├── get-posts.txt │ │ │ ├── multi-file.txt │ │ │ ├── multi-highlights.txt │ │ │ ├── no-codefence.html │ │ │ ├── lang-no-meta.html │ │ │ ├── get-posts.html │ │ │ ├── cut.html │ │ │ ├── highlight-normal.html │ │ │ └── highlight-twoslash.html │ │ ├── setLineNumberBaseTo1.ts │ │ ├── setLineNumberBaseTo1.test.ts │ │ └── index.test.ts │ ├── vitest.config.ts │ ├── build.config.ts │ ├── tsconfig.json │ ├── LICENSE │ ├── mdsvex.js │ └── package.json ├── template │ ├── .npmrc │ ├── .gitignore │ ├── src │ │ ├── routes │ │ │ ├── (app) │ │ │ │ ├── _page.md │ │ │ │ ├── about │ │ │ │ │ └── +page.svelte │ │ │ │ ├── +page.ts │ │ │ │ ├── _page.variants.ts │ │ │ │ └── +page.svelte │ │ │ ├── kitbook │ │ │ │ ├── [...file] │ │ │ │ │ ├── +page.js │ │ │ │ │ └── +page.svelte │ │ │ │ ├── sandbox │ │ │ │ │ └── [...file] │ │ │ │ │ │ ├── +page.js │ │ │ │ │ │ └── +page.svelte │ │ │ │ ├── tools │ │ │ │ │ └── +page.svelte │ │ │ │ └── +layout.js │ │ │ └── +layout.ts │ │ ├── lib │ │ │ ├── Image.md │ │ │ ├── Image.svelte │ │ │ └── Image.variants.ts │ │ ├── docs │ │ │ ├── 1-b.md │ │ │ └── 0-file-ordering.md │ │ ├── app.d.ts │ │ ├── app.html │ │ └── index.md │ ├── README.md │ ├── e2e │ │ └── kitbook.spec.ts │ ├── vite.config.js │ ├── .stackblitz.js │ ├── svelte.config.js │ ├── tsconfig.json │ ├── kitbook.config.ts │ ├── playwright.config.ts │ └── package.json ├── rehype-display-link-titles │ ├── .gitignore │ ├── vitest.config.ts │ ├── build.config.ts │ ├── tsconfig.json │ ├── README.md │ └── LICENSE └── format-snapshot-results-action │ ├── src │ ├── index.ts │ ├── main.ts │ └── makeComment.snap.md │ ├── vitest.config.ts │ ├── package.json │ ├── tsconfig.json │ ├── README.md │ ├── action.yml │ └── LICENSE ├── pnpm-workspace.yaml ├── .prettierrc ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── config.yml │ └── feature_request.yml └── workflows │ ├── pkg.pr.new.yml │ ├── lint.yml │ ├── svelte-check-unit-test.yml │ └── release.yml ├── .vscode ├── foam.json └── extensions.json ├── .gitignore ├── .foam └── templates │ └── new-note.md ├── vitest.workspace.ts ├── fiveserver.config.cjs ├── LICENSE ├── .gitpod.yml ├── README.md └── package.json /.npmrc: -------------------------------------------------------------------------------- 1 | # link-workspace-packages=false -------------------------------------------------------------------------------- /packages/kitbook/.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /packages/mdsvex-shiki-twoslash/.gitignore: -------------------------------------------------------------------------------- 1 | dist -------------------------------------------------------------------------------- /packages/template/.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /packages/kitbook/.gitignore: -------------------------------------------------------------------------------- 1 | /.svelte-kit 2 | dist 3 | -------------------------------------------------------------------------------- /packages/rehype-display-link-titles/.gitignore: -------------------------------------------------------------------------------- 1 | dist -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'packages/*' 3 | -------------------------------------------------------------------------------- /packages/kitbook/.npmignore: -------------------------------------------------------------------------------- 1 | /mockComponents 2 | *.variants.ts 3 | **/*.md -------------------------------------------------------------------------------- /packages/mdsvex-shiki-twoslash/src/fixtures/no-codefence.txt: -------------------------------------------------------------------------------- 1 | 2 | const foo = 2 -------------------------------------------------------------------------------- /packages/kitbook/src/lib/viewer/EdgeDraggable.md: -------------------------------------------------------------------------------- 1 | Remembers postion in localStorage -------------------------------------------------------------------------------- /packages/mdsvex-shiki-twoslash/src/fixtures/lang-no-meta.txt: -------------------------------------------------------------------------------- 1 | js 2 | const foo = 2 -------------------------------------------------------------------------------- /packages/kitbook/src/lib/routes/[...file]/mockComponents/Hi.svelte: -------------------------------------------------------------------------------- 1 |
-------------------------------------------------------------------------------- /packages/kitbook/src/lib/routes/[...file]/frame/sidebar/Folder.variants.ts: -------------------------------------------------------------------------------- 1 | import type { Variant } from 'kitbook' 2 | import type Component from './Folder.svelte' 3 | 4 | export const First: Variantjsconst a = 2
Documentation, Prototyping, Inspection & Testing Workbench Tool for Svelte built with SvelteKit that lets you rapidly build, document, and test components. Inspired by Foo
4 |A example.
11 |More text.
MIT
15 | -------------------------------------------------------------------------------- /packages/format-snapshot-results-action/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "compilerOptions": { 4 | "target": "ES2022", 5 | "baseUrl": "./", 6 | "rootDir": "./src", 7 | "module": "NodeNext", 8 | "moduleResolution": "NodeNext", 9 | "types": [ 10 | "vitest/globals", 11 | "vitest/importMeta" 12 | ], 13 | "strict": true, 14 | "noImplicitAny": true, 15 | "outDir": "./dist", 16 | "sourceMap": true, 17 | "esModuleInterop": true, 18 | "forceConsistentCasingInFileNames": true, 19 | "skipLibCheck": true 20 | }, 21 | "include": [ 22 | "src" 23 | ], 24 | "exclude": ["./dist", "./node_modules", "./__tests__", "./coverage"] 25 | } 26 | -------------------------------------------------------------------------------- /packages/kitbook/src/lib/view/Iframe.md: -------------------------------------------------------------------------------- 1 | TODO: Make large desktop views smaller to be able to more quickly digest and then expand on click to focused view. 2 | 3 | ```css 4 | .container { 5 | width: 100px; 6 | height: 100px; 7 | position: relative; 8 | } 9 | 10 | .iframe { 11 | position: absolute; 12 | width: 200%; 13 | height: 200%; 14 | top: 0; 15 | /* or top: 50% */ 16 | left: 0; 17 | /* or left: 50% */ 18 | transform: scale(0.5); 19 | /* transform: translate(-50% -50%) scale(0.5); */ 20 | transform-origin: top left; 21 | } 22 | ``` 23 | 24 | Also can look into auto iframe resizing http://davidjbradshaw.github.io/iframe-resizer/ or just a simple inspect the size of the iframe's content on window or iframe resize -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | // Svelte 4 | "svelte.svelte-vscode", 5 | // Styles 6 | "antfu.iconify", 7 | "antfu.unocss", 8 | // Code quality 9 | "dbaeumer.vscode-eslint", 10 | // Git 11 | "github.vscode-pull-request-github", 12 | // Kitbook 13 | "yzhang.markdown-all-in-one", 14 | "foam.foam-vscode" 15 | // ---- You should definitely install the ones above, the ones below are recommended 16 | // Efficiency 17 | // "usernamehw.errorlens" 18 | // "eamodio.gitlens", 19 | // "cschleiden.vscode-github-actions", 20 | // "aaron-bond.better-comments", 21 | // "vscode-icons-team.vscode-icons", 22 | // "wallabyjs.quokka-vscode", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /packages/kitbook/playwright.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig, devices } from '@playwright/test' 2 | 3 | export default defineConfig({ 4 | testDir: 'e2e', 5 | snapshotDir: 'e2e/snapshots', 6 | snapshotPathTemplate: '{snapshotDir}/{arg}-{projectName}-{platform}{ext}', 7 | fullyParallel: true, 8 | reporter: 'html', 9 | retries: 0, 10 | workers: process.env.CI ? 1 : undefined, 11 | use: { 12 | baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:5173', 13 | }, 14 | projects: [ 15 | { 16 | name: 'chromium', 17 | use: { ...devices['Desktop Chrome'] }, 18 | }, 19 | ], 20 | webServer: { 21 | command: 'pnpm run dev', 22 | port: 5173, 23 | reuseExistingServer: true, 24 | }, 25 | }) 26 | -------------------------------------------------------------------------------- /packages/kitbook/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json", 3 | "compilerOptions": { 4 | // "strict": true, 5 | "paths": { 6 | "$lib": [ 7 | "./src/lib" 8 | ], 9 | "$lib/*": [ 10 | "./src/lib/*" 11 | ], 12 | "kitbook": [ 13 | "./src/lib" 14 | ], 15 | "kitbook/*": [ 16 | "./src/lib/*" 17 | ] 18 | }, 19 | "resolveJsonModule": true, 20 | "types": [ 21 | "vitest/globals", 22 | "vitest/importMeta" 23 | ], 24 | "allowJs": true, 25 | "checkJs": true, 26 | "sourceMap": true, 27 | "esModuleInterop": true, 28 | "forceConsistentCasingInFileNames": true, 29 | "skipLibCheck": true 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/kitbook/vite.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | import { defineConfig } from 'vite' 3 | import { sveltekit } from '@sveltejs/kit/vite' 4 | import Inspect from 'vite-plugin-inspect' 5 | import { kitbook } from './src/lib/plugins/vite' 6 | import kitbookConfig from './kitbook.config' 7 | 8 | export default defineConfig({ 9 | plugins: [ 10 | Inspect(), 11 | kitbook(kitbookConfig), 12 | sveltekit(), 13 | ], 14 | define: { 15 | 'import.meta.vitest': false, 16 | }, 17 | resolve: { 18 | alias: { 19 | kitbook: path.resolve('./src/lib'), 20 | }, 21 | }, 22 | server: { 23 | port: 3212, 24 | strictPort: true, 25 | }, 26 | build: { 27 | target: 'es2015', // es6 28 | }, 29 | }) 30 | -------------------------------------------------------------------------------- /.github/workflows/pkg.pr.new.yml: -------------------------------------------------------------------------------- 1 | name: Publish Any Commit to pkg.pr.new 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - '**' 8 | tags: 9 | - '!**' 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 19 | 20 | - uses: pnpm/action-setup@v2 21 | with: 22 | version: 9.6.0 23 | 24 | - uses: actions/setup-node@v4 25 | with: 26 | node-version: 20 27 | cache: pnpm 28 | 29 | - run: pnpm install 30 | 31 | - run: pnpm build 32 | 33 | - name: Release 34 | run: pnpm dlx pkg-pr-new publish --compact --pnpm './packages/*' 35 | -------------------------------------------------------------------------------- /packages/mdsvex-shiki-twoslash/src/fixtures/no-codefence.html: -------------------------------------------------------------------------------- 1 |const foo = 2
-------------------------------------------------------------------------------- /packages/kitbook/static/icons/kitbook-editable-text.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /packages/kitbook/src/lib/viewer/Viewer.md: -------------------------------------------------------------------------------- 1 | Does not show Kitbook icon if using Kitbook by itself to build a library because you are already in the Kitbook. 2 | 3 | -------------------------------------------------------------------------------- /packages/kitbook/src/docs/1-variants/SSR.variants.ts: -------------------------------------------------------------------------------- 1 | import type { Variant, VariantMeta } from 'kitbook' 2 | import type Component from './SSR.svelte' 3 | 4 | export const shared_meta: VariantMeta = { 5 | viewports: [ 6 | { width: 400, height: 100 }, 7 | ], 8 | } 9 | 10 | export const Test_SSR: Variantconst foo = 2
22 | {dev ? $error.stack : ''}
23 |
24 | jsconst foo = 2
-------------------------------------------------------------------------------- /packages/kitbook/src/lib/viewer/Viewer.variants.ts: -------------------------------------------------------------------------------- 1 | import type { Variant, VariantMeta } from 'kitbook' 2 | import type Component from './Viewer.svelte' 3 | 4 | export const shared_meta: VariantMeta = { 5 | viewports: [ 6 | { width: 500, height: 200 }, 7 | ], 8 | ssr: false, 9 | } 10 | 11 | const shared_settings = { 12 | title: 'foo', 13 | description: 'foo', 14 | kitbookRoute: '/kitbook', 15 | _languageInsertedKitbookRoute: '/kitbook', 16 | viewer: { 17 | showToggleButton: 'always', 18 | __internal: { 19 | viteBase: '', 20 | }, 21 | }, 22 | } satisfies Partialjsconst foo = 2
-------------------------------------------------------------------------------- /packages/kitbook/src/lib/routes/sandbox/[...file]/SandboxPage.svelte: -------------------------------------------------------------------------------- 1 | 11 | 12 |examples/index.tstsconstfoo = 2 // highlight// nope// highlight// highlight me// not me
6 |diffimport { sveltekit } from '@sveltejs/kit/vite';+import { kitbook } from 'kitbook/plugins/vite';const config = {plugins: [+ kitbook(),sveltekit(),],};
I'm going to link to [FooBook]
7 | -------------------------------------------------------------------------------- /packages/mdsvex-shiki-twoslash/src/setLineNumberBaseTo1.test.ts: -------------------------------------------------------------------------------- 1 | import { setLineNumberBaseTo1 } from './setLineNumberBaseTo1' 2 | 3 | test('setLineNumberBaseTo1', () => { 4 | const meta = { 5 | title: 'examples/index.ts', 6 | highlight: { 1: true, 3: true }, 7 | } 8 | expect(setLineNumberBaseTo1(meta)).toMatchInlineSnapshot(` 9 | { 10 | "highlight": { 11 | "0": true, 12 | "2": true, 13 | }, 14 | "title": "examples/index.ts", 15 | } 16 | `) 17 | }) 18 | 19 | test('setLineNumberBaseTo1 handles ranges', () => { 20 | const meta = { 21 | title: 'examples/index.ts', 22 | highlight: { '1': true, '3-4': true }, 23 | } 24 | expect(setLineNumberBaseTo1(meta)).toMatchInlineSnapshot(` 25 | { 26 | "highlight": { 27 | "0": true, 28 | "2-3": true, 29 | }, 30 | "title": "examples/index.ts", 31 | } 32 | `) 33 | }) 34 | 35 | test('setLineNumberBaseTo1 handles no highlight', () => { 36 | const meta = { 37 | title: 'examples/index.ts', 38 | } 39 | expect(setLineNumberBaseTo1(meta)).toMatchInlineSnapshot(` 40 | { 41 | "title": "examples/index.ts", 42 | } 43 | `) 44 | }) 45 | 46 | test('setLineNumberBaseTo1 handles undefined meta', () => { 47 | // @ts-expect-error - undefined is incorrect 48 | expect(setLineNumberBaseTo1(undefined)).toEqual(undefined) 49 | }) 50 | -------------------------------------------------------------------------------- /packages/mdsvex-shiki-twoslash/src/fixtures/get-posts.html: -------------------------------------------------------------------------------- 1 |tsconstposts =getPosts ();
-------------------------------------------------------------------------------- /packages/kitbook/src/lib/routes/[...file]/frame/Frame.variants.ts: -------------------------------------------------------------------------------- 1 | import type { Variant, VariantMeta } from 'kitbook' 2 | import type Component from './Frame.svelte' 3 | import { pages } from './mock-pages' 4 | 5 | export const shared_meta: VariantMeta = {} 6 | 7 | const shared = { 8 | pages, 9 | kitbookPath: '/', 10 | activePath: '/foo', 11 | settings: { 12 | githubURL: 'https://github.com', 13 | title: 'My Cool Kitbook', 14 | description: 'foo', 15 | viewports: [ 16 | { name: 'Mobile', width: 320, height: 568 }, 17 | { name: 'Desktop', width: 1024, height: 768 }, 18 | ], 19 | // languages: [{ name: null, code: null }], 20 | }, 21 | latest_edited_filepath: null, 22 | } satisfies Partialtsconstposts =getPosts ();
tsconsole .log (level )
-------------------------------------------------------------------------------- /packages/kitbook/src/lib/routes/[...file]/relative-names.ts: -------------------------------------------------------------------------------- 1 | export function friendly_relative_name(path: string) { 2 | let no_extension = path.replace(/\.svelte$/, '') 3 | 4 | if (no_extension.includes('/+page') || no_extension.includes('/+layout')) { 5 | no_extension = no_extension.substring(0, no_extension.lastIndexOf('/')) 6 | no_extension = no_extension.replace(/.*routes/, '') 7 | 8 | if (no_extension === '') 9 | no_extension = '/' 10 | 11 | if (path.includes('/+layout')) 12 | no_extension += ' Layout' 13 | 14 | return no_extension 15 | } 16 | 17 | return no_extension.substring(no_extension.lastIndexOf('/') + 1) 18 | } 19 | 20 | if (import.meta.vitest) { 21 | describe(friendly_relative_name, () => { 22 | test('shows url for page routes', () => { 23 | expect(friendly_relative_name('/routes/+page.svelte')).toEqual('/') 24 | expect(friendly_relative_name('/routes/another/+page.svelte')).toEqual('/another') 25 | }) 26 | 27 | test('shows url and Layout title for layouts', () => { 28 | expect(friendly_relative_name('/routes/+layout.svelte')).toEqual('/ Layout') 29 | expect(friendly_relative_name('/routes/inner/+layout.svelte')).toEqual('/inner Layout') 30 | }) 31 | 32 | test('Only shows component title for regular Svelte components', () => { 33 | expect(friendly_relative_name('/lib/Button.svelte')).toEqual('Button') 34 | expect(friendly_relative_name('/lib/a/b/Header.svelte')).toEqual('Header') 35 | }) 36 | }) 37 | } 38 | -------------------------------------------------------------------------------- /packages/kitbook/src/lib/routes/[...file]/frame/parseUpdatedPath.ts: -------------------------------------------------------------------------------- 1 | export function urlFromPath(filepath: string): string | null { 2 | const normalizedPath = filepath.replace(/\\/g, '/') 3 | 4 | const match = normalizedPath.match(/^(?:.*\/src\/)(?tsconsole .log (level )
You could build something amazing here, like an Image component.
12 | 13 |
2 |
3 |
4 |
5 |
8 | Documentation, Prototyping, Inspection & Testing Workbench Tool for SvelteKit apps built with SvelteKit. 9 |
10 | 11 |
14 | 15 |
16 | View the Kitbook Docs (and demo) 17 |
18 | 19 | ## Contributing 20 | 21 | Would love to have you help! Read the [[0-roadmap|Roadmap]] for good places to start. We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). 22 | 23 | [](https:///pr.new/jacob-8/kitbook) 24 | 25 | Or work on Kitbook locally: 26 | 27 | - `pnpm install` 28 | - `pnpm stub` 29 | - `pnpm dev` 30 | 31 | To update the Kitbook code while using it in your own app, you can change your `devDependency` to point to it instead of npm by using something like `"kitbook": "link:../kitbook/packages/kitbook",` then run `pnpm package:watch` in Kitbook to keep it updating on changes. 32 | 33 | [//begin]: # "Autogenerated link references for markdown compatibility" 34 | [0-roadmap|Roadmap]: packages/kitbook/src/docs/9-maintainer-notes/0-roadmap.md "Roadmap" 35 | [//end]: # "Autogenerated link references" -------------------------------------------------------------------------------- /packages/kitbook/README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
8 | Documentation, Prototyping, Inspection & Testing Workbench Tool for SvelteKit apps built with SvelteKit. 9 |
10 | 11 |
14 | 15 |
16 | View the Kitbook Docs (and demo) 17 |
18 | 19 | ## Contributing 20 | 21 | Would love to have you help! Read the [[0-roadmap|Roadmap]] for good places to start. We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). 22 | 23 | [](https:///pr.new/jacob-8/kitbook) 24 | 25 | Or work on Kitbook locally: 26 | 27 | - `pnpm install` 28 | - `pnpm stub` 29 | - `pnpm dev` 30 | 31 | To update the Kitbook code while using it in your own app, you can change your `devDependency` to point to it instead of npm by using something like `"kitbook": "link:../kitbook/packages/kitbook",` then run `pnpm package:watch` in Kitbook to keep it updating on changes. 32 | 33 | [//begin]: # "Autogenerated link references for markdown compatibility" 34 | [0-roadmap|Roadmap]: src/docs/9-maintainer-notes/0-roadmap.md "Roadmap" 35 | [//end]: # "Autogenerated link references" 36 | -------------------------------------------------------------------------------- /packages/kitbook/src/lib/plugins/rpc/get-svelte-modules.ts: -------------------------------------------------------------------------------- 1 | import type { ModuleNode, ViteDevServer } from 'vite' 2 | import type { SvelteModules } from '../../kitbook-types' 3 | import { get_sfc_list } from './get-sfc-list.js' 4 | 5 | export async function get_svelte_modules(server: ViteDevServer, root: string): Promiseexamples/index.tsts// 1// 2// 3// 4// 5// 6
-------------------------------------------------------------------------------- /packages/kitbook/src/lib/routes/[...file]/frame/FramePanes.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 |examples/index.tsts// 1// 2// 3// 4// 5// 6
2 | Visual Regression Report
examples/index.tsts// 1// 2// 3// 4// 5// 6
-------------------------------------------------------------------------------- /packages/kitbook/src/lib/components/errorBoundary/createBoundary.ts: -------------------------------------------------------------------------------- 1 | // From @crownframework/svelte-error-boundary 2 | import { writable } from 'svelte/store' 3 | 4 | const GUARDED_BLOCK_FNS = ['c', 'l', 'h', 'm', 'p', 'a', 'i', 'o', 'd'] 5 | 6 | export function createBoundary(Component) { 7 | if (Component.$$render) { 8 | const render = Component.$$render 9 | Component.$$render = (result, props, bindings, slots) => { 10 | const error = writable(undefined) 11 | 12 | try { 13 | return render(result, { error, ...props }, bindings, slots) 14 | } 15 | catch (e) { 16 | error.set(e) 17 | return render(result, { error, ...props }, bindings, {}) 18 | } 19 | } 20 | 21 | return Component 22 | } 23 | 24 | function guard(fn, onError) { 25 | return function guarded(...args) { 26 | try { 27 | return fn(...args) 28 | } 29 | catch (err) { 30 | onError(err) 31 | } 32 | } 33 | } 34 | 35 | return class ErrorBoundaryComponent extends Component { 36 | constructor(config) { 37 | const error = writable(undefined) 38 | 39 | config.props.$$slots.default = config.props.$$slots.default.map( 40 | slot => (...args) => { 41 | const guarded = guard(slot, error.set) 42 | const block = guarded(...args) 43 | 44 | if (block) { 45 | for (const fn of GUARDED_BLOCK_FNS) { 46 | if (block[fn]) 47 | block[fn] = guard(block[fn], error.set) 48 | } 49 | } 50 | 51 | return block 52 | }, 53 | ) 54 | 55 | super(config) 56 | 57 | this.$$set({ error }) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/mdsvex-shiki-twoslash/src/index.test.ts: -------------------------------------------------------------------------------- 1 | import fs from 'node:fs' 2 | import { dirname, resolve } from 'node:path' 3 | import { fileURLToPath } from 'node:url' 4 | import parserHTML from 'prettier/parser-html' 5 | import { format as prettier } from 'prettier' 6 | import { shikiTwoslashHighlighter } from '.' 7 | 8 | const _dirname = typeof __dirname !== 'undefined' 9 | ? __dirname 10 | : dirname(fileURLToPath(import.meta.url)) 11 | 12 | describe('mdsvex-shiki-twoslash', () => { 13 | const fixturesDirectory = resolve(_dirname, './fixtures') 14 | fs.readdirSync(fixturesDirectory).forEach((filename) => { 15 | if (!filename.includes('txt')) 16 | return 17 | 18 | const name = filename.replace('.txt', '') 19 | test(name, async () => { 20 | const fileContents = fs.readFileSync(`${fixturesDirectory}/${name}.txt`, 'utf8') 21 | const normalizedContents = fileContents.replace(/\r\n/g, '\n') // Replace CRLF with LF 22 | const SPLIT = '__SPLIT__' 23 | const [firstLine, code] = normalizedContents.replace('\n', SPLIT).split(SPLIT) 24 | const [lang, meta] = firstLine.replace(' ', SPLIT).split(SPLIT) 25 | const highlightedCode = await highlight(code, lang, meta) 26 | expect(highlightedCode).toMatchFileSnapshot(`${fixturesDirectory}/${name}.html`) 27 | }) 28 | }) 29 | }) 30 | 31 | const highlighter = shikiTwoslashHighlighter().highlighter 32 | 33 | async function highlight(code: string, lang?: string | undefined, meta?: string | undefined, format = false) { 34 | const highlighted = await highlighter(code, lang, meta) 35 | if (format) { 36 | return prettier(highlighted, { 37 | parser: 'html', 38 | plugins: [parserHTML], 39 | }) 40 | } 41 | return highlighted 42 | } 43 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: 🚀 New feature proposal 2 | description: Propose a new feature to be added to Kitbook 3 | labels: ['enhancement: pending triage'] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thanks for your interest in Kitbook and taking the time to fill out this feature proposal! 9 | - type: checkboxes 10 | id: checkboxes 11 | attributes: 12 | label: Double-Check 13 | description: Before submitting the issue, please make sure you have done the following 14 | options: 15 | - label: Read the entire [Kitbook docs](https://kitbook.vercel.app). 16 | required: true 17 | - label: Check that there isn't [already an issue](https://github.com/jacob-8/kitbook/issues) that requests a similar feature. 18 | required: true 19 | - type: textarea 20 | id: feature-description 21 | attributes: 22 | label: Clear description of the requested feature 23 | description: What is it that you would like to see Kitbook offer and why? Do you intend to submit a PR for this feature? 24 | validations: 25 | required: true 26 | - type: textarea 27 | id: suggested-solution 28 | attributes: 29 | label: Suggested solution 30 | description: Here's how it could be implemented... 31 | validations: 32 | required: true 33 | - type: textarea 34 | id: alternative 35 | attributes: 36 | label: Alternative 37 | description: Concise description of any alternative solutions you've considered. 38 | - type: textarea 39 | id: additional-context 40 | attributes: 41 | label: Additional context 42 | description: Add any other helpful context or screenshots about the feature request. 43 | -------------------------------------------------------------------------------- /packages/kitbook/src/lib/plugins/rpc/rpc.plugin.ts: -------------------------------------------------------------------------------- 1 | import type { Plugin } from 'vite' 2 | import { createRPCServer } from 'vite-dev-rpc' 3 | import { RPC_NAME } from '../constants.js' 4 | import type { RPCFunctions } from '../../kitbook-types' 5 | import type { KitbookPluginContext } from '../vite.js' 6 | import { get_svelte_modules } from './get-svelte-modules.js' 7 | 8 | export function RPCPlugin({ config, rpc_functions }: KitbookPluginContext): Plugin { 9 | return { 10 | name: 'vite-plugin-kitbook:rpc', 11 | enforce: 'pre', 12 | apply: 'serve', // TODO: remove later once also getting modules from build 13 | 14 | configResolved(_config) { 15 | config = _config 16 | }, 17 | 18 | configureServer(server) { 19 | const rpc_server = createRPCServerexamples/index.tsts// 1// 2// 3// 4// 5// 6