var e=512*1024,t=[`html`,`document`,`slides`,`social`,`app`,`custom`],n=[`fixed`,`responsive`,`paged`],r=[`contain`,`width`,`none`],i=[`neutral`,`transparent`],a=[`three`,`d3`,`motion`],o=new Set([`.html`,`.htm`,`.css`,`.js`,`.mjs`,`.svg`,`.json`,`.txt`,`.md`]),s=/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/,c=/^[a-zA-Z0-9][a-zA-Z0-9._/-]{0,255}$/;function l(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function u(e){return new TextEncoder().encode(JSON.stringify(e)).length}function d(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function f(e){return!(!c.test(e)||e.includes(`..`)||e.includes(`//`)||/^[a-z][a-z0-9+.-]*:/i.test(e))}function p(e){return typeof e==`string`&&e.trim()?e.trim():null}function m(e){let t=Object.entries(e).filter(([e])=>/\.(html?|m?js|css|svg)$/i.test(e)).map(([,e])=>e).join(`
`),n=[];return(/\b(?:window\.)?THREE\b/.test(t)||/\bfrom\s+['"]three(?:\/[^'"]*)?['"]/.test(t))&&n.push(`three`),(/\b(?:window\.)?d3\b/.test(t)||/\bfrom\s+['"]d3(?:\/[^'"]*)?['"]/.test(t))&&n.push(`d3`),(/\b(?:window\.)?Motion\b/.test(t)||/\bmotion\.(?:animate|spring|inView|scroll)\b/.test(t)||/\bfrom\s+['"]motion(?:\/[^'"]*)?['"]/.test(t))&&n.push(`motion`),n}function h(c){let h=[],g=u(c);if(g>524288&&h.push(`Artifact bundle exceeds ${e} bytes`),!l(c))return{ok:!1,errors:[`Artifact bundle must be an object`,...h],byteSize:g};c.schemaVersion!==1&&h.push(`schemaVersion must be 1`);let _=p(c.artifactId);(!_||!s.test(_))&&h.push(`artifactId must be a stable alphanumeric id`);let v=p(c.title);v||h.push(`title is required`);let y=p(c.kind);(!y||!t.includes(y))&&h.push(`kind must be one of: ${t.join(`, `)}`);let b=c.viewport,x=null;if(!l(b))h.push(`viewport is required`);else{let e=b.width,t=b.height,r=b.mode;(typeof e!=`number`||!Number.isFinite(e)||e<120||e>1e4)&&h.push(`viewport.width must be between 120 and 10000`),(typeof t!=`number`||!Number.isFinite(t)||t<120||t>1e4)&&h.push(`viewport.height must be between 120 and 10000`),(typeof r!=`string`||!n.includes(r))&&h.push(`viewport.mode must be one of: ${n.join(`, `)}`),typeof e==`number`&&typeof t==`number`&&typeof r==`string`&&(x={width:Math.round(e),height:Math.round(t),mode:r})}let S=p(c.entrypoint);(!S||!f(S))&&h.push(`entrypoint must be a safe relative file path`);let C=c.files,w={};if(!l(C))h.push(`files must be an object of text file paths to string contents`);else{let e=Object.entries(C);e.length===0&&h.push(`files must contain at least one file`);for(let[t,n]of e){if(!f(t)){h.push(`file path "${t}" must be a safe relative path`);continue}let e=d(t);if(o.has(e)||h.push(`file "${t}" must be a supported text file`),typeof n!=`string`){h.push(`file "${t}" must be a string`);continue}w[t]=n}}S&&!Object.prototype.hasOwnProperty.call(w,S)&&h.push(`entrypoint must exist in files`);let T=new Set;if(c.libraries!==void 0)if(!Array.isArray(c.libraries))h.push(`libraries must be an array when provided`);else for(let e of c.libraries){if(typeof e!=`string`||!a.includes(e)){h.push(`libraries must contain only: ${a.join(`, `)}`);continue}T.add(e)}let E;if(c.display!==void 0)if(!l(c.display))h.push(`display must be an object when provided`);else{if(E={},c.display.fullscreenFit!==void 0&&(typeof c.display.fullscreenFit!=`string`||!r.includes(c.display.fullscreenFit)?h.push(`display.fullscreenFit must be one of: ${r.join(`, `)}`):E.fullscreenFit=c.display.fullscreenFit),c.display.background!==void 0&&(typeof c.display.background!=`string`||!i.includes(c.display.background)?h.push(`display.background must be one of: ${i.join(`, `)}`):E.background=c.display.background),c.display.fullscreenViewport!==void 0)if(!l(c.display.fullscreenViewport))h.push(`display.fullscreenViewport must be an object when provided`);else{let e=c.display.fullscreenViewport.width,t=c.display.fullscreenViewport.height;(typeof e!=`number`||!Number.isFinite(e)||e<120||e>1e4)&&h.push(`display.fullscreenViewport.width must be between 120 and 10000`),(typeof t!=`number`||!Number.isFinite(t)||t<120||t>1e4)&&h.push(`display.fullscreenViewport.height must be between 120 and 10000`),typeof e==`number`&&typeof t==`number`&&(E.fullscreenViewport={width:Math.round(e),height:Math.round(t)})}if(c.display.controls!==void 0)if(!l(c.display.controls))h.push(`display.controls must be an object when provided`);else{let e={},t=!1;if(c.display.controls.stepper!==void 0)if(!l(c.display.controls.stepper))h.push(`display.controls.stepper must be an object when provided`);else{let n={};if(c.display.controls.stepper.selector!==void 0){let e=p(c.display.controls.stepper.selector);!e||e.length>180?h.push(`display.controls.stepper.selector must be a non-empty string up to 180 characters`):n.selector=e}if(c.display.controls.stepper.label!==void 0){let e=p(c.display.controls.stepper.label);!e||e.length>40?h.push(`display.controls.stepper.label must be a non-empty string up to 40 characters`):n.label=e}e.stepper=n,t=!0}c.display.controls.reset!==void 0&&(typeof c.display.controls.reset==`boolean`?(e.reset=c.display.controls.reset,t=!0):h.push(`display.controls.reset must be a boolean when provided`)),t&&(E.controls=e)}Object.keys(E).length===0&&(E=void 0)}let D;if(c.source!==void 0)if(!l(c.source))h.push(`source must be an object when provided`);else{D={};for(let e of[`repo`,`entityType`,`entityId`,`skillId`])if(c.source[e]!==void 0){let t=p(c.source[e]);t?D[e]=t:h.push(`source.${e} must be a non-empty string`)}}if(h.length>0||!_||!v||!y||!S||!x)return{ok:!1,errors:h,byteSize:g};let O=Array.from(new Set([...T,...m(w)]));return{ok:!0,errors:[],byteSize:g,bundle:{schemaVersion:1,artifactId:_,title:v,kind:y,viewport:x,...E?{display:E}:{},...O.length>0?{libraries:O}:{},files:w,entrypoint:S,...D?{source:D}:{}}}}export{h as t};