Coralite Type Reference

This document serves as a comprehensive reference for the type definitions used within the Coralite. It outlines the structure, properties, and relationships of core types involved in parsing, rendering, and managing HTML documents, templates, and modules. The following sections provide detailed breakdowns of each type, with tables and internal links for easy navigation.

Core Types

HTMLData

Represents HTML file data including path and raw content.

Property Type Description
type 'page' | 'template' The type of HTML file. 'page' for main pages, 'template' for reusable components.
values CoraliteModuleValues The initial values for the HTML module.
path CoraliteFilePath The file's path information within the project structure.
content string (optional) The raw HTML string contents of the file (optional, may be omitted for templates).

CoraliteFilePath

Represents a file's path structure within the project.

Property Type Description
pathname string Full relative path from the project root to the file.
dirname string Directory name containing the file.
filename string The base file name (including extension).

CoralitePath

Defines root directories for pages and templates in a Coralite project.

Property Type Description
pages string The path to the root pages directory.
templates string The path to the root templates directory.

CoraliteToken

Represents a token with name and value.

Property Type Description
name string Token identifier.
content string Token value or content.

CoraliteAttributeToken

Represents an HTML attribute token linked to its parent element.

Property Type Description
name string Attribute token identifier.
element CoraliteElement Corresponding HTML element for the attribute.
tokens CoraliteToken[] Array of associated tokens.

CoraliteTextNodeToken

Represents a text node token with associated metadata.

Property Type Description
textNode CoraliteTextNode Text node that contains the token.
tokens CoraliteToken[] Array of associated tokens.

CoraliteTokenOptions

Configuration options for token handling during processing.

Property Type Description
default Object.<string, string> Default token values for properties not explicitly set.
aliases Object.<string, string[]> Token aliases and their possible values.

Document and Result Types

CoraliteDocumentValues

Holds tokenized metadata extracted from document attributes and text nodes.

Property Type Description
attributes CoraliteAttributeToken[] Array of attribute tokens from the document.
textNodes CoraliteTextNodeToken[] Array of text node tokens from the document.

CoraliteResult

Represents a rendered output document with metadata and statistics.

Property Type Description
item CoraliteDocument The document object from the rendering process.
html string Raw HTML content of the render process as a string.
duration number (optional) Time taken to render the page in milliseconds.

CoraliteDocumentRoot

Represents the root node of a document containing all content nodes.

Property Type Description
children CoraliteAnyNode[] | CoraliteDirective[] Document list of elements, text nodes, or directives.

CoraliteDocument

Represents a complete Coralite document with metadata and rendering structure.

Property Type Description
root CoraliteDocumentRoot Array of elements and text nodes in the document.
customElements CoraliteElement[] Custom elements defined in the document.
path CoralitePath & CoraliteFilePath Document's file path.
ignoreByAttribute IgnoreByAttribute[] An array of attribute names and values to ignore by element type.

Module and Plugin Types

CoraliteModuleValues

A collection of module values associated with a module.

Property Type Description
(Key) CoraliteModuleValue Key-value pairs representing module data.

CoraliteModuleValue

Represents a single value that a module can store or process.

Type Description
string A simple string value.
string[] An array of strings.
CoraliteDirective[] Array of directives (e.g., DOCTYPE).
CoraliteAnyNode[] Array of content nodes (elements, text, comments).

CoraliteModule

A module within the Coralite library, containing metadata and rendering logic.

Property Type Description
id string Unique module identifier used to reference this module within the application.
path CoraliteFilePath Template paths associated with this module, if any.
lineOffset number (optional) Optional offset value for line numbering purposes within the template.
template CoraliteElement Module's rendering template which defines its structure and layout.
script string (optional) Module's JavaScript raw code used for logic or behavior associated with this module.
values CoraliteDocumentValues Values generated from the module's markup, containing metadata or variable information.
customElements CoraliteElement[] Custom elements defined in the module, allowing extension of HTML capabilities.
slotElements Object.<string, CoraliteModuleSlotElement> Custom slot elements and their configurations, enabling flexible content insertion points within components.

CoraliteModuleSlotElement

Defines a slot element and its configuration within a module.

Property Type Description
name string Slot element identifier.
element CoraliteElement Corresponding HTML element for the slot.

CoraliteDirective

Represents a directive found in HTML content, like a DOCTYPE declaration.

Property Type Description
type 'directive' Node type.
data string Raw HTML Doctype.
name string Doctype name.

Content Nodes

CoraliteElement

Represents a standard HTML element in the Coralite content tree.

Property Type Description
type 'tag' Element type.
name string Tag name.
attribs Object.<string, string> Element attributes.
children CoraliteAnyNode[] Child nodes of the element.
parent CoraliteContentNode Parent element.
parentChildIndex number (optional) Position in parent's child list.
slots Object[] (optional) Slot configurations.
remove boolean (optional) Mark element to be removed from stack.

CoraliteTextNode

Represents a text node within the Coralite content tree.

Property Type Description
type 'text' Text node type.
data string Additional attributes for the text node.
parent CoraliteContentNode Parent element of the text node.

CoraliteComment

Represents an HTML comment within the Coralite content tree.

Property Type Description
data string The content of the HTML comment.

CoraliteAnyNode

Union type representing any content node (element, text, or comment).

Type Description
CoraliteElement A standard HTML element.
CoraliteTextNode A text node within the content tree.
CoraliteComment An HTML comment in the content tree.

CoraliteContentNode

Union type representing nodes that can be part of a document's content hierarchy.

Type Description
CoraliteElement A standard HTML element.
CoraliteDocumentRoot Root node containing all content nodes.

Plugins, Collections and Events

IgnoreByAttribute

An array of attribute name-value pairs to exclude from processing.

Property Type Description
(Key) [string, string][] List of attribute names and values to ignore by element type.

CoralitePluginContext

Runtime context for plugin execution.

Property Type Description
values Object.<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.

Execution function that processes content using plugin logic.

JavaScript
Code copied!
/**
 * @callback CoralitePluginModule
 * @param {Object} options - Configuration options passed to the plugin
 * @param {CoralitePluginContext} context - Runtime context providing access to values, document data, module
 info,
 and path details
 */

CoralitePlugin

Definition of a Coralite plugin.

Property Type Description
name string Unique identifier/name of the plugin.
method CoralitePluginModule Execution function that processes content using plugin logic.
templates string[] (optional, default: []) List of custom templates to be included in the coralite instance.

CoralitePluginInstance

A Coralite plugin with associated template data.

Property Type Description
name string Unique identifier/name of the plugin.
method CoralitePluginModule Execution function that processes content using plugin logic.
templates HTMLData[] (optional, default: []) List of custom templates to be included in the coralite instance.

CoraliteCollectionCallbackResult

Result value returned from event handlers.

Property Type Description
type 'page' | 'template' Document type.
result * Result value returned from event handlers.

CoraliteCollectionItem

A document object with both HTMLData properties and result handling capabilities.

Type Description
CoraliteCollectionCallbackResult & HTMLData Combines callback results and HTML data.

CoraliteCollectionEventResult

Processed value from event handlers.

Property Type Description
value * The processed value.
type 'page' | 'template' (optional) Document type.
id string (optional) Optional identifier for the item.

CoraliteCollectionEventSet

Callback for setting an item in a collection.

JavaScript
Code copied!
/**
 * @callback CoraliteCollectionEventSet
 * @param {CoraliteCollectionItem} value - Item to be set
 * @returns {CoraliteCollectionEventResult} Returns a result object with processed value and optional ID
 */

CoraliteCollectionEventDelete

Callback for deleting an item from a collection.

JavaScript
Code copied!
/**
 * @callback CoraliteCollectionEventDelete
 * @param {CoraliteCollectionItem} value - Item or pathname to delete
 */

CoraliteCollectionEventUpdate

Callback for updating an item in a collection.

JavaScript
Code copied!
/**
 * @callback CoraliteCollectionEventUpdate
 * @param {CoraliteCollectionItem} newValue - New item value
 * @param {CoraliteCollectionItem} oldValue - Original item value
 */