typed-dom
Advanced tools
Comparing version 0.0.25 to 0.0.26
@@ -1,2 +0,2 @@ | ||
/*! typed-dom v0.0.25 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
/*! typed-dom v0.0.26 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
require = function e(t, n, r) { | ||
@@ -69,2 +69,8 @@ function s(o, u) { | ||
case 'collection': | ||
if (element_.id) { | ||
void children_.forEach(function (_a) { | ||
var element = _a.element; | ||
return element instanceof HTMLStyleElement && void scope(element); | ||
}); | ||
} | ||
this.children_ = Object.freeze([]); | ||
@@ -74,2 +80,10 @@ this.children = children_; | ||
case 'struct': | ||
if (element_.id) { | ||
void Object.keys(children_).map(function (k) { | ||
return children_[k]; | ||
}).forEach(function (_a) { | ||
var element = _a.element; | ||
return element instanceof HTMLStyleElement && void scope(element); | ||
}); | ||
} | ||
this.children_ = this.observe(__assign({}, children_)); | ||
@@ -81,2 +95,10 @@ void this.structkeys.forEach(function (k) { | ||
} | ||
function scope(style) { | ||
if (!element_.id.match(/^[\w\-]+$/)) | ||
return; | ||
style.innerHTML = style.innerHTML.replace(/^\s*\$scope(?!\w)/gm, '#' + element_.id); | ||
void Array.from(style.querySelectorAll('*')).forEach(function (el) { | ||
return void el.remove(); | ||
}); | ||
} | ||
} | ||
@@ -83,0 +105,0 @@ Object.defineProperty(TypedHTMLElement.prototype, 'element', { |
@@ -1,2 +0,2 @@ | ||
/*! typed-dom v0.0.25 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
require=function e(t,r,n){function i(c,u){if(!r[c]){if(!t[c]){var s="function"==typeof require&&require;if(!u&&s)return s(c,!0);if(o)return o(c,!0);var d=new Error("Cannot find module '"+c+"'");throw d.code="MODULE_NOT_FOUND",d}var a=r[c]={exports:{}};t[c][0].call(a.exports,function(e){var r=t[c][1][e];return i(r||e)},a,a.exports,e,t,r,n)}return r[c].exports}for(var o="function"==typeof require&&require,c=0;c<n.length;c++)i(n[c]);return i}({1:[function(e,t,r){},{}],2:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],3:[function(e,t,r){"use strict";var n=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e};Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){var r=this;if(this.element_=e,this.children_=t,this.mode=void 0===this.children_?"empty":"string"==typeof this.children_?"text":Array.isArray(this.children_)?"collection":"struct",this.structkeys="struct"===this.mode?Object.keys(this.children_):[],void 0!==t)switch(this.mode){case"empty":return;case"text":return this.children_=document.createTextNode(""),this.element_.appendChild(this.children_),void(this.children=t);case"collection":return this.children_=Object.freeze([]),void(this.children=t);case"struct":return this.children_=this.observe(n({},t)),void this.structkeys.forEach(function(e){return void r.element_.appendChild(t[e].element)})}}return Object.defineProperty(e.prototype,"element",{get:function(){return this.element_},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"children",{get:function(){switch(this.mode){case"text":return this.children_.data;default:return this.children_}},set:function(e){var t=this;switch(this.mode){case"empty":return;case"text":if(e===this.children_.data)return;return void(this.children_.data=e);case"collection":if(e===this.children_)return;if(!Object.isFrozen(this.children_))throw new Error("TypedHTMLElement collections cannot be updated recursively.");return e.reduce(function(e,t){var r=e.indexOf(t);return-1===r?e:(e.splice(r,1),e)},this.children_.slice()).forEach(function(e){return void e.element.remove()}),this.children_=[],e.forEach(function(e,r){return t.children_[r]=e,void t.element_.appendChild(e.element)}),void Object.freeze(this.children_);case"struct":if(e===this.children_)return;return void this.structkeys.forEach(function(r){return t.children_[r]=e[r]})}},enumerable:!0,configurable:!0}),e.prototype.observe=function(e){var t=this;return Object.defineProperties(e,this.structkeys.reduce(function(r,n){var i=e[n];return r[n]={configurable:!0,enumerable:!0,get:function(){return i},set:function(e){var r=i;e!==r&&(i=e,t.element_.replaceChild(e.element,r.element))}},r},{}))},e}();r.TypedHTMLElement=i},{}],4:[function(e,t,r){"use strict";function n(e,t){return Object.keys(e).forEach(function(r){return void t.setAttribute(r,e[r]||"")}),t}Object.defineProperty(r,"__esModule",{value:!0});var i=e("./builder");r.TypedHTML=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdo","big","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","datalist","dd","del","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","map","mark","marquee","menu","meta","meter","nav","nextid","nobr","noframes","noscript","object","ol","optgroup","option","p","param","picture","plaintext","pre","progress","q","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","sup","table","tbody","td","template","textarea","tfoot","th","thead","title","tr","track","tt","u","ul","var","video","wbr","xmp","custom"].reduce(function(e,t){return e[t]=function(e,r,o){return e&&r&&"function"!=typeof r?new i.TypedHTMLElement(n(e,(o||function(){return document.createElement(t)})()),r):new i.TypedHTMLElement((r||function(){return document.createElement(t)})(),e)},e},{})},{"./builder":3}],5:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e("./dom/html");r.default=n.TypedHTML,r.TypedHTML=n.TypedHTML,function(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}(e("./util/dom"))},{"./dom/html":4,"./util/dom":6}],6:[function(e,t,r){"use strict";function n(e,t,r,n){function i(e){"object"==typeof n&&n.passive&&(e.preventDefault=s.noop),r(e)}void 0===n&&(n=!1),e.addEventListener(t,i,c(n));var o=function(){return o=s.noop,void e.removeEventListener(t,i,c(n))};return function(){return void o()}}function i(e,t,r,i){void 0===i&&(i=!1);var o=n(e,t,function(e){o(),r(e)},i);return function(){return void o()}}function o(e,t,r,o,c){return void 0===c&&(c={}),n(e,r,function(n){var u=n.target.closest(t);u&&Array.from(e.querySelectorAll(t)).filter(function(e){return e===u}).forEach(function(e){return void i(e,r,function(e){o(e)},c)})},u({},c,{capture:!0}))}function c(e){return d?e:"boolean"==typeof e?e:e.capture}var u=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e};Object.defineProperty(r,"__esModule",{value:!0});var s=e("./noop");r.bind=n,r.once=i,r.delegate=o;var d=!1;try{document.createElement("div").addEventListener("test",function(){},{get capture(){return d=!0}})}catch(e){}},{"./noop":7}],7:[function(e,t,r){"use strict";function n(){}Object.defineProperty(r,"__esModule",{value:!0}),r.noop=n},{}],"typed-dom":[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),function(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}(e("./src/export"));var n=e("./src/export");r.default=n.default},{"./src/export":5}]},{},[1,2,"typed-dom"]); | ||
/*! typed-dom v0.0.26 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
require=function e(t,r,n){function i(c,u){if(!r[c]){if(!t[c]){var s="function"==typeof require&&require;if(!u&&s)return s(c,!0);if(o)return o(c,!0);var a=new Error("Cannot find module '"+c+"'");throw a.code="MODULE_NOT_FOUND",a}var d=r[c]={exports:{}};t[c][0].call(d.exports,function(e){var r=t[c][1][e];return i(r||e)},d,d.exports,e,t,r,n)}return r[c].exports}for(var o="function"==typeof require&&require,c=0;c<n.length;c++)i(n[c]);return i}({1:[function(e,t,r){},{}],2:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],3:[function(e,t,r){"use strict";var n=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e};Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){function r(t){e.id.match(/^[\w\-]+$/)&&(t.innerHTML=t.innerHTML.replace(/^\s*\$scope(?!\w)/gm,"#"+e.id),Array.from(t.querySelectorAll("*")).forEach(function(e){return void e.remove()}))}var i=this;if(this.element_=e,this.children_=t,this.mode=void 0===this.children_?"empty":"string"==typeof this.children_?"text":Array.isArray(this.children_)?"collection":"struct",this.structkeys="struct"===this.mode?Object.keys(this.children_):[],void 0!==t)switch(this.mode){case"empty":return;case"text":return this.children_=document.createTextNode(""),this.element_.appendChild(this.children_),void(this.children=t);case"collection":return e.id&&t.forEach(function(e){var t=e.element;return t instanceof HTMLStyleElement&&void r(t)}),this.children_=Object.freeze([]),void(this.children=t);case"struct":return e.id&&Object.keys(t).map(function(e){return t[e]}).forEach(function(e){var t=e.element;return t instanceof HTMLStyleElement&&void r(t)}),this.children_=this.observe(n({},t)),void this.structkeys.forEach(function(e){return void i.element_.appendChild(t[e].element)})}}return Object.defineProperty(e.prototype,"element",{get:function(){return this.element_},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"children",{get:function(){switch(this.mode){case"text":return this.children_.data;default:return this.children_}},set:function(e){var t=this;switch(this.mode){case"empty":return;case"text":if(e===this.children_.data)return;return void(this.children_.data=e);case"collection":if(e===this.children_)return;if(!Object.isFrozen(this.children_))throw new Error("TypedHTMLElement collections cannot be updated recursively.");return e.reduce(function(e,t){var r=e.indexOf(t);return-1===r?e:(e.splice(r,1),e)},this.children_.slice()).forEach(function(e){return void e.element.remove()}),this.children_=[],e.forEach(function(e,r){return t.children_[r]=e,void t.element_.appendChild(e.element)}),void Object.freeze(this.children_);case"struct":if(e===this.children_)return;return void this.structkeys.forEach(function(r){return t.children_[r]=e[r]})}},enumerable:!0,configurable:!0}),e.prototype.observe=function(e){var t=this;return Object.defineProperties(e,this.structkeys.reduce(function(r,n){var i=e[n];return r[n]={configurable:!0,enumerable:!0,get:function(){return i},set:function(e){var r=i;e!==r&&(i=e,t.element_.replaceChild(e.element,r.element))}},r},{}))},e}();r.TypedHTMLElement=i},{}],4:[function(e,t,r){"use strict";function n(e,t){return Object.keys(e).forEach(function(r){return void t.setAttribute(r,e[r]||"")}),t}Object.defineProperty(r,"__esModule",{value:!0});var i=e("./builder");r.TypedHTML=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdo","big","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","datalist","dd","del","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","map","mark","marquee","menu","meta","meter","nav","nextid","nobr","noframes","noscript","object","ol","optgroup","option","p","param","picture","plaintext","pre","progress","q","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","sup","table","tbody","td","template","textarea","tfoot","th","thead","title","tr","track","tt","u","ul","var","video","wbr","xmp","custom"].reduce(function(e,t){return e[t]=function(e,r,o){return e&&r&&"function"!=typeof r?new i.TypedHTMLElement(n(e,(o||function(){return document.createElement(t)})()),r):new i.TypedHTMLElement((r||function(){return document.createElement(t)})(),e)},e},{})},{"./builder":3}],5:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e("./dom/html");r.default=n.TypedHTML,r.TypedHTML=n.TypedHTML,function(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}(e("./util/dom"))},{"./dom/html":4,"./util/dom":6}],6:[function(e,t,r){"use strict";function n(e,t,r,n){function i(e){"object"==typeof n&&n.passive&&(e.preventDefault=s.noop),r(e)}void 0===n&&(n=!1),e.addEventListener(t,i,c(n));var o=function(){return o=s.noop,void e.removeEventListener(t,i,c(n))};return function(){return void o()}}function i(e,t,r,i){void 0===i&&(i=!1);var o=n(e,t,function(e){o(),r(e)},i);return function(){return void o()}}function o(e,t,r,o,c){return void 0===c&&(c={}),n(e,r,function(n){var u=n.target.closest(t);u&&Array.from(e.querySelectorAll(t)).filter(function(e){return e===u}).forEach(function(e){return void i(e,r,function(e){o(e)},c)})},u({},c,{capture:!0}))}function c(e){return a?e:"boolean"==typeof e?e:e.capture}var u=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e};Object.defineProperty(r,"__esModule",{value:!0});var s=e("./noop");r.bind=n,r.once=i,r.delegate=o;var a=!1;try{document.createElement("div").addEventListener("test",function(){},{get capture(){return a=!0}})}catch(e){}},{"./noop":7}],7:[function(e,t,r){"use strict";function n(){}Object.defineProperty(r,"__esModule",{value:!0}),r.noop=n},{}],"typed-dom":[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),function(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}(e("./src/export"));var n=e("./src/export");r.default=n.default},{"./src/export":5}]},{},[1,2,"typed-dom"]); |
{ | ||
"name": "typed-dom", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"description": "Static typed dom component builder.", | ||
@@ -45,4 +45,4 @@ "private": false, | ||
"gulp-unassert": "^1.0.1", | ||
"karma": "1.6.0", | ||
"karma-chrome-launcher": "^2.1.0", | ||
"karma": "1.7.0", | ||
"karma-chrome-launcher": "^2.1.1", | ||
"karma-coverage": "^1.1.1", | ||
@@ -56,3 +56,3 @@ "karma-coveralls": "^1.1.2", | ||
"mocha": "^3.3.0", | ||
"npm-check-updates": "^2.11.0", | ||
"npm-check-updates": "^2.11.1", | ||
"power-assert": "^1.4.2", | ||
@@ -62,3 +62,3 @@ "run-sequence": "^1.2.2", | ||
"tsify": "^3.0.1", | ||
"typescript": "2.4.0-dev.20170504", | ||
"typescript": "2.4.0-dev.20170511", | ||
"vinyl-buffer": "^1.0.0", | ||
@@ -65,0 +65,0 @@ "vinyl-source-stream": "^1.1.0" |
@@ -11,3 +11,3 @@ # typed-dom | ||
[typed-dom.d.ts](typed-dom.d.ts) | ||
[index.d.ts](index.d.ts) | ||
@@ -21,5 +21,4 @@ ## Usage | ||
const id = 'id'; | ||
const component = TypedHTML.article({ id }, { | ||
style: TypedHTML.style(`#${id} ul { width: 100px; }`), | ||
const component = TypedHTML.article({ id: 'id' }, { | ||
style: TypedHTML.style(`$scope ul { width: 100px; }`), | ||
title: TypedHTML.h1(`title`), | ||
@@ -26,0 +25,0 @@ content: TypedHTML.ul([ |
@@ -39,2 +39,8 @@ import { TypedHTMLElement as ITypedHTMLElement } from '../../'; | ||
case 'collection': | ||
if (element_.id) { | ||
void (<TypedHTMLElementChildren.Collection>children_) | ||
.forEach(({ element }) => | ||
element instanceof HTMLStyleElement && | ||
void scope(element)); | ||
} | ||
this.children_ = <C><TypedHTMLElementChildren.Collection><never[]>Object.freeze([]); | ||
@@ -44,2 +50,9 @@ this.children = children_; | ||
case 'struct': | ||
if (element_.id) { | ||
void Object.keys(children_) | ||
.map(k => (<TypedHTMLElementChildren.Struct>children_)[k]) | ||
.forEach(({ element }) => | ||
element instanceof HTMLStyleElement && | ||
void scope(element)); | ||
} | ||
this.children_ = <C>this.observe({ ...<TypedHTMLElementChildren.Struct>children_ }); | ||
@@ -51,2 +64,10 @@ void this.structkeys | ||
} | ||
function scope(style: HTMLStyleElement): void { | ||
if (!element_.id.match(/^[\w\-]+$/)) return; | ||
style.innerHTML = style.innerHTML.replace(/^\s*\$scope(?!\w)/gm, `#${element_.id}`); | ||
void Array.from(style.querySelectorAll('*')) | ||
.forEach(el => | ||
void el.remove()); | ||
} | ||
} | ||
@@ -53,0 +74,0 @@ private readonly mode: 'empty' | 'text' | 'collection' | 'struct' = this.children_ === void 0 |
@@ -53,2 +53,11 @@ import { Sequence } from 'spica'; | ||
it('scope', function () { | ||
const template = `$scope {}\n $scope {}`; | ||
const result = `#test {}\n#test {}`; | ||
assert(TypedHTML.div({ id: 'test' }, [TypedHTML.style(template)]).children[0].element.innerHTML === result); | ||
assert(TypedHTML.div({ id: 'test' }, { style: TypedHTML.style(template) }).children.style.element.innerHTML === result); | ||
assert(TypedHTML.div({ id: 'test' }, [TypedHTML.style(`<script>`)]).children[0].element.children.length === 0); | ||
assert(TypedHTML.div({ id: '><script>' }, [TypedHTML.style(template)]).children[0].element.innerHTML === template); | ||
}); | ||
it('empty', function () { | ||
@@ -55,0 +64,0 @@ const empty = TypedHTML.div(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66652
1475
139