Skip to main content

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' | 'component' The type of HTML file. 'page' for main pages, 'component' for reusable components.
properties CoraliteModuleDefinitions The initial properties 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 components in a Coralite project.

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

CoralitePathProperties #

Represents URL and file path properties available during component rendering.

Property Type Description
page_url_pathname string The URL pathname.
page_url_dirname string The directory name of the URL.
page_pathname string The file path name.
page_dirname string The directory name of the file.
page_filename string The filename.
data.properties Object<string, string> (optional) Additional properties from data.

CoraliteProperties #

Union type representing properties available for token replacement in components.

Type Description
CoralitePathProperties URL and file path properties.
Object<string, string> Key-value pairs for token replacement.

CoraliteToken #

Represents a token with name and value.

properties Object<string, string> Key-value pairs for token replacement.
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.

CoraliteRef #

Represents an element reference with name and element.

Property Type Description
name string Ref identifier.
element CoraliteElement Corresponding HTML element for the ref.

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.

CoraliteModuleDefinitions #

A collection of module properties associated with a module.

Property Type Description
(Key) CoraliteModuleDefinition Key-value pairs representing module data.
__script__ ScriptContent (optional) Script content for the module.

ScriptContent #

Coralite module script content.

Property Type Description
content string The script content string.
properties Object<string, CoraliteModuleDefinition> Properties associated with the script.

CoraliteModuleProperty #

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).

CoraliteErrorData #

Error or warning data passed to the onError callback.

Property Type Description
level 'WARN' | 'ERR' | 'LOG' The severity level.
message string The message describing the error or warning.
error Error (optional) Optional error object for tracing.

CoraliteOnError #

Callback function for handling errors and warnings.

JavaScript
Code copied!
  /**
  * @callback CoraliteOnError
  * @param {CoraliteErrorData} data - The error or warning data.
  * @returns {void}
  */

Document and Result Types #

CoraliteComponentProperties #

Holds tokenized metadata extracted from document attributes, element references and text nodes.

Property Type Description
refs CoraliteRef[] List of element references.
attributes CoraliteAttributeToken[] List of attribute tokens from the document.
textNodes CoraliteTextNodeToken[] List of text node tokens from the document.

CoraliteComponentResult #

Result of document processing containing extracted properties and temporary elements.

Property Type Description
properties CoraliteModuleDefinitions The module properties extracted from the document.
tempElements CoraliteElement[] Temporary elements created during processing.

CoraliteResult #

Represents a rendered output document with metadata and statistics.

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

CoraliteComponentRoot #

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

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

CoraliteComponent #

Represents a complete Coralite document with metadata and rendering structure.

Property Type Description
root CoraliteComponentRoot 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 properties to ignore by element type.

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.
remove boolean (optional) Mark element to be removed from stack.

ParseHTMLResult #

Result of parsing HTML content.

Property Type Description
root CoraliteComponentRoot The root element of the parsed HTML document.
customElements CoraliteElement[] An array of custom elements identified during parsing.
tempElements CoraliteElement[] An array of temporary elements created during the parsing process.

Module and Plugin Types #

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 (optional) Component paths associated with this module, if any.
lineOffset number (optional) Optional offset value for line numbering purposes within the component.
component CoraliteElement Module's rendering component which defines its structure and layout.
script string (optional) Module's JavaScript raw code used for logic or behavior associated with this module.
properties CoraliteComponentProperties Properties 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, Object<string, CoraliteModuleSlotElement>> Custom slot elements and their configurations, enabling flexible content insertion points within components.
isComponent boolean Indicates whether the module is a component.

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.

CoraliteConfig #

Configuration object for Coralite instance.

Property Type Description
output string The path to the output directory where built files will be placed.
components string The path to the directory containing Coralite components.
pages string The path to the directory containing pages that will be rendered using the provided components.
plugins CoralitePluginInstance[] (optional) Optional array of plugin instances to extend Coralite functionality.
skipRenderByAttribute IgnoreByAttribute[] | string[] (optional) An array of attribute names and properties to skip rendering.

CoraliteScriptContent #

Script content for Coralite instances.

Property Type Description
instanceId string Unique instance identifier.
componentId string (optional) Component identifier for shared functions.
root HTMLElement The custom element instance (Light DOM).
properties Object<string, CoraliteModuleDefinition> (optional) Instance properties.
refs Object Array of reference identifiers.
signal AbortSignal (optional) Lifecycle abort signal for unmount events.

CoraliteModuleScript #

Callback for module script execution.

JavaScript
Code copied!
  /**
        * @callback CoraliteModuleScript
        * @param {CoraliteProperties} properties - The module's current properties
        * @param {CoraliteRef} refs - References template elements
        */

