Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docxtemplater

Package Overview
Dependencies
Maintainers
1
Versions
319
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docxtemplater - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

8

js/docxgen.js
(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,a;a="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",a.TemplaterState=t=function(){function t(){}return t.prototype.calcStartTag=function(t){return this.matches[t.start.numXmlTag].offset+this.matches[t.start.numXmlTag][1].length+this.charactersAdded[t.start.numXmlTag]+t.start.numCharacter},t.prototype.calcEndTag=function(t){return this.matches[t.end.numXmlTag].offset+this.matches[t.end.numXmlTag][1].length+this.charactersAdded[t.end.numXmlTag]+t.end.numCharacter+1},t.prototype.initialize=function(){return this.inForLoop=!1,this.inTag=!1,this.inDashLoop=!1,this.textInsideTag=""},t.prototype.startTag=function(){if(this.inTag===!0)throw"Tag already open with text: "+this.textInsideTag;return this.inTag=!0,this.textInsideTag="",this.tagStart=this.currentStep},t.prototype.loopType=function(){return this.inDashLoop?"dash":this.inForLoop?"for":"simple"},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.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 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,o,a,r,m,p;for(s=DocUtils.decode_utf8(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++)o=n[m],o.getAttribute("Extension")===e&&(i=!1);return i?(a=r.getElementsByTagName("Types")[0],l=r.createElement("Default"),l.namespaceURI=null,l.setAttribute("ContentType",t),l.setAttribute("Extension",e),a.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,o;for(n=this.xmlDoc.getElementsByTagName("Relationship"),l=0,o=n.length;o>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 e,t,n;n="undefined"!=typeof global&&null!==global?global:window,t="undefined"!=typeof global&&null!==global?"node":"browser","node"===t&&(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,global.PNG=require("../libs/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(e){return vm.runInThisContext(global.fs.readFileSync(__dirname+"/../libs/jsqrcode/"+e),e)}),["jszip.js"].forEach(function(e){return vm.runInThisContext(global.fs.readFileSync(__dirname+"/../libs/jszip2.0/dist/"+e),e)})),n.DocxGen=e=function(){function e(e,t,n,i){this.Tags=null!=t?t:{},this.intelligentTagging=null!=n?n:!0,this.qrCode=null!=i?i:!1,this.finishedCallback=function(){},this.localImageCreator=function(e,t){var n;return n=JSZipBase64.decode("iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACXSURBVDhPtY7BDYAwDAMZhCf7b8YMxeCoatOQJhWc/KGxT2zlCyaWcz8Y+X7Bs1TFVJSwIHIYyFkQufWIRVX9cNJyW1QpEo4rixaEe7JuQagAUctb7ZFYFh5MVJPBe84CVBnB42//YsZRgKjFDBVg3cI9WbRwXLktQJX8cNIiFhM1ZuTWk7PIYSBhkVcLzwIiCjCxhCjlAkBqYnqFoQQ2AAAAAElFTkSuQmCC"),t(n)},this.filesProcessed=0,this.qrCodeNumCallBack=0,this.qrCodeWaitingFor=[],null!=e&&this.load(e)}var n;return n=["word/document.xml","word/footer1.xml","word/footer2.xml","word/footer3.xml","word/header1.xml","word/header2.xml","word/header3.xml"],e.prototype.loadFromFile=function(e,t){var n;return null==t&&(t={}),n={success:function(e){return this.successFun=e},successFun:function(){}},null==t.docx&&(t.docx=!1),null==t.async&&(t.async=!1),null==t.callback&&(t.callback=function(e){return function(t){return e.load(t),n.successFun(e)}}(this)),DocUtils.loadDoc(e,t),t.async===!1?this:n},e.prototype.qrCodeCallBack=function(e,t){var n;return null==t&&(t=!0),t===!0?this.qrCodeWaitingFor.push(e):t===!1&&(n=this.qrCodeWaitingFor.indexOf(e),this.qrCodeWaitingFor.splice(n,1)),this.testReady()},e.prototype.testReady=function(){return 0===this.qrCodeWaitingFor.length&&this.filesProcessed===n.length?(this.ready=!0,this.finishedCallback()):void 0},e.prototype.logUndefined=function(){},e.prototype.getImageList=function(){return this.imgManager.getImageList()},e.prototype.setImage=function(e,t,n){return this.imgManager.setImage(e,t,n)},e.prototype.load=function(e){return this.loadedContent=e,this.zip=new JSZip(e),this.imgManager=new ImgManager(this.zip).loadImageRels(),this},e.prototype.applyTags=function(e,t){var i,o,l,r,s,a;for(this.Tags=null!=e?e:this.Tags,null==t&&(t=null),l=0,s=n.length;s>l;l++)o=n[l],null==this.zip.files[o]&&this.filesProcessed++;for(r=0,a=n.length;a>r;r++)o=n[r],null!=this.zip.files[o]&&(i=new DocXTemplater(this.zip.files[o].asText(),{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging,qrCodeCallback:t,localImageCreator:this.localImageCreator},this,this.Tags,this.intelligentTagging,[],{},0,t,this.localImageCreator),this.setData(o,i.applyTags().content),this.filesProcessed++);return this.testReady()},e.prototype.setData=function(e,t,n){return null==n&&(n={}),this.zip.remove(e),this.zip.file(e,t,n)},e.prototype.getTags=function(){var e,t,i,o,l,r;for(i=[],l=0,r=n.length;r>l;l++)t=n[l],null!=this.zip.files[t]&&(e=new DocXTemplater(this.zip.files[t].asText(),{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging}),o=e.applyTags().usedTags,DocUtils.sizeOfObject(o)&&i.push({fileName:t,vars:o}));return i},e.prototype.setTags=function(e){return this.Tags=e,this},e.prototype.output=function(e,n){var i;return null==e&&(e=!0),null==n&&(n="output.docx"),i=this.zip.generate(),e&&("node"===t?fs.writeFile(process.cwd()+"/"+n,i,"base64",function(e){if(e)throw e}):document.location.href="data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,"+i),i},e.prototype.getFullText=function(e,t){var n;return null==e&&(e="word/document.xml"),null==t&&(t=""),""===t?(n=this.zip.files[e].asText(),this.getFullText(e,n)):new DocXTemplater(t,{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging}).getFullText()},e.prototype.download=function(e,t,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:e,downloadImage:t,width:100,height:30,transparent:!0,append:!1,dataType:"base64"})},e}(),"node"===t&&(module.exports=n.DocxGen)}).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.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,a,c,u,s,f,d,p,g,h,m,b,y,D,w;if(null==r&&(r={}),h=null!=r.docx?!r.docx:!1,l=null!=r.async?r.async:!1,p=null!=r.intelligentTagging?r.intelligentTagging:!1,a=null!=r.callback?r.callback:null,i="",null==t)throw"path not defined";if(-1!==t.indexOf("/")?(y=t,f=y):(f=t,""===i&&null!=DocUtils.pathConfig&&(i="browser"===e?DocUtils.pathConfig.browser:DocUtils.pathConfig.node),y=i+t),g=function(e){return n.docXData[f]=e,h===!1?(n.docX[f]=new DocxGen(e,{},p),n.docX[f]):(null!=a&&a(n.docXData[f]),l===!1?n.docXData[f]:void 0)},"browser"===e)w=new XMLHttpRequest,w.open("GET",y,l),w.overrideMimeType&&w.overrideMimeType("text/plain; charset=x-user-defined"),w.onreadystatechange=function(){if(4===this.readyState){if(200===this.status)return g(this.response);if(null!=a)return a(!0)}},w.send();else if(d=new RegExp("(https?)","i"),d.test(t)){switch(D=url.parse(t),r={hostname:D.hostname,path:D.path,method:"GET",rejectUnauthorized:!1},s=function(){},b=function(e){var n;return e.setEncoding("binary"),n="",e.on("data",function(e){return n+=e}),e.on("end",function(){return g(n)}),e.on("error",function(){})},D.protocol){case"https:":m=https.request(r,b).on("error",s);break;case"http:":m=http.request(r,b).on("error",s)}m.end()}else if(l===!0)fs.readFile(y,"binary",function(e,n){if(e){if(null!=a)return a(!0)}else if(g(n),null!=a)return a(n)});else try{if(c=fs.readFileSync(y,"binary"),o=g(c),null==a)return o;a(c)}catch(x){u=x,null!=a&&a()}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.decode_utf8=function(e){var n;try{return void 0===e?void 0:decodeURIComponent(escape(e.replace(new RegExp(String.fromCharCode(160),"g")," ")))}catch(t){throw n=t,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,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,m,o,r,l,a,s,n,i,c,p,d,g,h,x,u,f,w;for(n=[],e=function(e){return e.xmlTemplater.numQrCode--,e.xmlTemplater.DocxGen.setImage("word/media/"+e.imgName,e.data),e.xmlTemplater.DocxGen.qrCodeCallBack(e.num,!1)},f=this.imgMatches,w=[],g=x=0,u=f.length;u>x;g=++x)if(l=f[g],h=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">'+l[0]+"</w:document>"),this.xmlTemplater.DocxGen.qrCode)d=h.getElementsByTagNameNS("*","blip")[0],void 0===d&&(d=h.getElementsByTagName("a:blip")[0]),void 0!==d?(i=d.getAttribute("r:embed"),s=this.xmlTemplater.DocxGen.imgManager.getImageByRid(i),null!==s?(p=h.getElementsByTagNameNS("*","docPr")[0],void 0===p&&(p=h.getElementsByTagName("wp:docPr")[0]),void 0!==p?"Copie_"!==p.getAttribute("name").substr(0,6)?(r=("Copie_"+this.xmlTemplater.imageId+".png").replace(/\x20/,""),this.xmlTemplater.DocxGen.qrCodeNumCallBack++,this.xmlTemplater.DocxGen.qrCodeCallBack(this.xmlTemplater.DocxGen.qrCodeNumCallBack,!0),a=this.xmlTemplater.DocxGen.imgManager.addImageRels(r,""),this.xmlTemplater.imageId++,this.xmlTemplater.DocxGen.setImage("word/media/"+r,s.data),"browser"===t&&(n[g]=new DocxQrCode(s.asBinary(),this.xmlTemplater,r,this.xmlTemplater.DocxGen.qrCodeNumCallBack)),p.setAttribute("name",""+r),d.setAttribute("r:embed","rId"+a),m=h.getElementsByTagNameNS("*","drawing")[0],void 0===m&&(m=h.getElementsByTagName("w:drawing")[0]),c=DocUtils.xml2Str(m),this.xmlTemplater.content=this.xmlTemplater.content.replace(l[0],c),this.xmlTemplater.numQrCode++,w.push("browser"===t?n[g].decode(e):/\.png$/.test(s.name)?function(t){return function(m){var o,r,l,a,i;return o=JSZip.base64.encode(s.asBinary()),r=new Buffer(o,"base64"),i=new PNG(r),a=function(o){var r;try{return i.decoded=o,n[g]=new DocxQrCode(i,t.xmlTemplater,m,t.xmlTemplater.DocxGen.qrCodeNumCallBack),n[g].decode(e)}catch(l){return r=l,console.log(r),t.xmlTemplater.DocxGen.qrCodeCallBack(t.xmlTemplater.DocxGen.qrCodeNumCallBack,!1)}},l=i.decode(a)}}(this)(r):this.xmlTemplater.DocxGen.qrCodeCallBack(this.xmlTemplater.DocxGen.qrCodeNumCallBack,!1))):w.push(void 0):w.push(void 0)):w.push(void 0)):w.push(void 0);else if(null!=this.xmlTemplater.currentScope.img)if(null!=this.xmlTemplater.currentScope.img[g]){if(r=this.xmlTemplater.currentScope.img[g].name,o=this.xmlTemplater.currentScope.img[g].data,null==this.xmlTemplater.DocxGen)throw"DocxGen not defined";a=this.xmlTemplater.DocxGen.imgManager.addImageRels(r,o),p=h.getElementsByTagNameNS("*","docPr")[0],void 0===p&&(p=h.getElementsByTagName("wp:docPr")[0]),void 0!==p?(this.xmlTemplater.imageId++,p.setAttribute("id",this.xmlTemplater.imageId),p.setAttribute("name",""+r),d=h.getElementsByTagNameNS("*","blip")[0],void 0===d&&(d=h.getElementsByTagName("a:blip")[0]),void 0!==d?(d.setAttribute("r:embed","rId"+a),m=h.getElementsByTagNameNS("*","drawing")[0],void 0===m&&(m=h.getElementsByTagName("w:drawing")[0]),w.push(this.xmlTemplater.content=this.xmlTemplater.content.replace(l[0],DocUtils.xml2Str(m)))):w.push(void 0)):w.push(void 0)}else w.push(void 0);else w.push(void 0);return w},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,e,a,r,l){if(this.xmlTemplater=e,this.imgName=null!=a?a:"",this.num=r,this.callback=l,this.data=t,void 0===this.data)throw"data of qrcode can't be undefined";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 null==e&&(e=!1),e?t.callback(t,t.imgName,t.num):(t.data=docXData[t.result],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 e,t,n;n="undefined"!=typeof global&&null!==global?global:window,t="undefined"!=typeof global&&null!==global?"node":"browser","node"===t&&(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,global.PNG=require("../libs/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(e){return vm.runInThisContext(global.fs.readFileSync(__dirname+"/../libs/jsqrcode/"+e),e)}),["jszip.js"].forEach(function(e){return vm.runInThisContext(global.fs.readFileSync(__dirname+"/../libs/jszip2.0/dist/"+e),e)})),n.DocxGen=e=function(){function e(e,t,n,i){this.Tags=null!=t?t:{},this.intelligentTagging=null!=n?n:!0,this.qrCode=null!=i?i:!1,this.finishedCallback=function(){},this.localImageCreator=function(e,t){var n;return n=JSZipBase64.decode("iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACXSURBVDhPtY7BDYAwDAMZhCf7b8YMxeCoatOQJhWc/KGxT2zlCyaWcz8Y+X7Bs1TFVJSwIHIYyFkQufWIRVX9cNJyW1QpEo4rixaEe7JuQagAUctb7ZFYFh5MVJPBe84CVBnB42//YsZRgKjFDBVg3cI9WbRwXLktQJX8cNIiFhM1ZuTWk7PIYSBhkVcLzwIiCjCxhCjlAkBqYnqFoQQ2AAAAAElFTkSuQmCC"),t(n)},this.filesProcessed=0,this.qrCodeNumCallBack=0,this.qrCodeWaitingFor=[],null!=e&&this.load(e)}var n;return n=["word/document.xml","word/footer1.xml","word/footer2.xml","word/footer3.xml","word/header1.xml","word/header2.xml","word/header3.xml"],e.prototype.loadFromFile=function(e,t){var n;return null==t&&(t={}),n={success:function(e){return this.successFun=e},successFun:function(){}},null==t.docx&&(t.docx=!1),null==t.async&&(t.async=!1),null==t.callback&&(t.callback=function(e){return function(t){return e.load(t),n.successFun(e)}}(this)),DocUtils.loadDoc(e,t),t.async===!1?this:n},e.prototype.qrCodeCallBack=function(e,t){var n;return null==t&&(t=!0),t===!0?this.qrCodeWaitingFor.push(e):t===!1&&(n=this.qrCodeWaitingFor.indexOf(e),this.qrCodeWaitingFor.splice(n,1)),this.testReady()},e.prototype.testReady=function(){return 0===this.qrCodeWaitingFor.length&&this.filesProcessed===n.length?(this.ready=!0,this.finishedCallback()):void 0},e.prototype.logUndefined=function(){},e.prototype.getImageList=function(){return this.imgManager.getImageList()},e.prototype.setImage=function(e,t,n){return null==n&&(n={}),null==n.binary&&(n.binary=!0),this.imgManager.setImage(e,t,n)},e.prototype.load=function(e){return this.loadedContent=e,this.zip=new JSZip(e),this.imgManager=new ImgManager(this.zip).loadImageRels(),this},e.prototype.applyTags=function(e,t){var i,o,l,r,s,a;for(this.Tags=null!=e?e:this.Tags,null==t&&(t=null),l=0,s=n.length;s>l;l++)o=n[l],null==this.zip.files[o]&&this.filesProcessed++;for(r=0,a=n.length;a>r;r++)o=n[r],null!=this.zip.files[o]&&(i=new DocXTemplater(this.zip.files[o].asText(),{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging,qrCodeCallback:t,localImageCreator:this.localImageCreator},this,this.Tags,this.intelligentTagging,[],{},0,t,this.localImageCreator),this.setData(o,i.applyTags().content),this.filesProcessed++);return this.testReady()},e.prototype.setData=function(e,t,n){return null==n&&(n={}),this.zip.remove(e),this.zip.file(e,t,n)},e.prototype.getTags=function(){var e,t,i,o,l,r;for(i=[],l=0,r=n.length;r>l;l++)t=n[l],null!=this.zip.files[t]&&(e=new DocXTemplater(this.zip.files[t].asText(),{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging}),o=e.applyTags().usedTags,DocUtils.sizeOfObject(o)&&i.push({fileName:t,vars:o}));return i},e.prototype.setTags=function(e){return this.Tags=e,this},e.prototype.output=function(e,n){var i;return null==e&&(e=!0),null==n&&(n="output.docx"),i=this.zip.generate(),e&&("node"===t?fs.writeFile(process.cwd()+"/"+n,i,"base64",function(e){if(e)throw e}):document.location.href="data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,"+i),i},e.prototype.getFullText=function(e,t){var n;return null==e&&(e="word/document.xml"),null==t&&(t=""),""===t?(n=this.zip.files[e].asText(),this.getFullText(e,n)):new DocXTemplater(t,{DocxGen:this,Tags:this.Tags,intelligentTagging:this.intelligentTagging}).getFullText()},e.prototype.download=function(e,t,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:e,downloadImage:t,width:100,height:30,transparent:!0,append:!1,dataType:"base64"})},e}(),"node"===t&&(module.exports=n.DocxGen)}).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.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,a,c,u,s,f,d,p,g,h,m,b,y,D,w;if(null==r&&(r={}),h=null!=r.docx?!r.docx:!1,l=null!=r.async?r.async:!1,p=null!=r.intelligentTagging?r.intelligentTagging:!1,a=null!=r.callback?r.callback:null,i="",null==t)throw"path not defined";if(-1!==t.indexOf("/")?(y=t,f=y):(f=t,""===i&&null!=DocUtils.pathConfig&&(i="browser"===e?DocUtils.pathConfig.browser:DocUtils.pathConfig.node),y=i+t),g=function(e){return n.docXData[f]=e,h===!1?(n.docX[f]=new DocxGen(e,{},p),n.docX[f]):(null!=a&&a(n.docXData[f]),l===!1?n.docXData[f]:void 0)},"browser"===e)w=new XMLHttpRequest,w.open("GET",y,l),w.overrideMimeType&&w.overrideMimeType("text/plain; charset=x-user-defined"),w.onreadystatechange=function(){if(4===this.readyState){if(200===this.status)return g(this.response);if(null!=a)return a(!0)}},w.send();else if(d=new RegExp("(https?)","i"),d.test(t)){switch(D=url.parse(t),r={hostname:D.hostname,path:D.path,method:"GET",rejectUnauthorized:!1},s=function(){throw"Error on HTTPS Call"},b=function(e){var n;return e.setEncoding("binary"),n="",e.on("data",function(e){return n+=e}),e.on("end",function(){return g(n)})},D.protocol){case"https:":m=https.request(r,b).on("error",s);break;case"http:":m=http.request(r,b).on("error",s)}m.end()}else if(l===!0)fs.readFile(y,"binary",function(e,n){if(e){if(null!=a)return a(!0)}else if(g(n),null!=a)return a(n)});else try{if(c=fs.readFileSync(y,"binary"),o=g(c),null==a)return o;a(c)}catch(x){u=x,null!=a&&a()}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.decode_utf8=function(e){var n;try{return void 0===e?void 0:decodeURIComponent(escape(e.replace(new RegExp(String.fromCharCode(160),"g")," ")))}catch(t){throw n=t,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,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,m,o,r,a,l,s,i,n,c,p,d,g,h,x,u,f,w;for(i=[],e=function(e){return e.xmlTemplater.numQrCode--,e.xmlTemplater.DocxGen.setImage("word/media/"+e.imgName,e.data),e.xmlTemplater.DocxGen.qrCodeCallBack(e.num,!1)},f=this.imgMatches,w=[],g=x=0,u=f.length;u>x;g=++x)if(a=f[g],h=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">'+a[0]+"</w:document>"),this.xmlTemplater.DocxGen.qrCode)d=h.getElementsByTagNameNS("*","blip")[0],void 0===d&&(d=h.getElementsByTagName("a:blip")[0]),void 0!==d?(n=d.getAttribute("r:embed"),s=this.xmlTemplater.DocxGen.imgManager.getImageByRid(n),null!==s?(p=h.getElementsByTagNameNS("*","docPr")[0],void 0===p&&(p=h.getElementsByTagName("wp:docPr")[0]),void 0!==p?"Copie_"!==p.getAttribute("name").substr(0,6)?(r=("Copie_"+this.xmlTemplater.imageId+".png").replace(/\x20/,""),this.xmlTemplater.DocxGen.qrCodeNumCallBack++,this.xmlTemplater.DocxGen.qrCodeCallBack(this.xmlTemplater.DocxGen.qrCodeNumCallBack,!0),l=this.xmlTemplater.DocxGen.imgManager.addImageRels(r,""),this.xmlTemplater.imageId++,this.xmlTemplater.DocxGen.setImage("word/media/"+r,s.data),p.setAttribute("name",""+r),d.setAttribute("r:embed","rId"+l),m=h.getElementsByTagNameNS("*","drawing")[0],void 0===m&&(m=h.getElementsByTagName("w:drawing")[0]),c=DocUtils.xml2Str(m),this.xmlTemplater.content=this.xmlTemplater.content.replace(a[0],c),this.xmlTemplater.numQrCode++,"browser"===t?(i[g]=new DocxQrCode(s.asBinary(),this.xmlTemplater,r,this.xmlTemplater.DocxGen.qrCodeNumCallBack),w.push(i[g].decode(e))):w.push(/\.png$/.test(s.name)?function(t){return function(m){var o,r,a,l,n;return o=JSZip.base64.encode(s.asBinary()),r=new Buffer(o,"base64"),n=new PNG(r),l=function(o){return n.decoded=o,i[g]=new DocxQrCode(n,t.xmlTemplater,m,t.xmlTemplater.DocxGen.qrCodeNumCallBack),i[g].decode(e)},a=n.decode(l)}}(this)(r):this.xmlTemplater.DocxGen.qrCodeCallBack(this.xmlTemplater.DocxGen.qrCodeNumCallBack,!1))):w.push(void 0):w.push(void 0)):w.push(void 0)):w.push(void 0);else if(null!=this.xmlTemplater.currentScope.img)if(null!=this.xmlTemplater.currentScope.img[g]){if(r=this.xmlTemplater.currentScope.img[g].name,o=this.xmlTemplater.currentScope.img[g].data,null==this.xmlTemplater.DocxGen)throw"DocxGen not defined";l=this.xmlTemplater.DocxGen.imgManager.addImageRels(r,o),p=h.getElementsByTagNameNS("*","docPr")[0],void 0===p&&(p=h.getElementsByTagName("wp:docPr")[0]),void 0!==p?(this.xmlTemplater.imageId++,p.setAttribute("id",this.xmlTemplater.imageId),p.setAttribute("name",""+r),d=h.getElementsByTagNameNS("*","blip")[0],void 0===d&&(d=h.getElementsByTagName("a:blip")[0]),void 0!==d?(d.setAttribute("r:embed","rId"+l),m=h.getElementsByTagNameNS("*","drawing")[0],void 0===m&&(m=h.getElementsByTagName("w:drawing")[0]),w.push(this.xmlTemplater.content=this.xmlTemplater.content.replace(a[0],DocUtils.xml2Str(m)))):w.push(void 0)):w.push(void 0)}else w.push(void 0);else w.push(void 0);return w},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,l=[].slice;a="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",t=t=function(){function t(e,a){null==e&&(e=""),null==a&&(a={}),this.tagXml="",this.currentClass=t,this.fromJson(a),this.currentScope=this.Tags,this.templaterState=new TemplaterState}return t.prototype.load=function(t){var e;return this.content=t,this.templaterState.matches=this._getFullTextMatchesFromData(),this.templaterState.charactersAdded=function(){var t,a,l;for(l=[],e=t=0,a=this.templaterState.matches.length;a>=0?a>t:t>a;e=a>=0?++t:--t)l.push(0);return l}.call(this),this.handleRecursiveCase()},t.prototype.getValueFromScope=function(t,e){var a;if(null==t&&(t=this.templaterState.loopOpen.tag),null==e&&(e=this.currentScope),null!=e[t])if("string"==typeof e[t]){if(this.useTag(t),a=DocUtils.encode_utf8(e[t]),-1!==a.indexOf("{")||-1!==a.indexOf("}"))throw"You can't enter { or } inside the content of a variable"}else a=e[t];else this.useTag(t),a="undefined",this.DocxGen.logUndefined(t,e);return a},t.prototype.getFullText=function(){var t,e;return this.templaterState.matches=this._getFullTextMatchesFromData(),e=function(){var e,a,l,n;for(l=this.templaterState.matches,n=[],e=0,a=l.length;a>e;e++)t=l[e],n.push(t[2]);return n}.call(this),DocUtils.decode_utf8(e.join(""))},t.prototype._getFullTextMatchesFromData=function(){return this.templaterState.matches=DocUtils.preg_match_all("(<"+this.tagXml+"[^>]*>)([^<>]*)</"+this.tagXml+">",this.content)},t.prototype.calcOuterXml=function(t,e,a,l){var n,r;if(n=t.indexOf("</"+l+">",a),-1===n)throw"can't find endTag "+n;if(n+=("</"+l+">").length,r=Math.max(t.lastIndexOf("<"+l+">",e),t.lastIndexOf("<"+l+" ",e)),-1===r)throw"can't find startTag";return{text:t.substr(r,n-r),startTag:r,endTag:n}},t.prototype.findOuterTagsContent=function(){var t,e;return e=this.templaterState.calcStartTag(this.templaterState.loopOpen),t=this.templaterState.calcEndTag(this.templaterState.loopClose),{content:this.content.substr(e,t-e),start:e,end:t}},t.prototype.findInnerTagsContent=function(){var t,e;return e=this.templaterState.calcEndTag(this.templaterState.loopOpen),t=this.templaterState.calcStartTag(this.templaterState.loopClose),{content:this.content.substr(e,t-e),start:e,end:t}},t.prototype.fromJson=function(t){return 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},t.prototype.toJson=function(){return{Tags:DocUtils.clone(this.Tags),DocxGen:this.DocxGen,intelligentTagging:DocUtils.clone(this.intelligentTagging),scopePath:DocUtils.clone(this.scopePath),usedTags:this.usedTags,localImageCreator:this.localImageCreator,imageId:this.imageId}},t.prototype.forLoop=function(t,e){var a,l,n,r,s,i,h,m;if(null==t&&(t=this.findInnerTagsContent().content),null==e&&(e=this.findOuterTagsContent().content),i=this.currentScope[this.templaterState.loopOpen.tag],l="",null!=i){if("object"==typeof i)for(a=h=0,m=i.length;m>h;a=++h)r=i[a],s=this.calcSubXmlTemplater(t,r),l+=s.content;i===!0&&(s=this.calcSubXmlTemplater(t,this.currentScope),l+=s.content)}else s=this.calcSubXmlTemplater(t,{});if(this.content=this.content.replace(e,l),n=this.calcSubXmlTemplater(this.content),-1!==n.getFullText().indexOf("{"))throw"they shouln't be a { in replaced file: "+n.getFullText()+" (3)";return n},t.prototype.dashLoop=function(t,e){var a,l,n,r,s,i,h,m,o,p,g;for(null==e&&(e=!1),p=this.findOuterTagsContent(),a=p.content,h=p.start,n=p.end,s=this.calcOuterXml(this.content,h,n,t),m=o=0,g=this.templaterState.matches.length;g>=0?g>=o:o>=g;m=g>=0?++o:--o)this.templaterState.charactersAdded[m]-=s.startTag;if(i=s.text,-1===this.content.indexOf(i))throw"couln't find outerXmlText in @content";if(r=i,l=r,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),r=this.replaceTagByValue("",r),l===r)throw"innerXmlText should have changed after deleting the opening tag";if(l=r,this.templaterState.textInsideTag="/"+this.templaterState.loopOpen.tag,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},r=this.replaceTagByValue("",r),l===r)throw"innerXmlText should have changed after deleting the opening tag";return this.forLoop(r,i)},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,n,r,s,i,h;if(h=e.xmlTagNumber,l=e.insideValue,s=null!=e.spacePreserve?e.spacePreserve:!0,n=null!=e.noStartTag?e.noStartTag:!1,r=this.xmlToBeReplaced(n,s,l,h),this.templaterState.matches[h][2]=l,i=this.templaterState.matches[h].offset+this.templaterState.charactersAdded[h],this.templaterState.charactersAdded[h+1]+=r.length-this.templaterState.matches[h][0].length,-1===t.indexOf(this.templaterState.matches[h][0]))throw"content "+this.templaterState.matches[h][0]+" not found in content";if(a=t,t=DocUtils.replaceFirstFrom(t,this.templaterState.matches[h][0],r,i),this.templaterState.matches[h][0]=r,a===t)throw"offset problem0: didnt changed the value (should have changed from "+this.templaterState.matches[this.templaterState.tagStart.numXmlTag][0]+" to "+r;return t},t.prototype.replaceTagByValue=function(t,e){var a,l,n,r,s,i,h,m,o,p,g,c,u,S;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(a=e,this.templaterState.tagEnd.numXmlTag===this.templaterState.tagStart.numXmlTag)l=this.templaterState.matches[this.templaterState.tagStart.numXmlTag][2].replace("{"+this.templaterState.textInsideTag+"}",t),e=this.replaceXmlTag(e,{xmlTagNumber:this.templaterState.tagStart.numXmlTag,insideValue:l,noStartTag:null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].first||null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].last});else if(this.templaterState.tagEnd.numXmlTag>this.templaterState.tagStart.numXmlTag){for(h=/^([^{]*){.*$/,m=this.templaterState.matches[this.templaterState.tagStart.numXmlTag][2].match(h),e=null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].first||null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].last?this.replaceXmlTag(e,{xmlTagNumber:this.templaterState.tagStart.numXmlTag,insideValue:t,noStartTag:null!=this.templaterState.matches[this.templaterState.tagStart.numXmlTag].last}):this.replaceXmlTag(e,{xmlTagNumber:this.templaterState.tagStart.numXmlTag,insideValue:m[1]+t}),r=o=c=this.templaterState.tagStart.numXmlTag+1,u=this.templaterState.tagEnd.numXmlTag;u>=c?u>o:o>u;r=u>=c?++o:--o)this.templaterState.charactersAdded[r+1]=this.templaterState.charactersAdded[r],e=this.replaceXmlTag(e,{xmlTagNumber:r,insideValue:"",spacePreserve:!1});i=/^[^}]*}(.*)$/,l=this.templaterState.matches[this.templaterState.tagEnd.numXmlTag][2].replace(i,"$1"),this.templaterState.charactersAdded[this.templaterState.tagEnd.numXmlTag+1]=this.templaterState.charactersAdded[this.templaterState.tagEnd.numXmlTag],e=this.replaceXmlTag(e,{xmlTagNumber:r,insideValue:l})}for(S=this.templaterState.matches,n=p=0,g=S.length;g>p;n=++p)s=S[n],n>this.templaterState.tagEnd.numXmlTag&&(this.templaterState.charactersAdded[n+1]=this.templaterState.charactersAdded[n]);if(a===e)throw"copycontent=content !!";return e},t.prototype.applyTags=function(){var t,e,a,l,n,r,s,i,h,m,o,p,g,c,u;for(this.templaterState.initialize(),c=this.templaterState.matches,r=i=0,o=c.length;o>i;r=++i)for(l=c[r],e=l[2],n=h=0,p=e.length;p>h;n=++h){for(t=e[n],this.templaterState.currentStep={numXmlTag:r,numCharacter:n},u=this.templaterState.matches,s=m=0,g=u.length;g>m;s=++m)if(a=u[s],r>=s&&this.content[a.offset+this.templaterState.charactersAdded[s]]!==a[0][0])throw"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(),"/"===this.templaterState.textInsideTag[0]&&"/"+this.templaterState.loopOpen.tag===this.templaterState.textInsideTag)return this.replaceLoopTag()}else this.templaterState.inTag===!0&&(this.templaterState.textInsideTag+=t)}return new ImgReplacer(this).findImages().replaceImages(),this},t.prototype.handleRecursiveCase=function(){var t,e,a;return a=function(t){return function(){var e,a,n,r,s;return e=arguments[0],n=4<=arguments.length?l.call(arguments,1,s=arguments.length-2):(s=1,[]),a=arguments[s++],r=arguments[s++],n.unshift(e),n.offset=a,n.first=!0,t.templaterState.matches.unshift(n),t.templaterState.charactersAdded.unshift(0)}}(this),this.content.replace(/^()([^<]+)/,a),e=function(t){return function(){var e,a,n,r,s;return e=arguments[0],n=4<=arguments.length?l.call(arguments,1,s=arguments.length-2):(s=1,[]),a=arguments[s++],r=arguments[s++],n.unshift(e),n.offset=a,n.last=!0,t.templaterState.matches.push(n),t.templaterState.charactersAdded.push(0)}}(this),t="(<"+this.tagXml+"[^>]*>)([^>]+)$",this.content.replace(new RegExp(t),e)},t.prototype.useTag=function(t){var e,a,l,n,r,s;for(l=this.usedTags,s=this.scopePath,e=n=0,r=s.length;r>n;e=++n)a=s[e],null==l[a]&&(l[a]={}),l=l[a];return""!==t?l[t]=!0:void 0},t.prototype.calcIntellegentlyDashElement=function(){return!1},t.prototype.replaceSimpleTag=function(){return this.content=this.replaceTagByValue(this.getValueFromScope(this.templaterState.textInsideTag))},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;if(a=this.toJson(),null!=e&&(a.Tags=e,a.scopePath=a.scopePath.concat(this.templaterState.loopOpen.tag)),l=new this.currentClass(t,a),l.applyTags(),-1!==l.getFullText().indexOf("{"))throw"they shouln't be a { in replaced file: "+l.getFullText()+" (1)";return this.imageId=l.imageId,l},t}(),a.XmlTemplater=t}).call(this);
(function(){var t,n,e,l={}.hasOwnProperty,o=function(t,n){function e(){this.constructor=t}for(var o in n)l.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t};e="undefined"!=typeof global&&null!==global?global:window,n="undefined"!=typeof global&&null!==global?"node":"browser",t=t=function(t){function n(t,e){if(null==t&&(t=""),null==e&&(e={}),n.__super__.constructor.call(this,"",e),this.currentClass=n,this.tagXml="w:t","string"!=typeof t)throw"content must be string!";this.load(t)}var e;return o(n,t),e=new XmlUtil,n.prototype.calcIntellegentlyDashElement=function(){var t,l,o,r,s,a,i,c;for(c=this.findOuterTagsContent(),t=c.content,r=c.start,l=c.end,o=e.getListXmlElements(this.content,r,l-r),a=0,i=o.length;i>a;a++)if(s=o[a],"<w:tc>"===s.tag)return"w:tr";return n.__super__.calcIntellegentlyDashElement.call(this)},n}(XmlTemplater),e.DocXTemplater=t}).call(this);
{
"name": "docxtemplater",
"version": "0.4.2",
"version": "0.4.3",
"author": "Edgar Hipp <hipp.edg@gmail.com>",

@@ -5,0 +5,0 @@ "description": "A docX templater",

@@ -19,2 +19,6 @@ # Docxgen.js #

## Why use a library for this ? ##
docx is a zipped format that contains some xml. If you want to build a simple replace {tag} by value system, it can already become complicated, because the {tag} is internally separated into `<w:t>{</w:t><w:t>tag</w:t><w:t>}</w:t>`. If you want to embed loops to iterate over an array, it becomes a real hassle.
## Syntax ##

@@ -50,9 +54,6 @@

1. **docxgen.js** uses [jszip.js](http://stuk.github.io/jszip/) to zip and unzip the docx files. Jszip uses:
1. **docxgen.js** uses [jszip.js](http://stuk.github.io/jszip/) to zip and unzip the docx files
- base64.js
- jszip.js
2. Optionally, if you want to be able to name the output files, you can use **Downloadify.js**, which is required to use method download. Be informed that it uses flash, this is why the method is not recommended. This method is howewer useful because a lot of browsers are limited for the download size with the Data-URI method. **Update**: I will probably implement in the future a way to use the FileSaver API, with [FileSaverJS](http://eligrey.com/demos/FileSaver.js/)
2. Optionally, if you want to be able to name the output files, you can use **Downloadify.js**, which is required to use method download. Be informed that it uses flash, this is why the method is not recommended. This method is howewer useful because a lot of browsers are limited for the download size with the Data-URI method.
3. Optionnaly, if you want to replace images by images situated at a particular URL, you can use QR codes. For example If you store an image at http://website.com/image.png , you should encode the URL in QR-Code format. ![Qr Code Sample](http://qrfree.kaywa.com/?l=1&s=8&d=http%3A%2F%2Fwebsite.com%2Fimage.png "Qrcode Sample to http://website.com/image.png"). You can even use bracket tags in images. http://website.com/image.png?color={color} will take the *Tags[color]* variable to make a dynamic URL. For this too work, you will need [jsqrcode](http://github.com/edi9999/jsqrcode "jsqrcode repositoty forked") and include the following files, in this order:

@@ -357,2 +358,3 @@

- jsZip
- [ ] output with FileSaver.js to name your file
- [x] Change signature of loadDoc function

@@ -359,0 +361,0 @@

@@ -1,1 +0,1 @@

(function(){var e,t,o,a,r,n;for(a="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",a.docX={},a.docXData={},"node"===e&&(a.DocxGen=require(__dirname+"/../../js/docxgen.js")),DocUtils.pathConfig={node:"../../examples/",browser:"../examples/"},t=["imageExample.docx","tagExample.docx","tagExampleExpected.docx","tagLoopExample.docx","tagExampleExpected.docx","tagLoopExampleImageExpected.docx","tagProduitLoop.docx","tagDashLoop.docx","tagDashLoopList.docx","tagDashLoopTable.docx","tagDashLoop.docx","qrCodeExample.docx","qrCodeExampleExpected.docx","qrCodeTaggingExample.docx","qrCodeTaggingExampleExpected.docx","qrCodeTaggingLoopExample.docx","qrCodeTaggingLoopExampleExpected.docx","tagIntelligentLoopTableExpected.docx"],r=0,n=t.length;n>r;r++)o=t[r],a.docX[o]=(new DocxGen).loadFromFile(o);DocUtils.loadDoc("tagIntelligentLoopTable.docx",{intelligentTagging:!0}),DocUtils.loadDoc("image.png",{docx:!1}),DocUtils.loadDoc("bootstrap_logo.png",{docx:!1}),DocUtils.loadDoc("BMW_logo.png",{docx:!1}),DocUtils.loadDoc("Firefox_logo.png",{docx:!1}),DocUtils.loadDoc("Volkswagen_logo.png",{docx:!1}),DocUtils.loadDoc("qrcodeTest.zip",{docx:!1}),describe("DocxGenBasis",function(){return it("should be defined",function(){return expect(DocxGen).not.toBe(void 0)}),it("should construct",function(){var e;return e=new DocxGen,expect(e).not.toBe(void 0)})}),describe("DocxGenLoading",function(){return describe("ajax done correctly",function(){return it("doc and img Data should have the expected length",function(){return expect(docX["imageExample.docx"].loadedContent.length).toEqual(729580),expect(docXData["image.png"].length).toEqual(18062)}),it("should have the right number of files (the docx unzipped)",function(){return docX["imageExample.docx"]=new DocxGen(docX["imageExample.docx"].loadedContent),expect(DocUtils.sizeOfObject(docX["imageExample.docx"].zip.files)).toEqual(22)})}),describe("basic loading",function(){return it("should load file imageExample.docx",function(){return expect(typeof docX["imageExample.docx"]).toBe("object")})}),describe("content_loading",function(){return it("should load the right content for the footer",function(){var e;return e=docX["imageExample.docx"].getFullText("word/footer1.xml"),expect(e.length).not.toBe(0),expect(e).toBe("{last_name}{first_name}{phone}")}),it("should load the right content for the document",function(){var e;return e=docX["imageExample.docx"].getFullText(),expect(e).toBe("")})}),describe("image loading",function(){return it("should find one image (and not more than 1)",function(){return expect(docX["imageExample.docx"].getImageList().length).toEqual(1)}),it("should find the image named with the good name",function(){return expect(docX["imageExample.docx"].getImageList()[0].path).toEqual("word/media/image1.jpeg")}),it("should change the image with another one",function(){var e,t;return t=docX["imageExample.docx"].zip.files["word/media/image1.jpeg"].asText(),docX["imageExample.docx"].setImage("word/media/image1.jpeg",docXData["image.png"]),e=docX["imageExample.docx"].zip.files["word/media/image1.jpeg"].asText(),expect(t).not.toEqual(e),expect(docXData["image.png"]).toEqual(e)})}),describe("output and input",function(){return it("should be the same",function(){var e,t;return e=new DocxGen(a.docX["tagExample.docx"].loadedContent),t=e.output(!1),expect(t.length).toEqual(91348),expect(t.substr(0,50)).toEqual("UEsDBAoAAAAAAAAAIQAMTxYSlgcAAJYHAAATAAAAW0NvbnRlbn")})})}),describe("DocxGenTemplating",function(){return describe("text templating",function(){return it("should change values with template vars",function(){var e;return e={first_name:"Hipp",last_name:"Edgar",phone:"0652455478",description:"New Website"},docX["tagExample.docx"].setTags(e),docX["tagExample.docx"].applyTags(),expect(docX["tagExample.docx"].getFullText()).toEqual("Edgar Hipp"),expect(docX["tagExample.docx"].getFullText("word/header1.xml")).toEqual("Edgar Hipp0652455478New Website"),expect(docX["tagExample.docx"].getFullText("word/footer1.xml")).toEqual("EdgarHipp0652455478")}),it("should export the good file",function(){var e,t;t=[];for(e in docX["tagExample.docx"].zip.files)expect(docX["tagExample.docx"].zip.files[e].options.date).not.toBe(docX["tagExampleExpected.docx"].zip.files[e].options.date),expect(docX["tagExample.docx"].zip.files[e].name).toBe(docX["tagExampleExpected.docx"].zip.files[e].name),expect(docX["tagExample.docx"].zip.files[e].options.dir).toBe(docX["tagExampleExpected.docx"].zip.files[e].options.dir),t.push(expect(docX["tagExample.docx"].zip.files[e].asText()).toBe(docX["tagExampleExpected.docx"].zip.files[e].asText()));return t})})}),describe("DocxGenTemplatingForLoop",function(){return describe("textLoop templating",function(){return it("should replace all the tags",function(){var e;return e={nom:"Hipp",prenom:"Edgar",telephone:"0652455478",description:"New Website",offre:[{titre:"titre1",prix:"1250"},{titre:"titre2",prix:"2000"},{titre:"titre3",prix:"1400"}]},docX["tagLoopExample.docx"].setTags(e),docX["tagLoopExample.docx"].applyTags(),expect(docX["tagLoopExample.docx"].getFullText()).toEqual("Votre proposition commercialePrix: 1250Titre titre1Prix: 2000Titre titre2Prix: 1400Titre titre3HippEdgar")}),it("should work with loops inside loops",function(){var e,t,o;return e={products:[{title:"Microsoft",name:"DOS",reference:"Win7",avantages:[{title:"Everyone uses it",proof:[{reason:"it is quite cheap"},{reason:"it is quit simple"},{reason:"it works on a lot of different Hardware"}]}]},{title:"Linux",name:"Ubuntu",reference:"Ubuntu10",avantages:[{title:"It's very powerful",proof:[{reason:"the terminal is your friend"},{reason:"Hello world"},{reason:"it's free"}]}]},{title:"Apple",name:"Mac",reference:"OSX",avantages:[{title:"It's very easy",proof:[{reason:"you can do a lot just with the mouse"},{reason:"It's nicely designed"}]}]}]},docX["tagProduitLoop.docx"].setTags(e),docX["tagProduitLoop.docx"].applyTags(),o=docX["tagProduitLoop.docx"].getFullText(),t="MicrosoftProduct name : DOSProduct reference : Win7Everyone uses itProof that it works nicely : It works because it is quite cheap It works because it is quit simple It works because it works on a lot of different HardwareLinuxProduct name : UbuntuProduct reference : Ubuntu10It's very powerfulProof that it works nicely : It works because the terminal is your friend It works because Hello world It works because it's freeAppleProduct name : MacProduct reference : OSXIt's very easyProof that it works nicely : It works because you can do a lot just with the mouse It works because It's nicely designed",expect(o.length).toEqual(t.length),expect(o).toEqual(t)})})}),describe("Xml Util",function(){var e;return e=new XmlUtil,it("should compute the scope between 2 <w:t>",function(){var t;return t=e.getListXmlElements('undefined</w:t></w:r></w:p><w:p w:rsidP="008A4B3C" w:rsidR="007929C1" w:rsidRDefault="007929C1" w:rsidRPr="008A4B3C"><w:pPr><w:pStyle w:val="Sous-titre"/></w:pPr><w:r w:rsidRPr="008A4B3C"><w:t xml:space="preserve">Audit réalisé le '),expect(t).toEqual([{tag:"</w:t>",offset:9},{tag:"</w:r>",offset:15},{tag:"</w:p>",offset:21},{tag:"<w:p>",offset:27},{tag:"<w:r>",offset:162},{tag:"<w:t>",offset:188}])}),it("should compute the scope between 2 <w:t> in an Array",function(){var t;return t=e.getListXmlElements('urs</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="4140"/></w:tcPr><w:p w:rsidP="00CE524B" w:rsidR="00CE524B" w:rsidRDefault="00CE524B"><w:pPr><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr><w:t>Sur exté'),expect(t).toEqual([{tag:"</w:t>",offset:3},{tag:"</w:r>",offset:9},{tag:"</w:p>",offset:15},{tag:"</w:tc>",offset:21},{tag:"<w:tc>",offset:28},{tag:"<w:p>",offset:83},{tag:"<w:r>",offset:268},{tag:"<w:t>",offset:374}])}),it("should compute the scope between a w:t in an array and the other outside",function(){var t;return t=e.getListXmlElements('defined </w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00137C91" w:rsidRDefault="00137C91"><w:r w:rsidRPr="00B12C70"><w:rPr><w:bCs/></w:rPr><w:t>Coût ressources '),expect(t).toEqual([{tag:"</w:t>",offset:8},{tag:"</w:r>",offset:14},{tag:"</w:p>",offset:20},{tag:"</w:tc>",offset:26},{tag:"</w:tr>",offset:33},{tag:"</w:tbl>",offset:40},{tag:"<w:p>",offset:188},{tag:"<w:r>",offset:257},{tag:"<w:t>",offset:306}])})}),describe("scope diff calculation",function(){var e;return e=new XmlUtil,it("should compute the scopeDiff between 2 <w:t>",function(){var t;return t=e.getListDifferenceXmlElements('undefined</w:t></w:r></w:p><w:p w:rsidP="008A4B3C" w:rsidR="007929C1" w:rsidRDefault="007929C1" w:rsidRPr="008A4B3C"><w:pPr><w:pStyle w:val="Sous-titre"/></w:pPr><w:r w:rsidRPr="008A4B3C"><w:t xml:space="preserve">Audit réalisé le '),expect(t).toEqual([])}),it("should compute the scopeDiff between 2 <w:t> in an Array",function(){var t;return t=e.getListDifferenceXmlElements('urs</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="4140"/></w:tcPr><w:p w:rsidP="00CE524B" w:rsidR="00CE524B" w:rsidRDefault="00CE524B"><w:pPr><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr><w:t>Sur exté'),expect(t).toEqual([])}),it("should compute the scopeDiff between a w:t in an array and the other outside",function(){var t;return t=e.getListDifferenceXmlElements('defined </w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00137C91" w:rsidRDefault="00137C91"><w:r w:rsidRPr="00B12C70"><w:rPr><w:bCs/></w:rPr><w:t>Coût ressources '),expect(t).toEqual([{tag:"</w:tc>",offset:26},{tag:"</w:tr>",offset:33},{tag:"</w:tbl>",offset:40}])})}),describe("scope inner text",function(){return it("should find the scope",function(){var e,t,o;return o=new DocXTemplater,docX["tagProduitLoop.docx"].load(docX["tagProduitLoop.docx"].loadedContent),t=o.calcOuterXml(docX["tagProduitLoop.docx"].zip.files["word/document.xml"].asText(),1195,1245,"w:p"),e={text:'<w:p w:rsidR="00923B77" w:rsidRDefault="00923B77"><w:r><w:t>{#</w:t></w:r><w:r w:rsidR="00713414"><w:t>products</w:t></w:r><w:r><w:t>}</w:t></w:r></w:p>',startTag:1134,endTag:1286},expect(t.endTag).toEqual(e.endTag),expect(t.startTag).toEqual(e.startTag),expect(t.text.length).toEqual(e.text.length),expect(t.text).toEqual(e.text)})}),describe("Dash Loop Testing",function(){return it("dash loop ok on simple table -> w:tr",function(){var e,t,o;return e={os:[{type:"linux",price:"0",reference:"Ubuntu10"},{type:"DOS",price:"500",reference:"Win7"},{type:"apple",price:"1200",reference:"MACOSX"}]},docX["tagDashLoop.docx"].setTags(e),docX["tagDashLoop.docx"].applyTags(),t="linux0Ubuntu10DOS500Win7apple1200MACOSX",o=docX["tagDashLoop.docx"].getFullText(),expect(o).toBe(t)}),it("dash loop ok on simple table -> w:table",function(){var e,t,o;return e={os:[{type:"linux",price:"0",reference:"Ubuntu10"},{type:"DOS",price:"500",reference:"Win7"},{type:"apple",price:"1200",reference:"MACOSX"}]},docX["tagDashLoopTable.docx"].setTags(e),docX["tagDashLoopTable.docx"].applyTags(),t="linux0Ubuntu10DOS500Win7apple1200MACOSX",o=docX["tagDashLoopTable.docx"].getFullText(),expect(o).toBe(t)}),it("dash loop ok on simple list -> w:p",function(){var e,t,o;return e={os:[{type:"linux",price:"0",reference:"Ubuntu10"},{type:"DOS",price:"500",reference:"Win7"},{type:"apple",price:"1200",reference:"MACOSX"}]},docX["tagDashLoopList.docx"].setTags(e),docX["tagDashLoopList.docx"].applyTags(),t="linux 0 Ubuntu10 DOS 500 Win7 apple 1200 MACOSX ",o=docX["tagDashLoopList.docx"].getFullText(),expect(o).toBe(t)})}),describe("Intelligent Loop Tagging",function(){return it("should work with tables",function(){var e,t,o,a,r;e={clients:[{first_name:"John",last_name:"Doe",phone:"+33647874513"},{first_name:"Jane",last_name:"Doe",phone:"+33454540124"},{first_name:"Phil",last_name:"Kiel",phone:"+44578451245"},{first_name:"Dave",last_name:"Sto",phone:"+44548787984"}]},docX["tagIntelligentLoopTable.docx"].setTags(e),docX["tagIntelligentLoopTable.docx"].applyTags(),t="JohnDoe+33647874513JaneDoe+33454540124PhilKiel+44578451245DaveSto+44548787984",a=docX["tagIntelligentLoopTableExpected.docx"].getFullText(),expect(a).toBe(t),r=[];for(o in docX["tagIntelligentLoopTable.docx"].zip.files)expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].asText()).toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].asText()),expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].name).toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].name),expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].options.dir).toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].options.dir),r.push(expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].options.date).not.toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].options.date));return r})}),describe("getTags",function(){return it("should work with simple document",function(){var e;return docX["tagExample.docx"]=new DocxGen(docX["tagExample.docx"].loadedContent,{},!1),e=docX["tagExample.docx"].getTags(),expect(e).toEqual([{fileName:"word/document.xml",vars:{last_name:!0,first_name:!0}},{fileName:"word/footer1.xml",vars:{last_name:!0,first_name:!0,phone:!0}},{fileName:"word/header1.xml",vars:{last_name:!0,first_name:!0,phone:!0,description:!0}}])}),it("should work with loop document",function(){var e;return docX["tagLoopExample.docx"]=new DocxGen(docX["tagLoopExample.docx"].loadedContent,{},!1),e=docX["tagLoopExample.docx"].getTags(),expect(e).toEqual([{fileName:"word/document.xml",vars:{offre:{prix:!0,titre:!0},nom:!0,prenom:!0}},{fileName:"word/footer1.xml",vars:{nom:!0,prenom:!0,telephone:!0}},{fileName:"word/header1.xml",vars:{nom:!0,prenom:!0}}])}),it("should work if there are no Tags",function(){var e;return docX["qrCodeExample.docx"]=new DocxGen(docX["qrCodeExample.docx"].loadedContent,{},!1),e=docX["qrCodeExample.docx"].getTags(),expect(e).toEqual([])})}),describe("xmlTemplater",function(){return it("should work with simpleContent",function(){var e,t,o;return e="<w:t>Hello {name}</w:t>",t={name:"Edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar")}),it("should work with non w:t content",function(){var e,t,o;return e="{image}.png",t={image:"edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.content).toBe("edgar.png")}),it("should work with tag in two elements",function(){var e,t,o;return e="<w:t>Hello {</w:t><w:t>name}</w:t>",t={name:"Edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar")}),it("should work with simple Loop",function(){var e,t,o;return e="<w:t>Hello {#names}{name},{/names}</w:t>",t={names:[{name:"Edgar"},{name:"Mary"},{name:"John"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar,Mary,John,")}),it("should work with dash Loop",function(){var e,t,o;return e="<w:p><w:t>Hello {-w:p names}{name},{/names}</w:t></w:p>",t={names:[{name:"Edgar"},{name:"Mary"},{name:"John"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar,Hello Mary,Hello John,")}),it("should work with loop and innerContent",function(){var e,t,o;return e='</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:pStyle w:val="Titre1"/></w:pPr><w:r><w:t>{title</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRPr="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:r><w:t>Proof that it works nicely :</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00923B77" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{#pr</w:t></w:r><w:r w:rsidR="00713414"><w:t>oof</w:t></w:r><w:r><w:t xml:space="preserve">} </w:t></w:r><w:r w:rsidR="00713414"><w:t>It works because</w:t></w:r><w:r><w:t xml:space="preserve"> {</w:t></w:r><w:r w:rsidR="006F26AC"><w:t>reason</w:t></w:r><w:r><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{/proof</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00FD04E9" w:rsidRDefault="00923B77"><w:r><w:t>',t={title:"Everyone uses it",proof:[{reason:"it is quite cheap"},{reason:"it is quit simple"},{reason:"it works on a lot of different Hardware"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Everyone uses itProof that it works nicely : It works because it is quite cheap It works because it is quit simple It works because it works on a lot of different Hardware")}),it("should work with loop and innerContent (with last)",function(){var e,t,o;return e='</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:pStyle w:val="Titre1"/></w:pPr><w:r><w:t>{title</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRPr="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:r><w:t>Proof that it works nicely :</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00923B77" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{#pr</w:t></w:r><w:r w:rsidR="00713414"><w:t>oof</w:t></w:r><w:r><w:t xml:space="preserve">} </w:t></w:r><w:r w:rsidR="00713414"><w:t>It works because</w:t></w:r><w:r><w:t xml:space="preserve"> {</w:t></w:r><w:r w:rsidR="006F26AC"><w:t>reason</w:t></w:r><w:r><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{/proof</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00FD04E9" w:rsidRDefault="00923B77"><w:r><w:t> ',t={title:"Everyone uses it",proof:[{reason:"it is quite cheap"},{reason:"it is quit simple"},{reason:"it works on a lot of different Hardware"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Everyone uses itProof that it works nicely : It works because it is quite cheap It works because it is quit simple It works because it works on a lot of different Hardware")}),it("should work with not w:t tag (if the for loop is like {#forloop} text {/forloop}) ",function(){var e,t,o;return e="Hello {#names}{name},{/names}",t={names:[{name:"Edgar"},{name:"Mary"},{name:"John"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.content).toBe("Hello Edgar,Mary,John,")})}),describe("DocxQrCode module",function(){return describe("Calculate simple Docx",function(){var t,o,a,r;return t=null,o=null,r=null,a=null,beforeEach(function(){var e;return r=new JSZip(docXData["qrcodeTest.zip"]),e=new DocxGen,a=new DocXTemplater("",{DocxGen:e,Tags:{Tag:"tagValue"}})}),it("should do it's thing with JSZip.base64",function(){var e,t;return t=r.files["blabla.png"].asText(),e=JSZip.base64.encode(t),expect(e.length).toBe(624),expect(e.substr(0,50)).toBe("kcNChoKAAAADUlIRFIAAAAAIAAABOAAAAAZ0Uk5TAEAA07AAAE"),expect(e).toBe("kcNChoKAAAADUlIRFIAAAAAIAAABOAAAAAZ0Uk5TAEAA07AAAEURBVHdQkUQ/RQDIg7ON9jXTF4flff17B0EYJEDoJQidBDPcfG30PMH+N1VJTkQOglCJ0Icn0rPTxJEDoJQidB0Egj89PenQhBCVg2Rk9c5RA6CUInQhBOPm8gdBCRA6CUInQfN3dBB0EYJEDoJQidheKSkkC0EYJEDoJs9P141dBB0EYJEDoJQidhm2fVzZlnQhBCRuRTcye633fQSkQOglCJ0IXX6KdHB0WEDoJQidB0Ec/dX/teYY/Tyc6CUInQhBCcv/Xic6CUInQhBCm/f+FP0EYJEDoJQidB9Fnvc1hBCRA6CWve0IQSkYWk3HuPcB0EYJEDoJQidBUcez9HP3fPE0EYJEDoJQidhOEc/p53vf6/PcB0EYJEDoJQidBHfhd8VPWfP59dBJEDoJQidBsH31kpVfkQOglCJ0I0fl1axBA6CUInQhBjn/mHdidB0EJwHPOXVPiAhBCRA6Cf3Xc/8n0EJ0IQSlYNkzedHd+Nfx9xHQSkQOglCJ08+H9QSRA6CUInQh+pnQhBCd/fUcMRdCJ0IQSnAfHhBCRA6CUIn0wsvkAAAAASUVORA")}),it("should work with Blablalalabioeajbiojbepbroji",function(){return runs(function(){var n,i,l,c,d,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["blabla.png"].asBinary(),a,"custom.png",6),s.decode(t.test)):(n=JSZip.base64.encode(r.files["blabla.png"].asBinary()),i=new Buffer(n,"base64"),d=new PNG(i),c=function(e){return d.decoded=e,s=new DocxQrCode(d,a,"custom.png",6),s.decode(t.test)},l=d.decode(c))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("Blablalalabioeajbiojbepbroji"),expect(t.test.mostRecentCall.args[1]).toEqual("custom.png"),expect(t.test.mostRecentCall.args[2]).toEqual(6)})}),it("should work with long texts",function(){return runs(function(){var n,i,l,c,d,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["custom.png"].asBinary(),a,"custom.png",6),s.decode(t.test)):(n=JSZip.base64.encode(r.files["custom.png"].asBinary()),i=new Buffer(n,"base64"),d=new PNG(i),c=function(e){return d.decoded=e,s=new DocxQrCode(d,a,"custom.png",6),s.decode(t.test)},l=d.decode(c))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("Some custom text"),expect(t.test.mostRecentCall.args[1]).toEqual("custom.png"),expect(t.test.mostRecentCall.args[2]).toEqual(6)})}),it("should work with basic image",function(){return runs(function(){var n,i,l,c,d,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["qrcodeTest.png"].asBinary(),a,"qrcodeTest.png",4),s.decode(t.test)):(n=JSZip.base64.encode(r.files["qrcodeTest.png"].asBinary()),i=new Buffer(n,"base64"),d=new PNG(i),c=function(e){return d.decoded=e,s=new DocxQrCode(d,a,"qrcodeTest.png",4),s.decode(t.test)},l=d.decode(c))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("test"),expect(t.test.mostRecentCall.args[1]).toEqual("qrcodeTest.png"),expect(t.test.mostRecentCall.args[2]).toEqual(4)})}),it("should work with image with {tags}",function(){return runs(function(){var n,i,l,c,d,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["qrcodetag.png"].asBinary(),a,"tag.png",2),s.decode(t.test)):(n=JSZip.base64.encode(r.files["qrcodetag.png"].asBinary()),i=new Buffer(n,"base64"),d=new PNG(i),c=function(e){return d.decoded=e,s=new DocxQrCode(d,a,"tag.png",2),s.decode(t.test)},l=d.decode(c))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("tagValue"),expect(t.test.mostRecentCall.args[1]).toEqual("tag.png"),expect(t.test.mostRecentCall.args[2]).toEqual(2)})})})}),describe("image Loop Replacing",function(){return describe("rels",function(){return it("should load",function(){return expect(docX["imageExample.docx"].imgManager.loadImageRels().imageRels).toEqual([]),expect(docX["imageExample.docx"].imgManager.maxRid).toEqual(10)}),it("should add",function(){var e,t,o,a,r,n,i;return a=docX["imageExample.docx"].zip.files["word/_rels/document.xml.rels"].asText(),expect(docX["imageExample.docx"].imgManager.addImageRels("image1.png",docXData["bootstrap_logo.png"])).toBe(11),expect(docX["imageExample.docx"].zip.files["word/_rels/document.xml.rels"].asText()).not.toBe(a),n=docX["imageExample.docx"].zip.files["word/_rels/document.xml.rels"].asText(),e=docX["imageExample.docx"].zip.files["[Content_Types].xml"].asText(),i=DocUtils.Str2xml(n),t=DocUtils.Str2xml(e),r=i.getElementsByTagName("Relationship"),o=t.getElementsByTagName("Default"),expect(r.length).toEqual(11),expect(o.length).toBe(4)})})}),describe("loop forTagging images",function(){return it("should work with a simple loop file",function(){var t,o,a,r,n,i,l,c,d;docX["tagLoopExample.docx"]=new DocxGen(docX["tagLoopExample.docx"].loadedContent),c={nom:"Hipp",prenom:"Edgar",telephone:"0652455478",description:"New Website",offre:[{titre:"titre1",prix:"1250",img:[{data:docXData["Volkswagen_logo.png"],name:"vw_logo.png"}]},{titre:"titre2",prix:"2000",img:[{data:docXData["BMW_logo.png"],name:"bmw_logo.png"}]},{titre:"titre3",prix:"1400",img:[{data:docXData["Firefox_logo.png"],name:"firefox_logo.png"}]}]},docX["tagLoopExample.docx"].setTags(c),docX["tagLoopExample.docx"].applyTags();for(r in docX["tagLoopExample.docx"].zip.files)expect(docX["tagLoopExample.docx"].zip.files[r].options.date).not.toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].options.date),expect(docX["tagLoopExample.docx"].zip.files[r].name).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].name),expect(docX["tagLoopExample.docx"].zip.files[r].options.dir).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].options.dir),"word/_rels/document.xml.rels"!==r&&"[Content_Types].xml"!==r&&("browser"===e||"word/document.xml"!==r)&&(("function"==typeof(d=docX["tagLoopExample.docx"].zip.files[r].asText())?d(0):void 0)&&expect(docX["tagLoopExample.docx"].zip.files[r].asText().length).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].asText().length),expect(docX["tagLoopExample.docx"].zip.files[r].asText()).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].asText()));return i=docX["tagLoopExample.docx"].zip.files["word/_rels/document.xml.rels"].asText(),t=docX["tagLoopExample.docx"].zip.files["[Content_Types].xml"].asText(),l=DocUtils.Str2xml(i),o=DocUtils.Str2xml(t),n=l.getElementsByTagName("Relationship"),a=o.getElementsByTagName("Default"),expect(n.length).toEqual(16),expect(a.length).toBe(3)})}),describe("qr code testing",function(){return it("should work with local QRCODE without tags",function(){var e;return docX["qrCodeExample.docx"]=new DocxGen(docX["qrCodeExample.docx"].loadedContent,{},!1,!0),e=function(){return 1},docX["qrCodeExample.docx"].applyTags({},e),waitsFor(function(){return null!=docX["qrCodeExample.docx"].ready}),runs(function(){var e,t;expect(null!=docX["qrCodeExample.docx"].zip.files["word/media/Copie_0.png"]).toBeTruthy(),t=[];for(e in docX["qrCodeExample.docx"].zip.files)expect(docX["qrCodeExample.docx"].zip.files[e].options.date).not.toBe(docX["qrCodeExampleExpected.docx"].zip.files[e].options.date),expect(docX["qrCodeExample.docx"].zip.files[e].name).toBe(docX["qrCodeExampleExpected.docx"].zip.files[e].name),t.push(expect(docX["qrCodeExample.docx"].zip.files[e].options.dir).toBe(docX["qrCodeExampleExpected.docx"].zip.files[e].options.dir));return t})}),it("should work with local QRCODE with {tags}",function(){var e;return docX["qrCodeTaggingExample.docx"]=new DocxGen(docX["qrCodeTaggingExample.docx"].loadedContent,{image:"Firefox_logo"},!1,!0),e=function(){return 1},docX["qrCodeTaggingExample.docx"].applyTags({image:"Firefox_logo"},e),waitsFor(function(){return null!=docX["qrCodeTaggingExample.docx"].ready}),runs(function(){var e,t;expect(null!=docX["qrCodeTaggingExample.docx"].zip.files["word/media/Copie_0.png"]).toBeTruthy(),t=[];for(e in docX["qrCodeTaggingExample.docx"].zip.files)expect(docX["qrCodeTaggingExample.docx"].zip.files[e].options.date).not.toBe(docX["qrCodeTaggingExampleExpected.docx"].zip.files[e].options.date),expect(docX["qrCodeTaggingExample.docx"].zip.files[e].name).toBe(docX["qrCodeTaggingExampleExpected.docx"].zip.files[e].name),t.push(expect(docX["qrCodeTaggingExample.docx"].zip.files[e].options.dir).toBe(docX["qrCodeTaggingExampleExpected.docx"].zip.files[e].options.dir));return t})}),it("should work with loop QRCODE with {tags}",function(){var e;return docX["qrCodeTaggingLoopExample.docx"]=new DocxGen(docX["qrCodeTaggingLoopExample.docx"].loadedContent,{},!1,!0),e=function(){return 1},docX["qrCodeTaggingLoopExample.docx"].applyTags({images:[{image:"Firefox_logo"},{image:"image"}]},e),docX["qrCodeTaggingLoopExample.docx"],waitsFor(function(){return null!=docX["qrCodeTaggingLoopExample.docx"].ready}),runs(function(){var e,t;expect(null!=docX["qrCodeTaggingLoopExample.docx"].zip.files["word/media/Copie_0.png"]).toBeTruthy(),expect(null!=docX["qrCodeTaggingLoopExample.docx"].zip.files["word/media/Copie_1.png"]).toBeTruthy(),expect(null!=docX["qrCodeTaggingLoopExample.docx"].zip.files["word/media/Copie_2.png"]).toBeFalsy(),t=[];for(e in docX["qrCodeTaggingLoopExample.docx"].zip.files)expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].options.date).not.toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].options.date),expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].name).toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].name),t.push(expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].options.dir).toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].options.dir));return t})})})}).call(this);
(function(){var e,t,o,a,r,n;for(a="undefined"!=typeof global&&null!==global?global:window,e="undefined"!=typeof global&&null!==global?"node":"browser",a.docX={},a.docXData={},"node"===e&&(a.DocxGen=require(__dirname+"/../../js/docxgen.js")),DocUtils.pathConfig={node:"../../examples/",browser:"../examples/"},t=["imageExample.docx","tagExample.docx","tagExampleExpected.docx","tagLoopExample.docx","tagExampleExpected.docx","tagLoopExampleImageExpected.docx","tagProduitLoop.docx","tagDashLoop.docx","tagDashLoopList.docx","tagDashLoopTable.docx","tagDashLoop.docx","qrCodeExample.docx","qrCodeExampleExpected.docx","qrCodeTaggingExample.docx","qrCodeTaggingExampleExpected.docx","qrCodeTaggingLoopExample.docx","qrCodeTaggingLoopExampleExpected.docx","tagIntelligentLoopTableExpected.docx"],r=0,n=t.length;n>r;r++)o=t[r],a.docX[o]=(new DocxGen).loadFromFile(o);DocUtils.loadDoc("tagIntelligentLoopTable.docx",{intelligentTagging:!0}),DocUtils.loadDoc("image.png",{docx:!1}),DocUtils.loadDoc("bootstrap_logo.png",{docx:!1}),DocUtils.loadDoc("BMW_logo.png",{docx:!1}),DocUtils.loadDoc("Firefox_logo.png",{docx:!1}),DocUtils.loadDoc("Volkswagen_logo.png",{docx:!1}),DocUtils.loadDoc("qrcodeTest.zip",{docx:!1}),describe("DocxGenBasis",function(){return it("should be defined",function(){return expect(DocxGen).not.toBe(void 0)}),it("should construct",function(){var e;return e=new DocxGen,expect(e).not.toBe(void 0)})}),describe("DocxGenLoading",function(){return describe("ajax done correctly",function(){return it("doc and img Data should have the expected length",function(){return expect(docX["imageExample.docx"].loadedContent.length).toEqual(729580),expect(docXData["image.png"].length).toEqual(18062)}),it("should have the right number of files (the docx unzipped)",function(){return docX["imageExample.docx"]=new DocxGen(docX["imageExample.docx"].loadedContent),expect(DocUtils.sizeOfObject(docX["imageExample.docx"].zip.files)).toEqual(22)})}),describe("basic loading",function(){return it("should load file imageExample.docx",function(){return expect(typeof docX["imageExample.docx"]).toBe("object")})}),describe("content_loading",function(){return it("should load the right content for the footer",function(){var e;return e=docX["imageExample.docx"].getFullText("word/footer1.xml"),expect(e.length).not.toBe(0),expect(e).toBe("{last_name}{first_name}{phone}")}),it("should load the right content for the document",function(){var e;return e=docX["imageExample.docx"].getFullText(),expect(e).toBe("")})}),describe("image loading",function(){return it("should find one image (and not more than 1)",function(){return expect(docX["imageExample.docx"].getImageList().length).toEqual(1)}),it("should find the image named with the good name",function(){return expect(docX["imageExample.docx"].getImageList()[0].path).toEqual("word/media/image1.jpeg")}),it("should change the image with another one",function(){var e,t;return t=docX["imageExample.docx"].zip.files["word/media/image1.jpeg"].asText(),docX["imageExample.docx"].setImage("word/media/image1.jpeg",docXData["image.png"],{binary:!1}),e=docX["imageExample.docx"].zip.files["word/media/image1.jpeg"].asText(),expect(t).not.toEqual(e),expect(docXData["image.png"]).toEqual(e)})}),describe("output and input",function(){return it("should be the same",function(){var e,t;return e=new DocxGen(a.docX["tagExample.docx"].loadedContent),t=e.output(!1),expect(t.length).toEqual(91348),expect(t.substr(0,50)).toEqual("UEsDBAoAAAAAAAAAIQAMTxYSlgcAAJYHAAATAAAAW0NvbnRlbn")})})}),describe("DocxGenTemplating",function(){return describe("text templating",function(){return it("should change values with template vars",function(){var e;return e={first_name:"Hipp",last_name:"Edgar",phone:"0652455478",description:"New Website"},docX["tagExample.docx"].setTags(e),docX["tagExample.docx"].applyTags(),expect(docX["tagExample.docx"].getFullText()).toEqual("Edgar Hipp"),expect(docX["tagExample.docx"].getFullText("word/header1.xml")).toEqual("Edgar Hipp0652455478New Website"),expect(docX["tagExample.docx"].getFullText("word/footer1.xml")).toEqual("EdgarHipp0652455478")}),it("should export the good file",function(){var e,t;t=[];for(e in docX["tagExample.docx"].zip.files)expect(docX["tagExample.docx"].zip.files[e].options.date).not.toBe(docX["tagExampleExpected.docx"].zip.files[e].options.date),expect(docX["tagExample.docx"].zip.files[e].name).toBe(docX["tagExampleExpected.docx"].zip.files[e].name),expect(docX["tagExample.docx"].zip.files[e].options.dir).toBe(docX["tagExampleExpected.docx"].zip.files[e].options.dir),t.push(expect(docX["tagExample.docx"].zip.files[e].asText()).toBe(docX["tagExampleExpected.docx"].zip.files[e].asText()));return t})})}),describe("DocxGenTemplatingForLoop",function(){return describe("textLoop templating",function(){return it("should replace all the tags",function(){var e;return e={nom:"Hipp",prenom:"Edgar",telephone:"0652455478",description:"New Website",offre:[{titre:"titre1",prix:"1250"},{titre:"titre2",prix:"2000"},{titre:"titre3",prix:"1400"}]},docX["tagLoopExample.docx"].setTags(e),docX["tagLoopExample.docx"].applyTags(),expect(docX["tagLoopExample.docx"].getFullText()).toEqual("Votre proposition commercialePrix: 1250Titre titre1Prix: 2000Titre titre2Prix: 1400Titre titre3HippEdgar")}),it("should work with loops inside loops",function(){var e,t,o;return e={products:[{title:"Microsoft",name:"DOS",reference:"Win7",avantages:[{title:"Everyone uses it",proof:[{reason:"it is quite cheap"},{reason:"it is quit simple"},{reason:"it works on a lot of different Hardware"}]}]},{title:"Linux",name:"Ubuntu",reference:"Ubuntu10",avantages:[{title:"It's very powerful",proof:[{reason:"the terminal is your friend"},{reason:"Hello world"},{reason:"it's free"}]}]},{title:"Apple",name:"Mac",reference:"OSX",avantages:[{title:"It's very easy",proof:[{reason:"you can do a lot just with the mouse"},{reason:"It's nicely designed"}]}]}]},docX["tagProduitLoop.docx"].setTags(e),docX["tagProduitLoop.docx"].applyTags(),o=docX["tagProduitLoop.docx"].getFullText(),t="MicrosoftProduct name : DOSProduct reference : Win7Everyone uses itProof that it works nicely : It works because it is quite cheap It works because it is quit simple It works because it works on a lot of different HardwareLinuxProduct name : UbuntuProduct reference : Ubuntu10It's very powerfulProof that it works nicely : It works because the terminal is your friend It works because Hello world It works because it's freeAppleProduct name : MacProduct reference : OSXIt's very easyProof that it works nicely : It works because you can do a lot just with the mouse It works because It's nicely designed",expect(o.length).toEqual(t.length),expect(o).toEqual(t)})})}),describe("Xml Util",function(){var e;return e=new XmlUtil,it("should compute the scope between 2 <w:t>",function(){var t;return t=e.getListXmlElements('undefined</w:t></w:r></w:p><w:p w:rsidP="008A4B3C" w:rsidR="007929C1" w:rsidRDefault="007929C1" w:rsidRPr="008A4B3C"><w:pPr><w:pStyle w:val="Sous-titre"/></w:pPr><w:r w:rsidRPr="008A4B3C"><w:t xml:space="preserve">Audit réalisé le '),expect(t).toEqual([{tag:"</w:t>",offset:9},{tag:"</w:r>",offset:15},{tag:"</w:p>",offset:21},{tag:"<w:p>",offset:27},{tag:"<w:r>",offset:162},{tag:"<w:t>",offset:188}])}),it("should compute the scope between 2 <w:t> in an Array",function(){var t;return t=e.getListXmlElements('urs</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="4140"/></w:tcPr><w:p w:rsidP="00CE524B" w:rsidR="00CE524B" w:rsidRDefault="00CE524B"><w:pPr><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr><w:t>Sur exté'),expect(t).toEqual([{tag:"</w:t>",offset:3},{tag:"</w:r>",offset:9},{tag:"</w:p>",offset:15},{tag:"</w:tc>",offset:21},{tag:"<w:tc>",offset:28},{tag:"<w:p>",offset:83},{tag:"<w:r>",offset:268},{tag:"<w:t>",offset:374}])}),it("should compute the scope between a w:t in an array and the other outside",function(){var t;return t=e.getListXmlElements('defined </w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00137C91" w:rsidRDefault="00137C91"><w:r w:rsidRPr="00B12C70"><w:rPr><w:bCs/></w:rPr><w:t>Coût ressources '),expect(t).toEqual([{tag:"</w:t>",offset:8},{tag:"</w:r>",offset:14},{tag:"</w:p>",offset:20},{tag:"</w:tc>",offset:26},{tag:"</w:tr>",offset:33},{tag:"</w:tbl>",offset:40},{tag:"<w:p>",offset:188},{tag:"<w:r>",offset:257},{tag:"<w:t>",offset:306}])})}),describe("scope diff calculation",function(){var e;return e=new XmlUtil,it("should compute the scopeDiff between 2 <w:t>",function(){var t;return t=e.getListDifferenceXmlElements('undefined</w:t></w:r></w:p><w:p w:rsidP="008A4B3C" w:rsidR="007929C1" w:rsidRDefault="007929C1" w:rsidRPr="008A4B3C"><w:pPr><w:pStyle w:val="Sous-titre"/></w:pPr><w:r w:rsidRPr="008A4B3C"><w:t xml:space="preserve">Audit réalisé le '),expect(t).toEqual([])}),it("should compute the scopeDiff between 2 <w:t> in an Array",function(){var t;return t=e.getListDifferenceXmlElements('urs</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:tcW w:type="dxa" w:w="4140"/></w:tcPr><w:p w:rsidP="00CE524B" w:rsidR="00CE524B" w:rsidRDefault="00CE524B"><w:pPr><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:color w:val="auto"/></w:rPr><w:t>Sur exté'),expect(t).toEqual([])}),it("should compute the scopeDiff between a w:t in an array and the other outside",function(){var t;return t=e.getListDifferenceXmlElements('defined </w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00BE3585" w:rsidRDefault="00BE3585"/><w:p w:rsidP="00CA7135" w:rsidR="00137C91" w:rsidRDefault="00137C91"><w:r w:rsidRPr="00B12C70"><w:rPr><w:bCs/></w:rPr><w:t>Coût ressources '),expect(t).toEqual([{tag:"</w:tc>",offset:26},{tag:"</w:tr>",offset:33},{tag:"</w:tbl>",offset:40}])})}),describe("scope inner text",function(){return it("should find the scope",function(){var e,t,o;return o=new DocXTemplater,docX["tagProduitLoop.docx"].load(docX["tagProduitLoop.docx"].loadedContent),t=o.calcOuterXml(docX["tagProduitLoop.docx"].zip.files["word/document.xml"].asText(),1195,1245,"w:p"),e={text:'<w:p w:rsidR="00923B77" w:rsidRDefault="00923B77"><w:r><w:t>{#</w:t></w:r><w:r w:rsidR="00713414"><w:t>products</w:t></w:r><w:r><w:t>}</w:t></w:r></w:p>',startTag:1134,endTag:1286},expect(t.endTag).toEqual(e.endTag),expect(t.startTag).toEqual(e.startTag),expect(t.text.length).toEqual(e.text.length),expect(t.text).toEqual(e.text)})}),describe("Dash Loop Testing",function(){return it("dash loop ok on simple table -> w:tr",function(){var e,t,o;return e={os:[{type:"linux",price:"0",reference:"Ubuntu10"},{type:"DOS",price:"500",reference:"Win7"},{type:"apple",price:"1200",reference:"MACOSX"}]},docX["tagDashLoop.docx"].setTags(e),docX["tagDashLoop.docx"].applyTags(),t="linux0Ubuntu10DOS500Win7apple1200MACOSX",o=docX["tagDashLoop.docx"].getFullText(),expect(o).toBe(t)}),it("dash loop ok on simple table -> w:table",function(){var e,t,o;return e={os:[{type:"linux",price:"0",reference:"Ubuntu10"},{type:"DOS",price:"500",reference:"Win7"},{type:"apple",price:"1200",reference:"MACOSX"}]},docX["tagDashLoopTable.docx"].setTags(e),docX["tagDashLoopTable.docx"].applyTags(),t="linux0Ubuntu10DOS500Win7apple1200MACOSX",o=docX["tagDashLoopTable.docx"].getFullText(),expect(o).toBe(t)}),it("dash loop ok on simple list -> w:p",function(){var e,t,o;return e={os:[{type:"linux",price:"0",reference:"Ubuntu10"},{type:"DOS",price:"500",reference:"Win7"},{type:"apple",price:"1200",reference:"MACOSX"}]},docX["tagDashLoopList.docx"].setTags(e),docX["tagDashLoopList.docx"].applyTags(),t="linux 0 Ubuntu10 DOS 500 Win7 apple 1200 MACOSX ",o=docX["tagDashLoopList.docx"].getFullText(),expect(o).toBe(t)})}),describe("Intelligent Loop Tagging",function(){return it("should work with tables",function(){var e,t,o,a,r;e={clients:[{first_name:"John",last_name:"Doe",phone:"+33647874513"},{first_name:"Jane",last_name:"Doe",phone:"+33454540124"},{first_name:"Phil",last_name:"Kiel",phone:"+44578451245"},{first_name:"Dave",last_name:"Sto",phone:"+44548787984"}]},docX["tagIntelligentLoopTable.docx"].setTags(e),docX["tagIntelligentLoopTable.docx"].applyTags(),t="JohnDoe+33647874513JaneDoe+33454540124PhilKiel+44578451245DaveSto+44548787984",a=docX["tagIntelligentLoopTableExpected.docx"].getFullText(),expect(a).toBe(t),r=[];for(o in docX["tagIntelligentLoopTable.docx"].zip.files)expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].asText()).toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].asText()),expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].name).toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].name),expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].options.dir).toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].options.dir),r.push(expect(docX["tagIntelligentLoopTable.docx"].zip.files[o].options.date).not.toBe(docX["tagIntelligentLoopTableExpected.docx"].zip.files[o].options.date));return r})}),describe("getTags",function(){return it("should work with simple document",function(){var e;return docX["tagExample.docx"]=new DocxGen(docX["tagExample.docx"].loadedContent,{},!1),e=docX["tagExample.docx"].getTags(),expect(e).toEqual([{fileName:"word/document.xml",vars:{last_name:!0,first_name:!0}},{fileName:"word/footer1.xml",vars:{last_name:!0,first_name:!0,phone:!0}},{fileName:"word/header1.xml",vars:{last_name:!0,first_name:!0,phone:!0,description:!0}}])}),it("should work with loop document",function(){var e;return docX["tagLoopExample.docx"]=new DocxGen(docX["tagLoopExample.docx"].loadedContent,{},!1),e=docX["tagLoopExample.docx"].getTags(),expect(e).toEqual([{fileName:"word/document.xml",vars:{offre:{prix:!0,titre:!0},nom:!0,prenom:!0}},{fileName:"word/footer1.xml",vars:{nom:!0,prenom:!0,telephone:!0}},{fileName:"word/header1.xml",vars:{nom:!0,prenom:!0}}])}),it("should work if there are no Tags",function(){var e;return docX["qrCodeExample.docx"]=new DocxGen(docX["qrCodeExample.docx"].loadedContent,{},!1),e=docX["qrCodeExample.docx"].getTags(),expect(e).toEqual([])})}),describe("xmlTemplater",function(){return it("should work with simpleContent",function(){var e,t,o;return e="<w:t>Hello {name}</w:t>",t={name:"Edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar")}),it("should work with non w:t content",function(){var e,t,o;return e="{image}.png",t={image:"edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.content).toBe("edgar.png")}),it("should work with tag in two elements",function(){var e,t,o;return e="<w:t>Hello {</w:t><w:t>name}</w:t>",t={name:"Edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar")}),it("should work with simple Loop",function(){var e,t,o;return e="<w:t>Hello {#names}{name},{/names}</w:t>",t={names:[{name:"Edgar"},{name:"Mary"},{name:"John"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar,Mary,John,")}),it("should work with simple Loop with boolean value",function(){var e,t,o;return e="<w:t>Hello {#showName}{name},{/showName}</w:t>",t={showName:!0,name:"Edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),t={showName:!1,name:"Edgar"},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello ")}),it("should work with dash Loop",function(){var e,t,o;return e="<w:p><w:t>Hello {-w:p names}{name},{/names}</w:t></w:p>",t={names:[{name:"Edgar"},{name:"Mary"},{name:"John"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Hello Edgar,Hello Mary,Hello John,")}),it("should work with loop and innerContent",function(){var e,t,o;return e='</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:pStyle w:val="Titre1"/></w:pPr><w:r><w:t>{title</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRPr="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:r><w:t>Proof that it works nicely :</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00923B77" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{#pr</w:t></w:r><w:r w:rsidR="00713414"><w:t>oof</w:t></w:r><w:r><w:t xml:space="preserve">} </w:t></w:r><w:r w:rsidR="00713414"><w:t>It works because</w:t></w:r><w:r><w:t xml:space="preserve"> {</w:t></w:r><w:r w:rsidR="006F26AC"><w:t>reason</w:t></w:r><w:r><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{/proof</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00FD04E9" w:rsidRDefault="00923B77"><w:r><w:t>',t={title:"Everyone uses it",proof:[{reason:"it is quite cheap"},{reason:"it is quit simple"},{reason:"it works on a lot of different Hardware"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Everyone uses itProof that it works nicely : It works because it is quite cheap It works because it is quit simple It works because it works on a lot of different Hardware")}),it("should work with loop and innerContent (with last)",function(){var e,t,o;return e='</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:pStyle w:val="Titre1"/></w:pPr><w:r><w:t>{title</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRPr="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:r><w:t>Proof that it works nicely :</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00923B77" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{#pr</w:t></w:r><w:r w:rsidR="00713414"><w:t>oof</w:t></w:r><w:r><w:t xml:space="preserve">} </w:t></w:r><w:r w:rsidR="00713414"><w:t>It works because</w:t></w:r><w:r><w:t xml:space="preserve"> {</w:t></w:r><w:r w:rsidR="006F26AC"><w:t>reason</w:t></w:r><w:r><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00923B77" w:rsidRDefault="00713414" w:rsidP="00923B77"><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr><w:r><w:t>{/proof</w:t></w:r><w:r w:rsidR="00923B77"><w:t>}</w:t></w:r></w:p><w:p w:rsidR="00FD04E9" w:rsidRDefault="00923B77"><w:r><w:t> ',t={title:"Everyone uses it",proof:[{reason:"it is quite cheap"},{reason:"it is quit simple"},{reason:"it works on a lot of different Hardware"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.getFullText()).toBe("Everyone uses itProof that it works nicely : It works because it is quite cheap It works because it is quit simple It works because it works on a lot of different Hardware")}),it("should work with not w:t tag (if the for loop is like {#forloop} text {/forloop}) ",function(){var e,t,o;return e="Hello {#names}{name},{/names}",t={names:[{name:"Edgar"},{name:"Mary"},{name:"John"}]},o=new DocXTemplater(e,{Tags:t}),o.applyTags(),expect(o.content).toBe("Hello Edgar,Mary,John,")})}),describe("DocxQrCode module",function(){return describe("Calculate simple Docx",function(){var t,o,a,r;return t=null,o=null,r=null,a=null,beforeEach(function(){var e;return r=new JSZip(docXData["qrcodeTest.zip"]),e=new DocxGen,a=new DocXTemplater("",{DocxGen:e,Tags:{Tag:"tagValue"}})}),it("should do it's thing with JSZip.base64",function(){var e,t;return t=r.files["blabla.png"].asText(),e=JSZip.base64.encode(t),expect(e.length).toBe(624),expect(e.substr(0,50)).toBe("kcNChoKAAAADUlIRFIAAAAAIAAABOAAAAAZ0Uk5TAEAA07AAAE"),expect(e).toBe("kcNChoKAAAADUlIRFIAAAAAIAAABOAAAAAZ0Uk5TAEAA07AAAEURBVHdQkUQ/RQDIg7ON9jXTF4flff17B0EYJEDoJQidBDPcfG30PMH+N1VJTkQOglCJ0Icn0rPTxJEDoJQidB0Egj89PenQhBCVg2Rk9c5RA6CUInQhBOPm8gdBCRA6CUInQfN3dBB0EYJEDoJQidheKSkkC0EYJEDoJs9P141dBB0EYJEDoJQidhm2fVzZlnQhBCRuRTcye633fQSkQOglCJ0IXX6KdHB0WEDoJQidB0Ec/dX/teYY/Tyc6CUInQhBCcv/Xic6CUInQhBCm/f+FP0EYJEDoJQidB9Fnvc1hBCRA6CWve0IQSkYWk3HuPcB0EYJEDoJQidBUcez9HP3fPE0EYJEDoJQidhOEc/p53vf6/PcB0EYJEDoJQidBHfhd8VPWfP59dBJEDoJQidBsH31kpVfkQOglCJ0I0fl1axBA6CUInQhBjn/mHdidB0EJwHPOXVPiAhBCRA6Cf3Xc/8n0EJ0IQSlYNkzedHd+Nfx9xHQSkQOglCJ08+H9QSRA6CUInQh+pnQhBCd/fUcMRdCJ0IQSnAfHhBCRA6CUIn0wsvkAAAAASUVORA")}),it("should work with Blablalalabioeajbiojbepbroji",function(){return runs(function(){var n,i,l,d,c,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["blabla.png"].asBinary(),a,"custom.png",6),s.decode(t.test)):(n=JSZip.base64.encode(r.files["blabla.png"].asBinary()),i=new Buffer(n,"base64"),c=new PNG(i),d=function(e){return c.decoded=e,s=new DocxQrCode(c,a,"custom.png",6),s.decode(t.test)},l=c.decode(d))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("Blablalalabioeajbiojbepbroji"),expect(t.test.mostRecentCall.args[1]).toEqual("custom.png"),expect(t.test.mostRecentCall.args[2]).toEqual(6)})}),it("should work with long texts",function(){return runs(function(){var n,i,l,d,c,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["custom.png"].asBinary(),a,"custom.png",6),s.decode(t.test)):(n=JSZip.base64.encode(r.files["custom.png"].asBinary()),i=new Buffer(n,"base64"),c=new PNG(i),d=function(e){return c.decoded=e,s=new DocxQrCode(c,a,"custom.png",6),s.decode(t.test)},l=c.decode(d))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("Some custom text"),expect(t.test.mostRecentCall.args[1]).toEqual("custom.png"),expect(t.test.mostRecentCall.args[2]).toEqual(6)})}),it("should work with basic image",function(){return runs(function(){var n,i,l,d,c,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["qrcodeTest.png"].asBinary(),a,"qrcodeTest.png",4),s.decode(t.test)):(n=JSZip.base64.encode(r.files["qrcodeTest.png"].asBinary()),i=new Buffer(n,"base64"),c=new PNG(i),d=function(e){return c.decoded=e,s=new DocxQrCode(c,a,"qrcodeTest.png",4),s.decode(t.test)},l=c.decode(d))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("test"),expect(t.test.mostRecentCall.args[1]).toEqual("qrcodeTest.png"),expect(t.test.mostRecentCall.args[2]).toEqual(4)})}),it("should work with image with {tags}",function(){return runs(function(){var n,i,l,d,c,s;return o=!1,t={test:function(){return o=!0}},spyOn(t,"test").andCallThrough(),"browser"===e?(s=new DocxQrCode(r.files["qrcodetag.png"].asBinary(),a,"tag.png",2),s.decode(t.test)):(n=JSZip.base64.encode(r.files["qrcodetag.png"].asBinary()),i=new Buffer(n,"base64"),c=new PNG(i),d=function(e){return c.decoded=e,s=new DocxQrCode(c,a,"tag.png",2),s.decode(t.test)},l=c.decode(d))}),waitsFor(function(){return o}),runs(function(){return expect(t.test).toHaveBeenCalled(),expect(t.test.calls.length).toEqual(1),expect(t.test.mostRecentCall.args[0].result).toEqual("tagValue"),expect(t.test.mostRecentCall.args[1]).toEqual("tag.png"),expect(t.test.mostRecentCall.args[2]).toEqual(2)})})})}),describe("image Loop Replacing",function(){return describe("rels",function(){return it("should load",function(){return expect(docX["imageExample.docx"].imgManager.loadImageRels().imageRels).toEqual([]),expect(docX["imageExample.docx"].imgManager.maxRid).toEqual(10)}),it("should add",function(){var e,t,o,a,r,n,i;return a=docX["imageExample.docx"].zip.files["word/_rels/document.xml.rels"].asText(),expect(docX["imageExample.docx"].imgManager.addImageRels("image1.png",docXData["bootstrap_logo.png"])).toBe(11),expect(docX["imageExample.docx"].zip.files["word/_rels/document.xml.rels"].asText()).not.toBe(a),n=docX["imageExample.docx"].zip.files["word/_rels/document.xml.rels"].asText(),e=docX["imageExample.docx"].zip.files["[Content_Types].xml"].asText(),i=DocUtils.Str2xml(n),t=DocUtils.Str2xml(e),r=i.getElementsByTagName("Relationship"),o=t.getElementsByTagName("Default"),expect(r.length).toEqual(11),expect(o.length).toBe(4)})})}),describe("loop forTagging images",function(){return it("should work with a simple loop file",function(){var t,o,a,r,n,i,l,d,c;docX["tagLoopExample.docx"]=new DocxGen(docX["tagLoopExample.docx"].loadedContent),d={nom:"Hipp",prenom:"Edgar",telephone:"0652455478",description:"New Website",offre:[{titre:"titre1",prix:"1250",img:[{data:docXData["Volkswagen_logo.png"],name:"vw_logo.png"}]},{titre:"titre2",prix:"2000",img:[{data:docXData["BMW_logo.png"],name:"bmw_logo.png"}]},{titre:"titre3",prix:"1400",img:[{data:docXData["Firefox_logo.png"],name:"firefox_logo.png"}]}]},docX["tagLoopExample.docx"].setTags(d),docX["tagLoopExample.docx"].applyTags();for(r in docX["tagLoopExample.docx"].zip.files)expect(docX["tagLoopExample.docx"].zip.files[r].options.date).not.toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].options.date),expect(docX["tagLoopExample.docx"].zip.files[r].name).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].name),expect(docX["tagLoopExample.docx"].zip.files[r].options.dir).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].options.dir),"word/_rels/document.xml.rels"!==r&&"[Content_Types].xml"!==r&&("browser"===e||"word/document.xml"!==r)&&(("function"==typeof(c=docX["tagLoopExample.docx"].zip.files[r].asText())?c(0):void 0)&&expect(docX["tagLoopExample.docx"].zip.files[r].asText().length).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].asText().length),expect(docX["tagLoopExample.docx"].zip.files[r].asText()).toBe(docX["tagLoopExampleImageExpected.docx"].zip.files[r].asText()));return i=docX["tagLoopExample.docx"].zip.files["word/_rels/document.xml.rels"].asText(),t=docX["tagLoopExample.docx"].zip.files["[Content_Types].xml"].asText(),l=DocUtils.Str2xml(i),o=DocUtils.Str2xml(t),n=l.getElementsByTagName("Relationship"),a=o.getElementsByTagName("Default"),expect(n.length).toEqual(16),expect(a.length).toBe(3)})}),describe("qr code testing",function(){return it("should work with local QRCODE without tags",function(){var e;return docX["qrCodeExample.docx"]=new DocxGen(docX["qrCodeExample.docx"].loadedContent,{},!1,!0),e=function(){return 1},docX["qrCodeExample.docx"].applyTags({},e),waitsFor(function(){return null!=docX["qrCodeExample.docx"].ready}),runs(function(){var e,t;expect(null!=docX["qrCodeExample.docx"].zip.files["word/media/Copie_0.png"]).toBeTruthy(),t=[];for(e in docX["qrCodeExample.docx"].zip.files)expect(docX["qrCodeExample.docx"].zip.files[e].options.date).not.toBe(docX["qrCodeExampleExpected.docx"].zip.files[e].options.date),expect(docX["qrCodeExample.docx"].zip.files[e].name).toBe(docX["qrCodeExampleExpected.docx"].zip.files[e].name),t.push(expect(docX["qrCodeExample.docx"].zip.files[e].options.dir).toBe(docX["qrCodeExampleExpected.docx"].zip.files[e].options.dir));return t})}),it("should work with local QRCODE with {tags}",function(){var e;return docX["qrCodeTaggingExample.docx"]=new DocxGen(docX["qrCodeTaggingExample.docx"].loadedContent,{image:"Firefox_logo"},!1,!0),e=function(){return 1},docX["qrCodeTaggingExample.docx"].applyTags({image:"Firefox_logo"},e),waitsFor(function(){return null!=docX["qrCodeTaggingExample.docx"].ready}),runs(function(){var e,t;expect(null!=docX["qrCodeTaggingExample.docx"].zip.files["word/media/Copie_0.png"]).toBeTruthy(),t=[];for(e in docX["qrCodeTaggingExample.docx"].zip.files)expect(docX["qrCodeTaggingExample.docx"].zip.files[e].options.date).not.toBe(docX["qrCodeTaggingExampleExpected.docx"].zip.files[e].options.date),expect(docX["qrCodeTaggingExample.docx"].zip.files[e].name).toBe(docX["qrCodeTaggingExampleExpected.docx"].zip.files[e].name),expect(docX["qrCodeTaggingExample.docx"].zip.files[e].options.dir).toBe(docX["qrCodeTaggingExampleExpected.docx"].zip.files[e].options.dir),null!==docX["qrCodeTaggingExample.docx"].zip.files[e].asText()&&"word/document.xml"!==e?(expect(docX["qrCodeTaggingExample.docx"].zip.files[e].asText().length).toBe(docX["qrCodeTaggingExampleExpected.docx"].zip.files[e].asText().length),t.push(expect(docX["qrCodeExample.docx"].zip.files[e].asText()).toBe(docX["qrCodeExampleExpected.docx"].zip.files[e].asText()))):t.push(void 0);return t})}),it("should work with loop QRCODE with {tags}",function(){var e;return docX["qrCodeTaggingLoopExample.docx"]=new DocxGen(docX["qrCodeTaggingLoopExample.docx"].loadedContent,{},!1,!0),e=function(){return 1},docX["qrCodeTaggingLoopExample.docx"].applyTags({images:[{image:"Firefox_logo"},{image:"image"}]},e),docX["qrCodeTaggingLoopExample.docx"],waitsFor(function(){return null!=docX["qrCodeTaggingLoopExample.docx"].ready}),runs(function(){var e,t;expect(null!=docX["qrCodeTaggingLoopExample.docx"].zip.files["word/media/Copie_0.png"]).toBeTruthy(),expect(null!=docX["qrCodeTaggingLoopExample.docx"].zip.files["word/media/Copie_1.png"]).toBeTruthy(),expect(null!=docX["qrCodeTaggingLoopExample.docx"].zip.files["word/media/Copie_2.png"]).toBeFalsy(),t=[];for(e in docX["qrCodeTaggingLoopExample.docx"].zip.files)expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].options.date).not.toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].options.date),expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].name).toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].name),expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].options.dir).toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].options.dir),null!==docX["qrCodeTaggingLoopExample.docx"].zip.files[e].asText()&&"word/document.xml"!==e?(expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].asText().length).toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].asText().length),t.push(expect(docX["qrCodeTaggingLoopExample.docx"].zip.files[e].asText()).toBe(docX["qrCodeTaggingLoopExampleExpected.docx"].zip.files[e].asText()))):t.push(void 0);return t})})})}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc