chromatic
Version:
Automate visual testing across browsers. Gather UI feedback. Versioned documentation.
7 lines (5 loc) • 4.76 kB
JavaScript
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2e2ea7a3-512f-5af5-b5cd-f5f2b61be408")}catch(e){}}();
require(`./chunk-gGpyby2o.cjs`);const e=require(`./from-Y7cUpUgc.cjs`);let t=0;const n={START_BOUNDARY:t++,HEADER_FIELD_START:t++,HEADER_FIELD:t++,HEADER_VALUE_START:t++,HEADER_VALUE:t++,HEADER_VALUE_ALMOST_DONE:t++,HEADERS_ALMOST_DONE:t++,PART_DATA_START:t++,PART_DATA:t++,END:t++};let r=1;const i={PART_BOUNDARY:r,LAST_BOUNDARY:r*=2},a=e=>e|32,o=()=>{};var s=class{constructor(e){this.index=0,this.flags=0,this.onHeaderEnd=o,this.onHeaderField=o,this.onHeadersEnd=o,this.onHeaderValue=o,this.onPartBegin=o,this.onPartData=o,this.onPartEnd=o,this.boundaryChars={},e=`\r
--`+e;let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n),this.boundaryChars[t[n]]=!0;this.boundary=t,this.lookbehind=new Uint8Array(this.boundary.length+8),this.state=n.START_BOUNDARY}write(e){let t=0,r=e.length,o=this.index,{lookbehind:s,boundary:c,boundaryChars:l,index:u,state:d,flags:f}=this,p=this.boundary.length,m=p-1,h=e.length,g,_,v=e=>{this[e+`Mark`]=t},y=e=>{delete this[e+`Mark`]},b=(e,t,n,r)=>{(t===void 0||t!==n)&&this[e](r&&r.subarray(t,n))},x=(n,r)=>{let i=n+`Mark`;i in this&&(r?(b(n,this[i],t,e),delete this[i]):(b(n,this[i],e.length,e),this[i]=0))};for(t=0;t<r;t++)switch(g=e[t],d){case n.START_BOUNDARY:if(u===c.length-2){if(g===45)f|=i.LAST_BOUNDARY;else if(g!==13)return;u++;break}else if(u-1==c.length-2){if(f&i.LAST_BOUNDARY&&g===45)d=n.END,f=0;else if(!(f&i.LAST_BOUNDARY)&&g===10)u=0,b(`onPartBegin`),d=n.HEADER_FIELD_START;else return;break}g!==c[u+2]&&(u=-2),g===c[u+2]&&u++;break;case n.HEADER_FIELD_START:d=n.HEADER_FIELD,v(`onHeaderField`),u=0;case n.HEADER_FIELD:if(g===13){y(`onHeaderField`),d=n.HEADERS_ALMOST_DONE;break}if(u++,g===45)break;if(g===58){if(u===1)return;x(`onHeaderField`,!0),d=n.HEADER_VALUE_START;break}if(_=a(g),_<97||_>122)return;break;case n.HEADER_VALUE_START:if(g===32)break;v(`onHeaderValue`),d=n.HEADER_VALUE;case n.HEADER_VALUE:g===13&&(x(`onHeaderValue`,!0),b(`onHeaderEnd`),d=n.HEADER_VALUE_ALMOST_DONE);break;case n.HEADER_VALUE_ALMOST_DONE:if(g!==10)return;d=n.HEADER_FIELD_START;break;case n.HEADERS_ALMOST_DONE:if(g!==10)return;b(`onHeadersEnd`),d=n.PART_DATA_START;break;case n.PART_DATA_START:d=n.PART_DATA,v(`onPartData`);case n.PART_DATA:if(o=u,u===0){for(t+=m;t<h&&!(e[t]in l);)t+=p;t-=m,g=e[t]}if(u<c.length)c[u]===g?(u===0&&x(`onPartData`,!0),u++):u=0;else if(u===c.length)u++,g===13?f|=i.PART_BOUNDARY:g===45?f|=i.LAST_BOUNDARY:u=0;else if(u-1===c.length)if(f&i.PART_BOUNDARY){if(u=0,g===10){f&=~i.PART_BOUNDARY,b(`onPartEnd`),b(`onPartBegin`),d=n.HEADER_FIELD_START;break}}else f&i.LAST_BOUNDARY&&g===45?(b(`onPartEnd`),d=n.END,f=0):u=0;if(u>0)s[u-1]=g;else if(o>0){let e=new Uint8Array(s.buffer,s.byteOffset,s.byteLength);b(`onPartData`,0,o,e),o=0,v(`onPartData`),t--}break;case n.END:break;default:throw Error(`Unexpected state entered: ${d}`)}x(`onHeaderField`),x(`onHeaderValue`),x(`onPartData`),this.index=u,this.state=d,this.flags=f}end(){if(this.state===n.HEADER_FIELD_START&&this.index===0||this.state===n.PART_DATA&&this.index===this.boundary.length)this.onPartEnd();else if(this.state!==n.END)throw Error(`MultipartParser.end(): stream ended unexpectedly`)}};function c(e){let t=e.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);if(!t)return;let n=t[2]||t[3]||``,r=n.slice(n.lastIndexOf(`\\`)+1);return r=r.replace(/%22/g,`"`),r=r.replace(/&#(\d{4});/g,(e,t)=>String.fromCharCode(t)),r}async function l(t,n){if(!/multipart/i.test(n))throw TypeError(`Failed to fetch`);let r=n.match(/boundary=(?:"([^"]+)"|([^;]+))/i);if(!r)throw TypeError(`no or bad content-type header, no multipart boundary`);let i=new s(r[1]||r[2]),a,o,l,u,d,f,p=[],m=new e.t,h=e=>{l+=y.decode(e,{stream:!0})},g=e=>{p.push(e)},_=()=>{let t=new e.r(p,f,{type:d});m.append(u,t)},v=()=>{m.append(u,l)},y=new TextDecoder(`utf-8`);y.decode(),i.onPartBegin=function(){i.onPartData=h,i.onPartEnd=v,a=``,o=``,l=``,u=``,d=``,f=null,p.length=0},i.onHeaderField=function(e){a+=y.decode(e,{stream:!0})},i.onHeaderValue=function(e){o+=y.decode(e,{stream:!0})},i.onHeaderEnd=function(){if(o+=y.decode(),a=a.toLowerCase(),a===`content-disposition`){let e=o.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);e&&(u=e[2]||e[3]||``),f=c(o),f&&(i.onPartData=g,i.onPartEnd=_)}else a===`content-type`&&(d=o);o=``,a=``};for await(let e of t)i.write(e);return i.end(),m}exports.toFormData=l;
//# sourceMappingURL=multipart-parser-ByXk8gPy.cjs.map
//# debugId=2e2ea7a3-512f-5af5-b5cd-f5f2b61be408