mark-js
Version:
Mark, an unified notation for all
2 lines (1 loc) • 23.1 kB
JavaScript
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){const $parent=Symbol.for("Mark.parent"),$length=Symbol.for("Mark.length");let MarkMutate=function(Mark,pushFunc){let api={push:pushFunc,pop:function(){let length=this[$length];if(length>0){let item=this[length-1];delete this[length-1];this[$length]=length-1;return item}else{return undefined}},splice(index,cnt){if(cnt<0){cnt=0}let len=newlen=this[$length];if(index<0){index=0}else if(index>len){index=len}cnt=Math.min(cnt,len-index);let trailing=len-(index+cnt);if(cnt){for(let i=index;i<index+cnt;i++){delete this[i]}newlen-=cnt}if(arguments.length>2||trailing){let items=Mark("Object");for(let i=2;i<arguments.length;i++){items.push(arguments[i])}if(trailing){for(let i=0;i<trailing;i++){items.push(this[index+cnt+i])}}let extra=Mark.lengthOf(items);if(extra){let i=0;newlen=index+extra;if(typeof items[0]==="string"&&index-1>=0&&typeof this[index-1]==="string"){this[index-1]=this[index-1]+items[0];i++;index--;newlen--}for(;i<extra;i++){Object.defineProperty(this,index+i,{value:items[i],writable:true,configurable:true});if(typeof items[i]==="object"){this[index+i][$parent]=this}}}}if(newlen<len){for(let i=0;i<len-newlen;i++){delete this[newlen+i]}}this[$length]=newlen;return this},set:function(key,value){var index;if(typeof key==="string"){if(isNaN(key*1)){this[key]=value;return this}index=key*1}else if(typeof key==="number"){index=Math.round(key)}else{return this}this.splice(index,1,value);return this}};for(let a in api){Object.defineProperty(Mark.prototype,a,{value:api[a],writable:true,configurable:true})}};module.exports=MarkMutate},{}],2:[function(require,module,exports){"use strict";const $length=Symbol.for("Mark.length"),_length=Symbol.for("Mark.length-property"),$parent=Symbol.for("Mark.parent"),$isList=Symbol.for("Mark.is-list"),$encoding=Symbol.for("Mark.encoding");const ws=[" ","\t","\r","\n"];let $convert=null,$ctrs={};let MARK=function(){function push(val){let len=this[$length];let t=typeof val;if(t==="string"){if(!val.length)return this;let prevType=len?typeof this[len-1]:null;if(prevType==="string"){len--;val=this[len]+val}}else if(t==="object"){if(val===null)return this;else if(val instanceof Array){if(val[$isList]){for(let v of val){push.call(this,v)}return this}}val[$parent]=this}else if(t==="undefined"){return this}else{}Object.defineProperty(this,len,{value:val,writable:true,configurable:true});this[$length]=len+1;for(let i=1;i<arguments.length;i++){push.call(this,arguments[i])}return this}function Mark(typeName,props,contents){if(arguments.length===1){let char=typeName[0];if(char==="<"||char==="{"||char==="["||char==="("){return MARK.parse(typeName)}else if(!isNameStart(char)){throw"Invalid element name: "+typeName}}if(typeof typeName!=="string"){if(this instanceof Mark){this[$length]=0;return}throw"Type name should be a string"}let con=$ctrs[typeName];if(!con){con=$ctrs[typeName]=function(){};Object.defineProperty(con,"name",{value:typeName,configurable:true});Object.setPrototypeOf(con.prototype,Mark.prototype)}let obj=Object.create(con.prototype);if(props){for(let p in props){if(isNaN(p*1)){obj[p]=props[p]}}}obj[$length]=0;if(contents){if(contents instanceof Array)contents[$isList]=true;push.call(obj,contents)}return obj}let api={contents:function(){let list=[];for(let c of this){list.push(c)}return list},parent:function(pa){return this[$parent]},source:function(options){return MARK.stringify(this,options)},text:function(){let txt=[];let _text=function(obj){for(let n of obj){if(typeof n==="string"){txt.push(n)}else if(n.constructor){_text(n)}}};_text(this);return txt.join("")},html:function(options){let opt=options||{};opt.format="html";return MARK.stringify(this,opt)},xml:function(options){let opt=options||{};opt.format="xml";return MARK.stringify(this,opt)}};let ap=Array.prototype;function wrapped(obj){return Object.create(obj,{length:{value:obj[$length]}})}for(let f of[ap.filter,ap.map,ap.reduce,ap.every,ap.some,ap.forEach,ap.includes,ap.indexOf,ap.lastIndexOf,ap.slice]){api[f.name]=function(){return f.apply(this[_length]!==null?wrapped(this):this,arguments)}}api["each"]=api.forEach;for(let func in api){Object.defineProperty(Mark.prototype,func,{value:api[func],writable:true,configurable:true})}let desc={set:function(value){this[_length]=value;let enumDesc=Object.assign({},desc);enumDesc.enumerable=true;Object.defineProperty(this,"length",enumDesc)},get:function(){return this[_length]!==undefined?this[_length]:this[$length]},configurable:true};Object.defineProperty(Mark.prototype,"length",desc);Mark.prototype[Symbol.iterator]=function*(){let length=this[$length];for(let i=0;i<length;i++){yield this[i]}};Mark.lengthOf=function(obj){return obj==null?null:obj[$length]!==undefined?obj[$length]:obj.length};Mark.parent=function(obj){return obj?obj[Symbol.for("Mark.parent")]:null};Mark.list=function(items){items[$isList]=true;return items};try{require("./lib/mark.selector.js")(Mark)}catch(e){console.trace("No Mark Selector API",e.message)}try{require("./lib/mark.mutate.js")(Mark,push)}catch(e){Object.defineProperty(Mark.prototype,"push",{value:push,writable:true,configurable:true});console.trace("No Mark Mutate API",e.message)}return Mark}();function isNameChar(c){return"a"<=c&&c<="z"||"A"<=c&&c<="Z"||"0"<=c&&c<="9"||c==="_"||c==="$"||c==="."||c==="-"}function isNameStart(c){return"a"<=c&&c<="z"||"A"<=c&&c<="Z"||c==="_"||c==="$"}MARK.isName=function(key){if(typeof key!=="string"){return false}if(!isNameStart(key[0])){return false}var i=1,length=key.length;while(i<length){if(!isNameChar(key[i])){return false}i++}return true};const base64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";MARK.parse=function(){"use strict";let UNEXPECT_END="Unexpected end of input",UNEXPECT_CHAR="Unexpected character ";let at,lineNumber,columnStart,ch,text,escapee={"'":"'",'"':'"',"\\":"\\","/":"/","\n":"",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},renderChar=function(chr){return chr===""?"EOF":"'"+chr+"'"},error=function(m){var columnNumber=at-columnStart;var msg=m+" at line "+lineNumber+" column "+columnNumber+" of the Mark data. Still to read: "+JSON.stringify(text.substring(at-1,at+30)+"...");var error=new SyntaxError(msg);error.at=at;error.lineNumber=lineNumber;error.columnNumber=columnNumber;throw error},next=function(c){if(c&&c!==ch){error("Expected '"+c+"' instead of "+renderChar(ch))}ch=text.charAt(at);at++;if(ch==="\n"||ch==="\r"&&text[at]!=="\n"){lineNumber++;columnStart=at}return ch},identifier=function(){var key=ch;if(ch!=="_"&&ch!=="$"&&(ch<"a"||ch>"z")&&(ch<"A"||ch>"Z")){error(UNEXPECT_CHAR+renderChar(ch))}while(next()&&("a"<=ch&&ch<="z"||"A"<=ch&&ch<="Z"||"0"<=ch&&ch<="9"||ch==="_"||ch==="$")){key+=ch}return key},number=function(){let number,sign="",string="";if(ch==="-"||ch==="+"){sign=ch;next(ch)}if(ch==="i"||ch==="n"){number=word();if(typeof number!=="number"){error("Invalid number")}return sign==="-"?-number:number}if(ch==="0"){string+=ch;next()}else{while(ch>="0"&&ch<="9"){string+=ch;next()}if(ch==="."){string+=".";while(next()&&ch>="0"&&ch<="9"){string+=ch}}if(string===""){error("Invalid number")}if(ch==="n"||ch==="N"){next();return BigInt(string)}else if(ch==="e"||ch==="E"){string+=ch;next();if(ch==="-"||ch==="+"){string+=ch;next()}while(ch>="0"&&ch<="9"){string+=ch;next()}}}if(sign==="-"){number=-string}else{number=+string}return number},_string=function(){var hex,i,string="",delim,uffff;if(ch==='"'||ch==="'"){delim=ch;while(next()){if(ch===delim){next();return string.length?string:null}if(ch==="\\"){next();if(ch==="u"){uffff=0;for(i=0;i<4;i+=1){hex=parseInt(next(),16);if(!isFinite(hex)){break}uffff=uffff*16+hex}string+=String.fromCharCode(uffff)}else if(ch==="\r"){if(text[at]==="\n"){next()}}else if(typeof escapee[ch]==="string"){string+=escapee[ch]}else{break}}else{string+=ch}}}error("Bad string")},string=_string,symbol=function(){let str=_string();return str?Symbol.for(str):null},inlineComment=function(){if(ch!=="/"){error("Not an inline comment")}do{next();if(ch==="\n"||ch==="\r"){next();return}}while(ch)},blockComment=function(){if(ch!=="*"){error("Not a block comment")}do{next();while(ch==="*"){next();if(ch==="/"){next();return}}if(ch==="/"&&text[at]==="*"){next();blockComment()}}while(ch);error("Unterminated block comment")},comment=function(){if(ch!=="/"){error("Not a comment")}next("/");if(ch==="/"){inlineComment()}else if(ch==="*"){blockComment()}else{error("Unrecognized comment")}},white=function(){while(ch){if(ch==="/"){comment()}else if(ws.indexOf(ch)>=0){next()}else{return}}},isSuffix=function(suffix){let len=suffix.length;for(let i=0;i<len;i++){if(text[at+i]!==suffix[i]){return false}}if(isNameStart(text[at+len])){return false}ch=text[at+len];at+=len+1;return true},word=function(){switch(ch){case"b":if(text[at]==="'"){return binary()}break;case"f":if(isSuffix("alse")){return false}break;case"i":if(isSuffix("nf")){return Infinity}break;case"t":if(text[at]==="'"){return datetime()}if(isSuffix("rue")){return true}break;case"n":if(isSuffix("ull")){return null}if(isSuffix("an")){return NaN}break}return identifier()},datetime=function(){at++;next();let start=at-1;let end=text.indexOf("'",start);if(end<0){error("Missing closing quote for datetime")}let dtStr=text.slice(start,end).trim();let timePattern="\\d{2}(?:[:.]\\d{2}(?:[:.]\\d{2}(?:\\.\\d{3})?)?)?";let dtRegex=new RegExp(`^(?:(\\d{4}(?:-\\d{2}(?:-\\d{2})?)?)(?:(?:[Tt]|\\s+)(${timePattern})?)?|(${timePattern}))(?:[zZ]|[+-]\\d{2}:?\\d{2})?$`);let match=dtRegex.exec(dtStr);if(!match){error("Invalid datetime format: "+dtStr)}let datePart=match[1];let datetimeTimePart=match[2];let timeOnlyPart=match[3];let dateOnly=datePart&&!datetimeTimePart&&!timeOnlyPart;let timeOnly=!datePart&&timeOnlyPart;at=end+1;next();let normalizedStr=dtStr;normalizedStr=normalizedStr.replace(/(\d{4}-\d{2}-\d{2})(?:[Tt]|\s+)(\d{2})/,"$1T$2");normalizedStr=normalizedStr.replace(/^(\d{2})([zZ]|[+-]\d{2}:?\d{2})?$/,(match,hour,tz)=>{return hour+":00"+(tz||"")});normalizedStr=normalizedStr.replace(/T(\d{2})([zZ]|[+-]\d{2}:?\d{2})?$/,(match,hour,tz)=>{return"T"+hour+":00"+(tz||"")});normalizedStr=normalizedStr.replace(/([+-])(\d{2})(\d{2})$/,"$1$2:$3");if(timeOnly){normalizedStr="2000-01-01"+"T"+normalizedStr}if(dateOnly){normalizedStr+="T00:00:00"}try{console.log("Parsing datetime: ",normalizedStr);let dateObj=new Date(normalizedStr);if(isNaN(dateObj.getTime())){error("Invalid datetime value: "+dtStr)}dateObj.timeOnly=timeOnly;dateObj.dateOnly=dateOnly;return dateObj}catch(e){error("Invalid datetime: "+e.message)}},value,listPush=function(list,val){let t=typeof val;if(t==="string"){if(!val.length)return;let prevType=list.length?typeof list[list.length-1]:null;if(prevType==="string"){list[list.length-1]+=val;return}}else if(t==="object"){if(val===null)return;else if(val instanceof Array){if(val[$isList]){for(let v of val){listPush(list,v)}return}}val[$parent]=list}else if(t==="undefined"){return}list.push(val)},array=function(){let array=[];let delim=ch==="["?"]":")";next();white();if(ch===delim){next();return delim===")"?null:array}while(ch){let v=value();if(delim===")"){listPush(array,v);console.log("Pushed to list:",v)}else{array.push(v)}if(ch===","){next();white()}else if(ch===delim){next();if(delim===")"){console.log("Parsed list:",array);if(array.length===0){return null}else if(array.length===1){return array[0]}array[$isList]=true}return array}else{error(UNEXPECT_CHAR+renderChar(ch))}}},list=array;let lookup64=new Uint8Array(128);lookup64.fill(65);for(var i=0;i<64;i++){lookup64[base64.charCodeAt(i)]=i}lookup64[32]=lookup64[9]=lookup64[13]=lookup64[10]=64;let binary=function(){at++;if(text[at]!=="\\"){error("Expect '\\'")}at++;if(text[at]==="x"){at++;let end=text.indexOf("'",at),bufEnd=end;if(end<0){error("Missing hex end delimiter")}let hex=new Uint8Array(new ArrayBuffer(bufEnd-at)),p=0;while(at<bufEnd){let code=text.charCodeAt(at);if(code===32||code===9||code===13||code===10){at++;continue}if(code>=48&&code<=57){hex[p++]=code-48}else if(code>=65&&code<=70){hex[p++]=code-55}else if(code>=97&&code<=102){hex[p++]=code-87}else{error("Invalid hex character: "+renderChar(text[at]))}at++}at=end+1;next();if(p%2!==0){error("Invalid hex stream length")}let len=p/2,code1,code2,buffer=new ArrayBuffer(len),bytes=new Uint8Array(buffer);if(len==0){return null}for(let i=0,p=0;p<len;i+=2){code1=hex[i];code2=hex[i+1];if(code1>15||code2>15){error("Invalid hex character")}bytes[p++]=code1<<4|code2}buffer[$encoding]="hex";return buffer}else if(text[at]==="6"&&text[at+1]==="4"){at+=2;let end=text.indexOf("'",at),bufEnd=end,pad=0;if(end<0){error("Missing base64 end delimiter")}if(text[bufEnd-1]==="="){bufEnd--;pad=1;if(text[bufEnd-1]==="="){bufEnd--;pad=2}}let base=new Uint8Array(new ArrayBuffer(bufEnd-at)),p=0;while(at<bufEnd){let code=lookup64[text.charCodeAt(at)];if(code>64){error("Invalid base64 character")}if(code<64){base[p++]=code}at++}at=end+1;next();console.log("base64 char length: ",p,pad);if(pad&&(p+pad)%4!=0||!pad&&p%4==1){error("Invalid base64 stream length")}let len=Math.floor(p*.75),code1,code2,code3,code4,buffer=new ArrayBuffer(len),bytes=new Uint8Array(buffer);if(len==0){return null}for(let i=0,p=0;p<len;i+=4){code1=base[i];code2=base[i+1];code3=base[i+2];code4=base[i+3];bytes[p++]=code1<<2|code2>>4;bytes[p++]=(code2&15)<<4|code3>>2;bytes[p++]=(code3&3)<<6|code4&63}buffer[$encoding]="b64";return buffer}else{error("Invalid binary value")}};let object=function(){let obj,key=null,extended=false,index=0;let putText=function(text){if(index>0&&typeof obj[index-1]==="string"){obj[index-1]+=text}else{Object.defineProperty(obj,index,{value:text,writable:true,configurable:true});index++}},parseContent=function(){while(ch){let needLB=false;if(ch==="<"||ch==="{"){let child=object(obj);Object.defineProperty(obj,index,{value:child,writable:true,configurable:true});child[$parent]=obj;index++}else if(ch==="("||ch==="["){let child=array();if(child){Object.defineProperty(obj,index,{value:child,writable:true,configurable:true});if(typeof child==="object")child[$parent]=obj;index++}needLB=true}else if(ch==='"'){let str=string();if(str)putText(str);needLB=false}else if(ch===">"){next();obj[$length]=index;return}else{let val=value();if(val!=null){Object.defineProperty(obj,index,{value:val,writable:true,configurable:true});index++}needLB=true}if(!needLB){white();if(ch==='"'||ch==="{"||ch==="<"){continue}}while(ch===" "&&ch==="\t"){next()}if(ch===";"||ch==="\n"||ch==="\r"&&text[at]==="\n"){next();white()}else if(ch===">"){}else error(UNEXPECT_CHAR+renderChar(ch))}error(UNEXPECT_END)};let delim=ch==="{"?"}":">";if(ch==="<"){extended=true;delim=">"}else{delim="}"}next();white();if(extended){let ident=ch==="'"?string():identifier();white();obj=MARK(ident,null,null)}else{obj={}}if(ch===delim){next();if(extended){obj[$length]=index}return obj}while(ch){let isSymbol=false,str="";if(ch==='"'||ch==="'"){isSymbol=ch==="'";str=string()}else if(isNameStart(ch)){str=identifier();isSymbol=true}else{if(extended){parseContent();return obj}error(UNEXPECT_CHAR+renderChar(ch))}let hasLB=false;while(ch===" "||ch==="\t"){next()}if(ch==="\n"||ch==="\r"&&text[at]==="\n"){next();white();hasLB=true}if(ch===":"){if(!str){error("Empty key not allowed")}key=str;next()}else{if(extended){if(str){if(isSymbol){Object.defineProperty(obj,index,{value:Symbol.for(str),writable:true,configurable:true});index++;if(ch===";"){next();white()}else if(!hasLB&&ch!==delim){error(UNEXPECT_CHAR+renderChar(ch))}}else{putText(str);if(ch===";"){next();white()}else if(!hasLB&&(ch!=='"'&&ch!=="<"&&ch!=="{"&&ch!==delim)){error(UNEXPECT_CHAR+renderChar(ch))}}}else{error(`Empty ${isSymbol?"symbol":"text"} not allowed`)}parseContent();return obj}error(UNEXPECT_CHAR+renderChar(ch))}var val=value();if(extended&&!isNaN(key*1)){error("Numeric key not allowed as Mark property name")}if(obj[key]&&typeof obj[key]!=="function"){error("Duplicate key not allowed: "+key)}obj[key]=val;hasLB=false;while(ch===" "||ch==="\t"){next()}if(ch==="\n"||ch==="\r"&&text[at]==="\n"){next();white();hasLB=true}if(ch===","){next();white();if(ch===delim){error(UNEXPECT_CHAR+renderChar(ch))}}else if(ch===";"){next();white();parseContent();return obj}else if(ch===delim){next();if(extended){obj[$length]=index}return obj}else if(hasLB){parseContent();return obj}else{error(UNEXPECT_CHAR+renderChar(ch))}}error(UNEXPECT_END)};value=function(){white();switch(ch){case"{":case"<":return object();case"[":return array();case"(":return list();case'"':return string();case"'":return symbol();case"-":case"+":case".":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return number();default:let w=word();return typeof w==="string"?Symbol.for(w):w}};let scanLineBreak=function(){if(ch===";"||ch==="\n"||ch==="\r"&&text[at]==="\n"){next();white();return true}return false};return function(source,options){at=0;lineNumber=1;columnStart=at;ch=" ";text=String(source);if(!source){return null}if(typeof options==="object"&&options.format&&options.format!="mark"){if(!$convert){$convert=require("./lib/mark.convert.js")(MARK)}return $convert.parse(source,options)}let result=[];white();if(!ch){return null}do{let val=value();while(ch===" "||ch==="\t"){next()}if(val!=null){result.push(val);if(typeof val==="object"){if(!(val instanceof Date)||val instanceof ArrayBuffer||Array.isArray(val)){continue}}else if(typeof val==="string"){if(ch==='"'||ch==="<"||ch==="{"){continue}}if(!scanLineBreak()){if(ch)error("Expect ';' or line break")}}}while(ch);if(result.length===0){result=null}else if(result.length===1){result=result[0]}return result}}();MARK.stringify=function(obj,options){"use strict";let indentStep,indentStrs,space;function indent(num,noNewLine){if(num>=indentStrs.length){for(var i=indentStrs.length;i<=num;i++){indentStrs[i]=indentStrs[i-1]+indentStep}}return noNewLine?indentStrs[num]:"\n"+indentStrs[num]}if(options){space=options.space;indentStrs=[""];if(space){if(typeof space==="string"){indentStep=space}else if(typeof space==="number"&&space>=0){indentStep=new Array(space+1).join(" ")}else{indentStep=""}if(indentStep&&indentStep.length>10){indentStep=indentStep.substring(0,10)}}if(options.format&&options.format!=="mark"){if(!$convert){$convert=require("./lib/mark.convert.js")(MARK)}$convert.indent=indent;if(options.format==="xml"||options.format==="html")return $convert.toSgml(obj,options);else return null}}function isDate(obj){return Object.prototype.toString.call(obj)==="[object Date]"}var objStack=[];function checkForCircular(obj){for(var i=0;i<objStack.length;i++){if(objStack[i]===obj){throw new TypeError("Got circular reference")}}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};function escapeString(string,isSymbol=false){escapable.lastIndex=0;let delim=isSymbol?"'":'"';return escapable.test(string)?delim+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+delim:delim+string+delim}function _stringify(value){let buffer;if(value&&!isDate(value)){value=value.valueOf()}switch(typeof value){case"boolean":return value.toString();case"number":if(isNaN(value)){return"nan"}else if(!isFinite(value)){return value>0?"inf":"-inf"}return value.toString();case"bigint":return value.toString()+"n";case"string":return escapeString(value.toString());case"symbol":return escapeString(Symbol.keyFor(value),true);case"object":if(value===null){return"null"}else if(Array.isArray(value)){checkForCircular(value);buffer=value[$isList]?"(":"[";objStack.push(value);for(var i=0;i<value.length;i++){let res=_stringify(value[i]);if(indentStep)buffer+=indent(objStack.length);if(res===null||res===undefined){buffer+="null"}else{buffer+=res}if(i<value.length-1){buffer+=", "}else if(indentStep){buffer+="\n"}}objStack.pop();if(value.length&&indentStep){buffer+=indent(objStack.length,true)}buffer+=value[$isList]?")":"]"}else if(value instanceof ArrayBuffer){buffer="b'";if(value[$encoding]==="hex"){buffer+="\\x";let bytes=new Uint8Array(value),i,len=bytes.length;for(i=0;i<len;i++){buffer+=(bytes[i]>>4).toString(16)+(bytes[i]&15).toString(16)}}else{buffer+="\\64";let bytes=new Uint8Array(value),i,fullLen=bytes.length,len=fullLen-fullLen%3;for(i=0;i<len;i+=3){buffer+=base64[bytes[i]>>2];buffer+=base64[(bytes[i]&3)<<4|bytes[i+1]>>4];buffer+=base64[(bytes[i+1]&15)<<2|bytes[i+2]>>6];buffer+=base64[bytes[i+2]&63]}if(fullLen%3){buffer+=base64[bytes[i]>>2]+base64[(bytes[i]&3)<<4|bytes[i+1]>>4]+(fullLen%3===2?base64[(bytes[i+1]&15)<<2]:"=")+"="}}buffer+="'"}else if(value instanceof Date){if(value.timeOnly){buffer="t'"+value.toTimeString().split(" ")[0]+"'"}else if(value.dateOnly){buffer="t'"+value.toISOString().split("T")[0]+"'"}else{buffer="t'"+value.toISOString().replace("T"," ")+"'"}}else{checkForCircular(value);let nonEmpty=false,isElement=false;objStack.push(value);if(value.constructor.name!=="Object"||value instanceof MARK){buffer="<"+value.constructor.name;isElement=true;nonEmpty=true}else{buffer="{"}let hasAttr=false;for(var prop in value){let res=_stringify(value[prop]);if(res!==undefined){let key=MARK.isName(prop)?prop:escapeString(prop,true);buffer+=(hasAttr?", ":nonEmpty?" ":"")+key+":"+res;hasAttr=true;nonEmpty=true}}let length=value[$length];if(length){if(hasAttr){buffer+=";"}for(let i=0;i<length;i++){buffer+=" ";let item=value[i];switch(typeof item){case"string":if(indentStep)buffer+=indent(objStack.length);buffer+=escapeString(item.toString());break;case"symbol":if(indentStep)buffer+=indent(objStack.length);buffer+=escapeString(Symbol.keyFor(item),true);break;case"object":if(indentStep)buffer+=indent(objStack.length);buffer+=_stringify(item);break;case"number":if(indentStep)buffer+=indent(objStack.length);if(isNaN(item)){buffer+="nan"}else if(!isFinite(item)){buffer+=item>0?"inf":"-inf"}else{buffer+=item.toString()}break;case"boolean":if(indentStep)buffer+=indent(objStack.length);buffer+=item.toString();break;default:console.log("Unknown content object",item)}}}objStack.pop();if(nonEmpty){if(length&&indentStep){buffer+=indent(objStack.length)}}buffer+=isElement?">":"}"}return buffer;default:return undefined}}if(obj===undefined){return undefined}return _stringify(obj)};module.exports=MARK;if(typeof window!=="undefined"){window.Mark=MARK}},{"./lib/mark.convert.js":"/lib/mark.convert.js","./lib/mark.mutate.js":1,"./lib/mark.selector.js":"/lib/mark.selector.js"}]},{},[2]);