ClientPlugin #

Configuration for client plugins.

Property Type Description
setup function(any): void (optional) Called when plugin is registered.
helpers Object<string, function> (optional) Global or instance helpers to add to scripts.
lifecycle Object<'register'|'beforeExecute'|'afterExecute'|'onScriptCompile', function> (optional) Lifecycle hooks.
transform function(string, Object): string (optional) Transform script content.

InstanceContext #

Context for Coralite script instances.

Property Type Description
instanceId string Unique instance identifier.
componentId string Component identifier.
properties Object<string, CoraliteModuleDefinition> Instance properties.
refs Object<string, string> Instance refs.
document CoraliteComponent (optional) Document context.

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.
helpers Object<string, function> (optional) Global or instance helpers to add to scripts.
lifecycle Object<'register'|'beforeExecute'|'afterExecute'|'onScriptCompile', function> (optional) Lifecycle hooks.
transform function(string, Object): string (optional) Transform script content.
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.
remove boolean (optional) Mark element to be removed from stack.

CoraliteComment #

Represents an HTML comment within the Coralite content tree.

Property Type Description
type 'comment' Comment type.
data string The content of the HTML comment.
parent CoraliteContentNode Parent element of the comment node.
remove boolean (optional) Mark element to be removed from stack.

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.
CoraliteComponentRoot 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
name string Name of attribute.
value string Value of attribute.

CoraliteCollectionCallbackResult #

Result value returned from event handlers.

Property Type Description
type 'page' | 'component' (optional) Document type.
result * (optional) 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 {Promise<coralitecollectioneventresult>} Returns a result object with processed value and optional ID
          * @async
          */</coralitecollectioneventresult>

CoraliteCollectionEventDelete #

Callback for deleting an item from a collection.

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

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
        * @async
        */

CoralitePluginContext #

Runtime context for plugin execution.

Property Type Description
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
properties Object<string, CoraliteModuleDefinition> Instance properties.
refs Object<string, string> Instance refs.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
param.properties CoraliteFilePath & Object<string, any> Properties associated with the page path.
properties Object<string, CoraliteModuleDefinition> Properties associated with the script.

CoralitePluginModule #

Execution function that processes content using plugin logic.

JavaScript
Code copied!
  /**
        * @template T
        * @this {ThisType<coralite>}
          * @callback CoralitePluginModule
          * @param {T} options - Configuration options passed to the plugin
          * @param {CoralitePluginContext} context - Runtime context providing access to properties, document data, module
          info, and path details
          */</coralite>

CoralitePlugin #

Definition of a Coralite plugin.

properties Object<string, CoraliteModuleDefinition> Instance properties.
refs Object<string, string> Instance refs.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
param.properties CoraliteFilePath & Object<string, any> Properties associated with the page path.
properties Object<string, CoraliteModuleDefinition> (optional) Instance properties.
refs Object<string, string> Instance refs.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
param.properties CoraliteFilePath & Object<string, any> Properties associated with the page path.
properties Object<string, CoraliteModuleDefinition> (optional) Instance properties.

CoralitePluginResult #

Result type for Coralite plugins with generic component parameter.

refs Object<string, string> Instance refs.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
properties Object<string, string | string[] | CoraliteAnyNode[]> Key-value pairs of data relevant to plugin execution.
param.properties CoraliteFilePath & Object<string, any> Properties associated with the page path.
metadata Object (optional) Plugin metadata.
client Object (optional) Client plugin configuration.
onPageSet CoralitePluginPageSetCallback (optional) Async callback triggered when a page is created.
onPageUpdate CoralitePluginPageUpdateCallback (optional) Async callback triggered when a page is updated.
onPageDelete CoralitePluginPageDeleteCallback (optional) Async callback triggered when a page is deleted.
onComponentSet CoralitePluginComponentCallback (optional) Async callback triggered when a component is created.
onComponentUpdate CoralitePluginComponentCallback (optional) Async callback triggered when a component is updated.
onComponentDelete CoralitePluginComponentCallback (optional) Async callback triggered when a component is deleted.
onBeforePageRender CoralitePluginBeforePageRenderCallback (optional) Async callback triggered before page render.
onBeforeBuild CoralitePluginBeforeBuildCallback (optional) Async callback triggered before build starts.
onAfterBuild CoralitePluginAfterBuildCallback (optional) Async callback triggered after build completes.

CoralitePluginInstance #

A Coralite plugin with associated component data.

