Skip to content

remove trim and weakmap polyfill #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict';
// globals
const WeakMap = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/weakmap'));

// utils
const createContent = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/create-content'));
const importNode = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/import-node'));
const trim = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/trim'));
const sanitize = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('domsanitizer'));
const umap = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('umap'));

Expand All @@ -27,8 +23,8 @@ function createInfo(options, template) {
var holes = [];
parse(content, holes, template.slice(0), []);
return {
content: content,
updates: function (content) {
content,
updates (content) {
var updates = [];
var len = holes.length;
var i = 0;
Expand Down Expand Up @@ -111,7 +107,7 @@ function cleanContent(fragment) {
var child = childNodes[i];
if (
child.nodeType !== 1 &&
trim.call(child.textContent).length === 0
child.textContent.trim().length === 0
) {
fragment.removeChild(child);
}
Expand Down
16 changes: 8 additions & 8 deletions cjs/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,25 @@ function parseAttributes(node, holes, parts, path) {
function Any(node, path) {
return {
type: 'any',
node: node,
path: path
node,
path
};
}

function Attr(node, path, name, sparse) {
return {
type: 'attr',
node: node,
path: path,
name: name,
sparse: sparse
node,
path,
name,
sparse
};
}

function Text(node, path) {
return {
type: 'text',
node: node,
path: path
node,
path
};
}
2 changes: 1 addition & 1 deletion esm.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*! (c) Andrea Giammarchi - ISC */var domtagger=function(y){"use strict";var t={};try{t.WeakMap=WeakMap}catch(e){t.WeakMap=function(t,e){var n=e.defineProperty,r=e.hasOwnProperty,a=i.prototype;return a.delete=function(e){return this.has(e)&&delete e[this._]},a.get=function(e){return this.has(e)?e[this._]:void 0},a.has=function(e){return r.call(e,this._)},a.set=function(e,t){return n(e,this._,{configurable:!0,value:t}),this},i;function i(e){n(this,"_",{value:"_@ungap/weakmap"+t++}),e&&e.forEach(o,this)}function o(e){this.set(e[0],e[1])}}(Math.random(),Object)}var n,a,i,r,e=t.WeakMap,c=(n=y,a="fragment",r="content"in s(i="template")?function(e){var t=s(i);return t.innerHTML=e,t.content}:function(e){var t,n=s(a),r=s(i);return o(n,/^[^\S]*?<(col(?:group)?|t(?:head|body|foot|r|d|h))/i.test(e)?(t=RegExp.$1,r.innerHTML="<table>"+e+"</table>",r.querySelectorAll(t)):(r.innerHTML=e,r.childNodes)),n},function(e,t){return("svg"===t?function(e){var t=s(a),n=s("div");return n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg">'+e+"</svg>",o(t,n.firstChild.childNodes),t}:r)(e)});function o(e,t){for(var n=t.length;n--;)e.appendChild(t[0])}function s(e){return e===a?n.createDocumentFragment():n.createElementNS("http://www.w3.org/1999/xhtml",e)}var u,l,f,h,p,v,d,g,m,x,w=(l="appendChild",f="cloneNode",h="createTextNode",v=(p="importNode")in(u=y),(d=u.createDocumentFragment())[l](u[h]("g")),d[l](u[h]("")),(v?u[p](d,!0):d[f](!0)).childNodes.length<2?function e(t,n){for(var r=t[f](),a=t.childNodes||[],i=a.length,o=0;n&&o<i;o++)r[l](e(a[o],n));return r}:v?u[p]:function(e,t){return e[f](!!t)}),b="".trim||function(){return String(this).replace(/^\s+|\s+/g,"")},N="-"+Math.random().toFixed(6)+"%",k=!1;try{g=y.createElement("template"),x="tabindex",(m="content")in g&&(g.innerHTML="<p "+x+'="'+N+'"></p>',g[m].childNodes[0].getAttribute(x)==N)||(N="_dt: "+N.slice(1,-1)+";",k=!0)}catch(e){}var C="\x3c!--"+N+"--\x3e",E=8,M=1,S=3,T=/^(?:plaintext|script|style|textarea|title|xmp)$/i,_=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;var $=" \\f\\n\\r\\t",A="[^"+$+"\\/>\"'=]+",L="["+$+"]+"+A,H="<([A-Za-z]+[A-Za-z0-9:._-]*)((?:",O="(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|<[^>]*?>|"+A.replace("\\/","")+"))?)",R=new RegExp(H+L+O+"+)(["+$+"]*/?>)","g"),j=new RegExp(H+L+O+"*)(["+$+"]*/>)","g"),W=new RegExp("("+L+"\\s*=\\s*)(['\"]?)"+C+"\\2","gi");function F(e,t,n,r){return"<"+t+n.replace(W,z)+r}function z(e,t,n){return t+(n||'"')+N+(n||'"')}function D(e,t,n){return _.test(t)?e:"<"+t+n+"></"+t+">"}var P=k?function(e,t){var n=t.join(" ");return t.slice.call(e,0).sort(function(e,t){return n.indexOf(e.name)<=n.indexOf(t.name)?-1:1})}:function(e,t){return t.slice.call(e,0)};function Z(e,t,n,r){for(var a=e.childNodes,i=a.length,o=0;o<i;){var s=a[o];switch(s.nodeType){case M:var c=r.concat(o);!function(e,t,n,r){var a,i=e.attributes,o=[],s=[],c=P(i,n),u=c.length,l=0;for(;l<u;){var f=c[l++],h=f.value===N;if(h||1<(a=f.value.split(C)).length){var p=f.name;if(o.indexOf(p)<0){o.push(p);var v=n.shift().replace(h?/^(?:|[\S\s]*?\s)(\S+?)\s*=\s*('|")?$/:new RegExp("^(?:|[\\S\\s]*?\\s)("+p+")\\s*=\\s*('|\")[\\S\\s]*","i"),"$1"),d=i[v]||i[v.toLowerCase()];if(h)t.push(q(d,r,v,null));else{for(var g=a.length-2;g--;)n.shift();t.push(q(d,r,v,a))}}s.push(f)}}u=s.length;var m=(l=0)<u&&k&&!("ownerSVGElement"in e);for(;l<u;){var x=s[l++];m&&(x.value=""),e.removeAttribute(x.name)}var w=e.nodeName;if(/^script$/i.test(w)){var b=y.createElement(w);for(u=i.length,l=0;l<u;)b.setAttributeNode(i[l++].cloneNode(!0));b.textContent=e.textContent,e.parentNode.replaceChild(b,e)}}(s,t,n,c),Z(s,t,n,c);break;case E:var u=s.textContent;if(u===N)n.shift(),t.push(T.test(e.nodeName)?G(e,r):{type:"any",node:s,path:r.concat(o)});else switch(u.slice(0,2)){case"/*":if("*/"!==u.slice(-2))break;case"👻":e.removeChild(s),o--,i--}break;case S:T.test(e.nodeName)&&b.call(s.textContent)===C&&(n.shift(),t.push(G(e,r)))}o++}}function q(e,t,n,r){return{type:"attr",node:e,path:t,name:n,sparse:r}}function G(e,t){return{type:"text",node:e,path:t}}var V,B=(V=new e,{get:function(e){return V.get(e)},set:function(e,t){return V.set(e,t),t}});function I(o,f){var e=(o.convert||function(e){return e.join(C).replace(j,D).replace(R,F)})(f),t=o.transform;t&&(e=t(e));var n=c(e,o.type);K(n);var s=[];return Z(n,s,f.slice(0),[]),{content:n,updates:function(c){for(var u=[],l=s.length,e=0,t=0;e<l;){var n=s[e++],r=function(e,t){for(var n=t.length,r=0;r<n;)e=e.childNodes[t[r++]];return e}(c,n.path);switch(n.type){case"any":u.push({fn:o.any(r,[]),sparse:!1});break;case"attr":var a=n.sparse,i=o.attribute(r,n.name,n.node);null===a?u.push({fn:i,sparse:!1}):(t+=a.length-2,u.push({fn:i,sparse:!0,values:a}));break;case"text":u.push({fn:o.text(r),sparse:!1}),r.textContent=""}}return l+=t,function(){var e=arguments.length;if(l!==e-1)throw new Error(e-1+" values instead of "+l+"\n"+f.join("${value}"));for(var t=1,n=1;t<e;){var r=u[t-n];if(r.sparse){var a=r.values,i=a[0],o=1,s=a.length;for(n+=s-2;o<s;)i+=arguments[t++]+a[o++];r.fn(i)}else r.fn(arguments[t++])}return c}}}}var J=[];function K(e){for(var t=e.childNodes,n=t.length;n--;){var r=t[n];1!==r.nodeType&&0===b.call(r.textContent).length&&e.removeChild(r)}}return function(a){var i=J,o=K;return function(e){var t,n,r;return i!==e&&(t=a,n=i=e,r=B.get(n)||B.set(n,I(t,n)),o=r.updates(w.call(y,r.content,!0))),o.apply(null,arguments)}}}(document);
/*! (c) Andrea Giammarchi - ISC */
export default domtagger;
10 changes: 3 additions & 7 deletions esm/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// globals
import WeakMap from '@ungap/weakmap';

// utils
import createContent from '@ungap/create-content';
import importNode from '@ungap/import-node';
import trim from '@ungap/trim';
import sanitize from 'domsanitizer';
import umap from 'umap';

Expand All @@ -26,8 +22,8 @@ function createInfo(options, template) {
var holes = [];
parse(content, holes, template.slice(0), []);
return {
content: content,
updates: function (content) {
content,
updates (content) {
var updates = [];
var len = holes.length;
var i = 0;
Expand Down Expand Up @@ -110,7 +106,7 @@ function cleanContent(fragment) {
var child = childNodes[i];
if (
child.nodeType !== 1 &&
trim.call(child.textContent).length === 0
child.textContent.trim().length === 0
) {
fragment.removeChild(child);
}
Expand Down
16 changes: 8 additions & 8 deletions esm/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,25 @@ function parseAttributes(node, holes, parts, path) {
function Any(node, path) {
return {
type: 'any',
node: node,
path: path
node,
path
};
}

function Attr(node, path, name, sparse) {
return {
type: 'attr',
node: node,
path: path,
name: name,
sparse: sparse
node,
path,
name,
sparse
};
}

function Text(node, path) {
return {
type: 'text',
node: node,
path: path
node,
path
};
}
Loading