"use strict"; feather.replace() var ns = 'http://standards.buildingsmart.org/IDS'; var xs = 'http://www.w3.org/2001/XMLSchema'; class IDSContainer extends HTMLElement { connectedCallback() { this.filename = 'specifications.ids'; this.ids = null; this.containerId = crypto.randomUUID(); } } class IDSInfo extends HTMLElement { load(idsElement) { this.idsElement = idsElement; var idsInfoElements = this.getElementsByTagName('ids-info-element'); for (var i=0; i c.toUpperCase()); } load(idsParentElement, idsElement) { this.idsElement = idsElement; this.idsParentElement = idsParentElement; if (idsElement) { this.textContent = idsElement.textContent; } this.idsElement ? this.classList.remove('null') : this.classList.add('null'); this.validate() ? this.classList.remove('error') : this.classList.add('error'); } input(e) { if ( ! this.idsElement && this.textContent) { this.add(); } this.idsElement ? this.idsElement.textContent = this.textContent : null; this.idsElement ? this.classList.remove('null') : this.classList.add('null'); this.validate() ? this.classList.remove('error') : this.classList.add('error'); } blur(e) { if (this.idsElement && ( ! this.textContent)) { this.remove(); } if ( ! this.textContent) { this.textContent = this.defaultValue; } this.idsElement ? this.classList.remove('null') : this.classList.add('null'); this.validate() ? this.classList.remove('error') : this.classList.add('error'); } validate() { if (this.attributes['name'].value == 'author') { return this.textContent.match(new RegExp('[^@]+@[^\.]+\..+')) != null; } else if (this.attributes['name'].value == 'date') { return this.textContent.match(new RegExp('[0-9]{4}-[0-9]{2}-[0-9]{2}')) != null; } return true; } add() { var container = this.closest('ids-container'); this.idsElement = container.ids.createElementNS(ns, this.attributes["name"].value); this.idsElement.textContent = this.textContent; this.idsParentElement.appendChild(this.idsElement); } remove() { this.idsParentElement.removeChild(this.idsElement); this.idsElement = null; } } class IDSSpecRemove extends HTMLElement { connectedCallback() { this.addEventListener('click', this.click); } click(e) { var specs = this.closest('ids-specs'); var spec = this.closest('ids-spec'); specs.idsElement.removeChild(spec.idsElement); specs.idsElement.dispatchEvent(new Event('ids-spec-remove')); } } class IDSSpecMove extends HTMLElement { connectedCallback() { this.direction = this.attributes['direction'].value; this.addEventListener('click', this.click); } load(idsElement) { var self = this; this.idsElement = idsElement; this.render(); } render() { var index = Array.prototype.indexOf.call(this.idsElement.parentElement.children, this.idsElement); if (index == 0 && this.direction == 'up') { this.classList.add('hidden'); } else if (index == this.idsElement.parentElement.children.length - 1 && this.direction == 'down') { this.classList.add('hidden'); } else { this.classList.remove('hidden'); } } click(e) { if (this.direction == "up") { this.idsElement.parentElement.insertBefore(this.idsElement, this.idsElement.previousElementSibling); } else if (this.direction == "down") { var nextNextSibling = this.idsElement.nextElementSibling.nextElementSibling; this.idsElement.parentElement.insertBefore(this.idsElement, nextNextSibling); } this.idsElement.parentElement.dispatchEvent(new Event('ids-spec-move')); } } class IDSSpecAdd extends HTMLElement { connectedCallback() { this.addEventListener('click', this.click); } click(e) { var specs = this.closest('ids-specs'); var spec = this.closest('ids-spec'); var container = this.closest('ids-container'); var newSpec = container.ids.createElementNS(ns, "specification"); var newApplicability = container.ids.createElementNS(ns, "applicability"); var newRequirements = container.ids.createElementNS(ns, "requirements"); specs.idsElement.insertBefore(newSpec, spec.idsElement.nextElementSibling); newSpec.appendChild(newApplicability); newSpec.appendChild(newRequirements); specs.idsElement.dispatchEvent(new Event('ids-spec-add')); } } class IDSSpecHandle extends HTMLElement { connectedCallback() { this.addEventListener('dragstart', this.dragstart); this.addEventListener('dragend', this.dragend); } dragstart(e) { var snippet = this.getElementsByClassName('snippet')[0]; snippet.style.left = e.clientX + 'px'; snippet.style.top = e.clientY + 'px'; var dropzones = document.getElementsByTagName('ids-spec'); for (var i=0; i'; this.params.push(value.param); } var predefinedTypes = this.idsElement.getElementsByTagNameNS(ns, 'predefinedType'); if (predefinedTypes.length) { value = this.getIdsValue(predefinedTypes[0]); if (value.type == 'simpleValue') { parameters.type = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'enumeration') { parameters.typeEnumeration = '' + value.content + ''; this.params.push(value.param); } } this.innerHTML = this.renderTemplate(templates, parameters); } loadAttribute() { if (this.type == 'applicability') { var templates = [ 'Data where the {name} is provided', 'Data where the {name} is {value}', 'Data where the {name} follows the convention of {valuePattern}', 'Data where the {name} is either {valueEnumeration}', ]; } else if (this.type == 'requirement') { var templates = [ 'The {name} shall be provided', 'The {name} shall be {value}', 'The {name} shall follow the convention of {valuePattern}', 'The {name} shall be either {valueEnumeration}' ]; } var parameters = {}; var name = this.idsElement.getElementsByTagNameNS(ns, 'name')[0]; var value = this.getIdsValue(name); if (value.type == 'simpleValue') { parameters.name = '' + this.sentence(value.content) + ''; this.params.push(value.param); } var values = this.idsElement.getElementsByTagNameNS(ns, 'value'); if (values.length) { value = this.getIdsValue(values[0]); if (value.type == 'simpleValue') { parameters.value = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'pattern') { parameters.valuePattern = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'enumeration') { parameters.valueEnumeration = '' + value.content + ''; this.params.push(value.param); } } this.innerHTML = this.renderTemplate(templates, parameters); } loadClassification() { if (this.type == 'applicability') { var templates = [ 'Data classified using {system}', 'Data classified as {reference}', 'Data classified following the convention of {referencePattern}', 'Data having a {system} reference of {reference}', 'Data having a {system} reference following the convention of {referencePattern}', ]; } else if (this.type == 'requirement') { var templates = [ 'Shall be classified using {system}', 'Shall be classified as {reference}', 'Shall be classified following the convention of {referencePattern}', 'Shall have a {system} reference of {reference}', 'Shall have a {system} reference following the convention of {referencePattern}', ]; } var parameters = {}; var value; var systems = this.idsElement.getElementsByTagNameNS(ns, 'system'); if (systems.length) { value = this.getIdsValue(systems[0]); if (value.type == 'simpleValue') { parameters.system = '' + value.content + ''; this.params.push(value.param); } } var references = this.idsElement.getElementsByTagNameNS(ns, 'value'); if (references.length) { value = this.getIdsValue(references[0]); if (value.type == 'simpleValue') { parameters.reference = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'pattern') { parameters.referencePattern = '' + value.content + ''; this.params.push(value.param); } } this.innerHTML = this.renderTemplate(templates, parameters); } loadProperty() { if (this.type == 'applicability') { var templates = [ 'Elements with {name} data in the dataset {pset}', 'Elements with {name} data of {value} in the dataset {pset}', 'Elements with {name} data following the convention of {valuePattern} in the dataset {pset}', 'Elements with {name} data with either {valueEnumeration} in the dataset {pset}', ]; } else if (this.type == 'requirement') { var templates = [ '{name} data shall be provided in the dataset {pset}', '{name} data shall be {value} and in the dataset {pset}', '{name} data shall follow the convention of {valuePattern} and in the dataset {pset}', '{name} data shall be one of {valueEnumeration} and in the dataset {pset}', ]; } var parameters = {}; var name = this.idsElement.getElementsByTagNameNS(ns, 'name')[0]; var value = this.getIdsValue(name); if (value.type == 'simpleValue') { parameters.name = '' + this.sentence(value.content) + ''; this.params.push(value.param); } var values = this.idsElement.getElementsByTagNameNS(ns, 'value'); if (values.length) { value = this.getIdsValue(values[0]); if (value.type == 'simpleValue') { parameters.value = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'pattern') { parameters.valuePattern = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'enumeration') { parameters.valueEnumeration = '' + value.content + ''; this.params.push(value.param); } } var propertySet = this.idsElement.getElementsByTagNameNS(ns, 'propertySet')[0]; value = this.getIdsValue(propertySet); if (value.type == 'simpleValue') { parameters.pset = '' + value.content + ''; this.params.push(value.param); } this.innerHTML = this.renderTemplate(templates, parameters); } loadMaterial() { if (this.type == 'applicability') { var templates = [ 'All data with a {value} material', 'All data with a material of either {valueEnumeration}', 'All data with a material', ]; } else if (this.type == 'requirement') { var templates = [ 'Shall shall have a material of {value}', 'Shall have a material of either {valueEnumeration}', 'Shall have a material', ]; } var parameters = {}; var value; var values = this.idsElement.getElementsByTagNameNS(ns, 'value'); if (values.length) { value = this.getIdsValue(values[0]); if (value.type == 'simpleValue') { parameters.value = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'pattern') { parameters.valuePattern = '' + value.content + ''; this.params.push(value.param); } else if (value.type == 'enumeration') { parameters.valueEnumeration = '' + value.content + ''; this.params.push(value.param); } } this.innerHTML = this.renderTemplate(templates, parameters); } loadPartOf() { var templates = ['Must be part of a {entity}'] var parameters = {}; var content = this.capitalise(this.idsElement.attributes['entity'].value.toLowerCase().replace('ifc', '')) parameters.entity = '' + content + ''; this.params.push(this.idsElement); this.innerHTML = this.renderTemplate(templates, parameters); } getIdsValue(element) { var simpleValues = element.getElementsByTagNameNS(ns, 'simpleValue'); if (simpleValues.length) { return {type: 'simpleValue', param: simpleValues[0], content: simpleValues[0].textContent} } var restriction = element.getElementsByTagNameNS(xs, 'restriction')[0]; var patterns = restriction.getElementsByTagNameNS(xs, 'pattern'); if (patterns.length) { return {type: 'pattern', param: patterns[0], content: patterns[0].attributes['value'].value} } var enumerations = restriction.getElementsByTagNameNS(xs, 'enumeration'); if (enumerations.length) { var values = []; for (var i=0; i c.toUpperCase()); } sentence(text) { // E.g. ElevationOfSSLRelative --> Elevation Of S S L Relative var words = text.match(/([A-Z]?[^A-Z]*)/g).slice(0,-1); var mergedWords = []; var mergedWord = ''; for (var i=0; i Elevation Of SSL Relative return mergedWords.join(' '); } } class IDSParam extends HTMLElement { connectedCallback() { this.contentEditable = true; this.addEventListener('input', this.input); this.filter = this.attributes['filter'] ? this.attributes['filter'].value : null; } load(idsElement) { this.idsElement = idsElement; } input(e) { if (this.filter == 'entityName') { this.idsElement.textContent = 'IFC' + this.textContent.toUpperCase(); } else if (this.filter == 'attributeName' || this.filter == 'propertyName') { this.idsElement.textContent = this.textContent.replace(/\s+/g, ''); } else { this.idsElement.textContent = this.textContent; } } } class IDSSpecs extends HTMLElement { load(idsElement) { var self = this; this.idsElement = idsElement; this.idsElement.addEventListener('ids-spec-remove', function() { self.render(); }); this.idsElement.addEventListener('ids-spec-add', function() { self.render(); }); this.idsElement.addEventListener('ids-spec-move', function() { self.render(); }); this.render(); } render() { var template = this.getElementsByTagName('template')[0]; var children = []; for (var i=0; i