Property Type Description
name string Unique identifier/name of the plugin.
method Function (optional) Execution function that processes content using plugin logic.
components HTMLData[] (optional, default: []) List of custom components to be included in the coralite instance.
client ClientPlugin (optional) Client plugin configuration for extending script functionality.
onPageSet CoralitePluginPageSetCallback (optional) Async callback triggered when a page is created.
onPageUpdate CoralitePluginPageUpdateCallback (optional) Async callback triggered when a page is updated.
onPageDelete CoralitePluginPageDeleteCallback (optional) Async callback triggered when a page is deleted.
onComponentSet CoralitePluginComponentCallback (optional) Async callback triggered when a component is created.
onComponentUpdate CoralitePluginComponentCallback (optional) Async callback triggered when a component is updated.
onComponentDelete CoralitePluginComponentCallback (optional) Async callback triggered when a component is deleted.
onBeforePageRender CoralitePluginBeforePageRenderCallback (optional) Async callback triggered before page render.
onBeforeBuild CoralitePluginBeforeBuildCallback (optional) Async callback triggered before build starts.
onAfterBuild CoralitePluginAfterBuildCallback (optional) Async callback triggered after build completes.

CoralitePluginPageSetCallback #

Async callback triggered when a page is created.

JavaScript
Code copied!
  /**
        * @this {ThisType<coralite>}
          * @callback CoralitePluginPageSetCallback
          * @description Async callback triggered when a page is created. Called with elements, properties, and data.
          * @param {Object} param
          * @param {ParseHTMLResult} param.elements - Parsed HTML elements from the page
          * @param {CoraliteFilePath &amp; Object.&amp;lt;string, any&gt;} param.properties - Properties associated with the page path
          * @param {CoraliteCollectionItem} param.data - Data item representing the newly created page
          * @async
          */</coralite>

CoralitePluginPageUpdateCallback #

Async callback triggered when a page is updated.

JavaScript
Code copied!
  /**
        * @this {ThisType<coralite>}
          * @callback CoralitePluginPageUpdateCallback
          * @description Async callback triggered when a page is updated. Called with elements, new and old properties.
          * @param {Object} param
          * @param {CoraliteElement[]} param.elements - Updated HTML elements from the page
          * @param {CoraliteCollectionItem} param.newValue - The updated data item
          * @param {CoraliteCollectionItem} param.oldValue - The previous data item before update
          * @async
          */</coralite>

CoralitePluginPageDeleteCallback #

Async callback triggered when a page is deleted.

JavaScript
Code copied!
  /**
        * @this {ThisType<coralite>}
          * @callback CoralitePluginPageDeleteCallback
          * @description Async callback triggered when a page is deleted. Called with the deleted data.
          * @param {CoraliteCollectionItem} value - The data item being deleted
          * @async
          */</coralite>

CoralitePluginComponentCallback #

Async callback triggered for component-related events.

JavaScript
Code copied!
  /**
        * @this {ThisType<coralite>}
          * @callback CoralitePluginComponentCallback
          * @description Async callback triggered for component-related events (set, update, delete).
          * @param {CoraliteModule} component - The component module that was set, updated, or deleted
          * @async
          */</coralite>

CoralitePluginBeforePageRenderCallback #

Async callback triggered before a page is rendered.

JavaScript
Code copied!
  /**
        * @this {ThisType<coralite>}
          * @callback CoralitePluginBeforePageRenderCallback
          * @param {Object} param
          * @param {CoraliteComponent} param.component - The page component being rendered
          * @param {Object} param.properties - The current properties context
          * @param {CoralitePage} param.page - The page metadata object
          * @param {Object} param.renderContext - The build&apos;s render context
          * @async
          */</coralite>

CoralitePluginAfterPageRenderCallback #

Async callback triggered after a page has been rendered. Results from this hook are aggregated.

JavaScript
Code copied!
  /**
        * @this {ThisType<coralite>}
          * @callback CoralitePluginAfterPageRenderCallback
          * @param {CoraliteResult} result - The rendered page result
          * @returns {CoraliteResult | CoraliteResult[] | void} Additional pages to add to the build
          * @async
          */</coralite>

Constructor and Methods #

Constructor #

The Coralite constructor initializes a new instance with configuration options for components, pages, plugins and assets.

JavaScript
Code copied!
  /**
  * @constructor
  * @param {Object} options
  * @param {string} options.components - The path to the directory containing Coralite components.
  * @param {string} options.pages - The path to the directory containing pages.
  * @param {CoralitePluginInstance[]} [options.plugins=[]]
  * @param {CoraliteStaticAsset[]} [options.assets=[]]
  * @param {IgnoreByAttribute[]} [options.ignoreByAttribute]
  * @param {string[]} [options.skipRenderByAttribute]
  * @param {CoraliteOnError} [options.onError]
  * @param {'production' | 'development'} [options.mode='production']
  * @param {string} [options.output]
  */

Initialise Method #

