import { UserConfig, InlineConfig, Plugin } from 'vite'; import MarkdownIt from 'markdown-it'; import { ConfiguredBuilder, BuilderOptions } from '@yankeeinlondon/builder-api'; import { MaybeRef } from '@vueuse/core'; import * as TE from 'fp-ts/lib/TaskEither.js'; import { Either } from 'fp-ts/lib/Either.js'; import { IElement, Fragment } from '@yankeeinlondon/happy-wrapper'; import { ExistingRawSourceMap } from 'rollup'; type FilterPattern = ReadonlyArray | string | RegExp | null; /** * **PipelineStage** * * The _stage_ in the transformation pipeline: * * - `initialize` - meant for configuration settings * - `metaExtracted` - all frontmatter has been separated from the text content * giving you a clear but raw markdown content and frontmatter key/value * - `parser` - a **markdown-it** parser is initialized; providing the `md` prop * on the payload. This is where builders who want to act as a markdown-it-plugin * will want to engage. * - `parsed` - The **MarkdownIt** parser is initialized and all builders * have been able to apply their customizations to it. * - `dom` - The HTML has been converted to a HappyDom tree to allow interested builders * to manipulate contents using DOM based queries * - `sfcBlocksExtracted` - SFC blocks (template, script, and an array of customBlocks) * are ready for builders to inspect/mutate/etc. * - `closeout` - All mutations of page are complete; builders can hook into this stage * but will _not_ be able to mutate at this stage */ type PipelineStage = 'initialize' | 'metaExtracted' | 'parser' | 'parsed' | 'dom' | 'sfcBlocksExtracted' | 'closeout'; interface RulesUse { ruleName: string; usage: 'adds' | 'patches' | 'modifies'; description?: string; } type Parser = S extends 'parser' | 'parsed' | 'dom' | 'sfcBlocksExtracted' | 'closeout' ? { /** the **MarkdownIT** parser instance */ parser: MarkdownIt; } : {}; /** * The **Route** custom-block can be configured with these properties. * * Note: this is best done with the _meta_ builder */ interface RouteConfig { /** The Route's name */ name?: string; /** The Route's path */ path?: string; /** A dictionary of key/value pairs for the route */ meta?: Frontmatter; } interface LinkProperty { rel?: string; href?: string; integrity?: string; crossorigin?: string; [key: string]: unknown; } interface StyleProperty { type?: string; [key: string]: unknown; } /** * The element specifies the base URL and/or target for all * relative URLs in a page. */ interface BaseProperty { href?: string; target?: string; } interface ScriptProperty { /** * For classic scripts, if the async attribute is present, then the classic * script will be fetched in parallel to parsing and evaluated as soon as it is * available. * * For module scripts, if the async attribute is present then the scripts and * all their dependencies will be executed in the defer queue, therefore they will * get fetched in parallel to parsing and evaluated as soon as they are available. */ async?: boolean; crossorigin?: string; /** only to be used alongside the `src` attribute */ defer?: boolean; /** Provides a hint of the relative priority to use when fetching an external script. */ fetchPriority?: 'high' | 'low' | 'auto'; integrity?: string; /** * This Boolean attribute is set to indicate that the script should not be executed * in browsers that support ES2015 modules — in effect, this can be used to serve * fallback scripts to older browsers that do not support modular JavaScript code. */ nomodule?: boolean; nonce?: string; referencePolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'; src?: string; type?: string; [key: string]: unknown; } /** * The properties destined for the HEAD block in the HTML */ interface HeadProps { title?: MaybeRef; meta?: MaybeRef; link?: MaybeRef; base?: MaybeRef; style?: MaybeRef; script?: MaybeRef; htmlAttrs?: MaybeRef[]>; bodyAttrs?: MaybeRef[]>; [key: string]: unknown; } /** types available _only_ during initialization */ type Initialization = S extends 'initialize' ? {} : {}; interface PipelineUtilityFunctions { /** * Adds a `` to the page's header section */ addLink: (link: LinkProperty) => void; /** * Adds a `