'use strict';
/**
* @author schukai GmbH
*/
import {Monster, Base} from '../types/base.js';
import {validateInstance, validateString} from "../types/validate.js";
import {getGlobalFunction} from "../types/global.js";
import {ProxyObserver} from "../types/proxyobserver.js";
/**
* attribute prefix
*
* @type {string}
* @memberOf Monster/DOM
*/
const ATTRIBUTEPREFIX = "data-monster-";
/**
* you can call the method via the monster namespace `new Monster.DOM.Assembler()`.
*
* ```
* <script type="module">
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.6.0/dist/modules/dom/assembler.js';
* console.log(new Monster.DOM.Assembler())
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {Assembler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.6.0/dist/modules/dom/assembler.js';
* console.log(new Assembler())
* </script>
* ```
*
* @since 1.6.0
* @copyright schukai GmbH
* @memberOf Monster/DOM
*/
class Assembler extends Base {
/**
* @param {DocumentFragment} fragment
* @throws {TypeError} value is not an instance of
* @throws {TypeError} value is not a function
* @throws {Error} the function is not defined
*/
constructor(fragment) {
super();
this.attributePrefix = ATTRIBUTEPREFIX;
validateInstance(fragment, getGlobalFunction('DocumentFragment'));
this.fragment = fragment;
}
/**
*
* @param {string} prefix
* @returns {Assembler}
* @throws {TypeError} value is not a string
*/
setAttributePrefix(prefix) {
validateString(prefix);
this.attributePrefix = prefix;
return this;
}
/**
*
* @returns {string}
*/
getAttributePrefix() {
return this.attributePrefix;
}
/**
*
* @param {ProxyObserver|undefined} data
* @return {DocumentFragment}
* @throws {TypeError} value is not an instance of
*/
createDocumentFragment(data) {
if (data === undefined) {
data = new ProxyObserver({});
}
validateInstance(data, ProxyObserver);
let fragment = this.fragment.cloneNode(true);
return fragment;
}
}
Monster.assignToNamespace('Monster.DOM', Assembler);
export {Monster, ATTRIBUTEPREFIX, Assembler}