Initialises the Coralite instance by loading components and pages from the file system.

JavaScript
Code copied!
  /**
      * Initialises the Coralite instance.
      * @returns {Promise<void>}
          */
          Coralite.prototype.initialise = async function () {
          }
  </void>

Build Method #

Compiles pages and collects the results with controlled concurrency. Can optionally transform each result via a callback before collecting.

JavaScript
Code copied!
  /**
      * @param {string | string[]} [path] - Optional page path(s) to build
      * @param {Object} [options] - Build configuration
      * @param {BuildPageHandler} [callback] - Transformation callback
      * @return {Promise<array<any>&gt;}
          */
          Coralite.prototype.build = async function (path, options, callback) {
          }
  </array<any>

Save Method #

Compiles and saves pages to the output directory.

JavaScript
Code copied!
  /**
      * Compiles and saves pages to disk.
      * @param {string | string[]} [path] - Optional page path(s) to build
      * @param {Object} [options] - Save configuration
      * @returns {Promise<array<{ path: string, duration: number }>&gt;}
          */
          Coralite.prototype.save = async function (path, options) {
          }
  </array<{>

Render Method #

Renders the provided node or array of nodes using the render function.

JavaScript
Code copied!
  /**
  * Renders the provided node or array of nodes using the render function.
  * @param {CoraliteComponentRoot | CoraliteAnyNode | CoraliteAnyNode[]} root - The node(s) to be rendered.
  * @returns {string} returns raw HTML
  */
  Coralite.prototype.transform = function (root) {
  }

Get Page Paths Using Custom Element #

Retrieves page paths associated with a custom element component.

JavaScript
Code copied!
  /**
  * Retrieves page paths associated with a custom element component.
  *
  * @param {string} path - The original path potentially prefixed with the components directory.
  * @returns {string[]} An array of page paths linked to the custom element component.
  */
  Coralite.prototype.getPagePathsUsingCustomElement = function (path) {
  }

Add Render Queue #

Adds a page to the current render queue.

JavaScript
Code copied!
  /**
  * Adds a page to the current render queue.
  * @param {string|CoraliteCollectionItem} value - The path to a page or a CoraliteCollectionItem to add to
  the render queue.
  * @param {string} buildId - The unique identifier for the current build process.
  */
  Coralite.prototype.addRenderQueue = async function (value, buildId) {
  }

Create Component #

Creates a component by processing the provided parameters and returning its template AST.

JavaScript
Code copied!
  /**
     * @param {Object} options
     * @param {string} options.id - Unique identifier for the component
     * @param {CoraliteModuleDefinitions} [options.properties={}] - Token properties available for replacement
     * @param {CoraliteElement} [options.element] - The target custom element
     * @param {CoraliteComponent} options.component - Current document being processed
     * @param {string} [options.contextId] - Context Id
     * @param {number} [options.index] - Context index
     * @param {Object} [options.renderContext] - The build's render context
     * @returns {Promise<coraliteelement | void>}
     */
    Coralite.prototype.createComponentElement = async function (options, head = true) {
    }
  </coraliteelement>

Evaluate Method #

Parses a Coralite module script and evaluates it using a sandboxed context.

JavaScript
Code copied!
  /**
      * Parses a Coralite module script and evaluates it.
      * @private
      * @param {Object} data
      * @param {CoraliteModule} data.module - The Coralite module to evaluate
      * @param {CoraliteModuleDefinitions} data.properties - Replacement properties for the component
      * @param {CoralitePage} data.page - The global page object
      * @param {CoraliteElement} data.root - The component's root element
      * @param {CoraliteComponent} data.component - The document context
      * @param {string} data.contextId - Context Id
      * @param {Object} data.renderContext - The build's render context
      *
      * @returns {Promise<coralitemoduledefinitions>}
          */
          Coralite.prototype._evaluate = async function (data) {
          }
  </coralitemoduledefinitions>

Module Linker #

Generates a custom module linker callback for the Node.js VM context.

JavaScript
Code copied!
  /**
  * @param {CoraliteFilePath} path
  * @param {Object} context
  * @private
  */
  Coralite.prototype._moduleLinker = function (path, context) {
  }

Trigger Plugin Hook #

Executes all plugin callbacks registered under the specified hook name sequentially.

JavaScript
Code copied!
  /**
      * @template T
      * @private
      * @param {string} name - The name of the hook to trigger.
      * @param {T} initialData - Data to pass to each callback function.
      * @return {Promise<t>} A promise that resolves to the merged data.
          */
          Coralite.prototype._triggerPluginHook = async function (name, initialData) {
          }
  </t>

Start Building with Coralite!

Use the scaffolding script to get jump started into your next project with Coralite

Copied commandline!