@master/internal-site 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +66 -2
- package/dist/astro.d.mts +3 -0
- package/dist/astro.mjs +510 -0
- package/dist/config.d.mts +64 -0
- package/dist/config.mjs +10 -0
- package/package.json +384 -4
- package/src/astro/Page.astro +12 -0
- package/src/astro/content-pages.ts +75 -0
- package/src/astro/index.ts +124 -0
- package/src/astro/module-id.ts +4 -0
- package/src/astro/propagated-assets.ts +29 -0
- package/src/astro/route-paths.ts +78 -0
- package/src/astro/routes.template.ts +110 -0
- package/src/astro/server-styles.ts +26 -0
- package/src/astro/site-context.ts +27 -0
- package/src/astro/source-url.ts +22 -0
- package/src/astro/svelte-renderer.ts +45 -0
- package/src/astro/svg-markup.ts +23 -0
- package/src/benchmarks/BenchmarkBarRows.astro +34 -0
- package/src/benchmarks/BenchmarkBars.astro +14 -0
- package/src/benchmarks/BenchmarkChart.astro +53 -0
- package/src/benchmarks/BenchmarkChartGroup.astro +24 -0
- package/src/benchmarks/BenchmarkDataTable.astro +24 -0
- package/src/benchmarks/BenchmarkDelta.astro +23 -0
- package/src/benchmarks/BenchmarkFigure.astro +30 -0
- package/src/benchmarks/BenchmarkMetricTable.astro +38 -0
- package/src/benchmarks/BenchmarkMetrics.astro +23 -0
- package/src/benchmarks/BenchmarkSampleSummary.astro +30 -0
- package/src/benchmarks/BenchmarkScrollRegion.svelte +27 -0
- package/src/benchmarks/BenchmarkSource.astro +20 -0
- package/src/benchmarks/BenchmarkStackedBars.astro +54 -0
- package/src/benchmarks/BenchmarkStatus.astro +16 -0
- package/src/benchmarks/types.ts +98 -0
- package/src/benchmarks/utils.ts +42 -0
- package/src/blog/BlogAuthors.astro +25 -0
- package/src/blog/article/BlogArticleContents.svelte +24 -0
- package/src/blog/article/BlogArticleEnd.astro +55 -0
- package/src/blog/article/BlogArticleMasthead.astro +61 -0
- package/src/blog/article/language.ts +29 -0
- package/src/blog/article/neighbors.ts +27 -0
- package/src/blog/article/title-lines.astro +14 -0
- package/src/blog/article/title-parts.ts +9 -0
- package/src/components.d.ts +5 -0
- package/src/config.ts +66 -0
- package/src/css/ButtonPreview.astro +22 -0
- package/src/css/ConfiguredExample.astro +15 -0
- package/src/css/NamespaceUtilityTable.astro +50 -0
- package/src/css/StylesheetExample.astro +15 -0
- package/src/css/ThemeNumberVariableTable.astro +57 -0
- package/src/css/configured-example.ts +53 -0
- package/src/css/foundation-data/elevation/shadow-data.ts +52 -0
- package/src/css/foundation-data/sizing/scale-data.ts +37 -0
- package/src/css/foundation-data/specimen-content.ts +10 -0
- package/src/css/foundation-data/specimens.ts +96 -0
- package/src/css/foundation-data/tokens.ts +32 -0
- package/src/css/generate-preset-css.ts +12 -0
- package/src/css/highlight.ts +34 -0
- package/src/css/manifest-utilities.ts +29 -0
- package/src/css/markdown.ts +279 -0
- package/src/css/preset-css.ts +15 -0
- package/src/css/preset-manifest.ts +3 -0
- package/src/css/stylesheet-example.ts +26 -0
- package/src/css/theme-variables.ts +74 -0
- package/src/css/variable-namespace-sources.ts +20 -0
- package/src/demo/Demo.svelte +55 -0
- package/src/demo/DemoAsset.astro +38 -0
- package/src/demo/DemoAxes.svelte +22 -0
- package/src/demo/DemoBadge.svelte +18 -0
- package/src/demo/DemoCatalog.astro +36 -0
- package/src/demo/DemoComparison.svelte +36 -0
- package/src/demo/DemoConfiguredExample.astro +48 -0
- package/src/demo/DemoContainer.svelte +48 -0
- package/src/demo/DemoControls.svelte +16 -0
- package/src/demo/DemoCopyButton.svelte +50 -0
- package/src/demo/DemoCopyGroup.svelte +15 -0
- package/src/demo/DemoExample.astro +27 -0
- package/src/demo/DemoFeatureSupport.svelte +18 -0
- package/src/demo/DemoGeneratedCSS.svelte +8 -0
- package/src/demo/DemoIndex.astro +23 -0
- package/src/demo/DemoInstallation.astro +17 -0
- package/src/demo/DemoItem.svelte +17 -0
- package/src/demo/DemoLabel.svelte +15 -0
- package/src/demo/DemoLegend.svelte +15 -0
- package/src/demo/DemoMeasure.svelte +28 -0
- package/src/demo/DemoMedia.svelte +43 -0
- package/src/demo/DemoMotion.svelte +41 -0
- package/src/demo/DemoPageViewport.astro +17 -0
- package/src/demo/DemoPalette.astro +29 -0
- package/src/demo/DemoPaletteGroups.svelte +15 -0
- package/src/demo/DemoScrollArea.svelte +15 -0
- package/src/demo/DemoStyleComparison.astro +25 -0
- package/src/demo/DemoSurface.svelte +15 -0
- package/src/demo/DemoSwatch.svelte +19 -0
- package/src/demo/DemoThemeComparison.astro +30 -0
- package/src/demo/DemoTokenTable.astro +34 -0
- package/src/demo/DemoViewTransition.astro +18 -0
- package/src/demo/DemoViewport.svelte +324 -0
- package/src/demo/DemoWaterfall.astro +30 -0
- package/src/demo/FoundationBreakpoint.astro +12 -0
- package/src/demo/ProjectStyleExample.astro +13 -0
- package/src/demo/copy-feedback.ts +10 -0
- package/src/demo/demo-waterfall.ts +17 -0
- package/src/demo/drag-readings.ts +20 -0
- package/src/demo/foundations/FoundationAxes.astro +12 -0
- package/src/demo/foundations/FoundationColorRoles.astro +5 -0
- package/src/demo/foundations/FoundationContainerGrid.astro +24 -0
- package/src/demo/foundations/FoundationDialog.astro +14 -0
- package/src/demo/foundations/FoundationElevation.astro +5 -0
- package/src/demo/foundations/FoundationElevationState.astro +5 -0
- package/src/demo/foundations/FoundationHue.astro +5 -0
- package/src/demo/foundations/FoundationLines.astro +5 -0
- package/src/demo/foundations/FoundationMedia.astro +28 -0
- package/src/demo/foundations/FoundationMotion.astro +5 -0
- package/src/demo/foundations/FoundationPalette.astro +8 -0
- package/src/demo/foundations/FoundationRadius.astro +13 -0
- package/src/demo/foundations/FoundationShapes.astro +12 -0
- package/src/demo/foundations/FoundationShrink.astro +14 -0
- package/src/demo/foundations/FoundationSizing.astro +19 -0
- package/src/demo/foundations/FoundationSpecimen.astro +20 -0
- package/src/demo/foundations/FoundationSurfaces.astro +5 -0
- package/src/demo/foundations/FoundationTextHue.astro +5 -0
- package/src/demo/foundations/FoundationTextRoles.astro +5 -0
- package/src/demo/foundations/FoundationTokens.astro +22 -0
- package/src/demo/foundations/FoundationTokensView.astro +65 -0
- package/src/demo/foundations/FoundationTransition.astro +5 -0
- package/src/demo/foundations/FoundationTypeComparison.astro +12 -0
- package/src/demo/foundations/FoundationTypography.astro +5 -0
- package/src/demo/foundations/Palette.svelte +37 -0
- package/src/demo/foundations/ShadowScaleDemo.astro +22 -0
- package/src/demo/illustration-materials.ts +180 -0
- package/src/demo/maintenance-example.ts +62 -0
- package/src/demo/playback.ts +75 -0
- package/src/demo/project-style-examples.ts +128 -0
- package/src/demo/reference/alignment.ts +42 -0
- package/src/demo/reference/animations.ts +30 -0
- package/src/demo/reference/backgrounds.ts +39 -0
- package/src/demo/reference/border-paint.ts +31 -0
- package/src/demo/reference/clipping.ts +26 -0
- package/src/demo/reference/document.ts +55 -0
- package/src/demo/reference/edges.ts +40 -0
- package/src/demo/reference/effects.ts +27 -0
- package/src/demo/reference/flexbox.ts +33 -0
- package/src/demo/reference/frame.css +118 -0
- package/src/demo/reference/grid.ts +42 -0
- package/src/demo/reference/html.ts +40 -0
- package/src/demo/reference/interaction.ts +42 -0
- package/src/demo/reference/layout-html.ts +10 -0
- package/src/demo/reference/layout.ts +102 -0
- package/src/demo/reference/media.ts +29 -0
- package/src/demo/reference/positioning.ts +90 -0
- package/src/demo/reference/scenes.ts +197 -0
- package/src/demo/reference/scrolling.ts +66 -0
- package/src/demo/reference/shapes.ts +22 -0
- package/src/demo/reference/sizing.ts +43 -0
- package/src/demo/reference/source.ts +8 -0
- package/src/demo/reference/text-effects.ts +37 -0
- package/src/demo/reference/text-flow.ts +41 -0
- package/src/demo/reference/transforms.ts +26 -0
- package/src/demo/reference/transitions.ts +24 -0
- package/src/demo/reference/type-specimens.ts +56 -0
- package/src/demo/reference/types.ts +30 -0
- package/src/demo/reference/typography.ts +32 -0
- package/src/demo/specimens/accent-color.json +50 -0
- package/src/demo/specimens/align-items.json +56 -0
- package/src/demo/specimens/animation-delay.json +55 -0
- package/src/demo/specimens/animation-direction.json +49 -0
- package/src/demo/specimens/animation-fill-mode.json +55 -0
- package/src/demo/specimens/animation-iteration-count.json +55 -0
- package/src/demo/specimens/animation-play-state.json +83 -0
- package/src/demo/specimens/animation-timing-function.json +48 -0
- package/src/demo/specimens/appearance.json +44 -0
- package/src/demo/specimens/aspect-ratio.json +28 -0
- package/src/demo/specimens/backdrop-filter.json +44 -0
- package/src/demo/specimens/background-attachment.json +49 -0
- package/src/demo/specimens/background-image.json +25 -0
- package/src/demo/specimens/background-origin.json +36 -0
- package/src/demo/specimens/background-size.json +29 -0
- package/src/demo/specimens/border-collapse.json +45 -0
- package/src/demo/specimens/border-color.json +35 -0
- package/src/demo/specimens/border-image-repeat.json +50 -0
- package/src/demo/specimens/border-image-slice.json +45 -0
- package/src/demo/specimens/border-radius.json +30 -0
- package/src/demo/specimens/box-decoration-break.json +35 -0
- package/src/demo/specimens/box-shadow.json +33 -0
- package/src/demo/specimens/clear.json +77 -0
- package/src/demo/specimens/clip-path.json +38 -0
- package/src/demo/specimens/content.json +27 -0
- package/src/demo/specimens/counter-set.json +31 -0
- package/src/demo/specimens/fill.json +23 -0
- package/src/demo/specimens/filter.json +23 -0
- package/src/demo/specimens/flex-direction.json +27 -0
- package/src/demo/specimens/flex-grow.json +27 -0
- package/src/demo/specimens/font-style.json +23 -0
- package/src/demo/specimens/font-variant-numeric.json +28 -0
- package/src/demo/specimens/grid-auto-columns.json +29 -0
- package/src/demo/specimens/grid-auto-flow.json +37 -0
- package/src/demo/specimens/grid-template-areas.json +34 -0
- package/src/demo/specimens/grid-template-columns.json +36 -0
- package/src/demo/specimens/isolation.json +25 -0
- package/src/demo/specimens/justify-content.json +36 -0
- package/src/demo/specimens/line-height.json +28 -0
- package/src/demo/specimens/list-style-position.json +36 -0
- package/src/demo/specimens/mask-image.json +54 -0
- package/src/demo/specimens/min-width.json +39 -0
- package/src/demo/specimens/mix-blend-mode.json +43 -0
- package/src/demo/specimens/object-fit.json +27 -0
- package/src/demo/specimens/object-position.json +27 -0
- package/src/demo/specimens/opacity.json +37 -0
- package/src/demo/specimens/order.json +28 -0
- package/src/demo/specimens/overflow-wrap.json +26 -0
- package/src/demo/specimens/overflow.json +53 -0
- package/src/demo/specimens/overscroll-behavior.json +29 -0
- package/src/demo/specimens/padding.json +84 -0
- package/src/demo/specimens/place-content.json +31 -0
- package/src/demo/specimens/pointer-events.json +46 -0
- package/src/demo/specimens/position.json +29 -0
- package/src/demo/specimens/resize.json +32 -0
- package/src/demo/specimens/screen-readers.json +37 -0
- package/src/demo/specimens/scroll-padding.json +29 -0
- package/src/demo/specimens/scroll-snap-stop.json +33 -0
- package/src/demo/specimens/shape-image-threshold.json +37 -0
- package/src/demo/specimens/shape-margin.json +40 -0
- package/src/demo/specimens/shape-outside.json +37 -0
- package/src/demo/specimens/stroke-width.json +27 -0
- package/src/demo/specimens/text-fill-color.json +23 -0
- package/src/demo/specimens/text-stroke-width.json +32 -0
- package/src/demo/specimens/touch-action.json +45 -0
- package/src/demo/specimens/transform-box.json +37 -0
- package/src/demo/specimens/transform-origin.json +56 -0
- package/src/demo/specimens/transform-style.json +55 -0
- package/src/demo/specimens/transform.json +47 -0
- package/src/demo/specimens/transition-delay.json +57 -0
- package/src/demo/specimens/transition-duration.json +60 -0
- package/src/demo/specimens/transition-property.json +60 -0
- package/src/demo/specimens/transition-timing-function.json +65 -0
- package/src/demo/specimens/user-drag.json +28 -0
- package/src/demo/specimens/user-select.json +25 -0
- package/src/demo/specimens/vertical-align.json +28 -0
- package/src/demo/specimens/width.json +56 -0
- package/src/demo/specimens/will-change.json +50 -0
- package/src/demo/specimens/writing-mode.json +26 -0
- package/src/demo/specimens/z-index.json +35 -0
- package/src/demo/style.ts +15 -0
- package/src/demo/tone.ts +4 -0
- package/src/demo/useDemoViewTransition.svelte.ts +71 -0
- package/src/docs-shell/common/i18n.config.d.ts +2 -0
- package/src/docs-shell/common/i18n.config.js +13 -0
- package/src/docs-shell/common/svgo.config.d.ts +2 -0
- package/src/docs-shell/common/svgo.config.js +11 -0
- package/src/docs-shell/components/ArticleHeader.astro +65 -0
- package/src/docs-shell/components/ArticleTOC.astro +18 -0
- package/src/docs-shell/components/Callout.astro +26 -0
- package/src/docs-shell/components/Code.astro +25 -0
- package/src/docs-shell/components/CodeCopyButton.astro +25 -0
- package/src/docs-shell/components/CodeTabBar.astro +40 -0
- package/src/docs-shell/components/CodeTabs.astro +53 -0
- package/src/docs-shell/components/CodeView.astro +23 -0
- package/src/docs-shell/components/Do.astro +5 -0
- package/src/docs-shell/components/DoNot.astro +5 -0
- package/src/docs-shell/components/DocArticle.astro +14 -0
- package/src/docs-shell/components/DocHeader.svelte +87 -0
- package/src/docs-shell/components/DocHeading.astro +28 -0
- package/src/docs-shell/components/DocMain.astro +19 -0
- package/src/docs-shell/components/DocMenuButton.svelte +95 -0
- package/src/docs-shell/components/DocSidebar.svelte +62 -0
- package/src/docs-shell/components/DocVersionSelect.svelte +22 -0
- package/src/docs-shell/components/DocWrapper.astro +11 -0
- package/src/docs-shell/components/DocumentAPIIndex.astro +24 -0
- package/src/docs-shell/components/DocumentChoices.astro +24 -0
- package/src/docs-shell/components/DocumentCodeExample.astro +20 -0
- package/src/docs-shell/components/DocumentCodeExampleView.astro +35 -0
- package/src/docs-shell/components/DocumentCodeTable.astro +19 -0
- package/src/docs-shell/components/DocumentComparison.astro +7 -0
- package/src/docs-shell/components/DocumentCopyButton.svelte +41 -0
- package/src/docs-shell/components/DocumentDeclaration.astro +17 -0
- package/src/docs-shell/components/DocumentDeclarationView.astro +12 -0
- package/src/docs-shell/components/DocumentDisclosure.astro +14 -0
- package/src/docs-shell/components/DocumentFileTree.astro +34 -0
- package/src/docs-shell/components/DocumentFlow.astro +27 -0
- package/src/docs-shell/components/DocumentIdentifier.astro +14 -0
- package/src/docs-shell/components/DocumentIllustration.astro +46 -0
- package/src/docs-shell/components/DocumentKeyList.astro +22 -0
- package/src/docs-shell/components/DocumentNamespaceTable.astro +20 -0
- package/src/docs-shell/components/DocumentOptionEntry.astro +15 -0
- package/src/docs-shell/components/DocumentOptionList.astro +11 -0
- package/src/docs-shell/components/DocumentOptions.astro +23 -0
- package/src/docs-shell/components/DocumentParameters.astro +30 -0
- package/src/docs-shell/components/DocumentPrompt.astro +16 -0
- package/src/docs-shell/components/DocumentValueList.astro +25 -0
- package/src/docs-shell/components/DocumentationIndex.svelte +144 -0
- package/src/docs-shell/components/Dropped.astro +21 -0
- package/src/docs-shell/components/ExpandContent.svelte +21 -0
- package/src/docs-shell/components/ExplorerView.astro +37 -0
- package/src/docs-shell/components/FileIcon.astro +123 -0
- package/src/docs-shell/components/Footer.svelte +80 -0
- package/src/docs-shell/components/GeneratedCSS.astro +8 -0
- package/src/docs-shell/components/Header.svelte +121 -0
- package/src/docs-shell/components/HeaderIcon.astro +14 -0
- package/src/docs-shell/components/HeaderNav.svelte +18 -0
- package/src/docs-shell/components/Image.svelte +56 -0
- package/src/docs-shell/components/Info.astro +5 -0
- package/src/docs-shell/components/InlineCode.astro +30 -0
- package/src/docs-shell/components/InteractingIndicator.astro +19 -0
- package/src/docs-shell/components/LanguageButton.svelte +18 -0
- package/src/docs-shell/components/LanguageSelect.svelte +44 -0
- package/src/docs-shell/components/Link.svelte +127 -0
- package/src/docs-shell/components/ModeImg.astro +11 -0
- package/src/docs-shell/components/NotFound.astro +21 -0
- package/src/docs-shell/components/OverviewButtons.astro +36 -0
- package/src/docs-shell/components/PMAction.astro +25 -0
- package/src/docs-shell/components/PackageBadges.astro +39 -0
- package/src/docs-shell/components/PageContent.svelte +38 -0
- package/src/docs-shell/components/PageContentBootstrap.astro +13 -0
- package/src/docs-shell/components/PageContentDisclosure.astro +25 -0
- package/src/docs-shell/components/PageContentList.svelte +70 -0
- package/src/docs-shell/components/PageContentProvider.svelte +15 -0
- package/src/docs-shell/components/PageContentTitle.svelte +16 -0
- package/src/docs-shell/components/PageNavs.astro +40 -0
- package/src/docs-shell/components/PreparedCodeView.astro +12 -0
- package/src/docs-shell/components/RenderNode.astro +16 -0
- package/src/docs-shell/components/RouteLayers.astro +17 -0
- package/src/docs-shell/components/SearchButton.svelte +31 -0
- package/src/docs-shell/components/SearchDialog.svelte +174 -0
- package/src/docs-shell/components/Segments.svelte +62 -0
- package/src/docs-shell/components/Step.astro +13 -0
- package/src/docs-shell/components/StepL.astro +10 -0
- package/src/docs-shell/components/StepR.astro +10 -0
- package/src/docs-shell/components/StepSection.astro +12 -0
- package/src/docs-shell/components/Tab.astro +8 -0
- package/src/docs-shell/components/Tabs.astro +10 -0
- package/src/docs-shell/components/ThemeIcon.astro +19 -0
- package/src/docs-shell/components/ThemeSelect.svelte +20 -0
- package/src/docs-shell/components/TimeAgo.svelte +32 -0
- package/src/docs-shell/components/Translate.astro +14 -0
- package/src/docs-shell/components/Warn.astro +5 -0
- package/src/docs-shell/components/code-props.ts +28 -0
- package/src/docs-shell/components/document-types.ts +119 -0
- package/src/docs-shell/components/markdown/Anchor.astro +5 -0
- package/src/docs-shell/components/markdown/Heading2.astro +5 -0
- package/src/docs-shell/components/markdown/Heading3.astro +5 -0
- package/src/docs-shell/components/markdown/Table.astro +6 -0
- package/src/docs-shell/components/markdown-components.ts +36 -0
- package/src/docs-shell/components/page-content-bootstrap.ts +115 -0
- package/src/docs-shell/components/page-content.svelte.ts +125 -0
- package/src/docs-shell/contexts/search.ts +18 -0
- package/src/docs-shell/contexts/theme-mode.svelte.ts +61 -0
- package/src/docs-shell/data/authors.ts +17 -0
- package/src/docs-shell/data/base-colors.ts +29 -0
- package/src/docs-shell/data/brands.ts +79 -0
- package/src/docs-shell/data/color-names.ts +1 -0
- package/src/docs-shell/data/color-palette.ts +50 -0
- package/src/docs-shell/data/colors.ts +1 -0
- package/src/docs-shell/factories/Page.astro +35 -0
- package/src/docs-shell/factories/create-page.ts +31 -0
- package/src/docs-shell/layouts/BlogArticle.astro +53 -0
- package/src/docs-shell/layouts/Doc.astro +41 -0
- package/src/docs-shell/remark/markdown-components.d.ts +2 -0
- package/src/docs-shell/remark/markdown-components.js +101 -0
- package/src/docs-shell/remark/slug-and-toc.d.ts +2 -0
- package/src/docs-shell/remark/slug-and-toc.js +53 -0
- package/src/docs-shell/scripts/code-tabs-bootstrap.ts +34 -0
- package/src/docs-shell/scripts/code.ts +124 -0
- package/src/docs-shell/scripts/document-anchor.ts +57 -0
- package/src/docs-shell/scripts/document.ts +47 -0
- package/src/docs-shell/site.ts +67 -0
- package/src/docs-shell/types/IllustrationImages.ts +2 -0
- package/src/docs-shell/types/Metadata.ts +17 -0
- package/src/docs-shell/types/Props.ts +9 -0
- package/src/docs-shell/types/StaticImage.ts +6 -0
- package/src/docs-shell/uses/use-selected-preview-syntax.svelte.ts +16 -0
- package/src/docs-shell/utils/anchor.ts +24 -0
- package/src/docs-shell/utils/beautify-css.ts +14 -0
- package/src/docs-shell/utils/beautify-html.ts +12 -0
- package/src/docs-shell/utils/beautify-js.ts +9 -0
- package/src/docs-shell/utils/create-highlighter.ts +50 -0
- package/src/docs-shell/utils/css-modern-grammar.ts +339 -0
- package/src/docs-shell/utils/documentation-search.ts +68 -0
- package/src/docs-shell/utils/generate-metadata.ts +60 -0
- package/src/docs-shell/utils/group-page-content.ts +10 -0
- package/src/docs-shell/utils/head.ts +72 -0
- package/src/docs-shell/utils/highlight-code-core.ts +146 -0
- package/src/docs-shell/utils/highlight-code.ts +1 -0
- package/src/docs-shell/utils/highlighted-code-text.ts +27 -0
- package/src/docs-shell/utils/i18n-pathname.ts +98 -0
- package/src/docs-shell/utils/i18n.ts +12 -0
- package/src/docs-shell/utils/is-date-within-seven-days.ts +16 -0
- package/src/docs-shell/utils/isBrowser.ts +1 -0
- package/src/docs-shell/utils/isInteractOutside.ts +16 -0
- package/src/docs-shell/utils/markdown-tree.ts +22 -0
- package/src/docs-shell/utils/metadata.ts +25 -0
- package/src/docs-shell/utils/prepared-code.ts +21 -0
- package/src/docs-shell/utils/resolve-heading.d.ts +1 -0
- package/src/docs-shell/utils/resolve-heading.js +19 -0
- package/src/docs-shell/utils/search-pages.ts +271 -0
- package/src/docs-shell/utils/slot-text.ts +15 -0
- package/src/docs-shell/utils/snackbar.ts +39 -0
- package/src/docs-shell/utils/syntax-theme.ts +53 -0
- package/src/docs-shell/utils/transformer-notation-word-mark.ts +146 -0
- package/src/docs-shell/utils/unique-id.ts +11 -0
- package/src/examples/article-transitions/page.astro +7 -0
- package/src/examples/article-transitions/transitions.css +10 -0
- package/src/examples/components/ArticleTransitionScene.svelte +83 -0
- package/src/examples/components/ViewTransitionScene.svelte +31 -0
- package/src/examples/images/article-aurora.jpg +0 -0
- package/src/examples/images/article-coast.jpg +0 -0
- package/src/examples/images/article-grid.jpg +0 -0
- package/src/examples/images/article-studio.jpg +0 -0
- package/src/examples/layout-system/page.astro +59 -0
- package/src/examples/scene.css +3 -0
- package/src/examples/view-transitions/page.astro +7 -0
- package/src/examples/view-transitions/transitions.css +9 -0
- package/src/home/HeroCanvas.svelte +617 -0
- package/src/home/HomeAction.astro +17 -0
- package/src/home/HomeBentoFrame.astro +9 -0
- package/src/home/HomeBentoGrid.astro +9 -0
- package/src/home/HomeCompactIcon.astro +15 -0
- package/src/home/HomeFooter.svelte +63 -0
- package/src/home/HomeIllustration.astro +17 -0
- package/src/home/HomeIllustrationArt.svelte +15 -0
- package/src/home/HomeLamp.svelte +18 -0
- package/src/home/design.css +532 -0
- package/src/home/footer.css +225 -0
- package/src/home/hero-shaders.ts +460 -0
- package/src/home/hero-title-mask.ts +175 -0
- package/src/home/hero.css +547 -0
- package/src/home/home-illustration.ts +5 -0
- package/src/home/home-lamp.ts +225 -0
- package/src/home/home.css +1077 -0
- package/src/home/icons/agent-check-preview-apply.svg +24 -0
- package/src/home/icons/agent-clients.svg +26 -0
- package/src/home/icons/agent-project-tools.svg +23 -0
- package/src/home/icons/artwork/agent-check-preview-apply-dark.webp +0 -0
- package/src/home/icons/artwork/agent-check-preview-apply-light.webp +0 -0
- package/src/home/icons/artwork/agent-clients-dark.webp +0 -0
- package/src/home/icons/artwork/agent-clients-light.webp +0 -0
- package/src/home/icons/artwork/agent-edit-file-dark.webp +0 -0
- package/src/home/icons/artwork/agent-edit-file-light.webp +0 -0
- package/src/home/icons/artwork/agent-project-tools-dark.webp +0 -0
- package/src/home/icons/artwork/agent-project-tools-light.webp +0 -0
- package/src/home/icons/artwork/design-cascade-layers-dark.webp +0 -0
- package/src/home/icons/artwork/design-cascade-layers-light.webp +0 -0
- package/src/home/icons/artwork/design-layout-motion-dark.webp +0 -0
- package/src/home/icons/artwork/design-layout-motion-light.webp +0 -0
- package/src/home/icons/artwork/design-p3-gamut-dark.webp +0 -0
- package/src/home/icons/artwork/design-p3-gamut-light.webp +0 -0
- package/src/home/icons/artwork/design-theme-modes-dark.webp +0 -0
- package/src/home/icons/artwork/design-theme-modes-light.webp +0 -0
- package/src/home/icons/artwork/design-theme-tokens-dark.webp +0 -0
- package/src/home/icons/artwork/design-theme-tokens-light.webp +0 -0
- package/src/home/icons/artwork/editor-color-tools-dark.webp +0 -0
- package/src/home/icons/artwork/editor-color-tools-light.webp +0 -0
- package/src/home/icons/artwork/editor-focused-highlighting-dark.webp +0 -0
- package/src/home/icons/artwork/editor-focused-highlighting-light.webp +0 -0
- package/src/home/icons/artwork/editor-hover-inspection-dark.webp +0 -0
- package/src/home/icons/artwork/editor-hover-inspection-light.webp +0 -0
- package/src/home/icons/artwork/editor-manifest-completions-dark.webp +0 -0
- package/src/home/icons/artwork/editor-manifest-completions-light.webp +0 -0
- package/src/home/icons/artwork/lint-class-order-dark.webp +0 -0
- package/src/home/icons/artwork/lint-class-order-light.webp +0 -0
- package/src/home/icons/artwork/lint-conflicting-classes-dark.webp +0 -0
- package/src/home/icons/artwork/lint-conflicting-classes-light.webp +0 -0
- package/src/home/icons/artwork/lint-fix-previews-dark.webp +0 -0
- package/src/home/icons/artwork/lint-fix-previews-light.webp +0 -0
- package/src/home/icons/artwork/lint-invalid-classes-dark.webp +0 -0
- package/src/home/icons/artwork/lint-invalid-classes-light.webp +0 -0
- package/src/home/icons/artwork/lint-strict-vocabulary-dark.webp +0 -0
- package/src/home/icons/artwork/lint-strict-vocabulary-light.webp +0 -0
- package/src/home/icons/artwork/lint-theme-tokens-dark.webp +0 -0
- package/src/home/icons/artwork/lint-theme-tokens-light.webp +0 -0
- package/src/home/icons/artwork/mcp-apply-preview-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-apply-preview-light.webp +0 -0
- package/src/home/icons/artwork/mcp-css-compare-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-css-compare-light.webp +0 -0
- package/src/home/icons/artwork/mcp-inspect-class-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-inspect-class-light.webp +0 -0
- package/src/home/icons/artwork/mcp-lint-project-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-lint-project-light.webp +0 -0
- package/src/home/icons/artwork/mcp-manifest-query-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-manifest-query-light.webp +0 -0
- package/src/home/icons/artwork/mcp-preview-fixes-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-preview-fixes-light.webp +0 -0
- package/src/home/icons/artwork/mcp-render-css-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-render-css-light.webp +0 -0
- package/src/home/icons/artwork/mcp-scan-project-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-scan-project-light.webp +0 -0
- package/src/home/icons/artwork/mcp-trace-class-dark.webp +0 -0
- package/src/home/icons/artwork/mcp-trace-class-light.webp +0 -0
- package/src/home/icons/artwork/render-progressive-dark.webp +0 -0
- package/src/home/icons/artwork/render-progressive-light.webp +0 -0
- package/src/home/icons/artwork/render-runtime-dark.webp +0 -0
- package/src/home/icons/artwork/render-runtime-light.webp +0 -0
- package/src/home/icons/artwork/render-static-dark.webp +0 -0
- package/src/home/icons/artwork/render-static-light.webp +0 -0
- package/src/home/icons/artwork/section-ai-agents-dark.webp +0 -0
- package/src/home/icons/artwork/section-ai-agents-light.webp +0 -0
- package/src/home/icons/artwork/section-css-size-dark.webp +0 -0
- package/src/home/icons/artwork/section-css-size-light.webp +0 -0
- package/src/home/icons/artwork/section-design-system-dark.webp +0 -0
- package/src/home/icons/artwork/section-design-system-light.webp +0 -0
- package/src/home/icons/artwork/section-editor-dark.webp +0 -0
- package/src/home/icons/artwork/section-editor-light.webp +0 -0
- package/src/home/icons/artwork/section-lint-dark.webp +0 -0
- package/src/home/icons/artwork/section-lint-light.webp +0 -0
- package/src/home/icons/artwork/section-rendering-dark.webp +0 -0
- package/src/home/icons/artwork/section-rendering-light.webp +0 -0
- package/src/home/icons/artwork/section-workflow-dark.webp +0 -0
- package/src/home/icons/artwork/section-workflow-light.webp +0 -0
- package/src/home/icons/artwork/source.json +303 -0
- package/src/home/icons/artwork/workflow-integrations-dark.webp +0 -0
- package/src/home/icons/artwork/workflow-integrations-light.webp +0 -0
- package/src/home/icons/artwork/workflow-monorepo-dark.webp +0 -0
- package/src/home/icons/artwork/workflow-monorepo-light.webp +0 -0
- package/src/home/icons/artwork/workflow-route-styles-dark.webp +0 -0
- package/src/home/icons/artwork/workflow-route-styles-light.webp +0 -0
- package/src/home/icons/artwork/workflow-trace-change-dark.webp +0 -0
- package/src/home/icons/artwork/workflow-trace-change-light.webp +0 -0
- package/src/home/icons/artwork.css +4 -0
- package/src/home/icons/artwork.ts +131 -0
- package/src/home/icons/catalog.ts +381 -0
- package/src/home/icons/design-cascade-layers.svg +32 -0
- package/src/home/icons/design-layout-motion.svg +16 -0
- package/src/home/icons/design-p3-gamut.svg +12 -0
- package/src/home/icons/design-theme-modes.svg +12 -0
- package/src/home/icons/design-theme-tokens.svg +20 -0
- package/src/home/icons/editor-color-tools.svg +18 -0
- package/src/home/icons/editor-focused-highlighting.svg +15 -0
- package/src/home/icons/editor-hover-inspection.svg +19 -0
- package/src/home/icons/editor-manifest-completions.svg +24 -0
- package/src/home/icons/lint-class-order-compact.svg +15 -0
- package/src/home/icons/lint-class-order.svg +28 -0
- package/src/home/icons/lint-conflicting-classes-compact.svg +11 -0
- package/src/home/icons/lint-conflicting-classes.svg +24 -0
- package/src/home/icons/lint-fix-previews-compact.svg +9 -0
- package/src/home/icons/lint-fix-previews.svg +19 -0
- package/src/home/icons/lint-invalid-classes-compact.svg +7 -0
- package/src/home/icons/lint-invalid-classes.svg +17 -0
- package/src/home/icons/lint-strict-vocabulary-compact.svg +8 -0
- package/src/home/icons/lint-strict-vocabulary.svg +16 -0
- package/src/home/icons/lint-theme-tokens-compact.svg +7 -0
- package/src/home/icons/lint-theme-tokens.svg +14 -0
- package/src/home/icons/mcp-apply-preview-compact.svg +9 -0
- package/src/home/icons/mcp-apply-preview.svg +18 -0
- package/src/home/icons/mcp-css-compare-compact.svg +9 -0
- package/src/home/icons/mcp-css-compare.svg +20 -0
- package/src/home/icons/mcp-inspect-class-compact.svg +9 -0
- package/src/home/icons/mcp-inspect-class.svg +18 -0
- package/src/home/icons/mcp-lint-project-compact.svg +14 -0
- package/src/home/icons/mcp-lint-project.svg +30 -0
- package/src/home/icons/mcp-manifest-query-compact.svg +14 -0
- package/src/home/icons/mcp-manifest-query.svg +27 -0
- package/src/home/icons/mcp-preview-fixes-compact.svg +9 -0
- package/src/home/icons/mcp-preview-fixes.svg +15 -0
- package/src/home/icons/mcp-render-css-compact.svg +13 -0
- package/src/home/icons/mcp-render-css.svg +30 -0
- package/src/home/icons/mcp-scan-project-compact.svg +7 -0
- package/src/home/icons/mcp-scan-project.svg +13 -0
- package/src/home/icons/mcp-trace-class-compact.svg +11 -0
- package/src/home/icons/mcp-trace-class.svg +24 -0
- package/src/home/icons/render-progressive.svg +17 -0
- package/src/home/icons/render-runtime.svg +23 -0
- package/src/home/icons/render-static.svg +29 -0
- package/src/home/icons/section-ai-agents.svg +24 -0
- package/src/home/icons/section-css-size.svg +13 -0
- package/src/home/icons/section-design-system.svg +24 -0
- package/src/home/icons/section-editor.svg +14 -0
- package/src/home/icons/section-lint.svg +14 -0
- package/src/home/icons/section-rendering.svg +30 -0
- package/src/home/icons/section-workflow.svg +22 -0
- package/src/home/icons/workflow-integrations.svg +15 -0
- package/src/home/icons/workflow-monorepo.svg +27 -0
- package/src/home/icons/workflow-route-styles.svg +24 -0
- package/src/home/icons/workflow-trace-change.svg +21 -0
- package/src/layouts/Document.astro +71 -0
- package/src/public/brand/v2/logo/mark/master-mark-small-on-dark.svg +1 -0
- package/src/public/brand/v2/logo/master-css/master-css-horizontal-on-dark.svg +1 -0
- package/src/public/brand/v2/logo/master-css/master-css-horizontal-on-light.svg +1 -0
- package/src/public/demo/border-grid.svg +7 -0
- package/src/public/demo/landscape.svg +1 -0
- package/src/public/demo/marker.svg +1 -0
- package/src/public/demo/mask.svg +1 -0
- package/src/public/fonts/Geist-Medium.ttf +0 -0
- package/src/public/fonts/Geist-Regular.ttf +0 -0
- package/src/public/fonts/GeistVariable.woff2 +0 -0
- package/src/public/fonts/IBMPlexMono-Bold.woff2 +0 -0
- package/src/public/fonts/IBMPlexMono-Medium.woff2 +0 -0
- package/src/public/fonts/IBMPlexMono-Regular.woff2 +0 -0
- package/src/public/fonts/IBMPlexMono-SemiBold.woff2 +0 -0
- package/src/public/fonts/index.css +40 -0
- package/src/public/icons/csharp.svg +1 -0
- package/src/public/icons/css.svg +1 -0
- package/src/public/icons/eslint.svg +1 -0
- package/src/public/icons/folder.svg +12 -0
- package/src/public/icons/html.svg +1 -0
- package/src/public/icons/php.svg +1 -0
- package/src/public/icons/sass.svg +1 -0
- package/src/public/icons/storybook.svg +1 -0
- package/src/public/icons/visualstudiocode.svg +41 -0
- package/src/public/images/authors/aron.jpg +0 -0
- package/src/public/images/authors/benseage.jpg +0 -0
- package/src/public/images/authors/joy.jpg +0 -0
- package/src/public/images/authors/lola.jpg +0 -0
- package/src/public/images/authors/miles.jpg +0 -0
- package/src/public/images/bootstrap.svg +23 -0
- package/src/public/images/build-tools/rsbuild.svg +1 -0
- package/src/public/images/build-tools/rspack.svg +1 -0
- package/src/public/images/build-tools/vite.svg +15 -0
- package/src/public/images/build-tools/webpack.svg +10 -0
- package/src/public/images/cdns/esm-sh.svg +1 -0
- package/src/public/images/chevron-left.svg +4 -0
- package/src/public/images/cover-bg.jpg +0 -0
- package/src/public/images/emotion.svg +1 -0
- package/src/public/images/frameworks/angular.svg +29 -0
- package/src/public/images/frameworks/astro.svg +4 -0
- package/src/public/images/frameworks/blazor.svg +22 -0
- package/src/public/images/frameworks/express.svg +1 -0
- package/src/public/images/frameworks/laravel.svg +8 -0
- package/src/public/images/frameworks/line-liff.svg +1 -0
- package/src/public/images/frameworks/lit.svg +1 -0
- package/src/public/images/frameworks/nextjs.svg +16 -0
- package/src/public/images/frameworks/nuxtjs.svg +3 -0
- package/src/public/images/frameworks/rails.svg +1 -0
- package/src/public/images/frameworks/react.svg +8 -0
- package/src/public/images/frameworks/remix.svg +5 -0
- package/src/public/images/frameworks/shopify.svg +1 -0
- package/src/public/images/frameworks/svelte.svg +6 -0
- package/src/public/images/frameworks/tanstack.svg +1 -0
- package/src/public/images/frameworks/vuejs.svg +11 -0
- package/src/public/images/frameworks/wordpress.svg +1 -0
- package/src/public/images/mui.svg +1 -0
- package/src/public/images/styled-components.svg +4 -0
- package/src/public/images/tailwindcss.svg +1 -0
- package/src/scripts/bundler-imports.ts +25 -0
- package/src/scripts/static-social.ts +333 -0
- package/src/scripts/write-if-changed.ts +26 -0
- package/src/sections/blog.astro +11 -0
- package/src/sections/design-system.astro +14 -0
- package/src/sections/document.astro +8 -0
- package/src/sections/examples.astro +6 -0
- package/src/sections/guide.astro +26 -0
- package/src/sections/home.astro +7 -0
- package/src/sections/page.astro +12 -0
- package/src/styles/base.css +57 -0
- package/src/styles/benchmarks.css +20 -0
- package/src/styles/blog-article.css +670 -0
- package/src/styles/blog-materials.css +399 -0
- package/src/styles/blog.css +568 -0
- package/src/styles/demo.css +30 -0
- package/src/styles/design-system.css +15 -0
- package/src/styles/docs-shell/code.css +61 -0
- package/src/styles/docs-shell/docs.css +79 -0
- package/src/styles/docs-shell/documentation-search.css +42 -0
- package/src/styles/docs-shell/footer.css +38 -0
- package/src/styles/docs-shell/header.css +69 -0
- package/src/styles/docs-shell/materials.css +25 -0
- package/src/styles/docs-shell/menu.css +19 -0
- package/src/styles/docs-shell/not-found.css +10 -0
- package/src/styles/docs-shell/page-content.css +37 -0
- package/src/styles/docs-shell/prose.css +89 -0
- package/src/styles/docs-shell/segments.css +13 -0
- package/src/styles/docs-shell/steps.css +39 -0
- package/src/styles/docs-shell/syntax-theme.css +18 -0
- package/src/styles/docs-shell/theme.css +68 -0
- package/src/styles/docs-shell/wrapper.css +10 -0
- package/src/styles/document-comparison.css +7 -0
- package/src/styles/documentation-illustration.css +34 -0
- package/src/styles/documentation-index.css +100 -0
- package/src/styles/documents.css +4 -0
- package/src/styles/documents.ts +2 -0
- package/src/styles/foundation.css +4 -0
- package/src/styles/globals.css +2 -0
- package/src/styles/interface.css +3 -0
- package/src/styles/interface.ts +2 -0
- package/src/styles/site.ts +2 -0
- package/src/styles/system/DESIGN.md +108 -0
- package/src/styles/system/buttons.css +51 -0
- package/src/styles/system/code.css +85 -0
- package/src/styles/system/controls.css +110 -0
- package/src/styles/system/data.css +134 -0
- package/src/styles/system/mixins.css +7 -0
- package/src/styles/system/prose.css +75 -0
- package/src/styles/system/shell.css +102 -0
- package/src/styles/system/specimens.css +98 -0
- package/src/styles/system/surfaces.css +104 -0
- package/src/styles/system/tokens.css +136 -0
- package/src/utils/cloudflare-image-loader.js +85 -0
- package/src/virtual.d.ts +36 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { HighlighterCore, ShikiTransformer } from 'shiki/core'
|
|
2
|
+
import { transformerNotationDiff, transformerNotationFocus, transformerNotationHighlight, transformerRemoveLineBreak } from '@shikijs/transformers'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import { dedent } from 'ts-dedent'
|
|
5
|
+
import { beautifyCSS } from '../utils/beautify-css'
|
|
6
|
+
import beautifyJS from '../utils/beautify-js'
|
|
7
|
+
import { beautifyHTML } from '../utils/beautify-html'
|
|
8
|
+
import createHighlighter, { theme } from './create-highlighter'
|
|
9
|
+
import transformerNotationWordMark from './transformer-notation-word-mark'
|
|
10
|
+
import { defu } from 'defu'
|
|
11
|
+
|
|
12
|
+
export type HighlightOptions = {
|
|
13
|
+
lang: string,
|
|
14
|
+
inline?: boolean,
|
|
15
|
+
beautify?: boolean
|
|
16
|
+
dedent?: boolean | 'block'
|
|
17
|
+
className?: string
|
|
18
|
+
[key: string]: unknown
|
|
19
|
+
transformers?: ShikiTransformer[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Notation classes Shiki's transformers add to a line, read back as its `data-mark`. */
|
|
23
|
+
const lineMarks = { added: 'notation-added', removed: 'notation-removed', active: 'notation-active' } as const
|
|
24
|
+
export interface HighlightAdapter {
|
|
25
|
+
languages?: import('shiki/core').LanguageRegistration[]
|
|
26
|
+
resolveLanguage?: (language: string) => string
|
|
27
|
+
transformers?: (language: string, options: HighlightOptions) => ShikiTransformer[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createCodeHighlighter(adapter: HighlightAdapter = {}) {
|
|
31
|
+
let highlighterPromise: Promise<HighlighterCore> | undefined
|
|
32
|
+
return async function highlightCode(code: string, options: HighlightOptions) {
|
|
33
|
+
options = defu(options, {
|
|
34
|
+
lang: 'plaintext',
|
|
35
|
+
inline: false,
|
|
36
|
+
beautify: false,
|
|
37
|
+
dedent: true,
|
|
38
|
+
mergeWhitespaces: false
|
|
39
|
+
} as HighlightOptions) as HighlightOptions
|
|
40
|
+
const transformers: ShikiTransformer[] = []
|
|
41
|
+
const lang = options.lang
|
|
42
|
+
const shikiLang = adapter.resolveLanguage?.(lang) ?? lang
|
|
43
|
+
if (options.beautify) {
|
|
44
|
+
switch (lang) {
|
|
45
|
+
case 'css':
|
|
46
|
+
code = beautifyCSS(code)
|
|
47
|
+
break
|
|
48
|
+
case 'html':
|
|
49
|
+
code = beautifyHTML(code)
|
|
50
|
+
break
|
|
51
|
+
default:
|
|
52
|
+
code = beautifyJS(code)
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (options.inline) {
|
|
57
|
+
transformers.push({
|
|
58
|
+
line(hast) {
|
|
59
|
+
hast.properties!.class = ''
|
|
60
|
+
},
|
|
61
|
+
code(element) {
|
|
62
|
+
element.properties!.class = clsx('shiki', options.className)
|
|
63
|
+
},
|
|
64
|
+
root(root) {
|
|
65
|
+
const code = (root.children![0] as any).children![0]
|
|
66
|
+
root.children = [code]
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
} else {
|
|
70
|
+
transformers.push(
|
|
71
|
+
transformerNotationDiff({
|
|
72
|
+
classLineAdd: lineMarks.added,
|
|
73
|
+
classLineRemove: lineMarks.removed,
|
|
74
|
+
}),
|
|
75
|
+
transformerRemoveLineBreak(),
|
|
76
|
+
transformerNotationWordMark(),
|
|
77
|
+
transformerNotationHighlight({
|
|
78
|
+
classActiveLine: lineMarks.active,
|
|
79
|
+
}),
|
|
80
|
+
transformerNotationFocus({
|
|
81
|
+
classActiveLine: 'focus',
|
|
82
|
+
}),
|
|
83
|
+
{
|
|
84
|
+
pre(element) {
|
|
85
|
+
element!.properties!.class = clsx(element!.properties!.class, options.className)
|
|
86
|
+
delete element!.properties!.style
|
|
87
|
+
},
|
|
88
|
+
code(element) {
|
|
89
|
+
delete element!.properties!.class
|
|
90
|
+
// Lines are `ui-code-line` parts; a notation's line state becomes their `data-mark`.
|
|
91
|
+
for (const line of element.children) {
|
|
92
|
+
if (line.type !== 'element') continue
|
|
93
|
+
const raw = line.properties.class
|
|
94
|
+
const classes = new Set((Array.isArray(raw) ? raw.map(String) : String(raw ?? '').split(/\s+/)).filter(Boolean))
|
|
95
|
+
for (const [mark, className] of Object.entries(lineMarks)) {
|
|
96
|
+
if (classes.delete(className)) line.properties.dataMark = mark
|
|
97
|
+
}
|
|
98
|
+
// An array: the Master CSS transformer finds lines by an exact `line` entry.
|
|
99
|
+
line.properties.class = [...classes, 'ui-code-line']
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
transformers.push(...(adapter.transformers?.(lang, options) ?? []))
|
|
106
|
+
if (options.transformers) {
|
|
107
|
+
transformers.push(...options.transformers)
|
|
108
|
+
}
|
|
109
|
+
const normalizedCode = options.dedent === false
|
|
110
|
+
? trimCodeBlockBoundary(code)
|
|
111
|
+
: options.dedent === 'block'
|
|
112
|
+
? dedentCodeBlock(code)
|
|
113
|
+
: dedent(code).trim()
|
|
114
|
+
const hast = (await (highlighterPromise ??= createHighlighter(adapter.languages))).codeToHast(normalizedCode, {
|
|
115
|
+
...options,
|
|
116
|
+
lang: shikiLang,
|
|
117
|
+
theme,
|
|
118
|
+
transformers,
|
|
119
|
+
})
|
|
120
|
+
return hast
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default createCodeHighlighter()
|
|
126
|
+
|
|
127
|
+
function trimCodeBlockBoundary(code: string): string {
|
|
128
|
+
return code.replace(/^\r?\n/, '').replace(/\r?\n$/, '')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function dedentCodeBlock(code: string): string {
|
|
132
|
+
code = trimCodeBlockBoundary(code)
|
|
133
|
+
const lines = code.split(/\r?\n/)
|
|
134
|
+
const firstCodeLine = lines.find((line) => line.trim())
|
|
135
|
+
if (!firstCodeLine || !countIndent(firstCodeLine)) return code
|
|
136
|
+
const commonIndent = lines.reduce((minIndent, line) => {
|
|
137
|
+
if (!line.trim()) return minIndent
|
|
138
|
+
return Math.min(minIndent, countIndent(line))
|
|
139
|
+
}, Infinity)
|
|
140
|
+
if (!Number.isFinite(commonIndent) || commonIndent === 0) return code
|
|
141
|
+
return lines.map((line) => line.trim() ? line.slice(commonIndent) : '').join('\n')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function countIndent(line: string): number {
|
|
145
|
+
return line.match(/^[\t ]*/)?.[0].length ?? 0
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from 'virtual:master-site/highlight'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Element, Root, RootContent } from 'hast'
|
|
2
|
+
|
|
3
|
+
function hasLineClass(element: Element): boolean {
|
|
4
|
+
const classes = element.properties?.class
|
|
5
|
+
if (Array.isArray(classes)) return classes.includes('line')
|
|
6
|
+
return typeof classes === 'string' && classes.split(/\s+/).includes('line')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function textContent(node: RootContent): string {
|
|
10
|
+
if (node.type === 'text') return node.value
|
|
11
|
+
if (node.type !== 'element') return ''
|
|
12
|
+
return node.children.map(textContent).join('')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Copy Shiki's rendered lines, without trailing whitespace left by notation markers. */
|
|
16
|
+
export default function highlightedCodeText(root: Root): string {
|
|
17
|
+
const lines: string[] = []
|
|
18
|
+
const visit = (nodes: RootContent[]) => {
|
|
19
|
+
for (const node of nodes) {
|
|
20
|
+
if (node.type !== 'element') continue
|
|
21
|
+
if (hasLineClass(node)) lines.push(node.children.map(textContent).join('').replace(/[\t ]+$/u, ''))
|
|
22
|
+
else visit(node.children)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
visit(root.children)
|
|
26
|
+
return lines.join('\n')
|
|
27
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export type LocalePrefixMode = 'always' | 'canonical'
|
|
2
|
+
|
|
3
|
+
export interface LocalizePathnameOptions {
|
|
4
|
+
defaultLocale: string
|
|
5
|
+
locale: string
|
|
6
|
+
locales: readonly string[]
|
|
7
|
+
localePrefixMode?: LocalePrefixMode
|
|
8
|
+
localizablePathnameRoots?: readonly string[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const nonPagePathnameRoots = new Set([
|
|
12
|
+
'_next',
|
|
13
|
+
'api',
|
|
14
|
+
'assets',
|
|
15
|
+
'cdn',
|
|
16
|
+
'fonts',
|
|
17
|
+
'images',
|
|
18
|
+
'og',
|
|
19
|
+
'search'
|
|
20
|
+
])
|
|
21
|
+
|
|
22
|
+
export function localizePathname(href: string, {
|
|
23
|
+
defaultLocale,
|
|
24
|
+
locale,
|
|
25
|
+
locales,
|
|
26
|
+
localePrefixMode = 'canonical',
|
|
27
|
+
localizablePathnameRoots
|
|
28
|
+
}: LocalizePathnameOptions) {
|
|
29
|
+
if (!href || !href.startsWith('/') || href.startsWith('//')) return href
|
|
30
|
+
|
|
31
|
+
const parsedHref = parseLocalHref(href)
|
|
32
|
+
if (!parsedHref || findPathnameLocale(parsedHref.pathname, locales)) return href
|
|
33
|
+
if (!isLocalizablePathname(parsedHref.pathname, localizablePathnameRoots)) return href
|
|
34
|
+
|
|
35
|
+
if (locale === defaultLocale && localePrefixMode !== 'always') return href
|
|
36
|
+
|
|
37
|
+
const localizedPathname = `/${locale}${parsedHref.pathname === '/' ? '' : parsedHref.pathname}`
|
|
38
|
+
return localizedPathname + parsedHref.suffix
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function canonicalizeDefaultLocalePathname(href: string, defaultLocale: string) {
|
|
42
|
+
const parsedHref = parseLocalHref(href)
|
|
43
|
+
if (!parsedHref) return href
|
|
44
|
+
|
|
45
|
+
const defaultLocalePrefix = `/${defaultLocale}`
|
|
46
|
+
if (parsedHref.pathname === defaultLocalePrefix) {
|
|
47
|
+
return '/' + parsedHref.suffix
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (parsedHref.pathname.startsWith(defaultLocalePrefix + '/')) {
|
|
51
|
+
return parsedHref.pathname.slice(defaultLocalePrefix.length) + parsedHref.suffix
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return href
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseLocalHref(href: string) {
|
|
58
|
+
const endIndex = firstPathnameEndIndex(href)
|
|
59
|
+
const pathname = href.slice(0, endIndex)
|
|
60
|
+
if (!pathname.startsWith('/')) return
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
pathname,
|
|
64
|
+
suffix: href.slice(endIndex)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function firstPathnameEndIndex(href: string) {
|
|
69
|
+
const queryIndex = href.indexOf('?')
|
|
70
|
+
const hashIndex = href.indexOf('#')
|
|
71
|
+
if (queryIndex === -1) return hashIndex === -1 ? href.length : hashIndex
|
|
72
|
+
if (hashIndex === -1) return queryIndex
|
|
73
|
+
return Math.min(queryIndex, hashIndex)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function findPathnameLocale(pathname: string, locales: readonly string[]) {
|
|
77
|
+
const firstSegment = getFirstPathnameSegment(pathname)
|
|
78
|
+
return firstSegment && locales.includes(firstSegment)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isLocalizablePathname(pathname: string, localizablePathnameRoots?: readonly string[]) {
|
|
82
|
+
if (pathname === '/') return true
|
|
83
|
+
if (hasFileExtension(pathname)) return false
|
|
84
|
+
|
|
85
|
+
const firstSegment = getFirstPathnameSegment(pathname)
|
|
86
|
+
if (!firstSegment || nonPagePathnameRoots.has(firstSegment)) return false
|
|
87
|
+
|
|
88
|
+
return !localizablePathnameRoots?.length || localizablePathnameRoots.includes(firstSegment)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function hasFileExtension(pathname: string) {
|
|
92
|
+
const lastSegment = pathname.split('/').pop() || ''
|
|
93
|
+
return /\.[^./]+$/.test(lastSegment)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getFirstPathnameSegment(pathname: string) {
|
|
97
|
+
return pathname.split('/')[1] || ''
|
|
98
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export async function createTranslation(locale: string, dictionaries: Record<string, () => Promise<any>>): Promise<(text: any) => string> {
|
|
2
|
+
const translations = await importTranslations(locale, dictionaries)
|
|
3
|
+
return (text: any) => (translations)[text || ''] || text
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const importTranslations = async (locale: string, dictionaries: Record<string, () => Promise<any>>) => {
|
|
7
|
+
if (!locale) {
|
|
8
|
+
throw new Error('locale is required')
|
|
9
|
+
}
|
|
10
|
+
const load = dictionaries[locale as keyof typeof dictionaries]
|
|
11
|
+
return await load()
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default function isDateWithinSevenDays(dateString: string) {
|
|
2
|
+
// 获取当前日期
|
|
3
|
+
const currentDate = new Date()
|
|
4
|
+
|
|
5
|
+
// 将字符串转换为日期对象
|
|
6
|
+
const date = new Date(dateString)
|
|
7
|
+
|
|
8
|
+
// 计算日期差异(以毫秒为单位)
|
|
9
|
+
const difference = currentDate.getTime() - date.getTime()
|
|
10
|
+
|
|
11
|
+
// 将毫秒转换为天数
|
|
12
|
+
const daysDifference = Math.ceil(difference / (1000 * 3600 * 24))
|
|
13
|
+
|
|
14
|
+
// 判断是否在7天内
|
|
15
|
+
return daysDifference < 7
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isBrowser = typeof window !== 'undefined'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isInteractOutside(
|
|
2
|
+
target: Element,
|
|
3
|
+
event: any,
|
|
4
|
+
senseEdge = 0
|
|
5
|
+
): boolean {
|
|
6
|
+
const x = event.clientX
|
|
7
|
+
const y = event.clientY
|
|
8
|
+
const rect = target.getBoundingClientRect()
|
|
9
|
+
const top = rect.top
|
|
10
|
+
const left = rect.left
|
|
11
|
+
|
|
12
|
+
return top > y + senseEdge
|
|
13
|
+
|| top + rect.height < y - senseEdge
|
|
14
|
+
|| left > x + senseEdge
|
|
15
|
+
|| left + rect.width < x - senseEdge
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { remark } from 'remark'
|
|
2
|
+
import gfm from 'remark-gfm'
|
|
3
|
+
import Slugger from 'github-slugger'
|
|
4
|
+
import resolveHeading from './resolve-heading'
|
|
5
|
+
|
|
6
|
+
const parser = remark().use(gfm)
|
|
7
|
+
export const markdownTree = (source: string) => parser.parse(source)
|
|
8
|
+
|
|
9
|
+
export function markdownHeadings(source: string) {
|
|
10
|
+
const slugger = new Slugger()
|
|
11
|
+
const headings: { id: string; title: string; depth: number }[] = []
|
|
12
|
+
function visit(node: any) {
|
|
13
|
+
if (node.type === 'heading' && (node.depth === 2 || node.depth === 3)) {
|
|
14
|
+
const title = node.children.filter((child: any) => child.type === 'text' || child.type === 'inlineCode').map((child: any) => child.value).join(' ').trim()
|
|
15
|
+
const resolved = resolveHeading(title, slugger.slug(title))
|
|
16
|
+
headings.push({ id: resolved.id!, title: resolved.title, depth: node.depth })
|
|
17
|
+
}
|
|
18
|
+
node.children?.forEach(visit)
|
|
19
|
+
}
|
|
20
|
+
visit(markdownTree(source))
|
|
21
|
+
return headings
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DefinedMetadata, Metadata } from '../types/Metadata'
|
|
2
|
+
|
|
3
|
+
const contentFolder = '/site/content'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Derive the canonical pathname and repository source path from a page's `metadata.ts`
|
|
7
|
+
* location under `site/content`. The machine-specific `fileURL` is dropped because
|
|
8
|
+
* metadata reaches island props, category data and client bundles.
|
|
9
|
+
*/
|
|
10
|
+
export default function define({ fileURL, ...metadata }: Metadata) {
|
|
11
|
+
const file = decodeURI(fileURL)
|
|
12
|
+
const index = file.indexOf(contentFolder + '/')
|
|
13
|
+
if (index === -1) {
|
|
14
|
+
throw new Error('Invalid metadata fileURL: ' + file)
|
|
15
|
+
}
|
|
16
|
+
const directory = file.slice(index + contentFolder.length + 1).split('/').slice(0, -1)
|
|
17
|
+
const pathname = '/' + directory
|
|
18
|
+
.filter((basename: string) => !basename.startsWith('('))
|
|
19
|
+
.join('/')
|
|
20
|
+
return {
|
|
21
|
+
...metadata,
|
|
22
|
+
sourcePath: ['site/content', ...directory, 'content.mdx'].join('/'),
|
|
23
|
+
pathname
|
|
24
|
+
} as DefinedMetadata
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Root } from 'hast'
|
|
2
|
+
import highlightedCodeText from './highlighted-code-text'
|
|
3
|
+
|
|
4
|
+
export interface PreparedCode {
|
|
5
|
+
/** The complete highlighted `<pre>`. */
|
|
6
|
+
html: string
|
|
7
|
+
text: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Store trusted Shiki HTML so a page renders the block without highlighting it again. */
|
|
11
|
+
export async function prepareCode(tree: Root): Promise<PreparedCode> {
|
|
12
|
+
const pre = tree.children[0]
|
|
13
|
+
if (pre?.type !== 'element' || pre.tagName !== 'pre' || tree.children.length !== 1) {
|
|
14
|
+
throw new Error('Expected one highlighted code block')
|
|
15
|
+
}
|
|
16
|
+
const { hastToHtml } = await import('shiki/core')
|
|
17
|
+
return {
|
|
18
|
+
html: hastToHtml(tree),
|
|
19
|
+
text: highlightedCodeText(tree)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function resolveHeading(title: string, id?: string): { title: string; id?: string; className?: string }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default function resolveHeading(title, id) {
|
|
2
|
+
const explicit = typeof title === 'string' && title.match(/\s+\{#([\w-]+)\}$/)
|
|
3
|
+
if (explicit) {
|
|
4
|
+
title = title.slice(0, explicit.index)
|
|
5
|
+
id = explicit[1]
|
|
6
|
+
}
|
|
7
|
+
const words = title?.split?.(' ')
|
|
8
|
+
|
|
9
|
+
if (words?.pop() === '[sr-only]') {
|
|
10
|
+
return {
|
|
11
|
+
title: words.join(' '),
|
|
12
|
+
id: id
|
|
13
|
+
?.replace('-sr-only', '')
|
|
14
|
+
?.replace('-[sr-only]', ''),
|
|
15
|
+
className: 'sr-only'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { title, id }
|
|
19
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import FastGlob from 'fast-glob'
|
|
2
|
+
import Slugger from 'github-slugger'
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, join, resolve } from 'node:path'
|
|
5
|
+
import { pathToFileURL } from 'node:url'
|
|
6
|
+
import { fromMarkdown } from 'mdast-util-from-markdown'
|
|
7
|
+
import { mdxjsEsm } from 'micromark-extension-mdxjs-esm'
|
|
8
|
+
import { mdxjsEsmFromMarkdown } from 'mdast-util-mdxjs-esm'
|
|
9
|
+
import * as acorn from 'acorn'
|
|
10
|
+
import resolveHeading from './resolve-heading.js'
|
|
11
|
+
import { writeIfChangedSync } from '../../scripts/write-if-changed'
|
|
12
|
+
import { localizePathname, type LocalePrefixMode } from './i18n-pathname.js'
|
|
13
|
+
|
|
14
|
+
const DEFAULT_METADATA_GLOB = './content/**/*metadata.ts'
|
|
15
|
+
|
|
16
|
+
export interface SearchNode {
|
|
17
|
+
id?: string
|
|
18
|
+
tag?: string
|
|
19
|
+
text: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SearchPage {
|
|
23
|
+
category?: string
|
|
24
|
+
description: string
|
|
25
|
+
disabled?: boolean
|
|
26
|
+
identifiers?: SearchNode[]
|
|
27
|
+
nodes: SearchNode[]
|
|
28
|
+
title: string
|
|
29
|
+
url: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SearchPageEntry {
|
|
33
|
+
content?: string
|
|
34
|
+
localizedContent?: Record<string, string>
|
|
35
|
+
metadata: Record<string, any>
|
|
36
|
+
metadataPath?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface LoadSearchPageEntriesOptions {
|
|
40
|
+
cwd?: string
|
|
41
|
+
metadataGlob?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface CreateSearchPageOptions {
|
|
45
|
+
defaultLocale: string
|
|
46
|
+
entry: SearchPageEntry
|
|
47
|
+
locale: string
|
|
48
|
+
translate?: Translate
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface GenerateSearchPagesOptions extends LoadSearchPageEntriesOptions {
|
|
52
|
+
defaultLocale: string
|
|
53
|
+
dictionariesDir?: string
|
|
54
|
+
locales: readonly string[]
|
|
55
|
+
outDir?: string
|
|
56
|
+
write?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type Translate = (text: string) => string
|
|
60
|
+
|
|
61
|
+
interface MdxNode {
|
|
62
|
+
children?: MdxNode[]
|
|
63
|
+
depth?: number
|
|
64
|
+
type: string
|
|
65
|
+
value?: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function generateSearchPages({
|
|
69
|
+
cwd = process.cwd(),
|
|
70
|
+
defaultLocale,
|
|
71
|
+
dictionariesDir = resolve(cwd, 'public/dictionaries'),
|
|
72
|
+
locales,
|
|
73
|
+
metadataGlob,
|
|
74
|
+
outDir = resolve(cwd, 'public/search'),
|
|
75
|
+
write = true
|
|
76
|
+
}: GenerateSearchPagesOptions): Promise<Record<string, SearchPage[]>> {
|
|
77
|
+
const entries = await loadSearchPageEntries({ cwd, metadataGlob })
|
|
78
|
+
const result: Record<string, SearchPage[]> = {}
|
|
79
|
+
if (write) mkdirSync(outDir, { recursive: true })
|
|
80
|
+
|
|
81
|
+
for (const locale of locales) {
|
|
82
|
+
const translations = loadDictionaryTranslations(dictionariesDir, locale)
|
|
83
|
+
const translate = createDictionaryTranslate(translations)
|
|
84
|
+
const pages = entries
|
|
85
|
+
.map((entry) => createSearchPage({ defaultLocale, entry, locale, translate }))
|
|
86
|
+
.sort((a, b) => a.url.localeCompare(b.url))
|
|
87
|
+
result[locale] = pages
|
|
88
|
+
if (write) {
|
|
89
|
+
const filename = resolve(outDir, `${locale}.json`)
|
|
90
|
+
writeIfChangedSync(filename, JSON.stringify(pages))
|
|
91
|
+
console.log(`產生 ${filename} (${pages.length} search pages)`)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function loadSearchPageEntries({
|
|
98
|
+
cwd = process.cwd(),
|
|
99
|
+
metadataGlob = DEFAULT_METADATA_GLOB
|
|
100
|
+
}: LoadSearchPageEntriesOptions = {}): Promise<SearchPageEntry[]> {
|
|
101
|
+
const metadataPaths = FastGlob.sync(metadataGlob, { cwd })
|
|
102
|
+
.filter((metadataPath) => (existsSync(resolve(cwd, dirname(metadataPath), 'page.astro')) || existsSync(resolve(cwd, dirname(metadataPath), 'content.mdx'))))
|
|
103
|
+
.sort()
|
|
104
|
+
|
|
105
|
+
return await Promise.all(metadataPaths.map(async (metadataPath) => {
|
|
106
|
+
const metadataModule = await import(pathToFileURL(resolve(cwd, metadataPath)).href)
|
|
107
|
+
const contentPath = resolve(cwd, dirname(metadataPath), 'content.mdx')
|
|
108
|
+
const contentDir = resolve(cwd, dirname(metadataPath))
|
|
109
|
+
return {
|
|
110
|
+
content: existsSync(contentPath) ? readFileSync(contentPath, 'utf8') : undefined,
|
|
111
|
+
localizedContent: loadLocalizedContent(contentDir),
|
|
112
|
+
metadata: metadataModule.default,
|
|
113
|
+
metadataPath
|
|
114
|
+
}
|
|
115
|
+
}))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function createSearchPage({
|
|
119
|
+
defaultLocale,
|
|
120
|
+
entry,
|
|
121
|
+
locale,
|
|
122
|
+
translate = (text) => text
|
|
123
|
+
}: CreateSearchPageOptions): SearchPage {
|
|
124
|
+
const { metadata } = entry
|
|
125
|
+
const title = translate(resolveMetadataString(metadata.title))
|
|
126
|
+
const description = translate(resolveMetadataString(metadata.description))
|
|
127
|
+
const category = translate(resolveMetadataString(metadata.category))
|
|
128
|
+
const content = entry.localizedContent?.[locale] ?? entry.content
|
|
129
|
+
const page: SearchPage = {
|
|
130
|
+
category,
|
|
131
|
+
description,
|
|
132
|
+
disabled: Boolean(metadata.disabled),
|
|
133
|
+
nodes: content ? extractSearchNodesFromMdx(content) : [],
|
|
134
|
+
title,
|
|
135
|
+
url: createLocalizedPathname(metadata.pathname, locale, defaultLocale)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return page
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function loadLocalizedContent(contentDir: string): Record<string, string> {
|
|
142
|
+
const localizedContent: Record<string, string> = {}
|
|
143
|
+
const entries = FastGlob.sync('content.*.mdx', { cwd: contentDir })
|
|
144
|
+
for (const entry of entries) {
|
|
145
|
+
const match = entry.match(/^content\.([^.]+)\.mdx$/)
|
|
146
|
+
if (!match) continue
|
|
147
|
+
localizedContent[match[1]] = readFileSync(resolve(contentDir, entry), 'utf8')
|
|
148
|
+
}
|
|
149
|
+
return localizedContent
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function createDictionaryTranslate(translations: Record<string, string>): Translate {
|
|
153
|
+
return (text) => translations[text || ''] || text
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function loadDictionaryTranslations(dictionariesDir: string, locale: string): Record<string, string> {
|
|
157
|
+
const filename = resolve(dictionariesDir, `${locale}.json`)
|
|
158
|
+
if (!existsSync(filename)) return {}
|
|
159
|
+
return JSON.parse(readFileSync(filename, 'utf8')) as Record<string, string>
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function createLocalizedPathname(pathname: string, locale: string, defaultLocale: string, localePrefixMode: LocalePrefixMode = 'canonical') {
|
|
163
|
+
const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`
|
|
164
|
+
return localizePathname(normalizedPathname, {
|
|
165
|
+
defaultLocale,
|
|
166
|
+
locale,
|
|
167
|
+
locales: [defaultLocale, locale],
|
|
168
|
+
localePrefixMode
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function extractSearchNodesFromMdx(source: string): SearchNode[] {
|
|
173
|
+
const tree = fromMarkdown(source, {
|
|
174
|
+
extensions: [mdxjsEsm({ acorn, addResult: true })],
|
|
175
|
+
mdastExtensions: [mdxjsEsmFromMarkdown()]
|
|
176
|
+
}) as MdxNode
|
|
177
|
+
const nodes: SearchNode[] = []
|
|
178
|
+
const slugger = new Slugger()
|
|
179
|
+
appendSearchNodes(tree.children ?? [], nodes, slugger)
|
|
180
|
+
return nodes
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function appendSearchNodes(children: MdxNode[], nodes: SearchNode[], slugger: Slugger) {
|
|
184
|
+
for (const child of children) {
|
|
185
|
+
appendSearchNode(child, nodes, slugger)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function appendSearchNode(node: MdxNode, nodes: SearchNode[], slugger: Slugger) {
|
|
190
|
+
switch (node.type) {
|
|
191
|
+
case 'heading':
|
|
192
|
+
appendHeadingSearchNode(node, nodes, slugger)
|
|
193
|
+
return
|
|
194
|
+
case 'paragraph':
|
|
195
|
+
appendTextSearchNode(nodes, collectText(node), 'p')
|
|
196
|
+
return
|
|
197
|
+
case 'code':
|
|
198
|
+
appendTextSearchNode(nodes, node.value ?? '', 'code')
|
|
199
|
+
return
|
|
200
|
+
case 'list':
|
|
201
|
+
for (const child of node.children ?? []) {
|
|
202
|
+
appendTextSearchNode(nodes, collectText(child), 'li')
|
|
203
|
+
}
|
|
204
|
+
return
|
|
205
|
+
case 'blockquote':
|
|
206
|
+
appendSearchNodes(node.children ?? [], nodes, slugger)
|
|
207
|
+
return
|
|
208
|
+
case 'mdxjsEsm':
|
|
209
|
+
case 'html':
|
|
210
|
+
case 'break':
|
|
211
|
+
case 'thematicBreak':
|
|
212
|
+
return
|
|
213
|
+
default:
|
|
214
|
+
if (node.children?.length) {
|
|
215
|
+
appendSearchNodes(node.children, nodes, slugger)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function appendHeadingSearchNode(node: MdxNode, nodes: SearchNode[], slugger: Slugger) {
|
|
221
|
+
const text = normalizeSearchText((node.children ?? []).filter(child => child.type === 'text' || child.type === 'inlineCode').map(child => child.value).join(' '))
|
|
222
|
+
if (!text) return
|
|
223
|
+
|
|
224
|
+
const tag = node.depth ? `h${node.depth}` : 'h'
|
|
225
|
+
if (node.depth === 2 || node.depth === 3) {
|
|
226
|
+
const resolved = resolveHeading(text, slugger.slug(text))
|
|
227
|
+
appendTextSearchNode(nodes, resolved.title, tag, resolved.id)
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
appendTextSearchNode(nodes, text, tag)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function appendTextSearchNode(nodes: SearchNode[], text: string, tag: string, id?: string) {
|
|
235
|
+
const normalizedText = normalizeSearchText(text)
|
|
236
|
+
if (!normalizedText) return
|
|
237
|
+
nodes.push({
|
|
238
|
+
...(id ? { id } : {}),
|
|
239
|
+
tag,
|
|
240
|
+
text: normalizedText
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function collectText(node: MdxNode): string {
|
|
245
|
+
switch (node.type) {
|
|
246
|
+
case 'text':
|
|
247
|
+
case 'inlineCode':
|
|
248
|
+
case 'code':
|
|
249
|
+
return node.value ?? ''
|
|
250
|
+
case 'html':
|
|
251
|
+
case 'mdxjsEsm':
|
|
252
|
+
return ''
|
|
253
|
+
default:
|
|
254
|
+
return node.children?.map(collectText).join('') ?? ''
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function normalizeSearchText(text: string) {
|
|
259
|
+
return text.replace(/ /g, ' ').replace(/\s+/g, ' ').trim()
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function resolveMetadataString(value: any): string {
|
|
263
|
+
if (!value) return ''
|
|
264
|
+
if (typeof value === 'string') return value
|
|
265
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value)
|
|
266
|
+
if (typeof value === 'object') {
|
|
267
|
+
if ('absolute' in value) return resolveMetadataString(value.absolute)
|
|
268
|
+
if ('default' in value) return resolveMetadataString(value.default)
|
|
269
|
+
}
|
|
270
|
+
return String(value)
|
|
271
|
+
}
|