docxtemplater
Advanced tools
Comparing version 0.5.5 to 0.5.6
@@ -60,3 +60,3 @@ (function() { | ||
if (docXData[jsonFileName]==undefined) throw 'no data found in json file' | ||
jsonInput=JSON.parse(docXData[jsonFileName]) | ||
//jsonInput=JSON.parse(docXData[jsonFileName]) | ||
if (docX[docxFileName]==undefined) throw 'no data found in json file' | ||
@@ -63,0 +63,0 @@ if (debugBool) |
@@ -247,3 +247,2 @@ (function() { | ||
DocUtils.charMap = { | ||
'"': """, | ||
'&': "&", | ||
@@ -1152,6 +1151,11 @@ "'": "'", | ||
}; | ||
if (env === 'browser') { | ||
return this.qr.decode("data:image/png;base64," + this.base64Data); | ||
} else { | ||
return this.qr.decode(this.data, this.data.decoded); | ||
try { | ||
if (env === 'browser') { | ||
return this.qr.decode("data:image/png;base64," + this.base64Data); | ||
} else { | ||
return this.qr.decode(this.data, this.data.decoded); | ||
} | ||
} catch (_error) { | ||
this.qr.result = null; | ||
return this.qr.callback(); | ||
} | ||
@@ -1158,0 +1162,0 @@ }; |
(function(){var t,l;l="undefined"!=typeof global&&null!==global?global:window,t="undefined"!=typeof global&&null!==global?"node":"browser",l.XmlUtil=l.XmlUtil=function(){function t(){}return t.prototype.getListXmlElements=function(t,l,e){var n,o,s,f,g,r,u,i,a,h;for(null==l&&(l=0),null==e&&(e=t.length-1),i=DocUtils.preg_match_all("<(/?[^/> ]+)([^>]*)>",t.substr(l,e)),r=[],n=a=0,h=i.length;h>a;n=++a)u=i[n],"/"===u[1][0]?(f=!1,r.length>0&&(g=r[r.length-1],s=g.tag.substr(1,g.tag.length-2),o=u[1].substr(1),s===o&&(f=!0)),f?r.pop():r.push({tag:"<"+u[1]+">",offset:u.offset})):"/"===u[2][u[2].length-1]||r.push({tag:"<"+u[1]+">",offset:u.offset});return r},t.prototype.getListDifferenceXmlElements=function(t,l,e){var n;for(null==l&&(l=0),null==e&&(e=t.length-1),n=this.getListXmlElements(t,l,e);;){if(n.length<=1)break;if(n[0].tag.substr(2)!==n[n.length-1].tag.substr(1))break;n.pop(),n.shift()}return n},t}()}).call(this); | ||
(function(){var t,e,i;i="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",i.TemplaterState=t=function(){function t(){}return t.prototype.moveCharacters=function(t,e,i){var n,s,a,o;if("number"!=typeof e)return this.moveCharacters(t,e.length,i);if("number"!=typeof i)return this.moveCharacters(t,e,i.length);for(o=[],n=s=t,a=this.matches.length;a>=t?a>=s:s>=a;n=a>=t?++s:--s)o.push(this.charactersAdded[n]+=e-i);return o},t.prototype.calcStartTag=function(t){return this.calcPosition(t.start)},t.prototype.calcXmlTagPosition=function(t){return this.matches[t].offset+this.charactersAdded[t]},t.prototype.calcEndTag=function(t){return this.calcPosition(t.end)+1},t.prototype.calcPosition=function(t){return this.matches[t.numXmlTag].offset+this.matches[t.numXmlTag][1].length+this.charactersAdded[t.numXmlTag]+t.numCharacter},t.prototype.findOuterTagsContent=function(t){var e,i;return i=this.calcStartTag(this.loopOpen),e=this.calcEndTag(this.loopClose),{content:t.substr(i,e-i),start:i,end:e}},t.prototype.findInnerTagsContent=function(t){var e,i;return i=this.calcEndTag(this.loopOpen),e=this.calcStartTag(this.loopClose),{content:t.substr(i,e-i),start:i,end:e}},t.prototype.initialize=function(){return this.inForLoop=!1,this.inTag=!1,this.inDashLoop=!1,this.rawXmlTag=!1,this.textInsideTag=""},t.prototype.startTag=function(){if(this.inTag===!0)throw"Tag already open with text: "+this.textInsideTag;return this.inTag=!0,this.rawXmlTag=!1,this.textInsideTag="",this.tagStart=this.currentStep},t.prototype.loopType=function(){return this.inDashLoop?"dash":this.inForLoop?"for":this.rawXmlTag?"xml":"simple"},t.prototype.isLoopClosingTag=function(){return"/"===this.textInsideTag[0]&&"/"+this.loopOpen.tag===this.textInsideTag},t.prototype.endTag=function(){var t;if(this.inTag===!1)throw"Tag already closed";return this.inTag=!1,this.tagEnd=this.currentStep,"@"===this.textInsideTag[0]&&"simple"===this.loopType()&&(this.rawXmlTag=!0,this.tag=this.textInsideTag.substr(1)),"#"===this.textInsideTag[0]&&"simple"===this.loopType()&&(this.inForLoop=!0,this.loopOpen={start:this.tagStart,end:this.tagEnd,tag:this.textInsideTag.substr(1)}),"-"===this.textInsideTag[0]&&"simple"===this.loopType()&&(this.inDashLoop=!0,t=/^-([a-zA-Z_:]+) ([a-zA-Z_:]+)$/,this.loopOpen={start:this.tagStart,end:this.tagEnd,tag:this.textInsideTag.replace(t,"$2"),element:this.textInsideTag.replace(t,"$1")}),"/"===this.textInsideTag[0]?this.loopClose={start:this.tagStart,end:this.tagEnd}:void 0},t}()}).call(this); | ||
(function(){var e,n,t=[].slice;n="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",n.DocUtils={},n.docX=[],n.docXData=[],DocUtils.escapeRegExp=function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},DocUtils.charMap={'"':""","&":"&","'":"'","<":"<",">":">"},DocUtils.wordToUtf8=function(e){var n,t,r;r=DocUtils.charMap;for(n in r)t=r[n],e=e.replace(new RegExp(DocUtils.escapeRegExp(t),"g"),n);return e},DocUtils.utf8ToWord=function(e){var n,t,r;r=DocUtils.charMap;for(t in r)n=r[t],e=e.replace(new RegExp(DocUtils.escapeRegExp(t),"g"),n);return e},DocUtils.defaultParser=function(e){return{get:function(n){return n[e]}}},DocUtils.nl2br=function(e){return(e+"").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br>$2")},DocUtils.loadDoc=function(t,r){var o,l,i,c,a,u,s,f,p,g,d,h,D,m,U,b,y;if(null==r&&(r={}),h=null!=r.docx?!r.docx:!1,l=null!=r.async?r.async:!1,g=null!=r.intelligentTagging?r.intelligentTagging:!1,c=null!=r.callback?r.callback:null,i="",null==t)throw"path not defined";if(-1!==t.indexOf("/")?(U=t,f=U):(f=t,""===i&&null!=DocUtils.pathConfig&&(i="browser"===e?DocUtils.pathConfig.browser:DocUtils.pathConfig.node),U=i+t),d=function(e){return n.docXData[f]=e,h===!1?(n.docX[f]=new DocxGen(e,{},{intelligentTagging:g}),n.docX[f]):(null!=c&&c(n.docXData[f]),l===!1?n.docXData[f]:void 0)},"browser"===e)y=new XMLHttpRequest,y.open("GET",U,l),y.overrideMimeType&&y.overrideMimeType("text/plain; charset=x-user-defined"),y.onreadystatechange=function(){if(4===this.readyState){if(200===this.status)return d(this.response);if(null!=c)return c(!0)}},y.send();else if(p=new RegExp("(https?)","i"),p.test(t)){switch(b=url.parse(t),r={hostname:b.hostname,path:b.path,method:"GET",rejectUnauthorized:!1},s=function(){throw"Error on HTTPS Call"},m=function(e){var n;return e.setEncoding("binary"),n="",e.on("data",function(e){return n+=e}),e.on("end",function(){return d(n)})},b.protocol){case"https:":D=https.request(r,m).on("error",s);break;case"http:":D=http.request(r,m).on("error",s)}D.end()}else if(l===!0)fs.readFile(U,"binary",function(e,n){if(e){if(null!=c)return c(!0)}else if(d(n),null!=c)return c(n)});else try{if(a=fs.readFileSync(U,"binary"),o=d(a),null==c)return o;c(a)}catch(w){u=w,null!=c&&c()}return f},DocUtils.clone=function(e){var n,t,r;if(null==e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return n="",null!=e.global&&(n+="g"),null!=e.ignoreCase&&(n+="i"),null!=e.multiline&&(n+="m"),null!=e.sticky&&(n+="y"),new RegExp(e.source,n);r=new e.constructor;for(t in e)r[t]=DocUtils.clone(e[t]);return r},DocUtils.xml2Str=function(e){var n,t,r;if(void 0===e)throw"xmlNode undefined!";try{"undefined"!=typeof global&&null!==global?(n=new XMLSerializer,t=n.serializeToString(e)):t=(new XMLSerializer).serializeToString(e)}catch(o){r=o,t=e.xml}return t=t.replace(/\x20xmlns=""/g,"")},DocUtils.Str2xml=function(e){var t,r;return n.DOMParser?(t=new DOMParser,r=t.parseFromString(e,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async=!1,r.loadXML(e)),r},DocUtils.replaceFirstFrom=function(e,n,t,r){return e.substr(0,r)+e.substr(r).replace(n,t)},DocUtils.encode_utf8=function(e){return unescape(encodeURIComponent(e))},DocUtils.convert_spaces=function(e){return e.replace(new RegExp(String.fromCharCode(160),"g")," ")},DocUtils.decode_utf8=function(e){var n;try{return void 0===e?void 0:decodeURIComponent(escape(DocUtils.convert_spaces(e)))}catch(t){throw n=t,console.log(e),console.log("could not decode"),"end"}},DocUtils.base64encode=function(e){return btoa(unescape(encodeURIComponent(e)))},DocUtils.preg_match_all=function(e,n){var r,o;return"object"!=typeof e&&(e=new RegExp(e,"g")),r=[],o=function(){var e,n,o,l,i;return e=arguments[0],o=4<=arguments.length?t.call(arguments,1,i=arguments.length-2):(i=1,[]),n=arguments[i++],l=arguments[i++],o.unshift(e),o.offset=n,r.push(o)},n.replace(e,o),r},DocUtils.sizeOfObject=function(e){var n,t,r;r=0,t=0;for(n in e)r++;return r},Array.prototype.max=function(){return Math.max.apply(null,this)},Array.prototype.min=function(){return Math.min.apply(null,this)}}).call(this); | ||
(function(){var e,n,t=[].slice;n="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",n.DocUtils={},n.docX=[],n.docXData=[],DocUtils.escapeRegExp=function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},DocUtils.charMap={"&":"&","'":"'","<":"<",">":">"},DocUtils.wordToUtf8=function(e){var n,t,r;r=DocUtils.charMap;for(n in r)t=r[n],e=e.replace(new RegExp(DocUtils.escapeRegExp(t),"g"),n);return e},DocUtils.utf8ToWord=function(e){var n,t,r;r=DocUtils.charMap;for(t in r)n=r[t],e=e.replace(new RegExp(DocUtils.escapeRegExp(t),"g"),n);return e},DocUtils.defaultParser=function(e){return{get:function(n){return n[e]}}},DocUtils.nl2br=function(e){return(e+"").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br>$2")},DocUtils.loadDoc=function(t,r){var o,l,i,c,a,u,s,f,p,g,d,h,D,m,U,b,y;if(null==r&&(r={}),h=null!=r.docx?!r.docx:!1,l=null!=r.async?r.async:!1,g=null!=r.intelligentTagging?r.intelligentTagging:!1,c=null!=r.callback?r.callback:null,i="",null==t)throw"path not defined";if(-1!==t.indexOf("/")?(U=t,f=U):(f=t,""===i&&null!=DocUtils.pathConfig&&(i="browser"===e?DocUtils.pathConfig.browser:DocUtils.pathConfig.node),U=i+t),d=function(e){return n.docXData[f]=e,h===!1?(n.docX[f]=new DocxGen(e,{},{intelligentTagging:g}),n.docX[f]):(null!=c&&c(n.docXData[f]),l===!1?n.docXData[f]:void 0)},"browser"===e)y=new XMLHttpRequest,y.open("GET",U,l),y.overrideMimeType&&y.overrideMimeType("text/plain; charset=x-user-defined"),y.onreadystatechange=function(){if(4===this.readyState){if(200===this.status)return d(this.response);if(null!=c)return c(!0)}},y.send();else if(p=new RegExp("(https?)","i"),p.test(t)){switch(b=url.parse(t),r={hostname:b.hostname,path:b.path,method:"GET",rejectUnauthorized:!1},s=function(){throw"Error on HTTPS Call"},m=function(e){var n;return e.setEncoding("binary"),n="",e.on("data",function(e){return n+=e}),e.on("end",function(){return d(n)})},b.protocol){case"https:":D=https.request(r,m).on("error",s);break;case"http:":D=http.request(r,m).on("error",s)}D.end()}else if(l===!0)fs.readFile(U,"binary",function(e,n){if(e){if(null!=c)return c(!0)}else if(d(n),null!=c)return c(n)});else try{if(a=fs.readFileSync(U,"binary"),o=d(a),null==c)return o;c(a)}catch(w){u=w,null!=c&&c()}return f},DocUtils.clone=function(e){var n,t,r;if(null==e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return n="",null!=e.global&&(n+="g"),null!=e.ignoreCase&&(n+="i"),null!=e.multiline&&(n+="m"),null!=e.sticky&&(n+="y"),new RegExp(e.source,n);r=new e.constructor;for(t in e)r[t]=DocUtils.clone(e[t]);return r},DocUtils.xml2Str=function(e){var n,t,r;if(void 0===e)throw"xmlNode undefined!";try{"undefined"!=typeof global&&null!==global?(n=new XMLSerializer,t=n.serializeToString(e)):t=(new XMLSerializer).serializeToString(e)}catch(o){r=o,t=e.xml}return t=t.replace(/\x20xmlns=""/g,"")},DocUtils.Str2xml=function(e){var t,r;return n.DOMParser?(t=new DOMParser,r=t.parseFromString(e,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async=!1,r.loadXML(e)),r},DocUtils.replaceFirstFrom=function(e,n,t,r){return e.substr(0,r)+e.substr(r).replace(n,t)},DocUtils.encode_utf8=function(e){return unescape(encodeURIComponent(e))},DocUtils.convert_spaces=function(e){return e.replace(new RegExp(String.fromCharCode(160),"g")," ")},DocUtils.decode_utf8=function(e){var n;try{return void 0===e?void 0:decodeURIComponent(escape(DocUtils.convert_spaces(e)))}catch(t){throw n=t,console.log(e),console.log("could not decode"),"end"}},DocUtils.base64encode=function(e){return btoa(unescape(encodeURIComponent(e)))},DocUtils.preg_match_all=function(e,n){var r,o;return"object"!=typeof e&&(e=new RegExp(e,"g")),r=[],o=function(){var e,n,o,l,i;return e=arguments[0],o=4<=arguments.length?t.call(arguments,1,i=arguments.length-2):(i=1,[]),n=arguments[i++],l=arguments[i++],o.unshift(e),o.offset=n,r.push(o)},n.replace(e,o),r},DocUtils.sizeOfObject=function(e){var n,t,r;r=0,t=0;for(n in e)r++;return r},Array.prototype.max=function(){return Math.max.apply(null,this)},Array.prototype.min=function(){return Math.min.apply(null,this)}}).call(this); | ||
(function(){var t,e,i,s=[].indexOf||function(t){for(var e=0,i=this.length;i>e;e++)if(e in this&&this[e]===t)return e;return-1};i="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",t=t=function(){function t(t){this.zip=t}var e;return e=["gif","jpeg","jpg","emf","png"],t.prototype.getImageList=function(){var t,i,n,l;l=/[^.]+\.([^.]+)/,i=[];for(n in this.zip.files)t=n.replace(l,"$1"),s.call(e,t)>=0&&i.push({path:n,files:this.zip.files[n]});return i},t.prototype.setImage=function(t,e,i){return null==i&&(i={}),this.zip.remove(t),this.zip.file(t,e,i)},t.prototype.loadImageRels=function(){var t,e,i;return e=DocUtils.decode_utf8(this.zip.files["word/_rels/document.xml.rels"].asText()),this.xmlDoc=DocUtils.Str2xml(e),t=function(){var t,e,s,n;for(s=this.xmlDoc.getElementsByTagName("Relationship"),n=[],t=0,e=s.length;e>t;t++)i=s[t],n.push(parseInt(i.getAttribute("Id").substr(3)));return n}.call(this),this.maxRid=t.max(),this.imageRels=[],this},t.prototype.addExtensionRels=function(t,e){var i,s,n,l,a,o,r,m,p;for(s=this.zip.files["[Content_Types].xml"].asText(),r=DocUtils.Str2xml(s),i=!0,n=r.getElementsByTagName("Default"),m=0,p=n.length;p>m;m++)a=n[m],a.getAttribute("Extension")===e&&(i=!1);return i?(o=r.getElementsByTagName("Types")[0],l=r.createElement("Default"),l.namespaceURI=null,l.setAttribute("ContentType",t),l.setAttribute("Extension",e),o.appendChild(l),this.setImage("[Content_Types].xml",DocUtils.encode_utf8(DocUtils.xml2Str(r)))):void 0},t.prototype.addImageRels=function(t,e){var i,s,n,l;if(null!=this.zip.files["word/media/"+t])throw"file already exists";return this.maxRid++,s={name:"word/media/"+t,data:e,options:{base64:!1,binary:!0,compression:null,date:new Date,dir:!1}},this.zip.file(s.name,s.data,s.options),i=t.replace(/[^.]+\.([^.]+)/,"$1"),this.addExtensionRels("image/"+i,i),l=this.xmlDoc.getElementsByTagName("Relationships")[0],n=this.xmlDoc.createElement("Relationship"),n.namespaceURI=null,n.setAttribute("Id","rId"+this.maxRid),n.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"),n.setAttribute("Target","media/"+t),l.appendChild(n),this.setImage("word/_rels/document.xml.rels",DocUtils.encode_utf8(DocUtils.xml2Str(this.xmlDoc))),this.maxRid},t.prototype.getImageByRid=function(t){var e,i,s,n,l,a;for(n=this.xmlDoc.getElementsByTagName("Relationship"),l=0,a=n.length;a>l;l++)if(s=n[l],e=s.getAttribute("Id"),t===e&&(i=s.getAttribute("Target"),"media/"===i.substr(0,6)))return this.zip.files["word/"+i];return null},t}(),i.ImgManager=t}).call(this); | ||
(function(){var t,e,n,i;i="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser","node"===e&&(global.http=require("http"),global.https=require("https"),global.fs=require("fs"),global.vm=require("vm"),global.DOMParser=require("xmldom").DOMParser,global.XMLSerializer=require("xmldom").XMLSerializer,n=require("path"),global.PNG=require(n.join(__dirname,"../vendor/pngjs/png-node")),global.url=require("url"),["grid.js","version.js","detector.js","formatinf.js","errorlevel.js","bitmat.js","datablock.js","bmparser.js","datamask.js","rsdecoder.js","gf256poly.js","gf256.js","decoder.js","qrcode.js","findpat.js","alignpat.js","databr.js"].forEach(function(t){return vm.runInThisContext(global.fs.readFileSync(__dirname+"/../vendor/jsqrcode/"+t),t)}),["jszip.js"].forEach(function(t){return vm.runInThisContext(global.fs.readFileSync(__dirname+"/../vendor/jszip2.0/dist/"+t),t)})),i.DocxGen=t=function(){function t(t,e,i){this.Tags=null!=e?e:{},this.options=i,this.setOptions(this.options),this.finishedCallback=function(){},this.localImageCreator=n,this.filesProcessed=0,this.qrCodeNumCallBack=0,this.qrCodeWaitingFor=[],null!=t&&t.length>0&&this.load(t)}var n,i;return i=["word/document.xml","word/footer1.xml","word/footer2.xml","word/footer3.xml","word/header1.xml","word/header2.xml","word/header3.xml"],n=function(t,e){var n;return n=JSZipBase64.decode("iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACXSURBVDhPtY7BDYAwDAMZhCf7b8YMxeCoatOQJhWc/KGxT2zlCyaWcz8Y+X7Bs1TFVJSwIHIYyFkQufWIRVX9cNJyW1QpEo4rixaEe7JuQagAUctb7ZFYFh5MVJPBe84CVBnB42//YsZRgKjFDBVg3cI9WbRwXLktQJX8cNIiFhM1ZuTWk7PIYSBhkVcLzwIiCjCxhCjlAkBqYnqFoQQ2AAAAAElFTkSuQmCC"),e(n)},t.prototype.setOptions=function(t){return this.options=t,null!=this.options&&(this.intelligentTagging=null!=this.options.intelligentTagging?this.options.intelligentTagging:!0,this.qrCode=null!=this.options.qrCode?this.options.qrCode:!1,null!=this.options.parser)?this.parser=t.parser:void 0},t.prototype.loadFromFile=function(t,e){var n;return null==e&&(e={}),this.setOptions(e),n={success:function(t){return this.successFun=t},successFun:function(){}},null==e.docx&&(e.docx=!1),null==e.async&&(e.async=!1),null==e.callback&&(e.callback=function(t){return function(e){return t.load(e),n.successFun(t)}}(this)),DocUtils.loadDoc(t,e),e.async===!1?this:n},t.prototype.qrCodeCallBack=function(t,e){var n;return null==e&&(e=!0),e===!0?this.qrCodeWaitingFor.push(t):e===!1&&(n=this.qrCodeWaitingFor.indexOf(t),this.qrCodeWaitingFor.splice(n,1)),this.testReady()},t.prototype.testReady=function(){return 0===this.qrCodeWaitingFor.length&&this.filesProcessed===i.length?(this.ready=!0,this.finishedCallback()):void 0},t.prototype.getImageList=function(){return this.imgManager.getImageList()},t.prototype.setImage=function(t,e,n){return null==n&&(n={}),null==n.binary&&(n.binary=!0),this.imgManager.setImage(t,e,n)},t.prototype.load=function(t){return this.loadedContent=t,this.zip=new JSZip(t),this.imgManager=new ImgManager(this.zip).loadImageRels(),this},t.prototype.applyTags=function(t,e){var n,o,s,r,l,a;for(this.Tags=null!=t?t:this.Tags,null==e&&(e=null),s=0,l=i.length;l>s;s++)o=i[s],null==this.zip.files[o]&&this.filesProcessed++;for(r=0,a=i.length;a>r;r++)o=i[r],null!=this.zip.files[o]&&(n=new DocXTemplater(this.zip.files[o].asText(),{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging,qrCodeCallback:e,localImageCreator:this.localImageCreator,parser:this.parser}),this.setData(o,n.applyTags().content),this.filesProcessed++);return this.testReady()},t.prototype.setData=function(t,e,n){return null==n&&(n={}),this.zip.remove(t),this.zip.file(t,e,n)},t.prototype.getTags=function(){var t,e,n,o,s,r;for(n=[],s=0,r=i.length;r>s;s++)e=i[s],null!=this.zip.files[e]&&(t=new DocXTemplater(this.zip.files[e].asText(),{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging,parser:this.parser}),o=t.applyTags().usedTags,DocUtils.sizeOfObject(o)&&n.push({fileName:e,vars:o}));return n},t.prototype.setTags=function(t){return this.Tags=t,this},t.prototype.output=function(t){var n;return null==t&&(t={}),null==t.download&&(t.download=!0),null==t.name&&(t.name="output.docx"),null==t.type&&(t.type="base64"),n=this.zip.generate({type:t.type}),t.download&&("node"===e?fs.writeFile(process.cwd()+"/"+t.name,n,"base64",function(e){if(e)throw e;return null!=t.callback?t.callback():void 0}):document.location.href="data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,"+n),n},t.prototype.getFullText=function(t){var e;return null==t&&(t="word/document.xml"),e=this.zip.files[t].asText(),new DocXTemplater(e,{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging}).getFullText()},t.prototype.download=function(t,e,n){var i;return null==n&&(n="default.docx"),i=this.zip.generate(),Downloadify.create("downloadify",{filename:function(){return n},data:function(){return i},onCancel:function(){return alert("You have cancelled the saving of this file.")},onError:function(){return alert("You must put something in the File Contents or there will be nothing to save!")},swf:t,downloadImage:e,width:100,height:30,transparent:!0,append:!1,dataType:"base64"})},t}(),"node"===e&&(module.exports=i.DocxGen)}).call(this); | ||
(function(){var e,t,m;m="undefined"!=typeof global&&null!==global?global:window,t="undefined"!=typeof global&&null!==global?"node":"browser",e=e=function(){function e(e){this.xmlTemplater=e,this.imgMatches=[]}return e.prototype.findImages=function(){return this.imgMatches=DocUtils.preg_match_all(/<w:drawing[^>]*>.*?<\/w:drawing>/g,this.xmlTemplater.content),this},e.prototype.replaceImages=function(){var e,t,m,o,r;for(this.qr=[],r=this.imgMatches,t=m=0,o=r.length;o>m;t=++m)e=r[t],this.replaceImage(e,t);return this},e.prototype.imageSetter=function(e){return e.xmlTemplater.numQrCode--,e.xmlTemplater.DocxGen.setImage("word/media/"+e.imgName,e.data),e.xmlTemplater.DocxGen.qrCodeCallBack(e.num,!1)},e.prototype.replaceImage=function(e,m){var o,r,a,s,n,i,l,c,d,p;if(p=DocUtils.Str2xml('<?xml version="1.0" ?><w:document mc:Ignorable="w14 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">'+e[0]+"</w:document>"),"browser"===t&&(d=p.getElementsByTagNameNS("*","blip")[0]),"node"===t&&(d=p.getElementsByTagName("a:blip")[0]),void 0===d)throw"tagRiD undefined !";if(i=d.getAttribute("r:embed"),n=this.xmlTemplater.DocxGen.imgManager.getImageByRid(i),null===n)throw"oldFile undefined";if("browser"===t&&(c=p.getElementsByTagNameNS("*","docPr")[0]),"node"===t&&(c=p.getElementsByTagName("wp:docPr")[0]),void 0===c)throw"tag undefined";if("Copie_"!==c.getAttribute("name").substr(0,6)){if(r=("Copie_"+this.xmlTemplater.imageId+".png").replace(/\x20/,""),this.xmlTemplater.DocxGen.qrCodeNumCallBack++,this.xmlTemplater.DocxGen.qrCodeCallBack(this.xmlTemplater.DocxGen.qrCodeNumCallBack,!0),s=this.xmlTemplater.DocxGen.imgManager.addImageRels(r,""),this.xmlTemplater.imageId++,this.xmlTemplater.DocxGen.setImage("word/media/"+r,n.data),c.setAttribute("name",""+r),d.setAttribute("r:embed","rId"+s),"browser"===t&&(o=p.getElementsByTagNameNS("*","drawing")[0]),"node"===t&&(o=p.getElementsByTagName("w:drawing")[0]),void 0===o)throw"imageTag undefined";return l=DocUtils.xml2Str(o),this.xmlTemplater.content=this.xmlTemplater.content.replace(e[0],l),this.xmlTemplater.numQrCode++,"browser"===t?(this.qr[m]=new DocxQrCode(n.asBinary(),this.xmlTemplater,r,this.xmlTemplater.DocxGen.qrCodeNumCallBack),this.qr[m].decode(this.imageSetter)):/\.png$/.test(n.name)?function(e){return function(t){var o,r,a,s,i;return o=JSZip.base64.encode(n.asBinary()),r=new Buffer(o,"base64"),i=new PNG(r),s=function(o){return i.decoded=o,e.qr[m]=new DocxQrCode(i,e.xmlTemplater,t,e.xmlTemplater.DocxGen.qrCodeNumCallBack),e.qr[m].decode(e.imageSetter)},a=i.decode(s)}}(this)(r):(a={xmlTemplater:this.xmlTemplater,imgName:r,data:n.asBinary()},this.imageSetter(a))}},e}(),m.ImgReplacer=e}).call(this); | ||
(function(){var t,e,a;a="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",t=t=function(){function t(t,a,r,s,l){if(this.xmlTemplater=a,this.imgName=null!=r?r:"",this.num=s,this.callback=l,this.data=t,void 0===this.data)throw"data of qrcode can't be undefined";"browser"===e&&(this.base64Data=JSZip.base64.encode(this.data)),this.ready=!1,this.result=null}return t.prototype.decode=function(t){var a;return this.callback=t,a=this,this.qr=new QrCode,this.qr.callback=function(){var t;return a.ready=!0,a.result=this.result,t=new a.xmlTemplater.currentClass(this.result,a.xmlTemplater.toJson()),t.applyTags(),a.result=t.content,a.searchImage()},"browser"===e?this.qr.decode("data:image/png;base64,"+this.base64Data):this.qr.decode(this.data,this.data.decoded)},t.prototype.searchImage=function(){var t,e,a;if("gen:"===this.result.substr(0,4))return t=function(e){return function(a){return e.data=a,e.callback(e,e.imgName,e.num),e.xmlTemplater.DocxGen.localImageCreator(e.result,t)}}(this);if(null===this.result||void 0===this.result||"error decoding QR Code"===this.result.substr(0,22))return this.callback(this,this.imgName,this.num);a=function(t){return function(e){return t.data=e,t.callback(t,t.imgName,t.num)}}(this);try{return DocUtils.loadDoc(this.result,{docx:!1,callback:a,async:!1})}catch(r){return e=r,console.log(e)}},t}(),a.DocxQrCode=t}).call(this); | ||
(function(){var t,e,a;a="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",t=t=function(){function t(t,a,r,l,s){if(this.xmlTemplater=a,this.imgName=null!=r?r:"",this.num=l,this.callback=s,this.data=t,void 0===this.data)throw"data of qrcode can't be undefined";"browser"===e&&(this.base64Data=JSZip.base64.encode(this.data)),this.ready=!1,this.result=null}return t.prototype.decode=function(t){var a;this.callback=t,a=this,this.qr=new QrCode,this.qr.callback=function(){var t;return a.ready=!0,a.result=this.result,t=new a.xmlTemplater.currentClass(this.result,a.xmlTemplater.toJson()),t.applyTags(),a.result=t.content,a.searchImage()};try{return"browser"===e?this.qr.decode("data:image/png;base64,"+this.base64Data):this.qr.decode(this.data,this.data.decoded)}catch(r){return this.qr.result=null,this.qr.callback()}},t.prototype.searchImage=function(){var t,e,a;if("gen:"===this.result.substr(0,4))return t=function(e){return function(a){return e.data=a,e.callback(e,e.imgName,e.num),e.xmlTemplater.DocxGen.localImageCreator(e.result,t)}}(this);if(null===this.result||void 0===this.result||"error decoding QR Code"===this.result.substr(0,22))return this.callback(this,this.imgName,this.num);a=function(t){return function(e){return t.data=e,t.callback(t,t.imgName,t.num)}}(this);try{return DocUtils.loadDoc(this.result,{docx:!1,callback:a,async:!1})}catch(r){return e=r,console.log(e)}},t}(),a.DocxQrCode=t}).call(this); | ||
(function(){var t,e,a;a="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",a.XmlTemplater=t=function(){function t(t,e){null==t&&(t=""),null==e&&(e={}),this.tagXml="",this.currentClass=a.XmlTemplater,this.fromJson(e),this.templaterState=new TemplaterState,this.currentScope=this.Tags}return t.prototype.load=function(t){var e;return this.content=t,e=new XmlMatcher(this.content).parse(this.tagXml),this.templaterState.matches=e.matches,this.templaterState.charactersAdded=e.charactersAdded},t.prototype.fromJson=function(t){return null==t&&(t={}),this.Tags=null!=t.Tags?t.Tags:{},this.DocxGen=null!=t.DocxGen?t.DocxGen:null,this.intelligentTagging=null!=t.intelligentTagging?t.intelligentTagging:!1,this.scopePath=null!=t.scopePath?t.scopePath:[],this.usedTags=null!=t.usedTags?t.usedTags:{},this.imageId=null!=t.imageId?t.imageId:0,this.parser=null!=t.parser?t.parser:a.DocUtils.defaultParser,this.scopeManager=new ScopeManager(this.Tags,this.scopePath,this.usedTags,this.Tags,this.parser)},t.prototype.toJson=function(){return{Tags:DocUtils.clone(this.scopeManager.tags),DocxGen:this.DocxGen,intelligentTagging:DocUtils.clone(this.intelligentTagging),scopePath:DocUtils.clone(this.scopeManager.scopePath),usedTags:this.scopeManager.usedTags,localImageCreator:this.localImageCreator,imageId:this.imageId,parser:this.parser}},t.prototype.calcIntellegentlyDashElement=function(){return!1},t.prototype.getFullText=function(t){var e,a,l;return this.tagXml=null!=t?t:this.tagXml,a=new XmlMatcher(this.content).parse(this.tagXml),l=function(){var t,l,r,s;for(r=a.matches,s=[],t=0,l=r.length;l>t;t++)e=r[t],s.push(e[2]);return s}(),DocUtils.wordToUtf8(DocUtils.convert_spaces(l.join("")))},t.prototype.applyTags=function(){var t,e,a,l,r,s,n,i,m,o,p,h,g,c,u;for(this.templaterState.initialize(),c=this.templaterState.matches,s=i=0,p=c.length;p>i;s=++i)for(l=c[s],e=l[2],r=m=0,h=e.length;h>m;r=++m){for(t=e[r],this.templaterState.currentStep={numXmlTag:s,numCharacter:r},u=this.templaterState.matches,n=o=0,g=u.length;g>o;n=++o)if(a=u[n],n===s&&this.content[a.offset+this.templaterState.charactersAdded[n]]!==a[0][0])throw new Error("no < at the beginning of "+a[0][0]+" (2)");if("{"===t)this.templaterState.startTag();else if("}"===t){if(this.templaterState.endTag(),"simple"===this.templaterState.loopType()&&this.replaceSimpleTag(),"xml"===this.templaterState.loopType()){this.replaceSimpleTagRawXml();break}if(this.templaterState.isLoopClosingTag())return this.replaceLoopTag()}else this.templaterState.inTag===!0&&(this.templaterState.textInsideTag+=t)}return null!=this.DocxGen&&this.DocxGen.qrCode&&new ImgReplacer(this).findImages().replaceImages(),this},t.prototype.replaceSimpleTag=function(){return this.content=this.replaceTagByValue(DocUtils.utf8ToWord(this.scopeManager.getValueFromScope(this.templaterState.textInsideTag)))},t.prototype.replaceSimpleTagRawXml=function(){var t,e;return e=new SubContent(this.content).getInnerTag(this.templaterState).getOuterXml("w:p"),t=this.scopeManager.getValueFromScope(this.templaterState.tag),this.templaterState.moveCharacters(this.templaterState.tagStart.numXmlTag,t,e.text),this.content=e.replace(t).fullText},t.prototype.deleteOuterTags=function(t,e){var a;return this.templaterState.tagEnd={numXmlTag:this.templaterState.loopOpen.end.numXmlTag,numCharacter:this.templaterState.loopOpen.end.numCharacter},this.templaterState.tagStart={numXmlTag:this.templaterState.loopOpen.start.numXmlTag,numCharacter:this.templaterState.loopOpen.start.numCharacter},e===!1&&(this.templaterState.textInsideTag="-"+this.templaterState.loopOpen.element+" "+this.templaterState.loopOpen.tag),e===!0&&(this.templaterState.textInsideTag="#"+this.templaterState.loopOpen.tag),a=this.replaceTagByValue("",t),this.templaterState.tagEnd={numXmlTag:this.templaterState.loopClose.end.numXmlTag,numCharacter:this.templaterState.loopClose.end.numCharacter},this.templaterState.tagStart={numXmlTag:this.templaterState.loopClose.start.numXmlTag,numCharacter:this.templaterState.loopClose.start.numCharacter},this.templaterState.textInsideTag="/"+this.templaterState.loopOpen.tag,this.replaceTagByValue("",a)},t.prototype.dashLoop=function(t,e){var a,l,r,s,n,i,m;return null==e&&(e=!1),m=this.templaterState.findOuterTagsContent(this.content),i=m._,n=m.start,a=m.end,r=this.getOuterXml(this.content,n,a,t),this.templaterState.moveCharacters(0,"",r.startTag),s=r.text,l=this.deleteOuterTags(s,e),this.forLoop(l,s)},t.prototype.xmlToBeReplaced=function(t,e,a,l){return t===!0?a:e===!0?"<"+this.tagXml+' xml:space="preserve">'+a+"</"+this.tagXml+">":this.templaterState.matches[l][1]+a+("</"+this.tagXml+">")},t.prototype.replaceXmlTag=function(t,e){var a,l,r,s,n,i;if(i=e.xmlTagNumber,a=e.insideValue,s=null!=e.spacePreserve?e.spacePreserve:!0,l=null!=e.noStartTag?e.noStartTag:!1,r=this.xmlToBeReplaced(l,s,a,i),this.templaterState.matches[i][2]=a,n=this.templaterState.calcXmlTagPosition(i),this.templaterState.moveCharacters(i+1,r,this.templaterState.matches[i][0]),-1===t.indexOf(this.templaterState.matches[i][0]))throw"content "+this.templaterState.matches[i][0]+" not found in content";return t=DocUtils.replaceFirstFrom(t,this.templaterState.matches[i][0],r,n),this.templaterState.matches[i][0]=r,t},t.prototype.replaceTagByValue=function(t,e){var a,l,r,s,n,i,m,o;if(null==e&&(e=this.content),-1===this.templaterState.matches[this.templaterState.tagEnd.numXmlTag][2].indexOf("}"))throw"no closing tag at @templaterState.tagEnd.numXmlTag "+this.templaterState.matches[this.templaterState.tagEnd.numXmlTag][2];if(-1===this.templaterState.matches[this.templaterState.tagStart.numXmlTag][2].indexOf("{"))throw"no opening tag at @templaterState.tagStart.numXmlTag "+this.templaterState.matches[this.templaterState.tagStart.numXmlTag][2];if(this.templaterState.tagEnd.numXmlTag===this.templaterState.tagStart.numXmlTag)l={xmlTagNumber:this.templaterState.tagStart.numXmlTag,insideValue:this.templaterState.matches[this.templaterState.tagStart.numXmlTag][2].replace("{"+this.templaterState.textInsideTag+"}",t),noStartTag:null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].first||null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].last},e=this.replaceXmlTag(e,l);else if(this.templaterState.tagEnd.numXmlTag>this.templaterState.tagStart.numXmlTag){for(s=/^([^{]*){.*$/,n=this.templaterState.matches[this.templaterState.tagStart.numXmlTag][2].match(s),l={xmlTagNumber:this.templaterState.tagStart.numXmlTag},null==this.templaterState.matches[this.templaterState.tagStart.numXmlTag].first&&null==this.templaterState.matches[this.templaterState.tagStart.numXmlTag].last?l.insideValue=n[1]+t:(l.insideValue=t,l.noStartTag=null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].last),e=this.replaceXmlTag(e,l),l={insideValue:"",spacePreserve:!1},a=i=m=this.templaterState.tagStart.numXmlTag+1,o=this.templaterState.tagEnd.numXmlTag;o>=m?o>i:i>o;a=o>=m?++i:--i)l.xmlTagNumber=a,e=this.replaceXmlTag(e,l);r=/^[^}]*}(.*)$/,l={insideValue:this.templaterState.matches[this.templaterState.tagEnd.numXmlTag][2].replace(r,"$1"),spacePreserve:!0,xmlTagNumber:a},e=this.replaceXmlTag(e,l)}return e},t.prototype.replaceLoopTag=function(){var t;return"dash"===this.templaterState.loopType()?this.dashLoop(this.templaterState.loopOpen.element):this.intelligentTagging===!0&&(t=this.calcIntellegentlyDashElement(),t!==!1)?this.dashLoop(t,!0):this.forLoop()},t.prototype.calcSubXmlTemplater=function(t,e){var a,l,r;return a=this.toJson(),null!=e&&null!=e.Tags&&(a.Tags=e.Tags,a.scopePath=a.scopePath.concat(this.templaterState.loopOpen.tag)),l=new this.currentClass(t,a),r=l.applyTags(),this.imageId=l.imageId,r},t.prototype.getOuterXml=function(t,e,a,l){var r,s;if(r=t.indexOf("</"+l+">",a),-1===r)throw"can't find endTag "+r;if(r+=("</"+l+">").length,s=Math.max(t.lastIndexOf("<"+l+">",e),t.lastIndexOf("<"+l+" ",e)),-1===s)throw"can't find startTag";return{text:t.substr(s,r-s),startTag:s,endTag:r}},t.prototype.forLoop=function(t,e){var a,l;return null==t&&(t=this.templaterState.findInnerTagsContent(this.content).content),null==e&&(e=this.templaterState.findOuterTagsContent(this.content).content),l=this.templaterState.loopOpen.tag,a="",this.scopeManager.loopOver(l,function(e){return function(l){var r;return r=e.calcSubXmlTemplater(t,{Tags:l}),a+=r.content}}(this)),null==this.scopeManager.get(l)&&this.calcSubXmlTemplater(t,{Tags:{}}),this.content=this.content.replace(e,a),this.calcSubXmlTemplater(this.content)},t}()}).call(this); | ||
@@ -9,0 +9,0 @@ (function(){var t,e,n,l={}.hasOwnProperty,o=function(t,e){function n(){this.constructor=t}for(var o in e)l.call(e,o)&&(t[o]=e[o]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};n="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",n.DocXTemplater=t=function(t){function e(t,l){if(null==t&&(t=""),null==l&&(l={}),e.__super__.constructor.call(this,"",l),this.currentClass=n.DocXTemplater,this.tagXml="w:t","string"!=typeof t)throw"content must be string!";this.load(t)}var l;return o(e,t),l=new XmlUtil,e.prototype.calcIntellegentlyDashElement=function(){var t,n,o,r,a,s,i,c;for(c=this.templaterState.findOuterTagsContent(this.content),t=c.content,r=c.start,n=c.end,o=l.getListXmlElements(this.content,r,n-r),s=0,i=o.length;i>s;s++)if(a=o[s],"<w:tc>"===a.tag)return"w:tr";return e.__super__.calcIntellegentlyDashElement.call(this)},e}(XmlTemplater)}).call(this); |
{ | ||
"name": "docxtemplater", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"author": "Edgar Hipp <hipp.edg@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "A docX templater", |
@@ -252,3 +252,3 @@ # DocxTemplater (also called docxgen.js) # | ||
If you need some help, please look at the docs (just below) read the readme, and then file an issue or come to chat at http://chat.stackexchange.com/rooms/14185/docxtemplater | ||
If you need some help, please look at the docs (just below) read the readme, and then file an issue. | ||
@@ -255,0 +255,0 @@ ### Docxgen methods ### |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
18966
6
12216775
212