import { CELL_INTRO, CELL_JOIN, CELL_TITLE, DIMENSION_INTRO, DIMENSION_TITLE, EDGE_INTRO, EDGE_LABEL, EDGE_TITLE, FOUNDATION_LAYERS_TITLE, FOUNDATION_SEQUENCE_TITLE, INVARIANT_GROUPS_TITLE, INVARIANT_INTRO, INVARIANT_TITLE, LENSES_LABEL, MAP_INTRO, MAP_TITLE, MEMBERS_LABEL, MODE_INTRO, MODE_LABEL, MODE_TITLE, NATURE_LABEL, PATTERN_INTRO, PATTERN_OPERATIONS_TITLE, PATTERN_TITLE, QUESTION_LABEL, REPRESENTATION_INTRO, REPRESENTATION_TITLE, SUBSUMES_LABEL, SURFACES_LABEL, TARGET_LABEL, TECHNIQUES_LABEL, TECHNIQUE_INTRO, TECHNIQUE_TITLE, UNIVERSAL_INTRO, UNIVERSAL_TITLE, } from "#configuration/strings/reason.strings"; import { DIMENSION_SECTION_ID, EDGE_SECTION_ID, INVARIANT_SECTION_ID, MAP_SECTION_ID, MODE_SECTION_ID, PATTERN_SECTION_ID, REASON_ANCHOR, REPRESENTATION_SECTION_ID, TECHNIQUE_SECTION_ID, UNCOVERED_SECTION_ID, UNIVERSAL_SECTION_ID, } from "#core/ids/ontology.ids"; import { FLOW_ARROW, INVARIANT_LABEL, PRINCIPLE_LABEL } from "#configuration/strings/ontology.strings"; import type { Section, Subsection } from "#types/document.types"; import { chips, glossary, labelled, linkList, linkOf, linkRow, linked, row, } from "#domain/converters/ontology.converter"; import { lensSection, mathSection, modelSection, surfaceSection } from "#domain/converters/reason.fragment.converter"; import type { Block } from "#types/block.types"; import { REASON_SECTION_ICON } from "#configuration/icons/ontology.icons"; import type { ReasonView } from "#types/reason.types"; const catalog = function catalog( id: string, title: string, intro: string, subsections: readonly Subsection[], ): Section { return { icon: REASON_SECTION_ICON, id, intro, subsections, title }; }; const record = function record( entry: { readonly anchor: string; readonly id: string }, blocks: readonly Block[], ): Subsection { return { blocks, id: REASON_ANCHOR + entry.anchor, title: entry.id }; }; const dimensionSection = function dimensionSection(reason: ReasonView): Section { return catalog( DIMENSION_SECTION_ID, DIMENSION_TITLE, DIMENSION_INTRO, reason.dimensions.map((dimension) => record(dimension, [ chips([labelled(NATURE_LABEL, dimension.mathNature)]), glossary([row(QUESTION_LABEL, dimension.question), ...linkRow(SURFACES_LABEL, dimension.surfaces)]), ]), ), ); }; const modeSection = function modeSection(reason: ReasonView): Section { return catalog( MODE_SECTION_ID, MODE_TITLE, MODE_INTRO, reason.modes.map((mode) => record(mode, [ glossary([ row(MODE_LABEL, mode.practice), ...(mode.question === null ? [] : [row(QUESTION_LABEL, mode.question)]), ...linkRow(TECHNIQUES_LABEL, mode.techniques), ]), ]), ), ); }; const universalSection = function universalSection(reason: ReasonView): Section { return catalog( UNIVERSAL_SECTION_ID, UNIVERSAL_TITLE, UNIVERSAL_INTRO, reason.universalAxes.map((axis) => record(axis, [ glossary([ row(QUESTION_LABEL, axis.question), row(SUBSUMES_LABEL, linkList(axis.subsumes)), ...linkRow(LENSES_LABEL, axis.lenses), ]), ]), ), ); }; const techniqueSection = function techniqueSection(reason: ReasonView): Section { return catalog( TECHNIQUE_SECTION_ID, TECHNIQUE_TITLE, TECHNIQUE_INTRO, reason.techniques.map((technique) => record(technique, [ chips([linked(MODE_LABEL, technique.mode)]), glossary([row(PRINCIPLE_LABEL, technique.principle), ...linkRow(SURFACES_LABEL, technique.surfaces)]), ]), ), ); }; const cellSection = function cellSection(reason: ReasonView): Section { return catalog(UNCOVERED_SECTION_ID, CELL_TITLE, CELL_INTRO, [ { blocks: [ glossary( reason.uncoveredCells.map((cell) => row( cell.dimension.label + CELL_JOIN + cell.lens.label, linkOf(cell.dimension) + CELL_JOIN + linkOf(cell.lens), ), ), ), ], title: CELL_TITLE, }, ]); }; const mapSection = function mapSection(reason: ReasonView): Section { const { maps } = reason; return catalog(MAP_SECTION_ID, MAP_TITLE, MAP_INTRO, [ { blocks: [glossary([row(FOUNDATION_SEQUENCE_TITLE, maps.foundationSequence.map(linkOf).join(FLOW_ARROW))])], title: FOUNDATION_SEQUENCE_TITLE, }, { blocks: [glossary(maps.foundationLayers.map((layer) => row(layer.layer, linkList(layer.mathTypes))))], title: FOUNDATION_LAYERS_TITLE, }, { blocks: [glossary(maps.invariantGroups.map((group) => row(group.group, linkList(group.members))))], title: INVARIANT_GROUPS_TITLE, }, { blocks: [glossary([row(MEMBERS_LABEL, linkList(maps.patternOperations))])], title: PATTERN_OPERATIONS_TITLE }, ]); }; const edgeSection = function edgeSection(reason: ReasonView): Section { return catalog(EDGE_SECTION_ID, EDGE_TITLE, EDGE_INTRO, [ { blocks: [ glossary( reason.edges.map((edge) => row( edge.from.label, [linkOf(edge.from), linked(TARGET_LABEL, edge.to), labelled(EDGE_LABEL, edge.label)] .filter((part): part is string => part !== null) .join(FLOW_ARROW), ), ), ), ], title: EDGE_TITLE, }, ]); }; export const catalogSections = function catalogSections(reason: ReasonView): readonly Section[] { return [ mathSection(reason), dimensionSection(reason), lensSection(reason), modeSection(reason), catalog( REPRESENTATION_SECTION_ID, REPRESENTATION_TITLE, REPRESENTATION_INTRO, reason.representations.map((representation) => record(representation, [{ kind: "text", text: representation.expression }]), ), ), catalog( PATTERN_SECTION_ID, PATTERN_TITLE, PATTERN_INTRO, reason.patternTypes.map((pattern) => record(pattern, [{ kind: "text", text: pattern.viewpoint }])), ), modelSection(reason), universalSection(reason), surfaceSection(reason), techniqueSection(reason), catalog( INVARIANT_SECTION_ID, INVARIANT_TITLE, INVARIANT_INTRO, reason.invariants.map((invariant) => record(invariant, [ glossary([ row(INVARIANT_LABEL, invariant.statement), ...linkRow(SURFACES_LABEL, invariant.surfaces), ]), ]), ), ), cellSection(reason), mapSection(reason), edgeSection(reason), ]; };