docx-preview.js 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("JSZip"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["JSZip"], factory);
  6. else if(typeof exports === 'object')
  7. exports["docx"] = factory(require("JSZip"));
  8. else
  9. root["docx"] = factory(root["JSZip"]);
  10. })(self, function(__WEBPACK_EXTERNAL_MODULE_jszip__) {
  11. return /******/ (() => { // webpackBootstrap
  12. /******/ "use strict";
  13. /******/ var __webpack_modules__ = ({
  14. /***/ "./src/common/open-xml-package.ts":
  15. /*!****************************************!*\
  16. !*** ./src/common/open-xml-package.ts ***!
  17. \****************************************/
  18. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20. exports.OpenXmlPackage = void 0;
  21. var JSZip = __webpack_require__(/*! jszip */ "jszip");
  22. var xml_parser_1 = __webpack_require__(/*! ../parser/xml-parser */ "./src/parser/xml-parser.ts");
  23. var utils_1 = __webpack_require__(/*! ../utils */ "./src/utils.ts");
  24. var relationship_1 = __webpack_require__(/*! ./relationship */ "./src/common/relationship.ts");
  25. var OpenXmlPackage = (function () {
  26. function OpenXmlPackage(_zip, options) {
  27. this._zip = _zip;
  28. this.options = options;
  29. this.xmlParser = new xml_parser_1.XmlParser();
  30. }
  31. OpenXmlPackage.prototype.get = function (path) {
  32. return this._zip.files[normalizePath(path)];
  33. };
  34. OpenXmlPackage.prototype.update = function (path, content) {
  35. this._zip.file(path, content);
  36. };
  37. OpenXmlPackage.load = function (input, options) {
  38. return JSZip.loadAsync(input).then(function (zip) { return new OpenXmlPackage(zip, options); });
  39. };
  40. OpenXmlPackage.prototype.save = function (type) {
  41. if (type === void 0) { type = "blob"; }
  42. return this._zip.generateAsync({ type: type });
  43. };
  44. OpenXmlPackage.prototype.load = function (path, type) {
  45. var _a, _b;
  46. if (type === void 0) { type = "string"; }
  47. return (_b = (_a = this.get(path)) === null || _a === void 0 ? void 0 : _a.async(type)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
  48. };
  49. OpenXmlPackage.prototype.loadRelationships = function (path) {
  50. var _this = this;
  51. if (path === void 0) { path = null; }
  52. var relsPath = "_rels/.rels";
  53. if (path != null) {
  54. var _a = (0, utils_1.splitPath)(path), f = _a[0], fn = _a[1];
  55. relsPath = f + "_rels/" + fn + ".rels";
  56. }
  57. return this.load(relsPath)
  58. .then(function (txt) { return txt ? (0, relationship_1.parseRelationships)(_this.parseXmlDocument(txt).firstElementChild, _this.xmlParser) : null; });
  59. };
  60. OpenXmlPackage.prototype.parseXmlDocument = function (txt) {
  61. return (0, xml_parser_1.parseXmlString)(txt, this.options.trimXmlDeclaration);
  62. };
  63. return OpenXmlPackage;
  64. }());
  65. exports.OpenXmlPackage = OpenXmlPackage;
  66. function normalizePath(path) {
  67. return path.startsWith('/') ? path.substr(1) : path;
  68. }
  69. /***/ }),
  70. /***/ "./src/common/part.ts":
  71. /*!****************************!*\
  72. !*** ./src/common/part.ts ***!
  73. \****************************/
  74. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  75. Object.defineProperty(exports, "__esModule", ({ value: true }));
  76. exports.Part = void 0;
  77. var xml_parser_1 = __webpack_require__(/*! ../parser/xml-parser */ "./src/parser/xml-parser.ts");
  78. var Part = (function () {
  79. function Part(_package, path) {
  80. this._package = _package;
  81. this.path = path;
  82. }
  83. Part.prototype.load = function () {
  84. var _this = this;
  85. return Promise.all([
  86. this._package.loadRelationships(this.path).then(function (rels) {
  87. _this.rels = rels;
  88. }),
  89. this._package.load(this.path).then(function (text) {
  90. var xmlDoc = _this._package.parseXmlDocument(text);
  91. if (_this._package.options.keepOrigin) {
  92. _this._xmlDocument = xmlDoc;
  93. }
  94. _this.parseXml(xmlDoc.firstElementChild);
  95. })
  96. ]);
  97. };
  98. Part.prototype.save = function () {
  99. this._package.update(this.path, (0, xml_parser_1.serializeXmlString)(this._xmlDocument));
  100. };
  101. Part.prototype.parseXml = function (root) {
  102. };
  103. return Part;
  104. }());
  105. exports.Part = Part;
  106. /***/ }),
  107. /***/ "./src/common/relationship.ts":
  108. /*!************************************!*\
  109. !*** ./src/common/relationship.ts ***!
  110. \************************************/
  111. /***/ ((__unused_webpack_module, exports) => {
  112. Object.defineProperty(exports, "__esModule", ({ value: true }));
  113. exports.parseRelationships = exports.RelationshipTypes = void 0;
  114. var RelationshipTypes;
  115. (function (RelationshipTypes) {
  116. RelationshipTypes["OfficeDocument"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
  117. RelationshipTypes["FontTable"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable";
  118. RelationshipTypes["Image"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
  119. RelationshipTypes["Numbering"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
  120. RelationshipTypes["Styles"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
  121. RelationshipTypes["StylesWithEffects"] = "http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects";
  122. RelationshipTypes["Theme"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
  123. RelationshipTypes["Settings"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings";
  124. RelationshipTypes["WebSettings"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings";
  125. RelationshipTypes["Hyperlink"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
  126. RelationshipTypes["Footer"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
  127. RelationshipTypes["Header"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
  128. RelationshipTypes["ExtendedProperties"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
  129. RelationshipTypes["CoreProperties"] = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
  130. })(RelationshipTypes = exports.RelationshipTypes || (exports.RelationshipTypes = {}));
  131. function parseRelationships(root, xml) {
  132. return xml.elements(root).map(function (e) { return ({
  133. id: xml.attr(e, "Id"),
  134. type: xml.attr(e, "Type"),
  135. target: xml.attr(e, "Target"),
  136. targetMode: xml.attr(e, "TargetMode")
  137. }); });
  138. }
  139. exports.parseRelationships = parseRelationships;
  140. /***/ }),
  141. /***/ "./src/document-parser.ts":
  142. /*!********************************!*\
  143. !*** ./src/document-parser.ts ***!
  144. \********************************/
  145. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  146. Object.defineProperty(exports, "__esModule", ({ value: true }));
  147. exports.DocumentParser = exports.autos = void 0;
  148. var dom_1 = __webpack_require__(/*! ./dom/dom */ "./src/dom/dom.ts");
  149. var utils = __webpack_require__(/*! ./utils */ "./src/utils.ts");
  150. var paragraph_1 = __webpack_require__(/*! ./dom/paragraph */ "./src/dom/paragraph.ts");
  151. var section_1 = __webpack_require__(/*! ./dom/section */ "./src/dom/section.ts");
  152. var xml_parser_1 = __webpack_require__(/*! ./parser/xml-parser */ "./src/parser/xml-parser.ts");
  153. var bookmark_1 = __webpack_require__(/*! ./dom/bookmark */ "./src/dom/bookmark.ts");
  154. var footer_1 = __webpack_require__(/*! ./footer/footer */ "./src/footer/footer.ts");
  155. var header_1 = __webpack_require__(/*! ./header/header */ "./src/header/header.ts");
  156. exports.autos = {
  157. shd: "white",
  158. color: "black",
  159. highlight: "transparent"
  160. };
  161. var DocumentParser = (function () {
  162. function DocumentParser() {
  163. this.skipDeclaration = true;
  164. this.ignoreWidth = false;
  165. this.debug = false;
  166. }
  167. DocumentParser.prototype.parseFooter = function (xmlDoc) {
  168. var result = new footer_1.WmlFooter();
  169. result.children = this.parseBodyElements(xmlDoc);
  170. return result;
  171. };
  172. DocumentParser.prototype.parseHeader = function (xmlDoc) {
  173. var result = new header_1.WmlHeader();
  174. result.children = this.parseBodyElements(xmlDoc);
  175. return result;
  176. };
  177. DocumentParser.prototype.parseDocumentFile = function (xmlDoc) {
  178. var xbody = xml_parser_1.default.element(xmlDoc, "body");
  179. var sectPr = xml_parser_1.default.element(xbody, "sectPr");
  180. return {
  181. type: dom_1.DomType.Document,
  182. children: this.parseBodyElements(xbody),
  183. props: sectPr ? (0, section_1.parseSectionProperties)(sectPr, xml_parser_1.default) : null,
  184. cssStyle: {},
  185. };
  186. };
  187. DocumentParser.prototype.parseBodyElements = function (element) {
  188. var _this = this;
  189. var children = [];
  190. xml.foreach(element, function (elem) {
  191. switch (elem.localName) {
  192. case "p":
  193. children.push(_this.parseParagraph(elem));
  194. break;
  195. case "tbl":
  196. children.push(_this.parseTable(elem));
  197. break;
  198. }
  199. });
  200. return children;
  201. };
  202. DocumentParser.prototype.parseStylesFile = function (xstyles) {
  203. var _this = this;
  204. var result = [];
  205. xml.foreach(xstyles, function (n) {
  206. switch (n.localName) {
  207. case "style":
  208. result.push(_this.parseStyle(n));
  209. break;
  210. case "docDefaults":
  211. result.push(_this.parseDefaultStyles(n));
  212. break;
  213. }
  214. });
  215. return result;
  216. };
  217. DocumentParser.prototype.parseDefaultStyles = function (node) {
  218. var _this = this;
  219. var result = {
  220. id: null,
  221. name: null,
  222. target: null,
  223. basedOn: null,
  224. styles: []
  225. };
  226. xml.foreach(node, function (c) {
  227. switch (c.localName) {
  228. case "rPrDefault":
  229. var rPr = xml_parser_1.default.element(c, "rPr");
  230. if (rPr)
  231. result.styles.push({
  232. target: "span",
  233. values: _this.parseDefaultProperties(rPr, {})
  234. });
  235. break;
  236. case "pPrDefault":
  237. var pPr = xml_parser_1.default.element(c, "pPr");
  238. if (pPr)
  239. result.styles.push({
  240. target: "p",
  241. values: _this.parseDefaultProperties(pPr, {})
  242. });
  243. break;
  244. }
  245. });
  246. return result;
  247. };
  248. DocumentParser.prototype.parseStyle = function (node) {
  249. var _this = this;
  250. var result = {
  251. id: xml.stringAttr(node, "styleId"),
  252. isDefault: xml.boolAttr(node, "default"),
  253. name: null,
  254. target: null,
  255. basedOn: null,
  256. styles: [],
  257. linked: null
  258. };
  259. switch (xml.stringAttr(node, "type")) {
  260. case "paragraph":
  261. result.target = "p";
  262. break;
  263. case "table":
  264. result.target = "table";
  265. break;
  266. case "character":
  267. result.target = "span";
  268. break;
  269. }
  270. xml.foreach(node, function (n) {
  271. switch (n.localName) {
  272. case "basedOn":
  273. result.basedOn = xml.className(n, "val");
  274. break;
  275. case "name":
  276. result.name = xml.stringAttr(n, "val");
  277. break;
  278. case "link":
  279. result.linked = xml.className(n, "val");
  280. break;
  281. case "next":
  282. result.next = xml.className(n, "val");
  283. break;
  284. case "aliases":
  285. result.aliases = xml.stringAttr(n, "val").split(",");
  286. break;
  287. case "pPr":
  288. result.styles.push({
  289. target: "p",
  290. values: _this.parseDefaultProperties(n, {})
  291. });
  292. result.paragraphProps = (0, paragraph_1.parseParagraphProperties)(n, xml_parser_1.default);
  293. break;
  294. case "rPr":
  295. result.styles.push({
  296. target: "span",
  297. values: _this.parseDefaultProperties(n, {})
  298. });
  299. result.runProps = (0, paragraph_1.parseParagraphProperties)(n, xml_parser_1.default);
  300. break;
  301. case "tblPr":
  302. case "tcPr":
  303. result.styles.push({
  304. target: "td",
  305. values: _this.parseDefaultProperties(n, {})
  306. });
  307. break;
  308. case "tblStylePr":
  309. for (var _i = 0, _a = _this.parseTableStyle(n); _i < _a.length; _i++) {
  310. var s = _a[_i];
  311. result.styles.push(s);
  312. }
  313. break;
  314. case "rsid":
  315. case "qFormat":
  316. case "hidden":
  317. case "semiHidden":
  318. case "unhideWhenUsed":
  319. case "autoRedefine":
  320. case "uiPriority":
  321. break;
  322. default:
  323. _this.debug && console.warn("DOCX: Unknown style element: " + n.localName);
  324. }
  325. });
  326. return result;
  327. };
  328. DocumentParser.prototype.parseTableStyle = function (node) {
  329. var _this = this;
  330. var result = [];
  331. var type = xml.stringAttr(node, "type");
  332. var selector = "";
  333. switch (type) {
  334. case "firstRow":
  335. selector = "tr.first-row td";
  336. break;
  337. case "lastRow":
  338. selector = "tr.last-row td";
  339. break;
  340. case "firstCol":
  341. selector = "td.first-col";
  342. break;
  343. case "lastCol":
  344. selector = "td.last-col";
  345. break;
  346. case "band1Vert":
  347. selector = "td.odd-col";
  348. break;
  349. case "band2Vert":
  350. selector = "td.even-col";
  351. break;
  352. case "band1Horz":
  353. selector = "tr.odd-row";
  354. break;
  355. case "band2Horz":
  356. selector = "tr.even-row";
  357. break;
  358. default: return [];
  359. }
  360. xml.foreach(node, function (n) {
  361. switch (n.localName) {
  362. case "pPr":
  363. result.push({
  364. target: selector + " p",
  365. values: _this.parseDefaultProperties(n, {})
  366. });
  367. break;
  368. case "rPr":
  369. result.push({
  370. target: selector + " span",
  371. values: _this.parseDefaultProperties(n, {})
  372. });
  373. break;
  374. case "tblPr":
  375. case "tcPr":
  376. result.push({
  377. target: selector,
  378. values: _this.parseDefaultProperties(n, {})
  379. });
  380. break;
  381. }
  382. });
  383. return result;
  384. };
  385. DocumentParser.prototype.parseNumberingFile = function (xnums) {
  386. var _this = this;
  387. var result = [];
  388. var mapping = {};
  389. var bullets = [];
  390. xml.foreach(xnums, function (n) {
  391. switch (n.localName) {
  392. case "abstractNum":
  393. _this.parseAbstractNumbering(n, bullets)
  394. .forEach(function (x) { return result.push(x); });
  395. break;
  396. case "numPicBullet":
  397. bullets.push(_this.parseNumberingPicBullet(n));
  398. break;
  399. case "num":
  400. var numId = xml.stringAttr(n, "numId");
  401. var abstractNumId = xml.elementStringAttr(n, "abstractNumId", "val");
  402. mapping[abstractNumId] = numId;
  403. break;
  404. }
  405. });
  406. result.forEach(function (x) { return x.id = mapping[x.id]; });
  407. return result;
  408. };
  409. DocumentParser.prototype.parseNumberingPicBullet = function (elem) {
  410. var pict = xml_parser_1.default.element(elem, "pict");
  411. var shape = pict && xml_parser_1.default.element(pict, "shape");
  412. var imagedata = shape && xml_parser_1.default.element(shape, "imagedata");
  413. return imagedata ? {
  414. id: xml.intAttr(elem, "numPicBulletId"),
  415. src: xml.stringAttr(imagedata, "id"),
  416. style: xml.stringAttr(shape, "style")
  417. } : null;
  418. };
  419. DocumentParser.prototype.parseAbstractNumbering = function (node, bullets) {
  420. var _this = this;
  421. var result = [];
  422. var id = xml.stringAttr(node, "abstractNumId");
  423. xml.foreach(node, function (n) {
  424. switch (n.localName) {
  425. case "lvl":
  426. result.push(_this.parseNumberingLevel(id, n, bullets));
  427. break;
  428. }
  429. });
  430. return result;
  431. };
  432. DocumentParser.prototype.parseNumberingLevel = function (id, node, bullets) {
  433. var _this = this;
  434. var result = {
  435. id: id,
  436. level: xml.intAttr(node, "ilvl"),
  437. pStyle: {},
  438. rStyle: {},
  439. suff: "tab"
  440. };
  441. xml.foreach(node, function (n) {
  442. switch (n.localName) {
  443. case "pPr":
  444. _this.parseDefaultProperties(n, result.pStyle);
  445. break;
  446. case "rPr":
  447. _this.parseDefaultProperties(n, result.rStyle);
  448. break;
  449. case "lvlPicBulletId":
  450. var id = xml.intAttr(n, "val");
  451. result.bullet = bullets.filter(function (x) { return x.id == id; })[0];
  452. break;
  453. case "lvlText":
  454. result.levelText = xml.stringAttr(n, "val");
  455. break;
  456. case "numFmt":
  457. result.format = xml.stringAttr(n, "val");
  458. break;
  459. case "suff":
  460. result.suff = xml.stringAttr(n, "val");
  461. break;
  462. }
  463. });
  464. return result;
  465. };
  466. DocumentParser.prototype.parseParagraph = function (node) {
  467. var _this = this;
  468. var result = { type: dom_1.DomType.Paragraph, children: [] };
  469. xml.foreach(node, function (c) {
  470. switch (c.localName) {
  471. case "r":
  472. result.children.push(_this.parseRun(c, result));
  473. break;
  474. case "hyperlink":
  475. result.children.push(_this.parseHyperlink(c, result));
  476. break;
  477. case "bookmarkStart":
  478. result.children.push((0, bookmark_1.parseBookmarkStart)(c, xml_parser_1.default));
  479. break;
  480. case "bookmarkEnd":
  481. result.children.push((0, bookmark_1.parseBookmarkEnd)(c, xml_parser_1.default));
  482. break;
  483. case "pPr":
  484. _this.parseParagraphProperties(c, result);
  485. break;
  486. }
  487. });
  488. return result;
  489. };
  490. DocumentParser.prototype.parseParagraphProperties = function (elem, paragraph) {
  491. var _this = this;
  492. this.parseDefaultProperties(elem, paragraph.cssStyle = {}, null, function (c) {
  493. if ((0, paragraph_1.parseParagraphProperty)(c, paragraph, xml_parser_1.default))
  494. return true;
  495. switch (c.localName) {
  496. case "pStyle":
  497. utils.addElementClass(paragraph, xml.className(c, "val"));
  498. break;
  499. case "cnfStyle":
  500. utils.addElementClass(paragraph, values.classNameOfCnfStyle(c));
  501. break;
  502. case "framePr":
  503. _this.parseFrame(c, paragraph);
  504. break;
  505. case "rPr":
  506. break;
  507. default:
  508. return false;
  509. }
  510. return true;
  511. });
  512. };
  513. DocumentParser.prototype.parseFrame = function (node, paragraph) {
  514. var dropCap = xml.stringAttr(node, "dropCap");
  515. if (dropCap == "drop")
  516. paragraph.cssStyle["float"] = "left";
  517. };
  518. DocumentParser.prototype.parseHyperlink = function (node, parent) {
  519. var _this = this;
  520. var result = { type: dom_1.DomType.Hyperlink, parent: parent, children: [] };
  521. var anchor = xml.stringAttr(node, "anchor");
  522. if (anchor)
  523. result.href = "#" + anchor;
  524. xml.foreach(node, function (c) {
  525. switch (c.localName) {
  526. case "r":
  527. result.children.push(_this.parseRun(c, result));
  528. break;
  529. }
  530. });
  531. return result;
  532. };
  533. DocumentParser.prototype.parseRun = function (node, parent) {
  534. var _this = this;
  535. var result = { type: dom_1.DomType.Run, parent: parent, children: [] };
  536. xml.foreach(node, function (c) {
  537. switch (c.localName) {
  538. case "t":
  539. result.children.push({
  540. type: dom_1.DomType.Text,
  541. text: c.textContent
  542. });
  543. break;
  544. case "fldChar":
  545. result.fldCharType = xml.stringAttr(c, "fldCharType");
  546. break;
  547. case "br":
  548. result.children.push({
  549. type: dom_1.DomType.Break,
  550. break: xml.stringAttr(c, "type") || "textWrapping"
  551. });
  552. break;
  553. case "lastRenderedPageBreak":
  554. result.children.push({
  555. type: dom_1.DomType.Break,
  556. break: "page"
  557. });
  558. break;
  559. case "sym":
  560. result.children.push({
  561. type: dom_1.DomType.Symbol,
  562. font: xml.stringAttr(c, "font"),
  563. char: xml.stringAttr(c, "char")
  564. });
  565. break;
  566. case "tab":
  567. result.children.push({ type: dom_1.DomType.Tab });
  568. break;
  569. case "instrText":
  570. result.instrText = c.textContent;
  571. break;
  572. case "drawing":
  573. var d = _this.parseDrawing(c);
  574. if (d)
  575. result.children = [d];
  576. break;
  577. case "rPr":
  578. _this.parseRunProperties(c, result);
  579. break;
  580. }
  581. });
  582. return result;
  583. };
  584. DocumentParser.prototype.parseRunProperties = function (elem, run) {
  585. this.parseDefaultProperties(elem, run.cssStyle = {}, null, function (c) {
  586. switch (c.localName) {
  587. case "rStyle":
  588. run.className = xml.className(c, "val");
  589. break;
  590. case "vertAlign":
  591. switch (xml.stringAttr(c, "val")) {
  592. case "subscript":
  593. run.wrapper = "sub";
  594. break;
  595. case "superscript":
  596. run.wrapper = "sup";
  597. break;
  598. }
  599. break;
  600. default:
  601. return false;
  602. }
  603. return true;
  604. });
  605. };
  606. DocumentParser.prototype.parseDrawing = function (node) {
  607. for (var _i = 0, _a = xml_parser_1.default.elements(node); _i < _a.length; _i++) {
  608. var n = _a[_i];
  609. switch (n.localName) {
  610. case "inline":
  611. case "anchor":
  612. return this.parseDrawingWrapper(n);
  613. }
  614. }
  615. };
  616. DocumentParser.prototype.parseDrawingWrapper = function (node) {
  617. var result = { type: dom_1.DomType.Drawing, children: [], cssStyle: {} };
  618. var isAnchor = node.localName == "anchor";
  619. var wrapType = null;
  620. var simplePos = xml.boolAttr(node, "simplePos");
  621. var posX = { relative: "page", align: "left", offset: "0" };
  622. var posY = { relative: "page", align: "top", offset: "0" };
  623. for (var _i = 0, _a = xml_parser_1.default.elements(node); _i < _a.length; _i++) {
  624. var n = _a[_i];
  625. switch (n.localName) {
  626. case "simplePos":
  627. if (simplePos) {
  628. posX.offset = xml.sizeAttr(n, "x", SizeType.Emu);
  629. posY.offset = xml.sizeAttr(n, "y", SizeType.Emu);
  630. }
  631. break;
  632. case "extent":
  633. result.cssStyle["width"] = xml.sizeAttr(n, "cx", SizeType.Emu);
  634. result.cssStyle["height"] = xml.sizeAttr(n, "cy", SizeType.Emu);
  635. break;
  636. case "positionH":
  637. case "positionV":
  638. if (!simplePos) {
  639. var pos = n.localName == "positionH" ? posX : posY;
  640. var alignNode = xml_parser_1.default.element(n, "align");
  641. var offsetNode = xml_parser_1.default.element(n, "posOffset");
  642. if (alignNode)
  643. pos.align = alignNode.textContent;
  644. if (offsetNode)
  645. pos.offset = xml.sizeValue(offsetNode, SizeType.Emu);
  646. }
  647. break;
  648. case "wrapTopAndBottom":
  649. wrapType = "wrapTopAndBottom";
  650. break;
  651. case "wrapNone":
  652. wrapType = "wrapNone";
  653. break;
  654. case "graphic":
  655. var g = this.parseGraphic(n);
  656. if (g)
  657. result.children.push(g);
  658. break;
  659. }
  660. }
  661. if (wrapType == "wrapTopAndBottom") {
  662. result.cssStyle['display'] = 'block';
  663. if (posX.align) {
  664. result.cssStyle['text-align'] = posX.align;
  665. result.cssStyle['width'] = "100%";
  666. }
  667. }
  668. else if (wrapType == "wrapNone") {
  669. result.cssStyle['display'] = 'block';
  670. result.cssStyle['position'] = 'relative';
  671. result.cssStyle["width"] = "0px";
  672. result.cssStyle["height"] = "0px";
  673. if (posX.offset)
  674. result.cssStyle["left"] = posX.offset;
  675. if (posY.offset)
  676. result.cssStyle["top"] = posY.offset;
  677. }
  678. else if (isAnchor && (posX.align == 'left' || posX.align == 'right')) {
  679. result.cssStyle["float"] = posX.align;
  680. }
  681. return result;
  682. };
  683. DocumentParser.prototype.parseGraphic = function (elem) {
  684. var graphicData = xml_parser_1.default.element(elem, "graphicData");
  685. for (var _i = 0, _a = xml_parser_1.default.elements(graphicData); _i < _a.length; _i++) {
  686. var n = _a[_i];
  687. switch (n.localName) {
  688. case "pic":
  689. return this.parsePicture(n);
  690. }
  691. }
  692. return null;
  693. };
  694. DocumentParser.prototype.parsePicture = function (elem) {
  695. var result = { type: dom_1.DomType.Image, src: "", cssStyle: {} };
  696. var blipFill = xml_parser_1.default.element(elem, "blipFill");
  697. var blip = xml_parser_1.default.element(blipFill, "blip");
  698. result.src = xml.stringAttr(blip, "embed");
  699. var spPr = xml_parser_1.default.element(elem, "spPr");
  700. var xfrm = xml_parser_1.default.element(spPr, "xfrm");
  701. result.cssStyle["position"] = "relative";
  702. for (var _i = 0, _a = xml_parser_1.default.elements(xfrm); _i < _a.length; _i++) {
  703. var n = _a[_i];
  704. switch (n.localName) {
  705. case "ext":
  706. result.cssStyle["width"] = xml.sizeAttr(n, "cx", SizeType.Emu);
  707. result.cssStyle["height"] = xml.sizeAttr(n, "cy", SizeType.Emu);
  708. break;
  709. case "off":
  710. result.cssStyle["left"] = xml.sizeAttr(n, "x", SizeType.Emu);
  711. result.cssStyle["top"] = xml.sizeAttr(n, "y", SizeType.Emu);
  712. break;
  713. }
  714. }
  715. return result;
  716. };
  717. DocumentParser.prototype.parseTable = function (node) {
  718. var _this = this;
  719. var result = { type: dom_1.DomType.Table, children: [] };
  720. xml.foreach(node, function (c) {
  721. switch (c.localName) {
  722. case "tr":
  723. result.children.push(_this.parseTableRow(c));
  724. break;
  725. case "tblGrid":
  726. result.columns = _this.parseTableColumns(c);
  727. break;
  728. case "tblPr":
  729. _this.parseTableProperties(c, result);
  730. break;
  731. }
  732. });
  733. return result;
  734. };
  735. DocumentParser.prototype.parseTableColumns = function (node) {
  736. var result = [];
  737. xml.foreach(node, function (n) {
  738. switch (n.localName) {
  739. case "gridCol":
  740. result.push({ width: xml.sizeAttr(n, "w") });
  741. break;
  742. }
  743. });
  744. return result;
  745. };
  746. DocumentParser.prototype.parseTableProperties = function (elem, table) {
  747. var _this = this;
  748. table.cssStyle = {};
  749. table.cellStyle = {};
  750. this.parseDefaultProperties(elem, table.cssStyle, table.cellStyle, function (c) {
  751. switch (c.localName) {
  752. case "tblStyle":
  753. table.className = xml.className(c, "val");
  754. break;
  755. case "tblLook":
  756. utils.addElementClass(table, values.classNameOftblLook(c));
  757. break;
  758. case "tblpPr":
  759. _this.parseTablePosition(c, table);
  760. break;
  761. default:
  762. return false;
  763. }
  764. return true;
  765. });
  766. switch (table.cssStyle["text-align"]) {
  767. case "center":
  768. delete table.cssStyle["text-align"];
  769. table.cssStyle["margin-left"] = "auto";
  770. table.cssStyle["margin-right"] = "auto";
  771. break;
  772. case "right":
  773. delete table.cssStyle["text-align"];
  774. table.cssStyle["margin-left"] = "auto";
  775. break;
  776. }
  777. };
  778. DocumentParser.prototype.parseTablePosition = function (node, table) {
  779. var topFromText = xml.sizeAttr(node, "topFromText");
  780. var bottomFromText = xml.sizeAttr(node, "bottomFromText");
  781. var rightFromText = xml.sizeAttr(node, "rightFromText");
  782. var leftFromText = xml.sizeAttr(node, "leftFromText");
  783. table.cssStyle["float"] = 'left';
  784. table.cssStyle["margin-bottom"] = values.addSize(table.cssStyle["margin-bottom"], bottomFromText);
  785. table.cssStyle["margin-left"] = values.addSize(table.cssStyle["margin-left"], leftFromText);
  786. table.cssStyle["margin-right"] = values.addSize(table.cssStyle["margin-right"], rightFromText);
  787. table.cssStyle["margin-top"] = values.addSize(table.cssStyle["margin-top"], topFromText);
  788. };
  789. DocumentParser.prototype.parseTableRow = function (node) {
  790. var _this = this;
  791. var result = { type: dom_1.DomType.Row, children: [] };
  792. xml.foreach(node, function (c) {
  793. switch (c.localName) {
  794. case "tc":
  795. result.children.push(_this.parseTableCell(c));
  796. break;
  797. case "trPr":
  798. _this.parseTableRowProperties(c, result);
  799. break;
  800. }
  801. });
  802. return result;
  803. };
  804. DocumentParser.prototype.parseTableRowProperties = function (elem, row) {
  805. row.cssStyle = this.parseDefaultProperties(elem, {}, null, function (c) {
  806. switch (c.localName) {
  807. case "cnfStyle":
  808. row.className = values.classNameOfCnfStyle(c);
  809. break;
  810. default:
  811. return false;
  812. }
  813. return true;
  814. });
  815. };
  816. DocumentParser.prototype.parseTableCell = function (node) {
  817. var _this = this;
  818. var result = { type: dom_1.DomType.Cell, children: [] };
  819. xml.foreach(node, function (c) {
  820. switch (c.localName) {
  821. case "tbl":
  822. result.children.push(_this.parseTable(c));
  823. break;
  824. case "p":
  825. result.children.push(_this.parseParagraph(c));
  826. break;
  827. case "tcPr":
  828. _this.parseTableCellProperties(c, result);
  829. break;
  830. }
  831. });
  832. return result;
  833. };
  834. DocumentParser.prototype.parseTableCellProperties = function (elem, cell) {
  835. cell.cssStyle = this.parseDefaultProperties(elem, {}, null, function (c) {
  836. switch (c.localName) {
  837. case "gridSpan":
  838. cell.span = xml.intAttr(c, "val", null);
  839. break;
  840. case "vMerge":
  841. break;
  842. case "cnfStyle":
  843. cell.className = values.classNameOfCnfStyle(c);
  844. break;
  845. default:
  846. return false;
  847. }
  848. return true;
  849. });
  850. };
  851. DocumentParser.prototype.parseDefaultProperties = function (elem, style, childStyle, handler) {
  852. var _this = this;
  853. if (style === void 0) { style = null; }
  854. if (childStyle === void 0) { childStyle = null; }
  855. if (handler === void 0) { handler = null; }
  856. style = style || {};
  857. xml.foreach(elem, function (c) {
  858. switch (c.localName) {
  859. case "jc":
  860. style["text-align"] = values.valueOfJc(c);
  861. break;
  862. case "textAlignment":
  863. style["vertical-align"] = values.valueOfTextAlignment(c);
  864. break;
  865. case "color":
  866. style["color"] = xml.colorAttr(c, "val", null, exports.autos.color);
  867. break;
  868. case "sz":
  869. style["font-size"] = style["min-height"] = xml.sizeAttr(c, "val", SizeType.FontSize);
  870. break;
  871. case "shd":
  872. style["background-color"] = xml.colorAttr(c, "fill", null, exports.autos.shd);
  873. break;
  874. case "highlight":
  875. style["background-color"] = xml.colorAttr(c, "val", null, exports.autos.highlight);
  876. break;
  877. case "tcW":
  878. if (_this.ignoreWidth)
  879. break;
  880. case "tblW":
  881. style["width"] = values.valueOfSize(c, "w");
  882. break;
  883. case "trHeight":
  884. _this.parseTrHeight(c, style);
  885. break;
  886. case "strike":
  887. style["text-decoration"] = values.valueOfStrike(c);
  888. break;
  889. case "b":
  890. style["font-weight"] = values.valueOfBold(c);
  891. break;
  892. case "i":
  893. style["font-style"] = "italic";
  894. break;
  895. case "u":
  896. _this.parseUnderline(c, style);
  897. break;
  898. case "ind":
  899. case "tblInd":
  900. _this.parseIndentation(c, style);
  901. break;
  902. case "rFonts":
  903. _this.parseFont(c, style);
  904. break;
  905. case "tblBorders":
  906. _this.parseBorderProperties(c, childStyle || style);
  907. break;
  908. case "tblCellSpacing":
  909. style["border-spacing"] = values.valueOfMargin(c);
  910. style["border-collapse"] = "separate";
  911. break;
  912. case "pBdr":
  913. _this.parseBorderProperties(c, style);
  914. break;
  915. case "bdr":
  916. style["border"] = values.valueOfBorder(c);
  917. break;
  918. case "tcBorders":
  919. _this.parseBorderProperties(c, style);
  920. break;
  921. case "noWrap":
  922. break;
  923. case "tblCellMar":
  924. case "tcMar":
  925. _this.parseMarginProperties(c, childStyle || style);
  926. break;
  927. case "tblLayout":
  928. style["table-layout"] = values.valueOfTblLayout(c);
  929. break;
  930. case "vAlign":
  931. style["vertical-align"] = values.valueOfTextAlignment(c);
  932. break;
  933. case "spacing":
  934. if (elem.localName == "pPr")
  935. _this.parseSpacing(c, style);
  936. break;
  937. case "lang":
  938. case "noProof":
  939. case "webHidden":
  940. break;
  941. default:
  942. if (handler != null && !handler(c))
  943. _this.debug && console.warn("DOCX: Unknown document element: " + c.localName);
  944. break;
  945. }
  946. });
  947. return style;
  948. };
  949. DocumentParser.prototype.parseUnderline = function (node, style) {
  950. var val = xml.stringAttr(node, "val");
  951. if (val == null || val == "none")
  952. return;
  953. switch (val) {
  954. case "dash":
  955. case "dashDotDotHeavy":
  956. case "dashDotHeavy":
  957. case "dashedHeavy":
  958. case "dashLong":
  959. case "dashLongHeavy":
  960. case "dotDash":
  961. case "dotDotDash":
  962. style["text-decoration-style"] = "dashed";
  963. break;
  964. case "dotted":
  965. case "dottedHeavy":
  966. style["text-decoration-style"] = "dotted";
  967. break;
  968. case "double":
  969. style["text-decoration-style"] = "double";
  970. break;
  971. case "single":
  972. case "thick":
  973. style["text-decoration"] = "underline";
  974. break;
  975. case "wave":
  976. case "wavyDouble":
  977. case "wavyHeavy":
  978. style["text-decoration-style"] = "wavy";
  979. break;
  980. case "words":
  981. style["text-decoration"] = "underline";
  982. break;
  983. }
  984. var col = xml.colorAttr(node, "color");
  985. if (col)
  986. style["text-decoration-color"] = col;
  987. };
  988. DocumentParser.prototype.parseFont = function (node, style) {
  989. var ascii = xml.stringAttr(node, "ascii");
  990. if (ascii)
  991. style["font-family"] = ascii;
  992. };
  993. DocumentParser.prototype.parseIndentation = function (node, style) {
  994. var firstLine = xml.sizeAttr(node, "firstLine");
  995. var hanging = xml.sizeAttr(node, "hanging");
  996. var left = xml.sizeAttr(node, "left");
  997. var start = xml.sizeAttr(node, "start");
  998. var right = xml.sizeAttr(node, "right");
  999. var end = xml.sizeAttr(node, "end");
  1000. if (firstLine)
  1001. style["text-indent"] = firstLine;
  1002. if (hanging)
  1003. style["text-indent"] = "-" + hanging;
  1004. if (left || start)
  1005. style["margin-left"] = left || start;
  1006. if (right || end)
  1007. style["margin-right"] = right || end;
  1008. };
  1009. DocumentParser.prototype.parseSpacing = function (node, style) {
  1010. var before = xml.sizeAttr(node, "before");
  1011. var after = xml.sizeAttr(node, "after");
  1012. var line = xml.intAttr(node, "line", null);
  1013. var lineRule = xml.stringAttr(node, "lineRule");
  1014. if (before)
  1015. style["margin-top"] = before;
  1016. if (after)
  1017. style["margin-bottom"] = after;
  1018. if (line !== null) {
  1019. switch (lineRule) {
  1020. case "auto":
  1021. style["line-height"] = "" + (line / 240).toFixed(2);
  1022. break;
  1023. case "atLeast":
  1024. style["line-height"] = "calc(100% + " + line / 20 + "pt)";
  1025. break;
  1026. default:
  1027. style["line-height"] = style["min-height"] = line / 20 + "pt";
  1028. break;
  1029. }
  1030. }
  1031. };
  1032. DocumentParser.prototype.parseMarginProperties = function (node, output) {
  1033. xml.foreach(node, function (c) {
  1034. switch (c.localName) {
  1035. case "left":
  1036. output["padding-left"] = values.valueOfMargin(c);
  1037. break;
  1038. case "right":
  1039. output["padding-right"] = values.valueOfMargin(c);
  1040. break;
  1041. case "top":
  1042. output["padding-top"] = values.valueOfMargin(c);
  1043. break;
  1044. case "bottom":
  1045. output["padding-bottom"] = values.valueOfMargin(c);
  1046. break;
  1047. }
  1048. });
  1049. };
  1050. DocumentParser.prototype.parseTrHeight = function (node, output) {
  1051. switch (xml.stringAttr(node, "hRule")) {
  1052. case "exact":
  1053. output["height"] = xml.sizeAttr(node, "val");
  1054. break;
  1055. case "atLeast":
  1056. default:
  1057. output["height"] = xml.sizeAttr(node, "val");
  1058. break;
  1059. }
  1060. };
  1061. DocumentParser.prototype.parseBorderProperties = function (node, output) {
  1062. xml.foreach(node, function (c) {
  1063. switch (c.localName) {
  1064. case "start":
  1065. case "left":
  1066. output["border-left"] = values.valueOfBorder(c);
  1067. break;
  1068. case "end":
  1069. case "right":
  1070. output["border-right"] = values.valueOfBorder(c);
  1071. break;
  1072. case "top":
  1073. output["border-top"] = values.valueOfBorder(c);
  1074. break;
  1075. case "bottom":
  1076. output["border-bottom"] = values.valueOfBorder(c);
  1077. break;
  1078. }
  1079. });
  1080. };
  1081. return DocumentParser;
  1082. }());
  1083. exports.DocumentParser = DocumentParser;
  1084. var SizeType;
  1085. (function (SizeType) {
  1086. SizeType[SizeType["FontSize"] = 0] = "FontSize";
  1087. SizeType[SizeType["Dxa"] = 1] = "Dxa";
  1088. SizeType[SizeType["Emu"] = 2] = "Emu";
  1089. SizeType[SizeType["Border"] = 3] = "Border";
  1090. SizeType[SizeType["Percent"] = 4] = "Percent";
  1091. })(SizeType || (SizeType = {}));
  1092. var xml = (function () {
  1093. function xml() {
  1094. }
  1095. xml.foreach = function (node, cb) {
  1096. for (var i = 0; i < node.childNodes.length; i++) {
  1097. var n = node.childNodes[i];
  1098. if (n.nodeType == 1)
  1099. cb(n);
  1100. }
  1101. };
  1102. xml.elementStringAttr = function (elem, nodeName, attrName) {
  1103. var n = xml_parser_1.default.element(elem, nodeName);
  1104. return n ? xml.stringAttr(n, attrName) : null;
  1105. };
  1106. xml.stringAttr = function (node, attrName) {
  1107. return xml_parser_1.default.attr(node, attrName);
  1108. };
  1109. xml.colorAttr = function (node, attrName, defValue, autoColor) {
  1110. if (defValue === void 0) { defValue = null; }
  1111. if (autoColor === void 0) { autoColor = 'black'; }
  1112. var v = xml.stringAttr(node, attrName);
  1113. switch (v) {
  1114. case "yellow":
  1115. return v;
  1116. case "auto":
  1117. return autoColor;
  1118. }
  1119. return v ? "#" + v : defValue;
  1120. };
  1121. xml.boolAttr = function (node, attrName, defValue) {
  1122. if (defValue === void 0) { defValue = false; }
  1123. return xml_parser_1.default.boolAttr(node, attrName, defValue);
  1124. };
  1125. xml.intAttr = function (node, attrName, defValue) {
  1126. if (defValue === void 0) { defValue = 0; }
  1127. var val = xml.stringAttr(node, attrName);
  1128. return val ? parseInt(xml.stringAttr(node, attrName)) : defValue;
  1129. };
  1130. xml.sizeAttr = function (node, attrName, type) {
  1131. if (type === void 0) { type = SizeType.Dxa; }
  1132. return xml.convertSize(xml.stringAttr(node, attrName), type);
  1133. };
  1134. xml.sizeValue = function (node, type) {
  1135. if (type === void 0) { type = SizeType.Dxa; }
  1136. return xml.convertSize(node.textContent, type);
  1137. };
  1138. xml.convertSize = function (val, type) {
  1139. if (type === void 0) { type = SizeType.Dxa; }
  1140. if (val == null || /.+p[xt]$/.test(val))
  1141. return val;
  1142. var intVal = parseInt(val);
  1143. switch (type) {
  1144. case SizeType.Dxa: return (0.05 * intVal).toFixed(2) + "pt";
  1145. case SizeType.Emu: return (intVal / 12700).toFixed(2) + "pt";
  1146. case SizeType.FontSize: return (0.5 * intVal).toFixed(2) + "pt";
  1147. case SizeType.Border: return (0.125 * intVal).toFixed(2) + "pt";
  1148. case SizeType.Percent: return (0.02 * intVal).toFixed(2) + "%";
  1149. }
  1150. return val;
  1151. };
  1152. xml.className = function (node, attrName) {
  1153. var val = xml.stringAttr(node, attrName);
  1154. return val && val.replace(/[ .]+/g, '-').replace(/[&]+/g, 'and');
  1155. };
  1156. return xml;
  1157. }());
  1158. var values = (function () {
  1159. function values() {
  1160. }
  1161. values.valueOfBold = function (c) {
  1162. return xml.boolAttr(c, "val", true) ? "bold" : "normal";
  1163. };
  1164. values.valueOfSize = function (c, attr) {
  1165. var type = SizeType.Dxa;
  1166. switch (xml.stringAttr(c, "type")) {
  1167. case "dxa": break;
  1168. case "pct":
  1169. type = SizeType.Percent;
  1170. break;
  1171. }
  1172. return xml.sizeAttr(c, attr, type);
  1173. };
  1174. values.valueOfStrike = function (c) {
  1175. return xml.boolAttr(c, "val", true) ? "line-through" : "none";
  1176. };
  1177. values.valueOfMargin = function (c) {
  1178. return xml.sizeAttr(c, "w");
  1179. };
  1180. values.valueOfBorder = function (c) {
  1181. var type = xml.stringAttr(c, "val");
  1182. if (type == "nil")
  1183. return "none";
  1184. var color = xml.colorAttr(c, "color");
  1185. var size = xml.sizeAttr(c, "sz", SizeType.Border);
  1186. return size + " solid " + (color == "auto" ? "black" : color);
  1187. };
  1188. values.valueOfTblLayout = function (c) {
  1189. var type = xml.stringAttr(c, "val");
  1190. return type == "fixed" ? "fixed" : "auto";
  1191. };
  1192. values.classNameOfCnfStyle = function (c) {
  1193. var className = "";
  1194. var val = xml.stringAttr(c, "val");
  1195. if (val[0] == "1")
  1196. className += " first-row";
  1197. if (val[1] == "1")
  1198. className += " last-row";
  1199. if (val[2] == "1")
  1200. className += " first-col";
  1201. if (val[3] == "1")
  1202. className += " last-col";
  1203. if (val[4] == "1")
  1204. className += " odd-col";
  1205. if (val[5] == "1")
  1206. className += " even-col";
  1207. if (val[6] == "1")
  1208. className += " odd-row";
  1209. if (val[7] == "1")
  1210. className += " even-row";
  1211. if (val[8] == "1")
  1212. className += " ne-cell";
  1213. if (val[9] == "1")
  1214. className += " nw-cell";
  1215. if (val[10] == "1")
  1216. className += " se-cell";
  1217. if (val[11] == "1")
  1218. className += " sw-cell";
  1219. return className.trim();
  1220. };
  1221. values.valueOfJc = function (c) {
  1222. var type = xml.stringAttr(c, "val");
  1223. switch (type) {
  1224. case "start":
  1225. case "left": return "left";
  1226. case "center": return "center";
  1227. case "end":
  1228. case "right": return "right";
  1229. case "both": return "justify";
  1230. }
  1231. return type;
  1232. };
  1233. values.valueOfTextAlignment = function (c) {
  1234. var type = xml.stringAttr(c, "val");
  1235. switch (type) {
  1236. case "auto":
  1237. case "baseline": return "baseline";
  1238. case "top": return "top";
  1239. case "center": return "middle";
  1240. case "bottom": return "bottom";
  1241. }
  1242. return type;
  1243. };
  1244. values.addSize = function (a, b) {
  1245. if (a == null)
  1246. return b;
  1247. if (b == null)
  1248. return a;
  1249. return "calc(" + a + " + " + b + ")";
  1250. };
  1251. values.checkMask = function (num, mask) {
  1252. return (num & mask) == mask;
  1253. };
  1254. values.classNameOftblLook = function (c) {
  1255. var className = "";
  1256. if (xml.boolAttr(c, "firstColumn"))
  1257. className += " first-col";
  1258. if (xml.boolAttr(c, "firstRow"))
  1259. className += " first-row";
  1260. if (xml.boolAttr(c, "lastColumn"))
  1261. className += " lat-col";
  1262. if (xml.boolAttr(c, "lastRow"))
  1263. className += " last-row";
  1264. if (xml.boolAttr(c, "noHBand"))
  1265. className += " no-hband";
  1266. if (xml.boolAttr(c, "noVBand"))
  1267. className += " no-vband";
  1268. return className.trim();
  1269. };
  1270. return values;
  1271. }());
  1272. /***/ }),
  1273. /***/ "./src/document-props/core-props-part.ts":
  1274. /*!***********************************************!*\
  1275. !*** ./src/document-props/core-props-part.ts ***!
  1276. \***********************************************/
  1277. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1278. var __extends = (this && this.__extends) || (function () {
  1279. var extendStatics = function (d, b) {
  1280. extendStatics = Object.setPrototypeOf ||
  1281. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1282. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  1283. return extendStatics(d, b);
  1284. };
  1285. return function (d, b) {
  1286. if (typeof b !== "function" && b !== null)
  1287. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  1288. extendStatics(d, b);
  1289. function __() { this.constructor = d; }
  1290. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1291. };
  1292. })();
  1293. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1294. exports.CorePropsPart = void 0;
  1295. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  1296. var core_props_1 = __webpack_require__(/*! ./core-props */ "./src/document-props/core-props.ts");
  1297. var CorePropsPart = (function (_super) {
  1298. __extends(CorePropsPart, _super);
  1299. function CorePropsPart() {
  1300. return _super !== null && _super.apply(this, arguments) || this;
  1301. }
  1302. CorePropsPart.prototype.parseXml = function (root) {
  1303. this.props = (0, core_props_1.parseCoreProps)(root, this._package.xmlParser);
  1304. };
  1305. return CorePropsPart;
  1306. }(part_1.Part));
  1307. exports.CorePropsPart = CorePropsPart;
  1308. /***/ }),
  1309. /***/ "./src/document-props/core-props.ts":
  1310. /*!******************************************!*\
  1311. !*** ./src/document-props/core-props.ts ***!
  1312. \******************************************/
  1313. /***/ ((__unused_webpack_module, exports) => {
  1314. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1315. exports.parseCoreProps = void 0;
  1316. function parseCoreProps(root, xmlParser) {
  1317. var result = {};
  1318. for (var _i = 0, _a = xmlParser.elements(root); _i < _a.length; _i++) {
  1319. var el = _a[_i];
  1320. switch (el.localName) {
  1321. case "title":
  1322. result.title = el.textContent;
  1323. break;
  1324. case "description":
  1325. result.description = el.textContent;
  1326. break;
  1327. case "subject":
  1328. result.subject = el.textContent;
  1329. break;
  1330. case "creator":
  1331. result.creator = el.textContent;
  1332. break;
  1333. case "keywords":
  1334. result.keywords = el.textContent;
  1335. break;
  1336. case "language":
  1337. result.language = el.textContent;
  1338. break;
  1339. case "lastModifiedBy":
  1340. result.lastModifiedBy = el.textContent;
  1341. break;
  1342. case "revision":
  1343. el.textContent && (result.revision = parseInt(el.textContent));
  1344. break;
  1345. }
  1346. }
  1347. return result;
  1348. }
  1349. exports.parseCoreProps = parseCoreProps;
  1350. /***/ }),
  1351. /***/ "./src/document-props/extended-props-part.ts":
  1352. /*!***************************************************!*\
  1353. !*** ./src/document-props/extended-props-part.ts ***!
  1354. \***************************************************/
  1355. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1356. var __extends = (this && this.__extends) || (function () {
  1357. var extendStatics = function (d, b) {
  1358. extendStatics = Object.setPrototypeOf ||
  1359. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1360. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  1361. return extendStatics(d, b);
  1362. };
  1363. return function (d, b) {
  1364. if (typeof b !== "function" && b !== null)
  1365. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  1366. extendStatics(d, b);
  1367. function __() { this.constructor = d; }
  1368. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1369. };
  1370. })();
  1371. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1372. exports.ExtendedPropsPart = void 0;
  1373. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  1374. var extended_props_1 = __webpack_require__(/*! ./extended-props */ "./src/document-props/extended-props.ts");
  1375. var ExtendedPropsPart = (function (_super) {
  1376. __extends(ExtendedPropsPart, _super);
  1377. function ExtendedPropsPart() {
  1378. return _super !== null && _super.apply(this, arguments) || this;
  1379. }
  1380. ExtendedPropsPart.prototype.parseXml = function (root) {
  1381. this.props = (0, extended_props_1.parseExtendedProps)(root, this._package.xmlParser);
  1382. };
  1383. return ExtendedPropsPart;
  1384. }(part_1.Part));
  1385. exports.ExtendedPropsPart = ExtendedPropsPart;
  1386. /***/ }),
  1387. /***/ "./src/document-props/extended-props.ts":
  1388. /*!**********************************************!*\
  1389. !*** ./src/document-props/extended-props.ts ***!
  1390. \**********************************************/
  1391. /***/ ((__unused_webpack_module, exports) => {
  1392. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1393. exports.parseExtendedProps = void 0;
  1394. function parseExtendedProps(root, xmlParser) {
  1395. var result = {};
  1396. for (var _i = 0, _a = xmlParser.elements(root); _i < _a.length; _i++) {
  1397. var el = _a[_i];
  1398. switch (el.localName) {
  1399. case "Template":
  1400. result.template = el.textContent;
  1401. break;
  1402. case "Pages":
  1403. result.pages = safeParseToInt(el.textContent);
  1404. break;
  1405. case "Words":
  1406. result.words = safeParseToInt(el.textContent);
  1407. break;
  1408. case "Characters":
  1409. result.characters = safeParseToInt(el.textContent);
  1410. break;
  1411. case "Application":
  1412. result.application = el.textContent;
  1413. break;
  1414. case "Lines":
  1415. result.lines = safeParseToInt(el.textContent);
  1416. break;
  1417. case "Paragraphs":
  1418. result.paragraphs = safeParseToInt(el.textContent);
  1419. break;
  1420. case "Company":
  1421. result.company = el.textContent;
  1422. break;
  1423. case "AppVersion":
  1424. result.appVersion = el.textContent;
  1425. break;
  1426. }
  1427. }
  1428. return result;
  1429. }
  1430. exports.parseExtendedProps = parseExtendedProps;
  1431. function safeParseToInt(value) {
  1432. if (typeof value === 'undefined')
  1433. return;
  1434. return parseInt(value);
  1435. }
  1436. /***/ }),
  1437. /***/ "./src/docx-preview.ts":
  1438. /*!*****************************!*\
  1439. !*** ./src/docx-preview.ts ***!
  1440. \*****************************/
  1441. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1442. var __assign = (this && this.__assign) || function () {
  1443. __assign = Object.assign || function(t) {
  1444. for (var s, i = 1, n = arguments.length; i < n; i++) {
  1445. s = arguments[i];
  1446. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  1447. t[p] = s[p];
  1448. }
  1449. return t;
  1450. };
  1451. return __assign.apply(this, arguments);
  1452. };
  1453. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1454. exports.renderAsync = void 0;
  1455. var word_document_1 = __webpack_require__(/*! ./word-document */ "./src/word-document.ts");
  1456. var document_parser_1 = __webpack_require__(/*! ./document-parser */ "./src/document-parser.ts");
  1457. var html_renderer_1 = __webpack_require__(/*! ./html-renderer */ "./src/html-renderer.ts");
  1458. function renderAsync(data, bodyContainer, styleContainer, userOptions) {
  1459. if (styleContainer === void 0) { styleContainer = null; }
  1460. if (userOptions === void 0) { userOptions = null; }
  1461. var parser = new document_parser_1.DocumentParser();
  1462. var renderer = new html_renderer_1.HtmlRenderer(window.document);
  1463. var options = __assign({ ignoreHeight: false, ignoreWidth: false, ignoreFonts: false, breakPages: true, debug: false, experimental: false, className: "docx", inWrapper: true, trimXmlDeclaration: true }, userOptions);
  1464. parser.ignoreWidth = options.ignoreWidth;
  1465. parser.debug = options.debug || parser.debug;
  1466. renderer.className = options.className || "docx";
  1467. renderer.inWrapper = options.inWrapper;
  1468. return word_document_1.WordDocument.load(data, parser, {
  1469. trimXmlDeclaration: options.trimXmlDeclaration
  1470. }).then(function (doc) {
  1471. renderer.render(doc, bodyContainer, styleContainer, options);
  1472. return doc;
  1473. });
  1474. }
  1475. exports.renderAsync = renderAsync;
  1476. /***/ }),
  1477. /***/ "./src/dom/bookmark.ts":
  1478. /*!*****************************!*\
  1479. !*** ./src/dom/bookmark.ts ***!
  1480. \*****************************/
  1481. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1482. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1483. exports.parseBookmarkEnd = exports.parseBookmarkStart = void 0;
  1484. var dom_1 = __webpack_require__(/*! ./dom */ "./src/dom/dom.ts");
  1485. function parseBookmarkStart(elem, xml) {
  1486. return {
  1487. type: dom_1.DomType.BookmarkStart,
  1488. id: xml.attr(elem, "id"),
  1489. name: xml.attr(elem, "name"),
  1490. colFirst: xml.intAttr(elem, "colFirst"),
  1491. colLast: xml.intAttr(elem, "colLast")
  1492. };
  1493. }
  1494. exports.parseBookmarkStart = parseBookmarkStart;
  1495. function parseBookmarkEnd(elem, xml) {
  1496. return {
  1497. type: dom_1.DomType.BookmarkEnd,
  1498. id: xml.attr(elem, "id")
  1499. };
  1500. }
  1501. exports.parseBookmarkEnd = parseBookmarkEnd;
  1502. /***/ }),
  1503. /***/ "./src/dom/common.ts":
  1504. /*!***************************!*\
  1505. !*** ./src/dom/common.ts ***!
  1506. \***************************/
  1507. /***/ ((__unused_webpack_module, exports) => {
  1508. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1509. exports.parseCommonProperty = exports.convertLength = exports.LengthUsage = exports.ns = void 0;
  1510. exports.ns = {
  1511. wordml: "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  1512. };
  1513. exports.LengthUsage = {
  1514. Dxa: { mul: 0.05, unit: "pt" },
  1515. Emu: { mul: 1 / 12700, unit: "pt" },
  1516. FontSize: { mul: 0.5, unit: "pt" },
  1517. Border: { mul: 0.125, unit: "pt" },
  1518. Point: { mul: 1, unit: "pt" },
  1519. Percent: { mul: 0.02, unit: "%" },
  1520. LineHeight: { mul: 1 / 240, unit: null }
  1521. };
  1522. function convertLength(val, usage) {
  1523. if (usage === void 0) { usage = exports.LengthUsage.Dxa; }
  1524. return val ? { value: parseInt(val) * usage.mul, type: usage.unit } : null;
  1525. }
  1526. exports.convertLength = convertLength;
  1527. function parseCommonProperty(elem, props, xml) {
  1528. if (elem.namespaceURI != exports.ns.wordml)
  1529. return false;
  1530. switch (elem.localName) {
  1531. case "color":
  1532. props.color = xml.attr(elem, "val");
  1533. break;
  1534. case "sz":
  1535. props.fontSize = xml.lengthAttr(elem, "val", exports.LengthUsage.FontSize);
  1536. break;
  1537. default:
  1538. return false;
  1539. }
  1540. return true;
  1541. }
  1542. exports.parseCommonProperty = parseCommonProperty;
  1543. /***/ }),
  1544. /***/ "./src/dom/document-part.ts":
  1545. /*!**********************************!*\
  1546. !*** ./src/dom/document-part.ts ***!
  1547. \**********************************/
  1548. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1549. var __extends = (this && this.__extends) || (function () {
  1550. var extendStatics = function (d, b) {
  1551. extendStatics = Object.setPrototypeOf ||
  1552. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1553. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  1554. return extendStatics(d, b);
  1555. };
  1556. return function (d, b) {
  1557. if (typeof b !== "function" && b !== null)
  1558. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  1559. extendStatics(d, b);
  1560. function __() { this.constructor = d; }
  1561. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1562. };
  1563. })();
  1564. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1565. exports.DocumentPart = void 0;
  1566. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  1567. var DocumentPart = (function (_super) {
  1568. __extends(DocumentPart, _super);
  1569. function DocumentPart(pkg, path, parser) {
  1570. var _this = _super.call(this, pkg, path) || this;
  1571. _this._documentParser = parser;
  1572. return _this;
  1573. }
  1574. DocumentPart.prototype.parseXml = function (root) {
  1575. this.body = this._documentParser.parseDocumentFile(root);
  1576. };
  1577. return DocumentPart;
  1578. }(part_1.Part));
  1579. exports.DocumentPart = DocumentPart;
  1580. /***/ }),
  1581. /***/ "./src/dom/dom.ts":
  1582. /*!************************!*\
  1583. !*** ./src/dom/dom.ts ***!
  1584. \************************/
  1585. /***/ ((__unused_webpack_module, exports) => {
  1586. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1587. exports.DomType = void 0;
  1588. var DomType;
  1589. (function (DomType) {
  1590. DomType["Document"] = "document";
  1591. DomType["Paragraph"] = "paragraph";
  1592. DomType["Run"] = "run";
  1593. DomType["Break"] = "break";
  1594. DomType["Table"] = "table";
  1595. DomType["Row"] = "row";
  1596. DomType["Cell"] = "cell";
  1597. DomType["Hyperlink"] = "hyperlink";
  1598. DomType["Drawing"] = "drawing";
  1599. DomType["Image"] = "image";
  1600. DomType["Text"] = "text";
  1601. DomType["Tab"] = "tab";
  1602. DomType["Symbol"] = "symbol";
  1603. DomType["BookmarkStart"] = "bookmarkStart";
  1604. DomType["BookmarkEnd"] = "bookmarkEnd";
  1605. DomType["Footer"] = "footer";
  1606. DomType["Header"] = "header";
  1607. })(DomType = exports.DomType || (exports.DomType = {}));
  1608. /***/ }),
  1609. /***/ "./src/dom/line-spacing.ts":
  1610. /*!*********************************!*\
  1611. !*** ./src/dom/line-spacing.ts ***!
  1612. \*********************************/
  1613. /***/ ((__unused_webpack_module, exports) => {
  1614. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1615. exports.parseLineSpacing = void 0;
  1616. function parseLineSpacing(elem, xml) {
  1617. return {
  1618. before: xml.lengthAttr(elem, "before"),
  1619. after: xml.lengthAttr(elem, "after"),
  1620. line: xml.intAttr(elem, "line"),
  1621. lineRule: xml.attr(elem, "lineRule")
  1622. };
  1623. }
  1624. exports.parseLineSpacing = parseLineSpacing;
  1625. /***/ }),
  1626. /***/ "./src/dom/paragraph.ts":
  1627. /*!******************************!*\
  1628. !*** ./src/dom/paragraph.ts ***!
  1629. \******************************/
  1630. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1631. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1632. exports.parseNumbering = exports.parseTabs = exports.parseParagraphProperty = exports.parseParagraphProperties = void 0;
  1633. var common_1 = __webpack_require__(/*! ./common */ "./src/dom/common.ts");
  1634. var section_1 = __webpack_require__(/*! ./section */ "./src/dom/section.ts");
  1635. var line_spacing_1 = __webpack_require__(/*! ./line-spacing */ "./src/dom/line-spacing.ts");
  1636. var run_1 = __webpack_require__(/*! ./run */ "./src/dom/run.ts");
  1637. function parseParagraphProperties(elem, xml) {
  1638. var result = {};
  1639. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  1640. var el = _a[_i];
  1641. parseParagraphProperty(el, result, xml);
  1642. }
  1643. return result;
  1644. }
  1645. exports.parseParagraphProperties = parseParagraphProperties;
  1646. function parseParagraphProperty(elem, props, xml) {
  1647. if (elem.namespaceURI != common_1.ns.wordml)
  1648. return false;
  1649. if ((0, common_1.parseCommonProperty)(elem, props, xml))
  1650. return true;
  1651. switch (elem.localName) {
  1652. case "tabs":
  1653. props.tabs = parseTabs(elem, xml);
  1654. break;
  1655. case "sectPr":
  1656. props.sectionProps = (0, section_1.parseSectionProperties)(elem, xml);
  1657. break;
  1658. case "numPr":
  1659. props.numbering = parseNumbering(elem, xml);
  1660. break;
  1661. case "spacing":
  1662. props.lineSpacing = (0, line_spacing_1.parseLineSpacing)(elem, xml);
  1663. return false;
  1664. break;
  1665. case "textAlignment":
  1666. props.textAlignment = xml.attr(elem, "val");
  1667. return false;
  1668. break;
  1669. case "keepNext":
  1670. props.keepLines = xml.boolAttr(elem, "val", true);
  1671. break;
  1672. case "keepNext":
  1673. props.keepNext = xml.boolAttr(elem, "val", true);
  1674. break;
  1675. case "pageBreakBefore":
  1676. props.pageBreakBefore = xml.boolAttr(elem, "val", true);
  1677. break;
  1678. case "outlineLvl":
  1679. props.outlineLevel = xml.intAttr(elem, "val");
  1680. break;
  1681. case "pStyle":
  1682. props.styleName = xml.attr(elem, "val");
  1683. break;
  1684. case "rPr":
  1685. props.runProps = (0, run_1.parseRunProperties)(elem, xml);
  1686. break;
  1687. default:
  1688. return false;
  1689. }
  1690. return true;
  1691. }
  1692. exports.parseParagraphProperty = parseParagraphProperty;
  1693. function parseTabs(elem, xml) {
  1694. return xml.elements(elem, "tab")
  1695. .map(function (e) { return ({
  1696. position: xml.lengthAttr(e, "pos"),
  1697. leader: xml.attr(e, "leader"),
  1698. style: xml.attr(e, "val")
  1699. }); });
  1700. }
  1701. exports.parseTabs = parseTabs;
  1702. function parseNumbering(elem, xml) {
  1703. var result = {};
  1704. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  1705. var e = _a[_i];
  1706. switch (e.localName) {
  1707. case "numId":
  1708. result.id = xml.attr(e, "val");
  1709. break;
  1710. case "ilvl":
  1711. result.level = xml.intAttr(e, "val");
  1712. break;
  1713. }
  1714. }
  1715. return result;
  1716. }
  1717. exports.parseNumbering = parseNumbering;
  1718. /***/ }),
  1719. /***/ "./src/dom/run.ts":
  1720. /*!************************!*\
  1721. !*** ./src/dom/run.ts ***!
  1722. \************************/
  1723. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1724. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1725. exports.parseRunProperty = exports.parseRunProperties = void 0;
  1726. var common_1 = __webpack_require__(/*! ./common */ "./src/dom/common.ts");
  1727. function parseRunProperties(elem, xml) {
  1728. var result = {};
  1729. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  1730. var el = _a[_i];
  1731. parseRunProperty(el, result, xml);
  1732. }
  1733. return result;
  1734. }
  1735. exports.parseRunProperties = parseRunProperties;
  1736. function parseRunProperty(elem, props, xml) {
  1737. if ((0, common_1.parseCommonProperty)(elem, props, xml))
  1738. return true;
  1739. return false;
  1740. }
  1741. exports.parseRunProperty = parseRunProperty;
  1742. /***/ }),
  1743. /***/ "./src/dom/section.ts":
  1744. /*!****************************!*\
  1745. !*** ./src/dom/section.ts ***!
  1746. \****************************/
  1747. /***/ ((__unused_webpack_module, exports) => {
  1748. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1749. exports.parseSectionProperties = exports.SectionType = void 0;
  1750. var SectionType;
  1751. (function (SectionType) {
  1752. SectionType["Continuous"] = "continuous";
  1753. SectionType["NextPage"] = "nextPage";
  1754. SectionType["NextColumn"] = "nextColumn";
  1755. SectionType["EvenPage"] = "evenPage";
  1756. SectionType["OddPage"] = "oddPage";
  1757. })(SectionType = exports.SectionType || (exports.SectionType = {}));
  1758. function parseSectionProperties(elem, xml) {
  1759. var section = {};
  1760. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  1761. var e = _a[_i];
  1762. switch (e.localName) {
  1763. case "pgSz":
  1764. section.pageSize = {
  1765. width: xml.lengthAttr(e, "w"),
  1766. height: xml.lengthAttr(e, "h"),
  1767. orientation: xml.attr(e, "orient")
  1768. };
  1769. break;
  1770. case "type":
  1771. section.type = xml.attr(e, "val");
  1772. break;
  1773. case "pgMar":
  1774. section.pageMargins = {
  1775. left: xml.lengthAttr(e, "left"),
  1776. right: xml.lengthAttr(e, "right"),
  1777. top: xml.lengthAttr(e, "top"),
  1778. bottom: xml.lengthAttr(e, "bottom"),
  1779. header: xml.lengthAttr(e, "header"),
  1780. footer: xml.lengthAttr(e, "footer"),
  1781. gutter: xml.lengthAttr(e, "gutter"),
  1782. };
  1783. break;
  1784. case "cols":
  1785. section.columns = parseColumns(e, xml);
  1786. break;
  1787. }
  1788. }
  1789. return section;
  1790. }
  1791. exports.parseSectionProperties = parseSectionProperties;
  1792. function parseColumns(elem, xml) {
  1793. return {
  1794. numberOfColumns: xml.intAttr(elem, "num"),
  1795. space: xml.lengthAttr(elem, "space"),
  1796. separator: xml.boolAttr(elem, "sep"),
  1797. equalWidth: xml.boolAttr(elem, "equalWidth", true),
  1798. columns: xml.elements(elem, "col")
  1799. .map(function (e) { return ({
  1800. width: xml.lengthAttr(e, "w"),
  1801. space: xml.lengthAttr(e, "space")
  1802. }); })
  1803. };
  1804. }
  1805. /***/ }),
  1806. /***/ "./src/font-table/font-table.ts":
  1807. /*!**************************************!*\
  1808. !*** ./src/font-table/font-table.ts ***!
  1809. \**************************************/
  1810. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1811. var __extends = (this && this.__extends) || (function () {
  1812. var extendStatics = function (d, b) {
  1813. extendStatics = Object.setPrototypeOf ||
  1814. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1815. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  1816. return extendStatics(d, b);
  1817. };
  1818. return function (d, b) {
  1819. if (typeof b !== "function" && b !== null)
  1820. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  1821. extendStatics(d, b);
  1822. function __() { this.constructor = d; }
  1823. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1824. };
  1825. })();
  1826. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1827. exports.FontTablePart = void 0;
  1828. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  1829. var fonts_1 = __webpack_require__(/*! ./fonts */ "./src/font-table/fonts.ts");
  1830. var FontTablePart = (function (_super) {
  1831. __extends(FontTablePart, _super);
  1832. function FontTablePart() {
  1833. return _super !== null && _super.apply(this, arguments) || this;
  1834. }
  1835. FontTablePart.prototype.parseXml = function (root) {
  1836. this.fonts = (0, fonts_1.parseFonts)(root, this._package.xmlParser);
  1837. };
  1838. return FontTablePart;
  1839. }(part_1.Part));
  1840. exports.FontTablePart = FontTablePart;
  1841. /***/ }),
  1842. /***/ "./src/font-table/fonts.ts":
  1843. /*!*********************************!*\
  1844. !*** ./src/font-table/fonts.ts ***!
  1845. \*********************************/
  1846. /***/ ((__unused_webpack_module, exports) => {
  1847. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1848. exports.parseFont = exports.parseFonts = void 0;
  1849. function parseFonts(root, xmlParser) {
  1850. return xmlParser.elements(root).map(function (el) { return parseFont(el, xmlParser); });
  1851. }
  1852. exports.parseFonts = parseFonts;
  1853. function parseFont(elem, xmlParser) {
  1854. var result = {
  1855. name: xmlParser.attr(elem, "name")
  1856. };
  1857. for (var _i = 0, _a = xmlParser.elements(elem); _i < _a.length; _i++) {
  1858. var el = _a[_i];
  1859. switch (el.localName) {
  1860. case "family":
  1861. result.family = xmlParser.attr(el, "val");
  1862. break;
  1863. case "altName":
  1864. result.altName = xmlParser.attr(el, "val");
  1865. break;
  1866. case "embedRegular":
  1867. result.fontKey = xmlParser.attr(el, "fontKey");
  1868. result.refId = xmlParser.attr(el, "id");
  1869. break;
  1870. }
  1871. }
  1872. return result;
  1873. }
  1874. exports.parseFont = parseFont;
  1875. /***/ }),
  1876. /***/ "./src/footer/footer-part.ts":
  1877. /*!***********************************!*\
  1878. !*** ./src/footer/footer-part.ts ***!
  1879. \***********************************/
  1880. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1881. var __extends = (this && this.__extends) || (function () {
  1882. var extendStatics = function (d, b) {
  1883. extendStatics = Object.setPrototypeOf ||
  1884. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1885. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  1886. return extendStatics(d, b);
  1887. };
  1888. return function (d, b) {
  1889. if (typeof b !== "function" && b !== null)
  1890. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  1891. extendStatics(d, b);
  1892. function __() { this.constructor = d; }
  1893. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1894. };
  1895. })();
  1896. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1897. exports.FooterPart = void 0;
  1898. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  1899. var FooterPart = (function (_super) {
  1900. __extends(FooterPart, _super);
  1901. function FooterPart(pkg, path, parser) {
  1902. var _this = _super.call(this, pkg, path) || this;
  1903. _this._documentParser = parser;
  1904. return _this;
  1905. }
  1906. FooterPart.prototype.parseXml = function (root) {
  1907. this.footerElement = this._documentParser.parseFooter(root);
  1908. };
  1909. return FooterPart;
  1910. }(part_1.Part));
  1911. exports.FooterPart = FooterPart;
  1912. /***/ }),
  1913. /***/ "./src/footer/footer.ts":
  1914. /*!******************************!*\
  1915. !*** ./src/footer/footer.ts ***!
  1916. \******************************/
  1917. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1918. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1919. exports.WmlFooter = void 0;
  1920. var dom_1 = __webpack_require__(/*! ../dom/dom */ "./src/dom/dom.ts");
  1921. var WmlFooter = (function () {
  1922. function WmlFooter() {
  1923. this.type = dom_1.DomType.Footer;
  1924. this.children = [];
  1925. this.cssStyle = {};
  1926. }
  1927. return WmlFooter;
  1928. }());
  1929. exports.WmlFooter = WmlFooter;
  1930. /***/ }),
  1931. /***/ "./src/header/header-part.ts":
  1932. /*!***********************************!*\
  1933. !*** ./src/header/header-part.ts ***!
  1934. \***********************************/
  1935. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1936. var __extends = (this && this.__extends) || (function () {
  1937. var extendStatics = function (d, b) {
  1938. extendStatics = Object.setPrototypeOf ||
  1939. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1940. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  1941. return extendStatics(d, b);
  1942. };
  1943. return function (d, b) {
  1944. if (typeof b !== "function" && b !== null)
  1945. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  1946. extendStatics(d, b);
  1947. function __() { this.constructor = d; }
  1948. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1949. };
  1950. })();
  1951. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1952. exports.HeaderPart = void 0;
  1953. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  1954. var HeaderPart = (function (_super) {
  1955. __extends(HeaderPart, _super);
  1956. function HeaderPart(pkg, path, parser) {
  1957. var _this = _super.call(this, pkg, path) || this;
  1958. _this._documentParser = parser;
  1959. return _this;
  1960. }
  1961. HeaderPart.prototype.parseXml = function (root) {
  1962. this.headerElement = this._documentParser.parseHeader(root);
  1963. };
  1964. return HeaderPart;
  1965. }(part_1.Part));
  1966. exports.HeaderPart = HeaderPart;
  1967. /***/ }),
  1968. /***/ "./src/header/header.ts":
  1969. /*!******************************!*\
  1970. !*** ./src/header/header.ts ***!
  1971. \******************************/
  1972. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1973. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1974. exports.WmlHeader = void 0;
  1975. var dom_1 = __webpack_require__(/*! ../dom/dom */ "./src/dom/dom.ts");
  1976. var WmlHeader = (function () {
  1977. function WmlHeader() {
  1978. this.type = dom_1.DomType.Header;
  1979. this.children = [];
  1980. this.cssStyle = {};
  1981. }
  1982. return WmlHeader;
  1983. }());
  1984. exports.WmlHeader = WmlHeader;
  1985. /***/ }),
  1986. /***/ "./src/html-renderer.ts":
  1987. /*!******************************!*\
  1988. !*** ./src/html-renderer.ts ***!
  1989. \******************************/
  1990. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1991. var __assign = (this && this.__assign) || function () {
  1992. __assign = Object.assign || function(t) {
  1993. for (var s, i = 1, n = arguments.length; i < n; i++) {
  1994. s = arguments[i];
  1995. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  1996. t[p] = s[p];
  1997. }
  1998. return t;
  1999. };
  2000. return __assign.apply(this, arguments);
  2001. };
  2002. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2003. exports.HtmlRenderer = void 0;
  2004. var dom_1 = __webpack_require__(/*! ./dom/dom */ "./src/dom/dom.ts");
  2005. var utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
  2006. var javascript_1 = __webpack_require__(/*! ./javascript */ "./src/javascript.ts");
  2007. var HtmlRenderer = (function () {
  2008. function HtmlRenderer(htmlDocument) {
  2009. this.htmlDocument = htmlDocument;
  2010. this.inWrapper = true;
  2011. this.className = "docx";
  2012. }
  2013. HtmlRenderer.prototype.render = function (document, bodyContainer, styleContainer, options) {
  2014. if (styleContainer === void 0) { styleContainer = null; }
  2015. this.document = document;
  2016. this.options = options;
  2017. this.styleMap = null;
  2018. styleContainer = styleContainer || bodyContainer;
  2019. removeAllElements(styleContainer);
  2020. removeAllElements(bodyContainer);
  2021. appendComment(styleContainer, "docxjs library predefined styles");
  2022. styleContainer.appendChild(this.renderDefaultStyle());
  2023. if (document.stylesPart != null) {
  2024. this.styleMap = this.processStyles(document.stylesPart.styles);
  2025. appendComment(styleContainer, "docx document styles");
  2026. styleContainer.appendChild(this.renderStyles(document.stylesPart.styles));
  2027. }
  2028. if (document.numberingPart) {
  2029. appendComment(styleContainer, "docx document numbering styles");
  2030. styleContainer.appendChild(this.renderNumbering(document.numberingPart.domNumberings, styleContainer));
  2031. }
  2032. if (!options.ignoreFonts && document.fontTablePart)
  2033. this.renderFontTable(document.fontTablePart, styleContainer);
  2034. var sectionElements = this.renderSections(document.documentPart.body);
  2035. if (this.inWrapper) {
  2036. var wrapper = this.renderWrapper();
  2037. appentElements(wrapper, sectionElements);
  2038. bodyContainer.appendChild(wrapper);
  2039. }
  2040. else {
  2041. appentElements(bodyContainer, sectionElements);
  2042. }
  2043. };
  2044. HtmlRenderer.prototype.renderFontTable = function (fontsPart, styleContainer) {
  2045. var _loop_1 = function (f) {
  2046. this_1.document.loadFont(f.refId, f.fontKey).then(function (fontData) {
  2047. var cssTest = "@font-face {\n font-family: \"" + f.name + "\";\n src: url(" + fontData + ");\n }";
  2048. appendComment(styleContainer, "Font " + f.name);
  2049. styleContainer.appendChild(createStyleElement(cssTest));
  2050. });
  2051. };
  2052. var this_1 = this;
  2053. for (var _i = 0, _a = fontsPart.fonts.filter(function (x) { return x.refId; }); _i < _a.length; _i++) {
  2054. var f = _a[_i];
  2055. _loop_1(f);
  2056. }
  2057. };
  2058. HtmlRenderer.prototype.processClassName = function (className) {
  2059. if (!className)
  2060. return this.className;
  2061. return this.className + "_" + className;
  2062. };
  2063. HtmlRenderer.prototype.processStyles = function (styles) {
  2064. var stylesMap = {};
  2065. for (var _i = 0, _a = styles.filter(function (x) { return x.id != null; }); _i < _a.length; _i++) {
  2066. var style = _a[_i];
  2067. stylesMap[style.id] = style;
  2068. }
  2069. for (var _b = 0, _c = styles.filter(function (x) { return x.basedOn; }); _b < _c.length; _b++) {
  2070. var style = _c[_b];
  2071. var baseStyle = stylesMap[style.basedOn];
  2072. if (baseStyle) {
  2073. var _loop_2 = function (styleValues) {
  2074. baseValues = baseStyle.styles.filter(function (x) { return x.target == styleValues.target; });
  2075. if (baseValues && baseValues.length > 0)
  2076. this_2.copyStyleProperties(baseValues[0].values, styleValues.values);
  2077. };
  2078. var this_2 = this, baseValues;
  2079. for (var _d = 0, _e = style.styles; _d < _e.length; _d++) {
  2080. var styleValues = _e[_d];
  2081. _loop_2(styleValues);
  2082. }
  2083. }
  2084. else if (this.options.debug)
  2085. console.warn("Can't find base style " + style.basedOn);
  2086. }
  2087. for (var _f = 0, styles_1 = styles; _f < styles_1.length; _f++) {
  2088. var style = styles_1[_f];
  2089. style.cssName = this.processClassName(this.escapeClassName(style.id));
  2090. }
  2091. return stylesMap;
  2092. };
  2093. HtmlRenderer.prototype.processElement = function (element) {
  2094. if (element.children) {
  2095. for (var _i = 0, _a = element.children; _i < _a.length; _i++) {
  2096. var e = _a[_i];
  2097. e.className = this.processClassName(e.className);
  2098. e.parent = element;
  2099. if (e.type == dom_1.DomType.Table) {
  2100. this.processTable(e);
  2101. }
  2102. else {
  2103. this.processElement(e);
  2104. }
  2105. }
  2106. }
  2107. };
  2108. HtmlRenderer.prototype.processTable = function (table) {
  2109. for (var _i = 0, _a = table.children; _i < _a.length; _i++) {
  2110. var r = _a[_i];
  2111. for (var _b = 0, _c = r.children; _b < _c.length; _b++) {
  2112. var c = _c[_b];
  2113. c.cssStyle = this.copyStyleProperties(table.cellStyle, c.cssStyle, [
  2114. "border-left", "border-right", "border-top", "border-bottom",
  2115. "padding-left", "padding-right", "padding-top", "padding-bottom"
  2116. ]);
  2117. this.processElement(c);
  2118. }
  2119. }
  2120. };
  2121. HtmlRenderer.prototype.copyStyleProperties = function (input, output, attrs) {
  2122. if (attrs === void 0) { attrs = null; }
  2123. if (!input)
  2124. return output;
  2125. if (output == null)
  2126. output = {};
  2127. if (attrs == null)
  2128. attrs = Object.getOwnPropertyNames(input);
  2129. for (var _i = 0, attrs_1 = attrs; _i < attrs_1.length; _i++) {
  2130. var key = attrs_1[_i];
  2131. if (input.hasOwnProperty(key) && !output.hasOwnProperty(key))
  2132. output[key] = input[key];
  2133. }
  2134. return output;
  2135. };
  2136. HtmlRenderer.prototype.createSection = function (className, props) {
  2137. var elem = this.htmlDocument.createElement("section");
  2138. elem.className = className;
  2139. if (props) {
  2140. if (props.pageMargins) {
  2141. elem.style.paddingLeft = this.renderLength(props.pageMargins.left);
  2142. elem.style.paddingRight = this.renderLength(props.pageMargins.right);
  2143. elem.style.paddingTop = this.renderLength(props.pageMargins.top);
  2144. elem.style.paddingBottom = this.renderLength(props.pageMargins.bottom);
  2145. }
  2146. if (props.pageSize) {
  2147. if (!this.options.ignoreWidth)
  2148. elem.style.width = this.renderLength(props.pageSize.width);
  2149. if (!this.options.ignoreHeight)
  2150. elem.style.minHeight = this.renderLength(props.pageSize.height);
  2151. }
  2152. if (props.columns && props.columns.numberOfColumns) {
  2153. elem.style.columnCount = "" + props.columns.numberOfColumns;
  2154. elem.style.columnGap = this.renderLength(props.columns.space);
  2155. if (props.columns.separator) {
  2156. elem.style.columnRule = "1px solid black";
  2157. }
  2158. }
  2159. }
  2160. return elem;
  2161. };
  2162. HtmlRenderer.prototype.renderSections = function (document) {
  2163. var result = [];
  2164. this.processElement(document);
  2165. for (var _i = 0, _a = this.splitBySection(document.children); _i < _a.length; _i++) {
  2166. var section = _a[_i];
  2167. var sectionElement = this.createSection(this.className, section.sectProps || document.props);
  2168. this.renderElements(section.elements, document, sectionElement);
  2169. result.push(sectionElement);
  2170. }
  2171. return result;
  2172. };
  2173. HtmlRenderer.prototype.splitBySection = function (elements) {
  2174. var _a;
  2175. var current = { sectProps: null, elements: [] };
  2176. var result = [current];
  2177. for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
  2178. var elem = elements_1[_i];
  2179. if (elem.type == dom_1.DomType.Paragraph) {
  2180. var styleName = elem.styleName;
  2181. var s = this.styleMap && styleName ? this.styleMap[styleName] : null;
  2182. if ((_a = s === null || s === void 0 ? void 0 : s.paragraphProps) === null || _a === void 0 ? void 0 : _a.pageBreakBefore) {
  2183. current.sectProps = sectProps;
  2184. current = { sectProps: null, elements: [] };
  2185. result.push(current);
  2186. }
  2187. }
  2188. current.elements.push(elem);
  2189. if (elem.type == dom_1.DomType.Paragraph) {
  2190. var p = elem;
  2191. var sectProps = p.sectionProps;
  2192. var pBreakIndex = -1;
  2193. var rBreakIndex = -1;
  2194. if (this.options.breakPages && p.children) {
  2195. pBreakIndex = p.children.findIndex(function (r) {
  2196. var _a, _b;
  2197. rBreakIndex = (_b = (_a = r.children) === null || _a === void 0 ? void 0 : _a.findIndex(function (t) { return t.break == "page"; })) !== null && _b !== void 0 ? _b : -1;
  2198. return rBreakIndex != -1;
  2199. });
  2200. }
  2201. if (sectProps || pBreakIndex != -1) {
  2202. current.sectProps = sectProps;
  2203. current = { sectProps: null, elements: [] };
  2204. result.push(current);
  2205. }
  2206. if (pBreakIndex != -1) {
  2207. var breakRun = p.children[pBreakIndex];
  2208. var splitRun = rBreakIndex < breakRun.children.length - 1;
  2209. if (pBreakIndex < p.children.length - 1 || splitRun) {
  2210. var children = elem.children;
  2211. var newParagraph = __assign(__assign({}, elem), { children: children.slice(pBreakIndex) });
  2212. elem.children = children.slice(0, pBreakIndex);
  2213. current.elements.push(newParagraph);
  2214. if (splitRun) {
  2215. var runChildren = breakRun.children;
  2216. var newRun = __assign(__assign({}, breakRun), { children: runChildren.slice(0, rBreakIndex) });
  2217. elem.children.push(newRun);
  2218. breakRun.children = runChildren.slice(rBreakIndex);
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. var currentSectProps = null;
  2225. for (var i = result.length - 1; i >= 0; i--) {
  2226. if (result[i].sectProps == null) {
  2227. result[i].sectProps = currentSectProps;
  2228. }
  2229. else {
  2230. currentSectProps = result[i].sectProps;
  2231. }
  2232. }
  2233. return result;
  2234. };
  2235. HtmlRenderer.prototype.renderLength = function (l) {
  2236. return l ? "" + l.value + l.type : null;
  2237. };
  2238. HtmlRenderer.prototype.renderWrapper = function () {
  2239. var wrapper = document.createElement("div");
  2240. wrapper.className = this.className + "-wrapper";
  2241. return wrapper;
  2242. };
  2243. HtmlRenderer.prototype.renderDefaultStyle = function () {
  2244. var c = this.className;
  2245. var styleText = "\n." + c + "-wrapper { background: gray; padding: 30px; padding-bottom: 0px; display: flex; flex-flow: column; align-items: center; } \n." + c + "-wrapper section." + c + " { background: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); margin-bottom: 30px; }\n." + c + " { color: black; }\nsection." + c + " { box-sizing: border-box; }\n." + c + " table { border-collapse: collapse; }\n." + c + " table td, ." + c + " table th { vertical-align: top; }\n." + c + " p { margin: 0pt; min-height: 1em; }\n." + c + " span { white-space: pre-wrap; }\n";
  2246. return createStyleElement(styleText);
  2247. };
  2248. HtmlRenderer.prototype.renderNumbering = function (numberings, styleContainer) {
  2249. var _this = this;
  2250. var styleText = "";
  2251. var rootCounters = [];
  2252. var _loop_3 = function () {
  2253. selector = "p." + this_3.numberingClass(num.id, num.level);
  2254. listStyleType = "none";
  2255. if (num.bullet) {
  2256. var valiable_1 = ("--" + this_3.className + "-" + num.bullet.src).toLowerCase();
  2257. styleText += this_3.styleToString(selector + ":before", {
  2258. "content": "' '",
  2259. "display": "inline-block",
  2260. "background": "var(" + valiable_1 + ")"
  2261. }, num.bullet.style);
  2262. this_3.document.loadNumberingImage(num.bullet.src).then(function (data) {
  2263. var text = "." + _this.className + "-wrapper { " + valiable_1 + ": url(" + data + ") }";
  2264. styleContainer.appendChild(createStyleElement(text));
  2265. });
  2266. }
  2267. else if (num.levelText) {
  2268. var counter = this_3.numberingCounter(num.id, num.level);
  2269. if (num.level > 0) {
  2270. styleText += this_3.styleToString("p." + this_3.numberingClass(num.id, num.level - 1), {
  2271. "counter-reset": counter
  2272. });
  2273. }
  2274. else {
  2275. rootCounters.push(counter);
  2276. }
  2277. styleText += this_3.styleToString(selector + ":before", __assign({ "content": this_3.levelTextToContent(num.levelText, num.suff, num.id, this_3.numFormatToCssValue(num.format)), "counter-increment": counter }, num.rStyle));
  2278. }
  2279. else {
  2280. listStyleType = this_3.numFormatToCssValue(num.format);
  2281. }
  2282. styleText += this_3.styleToString(selector, __assign({ "display": "list-item", "list-style-position": "inside", "list-style-type": listStyleType }, num.pStyle));
  2283. };
  2284. var this_3 = this, selector, listStyleType;
  2285. for (var _i = 0, numberings_1 = numberings; _i < numberings_1.length; _i++) {
  2286. var num = numberings_1[_i];
  2287. _loop_3();
  2288. }
  2289. if (rootCounters.length > 0) {
  2290. styleText += this.styleToString("." + this.className + "-wrapper", {
  2291. "counter-reset": rootCounters.join(" ")
  2292. });
  2293. }
  2294. return createStyleElement(styleText);
  2295. };
  2296. HtmlRenderer.prototype.renderStyles = function (styles) {
  2297. var styleText = "";
  2298. var stylesMap = this.styleMap;
  2299. for (var _i = 0, styles_2 = styles; _i < styles_2.length; _i++) {
  2300. var style = styles_2[_i];
  2301. var subStyles = style.styles;
  2302. if (style.linked) {
  2303. var linkedStyle = style.linked && stylesMap[style.linked];
  2304. if (linkedStyle)
  2305. subStyles = subStyles.concat(linkedStyle.styles);
  2306. else if (this.options.debug)
  2307. console.warn("Can't find linked style " + style.linked);
  2308. }
  2309. for (var _a = 0, subStyles_1 = subStyles; _a < subStyles_1.length; _a++) {
  2310. var subStyle = subStyles_1[_a];
  2311. var selector = "";
  2312. if (style.target == subStyle.target)
  2313. selector += style.target + "." + style.cssName;
  2314. else if (style.target)
  2315. selector += style.target + "." + style.cssName + " " + subStyle.target;
  2316. else
  2317. selector += "." + style.cssName + " " + subStyle.target;
  2318. if (style.isDefault && style.target)
  2319. selector = "." + this.className + " " + style.target + ", " + selector;
  2320. styleText += this.styleToString(selector, subStyle.values);
  2321. }
  2322. }
  2323. return createStyleElement(styleText);
  2324. };
  2325. HtmlRenderer.prototype.renderElement = function (elem, parent) {
  2326. switch (elem.type) {
  2327. case dom_1.DomType.Paragraph:
  2328. return this.renderParagraph(elem);
  2329. case dom_1.DomType.BookmarkStart:
  2330. return this.renderBookmarkStart(elem);
  2331. case dom_1.DomType.BookmarkEnd:
  2332. return null;
  2333. case dom_1.DomType.Run:
  2334. return this.renderRun(elem);
  2335. case dom_1.DomType.Table:
  2336. return this.renderTable(elem);
  2337. case dom_1.DomType.Row:
  2338. return this.renderTableRow(elem);
  2339. case dom_1.DomType.Cell:
  2340. return this.renderTableCell(elem);
  2341. case dom_1.DomType.Hyperlink:
  2342. return this.renderHyperlink(elem);
  2343. case dom_1.DomType.Drawing:
  2344. return this.renderDrawing(elem);
  2345. case dom_1.DomType.Image:
  2346. return this.renderImage(elem);
  2347. case dom_1.DomType.Text:
  2348. return this.renderText(elem);
  2349. case dom_1.DomType.Tab:
  2350. return this.renderTab(elem);
  2351. case dom_1.DomType.Symbol:
  2352. return this.renderSymbol(elem);
  2353. case dom_1.DomType.Break:
  2354. return this.renderBreak(elem);
  2355. }
  2356. return null;
  2357. };
  2358. HtmlRenderer.prototype.renderChildren = function (elem, into) {
  2359. return this.renderElements(elem.children, elem, into);
  2360. };
  2361. HtmlRenderer.prototype.renderElements = function (elems, parent, into) {
  2362. var _this = this;
  2363. if (elems == null)
  2364. return null;
  2365. var result = elems.map(function (e) { return _this.renderElement(e, parent); }).filter(function (e) { return e != null; });
  2366. if (into)
  2367. for (var _i = 0, result_1 = result; _i < result_1.length; _i++) {
  2368. var c = result_1[_i];
  2369. into.appendChild(c);
  2370. }
  2371. return result;
  2372. };
  2373. HtmlRenderer.prototype.renderParagraph = function (elem) {
  2374. var result = this.htmlDocument.createElement("p");
  2375. this.renderClass(elem, result);
  2376. this.renderChildren(elem, result);
  2377. this.renderStyleValues(elem.cssStyle, result);
  2378. this.renderCommonProeprties(result.style, elem);
  2379. if (elem.numbering) {
  2380. var numberingClass = this.numberingClass(elem.numbering.id, elem.numbering.level);
  2381. result.className = (0, utils_1.appendClass)(result.className, numberingClass);
  2382. }
  2383. if (elem.styleName) {
  2384. var styleClassName = this.processClassName(this.escapeClassName(elem.styleName));
  2385. result.className = (0, utils_1.appendClass)(result.className, styleClassName);
  2386. }
  2387. return result;
  2388. };
  2389. HtmlRenderer.prototype.renderRunProperties = function (style, props) {
  2390. this.renderCommonProeprties(style, props);
  2391. };
  2392. HtmlRenderer.prototype.renderCommonProeprties = function (style, props) {
  2393. if (props == null)
  2394. return;
  2395. if (props.color) {
  2396. style["color"] = props.color;
  2397. }
  2398. if (props.fontSize) {
  2399. style["font-size"] = this.renderLength(props.fontSize);
  2400. }
  2401. };
  2402. HtmlRenderer.prototype.renderHyperlink = function (elem) {
  2403. var result = this.htmlDocument.createElement("a");
  2404. this.renderChildren(elem, result);
  2405. this.renderStyleValues(elem.cssStyle, result);
  2406. if (elem.href)
  2407. result.href = elem.href;
  2408. return result;
  2409. };
  2410. HtmlRenderer.prototype.renderDrawing = function (elem) {
  2411. var result = this.htmlDocument.createElement("div");
  2412. result.style.display = "inline-block";
  2413. result.style.position = "relative";
  2414. result.style.textIndent = "0px";
  2415. this.renderChildren(elem, result);
  2416. this.renderStyleValues(elem.cssStyle, result);
  2417. return result;
  2418. };
  2419. HtmlRenderer.prototype.renderImage = function (elem) {
  2420. var result = this.htmlDocument.createElement("img");
  2421. this.renderStyleValues(elem.cssStyle, result);
  2422. if (this.document) {
  2423. this.document.loadDocumentImage(elem.src).then(function (x) {
  2424. result.src = x;
  2425. });
  2426. }
  2427. return result;
  2428. };
  2429. HtmlRenderer.prototype.renderText = function (elem) {
  2430. return this.htmlDocument.createTextNode(elem.text);
  2431. };
  2432. HtmlRenderer.prototype.renderBreak = function (elem) {
  2433. if (elem.break == "textWrapping") {
  2434. return this.htmlDocument.createElement("br");
  2435. }
  2436. return null;
  2437. };
  2438. HtmlRenderer.prototype.renderSymbol = function (elem) {
  2439. var span = this.htmlDocument.createElement("span");
  2440. span.style.fontFamily = elem.font;
  2441. span.innerHTML = "&#x" + elem.char + ";";
  2442. return span;
  2443. };
  2444. HtmlRenderer.prototype.renderTab = function (elem) {
  2445. var tabSpan = this.htmlDocument.createElement("span");
  2446. tabSpan.innerHTML = "&emsp;";
  2447. if (this.options.experimental) {
  2448. setTimeout(function () {
  2449. var paragraph = findParent(elem, dom_1.DomType.Paragraph);
  2450. if (paragraph.tabs == null)
  2451. return;
  2452. paragraph.tabs.sort(function (a, b) { return a.position.value - b.position.value; });
  2453. tabSpan.style.display = "inline-block";
  2454. (0, javascript_1.updateTabStop)(tabSpan, paragraph.tabs);
  2455. }, 0);
  2456. }
  2457. return tabSpan;
  2458. };
  2459. HtmlRenderer.prototype.renderBookmarkStart = function (elem) {
  2460. var result = this.htmlDocument.createElement("span");
  2461. result.id = elem.name;
  2462. return result;
  2463. };
  2464. HtmlRenderer.prototype.renderRun = function (elem) {
  2465. if (elem.fldCharType || elem.instrText)
  2466. return null;
  2467. var result = this.htmlDocument.createElement("span");
  2468. if (elem.id)
  2469. result.id = elem.id;
  2470. this.renderClass(elem, result);
  2471. this.renderChildren(elem, result);
  2472. this.renderStyleValues(elem.cssStyle, result);
  2473. if (elem.href) {
  2474. var link = this.htmlDocument.createElement("a");
  2475. link.href = elem.href;
  2476. link.appendChild(result);
  2477. return link;
  2478. }
  2479. else if (elem.wrapper) {
  2480. var wrapper = this.htmlDocument.createElement(elem.wrapper);
  2481. wrapper.appendChild(result);
  2482. return wrapper;
  2483. }
  2484. return result;
  2485. };
  2486. HtmlRenderer.prototype.renderTable = function (elem) {
  2487. var result = this.htmlDocument.createElement("table");
  2488. if (elem.columns)
  2489. result.appendChild(this.renderTableColumns(elem.columns));
  2490. this.renderClass(elem, result);
  2491. this.renderChildren(elem, result);
  2492. this.renderStyleValues(elem.cssStyle, result);
  2493. return result;
  2494. };
  2495. HtmlRenderer.prototype.renderTableColumns = function (columns) {
  2496. var result = this.htmlDocument.createElement("colGroup");
  2497. for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
  2498. var col = columns_1[_i];
  2499. var colElem = this.htmlDocument.createElement("col");
  2500. if (col.width)
  2501. colElem.style.width = col.width;
  2502. result.appendChild(colElem);
  2503. }
  2504. return result;
  2505. };
  2506. HtmlRenderer.prototype.renderTableRow = function (elem) {
  2507. var result = this.htmlDocument.createElement("tr");
  2508. this.renderClass(elem, result);
  2509. this.renderChildren(elem, result);
  2510. this.renderStyleValues(elem.cssStyle, result);
  2511. return result;
  2512. };
  2513. HtmlRenderer.prototype.renderTableCell = function (elem) {
  2514. var result = this.htmlDocument.createElement("td");
  2515. this.renderClass(elem, result);
  2516. this.renderChildren(elem, result);
  2517. this.renderStyleValues(elem.cssStyle, result);
  2518. if (elem.span)
  2519. result.colSpan = elem.span;
  2520. return result;
  2521. };
  2522. HtmlRenderer.prototype.renderStyleValues = function (style, ouput) {
  2523. if (style == null)
  2524. return;
  2525. for (var key in style) {
  2526. if (style.hasOwnProperty(key)) {
  2527. ouput.style[key] = style[key];
  2528. }
  2529. }
  2530. };
  2531. HtmlRenderer.prototype.renderClass = function (input, ouput) {
  2532. if (input.className)
  2533. ouput.className = input.className;
  2534. };
  2535. HtmlRenderer.prototype.numberingClass = function (id, lvl) {
  2536. return this.className + "-num-" + id + "-" + lvl;
  2537. };
  2538. HtmlRenderer.prototype.styleToString = function (selectors, values, cssText) {
  2539. if (cssText === void 0) { cssText = null; }
  2540. var result = selectors + " {\r\n";
  2541. for (var key in values) {
  2542. result += " " + key + ": " + values[key] + ";\r\n";
  2543. }
  2544. if (cssText)
  2545. result += ";" + cssText;
  2546. return result + "}\r\n";
  2547. };
  2548. HtmlRenderer.prototype.numberingCounter = function (id, lvl) {
  2549. return this.className + "-num-" + id + "-" + lvl;
  2550. };
  2551. HtmlRenderer.prototype.levelTextToContent = function (text, suff, id, numformat) {
  2552. var _this = this;
  2553. var _a;
  2554. var suffMap = {
  2555. "tab": "\\9",
  2556. "space": "\\a0",
  2557. };
  2558. var result = text.replace(/%\d*/g, function (s) {
  2559. var lvl = parseInt(s.substring(1), 10) - 1;
  2560. return "\"counter(" + _this.numberingCounter(id, lvl) + ", " + numformat + ")\"";
  2561. });
  2562. return "\"" + result + ((_a = suffMap[suff]) !== null && _a !== void 0 ? _a : "") + "\"";
  2563. };
  2564. HtmlRenderer.prototype.numFormatToCssValue = function (format) {
  2565. var mapping = {
  2566. "none": "none",
  2567. "bullet": "disc",
  2568. "decimal": "decimal",
  2569. "lowerLetter": "lower-alpha",
  2570. "upperLetter": "upper-alpha",
  2571. "lowerRoman": "lower-roman",
  2572. "upperRoman": "upper-roman",
  2573. };
  2574. return mapping[format] || format;
  2575. };
  2576. HtmlRenderer.prototype.escapeClassName = function (className) {
  2577. return className === null || className === void 0 ? void 0 : className.replace(/[ .]+/g, '-').replace(/[&]+/g, 'and');
  2578. };
  2579. return HtmlRenderer;
  2580. }());
  2581. exports.HtmlRenderer = HtmlRenderer;
  2582. function appentElements(container, children) {
  2583. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  2584. var c = children_1[_i];
  2585. container.appendChild(c);
  2586. }
  2587. }
  2588. function removeAllElements(elem) {
  2589. while (elem.firstChild) {
  2590. elem.removeChild(elem.firstChild);
  2591. }
  2592. }
  2593. function createStyleElement(cssText) {
  2594. var styleElement = document.createElement("style");
  2595. styleElement.innerHTML = cssText;
  2596. return styleElement;
  2597. }
  2598. function appendComment(elem, comment) {
  2599. elem.appendChild(document.createComment(comment));
  2600. }
  2601. function findParent(elem, type) {
  2602. var parent = elem.parent;
  2603. while (parent != null && parent.type != type)
  2604. parent = parent.parent;
  2605. return parent;
  2606. }
  2607. /***/ }),
  2608. /***/ "./src/javascript.ts":
  2609. /*!***************************!*\
  2610. !*** ./src/javascript.ts ***!
  2611. \***************************/
  2612. /***/ ((__unused_webpack_module, exports) => {
  2613. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2614. exports.updateTabStop = void 0;
  2615. function updateTabStop(elem, tabs, pixelToPoint) {
  2616. if (pixelToPoint === void 0) { pixelToPoint = 72 / 96; }
  2617. var p = elem.closest("p");
  2618. var tbb = elem.getBoundingClientRect();
  2619. var pbb = p.getBoundingClientRect();
  2620. var left = (tbb.left - pbb.left) * pixelToPoint;
  2621. var tab = tabs.find(function (t) { return t.style != "clear" && t.position.value > left; });
  2622. if (tab == null)
  2623. return;
  2624. elem.style.display = "inline-block";
  2625. elem.style.width = (tab.position.value - left) + "pt";
  2626. switch (tab.leader) {
  2627. case "dot":
  2628. case "middleDot":
  2629. elem.style.borderBottom = "1px black dotted";
  2630. break;
  2631. case "hyphen":
  2632. case "heavy":
  2633. case "underscore":
  2634. elem.style.borderBottom = "1px black solid";
  2635. break;
  2636. }
  2637. }
  2638. exports.updateTabStop = updateTabStop;
  2639. /***/ }),
  2640. /***/ "./src/numbering/numbering-part.ts":
  2641. /*!*****************************************!*\
  2642. !*** ./src/numbering/numbering-part.ts ***!
  2643. \*****************************************/
  2644. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  2645. var __extends = (this && this.__extends) || (function () {
  2646. var extendStatics = function (d, b) {
  2647. extendStatics = Object.setPrototypeOf ||
  2648. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2649. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  2650. return extendStatics(d, b);
  2651. };
  2652. return function (d, b) {
  2653. if (typeof b !== "function" && b !== null)
  2654. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  2655. extendStatics(d, b);
  2656. function __() { this.constructor = d; }
  2657. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2658. };
  2659. })();
  2660. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2661. exports.NumberingPart = void 0;
  2662. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  2663. var numbering_1 = __webpack_require__(/*! ./numbering */ "./src/numbering/numbering.ts");
  2664. var NumberingPart = (function (_super) {
  2665. __extends(NumberingPart, _super);
  2666. function NumberingPart(pkg, path, parser) {
  2667. var _this = _super.call(this, pkg, path) || this;
  2668. _this._documentParser = parser;
  2669. return _this;
  2670. }
  2671. NumberingPart.prototype.parseXml = function (root) {
  2672. Object.assign(this, (0, numbering_1.parseNumberingPart)(root, this._package.xmlParser));
  2673. this.domNumberings = this._documentParser.parseNumberingFile(root);
  2674. };
  2675. return NumberingPart;
  2676. }(part_1.Part));
  2677. exports.NumberingPart = NumberingPart;
  2678. /***/ }),
  2679. /***/ "./src/numbering/numbering.ts":
  2680. /*!************************************!*\
  2681. !*** ./src/numbering/numbering.ts ***!
  2682. \************************************/
  2683. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2684. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2685. exports.parseNumberingBulletPicture = exports.parseNumberingLevelOverrride = exports.parseNumberingLevel = exports.parseAbstractNumbering = exports.parseNumbering = exports.parseNumberingPart = void 0;
  2686. var paragraph_1 = __webpack_require__(/*! ../dom/paragraph */ "./src/dom/paragraph.ts");
  2687. var run_1 = __webpack_require__(/*! ../dom/run */ "./src/dom/run.ts");
  2688. function parseNumberingPart(elem, xml) {
  2689. var result = {
  2690. numberings: [],
  2691. abstractNumberings: [],
  2692. bulletPictures: []
  2693. };
  2694. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  2695. var e = _a[_i];
  2696. switch (e.localName) {
  2697. case "num":
  2698. result.numberings.push(parseNumbering(e, xml));
  2699. break;
  2700. case "abstractNum":
  2701. result.abstractNumberings.push(parseAbstractNumbering(e, xml));
  2702. break;
  2703. case "numPicBullet":
  2704. result.bulletPictures.push(parseNumberingBulletPicture(e, xml));
  2705. break;
  2706. }
  2707. }
  2708. return result;
  2709. }
  2710. exports.parseNumberingPart = parseNumberingPart;
  2711. function parseNumbering(elem, xml) {
  2712. var result = {
  2713. id: xml.attr(elem, 'numId'),
  2714. overrides: []
  2715. };
  2716. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  2717. var e = _a[_i];
  2718. switch (e.localName) {
  2719. case "abstractNumId":
  2720. result.abstractId = xml.attr(e, "val");
  2721. break;
  2722. case "lvlOverride":
  2723. result.overrides.push(parseNumberingLevelOverrride(e, xml));
  2724. break;
  2725. }
  2726. }
  2727. return result;
  2728. }
  2729. exports.parseNumbering = parseNumbering;
  2730. function parseAbstractNumbering(elem, xml) {
  2731. var result = {
  2732. id: xml.attr(elem, 'abstractNumId'),
  2733. levels: []
  2734. };
  2735. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  2736. var e = _a[_i];
  2737. switch (e.localName) {
  2738. case "name":
  2739. result.name = xml.attr(e, "val");
  2740. break;
  2741. case "multiLevelType":
  2742. result.multiLevelType = xml.attr(e, "val");
  2743. break;
  2744. case "numStyleLink":
  2745. result.numberingStyleLink = xml.attr(e, "val");
  2746. break;
  2747. case "styleLink":
  2748. result.styleLink = xml.attr(e, "val");
  2749. break;
  2750. case "lvl":
  2751. result.levels.push(parseNumberingLevel(e, xml));
  2752. break;
  2753. }
  2754. }
  2755. return result;
  2756. }
  2757. exports.parseAbstractNumbering = parseAbstractNumbering;
  2758. function parseNumberingLevel(elem, xml) {
  2759. var result = {
  2760. level: xml.intAttr(elem, 'ilvl')
  2761. };
  2762. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  2763. var e = _a[_i];
  2764. switch (e.localName) {
  2765. case "start":
  2766. result.start = xml.attr(e, "val");
  2767. break;
  2768. case "lvlRestart":
  2769. result.restart = xml.intAttr(e, "val");
  2770. break;
  2771. case "numFmt":
  2772. result.format = xml.attr(e, "val");
  2773. break;
  2774. case "lvlText":
  2775. result.text = xml.attr(e, "val");
  2776. break;
  2777. case "lvlJc":
  2778. result.justification = xml.attr(e, "val");
  2779. break;
  2780. case "lvlPicBulletId":
  2781. result.bulletPictureId = xml.attr(e, "val");
  2782. break;
  2783. case "pPr":
  2784. result.paragraphProps = (0, paragraph_1.parseParagraphProperties)(e, xml);
  2785. break;
  2786. case "rPr":
  2787. result.runProps = (0, run_1.parseRunProperties)(e, xml);
  2788. break;
  2789. }
  2790. }
  2791. return result;
  2792. }
  2793. exports.parseNumberingLevel = parseNumberingLevel;
  2794. function parseNumberingLevelOverrride(elem, xml) {
  2795. var result = {
  2796. level: xml.intAttr(elem, 'ilvl')
  2797. };
  2798. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  2799. var e = _a[_i];
  2800. switch (e.localName) {
  2801. case "startOverride":
  2802. result.start = xml.intAttr(e, "val");
  2803. break;
  2804. case "lvl":
  2805. result.numberingLevel = parseNumberingLevel(e, xml);
  2806. break;
  2807. }
  2808. }
  2809. return result;
  2810. }
  2811. exports.parseNumberingLevelOverrride = parseNumberingLevelOverrride;
  2812. function parseNumberingBulletPicture(elem, xml) {
  2813. var pict = xml.element(elem, "pict");
  2814. var shape = pict && xml.element(pict, "shape");
  2815. var imagedata = shape && xml.element(shape, "imagedata");
  2816. return imagedata ? {
  2817. id: xml.attr(elem, "numPicBulletId"),
  2818. referenceId: xml.attr(imagedata, "id"),
  2819. style: xml.attr(shape, "style")
  2820. } : null;
  2821. }
  2822. exports.parseNumberingBulletPicture = parseNumberingBulletPicture;
  2823. /***/ }),
  2824. /***/ "./src/parser/xml-parser.ts":
  2825. /*!**********************************!*\
  2826. !*** ./src/parser/xml-parser.ts ***!
  2827. \**********************************/
  2828. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2829. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2830. exports.XmlParser = exports.serializeXmlString = exports.parseXmlString = void 0;
  2831. var common_1 = __webpack_require__(/*! ../dom/common */ "./src/dom/common.ts");
  2832. function parseXmlString(xmlString, trimXmlDeclaration) {
  2833. if (trimXmlDeclaration === void 0) { trimXmlDeclaration = false; }
  2834. if (trimXmlDeclaration)
  2835. xmlString = xmlString.replace(/<[?].*[?]>/, "");
  2836. var result = new DOMParser().parseFromString(xmlString, "application/xml");
  2837. var errorText = hasXmlParserError(result);
  2838. if (errorText)
  2839. throw new Error(errorText);
  2840. return result;
  2841. }
  2842. exports.parseXmlString = parseXmlString;
  2843. function hasXmlParserError(doc) {
  2844. var _a;
  2845. return (_a = doc.getElementsByTagName("parsererror")[0]) === null || _a === void 0 ? void 0 : _a.textContent;
  2846. }
  2847. function serializeXmlString(elem) {
  2848. return new XMLSerializer().serializeToString(elem);
  2849. }
  2850. exports.serializeXmlString = serializeXmlString;
  2851. var XmlParser = (function () {
  2852. function XmlParser() {
  2853. }
  2854. XmlParser.prototype.parse = function (xmlString, skipDeclaration) {
  2855. if (skipDeclaration === void 0) { skipDeclaration = true; }
  2856. if (skipDeclaration)
  2857. xmlString = xmlString.replace(/<[?].*[?]>/, "");
  2858. return new DOMParser().parseFromString(xmlString, "application/xml").firstChild;
  2859. };
  2860. XmlParser.prototype.elements = function (elem, localName) {
  2861. if (localName === void 0) { localName = null; }
  2862. var result = [];
  2863. for (var i = 0, l = elem.childNodes.length; i < l; i++) {
  2864. var c = elem.childNodes.item(i);
  2865. if (c.nodeType == 1 && (localName == null || c.localName == localName))
  2866. result.push(c);
  2867. }
  2868. return result;
  2869. };
  2870. XmlParser.prototype.element = function (elem, localName) {
  2871. for (var i = 0, l = elem.childNodes.length; i < l; i++) {
  2872. var c = elem.childNodes.item(i);
  2873. if (c.nodeType == 1 && c.localName == localName)
  2874. return c;
  2875. }
  2876. return null;
  2877. };
  2878. XmlParser.prototype.elementAttr = function (elem, localName, attrLocalName) {
  2879. var el = this.element(elem, localName);
  2880. return el ? this.attr(el, attrLocalName) : undefined;
  2881. };
  2882. XmlParser.prototype.attr = function (elem, localName) {
  2883. for (var i = 0, l = elem.attributes.length; i < l; i++) {
  2884. var a = elem.attributes.item(i);
  2885. if (a.localName == localName)
  2886. return a.value;
  2887. }
  2888. return null;
  2889. };
  2890. XmlParser.prototype.intAttr = function (node, attrName, defaultValue) {
  2891. if (defaultValue === void 0) { defaultValue = null; }
  2892. var val = this.attr(node, attrName);
  2893. return val ? parseInt(val) : defaultValue;
  2894. };
  2895. XmlParser.prototype.floatAttr = function (node, attrName, defaultValue) {
  2896. if (defaultValue === void 0) { defaultValue = null; }
  2897. var val = this.attr(node, attrName);
  2898. return val ? parseFloat(val) : defaultValue;
  2899. };
  2900. XmlParser.prototype.boolAttr = function (node, attrName, defaultValue) {
  2901. if (defaultValue === void 0) { defaultValue = null; }
  2902. var v = this.attr(node, attrName);
  2903. switch (v) {
  2904. case "1": return true;
  2905. case "0": return false;
  2906. default: return defaultValue;
  2907. }
  2908. };
  2909. XmlParser.prototype.lengthAttr = function (node, attrName, usage) {
  2910. if (usage === void 0) { usage = common_1.LengthUsage.Dxa; }
  2911. return (0, common_1.convertLength)(this.attr(node, attrName), usage);
  2912. };
  2913. return XmlParser;
  2914. }());
  2915. exports.XmlParser = XmlParser;
  2916. var globalXmlParser = new XmlParser();
  2917. exports["default"] = globalXmlParser;
  2918. /***/ }),
  2919. /***/ "./src/styles/styles-part.ts":
  2920. /*!***********************************!*\
  2921. !*** ./src/styles/styles-part.ts ***!
  2922. \***********************************/
  2923. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  2924. var __extends = (this && this.__extends) || (function () {
  2925. var extendStatics = function (d, b) {
  2926. extendStatics = Object.setPrototypeOf ||
  2927. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2928. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  2929. return extendStatics(d, b);
  2930. };
  2931. return function (d, b) {
  2932. if (typeof b !== "function" && b !== null)
  2933. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  2934. extendStatics(d, b);
  2935. function __() { this.constructor = d; }
  2936. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2937. };
  2938. })();
  2939. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2940. exports.StylesPart = void 0;
  2941. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  2942. var StylesPart = (function (_super) {
  2943. __extends(StylesPart, _super);
  2944. function StylesPart(pkg, path, parser) {
  2945. var _this = _super.call(this, pkg, path) || this;
  2946. _this._documentParser = parser;
  2947. return _this;
  2948. }
  2949. StylesPart.prototype.parseXml = function (root) {
  2950. this.styles = this._documentParser.parseStylesFile(root);
  2951. };
  2952. return StylesPart;
  2953. }(part_1.Part));
  2954. exports.StylesPart = StylesPart;
  2955. /***/ }),
  2956. /***/ "./src/theme/theme-part.ts":
  2957. /*!*********************************!*\
  2958. !*** ./src/theme/theme-part.ts ***!
  2959. \*********************************/
  2960. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  2961. var __extends = (this && this.__extends) || (function () {
  2962. var extendStatics = function (d, b) {
  2963. extendStatics = Object.setPrototypeOf ||
  2964. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2965. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  2966. return extendStatics(d, b);
  2967. };
  2968. return function (d, b) {
  2969. if (typeof b !== "function" && b !== null)
  2970. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  2971. extendStatics(d, b);
  2972. function __() { this.constructor = d; }
  2973. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2974. };
  2975. })();
  2976. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2977. exports.ThemePart = void 0;
  2978. var part_1 = __webpack_require__(/*! ../common/part */ "./src/common/part.ts");
  2979. var theme_1 = __webpack_require__(/*! ./theme */ "./src/theme/theme.ts");
  2980. var ThemePart = (function (_super) {
  2981. __extends(ThemePart, _super);
  2982. function ThemePart(pkg, path) {
  2983. return _super.call(this, pkg, path) || this;
  2984. }
  2985. ThemePart.prototype.parseXml = function (root) {
  2986. this.theme = (0, theme_1.parseTheme)(root, this._package.xmlParser);
  2987. };
  2988. return ThemePart;
  2989. }(part_1.Part));
  2990. exports.ThemePart = ThemePart;
  2991. /***/ }),
  2992. /***/ "./src/theme/theme.ts":
  2993. /*!****************************!*\
  2994. !*** ./src/theme/theme.ts ***!
  2995. \****************************/
  2996. /***/ ((__unused_webpack_module, exports) => {
  2997. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2998. exports.parseFontInfo = exports.parseFontScheme = exports.parseColorScheme = exports.parseTheme = exports.DmlTheme = void 0;
  2999. var DmlTheme = (function () {
  3000. function DmlTheme() {
  3001. }
  3002. return DmlTheme;
  3003. }());
  3004. exports.DmlTheme = DmlTheme;
  3005. function parseTheme(elem, xml) {
  3006. var result = new DmlTheme();
  3007. var themeElements = xml.element(elem, "themeElements");
  3008. for (var _i = 0, _a = xml.elements(themeElements); _i < _a.length; _i++) {
  3009. var el = _a[_i];
  3010. switch (el.localName) {
  3011. case "clrScheme":
  3012. result.colorScheme = parseColorScheme(el, xml);
  3013. break;
  3014. case "fontScheme":
  3015. result.fontScheme = parseFontScheme(el, xml);
  3016. break;
  3017. }
  3018. }
  3019. return result;
  3020. }
  3021. exports.parseTheme = parseTheme;
  3022. function parseColorScheme(elem, xml) {
  3023. var result = {
  3024. name: xml.attr(elem, "name"),
  3025. colors: {}
  3026. };
  3027. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  3028. var el = _a[_i];
  3029. var srgbClr = xml.element(el, "srgbClr");
  3030. var sysClr = xml.element(el, "sysClr");
  3031. if (srgbClr) {
  3032. result.colors[el.localName] = xml.attr(srgbClr, "val");
  3033. }
  3034. else if (sysClr) {
  3035. result.colors[el.localName] = xml.attr(sysClr, "lastClr");
  3036. }
  3037. }
  3038. return result;
  3039. }
  3040. exports.parseColorScheme = parseColorScheme;
  3041. function parseFontScheme(elem, xml) {
  3042. var result = {
  3043. name: xml.attr(elem, "name"),
  3044. };
  3045. for (var _i = 0, _a = xml.elements(elem); _i < _a.length; _i++) {
  3046. var el = _a[_i];
  3047. switch (el.localName) {
  3048. case "majorFont":
  3049. result.majorFont = parseFontInfo(el, xml);
  3050. break;
  3051. case "minorFont":
  3052. result.minorFont = parseFontInfo(el, xml);
  3053. break;
  3054. }
  3055. }
  3056. return result;
  3057. }
  3058. exports.parseFontScheme = parseFontScheme;
  3059. function parseFontInfo(elem, xml) {
  3060. return {
  3061. latinTypeface: xml.elementAttr(elem, "latin", "typeface"),
  3062. eaTypeface: xml.elementAttr(elem, "ea", "typeface"),
  3063. csTypeface: xml.elementAttr(elem, "cs", "typeface"),
  3064. };
  3065. }
  3066. exports.parseFontInfo = parseFontInfo;
  3067. /***/ }),
  3068. /***/ "./src/utils.ts":
  3069. /*!**********************!*\
  3070. !*** ./src/utils.ts ***!
  3071. \**********************/
  3072. /***/ (function(__unused_webpack_module, exports) {
  3073. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  3074. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  3075. if (ar || !(i in from)) {
  3076. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  3077. ar[i] = from[i];
  3078. }
  3079. }
  3080. return to.concat(ar || Array.prototype.slice.call(from));
  3081. };
  3082. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3083. exports.mergeDeep = exports.isObject = exports.keyBy = exports.resolvePath = exports.splitPath = exports.appendClass = exports.addElementClass = void 0;
  3084. function addElementClass(element, className) {
  3085. return element.className = appendClass(element.className, className);
  3086. }
  3087. exports.addElementClass = addElementClass;
  3088. function appendClass(classList, className) {
  3089. return (!classList) ? className : classList + " " + className;
  3090. }
  3091. exports.appendClass = appendClass;
  3092. function splitPath(path) {
  3093. var si = path.lastIndexOf('/') + 1;
  3094. var folder = si == 0 ? "" : path.substring(0, si);
  3095. var fileName = si == 0 ? path : path.substring(si);
  3096. return [folder, fileName];
  3097. }
  3098. exports.splitPath = splitPath;
  3099. function resolvePath(path, base) {
  3100. try {
  3101. var prefix = "file://docx/";
  3102. var url = new URL(path, prefix + base).toString();
  3103. return url.substr(prefix.length);
  3104. }
  3105. catch (_a) {
  3106. return "" + base + path;
  3107. }
  3108. }
  3109. exports.resolvePath = resolvePath;
  3110. function keyBy(array, by) {
  3111. return array.reduce(function (a, x) {
  3112. a[by(x)] = x;
  3113. return a;
  3114. }, {});
  3115. }
  3116. exports.keyBy = keyBy;
  3117. function isObject(item) {
  3118. return (item && typeof item === 'object' && !Array.isArray(item));
  3119. }
  3120. exports.isObject = isObject;
  3121. function mergeDeep(target) {
  3122. var _a;
  3123. var sources = [];
  3124. for (var _i = 1; _i < arguments.length; _i++) {
  3125. sources[_i - 1] = arguments[_i];
  3126. }
  3127. if (!sources.length)
  3128. return target;
  3129. var source = sources.shift();
  3130. if (isObject(target) && isObject(source)) {
  3131. for (var key in source) {
  3132. if (isObject(source[key])) {
  3133. var val = (_a = target[key]) !== null && _a !== void 0 ? _a : (target[key] = {});
  3134. mergeDeep(val, source[key]);
  3135. }
  3136. else {
  3137. target[key] = source[key];
  3138. }
  3139. }
  3140. }
  3141. return mergeDeep.apply(void 0, __spreadArray([target], sources, false));
  3142. }
  3143. exports.mergeDeep = mergeDeep;
  3144. /***/ }),
  3145. /***/ "./src/word-document.ts":
  3146. /*!******************************!*\
  3147. !*** ./src/word-document.ts ***!
  3148. \******************************/
  3149. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3150. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3151. exports.deobfuscate = exports.WordDocument = void 0;
  3152. var relationship_1 = __webpack_require__(/*! ./common/relationship */ "./src/common/relationship.ts");
  3153. var font_table_1 = __webpack_require__(/*! ./font-table/font-table */ "./src/font-table/font-table.ts");
  3154. var open_xml_package_1 = __webpack_require__(/*! ./common/open-xml-package */ "./src/common/open-xml-package.ts");
  3155. var document_part_1 = __webpack_require__(/*! ./dom/document-part */ "./src/dom/document-part.ts");
  3156. var utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
  3157. var numbering_part_1 = __webpack_require__(/*! ./numbering/numbering-part */ "./src/numbering/numbering-part.ts");
  3158. var styles_part_1 = __webpack_require__(/*! ./styles/styles-part */ "./src/styles/styles-part.ts");
  3159. var footer_part_1 = __webpack_require__(/*! ./footer/footer-part */ "./src/footer/footer-part.ts");
  3160. var header_part_1 = __webpack_require__(/*! ./header/header-part */ "./src/header/header-part.ts");
  3161. var extended_props_part_1 = __webpack_require__(/*! ./document-props/extended-props-part */ "./src/document-props/extended-props-part.ts");
  3162. var core_props_part_1 = __webpack_require__(/*! ./document-props/core-props-part */ "./src/document-props/core-props-part.ts");
  3163. var theme_part_1 = __webpack_require__(/*! ./theme/theme-part */ "./src/theme/theme-part.ts");
  3164. var topLevelRels = [
  3165. { type: relationship_1.RelationshipTypes.OfficeDocument, target: "word/document.xml" },
  3166. { type: relationship_1.RelationshipTypes.ExtendedProperties, target: "docProps/app.xml" },
  3167. { type: relationship_1.RelationshipTypes.CoreProperties, target: "docProps/core.xml" },
  3168. ];
  3169. var WordDocument = (function () {
  3170. function WordDocument() {
  3171. this.parts = [];
  3172. this.partsMap = {};
  3173. }
  3174. WordDocument.load = function (blob, parser, options) {
  3175. var d = new WordDocument();
  3176. d._parser = parser;
  3177. return open_xml_package_1.OpenXmlPackage.load(blob, options)
  3178. .then(function (pkg) {
  3179. d._package = pkg;
  3180. return d._package.loadRelationships();
  3181. }).then(function (rels) {
  3182. d.rels = rels;
  3183. var tasks = topLevelRels.map(function (rel) {
  3184. var _a;
  3185. var r = (_a = rels.find(function (x) { return x.type === rel.type; })) !== null && _a !== void 0 ? _a : rel;
  3186. return d.loadRelationshipPart(r.target, r.type);
  3187. });
  3188. return Promise.all(tasks);
  3189. }).then(function () { return d; });
  3190. };
  3191. WordDocument.prototype.save = function (type) {
  3192. if (type === void 0) { type = "blob"; }
  3193. return this._package.save(type);
  3194. };
  3195. WordDocument.prototype.loadRelationshipPart = function (path, type) {
  3196. var _this = this;
  3197. if (this.partsMap[path])
  3198. return Promise.resolve(this.partsMap[path]);
  3199. if (!this._package.get(path))
  3200. return Promise.resolve(null);
  3201. var part = null;
  3202. switch (type) {
  3203. case relationship_1.RelationshipTypes.OfficeDocument:
  3204. this.documentPart = part = new document_part_1.DocumentPart(this._package, path, this._parser);
  3205. break;
  3206. case relationship_1.RelationshipTypes.FontTable:
  3207. this.fontTablePart = part = new font_table_1.FontTablePart(this._package, path);
  3208. break;
  3209. case relationship_1.RelationshipTypes.Numbering:
  3210. this.numberingPart = part = new numbering_part_1.NumberingPart(this._package, path, this._parser);
  3211. break;
  3212. case relationship_1.RelationshipTypes.Styles:
  3213. this.stylesPart = part = new styles_part_1.StylesPart(this._package, path, this._parser);
  3214. break;
  3215. case relationship_1.RelationshipTypes.Theme:
  3216. part = new theme_part_1.ThemePart(this._package, path);
  3217. break;
  3218. case relationship_1.RelationshipTypes.Footer:
  3219. part = new footer_part_1.FooterPart(this._package, path, this._parser);
  3220. break;
  3221. case relationship_1.RelationshipTypes.Header:
  3222. part = new header_part_1.HeaderPart(this._package, path, this._parser);
  3223. break;
  3224. case relationship_1.RelationshipTypes.CoreProperties:
  3225. this.corePropsPart = part = new core_props_part_1.CorePropsPart(this._package, path);
  3226. break;
  3227. case relationship_1.RelationshipTypes.ExtendedProperties:
  3228. this.extendedPropsPart = part = new extended_props_part_1.ExtendedPropsPart(this._package, path);
  3229. break;
  3230. }
  3231. if (part == null)
  3232. return Promise.resolve(null);
  3233. this.partsMap[path] = part;
  3234. this.parts.push(part);
  3235. return part.load().then(function () {
  3236. if (part.rels == null || part.rels.length == 0)
  3237. return part;
  3238. var folder = (0, utils_1.splitPath)(part.path)[0];
  3239. var rels = part.rels.map(function (rel) {
  3240. return _this.loadRelationshipPart((0, utils_1.resolvePath)(rel.target, folder), rel.type);
  3241. });
  3242. return Promise.all(rels).then(function () { return part; });
  3243. });
  3244. };
  3245. WordDocument.prototype.loadDocumentImage = function (id) {
  3246. return this.loadResource(this.documentPart, id, "blob")
  3247. .then(function (x) { return x ? URL.createObjectURL(x) : null; });
  3248. };
  3249. WordDocument.prototype.loadNumberingImage = function (id) {
  3250. return this.loadResource(this.numberingPart, id, "blob")
  3251. .then(function (x) { return x ? URL.createObjectURL(x) : null; });
  3252. };
  3253. WordDocument.prototype.loadFont = function (id, key) {
  3254. return this.loadResource(this.fontTablePart, id, "uint8array")
  3255. .then(function (x) { return x ? URL.createObjectURL(new Blob([deobfuscate(x, key)])) : x; });
  3256. };
  3257. WordDocument.prototype.getPathById = function (part, id) {
  3258. var rel = part.rels.find(function (x) { return x.id == id; });
  3259. var folder = (0, utils_1.splitPath)(part.path)[0];
  3260. return rel ? (0, utils_1.resolvePath)(rel.target, folder) : null;
  3261. };
  3262. WordDocument.prototype.loadResource = function (part, id, outputType) {
  3263. var path = this.getPathById(part, id);
  3264. return path ? this._package.load(path, outputType) : Promise.resolve(null);
  3265. };
  3266. return WordDocument;
  3267. }());
  3268. exports.WordDocument = WordDocument;
  3269. function deobfuscate(data, guidKey) {
  3270. var len = 16;
  3271. var trimmed = guidKey.replace(/{|}|-/g, "");
  3272. var numbers = new Array(len);
  3273. for (var i = 0; i < len; i++)
  3274. numbers[len - i - 1] = parseInt(trimmed.substr(i * 2, 2), 16);
  3275. for (var i = 0; i < 32; i++)
  3276. data[i] = data[i] ^ numbers[i % len];
  3277. return data;
  3278. }
  3279. exports.deobfuscate = deobfuscate;
  3280. /***/ }),
  3281. /***/ "jszip":
  3282. /*!************************!*\
  3283. !*** external "JSZip" ***!
  3284. \************************/
  3285. /***/ ((module) => {
  3286. module.exports = __WEBPACK_EXTERNAL_MODULE_jszip__;
  3287. /***/ })
  3288. /******/ });
  3289. /************************************************************************/
  3290. /******/ // The module cache
  3291. /******/ var __webpack_module_cache__ = {};
  3292. /******/
  3293. /******/ // The require function
  3294. /******/ function __webpack_require__(moduleId) {
  3295. /******/ // Check if module is in cache
  3296. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  3297. /******/ if (cachedModule !== undefined) {
  3298. /******/ return cachedModule.exports;
  3299. /******/ }
  3300. /******/ // Create a new module (and put it into the cache)
  3301. /******/ var module = __webpack_module_cache__[moduleId] = {
  3302. /******/ // no module.id needed
  3303. /******/ // no module.loaded needed
  3304. /******/ exports: {}
  3305. /******/ };
  3306. /******/
  3307. /******/ // Execute the module function
  3308. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  3309. /******/
  3310. /******/ // Return the exports of the module
  3311. /******/ return module.exports;
  3312. /******/ }
  3313. /******/
  3314. /************************************************************************/
  3315. /******/
  3316. /******/ // startup
  3317. /******/ // Load entry module and return exports
  3318. /******/ // This entry module is referenced by other modules so it can't be inlined
  3319. /******/ var __webpack_exports__ = __webpack_require__("./src/docx-preview.ts");
  3320. /******/
  3321. /******/ return __webpack_exports__;
  3322. /******/ })()
  3323. ;
  3324. });
  3325. //# sourceMappingURL=docx-preview.js.map