jstd-web/node_modules/saxen/dist/saxen.umd.min.js

2 lines
6.3 KiB
JavaScript
Raw Normal View History

2025-11-25 15:23:22 +08:00
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.Saxen={})}(this,function(e){"use strict";var n=String.fromCharCode,t=Object.prototype.hasOwnProperty,r=/&#(\d+);|&#x([0-9a-f]+);|&(\w+);/gi,i={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'};function s(e,r,s,u){return u?t.call(i,u)?i[u]:"&"+u+";":n(r||parseInt(s,16))}function u(e){return e.length>3&&-1!==e.indexOf("&")?e.replace(r,s):e}Object.keys(i).forEach(function(e){i[e.toUpperCase()]=i[e]});var o="http://www.w3.org/2001/XMLSchema-instance",f="xsi",a="xsi:type",c="non-whitespace outside of root node";function l(e){return new Error(e)}function d(e){return"missing namespace for prefix <"+e+">"}function g(e){return{get:e,enumerable:!0}}function b(e){var n,t={};for(n in e)t[n]=e[n];return t}function h(e){return e+"$uri"}function m(){return{line:0,column:0}}function x(e){throw e}e.Parser=function e(n){if(!this)return new e(n);var t,r,i,s,p,O,v,C,w,A=n&&n.proxy,k=x,y=m,q=!1,j=!1,N=null,E=!1;function M(e){e instanceof Error||(e=l(e)),N=e,k(e,y)}function P(e){p&&(e instanceof Error||(e=l(e)),p(e,y))}this.on=function(e,n){if("function"!=typeof n)throw l("required args <name, cb>");switch(e){case"openTag":r=n;break;case"text":t=n;break;case"closeTag":i=n;break;case"error":k=n;break;case"warn":p=n;break;case"cdata":s=n;break;case"attention":C=n;break;case"question":v=n;break;case"comment":O=n;break;default:throw l("unsupported event: "+e)}return this},this.ns=function(e){if(void 0===e&&(e={}),"object"!=typeof e)throw l("required args <nsMap={}>");var n,t={};for(n in e)t[n]=e[n];return t[o]=f,j=!0,w=t,this},this.parse=function(e){if("string"!=typeof e)throw l("required args <xml=string>");return N=null,function(e){var n,o,f,l,m,x,p,k,N,S,T,_=j?[]:null,D=j?function(e){var n,t,r={};for(n in e)r[t=e[n]]=t,r[h(t)]=n;return r}(w):null,I=[],L=0,U=!1,X=!1,$=0,z=0,B="",F=0;function G(){if(null!==T)return T;var e,n,t,r,i,s,o,f,c,l,g,m=j&&D.xmlns,x=j&&q?[]:null,p=F,O=B,v=O.length,C={},A={};e:for(;p<v;p++)if(c=!1,!(32===(l=O.charCodeAt(p))||l<14&&l>8)){for((l<65||l>122||l>90&&l<97)&&95!==l&&58!==l&&(P("illegal first char attribute name"),c=!0),g=p+1;g<v;g++)if(!((l=O.charCodeAt(g))>96&&l<123||l>64&&l<91||l>47&&l<59||46===l||45===l||95===l)){if(32===l||l<14&&l>8){P("missing attribute value"),p=g;continue e}if(61===l)break;P("illegal attribute name char"),c=!0}if("xmlns:xmlns"===(f=O.substring(p,g))&&(P("illegal declaration of xmlns"),c=!0),34===(l=O.charCodeAt(g+1)))-1===(g=O.indexOf('"',p=g+2))&&-1!==(g=O.indexOf("'",p))&&(P("attribute value quote missmatch"),c=!0);else if(39===l)-1===(g=O.indexOf("'",p=g+2))&&-1!==(g=O.indexOf('"',p))&&(P("attribute value quote missmatch"),c=!0);else for(P("missing attribute value quotes"),c=!0,g+=1;g<v&&!(32===(l=O.charCodeAt(g+1))||l<14&&l>8);g++);for(-1===g&&(P("missing closing quotes"),g=v,c=!0),c||(s=O.substring(p,g)),p=g;g+1<v&&!(32===(l=O.charCodeAt(g+1))||l<14&&l>8);g++)p===g&&(P("illegal character after attribute end"),c=!0);if(p=g+1,!c)if(f in A)P("attribute <"+f+"> already defined");else if(A[f]=!0,j)if(q){if(null!==(i="xmlns"===f?"xmlns":120===f.charCodeAt(0)&&"xmlns:"===f.substr(0,6)?f.substr(6):null)){if(e=u(s),n=h(i),!(o=w[e])){if("xmlns"===i||n in D&&D[n]!==e)do{o="ns"+L++}while(void 0!==D[o]);else o=i;w[e]=o}D[i]!==o&&(r||(D=b(D),r=!0),D[i]=o,"xmlns"===i&&(D[h(o)]=e,m=o),D[n]=e),C[f]=s;continue}x.push(f,s)}else-1!==(l=f.indexOf(":"))?(t=D[f.substring(0,l)])?((f=m===t?f.substr(l+1):t+f.substr(l))===a&&(-1!==(l=s.indexOf(":"))?(t=s.substring(0,l),t=D[t]||t,s=t+s.substring(l)):s=m+":"+s),C[f]=s):P(d(f.substring(0,l))):C[f]=s;else C[f]=s}if(q)for(p=0,v=x.length;p<v;p++){if(f=x[p++],s=x[p],-1!==(l=f.indexOf(":"))){if(!(t=D[f.substring(0,l)])){P(d(f.substring(0,l)));continue}(f=m===t?f.substr(l+1):t+f.substr(l))===a&&(-1!==(l=s.indexOf(":"))?(t=s.substring(0,l),t=D[t]||t,s=t+s.substring(l)):s=m+":"+s)}C[f]=s}return T=C}for(y=function(){for(var n,t,r=/(\r\n|\r|\n)/g,i=0,s=0,u=0,o=z;$>=u&&(n=r.exec(e))&&!((o=n[0].length+n.index)>$);)i+=1,u=o;return-1==$?(s=o,t=e