dom/template.js

'use strict';

/**
 * @author schukai GmbH
 */

import {Monster, Base} from '../types/base.js';
import {getGlobalFunction} from '../types/global.js';
import {validateInstance} from "../types/validate.js";

/**
 * you can call the method via the monster namespace `new Monster.DOM.Template()`.
 *
 * ```
 * <script type="module">
 * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.6.0/dist/modules/dom/template.js';
 * console.log(new Monster.DOM.Template())
 * </script>
 * ```
 *
 * Alternatively, you can also integrate this function individually.
 *
 * ```
 * <script type="module">
 * import {Template} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.6.0/dist/modules/dom/template.js';
 * console.log(new Template())
 * </script>
 * ```
 *
 * @since 1.6.0
 * @copyright schukai GmbH
 * @memberOf Monster/DOM
 */
class Template extends Base {
    /**
     *
     * @param {HTMLTemplateElement} template
     * @throws {TypeError} value is not an instance of
     * @throws {TypeError} value is not a function
     * @throws {Error} the function is not defined
     */
    constructor(template) {
        super();
        validateInstance(template, getGlobalFunction('HTMLTemplateElement'));
        this.template = template;
    }

    /**
     *
     * @returns {HTMLTemplateElement}
     */
    getTemplateElement() {
        return this.template;
    }

    /**
     *
     * @return {DocumentFragment}
     * @throws {TypeError} value is not an instance of
     */
    createDocumentFragment() {
        return this.template.content.cloneNode(true);
    }

}

Monster.assignToNamespace('Monster.DOM', Template);
export {Monster, Template}