2
0

template.js 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.Value = exports.Text = exports.TemplateNamespace = exports.Template = exports.SetProperty = exports.Items = exports.Field = exports.BindItems = void 0;
  27. var _xfa_object = require("./xfa_object.js");
  28. var _namespaces = require("./namespaces.js");
  29. var _layout = require("./layout.js");
  30. var _html_utils = require("./html_utils.js");
  31. var _utils = require("./utils.js");
  32. var _util = require("../../shared/util.js");
  33. var _som = require("./som.js");
  34. const TEMPLATE_NS_ID = _namespaces.NamespaceIds.template.id;
  35. const SVG_NS = "http://www.w3.org/2000/svg";
  36. const MAX_ATTEMPTS_FOR_LRTB_LAYOUT = 2;
  37. const MAX_EMPTY_PAGES = 3;
  38. function hasMargin(node) {
  39. return node.margin && (node.margin.topInset || node.margin.rightInset || node.margin.bottomInset || node.margin.leftInset);
  40. }
  41. function _setValue(templateNode, value) {
  42. if (!templateNode.value) {
  43. const nodeValue = new Value({});
  44. templateNode[_xfa_object.$appendChild](nodeValue);
  45. templateNode.value = nodeValue;
  46. }
  47. templateNode.value[_xfa_object.$setValue](value);
  48. }
  49. function* getContainedChildren(node) {
  50. for (const child of node[_xfa_object.$getChildren]()) {
  51. if (child instanceof SubformSet) {
  52. yield* child[_xfa_object.$getContainedChildren]();
  53. continue;
  54. }
  55. yield child;
  56. }
  57. }
  58. function setTabIndex(node) {
  59. while (node) {
  60. if (!node.traversal || node[_xfa_object.$tabIndex]) {
  61. return;
  62. }
  63. let next = null;
  64. for (const child of node.traversal[_xfa_object.$getChildren]()) {
  65. if (child.operation === "next") {
  66. next = child;
  67. break;
  68. }
  69. }
  70. if (!next || !next.ref) {
  71. return;
  72. }
  73. const root = node[_xfa_object.$getTemplateRoot]();
  74. node[_xfa_object.$tabIndex] = ++root[_xfa_object.$tabIndex];
  75. const ref = root[_xfa_object.$searchNode](next.ref, node);
  76. if (!ref) {
  77. return;
  78. }
  79. node = ref[0];
  80. }
  81. }
  82. function valueToHtml(value) {
  83. return _utils.HTMLResult.success({
  84. name: "div",
  85. attributes: {
  86. class: ["xfaRich"],
  87. style: Object.create(null)
  88. },
  89. children: [{
  90. name: "span",
  91. attributes: {
  92. style: Object.create(null)
  93. },
  94. value
  95. }]
  96. });
  97. }
  98. function setFirstUnsplittable(node) {
  99. const root = node[_xfa_object.$getTemplateRoot]();
  100. if (root[_xfa_object.$extra].firstUnsplittable === null) {
  101. root[_xfa_object.$extra].firstUnsplittable = node;
  102. root[_xfa_object.$extra].noLayoutFailure = true;
  103. }
  104. }
  105. function unsetFirstUnsplittable(node) {
  106. const root = node[_xfa_object.$getTemplateRoot]();
  107. if (root[_xfa_object.$extra].firstUnsplittable === node) {
  108. root[_xfa_object.$extra].noLayoutFailure = false;
  109. }
  110. }
  111. function handleBreak(node) {
  112. if (node[_xfa_object.$extra]) {
  113. return false;
  114. }
  115. node[_xfa_object.$extra] = Object.create(null);
  116. if (node.targetType === "auto") {
  117. return false;
  118. }
  119. const root = node[_xfa_object.$getTemplateRoot]();
  120. let target = null;
  121. if (node.target) {
  122. target = root[_xfa_object.$searchNode](node.target, node[_xfa_object.$getParent]());
  123. if (!target) {
  124. return false;
  125. }
  126. target = target[0];
  127. }
  128. const {
  129. currentPageArea,
  130. currentContentArea
  131. } = root[_xfa_object.$extra];
  132. if (node.targetType === "pageArea") {
  133. if (!(target instanceof PageArea)) {
  134. target = null;
  135. }
  136. if (node.startNew) {
  137. node[_xfa_object.$extra].target = target || currentPageArea;
  138. return true;
  139. } else if (target && target !== currentPageArea) {
  140. node[_xfa_object.$extra].target = target;
  141. return true;
  142. }
  143. return false;
  144. }
  145. if (!(target instanceof ContentArea)) {
  146. target = null;
  147. }
  148. const pageArea = target && target[_xfa_object.$getParent]();
  149. let index;
  150. if (node.startNew) {
  151. if (target) {
  152. const contentAreas = pageArea.contentArea.children;
  153. index = contentAreas.findIndex(e => e === target) - 1;
  154. } else {
  155. index = currentPageArea.contentArea.children.findIndex(e => e === currentContentArea);
  156. }
  157. } else if (target && target !== currentContentArea) {
  158. const contentAreas = pageArea.contentArea.children;
  159. index = contentAreas.findIndex(e => e === target) - 1;
  160. } else {
  161. return false;
  162. }
  163. node[_xfa_object.$extra].target = pageArea === currentPageArea ? null : pageArea;
  164. node[_xfa_object.$extra].index = index;
  165. return true;
  166. }
  167. function handleOverflow(node, extraNode, space) {
  168. const root = node[_xfa_object.$getTemplateRoot]();
  169. const saved = root[_xfa_object.$extra].noLayoutFailure;
  170. const savedMethod = extraNode[_xfa_object.$getSubformParent];
  171. extraNode[_xfa_object.$getSubformParent] = () => node;
  172. root[_xfa_object.$extra].noLayoutFailure = true;
  173. const res = extraNode[_xfa_object.$toHTML](space);
  174. node[_xfa_object.$addHTML](res.html, res.bbox);
  175. root[_xfa_object.$extra].noLayoutFailure = saved;
  176. extraNode[_xfa_object.$getSubformParent] = savedMethod;
  177. }
  178. class AppearanceFilter extends _xfa_object.StringObject {
  179. constructor(attributes) {
  180. super(TEMPLATE_NS_ID, "appearanceFilter");
  181. this.id = attributes.id || "";
  182. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  183. this.use = attributes.use || "";
  184. this.usehref = attributes.usehref || "";
  185. }
  186. }
  187. class Arc extends _xfa_object.XFAObject {
  188. constructor(attributes) {
  189. super(TEMPLATE_NS_ID, "arc", true);
  190. this.circular = (0, _utils.getInteger)({
  191. data: attributes.circular,
  192. defaultValue: 0,
  193. validate: x => x === 1
  194. });
  195. this.hand = (0, _utils.getStringOption)(attributes.hand, ["even", "left", "right"]);
  196. this.id = attributes.id || "";
  197. this.startAngle = (0, _utils.getFloat)({
  198. data: attributes.startAngle,
  199. defaultValue: 0,
  200. validate: x => true
  201. });
  202. this.sweepAngle = (0, _utils.getFloat)({
  203. data: attributes.sweepAngle,
  204. defaultValue: 360,
  205. validate: x => true
  206. });
  207. this.use = attributes.use || "";
  208. this.usehref = attributes.usehref || "";
  209. this.edge = null;
  210. this.fill = null;
  211. }
  212. [_xfa_object.$toHTML]() {
  213. const edge = this.edge ? this.edge : new Edge({});
  214. const edgeStyle = edge[_xfa_object.$toStyle]();
  215. const style = Object.create(null);
  216. if (this.fill && this.fill.presence === "visible") {
  217. Object.assign(style, this.fill[_xfa_object.$toStyle]());
  218. } else {
  219. style.fill = "transparent";
  220. }
  221. style.strokeWidth = (0, _html_utils.measureToString)(edge.presence === "visible" ? edge.thickness : 0);
  222. style.stroke = edgeStyle.color;
  223. let arc;
  224. const attributes = {
  225. xmlns: SVG_NS,
  226. style: {
  227. width: "100%",
  228. height: "100%",
  229. overflow: "visible"
  230. }
  231. };
  232. if (this.startAngle === 0 && this.sweepAngle === 360) {
  233. arc = {
  234. name: "ellipse",
  235. attributes: {
  236. xmlns: SVG_NS,
  237. cx: "50%",
  238. cy: "50%",
  239. rx: "50%",
  240. ry: "50%",
  241. style
  242. }
  243. };
  244. } else {
  245. const startAngle = this.startAngle * Math.PI / 180;
  246. const sweepAngle = this.sweepAngle * Math.PI / 180;
  247. const largeArc = this.sweepAngle - this.startAngle > 180 ? 1 : 0;
  248. const [x1, y1, x2, y2] = [50 * (1 + Math.cos(startAngle)), 50 * (1 - Math.sin(startAngle)), 50 * (1 + Math.cos(sweepAngle)), 50 * (1 - Math.sin(sweepAngle))];
  249. arc = {
  250. name: "path",
  251. attributes: {
  252. xmlns: SVG_NS,
  253. d: `M ${x1} ${y1} A 50 50 0 ${largeArc} 0 ${x2} ${y2}`,
  254. vectorEffect: "non-scaling-stroke",
  255. style
  256. }
  257. };
  258. Object.assign(attributes, {
  259. viewBox: "0 0 100 100",
  260. preserveAspectRatio: "none"
  261. });
  262. }
  263. const svg = {
  264. name: "svg",
  265. children: [arc],
  266. attributes
  267. };
  268. const parent = this[_xfa_object.$getParent]()[_xfa_object.$getParent]();
  269. if (hasMargin(parent)) {
  270. return _utils.HTMLResult.success({
  271. name: "div",
  272. attributes: {
  273. style: {
  274. display: "inline",
  275. width: "100%",
  276. height: "100%"
  277. }
  278. },
  279. children: [svg]
  280. });
  281. }
  282. svg.attributes.style.position = "absolute";
  283. return _utils.HTMLResult.success(svg);
  284. }
  285. }
  286. class Area extends _xfa_object.XFAObject {
  287. constructor(attributes) {
  288. super(TEMPLATE_NS_ID, "area", true);
  289. this.colSpan = (0, _utils.getInteger)({
  290. data: attributes.colSpan,
  291. defaultValue: 1,
  292. validate: n => n >= 1 || n === -1
  293. });
  294. this.id = attributes.id || "";
  295. this.name = attributes.name || "";
  296. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  297. this.use = attributes.use || "";
  298. this.usehref = attributes.usehref || "";
  299. this.x = (0, _utils.getMeasurement)(attributes.x, "0pt");
  300. this.y = (0, _utils.getMeasurement)(attributes.y, "0pt");
  301. this.desc = null;
  302. this.extras = null;
  303. this.area = new _xfa_object.XFAObjectArray();
  304. this.draw = new _xfa_object.XFAObjectArray();
  305. this.exObject = new _xfa_object.XFAObjectArray();
  306. this.exclGroup = new _xfa_object.XFAObjectArray();
  307. this.field = new _xfa_object.XFAObjectArray();
  308. this.subform = new _xfa_object.XFAObjectArray();
  309. this.subformSet = new _xfa_object.XFAObjectArray();
  310. }
  311. *[_xfa_object.$getContainedChildren]() {
  312. yield* getContainedChildren(this);
  313. }
  314. [_xfa_object.$isTransparent]() {
  315. return true;
  316. }
  317. [_xfa_object.$addHTML](html, bbox) {
  318. const [x, y, w, h] = bbox;
  319. this[_xfa_object.$extra].width = Math.max(this[_xfa_object.$extra].width, x + w);
  320. this[_xfa_object.$extra].height = Math.max(this[_xfa_object.$extra].height, y + h);
  321. this[_xfa_object.$extra].children.push(html);
  322. }
  323. [_xfa_object.$getAvailableSpace]() {
  324. return this[_xfa_object.$extra].availableSpace;
  325. }
  326. [_xfa_object.$toHTML](availableSpace) {
  327. const style = (0, _html_utils.toStyle)(this, "position");
  328. const attributes = {
  329. style,
  330. id: this[_xfa_object.$uid],
  331. class: ["xfaArea"]
  332. };
  333. if ((0, _html_utils.isPrintOnly)(this)) {
  334. attributes.class.push("xfaPrintOnly");
  335. }
  336. if (this.name) {
  337. attributes.xfaName = this.name;
  338. }
  339. const children = [];
  340. this[_xfa_object.$extra] = {
  341. children,
  342. width: 0,
  343. height: 0,
  344. availableSpace
  345. };
  346. const result = this[_xfa_object.$childrenToHTML]({
  347. filter: new Set(["area", "draw", "field", "exclGroup", "subform", "subformSet"]),
  348. include: true
  349. });
  350. if (!result.success) {
  351. if (result.isBreak()) {
  352. return result;
  353. }
  354. delete this[_xfa_object.$extra];
  355. return _utils.HTMLResult.FAILURE;
  356. }
  357. style.width = (0, _html_utils.measureToString)(this[_xfa_object.$extra].width);
  358. style.height = (0, _html_utils.measureToString)(this[_xfa_object.$extra].height);
  359. const html = {
  360. name: "div",
  361. attributes,
  362. children
  363. };
  364. const bbox = [this.x, this.y, this[_xfa_object.$extra].width, this[_xfa_object.$extra].height];
  365. delete this[_xfa_object.$extra];
  366. return _utils.HTMLResult.success(html, bbox);
  367. }
  368. }
  369. class Assist extends _xfa_object.XFAObject {
  370. constructor(attributes) {
  371. super(TEMPLATE_NS_ID, "assist", true);
  372. this.id = attributes.id || "";
  373. this.role = attributes.role || "";
  374. this.use = attributes.use || "";
  375. this.usehref = attributes.usehref || "";
  376. this.speak = null;
  377. this.toolTip = null;
  378. }
  379. [_xfa_object.$toHTML]() {
  380. return this.toolTip && this.toolTip[_xfa_object.$content] ? this.toolTip[_xfa_object.$content] : null;
  381. }
  382. }
  383. class Barcode extends _xfa_object.XFAObject {
  384. constructor(attributes) {
  385. super(TEMPLATE_NS_ID, "barcode", true);
  386. this.charEncoding = (0, _utils.getKeyword)({
  387. data: attributes.charEncoding ? attributes.charEncoding.toLowerCase() : "",
  388. defaultValue: "",
  389. validate: k => ["utf-8", "big-five", "fontspecific", "gbk", "gb-18030", "gb-2312", "ksc-5601", "none", "shift-jis", "ucs-2", "utf-16"].includes(k) || k.match(/iso-8859-[0-9]{2}/)
  390. });
  391. this.checksum = (0, _utils.getStringOption)(attributes.checksum, ["none", "1mod10", "1mod10_1mod11", "2mod10", "auto"]);
  392. this.dataColumnCount = (0, _utils.getInteger)({
  393. data: attributes.dataColumnCount,
  394. defaultValue: -1,
  395. validate: x => x >= 0
  396. });
  397. this.dataLength = (0, _utils.getInteger)({
  398. data: attributes.dataLength,
  399. defaultValue: -1,
  400. validate: x => x >= 0
  401. });
  402. this.dataPrep = (0, _utils.getStringOption)(attributes.dataPrep, ["none", "flateCompress"]);
  403. this.dataRowCount = (0, _utils.getInteger)({
  404. data: attributes.dataRowCount,
  405. defaultValue: -1,
  406. validate: x => x >= 0
  407. });
  408. this.endChar = attributes.endChar || "";
  409. this.errorCorrectionLevel = (0, _utils.getInteger)({
  410. data: attributes.errorCorrectionLevel,
  411. defaultValue: -1,
  412. validate: x => x >= 0 && x <= 8
  413. });
  414. this.id = attributes.id || "";
  415. this.moduleHeight = (0, _utils.getMeasurement)(attributes.moduleHeight, "5mm");
  416. this.moduleWidth = (0, _utils.getMeasurement)(attributes.moduleWidth, "0.25mm");
  417. this.printCheckDigit = (0, _utils.getInteger)({
  418. data: attributes.printCheckDigit,
  419. defaultValue: 0,
  420. validate: x => x === 1
  421. });
  422. this.rowColumnRatio = (0, _utils.getRatio)(attributes.rowColumnRatio);
  423. this.startChar = attributes.startChar || "";
  424. this.textLocation = (0, _utils.getStringOption)(attributes.textLocation, ["below", "above", "aboveEmbedded", "belowEmbedded", "none"]);
  425. this.truncate = (0, _utils.getInteger)({
  426. data: attributes.truncate,
  427. defaultValue: 0,
  428. validate: x => x === 1
  429. });
  430. this.type = (0, _utils.getStringOption)(attributes.type ? attributes.type.toLowerCase() : "", ["aztec", "codabar", "code2of5industrial", "code2of5interleaved", "code2of5matrix", "code2of5standard", "code3of9", "code3of9extended", "code11", "code49", "code93", "code128", "code128a", "code128b", "code128c", "code128sscc", "datamatrix", "ean8", "ean8add2", "ean8add5", "ean13", "ean13add2", "ean13add5", "ean13pwcd", "fim", "logmars", "maxicode", "msi", "pdf417", "pdf417macro", "plessey", "postauscust2", "postauscust3", "postausreplypaid", "postausstandard", "postukrm4scc", "postusdpbc", "postusimb", "postusstandard", "postus5zip", "qrcode", "rfid", "rss14", "rss14expanded", "rss14limited", "rss14stacked", "rss14stackedomni", "rss14truncated", "telepen", "ucc128", "ucc128random", "ucc128sscc", "upca", "upcaadd2", "upcaadd5", "upcapwcd", "upce", "upceadd2", "upceadd5", "upcean2", "upcean5", "upsmaxicode"]);
  431. this.upsMode = (0, _utils.getStringOption)(attributes.upsMode, ["usCarrier", "internationalCarrier", "secureSymbol", "standardSymbol"]);
  432. this.use = attributes.use || "";
  433. this.usehref = attributes.usehref || "";
  434. this.wideNarrowRatio = (0, _utils.getRatio)(attributes.wideNarrowRatio);
  435. this.encrypt = null;
  436. this.extras = null;
  437. }
  438. }
  439. class Bind extends _xfa_object.XFAObject {
  440. constructor(attributes) {
  441. super(TEMPLATE_NS_ID, "bind", true);
  442. this.match = (0, _utils.getStringOption)(attributes.match, ["once", "dataRef", "global", "none"]);
  443. this.ref = attributes.ref || "";
  444. this.picture = null;
  445. }
  446. }
  447. class BindItems extends _xfa_object.XFAObject {
  448. constructor(attributes) {
  449. super(TEMPLATE_NS_ID, "bindItems");
  450. this.connection = attributes.connection || "";
  451. this.labelRef = attributes.labelRef || "";
  452. this.ref = attributes.ref || "";
  453. this.valueRef = attributes.valueRef || "";
  454. }
  455. }
  456. exports.BindItems = BindItems;
  457. class Bookend extends _xfa_object.XFAObject {
  458. constructor(attributes) {
  459. super(TEMPLATE_NS_ID, "bookend");
  460. this.id = attributes.id || "";
  461. this.leader = attributes.leader || "";
  462. this.trailer = attributes.trailer || "";
  463. this.use = attributes.use || "";
  464. this.usehref = attributes.usehref || "";
  465. }
  466. }
  467. class BooleanElement extends _xfa_object.Option01 {
  468. constructor(attributes) {
  469. super(TEMPLATE_NS_ID, "boolean");
  470. this.id = attributes.id || "";
  471. this.name = attributes.name || "";
  472. this.use = attributes.use || "";
  473. this.usehref = attributes.usehref || "";
  474. }
  475. [_xfa_object.$toHTML](availableSpace) {
  476. return valueToHtml(this[_xfa_object.$content] === 1 ? "1" : "0");
  477. }
  478. }
  479. class Border extends _xfa_object.XFAObject {
  480. constructor(attributes) {
  481. super(TEMPLATE_NS_ID, "border", true);
  482. this.break = (0, _utils.getStringOption)(attributes.break, ["close", "open"]);
  483. this.hand = (0, _utils.getStringOption)(attributes.hand, ["even", "left", "right"]);
  484. this.id = attributes.id || "";
  485. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  486. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  487. this.use = attributes.use || "";
  488. this.usehref = attributes.usehref || "";
  489. this.corner = new _xfa_object.XFAObjectArray(4);
  490. this.edge = new _xfa_object.XFAObjectArray(4);
  491. this.extras = null;
  492. this.fill = null;
  493. this.margin = null;
  494. }
  495. [_xfa_object.$toStyle]() {
  496. const edges = this.edge.children.slice();
  497. if (edges.length < 4) {
  498. const defaultEdge = edges[edges.length - 1] || new Edge({});
  499. for (let i = edges.length; i < 4; i++) {
  500. edges.push(defaultEdge);
  501. }
  502. }
  503. const edgeStyles = edges.map(node => {
  504. const style = node[_xfa_object.$toStyle]();
  505. style.color = style.color || "#000000";
  506. return style;
  507. });
  508. const widths = edges.map(edge => edge.thickness);
  509. const insets = [0, 0, 0, 0];
  510. if (this.margin) {
  511. insets[0] = this.margin.topInset;
  512. insets[1] = this.margin.rightInset;
  513. insets[2] = this.margin.bottomInset;
  514. insets[3] = this.margin.leftInset;
  515. }
  516. this[_xfa_object.$extra] = {
  517. widths,
  518. insets
  519. };
  520. const style = Object.create(null);
  521. if (this.margin) {
  522. Object.assign(style, this.margin[_xfa_object.$toStyle]());
  523. }
  524. if (this.fill && this.fill.presence === "visible") {
  525. Object.assign(style, this.fill[_xfa_object.$toStyle]());
  526. }
  527. if (this.corner.children.some(node => node.radius !== 0)) {
  528. const cornerStyles = this.corner.children.map(node => node[_xfa_object.$toStyle]());
  529. if (cornerStyles.length === 2 || cornerStyles.length === 3) {
  530. const last = cornerStyles[cornerStyles.length - 1];
  531. for (let i = cornerStyles.length; i < 4; i++) {
  532. cornerStyles.push(last);
  533. }
  534. }
  535. style.borderRadius = cornerStyles.map(s => s.radius).join(" ");
  536. }
  537. switch (this.presence) {
  538. case "invisible":
  539. case "hidden":
  540. style.borderStyle = "";
  541. break;
  542. case "inactive":
  543. style.borderStyle = "none";
  544. break;
  545. default:
  546. style.borderStyle = edgeStyles.map(s => s.style).join(" ");
  547. break;
  548. }
  549. style.borderWidth = edgeStyles.map(s => s.width).join(" ");
  550. style.borderColor = edgeStyles.map(s => s.color).join(" ");
  551. return style;
  552. }
  553. }
  554. class Break extends _xfa_object.XFAObject {
  555. constructor(attributes) {
  556. super(TEMPLATE_NS_ID, "break", true);
  557. this.after = (0, _utils.getStringOption)(attributes.after, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]);
  558. this.afterTarget = attributes.afterTarget || "";
  559. this.before = (0, _utils.getStringOption)(attributes.before, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]);
  560. this.beforeTarget = attributes.beforeTarget || "";
  561. this.bookendLeader = attributes.bookendLeader || "";
  562. this.bookendTrailer = attributes.bookendTrailer || "";
  563. this.id = attributes.id || "";
  564. this.overflowLeader = attributes.overflowLeader || "";
  565. this.overflowTarget = attributes.overflowTarget || "";
  566. this.overflowTrailer = attributes.overflowTrailer || "";
  567. this.startNew = (0, _utils.getInteger)({
  568. data: attributes.startNew,
  569. defaultValue: 0,
  570. validate: x => x === 1
  571. });
  572. this.use = attributes.use || "";
  573. this.usehref = attributes.usehref || "";
  574. this.extras = null;
  575. }
  576. }
  577. class BreakAfter extends _xfa_object.XFAObject {
  578. constructor(attributes) {
  579. super(TEMPLATE_NS_ID, "breakAfter", true);
  580. this.id = attributes.id || "";
  581. this.leader = attributes.leader || "";
  582. this.startNew = (0, _utils.getInteger)({
  583. data: attributes.startNew,
  584. defaultValue: 0,
  585. validate: x => x === 1
  586. });
  587. this.target = attributes.target || "";
  588. this.targetType = (0, _utils.getStringOption)(attributes.targetType, ["auto", "contentArea", "pageArea"]);
  589. this.trailer = attributes.trailer || "";
  590. this.use = attributes.use || "";
  591. this.usehref = attributes.usehref || "";
  592. this.script = null;
  593. }
  594. }
  595. class BreakBefore extends _xfa_object.XFAObject {
  596. constructor(attributes) {
  597. super(TEMPLATE_NS_ID, "breakBefore", true);
  598. this.id = attributes.id || "";
  599. this.leader = attributes.leader || "";
  600. this.startNew = (0, _utils.getInteger)({
  601. data: attributes.startNew,
  602. defaultValue: 0,
  603. validate: x => x === 1
  604. });
  605. this.target = attributes.target || "";
  606. this.targetType = (0, _utils.getStringOption)(attributes.targetType, ["auto", "contentArea", "pageArea"]);
  607. this.trailer = attributes.trailer || "";
  608. this.use = attributes.use || "";
  609. this.usehref = attributes.usehref || "";
  610. this.script = null;
  611. }
  612. [_xfa_object.$toHTML](availableSpace) {
  613. this[_xfa_object.$extra] = {};
  614. return _utils.HTMLResult.FAILURE;
  615. }
  616. }
  617. class Button extends _xfa_object.XFAObject {
  618. constructor(attributes) {
  619. super(TEMPLATE_NS_ID, "button", true);
  620. this.highlight = (0, _utils.getStringOption)(attributes.highlight, ["inverted", "none", "outline", "push"]);
  621. this.id = attributes.id || "";
  622. this.use = attributes.use || "";
  623. this.usehref = attributes.usehref || "";
  624. this.extras = null;
  625. }
  626. [_xfa_object.$toHTML](availableSpace) {
  627. return _utils.HTMLResult.success({
  628. name: "button",
  629. attributes: {
  630. id: this[_xfa_object.$uid],
  631. class: ["xfaButton"],
  632. style: {}
  633. },
  634. children: []
  635. });
  636. }
  637. }
  638. class Calculate extends _xfa_object.XFAObject {
  639. constructor(attributes) {
  640. super(TEMPLATE_NS_ID, "calculate", true);
  641. this.id = attributes.id || "";
  642. this.override = (0, _utils.getStringOption)(attributes.override, ["disabled", "error", "ignore", "warning"]);
  643. this.use = attributes.use || "";
  644. this.usehref = attributes.usehref || "";
  645. this.extras = null;
  646. this.message = null;
  647. this.script = null;
  648. }
  649. }
  650. class Caption extends _xfa_object.XFAObject {
  651. constructor(attributes) {
  652. super(TEMPLATE_NS_ID, "caption", true);
  653. this.id = attributes.id || "";
  654. this.placement = (0, _utils.getStringOption)(attributes.placement, ["left", "bottom", "inline", "right", "top"]);
  655. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  656. this.reserve = Math.ceil((0, _utils.getMeasurement)(attributes.reserve));
  657. this.use = attributes.use || "";
  658. this.usehref = attributes.usehref || "";
  659. this.extras = null;
  660. this.font = null;
  661. this.margin = null;
  662. this.para = null;
  663. this.value = null;
  664. }
  665. [_xfa_object.$setValue](value) {
  666. _setValue(this, value);
  667. }
  668. [_xfa_object.$getExtra](availableSpace) {
  669. if (!this[_xfa_object.$extra]) {
  670. let {
  671. width,
  672. height
  673. } = availableSpace;
  674. switch (this.placement) {
  675. case "left":
  676. case "right":
  677. case "inline":
  678. width = this.reserve <= 0 ? width : this.reserve;
  679. break;
  680. case "top":
  681. case "bottom":
  682. height = this.reserve <= 0 ? height : this.reserve;
  683. break;
  684. }
  685. this[_xfa_object.$extra] = (0, _html_utils.layoutNode)(this, {
  686. width,
  687. height
  688. });
  689. }
  690. return this[_xfa_object.$extra];
  691. }
  692. [_xfa_object.$toHTML](availableSpace) {
  693. if (!this.value) {
  694. return _utils.HTMLResult.EMPTY;
  695. }
  696. const value = this.value[_xfa_object.$toHTML](availableSpace).html;
  697. if (!value) {
  698. return _utils.HTMLResult.EMPTY;
  699. }
  700. const savedReserve = this.reserve;
  701. if (this.reserve <= 0) {
  702. const {
  703. w,
  704. h
  705. } = this[_xfa_object.$getExtra](availableSpace);
  706. switch (this.placement) {
  707. case "left":
  708. case "right":
  709. case "inline":
  710. this.reserve = w;
  711. break;
  712. case "top":
  713. case "bottom":
  714. this.reserve = h;
  715. break;
  716. }
  717. }
  718. const children = [];
  719. if (typeof value === "string") {
  720. children.push({
  721. name: "#text",
  722. value
  723. });
  724. } else {
  725. children.push(value);
  726. }
  727. const style = (0, _html_utils.toStyle)(this, "font", "margin", "visibility");
  728. switch (this.placement) {
  729. case "left":
  730. case "right":
  731. if (this.reserve > 0) {
  732. style.width = (0, _html_utils.measureToString)(this.reserve);
  733. }
  734. break;
  735. case "top":
  736. case "bottom":
  737. if (this.reserve > 0) {
  738. style.height = (0, _html_utils.measureToString)(this.reserve);
  739. }
  740. break;
  741. }
  742. (0, _html_utils.setPara)(this, null, value);
  743. this.reserve = savedReserve;
  744. return _utils.HTMLResult.success({
  745. name: "div",
  746. attributes: {
  747. style,
  748. class: ["xfaCaption"]
  749. },
  750. children
  751. });
  752. }
  753. }
  754. class Certificate extends _xfa_object.StringObject {
  755. constructor(attributes) {
  756. super(TEMPLATE_NS_ID, "certificate");
  757. this.id = attributes.id || "";
  758. this.name = attributes.name || "";
  759. this.use = attributes.use || "";
  760. this.usehref = attributes.usehref || "";
  761. }
  762. }
  763. class Certificates extends _xfa_object.XFAObject {
  764. constructor(attributes) {
  765. super(TEMPLATE_NS_ID, "certificates", true);
  766. this.credentialServerPolicy = (0, _utils.getStringOption)(attributes.credentialServerPolicy, ["optional", "required"]);
  767. this.id = attributes.id || "";
  768. this.url = attributes.url || "";
  769. this.urlPolicy = attributes.urlPolicy || "";
  770. this.use = attributes.use || "";
  771. this.usehref = attributes.usehref || "";
  772. this.encryption = null;
  773. this.issuers = null;
  774. this.keyUsage = null;
  775. this.oids = null;
  776. this.signing = null;
  777. this.subjectDNs = null;
  778. }
  779. }
  780. class CheckButton extends _xfa_object.XFAObject {
  781. constructor(attributes) {
  782. super(TEMPLATE_NS_ID, "checkButton", true);
  783. this.id = attributes.id || "";
  784. this.mark = (0, _utils.getStringOption)(attributes.mark, ["default", "check", "circle", "cross", "diamond", "square", "star"]);
  785. this.shape = (0, _utils.getStringOption)(attributes.shape, ["square", "round"]);
  786. this.size = (0, _utils.getMeasurement)(attributes.size, "10pt");
  787. this.use = attributes.use || "";
  788. this.usehref = attributes.usehref || "";
  789. this.border = null;
  790. this.extras = null;
  791. this.margin = null;
  792. }
  793. [_xfa_object.$toHTML](availableSpace) {
  794. const style = (0, _html_utils.toStyle)("margin");
  795. const size = (0, _html_utils.measureToString)(this.size);
  796. style.width = style.height = size;
  797. let type;
  798. let className;
  799. let groupId;
  800. const field = this[_xfa_object.$getParent]()[_xfa_object.$getParent]();
  801. const items = field.items.children.length && field.items.children[0][_xfa_object.$toHTML]().html || [];
  802. const exportedValue = {
  803. on: (items[0] || "on").toString(),
  804. off: (items[1] || "off").toString()
  805. };
  806. const value = field.value && field.value[_xfa_object.$text]() || "off";
  807. const checked = value === exportedValue.on || undefined;
  808. const container = field[_xfa_object.$getSubformParent]();
  809. const fieldId = field[_xfa_object.$uid];
  810. let dataId;
  811. if (container instanceof ExclGroup) {
  812. groupId = container[_xfa_object.$uid];
  813. type = "radio";
  814. className = "xfaRadio";
  815. dataId = container[_xfa_object.$data] && container[_xfa_object.$data][_xfa_object.$uid] || container[_xfa_object.$uid];
  816. } else {
  817. type = "checkbox";
  818. className = "xfaCheckbox";
  819. dataId = field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid];
  820. }
  821. const input = {
  822. name: "input",
  823. attributes: {
  824. class: [className],
  825. style,
  826. fieldId,
  827. dataId,
  828. type,
  829. checked,
  830. xfaOn: exportedValue.on
  831. }
  832. };
  833. if (groupId) {
  834. input.attributes.name = groupId;
  835. }
  836. return _utils.HTMLResult.success({
  837. name: "label",
  838. attributes: {
  839. class: ["xfaLabel"]
  840. },
  841. children: [input]
  842. });
  843. }
  844. }
  845. class ChoiceList extends _xfa_object.XFAObject {
  846. constructor(attributes) {
  847. super(TEMPLATE_NS_ID, "choiceList", true);
  848. this.commitOn = (0, _utils.getStringOption)(attributes.commitOn, ["select", "exit"]);
  849. this.id = attributes.id || "";
  850. this.open = (0, _utils.getStringOption)(attributes.open, ["userControl", "always", "multiSelect", "onEntry"]);
  851. this.textEntry = (0, _utils.getInteger)({
  852. data: attributes.textEntry,
  853. defaultValue: 0,
  854. validate: x => x === 1
  855. });
  856. this.use = attributes.use || "";
  857. this.usehref = attributes.usehref || "";
  858. this.border = null;
  859. this.extras = null;
  860. this.margin = null;
  861. }
  862. [_xfa_object.$toHTML](availableSpace) {
  863. const style = (0, _html_utils.toStyle)(this, "border", "margin");
  864. const ui = this[_xfa_object.$getParent]();
  865. const field = ui[_xfa_object.$getParent]();
  866. const children = [];
  867. if (field.items.children.length > 0) {
  868. const items = field.items;
  869. let displayedIndex = 0;
  870. let saveIndex = 0;
  871. if (items.children.length === 2) {
  872. displayedIndex = items.children[0].save;
  873. saveIndex = 1 - displayedIndex;
  874. }
  875. const displayed = items.children[displayedIndex][_xfa_object.$toHTML]().html;
  876. const values = items.children[saveIndex][_xfa_object.$toHTML]().html;
  877. let selected = false;
  878. const value = field.value && field.value[_xfa_object.$text]() || "";
  879. for (let i = 0, ii = displayed.length; i < ii; i++) {
  880. const option = {
  881. name: "option",
  882. attributes: {
  883. value: values[i] || displayed[i]
  884. },
  885. value: displayed[i]
  886. };
  887. if (values[i] === value) {
  888. option.attributes.selected = selected = true;
  889. }
  890. children.push(option);
  891. }
  892. if (!selected) {
  893. children.splice(0, 0, {
  894. name: "option",
  895. attributes: {
  896. hidden: true,
  897. selected: true
  898. },
  899. value: " "
  900. });
  901. }
  902. }
  903. const selectAttributes = {
  904. class: ["xfaSelect"],
  905. fieldId: field[_xfa_object.$uid],
  906. dataId: field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid],
  907. style
  908. };
  909. if (this.open === "multiSelect") {
  910. selectAttributes.multiple = true;
  911. }
  912. return _utils.HTMLResult.success({
  913. name: "label",
  914. attributes: {
  915. class: ["xfaLabel"]
  916. },
  917. children: [{
  918. name: "select",
  919. children,
  920. attributes: selectAttributes
  921. }]
  922. });
  923. }
  924. }
  925. class Color extends _xfa_object.XFAObject {
  926. constructor(attributes) {
  927. super(TEMPLATE_NS_ID, "color", true);
  928. this.cSpace = (0, _utils.getStringOption)(attributes.cSpace, ["SRGB"]);
  929. this.id = attributes.id || "";
  930. this.use = attributes.use || "";
  931. this.usehref = attributes.usehref || "";
  932. this.value = attributes.value ? (0, _utils.getColor)(attributes.value) : "";
  933. this.extras = null;
  934. }
  935. [_xfa_object.$hasSettableValue]() {
  936. return false;
  937. }
  938. [_xfa_object.$toStyle]() {
  939. return this.value ? _util.Util.makeHexColor(this.value.r, this.value.g, this.value.b) : null;
  940. }
  941. }
  942. class Comb extends _xfa_object.XFAObject {
  943. constructor(attributes) {
  944. super(TEMPLATE_NS_ID, "comb");
  945. this.id = attributes.id || "";
  946. this.numberOfCells = (0, _utils.getInteger)({
  947. data: attributes.numberOfCells,
  948. defaultValue: 0,
  949. validate: x => x >= 0
  950. });
  951. this.use = attributes.use || "";
  952. this.usehref = attributes.usehref || "";
  953. }
  954. }
  955. class Connect extends _xfa_object.XFAObject {
  956. constructor(attributes) {
  957. super(TEMPLATE_NS_ID, "connect", true);
  958. this.connection = attributes.connection || "";
  959. this.id = attributes.id || "";
  960. this.ref = attributes.ref || "";
  961. this.usage = (0, _utils.getStringOption)(attributes.usage, ["exportAndImport", "exportOnly", "importOnly"]);
  962. this.use = attributes.use || "";
  963. this.usehref = attributes.usehref || "";
  964. this.picture = null;
  965. }
  966. }
  967. class ContentArea extends _xfa_object.XFAObject {
  968. constructor(attributes) {
  969. super(TEMPLATE_NS_ID, "contentArea", true);
  970. this.h = (0, _utils.getMeasurement)(attributes.h);
  971. this.id = attributes.id || "";
  972. this.name = attributes.name || "";
  973. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  974. this.use = attributes.use || "";
  975. this.usehref = attributes.usehref || "";
  976. this.w = (0, _utils.getMeasurement)(attributes.w);
  977. this.x = (0, _utils.getMeasurement)(attributes.x, "0pt");
  978. this.y = (0, _utils.getMeasurement)(attributes.y, "0pt");
  979. this.desc = null;
  980. this.extras = null;
  981. }
  982. [_xfa_object.$toHTML](availableSpace) {
  983. const left = (0, _html_utils.measureToString)(this.x);
  984. const top = (0, _html_utils.measureToString)(this.y);
  985. const style = {
  986. left,
  987. top,
  988. width: (0, _html_utils.measureToString)(this.w),
  989. height: (0, _html_utils.measureToString)(this.h)
  990. };
  991. const classNames = ["xfaContentarea"];
  992. if ((0, _html_utils.isPrintOnly)(this)) {
  993. classNames.push("xfaPrintOnly");
  994. }
  995. return _utils.HTMLResult.success({
  996. name: "div",
  997. children: [],
  998. attributes: {
  999. style,
  1000. class: classNames,
  1001. id: this[_xfa_object.$uid]
  1002. }
  1003. });
  1004. }
  1005. }
  1006. class Corner extends _xfa_object.XFAObject {
  1007. constructor(attributes) {
  1008. super(TEMPLATE_NS_ID, "corner", true);
  1009. this.id = attributes.id || "";
  1010. this.inverted = (0, _utils.getInteger)({
  1011. data: attributes.inverted,
  1012. defaultValue: 0,
  1013. validate: x => x === 1
  1014. });
  1015. this.join = (0, _utils.getStringOption)(attributes.join, ["square", "round"]);
  1016. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  1017. this.radius = (0, _utils.getMeasurement)(attributes.radius);
  1018. this.stroke = (0, _utils.getStringOption)(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]);
  1019. this.thickness = (0, _utils.getMeasurement)(attributes.thickness, "0.5pt");
  1020. this.use = attributes.use || "";
  1021. this.usehref = attributes.usehref || "";
  1022. this.color = null;
  1023. this.extras = null;
  1024. }
  1025. [_xfa_object.$toStyle]() {
  1026. const style = (0, _html_utils.toStyle)(this, "visibility");
  1027. style.radius = (0, _html_utils.measureToString)(this.join === "square" ? 0 : this.radius);
  1028. return style;
  1029. }
  1030. }
  1031. class DateElement extends _xfa_object.ContentObject {
  1032. constructor(attributes) {
  1033. super(TEMPLATE_NS_ID, "date");
  1034. this.id = attributes.id || "";
  1035. this.name = attributes.name || "";
  1036. this.use = attributes.use || "";
  1037. this.usehref = attributes.usehref || "";
  1038. }
  1039. [_xfa_object.$finalize]() {
  1040. const date = this[_xfa_object.$content].trim();
  1041. this[_xfa_object.$content] = date ? new Date(date) : null;
  1042. }
  1043. [_xfa_object.$toHTML](availableSpace) {
  1044. return valueToHtml(this[_xfa_object.$content] ? this[_xfa_object.$content].toString() : "");
  1045. }
  1046. }
  1047. class DateTime extends _xfa_object.ContentObject {
  1048. constructor(attributes) {
  1049. super(TEMPLATE_NS_ID, "dateTime");
  1050. this.id = attributes.id || "";
  1051. this.name = attributes.name || "";
  1052. this.use = attributes.use || "";
  1053. this.usehref = attributes.usehref || "";
  1054. }
  1055. [_xfa_object.$finalize]() {
  1056. const date = this[_xfa_object.$content].trim();
  1057. this[_xfa_object.$content] = date ? new Date(date) : null;
  1058. }
  1059. [_xfa_object.$toHTML](availableSpace) {
  1060. return valueToHtml(this[_xfa_object.$content] ? this[_xfa_object.$content].toString() : "");
  1061. }
  1062. }
  1063. class DateTimeEdit extends _xfa_object.XFAObject {
  1064. constructor(attributes) {
  1065. super(TEMPLATE_NS_ID, "dateTimeEdit", true);
  1066. this.hScrollPolicy = (0, _utils.getStringOption)(attributes.hScrollPolicy, ["auto", "off", "on"]);
  1067. this.id = attributes.id || "";
  1068. this.picker = (0, _utils.getStringOption)(attributes.picker, ["host", "none"]);
  1069. this.use = attributes.use || "";
  1070. this.usehref = attributes.usehref || "";
  1071. this.border = null;
  1072. this.comb = null;
  1073. this.extras = null;
  1074. this.margin = null;
  1075. }
  1076. [_xfa_object.$toHTML](availableSpace) {
  1077. const style = (0, _html_utils.toStyle)(this, "border", "font", "margin");
  1078. const field = this[_xfa_object.$getParent]()[_xfa_object.$getParent]();
  1079. const html = {
  1080. name: "input",
  1081. attributes: {
  1082. type: "text",
  1083. fieldId: field[_xfa_object.$uid],
  1084. dataId: field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid],
  1085. class: ["xfaTextfield"],
  1086. style
  1087. }
  1088. };
  1089. return _utils.HTMLResult.success({
  1090. name: "label",
  1091. attributes: {
  1092. class: ["xfaLabel"]
  1093. },
  1094. children: [html]
  1095. });
  1096. }
  1097. }
  1098. class Decimal extends _xfa_object.ContentObject {
  1099. constructor(attributes) {
  1100. super(TEMPLATE_NS_ID, "decimal");
  1101. this.fracDigits = (0, _utils.getInteger)({
  1102. data: attributes.fracDigits,
  1103. defaultValue: 2,
  1104. validate: x => true
  1105. });
  1106. this.id = attributes.id || "";
  1107. this.leadDigits = (0, _utils.getInteger)({
  1108. data: attributes.leadDigits,
  1109. defaultValue: -1,
  1110. validate: x => true
  1111. });
  1112. this.name = attributes.name || "";
  1113. this.use = attributes.use || "";
  1114. this.usehref = attributes.usehref || "";
  1115. }
  1116. [_xfa_object.$finalize]() {
  1117. const number = parseFloat(this[_xfa_object.$content].trim());
  1118. this[_xfa_object.$content] = isNaN(number) ? null : number;
  1119. }
  1120. [_xfa_object.$toHTML](availableSpace) {
  1121. return valueToHtml(this[_xfa_object.$content] !== null ? this[_xfa_object.$content].toString() : "");
  1122. }
  1123. }
  1124. class DefaultUi extends _xfa_object.XFAObject {
  1125. constructor(attributes) {
  1126. super(TEMPLATE_NS_ID, "defaultUi", true);
  1127. this.id = attributes.id || "";
  1128. this.use = attributes.use || "";
  1129. this.usehref = attributes.usehref || "";
  1130. this.extras = null;
  1131. }
  1132. }
  1133. class Desc extends _xfa_object.XFAObject {
  1134. constructor(attributes) {
  1135. super(TEMPLATE_NS_ID, "desc", true);
  1136. this.id = attributes.id || "";
  1137. this.use = attributes.use || "";
  1138. this.usehref = attributes.usehref || "";
  1139. this.boolean = new _xfa_object.XFAObjectArray();
  1140. this.date = new _xfa_object.XFAObjectArray();
  1141. this.dateTime = new _xfa_object.XFAObjectArray();
  1142. this.decimal = new _xfa_object.XFAObjectArray();
  1143. this.exData = new _xfa_object.XFAObjectArray();
  1144. this.float = new _xfa_object.XFAObjectArray();
  1145. this.image = new _xfa_object.XFAObjectArray();
  1146. this.integer = new _xfa_object.XFAObjectArray();
  1147. this.text = new _xfa_object.XFAObjectArray();
  1148. this.time = new _xfa_object.XFAObjectArray();
  1149. }
  1150. }
  1151. class DigestMethod extends _xfa_object.OptionObject {
  1152. constructor(attributes) {
  1153. super(TEMPLATE_NS_ID, "digestMethod", ["", "SHA1", "SHA256", "SHA512", "RIPEMD160"]);
  1154. this.id = attributes.id || "";
  1155. this.use = attributes.use || "";
  1156. this.usehref = attributes.usehref || "";
  1157. }
  1158. }
  1159. class DigestMethods extends _xfa_object.XFAObject {
  1160. constructor(attributes) {
  1161. super(TEMPLATE_NS_ID, "digestMethods", true);
  1162. this.id = attributes.id || "";
  1163. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  1164. this.use = attributes.use || "";
  1165. this.usehref = attributes.usehref || "";
  1166. this.digestMethod = new _xfa_object.XFAObjectArray();
  1167. }
  1168. }
  1169. class Draw extends _xfa_object.XFAObject {
  1170. constructor(attributes) {
  1171. super(TEMPLATE_NS_ID, "draw", true);
  1172. this.anchorType = (0, _utils.getStringOption)(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  1173. this.colSpan = (0, _utils.getInteger)({
  1174. data: attributes.colSpan,
  1175. defaultValue: 1,
  1176. validate: n => n >= 1 || n === -1
  1177. });
  1178. this.h = attributes.h ? (0, _utils.getMeasurement)(attributes.h) : "";
  1179. this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  1180. this.id = attributes.id || "";
  1181. this.locale = attributes.locale || "";
  1182. this.maxH = (0, _utils.getMeasurement)(attributes.maxH, "0pt");
  1183. this.maxW = (0, _utils.getMeasurement)(attributes.maxW, "0pt");
  1184. this.minH = (0, _utils.getMeasurement)(attributes.minH, "0pt");
  1185. this.minW = (0, _utils.getMeasurement)(attributes.minW, "0pt");
  1186. this.name = attributes.name || "";
  1187. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  1188. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  1189. this.rotate = (0, _utils.getInteger)({
  1190. data: attributes.rotate,
  1191. defaultValue: 0,
  1192. validate: x => x % 90 === 0
  1193. });
  1194. this.use = attributes.use || "";
  1195. this.usehref = attributes.usehref || "";
  1196. this.w = attributes.w ? (0, _utils.getMeasurement)(attributes.w) : "";
  1197. this.x = (0, _utils.getMeasurement)(attributes.x, "0pt");
  1198. this.y = (0, _utils.getMeasurement)(attributes.y, "0pt");
  1199. this.assist = null;
  1200. this.border = null;
  1201. this.caption = null;
  1202. this.desc = null;
  1203. this.extras = null;
  1204. this.font = null;
  1205. this.keep = null;
  1206. this.margin = null;
  1207. this.para = null;
  1208. this.traversal = null;
  1209. this.ui = null;
  1210. this.value = null;
  1211. this.setProperty = new _xfa_object.XFAObjectArray();
  1212. }
  1213. [_xfa_object.$setValue](value) {
  1214. _setValue(this, value);
  1215. }
  1216. [_xfa_object.$toHTML](availableSpace) {
  1217. if (this.presence === "hidden" || this.presence === "inactive") {
  1218. return _utils.HTMLResult.EMPTY;
  1219. }
  1220. (0, _html_utils.fixDimensions)(this);
  1221. const savedW = this.w;
  1222. const savedH = this.h;
  1223. const {
  1224. w,
  1225. h,
  1226. isBroken
  1227. } = (0, _html_utils.layoutNode)(this, availableSpace);
  1228. if (w && this.w === "") {
  1229. if (isBroken && this[_xfa_object.$getSubformParent]()[_xfa_object.$isThereMoreWidth]()) {
  1230. return _utils.HTMLResult.FAILURE;
  1231. }
  1232. this.w = w;
  1233. }
  1234. if (h && this.h === "") {
  1235. this.h = h;
  1236. }
  1237. setFirstUnsplittable(this);
  1238. if (!(0, _layout.checkDimensions)(this, availableSpace)) {
  1239. this.w = savedW;
  1240. this.h = savedH;
  1241. return _utils.HTMLResult.FAILURE;
  1242. }
  1243. unsetFirstUnsplittable(this);
  1244. const style = (0, _html_utils.toStyle)(this, "font", "hAlign", "dimensions", "position", "presence", "rotate", "anchorType", "border", "margin");
  1245. (0, _html_utils.setMinMaxDimensions)(this, style);
  1246. if (style.margin) {
  1247. style.padding = style.margin;
  1248. delete style.margin;
  1249. }
  1250. const classNames = ["xfaDraw"];
  1251. if (this.font) {
  1252. classNames.push("xfaFont");
  1253. }
  1254. if ((0, _html_utils.isPrintOnly)(this)) {
  1255. classNames.push("xfaPrintOnly");
  1256. }
  1257. const attributes = {
  1258. style,
  1259. id: this[_xfa_object.$uid],
  1260. class: classNames
  1261. };
  1262. if (this.name) {
  1263. attributes.xfaName = this.name;
  1264. }
  1265. const html = {
  1266. name: "div",
  1267. attributes,
  1268. children: []
  1269. };
  1270. const assist = this.assist ? this.assist[_xfa_object.$toHTML]() : null;
  1271. if (assist) {
  1272. html.attributes.title = assist;
  1273. }
  1274. const bbox = (0, _html_utils.computeBbox)(this, html, availableSpace);
  1275. const value = this.value ? this.value[_xfa_object.$toHTML](availableSpace).html : null;
  1276. if (value === null) {
  1277. this.w = savedW;
  1278. this.h = savedH;
  1279. return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox);
  1280. }
  1281. html.children.push(value);
  1282. (0, _html_utils.setPara)(this, style, value);
  1283. this.w = savedW;
  1284. this.h = savedH;
  1285. return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox);
  1286. }
  1287. }
  1288. class Edge extends _xfa_object.XFAObject {
  1289. constructor(attributes) {
  1290. super(TEMPLATE_NS_ID, "edge", true);
  1291. this.cap = (0, _utils.getStringOption)(attributes.cap, ["square", "butt", "round"]);
  1292. this.id = attributes.id || "";
  1293. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  1294. this.stroke = (0, _utils.getStringOption)(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]);
  1295. this.thickness = (0, _utils.getMeasurement)(attributes.thickness, "0.5pt");
  1296. this.use = attributes.use || "";
  1297. this.usehref = attributes.usehref || "";
  1298. this.color = null;
  1299. this.extras = null;
  1300. }
  1301. [_xfa_object.$toStyle]() {
  1302. const style = (0, _html_utils.toStyle)(this, "visibility");
  1303. Object.assign(style, {
  1304. linecap: this.cap,
  1305. width: (0, _html_utils.measureToString)(this.thickness),
  1306. color: this.color ? this.color[_xfa_object.$toStyle]() : "#000000",
  1307. style: ""
  1308. });
  1309. if (this.presence !== "visible") {
  1310. style.style = "none";
  1311. } else {
  1312. switch (this.stroke) {
  1313. case "solid":
  1314. style.style = "solid";
  1315. break;
  1316. case "dashDot":
  1317. style.style = "dashed";
  1318. break;
  1319. case "dashDotDot":
  1320. style.style = "dashed";
  1321. break;
  1322. case "dashed":
  1323. style.style = "dashed";
  1324. break;
  1325. case "dotted":
  1326. style.style = "dotted";
  1327. break;
  1328. case "embossed":
  1329. style.style = "ridge";
  1330. break;
  1331. case "etched":
  1332. style.style = "groove";
  1333. break;
  1334. case "lowered":
  1335. style.style = "inset";
  1336. break;
  1337. case "raised":
  1338. style.style = "outset";
  1339. break;
  1340. }
  1341. }
  1342. return style;
  1343. }
  1344. }
  1345. class Encoding extends _xfa_object.OptionObject {
  1346. constructor(attributes) {
  1347. super(TEMPLATE_NS_ID, "encoding", ["adbe.x509.rsa_sha1", "adbe.pkcs7.detached", "adbe.pkcs7.sha1"]);
  1348. this.id = attributes.id || "";
  1349. this.use = attributes.use || "";
  1350. this.usehref = attributes.usehref || "";
  1351. }
  1352. }
  1353. class Encodings extends _xfa_object.XFAObject {
  1354. constructor(attributes) {
  1355. super(TEMPLATE_NS_ID, "encodings", true);
  1356. this.id = attributes.id || "";
  1357. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  1358. this.use = attributes.use || "";
  1359. this.usehref = attributes.usehref || "";
  1360. this.encoding = new _xfa_object.XFAObjectArray();
  1361. }
  1362. }
  1363. class Encrypt extends _xfa_object.XFAObject {
  1364. constructor(attributes) {
  1365. super(TEMPLATE_NS_ID, "encrypt", true);
  1366. this.id = attributes.id || "";
  1367. this.use = attributes.use || "";
  1368. this.usehref = attributes.usehref || "";
  1369. this.certificate = null;
  1370. }
  1371. }
  1372. class EncryptData extends _xfa_object.XFAObject {
  1373. constructor(attributes) {
  1374. super(TEMPLATE_NS_ID, "encryptData", true);
  1375. this.id = attributes.id || "";
  1376. this.operation = (0, _utils.getStringOption)(attributes.operation, ["encrypt", "decrypt"]);
  1377. this.target = attributes.target || "";
  1378. this.use = attributes.use || "";
  1379. this.usehref = attributes.usehref || "";
  1380. this.filter = null;
  1381. this.manifest = null;
  1382. }
  1383. }
  1384. class Encryption extends _xfa_object.XFAObject {
  1385. constructor(attributes) {
  1386. super(TEMPLATE_NS_ID, "encryption", true);
  1387. this.id = attributes.id || "";
  1388. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  1389. this.use = attributes.use || "";
  1390. this.usehref = attributes.usehref || "";
  1391. this.certificate = new _xfa_object.XFAObjectArray();
  1392. }
  1393. }
  1394. class EncryptionMethod extends _xfa_object.OptionObject {
  1395. constructor(attributes) {
  1396. super(TEMPLATE_NS_ID, "encryptionMethod", ["", "AES256-CBC", "TRIPLEDES-CBC", "AES128-CBC", "AES192-CBC"]);
  1397. this.id = attributes.id || "";
  1398. this.use = attributes.use || "";
  1399. this.usehref = attributes.usehref || "";
  1400. }
  1401. }
  1402. class EncryptionMethods extends _xfa_object.XFAObject {
  1403. constructor(attributes) {
  1404. super(TEMPLATE_NS_ID, "encryptionMethods", true);
  1405. this.id = attributes.id || "";
  1406. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  1407. this.use = attributes.use || "";
  1408. this.usehref = attributes.usehref || "";
  1409. this.encryptionMethod = new _xfa_object.XFAObjectArray();
  1410. }
  1411. }
  1412. class Event extends _xfa_object.XFAObject {
  1413. constructor(attributes) {
  1414. super(TEMPLATE_NS_ID, "event", true);
  1415. this.activity = (0, _utils.getStringOption)(attributes.activity, ["click", "change", "docClose", "docReady", "enter", "exit", "full", "indexChange", "initialize", "mouseDown", "mouseEnter", "mouseExit", "mouseUp", "postExecute", "postOpen", "postPrint", "postSave", "postSign", "postSubmit", "preExecute", "preOpen", "prePrint", "preSave", "preSign", "preSubmit", "ready", "validationState"]);
  1416. this.id = attributes.id || "";
  1417. this.listen = (0, _utils.getStringOption)(attributes.listen, ["refOnly", "refAndDescendents"]);
  1418. this.name = attributes.name || "";
  1419. this.ref = attributes.ref || "";
  1420. this.use = attributes.use || "";
  1421. this.usehref = attributes.usehref || "";
  1422. this.extras = null;
  1423. this.encryptData = null;
  1424. this.execute = null;
  1425. this.script = null;
  1426. this.signData = null;
  1427. this.submit = null;
  1428. }
  1429. }
  1430. class ExData extends _xfa_object.ContentObject {
  1431. constructor(attributes) {
  1432. super(TEMPLATE_NS_ID, "exData");
  1433. this.contentType = attributes.contentType || "";
  1434. this.href = attributes.href || "";
  1435. this.id = attributes.id || "";
  1436. this.maxLength = (0, _utils.getInteger)({
  1437. data: attributes.maxLength,
  1438. defaultValue: -1,
  1439. validate: x => x >= -1
  1440. });
  1441. this.name = attributes.name || "";
  1442. this.rid = attributes.rid || "";
  1443. this.transferEncoding = (0, _utils.getStringOption)(attributes.transferEncoding, ["none", "base64", "package"]);
  1444. this.use = attributes.use || "";
  1445. this.usehref = attributes.usehref || "";
  1446. }
  1447. [_xfa_object.$isCDATAXml]() {
  1448. return this.contentType === "text/html";
  1449. }
  1450. [_xfa_object.$onChild](child) {
  1451. if (this.contentType === "text/html" && child[_xfa_object.$namespaceId] === _namespaces.NamespaceIds.xhtml.id) {
  1452. this[_xfa_object.$content] = child;
  1453. return true;
  1454. }
  1455. if (this.contentType === "text/xml") {
  1456. this[_xfa_object.$content] = child;
  1457. return true;
  1458. }
  1459. return false;
  1460. }
  1461. [_xfa_object.$toHTML](availableSpace) {
  1462. if (this.contentType !== "text/html" || !this[_xfa_object.$content]) {
  1463. return _utils.HTMLResult.EMPTY;
  1464. }
  1465. return this[_xfa_object.$content][_xfa_object.$toHTML](availableSpace);
  1466. }
  1467. }
  1468. class ExObject extends _xfa_object.XFAObject {
  1469. constructor(attributes) {
  1470. super(TEMPLATE_NS_ID, "exObject", true);
  1471. this.archive = attributes.archive || "";
  1472. this.classId = attributes.classId || "";
  1473. this.codeBase = attributes.codeBase || "";
  1474. this.codeType = attributes.codeType || "";
  1475. this.id = attributes.id || "";
  1476. this.name = attributes.name || "";
  1477. this.use = attributes.use || "";
  1478. this.usehref = attributes.usehref || "";
  1479. this.extras = null;
  1480. this.boolean = new _xfa_object.XFAObjectArray();
  1481. this.date = new _xfa_object.XFAObjectArray();
  1482. this.dateTime = new _xfa_object.XFAObjectArray();
  1483. this.decimal = new _xfa_object.XFAObjectArray();
  1484. this.exData = new _xfa_object.XFAObjectArray();
  1485. this.exObject = new _xfa_object.XFAObjectArray();
  1486. this.float = new _xfa_object.XFAObjectArray();
  1487. this.image = new _xfa_object.XFAObjectArray();
  1488. this.integer = new _xfa_object.XFAObjectArray();
  1489. this.text = new _xfa_object.XFAObjectArray();
  1490. this.time = new _xfa_object.XFAObjectArray();
  1491. }
  1492. }
  1493. class ExclGroup extends _xfa_object.XFAObject {
  1494. constructor(attributes) {
  1495. super(TEMPLATE_NS_ID, "exclGroup", true);
  1496. this.access = (0, _utils.getStringOption)(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
  1497. this.accessKey = attributes.accessKey || "";
  1498. this.anchorType = (0, _utils.getStringOption)(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  1499. this.colSpan = (0, _utils.getInteger)({
  1500. data: attributes.colSpan,
  1501. defaultValue: 1,
  1502. validate: n => n >= 1 || n === -1
  1503. });
  1504. this.h = attributes.h ? (0, _utils.getMeasurement)(attributes.h) : "";
  1505. this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  1506. this.id = attributes.id || "";
  1507. this.layout = (0, _utils.getStringOption)(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]);
  1508. this.maxH = (0, _utils.getMeasurement)(attributes.maxH, "0pt");
  1509. this.maxW = (0, _utils.getMeasurement)(attributes.maxW, "0pt");
  1510. this.minH = (0, _utils.getMeasurement)(attributes.minH, "0pt");
  1511. this.minW = (0, _utils.getMeasurement)(attributes.minW, "0pt");
  1512. this.name = attributes.name || "";
  1513. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  1514. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  1515. this.use = attributes.use || "";
  1516. this.usehref = attributes.usehref || "";
  1517. this.w = attributes.w ? (0, _utils.getMeasurement)(attributes.w) : "";
  1518. this.x = (0, _utils.getMeasurement)(attributes.x, "0pt");
  1519. this.y = (0, _utils.getMeasurement)(attributes.y, "0pt");
  1520. this.assist = null;
  1521. this.bind = null;
  1522. this.border = null;
  1523. this.calculate = null;
  1524. this.caption = null;
  1525. this.desc = null;
  1526. this.extras = null;
  1527. this.margin = null;
  1528. this.para = null;
  1529. this.traversal = null;
  1530. this.validate = null;
  1531. this.connect = new _xfa_object.XFAObjectArray();
  1532. this.event = new _xfa_object.XFAObjectArray();
  1533. this.field = new _xfa_object.XFAObjectArray();
  1534. this.setProperty = new _xfa_object.XFAObjectArray();
  1535. }
  1536. [_xfa_object.$isBindable]() {
  1537. return true;
  1538. }
  1539. [_xfa_object.$hasSettableValue]() {
  1540. return true;
  1541. }
  1542. [_xfa_object.$setValue](value) {
  1543. for (const field of this.field.children) {
  1544. if (!field.value) {
  1545. const nodeValue = new Value({});
  1546. field[_xfa_object.$appendChild](nodeValue);
  1547. field.value = nodeValue;
  1548. }
  1549. field.value[_xfa_object.$setValue](value);
  1550. }
  1551. }
  1552. [_xfa_object.$isThereMoreWidth]() {
  1553. return this.layout.endsWith("-tb") && this[_xfa_object.$extra].attempt === 0 && this[_xfa_object.$extra].numberInLine > 0 || this[_xfa_object.$getParent]()[_xfa_object.$isThereMoreWidth]();
  1554. }
  1555. [_xfa_object.$isSplittable]() {
  1556. const parent = this[_xfa_object.$getSubformParent]();
  1557. if (!parent[_xfa_object.$isSplittable]()) {
  1558. return false;
  1559. }
  1560. if (this[_xfa_object.$extra]._isSplittable !== undefined) {
  1561. return this[_xfa_object.$extra]._isSplittable;
  1562. }
  1563. if (this.layout === "position" || this.layout.includes("row")) {
  1564. this[_xfa_object.$extra]._isSplittable = false;
  1565. return false;
  1566. }
  1567. if (parent.layout && parent.layout.endsWith("-tb") && parent[_xfa_object.$extra].numberInLine !== 0) {
  1568. return false;
  1569. }
  1570. this[_xfa_object.$extra]._isSplittable = true;
  1571. return true;
  1572. }
  1573. [_xfa_object.$flushHTML]() {
  1574. return (0, _layout.flushHTML)(this);
  1575. }
  1576. [_xfa_object.$addHTML](html, bbox) {
  1577. (0, _layout.addHTML)(this, html, bbox);
  1578. }
  1579. [_xfa_object.$getAvailableSpace]() {
  1580. return (0, _layout.getAvailableSpace)(this);
  1581. }
  1582. [_xfa_object.$toHTML](availableSpace) {
  1583. if (this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) {
  1584. return _utils.HTMLResult.EMPTY;
  1585. }
  1586. (0, _html_utils.fixDimensions)(this);
  1587. const children = [];
  1588. const attributes = {
  1589. id: this[_xfa_object.$uid],
  1590. class: []
  1591. };
  1592. (0, _html_utils.setAccess)(this, attributes.class);
  1593. if (!this[_xfa_object.$extra]) {
  1594. this[_xfa_object.$extra] = Object.create(null);
  1595. }
  1596. Object.assign(this[_xfa_object.$extra], {
  1597. children,
  1598. attributes,
  1599. attempt: 0,
  1600. line: null,
  1601. numberInLine: 0,
  1602. availableSpace: {
  1603. width: Math.min(this.w || Infinity, availableSpace.width),
  1604. height: Math.min(this.h || Infinity, availableSpace.height)
  1605. },
  1606. width: 0,
  1607. height: 0,
  1608. prevHeight: 0,
  1609. currentWidth: 0
  1610. });
  1611. const isSplittable = this[_xfa_object.$isSplittable]();
  1612. if (!isSplittable) {
  1613. setFirstUnsplittable(this);
  1614. }
  1615. if (!(0, _layout.checkDimensions)(this, availableSpace)) {
  1616. return _utils.HTMLResult.FAILURE;
  1617. }
  1618. availableSpace = {
  1619. width: this.w === "" ? availableSpace.width : this.w,
  1620. height: this.h === "" ? availableSpace.height : this.h
  1621. };
  1622. const filter = new Set(["field"]);
  1623. if (this.layout.includes("row")) {
  1624. const columnWidths = this[_xfa_object.$getSubformParent]().columnWidths;
  1625. if (Array.isArray(columnWidths) && columnWidths.length > 0) {
  1626. this[_xfa_object.$extra].columnWidths = columnWidths;
  1627. this[_xfa_object.$extra].currentColumn = 0;
  1628. }
  1629. }
  1630. const style = (0, _html_utils.toStyle)(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign");
  1631. const classNames = ["xfaExclgroup"];
  1632. const cl = (0, _html_utils.layoutClass)(this);
  1633. if (cl) {
  1634. classNames.push(cl);
  1635. }
  1636. if ((0, _html_utils.isPrintOnly)(this)) {
  1637. classNames.push("xfaPrintOnly");
  1638. }
  1639. attributes.style = style;
  1640. attributes.class = classNames;
  1641. if (this.name) {
  1642. attributes.xfaName = this.name;
  1643. }
  1644. const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
  1645. const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
  1646. for (; this[_xfa_object.$extra].attempt < maxRun; this[_xfa_object.$extra].attempt++) {
  1647. if (isLrTb && this[_xfa_object.$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) {
  1648. this[_xfa_object.$extra].numberInLine = 0;
  1649. }
  1650. const result = this[_xfa_object.$childrenToHTML]({
  1651. filter,
  1652. include: true
  1653. });
  1654. if (result.success) {
  1655. break;
  1656. }
  1657. if (result.isBreak()) {
  1658. return result;
  1659. }
  1660. if (isLrTb && this[_xfa_object.$extra].attempt === 0 && this[_xfa_object.$extra].numberInLine === 0 && !this[_xfa_object.$getTemplateRoot]()[_xfa_object.$extra].noLayoutFailure) {
  1661. this[_xfa_object.$extra].attempt = maxRun;
  1662. break;
  1663. }
  1664. }
  1665. if (!isSplittable) {
  1666. unsetFirstUnsplittable(this);
  1667. }
  1668. if (this[_xfa_object.$extra].attempt === maxRun) {
  1669. if (!isSplittable) {
  1670. delete this[_xfa_object.$extra];
  1671. }
  1672. return _utils.HTMLResult.FAILURE;
  1673. }
  1674. let marginH = 0;
  1675. let marginV = 0;
  1676. if (this.margin) {
  1677. marginH = this.margin.leftInset + this.margin.rightInset;
  1678. marginV = this.margin.topInset + this.margin.bottomInset;
  1679. }
  1680. const width = Math.max(this[_xfa_object.$extra].width + marginH, this.w || 0);
  1681. const height = Math.max(this[_xfa_object.$extra].height + marginV, this.h || 0);
  1682. const bbox = [this.x, this.y, width, height];
  1683. if (this.w === "") {
  1684. style.width = (0, _html_utils.measureToString)(width);
  1685. }
  1686. if (this.h === "") {
  1687. style.height = (0, _html_utils.measureToString)(height);
  1688. }
  1689. const html = {
  1690. name: "div",
  1691. attributes,
  1692. children
  1693. };
  1694. const assist = this.assist ? this.assist[_xfa_object.$toHTML]() : null;
  1695. if (assist) {
  1696. html.attributes.title = assist;
  1697. }
  1698. delete this[_xfa_object.$extra];
  1699. return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox);
  1700. }
  1701. }
  1702. class Execute extends _xfa_object.XFAObject {
  1703. constructor(attributes) {
  1704. super(TEMPLATE_NS_ID, "execute");
  1705. this.connection = attributes.connection || "";
  1706. this.executeType = (0, _utils.getStringOption)(attributes.executeType, ["import", "remerge"]);
  1707. this.id = attributes.id || "";
  1708. this.runAt = (0, _utils.getStringOption)(attributes.runAt, ["client", "both", "server"]);
  1709. this.use = attributes.use || "";
  1710. this.usehref = attributes.usehref || "";
  1711. }
  1712. }
  1713. class Extras extends _xfa_object.XFAObject {
  1714. constructor(attributes) {
  1715. super(TEMPLATE_NS_ID, "extras", true);
  1716. this.id = attributes.id || "";
  1717. this.name = attributes.name || "";
  1718. this.use = attributes.use || "";
  1719. this.usehref = attributes.usehref || "";
  1720. this.boolean = new _xfa_object.XFAObjectArray();
  1721. this.date = new _xfa_object.XFAObjectArray();
  1722. this.dateTime = new _xfa_object.XFAObjectArray();
  1723. this.decimal = new _xfa_object.XFAObjectArray();
  1724. this.exData = new _xfa_object.XFAObjectArray();
  1725. this.extras = new _xfa_object.XFAObjectArray();
  1726. this.float = new _xfa_object.XFAObjectArray();
  1727. this.image = new _xfa_object.XFAObjectArray();
  1728. this.integer = new _xfa_object.XFAObjectArray();
  1729. this.text = new _xfa_object.XFAObjectArray();
  1730. this.time = new _xfa_object.XFAObjectArray();
  1731. }
  1732. }
  1733. class Field extends _xfa_object.XFAObject {
  1734. constructor(attributes) {
  1735. super(TEMPLATE_NS_ID, "field", true);
  1736. this.access = (0, _utils.getStringOption)(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
  1737. this.accessKey = attributes.accessKey || "";
  1738. this.anchorType = (0, _utils.getStringOption)(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  1739. this.colSpan = (0, _utils.getInteger)({
  1740. data: attributes.colSpan,
  1741. defaultValue: 1,
  1742. validate: n => n >= 1 || n === -1
  1743. });
  1744. this.h = attributes.h ? (0, _utils.getMeasurement)(attributes.h) : "";
  1745. this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  1746. this.id = attributes.id || "";
  1747. this.locale = attributes.locale || "";
  1748. this.maxH = (0, _utils.getMeasurement)(attributes.maxH, "0pt");
  1749. this.maxW = (0, _utils.getMeasurement)(attributes.maxW, "0pt");
  1750. this.minH = (0, _utils.getMeasurement)(attributes.minH, "0pt");
  1751. this.minW = (0, _utils.getMeasurement)(attributes.minW, "0pt");
  1752. this.name = attributes.name || "";
  1753. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  1754. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  1755. this.rotate = (0, _utils.getInteger)({
  1756. data: attributes.rotate,
  1757. defaultValue: 0,
  1758. validate: x => x % 90 === 0
  1759. });
  1760. this.use = attributes.use || "";
  1761. this.usehref = attributes.usehref || "";
  1762. this.w = attributes.w ? (0, _utils.getMeasurement)(attributes.w) : "";
  1763. this.x = (0, _utils.getMeasurement)(attributes.x, "0pt");
  1764. this.y = (0, _utils.getMeasurement)(attributes.y, "0pt");
  1765. this.assist = null;
  1766. this.bind = null;
  1767. this.border = null;
  1768. this.calculate = null;
  1769. this.caption = null;
  1770. this.desc = null;
  1771. this.extras = null;
  1772. this.font = null;
  1773. this.format = null;
  1774. this.items = new _xfa_object.XFAObjectArray(2);
  1775. this.keep = null;
  1776. this.margin = null;
  1777. this.para = null;
  1778. this.traversal = null;
  1779. this.ui = null;
  1780. this.validate = null;
  1781. this.value = null;
  1782. this.bindItems = new _xfa_object.XFAObjectArray();
  1783. this.connect = new _xfa_object.XFAObjectArray();
  1784. this.event = new _xfa_object.XFAObjectArray();
  1785. this.setProperty = new _xfa_object.XFAObjectArray();
  1786. }
  1787. [_xfa_object.$isBindable]() {
  1788. return true;
  1789. }
  1790. [_xfa_object.$setValue](value) {
  1791. _setValue(this, value);
  1792. }
  1793. [_xfa_object.$toHTML](availableSpace) {
  1794. if (!this.ui) {
  1795. this.ui = new Ui({});
  1796. this.ui[_xfa_object.$globalData] = this[_xfa_object.$globalData];
  1797. this[_xfa_object.$appendChild](this.ui);
  1798. let node;
  1799. switch (this.items.children.length) {
  1800. case 0:
  1801. node = new TextEdit({});
  1802. this.ui.textEdit = node;
  1803. break;
  1804. case 1:
  1805. node = new CheckButton({});
  1806. this.ui.checkButton = node;
  1807. break;
  1808. case 2:
  1809. node = new ChoiceList({});
  1810. this.ui.choiceList = node;
  1811. break;
  1812. }
  1813. this.ui[_xfa_object.$appendChild](node);
  1814. }
  1815. setTabIndex(this);
  1816. if (!this.ui || this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) {
  1817. return _utils.HTMLResult.EMPTY;
  1818. }
  1819. if (this.caption) {
  1820. delete this.caption[_xfa_object.$extra];
  1821. }
  1822. const caption = this.caption ? this.caption[_xfa_object.$toHTML](availableSpace).html : null;
  1823. const savedW = this.w;
  1824. const savedH = this.h;
  1825. if (this.w === "" || this.h === "") {
  1826. let marginH = 0;
  1827. let marginV = 0;
  1828. if (this.margin) {
  1829. marginH = this.margin.leftInset + this.margin.rightInset;
  1830. marginV = this.margin.topInset + this.margin.bottomInset;
  1831. }
  1832. let width = null;
  1833. let height = null;
  1834. if (this.caption) {
  1835. const {
  1836. w,
  1837. h,
  1838. isBroken
  1839. } = this.caption[_xfa_object.$getExtra](availableSpace);
  1840. if (isBroken && this[_xfa_object.$getSubformParent]()[_xfa_object.$isThereMoreWidth]()) {
  1841. return _utils.HTMLResult.FAILURE;
  1842. }
  1843. width = w;
  1844. height = h;
  1845. if (this.ui.checkButton) {
  1846. switch (this.caption.placement) {
  1847. case "left":
  1848. case "right":
  1849. case "inline":
  1850. width += this.ui.checkButton.size;
  1851. break;
  1852. case "top":
  1853. case "bottom":
  1854. height += this.ui.checkButton.size;
  1855. break;
  1856. }
  1857. }
  1858. }
  1859. if (width && this.w === "") {
  1860. this.w = Math.min(this.maxW <= 0 ? Infinity : this.maxW, Math.max(this.minW, width + marginH));
  1861. }
  1862. if (height && this.h === "") {
  1863. this.h = Math.min(this.maxH <= 0 ? Infinity : this.maxH, Math.max(this.minH, height + marginV));
  1864. }
  1865. }
  1866. (0, _html_utils.fixDimensions)(this);
  1867. setFirstUnsplittable(this);
  1868. if (!(0, _layout.checkDimensions)(this, availableSpace)) {
  1869. this.w = savedW;
  1870. this.h = savedH;
  1871. return _utils.HTMLResult.FAILURE;
  1872. }
  1873. unsetFirstUnsplittable(this);
  1874. const style = (0, _html_utils.toStyle)(this, "font", "dimensions", "position", "rotate", "anchorType", "presence", "margin", "hAlign");
  1875. (0, _html_utils.setMinMaxDimensions)(this, style);
  1876. const classNames = ["xfaField"];
  1877. if (this.font) {
  1878. classNames.push("xfaFont");
  1879. }
  1880. if ((0, _html_utils.isPrintOnly)(this)) {
  1881. classNames.push("xfaPrintOnly");
  1882. }
  1883. const attributes = {
  1884. style,
  1885. id: this[_xfa_object.$uid],
  1886. class: classNames
  1887. };
  1888. if (style.margin) {
  1889. style.padding = style.margin;
  1890. delete style.margin;
  1891. }
  1892. (0, _html_utils.setAccess)(this, classNames);
  1893. if (this.name) {
  1894. attributes.xfaName = this.name;
  1895. }
  1896. const children = [];
  1897. const html = {
  1898. name: "div",
  1899. attributes,
  1900. children
  1901. };
  1902. const assist = this.assist ? this.assist[_xfa_object.$toHTML]() : null;
  1903. if (assist) {
  1904. html.attributes.title = assist;
  1905. }
  1906. const borderStyle = this.border ? this.border[_xfa_object.$toStyle]() : null;
  1907. const bbox = (0, _html_utils.computeBbox)(this, html, availableSpace);
  1908. const ui = this.ui[_xfa_object.$toHTML]().html;
  1909. if (!ui) {
  1910. Object.assign(style, borderStyle);
  1911. return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox);
  1912. }
  1913. if (this[_xfa_object.$tabIndex]) {
  1914. if (ui.children && ui.children[0]) {
  1915. ui.children[0].attributes.tabindex = this[_xfa_object.$tabIndex];
  1916. } else {
  1917. ui.attributes.tabindex = this[_xfa_object.$tabIndex];
  1918. }
  1919. }
  1920. if (!ui.attributes.style) {
  1921. ui.attributes.style = Object.create(null);
  1922. }
  1923. if (this.ui.button) {
  1924. Object.assign(ui.attributes.style, borderStyle);
  1925. } else {
  1926. Object.assign(style, borderStyle);
  1927. }
  1928. children.push(ui);
  1929. if (this.value) {
  1930. if (this.ui.imageEdit) {
  1931. ui.children.push(this.value[_xfa_object.$toHTML]().html);
  1932. } else if (!this.ui.button) {
  1933. let value = "";
  1934. if (this.value.exData) {
  1935. value = this.value.exData[_xfa_object.$text]();
  1936. } else {
  1937. const htmlValue = this.value[_xfa_object.$toHTML]().html;
  1938. if (htmlValue !== null) {
  1939. value = htmlValue.children[0].value;
  1940. }
  1941. }
  1942. if (this.ui.textEdit && this.value.text && this.value.text.maxChars) {
  1943. ui.children[0].attributes.maxLength = this.value.text.maxChars;
  1944. }
  1945. if (value) {
  1946. if (ui.children[0].name === "textarea") {
  1947. ui.children[0].attributes.textContent = value;
  1948. } else {
  1949. ui.children[0].attributes.value = value;
  1950. }
  1951. }
  1952. }
  1953. }
  1954. if (!caption) {
  1955. if (ui.attributes.class) {
  1956. ui.attributes.class.push("xfaLeft");
  1957. }
  1958. this.w = savedW;
  1959. this.h = savedH;
  1960. return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox);
  1961. }
  1962. if (this.ui.button) {
  1963. if (style.padding) {
  1964. delete style.padding;
  1965. }
  1966. if (caption.name === "div") {
  1967. caption.name = "span";
  1968. }
  1969. ui.children.push(caption);
  1970. return _utils.HTMLResult.success(html, bbox);
  1971. } else if (this.ui.checkButton) {
  1972. caption.attributes.class[0] = "xfaCaptionForCheckButton";
  1973. }
  1974. if (!ui.attributes.class) {
  1975. ui.attributes.class = [];
  1976. }
  1977. switch (this.caption.placement) {
  1978. case "left":
  1979. ui.children.splice(0, 0, caption);
  1980. ui.attributes.class.push("xfaLeft");
  1981. break;
  1982. case "right":
  1983. ui.children.push(caption);
  1984. ui.attributes.class.push("xfaLeft");
  1985. break;
  1986. case "top":
  1987. ui.children.splice(0, 0, caption);
  1988. ui.attributes.class.push("xfaTop");
  1989. break;
  1990. case "bottom":
  1991. ui.children.push(caption);
  1992. ui.attributes.class.push("xfaTop");
  1993. break;
  1994. case "inline":
  1995. ui.attributes.class.push("xfaLeft");
  1996. break;
  1997. }
  1998. this.w = savedW;
  1999. this.h = savedH;
  2000. return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox);
  2001. }
  2002. }
  2003. exports.Field = Field;
  2004. class Fill extends _xfa_object.XFAObject {
  2005. constructor(attributes) {
  2006. super(TEMPLATE_NS_ID, "fill", true);
  2007. this.id = attributes.id || "";
  2008. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  2009. this.use = attributes.use || "";
  2010. this.usehref = attributes.usehref || "";
  2011. this.color = null;
  2012. this.extras = null;
  2013. this.linear = null;
  2014. this.pattern = null;
  2015. this.radial = null;
  2016. this.solid = null;
  2017. this.stipple = null;
  2018. }
  2019. [_xfa_object.$toStyle]() {
  2020. const parent = this[_xfa_object.$getParent]();
  2021. const style = Object.create(null);
  2022. let propName = "color";
  2023. if (parent instanceof Border) {
  2024. propName = "background";
  2025. }
  2026. if (parent instanceof Rectangle || parent instanceof Arc) {
  2027. propName = "fill";
  2028. style.fill = "white";
  2029. }
  2030. for (const name of Object.getOwnPropertyNames(this)) {
  2031. if (name === "extras" || name === "color") {
  2032. continue;
  2033. }
  2034. const obj = this[name];
  2035. if (!(obj instanceof _xfa_object.XFAObject)) {
  2036. continue;
  2037. }
  2038. style[propName] = obj[_xfa_object.$toStyle](this.color);
  2039. return style;
  2040. }
  2041. if (this.color) {
  2042. style[propName] = this.color[_xfa_object.$toStyle]();
  2043. }
  2044. return style;
  2045. }
  2046. }
  2047. class Filter extends _xfa_object.XFAObject {
  2048. constructor(attributes) {
  2049. super(TEMPLATE_NS_ID, "filter", true);
  2050. this.addRevocationInfo = (0, _utils.getStringOption)(attributes.addRevocationInfo, ["", "required", "optional", "none"]);
  2051. this.id = attributes.id || "";
  2052. this.name = attributes.name || "";
  2053. this.use = attributes.use || "";
  2054. this.usehref = attributes.usehref || "";
  2055. this.version = (0, _utils.getInteger)({
  2056. data: this.version,
  2057. defaultValue: 5,
  2058. validate: x => x >= 1 && x <= 5
  2059. });
  2060. this.appearanceFilter = null;
  2061. this.certificates = null;
  2062. this.digestMethods = null;
  2063. this.encodings = null;
  2064. this.encryptionMethods = null;
  2065. this.handler = null;
  2066. this.lockDocument = null;
  2067. this.mdp = null;
  2068. this.reasons = null;
  2069. this.timeStamp = null;
  2070. }
  2071. }
  2072. class Float extends _xfa_object.ContentObject {
  2073. constructor(attributes) {
  2074. super(TEMPLATE_NS_ID, "float");
  2075. this.id = attributes.id || "";
  2076. this.name = attributes.name || "";
  2077. this.use = attributes.use || "";
  2078. this.usehref = attributes.usehref || "";
  2079. }
  2080. [_xfa_object.$finalize]() {
  2081. const number = parseFloat(this[_xfa_object.$content].trim());
  2082. this[_xfa_object.$content] = isNaN(number) ? null : number;
  2083. }
  2084. [_xfa_object.$toHTML](availableSpace) {
  2085. return valueToHtml(this[_xfa_object.$content] !== null ? this[_xfa_object.$content].toString() : "");
  2086. }
  2087. }
  2088. class Font extends _xfa_object.XFAObject {
  2089. constructor(attributes) {
  2090. super(TEMPLATE_NS_ID, "font", true);
  2091. this.baselineShift = (0, _utils.getMeasurement)(attributes.baselineShift);
  2092. this.fontHorizontalScale = (0, _utils.getFloat)({
  2093. data: attributes.fontHorizontalScale,
  2094. defaultValue: 100,
  2095. validate: x => x >= 0
  2096. });
  2097. this.fontVerticalScale = (0, _utils.getFloat)({
  2098. data: attributes.fontVerticalScale,
  2099. defaultValue: 100,
  2100. validate: x => x >= 0
  2101. });
  2102. this.id = attributes.id || "";
  2103. this.kerningMode = (0, _utils.getStringOption)(attributes.kerningMode, ["none", "pair"]);
  2104. this.letterSpacing = (0, _utils.getMeasurement)(attributes.letterSpacing, "0");
  2105. this.lineThrough = (0, _utils.getInteger)({
  2106. data: attributes.lineThrough,
  2107. defaultValue: 0,
  2108. validate: x => x === 1 || x === 2
  2109. });
  2110. this.lineThroughPeriod = (0, _utils.getStringOption)(attributes.lineThroughPeriod, ["all", "word"]);
  2111. this.overline = (0, _utils.getInteger)({
  2112. data: attributes.overline,
  2113. defaultValue: 0,
  2114. validate: x => x === 1 || x === 2
  2115. });
  2116. this.overlinePeriod = (0, _utils.getStringOption)(attributes.overlinePeriod, ["all", "word"]);
  2117. this.posture = (0, _utils.getStringOption)(attributes.posture, ["normal", "italic"]);
  2118. this.size = (0, _utils.getMeasurement)(attributes.size, "10pt");
  2119. this.typeface = attributes.typeface || "Courier";
  2120. this.underline = (0, _utils.getInteger)({
  2121. data: attributes.underline,
  2122. defaultValue: 0,
  2123. validate: x => x === 1 || x === 2
  2124. });
  2125. this.underlinePeriod = (0, _utils.getStringOption)(attributes.underlinePeriod, ["all", "word"]);
  2126. this.use = attributes.use || "";
  2127. this.usehref = attributes.usehref || "";
  2128. this.weight = (0, _utils.getStringOption)(attributes.weight, ["normal", "bold"]);
  2129. this.extras = null;
  2130. this.fill = null;
  2131. }
  2132. [_xfa_object.$clean](builder) {
  2133. super[_xfa_object.$clean](builder);
  2134. this[_xfa_object.$globalData].usedTypefaces.add(this.typeface);
  2135. }
  2136. [_xfa_object.$toStyle]() {
  2137. const style = (0, _html_utils.toStyle)(this, "fill");
  2138. const color = style.color;
  2139. if (color) {
  2140. if (color === "#000000") {
  2141. delete style.color;
  2142. } else if (!color.startsWith("#")) {
  2143. style.background = color;
  2144. style.backgroundClip = "text";
  2145. style.color = "transparent";
  2146. }
  2147. }
  2148. if (this.baselineShift) {
  2149. style.verticalAlign = (0, _html_utils.measureToString)(this.baselineShift);
  2150. }
  2151. style.fontKerning = this.kerningMode === "none" ? "none" : "normal";
  2152. style.letterSpacing = (0, _html_utils.measureToString)(this.letterSpacing);
  2153. if (this.lineThrough !== 0) {
  2154. style.textDecoration = "line-through";
  2155. if (this.lineThrough === 2) {
  2156. style.textDecorationStyle = "double";
  2157. }
  2158. }
  2159. if (this.overline !== 0) {
  2160. style.textDecoration = "overline";
  2161. if (this.overline === 2) {
  2162. style.textDecorationStyle = "double";
  2163. }
  2164. }
  2165. style.fontStyle = this.posture;
  2166. style.fontSize = (0, _html_utils.measureToString)(0.99 * this.size);
  2167. (0, _html_utils.setFontFamily)(this, this[_xfa_object.$globalData].fontFinder, style);
  2168. if (this.underline !== 0) {
  2169. style.textDecoration = "underline";
  2170. if (this.underline === 2) {
  2171. style.textDecorationStyle = "double";
  2172. }
  2173. }
  2174. style.fontWeight = this.weight;
  2175. return style;
  2176. }
  2177. }
  2178. class Format extends _xfa_object.XFAObject {
  2179. constructor(attributes) {
  2180. super(TEMPLATE_NS_ID, "format", true);
  2181. this.id = attributes.id || "";
  2182. this.use = attributes.use || "";
  2183. this.usehref = attributes.usehref || "";
  2184. this.extras = null;
  2185. this.picture = null;
  2186. }
  2187. }
  2188. class Handler extends _xfa_object.StringObject {
  2189. constructor(attributes) {
  2190. super(TEMPLATE_NS_ID, "handler");
  2191. this.id = attributes.id || "";
  2192. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  2193. this.use = attributes.use || "";
  2194. this.usehref = attributes.usehref || "";
  2195. }
  2196. }
  2197. class Hyphenation extends _xfa_object.XFAObject {
  2198. constructor(attributes) {
  2199. super(TEMPLATE_NS_ID, "hyphenation");
  2200. this.excludeAllCaps = (0, _utils.getInteger)({
  2201. data: attributes.excludeAllCaps,
  2202. defaultValue: 0,
  2203. validate: x => x === 1
  2204. });
  2205. this.excludeInitialCap = (0, _utils.getInteger)({
  2206. data: attributes.excludeInitialCap,
  2207. defaultValue: 0,
  2208. validate: x => x === 1
  2209. });
  2210. this.hyphenate = (0, _utils.getInteger)({
  2211. data: attributes.hyphenate,
  2212. defaultValue: 0,
  2213. validate: x => x === 1
  2214. });
  2215. this.id = attributes.id || "";
  2216. this.pushCharacterCount = (0, _utils.getInteger)({
  2217. data: attributes.pushCharacterCount,
  2218. defaultValue: 3,
  2219. validate: x => x >= 0
  2220. });
  2221. this.remainCharacterCount = (0, _utils.getInteger)({
  2222. data: attributes.remainCharacterCount,
  2223. defaultValue: 3,
  2224. validate: x => x >= 0
  2225. });
  2226. this.use = attributes.use || "";
  2227. this.usehref = attributes.usehref || "";
  2228. this.wordCharacterCount = (0, _utils.getInteger)({
  2229. data: attributes.wordCharacterCount,
  2230. defaultValue: 7,
  2231. validate: x => x >= 0
  2232. });
  2233. }
  2234. }
  2235. class Image extends _xfa_object.StringObject {
  2236. constructor(attributes) {
  2237. super(TEMPLATE_NS_ID, "image");
  2238. this.aspect = (0, _utils.getStringOption)(attributes.aspect, ["fit", "actual", "height", "none", "width"]);
  2239. this.contentType = attributes.contentType || "";
  2240. this.href = attributes.href || "";
  2241. this.id = attributes.id || "";
  2242. this.name = attributes.name || "";
  2243. this.transferEncoding = (0, _utils.getStringOption)(attributes.transferEncoding, ["base64", "none", "package"]);
  2244. this.use = attributes.use || "";
  2245. this.usehref = attributes.usehref || "";
  2246. }
  2247. [_xfa_object.$toHTML]() {
  2248. let buffer = this[_xfa_object.$globalData].images && this[_xfa_object.$globalData].images.get(this.href);
  2249. if (!buffer && (this.href || !this[_xfa_object.$content])) {
  2250. return _utils.HTMLResult.EMPTY;
  2251. }
  2252. if (!buffer && this.transferEncoding === "base64") {
  2253. buffer = (0, _util.stringToBytes)(atob(this[_xfa_object.$content]));
  2254. }
  2255. if (!buffer) {
  2256. return _utils.HTMLResult.EMPTY;
  2257. }
  2258. const blob = new Blob([buffer], {
  2259. type: this.contentType
  2260. });
  2261. let style;
  2262. switch (this.aspect) {
  2263. case "fit":
  2264. case "actual":
  2265. break;
  2266. case "height":
  2267. style = {
  2268. height: "100%",
  2269. objectFit: "fill"
  2270. };
  2271. break;
  2272. case "none":
  2273. style = {
  2274. width: "100%",
  2275. height: "100%",
  2276. objectFit: "fill"
  2277. };
  2278. break;
  2279. case "width":
  2280. style = {
  2281. width: "100%",
  2282. objectFit: "fill"
  2283. };
  2284. break;
  2285. }
  2286. return _utils.HTMLResult.success({
  2287. name: "img",
  2288. attributes: {
  2289. class: ["xfaImage"],
  2290. style,
  2291. src: URL.createObjectURL(blob)
  2292. }
  2293. });
  2294. }
  2295. }
  2296. class ImageEdit extends _xfa_object.XFAObject {
  2297. constructor(attributes) {
  2298. super(TEMPLATE_NS_ID, "imageEdit", true);
  2299. this.data = (0, _utils.getStringOption)(attributes.data, ["link", "embed"]);
  2300. this.id = attributes.id || "";
  2301. this.use = attributes.use || "";
  2302. this.usehref = attributes.usehref || "";
  2303. this.border = null;
  2304. this.extras = null;
  2305. this.margin = null;
  2306. }
  2307. [_xfa_object.$toHTML](availableSpace) {
  2308. if (this.data === "embed") {
  2309. return _utils.HTMLResult.success({
  2310. name: "div",
  2311. children: [],
  2312. attributes: {}
  2313. });
  2314. }
  2315. return _utils.HTMLResult.EMPTY;
  2316. }
  2317. }
  2318. class Integer extends _xfa_object.ContentObject {
  2319. constructor(attributes) {
  2320. super(TEMPLATE_NS_ID, "integer");
  2321. this.id = attributes.id || "";
  2322. this.name = attributes.name || "";
  2323. this.use = attributes.use || "";
  2324. this.usehref = attributes.usehref || "";
  2325. }
  2326. [_xfa_object.$finalize]() {
  2327. const number = parseInt(this[_xfa_object.$content].trim(), 10);
  2328. this[_xfa_object.$content] = isNaN(number) ? null : number;
  2329. }
  2330. [_xfa_object.$toHTML](availableSpace) {
  2331. return valueToHtml(this[_xfa_object.$content] !== null ? this[_xfa_object.$content].toString() : "");
  2332. }
  2333. }
  2334. class Issuers extends _xfa_object.XFAObject {
  2335. constructor(attributes) {
  2336. super(TEMPLATE_NS_ID, "issuers", true);
  2337. this.id = attributes.id || "";
  2338. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  2339. this.use = attributes.use || "";
  2340. this.usehref = attributes.usehref || "";
  2341. this.certificate = new _xfa_object.XFAObjectArray();
  2342. }
  2343. }
  2344. class Items extends _xfa_object.XFAObject {
  2345. constructor(attributes) {
  2346. super(TEMPLATE_NS_ID, "items", true);
  2347. this.id = attributes.id || "";
  2348. this.name = attributes.name || "";
  2349. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  2350. this.ref = attributes.ref || "";
  2351. this.save = (0, _utils.getInteger)({
  2352. data: attributes.save,
  2353. defaultValue: 0,
  2354. validate: x => x === 1
  2355. });
  2356. this.use = attributes.use || "";
  2357. this.usehref = attributes.usehref || "";
  2358. this.boolean = new _xfa_object.XFAObjectArray();
  2359. this.date = new _xfa_object.XFAObjectArray();
  2360. this.dateTime = new _xfa_object.XFAObjectArray();
  2361. this.decimal = new _xfa_object.XFAObjectArray();
  2362. this.exData = new _xfa_object.XFAObjectArray();
  2363. this.float = new _xfa_object.XFAObjectArray();
  2364. this.image = new _xfa_object.XFAObjectArray();
  2365. this.integer = new _xfa_object.XFAObjectArray();
  2366. this.text = new _xfa_object.XFAObjectArray();
  2367. this.time = new _xfa_object.XFAObjectArray();
  2368. }
  2369. [_xfa_object.$toHTML]() {
  2370. const output = [];
  2371. for (const child of this[_xfa_object.$getChildren]()) {
  2372. output.push(child[_xfa_object.$text]());
  2373. }
  2374. return _utils.HTMLResult.success(output);
  2375. }
  2376. }
  2377. exports.Items = Items;
  2378. class Keep extends _xfa_object.XFAObject {
  2379. constructor(attributes) {
  2380. super(TEMPLATE_NS_ID, "keep", true);
  2381. this.id = attributes.id || "";
  2382. const options = ["none", "contentArea", "pageArea"];
  2383. this.intact = (0, _utils.getStringOption)(attributes.intact, options);
  2384. this.next = (0, _utils.getStringOption)(attributes.next, options);
  2385. this.previous = (0, _utils.getStringOption)(attributes.previous, options);
  2386. this.use = attributes.use || "";
  2387. this.usehref = attributes.usehref || "";
  2388. this.extras = null;
  2389. }
  2390. }
  2391. class KeyUsage extends _xfa_object.XFAObject {
  2392. constructor(attributes) {
  2393. super(TEMPLATE_NS_ID, "keyUsage");
  2394. const options = ["", "yes", "no"];
  2395. this.crlSign = (0, _utils.getStringOption)(attributes.crlSign, options);
  2396. this.dataEncipherment = (0, _utils.getStringOption)(attributes.dataEncipherment, options);
  2397. this.decipherOnly = (0, _utils.getStringOption)(attributes.decipherOnly, options);
  2398. this.digitalSignature = (0, _utils.getStringOption)(attributes.digitalSignature, options);
  2399. this.encipherOnly = (0, _utils.getStringOption)(attributes.encipherOnly, options);
  2400. this.id = attributes.id || "";
  2401. this.keyAgreement = (0, _utils.getStringOption)(attributes.keyAgreement, options);
  2402. this.keyCertSign = (0, _utils.getStringOption)(attributes.keyCertSign, options);
  2403. this.keyEncipherment = (0, _utils.getStringOption)(attributes.keyEncipherment, options);
  2404. this.nonRepudiation = (0, _utils.getStringOption)(attributes.nonRepudiation, options);
  2405. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  2406. this.use = attributes.use || "";
  2407. this.usehref = attributes.usehref || "";
  2408. }
  2409. }
  2410. class Line extends _xfa_object.XFAObject {
  2411. constructor(attributes) {
  2412. super(TEMPLATE_NS_ID, "line", true);
  2413. this.hand = (0, _utils.getStringOption)(attributes.hand, ["even", "left", "right"]);
  2414. this.id = attributes.id || "";
  2415. this.slope = (0, _utils.getStringOption)(attributes.slope, ["\\", "/"]);
  2416. this.use = attributes.use || "";
  2417. this.usehref = attributes.usehref || "";
  2418. this.edge = null;
  2419. }
  2420. [_xfa_object.$toHTML]() {
  2421. const parent = this[_xfa_object.$getParent]()[_xfa_object.$getParent]();
  2422. const edge = this.edge ? this.edge : new Edge({});
  2423. const edgeStyle = edge[_xfa_object.$toStyle]();
  2424. const style = Object.create(null);
  2425. const thickness = edge.presence === "visible" ? edge.thickness : 0;
  2426. style.strokeWidth = (0, _html_utils.measureToString)(thickness);
  2427. style.stroke = edgeStyle.color;
  2428. let x1, y1, x2, y2;
  2429. let width = "100%";
  2430. let height = "100%";
  2431. if (parent.w <= thickness) {
  2432. [x1, y1, x2, y2] = ["50%", 0, "50%", "100%"];
  2433. width = style.strokeWidth;
  2434. } else if (parent.h <= thickness) {
  2435. [x1, y1, x2, y2] = [0, "50%", "100%", "50%"];
  2436. height = style.strokeWidth;
  2437. } else {
  2438. if (this.slope === "\\") {
  2439. [x1, y1, x2, y2] = [0, 0, "100%", "100%"];
  2440. } else {
  2441. [x1, y1, x2, y2] = [0, "100%", "100%", 0];
  2442. }
  2443. }
  2444. const line = {
  2445. name: "line",
  2446. attributes: {
  2447. xmlns: SVG_NS,
  2448. x1,
  2449. y1,
  2450. x2,
  2451. y2,
  2452. style
  2453. }
  2454. };
  2455. const svg = {
  2456. name: "svg",
  2457. children: [line],
  2458. attributes: {
  2459. xmlns: SVG_NS,
  2460. width,
  2461. height,
  2462. style: {
  2463. overflow: "visible"
  2464. }
  2465. }
  2466. };
  2467. if (hasMargin(parent)) {
  2468. return _utils.HTMLResult.success({
  2469. name: "div",
  2470. attributes: {
  2471. style: {
  2472. display: "inline",
  2473. width: "100%",
  2474. height: "100%"
  2475. }
  2476. },
  2477. children: [svg]
  2478. });
  2479. }
  2480. svg.attributes.style.position = "absolute";
  2481. return _utils.HTMLResult.success(svg);
  2482. }
  2483. }
  2484. class Linear extends _xfa_object.XFAObject {
  2485. constructor(attributes) {
  2486. super(TEMPLATE_NS_ID, "linear", true);
  2487. this.id = attributes.id || "";
  2488. this.type = (0, _utils.getStringOption)(attributes.type, ["toRight", "toBottom", "toLeft", "toTop"]);
  2489. this.use = attributes.use || "";
  2490. this.usehref = attributes.usehref || "";
  2491. this.color = null;
  2492. this.extras = null;
  2493. }
  2494. [_xfa_object.$toStyle](startColor) {
  2495. startColor = startColor ? startColor[_xfa_object.$toStyle]() : "#FFFFFF";
  2496. const transf = this.type.replace(/([RBLT])/, " $1").toLowerCase();
  2497. const endColor = this.color ? this.color[_xfa_object.$toStyle]() : "#000000";
  2498. return `linear-gradient(${transf}, ${startColor}, ${endColor})`;
  2499. }
  2500. }
  2501. class LockDocument extends _xfa_object.ContentObject {
  2502. constructor(attributes) {
  2503. super(TEMPLATE_NS_ID, "lockDocument");
  2504. this.id = attributes.id || "";
  2505. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  2506. this.use = attributes.use || "";
  2507. this.usehref = attributes.usehref || "";
  2508. }
  2509. [_xfa_object.$finalize]() {
  2510. this[_xfa_object.$content] = (0, _utils.getStringOption)(this[_xfa_object.$content], ["auto", "0", "1"]);
  2511. }
  2512. }
  2513. class Manifest extends _xfa_object.XFAObject {
  2514. constructor(attributes) {
  2515. super(TEMPLATE_NS_ID, "manifest", true);
  2516. this.action = (0, _utils.getStringOption)(attributes.action, ["include", "all", "exclude"]);
  2517. this.id = attributes.id || "";
  2518. this.name = attributes.name || "";
  2519. this.use = attributes.use || "";
  2520. this.usehref = attributes.usehref || "";
  2521. this.extras = null;
  2522. this.ref = new _xfa_object.XFAObjectArray();
  2523. }
  2524. }
  2525. class Margin extends _xfa_object.XFAObject {
  2526. constructor(attributes) {
  2527. super(TEMPLATE_NS_ID, "margin", true);
  2528. this.bottomInset = (0, _utils.getMeasurement)(attributes.bottomInset, "0");
  2529. this.id = attributes.id || "";
  2530. this.leftInset = (0, _utils.getMeasurement)(attributes.leftInset, "0");
  2531. this.rightInset = (0, _utils.getMeasurement)(attributes.rightInset, "0");
  2532. this.topInset = (0, _utils.getMeasurement)(attributes.topInset, "0");
  2533. this.use = attributes.use || "";
  2534. this.usehref = attributes.usehref || "";
  2535. this.extras = null;
  2536. }
  2537. [_xfa_object.$toStyle]() {
  2538. return {
  2539. margin: (0, _html_utils.measureToString)(this.topInset) + " " + (0, _html_utils.measureToString)(this.rightInset) + " " + (0, _html_utils.measureToString)(this.bottomInset) + " " + (0, _html_utils.measureToString)(this.leftInset)
  2540. };
  2541. }
  2542. }
  2543. class Mdp extends _xfa_object.XFAObject {
  2544. constructor(attributes) {
  2545. super(TEMPLATE_NS_ID, "mdp");
  2546. this.id = attributes.id || "";
  2547. this.permissions = (0, _utils.getInteger)({
  2548. data: attributes.permissions,
  2549. defaultValue: 2,
  2550. validate: x => x === 1 || x === 3
  2551. });
  2552. this.signatureType = (0, _utils.getStringOption)(attributes.signatureType, ["filler", "author"]);
  2553. this.use = attributes.use || "";
  2554. this.usehref = attributes.usehref || "";
  2555. }
  2556. }
  2557. class Medium extends _xfa_object.XFAObject {
  2558. constructor(attributes) {
  2559. super(TEMPLATE_NS_ID, "medium");
  2560. this.id = attributes.id || "";
  2561. this.imagingBBox = (0, _utils.getBBox)(attributes.imagingBBox);
  2562. this.long = (0, _utils.getMeasurement)(attributes.long);
  2563. this.orientation = (0, _utils.getStringOption)(attributes.orientation, ["portrait", "landscape"]);
  2564. this.short = (0, _utils.getMeasurement)(attributes.short);
  2565. this.stock = attributes.stock || "";
  2566. this.trayIn = (0, _utils.getStringOption)(attributes.trayIn, ["auto", "delegate", "pageFront"]);
  2567. this.trayOut = (0, _utils.getStringOption)(attributes.trayOut, ["auto", "delegate"]);
  2568. this.use = attributes.use || "";
  2569. this.usehref = attributes.usehref || "";
  2570. }
  2571. }
  2572. class Message extends _xfa_object.XFAObject {
  2573. constructor(attributes) {
  2574. super(TEMPLATE_NS_ID, "message", true);
  2575. this.id = attributes.id || "";
  2576. this.use = attributes.use || "";
  2577. this.usehref = attributes.usehref || "";
  2578. this.text = new _xfa_object.XFAObjectArray();
  2579. }
  2580. }
  2581. class NumericEdit extends _xfa_object.XFAObject {
  2582. constructor(attributes) {
  2583. super(TEMPLATE_NS_ID, "numericEdit", true);
  2584. this.hScrollPolicy = (0, _utils.getStringOption)(attributes.hScrollPolicy, ["auto", "off", "on"]);
  2585. this.id = attributes.id || "";
  2586. this.use = attributes.use || "";
  2587. this.usehref = attributes.usehref || "";
  2588. this.border = null;
  2589. this.comb = null;
  2590. this.extras = null;
  2591. this.margin = null;
  2592. }
  2593. [_xfa_object.$toHTML](availableSpace) {
  2594. const style = (0, _html_utils.toStyle)(this, "border", "font", "margin");
  2595. const field = this[_xfa_object.$getParent]()[_xfa_object.$getParent]();
  2596. const html = {
  2597. name: "input",
  2598. attributes: {
  2599. type: "text",
  2600. fieldId: field[_xfa_object.$uid],
  2601. dataId: field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid],
  2602. class: ["xfaTextfield"],
  2603. style
  2604. }
  2605. };
  2606. return _utils.HTMLResult.success({
  2607. name: "label",
  2608. attributes: {
  2609. class: ["xfaLabel"]
  2610. },
  2611. children: [html]
  2612. });
  2613. }
  2614. }
  2615. class Occur extends _xfa_object.XFAObject {
  2616. constructor(attributes) {
  2617. super(TEMPLATE_NS_ID, "occur", true);
  2618. this.id = attributes.id || "";
  2619. this.initial = (0, _utils.getInteger)({
  2620. data: attributes.initial,
  2621. defaultValue: 1,
  2622. validate: x => true
  2623. });
  2624. this.max = (0, _utils.getInteger)({
  2625. data: attributes.max,
  2626. defaultValue: 1,
  2627. validate: x => true
  2628. });
  2629. this.min = (0, _utils.getInteger)({
  2630. data: attributes.min,
  2631. defaultValue: 1,
  2632. validate: x => true
  2633. });
  2634. this.use = attributes.use || "";
  2635. this.usehref = attributes.usehref || "";
  2636. this.extras = null;
  2637. }
  2638. }
  2639. class Oid extends _xfa_object.StringObject {
  2640. constructor(attributes) {
  2641. super(TEMPLATE_NS_ID, "oid");
  2642. this.id = attributes.id || "";
  2643. this.name = attributes.name || "";
  2644. this.use = attributes.use || "";
  2645. this.usehref = attributes.usehref || "";
  2646. }
  2647. }
  2648. class Oids extends _xfa_object.XFAObject {
  2649. constructor(attributes) {
  2650. super(TEMPLATE_NS_ID, "oids", true);
  2651. this.id = attributes.id || "";
  2652. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  2653. this.use = attributes.use || "";
  2654. this.usehref = attributes.usehref || "";
  2655. this.oid = new _xfa_object.XFAObjectArray();
  2656. }
  2657. }
  2658. class Overflow extends _xfa_object.XFAObject {
  2659. constructor(attributes) {
  2660. super(TEMPLATE_NS_ID, "overflow");
  2661. this.id = attributes.id || "";
  2662. this.leader = attributes.leader || "";
  2663. this.target = attributes.target || "";
  2664. this.trailer = attributes.trailer || "";
  2665. this.use = attributes.use || "";
  2666. this.usehref = attributes.usehref || "";
  2667. }
  2668. [_xfa_object.$getExtra]() {
  2669. if (!this[_xfa_object.$extra]) {
  2670. const parent = this[_xfa_object.$getParent]();
  2671. const root = this[_xfa_object.$getTemplateRoot]();
  2672. const target = root[_xfa_object.$searchNode](this.target, parent);
  2673. const leader = root[_xfa_object.$searchNode](this.leader, parent);
  2674. const trailer = root[_xfa_object.$searchNode](this.trailer, parent);
  2675. this[_xfa_object.$extra] = {
  2676. target: target && target[0] || null,
  2677. leader: leader && leader[0] || null,
  2678. trailer: trailer && trailer[0] || null,
  2679. addLeader: false,
  2680. addTrailer: false
  2681. };
  2682. }
  2683. return this[_xfa_object.$extra];
  2684. }
  2685. }
  2686. class PageArea extends _xfa_object.XFAObject {
  2687. constructor(attributes) {
  2688. super(TEMPLATE_NS_ID, "pageArea", true);
  2689. this.blankOrNotBlank = (0, _utils.getStringOption)(attributes.blankOrNotBlank, ["any", "blank", "notBlank"]);
  2690. this.id = attributes.id || "";
  2691. this.initialNumber = (0, _utils.getInteger)({
  2692. data: attributes.initialNumber,
  2693. defaultValue: 1,
  2694. validate: x => true
  2695. });
  2696. this.name = attributes.name || "";
  2697. this.numbered = (0, _utils.getInteger)({
  2698. data: attributes.numbered,
  2699. defaultValue: 1,
  2700. validate: x => true
  2701. });
  2702. this.oddOrEven = (0, _utils.getStringOption)(attributes.oddOrEven, ["any", "even", "odd"]);
  2703. this.pagePosition = (0, _utils.getStringOption)(attributes.pagePosition, ["any", "first", "last", "only", "rest"]);
  2704. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  2705. this.use = attributes.use || "";
  2706. this.usehref = attributes.usehref || "";
  2707. this.desc = null;
  2708. this.extras = null;
  2709. this.medium = null;
  2710. this.occur = null;
  2711. this.area = new _xfa_object.XFAObjectArray();
  2712. this.contentArea = new _xfa_object.XFAObjectArray();
  2713. this.draw = new _xfa_object.XFAObjectArray();
  2714. this.exclGroup = new _xfa_object.XFAObjectArray();
  2715. this.field = new _xfa_object.XFAObjectArray();
  2716. this.subform = new _xfa_object.XFAObjectArray();
  2717. }
  2718. [_xfa_object.$isUsable]() {
  2719. if (!this[_xfa_object.$extra]) {
  2720. this[_xfa_object.$extra] = {
  2721. numberOfUse: 0
  2722. };
  2723. return true;
  2724. }
  2725. return !this.occur || this.occur.max === -1 || this[_xfa_object.$extra].numberOfUse < this.occur.max;
  2726. }
  2727. [_xfa_object.$cleanPage]() {
  2728. delete this[_xfa_object.$extra];
  2729. }
  2730. [_xfa_object.$getNextPage]() {
  2731. if (!this[_xfa_object.$extra]) {
  2732. this[_xfa_object.$extra] = {
  2733. numberOfUse: 0
  2734. };
  2735. }
  2736. const parent = this[_xfa_object.$getParent]();
  2737. if (parent.relation === "orderedOccurrence") {
  2738. if (this[_xfa_object.$isUsable]()) {
  2739. this[_xfa_object.$extra].numberOfUse += 1;
  2740. return this;
  2741. }
  2742. }
  2743. return parent[_xfa_object.$getNextPage]();
  2744. }
  2745. [_xfa_object.$getAvailableSpace]() {
  2746. return this[_xfa_object.$extra].space || {
  2747. width: 0,
  2748. height: 0
  2749. };
  2750. }
  2751. [_xfa_object.$toHTML]() {
  2752. if (!this[_xfa_object.$extra]) {
  2753. this[_xfa_object.$extra] = {
  2754. numberOfUse: 1
  2755. };
  2756. }
  2757. const children = [];
  2758. this[_xfa_object.$extra].children = children;
  2759. const style = Object.create(null);
  2760. if (this.medium && this.medium.short && this.medium.long) {
  2761. style.width = (0, _html_utils.measureToString)(this.medium.short);
  2762. style.height = (0, _html_utils.measureToString)(this.medium.long);
  2763. this[_xfa_object.$extra].space = {
  2764. width: this.medium.short,
  2765. height: this.medium.long
  2766. };
  2767. if (this.medium.orientation === "landscape") {
  2768. const x = style.width;
  2769. style.width = style.height;
  2770. style.height = x;
  2771. this[_xfa_object.$extra].space = {
  2772. width: this.medium.long,
  2773. height: this.medium.short
  2774. };
  2775. }
  2776. } else {
  2777. (0, _util.warn)("XFA - No medium specified in pageArea: please file a bug.");
  2778. }
  2779. this[_xfa_object.$childrenToHTML]({
  2780. filter: new Set(["area", "draw", "field", "subform"]),
  2781. include: true
  2782. });
  2783. this[_xfa_object.$childrenToHTML]({
  2784. filter: new Set(["contentArea"]),
  2785. include: true
  2786. });
  2787. return _utils.HTMLResult.success({
  2788. name: "div",
  2789. children,
  2790. attributes: {
  2791. class: ["xfaPage"],
  2792. id: this[_xfa_object.$uid],
  2793. style,
  2794. xfaName: this.name
  2795. }
  2796. });
  2797. }
  2798. }
  2799. class PageSet extends _xfa_object.XFAObject {
  2800. constructor(attributes) {
  2801. super(TEMPLATE_NS_ID, "pageSet", true);
  2802. this.duplexImposition = (0, _utils.getStringOption)(attributes.duplexImposition, ["longEdge", "shortEdge"]);
  2803. this.id = attributes.id || "";
  2804. this.name = attributes.name || "";
  2805. this.relation = (0, _utils.getStringOption)(attributes.relation, ["orderedOccurrence", "duplexPaginated", "simplexPaginated"]);
  2806. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  2807. this.use = attributes.use || "";
  2808. this.usehref = attributes.usehref || "";
  2809. this.extras = null;
  2810. this.occur = null;
  2811. this.pageArea = new _xfa_object.XFAObjectArray();
  2812. this.pageSet = new _xfa_object.XFAObjectArray();
  2813. }
  2814. [_xfa_object.$cleanPage]() {
  2815. for (const page of this.pageArea.children) {
  2816. page[_xfa_object.$cleanPage]();
  2817. }
  2818. for (const page of this.pageSet.children) {
  2819. page[_xfa_object.$cleanPage]();
  2820. }
  2821. }
  2822. [_xfa_object.$isUsable]() {
  2823. return !this.occur || this.occur.max === -1 || this[_xfa_object.$extra].numberOfUse < this.occur.max;
  2824. }
  2825. [_xfa_object.$getNextPage]() {
  2826. if (!this[_xfa_object.$extra]) {
  2827. this[_xfa_object.$extra] = {
  2828. numberOfUse: 1,
  2829. pageIndex: -1,
  2830. pageSetIndex: -1
  2831. };
  2832. }
  2833. if (this.relation === "orderedOccurrence") {
  2834. if (this[_xfa_object.$extra].pageIndex + 1 < this.pageArea.children.length) {
  2835. this[_xfa_object.$extra].pageIndex += 1;
  2836. const pageArea = this.pageArea.children[this[_xfa_object.$extra].pageIndex];
  2837. return pageArea[_xfa_object.$getNextPage]();
  2838. }
  2839. if (this[_xfa_object.$extra].pageSetIndex + 1 < this.pageSet.children.length) {
  2840. this[_xfa_object.$extra].pageSetIndex += 1;
  2841. return this.pageSet.children[this[_xfa_object.$extra].pageSetIndex][_xfa_object.$getNextPage]();
  2842. }
  2843. if (this[_xfa_object.$isUsable]()) {
  2844. this[_xfa_object.$extra].numberOfUse += 1;
  2845. this[_xfa_object.$extra].pageIndex = -1;
  2846. this[_xfa_object.$extra].pageSetIndex = -1;
  2847. return this[_xfa_object.$getNextPage]();
  2848. }
  2849. const parent = this[_xfa_object.$getParent]();
  2850. if (parent instanceof PageSet) {
  2851. return parent[_xfa_object.$getNextPage]();
  2852. }
  2853. this[_xfa_object.$cleanPage]();
  2854. return this[_xfa_object.$getNextPage]();
  2855. }
  2856. const pageNumber = this[_xfa_object.$getTemplateRoot]()[_xfa_object.$extra].pageNumber;
  2857. const parity = pageNumber % 2 === 0 ? "even" : "odd";
  2858. const position = pageNumber === 0 ? "first" : "rest";
  2859. let page = this.pageArea.children.find(p => p.oddOrEven === parity && p.pagePosition === position);
  2860. if (page) {
  2861. return page;
  2862. }
  2863. page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === position);
  2864. if (page) {
  2865. return page;
  2866. }
  2867. page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === "any");
  2868. if (page) {
  2869. return page;
  2870. }
  2871. return this.pageArea.children[0];
  2872. }
  2873. }
  2874. class Para extends _xfa_object.XFAObject {
  2875. constructor(attributes) {
  2876. super(TEMPLATE_NS_ID, "para", true);
  2877. this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  2878. this.id = attributes.id || "";
  2879. this.lineHeight = attributes.lineHeight ? (0, _utils.getMeasurement)(attributes.lineHeight, "0pt") : "";
  2880. this.marginLeft = attributes.marginLeft ? (0, _utils.getMeasurement)(attributes.marginLeft, "0pt") : "";
  2881. this.marginRight = attributes.marginRight ? (0, _utils.getMeasurement)(attributes.marginRight, "0pt") : "";
  2882. this.orphans = (0, _utils.getInteger)({
  2883. data: attributes.orphans,
  2884. defaultValue: 0,
  2885. validate: x => x >= 0
  2886. });
  2887. this.preserve = attributes.preserve || "";
  2888. this.radixOffset = attributes.radixOffset ? (0, _utils.getMeasurement)(attributes.radixOffset, "0pt") : "";
  2889. this.spaceAbove = attributes.spaceAbove ? (0, _utils.getMeasurement)(attributes.spaceAbove, "0pt") : "";
  2890. this.spaceBelow = attributes.spaceBelow ? (0, _utils.getMeasurement)(attributes.spaceBelow, "0pt") : "";
  2891. this.tabDefault = attributes.tabDefault ? (0, _utils.getMeasurement)(this.tabDefault) : "";
  2892. this.tabStops = (attributes.tabStops || "").trim().split(/\s+/).map((x, i) => i % 2 === 1 ? (0, _utils.getMeasurement)(x) : x);
  2893. this.textIndent = attributes.textIndent ? (0, _utils.getMeasurement)(attributes.textIndent, "0pt") : "";
  2894. this.use = attributes.use || "";
  2895. this.usehref = attributes.usehref || "";
  2896. this.vAlign = (0, _utils.getStringOption)(attributes.vAlign, ["top", "bottom", "middle"]);
  2897. this.widows = (0, _utils.getInteger)({
  2898. data: attributes.widows,
  2899. defaultValue: 0,
  2900. validate: x => x >= 0
  2901. });
  2902. this.hyphenation = null;
  2903. }
  2904. [_xfa_object.$toStyle]() {
  2905. const style = (0, _html_utils.toStyle)(this, "hAlign");
  2906. if (this.marginLeft !== "") {
  2907. style.paddingLeft = (0, _html_utils.measureToString)(this.marginLeft);
  2908. }
  2909. if (this.marginRight !== "") {
  2910. style.paddingight = (0, _html_utils.measureToString)(this.marginRight);
  2911. }
  2912. if (this.spaceAbove !== "") {
  2913. style.paddingTop = (0, _html_utils.measureToString)(this.spaceAbove);
  2914. }
  2915. if (this.spaceBelow !== "") {
  2916. style.paddingBottom = (0, _html_utils.measureToString)(this.spaceBelow);
  2917. }
  2918. if (this.textIndent !== "") {
  2919. style.textIndent = (0, _html_utils.measureToString)(this.textIndent);
  2920. (0, _html_utils.fixTextIndent)(style);
  2921. }
  2922. if (this.lineHeight > 0) {
  2923. style.lineHeight = (0, _html_utils.measureToString)(this.lineHeight);
  2924. }
  2925. if (this.tabDefault !== "") {
  2926. style.tabSize = (0, _html_utils.measureToString)(this.tabDefault);
  2927. }
  2928. if (this.tabStops.length > 0) {}
  2929. if (this.hyphenatation) {
  2930. Object.assign(style, this.hyphenatation[_xfa_object.$toStyle]());
  2931. }
  2932. return style;
  2933. }
  2934. }
  2935. class PasswordEdit extends _xfa_object.XFAObject {
  2936. constructor(attributes) {
  2937. super(TEMPLATE_NS_ID, "passwordEdit", true);
  2938. this.hScrollPolicy = (0, _utils.getStringOption)(attributes.hScrollPolicy, ["auto", "off", "on"]);
  2939. this.id = attributes.id || "";
  2940. this.passwordChar = attributes.passwordChar || "*";
  2941. this.use = attributes.use || "";
  2942. this.usehref = attributes.usehref || "";
  2943. this.border = null;
  2944. this.extras = null;
  2945. this.margin = null;
  2946. }
  2947. }
  2948. class Pattern extends _xfa_object.XFAObject {
  2949. constructor(attributes) {
  2950. super(TEMPLATE_NS_ID, "pattern", true);
  2951. this.id = attributes.id || "";
  2952. this.type = (0, _utils.getStringOption)(attributes.type, ["crossHatch", "crossDiagonal", "diagonalLeft", "diagonalRight", "horizontal", "vertical"]);
  2953. this.use = attributes.use || "";
  2954. this.usehref = attributes.usehref || "";
  2955. this.color = null;
  2956. this.extras = null;
  2957. }
  2958. [_xfa_object.$toStyle](startColor) {
  2959. startColor = startColor ? startColor[_xfa_object.$toStyle]() : "#FFFFFF";
  2960. const endColor = this.color ? this.color[_xfa_object.$toStyle]() : "#000000";
  2961. const width = 5;
  2962. const cmd = "repeating-linear-gradient";
  2963. const colors = `${startColor},${startColor} ${width}px,${endColor} ${width}px,${endColor} ${2 * width}px`;
  2964. switch (this.type) {
  2965. case "crossHatch":
  2966. return `${cmd}(to top,${colors}) ${cmd}(to right,${colors})`;
  2967. case "crossDiagonal":
  2968. return `${cmd}(45deg,${colors}) ${cmd}(-45deg,${colors})`;
  2969. case "diagonalLeft":
  2970. return `${cmd}(45deg,${colors})`;
  2971. case "diagonalRight":
  2972. return `${cmd}(-45deg,${colors})`;
  2973. case "horizontal":
  2974. return `${cmd}(to top,${colors})`;
  2975. case "vertical":
  2976. return `${cmd}(to right,${colors})`;
  2977. }
  2978. return "";
  2979. }
  2980. }
  2981. class Picture extends _xfa_object.StringObject {
  2982. constructor(attributes) {
  2983. super(TEMPLATE_NS_ID, "picture");
  2984. this.id = attributes.id || "";
  2985. this.use = attributes.use || "";
  2986. this.usehref = attributes.usehref || "";
  2987. }
  2988. }
  2989. class Proto extends _xfa_object.XFAObject {
  2990. constructor(attributes) {
  2991. super(TEMPLATE_NS_ID, "proto", true);
  2992. this.appearanceFilter = new _xfa_object.XFAObjectArray();
  2993. this.arc = new _xfa_object.XFAObjectArray();
  2994. this.area = new _xfa_object.XFAObjectArray();
  2995. this.assist = new _xfa_object.XFAObjectArray();
  2996. this.barcode = new _xfa_object.XFAObjectArray();
  2997. this.bindItems = new _xfa_object.XFAObjectArray();
  2998. this.bookend = new _xfa_object.XFAObjectArray();
  2999. this.boolean = new _xfa_object.XFAObjectArray();
  3000. this.border = new _xfa_object.XFAObjectArray();
  3001. this.break = new _xfa_object.XFAObjectArray();
  3002. this.breakAfter = new _xfa_object.XFAObjectArray();
  3003. this.breakBefore = new _xfa_object.XFAObjectArray();
  3004. this.button = new _xfa_object.XFAObjectArray();
  3005. this.calculate = new _xfa_object.XFAObjectArray();
  3006. this.caption = new _xfa_object.XFAObjectArray();
  3007. this.certificate = new _xfa_object.XFAObjectArray();
  3008. this.certificates = new _xfa_object.XFAObjectArray();
  3009. this.checkButton = new _xfa_object.XFAObjectArray();
  3010. this.choiceList = new _xfa_object.XFAObjectArray();
  3011. this.color = new _xfa_object.XFAObjectArray();
  3012. this.comb = new _xfa_object.XFAObjectArray();
  3013. this.connect = new _xfa_object.XFAObjectArray();
  3014. this.contentArea = new _xfa_object.XFAObjectArray();
  3015. this.corner = new _xfa_object.XFAObjectArray();
  3016. this.date = new _xfa_object.XFAObjectArray();
  3017. this.dateTime = new _xfa_object.XFAObjectArray();
  3018. this.dateTimeEdit = new _xfa_object.XFAObjectArray();
  3019. this.decimal = new _xfa_object.XFAObjectArray();
  3020. this.defaultUi = new _xfa_object.XFAObjectArray();
  3021. this.desc = new _xfa_object.XFAObjectArray();
  3022. this.digestMethod = new _xfa_object.XFAObjectArray();
  3023. this.digestMethods = new _xfa_object.XFAObjectArray();
  3024. this.draw = new _xfa_object.XFAObjectArray();
  3025. this.edge = new _xfa_object.XFAObjectArray();
  3026. this.encoding = new _xfa_object.XFAObjectArray();
  3027. this.encodings = new _xfa_object.XFAObjectArray();
  3028. this.encrypt = new _xfa_object.XFAObjectArray();
  3029. this.encryptData = new _xfa_object.XFAObjectArray();
  3030. this.encryption = new _xfa_object.XFAObjectArray();
  3031. this.encryptionMethod = new _xfa_object.XFAObjectArray();
  3032. this.encryptionMethods = new _xfa_object.XFAObjectArray();
  3033. this.event = new _xfa_object.XFAObjectArray();
  3034. this.exData = new _xfa_object.XFAObjectArray();
  3035. this.exObject = new _xfa_object.XFAObjectArray();
  3036. this.exclGroup = new _xfa_object.XFAObjectArray();
  3037. this.execute = new _xfa_object.XFAObjectArray();
  3038. this.extras = new _xfa_object.XFAObjectArray();
  3039. this.field = new _xfa_object.XFAObjectArray();
  3040. this.fill = new _xfa_object.XFAObjectArray();
  3041. this.filter = new _xfa_object.XFAObjectArray();
  3042. this.float = new _xfa_object.XFAObjectArray();
  3043. this.font = new _xfa_object.XFAObjectArray();
  3044. this.format = new _xfa_object.XFAObjectArray();
  3045. this.handler = new _xfa_object.XFAObjectArray();
  3046. this.hyphenation = new _xfa_object.XFAObjectArray();
  3047. this.image = new _xfa_object.XFAObjectArray();
  3048. this.imageEdit = new _xfa_object.XFAObjectArray();
  3049. this.integer = new _xfa_object.XFAObjectArray();
  3050. this.issuers = new _xfa_object.XFAObjectArray();
  3051. this.items = new _xfa_object.XFAObjectArray();
  3052. this.keep = new _xfa_object.XFAObjectArray();
  3053. this.keyUsage = new _xfa_object.XFAObjectArray();
  3054. this.line = new _xfa_object.XFAObjectArray();
  3055. this.linear = new _xfa_object.XFAObjectArray();
  3056. this.lockDocument = new _xfa_object.XFAObjectArray();
  3057. this.manifest = new _xfa_object.XFAObjectArray();
  3058. this.margin = new _xfa_object.XFAObjectArray();
  3059. this.mdp = new _xfa_object.XFAObjectArray();
  3060. this.medium = new _xfa_object.XFAObjectArray();
  3061. this.message = new _xfa_object.XFAObjectArray();
  3062. this.numericEdit = new _xfa_object.XFAObjectArray();
  3063. this.occur = new _xfa_object.XFAObjectArray();
  3064. this.oid = new _xfa_object.XFAObjectArray();
  3065. this.oids = new _xfa_object.XFAObjectArray();
  3066. this.overflow = new _xfa_object.XFAObjectArray();
  3067. this.pageArea = new _xfa_object.XFAObjectArray();
  3068. this.pageSet = new _xfa_object.XFAObjectArray();
  3069. this.para = new _xfa_object.XFAObjectArray();
  3070. this.passwordEdit = new _xfa_object.XFAObjectArray();
  3071. this.pattern = new _xfa_object.XFAObjectArray();
  3072. this.picture = new _xfa_object.XFAObjectArray();
  3073. this.radial = new _xfa_object.XFAObjectArray();
  3074. this.reason = new _xfa_object.XFAObjectArray();
  3075. this.reasons = new _xfa_object.XFAObjectArray();
  3076. this.rectangle = new _xfa_object.XFAObjectArray();
  3077. this.ref = new _xfa_object.XFAObjectArray();
  3078. this.script = new _xfa_object.XFAObjectArray();
  3079. this.setProperty = new _xfa_object.XFAObjectArray();
  3080. this.signData = new _xfa_object.XFAObjectArray();
  3081. this.signature = new _xfa_object.XFAObjectArray();
  3082. this.signing = new _xfa_object.XFAObjectArray();
  3083. this.solid = new _xfa_object.XFAObjectArray();
  3084. this.speak = new _xfa_object.XFAObjectArray();
  3085. this.stipple = new _xfa_object.XFAObjectArray();
  3086. this.subform = new _xfa_object.XFAObjectArray();
  3087. this.subformSet = new _xfa_object.XFAObjectArray();
  3088. this.subjectDN = new _xfa_object.XFAObjectArray();
  3089. this.subjectDNs = new _xfa_object.XFAObjectArray();
  3090. this.submit = new _xfa_object.XFAObjectArray();
  3091. this.text = new _xfa_object.XFAObjectArray();
  3092. this.textEdit = new _xfa_object.XFAObjectArray();
  3093. this.time = new _xfa_object.XFAObjectArray();
  3094. this.timeStamp = new _xfa_object.XFAObjectArray();
  3095. this.toolTip = new _xfa_object.XFAObjectArray();
  3096. this.traversal = new _xfa_object.XFAObjectArray();
  3097. this.traverse = new _xfa_object.XFAObjectArray();
  3098. this.ui = new _xfa_object.XFAObjectArray();
  3099. this.validate = new _xfa_object.XFAObjectArray();
  3100. this.value = new _xfa_object.XFAObjectArray();
  3101. this.variables = new _xfa_object.XFAObjectArray();
  3102. }
  3103. }
  3104. class Radial extends _xfa_object.XFAObject {
  3105. constructor(attributes) {
  3106. super(TEMPLATE_NS_ID, "radial", true);
  3107. this.id = attributes.id || "";
  3108. this.type = (0, _utils.getStringOption)(attributes.type, ["toEdge", "toCenter"]);
  3109. this.use = attributes.use || "";
  3110. this.usehref = attributes.usehref || "";
  3111. this.color = null;
  3112. this.extras = null;
  3113. }
  3114. [_xfa_object.$toStyle](startColor) {
  3115. startColor = startColor ? startColor[_xfa_object.$toStyle]() : "#FFFFFF";
  3116. const endColor = this.color ? this.color[_xfa_object.$toStyle]() : "#000000";
  3117. const colors = this.type === "toEdge" ? `${startColor},${endColor}` : `${endColor},${startColor}`;
  3118. return `radial-gradient(circle at center, ${colors})`;
  3119. }
  3120. }
  3121. class Reason extends _xfa_object.StringObject {
  3122. constructor(attributes) {
  3123. super(TEMPLATE_NS_ID, "reason");
  3124. this.id = attributes.id || "";
  3125. this.name = attributes.name || "";
  3126. this.use = attributes.use || "";
  3127. this.usehref = attributes.usehref || "";
  3128. }
  3129. }
  3130. class Reasons extends _xfa_object.XFAObject {
  3131. constructor(attributes) {
  3132. super(TEMPLATE_NS_ID, "reasons", true);
  3133. this.id = attributes.id || "";
  3134. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  3135. this.use = attributes.use || "";
  3136. this.usehref = attributes.usehref || "";
  3137. this.reason = new _xfa_object.XFAObjectArray();
  3138. }
  3139. }
  3140. class Rectangle extends _xfa_object.XFAObject {
  3141. constructor(attributes) {
  3142. super(TEMPLATE_NS_ID, "rectangle", true);
  3143. this.hand = (0, _utils.getStringOption)(attributes.hand, ["even", "left", "right"]);
  3144. this.id = attributes.id || "";
  3145. this.use = attributes.use || "";
  3146. this.usehref = attributes.usehref || "";
  3147. this.corner = new _xfa_object.XFAObjectArray(4);
  3148. this.edge = new _xfa_object.XFAObjectArray(4);
  3149. this.fill = null;
  3150. }
  3151. [_xfa_object.$toHTML]() {
  3152. const edge = this.edge.children.length ? this.edge.children[0] : new Edge({});
  3153. const edgeStyle = edge[_xfa_object.$toStyle]();
  3154. const style = Object.create(null);
  3155. if (this.fill && this.fill.presence === "visible") {
  3156. Object.assign(style, this.fill[_xfa_object.$toStyle]());
  3157. } else {
  3158. style.fill = "transparent";
  3159. }
  3160. style.strokeWidth = (0, _html_utils.measureToString)(edge.presence === "visible" ? edge.thickness : 0);
  3161. style.stroke = edgeStyle.color;
  3162. const corner = this.corner.children.length ? this.corner.children[0] : new Corner({});
  3163. const cornerStyle = corner[_xfa_object.$toStyle]();
  3164. const rect = {
  3165. name: "rect",
  3166. attributes: {
  3167. xmlns: SVG_NS,
  3168. width: "100%",
  3169. height: "100%",
  3170. x: 0,
  3171. y: 0,
  3172. rx: cornerStyle.radius,
  3173. ry: cornerStyle.radius,
  3174. style
  3175. }
  3176. };
  3177. const svg = {
  3178. name: "svg",
  3179. children: [rect],
  3180. attributes: {
  3181. xmlns: SVG_NS,
  3182. style: {
  3183. overflow: "visible"
  3184. },
  3185. width: "100%",
  3186. height: "100%"
  3187. }
  3188. };
  3189. const parent = this[_xfa_object.$getParent]()[_xfa_object.$getParent]();
  3190. if (hasMargin(parent)) {
  3191. return _utils.HTMLResult.success({
  3192. name: "div",
  3193. attributes: {
  3194. style: {
  3195. display: "inline",
  3196. width: "100%",
  3197. height: "100%"
  3198. }
  3199. },
  3200. children: [svg]
  3201. });
  3202. }
  3203. svg.attributes.style.position = "absolute";
  3204. return _utils.HTMLResult.success(svg);
  3205. }
  3206. }
  3207. class RefElement extends _xfa_object.StringObject {
  3208. constructor(attributes) {
  3209. super(TEMPLATE_NS_ID, "ref");
  3210. this.id = attributes.id || "";
  3211. this.use = attributes.use || "";
  3212. this.usehref = attributes.usehref || "";
  3213. }
  3214. }
  3215. class Script extends _xfa_object.StringObject {
  3216. constructor(attributes) {
  3217. super(TEMPLATE_NS_ID, "script");
  3218. this.binding = attributes.binding || "";
  3219. this.contentType = attributes.contentType || "";
  3220. this.id = attributes.id || "";
  3221. this.name = attributes.name || "";
  3222. this.runAt = (0, _utils.getStringOption)(attributes.runAt, ["client", "both", "server"]);
  3223. this.use = attributes.use || "";
  3224. this.usehref = attributes.usehref || "";
  3225. }
  3226. }
  3227. class SetProperty extends _xfa_object.XFAObject {
  3228. constructor(attributes) {
  3229. super(TEMPLATE_NS_ID, "setProperty");
  3230. this.connection = attributes.connection || "";
  3231. this.ref = attributes.ref || "";
  3232. this.target = attributes.target || "";
  3233. }
  3234. }
  3235. exports.SetProperty = SetProperty;
  3236. class SignData extends _xfa_object.XFAObject {
  3237. constructor(attributes) {
  3238. super(TEMPLATE_NS_ID, "signData", true);
  3239. this.id = attributes.id || "";
  3240. this.operation = (0, _utils.getStringOption)(attributes.operation, ["sign", "clear", "verify"]);
  3241. this.ref = attributes.ref || "";
  3242. this.target = attributes.target || "";
  3243. this.use = attributes.use || "";
  3244. this.usehref = attributes.usehref || "";
  3245. this.filter = null;
  3246. this.manifest = null;
  3247. }
  3248. }
  3249. class Signature extends _xfa_object.XFAObject {
  3250. constructor(attributes) {
  3251. super(TEMPLATE_NS_ID, "signature", true);
  3252. this.id = attributes.id || "";
  3253. this.type = (0, _utils.getStringOption)(attributes.type, ["PDF1.3", "PDF1.6"]);
  3254. this.use = attributes.use || "";
  3255. this.usehref = attributes.usehref || "";
  3256. this.border = null;
  3257. this.extras = null;
  3258. this.filter = null;
  3259. this.manifest = null;
  3260. this.margin = null;
  3261. }
  3262. }
  3263. class Signing extends _xfa_object.XFAObject {
  3264. constructor(attributes) {
  3265. super(TEMPLATE_NS_ID, "signing", true);
  3266. this.id = attributes.id || "";
  3267. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  3268. this.use = attributes.use || "";
  3269. this.usehref = attributes.usehref || "";
  3270. this.certificate = new _xfa_object.XFAObjectArray();
  3271. }
  3272. }
  3273. class Solid extends _xfa_object.XFAObject {
  3274. constructor(attributes) {
  3275. super(TEMPLATE_NS_ID, "solid", true);
  3276. this.id = attributes.id || "";
  3277. this.use = attributes.use || "";
  3278. this.usehref = attributes.usehref || "";
  3279. this.extras = null;
  3280. }
  3281. [_xfa_object.$toStyle](startColor) {
  3282. return startColor ? startColor[_xfa_object.$toStyle]() : "#FFFFFF";
  3283. }
  3284. }
  3285. class Speak extends _xfa_object.StringObject {
  3286. constructor(attributes) {
  3287. super(TEMPLATE_NS_ID, "speak");
  3288. this.disable = (0, _utils.getInteger)({
  3289. data: attributes.disable,
  3290. defaultValue: 0,
  3291. validate: x => x === 1
  3292. });
  3293. this.id = attributes.id || "";
  3294. this.priority = (0, _utils.getStringOption)(attributes.priority, ["custom", "caption", "name", "toolTip"]);
  3295. this.rid = attributes.rid || "";
  3296. this.use = attributes.use || "";
  3297. this.usehref = attributes.usehref || "";
  3298. }
  3299. }
  3300. class Stipple extends _xfa_object.XFAObject {
  3301. constructor(attributes) {
  3302. super(TEMPLATE_NS_ID, "stipple", true);
  3303. this.id = attributes.id || "";
  3304. this.rate = (0, _utils.getInteger)({
  3305. data: attributes.rate,
  3306. defaultValue: 50,
  3307. validate: x => x >= 0 && x <= 100
  3308. });
  3309. this.use = attributes.use || "";
  3310. this.usehref = attributes.usehref || "";
  3311. this.color = null;
  3312. this.extras = null;
  3313. }
  3314. [_xfa_object.$toStyle](bgColor) {
  3315. const alpha = this.rate / 100;
  3316. return _util.Util.makeHexColor(Math.round(bgColor.value.r * (1 - alpha) + this.value.r * alpha), Math.round(bgColor.value.g * (1 - alpha) + this.value.g * alpha), Math.round(bgColor.value.b * (1 - alpha) + this.value.b * alpha));
  3317. }
  3318. }
  3319. class Subform extends _xfa_object.XFAObject {
  3320. constructor(attributes) {
  3321. super(TEMPLATE_NS_ID, "subform", true);
  3322. this.access = (0, _utils.getStringOption)(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
  3323. this.allowMacro = (0, _utils.getInteger)({
  3324. data: attributes.allowMacro,
  3325. defaultValue: 0,
  3326. validate: x => x === 1
  3327. });
  3328. this.anchorType = (0, _utils.getStringOption)(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  3329. this.colSpan = (0, _utils.getInteger)({
  3330. data: attributes.colSpan,
  3331. defaultValue: 1,
  3332. validate: n => n >= 1 || n === -1
  3333. });
  3334. this.columnWidths = (attributes.columnWidths || "").trim().split(/\s+/).map(x => x === "-1" ? -1 : (0, _utils.getMeasurement)(x));
  3335. this.h = attributes.h ? (0, _utils.getMeasurement)(attributes.h) : "";
  3336. this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  3337. this.id = attributes.id || "";
  3338. this.layout = (0, _utils.getStringOption)(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]);
  3339. this.locale = attributes.locale || "";
  3340. this.maxH = (0, _utils.getMeasurement)(attributes.maxH, "0pt");
  3341. this.maxW = (0, _utils.getMeasurement)(attributes.maxW, "0pt");
  3342. this.mergeMode = (0, _utils.getStringOption)(attributes.mergeMode, ["consumeData", "matchTemplate"]);
  3343. this.minH = (0, _utils.getMeasurement)(attributes.minH, "0pt");
  3344. this.minW = (0, _utils.getMeasurement)(attributes.minW, "0pt");
  3345. this.name = attributes.name || "";
  3346. this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  3347. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  3348. this.restoreState = (0, _utils.getStringOption)(attributes.restoreState, ["manual", "auto"]);
  3349. this.scope = (0, _utils.getStringOption)(attributes.scope, ["name", "none"]);
  3350. this.use = attributes.use || "";
  3351. this.usehref = attributes.usehref || "";
  3352. this.w = attributes.w ? (0, _utils.getMeasurement)(attributes.w) : "";
  3353. this.x = (0, _utils.getMeasurement)(attributes.x, "0pt");
  3354. this.y = (0, _utils.getMeasurement)(attributes.y, "0pt");
  3355. this.assist = null;
  3356. this.bind = null;
  3357. this.bookend = null;
  3358. this.border = null;
  3359. this.break = null;
  3360. this.calculate = null;
  3361. this.desc = null;
  3362. this.extras = null;
  3363. this.keep = null;
  3364. this.margin = null;
  3365. this.occur = null;
  3366. this.overflow = null;
  3367. this.pageSet = null;
  3368. this.para = null;
  3369. this.traversal = null;
  3370. this.validate = null;
  3371. this.variables = null;
  3372. this.area = new _xfa_object.XFAObjectArray();
  3373. this.breakAfter = new _xfa_object.XFAObjectArray();
  3374. this.breakBefore = new _xfa_object.XFAObjectArray();
  3375. this.connect = new _xfa_object.XFAObjectArray();
  3376. this.draw = new _xfa_object.XFAObjectArray();
  3377. this.event = new _xfa_object.XFAObjectArray();
  3378. this.exObject = new _xfa_object.XFAObjectArray();
  3379. this.exclGroup = new _xfa_object.XFAObjectArray();
  3380. this.field = new _xfa_object.XFAObjectArray();
  3381. this.proto = new _xfa_object.XFAObjectArray();
  3382. this.setProperty = new _xfa_object.XFAObjectArray();
  3383. this.subform = new _xfa_object.XFAObjectArray();
  3384. this.subformSet = new _xfa_object.XFAObjectArray();
  3385. }
  3386. [_xfa_object.$getSubformParent]() {
  3387. const parent = this[_xfa_object.$getParent]();
  3388. if (parent instanceof SubformSet) {
  3389. return parent[_xfa_object.$getSubformParent]();
  3390. }
  3391. return parent;
  3392. }
  3393. [_xfa_object.$isBindable]() {
  3394. return true;
  3395. }
  3396. [_xfa_object.$isThereMoreWidth]() {
  3397. return this.layout.endsWith("-tb") && this[_xfa_object.$extra].attempt === 0 && this[_xfa_object.$extra].numberInLine > 0 || this[_xfa_object.$getParent]()[_xfa_object.$isThereMoreWidth]();
  3398. }
  3399. *[_xfa_object.$getContainedChildren]() {
  3400. yield* getContainedChildren(this);
  3401. }
  3402. [_xfa_object.$flushHTML]() {
  3403. return (0, _layout.flushHTML)(this);
  3404. }
  3405. [_xfa_object.$addHTML](html, bbox) {
  3406. (0, _layout.addHTML)(this, html, bbox);
  3407. }
  3408. [_xfa_object.$getAvailableSpace]() {
  3409. return (0, _layout.getAvailableSpace)(this);
  3410. }
  3411. [_xfa_object.$isSplittable]() {
  3412. const parent = this[_xfa_object.$getSubformParent]();
  3413. if (!parent[_xfa_object.$isSplittable]()) {
  3414. return false;
  3415. }
  3416. const contentArea = this[_xfa_object.$getTemplateRoot]()[_xfa_object.$extra].currentContentArea;
  3417. if (this.overflow && this.overflow[_xfa_object.$getExtra]().target === contentArea) {
  3418. return false;
  3419. }
  3420. if (this[_xfa_object.$extra]._isSplittable !== undefined) {
  3421. return this[_xfa_object.$extra]._isSplittable;
  3422. }
  3423. if (this.layout === "position" || this.layout.includes("row")) {
  3424. this[_xfa_object.$extra]._isSplittable = false;
  3425. return false;
  3426. }
  3427. if (this.keep && this.keep.intact !== "none") {
  3428. this[_xfa_object.$extra]._isSplittable = false;
  3429. return false;
  3430. }
  3431. if (parent.layout && parent.layout.endsWith("-tb") && parent[_xfa_object.$extra].numberInLine !== 0) {
  3432. return false;
  3433. }
  3434. this[_xfa_object.$extra]._isSplittable = true;
  3435. return true;
  3436. }
  3437. [_xfa_object.$toHTML](availableSpace) {
  3438. if (this.break) {
  3439. if (this.break.after !== "auto" || this.break.afterTarget !== "") {
  3440. const node = new BreakAfter({
  3441. targetType: this.break.after,
  3442. target: this.break.afterTarget,
  3443. startNew: this.break.startNew.toString()
  3444. });
  3445. node[_xfa_object.$globalData] = this[_xfa_object.$globalData];
  3446. this[_xfa_object.$appendChild](node);
  3447. this.breakAfter.push(node);
  3448. }
  3449. if (this.break.before !== "auto" || this.break.beforeTarget !== "") {
  3450. const node = new BreakBefore({
  3451. targetType: this.break.before,
  3452. target: this.break.beforeTarget,
  3453. startNew: this.break.startNew.toString()
  3454. });
  3455. node[_xfa_object.$globalData] = this[_xfa_object.$globalData];
  3456. this[_xfa_object.$appendChild](node);
  3457. this.breakBefore.push(node);
  3458. }
  3459. if (this.break.overflowTarget !== "") {
  3460. const node = new Overflow({
  3461. target: this.break.overflowTarget,
  3462. leader: this.break.overflowLeader,
  3463. trailer: this.break.overflowTrailer
  3464. });
  3465. node[_xfa_object.$globalData] = this[_xfa_object.$globalData];
  3466. this[_xfa_object.$appendChild](node);
  3467. this.overflow.push(node);
  3468. }
  3469. this[_xfa_object.$removeChild](this.break);
  3470. this.break = null;
  3471. }
  3472. if (this.presence === "hidden" || this.presence === "inactive") {
  3473. return _utils.HTMLResult.EMPTY;
  3474. }
  3475. if (this.breakBefore.children.length > 1 || this.breakAfter.children.length > 1) {
  3476. (0, _util.warn)("XFA - Several breakBefore or breakAfter in subforms: please file a bug.");
  3477. }
  3478. if (this.breakBefore.children.length >= 1) {
  3479. const breakBefore = this.breakBefore.children[0];
  3480. if (handleBreak(breakBefore)) {
  3481. return _utils.HTMLResult.breakNode(breakBefore);
  3482. }
  3483. }
  3484. if (this[_xfa_object.$extra] && this[_xfa_object.$extra].afterBreakAfter) {
  3485. return _utils.HTMLResult.EMPTY;
  3486. }
  3487. (0, _html_utils.fixDimensions)(this);
  3488. const children = [];
  3489. const attributes = {
  3490. id: this[_xfa_object.$uid],
  3491. class: []
  3492. };
  3493. (0, _html_utils.setAccess)(this, attributes.class);
  3494. if (!this[_xfa_object.$extra]) {
  3495. this[_xfa_object.$extra] = Object.create(null);
  3496. }
  3497. Object.assign(this[_xfa_object.$extra], {
  3498. children,
  3499. line: null,
  3500. attributes,
  3501. attempt: 0,
  3502. numberInLine: 0,
  3503. availableSpace: {
  3504. width: Math.min(this.w || Infinity, availableSpace.width),
  3505. height: Math.min(this.h || Infinity, availableSpace.height)
  3506. },
  3507. width: 0,
  3508. height: 0,
  3509. prevHeight: 0,
  3510. currentWidth: 0
  3511. });
  3512. const root = this[_xfa_object.$getTemplateRoot]();
  3513. const currentContentArea = root[_xfa_object.$extra].currentContentArea;
  3514. const savedNoLayoutFailure = root[_xfa_object.$extra].noLayoutFailure;
  3515. if (this.overflow) {
  3516. root[_xfa_object.$extra].noLayoutFailure = root[_xfa_object.$extra].noLayoutFailure || this.overflow[_xfa_object.$getExtra]().target === currentContentArea;
  3517. }
  3518. const isSplittable = this[_xfa_object.$isSplittable]();
  3519. if (!isSplittable) {
  3520. setFirstUnsplittable(this);
  3521. }
  3522. if (!(0, _layout.checkDimensions)(this, availableSpace)) {
  3523. return _utils.HTMLResult.FAILURE;
  3524. }
  3525. const filter = new Set(["area", "draw", "exclGroup", "field", "subform", "subformSet"]);
  3526. if (this.layout.includes("row")) {
  3527. const columnWidths = this[_xfa_object.$getSubformParent]().columnWidths;
  3528. if (Array.isArray(columnWidths) && columnWidths.length > 0) {
  3529. this[_xfa_object.$extra].columnWidths = columnWidths;
  3530. this[_xfa_object.$extra].currentColumn = 0;
  3531. }
  3532. }
  3533. const style = (0, _html_utils.toStyle)(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign");
  3534. const classNames = ["xfaSubform"];
  3535. const cl = (0, _html_utils.layoutClass)(this);
  3536. if (cl) {
  3537. classNames.push(cl);
  3538. }
  3539. attributes.style = style;
  3540. attributes.class = classNames;
  3541. if (this.name) {
  3542. attributes.xfaName = this.name;
  3543. }
  3544. if (this.overflow) {
  3545. const overflowExtra = this.overflow[_xfa_object.$getExtra]();
  3546. if (overflowExtra.addLeader) {
  3547. overflowExtra.addLeader = false;
  3548. handleOverflow(this, overflowExtra.leader, availableSpace);
  3549. }
  3550. }
  3551. const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
  3552. const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
  3553. for (; this[_xfa_object.$extra].attempt < maxRun; this[_xfa_object.$extra].attempt++) {
  3554. if (isLrTb && this[_xfa_object.$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) {
  3555. this[_xfa_object.$extra].numberInLine = 0;
  3556. }
  3557. const result = this[_xfa_object.$childrenToHTML]({
  3558. filter,
  3559. include: true
  3560. });
  3561. if (result.success) {
  3562. break;
  3563. }
  3564. if (result.isBreak()) {
  3565. return result;
  3566. }
  3567. if (isLrTb && this[_xfa_object.$extra].attempt === 0 && this[_xfa_object.$extra].numberInLine === 0 && !root[_xfa_object.$extra].noLayoutFailure) {
  3568. this[_xfa_object.$extra].attempt = maxRun;
  3569. break;
  3570. }
  3571. }
  3572. if (!isSplittable) {
  3573. unsetFirstUnsplittable(this);
  3574. }
  3575. root[_xfa_object.$extra].noLayoutFailure = savedNoLayoutFailure;
  3576. if (this[_xfa_object.$extra].attempt === maxRun) {
  3577. if (this.overflow) {
  3578. this[_xfa_object.$getTemplateRoot]()[_xfa_object.$extra].overflowNode = this.overflow;
  3579. }
  3580. if (!isSplittable) {
  3581. delete this[_xfa_object.$extra];
  3582. }
  3583. return _utils.HTMLResult.FAILURE;
  3584. }
  3585. if (this.overflow) {
  3586. const overflowExtra = this.overflow[_xfa_object.$getExtra]();
  3587. if (overflowExtra.addTrailer) {
  3588. overflowExtra.addTrailer = false;
  3589. handleOverflow(this, overflowExtra.trailer, availableSpace);
  3590. }
  3591. }
  3592. let marginH = 0;
  3593. let marginV = 0;
  3594. if (this.margin) {
  3595. marginH = this.margin.leftInset + this.margin.rightInset;
  3596. marginV = this.margin.topInset + this.margin.bottomInset;
  3597. }
  3598. const width = Math.max(this[_xfa_object.$extra].width + marginH, this.w || 0);
  3599. const height = Math.max(this[_xfa_object.$extra].height + marginV, this.h || 0);
  3600. const bbox = [this.x, this.y, width, height];
  3601. if (this.w === "") {
  3602. style.width = (0, _html_utils.measureToString)(width);
  3603. }
  3604. if (this.h === "") {
  3605. style.height = (0, _html_utils.measureToString)(height);
  3606. }
  3607. const html = {
  3608. name: "div",
  3609. attributes,
  3610. children
  3611. };
  3612. const assist = this.assist ? this.assist[_xfa_object.$toHTML]() : null;
  3613. if (assist) {
  3614. html.attributes.title = assist;
  3615. }
  3616. const result = _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox);
  3617. if (this.breakAfter.children.length >= 1) {
  3618. const breakAfter = this.breakAfter.children[0];
  3619. if (handleBreak(breakAfter)) {
  3620. this[_xfa_object.$extra].afterBreakAfter = result;
  3621. return _utils.HTMLResult.breakNode(breakAfter);
  3622. }
  3623. }
  3624. delete this[_xfa_object.$extra];
  3625. return result;
  3626. }
  3627. }
  3628. class SubformSet extends _xfa_object.XFAObject {
  3629. constructor(attributes) {
  3630. super(TEMPLATE_NS_ID, "subformSet", true);
  3631. this.id = attributes.id || "";
  3632. this.name = attributes.name || "";
  3633. this.relation = (0, _utils.getStringOption)(attributes.relation, ["ordered", "choice", "unordered"]);
  3634. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  3635. this.use = attributes.use || "";
  3636. this.usehref = attributes.usehref || "";
  3637. this.bookend = null;
  3638. this.break = null;
  3639. this.desc = null;
  3640. this.extras = null;
  3641. this.occur = null;
  3642. this.overflow = null;
  3643. this.breakAfter = new _xfa_object.XFAObjectArray();
  3644. this.breakBefore = new _xfa_object.XFAObjectArray();
  3645. this.subform = new _xfa_object.XFAObjectArray();
  3646. this.subformSet = new _xfa_object.XFAObjectArray();
  3647. }
  3648. *[_xfa_object.$getContainedChildren]() {
  3649. yield* getContainedChildren(this);
  3650. }
  3651. [_xfa_object.$getSubformParent]() {
  3652. let parent = this[_xfa_object.$getParent]();
  3653. while (!(parent instanceof Subform)) {
  3654. parent = parent[_xfa_object.$getParent]();
  3655. }
  3656. return parent;
  3657. }
  3658. }
  3659. class SubjectDN extends _xfa_object.ContentObject {
  3660. constructor(attributes) {
  3661. super(TEMPLATE_NS_ID, "subjectDN");
  3662. this.delimiter = attributes.delimiter || ",";
  3663. this.id = attributes.id || "";
  3664. this.name = attributes.name || "";
  3665. this.use = attributes.use || "";
  3666. this.usehref = attributes.usehref || "";
  3667. }
  3668. [_xfa_object.$finalize]() {
  3669. this[_xfa_object.$content] = new Map(this[_xfa_object.$content].split(this.delimiter).map(kv => {
  3670. kv = kv.split("=", 2);
  3671. kv[0] = kv[0].trim();
  3672. return kv;
  3673. }));
  3674. }
  3675. }
  3676. class SubjectDNs extends _xfa_object.XFAObject {
  3677. constructor(attributes) {
  3678. super(TEMPLATE_NS_ID, "subjectDNs", true);
  3679. this.id = attributes.id || "";
  3680. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  3681. this.use = attributes.use || "";
  3682. this.usehref = attributes.usehref || "";
  3683. this.subjectDN = new _xfa_object.XFAObjectArray();
  3684. }
  3685. }
  3686. class Submit extends _xfa_object.XFAObject {
  3687. constructor(attributes) {
  3688. super(TEMPLATE_NS_ID, "submit", true);
  3689. this.embedPDF = (0, _utils.getInteger)({
  3690. data: attributes.embedPDF,
  3691. defaultValue: 0,
  3692. validate: x => x === 1
  3693. });
  3694. this.format = (0, _utils.getStringOption)(attributes.format, ["xdp", "formdata", "pdf", "urlencoded", "xfd", "xml"]);
  3695. this.id = attributes.id || "";
  3696. this.target = attributes.target || "";
  3697. this.textEncoding = (0, _utils.getKeyword)({
  3698. data: attributes.textEncoding ? attributes.textEncoding.toLowerCase() : "",
  3699. defaultValue: "",
  3700. validate: k => ["utf-8", "big-five", "fontspecific", "gbk", "gb-18030", "gb-2312", "ksc-5601", "none", "shift-jis", "ucs-2", "utf-16"].includes(k) || k.match(/iso-8859-[0-9]{2}/)
  3701. });
  3702. this.use = attributes.use || "";
  3703. this.usehref = attributes.usehref || "";
  3704. this.xdpContent = attributes.xdpContent || "";
  3705. this.encrypt = null;
  3706. this.encryptData = new _xfa_object.XFAObjectArray();
  3707. this.signData = new _xfa_object.XFAObjectArray();
  3708. }
  3709. }
  3710. class Template extends _xfa_object.XFAObject {
  3711. constructor(attributes) {
  3712. super(TEMPLATE_NS_ID, "template", true);
  3713. this.baseProfile = (0, _utils.getStringOption)(attributes.baseProfile, ["full", "interactiveForms"]);
  3714. this.extras = null;
  3715. this.subform = new _xfa_object.XFAObjectArray();
  3716. }
  3717. [_xfa_object.$finalize]() {
  3718. if (this.subform.children.length === 0) {
  3719. (0, _util.warn)("XFA - No subforms in template node.");
  3720. }
  3721. if (this.subform.children.length >= 2) {
  3722. (0, _util.warn)("XFA - Several subforms in template node: please file a bug.");
  3723. }
  3724. this[_xfa_object.$tabIndex] = 1000;
  3725. }
  3726. [_xfa_object.$isSplittable]() {
  3727. return true;
  3728. }
  3729. [_xfa_object.$searchNode](expr, container) {
  3730. if (expr.startsWith("#")) {
  3731. return [this[_xfa_object.$ids].get(expr.slice(1))];
  3732. }
  3733. return (0, _som.searchNode)(this, container, expr, true, true);
  3734. }
  3735. [_xfa_object.$toHTML]() {
  3736. if (!this.subform.children.length) {
  3737. return _utils.HTMLResult.success({
  3738. name: "div",
  3739. children: []
  3740. });
  3741. }
  3742. this[_xfa_object.$extra] = {
  3743. overflowNode: null,
  3744. firstUnsplittable: null,
  3745. currentContentArea: null,
  3746. currentPageArea: null,
  3747. noLayoutFailure: false,
  3748. pageNumber: 1,
  3749. pagePosition: "first",
  3750. oddOrEven: "odd",
  3751. blankOrNotBlank: "nonBlank"
  3752. };
  3753. const root = this.subform.children[0];
  3754. root.pageSet[_xfa_object.$cleanPage]();
  3755. const pageAreas = root.pageSet.pageArea.children;
  3756. const mainHtml = {
  3757. name: "div",
  3758. children: []
  3759. };
  3760. let pageArea = null;
  3761. let breakBefore = null;
  3762. let breakBeforeTarget = null;
  3763. if (root.breakBefore.children.length >= 1) {
  3764. breakBefore = root.breakBefore.children[0];
  3765. breakBeforeTarget = breakBefore.target;
  3766. } else if (root.subform.children.length >= 1 && root.subform.children[0].breakBefore.children.length >= 1) {
  3767. breakBefore = root.subform.children[0].breakBefore.children[0];
  3768. breakBeforeTarget = breakBefore.target;
  3769. } else if (root.break && root.break.beforeTarget) {
  3770. breakBefore = root.break;
  3771. breakBeforeTarget = breakBefore.beforeTarget;
  3772. } else if (root.subform.children.length >= 1 && root.subform.children[0].break && root.subform.children[0].break.beforeTarget) {
  3773. breakBefore = root.subform.children[0].break;
  3774. breakBeforeTarget = breakBefore.beforeTarget;
  3775. }
  3776. if (breakBefore) {
  3777. const target = this[_xfa_object.$searchNode](breakBeforeTarget, breakBefore[_xfa_object.$getParent]());
  3778. if (target instanceof PageArea) {
  3779. pageArea = target;
  3780. breakBefore[_xfa_object.$extra] = {};
  3781. }
  3782. }
  3783. if (!pageArea) {
  3784. pageArea = pageAreas[0];
  3785. }
  3786. pageArea[_xfa_object.$extra] = {
  3787. numberOfUse: 1
  3788. };
  3789. const pageAreaParent = pageArea[_xfa_object.$getParent]();
  3790. pageAreaParent[_xfa_object.$extra] = {
  3791. numberOfUse: 1,
  3792. pageIndex: pageAreaParent.pageArea.children.indexOf(pageArea),
  3793. pageSetIndex: 0
  3794. };
  3795. let targetPageArea;
  3796. let leader = null;
  3797. let trailer = null;
  3798. let hasSomething = true;
  3799. let hasSomethingCounter = 0;
  3800. let startIndex = 0;
  3801. while (true) {
  3802. if (!hasSomething) {
  3803. mainHtml.children.pop();
  3804. if (++hasSomethingCounter === MAX_EMPTY_PAGES) {
  3805. (0, _util.warn)("XFA - Something goes wrong: please file a bug.");
  3806. return mainHtml;
  3807. }
  3808. } else {
  3809. hasSomethingCounter = 0;
  3810. }
  3811. targetPageArea = null;
  3812. this[_xfa_object.$extra].currentPageArea = pageArea;
  3813. const page = pageArea[_xfa_object.$toHTML]().html;
  3814. mainHtml.children.push(page);
  3815. if (leader) {
  3816. this[_xfa_object.$extra].noLayoutFailure = true;
  3817. page.children.push(leader[_xfa_object.$toHTML](pageArea[_xfa_object.$extra].space).html);
  3818. leader = null;
  3819. }
  3820. if (trailer) {
  3821. this[_xfa_object.$extra].noLayoutFailure = true;
  3822. page.children.push(trailer[_xfa_object.$toHTML](pageArea[_xfa_object.$extra].space).html);
  3823. trailer = null;
  3824. }
  3825. const contentAreas = pageArea.contentArea.children;
  3826. const htmlContentAreas = page.children.filter(node => node.attributes.class.includes("xfaContentarea"));
  3827. hasSomething = false;
  3828. this[_xfa_object.$extra].firstUnsplittable = null;
  3829. this[_xfa_object.$extra].noLayoutFailure = false;
  3830. const flush = index => {
  3831. const html = root[_xfa_object.$flushHTML]();
  3832. if (html) {
  3833. hasSomething = hasSomething || html.children && html.children.length !== 0;
  3834. htmlContentAreas[index].children.push(html);
  3835. }
  3836. };
  3837. for (let i = startIndex, ii = contentAreas.length; i < ii; i++) {
  3838. const contentArea = this[_xfa_object.$extra].currentContentArea = contentAreas[i];
  3839. const space = {
  3840. width: contentArea.w,
  3841. height: contentArea.h
  3842. };
  3843. startIndex = 0;
  3844. if (leader) {
  3845. htmlContentAreas[i].children.push(leader[_xfa_object.$toHTML](space).html);
  3846. leader = null;
  3847. }
  3848. if (trailer) {
  3849. htmlContentAreas[i].children.push(trailer[_xfa_object.$toHTML](space).html);
  3850. trailer = null;
  3851. }
  3852. const html = root[_xfa_object.$toHTML](space);
  3853. if (html.success) {
  3854. if (html.html) {
  3855. hasSomething = hasSomething || html.html.children && html.html.children.length !== 0;
  3856. htmlContentAreas[i].children.push(html.html);
  3857. } else if (!hasSomething) {
  3858. mainHtml.children.pop();
  3859. }
  3860. return mainHtml;
  3861. }
  3862. if (html.isBreak()) {
  3863. const node = html.breakNode;
  3864. flush(i);
  3865. if (node.targetType === "auto") {
  3866. continue;
  3867. }
  3868. if (node.leader) {
  3869. leader = this[_xfa_object.$searchNode](node.leader, node[_xfa_object.$getParent]());
  3870. leader = leader ? leader[0] : null;
  3871. }
  3872. if (node.trailer) {
  3873. trailer = this[_xfa_object.$searchNode](node.trailer, node[_xfa_object.$getParent]());
  3874. trailer = trailer ? trailer[0] : null;
  3875. }
  3876. if (node.targetType === "pageArea") {
  3877. targetPageArea = node[_xfa_object.$extra].target;
  3878. i = Infinity;
  3879. } else if (!node[_xfa_object.$extra].target) {
  3880. i = node[_xfa_object.$extra].index;
  3881. } else {
  3882. targetPageArea = node[_xfa_object.$extra].target;
  3883. startIndex = node[_xfa_object.$extra].index + 1;
  3884. i = Infinity;
  3885. }
  3886. continue;
  3887. }
  3888. if (this[_xfa_object.$extra].overflowNode) {
  3889. const node = this[_xfa_object.$extra].overflowNode;
  3890. this[_xfa_object.$extra].overflowNode = null;
  3891. const overflowExtra = node[_xfa_object.$getExtra]();
  3892. const target = overflowExtra.target;
  3893. overflowExtra.addLeader = overflowExtra.leader !== null;
  3894. overflowExtra.addTrailer = overflowExtra.trailer !== null;
  3895. flush(i);
  3896. i = Infinity;
  3897. if (target instanceof PageArea) {
  3898. targetPageArea = target;
  3899. } else if (target instanceof ContentArea) {
  3900. const index = contentAreas.findIndex(e => e === target);
  3901. if (index !== -1) {
  3902. i = index - 1;
  3903. } else {
  3904. targetPageArea = target[_xfa_object.$getParent]();
  3905. startIndex = targetPageArea.contentArea.children.findIndex(e => e === target);
  3906. }
  3907. }
  3908. continue;
  3909. }
  3910. flush(i);
  3911. }
  3912. this[_xfa_object.$extra].pageNumber += 1;
  3913. if (targetPageArea) {
  3914. if (targetPageArea[_xfa_object.$isUsable]()) {
  3915. targetPageArea[_xfa_object.$extra].numberOfUse += 1;
  3916. } else {
  3917. targetPageArea = null;
  3918. }
  3919. }
  3920. pageArea = targetPageArea || pageArea[_xfa_object.$getNextPage]();
  3921. }
  3922. }
  3923. }
  3924. exports.Template = Template;
  3925. class Text extends _xfa_object.ContentObject {
  3926. constructor(attributes) {
  3927. super(TEMPLATE_NS_ID, "text");
  3928. this.id = attributes.id || "";
  3929. this.maxChars = (0, _utils.getInteger)({
  3930. data: attributes.maxChars,
  3931. defaultValue: 0,
  3932. validate: x => x >= 0
  3933. });
  3934. this.name = attributes.name || "";
  3935. this.rid = attributes.rid || "";
  3936. this.use = attributes.use || "";
  3937. this.usehref = attributes.usehref || "";
  3938. }
  3939. [_xfa_object.$acceptWhitespace]() {
  3940. return true;
  3941. }
  3942. [_xfa_object.$onChild](child) {
  3943. if (child[_xfa_object.$namespaceId] === _namespaces.NamespaceIds.xhtml.id) {
  3944. this[_xfa_object.$content] = child;
  3945. return true;
  3946. }
  3947. (0, _util.warn)(`XFA - Invalid content in Text: ${child[_xfa_object.$nodeName]}.`);
  3948. return false;
  3949. }
  3950. [_xfa_object.$onText](str) {
  3951. if (this[_xfa_object.$content] instanceof _xfa_object.XFAObject) {
  3952. return;
  3953. }
  3954. super[_xfa_object.$onText](str);
  3955. }
  3956. [_xfa_object.$toHTML](availableSpace) {
  3957. if (typeof this[_xfa_object.$content] === "string") {
  3958. const html = valueToHtml(this[_xfa_object.$content]).html;
  3959. if (this[_xfa_object.$content].includes("\u2029")) {
  3960. html.name = "div";
  3961. html.children = [];
  3962. this[_xfa_object.$content].split("\u2029").map(para => para.split(/[\u2028\n]/).reduce((acc, line) => {
  3963. acc.push({
  3964. name: "span",
  3965. value: line
  3966. }, {
  3967. name: "br"
  3968. });
  3969. return acc;
  3970. }, [])).forEach(lines => {
  3971. html.children.push({
  3972. name: "p",
  3973. children: lines
  3974. });
  3975. });
  3976. } else if (/[\u2028\n]/.test(this[_xfa_object.$content])) {
  3977. html.name = "div";
  3978. html.children = [];
  3979. this[_xfa_object.$content].split(/[\u2028\n]/).forEach(line => {
  3980. html.children.push({
  3981. name: "span",
  3982. value: line
  3983. }, {
  3984. name: "br"
  3985. });
  3986. });
  3987. }
  3988. return _utils.HTMLResult.success(html);
  3989. }
  3990. return this[_xfa_object.$content][_xfa_object.$toHTML](availableSpace);
  3991. }
  3992. }
  3993. exports.Text = Text;
  3994. class TextEdit extends _xfa_object.XFAObject {
  3995. constructor(attributes) {
  3996. super(TEMPLATE_NS_ID, "textEdit", true);
  3997. this.allowRichText = (0, _utils.getInteger)({
  3998. data: attributes.allowRichText,
  3999. defaultValue: 0,
  4000. validate: x => x === 1
  4001. });
  4002. this.hScrollPolicy = (0, _utils.getStringOption)(attributes.hScrollPolicy, ["auto", "off", "on"]);
  4003. this.id = attributes.id || "";
  4004. this.multiLine = attributes.multiLine || "";
  4005. this.use = attributes.use || "";
  4006. this.usehref = attributes.usehref || "";
  4007. this.vScrollPolicy = (0, _utils.getStringOption)(attributes.vScrollPolicy, ["auto", "off", "on"]);
  4008. this.border = null;
  4009. this.comb = null;
  4010. this.extras = null;
  4011. this.margin = null;
  4012. }
  4013. [_xfa_object.$clean](builder) {
  4014. super[_xfa_object.$clean](builder);
  4015. const parent = this[_xfa_object.$getParent]();
  4016. const defaultValue = parent instanceof Draw ? 1 : 0;
  4017. this.multiLine = (0, _utils.getInteger)({
  4018. data: this.multiLine,
  4019. defaultValue,
  4020. validate: x => x === 0 || x === 1
  4021. });
  4022. }
  4023. [_xfa_object.$toHTML](availableSpace) {
  4024. const style = (0, _html_utils.toStyle)(this, "border", "font", "margin");
  4025. let html;
  4026. const field = this[_xfa_object.$getParent]()[_xfa_object.$getParent]();
  4027. if (this.multiLine === 1) {
  4028. html = {
  4029. name: "textarea",
  4030. attributes: {
  4031. dataId: field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid],
  4032. fieldId: field[_xfa_object.$uid],
  4033. class: ["xfaTextfield"],
  4034. style
  4035. }
  4036. };
  4037. } else {
  4038. html = {
  4039. name: "input",
  4040. attributes: {
  4041. type: "text",
  4042. dataId: field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid],
  4043. fieldId: field[_xfa_object.$uid],
  4044. class: ["xfaTextfield"],
  4045. style
  4046. }
  4047. };
  4048. }
  4049. return _utils.HTMLResult.success({
  4050. name: "label",
  4051. attributes: {
  4052. class: ["xfaLabel"]
  4053. },
  4054. children: [html]
  4055. });
  4056. }
  4057. }
  4058. class Time extends _xfa_object.StringObject {
  4059. constructor(attributes) {
  4060. super(TEMPLATE_NS_ID, "time");
  4061. this.id = attributes.id || "";
  4062. this.name = attributes.name || "";
  4063. this.use = attributes.use || "";
  4064. this.usehref = attributes.usehref || "";
  4065. }
  4066. [_xfa_object.$finalize]() {
  4067. const date = this[_xfa_object.$content].trim();
  4068. this[_xfa_object.$content] = date ? new Date(date) : null;
  4069. }
  4070. [_xfa_object.$toHTML](availableSpace) {
  4071. return valueToHtml(this[_xfa_object.$content] ? this[_xfa_object.$content].toString() : "");
  4072. }
  4073. }
  4074. class TimeStamp extends _xfa_object.XFAObject {
  4075. constructor(attributes) {
  4076. super(TEMPLATE_NS_ID, "timeStamp");
  4077. this.id = attributes.id || "";
  4078. this.server = attributes.server || "";
  4079. this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]);
  4080. this.use = attributes.use || "";
  4081. this.usehref = attributes.usehref || "";
  4082. }
  4083. }
  4084. class ToolTip extends _xfa_object.StringObject {
  4085. constructor(attributes) {
  4086. super(TEMPLATE_NS_ID, "toolTip");
  4087. this.id = attributes.id || "";
  4088. this.rid = attributes.rid || "";
  4089. this.use = attributes.use || "";
  4090. this.usehref = attributes.usehref || "";
  4091. }
  4092. }
  4093. class Traversal extends _xfa_object.XFAObject {
  4094. constructor(attributes) {
  4095. super(TEMPLATE_NS_ID, "traversal", true);
  4096. this.id = attributes.id || "";
  4097. this.use = attributes.use || "";
  4098. this.usehref = attributes.usehref || "";
  4099. this.extras = null;
  4100. this.traverse = new _xfa_object.XFAObjectArray();
  4101. }
  4102. }
  4103. class Traverse extends _xfa_object.XFAObject {
  4104. constructor(attributes) {
  4105. super(TEMPLATE_NS_ID, "traverse", true);
  4106. this.id = attributes.id || "";
  4107. this.operation = (0, _utils.getStringOption)(attributes.operation, ["next", "back", "down", "first", "left", "right", "up"]);
  4108. this.ref = attributes.ref || "";
  4109. this.use = attributes.use || "";
  4110. this.usehref = attributes.usehref || "";
  4111. this.extras = null;
  4112. this.script = null;
  4113. }
  4114. get name() {
  4115. return this.operation;
  4116. }
  4117. [_xfa_object.$isTransparent]() {
  4118. return false;
  4119. }
  4120. }
  4121. class Ui extends _xfa_object.XFAObject {
  4122. constructor(attributes) {
  4123. super(TEMPLATE_NS_ID, "ui", true);
  4124. this.id = attributes.id || "";
  4125. this.use = attributes.use || "";
  4126. this.usehref = attributes.usehref || "";
  4127. this.extras = null;
  4128. this.picture = null;
  4129. this.barcode = null;
  4130. this.button = null;
  4131. this.checkButton = null;
  4132. this.choiceList = null;
  4133. this.dateTimeEdit = null;
  4134. this.defaultUi = null;
  4135. this.imageEdit = null;
  4136. this.numericEdit = null;
  4137. this.passwordEdit = null;
  4138. this.signature = null;
  4139. this.textEdit = null;
  4140. }
  4141. [_xfa_object.$toHTML](availableSpace) {
  4142. for (const name of Object.getOwnPropertyNames(this)) {
  4143. if (name === "extras" || name === "picture") {
  4144. continue;
  4145. }
  4146. const obj = this[name];
  4147. if (!(obj instanceof _xfa_object.XFAObject)) {
  4148. continue;
  4149. }
  4150. return obj[_xfa_object.$toHTML](availableSpace);
  4151. }
  4152. return _utils.HTMLResult.EMPTY;
  4153. }
  4154. }
  4155. class Validate extends _xfa_object.XFAObject {
  4156. constructor(attributes) {
  4157. super(TEMPLATE_NS_ID, "validate", true);
  4158. this.formatTest = (0, _utils.getStringOption)(attributes.formatTest, ["warning", "disabled", "error"]);
  4159. this.id = attributes.id || "";
  4160. this.nullTest = (0, _utils.getStringOption)(attributes.nullTest, ["disabled", "error", "warning"]);
  4161. this.scriptTest = (0, _utils.getStringOption)(attributes.scriptTest, ["error", "disabled", "warning"]);
  4162. this.use = attributes.use || "";
  4163. this.usehref = attributes.usehref || "";
  4164. this.extras = null;
  4165. this.message = null;
  4166. this.picture = null;
  4167. this.script = null;
  4168. }
  4169. }
  4170. class Value extends _xfa_object.XFAObject {
  4171. constructor(attributes) {
  4172. super(TEMPLATE_NS_ID, "value", true);
  4173. this.id = attributes.id || "";
  4174. this.override = (0, _utils.getInteger)({
  4175. data: attributes.override,
  4176. defaultValue: 0,
  4177. validate: x => x === 1
  4178. });
  4179. this.relevant = (0, _utils.getRelevant)(attributes.relevant);
  4180. this.use = attributes.use || "";
  4181. this.usehref = attributes.usehref || "";
  4182. this.arc = null;
  4183. this.boolean = null;
  4184. this.date = null;
  4185. this.dateTime = null;
  4186. this.decimal = null;
  4187. this.exData = null;
  4188. this.float = null;
  4189. this.image = null;
  4190. this.integer = null;
  4191. this.line = null;
  4192. this.rectangle = null;
  4193. this.text = null;
  4194. this.time = null;
  4195. }
  4196. [_xfa_object.$setValue](value) {
  4197. const parent = this[_xfa_object.$getParent]();
  4198. if (parent instanceof Field) {
  4199. if (parent.ui && parent.ui.imageEdit) {
  4200. if (!this.image) {
  4201. this.image = new Image({});
  4202. }
  4203. this.image[_xfa_object.$content] = value[_xfa_object.$content];
  4204. return;
  4205. }
  4206. }
  4207. const valueName = value[_xfa_object.$nodeName];
  4208. if (this[valueName] !== null) {
  4209. this[valueName][_xfa_object.$content] = value[_xfa_object.$content];
  4210. return;
  4211. }
  4212. for (const name of Object.getOwnPropertyNames(this)) {
  4213. const obj = this[name];
  4214. if (obj instanceof _xfa_object.XFAObject) {
  4215. this[name] = null;
  4216. this[_xfa_object.$removeChild](obj);
  4217. }
  4218. }
  4219. this[value[_xfa_object.$nodeName]] = value;
  4220. this[_xfa_object.$appendChild](value);
  4221. }
  4222. [_xfa_object.$text]() {
  4223. if (this.exData) {
  4224. return this.exData[_xfa_object.$content][_xfa_object.$text]().trim();
  4225. }
  4226. for (const name of Object.getOwnPropertyNames(this)) {
  4227. if (name === "image") {
  4228. continue;
  4229. }
  4230. const obj = this[name];
  4231. if (obj instanceof _xfa_object.XFAObject) {
  4232. return (obj[_xfa_object.$content] || "").toString().trim();
  4233. }
  4234. }
  4235. return null;
  4236. }
  4237. [_xfa_object.$toHTML](availableSpace) {
  4238. for (const name of Object.getOwnPropertyNames(this)) {
  4239. const obj = this[name];
  4240. if (!(obj instanceof _xfa_object.XFAObject)) {
  4241. continue;
  4242. }
  4243. return obj[_xfa_object.$toHTML](availableSpace);
  4244. }
  4245. return _utils.HTMLResult.EMPTY;
  4246. }
  4247. }
  4248. exports.Value = Value;
  4249. class Variables extends _xfa_object.XFAObject {
  4250. constructor(attributes) {
  4251. super(TEMPLATE_NS_ID, "variables", true);
  4252. this.id = attributes.id || "";
  4253. this.use = attributes.use || "";
  4254. this.usehref = attributes.usehref || "";
  4255. this.boolean = new _xfa_object.XFAObjectArray();
  4256. this.date = new _xfa_object.XFAObjectArray();
  4257. this.dateTime = new _xfa_object.XFAObjectArray();
  4258. this.decimal = new _xfa_object.XFAObjectArray();
  4259. this.exData = new _xfa_object.XFAObjectArray();
  4260. this.float = new _xfa_object.XFAObjectArray();
  4261. this.image = new _xfa_object.XFAObjectArray();
  4262. this.integer = new _xfa_object.XFAObjectArray();
  4263. this.manifest = new _xfa_object.XFAObjectArray();
  4264. this.script = new _xfa_object.XFAObjectArray();
  4265. this.text = new _xfa_object.XFAObjectArray();
  4266. this.time = new _xfa_object.XFAObjectArray();
  4267. }
  4268. [_xfa_object.$isTransparent]() {
  4269. return true;
  4270. }
  4271. }
  4272. class TemplateNamespace {
  4273. static [_namespaces.$buildXFAObject](name, attributes) {
  4274. if (TemplateNamespace.hasOwnProperty(name)) {
  4275. const node = TemplateNamespace[name](attributes);
  4276. node[_xfa_object.$setSetAttributes](attributes);
  4277. return node;
  4278. }
  4279. return undefined;
  4280. }
  4281. static appearanceFilter(attrs) {
  4282. return new AppearanceFilter(attrs);
  4283. }
  4284. static arc(attrs) {
  4285. return new Arc(attrs);
  4286. }
  4287. static area(attrs) {
  4288. return new Area(attrs);
  4289. }
  4290. static assist(attrs) {
  4291. return new Assist(attrs);
  4292. }
  4293. static barcode(attrs) {
  4294. return new Barcode(attrs);
  4295. }
  4296. static bind(attrs) {
  4297. return new Bind(attrs);
  4298. }
  4299. static bindItems(attrs) {
  4300. return new BindItems(attrs);
  4301. }
  4302. static bookend(attrs) {
  4303. return new Bookend(attrs);
  4304. }
  4305. static boolean(attrs) {
  4306. return new BooleanElement(attrs);
  4307. }
  4308. static border(attrs) {
  4309. return new Border(attrs);
  4310. }
  4311. static break(attrs) {
  4312. return new Break(attrs);
  4313. }
  4314. static breakAfter(attrs) {
  4315. return new BreakAfter(attrs);
  4316. }
  4317. static breakBefore(attrs) {
  4318. return new BreakBefore(attrs);
  4319. }
  4320. static button(attrs) {
  4321. return new Button(attrs);
  4322. }
  4323. static calculate(attrs) {
  4324. return new Calculate(attrs);
  4325. }
  4326. static caption(attrs) {
  4327. return new Caption(attrs);
  4328. }
  4329. static certificate(attrs) {
  4330. return new Certificate(attrs);
  4331. }
  4332. static certificates(attrs) {
  4333. return new Certificates(attrs);
  4334. }
  4335. static checkButton(attrs) {
  4336. return new CheckButton(attrs);
  4337. }
  4338. static choiceList(attrs) {
  4339. return new ChoiceList(attrs);
  4340. }
  4341. static color(attrs) {
  4342. return new Color(attrs);
  4343. }
  4344. static comb(attrs) {
  4345. return new Comb(attrs);
  4346. }
  4347. static connect(attrs) {
  4348. return new Connect(attrs);
  4349. }
  4350. static contentArea(attrs) {
  4351. return new ContentArea(attrs);
  4352. }
  4353. static corner(attrs) {
  4354. return new Corner(attrs);
  4355. }
  4356. static date(attrs) {
  4357. return new DateElement(attrs);
  4358. }
  4359. static dateTime(attrs) {
  4360. return new DateTime(attrs);
  4361. }
  4362. static dateTimeEdit(attrs) {
  4363. return new DateTimeEdit(attrs);
  4364. }
  4365. static decimal(attrs) {
  4366. return new Decimal(attrs);
  4367. }
  4368. static defaultUi(attrs) {
  4369. return new DefaultUi(attrs);
  4370. }
  4371. static desc(attrs) {
  4372. return new Desc(attrs);
  4373. }
  4374. static digestMethod(attrs) {
  4375. return new DigestMethod(attrs);
  4376. }
  4377. static digestMethods(attrs) {
  4378. return new DigestMethods(attrs);
  4379. }
  4380. static draw(attrs) {
  4381. return new Draw(attrs);
  4382. }
  4383. static edge(attrs) {
  4384. return new Edge(attrs);
  4385. }
  4386. static encoding(attrs) {
  4387. return new Encoding(attrs);
  4388. }
  4389. static encodings(attrs) {
  4390. return new Encodings(attrs);
  4391. }
  4392. static encrypt(attrs) {
  4393. return new Encrypt(attrs);
  4394. }
  4395. static encryptData(attrs) {
  4396. return new EncryptData(attrs);
  4397. }
  4398. static encryption(attrs) {
  4399. return new Encryption(attrs);
  4400. }
  4401. static encryptionMethod(attrs) {
  4402. return new EncryptionMethod(attrs);
  4403. }
  4404. static encryptionMethods(attrs) {
  4405. return new EncryptionMethods(attrs);
  4406. }
  4407. static event(attrs) {
  4408. return new Event(attrs);
  4409. }
  4410. static exData(attrs) {
  4411. return new ExData(attrs);
  4412. }
  4413. static exObject(attrs) {
  4414. return new ExObject(attrs);
  4415. }
  4416. static exclGroup(attrs) {
  4417. return new ExclGroup(attrs);
  4418. }
  4419. static execute(attrs) {
  4420. return new Execute(attrs);
  4421. }
  4422. static extras(attrs) {
  4423. return new Extras(attrs);
  4424. }
  4425. static field(attrs) {
  4426. return new Field(attrs);
  4427. }
  4428. static fill(attrs) {
  4429. return new Fill(attrs);
  4430. }
  4431. static filter(attrs) {
  4432. return new Filter(attrs);
  4433. }
  4434. static float(attrs) {
  4435. return new Float(attrs);
  4436. }
  4437. static font(attrs) {
  4438. return new Font(attrs);
  4439. }
  4440. static format(attrs) {
  4441. return new Format(attrs);
  4442. }
  4443. static handler(attrs) {
  4444. return new Handler(attrs);
  4445. }
  4446. static hyphenation(attrs) {
  4447. return new Hyphenation(attrs);
  4448. }
  4449. static image(attrs) {
  4450. return new Image(attrs);
  4451. }
  4452. static imageEdit(attrs) {
  4453. return new ImageEdit(attrs);
  4454. }
  4455. static integer(attrs) {
  4456. return new Integer(attrs);
  4457. }
  4458. static issuers(attrs) {
  4459. return new Issuers(attrs);
  4460. }
  4461. static items(attrs) {
  4462. return new Items(attrs);
  4463. }
  4464. static keep(attrs) {
  4465. return new Keep(attrs);
  4466. }
  4467. static keyUsage(attrs) {
  4468. return new KeyUsage(attrs);
  4469. }
  4470. static line(attrs) {
  4471. return new Line(attrs);
  4472. }
  4473. static linear(attrs) {
  4474. return new Linear(attrs);
  4475. }
  4476. static lockDocument(attrs) {
  4477. return new LockDocument(attrs);
  4478. }
  4479. static manifest(attrs) {
  4480. return new Manifest(attrs);
  4481. }
  4482. static margin(attrs) {
  4483. return new Margin(attrs);
  4484. }
  4485. static mdp(attrs) {
  4486. return new Mdp(attrs);
  4487. }
  4488. static medium(attrs) {
  4489. return new Medium(attrs);
  4490. }
  4491. static message(attrs) {
  4492. return new Message(attrs);
  4493. }
  4494. static numericEdit(attrs) {
  4495. return new NumericEdit(attrs);
  4496. }
  4497. static occur(attrs) {
  4498. return new Occur(attrs);
  4499. }
  4500. static oid(attrs) {
  4501. return new Oid(attrs);
  4502. }
  4503. static oids(attrs) {
  4504. return new Oids(attrs);
  4505. }
  4506. static overflow(attrs) {
  4507. return new Overflow(attrs);
  4508. }
  4509. static pageArea(attrs) {
  4510. return new PageArea(attrs);
  4511. }
  4512. static pageSet(attrs) {
  4513. return new PageSet(attrs);
  4514. }
  4515. static para(attrs) {
  4516. return new Para(attrs);
  4517. }
  4518. static passwordEdit(attrs) {
  4519. return new PasswordEdit(attrs);
  4520. }
  4521. static pattern(attrs) {
  4522. return new Pattern(attrs);
  4523. }
  4524. static picture(attrs) {
  4525. return new Picture(attrs);
  4526. }
  4527. static proto(attrs) {
  4528. return new Proto(attrs);
  4529. }
  4530. static radial(attrs) {
  4531. return new Radial(attrs);
  4532. }
  4533. static reason(attrs) {
  4534. return new Reason(attrs);
  4535. }
  4536. static reasons(attrs) {
  4537. return new Reasons(attrs);
  4538. }
  4539. static rectangle(attrs) {
  4540. return new Rectangle(attrs);
  4541. }
  4542. static ref(attrs) {
  4543. return new RefElement(attrs);
  4544. }
  4545. static script(attrs) {
  4546. return new Script(attrs);
  4547. }
  4548. static setProperty(attrs) {
  4549. return new SetProperty(attrs);
  4550. }
  4551. static signData(attrs) {
  4552. return new SignData(attrs);
  4553. }
  4554. static signature(attrs) {
  4555. return new Signature(attrs);
  4556. }
  4557. static signing(attrs) {
  4558. return new Signing(attrs);
  4559. }
  4560. static solid(attrs) {
  4561. return new Solid(attrs);
  4562. }
  4563. static speak(attrs) {
  4564. return new Speak(attrs);
  4565. }
  4566. static stipple(attrs) {
  4567. return new Stipple(attrs);
  4568. }
  4569. static subform(attrs) {
  4570. return new Subform(attrs);
  4571. }
  4572. static subformSet(attrs) {
  4573. return new SubformSet(attrs);
  4574. }
  4575. static subjectDN(attrs) {
  4576. return new SubjectDN(attrs);
  4577. }
  4578. static subjectDNs(attrs) {
  4579. return new SubjectDNs(attrs);
  4580. }
  4581. static submit(attrs) {
  4582. return new Submit(attrs);
  4583. }
  4584. static template(attrs) {
  4585. return new Template(attrs);
  4586. }
  4587. static text(attrs) {
  4588. return new Text(attrs);
  4589. }
  4590. static textEdit(attrs) {
  4591. return new TextEdit(attrs);
  4592. }
  4593. static time(attrs) {
  4594. return new Time(attrs);
  4595. }
  4596. static timeStamp(attrs) {
  4597. return new TimeStamp(attrs);
  4598. }
  4599. static toolTip(attrs) {
  4600. return new ToolTip(attrs);
  4601. }
  4602. static traversal(attrs) {
  4603. return new Traversal(attrs);
  4604. }
  4605. static traverse(attrs) {
  4606. return new Traverse(attrs);
  4607. }
  4608. static ui(attrs) {
  4609. return new Ui(attrs);
  4610. }
  4611. static validate(attrs) {
  4612. return new Validate(attrs);
  4613. }
  4614. static value(attrs) {
  4615. return new Value(attrs);
  4616. }
  4617. static variables(attrs) {
  4618. return new Variables(attrs);
  4619. }
  4620. }
  4621. exports.TemplateNamespace = TemplateNamespace;