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 | 5x | /**
* Types for static usage generation.
*
* The generator emits markup that uses components in a target language. Two
* orthogonal options shape the output:
*
* - `target` — output language (HTML today; extensible).
* - `compose` — composition strategy: `'reference'` emits external library
* tags where mappings exist; `'expand'` recursively inlines
* child UIFs into a self-contained snapshot.
*
* For the HTML target with Lightning Base Components, this produces Pure LBC
* (`compose: 'reference'`, top-level mapping), LBC Recipe (`compose: 'reference'`,
* no top-level mapping), and Pure Blueprint (`compose: 'expand'`).
*/
import type {
ComponentMetadata,
GeneratedCode,
GeneratorOptions,
ResolvedUIF,
} from '@fds-uif/generator-base/browser';
/**
* Output language for the static generator.
*
* HTML is the only target shipping today. The pipeline is designed so that
* additional targets (e.g., `'jsx'`) can be added by swapping the
* serialization stage.
*/
export type StaticTarget = 'html';
/**
* Composition strategy for `children[].component` references.
*
* - `'reference'` (default): emits a tag for the external component library
* wherever a referenced child has a mapping. For the HTML target, this
* means `<lightning-*>` custom elements driven by `structure.component`,
* producing Pure LBC (when the top-level UIF declares a mapping) or LBC
* Recipe (when it does not).
* - `'expand'`: recursively inlines every referenced child's UIF until the
* structure is fully self-contained. For the HTML target, this is the
* Pure Blueprint output.
*/
export type StaticCompose = 'expand' | 'reference';
/**
* Options for the static generator.
*/
export interface StaticGeneratorOptions extends Partial<GeneratorOptions> {
/** Output language. Today only `'html'` is supported (default: `'html'`). */
target?: StaticTarget;
/** Composition strategy for child component references (default: `'reference'`). */
compose?: StaticCompose;
/** Generate all variant/modifier permutations (default: false) */
variants?: boolean;
/** Skip Prettier formatting (for testing/debugging) */
skipFormat?: boolean;
/** Resolved UIFs keyed by component name, for inline component resolution */
componentRegistry?: Record<string, ResolvedUIF>;
/** Max nesting depth when resolving component references (default: 5) */
maxDepth?: number;
/** Override slot content by slot name — literal text or HTML string for unrestricted (text) slots */
slotOverrides?: Record<string, string>;
/** Override which component fills a restricted slot by slot name — value must be a component name present in slot.restrict */
slotComponentOverrides?: Record<string, string>;
/** Override the active variant selection for preview rendering — variant prop name → option value.
* Any variant not listed falls back to its UIF-defined default. */
variantOverrides?: Record<string, string>;
/** Override which modifiers are active for preview rendering.
* Boolean modifiers: prop name → true/false.
* Grouped (enum) modifiers: prop name → selected propValue string.
* Any modifier not listed falls back to its UIF-defined default. */
modifierOverrides?: Record<string, string | boolean>;
/** Override which composed components (renderWhen: "propFilled") are included.
* Maps the child node name to true to include it. Nodes not listed are excluded. */
componentOverrides?: Record<string, boolean>;
}
/**
* Result of static generation.
*/
export interface StaticGeneratedCode extends GeneratedCode {
metadata: ComponentMetadata;
artifacts: {
/** Serialized markup in the requested target language (HTML by default). */
code: string;
/** Individual permutations when --variants is active */
permutations?: VariantPermutation[];
};
}
/**
* Active state for a single permutation in the variant matrix.
* Modifiers and states are boolean; variants select one option value.
*/
export interface PermutationState {
/** Active modifier/state values (prop name → on/off) */
modifiers: Record<string, boolean>;
/** Active variant selections (variant name → selected value) */
variants: Record<string, string>;
}
/**
* One entry in the variant matrix output
*/
export interface VariantPermutation {
/** Human-readable label describing the active configuration */
label: string;
/** The state that produced this output */
state: PermutationState;
/** Generated code for this permutation, in the requested target language */
code: string;
}
/**
* Context threaded through static generation stages
*/
export interface StaticGenerationContext {
/** Component metadata from analyzer */
metadata: ComponentMetadata;
/** Generator options */
options: StaticGeneratorOptions;
/** Current indentation depth */
indent: number;
/** Active permutation state for class/attribute resolution */
state: PermutationState;
/** Current component resolution depth (prevents infinite recursion) */
depth: number;
/** Additional CSS classes to merge onto the root element (from parent composition) */
extraClasses?: string[];
/** Bound prop names on the root LBC tag — composed children whose props
* overlap with these are prop-forwarding helpers, not actual slot children. */
rootBoundPropKeys?: Set<string>;
}
/**
* Default generator options
*/
export const DEFAULT_OPTIONS: Required<
Pick<StaticGeneratorOptions, 'target' | 'compose' | 'variants' | 'maxDepth'>
> = {
target: 'html',
compose: 'reference',
variants: false,
maxDepth: 5,
};
|