Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | 26x 26x 26x 26x 26x 26x 26x 26x 26x 31x 4x 6x 6x 4x 7x 4x | import { DocumentNode, PipelineCache } from '..'; /** * Compiles inputs from the project source into plain web resources */ export interface Pipeline { /** * Caches reusable data for the pipeline */ readonly cache: PipelineCache; /** * Frontend / Backend for the pipeline */ readonly pipelineIO: PipelineIO; /** * HTML formatter, if provided */ readonly htmlFormatter: HtmlFormatter; /** * Compiles a page from start to finish. * This entry point should be used with the source HTML is intended to be used as a full HTML page. * * @param resPath Path to the page, relative to both source and destination. * @returns a Page containing the DOM and serialized / formatted HTML */ compilePage(resPath: string): Promise<Page>; /** * Compiles a fragment. * This entry point should be used if the source HTML does not represent a complete page, or if further processing is to be done. * * @param resPath Path to fragment source * @param fragmentContext Data related to the specific usage context of this fragment * @returns Fragment instance */ compileFragment(resPath: string, fragmentContext?: FragmentContext): Promise<Fragment>; /** * Resets the pipeline to its initial state. */ reset(): void; } /** * State data for the current unit of compilation in the pipeline */ export interface PipelineContext { /** * Current pipeline instance */ readonly pipeline: Pipeline; /** * Fragment that is currently being compiled */ readonly fragment: Fragment; /** * Fragment usage context */ readonly fragmentContext: FragmentContext; /** * Set of all unique CSS styles that have been found during compilation. * This set is inherited and shared by all nodes within the same compilation unit. * TODO remove this from global state */ readonly stylesInPage: Set<string>; /** * Set of all unique HTML link node targets that have been found during compilation. * This set is inherited and shared by all nodes within the same compilation unit. * TODO remove this from global scope */ readonly linksInPage: Set<string>; } /** * Usage data for the current fragment */ export interface FragmentContext { /** * Slot contents for the current fragment */ readonly slotContents: ReadonlyMap<string, DocumentNode>; /** * Fragment-global scope. * Is read-only. * Contains mapped fragment params, if applicable. */ readonly scope: ScopeData; /** * Path that was used to access this fragment. * This path may not reflect the actual file where this fragment will end up. * If that path is needed, then see {@link rootResPath}. */ readonly fragmentResPath: string; /** * Path to the "root" fragment or page. * This is the path to the actual file that will be produced in the compilation output. * This path may not point to the current fragment being compiled, if this fragment is included as a reference. * If that path is needed, then see {@link fragmentResPath}. */ readonly rootResPath: string; } /** * Base unit of work for HTML compilation */ export interface Fragment { /** * Path to fragment, relative to source */ readonly path: string; /** * Fragment Document Object Model */ readonly dom: DocumentNode; } /** * Special type of fragment that represents a fully compiled HTML page */ export interface Page extends Fragment { /** * Serialized and formatted HTML representation of the page */ readonly html: string; } /** * Type of key for scope data */ export type ScopeKey = string | number; /** * Local scope data */ export type ScopeData = Record<ScopeKey, unknown>; /** * Provides HTML formatting support to the pipeline. */ export interface HtmlFormatter { /** * Formats a DOM tree before serialization. * * @param dom DOM tree to format */ formatDom(dom: DocumentNode): void; /** * Formats serialized HTML before being exported from the pipeline. * * @param html HTML to format. */ formatHtml(html: string): string; } /** * Common MIME types */ export enum MimeType { /** * HTML resource */ HTML = 'text/html', /** * CSS resource */ CSS = 'text/css', /** * SCSS (CSS variant) resource */ SCSS = 'text/scss', /** * SASS (CSS variant) resource */ SASS = 'text/sass', /** * JavaScript resource */ JAVASCRIPT = 'text/javascript', /** * JSON resource */ JSON = 'application/json', // eslint-disable-line no-shadow /** * Plain text resource */ TEXT = 'text/plain' } /** * Gets the filename extension to use for a specified resource type. * Defaults to "dat" for unknown resource types. * @param resourceType Resource type to get extension for * @returns filename extension, without the dot. */ export function getResourceTypeExtension(resourceType: MimeType): string { switch (resourceType) { case MimeType.HTML: return 'html'; case MimeType.CSS: return 'css'; case MimeType.SASS: return 'sass'; case MimeType.SCSS: return 'scss'; case MimeType.JAVASCRIPT: return 'js'; case MimeType.JSON: return 'json'; case MimeType.TEXT: return 'txt'; default: return 'dat'; } } /** * Provides file I/O support to the pipeline */ export interface PipelineIO { /** * Path to source directory */ readonly sourcePath: string; /** * Path to destination directory */ readonly destinationPath: string; /** * Reads a resource of a specified type from the pipeline input. * Path will be computed by using resPath relative to {@link sourcePath}. * See {@link resolveSourceResource} for details. * * @param type Type of resource * @param resPath Relative path to resource (source and destination) * @returns text content of resource */ getResource(type: MimeType, resPath: string): Promise<string>; /** * Writes a resource of a specified type to the pipeline output. * This resource must map directly to a source resource, for generated output use createResource(). * Path will be computed by using resPath relative to {@link destinationPath}. * See {@link resolveDestinationResource} for details. * * @param type Type of resource * @param resPath Relative path to resource (source and destination) * @param contents File contents as a UTF-8 string */ writeResource(type: MimeType, resPath: string, contents: string): Promise<void>; /** * Creates a new output resource and generates a resource path to reference it * This should be used for all generated resources, such as external stylesheets. * Path will be computed by using resPath relative to {@link destinationPath}. * See {@link resolveDestinationResource} for details. * * @param type MIME type of the new resource * @param contents File contents * @returns path to resource */ createResource(type: MimeType, contents: string): Promise<string>; /** * Gets the absolute path to a resource in {@link sourcePath}. * @param resPath Raw path to resource * @returns Real path to resource */ resolveSourceResource(resPath: string): string; /** * Gets the absolute path to a resource in {@link destinationPath}. * @param resPath Raw path to resource * @returns Real path to resource */ resolveDestinationResource(resPath: string): string; /** * Generates a unique resource path in {@link destinationPath} that can be used for a generated resource. * This method does not create the file, only reserves the path. * @param type MIME type of the resource to create * @param contents Contents of the file * @returns returns a unique resource path that is acceptable for the specified MIME type */ createResPath(type: MimeType, contents: string): string; /** * Computes the relative path from {@link sourcePath} to rawResPath. * @param rawResPath Target path * @returns returns the relative path to {@link sourcePath}. */ getSourceResPathForAbsolutePath(rawResPath: string): string; /** * Computes the relative path from {@link destinationPath} to rawResPath. * @param rawResPath Target path * @returns returns the relative path to {@link destinationPath}. */ getDestinationResPathForAbsolutePath(rawResPath: string): string; } |