# @embedpdf/angular — ./toolbar BarChild [TypeAliasDeclaration] (from packages/core/ui/src/schema.ts): export type BarChild = BarItem | CustomItem | string; BarGroup [InterfaceDeclaration] (from packages/core/ui/src/schema.ts): export interface BarGroup{ readonly id: string; readonly labelKey?: string; readonly role?: 'buttons' | 'tabs'; readonly shed?: boolean; readonly collapse?: 'menu' | 'select'; readonly importance?: Importance; readonly dependent?: boolean; readonly items: readonly BarChild[]; } BarItem [InterfaceDeclaration] (from packages/core/ui/src/schema.ts): export interface BarItem{ readonly command: string; readonly variants?: readonly Variant[]; readonly importance?: Importance; readonly emphasis?: Emphasis; } BarSchema [InterfaceDeclaration] (from packages/core/ui/src/schema.ts): export interface BarSchema{ readonly id: string; readonly sections: BarSections; } BarSections [InterfaceDeclaration] (from packages/core/ui/src/schema.ts): export interface BarSections{ readonly start?: readonly BarGroup[]; readonly center?: readonly BarGroup[]; readonly end?: readonly BarGroup[]; } CollapsedGroupView [TypeAliasDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): export type CollapsedGroupView = CollapsedGroupViewOf; CustomItem [InterfaceDeclaration] (from packages/core/ui/src/schema.ts): export interface CustomItem{ readonly slot: string; readonly variants?: readonly string[]; readonly terminal?: string; readonly importance?: Importance; readonly grow?: boolean; } DEFAULT_IMPORTANCE [VariableDeclaration] (from packages/core/ui/src/schema.ts): DEFAULT_IMPORTANCE: Importance = 3 EpdfToolbar [ClassDeclaration] (from packages/framework/angular/toolbar/src/toolbar.ts): @Component({ selector: 'epdf-toolbar', imports: [ NgTemplateOutlet, EpdfToolbarLength, EpdfToolbarMoreButton, EpdfToolbarMenu, EpdfToolbarCollapsed, EpdfToolbarGroupTrigger, EpdfToolbarCommandTemplate, EpdfToolbarCollapsedTemplate, EpdfToolbarGroupTriggerTemplate, EpdfToolbarOverflowTriggerTemplate, EpdfToolbarOverflowMenuTemplate, ], changeDetection: ChangeDetectionStrategy.OnPush, providers: [{ provide: TOOLBAR_LENGTHS, useExisting: forwardRef(() => EpdfToolbar)} ], host:{ role: 'toolbar', '[attr.aria-orientation]': 'orientation()', style: 'position: relative; display: flex; align-items: center; ', '[style.flex-direction]': "orientation() === 'vertical' ? 'column' : 'row'", } , template: `
@for (entry of row().start; track entry.key){ }
@for (entry of row().center; track entry.key){ }
@for (entry of row().end; track entry.key){ } @if (hasOverflow()){ }
@if (entry.kind === 'separator'){ } @else{ } @switch (entry.kind){ @case ('command'){ } @case ('custom'){ } @case ('socket'){ @if (entry.context){ } } @case ('collapsed'){ } @case ('trigger'){ } @case ('separator'){ } } `, } ) export class EpdfToolbar implements ToolbarLengthSink{ readonly bar = input.required(); readonly orientation = input<'horizontal' | 'vertical'>('horizontal'); readonly gap = input(8); readonly separatorWidth = input(1); protected readonly commandTemplate = contentChild(EpdfToolbarCommandTemplate); private readonly customTemplates = contentChildren(EpdfToolbarCustomTemplate); protected readonly collapsedTemplate = contentChild(EpdfToolbarCollapsedTemplate); protected readonly groupTriggerTemplate = contentChild(EpdfToolbarGroupTriggerTemplate); protected readonly separatorTemplate = contentChild(EpdfToolbarSeparatorTemplate); protected readonly overflowTriggerTemplate = contentChild(EpdfToolbarOverflowTriggerTemplate); protected readonly overflowMenuTemplate = contentChild(EpdfToolbarOverflowMenuTemplate); private readonly host = injectKernelHost(''); private readonly commands = inject(EpdfCommands); private readonly registry = new CapabilityBinding( this.host, () => CommandsHostToken, injectDocumentScope(), ).capability; private readonly lengths = createToolbarLengths(); private readonly measureVersion = signal(0); private readonly containerLength = signal(0); private readonly overflowOpen = signal(false); private roving: RovingFocus | null = null; private readonly vertical = computed(() => this.orientation() === 'vertical'); private readonly normalized = computed(() => normalizeBar(this.bar())); private readonly layout = this.host.read( (): ToolbarLayout =>{ this.measureVersion(); const registry = this.registry(); if (!registry) return EMPTY_LAYOUT; return layoutToolbar({ bar: this.normalized(), resolve: (id) => registry.resolveCommand(id), unregistered: unregisteredCommand, execute: (id) => this.execute(id), menuTarget: (id) => registry.getMenuTarget(id), metrics: this.lengths.metrics(this.orientation(), this.gap(), this.separatorWidth()), measureKey: toolbarMeasureKey, containerLength: this.containerLength(), orientation: this.orientation(), } ); } , () => EMPTY_LAYOUT, ); protected readonly hasOverflow = computed(() => this.layout().hasOverflow); protected readonly row = computed((): Row =>{ const [start, center, end] = this.layout().sections; return{ start: this.liveEntries(start), center: this.liveEntries(center), end: this.liveEntries(end), } ; } ); protected readonly measured = computed(() => this.layout().measured.flatMap((part) =>{ const entry = this.entryOf(part, 'measure'); return entry ? [{ key: part.measureKey, entry} ] : []; } ), ); protected readonly overflowTrigger = computed( (): EpdfToolbarOverflowTriggerContext => ({ $implicit: this.overflowOpen(), toggle: () => this.overflowOpen.update((open) => !open), } ), ); protected readonly closedTrigger: EpdfToolbarOverflowTriggerContext ={ $implicit: false, toggle: noop, } ; protected readonly overflowMenu = computed((): EpdfToolbarViewContext =>{ return{ $implicit:{ sections: this.layout().overflow, isOpen: this.overflowOpen(), close: () => this.overflowOpen.set(false), resolve: (id) => this.resolve(id), execute: (id) => this.execute(id), } , } ; } ); protected readonly overflowTriggerKey = toolbarMeasureKey.overflowTrigger; protected readonly paint = TOOLBAR_PAINT; protected readonly sectionStyles = computed(() => this.layout().sections.map((section) =>{ const vertical = this.vertical(); const spacing = section.spacing === 'balance' ? vertical ? ' margin-top: auto; margin-bottom: auto; ' : ' margin-left: auto; margin-right: auto; ' : section.spacing === 'gap' ? vertical ? ` margin-top: ${ this.gap()} px; ` : ` margin-inline-start: ${ this.gap()} px; ` : ''; return ( `display: flex; flex-direction: ${ vertical ? 'column' : 'row'} ; align-items: center; ` + `flex: ${ section.grows ? '1 0 auto' : '0 0 auto'} ; ${ spacing} ` ); } ), ); protected itemStyle(entry: Entry): string{ return (entry.kind === 'custom' || entry.kind === 'socket') && entry.grow ? `display: flex; flex-direction: ${ this.vertical() ? 'column' : 'row'} ; ` + 'align-items: center; flex: 1 0 auto; ' : 'display: contents; '; } protected readonly separatorStyle = computed( () => `${ this.vertical() ? 'height' : 'width'} : 1px; align-self: stretch; ` + 'background: currentColor; opacity: 0.2; ', ); protected readonly measureLayerStyle = computed( () => 'position: absolute; left: 0; top: 0; height: 0; overflow: hidden; visibility: hidden; ' + 'pointer-events: none; display: flex; white-space: nowrap; ' + (this.vertical() ? ' flex-direction: column; align-items: flex-start; ' : ''), ); protected readonly commandStyle = 'display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; ' + `white-space: nowrap; color: inherit; font: inherit; border: 1px solid ${ TOOLBAR_PAINT.border} ; ` + 'border-radius: 4px; '; constructor(){ effect(() =>{ if (!this.hasOverflow()) untracked(() => this.overflowOpen.set(false)); } ); if (!isPlatformBrowser(inject(PLATFORM_ID))) return; const element = inject>(ElementRef).nativeElement; effect((onCleanup) =>{ const orientation = this.orientation(); onCleanup( untracked(() => observeContentLength(element, orientation, (length) => this.containerLength.set(length)), ), ); } ); afterRenderEffect((onCleanup) =>{ const orientation = this.orientation(); const focus = untracked(() => attachToolbarFocus(element, orientation)); this.roving = focus; onCleanup(() =>{ focus.detach(); this.roving = null; } ); } ); afterRenderEffect(() =>{ this.row(); this.hasOverflow(); this.overflowOpen(); untracked(() => this.roving?.refresh()); } ); } reportLength(key: string, length: number): void{ if (this.lengths.report(untracked(this.orientation), key, length)){ this.measureVersion.update((version) => version + 1); } } private resolve(id: string): ResolvedCommand | null{ return untracked(this.registry)?.resolveCommand(id) ?? null; } private execute(id: string): void{ this.commands.execute(id).catch(noop); } private customTemplateFor(slot: string): EpdfToolbarCustomTemplate | undefined{ return this.customTemplates().find((template) => template.slot() === slot); } private liveEntries(section: LiveSection | undefined): Entry[]{ const entries: Entry[] = []; section?.groups.forEach((group, index) =>{ if (index > 0) entries.push({ kind: 'separator', key: `separator:${ group.id} `} ); for (const part of group.parts){ const entry = this.entryOf(part, 'live'); if (entry) entries.push(entry); } } ); return entries; } private entryOf(part: ToolbarPart, layer: 'live' | 'measure'): Entry | null{ const key = part.measureKey; switch (part.kind){ case 'command': return{ kind: 'command', key, context:{ $implicit: part.command, variant: part.variant, run: part.run} , } ; case 'custom':{ const custom = this.customTemplateFor(part.name); if (custom){ return{ kind: 'custom', key, template: custom.template, context:{ $implicit: part.variant, layer, measure: (length) => this.reportLength(key, length), } , grow: part.grow, } ; } if (layer === 'measure') return null; return{ kind: 'socket', key, slot: part.name, context: part.terminal &&{ $implicit: part.terminal, variant: 'icon', run: part.runTerminal, } , grow: part.grow, } ; } case 'collapsed': return{ kind: 'collapsed', key, context:{ $implicit: part.view} } ; case 'disclosure': return{ kind: 'trigger', key, context:{ $implicit: part.view} } ; } } } EpdfToolbarCollapsedTemplate [ClassDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): @Directive({ selector: 'ng-template[epdfToolbarCollapsed]'} ) export class EpdfToolbarCollapsedTemplate{ readonly template = inject>>(TemplateRef); static ngTemplateContextGuard( _directive: EpdfToolbarCollapsedTemplate, context: unknown, ): context is EpdfToolbarViewContext{ return true; } } EpdfToolbarCommandContext [InterfaceDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): export interface EpdfToolbarCommandContext{ $implicit: ResolvedCommand; variant: string; run: () => void; } EpdfToolbarCommandTemplate [ClassDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): @Directive({ selector: 'ng-template[epdfToolbarCommand]'} ) export class EpdfToolbarCommandTemplate{ readonly template = inject>(TemplateRef); static ngTemplateContextGuard( _directive: EpdfToolbarCommandTemplate, context: unknown, ): context is EpdfToolbarCommandContext{ return true; } } EpdfToolbarCustomContext [InterfaceDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): export interface EpdfToolbarCustomContext{ $implicit: string; layer: 'live' | 'measure'; measure: (length: number) => void; } EpdfToolbarCustomTemplate [ClassDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): @Directive({ selector: 'ng-template[epdfToolbarCustom]'} ) export class EpdfToolbarCustomTemplate{ readonly slot = input.required({ alias: 'epdfToolbarCustom'} ); readonly template = inject>(TemplateRef); static ngTemplateContextGuard( _directive: EpdfToolbarCustomTemplate, context: unknown, ): context is EpdfToolbarCustomContext{ return true; } } EpdfToolbarGroupTriggerTemplate [ClassDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): @Directive({ selector: 'ng-template[epdfToolbarGroupTrigger]'} ) export class EpdfToolbarGroupTriggerTemplate{ readonly template = inject>>(TemplateRef); static ngTemplateContextGuard( _directive: EpdfToolbarGroupTriggerTemplate, context: unknown, ): context is EpdfToolbarViewContext{ return true; } } EpdfToolbarOverflowMenuTemplate [ClassDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): @Directive({ selector: 'ng-template[epdfToolbarOverflowMenu]'} ) export class EpdfToolbarOverflowMenuTemplate{ readonly template = inject>>(TemplateRef); static ngTemplateContextGuard( _directive: EpdfToolbarOverflowMenuTemplate, context: unknown, ): context is EpdfToolbarViewContext{ return true; } } EpdfToolbarOverflowTriggerContext [InterfaceDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): export interface EpdfToolbarOverflowTriggerContext{ $implicit: boolean; toggle: () => void; } EpdfToolbarOverflowTriggerTemplate [ClassDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): @Directive({ selector: 'ng-template[epdfToolbarOverflowTrigger]'} ) export class EpdfToolbarOverflowTriggerTemplate{ readonly template = inject>(TemplateRef); static ngTemplateContextGuard( _directive: EpdfToolbarOverflowTriggerTemplate, context: unknown, ): context is EpdfToolbarOverflowTriggerContext{ return true; } } EpdfToolbarSeparatorTemplate [ClassDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): @Directive({ selector: 'ng-template[epdfToolbarSeparator]'} ) export class EpdfToolbarSeparatorTemplate{ readonly template = inject>(TemplateRef); } EpdfToolbarViewContext [InterfaceDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): export interface EpdfToolbarViewContext{ $implicit: View; } GroupDisclosureView [TypeAliasDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): export type GroupDisclosureView = GroupDisclosureViewOf; Importance [TypeAliasDeclaration] (from packages/core/ui/src/schema.ts): export type Importance = 1 | 2 | 3 | 4 | 5; OverflowMenuView [TypeAliasDeclaration] (from packages/framework/angular/toolbar/src/templates.ts): export type OverflowMenuView = OverflowMenuViewOf; OverflowRow [TypeAliasDeclaration] (from packages/core/ui/src/projection.ts): export type OverflowRow = |{ readonly kind: 'command'; readonly command: string} |{ readonly kind: 'submenu'; readonly command: string; readonly menu: string} ; OverflowSection [InterfaceDeclaration] (from packages/core/ui/src/projection.ts): export interface OverflowSection{ readonly labelKey?: string; readonly role?: 'radio'; readonly rows: readonly OverflowRow[]; } PINNED [VariableDeclaration] (from packages/core/ui/src/schema.ts): PINNED: Importance = 5 Variant [TypeAliasDeclaration] (from packages/core/ui/src/schema.ts): export type Variant = 'icon+label' | 'icon' | 'label'; custom [FunctionDeclaration] (from packages/core/ui/src/schema.ts): export function custom( slot: string, terminal?: string, options?: Omit, ): CustomItem{ return terminal === undefined ?{ slot, ...options} :{ slot, terminal, ...options} ; } group [FunctionDeclaration] (from packages/core/ui/src/schema.ts): export function group( id: string, items: readonly BarChild[], options?: Omit, ): BarGroup{ return{ id, ...options, items} ; } item [FunctionDeclaration] (from packages/core/ui/src/schema.ts): export function item(command: string, options?: Omit): BarItem{ return{ command, ...options} ; }