@gentbajko/slopify 3.2.2 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -101,7 +101,7 @@ Error generating stack: `+e.message+`
101
101
  Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}e.external&&(e.sharedDefsExtractedFor=e.external)}function uE(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;uE(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var dE=new Set([`type`,`properties`,`required`,`additionalProperties`]),fE=[`oneOf`,`anyOf`];function pE(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function mE(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!dE.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??pE(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}aC(n,r,e.length===1?e[0]:mE(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=pE(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function hE(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of dE)if(t in e)return;let n=t.filter(e=>fE.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=mE(t);else{let e=n[0],i=fE.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>mE([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,iE(e,r))}function gE(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):iE(i,s),iE(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())uE(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])hE(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}iE(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,aC(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:yE(t,`input`,e.processors),output:yE(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function _E(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return _E(r.element,n);if(r.type===`set`)return _E(r.valueType,n);if(r.type===`lazy`)return _E(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return _E(r.innerType,n);if(r.type===`intersection`)return _E(r.left,n)||_E(r.right,n);if(r.type===`record`||r.type===`map`)return _E(r.keyType,n)||_E(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:_E(r.in,n)||_E(r.out,n);if(r.type===`object`){for(let e in r.shape)if(_E(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(_E(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(_E(e,n))return!0;return!!(r.rest&&_E(r.rest,n))}return!1}var vE=(e,t={})=>n=>{let r=aE({...n,processors:t});return sE(e,r),lE(r,e),gE(r,e)},yE=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=aE({...i??{},target:a,io:t,processors:n});return sE(e,o),lE(o,e),gE(o,e)},bE={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},xE=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=bE[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},SE=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;i.type=typeof s==`string`&&s.includes(`int`)?`integer`:`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(Number.isFinite(c)&&c!==0?i.multipleOf=Math.abs(c):oE(e,t,i,r,`A multipleOf divisor of ${c} cannot be represented in JSON Schema`))},CE=(e,t,n,r)=>{n.type=`boolean`},wE=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},TE=(e,t,n,r)=>{n.not={}},EE=(e,t,n,r)=>{let i=e._zod.def,a=QS(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},DE=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(oE(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(oE(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},OE=(e,t,n,r)=>{oE(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},kE=(e,t,n,r)=>{oE(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},AE=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=sE(a.element,t,{...r,path:[...r.path,`items`]})};function jE(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?jE(t.out):t.type===`catch`?jE(t.innerType):e._zod.optin}var ME=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&oE(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)aC(i.properties,e,sE(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e];return t.io===`input`?jE(n)===void 0:n._zod.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=sE(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},NE=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>sE(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},PE=(e,t,n,r)=>{let i=e._zod.def,a=sE(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=sE(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},FE=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>sE(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?sE(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null,u=a.items.length;for(;u>0;){let e=a.items[u-1];if(!(t.io===`input`?jE(e)!==void 0:e._zod.optout===`optional`))break;u--}let d=a.items.length,f=!a.rest;t.target===`draft-2020-12`?(i.prefixItems=c,f?i.items=!1:l&&(i.items=l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):(i.items=c,f?i.additionalItems=!1:l&&(i.additionalItems=l),u>0&&(i.minItems=u),f&&(i.maxItems=d));let{minimum:p,maximum:m}=e._zod.bag;typeof p==`number`&&(i.minItems=p),typeof m==`number`&&(i.maxItems=m)};function IE(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=IE(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>IE(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?rT:nT).source),p):p}var LE=new WeakMap;function RE(e){let t=new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=new Map;for(let r of LE.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=IE(t,a,new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}var zE=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=sE(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)aC(i.patternProperties,t.source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=sE(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=LE.get(t);n||(n=[],LE.set(t,n),t.deferred.push(()=>RE(t))),n.push(e)}i.additionalProperties=sE(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&jE(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},BE=(e,t,n,r)=>{let i=e._zod.def,a=sE(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},VE=(e,t,n,r)=>{let i=e._zod.def;sE(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},HE=Symbol();function UE(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(oE(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),HE):JSON.parse(o)}var WE=(e,t,n,r)=>{let i=e._zod.def;sE(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=UE(i.defaultValue,e,t,n,r);o!==HE&&(n.default=o)},GE=(e,t,n,r)=>{let i=e._zod.def;sE(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=UE(i.defaultValue,e,t,n,r);o!==HE&&(n._prefault=o)},KE=(e,t,n,r)=>{let i=e._zod.def;sE(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{oE(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},qE=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;sE(o,t,r);let s=t.seen.get(e);s.ref=o},JE=(e,t,n,r)=>{let i=e._zod.def;sE(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},YE=(e,t,n,r)=>{let i=e._zod.def;sE(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},XE=new WeakSet([Object.prototype,Error.prototype]);function ZE(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var QE=U(`ZodError`,(e,t)=>{fw.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);XE.has(n)||(XE.add(n),ZE(n,`format`,e=>t=>gw(e,t)),ZE(n,`flatten`,e=>t=>hw(e,t)),ZE(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,eC,2)}),ZE(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,eC,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),$E=vw(QE),eD=yw(QE),tD=bw(QE),nD=Sw(QE),rD=ww(QE),iD=Tw(QE),aD=Ew(QE),oD=Dw(QE),sD=Ow(QE),cD=kw(QE),lD=Aw(QE),uD=jw(QE);function dD(){rw.localeError||iw(Gne())}function fD(){rw.memoizer||iw({memoizer:Hne()})}var pD=U(`ZodType`,(e,t)=>(dD(),uT.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(oC(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return gC(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(FO(e,t))},superRefine(e,t){return this.check(IO(e,t))},overwrite(e){return this.check(rE(e))},optional(){return _O(this)},exactOptional(){return yO(this)},nullable(){return xO(this)},nullish(){return _O(xO(this))},nonoptional(e){return DO(this,e)},array(){return K(this)},or(e){return tO([this,e])},and(e){return aO(this,e)},transform(e){return jO(this,hO(e))},default(e){return CO(this,e)},prefault(e){return TO(this,e)},catch(e){return kO(this,e)},pipe(e){return jO(this,e)},readonly(){return NO(this)},describe(e){let t=this.clone();return KT.add(t,{description:e}),t},meta(...e){if(e.length===0)return KT.get(this);let t=this.clone();return KT.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return VC(this,`~standard`,{...fT(this),jsonSchema:{input:yE(this,`input`),output:yE(this,`output`)}})},set"~standard"(e){BC(this,`~standard`,e)},parse:function e(t,n){return $E(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await eD(this,t,n,{callee:e})},safeParse(e,t){return tD(this,e,t)},async safeParseAsync(e,t){return nD(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){BC(this,`spa`,e)},encode:function e(t,n){return rD(this,t,n,{callee:e})},decode:function e(t,n){return iD(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await aD(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await oD(this,t,n,{callee:e})},safeEncode(e,t){return sD(this,e,t)},safeDecode(e,t){return cD(this,e,t)},async safeEncodeAsync(e,t){return lD(this,e,t)},async safeDecodeAsync(e,t){return uD(this,e,t)},toJSONSchema(e){return vE(this,{})(e)},get description(){return KT.get(this)?.description},get _def(){return this._zod.def}}),mD=U(`_ZodString`,(e,t)=>{pT.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xE(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null},{regex(...e){return this.check(Tre(...e))},includes(...e){return this.check(Ore(...e))},startsWith(...e){return this.check(kre(...e))},endsWith(...e){return this.check(Are(...e))},min(...e){return this.check(tE(...e))},max(...e){return this.check(eE(...e))},length(...e){return this.check(nE(...e))},nonempty(...e){return this.check(tE(1,...e))},lowercase(e){return this.check(Ere(e))},uppercase(e){return this.check(Dre(e))},trim(){return this.check(Mre())},normalize(...e){return this.check(jre(...e))},toLowerCase(){return this.check(Nre())},toUpperCase(){return this.check(Pre())},slugify(){return this.check(Fre())}}),hD=U(`ZodString`,(e,t)=>{pT.init(e,t),mD.init(e,t)},{email(e){return this.check(Yne(xD,e))},url(e){return this.check(ere(TD,e))},jwt(e){return this.check(hre(BD,e))},emoji(e){return this.check(tre(ED,e))},guid(e){return this.check(Xne(SD,e))},uuid(e){return this.check(qT(CD,e))},uuidv4(e){return this.check(Zne(CD,e))},uuidv6(e){return this.check(Qne(CD,e))},uuidv7(e){return this.check($ne(CD,e))},nanoid(e){return this.check(nre(DD,e))},cuid(e){return this.check(rre(OD,e))},cuid2(e){return this.check(ire(kD,e))},ulid(e){return this.check(are(AD,e))},base64(e){return this.check(fre(LD,e))},base64url(e){return this.check(pre(RD,e))},xid(e){return this.check(ore(jD,e))},ksuid(e){return this.check(sre(MD,e))},ipv4(e){return this.check(cre(ND,e))},ipv6(e){return this.check(lre(PD,e))},cidrv4(e){return this.check(ure(FD,e))},cidrv6(e){return this.check(dre(ID,e))},e164(e){return this.check(mre(zD,e))},datetime(e){return this.check(JT(_D,e))},date(e){return this.check(gre(vD,e))},time(e){return this.check(_re(yD,e))},duration(e){return this.check(vre(bD,e))}});function W(e){return Jne(hD,e)}var gD=U(`ZodStringFormat`,(e,t)=>{mT.init(e,t),mD.init(e,t)}),_D=U(`ZodISODateTime`,(e,t)=>{Qte.init(e,t),gD.init(e,t)}),vD=U(`ZodISODate`,(e,t)=>{$te.init(e,t),gD.init(e,t)}),yD=U(`ZodISOTime`,(e,t)=>{ene.init(e,t),gD.init(e,t)}),bD=U(`ZodISODuration`,(e,t)=>{tne.init(e,t),gD.init(e,t)}),xD=U(`ZodEmail`,(e,t)=>{Rte.init(e,t),gD.init(e,t)}),SD=U(`ZodGUID`,(e,t)=>{Ite.init(e,t),gD.init(e,t)}),CD=U(`ZodUUID`,(e,t)=>{Lte.init(e,t),gD.init(e,t)});function wD(e){return qT(CD,e)}var TD=U(`ZodURL`,(e,t)=>{Wte.init(e,t),gD.init(e,t)}),ED=U(`ZodEmoji`,(e,t)=>{Gte.init(e,t),gD.init(e,t)}),DD=U(`ZodNanoID`,(e,t)=>{Kte.init(e,t),gD.init(e,t)}),OD=U(`ZodCUID`,(e,t)=>{qte.init(e,t),gD.init(e,t)}),kD=U(`ZodCUID2`,(e,t)=>{Jte.init(e,t),gD.init(e,t)}),AD=U(`ZodULID`,(e,t)=>{Yte.init(e,t),gD.init(e,t)}),jD=U(`ZodXID`,(e,t)=>{Xte.init(e,t),gD.init(e,t)}),MD=U(`ZodKSUID`,(e,t)=>{Zte.init(e,t),gD.init(e,t)}),ND=U(`ZodIPv4`,(e,t)=>{nne.init(e,t),gD.init(e,t)}),PD=U(`ZodIPv6`,(e,t)=>{ine.init(e,t),gD.init(e,t)}),FD=U(`ZodCIDRv4`,(e,t)=>{ane.init(e,t),gD.init(e,t)}),ID=U(`ZodCIDRv6`,(e,t)=>{sne.init(e,t),gD.init(e,t)}),LD=U(`ZodBase64`,(e,t)=>{cne.init(e,t),gD.init(e,t)}),RD=U(`ZodBase64URL`,(e,t)=>{une.init(e,t),gD.init(e,t)}),zD=U(`ZodE164`,(e,t)=>{dne.init(e,t),gD.init(e,t)}),BD=U(`ZodJWT`,(e,t)=>{pne.init(e,t),gD.init(e,t)}),VD=U(`ZodNumber`,(e,t)=>{_T.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>SE(e,t,n,r);let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null},{gt(e,t){return this.check(ZT(e,t))},gte(e,t){return this.check(QT(e,t))},min(e,t){return this.check(QT(e,t))},lt(e,t){return this.check(YT(e,t))},lte(e,t){return this.check(XT(e,t))},max(e,t){return this.check(XT(e,t))},int(e){return this.check(UD(e))},safe(e){return this.check(UD(e))},positive(e){return this.check(ZT(0,e))},nonnegative(e){return this.check(QT(0,e))},negative(e){return this.check(YT(0,e))},nonpositive(e){return this.check(XT(0,e))},multipleOf(e,t){return this.check($T(e,t))},step(e,t){return this.check($T(e,t))},finite(){return this}});function G(e){return yre(VD,e)}var HD=U(`ZodNumberFormat`,(e,t)=>{mne.init(e,t),VD.init(e,t)});function UD(e){return bre(HD,e)}var WD=U(`ZodBoolean`,(e,t)=>{hne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>CE(e,t,n,r)});function GD(e){return xre(WD,e)}var KD=U(`ZodNull`,(e,t)=>{gne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wE(e,t,n,r)});function qD(e){return Sre(KD,e)}var JD=U(`ZodUnknown`,(e,t)=>{_ne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function YD(){return Cre(JD)}var XD=U(`ZodNever`,(e,t)=>{vne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>TE(e,t,n,r)});function ZD(e){return wre(XD,e)}var QD=U(`ZodArray`,(e,t)=>{fD(),yne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>AE(e,t,n,r),e.element=t.element},{min(e,t){return this.check(tE(e,t))},nonempty(e){return this.check(tE(1,e))},max(e,t){return this.check(eE(e,t))},length(e,t){return this.check(nE(e,t))},unwrap(){return this.element}});function K(e,t){return Ire(QD,e,t)}var $D=U(`ZodObject`,(e,t)=>{fD(),Sne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ME(e,t,n,r),JC(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return J(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:YD()})},loose(){return this.clone({...this._zod.def,catchall:YD()})},strict(){return this.clone({...this._zod.def,catchall:ZD()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return CC(this,e)},safeExtend(e){return wC(this,e)},merge(e){return TC(this,e)},pick(e){return xC(this,e)},omit(e){return SC(this,e)},partial(...e){return EC(gO,this,e[0])},exactPartial(...e){return EC(vO,this,e[0],`exactPartial`)},required(...e){return DC(EO,this,e[0])}});function q(e,t){return new $D({type:`object`,shape:e??{},..._C(t)})}var eO=U(`ZodUnion`,(e,t)=>{wT.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>NE(e,t,n,r),e.options=t.options});function tO(e,t){return new eO({type:`union`,options:e,..._C(t)})}var nO=U(`ZodDiscriminatedUnion`,(e,t)=>{eO.init(e,t),Cne.init(e,t)});function rO(e,t,n){return new nO({type:`union`,options:t,discriminator:e,..._C(n)})}var iO=U(`ZodIntersection`,(e,t)=>{wne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>PE(e,t,n,r)});function aO(e,t){return new iO({type:`intersection`,left:e,right:t})}var oO=U(`ZodTuple`,(e,t)=>{fD(),Tne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>FE(e,t,n,r)},{rest(e){return this.clone({...this._zod.def,rest:e})},partial(){let e=this._zod.def;if(e.checks?.length)throw Error(`.partial() cannot be used on tuple schemas containing refinements`);return this.clone({...e,items:e.items.map(e=>new gO({type:`optional`,innerType:e}))})}});function sO(e,t,n){let r=t instanceof uT;return new oO({type:`tuple`,items:e,rest:r?t:null,..._C(r?n:t)})}var cO=U(`ZodRecord`,(e,t)=>{fD(),Ene.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zE(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function lO(e,t,n){return!t||!t._zod?new cO({type:`record`,keyType:W(),valueType:e,..._C(t)}):new cO({type:`record`,keyType:e,valueType:t,..._C(n)})}function uO(e,t,n){return new cO({type:`record`,keyType:e,valueType:t,..._C(n),partial:!0})}var dO=U(`ZodEnum`,(e,t)=>{Dne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>EE(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new dO({...t,checks:[],..._C(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new dO({...t,checks:[],..._C(r),entries:i})}});function J(e,t){return new dO({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,..._C(t)})}var fO=U(`ZodLiteral`,(e,t)=>{One.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>DE(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function pO(e,t){return new fO({type:`literal`,values:Array.isArray(e)?e:[e],..._C(t)})}var mO=U(`ZodTransform`,(e,t)=>{fD(),kne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>kE(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new nw(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(RC(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(RC(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function hO(e){return new mO({type:`transform`,transform:e})}var gO=U(`ZodOptional`,(e,t)=>{jT.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>YE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function _O(e){return new gO({type:`optional`,innerType:e})}var vO=U(`ZodExactOptional`,(e,t)=>{Ane.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>YE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yO(e){return new vO({type:`optional`,innerType:e})}var bO=U(`ZodNullable`,(e,t)=>{jne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>BE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function xO(e){return new bO({type:`nullable`,innerType:e})}var SO=U(`ZodDefault`,(e,t)=>{Mne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>WE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function CO(e,t){return new SO({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():pC(t)}})}var wO=U(`ZodPrefault`,(e,t)=>{Nne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>GE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function TO(e,t){return new wO({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():pC(t)}})}var EO=U(`ZodNonOptional`,(e,t)=>{Pne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>VE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function DO(e,t){return new EO({type:`nonoptional`,innerType:e,..._C(t)})}var OO=U(`ZodCatch`,(e,t)=>{Fne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>KE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function kO(e,t){return new OO({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:XC(t)})}var AO=U(`ZodPipe`,(e,t)=>{Ine.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qE(e,t,n,r),e.in=t.in,e.out=t.out});function jO(e,t){return new AO({type:`pipe`,in:e,out:t})}var MO=U(`ZodReadonly`,(e,t)=>{Lne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>JE(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function NO(e){return new MO({type:`readonly`,innerType:e})}var PO=U(`ZodCustom`,(e,t)=>{Rne.init(e,t),pD.init(e,t),e._zod.processJSONSchema=(t,n,r)=>OE(e,t,n,r)});function FO(e,t={}){return Lre(PO,e,t)}function IO(e,t){return Rre(e,t)}function LO(e){return JT(_D,e)}var RO=[{code:`en`,name:`English`,native:`English`,script:`latin`,timing:`english`},{code:`es`,name:`Spanish`,native:`Español`,script:`latin`,timing:`multilingual`},{code:`de`,name:`German`,native:`Deutsch`,script:`latin`,timing:`multilingual`},{code:`fr`,name:`French`,native:`Français`,script:`latin`,timing:`multilingual`},{code:`it`,name:`Italian`,native:`Italiano`,script:`latin`,timing:`multilingual`},{code:`pt`,name:`Portuguese`,native:`Português`,script:`latin`,timing:`multilingual`},{code:`nl`,name:`Dutch`,native:`Nederlands`,script:`latin`,timing:`multilingual`},{code:`ca`,name:`Catalan`,native:`Català`,script:`latin`,timing:`multilingual`},{code:`pl`,name:`Polish`,native:`Polski`,script:`latin`,timing:`multilingual`},{code:`cs`,name:`Czech`,native:`Čeština`,script:`latin`,timing:`multilingual`},{code:`ro`,name:`Romanian`,native:`Română`,script:`latin`,timing:`sentences`},{code:`sv`,name:`Swedish`,native:`Svenska`,script:`latin`,timing:`sentences`},{code:`da`,name:`Danish`,native:`Dansk`,script:`latin`,timing:`sentences`},{code:`nb`,name:`Norwegian`,native:`Norsk bokmål`,script:`latin`,timing:`sentences`},{code:`fi`,name:`Finnish`,native:`Suomi`,script:`latin`,timing:`sentences`},{code:`hu`,name:`Hungarian`,native:`Magyar`,script:`latin`,timing:`sentences`},{code:`tr`,name:`Turkish`,native:`Türkçe`,script:`latin`,timing:`sentences`},{code:`id`,name:`Indonesian`,native:`Bahasa Indonesia`,script:`latin`,timing:`sentences`},{code:`vi`,name:`Vietnamese`,native:`Tiếng Việt`,script:`latin`,timing:`sentences`},{code:`el`,name:`Greek`,native:`Ελληνικά`,script:`greek`,timing:`sentences`},{code:`ru`,name:`Russian`,native:`Русский`,script:`cyrillic`,timing:`sentences`},{code:`uk`,name:`Ukrainian`,native:`Українська`,script:`cyrillic`,timing:`sentences`},{code:`ar`,name:`Arabic`,native:`العربية`,script:`arabic`,timing:`sentences`},{code:`he`,name:`Hebrew`,native:`עברית`,script:`hebrew`,timing:`sentences`},{code:`hi`,name:`Hindi`,native:`हिन्दी`,script:`devanagari`,timing:`sentences`},{code:`th`,name:`Thai`,native:`ไทย`,script:`thai`,timing:`sentences`},{code:`ja`,name:`Japanese`,native:`日本語`,script:`cjk`,timing:`sentences`},{code:`zh`,name:`Chinese`,native:`中文`,script:`cjk`,timing:`sentences`},{code:`ko`,name:`Korean`,native:`한국어`,script:`hangul`,timing:`sentences`}],zO=J(RO.map(e=>e.code));function BO(e){return RO.find(t=>t.code===(e??`en`))??RO[0]}function VO(e){let t=BO(e);if(t.timing===`sentences`)return`Word timing isn't available for ${t.name} yet, so captions are timed sentence by sentence: each sentence is shown for the part of the narration that reads it. Word-by-word captions and cuts that follow the narration need word timing and are off.`}var HO=[`off`,`low`,`medium`,`high`,`xhigh`,`max`,`ultra`],UO=60/240,WO=1e5,GO=1500;function KO(e){return e.imageScale===void 0?60:240}function qO(e){return e.split(/\s+/).filter(e=>e!==``).length}function JO(e){return e/150}function YO(e){return Math.round(60/e*1e4)/1e4}function XO(e){let t=60/e.perHour,n=Math.round(t*4);return Math.abs(t*4-n)<.001?{every:`minutes`,value:String(n/4)}:{every:`hour`,value:String(e.perHour)}}function ZO(e){let t=JO(e.words)*e.perHour/60;return Math.min(Math.max(Math.ceil(t-1e-9),0),240)}function QO(e){return e.imageScale!==void 0&&e.sources.images===`generate`}function $O(e){let t=e.imagePrompts.map(e=>e.number);if(!QO(e)||t.length===0)return t;let n=t.reduce((e,t)=>e+t,0),r=ZO(e.imageScale)-n;for(let e=0;e<r;e+=1){let n=e%t.length;t[n]=(t[n]??0)+1}return t}function ek(e){if(!Number.isFinite(e.perHour)||e.perHour<1||e.perHour>240)return`Enter between 1 and 240 images per hour (one every ${String(UO)} to 60 minutes) under Images → More images for long videos.`;if(!Number.isInteger(e.words)||e.words<1||e.words>1e5)return`Enter the expected words (Review) as a whole number between 1 and ${String(WO)}; the image count for long videos is planned from it.`}var tk={enabled:!0,videoLufs:-14,audioFilesLufs:-18},nk=-1.5,rk=.5;function ik(e){return e===`video`?-14:-18}function ak(e){return e===`video`?nk:-3}function ok(e,t){return gk(e-ik(t),2)}function sk(e,t){return gk(ik(t)+e,2)}function ck(e){return Math.round(10**(e/20)*100)}function lk(e){return gk(20*Math.log10(e/100),2)}function uk(e){if(!Number.isFinite(e))return;let t=Math.round(e/rk)*rk;return Math.min(4,Math.max(-10,t))}function dk(e,t){let n=e-ik(t);return Number.isFinite(n)&&Number.isInteger(gk(n/.5,6))&&n>=-10.000000001&&n<=4.000000001?void 0:`The volume must be between -10 dB and +4 dB of the recommended level, in steps of ${String(rk)} dB. Change it under Level the volume (Play → Video and style, Edit project → Pauses and volume, or Settings → General).`}function fk(e){if(e===void 0)return[];let t=[],n=dk(e.videoLufs,`video`);n!==void 0&&t.push({field:`loudness.videoLufs`,message:n});let r=dk(e.audioFilesLufs,`audioFiles`);return r!==void 0&&t.push({field:`loudness.audioFilesLufs`,message:r}),t}function pk(e,t){if(e?.enabled??t.enabled)return{videoLufs:e?.videoLufs??t.videoLufs,audioFilesLufs:e?.audioFilesLufs??t.audioFilesLufs}}function mk(e){let t=`${String(e.pieces)} ${e.pieces===1?`piece`:`pieces`}`,n=e.skipped===0?``:` (${String(e.skipped)} too short or quiet to measure, left as they were)`;return`Levelled ${t} to ${_k(e.target)} LUFS${n}: the spread was ${_k(e.spreadBefore)} LU, now ${_k(e.spreadAfter)} LU.`}function hk(e){return`Mastered to ${_k(e.target)} LUFS: measured ${_k(e.integrated)} LUFS, peaks ${_k(e.truePeak)} dBTP`}function gk(e,t){let n=10**t;return Math.round(e*n)/n}function _k(e){return String(gk(e,1)).replace(`-`,`−`)}var vk=.4,yk=.05;function bk(e,t){let n=e/yk;return Number.isFinite(e)&&e>=0&&e<=2&&Math.abs(n-Math.round(n))<1e-6?void 0:`The pause between ${t} must be between 0 and 2 seconds, in steps of ${String(yk)}. Change it under Play → Video and style, or Edit project → Pauses and volume.`}function xk(e){let t=[];if(e.sentencePauseSeconds!==void 0){let n=bk(e.sentencePauseSeconds,`sentences`);n!==void 0&&t.push({field:`sentencePauseSeconds`,message:n})}if(e.paragraphPauseSeconds!==void 0){let n=bk(e.paragraphPauseSeconds,`paragraphs`);n!==void 0&&t.push({field:`paragraphPauseSeconds`,message:n})}return t}function Sk(e){let t=(e,t)=>e===void 0||e.trim()===``?t:Number(e.trim().replace(`,`,`.`)),n=t(e.sentencePause,vk),r=t(e.paragraphPause,0);return{...n===0?{}:{sentencePauseSeconds:n},...r===0?{}:{paragraphPauseSeconds:r}}}var Ck=[`article`,`images`,`narration`,`thumbnail`,`shorts`],wk=[`off`,`flag`,`redo`],Tk={article:`Article`,images:`Images`,narration:`Narration`,thumbnail:`Thumbnail`,shorts:`Shorts`},Ek={off:`Off`,flag:`Flag only`,redo:`Flag and redo`},Dk=[`images`,`thumbnail`,`shorts`],Ok=[`claude-code`,`codex`];function kk(e,t){return e?.stages[t]?.mode??`off`}function Ak(e){return`review.${e}`}function jk(e){return{provider:e.provider,model:e.model,...e.thinking===void 0?{}:{thinking:e.thinking},retries:e.retries===void 0?``:String(e.retries),stages:Object.fromEntries(Ck.flatMap(t=>{let n=e.stages[t];return n===void 0?[]:[[t,{mode:n.mode,prompt:n.prompt??``}]]}))}}function Mk(e,t){let n=Object.fromEntries(Ck.flatMap(n=>{let r=e.stages[n];return r===void 0||r.mode===`off`||!t(n)?[]:[[n,{mode:r.mode,...r.prompt.trim()?{prompt:r.prompt}:{}}]]}));if(Object.keys(n).length===0)return{settings:void 0};let r=e.retries.trim()===``?void 0:Number(e.retries),i=r===void 0||Number.isFinite(r);return{settings:{provider:e.provider,model:e.model,...e.thinking===void 0?{}:{thinking:e.thinking},...r===void 0||!i?{}:{retries:r},stages:n},...i?{}:{retriesProblem:`Enter a number of redos between 0 and 5 in the Reviews section.`}}}function Nk(e,t){let{sources:n}=e;switch(t){case`article`:return n.article===`generate`;case`images`:return n.images===`generate`;case`narration`:return n.audio===`generate`;case`thumbnail`:return n.thumbnail===`from_prompt`||n.thumbnail===`prompt_by_llm`;case`shorts`:return e.shorts?.enabled===!0&&n.audio!==`off`}}function Pk(e){return Ck.filter(t=>kk(e.reviews,t)!==`off`&&Nk(e,t))}function Fk(e){return Ok.includes(e)}function Ik(e){let t=Pk(e),n=e.reviews;if(t.length===0||n===void 0)return[];let r=[];(n.provider.trim()===``||n.model.trim()===``)&&r.push({field:`reviews.provider`,message:`Automatic reviews need a reviewer model. Choose one in the Reviews section, or set every review to Off.`});let i=n.retries;i!==void 0&&(!Number.isInteger(i)||i<0||i>5)&&r.push({field:`reviews.retries`,message:`Enter a number of redos between 0 and 5 in the Reviews section.`});let a=t.filter(e=>Dk.includes(e));return a.length>0&&n.provider.trim()!==``&&!Fk(n.provider)&&r.push({field:`reviews.provider`,message:`The ${a.map(e=>Tk[e]).join(`, `)} ${a.length===1?`review looks`:`reviews look`} at pictures, and Slopify can't show pictures to this reviewer. In the Reviews section, choose Claude Code or Codex as the reviewer, or set ${a.length===1?`that review`:`those reviews`} to Off.`}),r}var Lk={enabled:!1,count:3,minSeconds:60,maxSeconds:120,titleOnScreen:!0},Rk=1.25,zk=.05,Bk=2e3,Vk=`[PASTE THE FULL VIDEO LINK HERE]`;function Hk(e){let t=e?.trim()??``;return`Watch the full video: ${t===``?Vk:t}`}function Uk(e,t){return[e.title,``,`${e.description}\n${Hk(t)}`,``,e.hashtags.join(` `)].join(`
102
102
  `)}var Wk=`Built-in`,Gk=[`Pick the moments of this video that work best as vertical shorts on YouTube Shorts, TikTok and Reels.`,``,`- Each short must make sense on its own, to a viewer who has not seen the rest of the video: no references to earlier parts, no setup that pays off outside the clip.`,`- Open on a hook: the first sentence should make someone stop scrolling (a surprising fact, a question, a bold claim). Skip clips that start with filler or a transition.`,`- End on a complete thought, not mid-argument.`,`- Prefer the most surprising, useful or emotional moments over summaries, and don't pick two shorts that say the same thing.`,`- Title: at most 60 characters, plain words, no clickbait and no hashtags.`,`- Description: one line that says what the viewer learns or feels.`,`- Hashtags: 3-5, about the subject of that clip, most specific last.`].join(`
103
103
  `);[`Vertical 9:16 images for a short video. Each image illustrates what is being said at that moment of the clip.`,`Cinematic, high-contrast and uncluttered, with the subject large and centred so it reads on a phone screen.`,`Leave the lower half calm: captions are drawn over the middle of the frame.`,`No text, letters, logos or watermarks in the image.`].join(`
104
- `);function Kk(e,t){return!Number.isFinite(e)||!Number.isFinite(t)||t<=0?1:Math.max(1,Math.ceil(e/t-.001))}function qk(e){let t=e=>e===void 0||e.trim()===``?void 0:Number(e),n=t(e.musicVolume),r=t(e.speed),i=e.fullVideoLink?.trim()??``;return{...e.titleOnScreen===void 0?{}:{titleOnScreen:e.titleOnScreen},...i===``?{}:{fullVideoLink:i},...n===void 0?{}:{musicVolume:n},...r===void 0?{}:{speed:r}}}function Jk(e){return{...e?.titleOnScreen===void 0?{}:{titleOnScreen:e.titleOnScreen},...e?.fullVideoLink===void 0?{}:{fullVideoLink:e.fullVideoLink},...e?.musicVolume===void 0?{}:{musicVolume:String(e.musicVolume)},...e?.speed===void 0?{}:{speed:e.speed.toFixed(2)}}}function Yk(e){let t=[],n=(e,t,n)=>Number.isInteger(e)&&e>=t&&e<=n;n(e.count,1,10)||t.push({field:`count`,message:`Enter a whole number of shorts between 1 and 10.`});for(let r of[`minSeconds`,`maxSeconds`])n(e[r],15,180)||t.push({field:r,message:`Enter a whole number of seconds between 15 and 180.`});if(t.every(e=>e.field===`count`)&&e.minSeconds>e.maxSeconds)for(let e of[`minSeconds`,`maxSeconds`])t.push({field:e,message:`The longest a short may be must be at least the shortest. Raise the maximum or lower the minimum.`});let r=e.speed;r!==void 0&&(!Number.isFinite(r)||r<.999999999||r>1.250000001||Math.abs((r-1)/.05-Math.round((r-1)/.05))>1e-6)&&t.push({field:`speed`,message:`Choose a speed between 1.00× and 1.25×, in steps of 0.05.`}),e.musicVolume!==void 0&&!n(e.musicVolume,0,100)&&t.push({field:`musicVolume`,message:`Enter the music volume as a whole number of percent between 0 and 100.`});let i=e.fullVideoLink?.trim()??``;return i!==``&&!Xk(i)&&t.push({field:`fullVideoLink`,message:`The full video link must be a whole web address starting with https:// or http://, like https://youtu.be/abc123. Paste it again, or leave the box empty.`}),t}function Xk(e){if(e.length>2e3||/\s/.test(e))return!1;try{let t=new URL(e);return(t.protocol===`https:`||t.protocol===`http:`)&&t.hostname!==``}catch{return!1}}var Zk=[`rain`,`fire`,`wind`],Qk=[...Zk,`upload`],$k={rain:`Rain`,fire:`Fireplace`,wind:`Wind`,upload:`My own file`},eA={levelDb:-18,fadeInSeconds:3,tailSeconds:6};function tA(e){return e.ambientBed!==void 0&&e.mode!==`short`&&e.sources.video===`generate`&&e.sources.audio!==`off`}function nA(e){let t=[];return Qk.includes(e.source)||t.push({field:`source`,message:`Choose Rain, Fireplace, Wind or My own file for the ambient sound.`}),Number.isInteger(e.levelDb)&&e.levelDb>=-40&&e.levelDb<=-6||t.push({field:`level`,message:`Enter an ambient sound level between -40 and -6 dB, in whole dB.`}),rA(e.fadeInSeconds,30)||t.push({field:`fadeIn`,message:`Enter a fade-in between 0 and 30 seconds, in steps of 0.5.`}),rA(e.tailSeconds,30)||t.push({field:`tail`,message:`Enter a tail between 0 and 30 seconds, in steps of 0.5.`}),t}function rA(e,t){return Number.isInteger(e*2)&&e>=0&&e<=t}function iA(e){return{source:e.source,level:String(e.levelDb),fadeIn:String(e.fadeInSeconds),tail:String(e.tailSeconds)}}function aA(e){if(e===void 0||e.source===`none`)return;let t=e=>e.trim()===``?NaN:Number(e);return{source:e.source,levelDb:t(e.level),fadeInSeconds:t(e.fadeIn),tailSeconds:t(e.tail)}}var oA=[`interval`,`narration`],sA=[`cut`,`crossfade`,`fadeblack`,`slide`,`wipe`],cA=[`off`,`subtle`,`strong`],lA=[`none`,`warm`,`cold`,`desaturated`,`sepia`],uA=[`none`,`embers`,`dust`,`fog`],dA=[`off`,`chapters`,`every`],fA={cuts:`interval`,transition:`cut`,transitionSeconds:.6,vignette:`off`,grain:`off`,grade:`none`,atmosphere:`none`,chapterCards:!1,animate:`off`,animateEvery:3,animateModel:``},pA={...fA,cuts:`narration`},mA=.2,hA=[.2,.4,.6,.8,1,1.2,1.5,2],gA={interval:`Every N seconds`,narration:`Follow the narration`},_A={cut:`Cut`,crossfade:`Crossfade`,fadeblack:`Fade through black`,slide:`Slide`,wipe:`Wipe`},vA={off:`Off`,subtle:`Subtle`,strong:`Strong`},yA={none:`None`,warm:`Warm fantasy`,cold:`Cold`,desaturated:`Desaturated`,sepia:`Sepia`},bA={none:`None`,embers:`Embers`,dust:`Dust`,fog:`Fog`},xA={off:`Off`,chapters:`Chapter openers`,every:`Every Nth image`};function SA(e){return e.videoEdit??fA}function CA(e){let t=SA(e);return t.animate!==`off`&&e.sources.video===`generate`&&(t.animate===`every`||e.sources.audio!==`off`)}function wA(e){let t=e.videoEdit;if(t===void 0||e.sources.video!==`generate`)return[];let n=[];return t.transition!==`cut`&&!(Number.isFinite(t.transitionSeconds)&&t.transitionSeconds>=.2&&t.transitionSeconds<=2)&&n.push({field:`transitionSeconds`,message:`Choose a transition length between ${String(mA)} and 2 seconds.`}),t.chapterCards&&e.sources.audio===`off`&&n.push({field:`chapterCards`,message:`Chapter cards are placed from the narration. Turn narration on, or turn chapter cards off.`}),t.animate===`chapters`&&e.sources.audio===`off`&&n.push({field:`animate`,message:`Chapter openers are found from the narration. Turn narration on, or choose Every Nth image.`}),t.animate===`every`&&!(Number.isInteger(t.animateEvery)&&t.animateEvery>=2&&t.animateEvery<=10)&&n.push({field:`animateEvery`,message:`Choose every 2nd to every 10th image.`}),t.animate!==`off`&&t.animateModel.trim()===``&&n.push({field:`animateModel`,message:`Choose an image-to-video model to animate images with, or turn Animate images off.`}),n}function TA(e){return[[`Cuts`,gA[e.cuts]],[`Transition`,e.transition===`cut`?_A.cut:`${_A[e.transition]} · ${String(e.transitionSeconds)} s`],[`Vignette`,vA[e.vignette]],[`Film grain`,vA[e.grain]],[`Colour grade`,yA[e.grade]],[`Atmosphere`,bA[e.atmosphere]],[`Chapter cards`,e.chapterCards?`On`:`Off`],[`Animate images`,e.animate===`off`?xA.off:`${e.animate===`every`?`Every ${(e=>e===2?`2nd`:e===3?`3rd`:`${String(e)}th`)(e.animateEvery)} image`:xA.chapters}${e.animateModel.trim()===``?``:` · ${e.animateModel}`}`]]}var EA=[`audiobook`,`podcast`,`drama`,`interview`],DA={audiobook:`Audiobook`,podcast:`Podcast`,drama:`Radio drama`,interview:`Interview`},OA=[`narrator`,`host`,`guest`,`character`],kA=[`script`,`attribute`],AA=[.8,.9,1,1.1,1.2],jA=[0,.2,.35,.5,.8,1.2],MA=.35,NA=q({provider:W(),model:W(),voice:W()}),PA=q({id:W().min(1).max(60).regex(/^[a-z0-9-]+$/),name:W().max(40),role:J(OA),voice:NA,pace:G().optional(),pronunciations:W().max(2e4).optional(),castId:W().max(200).optional(),portrait:W().regex(/^[0-9a-f]{64}$/).optional()}),FA=9999,IA=q({title:W().max(200),chapter:G()}).strict().readonly();function LA(e){return`${e.title.trim()} · Chapter ${String(e.chapter)}`}var RA=q({format:J(EA),source:J(kA),speakers:K(PA).max(10),turnGapSeconds:G(),nameTags:GD(),nativeDialogue:GD(),audioFiles:GD(),book:IA.optional()});function zA(e,t=[]){return{format:e,source:`script`,speakers:BA(e,VA(e),t),turnGapSeconds:MA,nameTags:e===`podcast`||e===`interview`,nativeDialogue:!0,audioFiles:!0}}function BA(e,t,n){if(n.length===0||e!==`podcast`&&e!==`interview`)return[...t];let r=n.slice(0,9).map(e=>({...e,role:`host`})),i=e===`podcast`?t.slice(0,Math.max(0,2-r.length)):t.filter(e=>e.role!==`host`);return[...r,...i.filter(e=>!r.some(t=>t.id===e.id))]}function VA(e){let t={provider:``,model:``,voice:``},n=(e,n,r)=>({id:e,name:n,role:r,voice:t});switch(e){case`audiobook`:return[n(`narrator`,`Narrator`,`narrator`)];case`podcast`:return[n(`host-1`,`Alex`,`host`),n(`host-2`,`Sam`,`host`)];case`drama`:return[n(`narrator`,`Narrator`,`narrator`),n(`character-1`,`Mara`,`character`)];case`interview`:return[n(`host-1`,`Host`,`host`),n(`guest-1`,`Guest`,`guest`)]}}function HA(e){return e.voices!==void 0&&e.sources.audio===`generate`}function UA(e){return HA(e)&&e.voices?.source===`script`}function WA(e){let t=[],{speakers:n}=e;n.length===0&&t.push({field:`voices.speakers`,message:`Add at least one speaker under Speakers (Play → Narration, or Edit project → Providers).`}),e.source===`attribute`&&e.format!==`audiobook`&&t.push({field:`voices.source`,message:`Only audiobooks can hand an existing text's dialogue to speakers. Choose Write a script under Speakers (Play → Narration, or Edit project → Providers).`}),(e.format===`podcast`||e.format===`interview`)&&n.length<2&&t.push({field:`voices.speakers`,message:`A ${DA[e.format].toLowerCase()} needs at least two speakers. Add one under Speakers (Play → Narration, or Edit project → Providers).`}),(e.format===`audiobook`||e.format===`drama`)&&!n.some(e=>e.role===`narrator`)&&t.push({field:`voices.speakers`,message:`An ${e.format===`drama`?`radio drama`:`audiobook`} needs a narrator. Set one speaker's role to Narrator under Speakers (Play → Narration, or Edit project → Providers).`});let r=new Set,i=new Set;for(let[e,a]of n.entries()){let n=`voices.speakers.${String(e)}`,o=a.name.trim();o===``?t.push({field:`${n}.name`,message:`Enter a name for this speaker.`}):/^[\p{L}\p{N}][\p{L}\p{N} .'-]*$/u.test(o)?r.has(o.toLowerCase())&&t.push({field:`${n}.name`,message:`Two speakers are called "${o}". Give each speaker a different name.`}):t.push({field:`${n}.name`,message:`Use only letters, numbers, spaces, dots, apostrophes and hyphens in a speaker name, starting with a letter or number.`}),r.add(o.toLowerCase()),i.has(a.id)&&t.push({field:`${n}.name`,message:`Two speakers share one id. Remove one of them and add it again.`}),i.add(a.id),a.voice.provider.trim()===``||a.voice.model.trim()===``?t.push({field:`${n}.voice`,message:`Choose a voice provider and model for ${o||`this speaker`}.`}):a.voice.voice.trim()===``&&t.push({field:`${n}.voice.voice`,message:`Choose a voice for ${o||`this speaker`}.`}),a.pace!==void 0&&!AA.includes(a.pace)&&t.push({field:`${n}.pace`,message:`Pick a pace from the list for ${o||`this speaker`}.`})}return e.book!==void 0&&(e.book.title.trim()===``&&t.push({field:`voices.book.title`,message:`Enter the book's title under Speakers (Play → Narration), or remove the book to make a project on its own.`}),(!Number.isInteger(e.book.chapter)||e.book.chapter<1||e.book.chapter>9999)&&t.push({field:`voices.book.chapter`,message:`Enter a chapter number from 1 to ${String(FA)} under Speakers (Play → Narration).`})),jA.includes(e.turnGapSeconds)||t.push({field:`voices.turnGapSeconds`,message:`Pick a gap between turns from the list under Speakers (Play → Narration, or Edit project → Providers).`}),t}function GA(e){return e.mode===`short`}function KA(e){if(!GA(e))return[];let t=[];e.format!==`9:16`&&t.push({field:`format`,message:`A short is vertical. Choose the 9:16 format, or make a long video instead.`}),RS(e.sources,`video`)!==`generate`&&t.push({field:`sources.video`,message:`A short is a video. Set Video to Generate.`}),RS(e.sources,`audio`)===`off`&&t.push({field:`sources.audio`,message:`A short's length and captions come from its narration. Set Narration to Generate or Provide.`}),RS(e.sources,`images`)===`off`&&t.push({field:`sources.images`,message:`A short shows images behind its captions. Set Images to Generate or Provide.`});for(let n of[`thumbnail`,`document`])RS(e.sources,n)!==`off`&&t.push({field:`sources.${n}`,message:`A short has no ${n===`thumbnail`?`thumbnail`:`PDF`}. Set ${n===`thumbnail`?`Thumbnail`:`Document`} to Off.`});return e.shorts?.enabled===!0&&t.push({field:`shorts.enabled`,message:`A short isn't cut into more shorts. Turn Shorts off.`}),t}var qA=22.5,JA=`zoom`,YA={zoom:`Zoom in and out`,pan:`Pan across`,mixed:`Mix of both`,still:`Still`};function XA(e){return Number.isInteger(e)&&e>=1&&e<=600?void 0:`Enter a whole number of seconds between 1 and 600.`}function ZA(e){return Number.isInteger(e*2)&&e>=0&&e<=50?void 0:`Enter a zoom between 0 and 50 percent, in steps of 0.5.`}function QA(e){return Number.isInteger(e*2)&&e>=0&&e<=30?void 0:`Enter a number of seconds between 0 and 30, in steps of 0.5.`}var $A={research:[`off`,`generate`,`provide`],article:[`off`,`generate`,`provide`],audio:[`off`,`generate`,`provide`],images:[`off`,`generate`,`provide`],thumbnail:[`off`,`from_prompt`,`prompt_by_llm`,`provide`],video:[`off`,`generate`],document:[`off`,`generate`]};function ej(e){let t=[],n=tj(e.draft),{sources:r}=n;n.title===``?t.push({field:`title`,message:`Enter a title for this video.`}):n.title.length>200&&t.push({field:`title`,message:`Keep the title to 200 characters or fewer.`});for(let e of FS)$A[e].includes(RS(r,e))||t.push({field:`sources.${e}`,message:`"${RS(r,e)}" is not an option for ${e}. Reload the page and choose again.`});lj(n)&&!xj(n.llm)&&t.push({field:`llm`,message:`Choose a text (LLM) provider and model.`}),r.article===`generate`&&sj(n.articlePrompt)&&t.push({field:`articlePrompt`,message:`Pick an article prompt.`});let i=n.audio;t.push(...dj(n)),t.push(...fj(n)),r.audio===`generate`&&(i===void 0||!xj(i)?t.push({field:`audio`,message:`Choose a narration provider and model.`}):i.voice.trim()===``&&t.push({field:`audio.voice`,message:`Choose a voice for the narration.`})),r.images===`generate`&&nj(n,t),(r.images===`generate`||r.thumbnail===`from_prompt`||r.thumbnail===`prompt_by_llm`||_j(n)||CA(n))&&!xj(n.images)&&t.push({field:`images`,message:`Choose an image provider and model.`}),(r.thumbnail===`from_prompt`||r.thumbnail===`prompt_by_llm`)&&sj(n.thumbnailPrompt)&&t.push({field:`thumbnailPrompt`,message:`Pick a thumbnail prompt.`}),r.audio===`off`&&n.subtitles!==void 0&&n.subtitles.mode!==`off`&&t.push({field:`subtitles.mode`,message:`Subtitles need narration. Turn narration on, or turn subtitles off.`}),t.push(...mj(n)),t.push(...vj(n)),t.push(...KA(n)),t.push(...yj(n)),t.push(...bj(n,e.staged)),t.push(...fk(n.loudness)),t.push(...xk(n)),t.push(...gj(n)),t.push(...Ik(n)),hj(n)&&n.reference?.source===`provide`&&aj(e.staged,n.provided.reference,`images`,`provided.reference`,`Upload the establishing image, or set Establishing image to Off in the Images section.`,t),rj(n,e.staged,t),oj(n,e.requiredSlots,t),(!Number.isFinite(n.silenceGapSeconds)||n.silenceGapSeconds<0||n.silenceGapSeconds>30)&&t.push({field:`silenceGapSeconds`,message:`Enter a silence gap between 0 and 30 seconds.`});let a=r.video===`generate`?XA(n.imageSeconds):void 0;a!==void 0&&t.push({field:`imageSeconds`,message:a});let o=r.video===`generate`?ZA(n.zoomPercent):void 0;o!==void 0&&t.push({field:`zoomPercent`,message:o});let s=r.audio===`off`?void 0:QA(n.edgeSilenceSeconds);return s!==void 0&&t.push({field:`edgeSilenceSeconds`,message:s}),t.length===0?{ok:!0,draft:n}:{ok:!1,fields:t}}function tj(e){let t={...e.sources};t.article!==`generate`&&(t.research=`off`),t.images===`off`&&t.video===`generate`&&(t.video=`off`);let n=Object.create(null);for(let[t,r]of Object.entries(e.values))n[t]=r.trim();return{...e,title:e.title.trim(),subtitles:t.video===`off`&&e.subtitles?.mode===`burn-in`?{...e.subtitles,mode:`files`}:e.subtitles,sources:t,values:n,intro:t.audio===`generate`?e.intro:void 0,outro:t.audio===`generate`?e.outro:void 0}}function nj(e,t){if(e.imagePrompts.length===0){t.push({field:`imagePrompts`,message:`Tick at least one image prompt, or turn images off.`});return}let n=0;for(let[r,i]of e.imagePrompts.entries())n+=i.number,sj(i.name)&&t.push({field:`imagePrompts.${r}.name`,message:`Pick an image prompt.`}),(!Number.isInteger(i.number)||i.number<1||i.number>20)&&t.push({field:`imagePrompts.${r}.number`,message:`Enter a whole number between 1 and 20.`});n>60&&t.push({field:`imagePrompts`,message:`A video can have at most 60 images; these prompts ask for ${n}. Lower the numbers.`});let r=e.imageScale===void 0?void 0:ek(e.imageScale);r!==void 0&&t.push({field:`imageScale`,message:r})}function rj(e,t,n){let{sources:r,provided:i}=e;if(r.research===`provide`&&sj(i.research)&&n.push({field:`provided.research`,message:`Paste the research notes.`}),r.article===`provide`&&sj(i.article)&&n.push({field:`provided.article`,message:`Paste the article.`}),n.push(...Cj(e)),r.audio===`provide`&&aj(t,i.audio,`audio`,`provided.audio`,`Pick an audio file.`,n),r.thumbnail===`provide`&&aj(t,i.thumbnail,`thumbnail`,`provided.thumbnail`,`Pick a thumbnail image.`,n),r.images===`provide`){let e=i.images??[];e.length===0?n.push({field:`provided.images`,message:`Pick at least one image.`}):e.length>60&&n.push({field:`provided.images`,message:`A video can have at most 60 images. Remove some.`}),new Set(e).size!==e.length&&n.push({field:`provided.images`,message:`The same image is picked twice. Remove the duplicate.`});for(let[r,i]of e.entries())aj(t,i,`images`,`provided.images.${r}`,`Pick an image.`,n)}ij(e,t,n)}function ij(e,t,n){let r=e.provided.shortsMusic;if(e.shorts?.enabled!==!0||r===void 0)return;let i=`under Outputs → More shorts options → Background music`,a=t.find(e=>e.id===r);a===void 0||a.stageKind!==`audio`?n.push({field:`shorts.music`,message:`The shorts' background music file is no longer available, so it can't be added to the project. Choose the file again ${i}, or remove it.`}):a.state!==`staged`&&n.push({field:`shorts.music`,message:`The shorts' background music is still uploading, so the run can't start yet. Wait for it to finish, or remove it ${i}.`})}function aj(e,t,n,r,i,a){if(t===void 0||t===``){a.push({field:r,message:i});return}let o=e.find(e=>e.id===t);if(o===void 0||o.stageKind!==n){a.push({field:r,message:`That upload is no longer available. Choose the file again.`});return}o.state!==`staged`&&a.push({field:r,message:`This file is still uploading. Wait for it to finish.`})}function oj(e,t,n){for(let r of t){let t=Object.hasOwn(e.values,r)?e.values[r]:void 0;if(t===void 0||t===``){n.push({field:`values.${r}`,message:`Fill in this field.`});continue}t.length>200&&n.push({field:`values.${r}`,message:`Keep this to 200 characters or fewer.`}),/[\n\r]/.test(t)&&n.push({field:`values.${r}`,message:`Keep this to a single line, without line breaks.`})}}function sj(e){return e===void 0||e.trim()===``}function cj(e){let t=e.sources,n=[];return t.research===`generate`&&n.push({section:`article`,label:`researching the topic`}),t.article===`generate`&&n.push({section:`article`,label:`writing the article`}),HA(e)&&e.voices?.source===`attribute`&&n.push({section:`narration`,label:`working out who speaks each line`}),uj(e)&&n.push({section:`narration`,label:`preparing the narration's delivery`}),e.intro?.mode===`llm`&&n.push({section:`narration`,label:`writing the intro`}),e.outro?.mode===`llm`&&n.push({section:`narration`,label:`writing the outro`}),t.thumbnail===`prompt_by_llm`&&n.push({section:`outputs`,label:`writing the thumbnail prompt`}),pj(e)&&n.push({section:`outputs`,label:`writing the YouTube description`}),_j(e)&&n.push({section:`outputs`,label:`picking the shorts`}),n}function lj(e){return cj(e).length>0}function uj(e){return e.sources.audio===`generate`&&!sj(e.narrationPrompt)}function dj(e){return uj(e)&&(e.audio?.provider!==`inworld`||e.audio.model!==`inworld-tts-2`)?[{field:`narrationPrompt`,message:`Narration preparation only works with the Inworld TTS-2 model. Choose that model under Narration, or turn preparation Off.`}]:[]}function fj(e){if(e.voices===void 0||!HA(e))return[];let t=[...WA(e.voices)];return!sj(e.narrationPrompt)&&!e.voices.speakers.some(e=>e.voice.provider===`inworld`&&e.voice.model===`inworld-tts-2`)&&t.push({field:`narrationPrompt`,message:`Narration preparation adds delivery cues only to speakers on Inworld's TTS-2 model, and no speaker uses it. Choose that model for a speaker under Speakers, or clear Narration Preparation under Narration → Audio Advanced.`}),t}function pj(e){return e.youtubeDescription===!0&&e.sources.audio!==`off`}function mj(e){return e.youtubeDescription===!0&&e.sources.audio===`off`?[{field:`youtubeDescription`,message:`The YouTube description is timed from the narration. Turn narration on, or turn the YouTube description off.`}]:[]}function hj(e){return e.reference!==void 0&&e.sources.images===`generate`}function gj(e){return hj(e)&&e.reference?.source===`prompt`&&(e.reference.prompt===void 0||e.reference.prompt.trim()===``)?[{field:`reference.prompt`,message:`Pick an image prompt for the establishing image, upload one instead, or set Establishing image to Off in the Images section.`}]:[]}function _j(e){return e.shorts?.enabled===!0&&e.sources.audio!==`off`}function vj(e){let t=e.shorts;if(t?.enabled!==!0)return[];if(e.sources.audio===`off`)return[{field:`shorts.enabled`,message:`Shorts are cut from the narration. Turn narration on, or turn Shorts off.`}];let n=Yk(t).map(e=>({field:`shorts.${e.field}`,message:e.message})),r=e.sources.video===`generate`?void 0:XA(e.imageSeconds);return r!==void 0&&n.push({field:`imageSeconds`,message:r}),n}function yj(e){return wA(e).map(e=>({field:`videoEdit.${e.field}`,message:e.message}))}function bj(e,t){let n=e.ambientBed;if(n===void 0||!tA(e))return[];let r=`under Video and style → Ambient sound`,i=nA(n).map(e=>({field:`ambientBed.${e.field}`,message:`${e.message} Change it ${r}.`}));if(n.source!==`upload`)return i;let a=e.provided.ambientBed,o=a===void 0?void 0:t.find(e=>e.id===a);return o===void 0||o.stageKind!==`audio`?i.push({field:`ambientBed.file`,message:`The ambient sound's audio file is missing, so it can't be added to the project. Choose the file ${r}, or pick Rain, Fireplace or Wind instead.`}):o.state!==`staged`&&i.push({field:`ambientBed.file`,message:`The ambient sound's audio file is still uploading, so the run can't start yet. Wait for it to finish ${r}.`}),i}function xj(e){return e!==void 0&&e.provider.trim()!==``&&e.model.trim()!==``}function Sj(e){return e.sources.audio===`generate`&&e.audio?.usePronunciationGlossary===!0&&e.audio.provider===`inworld`&&(e.audio.model===`inworld-tts-2`||e.audio.model===`inworld-tts-2-flash`)}function Cj(e){let{sources:t}=e;if(t.article!==`off`)return[];let n=`Set Article to Generate or Provide`;return[...t.audio===`generate`?[{field:`sources.audio`,message:`Narration reads the article, and Article is Off. ${n}, or set Narration to Off or Provide.`}]:[],...t.document===`generate`?[{field:`sources.document`,message:`The PDF is made from the article, and Article is Off. ${n}, or set PDF to Off.`}]:[],...t.thumbnail===`prompt_by_llm`?[{field:`sources.thumbnail`,message:`The AI writes the thumbnail prompt from the article, and Article is Off. ${n}, or pick From prompt for the thumbnail.`}]:[],...t.audio!==`off`&&e.subtitles!==void 0&&e.subtitles.mode!==`off`?[{field:`subtitles.mode`,message:`Captions are matched to the article's words, and Article is Off. ${n}, or turn captions off.`}]:[],...pj(e)?[{field:`youtubeDescription`,message:`The YouTube description is written from the narration's words, which come from the article, and Article is Off. ${n}, or turn the YouTube description off.`}]:[],..._j(e)?[{field:`shorts.enabled`,message:`Shorts are picked from the narration's words, which come from the article, and Article is Off. ${n}, or turn Shorts off.`}]:[],...t.images===`generate`&&e.imageScenes===!0?[{field:`imageScenes`,message:`Scenes from the article need the article, and Article is Off. ${n}, or turn Scenes from the article off.`}]:[]]}var wj=[`auto`,`yes`,`no`],Tj={auto:`Automatic`,yes:`Always Yes`,no:`Always No`},Ej={levelDb:G(),fadeInSeconds:G(),tailSeconds:G()},Dj=q({source:J(Qk),...Ej}).strict(),Oj=q({source:J(Zk),...Ej}).strict(),kj=`Previous video`,Aj=2e3,jj=/\{\{([^{}\n]{1,80})\}\}/gu;function Mj(e){return e.trim().replace(/\s+/gu,` `).toLowerCase()}function Nj(e,t){let n=new Set,r=[];for(let i of[...t,...e]){let e=Mj(i.name);n.has(e)||i.url.trim()===``||(n.add(e),r.push(i))}return r}function Pj(e,t){let n=new Map(t.map(e=>[Mj(e.name),e.url])),r=[],i=0;for(let t of e.matchAll(jj)){let a=t.index;a>i&&r.push({kind:`text`,text:e.slice(i,a)});let o=(t[1]??``).trim();r.push({kind:`placeholder`,raw:t[0],name:o,url:n.get(Mj(o))}),i=a+t[0].length}return i<e.length&&r.push({kind:`text`,text:e.slice(i)}),r}function Fj(e,t){let n=[];return{text:Pj(e,t).map(e=>e.kind===`text`?e.text:e.url===void 0?(n.some(t=>Mj(t)===Mj(e.name))||n.push(e.name),e.raw):e.url).join(``),unknown:n}}function Ij(e){if(e.length>50)return`Keep at most 50 links. Remove some.`;let t=new Set;for(let[n,r]of e.entries()){let e=`Link ${String(n+1)}`,i=r.name.trim();if(i===``)return`${e} has no name. Give it one, such as Patreon.`;if(i.length>60)return`${e}'s name is over 60 characters. Shorten it.`;if(/[{}]/u.test(i))return`${e}'s name contains { or }. Use the name alone; the description writes it as {{${i.replace(/[{}]/gu,``)}}}.`;if(t.has(Mj(i)))return`Two links are named "${i}". Rename one, since {{${i}}} can only fill with one.`;t.add(Mj(i));let a=r.url.trim();if(a.length>2e3)return`The "${i}" link is over ${String(Aj)} characters. Use a shorter address.`;if(a===``)return`The "${i}" link has no address. Paste it, starting with https://.`;if(!Lj(a))return`The "${i}" link is not a web address. Paste the full address, starting with https://.`}}function Lj(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`}catch{return!1}}var Rj=wD(),zj=W().regex(/^#[0-9a-fA-F]{6}$/,`Use a colour like #FFD700.`).transform(e=>e.toUpperCase()),Bj=e=>W().trim().max(e).optional(),Vj=W().max(160).regex(/^[A-Za-z0-9_-]+$/,`Choose a font from the list.`).optional(),Hj=q({captionFontId:Vj,captionColor:zj.optional(),captionOutlineColor:zj.optional(),titleFontId:Vj,titleColor:zj.optional(),intro:Bj(200),outro:Bj(200),endScreenText:Bj(200),documentTheme:Bj(200),ambientBed:Oj.superRefine((e,t)=>{for(let n of nA(e))t.addIssue({code:`custom`,path:[n.field],message:`${n.message} Change it under Brand kit → Ambient sound on the channel page.`})}).optional(),language:zO.optional(),links:K(q({name:W().max(240),url:W().max(Aj*2)}).strict()).max(100).transform(e=>e.map(e=>({name:e.name.trim(),url:e.url.trim()}))).superRefine((e,t)=>{let n=Ij(e);n!==void 0&&t.addIssue({code:`custom`,message:`The channel's links weren't saved: ${n} Then press Save channel on the channel's Brand tab.`})}).optional()}).strict().transform(e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``))),Uj=W().trim().min(1,`Enter a name.`).max(200,`Keep the name to 200 characters or fewer.`);q({id:Rj,name:Uj}).strict().readonly(),q({name:Uj,brand:Hj,seriesBrief:W().max(1e4,`Keep the series brief to 10,000 characters or fewer.`),baseVersion:G().int().positive()}).strict().readonly();var Wj=W().trim().min(1,`Enter a name, and remove empty aliases.`).max(200,`Keep names and aliases to 200 characters or fewer.`),Gj=q({provider:W().trim().min(1,`Choose a voice provider.`).max(100),model:W().trim().min(1,`Choose a voice model.`).max(200),voice:W().trim().min(1,`Choose a voice.`).max(200),pace:G().refine(e=>AA.includes(e),`Pick a pace from the list.`).optional(),pronunciations:W().max(2e4,`Keep the pronunciations to 20,000 characters or fewer.`).optional()}).strict(),Kj=q({kind:J(Gb),name:Wj,aliases:K(Wj).max(20,`Keep to 20 aliases or fewer.`).default([]),description:W().trim().max(2e3,`Keep the description to 2,000 characters or fewer.`).default(``),voice:Gj.nullable().optional(),host:GD().optional()}).strict();Kj.extend({id:Rj}).strict(),Kj.extend({baseVersion:G().int().positive()}).strict(),q({prompt:W().trim().min(1,`Describe the picture to make.`).max(4e3,`Keep the picture's description to 4,000 characters or fewer.`),provider:W().min(1).max(100),model:W().min(1).max(200)}).strict(),q({channelId:Rj}).strict(),q({aiDisclosure:J(wj,`Choose Automatic, Always Yes or Always No.`)}).strict();var qj=K(q({name:W(),aliases:K(W()).readonly(),description:W(),images:K(W()).readonly()})).readonly(),Jj=W().min(1),Yj=W().regex(/^[a-f0-9]{64}$/),Xj=J([`audio`,`images`,`video`]),Zj=q({projectId:Jj,revisionId:Jj,checkpointId:Jj,stage:Xj,workId:Jj,fingerprint:Yj,state:J([`configured`,`pending-review`,`held`,`released`,`satisfied`,`invalidated`,`canceled`]),createdAt:LO(),approvedAt:LO().nullable()}).strict().readonly();q({projectId:Jj,revisionId:Jj,checkpoints:K(q({checkpointId:Jj,stage:Xj,workId:Jj,fingerprint:Yj,state:J([`configured`,`pending-review`,`held`])}).strict().readonly()).max(3).readonly(),createdAt:LO()}).strict().readonly();var Qj=q({projectId:Jj,revisionId:Jj,checkpointId:Jj,fingerprint:Yj,idempotencyKey:wD(),approvedAt:LO()}).strict().readonly(),$j=[`Cinzel`,`Literata`,`times`,`helvetica`,`courier`],eM=[`normal`,`medium`,`bold`,`black`,`italic`,`bolditalic`],tM=(e,t)=>{let n={error:`Use a value from ${String(e)} to ${String(t)}.`};return G({error:`Enter a number.`}).finite(n).min(e,n).max(t,n)},nM=W().regex(/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i,`Use a colour like #8c1e14.`),rM=W().max(300,{error:`Keep this under 300 characters.`}),iM=rM.nullable(),aM=W().max(500,{error:`Keep this under 500 characters.`}).nullable(),oM=q({family:J($j),style:J(eM),letterSpacing:tM(-.5,2)}).strict(),sM=q({page:q({format:J([`a4`,`letter`]),margin:tM(5,60),contentTop:tM(5,80)}).strict(),background:q({image:J([`parchment`]).nullable(),color:nM}).strict(),colors:q({heading:nM,text:nM,muted:nM,faint:nM}).strict(),fonts:q({body:oM,strong:oM,emphasis:oM,heading:oM,dramatic:oM,decorative:oM,dropCap:oM,footer:oM}).strict(),sizes:q({brand:tM(6,72),title:tM(6,72),section:tM(6,72),heading:tM(6,72),subheading:tM(6,72),body:tM(6,24),footer:tM(5,24),meta:tM(5,24)}).strict(),spacing:q({bodyLine:tM(3,20),headingLine:tM(3,30),subheadingLine:tM(3,30),paragraphGap:tM(0,3),headingGap:tM(0,5),itemGap:tM(0,3),listIndent:tM(0,30),quoteIndent:tM(0,40),ruleWidth:tM(0,150)}).strict(),dropCap:q({enabled:GD(),lines:tO([pO(2),pO(3),pO(4)]),scale:tM(1,5),gap:tM(0,20),minLength:G({error:`Enter a number.`}).int({error:`Use a whole number.`}).min(0,{error:`Use a value from 0 to 2000.`}).max(2e3,{error:`Use a value from 0 to 2000.`}),minRoom:tM(0,1)}).strict(),titlePage:q({brandY:tM(10,200),taglineOffset:tM(0,60),titleY:tM(10,250),titleLine:tM(3,40),metaOffset:tM(0,100),metaLine:tM(3,30),showDate:GD(),showWordCount:GD(),cover:q({enabled:GD(),gap:tM(0,40),maxHeight:tM(20,200)}).strict()}).strict(),contents:q({enabled:GD(),title:rM,depth:tO([pO(1),pO(2),pO(3)]),titleOffset:tM(0,100),firstEntryOffset:tM(0,150),line:tM(3,30),indent:tM(0,30)}).strict(),header:q({enabled:GD(),top:tM(3,60),maxTitleCharacters:G({error:`Enter a number.`}).int({error:`Use a whole number.`}).min(5,{error:`Use a value from 5 to 200.`}).max(200,{error:`Use a value from 5 to 200.`})}).strict(),footer:q({enabled:GD(),bottom:tM(3,60),reserve:tM(0,60),text:rM}).strict(),brand:q({name:iM,url:aM,tagline:iM,linkLabel:iM}).strict(),metadata:q({author:rM,subject:rM,keywords:W().max(1e3),creator:rM}).strict(),sources:q({enabled:GD(),title:rM,titleOffset:tM(0,100),bodyOffset:tM(0,150),line:tM(3,30),gap:tM(0,20)}).strict(),endPage:q({enabled:GD(),title:rM,titleOffset:tM(0,100),bodyOffset:tM(0,150),lines:K(rM).max(60).readonly(),showDocumentDetails:GD(),link:q({text:rM,url:aM}).strict().nullable(),closing:iM}).strict()}).strict(),cM=q({id:W().min(1).max(64),name:W().min(1).max(80),values:sM}).strict(),lM=q({theme:J(KS),custom:cM.optional()}).strict(),uM=K(q({written:W().trim().min(1).max(200),spoken:W().trim().min(1).max(500),wholeWord:GD(),caseSensitive:GD()}).strict().readonly()).max(1e3).readonly(),dM=[`whole`,`paragraph`,`words`,`characters`],fM=[`off`,`files`,`burn-in`],pM=[`top`,`upper-middle`,`center`,`lower-middle`,`bottom`],mM=q({mode:J(fM),language:pO(`en`).default(`en`),fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/).default(`default`),position:J(pM).default(`bottom`),fontSize:G().int().min(16).max(120).default(48),color:W().regex(/^#[0-9A-Fa-f]{6}$/).optional(),outlineColor:W().regex(/^#[0-9A-Fa-f]{6}$/).optional()}),hM={mode:`off`,language:`en`,fontId:`default`,fontSize:48,position:`bottom`},gM=W().regex(/^#[0-9A-Fa-f]{6}$/),_M=q({provider:W(),model:W(),thinking:J(HO).optional()}),vM=q({name:W(),mode:J(BS)}),yM=q({cuts:J(oA),transition:J(sA),transitionSeconds:G(),vignette:J(cA),grain:J(cA),grade:J(lA),atmosphere:J(uA),chapterCards:GD(),animate:J(dA),animateEvery:G(),animateModel:W()}),bM=q({mode:J(US).optional(),checkpoints:K(Xj).max(3).refine(e=>new Set(e).size===e.length).readonly().optional(),title:W(),format:J(PS),sources:q({research:J(LS),article:J(LS),audio:J(LS),images:J(LS),thumbnail:J(LS),video:J(LS),document:J(LS).optional()}),llm:_M.optional(),audio:_M.extend({voice:W(),usePronunciationGlossary:GD().optional(),shareGlossary:GD().optional(),useNarrationAliases:GD().optional(),describeFigures:GD().optional(),skipCode:GD().optional()}).optional(),narrationAliases:uM.optional(),sharedGlossary:K(q({term:W().min(1).max(200),ipa:K(W().min(1).max(200)).min(1).max(20).readonly()})).max(2e4).readonly().optional(),images:_M.optional(),reference:q({source:J(HS),prompt:W().optional(),thumbnail:GD().optional()}).optional(),articlePrompt:W().optional(),narrationPrompt:W().optional(),imagePrompts:K(q({name:W(),number:G()})),imageScale:q({perHour:G(),words:G()}).optional(),imageScenes:GD().optional(),thumbnailPrompt:W().optional(),thumbnailCount:tO([pO(1),pO(3)]).optional(),intro:vM.optional(),outro:vM.optional(),values:lO(W(),W()),provided:q({research:W().optional(),article:W().optional(),audio:W().optional(),images:K(W()).optional(),thumbnail:W().optional(),reference:W().optional(),shortsMusic:W().optional(),ambientBed:W().optional()}),chunking:q({mode:J(dM),words:G().optional(),characters:G().int().min(1).max(1e6).optional()}).optional(),silenceGapSeconds:G(),imageSeconds:G().default(15),zoomPercent:G().default(qA),motionStyle:J(zS).default(JA),edgeSilenceSeconds:G().default(2),subtitles:mM.optional(),document:lM.optional(),youtubeDescription:GD().optional(),showFigures:GD().optional(),descriptionPrompt:W().optional(),shorts:q({enabled:GD(),count:G(),minSeconds:G(),maxSeconds:G(),prompt:W().optional(),imagePrompt:W().optional(),titleOnScreen:GD().optional(),fullVideoLink:W().optional(),musicVolume:G().optional(),speed:G().optional()}).optional(),videoEdit:yM.optional(),channelId:W().optional(),useBrandKit:pO(!1).optional(),cast:qj.optional(),earlierEpisodes:K(q({title:W(),summary:W()})).readonly().optional(),titleStyle:q({fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/).optional(),color:gM.optional()}).optional(),endScreen:q({text:W().max(200)}).optional(),reviews:q({provider:W(),model:W(),thinking:J(HO).optional(),retries:G().optional(),stages:uO(J(Ck),q({mode:J(wk),prompt:W().optional()}))}).optional(),voices:RA.optional(),ambientBed:Dj.optional(),loudness:q({videoLufs:G(),audioFilesLufs:G()}).strict().optional(),sentencePauseSeconds:G().optional(),paragraphPauseSeconds:G().optional(),language:zO.optional()}),xM=bM.extend({rendered:lO(W(),W())}),SM=[`article`,`image`,`thumbnail`,`narration`,`description`,`shorts`,`review`,`script`],CM=[`intro`,`outro`],wM=1e5;q({id:W(),kind:J(SM),name:W(),body:W(),slots:W(),updated_at:W()}),q({id:W(),category:J(CM),mode:J(BS),name:W(),body:W(),slots:W(),updated_at:W()});var TM=q({id:W(),name:W(),body:W(),slots:K(W()).readonly(),updatedAt:W()}),EM=q({prompts:K(TM.extend({kind:J(SM)}).strict().readonly()).readonly(),entries:K(TM.extend({category:J(CM),mode:J(BS)}).strict().readonly()).readonly()}).strict().readonly(),DM=wD(),OM=W(),kM=lO(OM,OM).readonly(),AM=q({provider:OM,model:OM,thinking:J(HO).optional()}).strict(),jM=[`audio`,`images`,`thumbnail`,`reference`],MM=q({attachmentId:DM,name:OM}).strict().readonly(),NM=q({title:OM,checkpoints:bM.shape.checkpoints,format:J(PS),sources:q({research:J(LS),article:J(LS),audio:J(LS),images:J(LS),thumbnail:J(LS),video:J(LS),document:J(LS).optional()}).strict().readonly(),document:lM.readonly().optional(),llm:AM.readonly(),audio:AM.extend({voice:OM,usePronunciationGlossary:GD().optional(),shareGlossary:GD().optional(),useNarrationAliases:GD().optional(),describeFigures:GD().optional(),skipCode:GD().optional()}).readonly(),images:AM.readonly(),reference:q({source:J([`off`,...HS]),prompt:OM,thumbnail:GD()}).strict().readonly().optional(),articlePrompt:OM,narrationPrompt:OM.optional(),thumbnailCount:tO([pO(1),pO(3)]).optional(),loudness:q({enabled:GD(),videoLufs:G().optional(),audioFilesLufs:G().optional()}).strict().readonly().optional(),sentencePause:OM.optional(),paragraphPause:OM.optional(),youtubeDescription:GD().optional(),showFigures:GD().optional(),descriptionPrompt:OM.optional(),language:zO.optional(),shorts:q({enabled:GD(),count:OM,minSeconds:OM,maxSeconds:OM,prompt:OM,imagePrompt:OM,titleOnScreen:GD().optional(),fullVideoLink:OM.optional(),musicVolume:OM.optional(),speed:OM.optional()}).strict().readonly().optional(),reviews:q({provider:OM,model:OM,thinking:J(HO).optional(),retries:OM,stages:uO(J(Ck),q({mode:J(wk),prompt:OM}).strict().readonly()).readonly()}).strict().readonly().optional(),imagePrompts:K(q({name:OM,number:OM}).strict().readonly()).readonly(),imageScale:q({every:J([`minutes`,`hour`]),value:OM}).strict().readonly().optional(),imageScenes:GD().optional(),thumbnailPrompt:OM,intro:OM,outro:OM,chunking:q({mode:J(dM),words:OM,characters:OM}).strict().readonly(),subtitles:q({mode:J(fM),language:pO(`en`),fontId:OM,fontSize:OM,position:J(pM)}).strict().readonly(),imageSeconds:OM.default(`15`),edgeSilenceSeconds:OM.default(`2`),zoomPercent:OM.default(String(qA)),motionStyle:J(zS).default(JA),silenceGapSeconds:OM.optional(),videoEdit:yM.strict().readonly().optional(),useBrandKit:GD().optional(),voices:RA.strict().readonly().optional(),ambientBed:q({source:J([`none`,...Qk]),level:OM,fadeIn:OM,tail:OM}).strict().readonly().optional(),values:kM,provided:q({research:OM,article:OM,audio:MM.nullable(),thumbnail:MM.nullable(),images:K(MM).readonly(),reference:MM.nullable().optional(),shortsMusic:MM.nullable().optional(),ambientBed:MM.nullable().optional()}).strict().readonly()}).strict().readonly(),PM=q({schemaVersion:pO(1),librarySnapshot:EM.optional(),templateSource:q({id:DM,version:G().int().positive()}).strict().readonly().optional(),channelId:DM.optional(),form:NM,section:J([`content`,`outputs`,`style`,`review`]),variants:K(q({id:DM,title:OM,values:kM}).strict().readonly()).readonly(),queue:GD().optional(),expectedWords:OM,previewText:OM,fontUpload:q({operationId:DM,name:OM}).strict().readonly().nullable()}).strict().readonly(),FM=q({id:DM,document:PM}).strict().readonly(),IM=FM.unwrap().extend({baseVersion:G().int().positive(),mutationId:DM}).strict().readonly(),LM=FM.unwrap().extend({sourceId:DM}).strict().readonly(),RM=q({id:DM,baseVersion:G().int().positive()}).strict().readonly(),zM=q({id:DM,kind:J(jM),name:OM,state:J([`pending`,`copying`,`ready`,`reattach`]),stagedFileId:OM.nullable(),bytes:G().nonnegative(),error:OM.nullable()}).strict().readonly(),BM=q({id:DM,version:G().int().positive(),createdAt:OM,updatedAt:OM,document:PM}).strict().readonly(),VM=q({checkpointSet:K(Zj.unwrap().extend({reviewedFingerprint:OM}).strict().readonly()).readonly().optional(),requestId:DM,projectIds:K(OM).readonly(),queue:K(q({projectId:OM,batchId:OM,position:G(),state:J([`queued`,`active`,`finished`])}).strict().readonly()).readonly(),replayed:GD()}).strict().readonly(),HM=q({currency:pO(`USD`),rows:K(q({stage:OM,low:G().nullable(),high:G().nullable(),detail:OM,onPlan:GD().optional(),apiLow:G().nullable().optional(),apiHigh:G().nullable().optional()}).strict().readonly()).readonly(),low:G(),high:G(),unknown:G(),apiLow:G().optional(),apiHigh:G().optional(),apiUnknown:G().optional(),expectedWords:G(),catalogueDate:OM.nullable(),assumptions:K(OM).readonly()}).strict().readonly(),UM=q({checkpointSet:K(q({runIndex:G().int().nonnegative(),checkpointId:OM,stage:Xj,fingerprint:OM,workKeys:K(OM).readonly(),dependents:K(J(FS)).readonly()}).strict().readonly()).readonly().optional(),id:DM,draftId:DM,draftVersion:G().int().positive(),fingerprint:OM,runs:K(q({draft:bM,rendered:kM,templates:kM}).strict().readonly()).readonly(),estimates:K(HM).readonly()}).strict().readonly(),WM=q({draft:BM,attachments:K(zM).readonly(),review:UM.nullable(),pendingStart:q({reviewId:DM,draftVersion:G().int().positive()}).strict().readonly().nullable(),start:VM.nullable()}).strict().readonly(),GM=q({title:W(),status:G(),detail:W().optional(),reason:W().optional(),currentVersion:G().int().positive().nullable().optional(),reviewId:wD().optional(),fields:K(q({field:W(),message:W()})).optional(),errors:K(q({path:W(),message:W()})).optional()}),KM=q({drafts:K(q({id:wD(),title:W(),version:G().int().positive(),updatedAt:W(),readable:GD()}).strict()).readonly()}).strict(),qM=RM.unwrap().omit({id:!0}).extend({draftId:wD(),reviewId:wD()}).strict();async function JM(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=GM.safeParse(n);if(!r.success)throw po(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw po(e,{title:i.title,status:i.status,...i.detail===void 0?{}:{detail:i.detail},...i.fields===void 0?{}:{fields:i.fields}});return{ok:!1,reason:i.reason??`invalid-request`,message:i.detail??i.title,currentVersion:i.currentVersion??null,fields:i.fields??i.errors?.map(e=>({field:e.path,message:e.message}))??[],...i.reviewId===void 0?{}:{reviewId:i.reviewId}}}async function YM(e,t,n,r,i){return JM(await e.fetch(`${e.origin}/api/drafts${t}`,{method:n,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}}),r)}function XM(e){return`/${encodeURIComponent(wD().parse(e))}`}async function ZM(e){return YM(e,``,`GET`,KM)}async function QM(e,t){return YM(e,``,`POST`,WM,FM.parse(t))}async function $M(e,t){return YM(e,XM(t),`GET`,WM)}async function eN(e,t){let{id:n,...r}=IM.parse(t);return YM(e,XM(n),`PUT`,WM,r)}async function tN(e,t){let{sourceId:n,...r}=LM.parse(t);return YM(e,`${XM(n)}/fork`,`POST`,WM,r)}async function nN(e,t){let{id:n,...r}=RM.parse(t);return YM(e,XM(n),`DELETE`,q({discarded:pO(!0)}).strict(),r)}async function rN(e,t){let{id:n,...r}=RM.parse(t);return YM(e,`${XM(n)}/review`,`POST`,UM,r)}async function iN(e,t){let{draftId:n,...r}=qM.parse(t);return YM(e,`${XM(n)}/start`,`POST`,VM,r)}function aN(e,t,n){return`${e.origin}/api/drafts${XM(t)}/attachments/${encodeURIComponent(wD().parse(n))}/file`}async function oN(e,t,n,r,i){let a=new FormData;return a.set(`file`,r),JM(await e.fetch(aN(e,t,n),{method:`PUT`,body:a,...i?{signal:i}:{}}),zM)}var sN=[`fonts`];async function cN(e){return F(await e.fetch(`${e.origin}/api/fonts`))}async function lN(e,t){let n=new FormData;return n.set(`file`,t),F(await e.fetch(`${e.origin}/api/fonts`,{method:`POST`,body:n}))}function uN(e,t){return`${e.origin}/api/fonts/${encodeURIComponent(t)}/file`}var dN=`slopify.play-draft`;function fN(e){try{e?window.localStorage?.setItem(dN,e):window.localStorage?.removeItem(dN)}catch(e){console.warn(`Active draft browser storage is unavailable`,e)}}function pN(){try{return window.localStorage?.getItem(dN)??null}catch(e){return console.warn(`Active draft browser storage is unavailable`,e),null}}async function mN(e,t){let n=await Promise.allSettled([t.fetchQuery({...eb(e),staleTime:0}),t.fetchQuery({...nb(e),staleTime:0}),t.fetchQuery({...rb(e),staleTime:0}),t.fetchQuery({...ob(e),staleTime:0}),t.fetchQuery({...tb(e),staleTime:0}),t.fetchQuery({queryKey:sN,queryFn:()=>cN(e),staleTime:0})]);for(let e of n)e.status===`rejected`&&console.warn(`Draft choices could not refresh`,e.reason)}var hN=`under Video and style → Ambient sound`;`${hN}`,`${hN}`;var gN=PM.parse({schemaVersion:1,form:{title:``,format:`16:9`,sources:{research:`off`,article:`generate`,audio:`generate`,images:`generate`,thumbnail:`off`,video:`generate`},llm:{provider:``,model:``},audio:{provider:``,model:``,voice:``,usePronunciationGlossary:!0,shareGlossary:!0,useNarrationAliases:!0,describeFigures:!0},images:{provider:``,model:``},articlePrompt:``,narrationPrompt:``,imagePrompts:[],thumbnailPrompt:``,intro:``,outro:``,chunking:{mode:`whole`,words:`500`,characters:`3000`},subtitles:{...hM,fontSize:`48`},imageSeconds:`15`,edgeSilenceSeconds:`2`,zoomPercent:String(qA),motionStyle:JA,videoEdit:pA,showFigures:!0,values:{},provided:{research:``,article:``,audio:null,images:[],thumbnail:null}},section:`content`,variants:[],expectedWords:`1500`,previewText:`Every story begins with a word.`,fontUpload:null}),_N={};function vN(e){_N=e}function yN(e,t=_N){let{form:n}=e;return n.llm.provider!==``||n.images.provider!==``||t.llm===void 0&&t.images===void 0?e:{...e,form:{...n,...t.llm===void 0?{}:{llm:{...t.llm}},...t.images===void 0?{}:{images:{...t.images}}}}}function bN(e){let t={...e.sources,...e.sources.article===`generate`?{}:{research:`off`},...e.sources.images===`off`?{video:`off`}:{}},n=t.audio===`off`?`off`:t.video===`off`&&e.subtitles.mode===`burn-in`?`files`:e.subtitles.mode;return{...e,sources:t,subtitles:{...e.subtitles,mode:n}}}function xN(e){let t=PM.parse(e);return JSON.stringify({...t,form:bN(t.form)})}function SN(e,t,n){return{...e,acknowledged:Math.max(e.acknowledged,t),version:n}}function CN(e,t){return t.type===`edit`?{...e,edited:e.edited+1}:SN(e,t.generation,t.version)}function wN(e,t,n){return{mutationId:n,document:PM.parse(JSON.parse(xN(e))),generation:t.edited,baseVersion:t.version}}function TN(){return{document:yN(gN),view:null,clock:{edited:0,acknowledged:0,version:0},id:null,recoveryId:null,pending:null,status:`unsaved`,error:null,reveal:null}}function EN(e,t,n){let r=e.form.provided,i=t.form.provided,a=new Map;for(let[e,t]of[[r.audio,i.audio],[r.thumbnail,i.thumbnail],[r.shortsMusic,i.shortsMusic],[r.ambientBed,i.ambientBed],...r.images.map((e,t)=>[e,i.images[t]])])e&&t&&a.set(e.attachmentId,t.attachmentId);let o=e=>e?{...e,attachmentId:a.get(e.attachmentId)??e.attachmentId}:null;return{...n,form:{...n.form,provided:{...n.form.provided,audio:o(n.form.provided.audio),thumbnail:o(n.form.provided.thumbnail),...n.form.provided.shortsMusic===void 0?{}:{shortsMusic:o(n.form.provided.shortsMusic)},...n.form.provided.ambientBed===void 0?{}:{ambientBed:o(n.form.provided.ambientBed)},images:n.form.provided.images.map(e=>({...e,attachmentId:a.get(e.attachmentId)??e.attachmentId}))}}}}function DN(e,t){if(e.draft.id!==t.id)return e;let n=t.document.form.provided,r=new Set([n.audio,n.thumbnail,n.shortsMusic,n.ambientBed,...n.images].flatMap(e=>e?[e.attachmentId]:[]));return{...e,attachments:e.attachments.filter(e=>r.has(e.id)).map(e=>{let n=t.view?.attachments.find(t=>t.id===e.id);return(e.state===`pending`||e.state===`copying`)&&(n?.state===`ready`||n?.state===`reattach`)?n:e})}}function ON(e,t){let n={...hM,...e},r=t.audio===`off`?`off`:(t.video===`off`||t.images===`off`)&&n.mode===`burn-in`?`files`:n.mode;if(r!==`off`)return{...n,mode:r};let i=mM.shape.fontId.safeParse(n.fontId),a=mM.shape.fontSize.safeParse(n.fontSize);return{...n,mode:r,fontId:i.success?i.data:hM.fontId,fontSize:a.success?a.data:hM.fontSize}}function kN(e){return e.mode===`off`||e.fontId!==``&&Number.isInteger(e.fontSize)&&e.fontSize>=16&&e.fontSize<=120}function AN(e){return e===`shortsMusic`||e===`ambientBed`?`audio`:e}function jN(e){return e.shorts?.enabled===!0&&e.sources.audio!==`off`}function MN(e){return e.ambientBed?.source===`upload`&&e.sources.video===`generate`&&e.sources.audio!==`off`}function NN(e){let t=e=>e.trim()===``?NaN:Number(e);return{enabled:e.enabled,count:t(e.count),minSeconds:t(e.minSeconds),maxSeconds:t(e.maxSeconds),...e.prompt.trim()?{prompt:e.prompt}:{},...e.imagePrompt.trim()?{imagePrompt:e.imagePrompt}:{},...qk(e)}}({...gN.form}),{...gN.form.sources};var PN={off:`Off`,generate:`Generate`,provide:`Provide`,from_prompt:`From prompt`,prompt_by_llm:`Prompt by LLM`};function FN(e){return $A[e].map(e=>({value:e,label:PN[e]}))}function IN(e,t){return cj(zN({form:e,entries:t,slots:[],silenceGapSeconds:0}))}function LN(e,t,n){if(n!==``)return e.find(e=>e.category===t&&e.name===n)?.mode}function RN(e){return[e.audio,e.thumbnail,e.shortsMusic,e.ambientBed,e.reference,...e.images].flatMap(e=>e?.file===void 0?[]:[e.file])}function zN(e){let{form:t}=e;return{...t.checkpoints===void 0?{}:{checkpoints:t.checkpoints},title:t.title,format:t.format,sources:{...t.sources,...t.sources.article===`provide`?{research:`off`}:{},...t.sources.images===`off`?{video:`off`}:{}},llm:t.llm,audio:t.audio,images:t.images,...t.sources.images===`generate`&&t.reference!==void 0&&t.reference.source!==`off`?{reference:{source:t.reference.source,...t.reference.source===`prompt`?{prompt:t.reference.prompt}:{},thumbnail:t.reference.thumbnail}}:{},articlePrompt:t.articlePrompt,...t.narrationPrompt===void 0?{}:{narrationPrompt:t.narrationPrompt},...t.language===void 0||t.language===`en`?{}:{language:t.language},...t.sources.video===`generate`&&t.sources.images!==`off`&&t.sources.audio===`generate`&&t.audio.describeFigures===!0&&t.showFigures===!0?{showFigures:!0}:{},...t.sources.audio!==`off`&&t.youtubeDescription===!0?{youtubeDescription:!0,...t.descriptionPrompt?.trim()?{descriptionPrompt:t.descriptionPrompt}:{}}:{},...jN(t)&&t.shorts!==void 0?{shorts:NN(t.shorts)}:{},imagePrompts:t.imagePrompts,thumbnailPrompt:t.thumbnailPrompt,...t.thumbnailCount===3&&(t.sources.thumbnail===`from_prompt`||t.sources.thumbnail===`prompt_by_llm`)?{thumbnailCount:3}:{},...BN(VN(e,`intro`),e=>({intro:e})),...BN(VN(e,`outro`),e=>({outro:e})),values:HN(t.values,e.slots),provided:{research:t.provided.research,article:t.provided.article,...BN(t.provided.audio?.file,e=>({audio:e.id})),...BN(t.provided.thumbnail?.file,e=>({thumbnail:e.id})),...BN(t.sources.images===`generate`&&t.reference?.source===`provide`?t.provided.reference?.file:void 0,e=>({reference:e.id})),images:t.provided.images.flatMap(e=>e.file===void 0?[]:[e.file.id]),...jN(t)?BN(t.provided.shortsMusic?.file,e=>({shortsMusic:e.id})):{},...t.ambientBed?.source===`upload`?BN(t.provided.ambientBed?.file,e=>({ambientBed:e.id})):{}},chunking:t.chunking,subtitles:ON(t.subtitles,t.sources),silenceGapSeconds:e.silenceGapSeconds,imageSeconds:t.imageSeconds,edgeSilenceSeconds:t.edgeSilenceSeconds,zoomPercent:t.zoomPercent,motionStyle:t.motionStyle,...t.videoEdit===void 0?{}:{videoEdit:t.videoEdit},...t.voices!==void 0&&t.sources.audio===`generate`?{voices:t.voices}:{},...t.sources.document===`generate`?{document:t.document}:{},...BN(t.sources.video===`generate`&&t.sources.audio!==`off`?aA(t.ambientBed):void 0,e=>({ambientBed:e})),...t.sources.audio===`generate`?Sk(t):{},...BN(t.sources.audio===`off`?void 0:pk(t.loudness,e.loudness??tk),e=>({loudness:e}))}}function BN(e,t){return e===void 0?{}:t(e)}function VN(e,t){if(e.form.sources.audio!==`generate`)return;let n=t===`intro`?e.form.intro:e.form.outro,r=LN(e.entries,t,n);return n===``||r===void 0?void 0:{name:n,mode:r}}function HN(e,t){let n=Object.create(null);for(let r of t)n[r]=Object.hasOwn(e,r)?e[r]??``:``;return n}function UN(e,t){return e?.draftId===t.draftId&&e.version===t.version&&e.editGeneration===t.editGeneration}function WN({api:e,queryClient:t,current:n,flush:r,resave:i,render:a}){let o={receipt:null,pending:!1,starting:!1,uncertain:!1,valid:!1,error:null,fields:[],created:null},s,c=0,l=0,u=null,d=e=>{o={...o,...e},a()},f=()=>({draftId:n().id??``,version:n().clock.version,editGeneration:n().clock.edited}),p=()=>UN(s,f())&&n().clock.edited===n().clock.acknowledged&&o.receipt?.runs.length===GN(n().document),m=(e=!1)=>{c++,s=void 0,d({valid:!1,...e?{fields:[],error:null}:{}})},h=e=>d({error:e.message,fields:e.fields,valid:!1}),g=e=>{u=null,d({created:e,uncertain:!1,starting:!1,valid:!1})},_=async()=>{let t=u?.draftId;if(!t)return;let n=await $M(e,t);if(!n.ok){h(n);return}n.value.start&&g(n.value.start)};return{reset:()=>{c++,l++,s=void 0,u=null,o={receipt:null,pending:!1,starting:!1,uncertain:!1,valid:!1,error:null,fields:[],created:null},a()},state:()=>({...o,valid:o.valid&&p()}),invalidate:m,restore:e=>{c++,l++,s=void 0,u=e.pendingStart?{draftId:e.draft.id,baseVersion:e.pendingStart.draftVersion,reviewId:e.pendingStart.reviewId}:null,o={receipt:null,pending:!1,starting:!1,uncertain:u!==null,valid:!1,error:null,fields:[],created:e.start},a()},review:async()=>{if(o.pending||o.starting||o.uncertain||o.created)return;let a=++l;d({pending:!0,valid:!1,error:null,fields:[]});try{if(await Promise.all([mN(e,t),t.refetchQueries({queryKey:[`provider-models`]})]),a!==l||!await r()||!n().id)return;let o=f(),u=c,p=await rN(e,{id:o.draftId,baseVersion:o.version});if(a!==l||u!==c||!UN(o,f()))return;if(!p.ok){h(p);return}if(p.value.draftId!==o.draftId||p.value.draftVersion!==o.version)return;let m=GN(n().document);if(p.value.runs.length!==m){d({receipt:null,valid:!1,error:`The saved draft has ${KN(p.value.runs.length)}, but this page shows ${m}. Slopify saved this page again. Press Refresh review, then start.`}),i();return}s=o,d({receipt:p.value,valid:!0})}catch(e){a===l&&d({error:e instanceof Error?e.message:`This setup couldn't be checked. Press Refresh review to try again.`})}finally{a===l&&d({pending:!1})}},start:async()=>{if(o.starting||o.created||!u&&(!o.valid||!p()||o.pending||!o.receipt||YN(n().document,n().view)!==void 0)||(!u&&o.receipt&&(u={draftId:o.receipt.draftId,baseVersion:o.receipt.draftVersion,reviewId:o.receipt.id}),!u))return;let t=u;fN(t.draftId),d({starting:!0,error:null});try{if(o.uncertain&&(await _(),o.created))return;let n=await iN(e,t);if(n.ok){g(n.value);return}n.reason===`pending-start`||n.reason===`already-started`?(d({uncertain:!0}),await _()):(u=null,d({uncertain:!1}),h(n))}catch(e){d({uncertain:!0,valid:!1,error:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the start`)} The run may already have started. Press Check Start result to find out before trying again.`})}finally{d({starting:!1})}}}}function GN(e){return e.variants.length+1}function KN(e){return e===1?`1 video`:`${e} videos`}function qN(e,t){if(e.starting)return`Starting…`;if(e.uncertain)return`Check Start result`;let n=e.valid&&e.receipt?e.receipt.runs.length:GN(t);return n===1?`Start run`:JN(t)?`Queue ${n} videos`:`Start ${n} videos`}function JN(e){return e.queue!==!1}function YN(e,t){if(e.fontUpload!==null)return`subtitles.fontUpload`;let{sources:n,provided:r}=e.form;return[...n.audio===`provide`&&r.audio?[{ref:r.audio,field:`provided.audio`}]:[],...n.thumbnail===`provide`&&r.thumbnail?[{ref:r.thumbnail,field:`provided.thumbnail`}]:[],...n.images===`provide`?r.images.map((e,t)=>({ref:e,field:`provided.images.${t}`})):[],...jN(e.form)&&r.shortsMusic?[{ref:r.shortsMusic,field:`shorts.music`}]:[],...MN(e.form)&&r.ambientBed?[{ref:r.ambientBed,field:`ambientBed.file`}]:[]].find(({ref:e})=>t?.attachments.find(t=>t.id===e.attachmentId)?.state!==`ready`)?.field}function XN(e,t){return e?.draftId===t.draftId&&e.attachmentId===t.attachmentId}function ZN({api:e,queryClient:t,state:n,edit:r,flush:i,generation:a,publish:o,render:s}){let c=(0,m.useRef)(0),l=(0,m.useRef)(null),u=(0,m.useRef)(null),d=(0,m.useRef)(new Map),f=(0,m.useRef)(new Map),p=e=>{let t=n.current.document.form.provided,r=[t.audio,t.thumbnail,t.shortsMusic,t.ambientBed,t.reference,...t.images].find(t=>t?.attachmentId===e.attachmentId);return XN(r&&n.current.id?{draftId:n.current.id,attachmentId:r.attachmentId}:void 0,e)};(0,m.useEffect)(()=>{for(let[e,t]of d.current)t!==a()&&d.current.delete(e);for(let[e,t]of f.current)(!p(t.owner)||t.generation!==a())&&(t.controller.abort(),f.current.delete(e))}),(0,m.useEffect)(()=>{let e=f.current,t=d.current;return()=>{c.current++,t.clear();for(let t of e.values())t.controller.abort();e.clear()}},[]);let h=async(t,l,u)=>{if(l.length===0)return;let m=AN(t),h=m===`images`&&!u?l:l.slice(-1),g=h.map(e=>({attachmentId:crypto.randomUUID(),name:e.name})),_=c.current,v=a();for(let e of g)d.current.set(e.attachmentId,v);let y=n.current.document,b=y.form.provided;r({...y,form:{...y.form,provided:m===`images`?{...b,images:u?b.images.flatMap(e=>e.attachmentId===u?g:[e]):[...b.images,...g]}:{...b,[t]:g.at(-1)??null}}});let x=await i();for(let e of g)d.current.delete(e.attachmentId);if(!x||v!==a()||_!==c.current){s();return}let S=n.current.id;S&&await Promise.all(g.map(async(t,r)=>{let i=h[r],s={draftId:S,attachmentId:t.attachmentId};if(!i||!p(s))return;let l=new AbortController;f.current.set(t.attachmentId,{owner:s,controller:l,generation:v});let u=e=>{let r=n.current.view;v===a()&&_===c.current&&r?.draft.id===S&&p(s)&&!l.signal.aborted&&o({view:{...r,review:null,attachments:[...r.attachments.filter(e=>e.id!==t.attachmentId),e]}})};try{let n=await oN(e,S,t.attachmentId,i,l.signal);n.ok?u(n.value):u({id:t.attachmentId,kind:m,name:t.name,state:`reattach`,stagedFileId:null,bytes:0,error:n.message})}catch(e){u({id:t.attachmentId,kind:m,name:t.name,state:`reattach`,stagedFileId:null,bytes:0,error:e instanceof Error?e.message:`Reattach this file`})}finally{f.current.delete(t.attachmentId)}}))},g=e=>{l.current=null;let t=n.current.document;r({...t,fontUpload:null,form:{...t.form,subtitles:{...t.form.subtitles,fontId:e}}})},_=async o=>{let d=crypto.randomUUID();l.current=d,r({...n.current.document,fontUpload:{operationId:d,name:o.name}});let f=c.current,p=a();if(!await i()||p!==a()||f!==c.current){l.current===d&&(l.current=null),s();return}if(n.current.document.fontUpload?.operationId===d)try{let{font:r}=await lN(e,o);if(p!==a()||f!==c.current||n.current.document.fontUpload?.operationId!==d)return;t.setQueryData(sN,e=>({fonts:[...(e?.fonts??[]).filter(e=>e.id!==r.id),r]})),g(r.id),await i()}catch(e){p===a()&&f===c.current&&n.current.document.fontUpload?.operationId===d&&(u.current={operationId:d,message:e instanceof Error?e.message:`Reattach this font`},s())}finally{l.current===d&&(l.current=null,s())}},v=l.current!==null&&l.current===n.current.document.fontUpload?.operationId;return{attachmentUploading:e=>{let t=f.current.get(e);return d.current.get(e)===a()||t!==void 0&&t.generation===a()&&p(t.owner)&&!t.controller.signal.aborted},fontUpload:{pending:v,error:u.current?.operationId===n.current.document.fontUpload?.operationId?u.current?.message:void 0,pick:e=>{_(e)}},attach:h,selectFont:g,uploadSubtitleFont:_,fontUploading:v}}function QN(e,t,n){(0,m.useEffect)(()=>{let r=e=>[`prompts`,`entries`,`providers`,`provider-models`,`fonts`,`settings`].includes(String(e[0])),i=t.getQueryCache().subscribe(e=>{e.type===`updated`&&r(e.query.queryKey)&&(e.action.type===`success`||e.action.type===`invalidate`)&&n.invalidate()}),a=()=>{n.invalidate(),mN(e,t),t.refetchQueries({queryKey:[`provider-models`]})};return window.addEventListener(`focus`,a),()=>{i(),window.removeEventListener(`focus`,a)}},[e,t,n])}function $N(){let{api:e}=z(),t=_(),[,n]=(0,m.useReducer)(e=>e+1,0),r=(0,m.useRef)(TN()),i=(0,m.useMemo)(()=>{let i,a=null,o=!1,s=0,c=!1,l=null,u=!0,d=e=>{r.current={...r.current,...e},u&&n()},f=()=>{clearTimeout(i),i=void 0},p=()=>{t.invalidateQueries({queryKey:[`play-drafts`]})},m=e=>{d({status:`error`,error:e instanceof Error?e.message:`Your latest changes weren't saved. Keep this page open and try again.`})},h=e=>e.ok?!0:(d({status:e.reason===`conflict`?`conflict`:`error`,error:e.message}),!1),g=e=>{b.restore(e),d({...TN(),document:e.draft.document,view:e,id:e.draft.id,clock:{edited:0,acknowledged:0,version:e.draft.version},status:`saved`}),fN(e.draft.id),p()},_=async()=>{let t=s;for(;r.current.clock.edited>r.current.clock.acknowledged;){if(r.current.status===`conflict`||t!==s||l!==null&&l===r.current.id)return!1;let n=r.current,i=n.id??crypto.randomUUID(),a=n.pending??wN(n.document,n.clock,crypto.randomUUID());d({id:i,pending:a,status:`saving`,error:null});try{let n=a.baseVersion===0?await QM(e,{id:i,document:a.document}):await eN(e,{id:i,baseVersion:a.baseVersion,mutationId:a.mutationId,document:a.document});if(t!==s)return!1;if(!h(n))return n.reason!==`conflict`&&d({pending:null}),!1;let c=CN(r.current.clock,{type:`acknowledge`,generation:a.generation,version:n.value.draft.version});if(d({clock:c,view:{...DN(n.value,r.current),review:c.edited>c.acknowledged?null:n.value.review},pending:null,status:c.edited>c.acknowledged?`unsaved`:`saved`,error:null}),fN(i),p(),!o)return!0}catch(e){return t===s&&m(e),!1}}return r.current.status!==`conflict`&&r.current.status!==`error`},v=()=>c?Promise.resolve(!1):a||(r.current.clock.edited===r.current.clock.acknowledged?Promise.resolve(!0):l!==null&&l===r.current.id?Promise.resolve(!1):(a=_().finally(()=>{a=null}),a)),y=()=>(f(),o=!0,v()),b=WN({api:e,queryClient:t,current:()=>r.current,flush:y,resave:()=>x(r.current.document),render:()=>{u&&n()}}),x=e=>{if(b.state().starting||b.state().uncertain||b.state().created)return;b.invalidate(JSON.stringify({...e,section:r.current.document.section})!==JSON.stringify(r.current.document));let t=r.current;d({document:e,clock:CN(t.clock,{type:`edit`}),view:t.view?{...t.view,review:null}:null,status:t.status===`conflict`||t.status===`error`?t.status:`unsaved`}),f(),!(c||l!==null&&l===t.id||t.status===`conflict`||t.status===`error`)&&(t.id?i=setTimeout(()=>{y()},500):(o=!1,v()))},S=async(n,i=()=>!0)=>{if(b.state().starting||b.state().uncertain||b.state().created||(r.current.id!==n||r.current.status!==`conflict`)&&!await y()||!i())return!1;let a=++s,o=r.current.clock.edited;f();try{let c=await $M(e,n);return a!==s||o!==r.current.clock.edited||!i()?!1:h(c)?(T=null,g(c.value),await mN(e,t),i()):(r.current.id||d({recoveryId:n}),!1)}catch(e){return a===s&&o===r.current.clock.edited&&(m(e),r.current.id||d({recoveryId:n})),!1}},C=async()=>{if(b.state().starting||b.state().uncertain||b.state().created)return;let e=s;await y()&&e===s&&(s++,T=null,d(TN()),b.reset(),fN(null))},w=async({id:t,version:n})=>{if(b.state().starting||b.state().uncertain||b.state().created)throw Error(`Resolve the pending Start before discarding a draft`);if(c||l!==null)throw Error(`Wait for the current draft operation before discarding`);let i=s;l=t,(r.current.id??r.current.recoveryId)===t&&f();try{a&&await a;let o=await nN(e,{id:t,baseVersion:n});if(!o.ok&&o.reason!==`not-found`)throw Error(o.message);if(p(),i!==s||(r.current.id??r.current.recoveryId)!==t)return;f(),s++,T=null,d(TN()),b.reset(),fN(null)}finally{l=null}},T=null;return{review:b,takeCreated:()=>{let e=b.state().created;if(!e)return null;s++,d(TN()),b.reset(),fN(null);for(let e of[[`projects`],[`staging`],[`play-drafts`]])t.invalidateQueries({queryKey:e});return e},edit:x,flush:y,open:S,newDraft:C,adoptDefaults:e=>{let t=r.current;if(t.id!==null||t.clock.edited>0||t.view!==null)return;let n=yN(t.document,e);n!==t.document&&d({document:n})},discard:w,saveAsNew:async()=>{if(b.state().starting||b.state().uncertain||b.state().created||(f(),c||l!==null))return;a&&await a;let t=r.current;if(!t.id||!t.view&&t.status!==`conflict`){await y();return}let n=s;T?.sourceId!==t.id&&(T=null),T??={sourceId:t.id,id:crypto.randomUUID(),document:wN(t.document,t.clock,crypto.randomUUID()).document,generation:t.clock.edited};let i=T;c=!0;try{let t=await tN(e,{sourceId:i.sourceId,id:i.id,document:i.document});if(n!==s)return;if(!h(t)){t.reason===`conflict`&&(T=null);return}let a=r.current.clock.edited>i.generation?r.current.document:null;s++,g(t.value),T=null,c=!1,a&&x(EN(i.document,t.value.draft.document,a))}catch(e){n===s&&m(e)}finally{c=!1}},navigate:async(e,t)=>{let n=s,i={...r.current.document,section:e};r.current.id||r.current.clock.edited>0?x(i):d({document:i}),await y()&&n===s&&d({reveal:{section:e,...t===void 0?{}:{field:t},sequence:(r.current.reveal?.sequence??0)+1}})},generation:()=>s,publish:d,start:()=>{u=!0;let e=pN();e&&S(e)},stop:()=>{u=!1,f()}}},[e,t]);(0,m.useEffect)(()=>(i.start(),i.stop),[i]),QN(e,t,i.review);let a=ZN({api:e,queryClient:t,state:r,edit:i.edit,flush:i.flush,generation:i.generation,publish:i.publish,render:n}),o=r.current;return{...a,review:i.review.state(),reviewDraft:i.review.review,startRun:i.review.start,invalidateReview:i.review.invalidate,takeCreated:i.takeCreated,document:o.document,section:o.document.section,view:o.view,status:o.status,error:o.error,edited:o.clock.edited,acknowledged:o.clock.acknowledged,reveal:o.reveal,edit:i.edit,flush:i.flush,open:i.open,generation:i.generation,newDraft:i.newDraft,adoptDefaults:i.adoptDefaults,discard:i.discard,saveAsNew:i.saveAsNew,navigate:i.navigate,activeId:o.id??o.recoveryId}}var eP=(0,m.createContext)(null);function tP({children:e}){let t=$N();return(0,h.jsx)(eP.Provider,{value:t,children:e})}function nP(){return(0,m.useContext)(eP)}function rP(){let e=(0,m.useContext)(eP);if(!e)throw Error(`PlayDraftProvider is required`);return e}var iP=(0,m.createContext)(void 0);function aP({children:e}){let[t,n]=(0,m.useState)(()=>new Map),r=(0,m.useCallback)((e,t)=>{n(n=>{let r=n.get(e),i=typeof t==`function`?t(r):t;if(r===i)return n;let a=new Map(n);return i===void 0?a.delete(e):a.set(e,i),a})},[]),i=(0,m.useMemo)(()=>({prompts:t,updatePrompt:r}),[t,r]);return(0,h.jsx)(iP.Provider,{value:i,children:e})}function oP(e){let t=(0,m.useContext)(iP),[n,r]=(0,m.useState)(void 0),i=t?.updatePrompt,a=(0,m.useCallback)(t=>{i?i(e,t):r(t)},[e,i]);return[t?t.prompts.get(e):n,a]}function sP(e){return e.trim()===``?NaN:Number(e)}function cP(){let e=rP(),t=(0,m.useRef)(e);t.current=e;let n=e.document.form,r=t=>{if(!t)return;let n=e.view?.attachments.find(e=>e.id===t.attachmentId),r=n?.state===`ready`&&n.stagedFileId?{id:n.stagedFileId,stageKind:n.kind===`reference`?`images`:n.kind,path:n.stagedFileId,originalFilename:n.name,bytes:n.bytes,state:`staged`,createdAt:e.view?.draft.createdAt??``}:void 0;return{key:t.attachmentId,name:t.name,file:r,error:n?.error??(n?.state===`reattach`||!r&&!e.attachmentUploading(t.attachmentId)?`Reattach this file`:void 0)}},i={...n,sources:{...n.sources,document:RS(n.sources,`document`)},document:{theme:YS(n.document),...n.document?.custom===void 0?{}:{custom:n.document.custom}},imagePrompts:n.imagePrompts.map(e=>({...e,number:Number(e.number)})),chunking:n.chunking.mode===`words`?{mode:`words`,...n.chunking.words===``?{}:{words:Number(n.chunking.words)}}:n.chunking.mode===`characters`?{mode:`characters`,...n.chunking.characters===``?{}:{characters:Number(n.chunking.characters)}}:{mode:n.chunking.mode},subtitles:{...n.subtitles,fontSize:Number(n.subtitles.fontSize)},imageSeconds:sP(n.imageSeconds),edgeSilenceSeconds:sP(n.edgeSilenceSeconds),zoomPercent:sP(n.zoomPercent),provided:{research:n.provided.research,article:n.provided.article,audio:r(n.provided.audio),thumbnail:r(n.provided.thumbnail),...n.provided.reference===void 0?{}:{reference:r(n.provided.reference)},shortsMusic:r(n.provided.shortsMusic),ambientBed:r(n.provided.ambientBed),images:n.provided.images.flatMap(e=>{let t=r(e);return t?[t]:[]})}},a=(0,m.useRef)(i);return a.current=i,[i,(0,m.useCallback)(e=>{let n=t.current.document,r=typeof e==`function`?e(a.current):e;a.current=r;let i=(e,t)=>e===void 0?``:Object.is(e,Number(t))?t:String(e),o=e=>e?{attachmentId:e.key,name:e.name}:null,{document:s,...c}=r.sources,{document:l,...u}=r,{shortsMusic:d,ambientBed:f}=r.provided,p=n.form.sources.document!==void 0||s!==`off`,m=n.form.document!==void 0||l.theme!==YS(n.form.document)||l.custom!==void 0;t.current.edit({...n,form:{...u,sources:p?r.sources:c,...m?{document:l}:{},imagePrompts:r.imagePrompts.map(e=>({...e,number:i(e.number,n.form.imagePrompts.find(t=>t.name===e.name)?.number??String(e.number))})),chunking:{...n.form.chunking,mode:r.chunking.mode,...r.chunking.mode===`words`?{words:i(r.chunking.words,n.form.chunking.words)}:{},...r.chunking.mode===`characters`?{characters:i(r.chunking.characters,n.form.chunking.characters)}:{}},subtitles:{...n.form.subtitles,...r.subtitles,fontSize:i(r.subtitles.fontSize,n.form.subtitles.fontSize)},imageSeconds:Object.is(r.imageSeconds,sP(n.form.imageSeconds))?n.form.imageSeconds:String(r.imageSeconds),edgeSilenceSeconds:Object.is(r.edgeSilenceSeconds,sP(n.form.edgeSilenceSeconds))?n.form.edgeSilenceSeconds:String(r.edgeSilenceSeconds),zoomPercent:Object.is(r.zoomPercent,sP(n.form.zoomPercent))?n.form.zoomPercent:String(r.zoomPercent),provided:{research:r.provided.research,article:r.provided.article,audio:o(r.provided.audio),thumbnail:o(r.provided.thumbnail),...r.provided.reference===void 0&&n.form.provided.reference===void 0?{}:{reference:o(r.provided.reference)},images:r.provided.images.map(e=>({attachmentId:e.key,name:e.name})),...d!==void 0||n.form.provided.shortsMusic!==void 0?{shortsMusic:o(d)}:{},...f!==void 0||n.form.provided.ambientBed!==void 0?{ambientBed:o(f)}:{}}}})},[])]}var lP={newVideo:[`C`],goHome:[`G`,`H`],goProjects:[`G`,`P`],goCalendar:[`G`,`C`],goSchedules:[`G`,`S`],goLibrary:[`G`,`L`],goChannels:[`G`,`K`],goSettings:[`G`,`,`],nextAction:[`Shift`,`N`],copyDescription:[`Shift`,`D`],reviewSetup:[`Ctrl`,`Enter`],save:[`Ctrl`,`S`]},uP=`slopify.notifications.browser`,dP=`slopify.notifications.sent`,fP=6e4,pP=new Set;function mP(){return typeof window<`u`&&`Notification`in window}function hP(){return mP()?Notification.permission:`unsupported`}function gP(){try{return window.localStorage.getItem(uP)===`on`}catch{return!1}}function _P(e){try{e?window.localStorage.setItem(uP,`on`):window.localStorage.removeItem(uP)}catch{}for(let e of pP)e()}function vP(e){pP.add(e);let t=t=>{t.key===uP&&e()};return window.addEventListener(`storage`,t),()=>{pP.delete(e),window.removeEventListener(`storage`,t)}}function yP(){return gP()&&hP()===`granted`}function bP(e){if(e===`unsupported`)return`This browser can't show notifications. Use a current Chrome, Edge, Firefox or Safari, or set a Notification URL below instead.`;if(e===`denied`)return`Notifications are blocked for this site. Allow them in your browser's site settings (the icon left of the address bar), reload, then turn Browser notifications on again.`}async function xP(){return mP()?Notification.permission==="default"?await Notification.requestPermission():Notification.permission:`unsupported`}async function SP(e,t=Date.now){let n=()=>{let n={};try{let e=JSON.parse(window.localStorage.getItem(dP)??`{}`);typeof e==`object`&&e&&(n=Object.fromEntries(Object.entries(e).filter(e=>typeof e[1]==`number`&&t()-e[1]<fP)))}catch{}if(n[e]!==void 0)return!1;try{window.localStorage.setItem(dP,JSON.stringify({...n,[e]:t()}))}catch{}return!0};try{if(typeof navigator<`u`&&navigator.locks!==void 0)return await navigator.locks.request(`slopify-run-notification`,n)}catch{}return n()}function CP(e,t){let n=new Notification(e.text.headline,{body:e.text.detail,tag:`slopify-run-${e.projectId}`});n.onclick=()=>{window.focus(),t(e.projectId),n.close()}}function wP(e,t){let n=new Notification(e.text.headline,{body:e.text.detail,tag:`slopify-topics-${e.scheduleId}`});n.onclick=()=>{window.focus(),t(),n.close()}}function TP(e,t){let n=e.title.trim()===``?`Untitled project`:e.title.trim(),r=new Notification(`Started: ${n}`,{body:`Slopify is working on it. You'll hear a different chime when it ends.`,tag:`slopify-run-${e.projectId}`});r.onclick=()=>{window.focus(),t(e.projectId),r.close()}}var EP=`slopify.notifications.sound`,DP=new Set;function OP(){try{return window.localStorage.getItem(EP)!==`off`}catch{return!0}}function kP(e){try{e?window.localStorage.removeItem(EP):window.localStorage.setItem(EP,`off`)}catch{}for(let e of DP)e()}function AP(e){DP.add(e);let t=t=>{t.key===EP&&e()};return window.addEventListener(`storage`,t),()=>{DP.delete(e),window.removeEventListener(`storage`,t)}}var jP={start:[[784,0,.16],[1175,.14,.3]],end:[[1047,0,.18],[1319,.16,.18],[1568,.32,.55]]},MP;function NP(){if(typeof window<`u`&&typeof window.AudioContext==`function`)return MP??=new window.AudioContext,MP}function PP(){let e=NP();e?.state===`suspended`&&e.resume().catch(()=>{})}function FP(e){let t=NP();if(t===void 0)return;t.state===`suspended`&&t.resume().catch(()=>{});let n=t.currentTime+.02,r=t.createDynamicsCompressor();r.threshold.value=-3,r.ratio.value=12,r.connect(t.destination);for(let[i,a,o]of jP[e])for(let[e,s,c]of[[1,.9,`sine`],[2,.25,`triangle`]]){let l=t.createOscillator(),u=t.createGain();l.type=c,l.frequency.value=i*e,u.gain.setValueAtTime(1e-4,n+a),u.gain.exponentialRampToValueAtTime(s,n+a+.012),u.gain.exponentialRampToValueAtTime(1e-4,n+a+o),l.connect(u).connect(r),l.start(n+a),l.stop(n+a+o+.05)}}function IP(e,t){if(e===`running`)switch(t){case`done`:return`ready`;case`partial`:return`partial`;case`failed`:return`failed`;case`pending`:return`waiting`;default:return}}var LP={article:`the article`,images:`an image`,narration:`the narration`,thumbnail:`the thumbnail`,shorts:`a short`};function RP(e){let t=e.title.trim()===``?`Untitled project`:e.title.trim(),n=BP(e.reason),r=LP[e.stage]??`an item`,i=`Review needs a decision: ${t}`;return{headline:n===void 0?i:`${i} — ${n}`,detail:`The automatic review flagged ${r} and kept it. Open the project and press Overrule to keep it or Redo to make it again.`}}var zP=140;function BP(e){let t=e?.split(/\r?\n/).map(e=>e.trim()).find(e=>e!==``);if(t!==void 0)return t.length<=zP?t:`${t.slice(0,139).trimEnd()}…`}function VP(e,t){let n=t.title.trim()===``?`Untitled project`:t.title.trim();switch(e){case`ready`:return t.makesVideo?{headline:`Video ready: ${n}`,detail:`Open the project to watch it.`}:{headline:`Run finished: ${n}`,detail:`Open the project to see its files.`};case`partial`:{let e=BP(t.reason),r=t.makesVideo?`Video ready with problems: ${n}`:`Run finished with problems: ${n}`;return{headline:e===void 0?r:`${r} — ${e}`,detail:`Open the project to see which step failed and the button that fixes it.`}}case`failed`:{let e=BP(t.reason);return{headline:e===void 0?`Run failed: ${n}`:`Run failed: ${n} — ${e}`,detail:`Open the project to see what stopped it and press Retry.`}}case`waiting`:return{headline:`Waiting for you: ${n}`,detail:`Open the project to review the held step or press Continue the run.`}}}function HP(e){let t=e.scheduleName.trim()===``?`Untitled schedule`:e.scheduleName.trim(),n=e.added,r=e.waiting>n?` ${String(e.waiting)} are waiting in all.`:``;return{headline:`${String(n)} new ${n===1?`topic is`:`topics are`} waiting for you`,detail:`Open Calendar → Suggested topics → ${t} to queue or reject ${n===1?`it`:`them`}.${r}`}}var UP={headline:`Slopify test notification`,detail:`Notifications work. You'll get one when a run finishes, fails or waits for you, and when a review needs your decision.`},WP=2048;function GP(e){let t=e.trim();if(t===``)return;if(t.length>2048)return`Keep the Notification URL to ${String(WP)} characters or fewer.`;let n;try{n=new URL(t)}catch{return`Enter a full address starting with https:// or http://, for example https://ntfy.sh/your-topic.`}if(n.protocol!==`https:`&&n.protocol!==`http:`)return`The Notification URL must start with https:// or http://.`;if(n.username!==``||n.password!==``)return`Remove the user name and password from the Notification URL; Slopify can't send them.`}var KP=new Set([`done`,`partial`,`failed`,`canceled`]);function qP(e){let t=new Map,n=new Set,r=()=>e.sounds?.()===!0&&e.play!==void 0,i=new Set,a=t=>{let n=t.catch(t=>{e.report(t)}).finally(()=>{i.delete(n)});i.add(n)},o=async(t,n,i)=>{let a=await e.subject(t);a!==void 0&&await e.claim(`${t}:${n}`)&&(r()&&e.play?.(`end`),e.enabled()&&e.show({projectId:t,kind:i,text:VP(i,a)}))},s=async t=>{let n=await e.subject(t);n!==void 0&&await e.claim(`${t}:started`)&&(r()&&e.play?.(`start`),e.enabled()&&e.showStart?.({projectId:t,title:n.title}))};return{observe:i=>{let c=t.get(i.projectId);if(t.set(i.projectId,i.state),c===i.state)return;let l=e.enabled()||r();if(i.state===`running`&&!n.has(i.projectId)){n.add(i.projectId),(r()||e.enabled()&&e.showStart!==void 0)&&a(s(i.projectId));return}KP.has(i.state)&&n.delete(i.projectId);let u=IP(c,i.state);u!==void 0&&l&&a(o(i.projectId,i.state,u))},observeTopics:t=>{if(t.added<=0||!e.enabled()||e.showTopics===void 0)return;let n=e.showTopics;a((async()=>{await e.claim(`topics:${t.scheduleId}:${String(t.waiting)}`)&&n({scheduleId:t.scheduleId,text:HP(t)})})())},observeReview:t=>{if(!e.enabled()||e.showReview===void 0)return;let n=e.showReview;a((async()=>{let r=await e.subject(t.projectId);r!==void 0&&await e.claim(`review:${t.verdictId}`)&&n({projectId:t.projectId,text:RP({title:r.title,stage:t.stage,reason:t.reason})})})())},seed:async()=>{try{for(let r of await e.seed())t.has(r.id)||(t.set(r.id,r.status),(r.status===`running`||r.status===`paused`)&&n.add(r.id))}catch(t){e.report(t)}},settled:async()=>{for(;i.size>0;)await Promise.all([...i])}}}function JP(){let{api:e}=z(),t=_(),n=Zi(),r=(0,m.useRef)(n);r.current=n;let i=(0,m.useMemo)(()=>qP({enabled:yP,sounds:OP,play:FP,showStart:e=>{TP(e,e=>{r.current({to:`/projects/$projectId`,params:{projectId:e}})})},seed:async()=>(await t.fetchQuery({...Yy(e),staleTime:5e3})).projects,subject:async t=>{let n=await jo(e,t);return{title:n.project.title,makesVideo:n.project.config.sources.video!==`off`,reason:n.stages.find(e=>e.state===`failed`)?.failureReason??void 0}},claim:e=>SP(e),showTopics:e=>{wP(e,()=>{r.current({to:`/calendar`})})},showReview:e=>{CP(e,e=>{r.current({to:`/projects/$projectId`,params:{projectId:e}})})},show:e=>{CP(e,e=>{r.current({to:`/projects/$projectId`,params:{projectId:e}})})},report:e=>{console.warn(`Slopify couldn't show a run notification.`,e)}}),[e,t]);return(0,m.useEffect)(()=>{let e=()=>yP()||OP();e()&&i.seed();let t=()=>{e()&&i.seed()},n=vP(t),r=AP(t);return window.addEventListener(`pointerdown`,PP,{once:!0}),window.addEventListener(`keydown`,PP,{once:!0}),()=>{n(),r(),window.removeEventListener(`pointerdown`,PP),window.removeEventListener(`keydown`,PP)}},[i]),i}function YP({open:e,title:t,onClose:n,children:r,footer:i,width:a=`wide`,headingRef:o,className:s}){let c=(0,m.useId)(),l=(0,m.useRef)(null),u=o??l,d=(0,m.useRef)(null),f=(0,m.useRef)(null),p=(0,m.useRef)(n);return(0,m.useEffect)(()=>{p.current=n}),(0,m.useEffect)(()=>{if(!e)return;d.current=document.activeElement,f.current?.contains(document.activeElement)||u.current?.focus({preventScroll:!0});let t=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`[data-slot="dialog-content"][data-state="open"]`)||p.current()};return document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`keydown`,t);let e=d.current;e instanceof HTMLElement&&e.isConnected&&e.focus({preventScroll:!0})}},[e,u]),e?(0,h.jsxs)(`aside`,{ref:f,role:`dialog`,"aria-modal":`false`,"aria-labelledby":c,"data-slot":`drawer`,className:L(`fixed top-0 right-0 bottom-0 z-50 flex w-full flex-col border-l border-line bg-raised shadow-[var(--shadow-dialog)]`,a===`wide`?`sm:w-[min(560px,100vw)]`:`sm:w-[min(440px,100vw)]`,`data-[state=open]:animate-tick-in motion-reduce:animate-none`,s),"data-state":`open`,children:[(0,h.jsxs)(`div`,{className:`flex min-h-12 shrink-0 items-center gap-3 border-b border-line px-4`,children:[(0,h.jsx)(`h2`,{ref:u,id:c,tabIndex:-1,className:`min-w-0 flex-1 truncate text-title-3 font-semibold focus-visible:outline-offset-[-2px]`,children:t}),(0,h.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close`,className:`inline-flex size-8 items-center justify-center rounded-control text-ink-2 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,className:`size-4`})})]}),(0,h.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:r}),i?(0,h.jsx)(`div`,{className:`flex min-h-14 shrink-0 flex-wrap items-center gap-2 border-t border-line px-4 py-2 pb-[max(8px,env(safe-area-inset-bottom))]`,children:i}):null]}):null}var XP=[{id:`text-key`,title:`1. Connect a text provider`,target:`keys-llm`,page:`settings`},{id:`audio-key`,title:`2. Connect a voice provider`,target:`keys-tts`,page:`settings`},{id:`image-key`,title:`3. Connect an image provider`,target:`keys-image`,page:`settings`},{id:`voice`,title:`4. Add a narration voice`,target:`voices`,page:`settings`},{id:`article-name`,title:`5. Name your article prompt`,target:`prompt-name`,page:`article`},{id:`article-body`,title:`6. Write instructions with keywords`,target:`prompt-body`,page:`article`},{id:`article-keywords`,title:`7. Check the detected keywords`,target:`prompt-slots`,page:`article`},{id:`article-save`,title:`8. Save your article prompt`,target:`prompt-save`,page:`article`},{id:`image-prompt`,title:`9. Create an image prompt`,target:`prompt-editor`,page:`image`},{id:`image-save`,title:`10. Save your image prompt`,target:`prompt-save`,page:`image`},{id:`play-options`,title:`11. Name the project and choose text generation`,target:`play-options`,page:`play`},{id:`play-article`,title:`12. Choose your article`,target:`play-article`,page:`play`},{id:`play-keywords`,title:`13. Fill in your keywords`,target:`play-keywords`,page:`play`},{id:`play-audio`,title:`14. Choose narration`,target:`play-audio`,page:`play`},{id:`play-images`,title:`15. Choose images`,target:`play-images`,page:`play`},{id:`play-video`,title:`16. Choose video output`,target:`play-video`,page:`play`},{id:`play-subtitles`,title:`17. Style optional subtitles`,target:`play-subtitles`,page:`play`},{id:`play-start`,title:`18. Review and start your run`,target:`play-start`,page:`play`},{id:`project`,title:`19. Follow and control the run`,target:`project-controls`,page:`project`},{id:`download`,title:`20. Download your results`,target:`project-video`,page:`project`},{id:`run-cost`,title:`21. See what the run cost`,target:`project-rail-cost`,page:`project`},{id:`studio-prep`,title:`22. Prepare the YouTube upload`,target:`project-rail-video`,page:`project`},{id:`home`,title:`23. Check Home each day`,target:`home`,page:`home`},{id:`channels`,title:`24. Set up a channel`,target:`channels`,page:`channels`},{id:`calendar`,title:`25. Plan uploads on the calendar`,target:`calendar`,page:`calendar`}],ZP=`home`;function QP(e,t){return e.active?t.type===`project-created`?{...e,projectId:t.id,step:XP.findIndex(e=>e.id===`project`)}:t.kind===`article`?{...e,articleId:t.id}:t.kind===`image`?{...e,imageId:t.id}:e:e}function $P(e){let t=XP.findIndex(t=>t.id===e);return t<0?void 0:t}var eF={"play-options":`content`,"play-article":`content`,"play-keywords":`content`,"play-audio":`outputs`,"play-images":`outputs`,"play-video":`outputs`,"play-subtitles":`style`,"play-start":`content`};function tF(e){return e.kind===`keyed`?e.hasKey:e.kind===`local`?e.available:e.installed&&e.issue===void 0}var nF={research:`Research`,article:`Article`,audio:`Audio`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`Document`};function rF(e){return e.sources.video===`off`?e.sources.audio===`off`?`article`:`audio`:`video`}function iF(e,t){return e===`video`&&rF(t)===`audio`?`Audio export`:nF[e]}function aF(e,t){return e.kind===`video`&&e.state===`running`&&t.subtitles!==void 0&&t.subtitles.mode!==`off`&&e.progressTotal===100&&(e.progressCurrent??0)<=35}var oF={research:(e,t)=>`chapter ${String(e)} of ${String(t)}`,article:(e,t)=>`${String(e)} of ${String(t)}`,audio:(e,t)=>`chunk ${String(e)} of ${String(t)}`,images:(e,t)=>`image ${String(e)} of ${String(t)}`,thumbnail:(e,t)=>`${String(e)} of ${String(t)}`,video:(e,t)=>`${String(vF(e,t))}% rendered`,document:(e,t)=>`${String(e)} of ${String(t)}`},sF={audio_intro:`intro`,audio_body:`body`,audio_outro:`outro`};function cF(e,t,n,r=!1){let i=t.filter(t=>t.stageKind===e.kind);switch(e.state){case`skipped`:return`Not part of this run`;case`pending`:return n.status===`paused`||r?`Waits until you continue the run`:e.retryAt===void 0?e.kind===`images`||e.kind===`thumbnail`&&e.source===`from_prompt`?`Ready to run`:`Waits for the stages above`:`Trying again at ${fF(e.retryAt)}`;case`provided`:return hF(i)??`Provided`;case`failed`:return`Stopped after ${pF(e)}`;case`canceled`:return`Canceled by user`;case`running`:return aF(e,n.config)?`Preparing subtitles · ${String(vF(e.progressCurrent??0,35))}%`:e.activity===void 0?e.kind===`video`&&rF(n.config)===`audio`?`Exporting combined audio`:e.progressTotal===null||e.progressTotal<=0?`Running`:oF[e.kind](e.progressCurrent??0,e.progressTotal):uF(lF(e)??``);case`done`:return mF(e.kind,i,n)}}function lF(e){let t=e.activity;if(t!==void 0)return t.percent===void 0?t.done!==void 0&&t.total!==void 0?`${t.label} (${String(t.done)} of ${String(t.total)})`:t.label:`${t.label} (${String(t.percent)}%)`}function uF(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function dF(e){let t=e.activity;if(t?.percent!==void 0)return t.percent/100;if(t?.done!==void 0&&t.total!==void 0&&t.total>0)return t.done/t.total;if(t===void 0&&!(e.progressTotal===null||e.progressTotal<=0))return Math.min(1,Math.max(0,(e.progressCurrent??0)/e.progressTotal))}function fF(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function pF(e){return e.attemptCount===1?`1 attempt`:`${String(e.attemptCount)} attempts`}function mF(e,t,n){switch(e){case`research`:return`Notes ready`;case`article`:{let e=t.filter(e=>e.role===`sources`||e.role===`glossary`);return e.length===0?`Article ready`:`Article and ${String(e.length)} end-matter files`}case`audio`:return SF([bF(t.flatMap(e=>{let t=sF[e.role];return t===void 0?[]:[t]})),_F(gF(t))]);case`images`:return yF(t.filter(e=>e.role===`image`).length,`image`);case`thumbnail`:return t.length===0?`Thumbnail ready`:`1 image`;case`video`:return SF([_F(gF(t)),rF(n.config)===`audio`?`WAV · stereo · 48 kHz`:n.format]);case`document`:return`PDF · ${XS(n.config.document)} theme`}}function hF(e){let t=e.flatMap(e=>e.originalFilename===null?[]:[e.originalFilename]);return t.length===0?void 0:t.join(`, `)}function gF(e){let t=Math.max(0,...e.map(e=>e.durationMs??0));return t===0?void 0:t}function _F(e){if(e===void 0||!Number.isFinite(e)||e<=0)return;let t=Math.round(e/1e3),n=[Math.floor(t/60)%60,t%60].map(e=>String(e).padStart(2,`0`)),r=Math.floor(t/3600);return r===0?n.join(`:`):[String(r),...n].join(`:`)}function vF(e,t){return t<=0?0:Math.min(100,Math.max(0,Math.round(e/t*100)))}function yF(e,t){return e===1?`1 ${t}`:`${String(e)} ${t}s`}function bF(e){if(e.length!==0)return e.length===1?xF(e[0]??``):xF(`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]??``}`)}function xF(e){return e.charAt(0).toUpperCase()+e.slice(1)}function SF(e){return e.filter(e=>e!==void 0&&e!==``).join(` · `)}var CF=12,wF=16;function TF(e,t,n){return Math.max(t,Math.min(e,Math.max(t,n)))}function EF(e,t,n){let r=Math.min(n.width,t.width-24),i=TF(e?.left??(t.width-r)/2,CF,t.width-r-CF),a=TF((e?.top??0)+((e?.height??t.height)-n.height)/2,CF,t.height-n.height-CF),o=t.height-n.height-CF;if(!e)return{left:i,top:a,width:r,docked:!1};let s=e.left+e.width,c=e.top+e.height;return s+wF+r<=t.width-CF?{left:s+wF,top:a,width:r,docked:!1}:e.left-wF-r>=CF?{left:e.left-wF-r,top:a,width:r,docked:!1}:c>=CF&&c+wF+n.height<=t.height-CF?{left:i,top:c+wF,width:r,docked:!1}:e.top-wF-n.height>=CF&&e.top<=t.height-CF?{left:i,top:e.top-wF-n.height,width:r,docked:!1}:{left:t.width-r-CF,top:Math.max(CF,o),width:r,docked:!0}}function DF(e,t,n=t.height){let r=TF(e.left-6,0,t.width),i=TF(e.top-6,0,Math.min(n,t.height)),a=TF(e.left+e.width+6,0,t.width),o=TF(e.top+e.height+6,0,Math.min(n,t.height));return a>r&&o>i?{left:r,top:i,width:a-r,height:o-i}:null}var OF=`[data-slot="select-content"], [data-slot="dropdown-menu-content"], [data-slot="menu-content"]`;function kF(e){try{return document.querySelector(e)}catch{return null}}function AF(){return[...document.querySelectorAll(`[data-slot="dialog-content"][data-state="open"]`)].at(-1)??null}function jF(e){if(!e)return[];let t=[e,...e.querySelectorAll(`[aria-controls]`)],n=new Set(t.flatMap(e=>(e.getAttribute(`aria-controls`)??``).split(` `)));return[...document.querySelectorAll(OF)].filter(e=>n.has(e.id))}function MF(e){let t=e.getBoundingClientRect();return t.width>0&&t.height>0?{left:t.left,top:t.top,width:t.width,height:t.height}:null}var NF=`a[href], button, input, select, textarea, summary, [tabindex], [contenteditable="true"]`;function PF(e,t,n,r){let i=(0,m.useRef)(document.activeElement),a=(0,m.useRef)(t);a.current=t,(0,m.useEffect)(()=>{let e=i.current;return()=>{queueMicrotask(()=>{e instanceof HTMLElement&&e.isConnected&&!n.current&&e.focus({preventScroll:!0})})}},[n]),(0,m.useEffect)(()=>{let t=()=>{let t=kF(e);return[t,n.current,...jF(t)].filter(e=>e!==null)},i=e=>e instanceof Node&&t().some(t=>t.contains(e)),o=e=>{AF()||i(e.target)||(e.preventDefault(),e.stopImmediatePropagation())},s=e=>{AF()||i(e.target)||e.target instanceof HTMLElement&&e.target.hasAttribute(`data-radix-focus-guard`)||r.current?.focus({preventScroll:!0})},c=n=>{if(AF())return;let r=jF(kF(e));if(n.key===`Escape`){if(r.length>0)return;n.preventDefault(),n.stopImmediatePropagation(),a.current();return}if(n.key!==`Tab`){i(n.target)||o(n);return}if(r.length>0)return;let s=t().flatMap(e=>[e,...e.querySelectorAll(NF)]).filter((e,t,n)=>n.indexOf(e)===t&&e.tabIndex>=0&&!e.matches(`:disabled, [hidden], [aria-hidden='true']`)&&!e.closest(`[hidden], [inert]`)&&(!e.closest(`details:not([open])`)||e.closest(`summary`)!==null));if(s.length===0)return;let c=s.indexOf(document.activeElement),l=c===-1?n.shiftKey?s.length-1:0:(c+(n.shiftKey?-1:1)+s.length)%s.length;n.preventDefault(),s[l]?.focus()},l=[`pointerdown`,`pointerup`,`mousedown`,`mouseup`,`click`,`dblclick`,`contextmenu`];for(let e of l)window.addEventListener(e,o,!0);return window.addEventListener(`keydown`,c,!0),window.addEventListener(`focusin`,s,!0),()=>{for(let e of l)window.removeEventListener(e,o,!0);window.removeEventListener(`keydown`,c,!0),window.removeEventListener(`focusin`,s,!0)}},[e,n,r])}function FF(e,t,n,r,i,a){let[o,s]=(0,m.useState)(()=>({key:e,target:null,portals:[],width:window.innerWidth,height:window.innerHeight,cardHeight:260,modalOpen:AF()!==null}));return(0,m.useLayoutEffect)(()=>{let o=0,c=0,l=null,u=null,d=new Map,f=new ResizeObserver(()=>h()),p=e=>{for(let[t,n]of d)e.has(t)||(t.style.zIndex=n,d.delete(t))},m=()=>{o=0;let r=kF(t);r!==u&&(u&&f.unobserve(u),r&&f.observe(r),u=r);let i=r?MF(r):null;r&&i&&l!==r&&(l=r,cancelAnimationFrame(c),c=requestAnimationFrame(()=>{c=0,r.isConnected&&(r.scrollIntoView({block:`start`,inline:`nearest`,behavior:`instant`}),m())}));let a=jF(r),h=new Set;for(let e of a){let t=e.closest(`[data-radix-popper-content-wrapper]`)??e;h.add(t),d.has(t)||(d.set(t,t.style.zIndex),t.style.zIndex=`102`)}p(h);let g={key:e,target:i,portals:a.map(MF).filter(e=>e!==null),width:window.innerWidth,height:window.innerHeight,cardHeight:n.current?.getBoundingClientRect().height||260,modalOpen:AF()!==null};s(e=>JSON.stringify(e)===JSON.stringify(g)?e:g)};function h(){o||=requestAnimationFrame(m)}let g=new MutationObserver(e=>{e.some(e=>!i.current?.contains(e.target)&&e.target!==a.current)&&h()});return g.observe(document.body,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`id`,`class`,`style`,`hidden`,`aria-controls`,`data-state`,`data-tour`]}),n.current&&f.observe(n.current),f.observe(document.documentElement),window.addEventListener(`resize`,h),window.addEventListener(`scroll`,h,!0),window.visualViewport?.addEventListener(`resize`,h),window.visualViewport?.addEventListener(`scroll`,h),m(),AF()||r.current?.focus({preventScroll:!0}),()=>{cancelAnimationFrame(o),cancelAnimationFrame(c),f.disconnect(),g.disconnect(),window.removeEventListener(`resize`,h),window.removeEventListener(`scroll`,h,!0),window.visualViewport?.removeEventListener(`resize`,h),window.visualViewport?.removeEventListener(`scroll`,h),p(new Set)}},[e,t,n,r,i,a]),o}function IF({stepId:e,target:t,title:n,children:r,progress:i,onNext:a,onBack:o,onClose:s,nextLabel:c=`Next`,nextDisabled:l=!1,onSkip:u,skipLabel:d=`Skip this step`}){let f=(0,m.useId)(),p=`${e}:${t}`,g=(0,m.useRef)(null),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=(0,m.useRef)(null),b=FF(p,t,g,_,v,y);PF(t,s,g,_);let[x,S]=(0,m.useState)({key:p,height:0}),C=b.key===p?b.target:null,w={width:b.width,height:b.height},T={width:Math.min(360,w.width-24),height:b.cardHeight},E=EF(C,w,T),D=C?DF(C,w,E.docked?E.top-12:w.height):null,O=b.key===p?b.portals.map(e=>DF(e,w)).filter(e=>e!==null):[],k=[...D?[D]:[],...O],A=`M0 0H${w.width}V${w.height}H0Z`+(D?`M${D.left} ${D.top}H${D.left+D.width}V${D.top+D.height}H${D.left}Z`:``);(0,m.useLayoutEffect)(()=>{S(e=>{let t=Math.max(e.key===p?e.height:0,E.docked?T.height+24:0);return e.key===p&&e.height===t?e:{key:p,height:t}})},[p,E.docked,T.height]);let ee=x.key===p?x.height:0;return(0,m.useEffect)(()=>{let e=document.documentElement,t=e.style.scrollPaddingBottom;return e.style.scrollPaddingBottom=`${ee}px`,()=>{e.style.scrollPaddingBottom=t}},[ee]),(0,Zu.createPortal)((0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{ref:y,"aria-hidden":`true`,style:{height:ee}}),(0,h.jsxs)(`div`,{ref:v,hidden:b.modalOpen,"data-tutorial":`spotlight`,className:`pointer-events-none fixed inset-0 z-[100] font-sans`,children:[(0,h.jsxs)(`svg`,{"aria-hidden":`true`,className:`absolute inset-0 h-full w-full`,width:w.width,height:w.height,children:[(0,h.jsx)(`defs`,{children:(0,h.jsxs)(`mask`,{id:`${f}-mask`,children:[(0,h.jsx)(`rect`,{width:`100%`,height:`100%`,fill:`white`}),k.map(e=>(0,h.jsx)(`rect`,{x:e.left,y:e.top,width:e.width,height:e.height,rx:`6`,fill:`black`},`${e.left}:${e.top}:${e.width}:${e.height}`))]})}),(0,h.jsx)(`rect`,{width:`100%`,height:`100%`,fill:`rgb(0 0 0 / 0.72)`,mask:`url(#${f}-mask)`}),(0,h.jsx)(`path`,{d:A,fill:`transparent`,fillRule:`evenodd`,pointerEvents:`fill`}),D&&(0,h.jsx)(`rect`,{"data-tutorial":`hole`,x:D.left,y:D.top,width:D.width,height:D.height,rx:`6`,fill:`none`,stroke:`var(--color-accent)`,strokeWidth:`2`})]}),(0,h.jsxs)(`section`,{ref:g,"aria-label":`Interactive getting started guide`,"aria-describedby":`${f}-instructions`,"data-tutorial":`card`,className:`pointer-events-auto fixed z-[101] flex flex-col gap-3 rounded-media border border-line-strong bg-surface p-4 text-body text-ink shadow-[var(--shadow-pop)]`,style:{left:E.left,top:E.top,width:E.width,maxHeight:Math.min(w.height-24,Math.max(160,Math.min(420,w.height*.48)))},children:[(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`engraved text-accent-ink`,children:[`Getting started · `,i]}),(0,h.jsx)(R,{variant:`quiet`,onClick:s,"aria-label":`Exit guide`,className:`h-7 px-2`,children:`Exit`})]}),(0,h.jsx)(`h2`,{ref:_,id:`${f}-title`,tabIndex:-1,className:`shrink-0 text-title-3 font-bold outline-none`,children:n}),(0,h.jsxs)(`div`,{id:`${f}-instructions`,className:`min-h-0 overflow-y-auto text-ink-2 [&_p+p]:mt-2 [&_code]:text-ink`,children:[r,!C&&(0,h.jsx)(`p`,{role:`status`,className:`mt-3 text-waiting`,children:`This section is not available yet. Wait for the page to load, go back, or exit the guide.`}),E.docked&&C&&(0,h.jsx)(`p`,{className:`mt-3 text-small`,children:`Scroll the page to work through the highlighted section.`})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-t border-line pt-3`,children:[o&&(0,h.jsx)(R,{onClick:o,children:`Back`}),u&&(0,h.jsx)(R,{variant:`quiet`,onClick:u,className:`px-2`,children:d}),(0,h.jsx)(R,{variant:`primary`,onClick:a,disabled:l||!C,className:`ml-auto`,children:c})]})]})]})]}),document.body)}function LF({href:e,children:t}){return(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-ink underline underline-offset-2`,children:t})}function RF({text:e}){let[t,n]=(0,m.useState)(!1),[r,i]=(0,m.useState)(!1);return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(`p`,{className:`select-text rounded-control border border-line-strong bg-raised p-3 text-small leading-relaxed`,children:e}),(0,h.jsx)(R,{onClick:()=>{if(i(!1),!navigator.clipboard){i(!0);return}navigator.clipboard.writeText(e).then(()=>n(!0),()=>i(!0))},children:t?`Copied`:`Copy example`}),r?(0,h.jsx)(`p`,{role:`status`,children:`Select the example above and copy it manually.`}):null]})}var zF={signUp:{label:`platform.openai.com/signup`,url:`https://platform.openai.com/signup`},keyPage:{label:`platform.openai.com/api-keys`,url:`https://platform.openai.com/api-keys`},billing:{label:`Billing`,url:`https://platform.openai.com/settings/organization/billing/overview`},steps:[`Sign up or sign in to the OpenAI platform.`,`Open Billing and buy prepaid credit (new accounts need at least $5 before any call works).`,`Open API keys, choose Create new secret key, and copy it (it is shown once).`,`Paste it here, choose Save, then Test.`],permissions:`A key with All permissions works. A restricted key needs Models: Read (for Test) and Model capabilities: Request (for speech and images). GPT Image models may also need Verify Organization under Settings → Organization → General on the OpenAI platform.`,docs:{label:`OpenAI API docs`,url:`https://developers.openai.com/api/docs/guides/error-codes`}},BF={signUp:{label:`aistudio.google.com`,url:`https://aistudio.google.com`},keyPage:{label:`aistudio.google.com/apikey`,url:`https://aistudio.google.com/apikey`},billing:{label:`Projects → Set up billing`,url:`https://aistudio.google.com/projects`},steps:[`Sign in to Google AI Studio with your Google account.`,`Open Projects and choose Set up billing next to your project: Gemini image models are not available on the free tier.`,`Open API keys, choose Create API key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`Use a key made in AI Studio. An older Google Cloud key must be set to Restrict to Gemini API only, or Google rejects it.`,docs:{label:`Gemini API keys`,url:`https://ai.google.dev/gemini-api/docs/api-key`}},VF={openrouter:{signUp:{label:`openrouter.ai/sign-up`,url:`https://openrouter.ai/sign-up`},keyPage:{label:`openrouter.ai/settings/keys`,url:`https://openrouter.ai/settings/keys`},billing:{label:`Credits`,url:`https://openrouter.ai/settings/credits`},steps:[`Sign up at OpenRouter.`,`Open Credits and buy credit (paid models are charged from it; a negative balance stops even free models).`,`Open Keys, choose Create API key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`Keys have no scopes. If you set a credit limit on the key, keep it above what a run costs.`,docs:{label:`OpenRouter docs`,url:`https://openrouter.ai/docs/api-reference/limits`}},"openai-tts":zF,"openai-image":zF,"google-image":BF,"google-tts":{...BF,steps:[`Sign in to Google AI Studio with your Google account.`,`Open API keys, choose Create API key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`The same Gemini API key as Google images: with one saved there, Gemini voices use it and nothing is needed here. ${BF.permissions}`},fal:{signUp:{label:`fal.ai/login`,url:`https://fal.ai/login`},keyPage:{label:`fal.ai/dashboard/keys`,url:`https://fal.ai/dashboard/keys`},billing:{label:`Billing`,url:`https://fal.ai/dashboard/billing`},steps:[`Sign up at fal.ai.`,`Open Billing and buy credit: fal.ai is prepaid and locks the account when the balance runs out.`,`Open Keys, choose Add key with the API scope, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`The API scope is enough; Slopify does not need an ADMIN key.`,docs:{label:`fal.ai authentication`,url:`https://fal.ai/docs/model-apis/authentication`}},replicate:{signUp:{label:`replicate.com/signin`,url:`https://replicate.com/signin`},keyPage:{label:`replicate.com/account/api-tokens`,url:`https://replicate.com/account/api-tokens`},billing:{label:`Billing`,url:`https://replicate.com/account/billing`},steps:[`Sign in to Replicate.`,`Open Billing and buy credit: Replicate needs credit up front before it runs paid models.`,`Open API tokens, create a token, and copy it (it starts with r8_).`,`Paste it here, choose Save, then Test.`],permissions:`Tokens have no scopes.`,docs:{label:`Replicate billing`,url:`https://replicate.com/docs/topics/billing`}},elevenlabs:{signUp:{label:`elevenlabs.io/app/sign-up`,url:`https://elevenlabs.io/app/sign-up`},keyPage:{label:`elevenlabs.io/app/developers/api-keys`,url:`https://elevenlabs.io/app/developers/api-keys`},steps:[`Sign up at ElevenLabs.`,`Open Developers → API keys, choose Create key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`A restricted key needs Text to Speech access and Models read access (models_read) for Test; Voices read helps when picking voices. Remove any credit quota or IP allowlist that would block this computer.`,docs:{label:`ElevenLabs API keys`,url:`https://elevenlabs.io/docs/api-reference/models/list`}},cartesia:{signUp:{label:`play.cartesia.ai/sign-up`,url:`https://play.cartesia.ai/sign-up`},keyPage:{label:`play.cartesia.ai/keys`,url:`https://play.cartesia.ai/keys`},steps:[`Sign up at Cartesia (the free plan needs no card).`,`Open API Keys, create a key, and copy it (it starts with sk_car_).`,`Paste it here, choose Save, then Test.`],permissions:`Keys have no scopes.`,docs:{label:`Cartesia authentication`,url:`https://docs.cartesia.ai/get-started/authenticate-your-client-applications`}},inworld:{signUp:{label:`platform.inworld.ai/signup`,url:`https://platform.inworld.ai/signup`},keyPage:{label:`platform.inworld.ai/api-keys`,url:`https://platform.inworld.ai/api-keys`},billing:{label:`Billing`,url:`https://platform.inworld.ai/billing`},steps:[`Sign up at the Inworld platform.`,`Open API Keys and choose Generate new key (a Standard key, not Realtime-only).`,`Copy the Base64 credentials value exactly as shown, without encoding it again.`,`Paste it here, choose Save, then Test.`],permissions:`A Standard key covers speech and reading voices. Realtime-only keys do not work.`,docs:{label:`Inworld API keys`,url:`https://docs.inworld.ai/portal/api-keys`}}},HF=[{id:`openrouter`,family:`llm`,displayName:`OpenRouter`,auth:`key`},{id:`claude-code`,family:`llm`,displayName:`Claude Code CLI`,auth:`cli`,binary:`claude`,versionArgs:[`--version`]},{id:`codex`,family:`llm`,displayName:`Codex CLI`,auth:`cli`,binary:`codex`,versionArgs:[`--version`]},{id:`gemini`,family:`llm`,displayName:`Gemini CLI`,auth:`cli`,binary:`gemini`,versionArgs:[`--version`]},{id:`elevenlabs`,family:`tts`,displayName:`ElevenLabs`,auth:`key`},{id:`openai-tts`,family:`tts`,displayName:`OpenAI`,auth:`key`},{id:`cartesia`,family:`tts`,displayName:`Cartesia`,auth:`key`},{id:`inworld`,family:`tts`,displayName:`Inworld`,auth:`key`},{id:`system-voice`,family:`tts`,displayName:`System voice`,auth:`local`},{id:`google-tts`,family:`tts`,displayName:`Google Gemini`,auth:`key`},{id:`fal`,family:`image`,displayName:`fal.ai`,auth:`key`},{id:`replicate`,family:`image`,displayName:`Replicate`,auth:`key`},{id:`openai-image`,family:`image`,displayName:`OpenAI`,auth:`key`},{id:`google-image`,family:`image`,displayName:`Google`,auth:`key`},{id:`codex-image`,family:`image`,displayName:`Codex CLI`,auth:`cli`,binary:`codex`,versionArgs:[`--version`]}],UF=[{name:`Zephyr`,style:`Bright`},{name:`Puck`,style:`Upbeat`},{name:`Charon`,style:`Informative`},{name:`Kore`,style:`Firm`},{name:`Fenrir`,style:`Excitable`},{name:`Leda`,style:`Youthful`},{name:`Orus`,style:`Firm`},{name:`Aoede`,style:`Breezy`},{name:`Callirrhoe`,style:`Easy-going`},{name:`Autonoe`,style:`Bright`},{name:`Enceladus`,style:`Breathy`},{name:`Iapetus`,style:`Clear`},{name:`Umbriel`,style:`Easy-going`},{name:`Algieba`,style:`Smooth`},{name:`Despina`,style:`Smooth`},{name:`Erinome`,style:`Clear`},{name:`Algenib`,style:`Gravelly`},{name:`Rasalgethi`,style:`Informative`},{name:`Laomedeia`,style:`Upbeat`},{name:`Achernar`,style:`Soft`},{name:`Alnilam`,style:`Firm`},{name:`Schedar`,style:`Even`},{name:`Gacrux`,style:`Mature`},{name:`Pulcherrima`,style:`Forward`},{name:`Achird`,style:`Friendly`},{name:`Zubenelgenubi`,style:`Casual`},{name:`Vindemiatrix`,style:`Gentle`},{name:`Sadachbia`,style:`Lively`},{name:`Sadaltager`,style:`Knowledgeable`},{name:`Sulafat`,style:`Warm`}];function WF(e){return HF.flatMap(t=>{let n=t.auth===`key`?VF[t.id]:void 0;return t.family===e&&n!==void 0?[{id:t.id,name:t.displayName,url:n.keyPage.url}]:[]})}function GF({family:e}){return(0,h.jsx)(`p`,{children:WF(e).map((e,t)=>(0,h.jsxs)(`span`,{children:[t===0?null:` · `,(0,h.jsx)(LF,{href:e.url,children:`${e.name} keys`})]},e.id))})}function KF(e){let t=WF(e).map(e=>e.name);return t.length<2?t[0]??``:`${t.slice(0,-1).join(`, `)} or ${t.at(-1)??``}`}function qF({step:e}){switch(e){case`text-key`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`First, choose what will write your scripts. You only need one text provider.`}),(0,h.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5`,children:[(0,h.jsxs)(`li`,{children:[`Sign in to`,` `,(0,h.jsx)(LF,{href:VF.openrouter?.keyPage.url??`https://openrouter.ai`,children:`OpenRouter`}),`, create an API key, and make sure the account can use your chosen model.`]}),(0,h.jsxs)(`li`,{children:[`Paste it into OpenRouter’s `,(0,h.jsx)(`strong`,{children:`API key`}),` field here, press`,` `,(0,h.jsx)(`strong`,{children:`Test`}),` to check it, then `,(0,h.jsx)(`strong`,{children:`Save`}),`.`]})]}),(0,h.jsx)(`p`,{children:`Already using Claude Code, Codex or Gemini CLI? You can use its existing CLI login instead. “Installed” means Slopify found the CLI; sign in through that CLI before generating. If it is missing, enter its executable path and save to check again.`}),(0,h.jsx)(`p`,{className:`text-ink-3`,children:`These are the real Settings controls. The tutorial never reads your key. Skip any step you have already handled.`})]});case`audio-key`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The voice provider turns the finished article into audio. Choose `,KF(`tts`),`; you only need one.`]}),(0,h.jsxs)(`p`,{children:[`Create a key in your provider’s account, enable the API access or credits it requires, then paste the key into its row, press `,(0,h.jsx)(`strong`,{children:`Test`}),` to check it, and press`,` `,(0,h.jsx)(`strong`,{children:`Save`}),`.`]}),(0,h.jsx)(GF,{family:`tts`}),(0,h.jsx)(`p`,{children:`Next, you’ll add the exact voice that this provider should use. Skip voice setup if you plan to provide your own narration or turn Audio Off.`})]});case`image-key`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Choose one image provider (`,KF(`image`),`), create a key in its dashboard, paste it into the matching row, press `,(0,h.jsx)(`strong`,{children:`Test`}),` to check it, and press`,` `,(0,h.jsx)(`strong`,{children:`Save`}),`.`]}),(0,h.jsx)(GF,{family:`image`}),(0,h.jsxs)(`p`,{children:[`A saved key is not a billing check. The selected image model needs available quota. If Google reports `,(0,h.jsx)(`strong`,{children:`limit: 0`}),`, check the key’s project, billing and image-model quota before retrying.`]}),(0,h.jsx)(`p`,{children:`OpenAI’s voice and image rows are saved separately, even when you use the same API key. Skip this step if you plan to provide your own images or turn Images and Thumbnail Off.`})]});case`voice`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5`,children:[(0,h.jsxs)(`li`,{children:[`Enter a `,(0,h.jsx)(`strong`,{children:`Voice name`}),` you will recognize, such as “Travel narrator.”`]}),(0,h.jsxs)(`li`,{children:[`Select the `,(0,h.jsx)(`strong`,{children:`Provider`}),` whose voice key you saved.`]}),(0,h.jsxs)(`li`,{children:[`Copy the exact `,(0,h.jsx)(`strong`,{children:`Voice ID`}),` from that provider’s voice library or documentation.`]}),(0,h.jsxs)(`li`,{children:[`Press `,(0,h.jsx)(`strong`,{children:`Add voice`}),`.`]})]}),(0,h.jsx)(`p`,{children:`The name is your label; the ID tells the provider which voice to use. Slopify checks the ID with the provider when narration runs. A voice is only required when Audio is set to Generate.`})]})}}var JF=`Write a 150-word narration about {{topic}} for {{audience}}. Open with an interesting fact, explain three highlights, and end with one memorable takeaway. Use natural spoken English. Return only the narration, without headings or stage directions.`,YF=`A cinematic editorial photograph of {{topic}}, with natural light, a clear focal point, rich detail, and no text or logos. Compose it for a travel video.`;function XF({step:e,output:t=`video`}){switch(e){case`text-key`:case`audio-key`:case`image-key`:case`voice`:return(0,h.jsx)(qF,{step:e});case`article-name`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`A prompt is a reusable set of instructions. This one will write the narration for each video.`}),(0,h.jsxs)(`p`,{children:[`Give it a recognizable name, such as `,(0,h.jsx)(`strong`,{children:`Short travel narration`}),`. This is the prompt’s library name, not your video’s title.`]}),(0,h.jsx)(`p`,{children:`The next steps will add its instructions and reusable keywords.`})]});case`article-body`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`Tell the model what to write, who it is for, the length, and the style. Put anything you want to change between runs inside double braces.`}),(0,h.jsx)(RF,{text:JF}),(0,h.jsxs)(`p`,{children:[`Paste or write the instructions in `,(0,h.jsx)(`strong`,{children:`Body`}),`. `,(0,h.jsx)(`strong`,{children:`{{topic}}`}),` `,`and `,(0,h.jsx)(`strong`,{children:`{{audience}}`}),` will become fields on Play.`]})]});case`article-keywords`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`This panel detects your keywords as you type. With the example, it should list`,` `,(0,h.jsx)(`strong`,{children:`topic`}),` and `,(0,h.jsx)(`strong`,{children:`audience`}),`.`]}),(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`{{topic}}`}),` is a field name, not the value. You will enter “Albania” on Play later. Repeated names use the same value; names are case-sensitive, so`,` `,(0,h.jsx)(`strong`,{children:`topic`}),` and `,(0,h.jsx)(`strong`,{children:`Topic`}),` are different.`]}),(0,h.jsxs)(`p`,{children:[`There are no automatic keywords: `,(0,h.jsx)(`strong`,{children:`{{title}}`}),` would also ask you for a value. Fix any keyword warnings in Body before saving.`]})]});case`article-save`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Press the highlighted `,(0,h.jsx)(`strong`,{children:`Save`}),` button in the editor. The prompt will appear in your Article library.`]}),(0,h.jsx)(`p`,{children:`The tour continues when the save succeeds and the editor returns to the prompt list. If a name is already taken, go Back and choose another.`})]});case`image-prompt`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Keep `,(0,h.jsx)(`strong`,{children:`Kind`}),` on `,(0,h.jsx)(`strong`,{children:`Image`}),`. Name this prompt`,` `,(0,h.jsx)(`strong`,{children:`Travel imagery`}),`, then enter this example or your own visual instructions.`]}),(0,h.jsx)(RF,{text:YF}),(0,h.jsxs)(`p`,{children:[`Using `,(0,h.jsx)(`strong`,{children:`{{topic}}`}),` in both prompts creates one shared field on Play. Image prompts describe the picture directly; they do not automatically receive your article.`]})]});case`image-save`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Press `,(0,h.jsx)(`strong`,{children:`Save`}),` to add this to your Image library. Next you will combine both prompts on Play.`]}),(0,h.jsx)(`p`,{children:`You can create more prompts later for different subjects, styles, lengths, or languages.`})]});case`play-article`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Play is where you configure one project. Leave `,(0,h.jsx)(`strong`,{children:`Article`}),` on`,` `,(0,h.jsx)(`strong`,{children:`Generate`}),`, then select the article prompt you saved.`]}),(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`Provide`}),` is for an article you already have. For this first run, use Generate and keep the script short. Article is required; every other stage can be Off.`]}),(0,h.jsx)(`p`,{children:`Research starts Off. You can turn it on in a later run for web-grounded notes that are automatically passed to the article writer.`})]});case`play-audio`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Leave `,(0,h.jsx)(`strong`,{children:`Audio`}),` on `,(0,h.jsx)(`strong`,{children:`Generate`}),`. Pick your voice`,` `,(0,h.jsx)(`strong`,{children:`TTS`}),` provider, a `,(0,h.jsx)(`strong`,{children:`TTS model`}),`, then the saved`,` `,(0,h.jsx)(`strong`,{children:`Voice`}),`.`]}),(0,h.jsxs)(`p`,{children:[`Keep `,(0,h.jsx)(`strong`,{children:`Chunking`}),` (under `,(0,h.jsx)(`strong`,{children:`Audio Advanced`}),`) on`,` `,(0,h.jsx)(`strong`,{children:`Whole`}),` for the short example: the narration is sent as one request. Other chunking modes split longer text into pieces. `,(0,h.jsx)(`strong`,{children:`Speakers`}),` is where an audiobook or podcast gets more than one voice; leave it on one voice for now.`]}),(0,h.jsx)(`p`,{children:`Use Provide to upload existing narration, including any intro and outro in that file, or Off to skip narration. Video can still run silently, with each image shown for 5 seconds.`})]});case`play-images`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Leave `,(0,h.jsx)(`strong`,{children:`Images`}),` on `,(0,h.jsx)(`strong`,{children:`Generate`}),`. Choose the image`,` `,(0,h.jsx)(`strong`,{children:`Provider`}),` and `,(0,h.jsx)(`strong`,{children:`Model`}),`, tick your image prompt, and type`,` `,(0,h.jsx)(`strong`,{children:`2`}),` in the number box beside it for a small first run.`]}),(0,h.jsx)(`p`,{children:`The number means separate images made from that same prompt. It does not make one scene per article paragraph. Add more image prompts when you want different scenes.`}),(0,h.jsx)(`p`,{children:`Use Provide for your own images or Off to skip them. Turning Images Off also turns Video Off. Thumbnail remains independent; keep it Off for this first run.`})]});case`play-video`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`On `,(0,h.jsx)(`strong`,{children:`Export`}),`, choose `,(0,h.jsx)(`strong`,{children:`Generate`}),` for an MP4 slideshow. It needs generated or provided images. With Audio Off, the video is silent and each image lasts 5 seconds.`]}),(0,h.jsxs)(`p`,{children:[`Choose `,(0,h.jsx)(`strong`,{children:`Off`}),` to skip video. If Audio is active, Slopify exports one combined `,(0,h.jsx)(`strong`,{children:`WAV`}),` with the intro, body, outro and configured gaps.`]}),(0,h.jsx)(`p`,{children:`If both Audio and Video are Off, download the article and any other enabled outputs individually.`})]});case`play-subtitles`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Subtitles are optional and start `,(0,h.jsx)(`strong`,{children:`Off`}),`. Choose`,` `,(0,h.jsx)(`strong`,{children:`Subtitle files`}),` for SRT and VTT downloads, or`,` `,(0,h.jsx)(`strong`,{children:`Burn into video + files`}),` to keep captions visible in an MP4.`]}),(0,h.jsxs)(`p`,{children:[`English captions are timed locally from your narration with no paid API. First use downloads an approximately `,(0,h.jsx)(`strong`,{children:`95 MB`}),` speech model. Audio must be active; WAV exports support separate subtitle files.`]}),(0,h.jsx)(`p`,{children:`Pick a font or upload a TTF/OTF file, then adjust its size in the preview. Styling applies to burned captions. You can also add or change subtitles on a completed project later without regenerating its narration.`})]});case`play-options`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Enter a `,(0,h.jsx)(`strong`,{children:`Project title`}),`, such as “A quick trip to Albania.” Set the title in Content.`]}),(0,h.jsxs)(`p`,{children:[`Select the text `,(0,h.jsx)(`strong`,{children:`LLM`}),` and `,(0,h.jsx)(`strong`,{children:`Text model`}),`. The model list loads for your provider. Use `,(0,h.jsx)(`strong`,{children:`Refresh`}),` for updated choices or`,` `,(0,h.jsx)(`strong`,{children:`Custom ID`}),`to enter an exact model ID when supported.`]}),(0,h.jsx)(`p`,{children:`Intro and Outro are available in Outputs when Audio is Generate. The LLM controls appear only when an enabled stage needs text generation.`})]});case`play-keywords`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The prompts you picked created these fields. For the examples, enter`,` `,(0,h.jsx)(`strong`,{children:`Albania`}),` for `,(0,h.jsx)(`strong`,{children:`topic`}),` and`,` `,(0,h.jsx)(`strong`,{children:`first-time travelers`}),` for `,(0,h.jsx)(`strong`,{children:`audience`}),`.`]}),(0,h.jsx)(`p`,{children:`Each keyword is asked once, with the prompts that use it named underneath. A keyword both prompts use feeds the article and the images, so changing it changes both for this run.`}),(0,h.jsx)(`p`,{children:`Fill every visible field. Each value must fit on one line and be no more than 200 characters. Your saved prompt keeps its braces so you can reuse it next time.`})]});case`play-start`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`Review the enabled outputs, costs and readiness in Review. If anything is missing, use Back to fix the highlighted section.`}),(0,h.jsxs)(`p`,{children:[`When ready, press the real `,(0,h.jsx)(`strong`,{children:`Start run`}),` or `,(0,h.jsx)(`strong`,{children:`Queue N`}),` `,`button. This creates a project and sends generation requests to your chosen providers, which may charge your account.`]}),(0,h.jsx)(`p`,{children:`The tour will follow you to the project. You can also skip generating and go on to the screens you run a channel from.`})]});case`project`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The rail on the left lists the project's sections: Article, Narration, Images, Video and the rest. The right rail says where the run stands and offers the one thing to do next, named for its result: `,(0,h.jsx)(`strong`,{children:`Pause`}),` while it runs,`,` `,(0,h.jsx)(`strong`,{children:`Continue the run`}),` when it is paused, `,(0,h.jsx)(`strong`,{children:`Try images again`}),` `,`when a step fails.`]}),(0,h.jsxs)(`p`,{children:[`Press `,(0,h.jsx)(`strong`,{children:`Edit settings`}),` to change providers, models, voice, prompts or optional steps. `,(0,h.jsx)(`strong`,{children:`Save changes`}),` keeps a new revision without starting generation; what the change made outdated is then offered as the next action, such as`,` `,(0,h.jsx)(`strong`,{children:`Remake 3 outdated images`}),`. Earlier revisions stay in`,` `,(0,h.jsx)(`strong`,{children:`History`}),`.`]}),(0,h.jsxs)(`p`,{children:[`A failed step says why beside it; open `,(0,h.jsx)(`strong`,{children:`Error details`}),` for the provider's own message. Rare actions, such as making a whole stage again, sit behind each section's`,` `,(0,h.jsx)(`strong`,{children:`More`}),` button and in the command palette (Ctrl+K).`]})]});case`download`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[t===`audio`?(0,h.jsxs)(h.Fragment,{children:[`When Audio export finishes, press `,(0,h.jsx)(`strong`,{children:`Download`}),`, then`,` `,(0,h.jsx)(`strong`,{children:`Audio (.wav)`}),` for the combined narration.`]}):t===`article`?(0,h.jsxs)(h.Fragment,{children:[`Use `,(0,h.jsx)(`strong`,{children:`Download`}),` here to save the article. Audio and Video are Off for this project.`]}):(0,h.jsxs)(h.Fragment,{children:[`When Video finishes, press `,(0,h.jsx)(`strong`,{children:`Download`}),`, then`,` `,(0,h.jsx)(`strong`,{children:`Video (.mp4)`}),`.`]}),` `,`The completed project stays in `,(0,h.jsx)(`strong`,{children:`Projects`}),` so you can return to it.`]}),(0,h.jsxs)(`p`,{children:[`Select Article, Audio or Images in the stage list on the `,(0,h.jsx)(`strong`,{children:`Output`}),` tab to download their outputs. `,(0,h.jsx)(`strong`,{children:`Download all`}),` under Images gives an image ZIP, not the video.`]}),(0,h.jsxs)(`p`,{children:[`If subtitles are enabled, download the `,(0,h.jsx)(`strong`,{children:`.srt`}),` or `,(0,h.jsx)(`strong`,{children:`.vtt`}),` `,`files beside the final export. File-mode captions are also available in the video player.`]})]});case`run-cost`:return(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`Cost`}),` in the project's sections shows what this run really cost, per stage and model. Totals for every project are in Settings, `,(0,h.jsx)(`strong`,{children:`Usage`}),`.`]});case`studio-prep`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Slopify never uploads for you. When the video is made, `,(0,h.jsx)(`strong`,{children:`Prepare upload`}),` `,`is the next action: it lists everything YouTube Studio asks for, in the order it asks, from the file and title to the thumbnail, tags and the AI disclosure.`]}),(0,h.jsxs)(`p`,{children:[`The browser extension in Settings, `,(0,h.jsx)(`strong`,{children:`YouTube Studio`}),`, can fill those in for you.`]})]});case`home`:return(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`Home`}),` is the day at a glance: what needs you, what is running and at which step, what is coming up this week and what is ready to upload.`]});case`channels`:return(0,h.jsxs)(`p`,{children:[`A `,(0,h.jsx)(`strong`,{children:`channel`}),` keeps its brand kit, series brief, templates, schedules and a cast that looks the same in every video. It also remembers finished episodes and your existing videos, so new topics do not repeat them.`]});case`calendar`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The `,(0,h.jsx)(`strong`,{children:`Calendar`}),` shows the coming weeks of uploads: what is ready, what needs you, and the topics a schedule suggested, waiting for your approval. Its`,` `,(0,h.jsx)(`strong`,{children:`Schedules`}),` tab is where you create, pause and resume the schedules that fill it.`]}),(0,h.jsx)(`p`,{children:`You have reached the end. Press the question-mark button at the foot of the sidebar anytime to walk through these steps again, or the book beside it for Help → Tutorials, the guides to every screen.`})]})}}function ZF(e){return tF(e.readiness)}function QF({session:e,progress:t,update:n}){let{api:r}=z(),i=rP(),a=Zi(),o=Ha(),s=N(Qy(r)),c=N(eb(r)),l=N(tb(r)),u=N({...Xy(r,e.projectId??``),enabled:e.projectId!==void 0}),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(null),g=XP[e.step],_=s.data?.seen===!0;if((0,m.useEffect)(()=>{if(!_||!g||p.current===e.step)return;if(p.current=e.step,g.page===`settings`){let e=g.id===`voice`?`voices`:`providers`;(o.pathname!==`/settings`||!o.searchStr.includes(`section=${e}`))&&a({to:`/settings`,search:{section:e}})}if(g.page===`article`||g.page===`image`){let t=g.page===`article`?e.articleId:e.imageId,n=o.pathname===`/prompts/new`&&o.searchStr.includes(`kind=${g.page}`);t&&o.pathname!==`/prompts/${t}`?a({to:`/prompts/$promptId`,params:{promptId:t}}):!t&&!n&&a({to:`/prompts/new`,search:{kind:g.page}})}g.page===`play`&&o.pathname!==`/play`&&a({to:`/play`});let t={home:`/`,channels:`/channels`,calendar:`/calendar`};if(g.page===`home`||g.page===`channels`||g.page===`calendar`){let e=t[g.page];o.pathname!==e&&a({to:e})}g.page===`project`&&e.projectId&&o.pathname!==`/projects/${e.projectId}`&&a({to:`/projects/$projectId`,params:{projectId:e.projectId}})},[_,g,e.step,e.articleId,e.imageId,e.projectId,o.pathname,o.searchStr,a]),(0,m.useEffect)(()=>{if(!_||g?.page!==`play`||o.pathname!==`/play`)return;let e=!0;return f(null),i.navigate(eF[g.id]).then(()=>{e&&f(g.id)}),()=>{e=!1}},[_,g,o.pathname,i.navigate]),(0,m.useEffect)(()=>{o.pathname===`/prompts`&&(g?.id===`image-prompt`&&e.imageId?n(e=>({...e,step:XP.findIndex(e=>e.id===`play-options`)})):(g?.id===`article-save`&&e.articleId||g?.id===`image-save`&&e.imageId)&&n(e=>({...e,step:e.step+1})))},[o.pathname,g?.id,e.articleId,e.imageId,n]),!_||!g||g.page===`play`&&(d!==g.id||i.section!==eF[g.id]))return null;let v=c.data?.providers??[],y=e=>v.some(t=>t.family===e&&ZF(t)),b=(l.data?.voices??[]).some(e=>v.some(t=>t.id===e.provider&&ZF(t))),x={"text-key":y(`llm`),"audio-key":y(`tts`),"image-key":y(`image`),voice:b,"article-name":t.promptIsArticle===!0&&t.promptNamed===!0,"article-body":t.promptIsArticle===!0&&t.promptBodyReady===!0&&t.promptHasKeywords===!0,"article-keywords":t.promptHasKeywords===!0,"article-save":!1,"image-prompt":t.promptIsImage===!0&&t.promptSaveReady===!0&&t.promptHasKeywords===!0,"image-save":!1,"play-article":t.playArticleReady===!0,"play-audio":t.playAudioReady===!0,"play-images":t.playImagesReady===!0,"play-video":t.playVideoReady===!0,"play-subtitles":t.playSubtitlesReady===!0,"play-options":t.playOptionsReady===!0,"play-keywords":t.playKeywordsReady===!0,"play-start":!1},S=()=>n(e=>({...e,active:!1})),C=XP.findIndex(e=>e.id===ZP),w=e.step===XP.length-1,T=()=>{w?S():g.id===`play-start`?n(e=>({...e,step:C})):n(e=>({...e,step:e.step+1}))},E=()=>n(t=>({...t,step:g.id===`home`&&e.projectId===void 0?XP.findIndex(e=>e.id===`play-start`):t.step-1})),D=u.data?rF(u.data.project.config):`video`,O=g.id===`download`&&D===`article`?`project-article`:g.id===`play-keywords`&&t.playHasKeywords===!1?`play-options`:g.id===`studio-prep`&&D!==`video`?`project-controls`:g.target,k=g.id===`article-save`||g.id===`image-save`,A=(g.page===`article`||g.page===`image`)&&t.promptSaving===!0;return(0,h.jsxs)(IF,{stepId:g.id,target:`[data-tour="${O}"]`,title:g.title,progress:`${e.step+1} of ${XP.length} · First project`,onClose:S,...e.step===0||g.id===`project`||A?{}:{onBack:E},onNext:T,nextDisabled:A||x[g.id]===!1,nextLabel:k?`Use Save in the editor`:g.id===`play-start`?`Use Start run / Queue N on the page`:w?`Finish tutorial`:`Next`,...A?{}:{onSkip:T},skipLabel:g.id===`play-start`?`Skip generating`:k?`Skip without saving`:`Skip this step`,children:[(0,h.jsx)(XF,{step:g.id,output:D}),c.error||l.error?(0,h.jsx)(`p`,{className:`text-danger`,children:c.error?.message??l.error?.message}):null]})}var $F=q({schemaVersion:pO(1),active:GD(),stepId:J([`text-key`,`audio-key`,`image-key`,`voice`,`article-name`,`article-body`,`article-keywords`,`article-save`,`image-prompt`,`image-save`,`play-options`,`play-article`,`play-keywords`,`play-audio`,`play-images`,`play-video`,`play-subtitles`,`play-start`,`project`,`download`,`run-cost`,`studio-prep`,`home`,`channels`,`calendar`]),articleId:W().optional(),imageId:W().optional(),projectId:W().optional()}).strict();q({baseVersion:G().int().nonnegative(),mutationId:wD(),session:$F}).strict();var eI=q({version:G().int().nonnegative(),session:$F,readable:GD()}).strict();async function tI(e){let t=await F(await e.client.tutorial.$get()),n=eI.safeParse(t);return n.success?n.data:{version:0,readable:!1,session:{schemaVersion:1,active:!1,stepId:`text-key`}}}async function nI(e,t){return eI.parse(await F(await e.client.tutorial.$put({json:t})))}async function rI(e){let t=await e.client.tutorial.$delete();if(!t.ok)throw await fo(t)}function iI(){let{api:e}=z(),[t,n]=(0,m.useState)({active:!1,step:0}),[r,i]=(0,m.useState)(null),a=(0,m.useMemo)(()=>{let t={active:!1,step:0},r=0,a=!1,o=!1,s=0,c=!0,l=!1,u=!1,d=null,f=[],p=[],m=e=>i(e instanceof Error?e.message:`Your tutorial progress wasn't saved. You can keep going; it will try again on the next step.`),h=async()=>{if(!u&&a&&c){u=!0;try{for(;d||p.length>0;){if(!d){let e=p.shift();if(!e)break;let t=XP[e.step];if(!t)throw Error(`This tutorial step isn't recognised. Choose Restart tutorial to start over.`);let{step:n,...i}=e;d={baseVersion:r,mutationId:crypto.randomUUID(),session:{...i,schemaVersion:1,stepId:t.id}}}r=(await nI(e,d)).version,d=null}i(null)}catch(e){m(e)}finally{u=!1}}},g=e=>{if(!a){f.push(e);return}let r=typeof e==`function`?e(t):e;r!==t&&(t=r,n(t),p.push(t),h())},_=()=>{if(!a){l=!0;return}if(!c){i(`Saved tutorial progress cannot be read. Choose Restart tutorial to recover.`);return}g({active:!0,step:0})},v=async()=>{if(o||a)return;o=!0;let u=s;try{let o=await tI(e);if(u!==s)return;if(r=o.version,c=o.readable,c||(a=!0),!c){i(`Saved tutorial progress cannot be read. Choose Restart tutorial to recover.`);return}let{schemaVersion:d,stepId:p,...m}=o.session;if(t={active:m.active,step:$P(p)??0,...m.articleId===void 0?{}:{articleId:m.articleId},...m.imageId===void 0?{}:{imageId:m.imageId},...m.projectId===void 0?{}:{projectId:m.projectId}},t.articleId||t.imageId){let{prompts:n}=await bs(e),{articleId:r,imageId:i,...a}=t;t={...a,...r!==void 0&&n.some(e=>e.id===r&&e.kind===`article`)?{articleId:r}:{},...i!==void 0&&n.some(e=>e.id===i&&e.kind===`image`)?{imageId:i}:{}}}if(t.projectId&&await jo(e,t.projectId),u!==s)return;a=!0,n(t);for(let e of f.splice(0))g(e);l&&_(),i(null)}catch(e){u===s&&m(e)}finally{o=!1}},y=async()=>{if(!u){u=!0,s++,f.length=0,l=!1;try{await rI(e),r=0,c=!0,a=!0,d=null,p.length=0,t={active:!0,step:0},n(t),p.push(t),i(null)}catch(e){m(e)}finally{u=!1}await h()}};return{update:g,start:_,restore:v,retry:()=>{a?h():v()},restart:()=>{y()}}},[e]);return(0,m.useEffect)(()=>{a.restore()},[a]),{session:t,update:a.update,start:a.start,retry:a.retry,restart:a.restart,error:r}}var aI=(0,m.createContext)(void 0);function oI({children:e}){let{session:t,update:n,start:r,retry:i,restart:a,error:o}=iI(),[s,c]=(0,m.useState)({}),l=(0,m.useCallback)(e=>{c(t=>Object.entries(e).every(([e,n])=>t[e]===n)?t:{...t,...e})},[]),u=(0,m.useCallback)(e=>{c(t=>Object.fromEntries(Object.entries(t).filter(([t])=>!e.includes(t))))},[]),d=(0,m.useCallback)(e=>{n(t=>QP(t,e))},[n]),f=XP[t.step]?.id,p=t.active&&(f===`project`||f===`download`)?f:void 0,g=(0,m.useMemo)(()=>({active:t.active,projectId:t.projectId,projectStep:p,start:r,report:l,clear:u,event:d}),[t.active,t.projectId,p,r,l,u,d]);return(0,h.jsxs)(aI.Provider,{value:g,children:[e,o?(0,h.jsxs)(`div`,{role:`alert`,className:`fixed bottom-4 left-4 z-[100] rounded-media border border-line bg-surface p-4 text-ink`,children:[(0,h.jsx)(`p`,{children:o}),(0,h.jsx)(R,{type:`button`,onClick:i,children:`Retry tutorial save`}),(0,h.jsx)(R,{type:`button`,onClick:a,children:`Restart tutorial`})]}):null,t.active?(0,h.jsx)(QF,{session:t,progress:s,update:n}):null]})}function sI(){return(0,m.useContext)(aI)}function cI(e){let t=(0,m.useContext)(aI),n=t?.report,r=t?.clear,i=(0,m.useRef)(e);i.current=e,(0,m.useEffect)(()=>{n?.(e)},[n,e]),(0,m.useEffect)(()=>()=>{r?.(Object.keys(i.current))},[r])}function lI(){let e=(0,m.useContext)(aI);return(0,m.useCallback)(t=>{e?.event(t)},[e?.event])}function uI(e){let t=(0,m.useContext)(aI);return t?.projectId===e?t.projectStep:void 0}var dI=[`patch-notes`];function fI(e){return ct({queryKey:dI,queryFn:async()=>F(await e.client[`patch-notes`].$get()),staleTime:1/0})}function pI(e,t){return ct({queryKey:[...dI,t],queryFn:async()=>lo(await e.client[`patch-notes`][`:id`].$get({param:{id:t}})),staleTime:1/0})}async function mI(e){await F(await e.client[`patch-notes`].seen.$post())}var hI={3:[{id:`home`,title:`Home`,body:`What is running and at which step, what is coming up, what needs you and what is ready to upload, on one screen.`,to:`/`,place:`Home`},{id:`play`,title:`Play's one path`,body:`Pick a template, type the topic, press Start. Everything else stays folded away until it needs you.`,to:`/play`,place:`Play`},{id:`reviews`,title:`Automatic reviews`,body:`A reviewer model checks the article, images, narration, thumbnail and shorts, and can send a failed item back to be made again. Turn it on in Play's Review step.`,to:`/play`,place:`Play`},{id:`channels`,title:`Channels and cast`,body:`A channel keeps its brand kit, series brief, templates and schedules, and a cast of characters and places that look the same in every video.`,to:`/channels`,place:`Channels`},{id:`memory`,title:`Episodes that remember`,body:`Each finished episode leaves a short summary on its channel's Episodes tab, and a new article reads the related ones. Add your existing video titles on Existing videos, and topic suggestions skip them too.`,to:`/channels`,place:`Channels`},{id:`calendar`,title:`The calendar`,body:`The coming weeks of uploads on one screen: what is ready, what needs you, and the topics still to come. Its Schedules tab holds every schedule.`,to:`/calendar`,place:`Calendar`},{id:`run-cost`,title:`What a run cost`,body:`Every project has a Run cost tab with the real cost per stage and model. Totals for all projects are in Settings, Usage.`,to:`/settings`,search:{section:`usage`},place:`Usage`},{id:`studio`,title:`YouTube Studio prep`,body:`Slopify never uploads. Prepare upload on a finished project lists everything Studio asks for, and the browser extension can fill it in for you.`,to:`/settings`,search:{section:`studio`},place:`YouTube Studio settings`},{id:`voices`,title:`Multiple voices`,body:`Audiobooks, podcasts, radio drama and interviews, with a voice per speaker. Pick the format under Audio, Speakers on Play.`,to:`/play`,place:`Play`},{id:`long-videos`,title:`Long videos stay watchable`,body:`More images for long videos sets images per hour or one every few minutes, with pan and zoom variety. An ambient bed of rain, fire, wind or your own file can play under the narration. Both are on Play; a channel's brand kit can set the ambient sound for all its videos.`,to:`/play`,place:`Play`},{id:`languages`,title:`Other languages`,body:`A project can be made in another language: pick it on Play, and the article, narration and description are written in it.`,to:`/play`,place:`Play`},{id:`trash`,title:`A trash bin`,body:`Deleted projects, prompts, templates and schedules stay in Settings, Trash for 30 days, and Restore brings them back.`,to:`/settings`,search:{section:`trash`},place:`Trash`}]},gI=[`whats-new`];async function _I(e){return F(await e.client[`whats-new`].$get())}function vI(e){return ct({queryKey:gI,queryFn:()=>_I(e),staleTime:1/0})}async function yI(e){return F(await e.client[`whats-new`].seen.$post())}function bI(){let{api:e}=z(),t=_(),n=sI(),r=N(Qy(e)),i=N({...vI(e),enabled:r.data?.seen===!0}),[a,o]=(0,m.useState)(0),s=P({mutationFn:()=>yI(e),onSuccess:e=>{t.setQueryData(gI,e),t.setQueryData(dI,e=>e===void 0?e:{...e,due:null})}}),c=i.data?.major,l=c==null?void 0:hI[c],u=l!==void 0&&a>=l.length-1,d=N({...fI(e),enabled:i.data?.show===!0&&u}).data?.current??void 0;if(i.data?.show!==!0||l===void 0||n?.active===!0)return null;let f=l[Math.min(a,l.length-1)];if(f===void 0)return null;let p=l.indexOf(f),g=p===l.length-1,v=()=>{s.mutate()};return(0,h.jsx)(YP,{open:!0,width:`narrow`,title:`What's new in ${String(c)}.0`,onClose:v,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,disabled:s.isPending,onClick:v,children:`Close tour`}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(R,{disabled:p===0,disabledReason:`This is the first step`,onClick:()=>{o(p-1)},children:`Back`}),(0,h.jsx)(R,{variant:`primary`,disabled:s.isPending,onClick:()=>{g?v():o(p+1)},children:g?`Finish tour`:`Next`})]}),children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-3`,children:`${String(p+1)} of ${String(l.length)}`}),(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:f.title}),(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:f.body}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsx)(fS,{to:f.to,...f.search===void 0?{}:{search:f.search},children:`Open ${f.place}`}),g?(0,h.jsx)(pS,{to:`/settings`,search:{section:`patch-notes`,...d===void 0?{}:{note:d}},onClick:v,children:`Read the full patch notes`}):null]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`Slopify could not save that you closed this tour: ${s.error.message} Press Close tour to try again.`})]})})}var xI={danger:(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),waiting:(0,h.jsx)(mc,{"aria-hidden":`true`,strokeWidth:1.75}),info:(0,h.jsx)(Cc,{"aria-hidden":`true`,strokeWidth:1.75})};function SI({tone:e=`info`,title:t,children:n,actions:r,className:i}){return(0,h.jsxs)(`div`,{role:e===`danger`?`alert`:`status`,"data-tone":e,className:L(`sl-callout`,e!==`info`&&`sl-callout--${e}`,i),children:[xI[e],(0,h.jsx)(`span`,{className:`sl-callout__title`,children:t}),n===void 0?null:(0,h.jsx)(`div`,{className:`sl-callout__body`,children:n}),r===void 0?null:(0,h.jsx)(`div`,{className:`sl-callout__actions`,children:r})]})}function CI(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var wI=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,TI=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,EI={};function DI(e,t){return((t||EI).jsx?TI:wI).test(e)}var OI=/[ \t\n\f\r]/g;function Bre(e){return typeof e==`object`?e.type===`text`&&kI(e.value):kI(e)}function kI(e){return e.replace(OI,``)===``}var AI=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};AI.prototype.normal={},AI.prototype.property={},AI.prototype.space=void 0;function jI(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new AI(n,r,t)}function MI(e){return e.toLowerCase()}var NI=class{constructor(e,t){this.attribute=t,this.property=e}};NI.prototype.attribute=``,NI.prototype.booleanish=!1,NI.prototype.boolean=!1,NI.prototype.commaOrSpaceSeparated=!1,NI.prototype.commaSeparated=!1,NI.prototype.defined=!1,NI.prototype.mustUseProperty=!1,NI.prototype.number=!1,NI.prototype.overloadedBoolean=!1,NI.prototype.property=``,NI.prototype.spaceSeparated=!1,NI.prototype.space=void 0;var PI=s({boolean:()=>FI,booleanish:()=>II,commaOrSpaceSeparated:()=>BI,commaSeparated:()=>zI,number:()=>Y,overloadedBoolean:()=>LI,spaceSeparated:()=>RI}),Vre=0,FI=VI(),II=VI(),LI=VI(),Y=VI(),RI=VI(),zI=VI(),BI=VI();function VI(){return 2**++Vre}var HI=Object.keys(PI),UI=class extends NI{constructor(e,t,n,r){let i=-1;if(super(e,t),WI(this,`space`,r),typeof n==`number`)for(;++i<HI.length;){let e=HI[i];WI(this,HI[i],(n&PI[e])===PI[e])}}};UI.prototype.defined=!0;function WI(e,t,n){n&&(e[t]=n)}function GI(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new UI(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[MI(r)]=r,n[MI(a.attribute)]=r}return new AI(t,n,e.space)}var KI=GI({properties:{ariaActiveDescendant:null,ariaAtomic:II,ariaAutoComplete:null,ariaBusy:II,ariaChecked:II,ariaColCount:Y,ariaColIndex:Y,ariaColSpan:Y,ariaControls:RI,ariaCurrent:null,ariaDescribedBy:RI,ariaDetails:null,ariaDisabled:II,ariaDropEffect:RI,ariaErrorMessage:null,ariaExpanded:II,ariaFlowTo:RI,ariaGrabbed:II,ariaHasPopup:null,ariaHidden:II,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:RI,ariaLevel:Y,ariaLive:null,ariaModal:II,ariaMultiLine:II,ariaMultiSelectable:II,ariaOrientation:null,ariaOwns:RI,ariaPlaceholder:null,ariaPosInSet:Y,ariaPressed:II,ariaReadOnly:II,ariaRelevant:null,ariaRequired:II,ariaRoleDescription:RI,ariaRowCount:Y,ariaRowIndex:Y,ariaRowSpan:Y,ariaSelected:II,ariaSetSize:Y,ariaSort:null,ariaValueMax:Y,ariaValueMin:Y,ariaValueNow:Y,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function qI(e,t){return t in e?e[t]:t}function JI(e,t){return qI(e,t.toLowerCase())}var Hre=GI({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:zI,acceptCharset:RI,accessKey:RI,action:null,allow:null,allowFullScreen:FI,allowPaymentRequest:FI,allowUserMedia:FI,alpha:FI,alt:null,as:null,async:FI,autoCapitalize:null,autoComplete:RI,autoFocus:FI,autoPlay:FI,blocking:RI,capture:null,charSet:null,checked:FI,cite:null,className:RI,closedBy:null,colorSpace:null,cols:Y,colSpan:Y,command:null,commandFor:null,content:null,contentEditable:II,controls:FI,controlsList:RI,coords:Y|zI,crossOrigin:null,data:null,dateTime:null,decoding:null,default:FI,defer:FI,dir:null,dirName:null,disabled:FI,download:LI,draggable:II,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:FI,formTarget:null,headers:RI,height:Y,hidden:LI,high:Y,href:null,hrefLang:null,htmlFor:RI,httpEquiv:RI,id:null,imageSizes:null,imageSrcSet:null,inert:FI,inputMode:null,integrity:null,is:null,isMap:FI,itemId:null,itemProp:RI,itemRef:RI,itemScope:FI,itemType:RI,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:FI,low:Y,manifest:null,max:null,maxLength:Y,media:null,method:null,min:null,minLength:Y,multiple:FI,muted:FI,name:null,nonce:null,noModule:FI,noValidate:FI,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:FI,optimum:Y,pattern:null,ping:RI,placeholder:null,playsInline:FI,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:FI,referrerPolicy:null,rel:RI,required:FI,reversed:FI,rows:Y,rowSpan:Y,sandbox:RI,scope:null,scoped:FI,seamless:FI,selected:FI,shadowRootClonable:FI,shadowRootCustomElementRegistry:FI,shadowRootDelegatesFocus:FI,shadowRootMode:null,shadowRootSerializable:FI,shape:null,size:Y,sizes:null,slot:null,span:Y,spellCheck:II,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Y,step:null,style:null,tabIndex:Y,target:null,title:null,translate:null,type:null,typeMustMatch:FI,useMap:null,value:II,width:Y,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:RI,axis:null,background:null,bgColor:null,border:Y,borderColor:null,bottomMargin:Y,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:FI,declare:FI,event:null,face:null,frame:null,frameBorder:null,hSpace:Y,leftMargin:Y,link:null,longDesc:null,lowSrc:null,marginHeight:Y,marginWidth:Y,noResize:FI,noHref:FI,noShade:FI,noWrap:FI,object:null,profile:null,prompt:null,rev:null,rightMargin:Y,rules:null,scheme:null,scrolling:II,standby:null,summary:null,text:null,topMargin:Y,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Y,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:FI,disablePictureInPicture:FI,disableRemotePlayback:FI,exportParts:zI,part:RI,prefix:null,property:null,results:Y,security:null,unselectable:null},space:`html`,transform:JI}),Ure=GI({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:BI,accentHeight:Y,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Y,amplitude:Y,arabicForm:null,ascent:Y,attributeName:null,attributeType:null,azimuth:Y,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Y,by:null,calcMode:null,capHeight:Y,className:RI,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Y,diffuseConstant:Y,direction:null,display:null,dur:null,divisor:Y,dominantBaseline:null,download:FI,dx:null,dy:null,edgeMode:null,editable:null,elevation:Y,enableBackground:null,end:null,event:null,exponent:Y,externalResourcesRequired:null,fill:null,fillOpacity:Y,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:zI,g2:zI,glyphName:zI,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Y,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Y,horizOriginX:Y,horizOriginY:Y,id:null,ideographic:Y,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Y,k:Y,k1:Y,k2:Y,k3:Y,k4:Y,kernelMatrix:BI,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Y,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Y,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Y,overlineThickness:Y,paintOrder:null,panose1:null,path:null,pathLength:Y,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:RI,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Y,pointsAtY:Y,pointsAtZ:Y,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:BI,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:BI,rev:BI,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:BI,requiredFeatures:BI,requiredFonts:BI,requiredFormats:BI,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Y,specularExponent:Y,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Y,strikethroughThickness:Y,string:null,stroke:null,strokeDashArray:BI,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Y,strokeOpacity:Y,strokeWidth:null,style:null,surfaceScale:Y,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:BI,tabIndex:Y,tableValues:null,target:null,targetX:Y,targetY:Y,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:BI,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Y,underlineThickness:Y,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Y,values:null,vAlphabetic:Y,vMathematical:Y,vectorEffect:null,vHanging:Y,vIdeographic:Y,version:null,vertAdvY:Y,vertOriginX:Y,vertOriginY:Y,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Y,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:qI}),YI=GI({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),XI=GI({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:JI}),ZI=GI({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),Wre={classId:`classID`,dataType:`datatype`,itemId:`itemID`,strokeDashArray:`strokeDasharray`,strokeDashOffset:`strokeDashoffset`,strokeLineCap:`strokeLinecap`,strokeLineJoin:`strokeLinejoin`,strokeMiterLimit:`strokeMiterlimit`,typeOf:`typeof`,xLinkActuate:`xlinkActuate`,xLinkArcRole:`xlinkArcrole`,xLinkHref:`xlinkHref`,xLinkRole:`xlinkRole`,xLinkShow:`xlinkShow`,xLinkTitle:`xlinkTitle`,xLinkType:`xlinkType`,xmlnsXLink:`xmlnsXlink`},Gre=/[A-Z]/g,QI=/-[a-z]/g,Kre=/^data[-\w.:]+$/i;function qre(e,t){let n=MI(t),r=t,i=NI;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&Kre.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(QI,Yre);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!QI.test(e)){let n=e.replace(Gre,Jre);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=UI}return new i(r,t)}function Jre(e){return`-`+e.toLowerCase()}function Yre(e){return e.charAt(1).toUpperCase()}var Xre=jI([KI,Hre,YI,XI,ZI],`html`),$I=jI([KI,Ure,YI,XI,ZI],`svg`);function Zre(e){return e.join(` `).trim()}var Qre=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g;function u(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,u=1;function f(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(`
104
+ `);function Kk(e,t){return!Number.isFinite(e)||!Number.isFinite(t)||t<=0?1:Math.max(1,Math.ceil(e/t-.001))}function qk(e){let t=e=>e===void 0||e.trim()===``?void 0:Number(e),n=t(e.musicVolume),r=t(e.speed),i=e.fullVideoLink?.trim()??``;return{...e.titleOnScreen===void 0?{}:{titleOnScreen:e.titleOnScreen},...i===``?{}:{fullVideoLink:i},...n===void 0?{}:{musicVolume:n},...r===void 0?{}:{speed:r}}}function Jk(e){return{...e?.titleOnScreen===void 0?{}:{titleOnScreen:e.titleOnScreen},...e?.fullVideoLink===void 0?{}:{fullVideoLink:e.fullVideoLink},...e?.musicVolume===void 0?{}:{musicVolume:String(e.musicVolume)},...e?.speed===void 0?{}:{speed:e.speed.toFixed(2)}}}function Yk(e){let t=[],n=(e,t,n)=>Number.isInteger(e)&&e>=t&&e<=n;n(e.count,1,10)||t.push({field:`count`,message:`Enter a whole number of shorts between 1 and 10.`});for(let r of[`minSeconds`,`maxSeconds`])n(e[r],15,180)||t.push({field:r,message:`Enter a whole number of seconds between 15 and 180.`});if(t.every(e=>e.field===`count`)&&e.minSeconds>e.maxSeconds)for(let e of[`minSeconds`,`maxSeconds`])t.push({field:e,message:`The longest a short may be must be at least the shortest. Raise the maximum or lower the minimum.`});let r=e.speed;r!==void 0&&(!Number.isFinite(r)||r<.999999999||r>1.250000001||Math.abs((r-1)/.05-Math.round((r-1)/.05))>1e-6)&&t.push({field:`speed`,message:`Choose a speed between 1.00× and 1.25×, in steps of 0.05.`}),e.musicVolume!==void 0&&!n(e.musicVolume,0,100)&&t.push({field:`musicVolume`,message:`Enter the music volume as a whole number of percent between 0 and 100.`});let i=e.fullVideoLink?.trim()??``;return i!==``&&!Xk(i)&&t.push({field:`fullVideoLink`,message:`The full video link must be a whole web address starting with https:// or http://, like https://youtu.be/abc123. Paste it again, or leave the box empty.`}),t}function Xk(e){if(e.length>2e3||/\s/.test(e))return!1;try{let t=new URL(e);return(t.protocol===`https:`||t.protocol===`http:`)&&t.hostname!==``}catch{return!1}}var Zk=[`rain`,`fire`,`wind`],Qk=[...Zk,`upload`],$k={rain:`Rain`,fire:`Fireplace`,wind:`Wind`,upload:`My own file`},eA={levelDb:-18,fadeInSeconds:3,tailSeconds:6};function tA(e){return e.ambientBed!==void 0&&e.mode!==`short`&&e.sources.video===`generate`&&e.sources.audio!==`off`}function nA(e){let t=[];return Qk.includes(e.source)||t.push({field:`source`,message:`Choose Rain, Fireplace, Wind or My own file for the ambient sound.`}),Number.isInteger(e.levelDb)&&e.levelDb>=-40&&e.levelDb<=-6||t.push({field:`level`,message:`Enter an ambient sound level between -40 and -6 dB, in whole dB.`}),rA(e.fadeInSeconds,30)||t.push({field:`fadeIn`,message:`Enter a fade-in between 0 and 30 seconds, in steps of 0.5.`}),rA(e.tailSeconds,30)||t.push({field:`tail`,message:`Enter a tail between 0 and 30 seconds, in steps of 0.5.`}),t}function rA(e,t){return Number.isInteger(e*2)&&e>=0&&e<=t}function iA(e){return{source:e.source,level:String(e.levelDb),fadeIn:String(e.fadeInSeconds),tail:String(e.tailSeconds)}}function aA(e){if(e===void 0||e.source===`none`)return;let t=e=>e.trim()===``?NaN:Number(e);return{source:e.source,levelDb:t(e.level),fadeInSeconds:t(e.fadeIn),tailSeconds:t(e.tail)}}var oA=[`interval`,`narration`],sA=[`cut`,`crossfade`,`fadeblack`,`slide`,`wipe`],cA=[`off`,`subtle`,`strong`],lA=[`none`,`warm`,`cold`,`desaturated`,`sepia`],uA=[`none`,`embers`,`dust`,`fog`],dA=[`off`,`chapters`,`every`],fA={cuts:`interval`,transition:`cut`,transitionSeconds:.6,vignette:`off`,grain:`off`,grade:`none`,atmosphere:`none`,chapterCards:!1,animate:`off`,animateEvery:3,animateModel:``},pA={...fA,cuts:`narration`},mA=.2,hA=[.2,.4,.6,.8,1,1.2,1.5,2],gA={interval:`Every N seconds`,narration:`Follow the narration`},_A={cut:`Cut`,crossfade:`Crossfade`,fadeblack:`Fade through black`,slide:`Slide`,wipe:`Wipe`},vA={off:`Off`,subtle:`Subtle`,strong:`Strong`},yA={none:`None`,warm:`Warm fantasy`,cold:`Cold`,desaturated:`Desaturated`,sepia:`Sepia`},bA={none:`None`,embers:`Embers`,dust:`Dust`,fog:`Fog`},xA={off:`Off`,chapters:`Chapter openers`,every:`Every Nth image`};function SA(e){return e.videoEdit??fA}function CA(e){let t=SA(e);return t.animate!==`off`&&e.sources.video===`generate`&&(t.animate===`every`||e.sources.audio!==`off`)}function wA(e){let t=e.videoEdit;if(t===void 0||e.sources.video!==`generate`)return[];let n=[];return t.transition!==`cut`&&!(Number.isFinite(t.transitionSeconds)&&t.transitionSeconds>=.2&&t.transitionSeconds<=2)&&n.push({field:`transitionSeconds`,message:`Choose a transition length between ${String(mA)} and 2 seconds.`}),t.chapterCards&&e.sources.audio===`off`&&n.push({field:`chapterCards`,message:`Chapter cards are placed from the narration. Turn narration on, or turn chapter cards off.`}),t.animate===`chapters`&&e.sources.audio===`off`&&n.push({field:`animate`,message:`Chapter openers are found from the narration. Turn narration on, or choose Every Nth image.`}),t.animate===`every`&&!(Number.isInteger(t.animateEvery)&&t.animateEvery>=2&&t.animateEvery<=10)&&n.push({field:`animateEvery`,message:`Choose every 2nd to every 10th image.`}),t.animate!==`off`&&t.animateModel.trim()===``&&n.push({field:`animateModel`,message:`Choose an image-to-video model to animate images with, or turn Animate images off.`}),n}function TA(e){return[[`Cuts`,gA[e.cuts]],[`Transition`,e.transition===`cut`?_A.cut:`${_A[e.transition]} · ${String(e.transitionSeconds)} s`],[`Vignette`,vA[e.vignette]],[`Film grain`,vA[e.grain]],[`Colour grade`,yA[e.grade]],[`Atmosphere`,bA[e.atmosphere]],[`Chapter cards`,e.chapterCards?`On`:`Off`],[`Animate images`,e.animate===`off`?xA.off:`${e.animate===`every`?`Every ${(e=>e===2?`2nd`:e===3?`3rd`:`${String(e)}th`)(e.animateEvery)} image`:xA.chapters}${e.animateModel.trim()===``?``:` · ${e.animateModel}`}`]]}var EA=[`audiobook`,`podcast`,`drama`,`interview`],DA={audiobook:`Audiobook`,podcast:`Podcast`,drama:`Radio drama`,interview:`Interview`},OA=[`narrator`,`host`,`guest`,`character`],kA=[`script`,`attribute`],AA=[.8,.9,1,1.1,1.2],jA=[0,.2,.35,.5,.8,1.2],MA=.35,NA=q({provider:W(),model:W(),voice:W()}),PA=q({id:W().min(1).max(60).regex(/^[a-z0-9-]+$/),name:W().max(40),role:J(OA),voice:NA,pace:G().optional(),pronunciations:W().max(2e4).optional(),castId:W().max(200).optional(),portrait:W().regex(/^[0-9a-f]{64}$/).optional()}),FA=9999,IA=q({title:W().max(200),chapter:G()}).strict().readonly();function LA(e){return`${e.title.trim()} · Chapter ${String(e.chapter)}`}var RA=q({format:J(EA),source:J(kA),speakers:K(PA).max(10),turnGapSeconds:G(),nameTags:GD(),nativeDialogue:GD(),audioFiles:GD(),book:IA.optional()});function zA(e,t=[]){return{format:e,source:`script`,speakers:BA(e,VA(e),t),turnGapSeconds:MA,nameTags:e===`podcast`||e===`interview`,nativeDialogue:!0,audioFiles:!0}}function BA(e,t,n){if(n.length===0||e!==`podcast`&&e!==`interview`)return[...t];let r=n.slice(0,9).map(e=>({...e,role:`host`})),i=e===`podcast`?t.slice(0,Math.max(0,2-r.length)):t.filter(e=>e.role!==`host`);return[...r,...i.filter(e=>!r.some(t=>t.id===e.id))]}function VA(e){let t={provider:``,model:``,voice:``},n=(e,n,r)=>({id:e,name:n,role:r,voice:t});switch(e){case`audiobook`:return[n(`narrator`,`Narrator`,`narrator`)];case`podcast`:return[n(`host-1`,`Alex`,`host`),n(`host-2`,`Sam`,`host`)];case`drama`:return[n(`narrator`,`Narrator`,`narrator`),n(`character-1`,`Mara`,`character`)];case`interview`:return[n(`host-1`,`Host`,`host`),n(`guest-1`,`Guest`,`guest`)]}}function HA(e){return e.voices!==void 0&&e.sources.audio===`generate`}function UA(e){return HA(e)&&e.voices?.source===`script`}function WA(e){let t=[],{speakers:n}=e;n.length===0&&t.push({field:`voices.speakers`,message:`Add at least one speaker under Speakers (Play → Narration, or Edit project → Providers).`}),e.source===`attribute`&&e.format!==`audiobook`&&t.push({field:`voices.source`,message:`Only audiobooks can hand an existing text's dialogue to speakers. Choose Write a script under Speakers (Play → Narration, or Edit project → Providers).`}),(e.format===`podcast`||e.format===`interview`)&&n.length<2&&t.push({field:`voices.speakers`,message:`A ${DA[e.format].toLowerCase()} needs at least two speakers. Add one under Speakers (Play → Narration, or Edit project → Providers).`}),(e.format===`audiobook`||e.format===`drama`)&&!n.some(e=>e.role===`narrator`)&&t.push({field:`voices.speakers`,message:`An ${e.format===`drama`?`radio drama`:`audiobook`} needs a narrator. Set one speaker's role to Narrator under Speakers (Play → Narration, or Edit project → Providers).`});let r=new Set,i=new Set;for(let[e,a]of n.entries()){let n=`voices.speakers.${String(e)}`,o=a.name.trim();o===``?t.push({field:`${n}.name`,message:`Enter a name for this speaker.`}):/^[\p{L}\p{N}][\p{L}\p{N} .'-]*$/u.test(o)?r.has(o.toLowerCase())&&t.push({field:`${n}.name`,message:`Two speakers are called "${o}". Give each speaker a different name.`}):t.push({field:`${n}.name`,message:`Use only letters, numbers, spaces, dots, apostrophes and hyphens in a speaker name, starting with a letter or number.`}),r.add(o.toLowerCase()),i.has(a.id)&&t.push({field:`${n}.name`,message:`Two speakers share one id. Remove one of them and add it again.`}),i.add(a.id),a.voice.provider.trim()===``||a.voice.model.trim()===``?t.push({field:`${n}.voice`,message:`Choose a voice provider and model for ${o||`this speaker`}.`}):a.voice.voice.trim()===``&&t.push({field:`${n}.voice.voice`,message:`Choose a voice for ${o||`this speaker`}.`}),a.pace!==void 0&&!AA.includes(a.pace)&&t.push({field:`${n}.pace`,message:`Pick a pace from the list for ${o||`this speaker`}.`})}return e.book!==void 0&&(e.book.title.trim()===``&&t.push({field:`voices.book.title`,message:`Enter the book's title under Speakers (Play → Narration), or remove the book to make a project on its own.`}),(!Number.isInteger(e.book.chapter)||e.book.chapter<1||e.book.chapter>9999)&&t.push({field:`voices.book.chapter`,message:`Enter a chapter number from 1 to ${String(FA)} under Speakers (Play → Narration).`})),jA.includes(e.turnGapSeconds)||t.push({field:`voices.turnGapSeconds`,message:`Pick a gap between turns from the list under Speakers (Play → Narration, or Edit project → Providers).`}),t}function GA(e){return e.mode===`short`}function KA(e){if(!GA(e))return[];let t=[];e.format!==`9:16`&&t.push({field:`format`,message:`A short is vertical. Choose the 9:16 format, or make a long video instead.`}),RS(e.sources,`video`)!==`generate`&&t.push({field:`sources.video`,message:`A short is a video. Set Video to Generate.`}),RS(e.sources,`audio`)===`off`&&t.push({field:`sources.audio`,message:`A short's length and captions come from its narration. Set Narration to Generate or Provide.`}),RS(e.sources,`images`)===`off`&&t.push({field:`sources.images`,message:`A short shows images behind its captions. Set Images to Generate or Provide.`});for(let n of[`thumbnail`,`document`])RS(e.sources,n)!==`off`&&t.push({field:`sources.${n}`,message:`A short has no ${n===`thumbnail`?`thumbnail`:`PDF`}. Set ${n===`thumbnail`?`Thumbnail`:`Document`} to Off.`});return e.shorts?.enabled===!0&&t.push({field:`shorts.enabled`,message:`A short isn't cut into more shorts. Turn Shorts off.`}),t}var qA=22.5,JA=`zoom`,YA={zoom:`Zoom in and out`,pan:`Pan across`,mixed:`Mix of both`,still:`Still`};function XA(e){return Number.isInteger(e)&&e>=1&&e<=600?void 0:`Enter a whole number of seconds between 1 and 600.`}function ZA(e){return Number.isInteger(e*2)&&e>=0&&e<=50?void 0:`Enter a zoom between 0 and 50 percent, in steps of 0.5.`}function QA(e){return Number.isInteger(e*2)&&e>=0&&e<=30?void 0:`Enter a number of seconds between 0 and 30, in steps of 0.5.`}var $A={research:[`off`,`generate`,`provide`],article:[`off`,`generate`,`provide`],audio:[`off`,`generate`,`provide`],images:[`off`,`generate`,`provide`],thumbnail:[`off`,`from_prompt`,`prompt_by_llm`,`provide`],video:[`off`,`generate`],document:[`off`,`generate`]};function ej(e){let t=[],n=tj(e.draft),{sources:r}=n;n.title===``?t.push({field:`title`,message:`Enter a title for this video.`}):n.title.length>200&&t.push({field:`title`,message:`Keep the title to 200 characters or fewer.`});for(let e of FS)$A[e].includes(RS(r,e))||t.push({field:`sources.${e}`,message:`"${RS(r,e)}" is not an option for ${e}. Reload the page and choose again.`});lj(n)&&!xj(n.llm)&&t.push({field:`llm`,message:`Choose a text (LLM) provider and model.`}),r.article===`generate`&&sj(n.articlePrompt)&&t.push({field:`articlePrompt`,message:`Pick an article prompt.`});let i=n.audio;t.push(...dj(n)),t.push(...fj(n)),r.audio===`generate`&&(i===void 0||!xj(i)?t.push({field:`audio`,message:`Choose a narration provider and model.`}):i.voice.trim()===``&&t.push({field:`audio.voice`,message:`Choose a voice for the narration.`})),r.images===`generate`&&nj(n,t),(r.images===`generate`||r.thumbnail===`from_prompt`||r.thumbnail===`prompt_by_llm`||_j(n)||CA(n))&&!xj(n.images)&&t.push({field:`images`,message:`Choose an image provider and model.`}),(r.thumbnail===`from_prompt`||r.thumbnail===`prompt_by_llm`)&&sj(n.thumbnailPrompt)&&t.push({field:`thumbnailPrompt`,message:`Pick a thumbnail prompt.`}),r.audio===`off`&&n.subtitles!==void 0&&n.subtitles.mode!==`off`&&t.push({field:`subtitles.mode`,message:`Subtitles need narration. Turn narration on, or turn subtitles off.`}),t.push(...mj(n)),t.push(...vj(n)),t.push(...KA(n)),t.push(...yj(n)),t.push(...bj(n,e.staged)),t.push(...fk(n.loudness)),t.push(...xk(n)),t.push(...gj(n)),t.push(...Ik(n)),hj(n)&&n.reference?.source===`provide`&&aj(e.staged,n.provided.reference,`images`,`provided.reference`,`Upload the establishing image, or set Establishing image to Off in the Images section.`,t),rj(n,e.staged,t),oj(n,e.requiredSlots,t),(!Number.isFinite(n.silenceGapSeconds)||n.silenceGapSeconds<0||n.silenceGapSeconds>30)&&t.push({field:`silenceGapSeconds`,message:`Enter a silence gap between 0 and 30 seconds.`});let a=r.video===`generate`?XA(n.imageSeconds):void 0;a!==void 0&&t.push({field:`imageSeconds`,message:a});let o=r.video===`generate`?ZA(n.zoomPercent):void 0;o!==void 0&&t.push({field:`zoomPercent`,message:o});let s=r.audio===`off`?void 0:QA(n.edgeSilenceSeconds);return s!==void 0&&t.push({field:`edgeSilenceSeconds`,message:s}),t.length===0?{ok:!0,draft:n}:{ok:!1,fields:t}}function tj(e){let t={...e.sources};t.article!==`generate`&&(t.research=`off`),t.images===`off`&&t.video===`generate`&&(t.video=`off`);let n=Object.create(null);for(let[t,r]of Object.entries(e.values))n[t]=r.trim();return{...e,title:e.title.trim(),subtitles:t.video===`off`&&e.subtitles?.mode===`burn-in`?{...e.subtitles,mode:`files`}:e.subtitles,sources:t,values:n,intro:t.audio===`generate`?e.intro:void 0,outro:t.audio===`generate`?e.outro:void 0}}function nj(e,t){if(e.imagePrompts.length===0){t.push({field:`imagePrompts`,message:`Tick at least one image prompt, or turn images off.`});return}let n=0;for(let[r,i]of e.imagePrompts.entries())n+=i.number,sj(i.name)&&t.push({field:`imagePrompts.${r}.name`,message:`Pick an image prompt.`}),(!Number.isInteger(i.number)||i.number<1||i.number>20)&&t.push({field:`imagePrompts.${r}.number`,message:`Enter a whole number between 1 and 20.`});n>60&&t.push({field:`imagePrompts`,message:`A video can have at most 60 images; these prompts ask for ${n}. Lower the numbers.`});let r=e.imageScale===void 0?void 0:ek(e.imageScale);r!==void 0&&t.push({field:`imageScale`,message:r})}function rj(e,t,n){let{sources:r,provided:i}=e;if(r.research===`provide`&&sj(i.research)&&n.push({field:`provided.research`,message:`Paste the research notes.`}),r.article===`provide`&&sj(i.article)&&n.push({field:`provided.article`,message:`Paste the article.`}),n.push(...Cj(e)),r.audio===`provide`&&aj(t,i.audio,`audio`,`provided.audio`,`Pick an audio file.`,n),r.thumbnail===`provide`&&aj(t,i.thumbnail,`thumbnail`,`provided.thumbnail`,`Pick a thumbnail image.`,n),r.images===`provide`){let e=i.images??[];e.length===0?n.push({field:`provided.images`,message:`Pick at least one image.`}):e.length>60&&n.push({field:`provided.images`,message:`A video can have at most 60 images. Remove some.`}),new Set(e).size!==e.length&&n.push({field:`provided.images`,message:`The same image is picked twice. Remove the duplicate.`});for(let[r,i]of e.entries())aj(t,i,`images`,`provided.images.${r}`,`Pick an image.`,n)}ij(e,t,n)}function ij(e,t,n){let r=e.provided.shortsMusic;if(e.shorts?.enabled!==!0||r===void 0)return;let i=`under Outputs → More shorts options → Background music`,a=t.find(e=>e.id===r);a===void 0||a.stageKind!==`audio`?n.push({field:`shorts.music`,message:`The shorts' background music file is no longer available, so it can't be added to the project. Choose the file again ${i}, or remove it.`}):a.state!==`staged`&&n.push({field:`shorts.music`,message:`The shorts' background music is still uploading, so the run can't start yet. Wait for it to finish, or remove it ${i}.`})}function aj(e,t,n,r,i,a){if(t===void 0||t===``){a.push({field:r,message:i});return}let o=e.find(e=>e.id===t);if(o===void 0||o.stageKind!==n){a.push({field:r,message:`That upload is no longer available. Choose the file again.`});return}o.state!==`staged`&&a.push({field:r,message:`This file is still uploading. Wait for it to finish.`})}function oj(e,t,n){for(let r of t){let t=Object.hasOwn(e.values,r)?e.values[r]:void 0;if(t===void 0||t===``){n.push({field:`values.${r}`,message:`Fill in this field.`});continue}t.length>200&&n.push({field:`values.${r}`,message:`Keep this to 200 characters or fewer.`}),/[\n\r]/.test(t)&&n.push({field:`values.${r}`,message:`Keep this to a single line, without line breaks.`})}}function sj(e){return e===void 0||e.trim()===``}function cj(e){let t=e.sources,n=[];return t.research===`generate`&&n.push({section:`article`,label:`researching the topic`}),t.article===`generate`&&n.push({section:`article`,label:`writing the article`}),HA(e)&&e.voices?.source===`attribute`&&n.push({section:`narration`,label:`working out who speaks each line`}),uj(e)&&n.push({section:`narration`,label:`preparing the narration's delivery`}),e.intro?.mode===`llm`&&n.push({section:`narration`,label:`writing the intro`}),e.outro?.mode===`llm`&&n.push({section:`narration`,label:`writing the outro`}),t.thumbnail===`prompt_by_llm`&&n.push({section:`outputs`,label:`writing the thumbnail prompt`}),pj(e)&&n.push({section:`outputs`,label:`writing the YouTube description`}),_j(e)&&n.push({section:`outputs`,label:`picking the shorts`}),n}function lj(e){return cj(e).length>0}function uj(e){return e.sources.audio===`generate`&&!sj(e.narrationPrompt)}function dj(e){return uj(e)&&(e.audio?.provider!==`inworld`||e.audio.model!==`inworld-tts-2`)?[{field:`narrationPrompt`,message:`Narration preparation only works with the Inworld TTS-2 model. Choose that model under Narration, or turn preparation Off.`}]:[]}function fj(e){if(e.voices===void 0||!HA(e))return[];let t=[...WA(e.voices)];return!sj(e.narrationPrompt)&&!e.voices.speakers.some(e=>e.voice.provider===`inworld`&&e.voice.model===`inworld-tts-2`)&&t.push({field:`narrationPrompt`,message:`Narration preparation adds delivery cues only to speakers on Inworld's TTS-2 model, and no speaker uses it. Choose that model for a speaker under Speakers, or clear Narration Preparation under Narration → Audio Advanced.`}),t}function pj(e){return e.youtubeDescription===!0&&e.sources.audio!==`off`}function mj(e){return e.youtubeDescription===!0&&e.sources.audio===`off`?[{field:`youtubeDescription`,message:`The YouTube description is timed from the narration. Turn narration on, or turn the YouTube description off.`}]:[]}function hj(e){return e.reference!==void 0&&e.sources.images===`generate`}function gj(e){return hj(e)&&e.reference?.source===`prompt`&&(e.reference.prompt===void 0||e.reference.prompt.trim()===``)?[{field:`reference.prompt`,message:`Pick an image prompt for the establishing image, upload one instead, or set Establishing image to Off in the Images section.`}]:[]}function _j(e){return e.shorts?.enabled===!0&&e.sources.audio!==`off`}function vj(e){let t=e.shorts;if(t?.enabled!==!0)return[];if(e.sources.audio===`off`)return[{field:`shorts.enabled`,message:`Shorts are cut from the narration. Turn narration on, or turn Shorts off.`}];let n=Yk(t).map(e=>({field:`shorts.${e.field}`,message:e.message})),r=e.sources.video===`generate`?void 0:XA(e.imageSeconds);return r!==void 0&&n.push({field:`imageSeconds`,message:r}),n}function yj(e){return wA(e).map(e=>({field:`videoEdit.${e.field}`,message:e.message}))}function bj(e,t){let n=e.ambientBed;if(n===void 0||!tA(e))return[];let r=`under Video and style → Ambient sound`,i=nA(n).map(e=>({field:`ambientBed.${e.field}`,message:`${e.message} Change it ${r}.`}));if(n.source!==`upload`)return i;let a=e.provided.ambientBed,o=a===void 0?void 0:t.find(e=>e.id===a);return o===void 0||o.stageKind!==`audio`?i.push({field:`ambientBed.file`,message:`The ambient sound's audio file is missing, so it can't be added to the project. Choose the file ${r}, or pick Rain, Fireplace or Wind instead.`}):o.state!==`staged`&&i.push({field:`ambientBed.file`,message:`The ambient sound's audio file is still uploading, so the run can't start yet. Wait for it to finish ${r}.`}),i}function xj(e){return e!==void 0&&e.provider.trim()!==``&&e.model.trim()!==``}function Sj(e){return e.sources.audio===`generate`&&e.audio?.usePronunciationGlossary===!0&&e.audio.provider===`inworld`&&(e.audio.model===`inworld-tts-2`||e.audio.model===`inworld-tts-2-flash`)}function Cj(e){let{sources:t}=e;if(t.article!==`off`)return[];let n=`Set Article to Generate or Provide`;return[...t.audio===`generate`?[{field:`sources.audio`,message:`Narration reads the article, and Article is Off. ${n}, or set Narration to Off or Provide.`}]:[],...t.document===`generate`?[{field:`sources.document`,message:`The PDF is made from the article, and Article is Off. ${n}, or set PDF to Off.`}]:[],...t.thumbnail===`prompt_by_llm`?[{field:`sources.thumbnail`,message:`The AI writes the thumbnail prompt from the article, and Article is Off. ${n}, or pick From prompt for the thumbnail.`}]:[],...t.audio!==`off`&&e.subtitles!==void 0&&e.subtitles.mode!==`off`?[{field:`subtitles.mode`,message:`Captions are matched to the article's words, and Article is Off. ${n}, or turn captions off.`}]:[],...pj(e)?[{field:`youtubeDescription`,message:`The YouTube description is written from the narration's words, which come from the article, and Article is Off. ${n}, or turn the YouTube description off.`}]:[],..._j(e)?[{field:`shorts.enabled`,message:`Shorts are picked from the narration's words, which come from the article, and Article is Off. ${n}, or turn Shorts off.`}]:[],...t.images===`generate`&&e.imageScenes===!0?[{field:`imageScenes`,message:`Scenes from the article need the article, and Article is Off. ${n}, or turn Scenes from the article off.`}]:[]]}var wj=[`auto`,`yes`,`no`],Tj={auto:`Automatic`,yes:`Always Yes`,no:`Always No`},Ej={levelDb:G(),fadeInSeconds:G(),tailSeconds:G()},Dj=q({source:J(Qk),...Ej}).strict(),Oj=q({source:J(Zk),...Ej}).strict(),kj=`Previous video`,Aj=2e3,jj=/\{\{([^{}\n]{1,80})\}\}/gu;function Mj(e){return e.trim().replace(/\s+/gu,` `).toLowerCase()}function Nj(e,t){let n=new Set,r=[];for(let i of[...t,...e]){let e=Mj(i.name);n.has(e)||i.url.trim()===``||(n.add(e),r.push(i))}return r}function Pj(e,t){let n=new Map(t.map(e=>[Mj(e.name),e.url])),r=[],i=0;for(let t of e.matchAll(jj)){let a=t.index;a>i&&r.push({kind:`text`,text:e.slice(i,a)});let o=(t[1]??``).trim();r.push({kind:`placeholder`,raw:t[0],name:o,url:n.get(Mj(o))}),i=a+t[0].length}return i<e.length&&r.push({kind:`text`,text:e.slice(i)}),r}function Fj(e,t){let n=[];return{text:Pj(e,t).map(e=>e.kind===`text`?e.text:e.url===void 0?(n.some(t=>Mj(t)===Mj(e.name))||n.push(e.name),e.raw):e.url).join(``),unknown:n}}function Ij(e){if(e.length>50)return`Keep at most 50 links. Remove some.`;let t=new Set;for(let[n,r]of e.entries()){let e=`Link ${String(n+1)}`,i=r.name.trim();if(i===``)return`${e} has no name. Give it one, such as Patreon.`;if(i.length>60)return`${e}'s name is over 60 characters. Shorten it.`;if(/[{}]/u.test(i))return`${e}'s name contains { or }. Use the name alone; the description writes it as {{${i.replace(/[{}]/gu,``)}}}.`;if(t.has(Mj(i)))return`Two links are named "${i}". Rename one, since {{${i}}} can only fill with one.`;t.add(Mj(i));let a=r.url.trim();if(a.length>2e3)return`The "${i}" link is over ${String(Aj)} characters. Use a shorter address.`;if(a===``)return`The "${i}" link has no address. Paste it, starting with https://.`;if(!Lj(a))return`The "${i}" link is not a web address. Paste the full address, starting with https://.`}}function Lj(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`}catch{return!1}}var Rj=wD(),zj=W().regex(/^#[0-9a-fA-F]{6}$/,`Use a colour like #FFD700.`).transform(e=>e.toUpperCase()),Bj=e=>W().trim().max(e).optional(),Vj=W().max(160).regex(/^[A-Za-z0-9_-]+$/,`Choose a font from the list.`).optional(),Hj=q({captionFontId:Vj,captionColor:zj.optional(),captionOutlineColor:zj.optional(),titleFontId:Vj,titleColor:zj.optional(),intro:Bj(200),outro:Bj(200),endScreenText:Bj(200),documentTheme:Bj(200),ambientBed:Oj.superRefine((e,t)=>{for(let n of nA(e))t.addIssue({code:`custom`,path:[n.field],message:`${n.message} Change it under Brand kit → Ambient sound on the channel page.`})}).optional(),language:zO.optional(),links:K(q({name:W().max(240),url:W().max(Aj*2)}).strict()).max(100).transform(e=>e.map(e=>({name:e.name.trim(),url:e.url.trim()}))).superRefine((e,t)=>{let n=Ij(e);n!==void 0&&t.addIssue({code:`custom`,message:`The channel's links weren't saved: ${n} Then press Save channel on the channel's Brand tab.`})}).optional()}).strict().transform(e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``))),Uj=W().trim().min(1,`Enter a name.`).max(200,`Keep the name to 200 characters or fewer.`);q({id:Rj,name:Uj}).strict().readonly(),q({name:Uj,brand:Hj,seriesBrief:W().max(1e4,`Keep the series brief to 10,000 characters or fewer.`),baseVersion:G().int().positive()}).strict().readonly();var Wj=W().trim().min(1,`Enter a name, and remove empty aliases.`).max(200,`Keep names and aliases to 200 characters or fewer.`),Gj=q({provider:W().trim().min(1,`Choose a voice provider.`).max(100),model:W().trim().min(1,`Choose a voice model.`).max(200),voice:W().trim().min(1,`Choose a voice.`).max(200),pace:G().refine(e=>AA.includes(e),`Pick a pace from the list.`).optional(),pronunciations:W().max(2e4,`Keep the pronunciations to 20,000 characters or fewer.`).optional()}).strict(),Kj=q({kind:J(Gb),name:Wj,aliases:K(Wj).max(20,`Keep to 20 aliases or fewer.`).default([]),description:W().trim().max(2e3,`Keep the description to 2,000 characters or fewer.`).default(``),voice:Gj.nullable().optional(),host:GD().optional()}).strict();Kj.extend({id:Rj}).strict(),Kj.extend({baseVersion:G().int().positive()}).strict(),q({prompt:W().trim().min(1,`Describe the picture to make.`).max(4e3,`Keep the picture's description to 4,000 characters or fewer.`),provider:W().min(1).max(100),model:W().min(1).max(200)}).strict(),q({channelId:Rj}).strict(),q({aiDisclosure:J(wj,`Choose Automatic, Always Yes or Always No.`)}).strict();var qj=K(q({name:W(),aliases:K(W()).readonly(),description:W(),images:K(W()).readonly()})).readonly(),Jj=W().min(1),Yj=W().regex(/^[a-f0-9]{64}$/),Xj=J([`audio`,`images`,`video`]),Zj=q({projectId:Jj,revisionId:Jj,checkpointId:Jj,stage:Xj,workId:Jj,fingerprint:Yj,state:J([`configured`,`pending-review`,`held`,`released`,`satisfied`,`invalidated`,`canceled`]),createdAt:LO(),approvedAt:LO().nullable()}).strict().readonly();q({projectId:Jj,revisionId:Jj,checkpoints:K(q({checkpointId:Jj,stage:Xj,workId:Jj,fingerprint:Yj,state:J([`configured`,`pending-review`,`held`])}).strict().readonly()).max(3).readonly(),createdAt:LO()}).strict().readonly();var Qj=q({projectId:Jj,revisionId:Jj,checkpointId:Jj,fingerprint:Yj,idempotencyKey:wD(),approvedAt:LO()}).strict().readonly(),$j=[`Cinzel`,`Literata`,`times`,`helvetica`,`courier`],eM=[`normal`,`medium`,`bold`,`black`,`italic`,`bolditalic`],tM=(e,t)=>{let n={error:`Use a value from ${String(e)} to ${String(t)}.`};return G({error:`Enter a number.`}).finite(n).min(e,n).max(t,n)},nM=W().regex(/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i,`Use a colour like #8c1e14.`),rM=W().max(300,{error:`Keep this under 300 characters.`}),iM=rM.nullable(),aM=W().max(500,{error:`Keep this under 500 characters.`}).nullable(),oM=q({family:J($j),style:J(eM),letterSpacing:tM(-.5,2)}).strict(),sM=q({page:q({format:J([`a4`,`letter`]),margin:tM(5,60),contentTop:tM(5,80)}).strict(),background:q({image:J([`parchment`]).nullable(),color:nM}).strict(),colors:q({heading:nM,text:nM,muted:nM,faint:nM}).strict(),fonts:q({body:oM,strong:oM,emphasis:oM,heading:oM,dramatic:oM,decorative:oM,dropCap:oM,footer:oM}).strict(),sizes:q({brand:tM(6,72),title:tM(6,72),section:tM(6,72),heading:tM(6,72),subheading:tM(6,72),body:tM(6,24),footer:tM(5,24),meta:tM(5,24)}).strict(),spacing:q({bodyLine:tM(3,20),headingLine:tM(3,30),subheadingLine:tM(3,30),paragraphGap:tM(0,3),headingGap:tM(0,5),itemGap:tM(0,3),listIndent:tM(0,30),quoteIndent:tM(0,40),ruleWidth:tM(0,150)}).strict(),dropCap:q({enabled:GD(),lines:tO([pO(2),pO(3),pO(4)]),scale:tM(1,5),gap:tM(0,20),minLength:G({error:`Enter a number.`}).int({error:`Use a whole number.`}).min(0,{error:`Use a value from 0 to 2000.`}).max(2e3,{error:`Use a value from 0 to 2000.`}),minRoom:tM(0,1)}).strict(),titlePage:q({brandY:tM(10,200),taglineOffset:tM(0,60),titleY:tM(10,250),titleLine:tM(3,40),metaOffset:tM(0,100),metaLine:tM(3,30),showDate:GD(),showWordCount:GD(),cover:q({enabled:GD(),gap:tM(0,40),maxHeight:tM(20,200)}).strict()}).strict(),contents:q({enabled:GD(),title:rM,depth:tO([pO(1),pO(2),pO(3)]),titleOffset:tM(0,100),firstEntryOffset:tM(0,150),line:tM(3,30),indent:tM(0,30)}).strict(),header:q({enabled:GD(),top:tM(3,60),maxTitleCharacters:G({error:`Enter a number.`}).int({error:`Use a whole number.`}).min(5,{error:`Use a value from 5 to 200.`}).max(200,{error:`Use a value from 5 to 200.`})}).strict(),footer:q({enabled:GD(),bottom:tM(3,60),reserve:tM(0,60),text:rM}).strict(),brand:q({name:iM,url:aM,tagline:iM,linkLabel:iM}).strict(),metadata:q({author:rM,subject:rM,keywords:W().max(1e3),creator:rM}).strict(),sources:q({enabled:GD(),title:rM,titleOffset:tM(0,100),bodyOffset:tM(0,150),line:tM(3,30),gap:tM(0,20)}).strict(),endPage:q({enabled:GD(),title:rM,titleOffset:tM(0,100),bodyOffset:tM(0,150),lines:K(rM).max(60).readonly(),showDocumentDetails:GD(),link:q({text:rM,url:aM}).strict().nullable(),closing:iM}).strict()}).strict(),cM=q({id:W().min(1).max(64),name:W().min(1).max(80),values:sM}).strict(),lM=q({theme:J(KS),custom:cM.optional()}).strict(),uM=K(q({written:W().trim().min(1).max(200),spoken:W().trim().min(1).max(500),wholeWord:GD(),caseSensitive:GD()}).strict().readonly()).max(1e3).readonly(),dM=[`whole`,`paragraph`,`words`,`characters`],fM=[`off`,`files`,`burn-in`],pM=[`top`,`upper-middle`,`center`,`lower-middle`,`bottom`],mM=q({mode:J(fM),language:pO(`en`).default(`en`),fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/).default(`default`),position:J(pM).default(`bottom`),fontSize:G().int().min(16).max(120).default(48),color:W().regex(/^#[0-9A-Fa-f]{6}$/).optional(),outlineColor:W().regex(/^#[0-9A-Fa-f]{6}$/).optional()}),hM={mode:`off`,language:`en`,fontId:`default`,fontSize:48,position:`bottom`},gM=W().regex(/^#[0-9A-Fa-f]{6}$/),_M=q({provider:W(),model:W(),thinking:J(HO).optional()}),vM=q({name:W(),mode:J(BS)}),yM=q({cuts:J(oA),transition:J(sA),transitionSeconds:G(),vignette:J(cA),grain:J(cA),grade:J(lA),atmosphere:J(uA),chapterCards:GD(),animate:J(dA),animateEvery:G(),animateModel:W()}),bM=q({mode:J(US).optional(),checkpoints:K(Xj).max(3).refine(e=>new Set(e).size===e.length).readonly().optional(),title:W(),format:J(PS),sources:q({research:J(LS),article:J(LS),audio:J(LS),images:J(LS),thumbnail:J(LS),video:J(LS),document:J(LS).optional()}),llm:_M.optional(),audio:_M.extend({voice:W(),usePronunciationGlossary:GD().optional(),shareGlossary:GD().optional(),useNarrationAliases:GD().optional(),describeFigures:GD().optional(),skipCode:GD().optional()}).optional(),narrationAliases:uM.optional(),sharedGlossary:K(q({term:W().min(1).max(200),ipa:K(W().min(1).max(200)).min(1).max(20).readonly()})).max(2e4).readonly().optional(),images:_M.optional(),reference:q({source:J(HS),prompt:W().optional(),thumbnail:GD().optional()}).optional(),articlePrompt:W().optional(),narrationPrompt:W().optional(),imagePrompts:K(q({name:W(),number:G()})),imageScale:q({perHour:G(),words:G()}).optional(),imageScenes:GD().optional(),thumbnailPrompt:W().optional(),thumbnailCount:tO([pO(1),pO(3)]).optional(),intro:vM.optional(),outro:vM.optional(),values:lO(W(),W()),provided:q({research:W().optional(),article:W().optional(),audio:W().optional(),images:K(W()).optional(),thumbnail:W().optional(),reference:W().optional(),shortsMusic:W().optional(),ambientBed:W().optional()}),chunking:q({mode:J(dM),words:G().optional(),characters:G().int().min(1).max(1e6).optional()}).optional(),silenceGapSeconds:G(),imageSeconds:G().default(15),zoomPercent:G().default(qA),motionStyle:J(zS).default(JA),edgeSilenceSeconds:G().default(2),subtitles:mM.optional(),document:lM.optional(),youtubeDescription:GD().optional(),showFigures:GD().optional(),descriptionPrompt:W().optional(),shorts:q({enabled:GD(),count:G(),minSeconds:G(),maxSeconds:G(),prompt:W().optional(),imagePrompt:W().optional(),titleOnScreen:GD().optional(),fullVideoLink:W().optional(),musicVolume:G().optional(),speed:G().optional()}).optional(),videoEdit:yM.optional(),channelId:W().optional(),useBrandKit:pO(!1).optional(),cast:qj.optional(),earlierEpisodes:K(q({title:W(),summary:W()})).readonly().optional(),titleStyle:q({fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/).optional(),color:gM.optional()}).optional(),endScreen:q({text:W().max(200)}).optional(),reviews:q({provider:W(),model:W(),thinking:J(HO).optional(),retries:G().optional(),stages:uO(J(Ck),q({mode:J(wk),prompt:W().optional()}))}).optional(),voices:RA.optional(),ambientBed:Dj.optional(),loudness:q({videoLufs:G(),audioFilesLufs:G()}).strict().optional(),sentencePauseSeconds:G().optional(),paragraphPauseSeconds:G().optional(),language:zO.optional()}),xM=bM.extend({rendered:lO(W(),W()),titlePattern:W().optional()}),SM=[`article`,`image`,`thumbnail`,`narration`,`description`,`shorts`,`review`,`script`],CM=[`intro`,`outro`],wM=1e5;q({id:W(),kind:J(SM),name:W(),body:W(),slots:W(),updated_at:W()}),q({id:W(),category:J(CM),mode:J(BS),name:W(),body:W(),slots:W(),updated_at:W()});var TM=q({id:W(),name:W(),body:W(),slots:K(W()).readonly(),updatedAt:W()}),EM=q({prompts:K(TM.extend({kind:J(SM)}).strict().readonly()).readonly(),entries:K(TM.extend({category:J(CM),mode:J(BS)}).strict().readonly()).readonly()}).strict().readonly(),DM=wD(),OM=W(),kM=lO(OM,OM).readonly(),AM=q({provider:OM,model:OM,thinking:J(HO).optional()}).strict(),jM=[`audio`,`images`,`thumbnail`,`reference`],MM=q({attachmentId:DM,name:OM}).strict().readonly(),NM=q({title:OM,checkpoints:bM.shape.checkpoints,format:J(PS),sources:q({research:J(LS),article:J(LS),audio:J(LS),images:J(LS),thumbnail:J(LS),video:J(LS),document:J(LS).optional()}).strict().readonly(),document:lM.readonly().optional(),llm:AM.readonly(),audio:AM.extend({voice:OM,usePronunciationGlossary:GD().optional(),shareGlossary:GD().optional(),useNarrationAliases:GD().optional(),describeFigures:GD().optional(),skipCode:GD().optional()}).readonly(),images:AM.readonly(),reference:q({source:J([`off`,...HS]),prompt:OM,thumbnail:GD()}).strict().readonly().optional(),articlePrompt:OM,narrationPrompt:OM.optional(),thumbnailCount:tO([pO(1),pO(3)]).optional(),loudness:q({enabled:GD(),videoLufs:G().optional(),audioFilesLufs:G().optional()}).strict().readonly().optional(),sentencePause:OM.optional(),paragraphPause:OM.optional(),youtubeDescription:GD().optional(),showFigures:GD().optional(),descriptionPrompt:OM.optional(),language:zO.optional(),shorts:q({enabled:GD(),count:OM,minSeconds:OM,maxSeconds:OM,prompt:OM,imagePrompt:OM,titleOnScreen:GD().optional(),fullVideoLink:OM.optional(),musicVolume:OM.optional(),speed:OM.optional()}).strict().readonly().optional(),reviews:q({provider:OM,model:OM,thinking:J(HO).optional(),retries:OM,stages:uO(J(Ck),q({mode:J(wk),prompt:OM}).strict().readonly()).readonly()}).strict().readonly().optional(),imagePrompts:K(q({name:OM,number:OM}).strict().readonly()).readonly(),imageScale:q({every:J([`minutes`,`hour`]),value:OM}).strict().readonly().optional(),imageScenes:GD().optional(),thumbnailPrompt:OM,intro:OM,outro:OM,chunking:q({mode:J(dM),words:OM,characters:OM}).strict().readonly(),subtitles:q({mode:J(fM),language:pO(`en`),fontId:OM,fontSize:OM,position:J(pM)}).strict().readonly(),imageSeconds:OM.default(`15`),edgeSilenceSeconds:OM.default(`2`),zoomPercent:OM.default(String(qA)),motionStyle:J(zS).default(JA),silenceGapSeconds:OM.optional(),videoEdit:yM.strict().readonly().optional(),useBrandKit:GD().optional(),voices:RA.strict().readonly().optional(),ambientBed:q({source:J([`none`,...Qk]),level:OM,fadeIn:OM,tail:OM}).strict().readonly().optional(),values:kM,provided:q({research:OM,article:OM,audio:MM.nullable(),thumbnail:MM.nullable(),images:K(MM).readonly(),reference:MM.nullable().optional(),shortsMusic:MM.nullable().optional(),ambientBed:MM.nullable().optional()}).strict().readonly()}).strict().readonly(),PM=q({schemaVersion:pO(1),librarySnapshot:EM.optional(),templateSource:q({id:DM,version:G().int().positive()}).strict().readonly().optional(),channelId:DM.optional(),form:NM,section:J([`content`,`outputs`,`style`,`review`]),variants:K(q({id:DM,title:OM,values:kM}).strict().readonly()).readonly(),queue:GD().optional(),expectedWords:OM,previewText:OM,fontUpload:q({operationId:DM,name:OM}).strict().readonly().nullable()}).strict().readonly(),FM=q({id:DM,document:PM}).strict().readonly(),IM=FM.unwrap().extend({baseVersion:G().int().positive(),mutationId:DM}).strict().readonly(),LM=FM.unwrap().extend({sourceId:DM}).strict().readonly(),RM=q({id:DM,baseVersion:G().int().positive()}).strict().readonly(),zM=q({id:DM,kind:J(jM),name:OM,state:J([`pending`,`copying`,`ready`,`reattach`]),stagedFileId:OM.nullable(),bytes:G().nonnegative(),error:OM.nullable()}).strict().readonly(),BM=q({id:DM,version:G().int().positive(),createdAt:OM,updatedAt:OM,document:PM}).strict().readonly(),VM=q({checkpointSet:K(Zj.unwrap().extend({reviewedFingerprint:OM}).strict().readonly()).readonly().optional(),requestId:DM,projectIds:K(OM).readonly(),queue:K(q({projectId:OM,batchId:OM,position:G(),state:J([`queued`,`active`,`finished`])}).strict().readonly()).readonly(),replayed:GD()}).strict().readonly(),HM=q({currency:pO(`USD`),rows:K(q({stage:OM,low:G().nullable(),high:G().nullable(),detail:OM,onPlan:GD().optional(),apiLow:G().nullable().optional(),apiHigh:G().nullable().optional()}).strict().readonly()).readonly(),low:G(),high:G(),unknown:G(),apiLow:G().optional(),apiHigh:G().optional(),apiUnknown:G().optional(),expectedWords:G(),catalogueDate:OM.nullable(),assumptions:K(OM).readonly()}).strict().readonly(),UM=q({checkpointSet:K(q({runIndex:G().int().nonnegative(),checkpointId:OM,stage:Xj,fingerprint:OM,workKeys:K(OM).readonly(),dependents:K(J(FS)).readonly()}).strict().readonly()).readonly().optional(),id:DM,draftId:DM,draftVersion:G().int().positive(),fingerprint:OM,runs:K(q({draft:bM,rendered:kM,templates:kM}).strict().readonly()).readonly(),estimates:K(HM).readonly()}).strict().readonly(),WM=q({draft:BM,attachments:K(zM).readonly(),review:UM.nullable(),pendingStart:q({reviewId:DM,draftVersion:G().int().positive()}).strict().readonly().nullable(),start:VM.nullable()}).strict().readonly(),GM=q({title:W(),status:G(),detail:W().optional(),reason:W().optional(),currentVersion:G().int().positive().nullable().optional(),reviewId:wD().optional(),fields:K(q({field:W(),message:W()})).optional(),errors:K(q({path:W(),message:W()})).optional()}),KM=q({drafts:K(q({id:wD(),title:W(),version:G().int().positive(),updatedAt:W(),readable:GD()}).strict()).readonly()}).strict(),qM=RM.unwrap().omit({id:!0}).extend({draftId:wD(),reviewId:wD()}).strict();async function JM(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=GM.safeParse(n);if(!r.success)throw po(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw po(e,{title:i.title,status:i.status,...i.detail===void 0?{}:{detail:i.detail},...i.fields===void 0?{}:{fields:i.fields}});return{ok:!1,reason:i.reason??`invalid-request`,message:i.detail??i.title,currentVersion:i.currentVersion??null,fields:i.fields??i.errors?.map(e=>({field:e.path,message:e.message}))??[],...i.reviewId===void 0?{}:{reviewId:i.reviewId}}}async function YM(e,t,n,r,i){return JM(await e.fetch(`${e.origin}/api/drafts${t}`,{method:n,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}}),r)}function XM(e){return`/${encodeURIComponent(wD().parse(e))}`}async function ZM(e){return YM(e,``,`GET`,KM)}async function QM(e,t){return YM(e,``,`POST`,WM,FM.parse(t))}async function $M(e,t){return YM(e,XM(t),`GET`,WM)}async function eN(e,t){let{id:n,...r}=IM.parse(t);return YM(e,XM(n),`PUT`,WM,r)}async function tN(e,t){let{sourceId:n,...r}=LM.parse(t);return YM(e,`${XM(n)}/fork`,`POST`,WM,r)}async function nN(e,t){let{id:n,...r}=RM.parse(t);return YM(e,XM(n),`DELETE`,q({discarded:pO(!0)}).strict(),r)}async function rN(e,t){let{id:n,...r}=RM.parse(t);return YM(e,`${XM(n)}/review`,`POST`,UM,r)}async function iN(e,t){let{draftId:n,...r}=qM.parse(t);return YM(e,`${XM(n)}/start`,`POST`,VM,r)}function aN(e,t,n){return`${e.origin}/api/drafts${XM(t)}/attachments/${encodeURIComponent(wD().parse(n))}/file`}async function oN(e,t,n,r,i){let a=new FormData;return a.set(`file`,r),JM(await e.fetch(aN(e,t,n),{method:`PUT`,body:a,...i?{signal:i}:{}}),zM)}var sN=[`fonts`];async function cN(e){return F(await e.fetch(`${e.origin}/api/fonts`))}async function lN(e,t){let n=new FormData;return n.set(`file`,t),F(await e.fetch(`${e.origin}/api/fonts`,{method:`POST`,body:n}))}function uN(e,t){return`${e.origin}/api/fonts/${encodeURIComponent(t)}/file`}var dN=`slopify.play-draft`;function fN(e){try{e?window.localStorage?.setItem(dN,e):window.localStorage?.removeItem(dN)}catch(e){console.warn(`Active draft browser storage is unavailable`,e)}}function pN(){try{return window.localStorage?.getItem(dN)??null}catch(e){return console.warn(`Active draft browser storage is unavailable`,e),null}}async function mN(e,t){let n=await Promise.allSettled([t.fetchQuery({...eb(e),staleTime:0}),t.fetchQuery({...nb(e),staleTime:0}),t.fetchQuery({...rb(e),staleTime:0}),t.fetchQuery({...ob(e),staleTime:0}),t.fetchQuery({...tb(e),staleTime:0}),t.fetchQuery({queryKey:sN,queryFn:()=>cN(e),staleTime:0})]);for(let e of n)e.status===`rejected`&&console.warn(`Draft choices could not refresh`,e.reason)}var hN=`under Video and style → Ambient sound`;`${hN}`,`${hN}`;var gN=PM.parse({schemaVersion:1,form:{title:``,format:`16:9`,sources:{research:`off`,article:`generate`,audio:`generate`,images:`generate`,thumbnail:`off`,video:`generate`},llm:{provider:``,model:``},audio:{provider:``,model:``,voice:``,usePronunciationGlossary:!0,shareGlossary:!0,useNarrationAliases:!0,describeFigures:!0},images:{provider:``,model:``},articlePrompt:``,narrationPrompt:``,imagePrompts:[],thumbnailPrompt:``,intro:``,outro:``,chunking:{mode:`whole`,words:`500`,characters:`3000`},subtitles:{...hM,fontSize:`48`},imageSeconds:`15`,edgeSilenceSeconds:`2`,zoomPercent:String(qA),motionStyle:JA,videoEdit:pA,showFigures:!0,values:{},provided:{research:``,article:``,audio:null,images:[],thumbnail:null}},section:`content`,variants:[],expectedWords:`1500`,previewText:`Every story begins with a word.`,fontUpload:null}),_N={};function vN(e){_N=e}function yN(e,t=_N){let{form:n}=e;return n.llm.provider!==``||n.images.provider!==``||t.llm===void 0&&t.images===void 0?e:{...e,form:{...n,...t.llm===void 0?{}:{llm:{...t.llm}},...t.images===void 0?{}:{images:{...t.images}}}}}function bN(e){let t={...e.sources,...e.sources.article===`generate`?{}:{research:`off`},...e.sources.images===`off`?{video:`off`}:{}},n=t.audio===`off`?`off`:t.video===`off`&&e.subtitles.mode===`burn-in`?`files`:e.subtitles.mode;return{...e,sources:t,subtitles:{...e.subtitles,mode:n}}}function xN(e){let t=PM.parse(e);return JSON.stringify({...t,form:bN(t.form)})}function SN(e,t,n){return{...e,acknowledged:Math.max(e.acknowledged,t),version:n}}function CN(e,t){return t.type===`edit`?{...e,edited:e.edited+1}:SN(e,t.generation,t.version)}function wN(e,t,n){return{mutationId:n,document:PM.parse(JSON.parse(xN(e))),generation:t.edited,baseVersion:t.version}}function TN(){return{document:yN(gN),view:null,clock:{edited:0,acknowledged:0,version:0},id:null,recoveryId:null,pending:null,status:`unsaved`,error:null,reveal:null}}function EN(e,t,n){let r=e.form.provided,i=t.form.provided,a=new Map;for(let[e,t]of[[r.audio,i.audio],[r.thumbnail,i.thumbnail],[r.shortsMusic,i.shortsMusic],[r.ambientBed,i.ambientBed],...r.images.map((e,t)=>[e,i.images[t]])])e&&t&&a.set(e.attachmentId,t.attachmentId);let o=e=>e?{...e,attachmentId:a.get(e.attachmentId)??e.attachmentId}:null;return{...n,form:{...n.form,provided:{...n.form.provided,audio:o(n.form.provided.audio),thumbnail:o(n.form.provided.thumbnail),...n.form.provided.shortsMusic===void 0?{}:{shortsMusic:o(n.form.provided.shortsMusic)},...n.form.provided.ambientBed===void 0?{}:{ambientBed:o(n.form.provided.ambientBed)},images:n.form.provided.images.map(e=>({...e,attachmentId:a.get(e.attachmentId)??e.attachmentId}))}}}}function DN(e,t){if(e.draft.id!==t.id)return e;let n=t.document.form.provided,r=new Set([n.audio,n.thumbnail,n.shortsMusic,n.ambientBed,...n.images].flatMap(e=>e?[e.attachmentId]:[]));return{...e,attachments:e.attachments.filter(e=>r.has(e.id)).map(e=>{let n=t.view?.attachments.find(t=>t.id===e.id);return(e.state===`pending`||e.state===`copying`)&&(n?.state===`ready`||n?.state===`reattach`)?n:e})}}function ON(e,t){let n={...hM,...e},r=t.audio===`off`?`off`:(t.video===`off`||t.images===`off`)&&n.mode===`burn-in`?`files`:n.mode;if(r!==`off`)return{...n,mode:r};let i=mM.shape.fontId.safeParse(n.fontId),a=mM.shape.fontSize.safeParse(n.fontSize);return{...n,mode:r,fontId:i.success?i.data:hM.fontId,fontSize:a.success?a.data:hM.fontSize}}function kN(e){return e.mode===`off`||e.fontId!==``&&Number.isInteger(e.fontSize)&&e.fontSize>=16&&e.fontSize<=120}function AN(e){return e===`shortsMusic`||e===`ambientBed`?`audio`:e}function jN(e){return e.shorts?.enabled===!0&&e.sources.audio!==`off`}function MN(e){return e.ambientBed?.source===`upload`&&e.sources.video===`generate`&&e.sources.audio!==`off`}function NN(e){let t=e=>e.trim()===``?NaN:Number(e);return{enabled:e.enabled,count:t(e.count),minSeconds:t(e.minSeconds),maxSeconds:t(e.maxSeconds),...e.prompt.trim()?{prompt:e.prompt}:{},...e.imagePrompt.trim()?{imagePrompt:e.imagePrompt}:{},...qk(e)}}({...gN.form}),{...gN.form.sources};var PN={off:`Off`,generate:`Generate`,provide:`Provide`,from_prompt:`From prompt`,prompt_by_llm:`Prompt by LLM`};function FN(e){return $A[e].map(e=>({value:e,label:PN[e]}))}function IN(e,t){return cj(zN({form:e,entries:t,slots:[],silenceGapSeconds:0}))}function LN(e,t,n){if(n!==``)return e.find(e=>e.category===t&&e.name===n)?.mode}function RN(e){return[e.audio,e.thumbnail,e.shortsMusic,e.ambientBed,e.reference,...e.images].flatMap(e=>e?.file===void 0?[]:[e.file])}function zN(e){let{form:t}=e;return{...t.checkpoints===void 0?{}:{checkpoints:t.checkpoints},title:t.title,format:t.format,sources:{...t.sources,...t.sources.article===`provide`?{research:`off`}:{},...t.sources.images===`off`?{video:`off`}:{}},llm:t.llm,audio:t.audio,images:t.images,...t.sources.images===`generate`&&t.reference!==void 0&&t.reference.source!==`off`?{reference:{source:t.reference.source,...t.reference.source===`prompt`?{prompt:t.reference.prompt}:{},thumbnail:t.reference.thumbnail}}:{},articlePrompt:t.articlePrompt,...t.narrationPrompt===void 0?{}:{narrationPrompt:t.narrationPrompt},...t.language===void 0||t.language===`en`?{}:{language:t.language},...t.sources.video===`generate`&&t.sources.images!==`off`&&t.sources.audio===`generate`&&t.audio.describeFigures===!0&&t.showFigures===!0?{showFigures:!0}:{},...t.sources.audio!==`off`&&t.youtubeDescription===!0?{youtubeDescription:!0,...t.descriptionPrompt?.trim()?{descriptionPrompt:t.descriptionPrompt}:{}}:{},...jN(t)&&t.shorts!==void 0?{shorts:NN(t.shorts)}:{},imagePrompts:t.imagePrompts,thumbnailPrompt:t.thumbnailPrompt,...t.thumbnailCount===3&&(t.sources.thumbnail===`from_prompt`||t.sources.thumbnail===`prompt_by_llm`)?{thumbnailCount:3}:{},...BN(VN(e,`intro`),e=>({intro:e})),...BN(VN(e,`outro`),e=>({outro:e})),values:HN(t.values,e.slots),provided:{research:t.provided.research,article:t.provided.article,...BN(t.provided.audio?.file,e=>({audio:e.id})),...BN(t.provided.thumbnail?.file,e=>({thumbnail:e.id})),...BN(t.sources.images===`generate`&&t.reference?.source===`provide`?t.provided.reference?.file:void 0,e=>({reference:e.id})),images:t.provided.images.flatMap(e=>e.file===void 0?[]:[e.file.id]),...jN(t)?BN(t.provided.shortsMusic?.file,e=>({shortsMusic:e.id})):{},...t.ambientBed?.source===`upload`?BN(t.provided.ambientBed?.file,e=>({ambientBed:e.id})):{}},chunking:t.chunking,subtitles:ON(t.subtitles,t.sources),silenceGapSeconds:e.silenceGapSeconds,imageSeconds:t.imageSeconds,edgeSilenceSeconds:t.edgeSilenceSeconds,zoomPercent:t.zoomPercent,motionStyle:t.motionStyle,...t.videoEdit===void 0?{}:{videoEdit:t.videoEdit},...t.voices!==void 0&&t.sources.audio===`generate`?{voices:t.voices}:{},...t.sources.document===`generate`?{document:t.document}:{},...BN(t.sources.video===`generate`&&t.sources.audio!==`off`?aA(t.ambientBed):void 0,e=>({ambientBed:e})),...t.sources.audio===`generate`?Sk(t):{},...BN(t.sources.audio===`off`?void 0:pk(t.loudness,e.loudness??tk),e=>({loudness:e}))}}function BN(e,t){return e===void 0?{}:t(e)}function VN(e,t){if(e.form.sources.audio!==`generate`)return;let n=t===`intro`?e.form.intro:e.form.outro,r=LN(e.entries,t,n);return n===``||r===void 0?void 0:{name:n,mode:r}}function HN(e,t){let n=Object.create(null);for(let r of t)n[r]=Object.hasOwn(e,r)?e[r]??``:``;return n}function UN(e,t){return e?.draftId===t.draftId&&e.version===t.version&&e.editGeneration===t.editGeneration}function WN({api:e,queryClient:t,current:n,flush:r,resave:i,render:a}){let o={receipt:null,pending:!1,starting:!1,uncertain:!1,valid:!1,error:null,fields:[],created:null},s,c=0,l=0,u=null,d=e=>{o={...o,...e},a()},f=()=>({draftId:n().id??``,version:n().clock.version,editGeneration:n().clock.edited}),p=()=>UN(s,f())&&n().clock.edited===n().clock.acknowledged&&o.receipt?.runs.length===GN(n().document),m=(e=!1)=>{c++,s=void 0,d({valid:!1,...e?{fields:[],error:null}:{}})},h=e=>d({error:e.message,fields:e.fields,valid:!1}),g=e=>{u=null,d({created:e,uncertain:!1,starting:!1,valid:!1})},_=async()=>{let t=u?.draftId;if(!t)return;let n=await $M(e,t);if(!n.ok){h(n);return}n.value.start&&g(n.value.start)};return{reset:()=>{c++,l++,s=void 0,u=null,o={receipt:null,pending:!1,starting:!1,uncertain:!1,valid:!1,error:null,fields:[],created:null},a()},state:()=>({...o,valid:o.valid&&p()}),invalidate:m,restore:e=>{c++,l++,s=void 0,u=e.pendingStart?{draftId:e.draft.id,baseVersion:e.pendingStart.draftVersion,reviewId:e.pendingStart.reviewId}:null,o={receipt:null,pending:!1,starting:!1,uncertain:u!==null,valid:!1,error:null,fields:[],created:e.start},a()},review:async()=>{if(o.pending||o.starting||o.uncertain||o.created)return;let a=++l;d({pending:!0,valid:!1,error:null,fields:[]});try{if(await Promise.all([mN(e,t),t.refetchQueries({queryKey:[`provider-models`]})]),a!==l||!await r()||!n().id)return;let o=f(),u=c,p=await rN(e,{id:o.draftId,baseVersion:o.version});if(a!==l||u!==c||!UN(o,f()))return;if(!p.ok){h(p);return}if(p.value.draftId!==o.draftId||p.value.draftVersion!==o.version)return;let m=GN(n().document);if(p.value.runs.length!==m){d({receipt:null,valid:!1,error:`The saved draft has ${KN(p.value.runs.length)}, but this page shows ${m}. Slopify saved this page again. Press Refresh review, then start.`}),i();return}s=o,d({receipt:p.value,valid:!0})}catch(e){a===l&&d({error:e instanceof Error?e.message:`This setup couldn't be checked. Press Refresh review to try again.`})}finally{a===l&&d({pending:!1})}},start:async()=>{if(o.starting||o.created||!u&&(!o.valid||!p()||o.pending||!o.receipt||YN(n().document,n().view)!==void 0)||(!u&&o.receipt&&(u={draftId:o.receipt.draftId,baseVersion:o.receipt.draftVersion,reviewId:o.receipt.id}),!u))return;let t=u;fN(t.draftId),d({starting:!0,error:null});try{if(o.uncertain&&(await _(),o.created))return;let n=await iN(e,t);if(n.ok){g(n.value);return}n.reason===`pending-start`||n.reason===`already-started`?(d({uncertain:!0}),await _()):(u=null,d({uncertain:!1}),h(n))}catch(e){d({uncertain:!0,valid:!1,error:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the start`)} The run may already have started. Press Check Start result to find out before trying again.`})}finally{d({starting:!1})}}}}function GN(e){return e.variants.length+1}function KN(e){return e===1?`1 video`:`${e} videos`}function qN(e,t){if(e.starting)return`Starting…`;if(e.uncertain)return`Check Start result`;let n=e.valid&&e.receipt?e.receipt.runs.length:GN(t);return n===1?`Start run`:JN(t)?`Queue ${n} videos`:`Start ${n} videos`}function JN(e){return e.queue!==!1}function YN(e,t){if(e.fontUpload!==null)return`subtitles.fontUpload`;let{sources:n,provided:r}=e.form;return[...n.audio===`provide`&&r.audio?[{ref:r.audio,field:`provided.audio`}]:[],...n.thumbnail===`provide`&&r.thumbnail?[{ref:r.thumbnail,field:`provided.thumbnail`}]:[],...n.images===`provide`?r.images.map((e,t)=>({ref:e,field:`provided.images.${t}`})):[],...jN(e.form)&&r.shortsMusic?[{ref:r.shortsMusic,field:`shorts.music`}]:[],...MN(e.form)&&r.ambientBed?[{ref:r.ambientBed,field:`ambientBed.file`}]:[]].find(({ref:e})=>t?.attachments.find(t=>t.id===e.attachmentId)?.state!==`ready`)?.field}function XN(e,t){return e?.draftId===t.draftId&&e.attachmentId===t.attachmentId}function ZN({api:e,queryClient:t,state:n,edit:r,flush:i,generation:a,publish:o,render:s}){let c=(0,m.useRef)(0),l=(0,m.useRef)(null),u=(0,m.useRef)(null),d=(0,m.useRef)(new Map),f=(0,m.useRef)(new Map),p=e=>{let t=n.current.document.form.provided,r=[t.audio,t.thumbnail,t.shortsMusic,t.ambientBed,t.reference,...t.images].find(t=>t?.attachmentId===e.attachmentId);return XN(r&&n.current.id?{draftId:n.current.id,attachmentId:r.attachmentId}:void 0,e)};(0,m.useEffect)(()=>{for(let[e,t]of d.current)t!==a()&&d.current.delete(e);for(let[e,t]of f.current)(!p(t.owner)||t.generation!==a())&&(t.controller.abort(),f.current.delete(e))}),(0,m.useEffect)(()=>{let e=f.current,t=d.current;return()=>{c.current++,t.clear();for(let t of e.values())t.controller.abort();e.clear()}},[]);let h=async(t,l,u)=>{if(l.length===0)return;let m=AN(t),h=m===`images`&&!u?l:l.slice(-1),g=h.map(e=>({attachmentId:crypto.randomUUID(),name:e.name})),_=c.current,v=a();for(let e of g)d.current.set(e.attachmentId,v);let y=n.current.document,b=y.form.provided;r({...y,form:{...y.form,provided:m===`images`?{...b,images:u?b.images.flatMap(e=>e.attachmentId===u?g:[e]):[...b.images,...g]}:{...b,[t]:g.at(-1)??null}}});let x=await i();for(let e of g)d.current.delete(e.attachmentId);if(!x||v!==a()||_!==c.current){s();return}let S=n.current.id;S&&await Promise.all(g.map(async(t,r)=>{let i=h[r],s={draftId:S,attachmentId:t.attachmentId};if(!i||!p(s))return;let l=new AbortController;f.current.set(t.attachmentId,{owner:s,controller:l,generation:v});let u=e=>{let r=n.current.view;v===a()&&_===c.current&&r?.draft.id===S&&p(s)&&!l.signal.aborted&&o({view:{...r,review:null,attachments:[...r.attachments.filter(e=>e.id!==t.attachmentId),e]}})};try{let n=await oN(e,S,t.attachmentId,i,l.signal);n.ok?u(n.value):u({id:t.attachmentId,kind:m,name:t.name,state:`reattach`,stagedFileId:null,bytes:0,error:n.message})}catch(e){u({id:t.attachmentId,kind:m,name:t.name,state:`reattach`,stagedFileId:null,bytes:0,error:e instanceof Error?e.message:`Reattach this file`})}finally{f.current.delete(t.attachmentId)}}))},g=e=>{l.current=null;let t=n.current.document;r({...t,fontUpload:null,form:{...t.form,subtitles:{...t.form.subtitles,fontId:e}}})},_=async o=>{let d=crypto.randomUUID();l.current=d,r({...n.current.document,fontUpload:{operationId:d,name:o.name}});let f=c.current,p=a();if(!await i()||p!==a()||f!==c.current){l.current===d&&(l.current=null),s();return}if(n.current.document.fontUpload?.operationId===d)try{let{font:r}=await lN(e,o);if(p!==a()||f!==c.current||n.current.document.fontUpload?.operationId!==d)return;t.setQueryData(sN,e=>({fonts:[...(e?.fonts??[]).filter(e=>e.id!==r.id),r]})),g(r.id),await i()}catch(e){p===a()&&f===c.current&&n.current.document.fontUpload?.operationId===d&&(u.current={operationId:d,message:e instanceof Error?e.message:`Reattach this font`},s())}finally{l.current===d&&(l.current=null,s())}},v=l.current!==null&&l.current===n.current.document.fontUpload?.operationId;return{attachmentUploading:e=>{let t=f.current.get(e);return d.current.get(e)===a()||t!==void 0&&t.generation===a()&&p(t.owner)&&!t.controller.signal.aborted},fontUpload:{pending:v,error:u.current?.operationId===n.current.document.fontUpload?.operationId?u.current?.message:void 0,pick:e=>{_(e)}},attach:h,selectFont:g,uploadSubtitleFont:_,fontUploading:v}}function QN(e,t,n){(0,m.useEffect)(()=>{let r=e=>[`prompts`,`entries`,`providers`,`provider-models`,`fonts`,`settings`].includes(String(e[0])),i=t.getQueryCache().subscribe(e=>{e.type===`updated`&&r(e.query.queryKey)&&(e.action.type===`success`||e.action.type===`invalidate`)&&n.invalidate()}),a=()=>{n.invalidate(),mN(e,t),t.refetchQueries({queryKey:[`provider-models`]})};return window.addEventListener(`focus`,a),()=>{i(),window.removeEventListener(`focus`,a)}},[e,t,n])}function $N(){let{api:e}=z(),t=_(),[,n]=(0,m.useReducer)(e=>e+1,0),r=(0,m.useRef)(TN()),i=(0,m.useMemo)(()=>{let i,a=null,o=!1,s=0,c=!1,l=null,u=!0,d=e=>{r.current={...r.current,...e},u&&n()},f=()=>{clearTimeout(i),i=void 0},p=()=>{t.invalidateQueries({queryKey:[`play-drafts`]})},m=e=>{d({status:`error`,error:e instanceof Error?e.message:`Your latest changes weren't saved. Keep this page open and try again.`})},h=e=>e.ok?!0:(d({status:e.reason===`conflict`?`conflict`:`error`,error:e.message}),!1),g=e=>{b.restore(e),d({...TN(),document:e.draft.document,view:e,id:e.draft.id,clock:{edited:0,acknowledged:0,version:e.draft.version},status:`saved`}),fN(e.draft.id),p()},_=async()=>{let t=s;for(;r.current.clock.edited>r.current.clock.acknowledged;){if(r.current.status===`conflict`||t!==s||l!==null&&l===r.current.id)return!1;let n=r.current,i=n.id??crypto.randomUUID(),a=n.pending??wN(n.document,n.clock,crypto.randomUUID());d({id:i,pending:a,status:`saving`,error:null});try{let n=a.baseVersion===0?await QM(e,{id:i,document:a.document}):await eN(e,{id:i,baseVersion:a.baseVersion,mutationId:a.mutationId,document:a.document});if(t!==s)return!1;if(!h(n))return n.reason!==`conflict`&&d({pending:null}),!1;let c=CN(r.current.clock,{type:`acknowledge`,generation:a.generation,version:n.value.draft.version});if(d({clock:c,view:{...DN(n.value,r.current),review:c.edited>c.acknowledged?null:n.value.review},pending:null,status:c.edited>c.acknowledged?`unsaved`:`saved`,error:null}),fN(i),p(),!o)return!0}catch(e){return t===s&&m(e),!1}}return r.current.status!==`conflict`&&r.current.status!==`error`},v=()=>c?Promise.resolve(!1):a||(r.current.clock.edited===r.current.clock.acknowledged?Promise.resolve(!0):l!==null&&l===r.current.id?Promise.resolve(!1):(a=_().finally(()=>{a=null}),a)),y=()=>(f(),o=!0,v()),b=WN({api:e,queryClient:t,current:()=>r.current,flush:y,resave:()=>x(r.current.document),render:()=>{u&&n()}}),x=e=>{if(b.state().starting||b.state().uncertain||b.state().created)return;b.invalidate(JSON.stringify({...e,section:r.current.document.section})!==JSON.stringify(r.current.document));let t=r.current;d({document:e,clock:CN(t.clock,{type:`edit`}),view:t.view?{...t.view,review:null}:null,status:t.status===`conflict`||t.status===`error`?t.status:`unsaved`}),f(),!(c||l!==null&&l===t.id||t.status===`conflict`||t.status===`error`)&&(t.id?i=setTimeout(()=>{y()},500):(o=!1,v()))},S=async(n,i=()=>!0)=>{if(b.state().starting||b.state().uncertain||b.state().created||(r.current.id!==n||r.current.status!==`conflict`)&&!await y()||!i())return!1;let a=++s,o=r.current.clock.edited;f();try{let c=await $M(e,n);return a!==s||o!==r.current.clock.edited||!i()?!1:h(c)?(T=null,g(c.value),await mN(e,t),i()):(r.current.id||d({recoveryId:n}),!1)}catch(e){return a===s&&o===r.current.clock.edited&&(m(e),r.current.id||d({recoveryId:n})),!1}},C=async()=>{if(b.state().starting||b.state().uncertain||b.state().created)return;let e=s;await y()&&e===s&&(s++,T=null,d(TN()),b.reset(),fN(null))},w=async({id:t,version:n})=>{if(b.state().starting||b.state().uncertain||b.state().created)throw Error(`Resolve the pending Start before discarding a draft`);if(c||l!==null)throw Error(`Wait for the current draft operation before discarding`);let i=s;l=t,(r.current.id??r.current.recoveryId)===t&&f();try{a&&await a;let o=await nN(e,{id:t,baseVersion:n});if(!o.ok&&o.reason!==`not-found`)throw Error(o.message);if(p(),i!==s||(r.current.id??r.current.recoveryId)!==t)return;f(),s++,T=null,d(TN()),b.reset(),fN(null)}finally{l=null}},T=null;return{review:b,takeCreated:()=>{let e=b.state().created;if(!e)return null;s++,d(TN()),b.reset(),fN(null);for(let e of[[`projects`],[`staging`],[`play-drafts`]])t.invalidateQueries({queryKey:e});return e},edit:x,flush:y,open:S,newDraft:C,adoptDefaults:e=>{let t=r.current;if(t.id!==null||t.clock.edited>0||t.view!==null)return;let n=yN(t.document,e);n!==t.document&&d({document:n})},discard:w,saveAsNew:async()=>{if(b.state().starting||b.state().uncertain||b.state().created||(f(),c||l!==null))return;a&&await a;let t=r.current;if(!t.id||!t.view&&t.status!==`conflict`){await y();return}let n=s;T?.sourceId!==t.id&&(T=null),T??={sourceId:t.id,id:crypto.randomUUID(),document:wN(t.document,t.clock,crypto.randomUUID()).document,generation:t.clock.edited};let i=T;c=!0;try{let t=await tN(e,{sourceId:i.sourceId,id:i.id,document:i.document});if(n!==s)return;if(!h(t)){t.reason===`conflict`&&(T=null);return}let a=r.current.clock.edited>i.generation?r.current.document:null;s++,g(t.value),T=null,c=!1,a&&x(EN(i.document,t.value.draft.document,a))}catch(e){n===s&&m(e)}finally{c=!1}},navigate:async(e,t)=>{let n=s,i={...r.current.document,section:e};r.current.id||r.current.clock.edited>0?x(i):d({document:i}),await y()&&n===s&&d({reveal:{section:e,...t===void 0?{}:{field:t},sequence:(r.current.reveal?.sequence??0)+1}})},generation:()=>s,publish:d,start:()=>{u=!0;let e=pN();e&&S(e)},stop:()=>{u=!1,f()}}},[e,t]);(0,m.useEffect)(()=>(i.start(),i.stop),[i]),QN(e,t,i.review);let a=ZN({api:e,queryClient:t,state:r,edit:i.edit,flush:i.flush,generation:i.generation,publish:i.publish,render:n}),o=r.current;return{...a,review:i.review.state(),reviewDraft:i.review.review,startRun:i.review.start,invalidateReview:i.review.invalidate,takeCreated:i.takeCreated,document:o.document,section:o.document.section,view:o.view,status:o.status,error:o.error,edited:o.clock.edited,acknowledged:o.clock.acknowledged,reveal:o.reveal,edit:i.edit,flush:i.flush,open:i.open,generation:i.generation,newDraft:i.newDraft,adoptDefaults:i.adoptDefaults,discard:i.discard,saveAsNew:i.saveAsNew,navigate:i.navigate,activeId:o.id??o.recoveryId}}var eP=(0,m.createContext)(null);function tP({children:e}){let t=$N();return(0,h.jsx)(eP.Provider,{value:t,children:e})}function nP(){return(0,m.useContext)(eP)}function rP(){let e=(0,m.useContext)(eP);if(!e)throw Error(`PlayDraftProvider is required`);return e}var iP=(0,m.createContext)(void 0);function aP({children:e}){let[t,n]=(0,m.useState)(()=>new Map),r=(0,m.useCallback)((e,t)=>{n(n=>{let r=n.get(e),i=typeof t==`function`?t(r):t;if(r===i)return n;let a=new Map(n);return i===void 0?a.delete(e):a.set(e,i),a})},[]),i=(0,m.useMemo)(()=>({prompts:t,updatePrompt:r}),[t,r]);return(0,h.jsx)(iP.Provider,{value:i,children:e})}function oP(e){let t=(0,m.useContext)(iP),[n,r]=(0,m.useState)(void 0),i=t?.updatePrompt,a=(0,m.useCallback)(t=>{i?i(e,t):r(t)},[e,i]);return[t?t.prompts.get(e):n,a]}function sP(e){return e.trim()===``?NaN:Number(e)}function cP(){let e=rP(),t=(0,m.useRef)(e);t.current=e;let n=e.document.form,r=t=>{if(!t)return;let n=e.view?.attachments.find(e=>e.id===t.attachmentId),r=n?.state===`ready`&&n.stagedFileId?{id:n.stagedFileId,stageKind:n.kind===`reference`?`images`:n.kind,path:n.stagedFileId,originalFilename:n.name,bytes:n.bytes,state:`staged`,createdAt:e.view?.draft.createdAt??``}:void 0;return{key:t.attachmentId,name:t.name,file:r,error:n?.error??(n?.state===`reattach`||!r&&!e.attachmentUploading(t.attachmentId)?`Reattach this file`:void 0)}},i={...n,sources:{...n.sources,document:RS(n.sources,`document`)},document:{theme:YS(n.document),...n.document?.custom===void 0?{}:{custom:n.document.custom}},imagePrompts:n.imagePrompts.map(e=>({...e,number:Number(e.number)})),chunking:n.chunking.mode===`words`?{mode:`words`,...n.chunking.words===``?{}:{words:Number(n.chunking.words)}}:n.chunking.mode===`characters`?{mode:`characters`,...n.chunking.characters===``?{}:{characters:Number(n.chunking.characters)}}:{mode:n.chunking.mode},subtitles:{...n.subtitles,fontSize:Number(n.subtitles.fontSize)},imageSeconds:sP(n.imageSeconds),edgeSilenceSeconds:sP(n.edgeSilenceSeconds),zoomPercent:sP(n.zoomPercent),provided:{research:n.provided.research,article:n.provided.article,audio:r(n.provided.audio),thumbnail:r(n.provided.thumbnail),...n.provided.reference===void 0?{}:{reference:r(n.provided.reference)},shortsMusic:r(n.provided.shortsMusic),ambientBed:r(n.provided.ambientBed),images:n.provided.images.flatMap(e=>{let t=r(e);return t?[t]:[]})}},a=(0,m.useRef)(i);return a.current=i,[i,(0,m.useCallback)(e=>{let n=t.current.document,r=typeof e==`function`?e(a.current):e;a.current=r;let i=(e,t)=>e===void 0?``:Object.is(e,Number(t))?t:String(e),o=e=>e?{attachmentId:e.key,name:e.name}:null,{document:s,...c}=r.sources,{document:l,...u}=r,{shortsMusic:d,ambientBed:f}=r.provided,p=n.form.sources.document!==void 0||s!==`off`,m=n.form.document!==void 0||l.theme!==YS(n.form.document)||l.custom!==void 0;t.current.edit({...n,form:{...u,sources:p?r.sources:c,...m?{document:l}:{},imagePrompts:r.imagePrompts.map(e=>({...e,number:i(e.number,n.form.imagePrompts.find(t=>t.name===e.name)?.number??String(e.number))})),chunking:{...n.form.chunking,mode:r.chunking.mode,...r.chunking.mode===`words`?{words:i(r.chunking.words,n.form.chunking.words)}:{},...r.chunking.mode===`characters`?{characters:i(r.chunking.characters,n.form.chunking.characters)}:{}},subtitles:{...n.form.subtitles,...r.subtitles,fontSize:i(r.subtitles.fontSize,n.form.subtitles.fontSize)},imageSeconds:Object.is(r.imageSeconds,sP(n.form.imageSeconds))?n.form.imageSeconds:String(r.imageSeconds),edgeSilenceSeconds:Object.is(r.edgeSilenceSeconds,sP(n.form.edgeSilenceSeconds))?n.form.edgeSilenceSeconds:String(r.edgeSilenceSeconds),zoomPercent:Object.is(r.zoomPercent,sP(n.form.zoomPercent))?n.form.zoomPercent:String(r.zoomPercent),provided:{research:r.provided.research,article:r.provided.article,audio:o(r.provided.audio),thumbnail:o(r.provided.thumbnail),...r.provided.reference===void 0&&n.form.provided.reference===void 0?{}:{reference:o(r.provided.reference)},images:r.provided.images.map(e=>({attachmentId:e.key,name:e.name})),...d!==void 0||n.form.provided.shortsMusic!==void 0?{shortsMusic:o(d)}:{},...f!==void 0||n.form.provided.ambientBed!==void 0?{ambientBed:o(f)}:{}}}})},[])]}var lP={newVideo:[`C`],goHome:[`G`,`H`],goProjects:[`G`,`P`],goCalendar:[`G`,`C`],goSchedules:[`G`,`S`],goLibrary:[`G`,`L`],goChannels:[`G`,`K`],goSettings:[`G`,`,`],nextAction:[`Shift`,`N`],copyDescription:[`Shift`,`D`],reviewSetup:[`Ctrl`,`Enter`],save:[`Ctrl`,`S`]},uP=`slopify.notifications.browser`,dP=`slopify.notifications.sent`,fP=6e4,pP=new Set;function mP(){return typeof window<`u`&&`Notification`in window}function hP(){return mP()?Notification.permission:`unsupported`}function gP(){try{return window.localStorage.getItem(uP)===`on`}catch{return!1}}function _P(e){try{e?window.localStorage.setItem(uP,`on`):window.localStorage.removeItem(uP)}catch{}for(let e of pP)e()}function vP(e){pP.add(e);let t=t=>{t.key===uP&&e()};return window.addEventListener(`storage`,t),()=>{pP.delete(e),window.removeEventListener(`storage`,t)}}function yP(){return gP()&&hP()===`granted`}function bP(e){if(e===`unsupported`)return`This browser can't show notifications. Use a current Chrome, Edge, Firefox or Safari, or set a Notification URL below instead.`;if(e===`denied`)return`Notifications are blocked for this site. Allow them in your browser's site settings (the icon left of the address bar), reload, then turn Browser notifications on again.`}async function xP(){return mP()?Notification.permission==="default"?await Notification.requestPermission():Notification.permission:`unsupported`}async function SP(e,t=Date.now){let n=()=>{let n={};try{let e=JSON.parse(window.localStorage.getItem(dP)??`{}`);typeof e==`object`&&e&&(n=Object.fromEntries(Object.entries(e).filter(e=>typeof e[1]==`number`&&t()-e[1]<fP)))}catch{}if(n[e]!==void 0)return!1;try{window.localStorage.setItem(dP,JSON.stringify({...n,[e]:t()}))}catch{}return!0};try{if(typeof navigator<`u`&&navigator.locks!==void 0)return await navigator.locks.request(`slopify-run-notification`,n)}catch{}return n()}function CP(e,t){let n=new Notification(e.text.headline,{body:e.text.detail,tag:`slopify-run-${e.projectId}`});n.onclick=()=>{window.focus(),t(e.projectId),n.close()}}function wP(e,t){let n=new Notification(e.text.headline,{body:e.text.detail,tag:`slopify-topics-${e.scheduleId}`});n.onclick=()=>{window.focus(),t(),n.close()}}function TP(e,t){let n=e.title.trim()===``?`Untitled project`:e.title.trim(),r=new Notification(`Started: ${n}`,{body:`Slopify is working on it. You'll hear a different chime when it ends.`,tag:`slopify-run-${e.projectId}`});r.onclick=()=>{window.focus(),t(e.projectId),r.close()}}var EP=`slopify.notifications.sound`,DP=new Set;function OP(){try{return window.localStorage.getItem(EP)!==`off`}catch{return!0}}function kP(e){try{e?window.localStorage.removeItem(EP):window.localStorage.setItem(EP,`off`)}catch{}for(let e of DP)e()}function AP(e){DP.add(e);let t=t=>{t.key===EP&&e()};return window.addEventListener(`storage`,t),()=>{DP.delete(e),window.removeEventListener(`storage`,t)}}var jP={start:[[784,0,.16],[1175,.14,.3]],end:[[1047,0,.18],[1319,.16,.18],[1568,.32,.55]]},MP;function NP(){if(typeof window<`u`&&typeof window.AudioContext==`function`)return MP??=new window.AudioContext,MP}function PP(){let e=NP();e?.state===`suspended`&&e.resume().catch(()=>{})}function FP(e){let t=NP();if(t===void 0)return;t.state===`suspended`&&t.resume().catch(()=>{});let n=t.currentTime+.02,r=t.createDynamicsCompressor();r.threshold.value=-3,r.ratio.value=12,r.connect(t.destination);for(let[i,a,o]of jP[e])for(let[e,s,c]of[[1,.9,`sine`],[2,.25,`triangle`]]){let l=t.createOscillator(),u=t.createGain();l.type=c,l.frequency.value=i*e,u.gain.setValueAtTime(1e-4,n+a),u.gain.exponentialRampToValueAtTime(s,n+a+.012),u.gain.exponentialRampToValueAtTime(1e-4,n+a+o),l.connect(u).connect(r),l.start(n+a),l.stop(n+a+o+.05)}}function IP(e,t){if(e===`running`)switch(t){case`done`:return`ready`;case`partial`:return`partial`;case`failed`:return`failed`;case`pending`:return`waiting`;default:return}}var LP={article:`the article`,images:`an image`,narration:`the narration`,thumbnail:`the thumbnail`,shorts:`a short`};function RP(e){let t=e.title.trim()===``?`Untitled project`:e.title.trim(),n=BP(e.reason),r=LP[e.stage]??`an item`,i=`Review needs a decision: ${t}`;return{headline:n===void 0?i:`${i} — ${n}`,detail:`The automatic review flagged ${r} and kept it. Open the project and press Overrule to keep it or Redo to make it again.`}}var zP=140;function BP(e){let t=e?.split(/\r?\n/).map(e=>e.trim()).find(e=>e!==``);if(t!==void 0)return t.length<=zP?t:`${t.slice(0,139).trimEnd()}…`}function VP(e,t){let n=t.title.trim()===``?`Untitled project`:t.title.trim();switch(e){case`ready`:return t.makesVideo?{headline:`Video ready: ${n}`,detail:`Open the project to watch it.`}:{headline:`Run finished: ${n}`,detail:`Open the project to see its files.`};case`partial`:{let e=BP(t.reason),r=t.makesVideo?`Video ready with problems: ${n}`:`Run finished with problems: ${n}`;return{headline:e===void 0?r:`${r} — ${e}`,detail:`Open the project to see which step failed and the button that fixes it.`}}case`failed`:{let e=BP(t.reason);return{headline:e===void 0?`Run failed: ${n}`:`Run failed: ${n} — ${e}`,detail:`Open the project to see what stopped it and press Retry.`}}case`waiting`:return{headline:`Waiting for you: ${n}`,detail:`Open the project to review the held step or press Continue the run.`}}}function HP(e){let t=e.scheduleName.trim()===``?`Untitled schedule`:e.scheduleName.trim(),n=e.added,r=e.waiting>n?` ${String(e.waiting)} are waiting in all.`:``;return{headline:`${String(n)} new ${n===1?`topic is`:`topics are`} waiting for you`,detail:`Open Calendar → Suggested topics → ${t} to queue or reject ${n===1?`it`:`them`}.${r}`}}var UP={headline:`Slopify test notification`,detail:`Notifications work. You'll get one when a run finishes, fails or waits for you, and when a review needs your decision.`},WP=2048;function GP(e){let t=e.trim();if(t===``)return;if(t.length>2048)return`Keep the Notification URL to ${String(WP)} characters or fewer.`;let n;try{n=new URL(t)}catch{return`Enter a full address starting with https:// or http://, for example https://ntfy.sh/your-topic.`}if(n.protocol!==`https:`&&n.protocol!==`http:`)return`The Notification URL must start with https:// or http://.`;if(n.username!==``||n.password!==``)return`Remove the user name and password from the Notification URL; Slopify can't send them.`}var KP=new Set([`done`,`partial`,`failed`,`canceled`]);function qP(e){let t=new Map,n=new Set,r=()=>e.sounds?.()===!0&&e.play!==void 0,i=new Set,a=t=>{let n=t.catch(t=>{e.report(t)}).finally(()=>{i.delete(n)});i.add(n)},o=async(t,n,i)=>{let a=await e.subject(t);a!==void 0&&await e.claim(`${t}:${n}`)&&(r()&&e.play?.(`end`),e.enabled()&&e.show({projectId:t,kind:i,text:VP(i,a)}))},s=async t=>{let n=await e.subject(t);n!==void 0&&await e.claim(`${t}:started`)&&(r()&&e.play?.(`start`),e.enabled()&&e.showStart?.({projectId:t,title:n.title}))};return{observe:i=>{let c=t.get(i.projectId);if(t.set(i.projectId,i.state),c===i.state)return;let l=e.enabled()||r();if(i.state===`running`&&!n.has(i.projectId)){n.add(i.projectId),(r()||e.enabled()&&e.showStart!==void 0)&&a(s(i.projectId));return}KP.has(i.state)&&n.delete(i.projectId);let u=IP(c,i.state);u!==void 0&&l&&a(o(i.projectId,i.state,u))},observeTopics:t=>{if(t.added<=0||!e.enabled()||e.showTopics===void 0)return;let n=e.showTopics;a((async()=>{await e.claim(`topics:${t.scheduleId}:${String(t.waiting)}`)&&n({scheduleId:t.scheduleId,text:HP(t)})})())},observeReview:t=>{if(!e.enabled()||e.showReview===void 0)return;let n=e.showReview;a((async()=>{let r=await e.subject(t.projectId);r!==void 0&&await e.claim(`review:${t.verdictId}`)&&n({projectId:t.projectId,text:RP({title:r.title,stage:t.stage,reason:t.reason})})})())},seed:async()=>{try{for(let r of await e.seed())t.has(r.id)||(t.set(r.id,r.status),(r.status===`running`||r.status===`paused`)&&n.add(r.id))}catch(t){e.report(t)}},settled:async()=>{for(;i.size>0;)await Promise.all([...i])}}}function JP(){let{api:e}=z(),t=_(),n=Zi(),r=(0,m.useRef)(n);r.current=n;let i=(0,m.useMemo)(()=>qP({enabled:yP,sounds:OP,play:FP,showStart:e=>{TP(e,e=>{r.current({to:`/projects/$projectId`,params:{projectId:e}})})},seed:async()=>(await t.fetchQuery({...Yy(e),staleTime:5e3})).projects,subject:async t=>{let n=await jo(e,t);return{title:n.project.title,makesVideo:n.project.config.sources.video!==`off`,reason:n.stages.find(e=>e.state===`failed`)?.failureReason??void 0}},claim:e=>SP(e),showTopics:e=>{wP(e,()=>{r.current({to:`/calendar`})})},showReview:e=>{CP(e,e=>{r.current({to:`/projects/$projectId`,params:{projectId:e}})})},show:e=>{CP(e,e=>{r.current({to:`/projects/$projectId`,params:{projectId:e}})})},report:e=>{console.warn(`Slopify couldn't show a run notification.`,e)}}),[e,t]);return(0,m.useEffect)(()=>{let e=()=>yP()||OP();e()&&i.seed();let t=()=>{e()&&i.seed()},n=vP(t),r=AP(t);return window.addEventListener(`pointerdown`,PP,{once:!0}),window.addEventListener(`keydown`,PP,{once:!0}),()=>{n(),r(),window.removeEventListener(`pointerdown`,PP),window.removeEventListener(`keydown`,PP)}},[i]),i}function YP({open:e,title:t,onClose:n,children:r,footer:i,width:a=`wide`,headingRef:o,className:s}){let c=(0,m.useId)(),l=(0,m.useRef)(null),u=o??l,d=(0,m.useRef)(null),f=(0,m.useRef)(null),p=(0,m.useRef)(n);return(0,m.useEffect)(()=>{p.current=n}),(0,m.useEffect)(()=>{if(!e)return;d.current=document.activeElement,f.current?.contains(document.activeElement)||u.current?.focus({preventScroll:!0});let t=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`[data-slot="dialog-content"][data-state="open"]`)||p.current()};return document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`keydown`,t);let e=d.current;e instanceof HTMLElement&&e.isConnected&&e.focus({preventScroll:!0})}},[e,u]),e?(0,h.jsxs)(`aside`,{ref:f,role:`dialog`,"aria-modal":`false`,"aria-labelledby":c,"data-slot":`drawer`,className:L(`fixed top-0 right-0 bottom-0 z-50 flex w-full flex-col border-l border-line bg-raised shadow-[var(--shadow-dialog)]`,a===`wide`?`sm:w-[min(560px,100vw)]`:`sm:w-[min(440px,100vw)]`,`data-[state=open]:animate-tick-in motion-reduce:animate-none`,s),"data-state":`open`,children:[(0,h.jsxs)(`div`,{className:`flex min-h-12 shrink-0 items-center gap-3 border-b border-line px-4`,children:[(0,h.jsx)(`h2`,{ref:u,id:c,tabIndex:-1,className:`min-w-0 flex-1 truncate text-title-3 font-semibold focus-visible:outline-offset-[-2px]`,children:t}),(0,h.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close`,className:`inline-flex size-8 items-center justify-center rounded-control text-ink-2 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,className:`size-4`})})]}),(0,h.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:r}),i?(0,h.jsx)(`div`,{className:`flex min-h-14 shrink-0 flex-wrap items-center gap-2 border-t border-line px-4 py-2 pb-[max(8px,env(safe-area-inset-bottom))]`,children:i}):null]}):null}var XP=[{id:`text-key`,title:`1. Connect a text provider`,target:`keys-llm`,page:`settings`},{id:`audio-key`,title:`2. Connect a voice provider`,target:`keys-tts`,page:`settings`},{id:`image-key`,title:`3. Connect an image provider`,target:`keys-image`,page:`settings`},{id:`voice`,title:`4. Add a narration voice`,target:`voices`,page:`settings`},{id:`article-name`,title:`5. Name your article prompt`,target:`prompt-name`,page:`article`},{id:`article-body`,title:`6. Write instructions with keywords`,target:`prompt-body`,page:`article`},{id:`article-keywords`,title:`7. Check the detected keywords`,target:`prompt-slots`,page:`article`},{id:`article-save`,title:`8. Save your article prompt`,target:`prompt-save`,page:`article`},{id:`image-prompt`,title:`9. Create an image prompt`,target:`prompt-editor`,page:`image`},{id:`image-save`,title:`10. Save your image prompt`,target:`prompt-save`,page:`image`},{id:`play-options`,title:`11. Name the project and choose text generation`,target:`play-options`,page:`play`},{id:`play-article`,title:`12. Choose your article`,target:`play-article`,page:`play`},{id:`play-keywords`,title:`13. Fill in your keywords`,target:`play-keywords`,page:`play`},{id:`play-audio`,title:`14. Choose narration`,target:`play-audio`,page:`play`},{id:`play-images`,title:`15. Choose images`,target:`play-images`,page:`play`},{id:`play-video`,title:`16. Choose video output`,target:`play-video`,page:`play`},{id:`play-subtitles`,title:`17. Style optional subtitles`,target:`play-subtitles`,page:`play`},{id:`play-start`,title:`18. Review and start your run`,target:`play-start`,page:`play`},{id:`project`,title:`19. Follow and control the run`,target:`project-controls`,page:`project`},{id:`download`,title:`20. Download your results`,target:`project-video`,page:`project`},{id:`run-cost`,title:`21. See what the run cost`,target:`project-rail-cost`,page:`project`},{id:`studio-prep`,title:`22. Prepare the YouTube upload`,target:`project-rail-video`,page:`project`},{id:`home`,title:`23. Check Home each day`,target:`home`,page:`home`},{id:`channels`,title:`24. Set up a channel`,target:`channels`,page:`channels`},{id:`calendar`,title:`25. Plan uploads on the calendar`,target:`calendar`,page:`calendar`}],ZP=`home`;function QP(e,t){return e.active?t.type===`project-created`?{...e,projectId:t.id,step:XP.findIndex(e=>e.id===`project`)}:t.kind===`article`?{...e,articleId:t.id}:t.kind===`image`?{...e,imageId:t.id}:e:e}function $P(e){let t=XP.findIndex(t=>t.id===e);return t<0?void 0:t}var eF={"play-options":`content`,"play-article":`content`,"play-keywords":`content`,"play-audio":`outputs`,"play-images":`outputs`,"play-video":`outputs`,"play-subtitles":`style`,"play-start":`content`};function tF(e){return e.kind===`keyed`?e.hasKey:e.kind===`local`?e.available:e.installed&&e.issue===void 0}var nF={research:`Research`,article:`Article`,audio:`Audio`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`Document`};function rF(e){return e.sources.video===`off`?e.sources.audio===`off`?`article`:`audio`:`video`}function iF(e,t){return e===`video`&&rF(t)===`audio`?`Audio export`:nF[e]}function aF(e,t){return e.kind===`video`&&e.state===`running`&&t.subtitles!==void 0&&t.subtitles.mode!==`off`&&e.progressTotal===100&&(e.progressCurrent??0)<=35}var oF={research:(e,t)=>`chapter ${String(e)} of ${String(t)}`,article:(e,t)=>`${String(e)} of ${String(t)}`,audio:(e,t)=>`chunk ${String(e)} of ${String(t)}`,images:(e,t)=>`image ${String(e)} of ${String(t)}`,thumbnail:(e,t)=>`${String(e)} of ${String(t)}`,video:(e,t)=>`${String(vF(e,t))}% rendered`,document:(e,t)=>`${String(e)} of ${String(t)}`},sF={audio_intro:`intro`,audio_body:`body`,audio_outro:`outro`};function cF(e,t,n,r=!1){let i=t.filter(t=>t.stageKind===e.kind);switch(e.state){case`skipped`:return`Not part of this run`;case`pending`:return n.status===`paused`||r?`Waits until you continue the run`:e.retryAt===void 0?e.kind===`images`||e.kind===`thumbnail`&&e.source===`from_prompt`?`Ready to run`:`Waits for the stages above`:`Trying again at ${fF(e.retryAt)}`;case`provided`:return hF(i)??`Provided`;case`failed`:return`Stopped after ${pF(e)}`;case`canceled`:return`Canceled by user`;case`running`:return aF(e,n.config)?`Preparing subtitles · ${String(vF(e.progressCurrent??0,35))}%`:e.activity===void 0?e.kind===`video`&&rF(n.config)===`audio`?`Exporting combined audio`:e.progressTotal===null||e.progressTotal<=0?`Running`:oF[e.kind](e.progressCurrent??0,e.progressTotal):uF(lF(e)??``);case`done`:return mF(e.kind,i,n)}}function lF(e){let t=e.activity;if(t!==void 0)return t.percent===void 0?t.done!==void 0&&t.total!==void 0?`${t.label} (${String(t.done)} of ${String(t.total)})`:t.label:`${t.label} (${String(t.percent)}%)`}function uF(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function dF(e){let t=e.activity;if(t?.percent!==void 0)return t.percent/100;if(t?.done!==void 0&&t.total!==void 0&&t.total>0)return t.done/t.total;if(t===void 0&&!(e.progressTotal===null||e.progressTotal<=0))return Math.min(1,Math.max(0,(e.progressCurrent??0)/e.progressTotal))}function fF(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function pF(e){return e.attemptCount===1?`1 attempt`:`${String(e.attemptCount)} attempts`}function mF(e,t,n){switch(e){case`research`:return`Notes ready`;case`article`:{let e=t.filter(e=>e.role===`sources`||e.role===`glossary`);return e.length===0?`Article ready`:`Article and ${String(e.length)} end-matter files`}case`audio`:return SF([bF(t.flatMap(e=>{let t=sF[e.role];return t===void 0?[]:[t]})),_F(gF(t))]);case`images`:return yF(t.filter(e=>e.role===`image`).length,`image`);case`thumbnail`:return t.length===0?`Thumbnail ready`:`1 image`;case`video`:return SF([_F(gF(t)),rF(n.config)===`audio`?`WAV · stereo · 48 kHz`:n.format]);case`document`:return`PDF · ${XS(n.config.document)} theme`}}function hF(e){let t=e.flatMap(e=>e.originalFilename===null?[]:[e.originalFilename]);return t.length===0?void 0:t.join(`, `)}function gF(e){let t=Math.max(0,...e.map(e=>e.durationMs??0));return t===0?void 0:t}function _F(e){if(e===void 0||!Number.isFinite(e)||e<=0)return;let t=Math.round(e/1e3),n=[Math.floor(t/60)%60,t%60].map(e=>String(e).padStart(2,`0`)),r=Math.floor(t/3600);return r===0?n.join(`:`):[String(r),...n].join(`:`)}function vF(e,t){return t<=0?0:Math.min(100,Math.max(0,Math.round(e/t*100)))}function yF(e,t){return e===1?`1 ${t}`:`${String(e)} ${t}s`}function bF(e){if(e.length!==0)return e.length===1?xF(e[0]??``):xF(`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]??``}`)}function xF(e){return e.charAt(0).toUpperCase()+e.slice(1)}function SF(e){return e.filter(e=>e!==void 0&&e!==``).join(` · `)}var CF=12,wF=16;function TF(e,t,n){return Math.max(t,Math.min(e,Math.max(t,n)))}function EF(e,t,n){let r=Math.min(n.width,t.width-24),i=TF(e?.left??(t.width-r)/2,CF,t.width-r-CF),a=TF((e?.top??0)+((e?.height??t.height)-n.height)/2,CF,t.height-n.height-CF),o=t.height-n.height-CF;if(!e)return{left:i,top:a,width:r,docked:!1};let s=e.left+e.width,c=e.top+e.height;return s+wF+r<=t.width-CF?{left:s+wF,top:a,width:r,docked:!1}:e.left-wF-r>=CF?{left:e.left-wF-r,top:a,width:r,docked:!1}:c>=CF&&c+wF+n.height<=t.height-CF?{left:i,top:c+wF,width:r,docked:!1}:e.top-wF-n.height>=CF&&e.top<=t.height-CF?{left:i,top:e.top-wF-n.height,width:r,docked:!1}:{left:t.width-r-CF,top:Math.max(CF,o),width:r,docked:!0}}function DF(e,t,n=t.height){let r=TF(e.left-6,0,t.width),i=TF(e.top-6,0,Math.min(n,t.height)),a=TF(e.left+e.width+6,0,t.width),o=TF(e.top+e.height+6,0,Math.min(n,t.height));return a>r&&o>i?{left:r,top:i,width:a-r,height:o-i}:null}var OF=`[data-slot="select-content"], [data-slot="dropdown-menu-content"], [data-slot="menu-content"]`;function kF(e){try{return document.querySelector(e)}catch{return null}}function AF(){return[...document.querySelectorAll(`[data-slot="dialog-content"][data-state="open"]`)].at(-1)??null}function jF(e){if(!e)return[];let t=[e,...e.querySelectorAll(`[aria-controls]`)],n=new Set(t.flatMap(e=>(e.getAttribute(`aria-controls`)??``).split(` `)));return[...document.querySelectorAll(OF)].filter(e=>n.has(e.id))}function MF(e){let t=e.getBoundingClientRect();return t.width>0&&t.height>0?{left:t.left,top:t.top,width:t.width,height:t.height}:null}var NF=`a[href], button, input, select, textarea, summary, [tabindex], [contenteditable="true"]`;function PF(e,t,n,r){let i=(0,m.useRef)(document.activeElement),a=(0,m.useRef)(t);a.current=t,(0,m.useEffect)(()=>{let e=i.current;return()=>{queueMicrotask(()=>{e instanceof HTMLElement&&e.isConnected&&!n.current&&e.focus({preventScroll:!0})})}},[n]),(0,m.useEffect)(()=>{let t=()=>{let t=kF(e);return[t,n.current,...jF(t)].filter(e=>e!==null)},i=e=>e instanceof Node&&t().some(t=>t.contains(e)),o=e=>{AF()||i(e.target)||(e.preventDefault(),e.stopImmediatePropagation())},s=e=>{AF()||i(e.target)||e.target instanceof HTMLElement&&e.target.hasAttribute(`data-radix-focus-guard`)||r.current?.focus({preventScroll:!0})},c=n=>{if(AF())return;let r=jF(kF(e));if(n.key===`Escape`){if(r.length>0)return;n.preventDefault(),n.stopImmediatePropagation(),a.current();return}if(n.key!==`Tab`){i(n.target)||o(n);return}if(r.length>0)return;let s=t().flatMap(e=>[e,...e.querySelectorAll(NF)]).filter((e,t,n)=>n.indexOf(e)===t&&e.tabIndex>=0&&!e.matches(`:disabled, [hidden], [aria-hidden='true']`)&&!e.closest(`[hidden], [inert]`)&&(!e.closest(`details:not([open])`)||e.closest(`summary`)!==null));if(s.length===0)return;let c=s.indexOf(document.activeElement),l=c===-1?n.shiftKey?s.length-1:0:(c+(n.shiftKey?-1:1)+s.length)%s.length;n.preventDefault(),s[l]?.focus()},l=[`pointerdown`,`pointerup`,`mousedown`,`mouseup`,`click`,`dblclick`,`contextmenu`];for(let e of l)window.addEventListener(e,o,!0);return window.addEventListener(`keydown`,c,!0),window.addEventListener(`focusin`,s,!0),()=>{for(let e of l)window.removeEventListener(e,o,!0);window.removeEventListener(`keydown`,c,!0),window.removeEventListener(`focusin`,s,!0)}},[e,n,r])}function FF(e,t,n,r,i,a){let[o,s]=(0,m.useState)(()=>({key:e,target:null,portals:[],width:window.innerWidth,height:window.innerHeight,cardHeight:260,modalOpen:AF()!==null}));return(0,m.useLayoutEffect)(()=>{let o=0,c=0,l=null,u=null,d=new Map,f=new ResizeObserver(()=>h()),p=e=>{for(let[t,n]of d)e.has(t)||(t.style.zIndex=n,d.delete(t))},m=()=>{o=0;let r=kF(t);r!==u&&(u&&f.unobserve(u),r&&f.observe(r),u=r);let i=r?MF(r):null;r&&i&&l!==r&&(l=r,cancelAnimationFrame(c),c=requestAnimationFrame(()=>{c=0,r.isConnected&&(r.scrollIntoView({block:`start`,inline:`nearest`,behavior:`instant`}),m())}));let a=jF(r),h=new Set;for(let e of a){let t=e.closest(`[data-radix-popper-content-wrapper]`)??e;h.add(t),d.has(t)||(d.set(t,t.style.zIndex),t.style.zIndex=`102`)}p(h);let g={key:e,target:i,portals:a.map(MF).filter(e=>e!==null),width:window.innerWidth,height:window.innerHeight,cardHeight:n.current?.getBoundingClientRect().height||260,modalOpen:AF()!==null};s(e=>JSON.stringify(e)===JSON.stringify(g)?e:g)};function h(){o||=requestAnimationFrame(m)}let g=new MutationObserver(e=>{e.some(e=>!i.current?.contains(e.target)&&e.target!==a.current)&&h()});return g.observe(document.body,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`id`,`class`,`style`,`hidden`,`aria-controls`,`data-state`,`data-tour`]}),n.current&&f.observe(n.current),f.observe(document.documentElement),window.addEventListener(`resize`,h),window.addEventListener(`scroll`,h,!0),window.visualViewport?.addEventListener(`resize`,h),window.visualViewport?.addEventListener(`scroll`,h),m(),AF()||r.current?.focus({preventScroll:!0}),()=>{cancelAnimationFrame(o),cancelAnimationFrame(c),f.disconnect(),g.disconnect(),window.removeEventListener(`resize`,h),window.removeEventListener(`scroll`,h,!0),window.visualViewport?.removeEventListener(`resize`,h),window.visualViewport?.removeEventListener(`scroll`,h),p(new Set)}},[e,t,n,r,i,a]),o}function IF({stepId:e,target:t,title:n,children:r,progress:i,onNext:a,onBack:o,onClose:s,nextLabel:c=`Next`,nextDisabled:l=!1,onSkip:u,skipLabel:d=`Skip this step`}){let f=(0,m.useId)(),p=`${e}:${t}`,g=(0,m.useRef)(null),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=(0,m.useRef)(null),b=FF(p,t,g,_,v,y);PF(t,s,g,_);let[x,S]=(0,m.useState)({key:p,height:0}),C=b.key===p?b.target:null,w={width:b.width,height:b.height},T={width:Math.min(360,w.width-24),height:b.cardHeight},E=EF(C,w,T),D=C?DF(C,w,E.docked?E.top-12:w.height):null,O=b.key===p?b.portals.map(e=>DF(e,w)).filter(e=>e!==null):[],k=[...D?[D]:[],...O],A=`M0 0H${w.width}V${w.height}H0Z`+(D?`M${D.left} ${D.top}H${D.left+D.width}V${D.top+D.height}H${D.left}Z`:``);(0,m.useLayoutEffect)(()=>{S(e=>{let t=Math.max(e.key===p?e.height:0,E.docked?T.height+24:0);return e.key===p&&e.height===t?e:{key:p,height:t}})},[p,E.docked,T.height]);let ee=x.key===p?x.height:0;return(0,m.useEffect)(()=>{let e=document.documentElement,t=e.style.scrollPaddingBottom;return e.style.scrollPaddingBottom=`${ee}px`,()=>{e.style.scrollPaddingBottom=t}},[ee]),(0,Zu.createPortal)((0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{ref:y,"aria-hidden":`true`,style:{height:ee}}),(0,h.jsxs)(`div`,{ref:v,hidden:b.modalOpen,"data-tutorial":`spotlight`,className:`pointer-events-none fixed inset-0 z-[100] font-sans`,children:[(0,h.jsxs)(`svg`,{"aria-hidden":`true`,className:`absolute inset-0 h-full w-full`,width:w.width,height:w.height,children:[(0,h.jsx)(`defs`,{children:(0,h.jsxs)(`mask`,{id:`${f}-mask`,children:[(0,h.jsx)(`rect`,{width:`100%`,height:`100%`,fill:`white`}),k.map(e=>(0,h.jsx)(`rect`,{x:e.left,y:e.top,width:e.width,height:e.height,rx:`6`,fill:`black`},`${e.left}:${e.top}:${e.width}:${e.height}`))]})}),(0,h.jsx)(`rect`,{width:`100%`,height:`100%`,fill:`rgb(0 0 0 / 0.72)`,mask:`url(#${f}-mask)`}),(0,h.jsx)(`path`,{d:A,fill:`transparent`,fillRule:`evenodd`,pointerEvents:`fill`}),D&&(0,h.jsx)(`rect`,{"data-tutorial":`hole`,x:D.left,y:D.top,width:D.width,height:D.height,rx:`6`,fill:`none`,stroke:`var(--color-accent)`,strokeWidth:`2`})]}),(0,h.jsxs)(`section`,{ref:g,"aria-label":`Interactive getting started guide`,"aria-describedby":`${f}-instructions`,"data-tutorial":`card`,className:`pointer-events-auto fixed z-[101] flex flex-col gap-3 rounded-media border border-line-strong bg-surface p-4 text-body text-ink shadow-[var(--shadow-pop)]`,style:{left:E.left,top:E.top,width:E.width,maxHeight:Math.min(w.height-24,Math.max(160,Math.min(420,w.height*.48)))},children:[(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`engraved text-accent-ink`,children:[`Getting started · `,i]}),(0,h.jsx)(R,{variant:`quiet`,onClick:s,"aria-label":`Exit guide`,className:`h-7 px-2`,children:`Exit`})]}),(0,h.jsx)(`h2`,{ref:_,id:`${f}-title`,tabIndex:-1,className:`shrink-0 text-title-3 font-bold outline-none`,children:n}),(0,h.jsxs)(`div`,{id:`${f}-instructions`,className:`min-h-0 overflow-y-auto text-ink-2 [&_p+p]:mt-2 [&_code]:text-ink`,children:[r,!C&&(0,h.jsx)(`p`,{role:`status`,className:`mt-3 text-waiting`,children:`This section is not available yet. Wait for the page to load, go back, or exit the guide.`}),E.docked&&C&&(0,h.jsx)(`p`,{className:`mt-3 text-small`,children:`Scroll the page to work through the highlighted section.`})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-t border-line pt-3`,children:[o&&(0,h.jsx)(R,{onClick:o,children:`Back`}),u&&(0,h.jsx)(R,{variant:`quiet`,onClick:u,className:`px-2`,children:d}),(0,h.jsx)(R,{variant:`primary`,onClick:a,disabled:l||!C,className:`ml-auto`,children:c})]})]})]})]}),document.body)}function LF({href:e,children:t}){return(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-ink underline underline-offset-2`,children:t})}function RF({text:e}){let[t,n]=(0,m.useState)(!1),[r,i]=(0,m.useState)(!1);return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(`p`,{className:`select-text rounded-control border border-line-strong bg-raised p-3 text-small leading-relaxed`,children:e}),(0,h.jsx)(R,{onClick:()=>{if(i(!1),!navigator.clipboard){i(!0);return}navigator.clipboard.writeText(e).then(()=>n(!0),()=>i(!0))},children:t?`Copied`:`Copy example`}),r?(0,h.jsx)(`p`,{role:`status`,children:`Select the example above and copy it manually.`}):null]})}var zF={signUp:{label:`platform.openai.com/signup`,url:`https://platform.openai.com/signup`},keyPage:{label:`platform.openai.com/api-keys`,url:`https://platform.openai.com/api-keys`},billing:{label:`Billing`,url:`https://platform.openai.com/settings/organization/billing/overview`},steps:[`Sign up or sign in to the OpenAI platform.`,`Open Billing and buy prepaid credit (new accounts need at least $5 before any call works).`,`Open API keys, choose Create new secret key, and copy it (it is shown once).`,`Paste it here, choose Save, then Test.`],permissions:`A key with All permissions works. A restricted key needs Models: Read (for Test) and Model capabilities: Request (for speech and images). GPT Image models may also need Verify Organization under Settings → Organization → General on the OpenAI platform.`,docs:{label:`OpenAI API docs`,url:`https://developers.openai.com/api/docs/guides/error-codes`}},BF={signUp:{label:`aistudio.google.com`,url:`https://aistudio.google.com`},keyPage:{label:`aistudio.google.com/apikey`,url:`https://aistudio.google.com/apikey`},billing:{label:`Projects → Set up billing`,url:`https://aistudio.google.com/projects`},steps:[`Sign in to Google AI Studio with your Google account.`,`Open Projects and choose Set up billing next to your project: Gemini image models are not available on the free tier.`,`Open API keys, choose Create API key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`Use a key made in AI Studio. An older Google Cloud key must be set to Restrict to Gemini API only, or Google rejects it.`,docs:{label:`Gemini API keys`,url:`https://ai.google.dev/gemini-api/docs/api-key`}},VF={openrouter:{signUp:{label:`openrouter.ai/sign-up`,url:`https://openrouter.ai/sign-up`},keyPage:{label:`openrouter.ai/settings/keys`,url:`https://openrouter.ai/settings/keys`},billing:{label:`Credits`,url:`https://openrouter.ai/settings/credits`},steps:[`Sign up at OpenRouter.`,`Open Credits and buy credit (paid models are charged from it; a negative balance stops even free models).`,`Open Keys, choose Create API key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`Keys have no scopes. If you set a credit limit on the key, keep it above what a run costs.`,docs:{label:`OpenRouter docs`,url:`https://openrouter.ai/docs/api-reference/limits`}},"openai-tts":zF,"openai-image":zF,"google-image":BF,"google-tts":{...BF,steps:[`Sign in to Google AI Studio with your Google account.`,`Open API keys, choose Create API key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`The same Gemini API key as Google images: with one saved there, Gemini voices use it and nothing is needed here. ${BF.permissions}`},fal:{signUp:{label:`fal.ai/login`,url:`https://fal.ai/login`},keyPage:{label:`fal.ai/dashboard/keys`,url:`https://fal.ai/dashboard/keys`},billing:{label:`Billing`,url:`https://fal.ai/dashboard/billing`},steps:[`Sign up at fal.ai.`,`Open Billing and buy credit: fal.ai is prepaid and locks the account when the balance runs out.`,`Open Keys, choose Add key with the API scope, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`The API scope is enough; Slopify does not need an ADMIN key.`,docs:{label:`fal.ai authentication`,url:`https://fal.ai/docs/model-apis/authentication`}},replicate:{signUp:{label:`replicate.com/signin`,url:`https://replicate.com/signin`},keyPage:{label:`replicate.com/account/api-tokens`,url:`https://replicate.com/account/api-tokens`},billing:{label:`Billing`,url:`https://replicate.com/account/billing`},steps:[`Sign in to Replicate.`,`Open Billing and buy credit: Replicate needs credit up front before it runs paid models.`,`Open API tokens, create a token, and copy it (it starts with r8_).`,`Paste it here, choose Save, then Test.`],permissions:`Tokens have no scopes.`,docs:{label:`Replicate billing`,url:`https://replicate.com/docs/topics/billing`}},elevenlabs:{signUp:{label:`elevenlabs.io/app/sign-up`,url:`https://elevenlabs.io/app/sign-up`},keyPage:{label:`elevenlabs.io/app/developers/api-keys`,url:`https://elevenlabs.io/app/developers/api-keys`},steps:[`Sign up at ElevenLabs.`,`Open Developers → API keys, choose Create key, and copy it.`,`Paste it here, choose Save, then Test.`],permissions:`A restricted key needs Text to Speech access and Models read access (models_read) for Test; Voices read helps when picking voices. Remove any credit quota or IP allowlist that would block this computer.`,docs:{label:`ElevenLabs API keys`,url:`https://elevenlabs.io/docs/api-reference/models/list`}},cartesia:{signUp:{label:`play.cartesia.ai/sign-up`,url:`https://play.cartesia.ai/sign-up`},keyPage:{label:`play.cartesia.ai/keys`,url:`https://play.cartesia.ai/keys`},steps:[`Sign up at Cartesia (the free plan needs no card).`,`Open API Keys, create a key, and copy it (it starts with sk_car_).`,`Paste it here, choose Save, then Test.`],permissions:`Keys have no scopes.`,docs:{label:`Cartesia authentication`,url:`https://docs.cartesia.ai/get-started/authenticate-your-client-applications`}},inworld:{signUp:{label:`platform.inworld.ai/signup`,url:`https://platform.inworld.ai/signup`},keyPage:{label:`platform.inworld.ai/api-keys`,url:`https://platform.inworld.ai/api-keys`},billing:{label:`Billing`,url:`https://platform.inworld.ai/billing`},steps:[`Sign up at the Inworld platform.`,`Open API Keys and choose Generate new key (a Standard key, not Realtime-only).`,`Copy the Base64 credentials value exactly as shown, without encoding it again.`,`Paste it here, choose Save, then Test.`],permissions:`A Standard key covers speech and reading voices. Realtime-only keys do not work.`,docs:{label:`Inworld API keys`,url:`https://docs.inworld.ai/portal/api-keys`}}},HF=[{id:`openrouter`,family:`llm`,displayName:`OpenRouter`,auth:`key`},{id:`claude-code`,family:`llm`,displayName:`Claude Code CLI`,auth:`cli`,binary:`claude`,versionArgs:[`--version`]},{id:`codex`,family:`llm`,displayName:`Codex CLI`,auth:`cli`,binary:`codex`,versionArgs:[`--version`]},{id:`gemini`,family:`llm`,displayName:`Gemini CLI`,auth:`cli`,binary:`gemini`,versionArgs:[`--version`]},{id:`elevenlabs`,family:`tts`,displayName:`ElevenLabs`,auth:`key`},{id:`openai-tts`,family:`tts`,displayName:`OpenAI`,auth:`key`},{id:`cartesia`,family:`tts`,displayName:`Cartesia`,auth:`key`},{id:`inworld`,family:`tts`,displayName:`Inworld`,auth:`key`},{id:`system-voice`,family:`tts`,displayName:`System voice`,auth:`local`},{id:`google-tts`,family:`tts`,displayName:`Google Gemini`,auth:`key`},{id:`fal`,family:`image`,displayName:`fal.ai`,auth:`key`},{id:`replicate`,family:`image`,displayName:`Replicate`,auth:`key`},{id:`openai-image`,family:`image`,displayName:`OpenAI`,auth:`key`},{id:`google-image`,family:`image`,displayName:`Google`,auth:`key`},{id:`codex-image`,family:`image`,displayName:`Codex CLI`,auth:`cli`,binary:`codex`,versionArgs:[`--version`]}],UF=[{name:`Zephyr`,style:`Bright`},{name:`Puck`,style:`Upbeat`},{name:`Charon`,style:`Informative`},{name:`Kore`,style:`Firm`},{name:`Fenrir`,style:`Excitable`},{name:`Leda`,style:`Youthful`},{name:`Orus`,style:`Firm`},{name:`Aoede`,style:`Breezy`},{name:`Callirrhoe`,style:`Easy-going`},{name:`Autonoe`,style:`Bright`},{name:`Enceladus`,style:`Breathy`},{name:`Iapetus`,style:`Clear`},{name:`Umbriel`,style:`Easy-going`},{name:`Algieba`,style:`Smooth`},{name:`Despina`,style:`Smooth`},{name:`Erinome`,style:`Clear`},{name:`Algenib`,style:`Gravelly`},{name:`Rasalgethi`,style:`Informative`},{name:`Laomedeia`,style:`Upbeat`},{name:`Achernar`,style:`Soft`},{name:`Alnilam`,style:`Firm`},{name:`Schedar`,style:`Even`},{name:`Gacrux`,style:`Mature`},{name:`Pulcherrima`,style:`Forward`},{name:`Achird`,style:`Friendly`},{name:`Zubenelgenubi`,style:`Casual`},{name:`Vindemiatrix`,style:`Gentle`},{name:`Sadachbia`,style:`Lively`},{name:`Sadaltager`,style:`Knowledgeable`},{name:`Sulafat`,style:`Warm`}];function WF(e){return HF.flatMap(t=>{let n=t.auth===`key`?VF[t.id]:void 0;return t.family===e&&n!==void 0?[{id:t.id,name:t.displayName,url:n.keyPage.url}]:[]})}function GF({family:e}){return(0,h.jsx)(`p`,{children:WF(e).map((e,t)=>(0,h.jsxs)(`span`,{children:[t===0?null:` · `,(0,h.jsx)(LF,{href:e.url,children:`${e.name} keys`})]},e.id))})}function KF(e){let t=WF(e).map(e=>e.name);return t.length<2?t[0]??``:`${t.slice(0,-1).join(`, `)} or ${t.at(-1)??``}`}function qF({step:e}){switch(e){case`text-key`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`First, choose what will write your scripts. You only need one text provider.`}),(0,h.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5`,children:[(0,h.jsxs)(`li`,{children:[`Sign in to`,` `,(0,h.jsx)(LF,{href:VF.openrouter?.keyPage.url??`https://openrouter.ai`,children:`OpenRouter`}),`, create an API key, and make sure the account can use your chosen model.`]}),(0,h.jsxs)(`li`,{children:[`Paste it into OpenRouter’s `,(0,h.jsx)(`strong`,{children:`API key`}),` field here, press`,` `,(0,h.jsx)(`strong`,{children:`Test`}),` to check it, then `,(0,h.jsx)(`strong`,{children:`Save`}),`.`]})]}),(0,h.jsx)(`p`,{children:`Already using Claude Code, Codex or Gemini CLI? You can use its existing CLI login instead. “Installed” means Slopify found the CLI; sign in through that CLI before generating. If it is missing, enter its executable path and save to check again.`}),(0,h.jsx)(`p`,{className:`text-ink-3`,children:`These are the real Settings controls. The tutorial never reads your key. Skip any step you have already handled.`})]});case`audio-key`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The voice provider turns the finished article into audio. Choose `,KF(`tts`),`; you only need one.`]}),(0,h.jsxs)(`p`,{children:[`Create a key in your provider’s account, enable the API access or credits it requires, then paste the key into its row, press `,(0,h.jsx)(`strong`,{children:`Test`}),` to check it, and press`,` `,(0,h.jsx)(`strong`,{children:`Save`}),`.`]}),(0,h.jsx)(GF,{family:`tts`}),(0,h.jsx)(`p`,{children:`Next, you’ll add the exact voice that this provider should use. Skip voice setup if you plan to provide your own narration or turn Audio Off.`})]});case`image-key`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Choose one image provider (`,KF(`image`),`), create a key in its dashboard, paste it into the matching row, press `,(0,h.jsx)(`strong`,{children:`Test`}),` to check it, and press`,` `,(0,h.jsx)(`strong`,{children:`Save`}),`.`]}),(0,h.jsx)(GF,{family:`image`}),(0,h.jsxs)(`p`,{children:[`A saved key is not a billing check. The selected image model needs available quota. If Google reports `,(0,h.jsx)(`strong`,{children:`limit: 0`}),`, check the key’s project, billing and image-model quota before retrying.`]}),(0,h.jsx)(`p`,{children:`OpenAI’s voice and image rows are saved separately, even when you use the same API key. Skip this step if you plan to provide your own images or turn Images and Thumbnail Off.`})]});case`voice`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5`,children:[(0,h.jsxs)(`li`,{children:[`Enter a `,(0,h.jsx)(`strong`,{children:`Voice name`}),` you will recognize, such as “Travel narrator.”`]}),(0,h.jsxs)(`li`,{children:[`Select the `,(0,h.jsx)(`strong`,{children:`Provider`}),` whose voice key you saved.`]}),(0,h.jsxs)(`li`,{children:[`Copy the exact `,(0,h.jsx)(`strong`,{children:`Voice ID`}),` from that provider’s voice library or documentation.`]}),(0,h.jsxs)(`li`,{children:[`Press `,(0,h.jsx)(`strong`,{children:`Add voice`}),`.`]})]}),(0,h.jsx)(`p`,{children:`The name is your label; the ID tells the provider which voice to use. Slopify checks the ID with the provider when narration runs. A voice is only required when Audio is set to Generate.`})]})}}var JF=`Write a 150-word narration about {{topic}} for {{audience}}. Open with an interesting fact, explain three highlights, and end with one memorable takeaway. Use natural spoken English. Return only the narration, without headings or stage directions.`,YF=`A cinematic editorial photograph of {{topic}}, with natural light, a clear focal point, rich detail, and no text or logos. Compose it for a travel video.`;function XF({step:e,output:t=`video`}){switch(e){case`text-key`:case`audio-key`:case`image-key`:case`voice`:return(0,h.jsx)(qF,{step:e});case`article-name`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`A prompt is a reusable set of instructions. This one will write the narration for each video.`}),(0,h.jsxs)(`p`,{children:[`Give it a recognizable name, such as `,(0,h.jsx)(`strong`,{children:`Short travel narration`}),`. This is the prompt’s library name, not your video’s title.`]}),(0,h.jsx)(`p`,{children:`The next steps will add its instructions and reusable keywords.`})]});case`article-body`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`Tell the model what to write, who it is for, the length, and the style. Put anything you want to change between runs inside double braces.`}),(0,h.jsx)(RF,{text:JF}),(0,h.jsxs)(`p`,{children:[`Paste or write the instructions in `,(0,h.jsx)(`strong`,{children:`Body`}),`. `,(0,h.jsx)(`strong`,{children:`{{topic}}`}),` `,`and `,(0,h.jsx)(`strong`,{children:`{{audience}}`}),` will become fields on Play.`]})]});case`article-keywords`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`This panel detects your keywords as you type. With the example, it should list`,` `,(0,h.jsx)(`strong`,{children:`topic`}),` and `,(0,h.jsx)(`strong`,{children:`audience`}),`.`]}),(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`{{topic}}`}),` is a field name, not the value. You will enter “Albania” on Play later. Repeated names use the same value; names are case-sensitive, so`,` `,(0,h.jsx)(`strong`,{children:`topic`}),` and `,(0,h.jsx)(`strong`,{children:`Topic`}),` are different.`]}),(0,h.jsxs)(`p`,{children:[`There are no automatic keywords: `,(0,h.jsx)(`strong`,{children:`{{title}}`}),` would also ask you for a value. Fix any keyword warnings in Body before saving.`]})]});case`article-save`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Press the highlighted `,(0,h.jsx)(`strong`,{children:`Save`}),` button in the editor. The prompt will appear in your Article library.`]}),(0,h.jsx)(`p`,{children:`The tour continues when the save succeeds and the editor returns to the prompt list. If a name is already taken, go Back and choose another.`})]});case`image-prompt`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Keep `,(0,h.jsx)(`strong`,{children:`Kind`}),` on `,(0,h.jsx)(`strong`,{children:`Image`}),`. Name this prompt`,` `,(0,h.jsx)(`strong`,{children:`Travel imagery`}),`, then enter this example or your own visual instructions.`]}),(0,h.jsx)(RF,{text:YF}),(0,h.jsxs)(`p`,{children:[`Using `,(0,h.jsx)(`strong`,{children:`{{topic}}`}),` in both prompts creates one shared field on Play. Image prompts describe the picture directly; they do not automatically receive your article.`]})]});case`image-save`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Press `,(0,h.jsx)(`strong`,{children:`Save`}),` to add this to your Image library. Next you will combine both prompts on Play.`]}),(0,h.jsx)(`p`,{children:`You can create more prompts later for different subjects, styles, lengths, or languages.`})]});case`play-article`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Play is where you configure one project. Leave `,(0,h.jsx)(`strong`,{children:`Article`}),` on`,` `,(0,h.jsx)(`strong`,{children:`Generate`}),`, then select the article prompt you saved.`]}),(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`Provide`}),` is for an article you already have. For this first run, use Generate and keep the script short. Article is required; every other stage can be Off.`]}),(0,h.jsx)(`p`,{children:`Research starts Off. You can turn it on in a later run for web-grounded notes that are automatically passed to the article writer.`})]});case`play-audio`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Leave `,(0,h.jsx)(`strong`,{children:`Audio`}),` on `,(0,h.jsx)(`strong`,{children:`Generate`}),`. Pick your voice`,` `,(0,h.jsx)(`strong`,{children:`TTS`}),` provider, a `,(0,h.jsx)(`strong`,{children:`TTS model`}),`, then the saved`,` `,(0,h.jsx)(`strong`,{children:`Voice`}),`.`]}),(0,h.jsxs)(`p`,{children:[`Keep `,(0,h.jsx)(`strong`,{children:`Chunking`}),` (under `,(0,h.jsx)(`strong`,{children:`Audio Advanced`}),`) on`,` `,(0,h.jsx)(`strong`,{children:`Whole`}),` for the short example: the narration is sent as one request. Other chunking modes split longer text into pieces. `,(0,h.jsx)(`strong`,{children:`Speakers`}),` is where an audiobook or podcast gets more than one voice; leave it on one voice for now.`]}),(0,h.jsx)(`p`,{children:`Use Provide to upload existing narration, including any intro and outro in that file, or Off to skip narration. Video can still run silently, with each image shown for 5 seconds.`})]});case`play-images`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Leave `,(0,h.jsx)(`strong`,{children:`Images`}),` on `,(0,h.jsx)(`strong`,{children:`Generate`}),`. Choose the image`,` `,(0,h.jsx)(`strong`,{children:`Provider`}),` and `,(0,h.jsx)(`strong`,{children:`Model`}),`, tick your image prompt, and type`,` `,(0,h.jsx)(`strong`,{children:`2`}),` in the number box beside it for a small first run.`]}),(0,h.jsx)(`p`,{children:`The number means separate images made from that same prompt. It does not make one scene per article paragraph. Add more image prompts when you want different scenes.`}),(0,h.jsx)(`p`,{children:`Use Provide for your own images or Off to skip them. Turning Images Off also turns Video Off. Thumbnail remains independent; keep it Off for this first run.`})]});case`play-video`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`On `,(0,h.jsx)(`strong`,{children:`Export`}),`, choose `,(0,h.jsx)(`strong`,{children:`Generate`}),` for an MP4 slideshow. It needs generated or provided images. With Audio Off, the video is silent and each image lasts 5 seconds.`]}),(0,h.jsxs)(`p`,{children:[`Choose `,(0,h.jsx)(`strong`,{children:`Off`}),` to skip video. If Audio is active, Slopify exports one combined `,(0,h.jsx)(`strong`,{children:`WAV`}),` with the intro, body, outro and configured gaps.`]}),(0,h.jsx)(`p`,{children:`If both Audio and Video are Off, download the article and any other enabled outputs individually.`})]});case`play-subtitles`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Subtitles are optional and start `,(0,h.jsx)(`strong`,{children:`Off`}),`. Choose`,` `,(0,h.jsx)(`strong`,{children:`Subtitle files`}),` for SRT and VTT downloads, or`,` `,(0,h.jsx)(`strong`,{children:`Burn into video + files`}),` to keep captions visible in an MP4.`]}),(0,h.jsxs)(`p`,{children:[`English captions are timed locally from your narration with no paid API. First use downloads an approximately `,(0,h.jsx)(`strong`,{children:`95 MB`}),` speech model. Audio must be active; WAV exports support separate subtitle files.`]}),(0,h.jsx)(`p`,{children:`Pick a font or upload a TTF/OTF file, then adjust its size in the preview. Styling applies to burned captions. You can also add or change subtitles on a completed project later without regenerating its narration.`})]});case`play-options`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Enter a `,(0,h.jsx)(`strong`,{children:`Project title`}),`, such as “A quick trip to Albania.” Set the title in Content.`]}),(0,h.jsxs)(`p`,{children:[`Select the text `,(0,h.jsx)(`strong`,{children:`LLM`}),` and `,(0,h.jsx)(`strong`,{children:`Text model`}),`. The model list loads for your provider. Use `,(0,h.jsx)(`strong`,{children:`Refresh`}),` for updated choices or`,` `,(0,h.jsx)(`strong`,{children:`Custom ID`}),`to enter an exact model ID when supported.`]}),(0,h.jsx)(`p`,{children:`Intro and Outro are available in Outputs when Audio is Generate. The LLM controls appear only when an enabled stage needs text generation.`})]});case`play-keywords`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The prompts you picked created these fields. For the examples, enter`,` `,(0,h.jsx)(`strong`,{children:`Albania`}),` for `,(0,h.jsx)(`strong`,{children:`topic`}),` and`,` `,(0,h.jsx)(`strong`,{children:`first-time travelers`}),` for `,(0,h.jsx)(`strong`,{children:`audience`}),`.`]}),(0,h.jsx)(`p`,{children:`Each keyword is asked once, with the prompts that use it named underneath. A keyword both prompts use feeds the article and the images, so changing it changes both for this run.`}),(0,h.jsx)(`p`,{children:`Fill every visible field. Each value must fit on one line and be no more than 200 characters. Your saved prompt keeps its braces so you can reuse it next time.`})]});case`play-start`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:`Review the enabled outputs, costs and readiness in Review. If anything is missing, use Back to fix the highlighted section.`}),(0,h.jsxs)(`p`,{children:[`When ready, press the real `,(0,h.jsx)(`strong`,{children:`Start run`}),` or `,(0,h.jsx)(`strong`,{children:`Queue N`}),` `,`button. This creates a project and sends generation requests to your chosen providers, which may charge your account.`]}),(0,h.jsx)(`p`,{children:`The tour will follow you to the project. You can also skip generating and go on to the screens you run a channel from.`})]});case`project`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The rail on the left lists the project's sections: Article, Narration, Images, Video and the rest. The right rail says where the run stands and offers the one thing to do next, named for its result: `,(0,h.jsx)(`strong`,{children:`Pause`}),` while it runs,`,` `,(0,h.jsx)(`strong`,{children:`Continue the run`}),` when it is paused, `,(0,h.jsx)(`strong`,{children:`Try images again`}),` `,`when a step fails.`]}),(0,h.jsxs)(`p`,{children:[`Press `,(0,h.jsx)(`strong`,{children:`Edit settings`}),` to change providers, models, voice, prompts or optional steps. `,(0,h.jsx)(`strong`,{children:`Save changes`}),` keeps a new revision without starting generation; what the change made outdated is then offered as the next action, such as`,` `,(0,h.jsx)(`strong`,{children:`Remake 3 outdated images`}),`. Earlier revisions stay in`,` `,(0,h.jsx)(`strong`,{children:`History`}),`.`]}),(0,h.jsxs)(`p`,{children:[`A failed step says why beside it; open `,(0,h.jsx)(`strong`,{children:`Error details`}),` for the provider's own message. Rare actions, such as making a whole stage again, sit behind each section's`,` `,(0,h.jsx)(`strong`,{children:`More`}),` button and in the command palette (Ctrl+K).`]})]});case`download`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[t===`audio`?(0,h.jsxs)(h.Fragment,{children:[`When Audio export finishes, press `,(0,h.jsx)(`strong`,{children:`Download`}),`, then`,` `,(0,h.jsx)(`strong`,{children:`Audio (.wav)`}),` for the combined narration.`]}):t===`article`?(0,h.jsxs)(h.Fragment,{children:[`Use `,(0,h.jsx)(`strong`,{children:`Download`}),` here to save the article. Audio and Video are Off for this project.`]}):(0,h.jsxs)(h.Fragment,{children:[`When Video finishes, press `,(0,h.jsx)(`strong`,{children:`Download`}),`, then`,` `,(0,h.jsx)(`strong`,{children:`Video (.mp4)`}),`.`]}),` `,`The completed project stays in `,(0,h.jsx)(`strong`,{children:`Projects`}),` so you can return to it.`]}),(0,h.jsxs)(`p`,{children:[`Select Article, Audio or Images in the stage list on the `,(0,h.jsx)(`strong`,{children:`Output`}),` tab to download their outputs. `,(0,h.jsx)(`strong`,{children:`Download all`}),` under Images gives an image ZIP, not the video.`]}),(0,h.jsxs)(`p`,{children:[`If subtitles are enabled, download the `,(0,h.jsx)(`strong`,{children:`.srt`}),` or `,(0,h.jsx)(`strong`,{children:`.vtt`}),` `,`files beside the final export. File-mode captions are also available in the video player.`]})]});case`run-cost`:return(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`Cost`}),` in the project's sections shows what this run really cost, per stage and model. Totals for every project are in Settings, `,(0,h.jsx)(`strong`,{children:`Usage`}),`.`]});case`studio-prep`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`Slopify never uploads for you. When the video is made, `,(0,h.jsx)(`strong`,{children:`Prepare upload`}),` `,`is the next action: it lists everything YouTube Studio asks for, in the order it asks, from the file and title to the thumbnail, tags and the AI disclosure.`]}),(0,h.jsxs)(`p`,{children:[`The browser extension in Settings, `,(0,h.jsx)(`strong`,{children:`YouTube Studio`}),`, can fill those in for you.`]})]});case`home`:return(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`strong`,{children:`Home`}),` is the day at a glance: what needs you, what is running and at which step, what is coming up this week and what is ready to upload.`]});case`channels`:return(0,h.jsxs)(`p`,{children:[`A `,(0,h.jsx)(`strong`,{children:`channel`}),` keeps its brand kit, series brief, templates, schedules and a cast that looks the same in every video. It also remembers finished episodes and your existing videos, so new topics do not repeat them.`]});case`calendar`:return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{children:[`The `,(0,h.jsx)(`strong`,{children:`Calendar`}),` shows the coming weeks of uploads: what is ready, what needs you, and the topics a schedule suggested, waiting for your approval. Its`,` `,(0,h.jsx)(`strong`,{children:`Schedules`}),` tab is where you create, pause and resume the schedules that fill it.`]}),(0,h.jsx)(`p`,{children:`You have reached the end. Press the question-mark button at the foot of the sidebar anytime to walk through these steps again, or the book beside it for Help → Tutorials, the guides to every screen.`})]})}}function ZF(e){return tF(e.readiness)}function QF({session:e,progress:t,update:n}){let{api:r}=z(),i=rP(),a=Zi(),o=Ha(),s=N(Qy(r)),c=N(eb(r)),l=N(tb(r)),u=N({...Xy(r,e.projectId??``),enabled:e.projectId!==void 0}),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(null),g=XP[e.step],_=s.data?.seen===!0;if((0,m.useEffect)(()=>{if(!_||!g||p.current===e.step)return;if(p.current=e.step,g.page===`settings`){let e=g.id===`voice`?`voices`:`providers`;(o.pathname!==`/settings`||!o.searchStr.includes(`section=${e}`))&&a({to:`/settings`,search:{section:e}})}if(g.page===`article`||g.page===`image`){let t=g.page===`article`?e.articleId:e.imageId,n=o.pathname===`/prompts/new`&&o.searchStr.includes(`kind=${g.page}`);t&&o.pathname!==`/prompts/${t}`?a({to:`/prompts/$promptId`,params:{promptId:t}}):!t&&!n&&a({to:`/prompts/new`,search:{kind:g.page}})}g.page===`play`&&o.pathname!==`/play`&&a({to:`/play`});let t={home:`/`,channels:`/channels`,calendar:`/calendar`};if(g.page===`home`||g.page===`channels`||g.page===`calendar`){let e=t[g.page];o.pathname!==e&&a({to:e})}g.page===`project`&&e.projectId&&o.pathname!==`/projects/${e.projectId}`&&a({to:`/projects/$projectId`,params:{projectId:e.projectId}})},[_,g,e.step,e.articleId,e.imageId,e.projectId,o.pathname,o.searchStr,a]),(0,m.useEffect)(()=>{if(!_||g?.page!==`play`||o.pathname!==`/play`)return;let e=!0;return f(null),i.navigate(eF[g.id]).then(()=>{e&&f(g.id)}),()=>{e=!1}},[_,g,o.pathname,i.navigate]),(0,m.useEffect)(()=>{o.pathname===`/prompts`&&(g?.id===`image-prompt`&&e.imageId?n(e=>({...e,step:XP.findIndex(e=>e.id===`play-options`)})):(g?.id===`article-save`&&e.articleId||g?.id===`image-save`&&e.imageId)&&n(e=>({...e,step:e.step+1})))},[o.pathname,g?.id,e.articleId,e.imageId,n]),!_||!g||g.page===`play`&&(d!==g.id||i.section!==eF[g.id]))return null;let v=c.data?.providers??[],y=e=>v.some(t=>t.family===e&&ZF(t)),b=(l.data?.voices??[]).some(e=>v.some(t=>t.id===e.provider&&ZF(t))),x={"text-key":y(`llm`),"audio-key":y(`tts`),"image-key":y(`image`),voice:b,"article-name":t.promptIsArticle===!0&&t.promptNamed===!0,"article-body":t.promptIsArticle===!0&&t.promptBodyReady===!0&&t.promptHasKeywords===!0,"article-keywords":t.promptHasKeywords===!0,"article-save":!1,"image-prompt":t.promptIsImage===!0&&t.promptSaveReady===!0&&t.promptHasKeywords===!0,"image-save":!1,"play-article":t.playArticleReady===!0,"play-audio":t.playAudioReady===!0,"play-images":t.playImagesReady===!0,"play-video":t.playVideoReady===!0,"play-subtitles":t.playSubtitlesReady===!0,"play-options":t.playOptionsReady===!0,"play-keywords":t.playKeywordsReady===!0,"play-start":!1},S=()=>n(e=>({...e,active:!1})),C=XP.findIndex(e=>e.id===ZP),w=e.step===XP.length-1,T=()=>{w?S():g.id===`play-start`?n(e=>({...e,step:C})):n(e=>({...e,step:e.step+1}))},E=()=>n(t=>({...t,step:g.id===`home`&&e.projectId===void 0?XP.findIndex(e=>e.id===`play-start`):t.step-1})),D=u.data?rF(u.data.project.config):`video`,O=g.id===`download`&&D===`article`?`project-article`:g.id===`play-keywords`&&t.playHasKeywords===!1?`play-options`:g.id===`studio-prep`&&D!==`video`?`project-controls`:g.target,k=g.id===`article-save`||g.id===`image-save`,A=(g.page===`article`||g.page===`image`)&&t.promptSaving===!0;return(0,h.jsxs)(IF,{stepId:g.id,target:`[data-tour="${O}"]`,title:g.title,progress:`${e.step+1} of ${XP.length} · First project`,onClose:S,...e.step===0||g.id===`project`||A?{}:{onBack:E},onNext:T,nextDisabled:A||x[g.id]===!1,nextLabel:k?`Use Save in the editor`:g.id===`play-start`?`Use Start run / Queue N on the page`:w?`Finish tutorial`:`Next`,...A?{}:{onSkip:T},skipLabel:g.id===`play-start`?`Skip generating`:k?`Skip without saving`:`Skip this step`,children:[(0,h.jsx)(XF,{step:g.id,output:D}),c.error||l.error?(0,h.jsx)(`p`,{className:`text-danger`,children:c.error?.message??l.error?.message}):null]})}var $F=q({schemaVersion:pO(1),active:GD(),stepId:J([`text-key`,`audio-key`,`image-key`,`voice`,`article-name`,`article-body`,`article-keywords`,`article-save`,`image-prompt`,`image-save`,`play-options`,`play-article`,`play-keywords`,`play-audio`,`play-images`,`play-video`,`play-subtitles`,`play-start`,`project`,`download`,`run-cost`,`studio-prep`,`home`,`channels`,`calendar`]),articleId:W().optional(),imageId:W().optional(),projectId:W().optional()}).strict();q({baseVersion:G().int().nonnegative(),mutationId:wD(),session:$F}).strict();var eI=q({version:G().int().nonnegative(),session:$F,readable:GD()}).strict();async function tI(e){let t=await F(await e.client.tutorial.$get()),n=eI.safeParse(t);return n.success?n.data:{version:0,readable:!1,session:{schemaVersion:1,active:!1,stepId:`text-key`}}}async function nI(e,t){return eI.parse(await F(await e.client.tutorial.$put({json:t})))}async function rI(e){let t=await e.client.tutorial.$delete();if(!t.ok)throw await fo(t)}function iI(){let{api:e}=z(),[t,n]=(0,m.useState)({active:!1,step:0}),[r,i]=(0,m.useState)(null),a=(0,m.useMemo)(()=>{let t={active:!1,step:0},r=0,a=!1,o=!1,s=0,c=!0,l=!1,u=!1,d=null,f=[],p=[],m=e=>i(e instanceof Error?e.message:`Your tutorial progress wasn't saved. You can keep going; it will try again on the next step.`),h=async()=>{if(!u&&a&&c){u=!0;try{for(;d||p.length>0;){if(!d){let e=p.shift();if(!e)break;let t=XP[e.step];if(!t)throw Error(`This tutorial step isn't recognised. Choose Restart tutorial to start over.`);let{step:n,...i}=e;d={baseVersion:r,mutationId:crypto.randomUUID(),session:{...i,schemaVersion:1,stepId:t.id}}}r=(await nI(e,d)).version,d=null}i(null)}catch(e){m(e)}finally{u=!1}}},g=e=>{if(!a){f.push(e);return}let r=typeof e==`function`?e(t):e;r!==t&&(t=r,n(t),p.push(t),h())},_=()=>{if(!a){l=!0;return}if(!c){i(`Saved tutorial progress cannot be read. Choose Restart tutorial to recover.`);return}g({active:!0,step:0})},v=async()=>{if(o||a)return;o=!0;let u=s;try{let o=await tI(e);if(u!==s)return;if(r=o.version,c=o.readable,c||(a=!0),!c){i(`Saved tutorial progress cannot be read. Choose Restart tutorial to recover.`);return}let{schemaVersion:d,stepId:p,...m}=o.session;if(t={active:m.active,step:$P(p)??0,...m.articleId===void 0?{}:{articleId:m.articleId},...m.imageId===void 0?{}:{imageId:m.imageId},...m.projectId===void 0?{}:{projectId:m.projectId}},t.articleId||t.imageId){let{prompts:n}=await bs(e),{articleId:r,imageId:i,...a}=t;t={...a,...r!==void 0&&n.some(e=>e.id===r&&e.kind===`article`)?{articleId:r}:{},...i!==void 0&&n.some(e=>e.id===i&&e.kind===`image`)?{imageId:i}:{}}}if(t.projectId&&await jo(e,t.projectId),u!==s)return;a=!0,n(t);for(let e of f.splice(0))g(e);l&&_(),i(null)}catch(e){u===s&&m(e)}finally{o=!1}},y=async()=>{if(!u){u=!0,s++,f.length=0,l=!1;try{await rI(e),r=0,c=!0,a=!0,d=null,p.length=0,t={active:!0,step:0},n(t),p.push(t),i(null)}catch(e){m(e)}finally{u=!1}await h()}};return{update:g,start:_,restore:v,retry:()=>{a?h():v()},restart:()=>{y()}}},[e]);return(0,m.useEffect)(()=>{a.restore()},[a]),{session:t,update:a.update,start:a.start,retry:a.retry,restart:a.restart,error:r}}var aI=(0,m.createContext)(void 0);function oI({children:e}){let{session:t,update:n,start:r,retry:i,restart:a,error:o}=iI(),[s,c]=(0,m.useState)({}),l=(0,m.useCallback)(e=>{c(t=>Object.entries(e).every(([e,n])=>t[e]===n)?t:{...t,...e})},[]),u=(0,m.useCallback)(e=>{c(t=>Object.fromEntries(Object.entries(t).filter(([t])=>!e.includes(t))))},[]),d=(0,m.useCallback)(e=>{n(t=>QP(t,e))},[n]),f=XP[t.step]?.id,p=t.active&&(f===`project`||f===`download`)?f:void 0,g=(0,m.useMemo)(()=>({active:t.active,projectId:t.projectId,projectStep:p,start:r,report:l,clear:u,event:d}),[t.active,t.projectId,p,r,l,u,d]);return(0,h.jsxs)(aI.Provider,{value:g,children:[e,o?(0,h.jsxs)(`div`,{role:`alert`,className:`fixed bottom-4 left-4 z-[100] rounded-media border border-line bg-surface p-4 text-ink`,children:[(0,h.jsx)(`p`,{children:o}),(0,h.jsx)(R,{type:`button`,onClick:i,children:`Retry tutorial save`}),(0,h.jsx)(R,{type:`button`,onClick:a,children:`Restart tutorial`})]}):null,t.active?(0,h.jsx)(QF,{session:t,progress:s,update:n}):null]})}function sI(){return(0,m.useContext)(aI)}function cI(e){let t=(0,m.useContext)(aI),n=t?.report,r=t?.clear,i=(0,m.useRef)(e);i.current=e,(0,m.useEffect)(()=>{n?.(e)},[n,e]),(0,m.useEffect)(()=>()=>{r?.(Object.keys(i.current))},[r])}function lI(){let e=(0,m.useContext)(aI);return(0,m.useCallback)(t=>{e?.event(t)},[e?.event])}function uI(e){let t=(0,m.useContext)(aI);return t?.projectId===e?t.projectStep:void 0}var dI=[`patch-notes`];function fI(e){return ct({queryKey:dI,queryFn:async()=>F(await e.client[`patch-notes`].$get()),staleTime:1/0})}function pI(e,t){return ct({queryKey:[...dI,t],queryFn:async()=>lo(await e.client[`patch-notes`][`:id`].$get({param:{id:t}})),staleTime:1/0})}async function mI(e){await F(await e.client[`patch-notes`].seen.$post())}var hI={3:[{id:`home`,title:`Home`,body:`What is running and at which step, what is coming up, what needs you and what is ready to upload, on one screen.`,to:`/`,place:`Home`},{id:`play`,title:`Play's one path`,body:`Pick a template, type the topic, press Start. Everything else stays folded away until it needs you.`,to:`/play`,place:`Play`},{id:`reviews`,title:`Automatic reviews`,body:`A reviewer model checks the article, images, narration, thumbnail and shorts, and can send a failed item back to be made again. Turn it on in Play's Review step.`,to:`/play`,place:`Play`},{id:`channels`,title:`Channels and cast`,body:`A channel keeps its brand kit, series brief, templates and schedules, and a cast of characters and places that look the same in every video.`,to:`/channels`,place:`Channels`},{id:`memory`,title:`Episodes that remember`,body:`Each finished episode leaves a short summary on its channel's Episodes tab, and a new article reads the related ones. Add your existing video titles on Existing videos, and topic suggestions skip them too.`,to:`/channels`,place:`Channels`},{id:`calendar`,title:`The calendar`,body:`The coming weeks of uploads on one screen: what is ready, what needs you, and the topics still to come. Its Schedules tab holds every schedule.`,to:`/calendar`,place:`Calendar`},{id:`run-cost`,title:`What a run cost`,body:`Every project has a Run cost tab with the real cost per stage and model. Totals for all projects are in Settings, Usage.`,to:`/settings`,search:{section:`usage`},place:`Usage`},{id:`studio`,title:`YouTube Studio prep`,body:`Slopify never uploads. Prepare upload on a finished project lists everything Studio asks for, and the browser extension can fill it in for you.`,to:`/settings`,search:{section:`studio`},place:`YouTube Studio settings`},{id:`voices`,title:`Multiple voices`,body:`Audiobooks, podcasts, radio drama and interviews, with a voice per speaker. Pick the format under Audio, Speakers on Play.`,to:`/play`,place:`Play`},{id:`long-videos`,title:`Long videos stay watchable`,body:`More images for long videos sets images per hour or one every few minutes, with pan and zoom variety. An ambient bed of rain, fire, wind or your own file can play under the narration. Both are on Play; a channel's brand kit can set the ambient sound for all its videos.`,to:`/play`,place:`Play`},{id:`languages`,title:`Other languages`,body:`A project can be made in another language: pick it on Play, and the article, narration and description are written in it.`,to:`/play`,place:`Play`},{id:`trash`,title:`A trash bin`,body:`Deleted projects, prompts, templates and schedules stay in Settings, Trash for 30 days, and Restore brings them back.`,to:`/settings`,search:{section:`trash`},place:`Trash`}]},gI=[`whats-new`];async function _I(e){return F(await e.client[`whats-new`].$get())}function vI(e){return ct({queryKey:gI,queryFn:()=>_I(e),staleTime:1/0})}async function yI(e){return F(await e.client[`whats-new`].seen.$post())}function bI(){let{api:e}=z(),t=_(),n=sI(),r=N(Qy(e)),i=N({...vI(e),enabled:r.data?.seen===!0}),[a,o]=(0,m.useState)(0),s=P({mutationFn:()=>yI(e),onSuccess:e=>{t.setQueryData(gI,e),t.setQueryData(dI,e=>e===void 0?e:{...e,due:null})}}),c=i.data?.major,l=c==null?void 0:hI[c],u=l!==void 0&&a>=l.length-1,d=N({...fI(e),enabled:i.data?.show===!0&&u}).data?.current??void 0;if(i.data?.show!==!0||l===void 0||n?.active===!0)return null;let f=l[Math.min(a,l.length-1)];if(f===void 0)return null;let p=l.indexOf(f),g=p===l.length-1,v=()=>{s.mutate()};return(0,h.jsx)(YP,{open:!0,width:`narrow`,title:`What's new in ${String(c)}.0`,onClose:v,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,disabled:s.isPending,onClick:v,children:`Close tour`}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(R,{disabled:p===0,disabledReason:`This is the first step`,onClick:()=>{o(p-1)},children:`Back`}),(0,h.jsx)(R,{variant:`primary`,disabled:s.isPending,onClick:()=>{g?v():o(p+1)},children:g?`Finish tour`:`Next`})]}),children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-3`,children:`${String(p+1)} of ${String(l.length)}`}),(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:f.title}),(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:f.body}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsx)(fS,{to:f.to,...f.search===void 0?{}:{search:f.search},children:`Open ${f.place}`}),g?(0,h.jsx)(pS,{to:`/settings`,search:{section:`patch-notes`,...d===void 0?{}:{note:d}},onClick:v,children:`Read the full patch notes`}):null]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`Slopify could not save that you closed this tour: ${s.error.message} Press Close tour to try again.`})]})})}var xI={danger:(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),waiting:(0,h.jsx)(mc,{"aria-hidden":`true`,strokeWidth:1.75}),info:(0,h.jsx)(Cc,{"aria-hidden":`true`,strokeWidth:1.75})};function SI({tone:e=`info`,title:t,children:n,actions:r,className:i}){return(0,h.jsxs)(`div`,{role:e===`danger`?`alert`:`status`,"data-tone":e,className:L(`sl-callout`,e!==`info`&&`sl-callout--${e}`,i),children:[xI[e],(0,h.jsx)(`span`,{className:`sl-callout__title`,children:t}),n===void 0?null:(0,h.jsx)(`div`,{className:`sl-callout__body`,children:n}),r===void 0?null:(0,h.jsx)(`div`,{className:`sl-callout__actions`,children:r})]})}function CI(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var wI=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,TI=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,EI={};function DI(e,t){return((t||EI).jsx?TI:wI).test(e)}var OI=/[ \t\n\f\r]/g;function Bre(e){return typeof e==`object`?e.type===`text`&&kI(e.value):kI(e)}function kI(e){return e.replace(OI,``)===``}var AI=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};AI.prototype.normal={},AI.prototype.property={},AI.prototype.space=void 0;function jI(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new AI(n,r,t)}function MI(e){return e.toLowerCase()}var NI=class{constructor(e,t){this.attribute=t,this.property=e}};NI.prototype.attribute=``,NI.prototype.booleanish=!1,NI.prototype.boolean=!1,NI.prototype.commaOrSpaceSeparated=!1,NI.prototype.commaSeparated=!1,NI.prototype.defined=!1,NI.prototype.mustUseProperty=!1,NI.prototype.number=!1,NI.prototype.overloadedBoolean=!1,NI.prototype.property=``,NI.prototype.spaceSeparated=!1,NI.prototype.space=void 0;var PI=s({boolean:()=>FI,booleanish:()=>II,commaOrSpaceSeparated:()=>BI,commaSeparated:()=>zI,number:()=>Y,overloadedBoolean:()=>LI,spaceSeparated:()=>RI}),Vre=0,FI=VI(),II=VI(),LI=VI(),Y=VI(),RI=VI(),zI=VI(),BI=VI();function VI(){return 2**++Vre}var HI=Object.keys(PI),UI=class extends NI{constructor(e,t,n,r){let i=-1;if(super(e,t),WI(this,`space`,r),typeof n==`number`)for(;++i<HI.length;){let e=HI[i];WI(this,HI[i],(n&PI[e])===PI[e])}}};UI.prototype.defined=!0;function WI(e,t,n){n&&(e[t]=n)}function GI(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new UI(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[MI(r)]=r,n[MI(a.attribute)]=r}return new AI(t,n,e.space)}var KI=GI({properties:{ariaActiveDescendant:null,ariaAtomic:II,ariaAutoComplete:null,ariaBusy:II,ariaChecked:II,ariaColCount:Y,ariaColIndex:Y,ariaColSpan:Y,ariaControls:RI,ariaCurrent:null,ariaDescribedBy:RI,ariaDetails:null,ariaDisabled:II,ariaDropEffect:RI,ariaErrorMessage:null,ariaExpanded:II,ariaFlowTo:RI,ariaGrabbed:II,ariaHasPopup:null,ariaHidden:II,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:RI,ariaLevel:Y,ariaLive:null,ariaModal:II,ariaMultiLine:II,ariaMultiSelectable:II,ariaOrientation:null,ariaOwns:RI,ariaPlaceholder:null,ariaPosInSet:Y,ariaPressed:II,ariaReadOnly:II,ariaRelevant:null,ariaRequired:II,ariaRoleDescription:RI,ariaRowCount:Y,ariaRowIndex:Y,ariaRowSpan:Y,ariaSelected:II,ariaSetSize:Y,ariaSort:null,ariaValueMax:Y,ariaValueMin:Y,ariaValueNow:Y,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function qI(e,t){return t in e?e[t]:t}function JI(e,t){return qI(e,t.toLowerCase())}var Hre=GI({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:zI,acceptCharset:RI,accessKey:RI,action:null,allow:null,allowFullScreen:FI,allowPaymentRequest:FI,allowUserMedia:FI,alpha:FI,alt:null,as:null,async:FI,autoCapitalize:null,autoComplete:RI,autoFocus:FI,autoPlay:FI,blocking:RI,capture:null,charSet:null,checked:FI,cite:null,className:RI,closedBy:null,colorSpace:null,cols:Y,colSpan:Y,command:null,commandFor:null,content:null,contentEditable:II,controls:FI,controlsList:RI,coords:Y|zI,crossOrigin:null,data:null,dateTime:null,decoding:null,default:FI,defer:FI,dir:null,dirName:null,disabled:FI,download:LI,draggable:II,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:FI,formTarget:null,headers:RI,height:Y,hidden:LI,high:Y,href:null,hrefLang:null,htmlFor:RI,httpEquiv:RI,id:null,imageSizes:null,imageSrcSet:null,inert:FI,inputMode:null,integrity:null,is:null,isMap:FI,itemId:null,itemProp:RI,itemRef:RI,itemScope:FI,itemType:RI,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:FI,low:Y,manifest:null,max:null,maxLength:Y,media:null,method:null,min:null,minLength:Y,multiple:FI,muted:FI,name:null,nonce:null,noModule:FI,noValidate:FI,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:FI,optimum:Y,pattern:null,ping:RI,placeholder:null,playsInline:FI,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:FI,referrerPolicy:null,rel:RI,required:FI,reversed:FI,rows:Y,rowSpan:Y,sandbox:RI,scope:null,scoped:FI,seamless:FI,selected:FI,shadowRootClonable:FI,shadowRootCustomElementRegistry:FI,shadowRootDelegatesFocus:FI,shadowRootMode:null,shadowRootSerializable:FI,shape:null,size:Y,sizes:null,slot:null,span:Y,spellCheck:II,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Y,step:null,style:null,tabIndex:Y,target:null,title:null,translate:null,type:null,typeMustMatch:FI,useMap:null,value:II,width:Y,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:RI,axis:null,background:null,bgColor:null,border:Y,borderColor:null,bottomMargin:Y,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:FI,declare:FI,event:null,face:null,frame:null,frameBorder:null,hSpace:Y,leftMargin:Y,link:null,longDesc:null,lowSrc:null,marginHeight:Y,marginWidth:Y,noResize:FI,noHref:FI,noShade:FI,noWrap:FI,object:null,profile:null,prompt:null,rev:null,rightMargin:Y,rules:null,scheme:null,scrolling:II,standby:null,summary:null,text:null,topMargin:Y,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Y,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:FI,disablePictureInPicture:FI,disableRemotePlayback:FI,exportParts:zI,part:RI,prefix:null,property:null,results:Y,security:null,unselectable:null},space:`html`,transform:JI}),Ure=GI({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:BI,accentHeight:Y,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Y,amplitude:Y,arabicForm:null,ascent:Y,attributeName:null,attributeType:null,azimuth:Y,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Y,by:null,calcMode:null,capHeight:Y,className:RI,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Y,diffuseConstant:Y,direction:null,display:null,dur:null,divisor:Y,dominantBaseline:null,download:FI,dx:null,dy:null,edgeMode:null,editable:null,elevation:Y,enableBackground:null,end:null,event:null,exponent:Y,externalResourcesRequired:null,fill:null,fillOpacity:Y,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:zI,g2:zI,glyphName:zI,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Y,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Y,horizOriginX:Y,horizOriginY:Y,id:null,ideographic:Y,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Y,k:Y,k1:Y,k2:Y,k3:Y,k4:Y,kernelMatrix:BI,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Y,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Y,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Y,overlineThickness:Y,paintOrder:null,panose1:null,path:null,pathLength:Y,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:RI,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Y,pointsAtY:Y,pointsAtZ:Y,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:BI,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:BI,rev:BI,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:BI,requiredFeatures:BI,requiredFonts:BI,requiredFormats:BI,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Y,specularExponent:Y,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Y,strikethroughThickness:Y,string:null,stroke:null,strokeDashArray:BI,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Y,strokeOpacity:Y,strokeWidth:null,style:null,surfaceScale:Y,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:BI,tabIndex:Y,tableValues:null,target:null,targetX:Y,targetY:Y,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:BI,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Y,underlineThickness:Y,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Y,values:null,vAlphabetic:Y,vMathematical:Y,vectorEffect:null,vHanging:Y,vIdeographic:Y,version:null,vertAdvY:Y,vertOriginX:Y,vertOriginY:Y,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Y,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:qI}),YI=GI({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),XI=GI({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:JI}),ZI=GI({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),Wre={classId:`classID`,dataType:`datatype`,itemId:`itemID`,strokeDashArray:`strokeDasharray`,strokeDashOffset:`strokeDashoffset`,strokeLineCap:`strokeLinecap`,strokeLineJoin:`strokeLinejoin`,strokeMiterLimit:`strokeMiterlimit`,typeOf:`typeof`,xLinkActuate:`xlinkActuate`,xLinkArcRole:`xlinkArcrole`,xLinkHref:`xlinkHref`,xLinkRole:`xlinkRole`,xLinkShow:`xlinkShow`,xLinkTitle:`xlinkTitle`,xLinkType:`xlinkType`,xmlnsXLink:`xmlnsXlink`},Gre=/[A-Z]/g,QI=/-[a-z]/g,Kre=/^data[-\w.:]+$/i;function qre(e,t){let n=MI(t),r=t,i=NI;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&Kre.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(QI,Yre);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!QI.test(e)){let n=e.replace(Gre,Jre);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=UI}return new i(r,t)}function Jre(e){return`-`+e.toLowerCase()}function Yre(e){return e.charAt(1).toUpperCase()}var Xre=jI([KI,Hre,YI,XI,ZI],`html`),$I=jI([KI,Ure,YI,XI,ZI],`svg`);function Zre(e){return e.join(` `).trim()}var Qre=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g;function u(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,u=1;function f(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(`
105
105
  `);u=~n?e.length-n:u+e.length}function p(){var e={line:l,column:u};return function(t){return t.position=new m(e),_(),t}}function m(e){this.start=e,this.end={line:l,column:u},this.source=t.source}m.prototype.content=e;function h(n){var r=Error(t.source+`:`+l+`:`+u+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=u,r.source=e,!t.silent)throw r}function g(t){var n=t.exec(e);if(n){var r=n[0];return f(r),e=e.slice(r.length),n}}function _(){g(i)}function v(e){var t;for(e||=[];t=y();)t!==!1&&e.push(t);return e}function y(){var t=p();if(e.charAt(0)==`/`&&e.charAt(1)==`*`){for(var n=2;e.charAt(n)!=``&&(e.charAt(n)!=`*`||e.charAt(n+1)!=`/`);)++n;if(n+=2,e.charAt(n-1)===``)return h(`End of comment missing`);var r=e.slice(2,n-2);return u+=2,f(r),e=e.slice(n),u+=2,t({type:`comment`,comment:r})}}function b(){var e=p(),t=g(a);if(t){if(y(),!g(o))return h(`property missing ':'`);var r=g(s),i=e({type:`declaration`,property:d(t[0].replace(n,``)),value:r?d(r[0].replace(n,``)):``});return g(c),i}}function x(){var e=[];v(e);for(var t;t=b();)t!==!1&&(e.push(t),v(e));return e}return _(),x()}function d(e){return e?e.replace(l,``):``}t.exports=u})),$re=o((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var n=t(Qre());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),eie=o((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),tie=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})($re()),r=eie();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),eL=nL(`end`),tL=nL(`start`);function nL(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function nie(e){let t=tL(e),n=eL(e);if(t&&n)return{start:t,end:n}}function rL(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?aL(e.position):`start`in e||`end`in e?aL(e):`line`in e||`column`in e?iL(e):``}function iL(e){return oL(e&&e.line)+`:`+oL(e&&e.column)}function aL(e){return iL(e&&e.start)+`-`+iL(e&&e.end)}function oL(e){return e&&typeof e==`number`?e:1}var sL=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=rL(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};sL.prototype.file=``,sL.prototype.name=``,sL.prototype.reason=``,sL.prototype.message=``,sL.prototype.stack=``,sL.prototype.column=void 0,sL.prototype.line=void 0,sL.prototype.ancestors=void 0,sL.prototype.cause=void 0,sL.prototype.fatal=void 0,sL.prototype.place=void 0,sL.prototype.ruleId=void 0,sL.prototype.source=void 0;var rie=l(tie(),1),cL={}.hasOwnProperty,iie=new Map,aie=/[A-Z]/g,oie=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),sie=new Set([`td`,`th`]),lL=`https://github.com/syntax-tree/hast-util-to-jsx-runtime`;function cie(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=gie(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=hie(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?$I:Xre,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=uL(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function uL(e,t,n){if(t.type===`element`)return lie(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return uie(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return fie(e,t,n);if(t.type===`mdxjsEsm`)return die(e,t);if(t.type===`root`)return pie(e,t,n);if(t.type===`text`)return mie(e,t)}function lie(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=$I,e.schema=i),e.ancestors.push(t);let a=mL(e,t.tagName,!1),o=_ie(e,t),s=pL(e,t);return oie.has(t.tagName)&&(s=s.filter(function(e){return typeof e!=`string`||!Bre(e)})),dL(e,o,a,t),fL(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function uie(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}hL(e,t.position)}function die(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);hL(e,t.position)}function fie(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=$I,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:mL(e,t.name,!0),o=vie(e,t),s=pL(e,t);return dL(e,o,a,t),fL(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function pie(e,t,n){let r={};return fL(r,pL(e,t)),e.create(t,e.Fragment,r,n)}function mie(e,t){return t.value}function dL(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function fL(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function hie(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function gie(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=tL(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function _ie(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&cL.call(t.properties,i)){let a=yie(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&sie.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function vie(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`){if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else hL(e,t.position)}else{let i=r.name,a;if(r.value&&typeof r.value==`object`){if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else hL(e,t.position)}else a=r.value===null||r.value;n[i]=a}return n}function pL(e,t){let n=[],r=-1,i=e.passKeys?new Map:iie;for(;++r<t.children.length;){let a=t.children[r],o;if(e.passKeys){let e=a.type===`element`?a.tagName:a.type===`mdxJsxFlowElement`||a.type===`mdxJsxTextElement`?a.name:void 0;if(e){let t=i.get(e)||0;o=e+`-`+t,i.set(e,t+1)}}let s=uL(e,a,o);s!==void 0&&n.push(s)}return n}function yie(e,t,n){let r=qre(e.schema,t);if(!(n==null||typeof n==`number`&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?CI(n):Zre(n)),r.property===`style`){let t=typeof n==`object`?n:bie(e,String(n));return e.stylePropertyNameCase===`css`&&(t=xie(t)),[`style`,t]}return[e.elementAttributeNameCase===`react`&&r.space?Wre[r.property]||r.property:r.attribute,n]}}function bie(e,t){try{return(0,rie.default)(t,{reactCompat:!0})}catch(t){if(e.ignoreInvalidStyle)return{};let n=t,r=new sL("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:n,ruleId:`style`,source:`hast-util-to-jsx-runtime`});throw r.file=e.filePath||void 0,r.url=lL+`#cannot-parse-style-attribute`,r}}function mL(e,t,n){let r;if(!n)r={type:`Literal`,value:t};else if(t.includes(`.`)){let e=t.split(`.`),n=-1,i;for(;++n<e.length;){let t=DI(e[n])?{type:`Identifier`,name:e[n]}:{type:`Literal`,value:e[n]};i=i?{type:`MemberExpression`,object:i,property:t,computed:!!(n&&t.type===`Literal`),optional:!1}:t}r=i}else r=DI(t)&&!/^[a-z]/.test(t)?{type:`Identifier`,name:t}:{type:`Literal`,value:t};if(r.type===`Literal`){let t=r.value;return cL.call(e.components,t)?e.components[t]:t}if(e.evaluater)return e.evaluater.evaluateExpression(r);hL(e)}function hL(e,t){let n=new sL("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:`mdx-estree`,source:`hast-util-to-jsx-runtime`});throw n.file=e.filePath||void 0,n.url=lL+`#cannot-handle-mdx-estrees-without-createevaluater`,n}function xie(e){let t={},n;for(n in e)cL.call(e,n)&&(t[Sie(n)]=e[n]);return t}function Sie(e){let t=e.replace(aie,Cie);return t.slice(0,3)===`ms-`&&(t=`-`+t),t}function Cie(e){return`-`+e.toLowerCase()}var gL={action:[`form`],cite:[`blockquote`,`del`,`ins`,`q`],data:[`object`],formAction:[`button`,`input`],href:[`a`,`area`,`base`,`link`],icon:[`menuitem`],itemId:null,manifest:[`html`],ping:[`a`,`area`],poster:[`video`],src:[`audio`,`embed`,`iframe`,`img`,`input`,`script`,`source`,`track`,`video`]},wie={};function _L(e,t){let n=t||wie;return vL(e,typeof n.includeImageAlt!=`boolean`||n.includeImageAlt,typeof n.includeHtml!=`boolean`||n.includeHtml)}function vL(e,t,n){if(Tie(e)){if(`value`in e)return e.type===`html`&&!n?``:e.value;if(t&&`alt`in e&&e.alt)return e.alt;if(`children`in e)return yL(e.children,t,n)}return Array.isArray(e)?yL(e,t,n):``}function yL(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=vL(e[i],t,n);return r.join(``)}function Tie(e){return!!(e&&typeof e==`object`)}var bL=document.createElement(`i`);function xL(e){let t=`&`+e+`;`;bL.innerHTML=t;let n=bL.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`?!1:n!==t&&n}function SL(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function CL(e,t){return e.length>0?(SL(e,e.length,0,t),e):t}var wL={}.hasOwnProperty;function TL(e){let t={},n=-1;for(;++n<e.length;)Eie(t,e[n]);return t}function Eie(e,t){let n;for(n in t){let r=(wL.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){wL.call(r,a)||(r[a]=[]);let e=i[a];Die(r[a],Array.isArray(e)?e:e?[e]:[])}}}function Die(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);SL(e,0,0,r)}function EL(e,t){let n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function DL(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var OL=LL(/[A-Za-z]/),kL=LL(/[\dA-Za-z]/),Oie=LL(/[#-'*+\--9=?A-Z^-~]/);function AL(e){return e!==null&&(e<32||e===127)}var jL=LL(/\d/),kie=LL(/[\dA-Fa-f]/),Aie=LL(/[!-/:-@[-`{-~]/);function ML(e){return e!==null&&e<-2}function NL(e){return e!==null&&(e<0||e===32)}function PL(e){return e===-2||e===-1||e===32}var FL=LL(/\p{P}|\p{S}/u),IL=LL(/\s/);function LL(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function RL(e){let t=[],n=-1,r=0,i=0;for(;++n<e.length;){let a=e.charCodeAt(n),o=``;if(a===37&&kL(e.charCodeAt(n+1))&&kL(e.charCodeAt(n+2)))i=2;else if(a<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(a))||(o=String.fromCharCode(a));else if(a>55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function zL(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return PL(r)?(e.enter(n),s(r)):t(r)}function s(r){return PL(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var jie={tokenize:Mie};function Mie(e){let t=e.attempt(this.parser.constructs.contentInitial,r,i),n;return t;function r(n){if(n===null){e.consume(n);return}return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),zL(e,t,`linePrefix`)}function i(t){return e.enter(`paragraph`),a(t)}function a(t){let r=e.enter(`chunkText`,{contentType:`text`,previous:n});return n&&(n.next=r),n=r,o(t)}function o(t){if(t===null){e.exit(`chunkText`),e.exit(`paragraph`),e.consume(t);return}return ML(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var Nie={tokenize:Pie},BL={tokenize:Fie};function Pie(e){let t=this,n=[],r=0,i,a,o;return s;function s(i){if(r<n.length){let a=n[r];return t.containerState=a[1],e.attempt(a[0].continuation,c,l)(i)}return l(i)}function c(e){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();let n=t.events.length,a=n,o;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){o=t.events[a][1].end;break}_(r);let s=n;for(;s<t.events.length;)t.events[s][1].end={...o},s++;return SL(t.events,a+1,0,t.events.slice(n)),t.events.length=s,l(e)}return s(e)}function l(a){if(r===n.length){if(!i)return f(a);if(i.currentConstruct&&i.currentConstruct.concrete)return m(a);t.interrupt=!(!i.currentConstruct||i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(BL,u,d)(a)}function u(e){return i&&v(),_(r),f(e)}function d(e){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(e)}function f(n){return t.containerState={},e.attempt(BL,p,m)(n)}function p(e){return r++,n.push([t.currentConstruct,t.containerState]),f(e)}function m(n){if(n===null){i&&v(),_(0),e.consume(n);return}return i||=t.parser.flow(t.now()),e.enter(`chunkFlow`,{_tokenizer:i,contentType:`flow`,previous:a}),h(n)}function h(n){if(n===null){g(e.exit(`chunkFlow`),!0),_(0),e.consume(n);return}return ML(n)?(e.consume(n),g(e.exit(`chunkFlow`)),r=0,t.interrupt=void 0,s):(e.consume(n),h)}function g(e,n){let s=t.sliceStream(e);if(n&&s.push(null),e.previous=a,a&&(a.next=e),a=e,i.defineSkip(e.start),i.write(s),t.parser.lazy[e.start.line]){let e=i.events.length;for(;e--;)if(i.events[e][1].start.offset<o&&(!i.events[e][1].end||i.events[e][1].end.offset>o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;e<t.events.length;)t.events[e][1].end={...c},e++;SL(t.events,a+1,0,t.events.slice(n)),t.events.length=e}}function _(r){let i=n.length;for(;i-->r;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Fie(e,t,n){return zL(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function VL(e){if(e===null||NL(e)||IL(e))return 1;if(FL(e))return 2}function HL(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}var UL={name:`attention`,resolveAll:Iie,tokenize:Lie};function Iie(e,t){let n=-1,r,i,a,o,s,c,l,u;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`attentionSequence`&&e[n][1]._close){for(r=n;r--;)if(e[r][0]===`exit`&&e[r][1].type===`attentionSequence`&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;c=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};WL(d,-c),WL(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=CL(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=CL(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=CL(l,HL(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=CL(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=CL(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,SL(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`attentionSequence`&&(e[n][1].type=`data`);return e}function Lie(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=VL(r),a;return o;function o(t){return a=t,e.enter(`attentionSequence`),s(t)}function s(o){if(o===a)return e.consume(o),s;let c=e.exit(`attentionSequence`),l=VL(o),u=!l||l===2&&i||n.includes(o),d=!i||i===2&&l||n.includes(r);return c._open=!!(a===42?u:u&&(i||!d)),c._close=!!(a===42?d:d&&(l||!u)),t(o)}}function WL(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var Rie={name:`autolink`,tokenize:zie};function zie(e,t,n){let r=0;return i;function i(t){return e.enter(`autolink`),e.enter(`autolinkMarker`),e.consume(t),e.exit(`autolinkMarker`),e.enter(`autolinkProtocol`),a}function a(t){return OL(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||kL(e)?(r=1,s(e)):l(e)}function s(t){return t===58?(e.consume(t),r=0,c):(t===43||t===45||t===46||kL(t))&&r++<32?(e.consume(t),s):(r=0,l(t))}function c(r){return r===62?(e.exit(`autolinkProtocol`),e.enter(`autolinkMarker`),e.consume(r),e.exit(`autolinkMarker`),e.exit(`autolink`),t):r===null||r===32||r===60||AL(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):Oie(t)?(e.consume(t),l):n(t)}function u(e){return kL(e)?d(e):n(e)}function d(n){return n===46?(e.consume(n),r=0,u):n===62?(e.exit(`autolinkProtocol`).type=`autolinkEmail`,e.enter(`autolinkMarker`),e.consume(n),e.exit(`autolinkMarker`),e.exit(`autolink`),t):f(n)}function f(t){if((t===45||kL(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var GL={partial:!0,tokenize:Bie};function Bie(e,t,n){return r;function r(t){return PL(t)?zL(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||ML(e)?t(e):n(e)}}var KL={continuation:{tokenize:Hie},exit:Uie,name:`blockQuote`,tokenize:Vie};function Vie(e,t,n){let r=this;return i;function i(t){if(t===62){let n=r.containerState;return n.open||=(e.enter(`blockQuote`,{_container:!0}),!0),e.enter(`blockQuotePrefix`),e.enter(`blockQuoteMarker`),e.consume(t),e.exit(`blockQuoteMarker`),a}return n(t)}function a(n){return PL(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function Hie(e,t,n){let r=this;return i;function i(t){return PL(t)?zL(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(KL,t,n)(r)}}function Uie(e){e.exit(`blockQuote`)}var qL={name:`characterEscape`,tokenize:Wie};function Wie(e,t,n){return r;function r(t){return e.enter(`characterEscape`),e.enter(`escapeMarker`),e.consume(t),e.exit(`escapeMarker`),i}function i(r){return Aie(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var JL={name:`characterReference`,tokenize:Gie};function Gie(e,t,n){let r=this,i=0,a,o;return s;function s(t){return e.enter(`characterReference`),e.enter(`characterReferenceMarker`),e.consume(t),e.exit(`characterReferenceMarker`),c}function c(t){return t===35?(e.enter(`characterReferenceMarkerNumeric`),e.consume(t),e.exit(`characterReferenceMarkerNumeric`),l):(e.enter(`characterReferenceValue`),a=31,o=kL,u(t))}function l(t){return t===88||t===120?(e.enter(`characterReferenceMarkerHexadecimal`),e.consume(t),e.exit(`characterReferenceMarkerHexadecimal`),e.enter(`characterReferenceValue`),a=6,o=kie,u):(e.enter(`characterReferenceValue`),a=7,o=jL,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===kL&&!xL(r.sliceSerialize(i))?n(s):(e.enter(`characterReferenceMarker`),e.consume(s),e.exit(`characterReferenceMarker`),e.exit(`characterReference`),t)}return o(s)&&i++<a?(e.consume(s),u):n(s)}}var YL={partial:!0,tokenize:qie},XL={concrete:!0,name:`codeFenced`,tokenize:Kie};function Kie(e,t,n){let r=this,i={partial:!0,tokenize:x},a=0,o=0,s;return c;function c(e){return l(e)}function l(t){let n=r.events[r.events.length-1];return a=n&&n[1].type===`linePrefix`?n[2].sliceSerialize(n[1],!0).length:0,s=t,e.enter(`codeFenced`),e.enter(`codeFencedFence`),e.enter(`codeFencedFenceSequence`),u(t)}function u(t){return t===s?(o++,e.consume(t),u):o<3?n(t):(e.exit(`codeFencedFenceSequence`),PL(t)?zL(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||ML(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check(YL,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||ML(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):PL(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),zL(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||ML(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||ML(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceMeta`),d(t)):t===96&&t===s?n(t):(e.consume(t),m)}function h(t){return e.attempt(i,b,g)(t)}function g(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),_}function _(t){return a>0&&PL(t)?zL(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||ML(t)?e.check(YL,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||ML(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),PL(t)?zL(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),PL(t)?zL(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||ML(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function qie(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var ZL={name:`codeIndented`,tokenize:Yie},Jie={partial:!0,tokenize:Xie};function Yie(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),zL(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):ML(t)?e.attempt(Jie,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||ML(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function Xie(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):ML(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):zL(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):ML(e)?i(e):n(e)}}var Zie={name:`codeText`,previous:$ie,resolve:Qie,tokenize:eae};function Qie(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r<t;)if(e[r][1].type===`codeTextData`){e[n][1].type=`codeTextPadding`,e[t][1].type=`codeTextPadding`,n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!==`lineEnding`&&(i=r):(r===t||e[r][1].type===`lineEnding`)&&(e[i][1].type=`codeTextData`,r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function $ie(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function eae(e,t,n){let r=0,i,a;return o;function o(t){return e.enter(`codeText`),e.enter(`codeTextSequence`),s(t)}function s(t){return t===96?(e.consume(t),r++,s):(e.exit(`codeTextSequence`),c(t))}function c(t){return t===null?n(t):t===32?(e.enter(`space`),e.consume(t),e.exit(`space`),c):t===96?(a=e.enter(`codeTextSequence`),i=0,u(t)):ML(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c):(e.enter(`codeTextData`),l(t))}function l(t){return t===null||t===32||t===96||ML(t)?(e.exit(`codeTextData`),c(t)):(e.consume(t),l)}function u(n){return n===96?(e.consume(n),i++,u):i===r?(e.exit(`codeTextSequence`),e.exit(`codeText`),t(n)):(a.type=`codeTextData`,l(n))}}var tae=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){let n=t??1/0;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&QL(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),QL(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),QL(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0)){if(e<this.left.length){let t=this.left.splice(e,1/0);QL(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);QL(this.left,t.reverse())}}}};function QL(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function $L(e){let t={},n=-1,r,i,a,o,s,c,l,u=new tae(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type===`chunkFlow`&&u.get(n-1)[1].type===`listItemPrefix`&&(c=r[1]._tokenizer.events,a=0,a<c.length&&c[a][1].type===`lineEndingBlank`&&(a+=2),a<c.length&&c[a][1].type===`content`))for(;++a<c.length&&c[a][1].type!==`content`;)c[a][1].type===`chunkText`&&(c[a][1]._isInFirstContentOfListItem=!0,a++);if(r[0]===`enter`)r[1].contentType&&(Object.assign(t,nae(u,n)),n=t[n],l=!0);else if(r[1]._container){for(a=n,i=void 0;a--;)if(o=u.get(a),o[1].type===`lineEnding`||o[1].type===`lineEndingBlank`)o[0]===`enter`&&(i&&(u.get(i)[1].type=`lineEndingBlank`),o[1].type=`lineEnding`,i=a);else if(o[1].type!==`linePrefix`&&o[1].type!==`listItemIndent`)break;i&&(r[1].end={...u.get(i)[1].start},s=u.slice(i,n),s.unshift(r),u.splice(i,n-i+1,s))}}return SL(e,0,1/0,u.slice(0)),!l}function nae(e,t){let n=e.get(t)[1],r=e.get(t)[2],i=t-1,a=[],o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));let s=o.events,c=[],l={},u,d,f=-1,p=n,m=0,h=0,g=[h];for(;p;){for(;e.get(++i)[1]!==p;);a.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<s.length;)s[f][0]===`exit`&&s[f-1][0]===`enter`&&s[f][1].type===s[f-1][1].type&&s[f][1].start.line!==s[f][1].end.line&&(h=f+1,g.push(h),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),f=g.length;f--;){let t=s.slice(g[f],g[f+1]),n=a.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[m+c[f][0]]=m+c[f][1],m+=c[f][1]-c[f][0]-1;return l}var rae={resolve:aae,tokenize:oae},iae={partial:!0,tokenize:sae};function aae(e){return $L(e),e}function oae(e,t){let n;return r;function r(t){return e.enter(`content`),n=e.enter(`chunkContent`,{contentType:`content`}),i(t)}function i(t){return t===null?a(t):ML(t)?e.check(iae,o,a)(t):(e.consume(t),i)}function a(n){return e.exit(`chunkContent`),e.exit(`content`),t(n)}function o(t){return e.consume(t),e.exit(`chunkContent`),n.next=e.enter(`chunkContent`,{contentType:`content`,previous:n}),n=n.next,i}}function sae(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),zL(e,a,`linePrefix`)}function a(i){if(i===null||ML(i))return n(i);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes(`codeIndented`)&&a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function eR(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||AL(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||ML(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||NL(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u<l&&i===40?(e.consume(i),u++,h):i===41?(e.consume(i),u--,h):i===null||i===32||i===40||AL(i)?n(i):(e.consume(i),i===92?g:h)}function g(t){return t===40||t===41||t===92?(e.consume(t),h):h(t)}}function tR(e,t,n,r,i,a){let o=this,s=0,c;return l;function l(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(a),u}function u(l){return s>999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):ML(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||ML(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!PL(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function nR(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):ML(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),zL(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||ML(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function rR(e,t){let n;return r;function r(i){return ML(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):PL(i)?zL(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var cae={name:`definition`,tokenize:uae},lae={partial:!0,tokenize:dae};function uae(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return tR.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=DL(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return NL(t)?rR(e,l)(t):l(t)}function l(t){return eR(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(lae,d,d)(t)}function d(t){return PL(t)?zL(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||ML(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function dae(e,t,n){return r;function r(t){return NL(t)?rR(e,i)(t):n(t)}function i(t){return nR(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return PL(t)?zL(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||ML(e)?t(e):n(e)}}var fae={name:`hardBreakEscape`,tokenize:pae};function pae(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return ML(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var mae={name:`headingAtx`,resolve:hae,tokenize:gae};function hae(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},SL(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function gae(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||NL(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||ML(n)?(e.exit(`atxHeading`),t(n)):PL(n)?zL(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||NL(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var _ae=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),iR=[`pre`,`script`,`style`,`textarea`],vae={concrete:!0,name:`htmlFlow`,resolveTo:xae,tokenize:Sae},yae={partial:!0,tokenize:wae},bae={partial:!0,tokenize:Cae};function xae(e){let t=e.length;for(;t--&&(e[t][0]!==`enter`||e[t][1].type!==`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function Sae(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:M):OL(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):OL(a)?(e.consume(a),i=4,r.interrupt?t:M):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:M):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return OL(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||NL(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&iR.includes(l)?(i=1,r.interrupt?t(s):O(s)):_ae.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||kL(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return PL(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||OL(t)?(e.consume(t),b):PL(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||kL(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):PL(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):PL(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||ML(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||NL(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||PL(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||ML(t)?O(t):PL(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),te):t===60&&i===1?(e.consume(t),ne):t===62&&i===4?(e.consume(t),ie):t===63&&i===3?(e.consume(t),M):t===93&&i===5?(e.consume(t),re):ML(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(yae,ae,k)(t)):t===null||ML(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(bae,A,ae)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),ee}function ee(t){return t===null||ML(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function te(t){return t===45?(e.consume(t),M):O(t)}function ne(t){return t===47?(e.consume(t),o=``,j):O(t)}function j(t){if(t===62){let n=o.toLowerCase();return iR.includes(n)?(e.consume(t),ie):O(t)}return OL(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),j):O(t)}function re(t){return t===93?(e.consume(t),M):O(t)}function M(t){return t===62?(e.consume(t),ie):t===45&&i===2?(e.consume(t),M):O(t)}function ie(t){return t===null||ML(t)?(e.exit(`htmlFlowData`),ae(t)):(e.consume(t),ie)}function ae(n){return e.exit(`htmlFlow`),t(n)}}function Cae(e,t,n){let r=this;return i;function i(t){return ML(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function wae(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(GL,t,n)}}var Tae={name:`htmlText`,tokenize:Eae};function Eae(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):OL(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):OL(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):ML(t)?(o=d,ne(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?te(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):ML(t)?(o=h,ne(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?te(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?te(t):ML(t)?(o=v,ne(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):ML(t)?(o=y,ne(t)):(e.consume(t),y)}function b(e){return e===62?te(e):y(e)}function x(t){return OL(t)?(e.consume(t),S):n(t)}function S(t){return t===45||kL(t)?(e.consume(t),S):C(t)}function C(t){return ML(t)?(o=C,ne(t)):PL(t)?(e.consume(t),C):te(t)}function w(t){return t===45||kL(t)?(e.consume(t),w):t===47||t===62||NL(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),te):t===58||t===95||OL(t)?(e.consume(t),E):ML(t)?(o=T,ne(t)):PL(t)?(e.consume(t),T):te(t)}function E(t){return t===45||t===46||t===58||t===95||kL(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):ML(t)?(o=D,ne(t)):PL(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):ML(t)?(o=O,ne(t)):PL(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,ee):t===null?n(t):ML(t)?(o=k,ne(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||NL(t)?T(t):(e.consume(t),A)}function ee(e){return e===47||e===62||NL(e)?T(e):n(e)}function te(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function ne(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return PL(t)?zL(e,re,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):re(t)}function re(t){return e.enter(`htmlTextData`),o(t)}}var aR={name:`labelEnd`,resolveAll:Aae,resolveTo:jae,tokenize:Mae},Dae={tokenize:Nae},Oae={tokenize:Pae},kae={tokenize:Fae};function Aae(e){let t=-1,n=[];for(;++t<e.length;){let r=e[t][1];if(n.push(e[t]),r.type===`labelImage`||r.type===`labelLink`||r.type===`labelEnd`){let e=r.type===`labelImage`?4:2;r.type=`data`,t+=e}}return e.length!==n.length&&SL(e,0,e.length,n),e}function jae(e,t){let n=e.length,r=0,i,a,o,s;for(;n--;)if(i=e[n][1],a){if(i.type===`link`||i.type===`labelLink`&&i._inactive)break;e[n][0]===`enter`&&i.type===`labelLink`&&(i._inactive=!0)}else if(o){if(e[n][0]===`enter`&&(i.type===`labelImage`||i.type===`labelLink`)&&!i._balanced&&(a=n,i.type!==`labelLink`)){r=2;break}}else i.type===`labelEnd`&&(o=n);let c={type:e[a][1].type===`labelLink`?`link`:`image`,start:{...e[a][1].start},end:{...e[e.length-1][1].end}},l={type:`label`,start:{...e[a][1].start},end:{...e[o][1].end}},u={type:`labelText`,start:{...e[a+r+2][1].end},end:{...e[o-2][1].start}};return s=[[`enter`,c,t],[`enter`,l,t]],s=CL(s,e.slice(a+1,a+r+3)),s=CL(s,[[`enter`,u,t]]),s=CL(s,HL(t.parser.constructs.insideSpan.null,e.slice(a+r+4,o-3),t)),s=CL(s,[[`exit`,u,t],e[o-2],e[o-1],[`exit`,l,t]]),s=CL(s,e.slice(o+1)),s=CL(s,[[`exit`,c,t]]),SL(e,a,e.length,s),e}function Mae(e,t,n){let r=this,i=r.events.length,a,o;for(;i--;)if((r.events[i][1].type===`labelImage`||r.events[i][1].type===`labelLink`)&&!r.events[i][1]._balanced){a=r.events[i][1];break}return s;function s(t){return a?a._inactive?d(t):(o=r.parser.defined.includes(DL(r.sliceSerialize({start:a.end,end:r.now()}))),e.enter(`labelEnd`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelEnd`),c):n(t)}function c(t){return t===40?e.attempt(Dae,u,o?u:d)(t):t===91?e.attempt(Oae,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(kae,u,d)(t)}function u(e){return t(e)}function d(e){return a._balanced=!0,n(e)}}function Nae(e,t,n){return r;function r(t){return e.enter(`resource`),e.enter(`resourceMarker`),e.consume(t),e.exit(`resourceMarker`),i}function i(t){return NL(t)?rR(e,a)(t):a(t)}function a(t){return t===41?u(t):eR(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return NL(t)?rR(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?nR(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return NL(t)?rR(e,u)(t):u(t)}function u(r){return r===41?(e.enter(`resourceMarker`),e.consume(r),e.exit(`resourceMarker`),e.exit(`resource`),t):n(r)}}function Pae(e,t,n){let r=this;return i;function i(t){return tR.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(DL(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function Fae(e,t,n){return r;function r(t){return e.enter(`reference`),e.enter(`referenceMarker`),e.consume(t),e.exit(`referenceMarker`),i}function i(r){return r===93?(e.enter(`referenceMarker`),e.consume(r),e.exit(`referenceMarker`),e.exit(`reference`),t):n(r)}}var Iae={name:`labelStartImage`,resolveAll:aR.resolveAll,tokenize:Lae};function Lae(e,t,n){let r=this;return i;function i(t){return e.enter(`labelImage`),e.enter(`labelImageMarker`),e.consume(t),e.exit(`labelImageMarker`),a}function a(t){return t===91?(e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelImage`),o):n(t)}function o(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var Rae={name:`labelStartLink`,resolveAll:aR.resolveAll,tokenize:zae};function zae(e,t,n){let r=this;return i;function i(t){return e.enter(`labelLink`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelLink`),a}function a(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var oR={name:`lineEnding`,tokenize:Bae};function Bae(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),zL(e,t,`linePrefix`)}}var sR={name:`thematicBreak`,tokenize:Vae};function Vae(e,t,n){let r=0,i;return a;function a(t){return e.enter(`thematicBreak`),o(t)}function o(e){return i=e,s(e)}function s(a){return a===i?(e.enter(`thematicBreakSequence`),c(a)):r>=3&&(a===null||ML(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),PL(t)?zL(e,s,`whitespace`)(t):s(t))}}var cR={continuation:{tokenize:Gae},exit:qae,name:`list`,tokenize:Wae},Hae={partial:!0,tokenize:Jae},Uae={partial:!0,tokenize:Kae};function Wae(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:jL(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(sR,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return jL(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(GL,r.interrupt?n:u,e.attempt(Hae,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return PL(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function Gae(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(GL,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,zL(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!PL(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(Uae,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,zL(e,e.attempt(cR,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function Kae(e,t,n){let r=this;return zL(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function qae(e){e.exit(this.containerState.type)}function Jae(e,t,n){let r=this;return zL(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!PL(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var lR={name:`setextUnderline`,resolveTo:Yae,tokenize:Xae};function Yae(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function Xae(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),PL(t)?zL(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||ML(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var Zae={tokenize:Qae};function Qae(e){let t=this,n=e.attempt(GL,r,e.attempt(this.parser.constructs.flowInitial,i,zL(e,e.attempt(this.parser.constructs.flow,i,e.attempt(rae,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var $ae={resolveAll:dR()},eoe=uR(`string`),toe=uR(`text`);function uR(e){return{resolveAll:dR(e===`text`?noe:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i<t.length;){let e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}function dR(e){return t;function t(t,n){let r=-1,i;for(;++r<=t.length;)i===void 0?t[r]&&t[r][1].type===`data`&&(i=r,r++):(!t[r]||t[r][1].type!==`data`)&&(r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),r=i+2),i=void 0);return e?e(t,n):t}}function noe(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type===`lineEnding`)&&e[n-1][1].type===`data`){let r=e[n-1][1],i=t.sliceStream(r),a=i.length,o=-1,s=0,c;for(;a--;){let e=i[a];if(typeof e==`string`){for(o=e.length;e.charCodeAt(o-1)===32;)s++,o--;if(o)break;o=-1}else if(e===-2)c=!0,s++;else if(e!==-1){a++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(s=0),s){let i={type:n===e.length||c||s<2?`lineSuffix`:`hardBreakTrailing`,start:{_bufferIndex:a?o:r.start._bufferIndex+o,_index:r.start._index+a,line:r.end.line,column:r.end.column-s,offset:r.end.offset-s},end:{...r.end}};r.end={...i.start},r.start.offset===r.end.offset?Object.assign(r,i):(e.splice(n,0,[`enter`,i,t],[`exit`,i,t]),n+=2)}n++}return e}var roe=s({attentionMarkers:()=>doe,contentInitial:()=>aoe,disable:()=>foe,document:()=>ioe,flow:()=>soe,flowInitial:()=>ooe,insideSpan:()=>uoe,string:()=>coe,text:()=>loe}),ioe={42:cR,43:cR,45:cR,48:cR,49:cR,50:cR,51:cR,52:cR,53:cR,54:cR,55:cR,56:cR,57:cR,62:KL},aoe={91:cae},ooe={[-2]:ZL,[-1]:ZL,32:ZL},soe={35:mae,42:sR,45:[lR,sR],60:vae,61:lR,95:sR,96:XL,126:XL},coe={38:JL,92:qL},loe={[-5]:oR,[-4]:oR,[-3]:oR,33:Iae,38:JL,42:UL,60:[Rie,Tae],91:Rae,92:[fae,qL],93:aR,95:UL,96:Zie},uoe={null:[UL,$ae]},doe={null:[42,95]},foe={null:[]};function poe(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=CL(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=HL(a,l.events,l),l.events):[]}function f(e,t){return hoe(p(e),t)}function p(e){return moe(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index<o.length;){let t=o[r._index];if(typeof t==`string`)for(e=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===e&&r._bufferIndex<t.length;)_(t.charCodeAt(r._bufferIndex));else _(t)}}function _(e){u=u(e)}function v(e){ML(e)?(r.line++,r.column=1,r.offset+=e===-3?2:1,E()):e!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),l.previous=e}function y(e,t){let n=t||{};return n.type=e,n.start=m(),l.events.push([`enter`,n,l]),s.push(n),n}function b(e){let t=s.pop();return t.end=m(),l.events.push([`exit`,t,l]),t}function x(e,t){w(e,t.from)}function S(e,t){t.restore()}function C(e,t){return n;function n(n,r,i){let a,o,s,u;return Array.isArray(n)?f(n):`tokenize`in n?f([n]):d(n);function d(e){return t;function t(t){let n=t!==null&&e[t],r=t!==null&&e.null;return f([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}function f(e){return a=e,o=0,e.length===0?i:p(e[o])}function p(e){return n;function n(n){return u=T(),s=e,e.partial||(l.currentConstruct=e),e.name&&l.parser.constructs.disable.null.includes(e.name)?h(n):e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,h)(n)}}function m(t){return e(s,u),r}function h(e){return u.restore(),++o<a.length?p(a[o]):i}}}function w(e,t){e.resolveAll&&!a.includes(e)&&a.push(e),e.resolve&&SL(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function T(){let e=m(),t=l.previous,n=l.currentConstruct,i=l.events.length,a=Array.from(s);return{from:i,restore:o};function o(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,s=a,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function moe(e,t){let n=t.start._index,r=t.start._bufferIndex,i=t.end._index,a=t.end._bufferIndex,o;if(n===i)o=[e[n].slice(r,a)];else{if(o=e.slice(n,i),r>-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function hoe(e,t){let n=-1,r=[],i;for(;++n<e.length;){let a=e[n],o;if(typeof a==`string`)o=a;else switch(a){case-5:o=`\r`;break;case-4:o=`
106
106
  `;break;case-3:o=`\r
107
107
  `;break;case-2:o=t?` `:` `;break;case-1:if(!t&&i)continue;o=` `;break;default:o=String.fromCharCode(a)}i=a===-2,r.push(o)}return r.join(``)}function goe(e){let t={constructs:TL([roe,...(e||{}).extensions||[]]),content:n(jie),defined:[],document:n(Nie),flow:n(Zae),lazy:{},string:n(eoe),text:n(toe)};return t;function n(e){return n;function n(n){return poe(t,e,n)}}}function _oe(e){for(;!$L(e););return e}var fR=/[\0\t\n\r]/g;function voe(){let e=1,t=``,n=!0,r;return i;function i(i,a,o){let s=[],c,l,u,d,f;for(i=t+(typeof i==`string`?i.toString():new TextDecoder(a||void 0).decode(i)),u=0,t=``,n&&=(i.charCodeAt(0)===65279&&u++,void 0);u<i.length;){if(fR.lastIndex=u,c=fR.exec(i),d=c&&c.index!==void 0?c.index:i.length,f=i.charCodeAt(d),!c){t=i.slice(u);break}if(f===10&&u===d&&r)s.push(-3),r=void 0;else switch(r&&=(s.push(-5),void 0),u<d&&(s.push(i.slice(u,d)),e+=d-u),f){case 0:s.push(65533),e++;break;case 9:for(l=Math.ceil(e/4)*4,s.push(-2);e++<l;)s.push(-1);break;case 10:s.push(-4),e=1;break;default:r=!0,e=1}u=d+1}return o&&(r&&s.push(-5),t&&s.push(t),s.push(null)),s}}var yoe=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function pR(e){return e.replace(yoe,boe)}function boe(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){let e=n.charCodeAt(1),t=e===120||e===88;return EL(n.slice(t?2:1),t?16:10)}return xL(n)||e}var mR={}.hasOwnProperty;function xoe(e,t,n){return t&&typeof t==`object`&&(n=t,t=void 0),Soe(n)(_oe(goe(n).document().write(voe()(e,t,!0))))}function Soe(e){let t={transforms:[],canContainEols:[`emphasis`,`fragment`,`heading`,`paragraph`,`strong`],enter:{autolink:a(Se),autolinkProtocol:T,autolinkEmail:T,atxHeading:a(ve),blockQuote:a(pe),characterEscape:T,characterReference:T,codeFenced:a(me),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:a(me,o),codeText:a(he,o),codeTextData:T,data:T,codeFlowValue:T,definition:a(ge),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:a(_e),hardBreakEscape:a(ye),hardBreakTrailing:a(ye),htmlFlow:a(be,o),htmlFlowData:T,htmlText:a(be,o),htmlTextData:T,image:a(xe),label:o,link:a(Se),listItem:a(we),listItemValue:f,listOrdered:a(Ce,d),listUnordered:a(Ce),paragraph:a(Te),reference:oe,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:a(ve),strong:a(Ee),thematicBreak:a(Oe)},exit:{atxHeading:c(),atxHeadingSequence:x,autolink:c(),autolinkEmail:fe,autolinkProtocol:de,blockQuote:c(),characterEscapeValue:E,characterReferenceMarkerHexadecimal:ce,characterReferenceMarkerNumeric:ce,characterReferenceValue:le,characterReference:ue,codeFenced:c(g),codeFencedFence:h,codeFencedFenceInfo:p,codeFencedFenceMeta:m,codeFlowValue:E,codeIndented:c(_),codeText:c(ee),codeTextData:E,data:E,definition:c(),definitionDestinationString:b,definitionLabelString:v,definitionTitleString:y,emphasis:c(),hardBreakEscape:c(O),hardBreakTrailing:c(O),htmlFlow:c(k),htmlFlowData:E,htmlText:c(A),htmlTextData:E,image:c(ne),label:re,labelText:j,lineEnding:D,link:c(te),listItem:c(),listOrdered:c(),listUnordered:c(),paragraph:c(),referenceString:se,resourceDestinationString:M,resourceTitleString:ie,resource:ae,setextHeading:c(w),setextHeadingLineSequence:C,setextHeadingText:S,strong:c(),thematicBreak:c()}};gR(t,(e||{}).mdastExtensions||[]);let n={};return r;function r(e){let r={type:`root`,children:[]},a={stack:[r],tokenStack:[],config:t,enter:s,exit:l,buffer:o,resume:u,data:n},c=[],d=-1;for(;++d<e.length;)(e[d][1].type===`listOrdered`||e[d][1].type===`listUnordered`)&&(e[d][0]===`enter`?c.push(d):d=i(e,c.pop(),d));for(d=-1;++d<e.length;){let n=t[e[d][0]];mR.call(n,e[d][1].type)&&n[e[d][1].type].call(Object.assign({sliceSerialize:e[d][2].sliceSerialize},a),e[d][1])}if(a.tokenStack.length>0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||_R).call(a,void 0,e[0])}for(r.position={start:hR(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:hR(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d<t.transforms.length;)r=t.transforms[d](r)||r;return r}function i(e,t,n){let r=t-1,i=-1,a=!1,o,s,c,l;for(;++r<=n;){let t=e[r];switch(t[1].type){case`listUnordered`:case`listOrdered`:case`blockQuote`:t[0]===`enter`?i++:i--,l=void 0;break;case`lineEndingBlank`:t[0]===`enter`&&(o&&!l&&!i&&!c&&(c=r),l=void 0);break;case`linePrefix`:case`listItemValue`:case`listItemMarker`:case`listItemPrefix`:case`listItemPrefixWhitespace`:break;default:l=void 0}if(!i&&t[0]===`enter`&&t[1].type===`listItemPrefix`||i===-1&&t[0]===`exit`&&(t[1].type===`listUnordered`||t[1].type===`listOrdered`)){if(o){let i=r;for(s=void 0;i--;){let t=e[i];if(t[1].type===`lineEnding`||t[1].type===`lineEndingBlank`){if(t[0]===`exit`)continue;s&&(e[s][1].type=`lineEndingBlank`,a=!0),t[1].type=`lineEnding`,s=i}else if(t[1].type!==`linePrefix`&&t[1].type!==`blockQuotePrefix`&&t[1].type!==`blockQuotePrefixWhitespace`&&t[1].type!==`blockQuoteMarker`&&t[1].type!==`listItemIndent`)break}c&&(!s||c<s)&&(o._spread=!0),o.end=Object.assign({},s?e[s][1].start:t[1].end),e.splice(s||r,0,[`exit`,o,t[2]]),r++,n++}if(t[1].type===`listItemPrefix`){let i={type:`listItem`,_spread:!1,start:Object.assign({},t[1].start),end:void 0};o=i,e.splice(r,0,[`enter`,i,t[2]]),r++,n++,c=void 0,l=!0}}}return e[t][1]._spread=a,n}function a(e,t){return n;function n(n){s.call(this,e(n),n),t&&t.call(this,n)}}function o(){this.stack.push({type:`fragment`,children:[]})}function s(e,t,n){this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n||void 0]),e.position={start:hR(t.start),end:void 0}}function c(e){return t;function t(t){e&&e.call(this,t),l.call(this,t)}}function l(e,t){let n=this.stack.pop(),r=this.tokenStack.pop();if(r)r[0].type!==e.type&&(t?t.call(this,e,r[0]):(r[1]||_R).call(this,e,r[0]));else throw Error("Cannot close `"+e.type+"` ("+rL({start:e.start,end:e.end})+`): it’s not open`);n.position.end=hR(e.end)}function u(){return _L(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function f(e){if(this.data.expectingFirstListItemValue){let t=this.stack[this.stack.length-2];t.start=Number.parseInt(this.sliceSerialize(e),10),this.data.expectingFirstListItemValue=void 0}}function p(){let e=this.resume(),t=this.stack[this.stack.length-1];t.lang=e}function m(){let e=this.resume(),t=this.stack[this.stack.length-1];t.meta=e}function h(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function g(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``),this.data.flowCodeInside=void 0}function _(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/(\r?\n|\r)$/g,``)}function v(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=DL(this.sliceSerialize(e)).toLowerCase()}function y(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function b(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function x(e){let t=this.stack[this.stack.length-1];t.depth||=this.sliceSerialize(e).length}function S(){this.data.setextHeadingSlurpLineEnding=!0}function C(e){let t=this.stack[this.stack.length-1];t.depth=this.sliceSerialize(e).codePointAt(0)===61?1:2}function w(){this.data.setextHeadingSlurpLineEnding=void 0}function T(e){let t=this.stack[this.stack.length-1].children,n=t[t.length-1];(!n||n.type!==`text`)&&(n=De(),n.position={start:hR(e.start),end:void 0},t.push(n)),this.stack.push(n)}function E(e){let t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=hR(e.end)}function D(e){let n=this.stack[this.stack.length-1];if(this.data.atHardBreak){let t=n.children[n.children.length-1];t.position.end=hR(e.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(n.type)&&(T.call(this,e),E.call(this,e))}function O(){this.data.atHardBreak=!0}function k(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function A(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function ee(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function te(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function ne(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function j(e){let t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=pR(t),n.identifier=DL(t).toLowerCase()}function re(){let e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];this.data.inReference=!0,n.type===`link`?n.children=e.children:n.alt=t}function M(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function ie(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function ae(){this.data.inReference=void 0}function oe(){this.data.referenceType=`collapsed`}function se(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=DL(this.sliceSerialize(e)).toLowerCase(),this.data.referenceType=`full`}function ce(e){this.data.characterReferenceType=e.type}function le(e){let t=this.sliceSerialize(e),n=this.data.characterReferenceType,r;n?(r=EL(t,n===`characterReferenceMarkerNumeric`?10:16),this.data.characterReferenceType=void 0):r=xL(t);let i=this.stack[this.stack.length-1];i.value+=r}function ue(e){let t=this.stack.pop();t.position.end=hR(e.end)}function de(e){E.call(this,e);let t=this.stack[this.stack.length-1];t.url=this.sliceSerialize(e)}function fe(e){E.call(this,e);let t=this.stack[this.stack.length-1];t.url=`mailto:`+this.sliceSerialize(e)}function pe(){return{type:`blockquote`,children:[]}}function me(){return{type:`code`,lang:null,meta:null,value:``}}function he(){return{type:`inlineCode`,value:``}}function ge(){return{type:`definition`,identifier:``,label:null,title:null,url:``}}function _e(){return{type:`emphasis`,children:[]}}function ve(){return{type:`heading`,depth:0,children:[]}}function ye(){return{type:`break`}}function be(){return{type:`html`,value:``}}function xe(){return{type:`image`,title:null,url:``,alt:null}}function Se(){return{type:`link`,title:null,url:``,children:[]}}function Ce(e){return{type:`list`,ordered:e.type===`listOrdered`,start:null,spread:e._spread,children:[]}}function we(e){return{type:`listItem`,spread:e._spread,checked:null,children:[]}}function Te(){return{type:`paragraph`,children:[]}}function Ee(){return{type:`strong`,children:[]}}function De(){return{type:`text`,value:``}}function Oe(){return{type:`thematicBreak`}}}function hR(e){return{line:e.line,column:e.column,offset:e.offset}}function gR(e,t){let n=-1;for(;++n<t.length;){let r=t[n];Array.isArray(r)?gR(e,r):Coe(e,r)}}function Coe(e,t){let n;for(n in t)if(mR.call(t,n))switch(n){case`canContainEols`:{let r=t[n];r&&e[n].push(...r);break}case`transforms`:{let r=t[n];r&&e[n].push(...r);break}case`enter`:case`exit`:{let r=t[n];r&&Object.assign(e[n],r);break}}}function _R(e,t){throw Error(e?"Cannot close `"+e.type+"` ("+rL({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+rL({start:t.start,end:t.end})+`) is open`:"Cannot close document, a token (`"+t.type+"`, "+rL({start:t.start,end:t.end})+`) is still open`)}function vR(e){let t=this;t.parser=n;function n(n){return xoe(n,{...t.data(`settings`),...e,extensions:t.data(`micromarkExtensions`)||[],mdastExtensions:t.data(`fromMarkdownExtensions`)||[]})}}function woe(e,t){let n={type:`element`,tagName:`blockquote`,properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function Toe(e,t){let n={type:`element`,tagName:`br`,properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:`text`,value:`
@@ -269,41 +269,41 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
269
269
  Sphinxes
270
270
  Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(xV,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(wV,{rows:10,className:`font-mono`,spellCheck:!1,value:e.yaml,onChange:n=>t({...e,yaml:n.target.value}),placeholder:`- ${f??`Topic`}: Cleopatra\n ${d.find(e=>e!==f)??`Min. Word Count`}: 12000\n- Hypatia`})}):(0,h.jsx)(Nde,{queue:e,onQueue:t,keyword:f,addable:O,setRow:D,titleOf:b}),k.length===0?null:(0,h.jsx)(SI,{tone:`danger`,title:`These topics can't be saved yet.`,children:(0,h.jsxs)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:[k.slice(0,8).map(e=>(0,h.jsx)(`li`,{children:e},e)),k.length>8?(0,h.jsx)(`li`,{children:`And ${String(k.length-8)} more.`}):null]})}),e.mode===`yaml`&&v.rows.length>0?(0,h.jsxs)(`section`,{"aria-label":`Project titles`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-1 text-small text-ink-2`,children:`Project titles, in order:`}),(0,h.jsxs)(`ol`,{className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:[v.rows.slice(0,20).map((e,t)=>(0,h.jsx)(`li`,{children:b(e)},t)),v.rows.length>20?(0,h.jsx)(`li`,{className:`list-none text-ink-3`,children:`And ${String(v.rows.length-20)} more.`}):null]})]}):null,a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Reading the template's keywords…`}):d.length===0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`This template has no keywords such as `,`{{Topic}}`,`, so each topic becomes the project's title.`]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:(0,h.jsx)(xV,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:g0({feeds:_(f)})},children:(0,h.jsx)(TV,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(_0,{keywords:d.filter(e=>e!==f).map(t=>({name:t,value:g[t]??``,feeds:_(t),...e.columns.includes(t)?{note:`Unless a topic sets its own.`}:{}})),onChange:i,fieldPrefix:`everyRun`,label:e=>`${e} (every run)`,inputLabel:e=>`${e} for every run`,tip:`planning.schedule.every-run`,maxLength:1e4})]}),e.mode===`lines`&&S!==void 0&&x!==void 0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Next project: `,(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:S}),f===null||C?null:(0,h.jsxs)(`span`,{className:`block text-ink-3`,children:[`The template's project title does not use `,`{{${f}}}`,`, so every project gets this title. Edit the template's title to include it.`]})]}):null]})}function Nde({queue:e,onQueue:t,keyword:n,addable:r,setRow:i,titleOf:a}){let o=n===null?`Title`:`{{${n}}}`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ob,children:[(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table`,"aria-label":`Topics`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,children:`#`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[o,(0,h.jsx)(V,{id:`planning.schedule.topic-table`,className:`-my-1`})]})}),e.columns.map(n=>(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`{{${n}}}`,(0,h.jsx)(wy,{label:`Use the every-run ${n} for all topics`,size:`small`,onClick:()=>t({...e,columns:e.columns.filter(e=>e!==n),rows:e.rows.map(e=>({title:e.title,values:Object.fromEntries(Object.entries(e.values).filter(([e])=>e!==n))}))}),children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})},n)),(0,h.jsx)(`th`,{scope:`col`,children:`Project title`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:e.rows.map((n,r)=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`num`,children:r+1}),(0,h.jsx)(`td`,{children:(0,h.jsx)(CV,{"aria-label":`Topic ${String(r+1)} ${o}`,maxLength:200,value:n.title,onChange:e=>i(r,{...n,title:e.target.value})})}),e.columns.map(e=>(0,h.jsx)(`td`,{children:(0,h.jsx)(CV,{"aria-label":`Topic ${String(r+1)} ${e}`,maxLength:gq,placeholder:`Every-run value`,value:n.values[e]??``,onChange:t=>i(r,{...n,values:{...n.values,[e]:t.target.value}})})},e)),(0,h.jsx)(`td`,{className:`min-w-[180px] text-small text-ink-2`,children:a(n)??`—`}),(0,h.jsx)(`td`,{children:(0,h.jsx)(wy,{label:`Remove topic ${String(r+1)}`,size:`small`,onClick:()=>t({...e,rows:e.rows.filter((e,t)=>t!==r)}),children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})})]},r))})]})}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(R,{size:`small`,onClick:()=>t({...e,rows:[...e.rows,{title:``,values:{}}]}),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]}),r.length===0?null:(0,h.jsxs)(TV,{"aria-label":`Set a keyword per topic`,value:``,className:`w-auto`,onChange:n=>{let r=n.target.value;r!==``&&t({...e,columns:[...e.columns,r]})},children:[(0,h.jsx)(`option`,{value:``,children:`Set a keyword per topic…`}),r.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))]})]})]})}var Pde=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Fde({templates:e,pending:t,onCreated:n,onError:r,editing:i,onCancel:a,error:o,onBusy:s}){let{api:c}=z(),[l,u]=(0,m.useState)(i?.name??``),[d,f]=(0,m.useState)(i?.templateId??``),[p,g]=(0,m.useState)(i?.cadence.kind??`daily`),[_,v]=(0,m.useState)(i?.cadence.kind===`once`?Yue(i.cadence.at,i.timezone):``),[y,b]=(0,m.useState)(i&&i.cadence.kind!==`once`?i.cadence.time:`09:00`),[x,S]=(0,m.useState)(i?.cadence.kind===`weekly`?i.cadence.days:[1,3,5]),[C,w]=(0,m.useState)(()=>i?.timezone??(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`)),[T,E]=(0,m.useState)(i?.missedPolicy??`skip`),[D,O]=(0,m.useState)(i?.spendLimitCents?.toString()??``),[k,A]=(0,m.useState)(()=>y0(i?.items??[])),[ee,te]=(0,m.useState)(i?.topicKeyword??null),[ne,j]=(0,m.useState)(i?.values??{}),[re,M]=(0,m.useState)(i?.brief??``),[ie,ae]=(0,m.useState)(i?.topicGeneration??lH),[oe,se]=(0,m.useState)(!1),[ce,le]=(0,m.useState)(!1),ue=(0,m.useRef)(!1),de=(0,m.useRef)(null),fe=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,pe=fe.find(e=>e.id===d),me=N({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await Uq(c,d);if(!e.ok)throw Error(e.message);return e.value}}),he=me.data?.document.form,ge=he===void 0?void 0:h0({form:he,prompts:me.data?.document.librarySnapshot?.prompts??[],entries:me.data?.document.librarySnapshot?.entries??[]}),_e=he===void 0?[]:_q(he),ve=ee!==null&&_e.includes(ee)?ee:_e.find(e=>he?.title.includes(`{{${e}}}`))??_e[0]??null,ye=Object.fromEntries(_e.filter(e=>e!==ve).map(e=>[e,ne[e]??he?.values[e]??``])),be={keywords:_e,topicKeyword:ve,everyRun:ye,form:he,kept:i?.items??[],...ge===void 0?{}:{origins:ge}},xe=S0(k,be);async function Se(e){if(e.preventDefault(),!(ue.current||t)){if(!pe&&!de.current){r(`Choose a template before saving the schedule.`);return}if(!de.current&&xe.problems.length>0){r(`Fix the topics first. ${xe.problems.slice(0,3).join(` `)}`);return}if(xe.rows.length>500){r(`Keep the list to 500 topics or fewer.`);return}if(re.trim().length>4e3){r(`Keep the series brief to ${String(sH)} characters or fewer.`);return}if(ie.llm!==null&&(ie.llm.provider===``||ie.llm.model===``)){r(`Pick both a provider and a model for topic generation, or choose Use the template's LLM.`);return}if(p===`weekly`&&x.length===0){r(`Choose at least one weekday for a weekly schedule.`);return}ue.current=!0,se(!0),s(!0);try{if(!de.current){if(!pe)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!$V(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Xue(_,e)}:p===`weekly`?{kind:p,time:y,days:x}:{kind:p,time:y},n=D.trim()===``?null:Number(D);if(n!==null&&(!Number.isInteger(n)||n<0))throw Error(`Enter the spend limit as a whole number of cents, 0 or more (500 is $5.00), or leave it empty.`);let r={id:i?.id??crypto.randomUUID(),name:l.trim(),templateId:pe.id,templateVersion:pe.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:xe.rows,topicKeyword:ve,values:ye,brief:re.trim()===``?null:re.trim(),topicGeneration:ie};de.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=de.current,{id:t,...a}=e,o=`mutationId`in a?await kH(c,t,a):await OH(c,e);if(!o.ok){de.current=null,le(!1),r(o.reason===`conflict`?`${o.message} Your inputs are kept here. To load the latest saved version, cancel editing and press Edit again.`:o.message);return}de.current=null,le(!1),u(``),A(y0([])),n()}catch(e){le(de.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{ue.current=!1,se(!1),s(de.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(SI,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{onSubmit:e=>void Se(e),children:[(0,h.jsxs)(`fieldset`,{disabled:oe||ce||t,className:`m-0 grid min-w-0 gap-4 border-0 p-0 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,children:(0,h.jsx)(CV,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(xV,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,children:(0,h.jsxs)(TV,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:fe.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),fe.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(xV,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(TV,{value:p,onChange:e=>g(e.target.value===`once`?`once`:e.target.value===`weekly`?`weekly`:`daily`),children:[(0,h.jsx)(`option`,{value:`daily`,children:`Every day`}),(0,h.jsx)(`option`,{value:`weekly`,children:`Selected weekdays`}),(0,h.jsx)(`option`,{value:`once`,children:`One time`})]})}),p===`once`?(0,h.jsx)(xV,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,children:(0,h.jsx)(CV,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(xV,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,children:(0,h.jsx)(CV,{required:!0,type:`time`,value:y,onChange:e=>b(e.target.value)})}),p===`weekly`?(0,h.jsxs)(`fieldset`,{className:`m-0 min-w-0 border-0 p-0`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`sl-field__label mb-2 flex items-center gap-1`,children:[`Weekdays`,(0,h.jsx)(V,{id:`planning.schedule.weekdays`,className:`-my-1`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Pde.map(([e,t])=>(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),onChange:t=>S(n=>t.target.checked?[...n,e]:n.filter(t=>t!==e))}),t]},e))})]}):(0,h.jsx)(`div`,{}),(0,h.jsx)(xV,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,children:(0,h.jsx)(CV,{value:C,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(xV,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(TV,{value:T,onChange:e=>E(e.target.value===`run-once`?`run-once`:`skip`),children:[(0,h.jsx)(`option`,{value:`skip`,children:`Skip if Slopify was closed`}),(0,h.jsx)(`option`,{value:`run-once`,children:`Run once when Slopify reopens`})]})}),(0,h.jsx)(xV,{label:`Spend ceiling (cents, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,children:(0,h.jsx)(CV,{inputMode:`numeric`,value:D,onChange:e=>O(e.target.value),placeholder:`1000`})}),(0,h.jsx)(Mde,{queue:k,onQueue:A,context:be,onKeyword:te,onValue:(e,t)=>j(n=>({...n,[e]:t})),loading:d!==``&&me.isPending,exportName:l}),(0,h.jsx)(Ide,{brief:re,onBrief:M,generation:ie,onGeneration:ae,templateLlm:he?.llm})]}),(0,h.jsxs)(`div`,{className:`sticky bottom-0 z-10 mt-6 flex flex-wrap gap-2 border-t border-line bg-ground py-3 max-md:bottom-[68px]`,children:[(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:t||oe||fe.length===0&&!ce,children:oe?`Saving…`:ce?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(R,{variant:`quiet`,disabled:oe||ce,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Ide({brief:e,onBrief:t,generation:n,onGeneration:r,templateLlm:i}){let{api:a}=z(),o=N({...eb(a),enabled:n.mode!==`off`}),s=n.llm;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topic generation`,(0,h.jsx)(V,{id:`planning.schedule.generation`})]}),(0,h.jsx)(xV,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,children:(0,h.jsx)(wV,{rows:3,maxLength:sH,value:e,onChange:e=>t(e.target.value),placeholder:`Ancient history, documentary style. Famous rulers and places first.`})}),(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,children:(0,h.jsxs)(TV,{value:n.mode,onChange:e=>{let t=e.target.value;r({...n,mode:t===`queue`||t===`hold`?t:`off`})},children:[(0,h.jsx)(`option`,{value:`off`,children:`Off: add topics yourself`}),(0,h.jsx)(`option`,{value:`queue`,children:`Generate and queue directly`}),(0,h.jsx)(`option`,{value:`hold`,children:`Generate and hold for approval`})]})}),n.mode===`off`?null:(0,h.jsx)(xV,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(CV,{type:`number`,min:1,max:100,value:String(n.keepAtLeast),onChange:e=>{let t=Math.round(Number(e.target.value));r({...n,keepAtLeast:Number.isFinite(t)?Math.min(100,Math.max(1,t)):1})}})})]}),n.mode===`off`?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s===null,onChange:e=>r({...n,llm:e.target.checked?null:{provider:i?.provider??``,model:i?.model??``}})}),`Use the template's LLM`,s===null&&i!==void 0&&i.provider!==``?` (${i.provider} · ${i.model})`:``]}),(0,h.jsx)(V,{id:`planning.schedule.generation-llm`,className:`-my-1`})]}),s===null?null:(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(RV,{label:`Provider`,family:`llm`,providers:o.data?.providers??[],value:s.provider,problem:o.error?.message,onPick:e=>r({...n,llm:{provider:e,model:``}})}),(0,h.jsx)(zV,{label:`Model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>r({...n,llm:{...s,model:e}})})]})]})]})}function Lde({schedule:e}){let{api:t}=z(),n=_(),r=Oy(),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(!1),c=(0,m.useRef)(!1),[l,u]=(0,m.useState)(``),d=(0,m.useRef)(e);e.version>d.current.version&&(d.current=e);let f=d.current.items,p=e.topicKeyword===null?`title`:`{{${e.topicKeyword}}}`,g=async(e,i,o)=>{if(c.current)return!1;c.current=!0;let l=d.current;s(!0),a(null);try{let s=await UH(t,l.id,{baseVersion:l.version,items:e});return s.ok?(d.current=s.value,n.setQueryData(TH,e=>e?.map(e=>e.id===s.value.id?s.value:e)),n.invalidateQueries({queryKey:GH}),r(i,`success`,o?{label:`Undo`,run:()=>void g(l.items,`Put the topics back as they were.`,!1)}:void 0),!0):(a(s.reason===`conflict`?`The topics weren't saved: this schedule changed since the page loaded, possibly because a run just took a topic. The list now shows the latest; make your change again.`:`The topics weren't saved: ${s.message}`),await n.invalidateQueries({queryKey:TH}),!1)}catch(e){return a(`The topics weren't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then try again.`),!1}finally{c.current=!1,s(!1)}},v=async e=>{e.preventDefault();let t=l.trim();if(t===``){a(`Write the new topic's ${p} first, then press Add topic.`);return}await g([...f,{title:t,values:{}}],`Added “${t}”.`,!0)&&u(``)},y=(e,t)=>{let n=f[e];if(n!==void 0&&t.trim()!==n.title){if(t.trim()===``){a(`Topic ${String(e+1)} needs a ${p}. Write one, or press its Remove button.`);return}g(f.map((n,r)=>r===e?{...n,title:t.trim()}:n),`Renamed to “${t.trim()}”.`,!0)}},b=(e,t)=>{let n=f[e];if(n===void 0)return;let r=[...f];r.splice(e,1),r.splice(e+t,0,n),g(r,`Moved “${n.title}” ${t===-1?`up`:`down`}.`,!0)},x=e=>{let t=f[e];t!==void 0&&g(f.filter((t,n)=>n!==e),`Removed “${t.title}”.`,!0)};return(0,h.jsxs)(`section`,{"aria-label":`Queued topics`,className:`mt-6`,...Ob,children:[(0,h.jsx)(H,{as:`h3`,title:`Queued topics · ${String(f.length)}`,info:`planning.schedule.inline-topics`,meta:e.topicKeyword===null?`Each topic becomes the next project's title.`:`Each topic fills ${p}; the next run takes the first.`}),i===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:i}),f.length===0?null:(0,h.jsx)(pU,{label:`Topics of ${e.name}`,className:`mt-2`,children:f.map((e,t)=>(0,h.jsx)(Rde,{index:t,title:e.title,count:f.length,busy:o,onRename:e=>y(t,e),onMove:e=>b(t,e),onRemove:()=>x(t)},`${String(t)}:${e.title}`))}),(0,h.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-center gap-2`,onSubmit:e=>void v(e),children:[(0,h.jsx)(CV,{"aria-label":`New topic`,placeholder:e.topicKeyword===null?`New topic`:`New ${p}`,maxLength:200,value:l,className:`min-w-0 flex-1`,onChange:e=>u(e.target.value)}),(0,h.jsxs)(R,{type:`submit`,size:`small`,disabled:o||f.length>=500,disabledReason:o?`Saving the last change`:`A queue holds at most 500 topics`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]})]})]})}function Rde({index:e,title:t,count:n,busy:r,onRename:i,onMove:a,onRemove:o}){let[s,c]=(0,m.useState)(t);(0,m.useEffect)(()=>c(t),[t]);let l=`Topic ${String(e+1)}`;return(0,h.jsx)(mU,{lead:(0,h.jsx)(`span`,{className:`w-6 text-small text-ink-3 tabular-nums`,children:e+1}),title:(0,h.jsx)(CV,{"aria-label":l,maxLength:200,value:s,onChange:e=>c(e.target.value),onBlur:()=>i(s),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i(s)):e.key===`Escape`&&c(t)}}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wy,{size:`small`,label:`Move ${t} up`,disabled:r||e===0,onClick:()=>a(-1),children:(0,h.jsx)(ic,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Move ${t} down`,disabled:r||e===n-1,onClick:()=>a(1),children:(0,h.jsx)(tc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Remove ${t}`,disabled:r,onClick:o,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function zde({pickedId:e,onPick:t}={}){let{api:n}=z(),r=_(),i=N(EH(n)),a=N(Hq(n)),[o,s]=(0,m.useState)(null),c=Oy(),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(null),b=t===void 0?v:e??null,x=e=>{t===void 0?y(e):t(e)},[S,C]=(0,m.useState)(null),w=(0,m.useRef)(!1),T=N(Zb(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=N(KH(n,E.from,E.to)),O=new Map;for(let e of D.data?.runs??[])e.renderedTitle!==null&&!O.has(e.scheduleId)&&O.set(e.scheduleId,e.renderedTitle);let[k,A]=(0,m.useState)(``),ee=e=>{if(k===``)return!0;let t=a.data?.find(t=>t.id===e.templateId);return(t?o0(t):Wb)===k},te=i.data?.filter(e=>e.deletedAt===null&&ee(e))??[],ne=i.data?.filter(e=>e.deletedAt!==null)??[],j=i.data?.find(e=>e.id===b)??te[0]??null,re=P({onError:e=>s(e.message),onSettled:async()=>{w.current=!1,await r.invalidateQueries({queryKey:TH})},mutationFn:async e=>e(),onSuccess:async e=>{if(!e.ok){s(e.message);return}s(null)}}),M=e=>{w.current||(w.current=!0,s(null),re.mutate(e))},ie=d||l!==null,ae=()=>{u(null),f(!1),s(null)},oe=a.data?.length===0,se=()=>{ie||oe||(u(null),f(!0),s(null))},ce=e=>{f(!1),x(e.id),u(e),s(null)};bx({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:se}),Yx(Wx.newSchedule,()=>{oe?c(`A schedule runs a project template, and there is none yet. Open a project, choose Save as template, then run New schedule again.`,`error`):se()},a.data!==void 0);let le=o?{tone:`error`,text:o}:i.error?{tone:`error`,text:`The schedules couldn't be loaded: ${i.error.message} Reload the page to try again.`}:a.error?{tone:`error`,text:`The templates couldn't be loaded: ${a.error.message} Reload the page to try again.`}:void 0,ue=re.isPending||p||ie;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 min-w-0 text-small text-ink-2`,children:oe?(0,h.jsxs)(h.Fragment,{children:[`Save a template in`,` `,(0,h.jsx)(ha,{className:`underline`,to:`/templates`,children:`Library → Templates`}),` `,`before creating a schedule.`]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Runs a saved template on this machine at a local time.`,(0,h.jsx)(V,{id:`planning.schedules`})]})}),(0,h.jsxs)(Ey,{children:[(0,h.jsxs)(TV,{"aria-label":`Filter schedules by channel`,value:k,className:`w-auto min-w-[160px]`,onChange:e=>A(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(T.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsxs)(R,{variant:`primary`,onClick:se,disabled:ie||oe,disabledReason:oe?`Save a template in Library → Templates first`:`Finish or cancel the open form first`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New schedule`]})]})]}),(0,h.jsx)(Q1,{tone:ie?`info`:le?.tone??`info`,className:`mb-2`,children:ie?void 0:le?.text}),(0,h.jsx)(jq,{className:`min-[768px]:grid-cols-[minmax(320px,460px)_minmax(0,1fr)]`,list:(0,h.jsxs)(h.Fragment,{children:[i.data&&te.length===0?(0,h.jsx)(a0,{title:k===``?ne.length===0?`No schedules yet`:`No active schedules`:`No schedules run this channel's templates`,children:k===``?ne.length===0?`Your first one can be a one-off run or a recurring series. Press New schedule.`:`Create one with New schedule, or review deleted history below.`:`Pick All channels to see the others, or make one from this channel's templates.`}):null,te.length>0?(0,h.jsx)(pU,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:te.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(w0,{schedule:e,nextTitle:O.get(e.id),selected:!ie&&j?.id===e.id,pending:ue,onSelect:()=>x(e.id),onEdit:()=>ce(e),onAction:M,onConfirm:t=>C({kind:t,schedule:e})}),(0,h.jsx)(c0,{kind:`schedule`,id:e.id,name:e.name})]},e.id))}):null,ne.length>0?(0,h.jsxs)(`details`,{className:`mt-6`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-small font-semibold text-ink-2`,children:[`Deleted schedules · `,ne.length]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 mb-2 text-small text-ink-2`,children:`Deleted schedules stay in Settings → Trash for 30 days, where Restore brings one back paused. Pick one to see its run history.`}),(0,h.jsx)(pU,{label:`Deleted schedules`,children:ne.map(e=>(0,h.jsx)(w0,{schedule:e,nextTitle:void 0,selected:!ie&&j?.id===e.id,pending:!1,onSelect:()=>x(e.id),onEdit:()=>void 0,onAction:M,onConfirm:()=>void 0},e.id))})]}):null]}),detail:ie?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{kicker:l?l.name:void 0,title:l?`Edit schedule`:`New schedule`,className:`mb-4`}),(0,h.jsx)(Fde,{onBusy:g,editing:l,onCancel:()=>{p||ae()},templates:a.data??[],pending:re.isPending,error:o,onCreated:()=>{c(l?`Schedule updated.`:`Schedule saved. It will run automatically while Slopify is open.`,`success`),ae(),r.invalidateQueries({queryKey:TH})},onError:e=>{s(e),r.invalidateQueries({queryKey:TH})}},l?.id??`new`)]}):j?(0,h.jsx)(Ude,{schedule:j,pending:ue,onAction:M,onConfirm:e=>C({kind:e,schedule:j})},j.id):null}),(0,h.jsx)(jy,{open:S!==null,title:S?.kind===`delete`?`Delete schedule?`:`Cancel schedule?`,consequence:(S?.kind===`delete`?`Moves this schedule to the trash for 30 days (Settings → Trash). Its run history is kept.`:`Stops future scheduled runs. Existing projects and run history are kept.`)+(o?` ${o}`:``),confirmLabel:S?.kind===`delete`?`Delete schedule`:`Cancel schedule`,cancelLabel:`Keep schedule`,pending:re.isPending,onCancel:()=>{re.isPending||C(null)},onConfirm:()=>{if(!S)return;let{kind:e,schedule:t}=S;M(async()=>{let r=e===`delete`?await jH(n,t.id,t.version):await AH(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}function Bde(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}var Vde={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Hde={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function C0({schedule:e}){return e.deletedAt===null?(0,h.jsx)(_S,{tone:Hde[e.status],children:Vde[e.status]}):(0,h.jsx)(_S,{tone:`off`,children:`Deleted`})}function w0({schedule:e,nextTitle:t,selected:n,pending:r,onSelect:i,onEdit:a,onAction:o,onConfirm:s}){let{api:c}=z(),l=e.deletedAt===null,u=l&&(e.status===`active`||e.status===`paused`),d=e.status===`canceled`||e.status===`completed`;return(0,h.jsx)(mU,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(C0,{schedule:e}),` · ${Bde(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${z1(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${z1(e.deletedAt,e.timezone)}`}${e.topics.held>0?` · ${String(e.topics.held)} waiting for you`:``}`]}),actions:l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,disabled:r||!u,disabledReason:u?`Finish or cancel the open form first`:`Only a live schedule can change`,onClick:a,children:`Edit`}),e.status===`paused`?(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Resume ${e.name}`,disabled:r,onClick:()=>o(()=>AH(c,e.id,`resume`,e.version)),children:`Resume`}):(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Pause ${e.name}`,disabled:r||e.status!==`active`,disabledReason:`Only an active schedule can pause`,onClick:()=>o(()=>AH(c,e.id,`pause`,e.version)),children:`Pause`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,disabled:r||!d,disabledReason:`Cancel the schedule first; a completed or canceled one can be deleted`,onClick:()=>s(`delete`),children:`Delete`})]}):void 0})}function Ude({schedule:e,pending:t,onAction:n,onConfirm:r}){let{api:i}=z(),a=N({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await DH(i,e.id);if(!t.ok)throw Error(t.message);return t.value},refetchInterval:3e4}),o=e.deletedAt===null,s=o&&(e.status===`active`||e.status===`paused`),c=e.status===`paused`,l=[[`When`,e.cadence.kind===`once`?`Once, ${z1(e.cadence.at,e.timezone)}`:e.cadence.kind===`daily`?`Every day at ${e.cadence.time}`:`Selected weekdays at ${e.cadence.time}`],[`Timezone`,e.timezone],[`Next run`,e.deletedAt!==null||e.nextRunAt===null?`None`:z1(e.nextRunAt,e.timezone)],[`Topics`,e.items.length===0?e.topicGeneration.mode===`off`?`Template as saved`:`No topics queued`:`${String(e.items.length)} ${e.items.length===1?`topic`:`topics`} left`],[`Missed runs`,e.missedPolicy===`skip`?`Skip`:`Run once on reopening`],[`Overlap`,`Skip`],[`Spend ceiling`,e.spendLimitCents===null?`Not set`:`${String(e.spendLimitCents)} cents`]];return(0,h.jsxs)(`section`,{"aria-label":`${e.name} detail`,children:[o&&s?(0,h.jsx)(Wde,{schedule:e,paused:c,onAction:n}):null,(0,h.jsx)(H,{kicker:(0,h.jsx)(C0,{schedule:e}),title:e.name,meta:e.topics.held>0?`${String(e.topics.held)} topics waiting for you`:void 0,children:o?(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Cancel ${e.name}`,disabled:t||!s,disabledReason:`Only an active or paused schedule can be canceled`,onClick:()=>r(`cancel`),children:`Cancel schedule`}):null}),(0,h.jsx)(`dl`,{className:`m-0 mt-4 grid grid-cols-1 gap-x-6 gap-y-3 text-small min-[600px]:grid-cols-2`,children:l.map(([e,t])=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`dt`,{className:`sl-kicker`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-words text-ink`,children:t})]},e))}),s?(0,h.jsx)(Lde,{schedule:e}):null,(0,h.jsx)(_de,{schedule:e}),(0,h.jsx)(Mq,{className:`my-6`}),(0,h.jsx)(H,{as:`h3`,title:`Run history`}),(0,h.jsx)(`div`,{className:`mt-3`,children:a.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading history…`}):a.error?(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The run history couldn't be loaded: ${a.error.message} It tries again every 30 seconds.`}):a.data.runs.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No runs yet.`}):(0,h.jsx)(pU,{label:`Runs of ${e.name}`,children:a.data.runs.map(t=>(0,h.jsx)(mU,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${z1(t.scheduledFor,e.timezone)}`}),meta:t.error?t.error:t.projectIds.length>0?(0,h.jsx)(`span`,{className:`inline-flex flex-wrap gap-x-3`,children:t.projectIds.map((e,t)=>(0,h.jsxs)(ha,{className:`underline hover:text-ink`,to:`/projects/$projectId`,params:{projectId:e},children:[`Project `,t+1]},e))}):`No projects`},t.id))})})]})}function Wde({schedule:e,paused:t,onAction:n}){let{api:r}=z();return bx({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>AH(r,e.id,t?`resume`:`pause`,e.version))}),null}var T0=`https://www.youtube.com/upload`,Gde=[`video`,`title`,`description`,`thumbnails`,`playlist`,`audience`,`altered`,`tags`];function Kde(e){return e.join(`, `)}var qde=[.75,1,1.25,1.5,1.75,2];function E0(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0,n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function D0(e){return`${String(e)}×`}function Jde(e,t){return e.filter(e=>e.start<=t).at(-1)}function O0(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var k0=(e,t,n)=>Math.min(n,Math.max(t,e));function A0(){let e=(0,m.useRef)(null),t=(0,m.useId)(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(0),[c,l]=(0,m.useState)(0),[u,d]=(0,m.useState)(1),[f,p]=(0,m.useState)(!1),[h,g]=(0,m.useState)(1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(null),[x,S]=(0,m.useState)(!1),C=Number.isFinite(o)&&o>0,w=()=>{let t=e.current;t!==null&&(t.paused||t.ended?t.play()?.catch(()=>void 0):t.pause())},T=t=>{let n=e.current;if(n===null||!C)return;let r=k0(t,0,o);n.currentTime=r,a(r)},E=t=>T((e.current?.currentTime??i)+t),D=t=>{let n=e.current;if(n===null)return;let r=k0(Math.round(t*100)/100,0,1);n.volume=r,n.muted=r===0,d(r),p(r===0)},O=()=>{let t=e.current;t!==null&&(t.muted=!t.muted,p(t.muted))};return{media:e,menuId:t,playing:n,current:i,duration:o,buffered:c,known:C,volume:u,muted:f,rate:h,menu:_,setMenu:v,hover:y,setHover:b,seeking:x,setSeeking:S,toggle:w,seekTo:T,jump:E,setLevel:D,toggleMute:O,pickRate:n=>{let r=e.current;r!==null&&(r.playbackRate=n),g(n),v(!1),document.getElementById(`${t}-button`)?.focus()},keyAction:e=>{let t=e.length===1?e.toLowerCase():e;if(t===` `||t===`k`)return w;if(t===`j`)return()=>E(-10);if(t===`l`)return()=>E(10);if(t===`ArrowLeft`)return()=>E(-5);if(t===`ArrowRight`)return()=>E(5);if(t===`m`)return O;if(/^[0-9]$/.test(t))return()=>T(Number(t)/10*o)},events:{onPlay:()=>r(!0),onPause:()=>r(!1),onEnded:()=>r(!1),onTimeUpdate:e=>{x||a(e.currentTarget.currentTime)},onDurationChange:e=>s(e.currentTarget.duration),onLoadedMetadata:e=>s(e.currentTarget.duration),onProgress:e=>{let t=e.currentTarget.buffered;l(t.length>0?t.end(t.length-1):0)},onVolumeChange:e=>{d(e.currentTarget.volume),p(e.currentTarget.muted)},onRateChange:e=>g(e.currentTarget.playbackRate)}}}function j0(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:k0((t-n.left)/n.width,0,1)}function M0(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function N0({controls:e,className:t}){return(0,h.jsx)(wy,{size:`small`,label:e.playing?`Pause`:`Play`,className:t,onClick:e.toggle,children:e.playing?(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})})}function P0({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:E0(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?E0(e.duration):`-:--`}`})]})}function F0({controls:e,chapters:t=[],waveform:n}){let r=(0,m.useRef)(null),{known:i,duration:a,current:o,buffered:s,seeking:c,hover:l}=e,u=Zde(r),d=n===void 0?void 0:Xde(n,u),f=i?t.filter(e=>e.start>0&&e.start<a):[],p=t=>{i&&(t.currentTarget.setPointerCapture?.(t.pointerId),e.setSeeking(!0),e.seekTo(j0(r.current,t.clientX)*a))},g=t=>{let n=j0(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{M0(t,{ArrowLeft:()=>e.jump(-5),ArrowDown:()=>e.jump(-5),ArrowRight:()=>e.jump(5),ArrowUp:()=>e.jump(5),PageDown:()=>e.jump(-10),PageUp:()=>e.jump(10),Home:()=>e.seekTo(0),End:()=>e.seekTo(a)}[t.key])},y=i?o/a*100:0,b=i?s/a*100:0,x=l===null||!i?void 0:l*a,S=x===void 0?void 0:Jde(t,x);return(0,h.jsxs)(`div`,{ref:r,role:`slider`,tabIndex:0,"aria-label":`Seek`,"aria-valuemin":0,"aria-valuemax":i?Math.floor(a):0,"aria-valuenow":Math.floor(o),"aria-valuetext":`${E0(o)} of ${i?E0(a):`unknown length`}`,"aria-disabled":!i,className:`sl-player__track`,onPointerDown:p,onPointerMove:g,onPointerUp:_,onPointerCancel:_,onPointerLeave:()=>e.setHover(null),onKeyDown:v,children:[d===void 0||d.length===0?(0,h.jsxs)(`span`,{className:`sl-player__rail`,children:[(0,h.jsx)(`span`,{className:`sl-player__buffered`,style:{width:`${String(b)}%`}}),(0,h.jsx)(`span`,{className:`sl-player__played`,style:{width:`${String(y)}%`}})]}):(0,h.jsx)(`span`,{className:`sl-player__wave`,"data-slot":`waveform`,"aria-hidden":`true`,children:d.map((e,t)=>(0,h.jsx)(`span`,{className:`sl-player__peak`,"data-played":(t+.5)/d.length*100<=y?``:void 0,style:{height:`${String(Math.max(12,Math.round(e*100)))}%`}},t))}),f.map(e=>(0,h.jsx)(`span`,{className:`sl-player__mark`,"data-chapter":e.title,title:e.title,style:{left:`${String(e.start/a*100)}%`}},`${String(e.start)}-${e.title}`)),(0,h.jsx)(`span`,{className:`sl-player__knob`,style:{left:`${String(y)}%`}}),x===void 0||l===null?null:(0,h.jsxs)(`span`,{className:`sl-player__tip`,"aria-hidden":`true`,style:{left:`${String(l*100)}%`},children:[S===void 0?null:(0,h.jsx)(`span`,{className:`sl-player__tip-title`,children:S.title}),E0(x)]})]})}function I0({controls:e}){let t=(0,m.useRef)(null),{muted:n,volume:r}=e,i=n?0:r;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wy,{size:`small`,label:n?`Unmute`:`Mute`,"aria-pressed":n,className:`sl-player__mute`,onClick:e.toggleMute,children:n||r===0?(0,h.jsx)(Wc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(`div`,{ref:t,role:`slider`,tabIndex:0,"aria-label":`Volume`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(i*100),"aria-valuetext":n?`Muted`:`${String(Math.round(i*100))}%`,className:`sl-player__volume`,onPointerDown:n=>{n.currentTarget.setPointerCapture?.(n.pointerId),e.setLevel(j0(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel(j0(t.current,n.clientX))},onKeyDown:t=>{let n={ArrowLeft:i-.05,ArrowDown:i-.05,ArrowRight:i+.05,ArrowUp:i+.05,Home:0,End:1}[t.key];M0(t,n===void 0?void 0:()=>e.setLevel(n))},children:(0,h.jsx)(`span`,{className:`sl-player__rail`,children:(0,h.jsx)(`span`,{className:`sl-player__played`,style:{width:`${String(i*100)}%`}})})})]})}function L0({controls:e}){let{menuId:t,menu:n,rate:r}=e;return(0,h.jsxs)(`span`,{className:`sl-player__speed`,children:[(0,h.jsx)(R,{id:`${t}-button`,variant:`quiet`,size:`small`,className:`sl-player__rate`,"aria-label":`Playback speed, ${D0(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:D0(r)}),n?(0,h.jsx)(`div`,{id:`${t}-menu`,role:`menu`,"aria-label":`Playback speed`,className:`sl-player__menu`,onKeyDown:n=>{if(n.key===`Escape`){M0(n,()=>{e.setMenu(!1),document.getElementById(`${t}-button`)?.focus()});return}if(n.key!==`ArrowDown`&&n.key!==`ArrowUp`)return;let r=[...n.currentTarget.querySelectorAll(`[role=menuitemradio]`)],i=r[(r.indexOf(document.activeElement)+(n.key===`ArrowDown`?1:-1)+r.length)%r.length];M0(n,()=>i?.focus())},children:qde.map(t=>(0,h.jsx)(R,{variant:`quiet`,size:`small`,role:`menuitemradio`,"aria-checked":t===r,className:L(`sl-player__option`),autoFocus:t===r,onClick:()=>e.pickRate(t),children:t===1?`Normal`:D0(t)},t))}):null]})}var Yde=4;function Xde(e,t){let n=Math.floor(t/Yde);if(n<=0||e.length<=n)return e;let r=[];for(let t=0;t<n;t+=1){let i=Math.floor(t*e.length/n),a=Math.max(i+1,Math.floor((t+1)*e.length/n));r.push(Math.max(...e.slice(i,a)))}return r}function Zde(e){let[t,n]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let t=e.current;if(t===null||(n(t.clientWidth),typeof ResizeObserver>`u`))return;let r=new ResizeObserver(()=>n(t.clientWidth));return r.observe(t),()=>r.disconnect()},[e]),t}var Qde=2500;function R0({src:e,poster:t,label:n,portrait:r=!1,captions:i,chapters:a=[],ref:o,className:s,children:c}){let l=A0(),u=l.media,d=(0,m.useRef)(null),f=(0,m.useRef)(void 0),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(0),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),[T,E]=(0,m.useState)(!1),[D,O]=(0,m.useState)(!0),{playing:k,menu:A,seeking:ee,hover:te,events:ne}=l,j=i!==void 0||y>0,re=typeof document<`u`&&`pictureInPictureEnabled`in document&&document.pictureInPictureEnabled===!0,M=(0,m.useCallback)(()=>{O(!0),clearTimeout(f.current),f.current=setTimeout(()=>O(!1),Qde)},[]);(0,m.useEffect)(()=>()=>clearTimeout(f.current),[]);let ie=k&&!D&&!A&&!T&&!ee&&te===null;(0,m.useEffect)(()=>{let e=()=>S(document.fullscreenElement===d.current);return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,m.useEffect)(()=>{let e=u.current;if(e===null)return;let t=()=>w(!0),n=()=>w(!1);return e.addEventListener(`enterpictureinpicture`,t),e.addEventListener(`leavepictureinpicture`,n),()=>{e.removeEventListener(`enterpictureinpicture`,t),e.removeEventListener(`leavepictureinpicture`,n)}},[u]),(0,m.useEffect)(()=>{let e=u.current?.textTracks;if(e!==void 0)for(let t=0;t<e.length;t+=1){let n=e[t];n!==void 0&&(n.mode=_&&t===0?`showing`:`hidden`)}},[_,u]);let ae=()=>{let e=u.current;e!==null&&(e.paused||e.ended)&&g(!0),l.toggle()},oe=()=>{let e=d.current;e!==null&&(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()?.catch(()=>void 0))},se=()=>{let e=u.current;e!==null&&(document.pictureInPictureElement===e?document.exitPictureInPicture?.().catch(()=>void 0):e.requestPictureInPicture?.().catch(()=>void 0))};return(0,h.jsxs)(`div`,{ref:d,"data-slot":`player`,"data-state":k?`playing`:`paused`,className:L(`sl-player`,r&&`sl-player--portrait`,ie&&`sl-player--bare`,x&&`sl-player--full`,s),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target.closest(`button`)!==null,n=e.key.length===1?e.key.toLowerCase():e.key,r=n===` `&&t?void 0:n===` `||n===`k`?ae:n===`f`?oe:n===`c`?j?()=>v(e=>!e):void 0:l.keyAction(n);r!==void 0&&(e.preventDefault(),e.stopPropagation(),M(),r())},onPointerMove:M,onPointerDown:M,onFocus:()=>E(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(E(!1),l.setMenu(!1))},children:[(0,h.jsxs)(`video`,{ref:O0(u,o),src:e,poster:t,preload:`metadata`,playsInline:!0,"aria-label":n,onClick:ae,...ne,onPlay:e=>{ne.onPlay(e),g(!0),M()},onPause:e=>{ne.onPause(e),O(!0)},onEnded:e=>{ne.onEnded(e),O(!0)},onLoadedMetadata:e=>{ne.onLoadedMetadata(e),b(e.currentTarget.textTracks?.length??0)},children:[i===void 0?null:(0,h.jsx)(`track`,{kind:`captions`,src:i.src,srcLang:i.lang,label:i.label}),c]}),p?null:(0,h.jsx)(wy,{label:`Play ${n}`,className:`sl-player__big`,onClick:ae,children:(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsxs)(`div`,{className:`sl-player__bar`,role:`group`,"aria-label":`${n} controls`,children:[(0,h.jsx)(N0,{controls:{...l,toggle:ae}}),(0,h.jsx)(P0,{controls:l}),(0,h.jsx)(F0,{controls:l,chapters:a}),(0,h.jsx)(I0,{controls:l}),(0,h.jsx)(L0,{controls:l}),j?(0,h.jsx)(wy,{size:`small`,label:`Captions`,"aria-pressed":_,onClick:()=>v(e=>!e),children:(0,h.jsx)(cc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,re?(0,h.jsx)(wy,{size:`small`,label:`Picture in picture`,"aria-pressed":C,className:`sl-player__pip`,onClick:se,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(wy,{size:`small`,label:x?`Exit full screen`:`Full screen`,"aria-pressed":x,onClick:oe,children:x?(0,h.jsx)(Oc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Dc,{"aria-hidden":`true`,strokeWidth:1.75})})]})]})}var $de={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function z0({src:e,alt:t,kind:n=`image`,poster:r,aspect:i=`landscape`,title:a,meta:o,badge:s,actions:c,actionsShown:l=!1,generating:u,onOpen:d,openLabel:f,className:p}){let m=u==null||u===!1;return(0,h.jsxs)(`figure`,{className:L(`sl-media m-0`,p),"data-slot":`media-frame`,children:[(0,h.jsxs)(`div`,{className:L(`sl-media__frame`,$de[i]),children:[m&&e!==void 0?n===`video`?(0,h.jsx)(`video`,{src:e,poster:r,muted:!0,preload:`metadata`,"aria-label":t}):(0,h.jsx)(`img`,{src:e,alt:t,loading:`lazy`,decoding:`async`}):null,m?null:(0,h.jsxs)(`div`,{className:`sl-media__generating`,role:`status`,children:[(0,h.jsx)(gS,{tone:`running`}),(0,h.jsx)(`span`,{children:u})]}),s===void 0?null:(0,h.jsx)(`span`,{className:`sl-media__badge`,children:s}),c===void 0?null:(0,h.jsx)(`div`,{className:L(`sl-media__actions`,l&&`sl-media__actions--shown`),children:c})]}),d!==void 0&&m&&e!==void 0?(0,h.jsx)(`button`,{type:`button`,className:`sl-media__open`,"aria-label":f??`Open ${t} full size`,onClick:d}):null,a===void 0&&o===void 0?null:(0,h.jsxs)(`figcaption`,{className:`sl-media__caption`,children:[a===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`strong`,{className:`min-w-0 truncate`,children:a}),o===void 0?null:(0,h.jsx)(`span`,{className:`shrink-0`,children:o})]})]})}function B0({shorts:e=!1,density:t=`default`,list:n=!1,className:r,children:i,label:a}){let o=L(`sl-grid`,e&&`sl-grid--shorts`,t===`compact`&&`sl-grid--compact`,n&&`m-0 list-none p-0`,r);return n?(0,h.jsx)(`ul`,{"aria-label":a,className:o,"data-slot":`media-grid`,children:i}):(0,h.jsx)(`section`,{"aria-label":a,className:o,"data-slot":`media-grid`,children:i})}function V0({items:e,index:t,onIndex:n,onClose:r,actions:i}){let a=t===null?void 0:e[t],o=e.length,s=e=>{t!==null&&o!==0&&n((t+e+o)%o)};return(0,h.jsx)(_m,{open:a!==void 0,onOpenChange:e=>{e||r()},children:(0,h.jsx)(xm,{children:(0,h.jsx)(Em,{className:`sl-lightbox sl-enter`,onKeyDown:e=>{e.key===`ArrowRight`?(e.preventDefault(),s(1)):e.key===`ArrowLeft`&&(e.preventDefault(),s(-1))},"aria-describedby":void 0,children:a===void 0||t===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`sl-lightbox__bar`,children:[(0,h.jsx)(jm,{className:`m-0 text-small font-semibold`,children:`${String(t+1)} of ${String(o)} · ${a.alt}`}),(0,h.jsxs)(`div`,{className:`sl-btn-row`,children:[i?.(a,t),(0,h.jsx)(wy,{label:`Previous`,onClick:()=>s(-1),disabled:o<2,children:(0,h.jsx)(dc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{label:`Next`,onClick:()=>s(1),disabled:o<2,children:(0,h.jsx)(fc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Fm,{asChild:!0,children:(0,h.jsx)(wy,{label:`Close`,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})})]})]}),(0,h.jsx)(`div`,{className:`sl-lightbox__stage`,children:a.kind===`video`?(0,h.jsx)(R0,{src:a.src,label:a.alt,className:`sl-lightbox__player`,...a.poster===void 0?{}:{poster:a.poster}},a.src):(0,h.jsx)(`img`,{src:a.src,alt:a.alt},a.src)}),a.caption===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`p`,{className:`sl-lightbox__caption`,children:a.caption})]})})})})}var H0={location:pO(`docker-host`),path:W().min(1)},U0=tO([q({opened:pO(!0)}).strict(),q({opened:pO(!0),...H0}).strict(),q({opened:pO(!1),...H0}).strict()]),W0=rO(`kind`,[q({kind:pO(`allAffected`)}).strict(),q({kind:pO(`selected`),workKeys:K(W().min(1).max(200)).min(1).max(1e4)}).strict()]),G0=W().min(1).max(64),efe=q({baseRevisionId:G0,request:W0}).strict(),tfe=q({baseRevisionId:G0,idempotencyKey:wD(),previewId:W().min(1).max(64),acknowledgeUnknownCosts:GD(),confirmedProvidedWorkKeys:K(W().min(1).max(200)).max(1e4)}).strict(),nfe=q({stage:W(),low:G().finite().nonnegative().nullable(),high:G().finite().nonnegative().nullable(),detail:W(),onPlan:GD().optional(),apiLow:G().finite().nonnegative().nullable().optional(),apiHigh:G().finite().nonnegative().nullable().optional()}),rfe=q({currency:pO(`USD`),rows:K(nfe),low:G().finite().nonnegative(),high:G().finite().nonnegative(),unknown:G().int().nonnegative(),apiLow:G().finite().nonnegative().optional(),apiHigh:G().finite().nonnegative().optional(),apiUnknown:G().int().nonnegative().optional(),expectedWords:G().finite().nonnegative(),catalogueDate:W().nullable(),assumptions:K(W())}),K0=q({revisionId:G0,admissionId:W().min(1).max(64),workIds:K(W().min(1).max(64)),replayed:GD()}),ife=q({id:W().min(1).max(64),projectId:W().min(1).max(64),baseRevisionId:G0,planFingerprint:W().min(1),selection:W0,changedInputs:K(q({path:W(),before:W().nullable(),after:W().nullable()})),work:K(q({key:W(),stage:J(FS),kind:J([`provider`,`local`,`provided`]),disposition:J([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:W(),fingerprint:W(),dependsOn:K(W()),reason:W(),inflight:GD(),pieceIds:K(W())})),retained:K(q({slot:W(),outputId:W(),assetId:W(),state:J([`ready`,`outdated`,`review`])})),providedReuseRequired:K(W()),costs:rfe,wholeRequestNotice:W().nullable(),warnings:K(W()),review:q({inputChanges:K(q({label:W(),before:W().nullable(),after:W().nullable()})),requests:K(q({key:W(),label:W(),text:W().nullable(),settings:W().nullable()}))}).optional()}),q0=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],J0=[`pending`,`running`,`done`,`failed`];q({id:W(),stage_id:W(),kind:J(q0),idx:G(),state:J(J0),payload:W().nullable()});var afe=`notes.article_md.article_txt.narration_txt.tts_script.sources.glossary.audio_body.audio_intro.audio_outro.audio_export.image.thumbnail.video.render_params.subtitles_srt.subtitles_vtt.subtitle_words.subtitle_ass.subtitle_font.instructions.document_pdf.youtube_description.youtube_tags.youtube_pinned_comment.youtube_titles.shorts.short_image.short_video.animated_image.figure_card.reference.script_md.audio_mp3.audio_m4b.audio_levelled`.split(`.`),ofe=[`copying`,`staged`],sfe=q({segment:J([`body`,`intro`,`outro`]).optional(),subtitleOmissions:K(q({start:G().finite().nonnegative(),text:W()})).optional(),subtitlesMode:J([`off`,`files`,`burn-in`]).optional(),promptName:W().optional(),prompt:W().optional(),index:G().optional(),short:G().optional(),format:J([`16:9`,`9:16`]).optional(),sentences:sO([G(),G()]).optional(),warnings:K(W()).optional(),provider:W().optional(),model:W().optional(),voice:W().optional(),loudness:q({pieces:G(),skipped:G(),spreadBefore:G(),spreadAfter:G(),target:G()}).optional(),master:q({target:G(),integrated:G(),truePeak:G()}).optional()}),cfe=q({id:W(),projectId:W(),stageKind:J(FS),role:J(afe),path:W(),originalFilename:W().nullable(),bytes:G().nonnegative(),durationMs:G().nonnegative().nullable(),meta:sfe,createdAt:W()});q({id:W(),stageKind:J(FS),path:W(),originalFilename:W(),bytes:G().nonnegative(),state:J(ofe),createdAt:W()});var Y0=W().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),X0=W().min(1).max(256),lfe=lO(X0,Y0),ufe=q({id:Y0,text:W().trim().min(1).max(1e4),start:G().finite().nonnegative(),end:G().finite().positive(),speaker:W().min(1).max(60).regex(/^[a-z0-9-]+$/).optional()}).strict().refine(e=>e.end>e.start,{path:[`end`],message:`The end time must be after the start time.`}),Z0=q({articleMarkdown:W().max(5e5).optional(),articleEdited:GD().default(!1),provided:q({research:Y0.optional(),article:Y0.optional(),audio:Y0.optional(),thumbnail:Y0.optional(),reference:Y0.optional()}).strict(),imageOrder:K(Y0).max(240),imageDefinitions:lO(Y0,q({source:J([`generate`,`provide`]),assetId:Y0.nullable(),prompt:W().max(5e5).nullable(),templateKey:W().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:lO(X0,rO(`kind`,[q({kind:pO(`asset`),assetId:Y0}).strict(),q({kind:pO(`text`),text:W().trim().min(1).max(5e5),direction:W().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:lO(X0,q({text:W().min(1).max(5e5),start:G().int().nonnegative().max(5e5),bodyFingerprint:W().regex(/^[0-9a-f]{64}$/u),chunkingFingerprint:W().regex(/^[0-9a-f]{64}$/u)}).strict()).refine(e=>Object.keys(e).length<=1e4&&Object.values(e).reduce((e,t)=>e+t.text.length,0)<=5e5,`Narration source bindings exceed the article limit.`).optional(),subtitleCues:q({audioFingerprint:W().min(1),cues:K(ufe)}).strict().optional(),regenerationTokens:lfe,promptTemplates:lO(W().min(1),W().max(5e5).nullable()),shortsMusic:Y0.optional(),shortsRanges:lO(W().regex(/^[1-9]\d?$/u),q({first:G().int().positive(),last:G().int().positive(),pick:W().min(1).max(128)}).strict()).optional(),ambientBed:Y0.optional()}).strict(),dfe=q({baseRevisionId:Y0,idempotencyKey:Y0,edit:q({config:xM.strict(),content:Z0,regenerate:K(X0).optional(),uploads:K(q({stagedFileId:Y0,destination:rO(`kind`,[q({kind:pO(`provided`),stage:J([`audio`,`thumbnail`,`reference`])}).strict(),q({kind:pO(`image`),imageKey:Y0}).strict(),q({kind:pO(`narration`),key:X0}).strict(),q({kind:pO(`shortsMusic`)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),ffe=q({baseRevisionId:Y0,idempotencyKey:Y0,targetRevisionId:Y0}).strict(),pfe=q({id:Y0,projectId:Y0,parentId:Y0.nullable(),restoredFromId:Y0.nullable(),config:xM,content:Z0,fingerprints:lO(X0,W()),createdAt:W()}),mfe=q({id:Y0,stageId:Y0,kind:J(q0),idx:G().int(),state:J(J0),payload:W().nullable()}),hfe=q({slot:W(),workKey:X0,assetId:Y0,output:cfe,fingerprint:W(),state:J([`ready`,`outdated`,`review`])}),gfe=q({key:X0,stageKind:J(FS),piece:mfe,assetId:Y0.nullable(),fingerprint:W()}),Q0={recordId:Y0,publicationId:Y0.nullable(),selected:GD(),available:GD()},$0=q({articleMarkdown:W().nullable(),revision:pfe,outputs:K(hfe.extend(Q0)),pieces:K(gfe.extend(Q0)),current:GD()}),_fe=q({id:Y0,parentId:Y0.nullable(),restoredFromId:Y0.nullable(),title:W(),createdAt:W(),current:GD()}),e2=q({ok:pO(!0),view:$0,duplicate:GD()}),vfe=q({ok:pO(!0),view:$0,created:GD()}),yfe=q({title:W(),status:G(),detail:W().optional(),reason:W().optional(),currentRevisionId:W().nullable().optional(),fields:K(q({field:W(),message:W()})).optional(),errors:K(q({path:W(),message:W()})).optional()});async function t2(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=yfe.safeParse(n);if(!r.success)throw po(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw po(e,{title:i.title,status:i.status,...i.detail===void 0?{}:{detail:i.detail},...i.fields===void 0?{}:{fields:i.fields}});return{ok:!1,reason:i.reason??`invalid-request`,message:i.detail??i.title,currentRevisionId:i.currentRevisionId??null,fields:i.fields??i.errors?.map(e=>({field:e.path,message:e.message}))??[]}}async function n2(e,t,n,r,i){return t2(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}${n}`,i===void 0?{method:`GET`}:{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}),r)}function r2(e,t){return n2(e,t,`/revisions/prepare`,vfe,{})}function i2(e,t,n){return n2(e,t,`/revisions`,e2,dfe.parse(n))}function bfe(e,t,n){return n2(e,t,`/revisions/restore`,e2,ffe.parse(n))}function xfe(e,t){return n2(e,t,`/revisions`,q({revisions:K(_fe)}))}function a2(e,t,n){return n2(e,t,`/revisions/${encodeURIComponent(n)}`,q({view:$0}))}var o2=K(W()).readonly();function Sfe(e,t,n){return n2(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,q({chunks:q({intro:o2.optional(),body:o2.optional(),outro:o2.optional()}).nullable()}))}function Cfe(e,t,n){return n2(e,t,`/rebuild/preview`,q({ok:pO(!0),value:ife}),efe.parse(n))}function wfe(e,t,n){return n2(e,t,`/rebuild`,q({ok:pO(!0),value:K0}),tfe.parse(n))}function s2(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function Tfe(e,t,n,r){let i=await t2(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),U0);if(!i.ok)throw Error(i.message);return i.value}function Efe(e,t,n){return s2(e,t,n,`images.zip`)}async function c2(e,{projectId:t,asset:n,folder:r=null}){if(r)return Tfe(e,t,r.revisionId,r.recordId);let i=await e.client.projects[`:id`][`open-folder`].$post({param:{id:t},json:{asset:n}});if(!i.ok)throw po(i,await mo(i));return U0.parse(await i.json())}var l2=`Slopify runs in Docker, which can't open windows on your desktop. Copy this path into your file manager. To have Open folder open it directly, run the Docker launcher again (npx @gentbajko/slopify@latest --docker) so it sets up the host helper.`;function u2(e){return(0,h.jsx)(Dfe,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function Dfe(e){let{api:t}=z(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(),[o,s]=(0,m.useState)();async function c(){r(!0),a(void 0),s(void 0);try{let n=await c2(t,e);n.opened||s(n.path)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Press Open folder to try again.`)}finally{r(!1)}}return(0,h.jsxs)(Sb,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(wb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`secondary`,size:e.size??`default`,disabled:n,onClick:()=>void c(),title:`Locate the saved output folder on the machine running Slopify`,children:[(0,h.jsx)(xc,{"aria-hidden":`true`,strokeWidth:1.75}),n?`Locating…`:o?`Locate folder`:`Open folder`]})}),(0,h.jsxs)(Eb,{className:`flex flex-col gap-2`,children:[o===void 0?null:(0,h.jsxs)(`div`,{role:`status`,className:`flex min-w-0 flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:l2}),(0,h.jsx)(`input`,{"aria-label":`Saved folder path`,readOnly:!0,value:o,onFocus:e=>e.currentTarget.select(),className:`sl-input w-full min-w-0 font-mono text-small`})]}),i===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i})]})]})}var Ofe={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function kfe(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function d2(){let{api:e}=z(),[t,n]=(0,m.useState)(kfe),r=`slopify-studio-${t}.zip`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(Ab,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:Ofe[e]}))}),(0,h.jsxs)(mS,{href:os(e,t),download:r,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download for ${t===`chrome`?`Chrome`:`Firefox`}`]})]}),(0,h.jsxs)(`ol`,{"aria-label":`Install steps`,className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:[t===`chrome`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`li`,{children:[`Press Download for Chrome, then unzip `,(0,h.jsx)(EV,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(EV,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(EV,{children:`edge://extensions`}),`), turn on Developer mode, press Load unpacked and pick that folder.`]})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`li`,{children:`Press Download for Firefox. It needs Firefox 128 or newer; keep the zip, you pick it in the next step.`}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(EV,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(EV,{children:r}),`. Firefox removes it when it restarts; load it again then.`]})]}),(0,h.jsx)(`li`,{children:`Pair it: press Copy beside the pairing token in Settings → YouTube Studio, click the Slopify extension's toolbar button, paste the token and press Pair.`})]})]})}var f2=[`studio`,`settings`];function Afe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Upload pack and extension`,info:`settings.studio.extension`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(jfe,{}),(0,h.jsx)(Nfe,{}),(0,h.jsxs)(`section`,{"aria-label":`Install the Studio extension`,children:[(0,h.jsx)(H,{as:`h3`,title:`Install the Studio extension`,className:`mb-3`}),(0,h.jsx)(d2,{})]})]})]})}var p2=``;function jfe(){let{api:e}=z(),t=_(),n=Oy(),r=(0,m.useId)(),i=N({queryKey:f2,queryFn:()=>rs(e)}),a=N(Zb(e)),o=(0,m.useId)(),[s,c]=(0,m.useState)(p2),[l,u]=(0,m.useState)(void 0),d=i.data?.playlists??[],f=s===p2?void 0:i.data?.channelPlaylists[s],p=l??(s===p2?d:f??[]),g=Mfe(p),v=P({mutationFn:t=>is(e,t,s===p2?void 0:s),onSuccess:()=>{u(void 0),t.invalidateQueries({queryKey:f2}),n(`Playlists saved.`,`success`)}}),y=e=>{v.reset(),u(e)},b=g??v.error?.message,x=[{value:p2,label:`Every channel (default)`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(xV,{label:`Playlists`,tip:`settings.studio.playlist`,help:s===p2?`The playlists upload packs offer, for every channel without its own. Ticked ones are on for every project; Prepare upload changes them for one project.`:f===void 0&&d.length>0?`This channel uses the default list (${(e=>e.map(e=>e.name).join(`, `))(d)}) until you add its own.`:`This channel's own playlists. Ticked ones are on for every project; Prepare upload changes them for one project.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(TV,{id:o,"aria-label":`Channel`,value:s,options:x,onChange:e=>{v.reset(),u(void 0),c(e.currentTarget.value)},className:`max-w-[260px]`}),p.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{autoComplete:`off`,"aria-label":`Playlist ${String(t+1)} name`,placeholder:`The playlist's name in Studio`,className:`min-w-0 flex-1 basis-[220px]`,value:e.name,disabled:i.data===void 0,"aria-invalid":e.name.trim().length>150,"aria-describedby":b===void 0?void 0:r,onChange:e=>y(p.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,h.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.byDefault,onChange:e=>{let n=e.currentTarget.checked;y(p.map((e,r)=>r===t?{...e,byDefault:n}:e))}}),`On by default`]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name.trim()||`playlist ${String(t+1)}`}`,onClick:()=>y(p.filter((e,n)=>n!==t)),children:`Remove`})]},t)),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(R,{variant:`secondary`,disabled:i.data===void 0||p.length>=20,onClick:()=>y([...p,{name:``,byDefault:p.length===0}]),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add playlist`]}),(0,h.jsx)(R,{variant:`primary`,disabled:v.isPending||l===void 0||g!==void 0,onClick:()=>v.mutate(p),children:`Save playlists`})]})]}),b===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:b})]})}function Mfe(e){if(e.find(e=>e.name.trim().length>150)!==void 0)return`A playlist name is longer than YouTube allows (150 characters). Shorten it.`;let t=new Set;for(let n of e){let e=n.name.trim().toLowerCase();if(e!==``){if(t.has(e))return`"${n.name.trim()}" is listed twice. Remove one.`;t.add(e)}}}function Nfe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:f2,queryFn:()=>rs(e)}),i=P({mutationFn:()=>ls(e),onSuccess:()=>{t.invalidateQueries({queryKey:f2}),n(`New pairing token made. Pair the extension again with it.`,`success`)}}),a=r.data?.pairing;return(0,h.jsxs)(`div`,{className:`sl-field`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Extension pairing token`}),(0,h.jsx)(V,{id:`settings.studio.pairing`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`code`,{className:`sl-code min-w-0 flex-1 basis-[220px] truncate py-2 select-all`,children:a?.token??`…`}),(0,h.jsxs)(R,{variant:`quiet`,disabled:a===void 0,onClick:()=>{if(a!==void 0){if(!navigator.clipboard){n(`Couldn't copy the token. Select it and copy it.`,`error`);return}navigator.clipboard.writeText(a.token).then(()=>n(`Pairing token copied. Paste it into the extension's options.`,`success`),()=>n(`Couldn't copy the token. Select it and copy it.`,`error`))}},children:[(0,h.jsx)(gc,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}),`Copy`]}),(0,h.jsx)(R,{variant:`quiet`,disabled:i.isPending||a===void 0,onClick:()=>i.mutate(),children:`New pairing token`})]}),(0,h.jsx)(`p`,{className:`sl-field__help m-0`,children:a?.origin==null?`No extension is paired. Paste this token into the Slopify Studio extension's options and press Pair.`:`Paired with the extension at ${a.origin}. A new token unpairs it.`}),i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.error.message})]})}var m2=[`studio`,`queue`];function h2({projectId:e,ready:t,variant:n=`secondary`,size:r=`default`}){let[i,a]=(0,m.useState)(!1);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:n,size:r,disabled:!t,disabledReason:`Available once the video has been made`,onClick:()=>a(!0),children:`Prepare upload`}),i?(0,h.jsx)(v2,{projectId:e,onClose:()=>a(!1)}):null]})}var g2={video:`Video file`,title:`Title`,description:`Description`,thumbnails:`Thumbnail`,playlist:`Playlist`,audience:`Audience`,altered:`AI use (under Show more)`,tags:`Tags (under Show more)`};function _2(e){return e.kind===`video`?`video`:`short-${String(e.short)}`}function v2({projectId:e,onClose:t}){let{api:n}=z(),r=_(),i=[`studio`,`pack`,e],a=N({queryKey:i,queryFn:()=>us(n,e)}),[o,s]=(0,m.useState)(`video`),[c,l]=(0,m.useState)(),u=a.data?.items??[],d=u.find(e=>_2(e)===o)??u[0],f=N({queryKey:f2,queryFn:()=>rs(n)}),p=f.data===void 0?void 0:f.data.pairing.origin!==null,g=N({queryKey:m2,queryFn:()=>ss(n)}),v=P({mutationFn:t=>fs(n,e,t.short),onSuccess:e=>{r.setQueryData(m2,e),l({text:e.length>1?`Added; ${String(e.length)} uploads are waiting. Studio is opening: each upload you start there is filled with the next one, in the order under Waiting for Studio. Check everything and publish yourself.`:`Studio is opening. Drop the video file into its upload dialog; the Slopify Studio extension fills in the details. Check everything and publish yourself.`,tone:`success`})},onError:e=>l({text:`Couldn't hand this to the extension: ${e.message}`,tone:`error`})}),y=P({mutationFn:e=>cs(n,e.projectId,e.short),onSuccess:e=>r.setQueryData(m2,e),onError:e=>l({text:`Couldn't remove it from Waiting for Studio: ${e.message} Press Remove again.`,tone:`error`})}),b=P({mutationFn:t=>ds(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved. The AI use answer is updated.`,tone:`success`})},onError:e=>l({text:`Couldn't save whether the clips are real footage: ${e.message} Press the switch again.`,tone:`error`})}),x=P({mutationFn:t=>as(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved this project's playlists.`,tone:`success`})},onError:e=>l({text:`Couldn't save the playlists: ${e.message} Tick the playlist again.`,tone:`error`})});return(0,h.jsxs)(YP,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(mS,{href:T0,target:`_blank`,rel:`noopener noreferrer`,variant:`secondary`,children:`Open YouTube Studio`}):null,(0,h.jsx)(R,{variant:`primary`,disabled:d===void 0||v.isPending||p!==!0,disabledReason:p===!1?`Install and pair the Slopify Studio extension first (steps above)`:f.error===null?`Wait for the upload pack to load`:`Couldn't check whether the extension is paired: ${f.error.message} Close Prepare upload and open it again.`,onClick:()=>{d!==void 0&&(window.open(T0,`_blank`,`noopener`),v.mutate(d))},children:`Fill in YouTube Studio`}),(0,h.jsx)(V,{id:`project.upload.fill-studio`})]}),children:[a.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The upload pack couldn't be read.`,children:`${a.error.message} Close Prepare upload and open it again.`}),a.data===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p===!1?(0,h.jsx)(SI,{tone:`waiting`,title:`The Slopify Studio extension isn't paired.`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Without it, the steps below are the upload pack: copy each into Studio's upload dialog. To have Studio filled in for you, install the extension:`}),(0,h.jsx)(d2,{})]})}):null,u.length>1?(0,h.jsx)(Ab,{label:`What to upload`,value:d===void 0?``:_2(d),onChange:s,tip:`project.upload.item`,options:u.map(e=>({value:_2(e),label:e.kind===`video`?`Video`:`Short ${String(e.short)}`})),className:`self-start`}):null,a.data.missing.length===0?null:(0,h.jsx)(SI,{tone:`waiting`,title:`Some of it isn't made yet.`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:a.data.missing.map(e=>(0,h.jsx)(`li`,{children:e},e))})}),d===void 0?null:(0,h.jsx)(Ffe,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(kb,{checked:b.isPending?b.variables:a.data.footage.real,disabled:b.isPending,onChange:e=>b.mutate(e),tip:`project.upload.real-footage`,label:`The ${a.data.footage.clips===1?`uploaded clip is`:`${String(a.data.footage.clips)} uploaded clips are`} real footage (filmed, not made by AI)`}):void 0,playlistPicker:a.data.playlistChoices.length>1?(0,h.jsx)(`span`,{className:`flex flex-col gap-1`,children:a.data.playlistChoices.map(e=>(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.chosen,disabled:x.isPending,onChange:t=>{let n=t.currentTarget.checked;x.mutate(a.data.playlistChoices.filter(t=>t.name===e.name?n:t.chosen).map(e=>e.name))}}),e.name]},e.name))}):void 0,copy:(e,t)=>{if(!navigator.clipboard){l({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>l({text:`Copied the ${t}.`,tone:`success`}),()=>l({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},doneKey:`slopify.upload.${e}.${_2(d)}`},_2(d)),(g.data??[]).length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Waiting for Studio`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:`Waiting for Studio`}),(0,h.jsx)(V,{id:`project.upload.queue`,className:`-my-1`})]}),(0,h.jsx)(pU,{label:`Waiting to be filled`,children:(g.data??[]).map((e,t)=>{let n=e.short===null?`Video`:`Short ${String(e.short)}`;return(0,h.jsx)(mU,{title:`${e.projectTitle} · ${n}`,meta:t===0?`Next: filled in the next upload dialog you open in Studio.`:`Filled after ${String(t)} more upload${t===1?``:`s`}.`,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:y.isPending,"aria-label":`Remove ${e.projectTitle} ${n.toLowerCase()} from Waiting for Studio`,onClick:()=>y.mutate(e),children:`Remove`})},`${e.projectId}-${String(e.short)}`)})})]}),(0,h.jsx)(SI,{title:`Slopify never publishes.`,children:p===!1?`Copy each step into Studio's upload dialog (Open YouTube Studio), check it and press Publish yourself.`:`Fill in YouTube Studio hands this to the Slopify Studio extension after you drop the video in. You check it and press Publish.`})]})]})}function Pfe(e){try{let t=JSON.parse(localStorage.getItem(e)??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function y2({href:e,filename:t}){return(0,h.jsxs)(mS,{href:e,download:t,"aria-label":`Download ${t}`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download`]})}function Ffe({projectId:e,item:t,footageSwitch:n,playlistPicker:r,copy:i,doneKey:a}){let{api:o}=z(),[s,c]=(0,m.useState)(()=>Pfe(a)),[l,u]=(0,m.useState)(null),d=e=>{c(e);try{localStorage.setItem(a,JSON.stringify(e))}catch{}},f=(e,t)=>d(t?[...s,e]:s.filter(t=>t!==e)),p=Gde.filter(e=>e!==`thumbnails`||t.kind===`video`),g=p.filter(e=>s.includes(e)).length,_=e=>{let n=b2(t,e);return(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:n===``,disabledReason:`Nothing to copy yet`,"aria-label":`Copy ${g2[e].toLowerCase()}`,onClick:()=>i(n,g2[e].toLowerCase()),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy`]})},v=a=>{switch(a){case`video`:return t.video===null?{value:(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not made yet.`})}:{value:t.video.filename,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(y2,{href:`${o.origin}${t.video.url}`,filename:t.video.filename}),(0,h.jsx)(u2,{projectId:e,asset:t.video.asset,size:`small`})]})};case`thumbnails`:return t.thumbnails.length===0?{value:(0,h.jsx)(`span`,{className:`text-ink-3`,children:`None made.`})}:{value:t.thumbnails.length>1?`The first under Thumbnail; all ${String(t.thumbnails.length)} in A/B Testing (beside the title).`:t.thumbnails[0]?.filename??``,actions:(0,h.jsx)(u2,{projectId:e,asset:t.thumbnails[0]?.asset??`thumbnail`,size:`small`})};case`audience`:return{value:`No, it's not made for kids`};case`altered`:return{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:t.alteredContent.altered?`Yes`:`No`}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:t.alteredContent.why}),n]})};case`description`:return{value:t.chapterNotice===void 0?b2(t,a)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}):(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:t.description}),(0,h.jsx)(`span`,{className:`text-waiting`,children:t.chapterNotice})]}),actions:_(a)};case`title`:return t.titles.length===0?{value:b2(t,a),actions:_(a)}:{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:t.title}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:`A/B Testing (beside the title): also ${t.titles.map(e=>`"${e}"`).join(` and `)}`})]}),actions:(0,h.jsxs)(h.Fragment,{children:[_(a),(0,h.jsxs)(R,{variant:`quiet`,size:`small`,"aria-label":`Copy the other titles`,onClick:()=>i(t.titles.join(`
271
271
  `),`other titles`),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy others`]})]})};case`playlist`:return{value:r??(t.playlists.length>0?t.playlists.join(`, `):(0,h.jsx)(`span`,{className:`text-ink-3`,children:`None set (Settings → YouTube Studio).`})),actions:_(a)};default:return{value:b2(t,a)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}),actions:_(a)}}};return(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`In the order Studio asks`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:`In the order Studio asks`}),(0,h.jsx)(V,{id:`project.upload.steps`,className:`-my-1`}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsxs)(`label`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:g===p.length,ref:e=>{e!==null&&(e.indeterminate=g>0&&g<p.length)},onChange:e=>d(e.currentTarget.checked?[...p]:[]),className:`size-4 shrink-0 accent-[var(--color-accent)]`}),`Select all`]})]}),(0,h.jsx)(pU,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:p.map(e=>{let{value:t,actions:n}=v(e);return(0,h.jsx)(mU,{className:`items-start`,lead:(0,h.jsx)(`input`,{type:`checkbox`,checked:s.includes(e),onChange:t=>f(e,t.currentTarget.checked),className:`mt-1 size-4 shrink-0 self-start accent-[var(--color-accent)]`,"aria-label":`${g2[e]} done`}),title:g2[e],meta:(0,h.jsx)(`span`,{className:`line-clamp-4 whitespace-pre-wrap break-words text-ink`,children:t}),actions:n},e)})})]}),t.thumbnails.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Thumbnails`,children:[(0,h.jsx)(H,{as:`h3`,kicker:`Thumbnails · A/B Testing`,title:`${String(t.thumbnails.length)} ${t.thumbnails.length===1?`thumbnail`:`thumbnails`}`,className:`mb-3`}),(0,h.jsx)(B0,{label:`Thumbnails to upload`,density:`compact`,children:t.thumbnails.map((e,t)=>(0,h.jsx)(z0,{src:`${o.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,title:String.fromCharCode(65+t),meta:e.filename,onOpen:()=>u(t),openLabel:`Open thumbnail ${String.fromCharCode(65+t)} full size`,actionsShown:!0,actions:(0,h.jsx)(y2,{href:`${o.origin}${e.url}`,filename:e.filename})},e.asset))}),(0,h.jsx)(V0,{items:t.thumbnails.map((e,t)=>({src:`${o.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,caption:e.filename})),index:l,onIndex:u,onClose:()=>u(null),actions:(e,n)=>{let r=t.thumbnails[n];return r===void 0?null:(0,h.jsx)(y2,{href:`${o.origin}${r.url}`,filename:r.filename})}})]})]})}function b2(e,t){switch(t){case`title`:return e.title;case`description`:return e.description;case`tags`:return Kde(e.tags);case`playlist`:return e.playlists.join(`, `);default:return``}}var x2=4;function Ife(e){return e===`schedules`?`schedules`:`weeks`}var S2=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),C2=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),w2=new Intl.DateTimeFormat(void 0,{timeStyle:`short`}),T2=`slopify.calendar.view`;function Lfe(){try{return window.localStorage.getItem(T2)===`list`?`list`:`weeks`}catch{return`weeks`}}function Rfe({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=z(),a=_(),o=gx(),[s]=(0,m.useState)(()=>sU(new Date,x2)),[c,l]=(0,m.useState)(Lfe),[u,d]=(0,m.useState)(e??`weeks`),f=n===void 0?u:e??`weeks`,p=e=>{n===void 0?d(e):n(e)},[g,v]=(0,m.useState)(!1),y=N(KH(i,s.from,s.to)),b=N(EH(i)),x=N(Hq(i)),S=N(Yy(i)),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),D=(0,m.useMemo)(()=>new Map((x.data??[]).map(e=>[e.id,e.channelId])),[x.data]),O=(0,m.useMemo)(()=>new Map((S.data?.projects??[]).map(e=>[e.id,e.channelId])),[S.data]),k=(b.data??[]).filter(e=>o.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>o.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>o.includes(O.get(e.id)))},ee=(0,m.useMemo)(()=>A===void 0?new Map:oU(A),[A]),te=A?.runs??[],ne=tU(A?.projects??[]),j=P({mutationFn:e=>e(),onSuccess:e=>w(e.ok?{tone:`info`,text:`Moved.`}:{tone:`error`,text:e.message}),onError:e=>w({tone:`error`,text:`The topic wasn't moved: ${e.message} Reload the calendar and try again.`}),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:GH}),a.invalidateQueries({queryKey:TH})])}}),re=e=>{if(e.kind!==`none`){if(e.kind===`refused`){w({tone:`error`,text:e.message});return}e.kind===`move`?j.mutate(()=>HH(i,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to})):j.mutate(()=>WH(i,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}}))}},M=(e,t)=>{let n=lU(te,e,t);if(n===void 0){w({tone:`error`,text:t===-1?`${uU(e)} is already the next topic of ${e.scheduleName}.`:`${uU(e)} is the last topic on the calendar for ${e.scheduleName}.`});return}re(cU(e,n,C2.format(new Date(n.at))))},ie=e=>{l(e),f!==`weeks`&&p(`weeks`);try{window.localStorage.setItem(T2,e)}catch{}};bx({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),bx({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>p(`schedules`)}),Yx(Wx.addToCalendar,()=>v(!0)),bx({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>ie(`weeks`)}),bx({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>ie(`list`)});let ae=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),oe=C?.text??y.error?.message??b.error?.message,se=rU(new Date),ce=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(kq,{title:`Calendar`,meta:`${o.channel?.name??`Every channel`} · ${String(te.length)} scheduled ${te.length===1?`run`:`runs`} in the next ${String(x2)} weeks · ${String(ae)} ${ae===1?`topic`:`topics`} queued`,actions:f===`schedules`?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Ab,{label:`Calendar view`,tip:`planning.calendar.view`,value:c,onChange:ie,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(R,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]})}),(0,h.jsx)(r0,{items:[{id:`weeks`,label:`Coming weeks`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ce)}}],value:f,onChange:p,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(i0,{idPrefix:`calendar`,id:`schedules`,active:f===`schedules`,children:f===`schedules`?(0,h.jsx)(zde,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(i0,{idPrefix:`calendar`,id:`weeks`,active:f===`weeks`,children:[(0,h.jsx)(Q1,{tone:C?.tone===`info`?`info`:oe?`error`:`info`,className:`mb-3`,children:oe}),(0,h.jsxs)(e0,{split:`aside`,className:`mb-6`,children:[(0,h.jsx)(t0,{label:`Needs you`,children:ne.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Nothing needs you right now.`}):(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(H,{title:`Needs you`,meta:eU(ne)}),(0,h.jsx)(pU,{label:`Needs you`,children:ne.map(e=>(0,h.jsx)(O2,{project:e},e.id))})]})}),(0,h.jsx)(t0,{as:`aside`,label:`Suggested topics`,children:(0,h.jsx)(vde,{schedules:k})})]}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[y.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the calendar…`}):c===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic to another day to change when it runs, or onto another schedule's run to move it there. With the keyboard: focus a topic and press Alt+← or Alt+→.`}),aU(new Date(s.from),x2).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=rU(e),n=ee.get(t);return(0,h.jsx)(zfe,{date:e,today:t===se,day:n,dragging:T,busy:j.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(re(cU(T,t,C2.format(e))),E(null))},onStep:M},t)})},rU(e[0]??new Date)))]}):(0,h.jsx)(Vfe,{days:ee,busy:j.isPending,onStep:M,schedules:k,onTransfer:(e,t)=>{e.index!==null&&re({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0})}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(H,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(pU,{label:`Batch queue`,children:A.queued.toSorted((e,t)=>e.position-t.position).map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsx)(_S,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`})},e.projectId)})})]}):null]})]}),(0,h.jsx)(JH,{open:g,onOpenChange:v,schedules:k})]})}function zfe({date:e,today:t,day:n,dragging:r,busy:i,onDragStart:a,onDragEnd:o,onDrop:s,onStep:c}){let[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(!1),p=n?.runs??[],g=n?.projects??[],_=d?g:g.slice(0,E2),v=()=>p.find(e=>e.scheduleId===r?.scheduleId)??p[0];return(0,h.jsxs)(`section`,{"aria-label":C2.format(e),className:L(`sl-cal-day`,t&&`sl-cal-day--today`,l&&`sl-cal-day--over`),onDragOver:e=>{r!==null&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,u(!0))},onDragLeave:()=>u(!1),onDrop:e=>{e.preventDefault(),u(!1),s(v())},children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:t?`Today · ${S2.format(e)}`:S2.format(e)}),p.map(e=>(0,h.jsx)(Bfe,{run:e,busy:i,onDragStart:a,onDragEnd:o,onDrop:t=>{t.preventDefault(),t.stopPropagation(),u(!1),s(e)},onStep:c},`${e.scheduleId}-${e.at}`)),_.map(e=>{let t=$H(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${dU}`,children:[(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${fU}`,children:e.title}),(0,h.jsx)(_S,{tone:t.tone,children:t.word})]},e.id)}),g.length>E2?(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":d,className:`self-start`,onClick:()=>f(e=>!e),children:d?`Show fewer`:`+${String(g.length-E2)} more`}):null]})}var E2=3;function Bfe({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=uU(e);return(0,h.jsxs)(`article`,{tabIndex:e.index===null?void 0:0,"aria-label":`${s}, ${w2.format(new Date(e.at))}, ${e.scheduleName}${e.index===null?``:`. Alt+arrow keys move it.`}`,draggable:o,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,s),n(e)},onDragEnd:r,onDragOver:e=>e.preventDefault(),onDrop:i,onKeyDown:t=>{o&&t.altKey&&(t.key===`ArrowLeft`||t.key===`ArrowUp`?(t.preventDefault(),a(e,-1)):(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(t.preventDefault(),a(e,1)))},className:L(`sl-cal-item`,o&&`sl-cal-item--movable`),children:[(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:w2.format(new Date(e.at))}),(0,h.jsx)(`b`,{className:L(`text-small`,e.topic===null&&`font-normal text-ink-2`),children:s}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.scheduleName}),e.paused?(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(_S,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(_S,{tone:`off`,children:`Queued`}):(0,h.jsx)(_S,{tone:`info`,children:`Prepared`}),(0,h.jsx)(D2,{run:e,compact:!0})]})}function D2({run:e,compact:t=!1}){let{api:n}=z(),r=_(),[i,a]=(0,m.useState)(),o=P({mutationFn:async()=>{if(e.topic===null)throw Error(`This run has no topic to prepare yet.`);let t=await LH(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:GH}),r.invalidateQueries({queryKey:[`projects`]})},onError:e=>a(e.message)});return e.prepared===null?e.index===null||e.topic===null||e.topicSource!==`queued`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,variant:t?`quiet`:`secondary`,disabled:o.isPending,onClick:e=>{e.stopPropagation(),o.mutate()},children:o.isPending?`Preparing…`:`Prepare`}),i===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-label text-danger`,children:i})]}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}function O2({project:e}){let t=$H(e);return(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(_S,{tone:t.tone,children:t.word}),t.action===void 0?null:t.action.kind===`upload`?(0,h.jsx)(h2,{projectId:e.id,ready:!0}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function Vfe({days:e,busy:t,schedules:n,onStep:r,onTransfer:i}){let a=[...e.values()].sort((e,t)=>e.key.localeCompare(t.key));if(a.length===0)return(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Nothing is planned for the next `,x2,` weeks. Add topics with Add to calendar, or create a schedule on the`,` `,(0,h.jsx)(ha,{to:`/calendar`,search:{tab:`schedules`},children:`Schedules`}),` `,`tab.`]});let o=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,...Ob,children:[(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Move a topic earlier, later or to another schedule from its row.`,(0,h.jsx)(V,{id:`planning.calendar.move`,className:`-my-1`})]}),a.map(e=>(0,h.jsxs)(`section`,{"aria-label":C2.format(e.date),children:[(0,h.jsx)(H,{title:C2.format(e.date),as:`h3`}),(0,h.jsxs)(pU,{label:`Planned on ${C2.format(e.date)}`,children:[e.runs.map(e=>{let n=uU(e),a=o.filter(t=>t.id!==e.scheduleId);return(0,h.jsx)(mU,{title:n,meta:`${w2.format(new Date(e.at))} · ${e.scheduleName}${e.templateName===null?``:` · ${e.templateName}`}${e.paused?` · Paused`:``}`,actions:e.index===null?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(D2,{run:e}),(0,h.jsx)(wy,{size:`small`,label:`Move ${n} earlier`,disabled:t,onClick:()=>r(e,-1),children:(0,h.jsx)(ic,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Move ${n} later`,disabled:t,onClick:()=>r(e,1),children:(0,h.jsx)(tc,{"aria-hidden":`true`,strokeWidth:1.75})}),a.length===0?null:(0,h.jsxs)(`select`,{"aria-label":`Move ${n} to another schedule`,className:`sl-select h-8 w-auto text-small`,value:``,disabled:t,onChange:t=>{t.target.value!==``&&i(e,t.target.value)},children:[(0,h.jsx)(`option`,{value:``,children:`Move to…`}),a.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})},`${e.scheduleId}-${e.at}`)}),e.projects.map(e=>(0,h.jsx)(O2,{project:e},e.id))]})]},e.key))]})}var Hfe=wj.map(e=>({value:e,label:Tj[e]}));function Ufe({channel:e}){let{api:t}=z(),n=_(),r=Oy(),i=P({mutationFn:n=>lx(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${Tj[e.aiDisclosure]}.`,`success`),n.setQueryData(Jb(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:qb,exact:!0})}});return(0,h.jsxs)(`section`,{"aria-label":`YouTube AI disclosure`,className:`mb-6 max-w-3xl border-b border-line pb-5`,children:[(0,h.jsx)(xV,{label:`YouTube AI disclosure`,tip:`planning.channel.ai-disclosure`,help:`Mark voices in Settings → Voices and Image prompts in Library → Prompts.`,children:(0,h.jsx)(TV,{value:i.isPending?i.variables:e.aiDisclosure,options:Hfe,disabled:i.isPending,onChange:e=>{let t=wj.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(Q1,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}function k2({value:e,onChange:t,inherited:n,label:r=`Language`,error:i,disabled:a=!1,tip:o=`play.language`}){let s=e??n?.language;return(0,h.jsx)(xV,{label:r,tip:o,help:Wfe(s),error:i,children:(0,h.jsxs)(TV,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:zO.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,BO(n.language).name,`)`]}),RO.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function Wfe(e){let t=BO(e);if(t.code===`en`)return`Everything is written and timed in English.`;let n=`The article, narration, YouTube description and Shorts titles are written in ${t.name}; pick a voice that speaks it.`,r=VO(t.code);return r===void 0?`${n} Captions are timed word by word with a free 248 MB model, downloaded the first time a ${t.name} project makes captions.`:`${n} ${r}`}function Gfe({rows:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,h.jsxs)(`section`,{"aria-label":`Channel links`,...Ob,children:[(0,h.jsx)(H,{title:`Channel links`,meta:`Write a link's name in braces in a description, such as {{Patreon}}.`,info:`planning.links.named`}),e.length===0?(0,h.jsx)(`p`,{className:`m-0 border-y border-line py-4 text-ink-2`,children:`No channel links yet. Add one, then write its name in braces in a description.`}):(0,h.jsx)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:e.map((r,i)=>(0,h.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,1fr)] items-center gap-2 border-b border-line py-3 md:grid-cols-[220px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(CV,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})}),(0,h.jsx)(CV,{"aria-label":`Address of link ${String(i+1)}`,type:`url`,placeholder:`https://`,value:r.url,onChange:e=>n(i,{url:e.currentTarget.value})}),(0,h.jsxs)(R,{variant:`quiet`,size:`small`,className:`justify-self-start`,"aria-label":`Remove link ${String(i+1)}`,onClick:()=>t(e.filter((e,t)=>t!==i)),children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(R,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function Kfe(){return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsx)(H,{title:`Named links`,info:`planning.links.named`}),(0,h.jsx)(`p`,{className:`m-0 max-w-[60ch] text-ink-2`,children:`Each channel keeps its own links now, on its Brand tab under Channel links. Links saved here before fill the default channel's descriptions until you save its Brand tab.`}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsx)(fS,{to:`/channels/$channelId`,params:{channelId:Wb},children:`Open the default channel's links`})})]})}function A2({value:e,inherit:t,sources:n,offerNone:r,problem:i,file:a,fieldPrefix:o=`ambientBed`,onChange:s}){let c=e!==void 0&&e.source!==`none`,l={level:e?.level??String(eA.levelDb),fadeIn:e?.fadeIn??String(eA.fadeInSeconds),tail:e?.tail??String(eA.tailSeconds)},u=e=>{if(e===``)s(void 0);else if(e===`none`)s({source:`none`,...l});else{let t=n.find(t=>t===e);t!==void 0&&s({source:t,...l})}},d=(t,n,r,a)=>e===void 0||!c?null:(0,h.jsx)(xV,{label:n,help:r,tip:a,error:i(t),children:(0,h.jsx)(CV,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})})});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(xV,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(TV,{"data-play-field":`${o}.source`,value:e?.source??``,onChange:e=>u(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:t}),r?(0,h.jsx)(`option`,{value:`none`,children:`None`}):null,n.map(e=>(0,h.jsx)(`option`,{value:e,children:$k[e]},e))]})}),e?.source===`upload`?a:null,c?(0,h.jsxs)(`div`,{className:`contents`,children:[d(`level`,`Level (dB)`,`-40 to -6; 0 is about as loud as the voice.`,`project.ambient.level`),d(`fadeIn`,`Fade in (seconds)`,`0 to 30.`,`project.ambient.fade-in`),d(`tail`,`Tail after the narration (seconds)`,`0 to 30, fading out.`,`project.ambient.tail`)]}):null]})}function qfe({value:e,onChange:t}){let n=aA(e),r=n===void 0?[]:nA(n);return(0,h.jsx)(A2,{value:e,inherit:`Not set`,sources:Zk,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function Jfe(e){return e.ambientBed===void 0?void 0:iA(e.ambientBed)}function Yfe(e){let t=aA(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:nA(t).length>0}}var j2=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`];function Xfe(e){return Object.fromEntries(j2.map(t=>[t,e[t]??``]))}function Zfe({channel:e}){let{api:t}=z(),n=_(),r=Oy(),i=N({queryKey:sN,queryFn:()=>cN(t)}),a=N(rb(t)),o=N(ib(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(Xfe(e.brand)),[p,g]=(0,m.useState)(Jfe(e.brand)),v=Yfe(p),y=N({queryKey:B.channelLinks,queryFn:()=>ws(t),enabled:e.isDefault&&e.brand.links===void 0}),[b,x]=(0,m.useState)(),S=b??e.brand.links??y.data??[],C=b!==void 0||e.brand.links!==void 0||(y.data?.length??0)>0,w=P({mutationFn:()=>ex(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(j2.flatMap(e=>d[e].trim()===``?[]:[[e,d[e].trim()]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(Jb(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:qb}),n.invalidateQueries({queryKey:B.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),D=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),O=[...(o.data?.builtIns??[]).map(e=>({value:e.name,label:e.label})),...(o.data?.themes??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(`form`,{"aria-label":`Brand kit`,onSubmit:e=>{e.preventDefault(),w.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-5`,children:[(0,h.jsx)(xV,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(CV,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(xV,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules.`,children:(0,h.jsx)(wV,{rows:4,value:l,maxLength:1e4,onChange:e=>u(e.target.value)})}),(0,h.jsx)(H,{title:`Brand kit`,meta:`Fills what a template leaves at its default. Blank fields add nothing.`,info:`planning.channel.brand-kit`,className:`mt-2 border-t border-line pt-6`}),(0,h.jsx)(`section`,{"aria-label":`Language`,className:`max-w-md`,children:(0,h.jsx)(k2,{label:`Language of new projects`,tip:`planning.channel.language`,value:d.language===``?void 0:d.language,inherited:{label:`Not set`,language:void 0},onChange:e=>T(`language`)(e??``)})}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(M2,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:E,onPick:T(`captionFontId`)}),(0,h.jsx)(N2,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(N2,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`)})]}),(0,h.jsxs)(`section`,{"aria-label":`Chapter cards and end screen`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(M2,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:E,onPick:T(`titleFontId`)}),(0,h.jsx)(N2,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(xV,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(CV,{value:d.endScreenText,maxLength:200,placeholder:`Subscribe for more`,onChange:e=>T(`endScreenText`)(e.target.value)})})]}),(0,h.jsxs)(`section`,{"aria-label":`Intro, outro and document`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(M2,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:D(`intro`),onPick:T(`intro`)}),(0,h.jsx)(M2,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:D(`outro`),onPick:T(`outro`)}),(0,h.jsx)(M2,{label:`Document theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:O,onPick:T(`documentTheme`)})]}),(0,h.jsx)(qfe,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(Gfe,{rows:S,onChange:x})})]}),(0,h.jsx)($1,{status:(0,h.jsx)(Q1,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked,disabledReason:s.trim()===``?`Give the channel a name`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function M2({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(xV,{label:e,tip:t,children:(0,h.jsxs)(TV,{value:n,onChange:e=>i(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Not set`}),n!==``&&!r.some(e=>e.value===n)?(0,h.jsxs)(`option`,{value:n,children:[n,` (no longer in the library)`]}):null,r.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))]})})}function N2({label:e,tip:t,value:n,onChange:r}){let i=/^#[0-9a-fA-F]{6}$/.test(n);return(0,h.jsx)(xV,{label:e,tip:t,...n!==``&&!i?{error:`Write the colour as # and six hex digits.`}:{},children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-6 shrink-0 rounded-control border border-line-strong`,style:{background:i?n:`transparent`}}),(0,h.jsx)(CV,{value:n,placeholder:`#FFFFFF`,maxLength:7,onChange:e=>r(e.target.value)})]})})}function P2(e,t){return e.languages===void 0||e.languages.includes(BO(t).code)}function Qfe(e,t,n,r){return n?e:e.filter(e=>P2(e,t)||e.voiceId===r)}function $fe(e,t){if(e===void 0||P2(e,t))return;let n=BO(t).name,r=(e.languages??[]).map(e=>BO(e).code===e?BO(e).name:e);return`${e.name} is listed for ${r.join(`, `)}, not ${n}, so it may read the ${n} narration with the wrong accent. Pick a ${n} voice under Narration, or correct the voice's languages in Settings → Voices.`}function F2(e,t,n){let[r,i]=(0,m.useState)(!1),a=Qfe(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function I2({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=$fe(t,e);return n===0&&!r&&o===void 0?null:(0,h.jsxs)(`div`,{className:`col-span-full grid gap-1`,children:[n>0||r?(0,h.jsxs)(`span`,{className:`flex min-h-8 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:a,type:`checkbox`,checked:r,onChange:e=>i(e.target.checked)}),`Show all voices`,r?``:` (${String(n)} listed for other languages than ${BO(e).name})`]}),(0,h.jsx)(V,{id:`play.show-all-voices`})]}):null,o===void 0?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:o})]})}function epe({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=z(),o=_(),[s,c]=(0,m.useState)(t?.kind??`character`),[l,u]=(0,m.useState)(t?.name??``),[d,f]=(0,m.useState)(t?.aliases??[]),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(t?.description??``),[b,x]=(0,m.useState)(t?.voice),[S,C]=(0,m.useState)(t?.host===!0),w=()=>Promise.all([o.invalidateQueries({queryKey:Jb(e)}),o.invalidateQueries({queryKey:qb})]),T=P({mutationFn:async()=>{let n={kind:s,name:l.trim(),aliases:d,description:v,voice:b!==void 0&&b.provider!==``&&b.model!==``&&b.voice!==``?b:null,host:S};return t===void 0?nx(a,e,crypto.randomUUID(),n):rx(a,t.id,{...n,baseVersion:t.version})},onSuccess:async e=>{await w(),t===void 0&&i(e.id)}}),E=()=>{let e=p.trim();e===``||d.some(t=>t.toLowerCase()===e.toLowerCase())||(f([...d,e]),g(``))};return n?(0,h.jsxs)(`section`,{"aria-label":t===void 0?`Add to cast`:`Edit ${t.name}`,children:[(0,h.jsx)(H,{kicker:t===void 0?`New cast member`:Kb[t.kind],title:t===void 0?`Add to cast`:t.name,meta:t===void 0?`Name it first, then give it reference pictures.`:`Used whenever a title or an image brief names it or one of its aliases.`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:r,children:`Close`})}),t!==void 0&&!t.images.some(e=>e.state===`ready`)?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-waiting`,children:`No picture yet, so it is not sent with any image. Upload or generate one below.`}):null,(0,h.jsxs)(`form`,{id:`cast-member-form`,"aria-label":`Cast member`,className:`mt-4 flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),l.trim()!==``&&T.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(xV,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(TV,{value:s,onChange:e=>c(Gb.find(t=>t===e.target.value)??`character`),options:Gb.map(e=>({value:e,label:Kb[e]}))})}),(0,h.jsx)(xV,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(CV,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(xV,{label:`Aliases`,tip:`planning.cast.aliases`,help:`Press Enter to add each one.`,children:(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(CV,{value:p,maxLength:200,placeholder:`Another name, such as the Last Pharaoh`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,h.jsxs)(R,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add alias`]})]})}),d.length>0?(0,h.jsx)(`ul`,{"aria-label":`Aliases added`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:d.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(yS,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(xV,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(wV,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(npe,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(kb,{label:`One of the channel's hosts`,tip:`planning.cast.host`,checked:S,onChange:C}),S&&(b===void 0||b.voice===``)?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`A host joins new podcasts and interviews only with a voice. Pick one under Voice above.`}):null]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(Q1,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(R,{type:`submit`,form:`cast-member-form`,variant:t===void 0?`primary`:`secondary`,disabled:T.isPending||l.trim()===``,children:t===void 0?`Add to cast`:`Save`})]})]}),t===void 0?null:(0,h.jsx)(tpe,{channelId:e,member:t})]}):null}function tpe({channelId:e,member:t}){let{api:n}=z(),r=_(),i=N(eb(n)),a=(0,m.useRef)(null),o=(0,m.useRef)(null),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(``),[d,f]=(0,m.useState)(`${t.name}${t.description.trim()?`, ${t.description.trim()}`:``}. A clear reference picture on a plain background, the whole ${t.kind===`place`?`place`:t.kind===`object`?`object`:`figure`} in view.`),p=()=>Promise.all([r.invalidateQueries({queryKey:Jb(e)}),r.invalidateQueries({queryKey:qb})]),g=P({mutationFn:e=>ax(n,t.id,e),onSettled:p}),v=P({mutationFn:()=>ox(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=P({mutationFn:e=>sx(n,t.id,e),onSettled:p}),b=g.error??v.error??y.error,x=t.images.flatMap((e,t)=>e.state===`ready`&&e.sha256!==null?[{id:e.id,number:t+1,src:ux(n,e.sha256)}]:[]),[S,C]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Reference pictures`,className:`mt-6`,children:[(0,h.jsx)(Mq,{className:`mb-6`}),(0,h.jsx)(H,{as:`h3`,title:`Reference pictures`,meta:`Sent with every image whose brief, or the video's title, names ${t.name}.`,info:`planning.cast.pictures`}),t.images.length>0?(0,h.jsx)(B0,{list:!0,density:`compact`,label:`Pictures of ${t.name}`,className:`mt-3`,children:t.images.map((e,r)=>(0,h.jsxs)(`li`,{className:`min-w-0`,children:[(0,h.jsx)(z0,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:ux(n,e.sha256)}:{},...e.state===`generating`?{generating:`Making the picture…`}:{},onOpen:()=>C(x.findIndex(t=>t.id===e.id)),openLabel:`Open picture ${String(r+1)} of ${t.name} full size`,...e.state===`failed`?{badge:(0,h.jsx)(vS,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Delete picture ${String(r+1)} of ${t.name}`,disabled:y.isPending||e.state===`generating`,disabledReason:`Wait until the picture is made`,onClick:()=>y.mutate(e.id),children:`Delete`})}),e.state===`failed`&&e.error?(0,h.jsx)(rpe,{error:e.error,retry:s===``||l===``||d.trim()===``?void 0:{run:()=>v.mutate(),busy:v.isPending},onReword:()=>o.current?.focus()}):null]},e.id))}):(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-3`,children:`No pictures yet.`}),(0,h.jsx)(V0,{items:x.map(e=>({src:e.src,alt:`${t.name}, reference ${String(e.number)}`})),index:S,onIndex:C,onClose:()=>C(null),actions:(e,n)=>{let r=x[n];return r===void 0?null:(0,h.jsx)(mS,{href:r.src,download:!0,size:`small`,"aria-label":`Download picture ${String(r.number)} of ${t.name}`,children:`Download`})}}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg`,className:`sr-only`,tabIndex:-1,"aria-hidden":`true`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&g.mutate(t)}}),(0,h.jsx)(R,{disabled:g.isPending,onClick:()=>a.current?.click(),children:`Upload a picture`}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`PNG or JPEG, up to 10 MB.`})]}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,...Ob,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(V,{id:`planning.cast.generate`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(RV,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(zV,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(xV,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,children:(0,h.jsx)(wV,{ref:o,rows:3,value:d,maxLength:4e3,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(R,{disabled:v.isPending||s===``||l===``||d.trim()===``,disabledReason:`Pick an image provider and model, and describe the picture`,onClick:()=>v.mutate(),children:`Generate a picture`})})]}),(0,h.jsx)(Q1,{tone:b?`error`:`info`,className:`mt-2`,children:b?.message??(g.isPending?`Uploading…`:v.isSuccess?`The picture is being made; it appears here when it is ready.`:void 0)})]})}function npe({channelId:e,value:t,onChange:n}){let{api:r}=z(),i=N(eb(r)),a=N(tb(r)),o=N(Qb(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=F2(c,o,s.voice||void 0),u=l.listed;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-3 border-0 border-t border-line p-0 pt-4`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(V,{id:`planning.cast.voice`,label:`Cast voice`,className:`-my-1`})]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`For multi-voice runs: pick this member under Speakers on Play.`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(RV,{label:`Voice provider`,family:`tts`,providers:i.data?.providers??[],value:s.provider,problem:void 0,onPick:e=>n(e===``?void 0:{provider:e,model:``,voice:``})}),(0,h.jsx)(zV,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(FV,{label:`Voice`,value:s.voice,placeholder:u.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:u.map(e=>({value:e.voiceId,label:e.name})),problem:void 0,onPick:e=>n({...s,voice:e})}),(0,h.jsx)(I2,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(FV,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:AA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:void 0,onPick:e=>{let{pace:t,...r}=s;n(Number(e)===1?r:{...r,pace:Number(e)})}})]}),t===void 0?null:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function rpe({error:e,retry:t,onReword:n}){let r=V1({stage:`images`,reason:e});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 mt-1 text-small text-danger`,children:e}),r===void 0?null:(0,h.jsx)(Ey,{className:`mt-2`,children:(0,h.jsx)(Y1,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(R,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}function ipe({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=z(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=P({mutationFn:e=>ix(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:Jb(e)}),a.invalidateQueries({queryKey:qb})])}}),p=t.find(e=>e.id===c),g=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:ux(i,t)}]:[]}),v=g.map(e=>({src:e.src,alt:e.member.name,caption:`${Kb[e.member.kind]} · ${e.member.description||`No description yet`}`})),[y,b]=(0,m.useState)(null),x=c===`new`||p!==void 0;return(0,h.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 min-[1024px]:grid-cols-[minmax(0,1fr)_440px]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:`When a video's title or an image's brief names a member, its pictures go with that image as references, so it looks the same in every video.`}),t.length===0?(0,h.jsx)(a0,{title:`No cast yet`,actions:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>l(`new`),children:`Add to cast`}),children:`Add the characters, creatures, places and objects this channel keeps coming back to.`}):(0,h.jsx)(B0,{label:`Cast`,children:t.map(e=>{let t=e.images.filter(e=>e.state===`ready`),n=t[0]?.sha256;return(0,h.jsx)(z0,{className:L(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...n?{src:ux(i,n)}:{},alt:e.name,onOpen:()=>b(g.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${Kb[e.kind]}${e.host===!0?` · Host`:``} · ${String(t.length)} ${t.length===1?`picture`:`pictures`}`,...t.length===0?{badge:(0,h.jsx)(vS,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`})]})},e.id)})}),(0,h.jsx)(V0,{items:v,index:y,onIndex:b,onClose:()=>b(null),actions:(e,t)=>{let n=g[t];return n===void 0?null:(0,h.jsx)(R,{size:`small`,onClick:()=>{b(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(Q1,{tone:`error`,className:`mt-2`,children:u?void 0:f.error?.message})]}),(0,h.jsx)(`aside`,{"aria-label":`Cast member editor`,className:`min-w-0`,children:x?(0,h.jsx)(epe,{channelId:e,member:p,open:!0,onClose:()=>l(null),onCreated:e=>l(e)},c??`closed`):t.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Pick a member's Edit to change its names, description and pictures here.`})}),(0,h.jsx)(jy,{open:u!==null,title:`Delete ${u?.name??`this cast member`}?`,consequence:f.error?.message??`New videos stop using its pictures. Videos already made keep the pictures they were started with.`,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var L2=e=>[`channels`,e,`episodes`],R2=e=>[`channels`,e,`videos`],z2=(e,t)=>`${e.origin}/api/channels/${t}`,B2=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function ape(e,t){return ct({queryKey:L2(t),queryFn:async()=>F(await e.fetch(`${z2(e,t)}/episodes`))})}async function ope(e,t,n){return F(await e.fetch(`${z2(e,t)}/episodes/setting`,B2(`PUT`,{enabled:n})))}async function spe(e,t,n,r){return F(await e.fetch(`${z2(e,t)}/episodes/${encodeURIComponent(n)}`,B2(`PUT`,{summary:r})))}async function cpe(e,t,n){let r=await e.fetch(`${z2(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await F(r)}function V2(e,t){return ct({queryKey:R2(t),queryFn:async()=>(await F(await e.fetch(`${z2(e,t)}/videos`))).videos})}async function lpe(e,t,n){return F(await e.fetch(`${z2(e,t)}/videos`,B2(`POST`,n)))}async function upe(e,t,n){return F(await e.fetch(`${z2(e,t)}/videos/preview`,B2(`POST`,{format:`csv`,text:n})))}async function dpe(e,t,n){let r=await e.fetch(`${z2(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await F(r)}async function fpe(e,t){await F(await e.fetch(`${z2(e,t)}/videos`,{method:`DELETE`}))}var ppe=e=>e.length>160?`${e.slice(0,160)}…`:e;function mpe({channelId:e}){let{api:t}=z(),n=_(),r=N(ape(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:L2(e)}),l=P({mutationFn:n=>ope(t,e,n),onSuccess:t=>n.setQueryData(L2(e),t)}),u=P({mutationFn:n=>cpe(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kb,{checked:d,disabled:r.data===void 0||l.isPending,onChange:e=>l.mutate(e),label:`Episode memory`,tip:`planning.channel.episode-memory`,describedBy:`${e}-memory-help`}),(0,h.jsx)(`p`,{id:`${e}-memory-help`,className:`mt-1 mb-3 text-small text-ink-2`,children:`Finished episodes leave a short summary that new related episodes are written with.`}),(0,h.jsx)(Q1,{tone:r.error||l.error||u.error?`error`:`info`,children:r.error?.message??l.error?.message??(o?void 0:u.error?.message)??(r.isPending?`Loading the episodes…`:void 0)}),r.data&&f.length===0?(0,h.jsx)(a0,{title:`No episodes remembered yet`,children:d?`When a video on this channel finishes, its summary appears here.`:`Turn on episode memory, and the next finished video's summary appears here.`}):null,f.length>0?(0,h.jsx)(pU,{label:`Episode summaries`,children:f.map(e=>(0,h.jsx)(mU,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,ppe(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(R,{size:`small`,variant:`quiet`,"aria-label":`Delete the summary of ${e.title}`,onClick:()=>{u.reset(),s(e)},children:`Delete`})]})},e.id))}):null,i?(0,h.jsx)(hpe,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(jy,{open:o!==null,title:`Delete the summary of ${o?.title??`this episode`}?`,consequence:u.error?.message??`New episodes stop being reminded of it. The video itself is not changed.`,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function hpe({channelId:e,memory:t,onClose:n}){let{api:r}=z(),i=_(),[a,o]=(0,m.useState)(t.summary),s=P({mutationFn:()=>spe(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:L2(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Ay,{open:!0,onOpenChange:e=>{e||n()},title:t.title,description:t.source===`edited`?`You edited this summary; finishing the video again keeps your text.`:`Written by the text model when the video finished. An edit here is kept.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{onClick:n,children:`Close`}),(0,h.jsx)(R,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(xV,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(wV,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}var H2=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function U2(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function gpe({channelId:e}){let{api:t}=z(),n=_(),r=N(V2(t,e)),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(void 0),u=(0,m.useRef)(null),d=()=>n.invalidateQueries({queryKey:R2(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=P({mutationFn:n=>lpe(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${H2(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=P({mutationFn:n=>upe(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:U2(e.titles,e.filter)})}}),x=P({mutationFn:n=>dpe(t,e,n),onSuccess:d}),S=P({mutationFn:()=>fpe(t,e),onSuccess:async()=>{s(!1),await d()}}),C=r.data??[],w=y.isPending||b.isPending||x.isPending||S.isPending,T=r.error??b.error??y.error??x.error;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`Topic suggestions and duplicate checks skip these titles, as they skip the videos made here.`}),(0,h.jsx)(xV,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(wV,{rows:5,value:i,onChange:e=>a(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:w||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(R,{disabled:w,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(V,{id:`planning.channel.videos-csv`}),(0,h.jsx)(`input`,{ref:u,type:`file`,accept:`.csv,text/csv`,className:`hidden`,"aria-label":`YouTube Studio CSV file`,onChange:async e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&(l(void 0),y.reset(),b.mutate(await t.text()))}}),(0,h.jsx)(R,{variant:`quiet`,disabled:w||C.length===0,onClick:()=>{S.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(Q1,{tone:T?`error`:c?`success`:`info`,className:`mt-1`,children:T?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(_pe,{preview:f,filter:g,busy:w,onFilter:e=>{v(e),p({...f,ticked:U2(f.titles,e)})},onTick:e=>p({...f,ticked:e}),onSave:()=>{l(void 0);let e=f.titles.filter((e,t)=>f.ticked[t]);y.mutate({text:e.join(`
272
- `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(a0,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(pU,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(mU,{title:e.title,actions:(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(jy,{open:o,title:`Remove all ${H2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function _pe({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...Ob,children:[(0,h.jsxs)(H,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${H2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(R,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,H2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(R,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(xV,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(CV,{value:t,maxLength:200,onChange:e=>r(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(pU,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(mU,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`],vpe={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`};function ype(e){return W2.find(t=>t===e)??`brand`}function bpe({channelId:e,tab:t,onTab:n}){let{api:r}=z(),i=_(),a=Zi(),o=N(Qb(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=P({mutationFn:()=>tx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:qb}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return bx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(ha,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(R,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(r0,{items:W2.map(e=>({id:e,label:vpe[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(Q1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(i0,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(Ufe,{channel:f}),(0,h.jsx)(Zfe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(ipe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(Sde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Tde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(mpe,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(gpe,{channelId:f.id}):null})]}):null,(0,h.jsx)(jy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function G2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:L(`sl-stats m-0`,e),children:t})}function K2({value:e,label:t,children:n}){return(0,h.jsxs)(`div`,{className:`sl-stat`,children:[(0,h.jsx)(`dt`,{className:`sl-stat__label order-2`,children:t}),(0,h.jsx)(`dd`,{className:`sl-stat__value order-1 m-0`,children:e}),n===void 0?null:(0,h.jsx)(`dd`,{className:`order-3 m-0 mt-1`,children:n})]})}function q2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:L(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function J2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:L(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}function xpe(){let{api:e}=z(),t=_(),n=Zi(),r=N(Zb(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=P({mutationFn:()=>$b(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:qb}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=P({mutationFn:t=>ex(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:qb}),a(null)}}),v=P({mutationFn:t=>tx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:qb})}}),y=()=>{p.reset(),l(``),a(`new`)};bx({id:`channels.new`,title:`New channel`,group:`Channels`,run:y});let b=i===`new`?p:g,x=()=>{c.trim()!==``&&i!==null&&(i===`new`?p.mutate():g.mutate(i))};return(0,h.jsxs)(`div`,{"data-tour":`channels`,children:[(0,h.jsx)(kq,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(V,{id:`planning.channels`})]}),actions:(0,h.jsxs)(R,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(Q1,{tone:r.error||v.error?`error`:`info`,className:`mb-2`,children:r.error?`The channels couldn't be loaded: ${r.error.message} Reload the page to try again.`:o===null&&v.error?v.error.message:r.isPending?`Loading channels…`:void 0}),r.data?.length===0?(0,h.jsx)(a0,{title:`No channels yet`,actions:(0,h.jsx)(R,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(jq,{list:(0,h.jsx)(pU,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(mU,{selected:e.id===f?.id,onSelect:()=>d(e.id),title:e.name,meta:`${e.isDefault?`Default · `:``}${String(e.templates)} ${e.templates===1?`template`:`templates`} · ${String(e.cast)} in the cast`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(pS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(Spe,{channel:f})}):null,(0,h.jsx)(Ay,{open:i!==null,onOpenChange:e=>{!e&&!b.isPending&&a(null)},title:i===`new`||i===null?`New channel`:`Rename ${i.name}`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(R,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(R,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(xV,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(CV,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(jy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function Spe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(H,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(fS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(G2,{className:`mb-6`,children:[(0,h.jsx)(K2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(K2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(H,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(H,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var Y2=2e3;function X2(e,t){let n=(0,m.useRef)(t);(0,m.useEffect)(()=>{n.current=t}),(0,m.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{n.current()},Y2);return()=>{clearTimeout(t)}},[e])}function Z2(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(lc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function Q2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Oy();bx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:lP.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(R,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(Q1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(Z2,{}):t)}),a,(0,h.jsx)(R,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Mx(lP.save),onClick:()=>{c||s()},children:`Save`})]})}var Cpe=`rounded-media border border-line bg-surface p-4`;function $2(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${Cpe} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var wpe=`modulepreload`,Tpe=function(e){return`/`+e},e4={},t4=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Tpe(t,n),t=s(t),t in e4)return;e4[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:wpe,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Epe({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return Dpe(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function Dpe(e,t){let n=await t4(()=>import(`./pdf-Dh7upqzO.js`),[]),r=await t4(()=>import(`./pdf.worker.min-zC6nfbxG.js`),[]);n.GlobalWorkerOptions.workerSrc=r.default;let i=n.getDocument({data:e.slice()}),a=await i.promise;try{let e=window.devicePixelRatio||1,n=[];for(let r=1;r<=a.numPages;r+=1){let i=await a.getPage(r),o=i.getViewport({scale:t*e/i.getViewport({scale:1}).width}),s=window.document.createElement(`canvas`);s.width=Math.floor(o.width),s.height=Math.floor(o.height),await i.render({canvas:s,viewport:o}).promise,n.push(s)}return n}finally{await i.destroy()}}var n4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),i4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),a4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),o4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),s4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),c4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),Ope=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},n4([`page`,`margin`],`Margins`),n4([`page`,`contentTop`],`Text starts at`,`From the top, on pages with the header.`),{kind:`choice`,path:[`background`,`image`],label:`Background`,options:[{value:`parchment`,label:`Parchment texture`},{value:null,label:`Flat colour`}]},{kind:`color`,path:[`background`,`color`],label:`Page colour`,help:`Used when the background is a flat colour.`}]},{title:`Colours`,fields:[{kind:`color`,path:[`colors`,`heading`],label:`Headings`,help:`Also drop caps, the brand name and links.`},{kind:`color`,path:[`colors`,`text`],label:`Body text`},{kind:`color`,path:[`colors`,`muted`],label:`Muted`,help:`Dates, bullets, quotes and the dots in the contents.`},{kind:`color`,path:[`colors`,`faint`],label:`Faint`,help:`Running header and page numbers.`}]},{title:`Fonts`,fields:[c4(`body`,`Body`),c4(`strong`,`Bold text`),c4(`emphasis`,`Italic text`),c4(`heading`,`Headings`),c4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),c4(`decorative`,`Tagline and title-page link`),c4(`dropCap`,`Drop caps`),c4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[r4([`sizes`,`title`],`Title`),r4([`sizes`,`brand`],`Brand`),r4([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),r4([`sizes`,`heading`],`Second-level headings`),r4([`sizes`,`subheading`],`Third-level headings`),r4([`sizes`,`body`],`Body`),r4([`sizes`,`meta`],`Date and word count`),r4([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[n4([`spacing`,`bodyLine`],`Body line height`),n4([`spacing`,`headingLine`],`Heading line height`),n4([`spacing`,`subheadingLine`],`Subheading line height`),i4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),i4([`spacing`,`headingGap`],`Before a heading`,`× line`),i4([`spacing`,`itemGap`],`After a list item`,`× line`),n4([`spacing`,`listIndent`],`List indent`),n4([`spacing`,`quoteIndent`],`Quote indent`),n4([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[a4([`dropCap`,`enabled`],`Drop caps`,`A large first letter after each heading.`),{kind:`choice`,path:[`dropCap`,`lines`],label:`Lines tall`,options:[{value:2,label:`2 lines`},{value:3,label:`3 lines`},{value:4,label:`4 lines`}]},i4([`dropCap`,`scale`],`Letter size`,`× lines`),n4([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},i4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[n4([`titlePage`,`brandY`],`Brand from top`),n4([`titlePage`,`taglineOffset`],`Tagline below brand`),n4([`titlePage`,`titleY`],`Title from top`),n4([`titlePage`,`titleLine`],`Title line height`),n4([`titlePage`,`metaOffset`],`Details below title`),n4([`titlePage`,`metaLine`],`Details line height`),a4([`titlePage`,`showDate`],`Show the date`),a4([`titlePage`,`showWordCount`],`Show the word count`),a4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),n4([`titlePage`,`cover`,`gap`],`Space around cover`),n4([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[s4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),s4([`brand`,`tagline`],`Tagline`),s4([`brand`,`url`],`Website`,`Where the brand and its link go.`),s4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[a4([`contents`,`enabled`],`Contents page`),o4([`contents`,`title`],`Title`),{kind:`choice`,path:[`contents`,`depth`],label:`Lists headings down to`,options:[{value:1,label:`Top level`},{value:2,label:`Second level`},{value:3,label:`Third level`}]},n4([`contents`,`titleOffset`],`Title from top margin`),n4([`contents`,`firstEntryOffset`],`First entry from top margin`),n4([`contents`,`line`],`Line height`),n4([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[a4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),n4([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},a4([`footer`,`enabled`],`Page numbers`),o4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),n4([`footer`,`bottom`],`From the bottom`),n4([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[a4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),o4([`sources`,`title`],`Title`),n4([`sources`,`titleOffset`],`Title from top margin`),n4([`sources`,`bodyOffset`],`List from top margin`),n4([`sources`,`line`],`Line height`),n4([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[a4([`endPage`,`enabled`],`Closing page`),o4([`endPage`,`title`],`Title`),{kind:`lines`,path:[`endPage`,`lines`],label:`Text`,help:`One line each. Start with "•" for a bullet, end with ":" for a bold label, leave a line empty for a gap.`},a4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},s4([`endPage`,`closing`],`Closing line`),n4([`endPage`,`titleOffset`],`Title from top margin`),n4([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[o4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),o4([`metadata`,`subject`],`Subject`),o4([`metadata`,`keywords`],`Keywords`),o4([`metadata`,`creator`],`Creator`)]}],l4=$j.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function u4(e){let t={normal:`Regular`,medium:`Medium`,bold:`Bold`,black:`Black`,italic:`Italic`,bolditalic:`Bold italic`};return(e===`Cinzel`?[`normal`,`medium`,`bold`,`black`]:[`normal`,`bold`,`italic`,`bolditalic`]).map(e=>({value:e,label:t[e]}))}function kpe(e,t){let n=e;for(let e of t)n=n?.[e];return n}function d4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:d4(a,i,n)}}function Ape(e){let t=sM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function f4(e){return`values.${e.join(`.`)}`}var p4=`pt-1`,m4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function h4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(fc,{"aria-hidden":`true`}),e]})}function g4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(SI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function _4({themeId:e,from:t,onLeave:n}){let{api:r}=z(),i=_(),a=N(ib(r)),o=(0,m.useId)(),[s,c]=(0,m.useState)(void 0),[l,u]=(0,m.useState)([]),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),v=a.data,y=e===void 0?void 0:v?.themes.find(t=>t.id===e),b=e===void 0?v?.themes.find(e=>e.id===t)??v?.builtIns.find(e=>e.name===(t??`plain`))??v?.builtIns[0]:y,x=b===void 0?void 0:{name:e===void 0?`${`label`in b?b.label:b.name} copy`:b.name,values:b.values},S=s??x,C=P({mutationFn:t=>Fs(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:ib(r).queryKey})}}),w=P({mutationFn:e=>Is(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:ib(r).queryKey}),n()}});X2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:sM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:ZS(S.name),...T===void 0||T.success?[]:T.error.issues.map(e=>({field:`values.${e.path.join(`.`)}`,message:e.message})),...l];if(a.error!==null)return(0,h.jsx)(b4,{children:a.error.message});if(v===void 0)return(0,h.jsx)($2,{});if(S===void 0)return(0,h.jsx)(b4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(xV,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),Ope.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>v4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(fc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(Npe,{field:e,theme:S.values,problem:v4(E,e.path),onChange:t=>{D({...S,values:t},f4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(fS,{to:`/document-themes`,variant:`secondary`,children:`Cancel`}),errors:[C.error,w.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{C.mutate(S)}})]}),(0,h.jsx)(Mpe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(jy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var jpe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function v4(e,t){let n=f4(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function Mpe({values:e}){let{api:t}=z(),[n,r]=(0,m.useState)(),[i,a]=(0,m.useState)(`busy`),[o,s]=(0,m.useState)(void 0),c=e===void 0?void 0:JSON.stringify(e);(0,m.useEffect)(()=>{if(c===void 0)return;let e=new AbortController,n=window.setTimeout(()=>{a(`busy`),Ls(t,JSON.parse(c),e.signal).then(async e=>({bytes:new Uint8Array(await e.arrayBuffer()),blob:e})).then(({bytes:t,blob:n})=>{e.signal.aborted||r({bytes:t,url:URL.createObjectURL(n)})},t=>{e.signal.aborted||(s(t instanceof Error?t.message:String(t)),a(`failed`))})},450);return()=>{window.clearTimeout(n),e.abort()}},[t,c]),(0,m.useEffect)(()=>()=>{n!==void 0&&URL.revokeObjectURL(n.url)},[n]);let l=(0,m.useCallback)(e=>{if(e===void 0){a(`idle`);return}s(e.message),a(`failed`)},[]),u=e===void 0?`Paused until the highlighted settings are fixed.`:i===`busy`?`Updating…`:i===`failed`?`The preview couldn't be made: ${o??`unknown error`}`:`A sample article with this theme. Your projects use their own text and thumbnail.`;return(0,h.jsxs)(`div`,{className:m4,children:[(0,h.jsx)(H,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(mS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open full size`]})}),(0,h.jsx)(`div`,{className:`max-h-[calc(100vh-220px)] min-h-[320px] overflow-y-auto rounded-media bg-sunken p-3`,children:(0,h.jsx)(Epe,{data:n?.bytes,label:`The sample article laid out with this theme`,onDrawn:l})}),(0,h.jsx)(`p`,{role:`status`,className:i===`failed`?`m-0 text-small text-danger`:`m-0 text-small text-ink-2`,children:u})]})}function Npe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=kpe(t,e.path),o=jpe[f4(e.path)],s=o===void 0?null:(0,h.jsx)(V,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(d4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=Ape(e.path);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(CV,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(CV,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(TV,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=u4(t.family);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(TV,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=l4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=u4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:l4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(TV,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(CV,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(wV,{...d,rows:8,value:Array.isArray(a)?a.join(`
272
+ `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(a0,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(pU,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(mU,{title:e.title,actions:(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(jy,{open:o,title:`Remove all ${H2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function _pe({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...Ob,children:[(0,h.jsxs)(H,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${H2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(R,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,H2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(R,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(xV,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(CV,{value:t,maxLength:200,onChange:e=>r(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(pU,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(mU,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`],vpe={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`};function ype(e){return W2.find(t=>t===e)??`brand`}function bpe({channelId:e,tab:t,onTab:n}){let{api:r}=z(),i=_(),a=Zi(),o=N(Qb(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=P({mutationFn:()=>tx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:qb}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return bx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(ha,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(R,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(r0,{items:W2.map(e=>({id:e,label:vpe[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(Q1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(i0,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(Ufe,{channel:f}),(0,h.jsx)(Zfe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(ipe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(Sde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Tde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(mpe,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(gpe,{channelId:f.id}):null})]}):null,(0,h.jsx)(jy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function G2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:L(`sl-stats m-0`,e),children:t})}function K2({value:e,label:t,children:n}){return(0,h.jsxs)(`div`,{className:`sl-stat`,children:[(0,h.jsx)(`dt`,{className:`sl-stat__label order-2`,children:t}),(0,h.jsx)(`dd`,{className:`sl-stat__value order-1 m-0`,children:e}),n===void 0?null:(0,h.jsx)(`dd`,{className:`order-3 m-0 mt-1`,children:n})]})}function q2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:L(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function J2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:L(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}function xpe(){let{api:e}=z(),t=_(),n=Zi(),r=N(Zb(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=P({mutationFn:()=>$b(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:qb}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=P({mutationFn:t=>ex(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:qb}),a(null)}}),v=P({mutationFn:t=>tx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:qb})}}),y=()=>{p.reset(),l(``),a(`new`)};bx({id:`channels.new`,title:`New channel`,group:`Channels`,run:y});let b=i===`new`?p:g,x=()=>{c.trim()!==``&&i!==null&&(i===`new`?p.mutate():g.mutate(i))};return(0,h.jsxs)(`div`,{"data-tour":`channels`,children:[(0,h.jsx)(kq,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(V,{id:`planning.channels`})]}),actions:(0,h.jsxs)(R,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(Q1,{tone:r.error||v.error?`error`:`info`,className:`mb-2`,children:r.error?`The channels couldn't be loaded: ${r.error.message} Reload the page to try again.`:o===null&&v.error?v.error.message:r.isPending?`Loading channels…`:void 0}),r.data?.length===0?(0,h.jsx)(a0,{title:`No channels yet`,actions:(0,h.jsx)(R,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(jq,{list:(0,h.jsx)(pU,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(mU,{selected:e.id===f?.id,onSelect:()=>d(e.id),title:e.name,meta:`${e.isDefault?`Default · `:``}${String(e.templates)} ${e.templates===1?`template`:`templates`} · ${String(e.cast)} in the cast`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(pS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(Spe,{channel:f})}):null,(0,h.jsx)(Ay,{open:i!==null,onOpenChange:e=>{!e&&!b.isPending&&a(null)},title:i===`new`||i===null?`New channel`:`Rename ${i.name}`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(R,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(R,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(xV,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(CV,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(jy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function Spe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(H,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(fS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(G2,{className:`mb-6`,children:[(0,h.jsx)(K2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(K2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(H,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(H,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var Y2=2e3;function X2(e,t){let n=(0,m.useRef)(t);(0,m.useEffect)(()=>{n.current=t}),(0,m.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{n.current()},Y2);return()=>{clearTimeout(t)}},[e])}function Z2(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(lc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function Q2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Oy();bx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:lP.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(R,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(Q1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(Z2,{}):t)}),a,(0,h.jsx)(R,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Mx(lP.save),onClick:()=>{c||s()},children:`Save`})]})}var Cpe=`rounded-media border border-line bg-surface p-4`;function $2(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${Cpe} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var wpe=`modulepreload`,Tpe=function(e){return`/`+e},e4={},t4=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Tpe(t,n),t=s(t),t in e4)return;e4[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:wpe,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Epe({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return Dpe(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function Dpe(e,t){let n=await t4(()=>import(`./pdf-BAR3gbOu.js`),[]),r=await t4(()=>import(`./pdf.worker.min-zC6nfbxG.js`),[]);n.GlobalWorkerOptions.workerSrc=r.default;let i=n.getDocument({data:e.slice()}),a=await i.promise;try{let e=window.devicePixelRatio||1,n=[];for(let r=1;r<=a.numPages;r+=1){let i=await a.getPage(r),o=i.getViewport({scale:t*e/i.getViewport({scale:1}).width}),s=window.document.createElement(`canvas`);s.width=Math.floor(o.width),s.height=Math.floor(o.height),await i.render({canvas:s,viewport:o}).promise,n.push(s)}return n}finally{await i.destroy()}}var n4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),i4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),a4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),o4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),s4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),c4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),Ope=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},n4([`page`,`margin`],`Margins`),n4([`page`,`contentTop`],`Text starts at`,`From the top, on pages with the header.`),{kind:`choice`,path:[`background`,`image`],label:`Background`,options:[{value:`parchment`,label:`Parchment texture`},{value:null,label:`Flat colour`}]},{kind:`color`,path:[`background`,`color`],label:`Page colour`,help:`Used when the background is a flat colour.`}]},{title:`Colours`,fields:[{kind:`color`,path:[`colors`,`heading`],label:`Headings`,help:`Also drop caps, the brand name and links.`},{kind:`color`,path:[`colors`,`text`],label:`Body text`},{kind:`color`,path:[`colors`,`muted`],label:`Muted`,help:`Dates, bullets, quotes and the dots in the contents.`},{kind:`color`,path:[`colors`,`faint`],label:`Faint`,help:`Running header and page numbers.`}]},{title:`Fonts`,fields:[c4(`body`,`Body`),c4(`strong`,`Bold text`),c4(`emphasis`,`Italic text`),c4(`heading`,`Headings`),c4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),c4(`decorative`,`Tagline and title-page link`),c4(`dropCap`,`Drop caps`),c4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[r4([`sizes`,`title`],`Title`),r4([`sizes`,`brand`],`Brand`),r4([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),r4([`sizes`,`heading`],`Second-level headings`),r4([`sizes`,`subheading`],`Third-level headings`),r4([`sizes`,`body`],`Body`),r4([`sizes`,`meta`],`Date and word count`),r4([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[n4([`spacing`,`bodyLine`],`Body line height`),n4([`spacing`,`headingLine`],`Heading line height`),n4([`spacing`,`subheadingLine`],`Subheading line height`),i4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),i4([`spacing`,`headingGap`],`Before a heading`,`× line`),i4([`spacing`,`itemGap`],`After a list item`,`× line`),n4([`spacing`,`listIndent`],`List indent`),n4([`spacing`,`quoteIndent`],`Quote indent`),n4([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[a4([`dropCap`,`enabled`],`Drop caps`,`A large first letter after each heading.`),{kind:`choice`,path:[`dropCap`,`lines`],label:`Lines tall`,options:[{value:2,label:`2 lines`},{value:3,label:`3 lines`},{value:4,label:`4 lines`}]},i4([`dropCap`,`scale`],`Letter size`,`× lines`),n4([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},i4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[n4([`titlePage`,`brandY`],`Brand from top`),n4([`titlePage`,`taglineOffset`],`Tagline below brand`),n4([`titlePage`,`titleY`],`Title from top`),n4([`titlePage`,`titleLine`],`Title line height`),n4([`titlePage`,`metaOffset`],`Details below title`),n4([`titlePage`,`metaLine`],`Details line height`),a4([`titlePage`,`showDate`],`Show the date`),a4([`titlePage`,`showWordCount`],`Show the word count`),a4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),n4([`titlePage`,`cover`,`gap`],`Space around cover`),n4([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[s4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),s4([`brand`,`tagline`],`Tagline`),s4([`brand`,`url`],`Website`,`Where the brand and its link go.`),s4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[a4([`contents`,`enabled`],`Contents page`),o4([`contents`,`title`],`Title`),{kind:`choice`,path:[`contents`,`depth`],label:`Lists headings down to`,options:[{value:1,label:`Top level`},{value:2,label:`Second level`},{value:3,label:`Third level`}]},n4([`contents`,`titleOffset`],`Title from top margin`),n4([`contents`,`firstEntryOffset`],`First entry from top margin`),n4([`contents`,`line`],`Line height`),n4([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[a4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),n4([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},a4([`footer`,`enabled`],`Page numbers`),o4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),n4([`footer`,`bottom`],`From the bottom`),n4([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[a4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),o4([`sources`,`title`],`Title`),n4([`sources`,`titleOffset`],`Title from top margin`),n4([`sources`,`bodyOffset`],`List from top margin`),n4([`sources`,`line`],`Line height`),n4([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[a4([`endPage`,`enabled`],`Closing page`),o4([`endPage`,`title`],`Title`),{kind:`lines`,path:[`endPage`,`lines`],label:`Text`,help:`One line each. Start with "•" for a bullet, end with ":" for a bold label, leave a line empty for a gap.`},a4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},s4([`endPage`,`closing`],`Closing line`),n4([`endPage`,`titleOffset`],`Title from top margin`),n4([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[o4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),o4([`metadata`,`subject`],`Subject`),o4([`metadata`,`keywords`],`Keywords`),o4([`metadata`,`creator`],`Creator`)]}],l4=$j.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function u4(e){let t={normal:`Regular`,medium:`Medium`,bold:`Bold`,black:`Black`,italic:`Italic`,bolditalic:`Bold italic`};return(e===`Cinzel`?[`normal`,`medium`,`bold`,`black`]:[`normal`,`bold`,`italic`,`bolditalic`]).map(e=>({value:e,label:t[e]}))}function kpe(e,t){let n=e;for(let e of t)n=n?.[e];return n}function d4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:d4(a,i,n)}}function Ape(e){let t=sM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function f4(e){return`values.${e.join(`.`)}`}var p4=`pt-1`,m4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function h4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(fc,{"aria-hidden":`true`}),e]})}function g4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(SI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function _4({themeId:e,from:t,onLeave:n}){let{api:r}=z(),i=_(),a=N(ib(r)),o=(0,m.useId)(),[s,c]=(0,m.useState)(void 0),[l,u]=(0,m.useState)([]),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),v=a.data,y=e===void 0?void 0:v?.themes.find(t=>t.id===e),b=e===void 0?v?.themes.find(e=>e.id===t)??v?.builtIns.find(e=>e.name===(t??`plain`))??v?.builtIns[0]:y,x=b===void 0?void 0:{name:e===void 0?`${`label`in b?b.label:b.name} copy`:b.name,values:b.values},S=s??x,C=P({mutationFn:t=>Fs(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:ib(r).queryKey})}}),w=P({mutationFn:e=>Is(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:ib(r).queryKey}),n()}});X2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:sM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:ZS(S.name),...T===void 0||T.success?[]:T.error.issues.map(e=>({field:`values.${e.path.join(`.`)}`,message:e.message})),...l];if(a.error!==null)return(0,h.jsx)(b4,{children:a.error.message});if(v===void 0)return(0,h.jsx)($2,{});if(S===void 0)return(0,h.jsx)(b4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(xV,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),Ope.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>v4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(fc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(Npe,{field:e,theme:S.values,problem:v4(E,e.path),onChange:t=>{D({...S,values:t},f4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(fS,{to:`/document-themes`,variant:`secondary`,children:`Cancel`}),errors:[C.error,w.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{C.mutate(S)}})]}),(0,h.jsx)(Mpe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(jy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var jpe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function v4(e,t){let n=f4(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function Mpe({values:e}){let{api:t}=z(),[n,r]=(0,m.useState)(),[i,a]=(0,m.useState)(`busy`),[o,s]=(0,m.useState)(void 0),c=e===void 0?void 0:JSON.stringify(e);(0,m.useEffect)(()=>{if(c===void 0)return;let e=new AbortController,n=window.setTimeout(()=>{a(`busy`),Ls(t,JSON.parse(c),e.signal).then(async e=>({bytes:new Uint8Array(await e.arrayBuffer()),blob:e})).then(({bytes:t,blob:n})=>{e.signal.aborted||r({bytes:t,url:URL.createObjectURL(n)})},t=>{e.signal.aborted||(s(t instanceof Error?t.message:String(t)),a(`failed`))})},450);return()=>{window.clearTimeout(n),e.abort()}},[t,c]),(0,m.useEffect)(()=>()=>{n!==void 0&&URL.revokeObjectURL(n.url)},[n]);let l=(0,m.useCallback)(e=>{if(e===void 0){a(`idle`);return}s(e.message),a(`failed`)},[]),u=e===void 0?`Paused until the highlighted settings are fixed.`:i===`busy`?`Updating…`:i===`failed`?`The preview couldn't be made: ${o??`unknown error`}`:`A sample article with this theme. Your projects use their own text and thumbnail.`;return(0,h.jsxs)(`div`,{className:m4,children:[(0,h.jsx)(H,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(mS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open full size`]})}),(0,h.jsx)(`div`,{className:`max-h-[calc(100vh-220px)] min-h-[320px] overflow-y-auto rounded-media bg-sunken p-3`,children:(0,h.jsx)(Epe,{data:n?.bytes,label:`The sample article laid out with this theme`,onDrawn:l})}),(0,h.jsx)(`p`,{role:`status`,className:i===`failed`?`m-0 text-small text-danger`:`m-0 text-small text-ink-2`,children:u})]})}function Npe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=kpe(t,e.path),o=jpe[f4(e.path)],s=o===void 0?null:(0,h.jsx)(V,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(d4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=Ape(e.path);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(CV,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(CV,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(TV,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=u4(t.family);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(TV,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=l4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=u4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:l4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(TV,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(CV,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(wV,{...d,rows:8,value:Array.isArray(a)?a.join(`
273
273
  `):``,onChange:e=>{c(e.target.value.split(`
274
274
  `))}}),u]});case`link`:{let t=a;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),s]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(CV,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{c({...t,text:e.target.value})}}),(0,h.jsx)(CV,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{c({...t,url:e.target.value===``?null:e.target.value})}})]}),u]})}}}function y4({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),r]}),i,n]})}function b4({children:e}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/document-themes`,children:`Back to Documents`}),children:e})}var Ppe=4e3;function x4(e){return e.match(/\s+|[^\s]+/gu)??[]}function Fpe(e,t){let n=x4(e),r=x4(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i+=1;let a=0;for(;a<n.length-i&&a<r.length-i&&n[n.length-1-a]===r[r.length-1-a];)a+=1;let o=[];C4(o,`same`,n.slice(0,i).join(``));let s=n.slice(i,n.length-a),c=r.slice(i,r.length-a);for(let e of Lpe(s,c))C4(o,e.op,e.text);return C4(o,`same`,n.slice(n.length-a).join(``)),o}function S4(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function Ipe(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+x4(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function C4(e,t,n){if(n===``)return;let r=e.at(-1);r!==void 0&&r.op===t?e[e.length-1]={op:t,text:r.text+n}:e.push({op:t,text:n})}function Lpe(e,t){if(e.length===0&&t.length===0)return[];if(e.length===0)return[{op:`added`,text:t.join(``)}];if(t.length===0)return[{op:`removed`,text:e.join(``)}];let n=e.length,r=t.length,i=Math.min(n+r,Ppe),a=i+1,o=new Int32Array(2*i+3),s=[],c=!1;for(let l=0;l<=i&&!c;l+=1){s.push(o.slice());let i=o.slice();for(let s=-l;s<=l;s+=2){let u=s===-l||s!==l&&(o[a+s-1]??0)<(o[a+s+1]??0)?o[a+s+1]??0:(o[a+s-1]??0)+1,d=u-s;for(;u<n&&d<r&&e[u]===t[d];)u+=1,d+=1;if(i[a+s]=u,u>=n&&d>=r){c=!0;break}}o=i}if(!c)return[{op:`removed`,text:e.join(``)},{op:`added`,text:t.join(``)}];let l=[],u=n,d=r;for(let n=s.length-1;n>=0;--n){let r=s[n]??new Int32Array,i=u-d,o=i===-n||i!==n&&(r[a+i-1]??0)<(r[a+i+1]??0),c=o?i+1:i-1,f=r[a+c]??0,p=f-c;for(;u>f&&d>p;)l.push({op:`same`,text:e[u-1]??``}),--u,--d;n>0&&(o?l.push({op:`added`,text:t[d-1]??``}):l.push({op:`removed`,text:e[u-1]??``}),u=f,d=p)}let f=[];for(let e of l.reverse())C4(f,e.op,e.text);return f}function w4({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>Fpe(e,t),[e,t]),a=Ipe(i);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:a.added===0&&a.removed===0?`The two texts are the same.`:`${String(a.added)} ${a.added===1?`word`:`words`} added, ${String(a.removed)} removed.`}),(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,h.jsx)(T4,{label:n,parts:S4(i,`before`)}),(0,h.jsx)(T4,{label:r,parts:S4(i,`after`)})]})]})}function T4({label:e,parts:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`h4`,{className:`sl-kicker m-0`,children:e}),(0,h.jsx)(`div`,{className:`min-w-0 whitespace-pre-wrap break-words border-l-2 border-line pl-3 text-small leading-relaxed text-ink`,children:Rpe(t).map(({key:e,part:t})=>t.op===`removed`?(0,h.jsx)(`del`,{className:`rounded-[2px] bg-danger-tint text-danger line-through`,children:t.text},e):t.op===`added`?(0,h.jsx)(`ins`,{className:`rounded-[2px] bg-accent-tint text-accent-ink no-underline`,children:t.text},e):(0,h.jsx)(`span`,{children:t.text},e))})]})}function Rpe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var E4={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function D4(e,t){let{api:n}=z();return N({queryKey:E4.versions(e,t),queryFn:()=>ks(n,e,t)})}function zpe(e,t){let{api:n}=z();return N({queryKey:E4.usedBy(e,t),queryFn:()=>As(n,e,t)})}function O4({item:e,id:t,name:n,onClose:r}){let{api:i}=z(),a=_(),o=D4(e,t),s=o.data?.versions??[],[c,l]=(0,m.useState)({}),u=c.after??s[0]?.version,d=c.before??s[1]?.version??u,f=s.find(e=>e.version===d),p=s.find(e=>e.version===u),[g,v]=(0,m.useState)(),y=P({mutationFn:n=>js(i,e,t,n),onSuccess:async(n,r)=>{v(`Restored version ${String(r)} as a new version.`),l({}),await Promise.all([a.invalidateQueries({queryKey:E4.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?B.prompts:B.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)(YP,{open:!0,title:`History of ${n}`,onClose:r,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[o.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:`The history couldn't be read: ${o.error.message}`}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(TV,{value:d===void 0?``:String(d),disabled:s.length===0,onChange:e=>l(t=>({...t,before:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:A4(e,b)},e.version))})}),(0,h.jsx)(xV,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(TV,{value:u===void 0?``:String(u),disabled:s.length===0,onChange:e=>l(t=>({...t,after:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:A4(e,b)},e.version))})})]}),f===void 0||p===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading the versions…`:`No versions to compare.`}):(0,h.jsxs)(h.Fragment,{children:[f.name===p.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${f.name}" to "${p.name}".`}),(0,h.jsx)(w4,{before:f.body,after:p.body,beforeLabel:`Version ${String(f.version)}`,afterLabel:`Version ${String(p.version)}`})]})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(pU,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(mU,{title:`Version ${String(e.version)}`,meta:k4(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(R,{size:`small`,"aria-label":`Restore version ${String(e.version)}`,disabled:y.isPending,disabledReason:`Restoring a version`,onClick:()=>{v(void 0),y.mutate(e.version)},children:`Restore`})},e.version))}),(0,h.jsx)(Q1,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function k4(e){return`${e.author} · ${j4(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function A4(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${j4(e.createdAt)}`}function j4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function M4({item:e,id:t,name:n,kicker:r,meta:i,body:a,slots:o,actions:s,onOpenHistory:c}){return(0,h.jsxs)(`section`,{"aria-label":`${n} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(H,{title:n,kicker:r,meta:i,className:`pb-0`,children:s}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`div`,{className:`m-0 max-h-[420px] min-w-0 overflow-y-auto whitespace-pre-wrap break-words rounded-media bg-sunken p-4 font-mono text-small text-ink-2`,children:a}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No keywords. It runs as written.`}):(0,h.jsx)(`ul`,{"aria-label":`Keywords`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:o.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(EV,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(Bpe,{item:e,id:t}),(0,h.jsx)(Vpe,{item:e,id:t,name:n,onOpenHistory:c})]})}function Bpe({item:e,id:t}){let n=zpe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:Hpe(r)}}),n.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`What uses it couldn't be read: ${n.error.message}`}),r===void 0?null:r.templates.length+r.schedules.length+r.projects.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Nothing uses it yet.`}):(0,h.jsxs)(pU,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name}),meta:e.status===`paused`?`Schedule · paused`:`Schedule`},`s-${e.id}`)),r.projects.map(e=>(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),meta:`Project${e.totalRevisions===0?``:` · ${String(e.revisions)} of ${String(e.totalRevisions)} ${e.totalRevisions===1?`revision`:`revisions`}${e.current?`, including the current one`:`, not the current one`}`}`},`p-${e.id}`))]})]})}function Vpe({item:e,id:t,name:n,onOpenHistory:r}){let i=D4(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:`${N4(a.length,`version`)} · latest ${k4(o)}`},children:(0,h.jsx)(R,{size:`small`,"aria-label":`Compare versions of ${n}`,onClick:r,children:`Compare versions`})}),i.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The history couldn't be read: ${i.error.message}`}),o===void 0?null:s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Only one version so far.`}):(0,h.jsx)(w4,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function Hpe(e){return[N4(e.templates.length,`template`),N4(e.schedules.length,`schedule`),N4(e.projects.length,`project`)].join(`, `)}function N4(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function P4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}var F4=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,I4=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function L4({label:e}){return(0,h.jsx)(`ul`,{"aria-label":`${e}, loading`,"aria-busy":`true`,className:`sl-list m-0 list-none p-0`,children:[0,1,2].map(e=>(0,h.jsx)(`li`,{className:`sl-row`,"aria-hidden":`true`,children:(0,h.jsxs)(`span`,{className:`flex flex-col gap-2 py-0.5`,children:[(0,h.jsx)(`span`,{className:`h-3 w-40 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 rounded-control bg-sunken`})]})},e))})}function R4({what:e,message:t,onRetry:n}){return(0,h.jsx)(SI,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(R,{size:`small`,onClick:n,children:`Try again`}),children:t})}function z4({name:e,edit:t,duplicate:n,play:r,onHistory:i,onDelete:a,className:o}){return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`Actions for ${e}`,className:L(`flex flex-wrap items-center gap-0.5`,o),children:[t,n,r===void 0?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Use ${e} in Play`,title:r.blocked,disabled:r.run===void 0||r.blocked!==void 0,onClick:r.run,children:`Use in Play`}),i===void 0?null:(0,h.jsx)(wy,{size:`small`,label:`History of ${e}`,onClick:i,children:(0,h.jsx)(Fc,{"aria-hidden":`true`})}),(0,h.jsx)(wy,{size:`small`,label:`Delete ${e}`,onClick:a,children:(0,h.jsx)(Bc,{"aria-hidden":`true`})})]})}var Upe=[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & Outros`},{to:`/templates`,label:`Templates`},{to:`/document-themes`,label:`Documents`},{to:`/narration-aliases`,label:`Aliases`}];function Wpe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Library`,meta:`Prompts, intros and outros, templates, document themes and narration aliases`}),(0,h.jsx)(xde,{items:Upe,label:`Library sections`,className:`mb-6`}),(0,h.jsx)(Gpe,{}),(0,h.jsx)(ja,{})]})}function Gpe(){let e=Zi(),t=Va({select:e=>e.location}),n=t.search,r=vV(t.pathname===`/prompts`?n.kind:void 0),i=hV(t.pathname===`/entries`?n.category:void 0);return bx({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),bx({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),bx({id:`library.new-document-theme`,title:`New document theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),bx({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),bx({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),bx({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),bx({id:`library.open-document-themes`,title:`Open document themes`,group:`Library`,keywords:[`pdf`,`documents`],run:()=>{e({to:`/document-themes`})}}),null}function B4({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:L(`mb-5 flex min-h-9 flex-wrap items-center gap-x-4 gap-y-3`,n),children:[(0,h.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-3`,children:e}),t===void 0?null:(0,h.jsx)(Ey,{className:`ml-auto shrink-0`,children:t})]})}function Kpe(){let{api:e}=z(),t=_(),n=N(ib(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(void 0),s=P({mutationFn:t=>Is(e,t),onSettled:async()=>{o(void 0),await t.invalidateQueries({queryKey:B.documentThemes})}}),c=n.data,l=r!==void 0&&`saved`in r?c?.themes.find(e=>e.id===r.saved):void 0,u=r!==void 0&&`builtIn`in r?c?.builtIns.find(e=>e.name===r.builtIn):void 0,d=l===void 0&&u===void 0?c?.themes[0]:void 0,f=l??d,p=f===void 0?u??c?.builtIns[0]:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B4,{action:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:`plain`},variant:`primary`,children:`New theme`}),children:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`How a project's PDF looks. Pick one on the Document row in Play or in Edit project.`})}),n.error===null?null:(0,h.jsx)(R4,{what:`document themes`,message:n.error.message,onRetry:()=>void n.refetch()}),c===void 0?n.error===null?(0,h.jsx)(L4,{label:`Document themes`}):null:(0,h.jsx)(jq,{className:F4,list:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`}),c.themes.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No themes of your own yet. Copy a built-in below to start one.`}):(0,h.jsx)(pU,{label:`Your themes`,children:c.themes.map(e=>(0,h.jsx)(mU,{className:I4,lead:(0,h.jsx)(K4,{colors:e.values.colors}),title:e.name,meta:`${V4(e.values)} · updated ${P4(e.updatedAt)}`,selected:e.id===f?.id,onSelect:()=>i({saved:e.id}),actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>o(e)})},e.id))})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(pU,{label:`Built-in themes`,children:c.builtIns.map(e=>(0,h.jsx)(mU,{className:I4,lead:(0,h.jsx)(K4,{colors:e.values.colors}),title:e.label,meta:V4(e.values),selected:e.name===p?.name,onSelect:()=>i({builtIn:e.name}),actions:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:f===void 0?p===void 0?null:(0,h.jsx)(W4,{name:p.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:p.values,action:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:p.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(W4,{name:f.name,kicker:`Your theme`,meta:`Updated ${P4(f.updatedAt)}`,values:f.values,action:(0,h.jsx)(fS,{to:`/document-themes/$themeId`,params:{themeId:f.id},size:`small`,children:`Edit theme`})})}),s.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:s.error.message}),(0,h.jsx)(jy,{open:a!==void 0,title:`Delete "${a?.name??``}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:s.isPending,onConfirm:()=>{a!==void 0&&s.mutate(a.id)},onCancel:()=>o(void 0)})]})}function V4(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${H4(e.fonts.body.family)} body`}function H4(e){return l4.find(t=>t.value===e)?.label??e}function U4(e){return e.startsWith(`#`)?e:`#${e}`}function W4({name:e,kicker:t,meta:n,values:r,action:i}){let a=[[`Headings`,r.colors.heading],[`Text`,r.colors.text],[`Muted`,r.colors.muted],[`Header and page numbers`,r.colors.faint]],o=[[`Body`,r.fonts.body],[`Headings`,r.fonts.heading],[`Drop cap`,r.fonts.dropCap]];return(0,h.jsxs)(`section`,{"aria-label":`${e} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(H,{title:e,kicker:t,meta:n,className:`pb-0`,children:i}),(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-[max-content_minmax(0,1fr)]`,children:[a.map(([e,t])=>(0,h.jsx)(G4,{label:e,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-4 rounded-full border border-line`,style:{backgroundColor:U4(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:U4(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(G4,{label:`${e} font`,children:`${H4(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(G4,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${U4(r.background.color)}`} background`})]})]})}function G4({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function K4({colors:e}){return(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`flex shrink-0 gap-1`,children:[e.heading,e.text,e.muted].map((e,t)=>(0,h.jsx)(`span`,{className:`size-3 rounded-full border border-line`,style:{backgroundColor:U4(e)}},t))})}function q4(e){let t=e.map(e=>e.message).join(` `);return`The name wasn't saved. ${t===``?`Pick another name and press Save name again.`:t}`}function J4({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Oy(),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(e),[u,d]=(0,m.useState)(null),[f,p]=(0,m.useState)(!1),g=(0,m.useRef)(!1),_=async e=>{try{return await n(e)}catch(e){return`The name wasn't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then press Save name again.`}},v=async()=>{let t=c.trim();if(t===e){s(!1),d(null);return}if(t===``){d(`Write a name first, or press Cancel to keep the old one.`);return}if(g.current)return;g.current=!0,p(!0);let n=await _(t);if(g.current=!1,p(!1),n!==null){d(n);return}s(!1),d(null),a(`Renamed “${e}” to “${t}”.`,`success`,{label:`Undo`,run:()=>void _(e).then(t=>{t===null?a(`Renamed back to “${e}”.`,`success`):a(t,`error`)})})},y=()=>{s(!1),l(e),d(null)};return o?(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(CV,{autoFocus:!0,"aria-label":`New name for ${e}`,"aria-invalid":u!==null,maxLength:i,value:c,className:`min-w-0 flex-1`,onChange:e=>{l(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v()):e.key===`Escape`&&(e.preventDefault(),y())}}),(0,h.jsx)(R,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(V,{id:r,label:`Rename`})]}),u===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small font-normal text-danger`,children:u})]}):(0,h.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[t===void 0?(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:e}):(0,h.jsx)(hU,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(wy,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function qpe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=z(),a=_(),o=N(rb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=xx(l,`intros and outros`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=P({mutationFn:e=>Vs(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:B.entries})}}),x=async(e,t)=>{let n=await Ns(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:B.entries}),n.ok?null:q4(n.fields)},S=o.data?.entries.filter(t=>t.category===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B4,{action:(0,h.jsx)(fS,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`}),children:[(0,h.jsx)(CV,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":Mx(u),placeholder:`Search intros and outros`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsx)(Ab,{label:`Entry category`,value:e,options:lV.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`})]}),o.error===null?null:(0,h.jsx)(R4,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(L4,{label:`Intros and outros`}):null:S.length===0?(0,h.jsx)(Ype,{category:e}):(0,h.jsx)(jq,{className:F4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${e}s match "${s.trim()}".`}):(0,h.jsx)(pU,{label:`${dV(e)}s`,children:w.map(e=>(0,h.jsx)(mU,{className:I4,title:(0,h.jsx)(J4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:Jpe(e),selected:e.id===T?.id,actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/entries/new`,search:{category:e.category,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(M4,{item:`entry`,id:T.id,name:T.name,kicker:`${dV(T.category)} · ${fV(T.mode)}`,meta:`Updated ${P4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(fS,{to:`/entries/$entryId`,params:{entryId:T.id},size:`small`,children:`Edit ${T.category}`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(O4,{item:`entry`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(jy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${p?.category??e}`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function Jpe(e){return`${fV(e.mode)} · ${N4(e.slots.length,`keyword`)} · updated ${P4(e.updatedAt)}`}function Ype({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(a0,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function Xpe({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:L(`animate-tick-in rounded-control border border-line-strong bg-sunken px-2 py-0.5 font-mono text-label text-ink-2 motion-reduce:animate-none`,t),children:e})}function Y4({slots:e,body:t,lint:n,lintId:r,noSlots:i=`No slots. This prompt runs as written.`}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Detected slots`,info:`library.slots`,size:`small`,className:`pb-0`}),e.length>0?(0,h.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.map(e=>(0,h.jsx)(Xpe,{name:e,className:`px-2 py-1`},e))}):t.trim()===``?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Slots appear here as you type {{name}}.`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i}),n.length===0?null:(0,h.jsxs)(`div`,{id:r,className:`flex flex-col gap-2 border-t border-line pt-3`,children:[(0,h.jsx)(`span`,{className:`sl-kicker text-danger`,children:n.length===1?`1 slot error`:`${String(n.length)} slot errors`}),n.map(e=>(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message},e.message))]})]})}function X4({className:e,...t}){return(0,h.jsx)(Wv,{"data-slot":`label`,className:L(`engraved block select-none text-ink-3`,e),...t})}function Z4({className:e,...t}){return(0,h.jsx)(Zee,{"data-slot":`toggle-group`,className:L(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function Q4({className:e,...t}){return(0,h.jsx)(nte,{"data-slot":`toggle-group-item`,className:L(`min-h-8 shrink-0 border-r border-line-strong px-3 py-1 text-label text-ink-2 last:border-r-0`,`transition-colors duration-150 ease-out motion-reduce:transition-none hover:bg-raised hover:text-ink`,`data-[state=on]:bg-raised data-[state=on]:text-ink data-[state=on]:shadow-[inset_0_-2px_0_var(--color-accent)]`,`disabled:cursor-not-allowed disabled:opacity-40`,e),...t})}function $4({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{id:o,children:e}),i===void 0?null:(0,h.jsx)(V,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(Z4,{type:`single`,value:t,"aria-labelledby":o,"aria-describedby":r,onValueChange:e=>{let t=n.find(t=>t.value===e);t!==void 0&&a(t.value)},children:n.map(e=>(0,h.jsx)(Q4,{value:e.value,children:e.label},e.value))})]})}function Zpe(e){return e3(e.name,e.body)}function Qpe(e){return e3(e.name,e.body)}function e3(e,t){let n=[],r=e.trim();if(r===``?n.push({field:`name`,message:`Enter a name.`}):r.length>200&&n.push({field:`name`,message:`Keep the name to 200 characters or fewer.`}),t.trim()===``)return n.push({field:`body`,message:`Enter the text.`}),n;if(t.length>1e5)return n.push({field:`body`,message:`The text is too long. Keep it to ${String(wM)} characters or fewer.`}),n;for(let e of dq(t).errors)n.push({field:`body`,message:$pe(e,t)});return n}function $pe(e,t){let n=eme(t,e.at);switch(e.kind){case`unclosed`:return`The \`{{\` at ${n} is never closed. Add \`}}\` after the keyword name.`;case`empty`:return`The keyword at ${n} has no name. Write a name between \`{{\` and \`}}\`.`;case`nested`:return`The keyword at ${n} contains a brace. Keywords cannot be placed inside other keywords.`}}function eme(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
275
275
  `),i=n.split(`
276
276
  `).length,a=t-r;return`line ${String(i)}, column ${String(a)}`}function t3(e,t){return[...`kind`in e?Zpe(e):Qpe(e),...t]}function n3(e){return e[0]?.message}function r3(e){return e.filter(e=>e.field===`body`)}function i3(e){return e.filter(e=>e.field===`name`)}function a3(e){return dq(e).names}function tme(e){let t=[],n=0;for(let r of dq(e).errors){if(r.at<n)continue;r.at>n&&t.push({start:n,text:e.slice(n,r.at),marked:!1});let i=Math.min(r.at+2,e.length);t.push({start:r.at,text:e.slice(r.at,i),marked:!0}),n=i}return n<e.length&&t.push({start:n,text:e.slice(n),marked:!1}),t}var o3=`px-3 py-3 font-sans text-body leading-[1.5] break-words [scrollbar-gutter:stable]`;function s3({id:e,value:t,invalid:n,describedBy:r,onChange:i}){let a=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:`relative max-w-[75ch]`,children:[(0,h.jsxs)(`div`,{ref:a,"aria-hidden":`true`,"data-slot":`lint-overlay`,className:L(o3,`pointer-events-none absolute inset-0 overflow-hidden whitespace-pre-wrap`,`rounded-control border border-transparent bg-sunken text-ink`),children:[tme(t).map(e=>(0,h.jsx)(`span`,{"data-lint-mark":e.marked?e.start:void 0,className:e.marked?`text-danger underline decoration-danger decoration-2 underline-offset-[3px]`:void 0,children:e.text},e.start)),`
277
- `]}),(0,h.jsx)(wV,{id:e,rows:24,value:t,spellCheck:!1,"aria-invalid":n,"aria-describedby":r,className:L(o3,`relative block min-h-[520px] resize-y border-line-strong overflow-auto bg-transparent text-transparent caret-ink`),onChange:e=>{i(e.target.value)},onScroll:e=>{let t=a.current;t!==null&&(t.scrollTop=e.currentTarget.scrollTop,t.scrollLeft=e.currentTarget.scrollLeft)}})]})}function c3({entryId:e,category:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=N(rb(i)),s=(0,m.useId)(),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),S=o.data?.entries,C=e??n,w=C===void 0?void 0:S?.find(e=>e.id===C),T=w===void 0?{category:t,mode:`text`,name:``,body:``}:{category:w.category,mode:w.mode,name:e===void 0?`${w.name} copy`:w.name,body:w.body},E=d??T,D=P({mutationFn:t=>Ns(i,t,e),onSuccess:async e=>{if(!e.ok){g(e.fields);return}y(!0),await a.invalidateQueries({queryKey:rb(i).queryKey})}}),O=P({mutationFn:e=>Vs(i,e),onSuccess:async()=>{x(!1),await a.invalidateQueries({queryKey:rb(i).queryKey}),r(E.category)}});X2(v,()=>{r(E.category)});let k=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},A=t3(E,p),ee=n3(A),te=a3(E.body),ne=E.body.trim()===``?[]:r3(A),j=E.name.trim()===``?[]:i3(A);return o.error===null?C!==void 0&&S===void 0?(0,h.jsx)($2,{}):C!==void 0&&w===void 0?(0,h.jsx)(l3,{category:t,children:`That entry is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/entries`,search:{category:E.category},children:`Intros & Outros`})}),title:e===void 0?`New entry`:`Edit entry`,meta:dV(E.category)}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{className:`min-w-[200px] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.entry.name`,...j.length===0?{}:{error:j.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:E.name,onChange:e=>{k({...E,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Category`,value:E.category,options:lV,tip:`library.entry.category`,onPick:e=>{k({...E,category:e},`name`)}}),(0,h.jsx)($4,{label:`Mode`,value:E.mode,options:uV,describedBy:s,tip:`library.entry.mode`,onPick:e=>{k({...E,mode:e},`mode`)}})]}),(0,h.jsx)(`p`,{id:s,className:`-mt-2 text-right text-small text-ink-2`,children:pV(E.mode)}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:`library.entry.body`,label:`Body`,className:`-my-1`})]}),(0,h.jsx)(s3,{id:c,value:E.body,invalid:ne.length>0,describedBy:ne.length===0?void 0:l,onChange:e=>{k({...E,body:e},`body`)}})]}),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{x(!0)},blocked:ee,blockedId:u,pending:D.isPending,saved:v,cancel:(0,h.jsx)(fS,{to:`/entries`,search:{category:E.category},variant:`secondary`,children:`Cancel`}),errors:[D.error,O.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{D.mutate(E)}})]}),(0,h.jsx)(`div`,{className:m4,children:(0,h.jsx)(Y4,{slots:te,body:E.body,lint:ne,lintId:l,noSlots:mV(E.mode)})})]}),(0,h.jsx)(jy,{open:b,title:`Delete "${E.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${E.category}`,pending:O.isPending,onConfirm:()=>{e!==void 0&&O.mutate(e)},onCancel:()=>{x(!1)}})]}):(0,h.jsx)(l3,{category:E.category,children:o.error.message})}function l3({category:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/entries`,search:{category:e},children:`Back to Intros & Outros`}),children:t})}var nme=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),rme=new Intl.DateTimeFormat(void 0,{timeStyle:`short`});function ime({runs:e}){return(0,h.jsx)(pU,{label:`Coming up`,children:e.map(e=>(0,h.jsx)(mU,{title:`${nme.format(new Date(e.at))} · ${rme.format(new Date(e.at))} · ${uU(e)}`,meta:[e.scheduleName,e.templateName].filter(e=>e!==null).join(` · `),actions:e.paused?(0,h.jsx)(vS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(vS,{tone:`info`,children:`Needs a topic`}):(0,h.jsx)(vS,{children:`Queued`})},`${e.scheduleId}-${e.at}`))})}var u3=q({revisionId:W(),checkpoints:K(Zj.unwrap().extend({currentFingerprint:W().regex(/^[a-f0-9]{64}$/),dependents:K(J(FS)),workKeys:K(W())}))}),ame=q({revisionId:W().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),stages:K(Xj).max(3).refine(e=>new Set(e).size===e.length).readonly()}).strict(),ome=q({title:W(),status:G(),detail:W().optional(),reason:J([`duplicate`,`not-found`,`conflict`,`invalid-input`]).optional()}),sme=Qj.unwrap().omit({projectId:!0,checkpointId:!0,approvedAt:!0}),d3=e=>[`checkpoints`,e],f3=(e,t)=>[...d3(e),t];async function p3(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=ome.safeParse(n);if(!r.success)throw po(e,void 0);if(![400,404,409].includes(e.status))throw Error(r.data.detail??r.data.title);return{ok:!1,reason:r.data.reason??`invalid-input`,message:r.data.detail??r.data.title}}async function m3(e,t){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`),u3)}async function h3(e,t,n,r){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints/${encodeURIComponent(n)}/approve`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(sme.parse(r))}),q({checkpoint:Zj,replayed:GD()}))}async function cme(e,t,n){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(ame.parse(n))}),u3)}var g3=(0,m.createContext)(void 0);function _3(e,t){if(e.state===`failed`)return V1({stage:e.kind,kind:e.failureKind,reason:e.failureReason,provider:ode(t.config,e.kind)})}function v3({projectId:e,className:t}){let{api:n}=z(),[r,i]=(0,m.useState)(!1);return(0,h.jsx)(`div`,{className:L(`sl-media__frame`,t),"aria-hidden":`true`,children:r?(0,h.jsx)(`div`,{className:`flex size-full items-center justify-center bg-sunken text-ink-3`,children:(0,h.jsx)(bc,{strokeWidth:1.75,className:`size-6`})}):(0,h.jsx)(`img`,{src:Ko(n,e,`thumbnail`),alt:``,loading:`lazy`,decoding:`async`,onError:()=>i(!0)})})}function y3(e){return e.status===`pending`&&e.progress>0}function b3({lead:e,status:t,title:n,detail:r,action:i}){return(0,h.jsxs)(`li`,{className:L(`sl-home-item`,dU),children:[e,(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[t,(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:n}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:r})]}),(0,h.jsx)(Ey,{className:`sl-home-item__action`,children:i})]})}function x3(e){return(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}var lme={audio:`Approve the article and record`,images:`Approve and draw the images`,video:`Approve and render`},ume={audio:`review before the narration`,images:`review before the images`,video:`review before the video`};function dme({project:e,primary:t}){let{api:n}=z(),r=_(),i=Oy(),a=Zi(),o=(0,m.useRef)(null),s=N({queryKey:d3(e.id),queryFn:async()=>{let t=await m3(n,e.id);if(!t.ok)throw Error(t.message);return t.value}}).data?.checkpoints.find(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint),c=P({mutationFn:async t=>{o.current??={revisionId:t.revisionId,fingerprint:t.fingerprint,idempotencyKey:crypto.randomUUID()};let r=await h3(n,e.id,t.checkpointId,o.current);return o.current=null,r},onSuccess:t=>{i(t.ok?`Approved: ${e.title}. The run continues.`:`${e.title} wasn't approved: ${t.message} Open the project to review it there.`,t.ok?`success`:`error`)},onError:t=>{i(`Slopify didn't confirm the approval of ${e.title}: ${t.message} Press the button again to check whether it went through.`,`error`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:d3(e.id)}),r.invalidateQueries({queryKey:B.projects})])}}),l=s===void 0?void 0:lme[s.stage];return bx({id:`home.approve.${e.id}`,title:l??`Open the held run`,group:`Needs you`,context:e.title,keywords:[`approve`,`review`,`waiting`],run:()=>{s===void 0?a({to:`/projects/$projectId`,params:{projectId:e.id}}):c.mutate(s)}}),(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:s===void 0?`Waiting for you`:`Waiting for you · ${ume[s.stage]}`}),title:x3(e),detail:s===void 0?`Its next step is held. Open the project to review it and continue the run.`:`Everything before this step is done. Approve to let the run go on, or open the project to look first.`,action:s===void 0||l===void 0?(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`}):(0,h.jsx)(R,{variant:t?`primary`:`secondary`,disabled:c.isPending,disabledReason:`Approving…`,onClick:()=>c.mutate(s),children:c.isPending?`Approving…`:l})})}function fme({schedule:e,primary:t}){let n=e.topics.held;return(0,h.jsx)(b3,{lead:(0,h.jsx)(`div`,{className:`sl-media__frame flex items-center justify-center bg-sunken text-info`,children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-7`})}),status:(0,h.jsx)(_S,{tone:`info`,children:`${String(n)} new ${n===1?`topic`:`topics`}`}),title:e.name,detail:`Slopify suggested ${n===1?`a topic`:`${String(n)} topics`} for this schedule. Queue the ones you want and reject the rest.`,action:(0,h.jsx)(fS,{to:`/calendar`,variant:t?`primary`:`secondary`,className:fU,children:`Review topics`})})}function pme({project:e,primary:t}){return(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}),title:x3(e),detail:`You paused this run. Nothing more happens until you open it and press Continue the run.`,action:(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`})})}function mme({project:e,primary:t}){let{api:n}=z(),r=N({queryKey:B.project(e.id),queryFn:()=>jo(n,e.id)}),i=r.data?.stages.find(e=>e.state===`failed`),a=Oy(),o=async e=>{let t=await q1(e);a(t?`Copied ${e}. Run it in a terminal on the computer running Slopify and sign in, then open the project and press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e} in a terminal, sign in, then open the project and press Check again.`,t?`success`:`error`)},s=i===void 0||r.data===void 0?void 0:_3(i,r.data.project),c=BP(i?.failureReason)??`The run stopped with an error.`,l=i===void 0?``:` · ${nF[i.kind]}`,u=t?`primary`:`secondary`,d=s?.kind===`provider-settings`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},variant:u,children:s.label}):s?.kind===`free-space`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`storage`},variant:u,children:s.label}):s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:u,onClick:()=>void o(s.command),children:`Copy sign-in command`}),(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},children:`Open to retry`})]}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:u,children:s?.label??`Open to retry`});return(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`failed`,children:`Failed${l}`}),title:x3(e),detail:s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[c,` Run `,(0,h.jsx)(`code`,{className:`sl-code`,children:s.command}),` in a terminal to sign in, then press Check again on the project to retry the step.`]}):c,action:d})}var hme=[`home`,`week`];function gme(e=new Date){let t=new Date(e);t.setHours(0,0,0,0);let n=(t.getDay()+6)%7;return t.setDate(t.getDate()-n),t}function _me(e,t,n){return ct({queryKey:[...hme,t,n],queryFn:async()=>{let r=new URLSearchParams({since:t});return n!==null&&r.set(`channelId`,n),F(await e.fetch(`${e.origin}/api/home/week?${r.toString()}`))},staleTime:3e4})}async function S3(e,t,n){return F(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/uploaded`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({uploaded:n})}))}function C3(e){return(e.status===`done`||e.status===`partial`)&&e.config.sources.video!==`off`&&e.uploadedAt===null}function vme({project:e}){let{api:t}=z(),n=_(),r=Oy(),i=P({mutationFn:n=>S3(t,e.id,n),onSuccess:(t,n)=>{r(n?`Marked uploaded: ${e.title}. It is off Ready to upload; Projects still lists it.`:`${e.title} is back on Ready to upload.`,`success`)},onError:t=>{r(`${e.title} wasn't marked uploaded: ${t.message} Press Mark uploaded again.`,`error`)},onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});return bx({id:`home.uploaded.${e.id}`,title:`Mark uploaded`,group:`Ready to upload`,context:e.title,keywords:[`youtube`,`published`,`done`],run:()=>i.mutate(!0)}),(0,h.jsxs)(`li`,{className:`sl-home-ready ${dU}`,children:[(0,h.jsx)(v3,{projectId:e.id}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:`${e.format} · finished ${ku(e.updatedAt)}${e.status===`partial`?` · a step failed`:``}`}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(h2,{projectId:e.id,ready:!0,size:`small`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i.isPending,disabledReason:`Saving…`,onClick:()=>i.mutate(!0),children:`Mark uploaded`})]})]})]})}function w3(e){return e.status===`pending`&&e.progress===0}var yme=2;function bme({running:e,queued:t}){let n=e>3;if(!n&&t.length===0)return null;let r=t.slice(0,yme).map(e=>e.title.trim()||`Untitled project`),i=t.length-r.length;return(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n?(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/projects`,search:{show:`running`},children:`See all ${String(e)} running`})}):null,t.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-ink`,children:`Queued, waiting to start (${String(t.length)}): `}),r.join(`, `),i>0?` and ${String(i)} more`:``]}),(0,h.jsx)(pS,{to:`/projects`,search:{show:`queued`},children:`See queued`})]})]})}function T3(e,t){if(e.state!==`running`)return;let n=e.startedAt===null?NaN:Date.parse(e.startedAt),r=Number.isFinite(n)?Math.max(0,(t-n)/1e3):void 0,i=e.progressCurrent??0,a=e.progressTotal??0;if(r!==void 0&&a>0&&i>0)return i>=a?{basis:`progress`,seconds:0}:{basis:`progress`,seconds:Math.round(r/i*(a-i))};let o=e.typicalSeconds;if(o===void 0||!Number.isFinite(o)||o<=0)return{basis:`unknown`};let s=o-(r??0);return s>0?{basis:`history`,seconds:Math.round(s)}:{basis:`overdue`}}function E3(e){if(e.basis===`unknown`)return`time left unknown`;if(e.basis===`overdue`)return`taking longer than usual`;let t=e.seconds??0;if(t<=0)return`finishing up`;if(t<60)return`under a minute left`;let n=Math.round(t/60);if(n<60)return`about ${String(n)} min left`;let r=Math.floor(n/60),i=n%60;return i===0?`about ${String(r)} h left`:`about ${String(r)} h ${String(i)} min left`}function D3(e){let t=e.role.replaceAll(`_`,`-`);return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment!==void 0?`${t}-${e.meta.segment}`:e.role===`short_video`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}`:e.role===`short_image`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}-${String(e.meta.index??1)}`:e.role===`thumbnail`&&e.meta.index!==void 0&&e.meta.index>1?`${t}-${String(e.meta.index)}`:e.role===`instructions`?`${e.stageKind}-${t}`:(e.role===`image`||e.role===`animated_image`)&&e.meta.index!==void 0?`${t}-${String(e.meta.index)}`:t}function O3({steps:e,label:t,dense:n=!1,className:r}){return(0,h.jsx)(`ol`,{"aria-label":t,className:L(`sl-steps m-0 list-none p-0`,n&&`sl-steps--dense`,r),children:e.map(e=>(0,h.jsxs)(`li`,{className:`sl-step`,"data-tone":e.tone,children:[(0,h.jsx)(gS,{tone:e.tone}),(0,h.jsxs)(`span`,{className:`sl-step__name`,children:[e.name,(0,h.jsx)(`span`,{className:`sr-only`,children:`, ${e.state}`})]}),(0,h.jsx)(`span`,{className:`sl-step__time`,children:e.time??`—`}),e.detail===void 0?null:(0,h.jsx)(`span`,{className:`sl-step__detail`,children:e.detail})]},e.id))})}function k3(e){let{api:t}=z();return N({...Xy(t,e),enabled:!1,select:e=>e.revisionId??null}).data??null}var A3=(e,t=null)=>[`live-writing`,e,t];function xme(e,t){let n=e=>e.callId===t.callId&&e.revisionId===t.revisionId&&e.workId===t.workId,r=e.find(n),i=(t.reset?t.text:`${r?.text??``}${t.text}`).slice(-65536),a={...t.revisionId===void 0?{}:{revisionId:t.revisionId},...t.workId===void 0?{}:{workId:t.workId},...t.workPieceId===void 0?{}:{workPieceId:t.workPieceId},stage:t.stage,callId:t.callId,...t.label===void 0?{}:{label:t.label},text:i};return(r?e.map(e=>n(e)?a:e):[...e,a]).slice(-24)}function j3({projectId:e,stage:t,className:n=`mx-5 mt-5`}){let r=(N({queryKey:A3(e,k3(e)),queryFn:()=>[],enabled:!1}).data??[]).filter(e=>e.stage===t),[i,a]=(0,m.useState)(),o=r.find(e=>e.callId===i)??r.at(-1),[s,c]=(0,m.useState)(!0),l=(0,m.useRef)(null);return(0,m.useEffect)(()=>{o?.text&&s&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},[s,o?.text]),r.length===0&&t!==`research`&&t!==`article`?null:(0,h.jsxs)(`div`,{className:L(`border-y border-line`,n),children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-line py-3`,...Ob,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-accent-ink`,children:`Live writing`}),(0,h.jsx)(V,{id:`project.live.writing`})]}),r.length>1?(0,h.jsx)(TV,{"aria-label":`Live writing task`,value:o?.callId??``,onChange:e=>a(e.target.value),className:`max-w-[280px]`,children:r.map((e,t)=>(0,h.jsxs)(`option`,{value:e.callId,children:[e.label??`Writing`,` · `,t+1]},e.callId))}):null,(0,h.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Follow output`]})]}),(0,h.jsx)(`section`,{ref:l,"aria-label":`Live writing preview`,tabIndex:0,className:`max-h-[360px] min-h-32 overflow-auto whitespace-pre-wrap break-words py-4 font-sans text-small leading-relaxed text-ink-2`,children:o?.text||`Waiting for the provider's first text…`}),(0,h.jsx)(`p`,{className:`border-t border-line py-2 text-label text-ink-3`,children:`Live preview. The complete output is saved when this stage finishes.`})]})}var Sme=q({id:W(),projectId:W(),revisionId:W(),itemKey:W(),stage:J(Ck),itemFingerprint:W(),reviewFingerprint:W(),passed:GD(),reasons:K(W()),outcome:J([`passed`,`flagged`,`redo`]),attempt:G(),action:J([`overruled`,`redone`]).nullable(),actionAt:W().nullable(),redoState:J([`pending`,`started`,`failed`]).nullable(),redoError:W().nullable(),createdAt:W(),current:GD(),outputId:W().nullable(),verdicts:G()}),M3=e=>[`reviews`,e],Cme=q({title:W(),detail:W().optional()});async function wme(e,t){let n=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews`);if(!n.ok)throw po(n,void 0);return So(q({reviews:K(Sme)}),await n.json()).reviews}async function Tme(e,t,n,r,i){let a=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews/${encodeURIComponent(n)}/${r}`,{method:`POST`,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}});if(a.ok)return{ok:!0};let o;try{o=await a.json()}catch{throw po(a,void 0)}let s=Cme.safeParse(o);if(!s.success||![400,404,409,503].includes(a.status))throw po(a,void 0);return{ok:!1,message:s.data.detail??s.data.title}}var Eme=200;function N3(e,t=null){let{api:n,openEvents:r}=z(),i=_();(0,m.useEffect)(()=>{i.setQueryData(B.article(e,t),``),i.setQueryData(A3(e,t),[]);let a=()=>i.getQueryData(B.project(e))?.revisionId??null,o=kB(()=>{i.invalidateQueries({queryKey:B.project(e)}),i.invalidateQueries({queryKey:B.projects}),i.invalidateQueries({queryKey:d3(e)}),i.invalidateQueries({queryKey:M3(e)})},Eme),s=AS(r,Hs(n,`projects/${e}`),{refetch:o.ask,accept:e=>e.type===`project.updated`||e.type===`project.state`&&e.revisionId===void 0||(e.revisionId??null)===a()||(o.ask(),!1),previewWriting:t=>{i.setQueryData(A3(e,a()),e=>xme(e??[],t))},narrationPiece:()=>{i.invalidateQueries({queryKey:Py(e,a())})},appendArticle:t=>{i.setQueryData(B.article(e,a()),e=>`${e??``}${t}`)},patch:t=>{if(t.type===`stage.state`&&t.state===`running`&&(i.setQueryData(A3(e,a()),e=>(e??[]).filter(e=>e.stage!==t.stage||e.workId!==t.workId||e.revisionId!==t.revisionId)),t.stage===`article`&&i.setQueryData(B.article(e,a()),``)),t.type!==`project.state`&&t.workId!==void 0){o.ask();return}i.setQueryData(B.project(e),e=>DB(e,t))}});return()=>{s(),o.stop()}},[n,r,i,e,t])}var Dme={pending:`off`,running:`running`,done:`done`,provided:`done`,failed:`failed`,canceled:`off`,skipped:`off`},Ome={pending:`Not started`,running:`Running`,done:`Done`,provided:`Provided`,failed:`Failed`,canceled:`Canceled`,skipped:`Skipped`};function kme(e,t,n){if(e===null)return;let r=(t===null?n:Date.parse(t))-Date.parse(e);if(!Number.isFinite(r)||r<0)return;let i=Math.round(r/1e3);if(i<60)return`${String(i)} s`;let a=Math.round(i/60);if(a<60)return`${String(a)} min`;let o=Math.floor(a/60);return`${String(o)} h ${String(a%60)} min`}function Ame(e,t){let n=T3(e,t);if(n!==void 0)return`${e.progressTotal!==null&&e.progressTotal>0?`${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)} · `:``}${E3(n)}`}function jme({project:e,now:t}){let{api:n}=z();N3(e.id);let[r,i]=(0,m.useState)(null),a=N(Xy(n,e.id)),o=(a.data?.stages??[]).filter(e=>e.source!==`off`&&e.state!==`skipped`),s=(a.data?.outputs??[]).filter(e=>e.role===`image`).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),c=o.find(e=>e.kind===`images`&&e.state===`running`),l=o.find(e=>e.state===`running`),u=YH(e.limitWaits),d=s.slice(c===void 0?-4:-3),f=o.map(n=>({id:n.kind,name:iF(n.kind,e.config),tone:Dme[n.state],state:Ome[n.state],time:kme(n.startedAt,n.finishedAt,t),detail:Ame(n,t)}));return(0,h.jsxs)(`li`,{className:`sl-home-run ${dU}`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),e.status===`paused`?(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}):u===void 0?(0,h.jsx)(_S,{tone:`running`,children:l===void 0?`Running`:`${iF(l.kind,e.config)}`}):(0,h.jsx)(_S,{tone:`waiting`,children:u})]}),d.length===0&&c===void 0?null:(0,h.jsxs)(B0,{list:!0,density:`compact`,label:`Images of ${e.title}`,children:[d.map((t,r)=>(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,onOpen:()=>i(r)})},t.id)),c===void 0?null:(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{alt:`The next image`,generating:`Drawing · ${String(s.length)} so far`})})]}),(0,h.jsx)(V0,{items:d.map(t=>({src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,...t.meta.prompt===void 0?{}:{caption:t.meta.prompt}})),index:r,onIndex:i,onClose:()=>i(null)}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Images ${String(c.progressCurrent??s.length)} of ${String(c.progressTotal??`?`)}`})]}),(0,h.jsx)(O3,{steps:f,label:`Steps of ${e.title}`})]})}var P3=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2});function Mme(e){return`spent${e.apiEquivalent===null?``:` · ~${P3.format(e.apiEquivalent)} via API`}${e.unpriced===0?``:` · ${String(e.unpriced)} ${e.unpriced===1?`call`:`calls`} without a price`}`}function Nme({channelId:e}){let{api:t}=z(),n=N(_me(t,gme().toISOString(),e));if(n.error!==null)return(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`This week's numbers didn't load: ${n.error.message} Reload the page to try again.`});let r=n.data;return(0,h.jsxs)(G2,{className:`sl-home-stats`,children:[(0,h.jsx)(K2,{value:r===void 0?`—`:String(r.videos),label:`videos made`}),(0,h.jsx)(K2,{value:r===void 0?`—`:P3.format(r.cost),label:r===void 0?`spent`:Mme(r)}),(r?.plans??[]).filter(e=>e.weeklyPercent!==null).map(e=>{let t=Math.round(e.weeklyPercent??0);return(0,h.jsx)(K2,{value:`${String(t)}%`,label:`weekly ${e.name} limit`,children:(0,h.jsx)(q2,{value:t/100,label:`Weekly ${e.name} limit`,valueText:`${String(t)}% of your weekly ${e.name} limit`,tone:t>=80?`waiting`:`accent`})},e.account)})]})}var Pme=864e5,Fme=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`}),F3=4,I3=!1,L3=!1;function Ime(){let{api:e}=z(),t=gx(),n=N(Yy(e)),r=N(EH(e)),i=N(Hq(e)),[a]=(0,m.useState)(()=>{let e=new Date;return e.setHours(0,0,0,0),{from:new Date().toISOString(),to:new Date(e.valueOf()+8*Pme).toISOString()}}),o=N(KH(e,a.from,a.to)),s=N({queryKey:My,queryFn:()=>Iy(e)}),c=Zi();(0,m.useEffect)(()=>{s.data?.show===!0&&!I3&&(I3=!0,c({to:`/welcome`}))},[s.data?.show,c]),(0,m.useEffect)(()=>{s.data?.settle===!0&&!L3&&(L3=!0,Ly(e).catch(()=>{L3=!1}))},[s.data?.settle,e]);let[l,u]=(0,m.useState)(()=>Date.now());(0,m.useEffect)(()=>{let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[]);let d=(0,m.useMemo)(()=>new Map((i.data??[]).map(e=>[e.id,e.channelId])),[i.data]),f=(n.data?.projects??[]).filter(e=>t.includes(e.channelId)),p=f.filter(e=>e.status===`running`),g=f.filter(w3),_=f.filter(e=>e.status===`paused`),v=f.filter(y3),y=f.filter(e=>e.status===`failed`),b=new Set(Object.values(s.data?.samples??{}).filter(e=>e!==null)),x=f.filter(e=>C3(e)&&!b.has(e.id)),S=(r.data??[]).filter(e=>e.deletedAt===null&&e.topicGeneration.mode===`hold`&&e.topics.held>0&&t.includes(d.get(e.templateId))),C=(o.data?.runs??[]).filter(e=>t.includes(d.get(e.templateId))),w=[...v.map(e=>({kind:`waiting`,project:e})),..._.map(e=>({kind:`paused`,project:e})),...S.map(e=>({kind:`held`,schedule:e})),...y.slice(0,F3).map(e=>({kind:`failed`,project:e}))],T=n.isPending;return(0,h.jsxs)(`div`,{"data-tour":`home`,children:[(0,h.jsx)(kq,{display:!0,crumb:Fme.format(new Date),title:t.channel?.name??`Home`,meta:t.channelId===null?`Every channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(fS,{to:`/play`,variant:`secondary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]}),(0,h.jsxs)(fS,{to:`/calendar`,variant:`quiet`,children:[(0,h.jsx)(sc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open calendar`]})]})}),(0,h.jsxs)(`div`,{className:`mb-5 flex items-end gap-1 md:hidden`,...Ob,children:[(0,h.jsx)(_x,{className:`min-w-0 flex-1`}),(0,h.jsx)(V,{id:`home.channel`,className:`mb-1`})]}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-5 text-danger`,children:`Your projects didn't load: ${n.error.message} Check that Slopify is still running, then reload the page.`}),(0,h.jsxs)(e0,{split:`main-side`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(H,{title:`Needs you`,info:`home.needs-you`,meta:T?`Loading…`:w.length===0?`Nothing is waiting for a decision`:`${String(w.length)} ${w.length===1?`thing is`:`things are`} waiting for you`}),w.length===0?null:(0,h.jsx)(`ul`,{"aria-label":`Waiting for you`,className:`m-0 flex list-none flex-col gap-3 p-0`,children:w.map((e,t)=>e.kind===`waiting`?(0,h.jsx)(dme,{project:e.project,primary:t===0},e.project.id):e.kind===`paused`?(0,h.jsx)(pme,{project:e.project,primary:t===0},e.project.id):e.kind===`held`?(0,h.jsx)(fme,{schedule:e.schedule,primary:t===0},e.schedule.id):(0,h.jsx)(mme,{project:e.project,primary:t===0},e.project.id))})]}),(0,h.jsxs)(`section`,{id:`running`,"aria-label":`Running now`,children:[(0,h.jsx)(H,{title:`Running now`,info:`home.running`,meta:p.length===0?`Nothing is running`:`${String(p.length)} ${p.length===1?`video`:`videos`}`}),p.length===0?T||g.length>0?null:(0,h.jsx)(a0,{title:`Start the next video`,children:`Pick a template and a topic on Play, or let a schedule start one.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:p.slice(0,3).map(e=>(0,h.jsx)(jme,{project:e,now:l},e.id))}),(0,h.jsx)(bme,{running:p.length,queued:g})]})]}),(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Coming up`,children:[(0,h.jsx)(H,{title:`Coming up`,info:`home.coming-up`,meta:`Next 7 days`,children:(0,h.jsx)(pS,{to:`/calendar`,children:`Calendar`})}),o.error===null?C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading…`:`No scheduled runs this week. Plan some on the calendar.`}):(0,h.jsx)(ime,{runs:C.slice(0,6)}):(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The calendar didn't load: ${o.error.message} Reload the page to try again.`})]}),(0,h.jsxs)(`section`,{"aria-label":`Ready to upload`,children:[(0,h.jsx)(H,{title:`Ready to upload`,info:`home.ready`,meta:x.length===0?`Finished videos you haven't marked uploaded show here`:`${String(x.length)} finished and not marked uploaded`}),x.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:x.slice(0,F3).map(e=>(0,h.jsx)(vme,{project:e},e.id))})]}),(0,h.jsxs)(`section`,{"aria-label":`This week`,children:[(0,h.jsx)(H,{title:`This week`,info:`home.this-week`,meta:`Since Monday`}),(0,h.jsx)(Nme,{channelId:t.channelId})]})]})]})]})}function R3({className:e,...t}){return(0,h.jsx)(`input`,{"data-slot":`input`,className:L(`h-8 w-full min-w-0 rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,`placeholder:text-ink-3 aria-invalid:border-danger`,e),...t})}var Lme={written:``,spoken:``,wholeWord:!0,caseSensitive:!1};function Rme(){let{api:e}=z(),t=_(),n=N(ab(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)({}),[s,c]=(0,m.useState)(),l=(0,m.useRef)(0),u=(0,m.useId)(),d=e=>e.map(e=>(l.current+=1,{...e,key:l.current}));(0,m.useEffect)(()=>{r===void 0&&n.data!==void 0&&i(d(n.data.aliases))});let f=r??[],p=P({mutationFn:t=>Bs(e,t),onSuccess:async e=>{if(!e.ok){let t={};for(let n of e.fields){let e=/^aliases\.(\d+)/u.exec(n.field)?.[1];e!==void 0&&(t[Number(e)]=n.message)}o(t),c({text:`Not saved: ${e.fields.map(e=>e.message).join(` `)}`,tone:`error`});return}o({}),i(d(e.value.aliases)),c({text:`Saved. New projects use these aliases; a project you already started keeps its copy until you refresh it in Edit project.`,tone:`success`}),await t.invalidateQueries({queryKey:B.narrationAliases})},onError:e=>c({text:`Couldn't save the aliases: ${e.message}`,tone:`error`})});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B4,{action:(0,h.jsxs)(R,{type:`button`,onClick:()=>{l.current+=1,i([...f,{...Lme,key:l.current}]),c(void 0)},disabled:r===void 0,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add alias`]}),children:(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Words the narrator says differently, like Dr. as Doctor.`,(0,h.jsx)(V,{id:`library.aliases`})]})}),n.error===null?null:(0,h.jsxs)(SI,{tone:`danger`,title:`Couldn't load the aliases`,className:`mb-6`,children:[n.error.message,` Reload the page to try again.`]}),(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsx)(t0,{label:`Aliases`,children:r===void 0?null:f.length===0?(0,h.jsx)(a0,{title:`No aliases yet`,children:`Use Add alias to say a word differently from how it is written.`}):(0,h.jsx)(zme,{rows:f,errors:a,idPrefix:u,update:(e,t)=>{i(f.map(n=>n.key===e?{...n,...t}:n)),c(void 0)},remove:e=>{i(f.filter(t=>t.key!==e)),o({}),c(void 0)}})}),(0,h.jsx)(t0,{as:`aside`,label:`How aliases are used`,children:(0,h.jsxs)(`section`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(H,{title:`How they are used`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`The narrator reads the alias instead of the written word. The article, the captions and the PDF keep the written word.`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`A project takes a copy of this list when it starts and uses it while Use narration aliases is on. A project you already started keeps its copy until you refresh it in Edit project.`}),(0,h.jsx)(`p`,{className:`m-0`,children:`Whole word skips matches inside longer words; Match case only matches the exact capitals.`})]})})]}),(0,h.jsx)($1,{status:(0,h.jsx)(Q1,{tone:s?.tone??`info`,children:s?.text}),children:(0,h.jsx)(R,{type:`button`,variant:`primary`,disabled:r===void 0||p.isPending,onClick:()=>p.mutate(f.map(({written:e,spoken:t,wholeWord:n,caseSensitive:r})=>({written:e,spoken:t,wholeWord:n,caseSensitive:r}))),children:p.isPending?`Saving…`:`Save aliases`})})]})}function zme({rows:e,errors:t,idPrefix:n,update:r,remove:i}){return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-4 gap-y-1 pb-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Written`,(0,h.jsx)(V,{id:`library.aliases.written`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Say it as`,(0,h.jsx)(V,{id:`library.aliases.spoken`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Whole word`,(0,h.jsx)(V,{id:`library.aliases.whole-word`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Match case`,(0,h.jsx)(V,{id:`library.aliases.match-case`})]})]}),(0,h.jsx)(pU,{label:`Narration aliases`,children:e.map((e,a)=>{let o=`${n}-${e.key}`,s=t[a],c=e.written.trim(),l=e.spoken.trim();return(0,h.jsx)(mU,{title:`Alias ${String(a+1)}`,meta:c===``||l===``?`Not filled in yet`:`Says ${c} as ${l}${e.wholeWord?` · whole word`:``}${e.caseSensitive?` · match case`:``}`,actions:(0,h.jsx)(wy,{size:`small`,label:`Remove alias ${String(a+1)}`,onClick:()=>i(e.key),children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto_auto] md:items-end`,children:[(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-written`,children:[`Written`,(0,h.jsx)(R3,{id:`${o}-written`,value:e.written,placeholder:`Dr.`,maxLength:200,"aria-invalid":s!==void 0,"aria-describedby":s===void 0?void 0:`${o}-error`,onChange:t=>r(e.key,{written:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-spoken`,children:[`Say it as`,(0,h.jsx)(R3,{id:`${o}-spoken`,value:e.spoken,placeholder:`Doctor`,maxLength:500,"aria-invalid":s!==void 0,onChange:t=>r(e.key,{spoken:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.wholeWord,onChange:t=>r(e.key,{wholeWord:t.target.checked})}),`Whole word`]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.caseSensitive,onChange:t=>r(e.key,{caseSensitive:t.target.checked})}),`Match case`]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${o}-error`,className:`m-0 text-small text-danger md:col-span-4`,children:s})]})},e.key)})})]})}function z3(e){return dq(e).names}function Bme(e,t){let n=z3(e),r=Object.create(null);for(let[e,i]of Object.entries(t))r[e]=n.includes(e)?``:i;return r}function Vme(e){return{...e,form:{...e.form,values:Bme(e.form.title,e.form.values)},variants:[]}}function B3({onDefaults:e}){let{api:t}=z(),n=_(),r=N({queryKey:H1.firstRun,queryFn:()=>fde(t),retry:!1,staleTime:1/0}),i=r.data?.defaults;(0,m.useEffect)(()=>{i!==void 0&&(vN(i),e?.(i))},[i,e]);let a=P({mutationFn:()=>pde(t),onSuccess:()=>n.invalidateQueries({queryKey:H1.firstRun})}),o=r.data;if(o===void 0||!o.firstRun||o.message===null)return null;let s=o.detected.filter(e=>e.usable);return(0,h.jsxs)(SI,{title:o.message,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:a.isPending,onClick:()=>a.mutate(),children:`Got it`}),children:[o.detail===null?null:(0,h.jsx)(`p`,{className:`m-0`,children:o.detail}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0`,children:[`Found:`,` `,s.map(e=>`${e.displayName}${e.version===void 0?``:` ${e.version}`}`).join(`, `)]}),a.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:a.error.message}):null]})}function V3(){let{api:e}=z(),{document:t}=rP(),n=N(Hq(e)),r=t.templateSource,i=n.data?.find(e=>e.id===r?.id);return t.channelId??(i===void 0?`00000000-0000-4000-8000-000000000001`:o0(i))}function H3(){let{api:e}=z();return N(Qb(e,V3())).data?.cast??[]}function Hme({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),{document:i}=n,a=V3(),o=r.data?.find(e=>e.id===a),s=i.form.useBrandKit!==!1,c=e=>{n.edit(e),n.invalidateReview(!0)};return(0,h.jsxs)(`div`,{className:`sl-fields items-end`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,children:(0,h.jsxs)(TV,{"data-play-field":`channelId`,value:a,disabled:e,onChange:e=>c({...i,channelId:e.target.value}),children:[r.data===void 0?(0,h.jsx)(`option`,{value:a,children:`Loading channels…`}):null,(r.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsx)(kb,{label:`Use the channel's brand kit`,tip:`play.brand-kit`,checked:s,disabled:e,className:`min-h-[38px]`,onChange:e=>{let{useBrandKit:t,...n}=i.form;c({...i,form:e?n:{...n,useBrandKit:!1}})}}),o?(0,h.jsxs)(`p`,{className:`sl-fields__wide m-0 text-small text-ink-3`,children:[(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:o.id},className:`underline`,children:[`Edit `,o.name]}),s?``:` · its cast is still used`]}):null]})}function U3(){let{api:e}=z(),{document:t}=rP(),n=N(Zb(e)),r=V3(),i=n.data?.find(e=>e.id===r);return t.form.language??i?.brand.language??`en`}function Ume({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),i=V3(),a=r.data?.find(e=>e.id===i),{document:o}=n;return(0,h.jsx)(`div`,{children:(0,h.jsx)(k2,{value:o.form.language,inherited:{label:`Channel's language`,language:a?.brand.language},disabled:e,onChange:e=>{let{language:t,...r}=o.form;n.edit({...o,form:e===void 0?r:{...r,language:e}}),n.invalidateReview(!0)}})})}var W3=[{stage:`audio`,label:`Audio`},{stage:`images`,label:`Images`},{stage:`video`,label:`Video / export`}];function Wme(e,t){if(e===`reviews`||e.startsWith(`reviews.`))return{section:`review`,field:e};if(e!==`checkpoints`&&!e.startsWith(`checkpoints.`))return;let n=e.slice(12),r=/^\d+$/.test(n)?t.checkpoints?.[Number(n)]:n;return{section:`review`,field:W3.some(e=>e.stage===r)?`checkpoints.${r}`:`checkpoints`}}function Gme({problem:e}){let t=rP(),{document:n,review:r}=t,{form:i}=n,a=(0,m.useId)(),o=i.checkpoints??[];return(0,h.jsxs)(`fieldset`,{"data-play-field":`checkpoints`,tabIndex:-1,"aria-invalid":e(`checkpoints`)!==void 0,disabled:r.starting||r.uncertain,className:`min-w-0 rounded-media border border-line px-3 pt-1 pb-2`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`flex items-center gap-1 px-1 font-semibold`,children:[`Review checkpoints`,(0,h.jsx)(V,{id:`play.checkpoints`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-6`,children:W3.map(({stage:r,label:s})=>{let c=o.includes(r),l=r===`video`?i.sources.video!==`off`&&i.sources.images!==`off`||i.sources.audio!==`off`:i.sources[r]===`generate`,u=e(`checkpoints.${r}`),d=`${a}-${r}`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:d,className:`flex min-h-10 items-center gap-3 max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:d,type:`checkbox`,"data-play-field":`checkpoints.${r}`,"aria-invalid":u!==void 0,"aria-describedby":`${d}-detail`,checked:c,disabled:!l&&!c,className:`size-4 accent-accent`,onChange:e=>{let a=e.target.checked?[...o,r]:o.filter(e=>e!==r);t.edit({...n,form:{...i,checkpoints:a}}),t.invalidateReview(!0)}}),`Before `,s]}),(0,h.jsx)(`p`,{id:`${d}-detail`,className:u||c&&!l?`pl-7 text-small text-danger`:`sr-only`,children:u??(l?`Approval required before this step and its dependents run.`:c?`This step is unavailable. Remove its checkpoint or enable the step.`:r===`video`?`Enable Video or Audio to review before export.`:`Choose Generate for ${s} to add this checkpoint.`)})]},r)})}),e(`checkpoints`)?(0,h.jsx)(`p`,{className:`text-small text-danger`,children:e(`checkpoints`)}):null]})}function G3({id:e,value:t,disabled:n,className:r,field:i,onChange:a}){let{api:o}=z(),s=N(ib(o)).data?.themes??[],c=t?.custom,l=c===void 0?void 0:s.find(e=>e.id===c.id),u=c!==void 0&&(l===void 0||l.name!==c.name||JSON.stringify(l.values)!==JSON.stringify(c.values)),d=c===void 0&&JS(t)===`dicemaster`,f=c===void 0?`builtin:${JS(t)}`:u?`kept`:`custom:${c.id}`;return(0,h.jsxs)(DV,{id:e,"data-play-field":i,className:r,disabled:n,value:f,onChange:e=>{let n=e.target.value;if(n===`kept`)return;if(n.startsWith(`builtin:`)){let e=WS.find(e=>`builtin:${e}`===n);e!==void 0&&a({theme:e});return}let r=s.find(e=>`custom:${e.id}`===n);r!==void 0&&a({theme:JS(t),custom:{id:r.id,name:r.name,values:r.values}})},children:[(0,h.jsxs)(`optgroup`,{label:`Built in`,children:[WS.map(e=>(0,h.jsx)(`option`,{value:`builtin:${e}`,children:qS[e]},e)),d?(0,h.jsx)(`option`,{value:`builtin:${GS}`,children:`${qS[GS]} (retired, this project's look)`}):null]}),s.length===0&&!u?null:(0,h.jsxs)(`optgroup`,{label:`Your themes`,children:[u?(0,h.jsx)(`option`,{value:`kept`,children:`${c.name} (this project's copy)`}):null,s.map(e=>(0,h.jsx)(`option`,{value:`custom:${e.id}`,children:u&&l?.id===e.id?`${e.name} (current version)`:e.name},e.id))]})]})}function K3({label:e,field:t,hideLabel:n=!1,value:r,options:i,className:a,tip:o,onPick:s}){let c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:L(`inline-flex items-center gap-3`,a),...o===void 0?{}:Ob,children:[(0,h.jsx)(X4,{id:c,className:n?`sr-only`:`shrink-0`,children:e}),(0,h.jsx)(Z4,{type:`single`,value:r,"aria-labelledby":c,onValueChange:e=>{let t=i.find(t=>t.value===e);t!==void 0&&t.disabled!==!0&&s(t.value)},children:i.map(e=>(0,h.jsx)(Q4,{value:e.value,"data-play-field":e.value===r?t:void 0,disabled:e.disabled===!0,children:e.label},e.value))}),o===void 0?null:(0,h.jsx)(V,{id:o,label:e,className:`-ml-1`})]})}function q3({value:e,onPick:t,rawCounts:n}){let r=e.words??500,i=e.characters??3e3,a=e.mode===`words`||e.mode===`characters`,o=e.mode===`characters`,s=o?e.characters:e.words;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(K3,{field:`chunking.mode`,label:`Chunking`,tip:`play.chunking`,className:`min-w-0 max-w-full flex-wrap [&_[data-slot=toggle-group]]:max-w-full [&_[data-slot=toggle-group]]:flex-wrap`,value:e.mode,options:[{value:`whole`,label:`Whole`},{value:`paragraph`,label:`Paragraph`},{value:`words`,label:`Every ${String(n?.words??r)} words`},{value:`characters`,label:`Every ${String(n?.characters??i)} characters`}],onPick:e=>{if(n){n.onChange(e,e===`characters`?n.characters:n.words);return}t(e===`words`?{mode:e,words:r}:e===`characters`?{mode:e,characters:i}:{mode:e})}}),a?(0,h.jsx)(PV,{label:o?`Characters`:`Words`,tip:`play.chunking.count`,problem:void 0,children:({id:r})=>(0,h.jsx)(CV,{id:r,"data-play-field":o?`chunking.characters`:`chunking.words`,type:n?`text`:`number`,min:1,max:o?1e6:1e4,inputMode:`numeric`,className:`sl-input--number`,value:n?o?n.characters:n.words:s===void 0?``:String(s),onChange:r=>{if(n){n.onChange(e.mode,r.target.value);return}let i=Number.parseInt(r.target.value,10),a=Number.isFinite(i)&&i>0;t(o?a?{mode:`characters`,characters:Math.min(i,1e6)}:{mode:`characters`}:a?{mode:`words`,words:Math.min(i,1e4)}:{mode:`words`})}})}):null]})}var J3=1;function Y3({prompts:e,picked:t,problem:n,onPick:r,rawNumbers:i}){let a=(0,m.useId)(),o=t.reduce((e,t)=>e+t.number,0),s=t.filter(t=>!e.some(e=>e.name===t.name)),c=[...e.map(e=>({name:e.name,missing:!1})),...s.map(e=>({name:e.name,missing:!0}))];return c.length===0?(0,h.jsx)(`p`,{className:`sl-fields__wide basis-full text-small text-ink-3`,children:`No image prompts saved. Write one on Prompts.`}):(0,h.jsxs)(`div`,{className:`sl-fields__wide flex w-full basis-full flex-col gap-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{id:a,className:`engraved text-ink-3`,children:`Image prompts`}),(0,h.jsx)(V,{id:`play.image-prompts`,className:`-my-1`})]}),(0,h.jsx)(`ul`,{"aria-labelledby":a,className:`m-0 grid w-full list-none grid-cols-[repeat(auto-fill,minmax(min(100%,15rem),1fr))] gap-x-6 gap-y-2 p-0`,children:c.map(e=>{let a=t.findIndex(t=>t.name===e.name),o=a===-1?void 0:t[a];return(0,h.jsxs)(`li`,{children:[e.missing?(0,h.jsx)(`span`,{className:`block text-label text-danger`,children:`Missing template · untick to remove`}):null,(0,h.jsx)(Kme,{name:e.name,number:o?.number,rawNumber:i?{value:i.values.find(t=>t.name===e.name)?.number??``,onChange:t=>i.onChange(e.name,t)}:void 0,problem:a===-1?void 0:n(`imagePrompts.${String(a)}.number`),onTick:n=>{r(n?[...t,{name:e.name,number:J3}]:t.filter(t=>t.name!==e.name))},onNumber:n=>{r(t.map(t=>t.name===e.name?{name:t.name,number:n}:t))}})]},e.name)})}),t.length===0?null:(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:Number.isFinite(o)?`${String(o)} of 60 images`:`Complete image counts to see the total`})]})}function Kme({name:e,number:t,problem:n,onTick:r,onNumber:i,rawNumber:a}){let o=(0,m.useId)(),s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex w-full min-w-0 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:o,"data-play-field":`imagePrompts`,type:`checkbox`,checked:t!==void 0,className:`size-[14px] shrink-0 accent-accent`,onChange:e=>{r(e.target.checked)}}),(0,h.jsx)(`label`,{htmlFor:o,title:e,className:L(`min-w-0 flex-1 truncate`,t===void 0?`text-ink-3`:`text-ink`),children:e}),(0,h.jsx)(X4,{htmlFor:s,className:`sr-only`,children:`Number for ${e}`}),(0,h.jsx)(CV,{id:s,"data-play-field":`imagePrompts.${e}.number`,type:a?`text`:`number`,min:J3,max:20,inputMode:`numeric`,disabled:t===void 0,"aria-invalid":n!==void 0,"aria-describedby":n===void 0?void 0:c,className:`sl-input--number`,value:a?.value??(t===void 0||t===0?``:String(t)),onChange:e=>{if(a){a.onChange(e.target.value);return}let t=Number.parseInt(e.target.value,10);i(Number.isFinite(t)?t:0)}}),n===void 0?null:(0,h.jsx)(`span`,{id:c,className:`text-label text-danger`,children:n})]})}var qme=`text-small text-ink-2 file:mr-3 file:h-8 file:rounded-control file:border file:border-line-strong file:bg-raised file:px-3 file:text-ink`;function X3({label:e,field:t,value:n,placeholder:r,problem:i,tip:a,onChange:o}){let s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`div`,{...a===void 0?{}:Ob,children:[(0,h.jsxs)(`span`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:s,children:e}),a===void 0?null:(0,h.jsx)(V,{id:a,label:e,className:`-my-1`})]}),(0,h.jsx)(wV,{id:s,"data-play-field":t,rows:6,value:n,placeholder:r,"aria-invalid":i!==void 0,"aria-describedby":i===void 0?void 0:c,onChange:e=>{o(e.target.value)}}),i===void 0?null:(0,h.jsx)(`p`,{id:c,className:`mt-1 text-label text-danger`,children:i})]})}function Z3({label:e,field:t,accept:n,multiple:r=!1,disabled:i=!1,uploads:a,problem:o,numbered:s=!1,onPick:c,onRemove:l,onReattach:u}){let d=(0,m.useId)(),f=(0,m.useId)();return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(X4,{htmlFor:d,className:`mb-1`,children:e}),(0,h.jsx)(`input`,{id:d,"data-play-field":t,type:`file`,accept:n,multiple:r,disabled:i,"aria-invalid":o!==void 0,"aria-describedby":o===void 0?void 0:f,className:qme,onChange:e=>{c([...e.target.files??[]]),e.target.value=``}}),o===void 0?null:(0,h.jsx)(`p`,{id:f,className:`mt-1 text-label text-danger`,children:o}),a.length===0?null:(0,h.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,children:a.map((e,t)=>(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3`,children:[s?(0,h.jsx)(`span`,{className:`engraved w-6 text-ink-3`,children:String(t+1)}):null,(0,h.jsx)(Jme,{upload:e}),e.error!==void 0&&u?(0,h.jsxs)(`label`,{className:`text-small text-ink-2`,children:[`Reattach`,(0,h.jsx)(`input`,{"aria-label":`Reattach ${e.name}`,className:`max-w-full`,type:`file`,accept:n,onChange:t=>{let n=t.target.files?.[0];t.target.value=``,n&&u(e.key,n)}})]}):null,l===void 0?null:(0,h.jsx)(R,{variant:`quiet`,className:`ml-auto`,"aria-label":`Remove ${e.name}`,onClick:()=>{l(e.key)},children:`Remove`})]},e.key))})]})}function Jme({upload:e}){return(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-3 text-small [overflow-wrap:anywhere]`,children:[(0,h.jsx)(`span`,{className:e.error===void 0?`text-ink`:`text-danger`,children:e.name}),e.error===void 0?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:e.file===void 0?`Copying`:`Staged`}):(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.error})]})}var Q3=`col-span-3 min-w-0 sl-fields`,$3=`col-span-3 min-w-0`;function e6({kind:e,name:t,dim:n,titled:r=!0,children:i}){return(0,h.jsxs)(`section`,{"data-tour":`play-${e}`,className:`grid grid-cols-[24px_1fr_auto] items-center gap-x-2 gap-y-4 border-b border-line py-4 [&>div:empty]:hidden`,children:[r?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(sS,{kind:e,className:n?`text-ink-3`:`text-ink-2`}),(0,h.jsx)(`h3`,{className:L(`m-0 text-title-3`,n?`text-ink-3`:void 0),children:t})]}):(0,h.jsx)(`span`,{className:`sl-field__label col-span-2`,children:`Source`}),i]})}var Yme={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`};function t6({kind:e,form:t,update:n}){return(0,h.jsx)(K3,{field:`sources.${e}`,label:`${e} source`,hideLabel:!0,tip:Yme[e],className:`max-[700px]:col-span-3 max-[700px]:justify-self-start [&_[data-slot=toggle-group]]:flex-wrap`,value:t.sources[e],options:FN(e).filter(n=>e!==`thumbnail`||n.value!==`prompt_by_llm`||t.sources.article!==`off`).map(n=>({...n,disabled:e===`video`&&n.value===`generate`&&t.sources.images===`off`})),onPick:r=>{if(e===`article`&&r===`off`){n(Xme(t));return}n({sources:{...t.sources,[e]:r,...e===`images`&&r===`off`?{video:`off`}:{}}})}})}function n6(e,t){return e.filter(e=>e.kind===t).map(e=>({value:e.name,label:e.name}))}function Xme(e){return{sources:{...e.sources,article:`off`,research:`off`,audio:`off`,document:`off`,...e.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}},subtitles:{...e.subtitles,mode:`off`},youtubeDescription:!1,...e.shorts===void 0?{}:{shorts:{...e.shorts,enabled:!1}}}}function Zme(e){let t=this;t.compiler=n;function n(n){return yle(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}var r6=QR().use(vR).use(Zme).freeze(),i6=`[ˈˌ]?[abdefghijklmnoprstuvwxzæðŋθɑɒɔəɚɛɜɝɡɪɹʃʊʌʒʔɫɾ][\\u0303\\u031a\\u0325\\u0329\\u032a\\u032c\\u032f\\u035c\\u0361ʰʲʷ]*[ːˑ]?`,Qme=RegExp(`^(?:${i6})+(?:\\.(?:${i6})+)*$`,`u`),a6=`[ˈˌ]?[a-zæçðøħŋœɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɪɫɬɭɮɯɰɱɲɳɴɵɶɸɹɺɻɽɾʀʁʂʃʄʈʉʊʋʌʍʎʏʐʑʒʔʕʙʛʜʝʟʡʢβθχ][\\u0300-\\u036fʰʱʲʷʼˠˤ˞]*[ːˑ]?`,$me=RegExp(`^(?:${a6})+(?:\\.(?:${a6})+)*$`,`u`);function o6(e){return e.type===`break`?`
278
- `:e.value??e.children?.map(o6).join(``)??``}function s6(e){if(e.type===`heading`){let t=o6(e).trim();return/^pronunciation glossary:?\s*$/iu.test(t)?[]:[t]}return e.type===`table`?(e.children??[]).slice(1).map(e=>{let t=e.children??[];if(t.length<2)return o6(e);let[n,r]=t.slice(0,2).map(e=>o6(e).trim());return`${n}: ${r!==void 0&&r!==``&&!r.includes(`/`)?`/${r}/`:r}`}):e.type===`paragraph`?o6(e).split(/\r?\n/u):e.type===`root`||e.type===`list`||e.type===`listItem`?(e.children??[]).flatMap(s6):[`(unsupported glossary block)`]}function ehe(e){return Array.from(e,e=>{let t=e.toLowerCase(),n=t.toUpperCase().toLowerCase();if(n===e)return e;let r=RegExp(`^${e.replace(/[|\\{}()[\]^$+*?.]/gu,`\\$&`)}$`,`iu`);return r.test(n)?n:r.test(t)?t:e}).join(``)}function c6(e,t){let n=t===void 0||t===`en`,r=n?Qme:$me,i=n?`standard-English IPA`:`IPA`,a=s6(r6().use(pB).parse(e)),o=new Map,s=[];for(let[e,t]of a.entries()){let a=t=>{s.push({row:e+1,reason:t})},c=t.trim();if(c===``||/^pronunciation glossary:?\s*$/iu.test(c))continue;let l=/^([^:]+):\s*(.+)$/u.exec(c),u=l?.[1]?.trim().replace(/\s+/gu,` `),d=l?.[2];if(u===void 0||d===void 0||!/[\p{L}\p{N}]/u.test(u)||/[/[\]<>\p{Cc}]/u.test(u)){a(`use Term: /IPA/ or a Term | IPA table`);continue}let f=/^(\/[^/]+\/(?:\s+\/[^/]+\/)*)(?:\s+[^/]+)?$/u.exec(d);if(f?.[1]===void 0){a(`use slash-delimited ${i}`);continue}let p=Array.from(f[1].matchAll(/\/([^/]+)\//gu)).flatMap(e=>(e[1]??``).trim().split(/\s+/u));if(p.length===0||p.some(e=>!r.test(e))){a(n?`use standard-English IPA only, not ARPAbet, delivery tags or non-English sounds; give a foreign name an English approximation`:`use IPA, not ARPAbet or delivery tags`);continue}if(u.split(` `).length!==p.length){a(`supply one IPA word for each written word`);continue}let m=ehe(u),h=o.get(m);if(h!==void 0&&h.ipa.join(` `)!==p.join(` `)){a(`an earlier entry already gives this term a different pronunciation`);continue}h===void 0&&o.set(m,{term:u,ipa:p})}return s.length===0?{ok:!0,entries:[...o.values()]}:{ok:!0,entries:[...o.values()],skipped:s}}function the(e,t){return e.flatMap(e=>{if(!e.pronunciations?.trim())return[];let n=c6(e.pronunciations,t),r=n.ok?n.skipped??[]:[];return r.length===0?[]:[{speaker:e.name.trim()||`A speaker`,skipped:r}]})}function nhe(e,t){let n=t?.turns.find(t=>t.speaker===e.id)?.text??rhe(e);if(n.length<=200)return n;let r=n.slice(0,200),i=Math.max(r.lastIndexOf(`. `),r.lastIndexOf(`? `),r.lastIndexOf(`! `));return i>60?r.slice(0,i+1):`${r.slice(0,r.lastIndexOf(` `))}…`}function rhe(e){let t=e.name.trim()||`your speaker`;switch(e.role){case`narrator`:return`The night was quiet, and the old house held its breath. I'm ${t}, and I'll be telling this story.`;case`host`:return`Hi everyone, I'm ${t}, and welcome back to the show. Today's topic is a good one.`;case`guest`:return`Thanks for having me. I'm ${t}, and I've been looking forward to this conversation.`;case`character`:return`You really thought I wouldn't find out? My name is ${t}, and I always find out.`}}function ihe(e){return e.flatMap(e=>e.host===!0&&e.voice!==void 0?[l6(e,`host`)]:[])}function ahe(e){let t=e.toLowerCase();return/^[a-z0-9-]{1,55}$/.test(t)?`cast-${t}`:`cast-h${ohe(e)}`}function ohe(e){let t=3735928559,n=1103547991;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,2654435761),n=Math.imul(n^i,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(4294967296*(2097151&n)+(t>>>0)).toString(36)}function l6(e,t){let n=e.voice;return{id:ahe(e.id),name:e.name.slice(0,40),role:t,voice:n===void 0?{provider:``,model:``,voice:``}:{provider:n.provider,model:n.model,voice:n.voice},...n?.pace===void 0||n.pace===1?{}:{pace:n.pace},...n?.pronunciations?.trim()?{pronunciations:n.pronunciations}:{},castId:e.id,...she(e)}}function she(e){let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null)?.sha256;return t==null?{}:{portrait:t}}var che=/^#{1,6}\s+(.+?)\s*#*\s*$/,lhe=/^\*{0,2}([^:*\n]{1,60}?)\*{0,2}\s*:\s*\*{0,2}\s*(.*)$/;function u6(e,t,n=!1){let r=new Map(t.map(e=>[e.name.trim().toLowerCase(),e])),i=t.map(e=>e.name.trim()).join(`, `),a=[],o=[],s=!1;for(let[t,n]of e.replace(/\r\n?/g,`
277
+ `]}),(0,h.jsx)(wV,{id:e,rows:24,value:t,spellCheck:!1,"aria-invalid":n,"aria-describedby":r,className:L(o3,`relative block min-h-[520px] resize-y border-line-strong overflow-auto bg-transparent text-transparent caret-ink`),onChange:e=>{i(e.target.value)},onScroll:e=>{let t=a.current;t!==null&&(t.scrollTop=e.currentTarget.scrollTop,t.scrollLeft=e.currentTarget.scrollLeft)}})]})}function c3({entryId:e,category:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=N(rb(i)),s=(0,m.useId)(),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),S=o.data?.entries,C=e??n,w=C===void 0?void 0:S?.find(e=>e.id===C),T=w===void 0?{category:t,mode:`text`,name:``,body:``}:{category:w.category,mode:w.mode,name:e===void 0?`${w.name} copy`:w.name,body:w.body},E=d??T,D=P({mutationFn:t=>Ns(i,t,e),onSuccess:async e=>{if(!e.ok){g(e.fields);return}y(!0),await a.invalidateQueries({queryKey:rb(i).queryKey})}}),O=P({mutationFn:e=>Vs(i,e),onSuccess:async()=>{x(!1),await a.invalidateQueries({queryKey:rb(i).queryKey}),r(E.category)}});X2(v,()=>{r(E.category)});let k=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},A=t3(E,p),ee=n3(A),te=a3(E.body),ne=E.body.trim()===``?[]:r3(A),j=E.name.trim()===``?[]:i3(A);return o.error===null?C!==void 0&&S===void 0?(0,h.jsx)($2,{}):C!==void 0&&w===void 0?(0,h.jsx)(l3,{category:t,children:`That entry is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/entries`,search:{category:E.category},children:`Intros & Outros`})}),title:e===void 0?`New entry`:`Edit entry`,meta:dV(E.category)}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{className:`min-w-[200px] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.entry.name`,...j.length===0?{}:{error:j.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:E.name,onChange:e=>{k({...E,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Category`,value:E.category,options:lV,tip:`library.entry.category`,onPick:e=>{k({...E,category:e},`name`)}}),(0,h.jsx)($4,{label:`Mode`,value:E.mode,options:uV,describedBy:s,tip:`library.entry.mode`,onPick:e=>{k({...E,mode:e},`mode`)}})]}),(0,h.jsx)(`p`,{id:s,className:`-mt-2 text-right text-small text-ink-2`,children:pV(E.mode)}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:`library.entry.body`,label:`Body`,className:`-my-1`})]}),(0,h.jsx)(s3,{id:c,value:E.body,invalid:ne.length>0,describedBy:ne.length===0?void 0:l,onChange:e=>{k({...E,body:e},`body`)}})]}),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{x(!0)},blocked:ee,blockedId:u,pending:D.isPending,saved:v,cancel:(0,h.jsx)(fS,{to:`/entries`,search:{category:E.category},variant:`secondary`,children:`Cancel`}),errors:[D.error,O.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{D.mutate(E)}})]}),(0,h.jsx)(`div`,{className:m4,children:(0,h.jsx)(Y4,{slots:te,body:E.body,lint:ne,lintId:l,noSlots:mV(E.mode)})})]}),(0,h.jsx)(jy,{open:b,title:`Delete "${E.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${E.category}`,pending:O.isPending,onConfirm:()=>{e!==void 0&&O.mutate(e)},onCancel:()=>{x(!1)}})]}):(0,h.jsx)(l3,{category:E.category,children:o.error.message})}function l3({category:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/entries`,search:{category:e},children:`Back to Intros & Outros`}),children:t})}var nme=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),rme=new Intl.DateTimeFormat(void 0,{timeStyle:`short`});function ime({runs:e}){return(0,h.jsx)(pU,{label:`Coming up`,children:e.map(e=>(0,h.jsx)(mU,{title:`${nme.format(new Date(e.at))} · ${rme.format(new Date(e.at))} · ${uU(e)}`,meta:[e.scheduleName,e.templateName].filter(e=>e!==null).join(` · `),actions:e.paused?(0,h.jsx)(vS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(vS,{tone:`info`,children:`Needs a topic`}):(0,h.jsx)(vS,{children:`Queued`})},`${e.scheduleId}-${e.at}`))})}var u3=q({revisionId:W(),checkpoints:K(Zj.unwrap().extend({currentFingerprint:W().regex(/^[a-f0-9]{64}$/),dependents:K(J(FS)),workKeys:K(W())}))}),ame=q({revisionId:W().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),stages:K(Xj).max(3).refine(e=>new Set(e).size===e.length).readonly()}).strict(),ome=q({title:W(),status:G(),detail:W().optional(),reason:J([`duplicate`,`not-found`,`conflict`,`invalid-input`]).optional()}),sme=Qj.unwrap().omit({projectId:!0,checkpointId:!0,approvedAt:!0}),d3=e=>[`checkpoints`,e],f3=(e,t)=>[...d3(e),t];async function p3(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=ome.safeParse(n);if(!r.success)throw po(e,void 0);if(![400,404,409].includes(e.status))throw Error(r.data.detail??r.data.title);return{ok:!1,reason:r.data.reason??`invalid-input`,message:r.data.detail??r.data.title}}async function m3(e,t){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`),u3)}async function h3(e,t,n,r){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints/${encodeURIComponent(n)}/approve`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(sme.parse(r))}),q({checkpoint:Zj,replayed:GD()}))}async function cme(e,t,n){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(ame.parse(n))}),u3)}var g3=(0,m.createContext)(void 0);function _3(e,t){if(e.state===`failed`)return V1({stage:e.kind,kind:e.failureKind,reason:e.failureReason,provider:ode(t.config,e.kind)})}var lme=[`home`,`week`];function ume(e=new Date){let t=new Date(e);t.setHours(0,0,0,0);let n=(t.getDay()+6)%7;return t.setDate(t.getDate()-n),t}function dme(e,t,n){return ct({queryKey:[...lme,t,n],queryFn:async()=>{let r=new URLSearchParams({since:t});return n!==null&&r.set(`channelId`,n),F(await e.fetch(`${e.origin}/api/home/week?${r.toString()}`))},staleTime:3e4})}async function fme(e,t,n){return F(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/set-aside`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({setAside:n})}))}async function v3(e,t,n){return F(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/uploaded`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({uploaded:n})}))}function y3({projectId:e,className:t}){let{api:n}=z(),[r,i]=(0,m.useState)(!1);return(0,h.jsx)(`div`,{className:L(`sl-media__frame`,t),"aria-hidden":`true`,children:r?(0,h.jsx)(`div`,{className:`flex size-full items-center justify-center bg-sunken text-ink-3`,children:(0,h.jsx)(bc,{strokeWidth:1.75,className:`size-6`})}):(0,h.jsx)(`img`,{src:Ko(n,e,`thumbnail`),alt:``,loading:`lazy`,decoding:`async`,onError:()=>i(!0)})})}function b3(e){return e.status===`pending`&&e.progress>0&&e.setAside!==!0}function x3({lead:e,status:t,title:n,detail:r,action:i}){return(0,h.jsxs)(`li`,{className:L(`sl-home-item`,dU),children:[e,(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[t,(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:n}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:r})]}),(0,h.jsx)(Ey,{className:`sl-home-item__action`,children:i})]})}function S3(e){return(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}var pme={audio:`Approve the article and record`,images:`Approve and draw the images`,video:`Approve and render`},mme={audio:`review before the narration`,images:`review before the images`,video:`review before the video`};function hme({project:e,primary:t}){let{api:n}=z(),r=_(),i=Oy(),a=Zi(),o=(0,m.useRef)(null),s=N({queryKey:d3(e.id),queryFn:async()=>{let t=await m3(n,e.id);if(!t.ok)throw Error(t.message);return t.value}}).data?.checkpoints.find(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint),c=P({mutationFn:async t=>{o.current??={revisionId:t.revisionId,fingerprint:t.fingerprint,idempotencyKey:crypto.randomUUID()};let r=await h3(n,e.id,t.checkpointId,o.current);return o.current=null,r},onSuccess:t=>{i(t.ok?`Approved: ${e.title}. The run continues.`:`${e.title} wasn't approved: ${t.message} Open the project to review it there.`,t.ok?`success`:`error`)},onError:t=>{i(`Slopify didn't confirm the approval of ${e.title}: ${t.message} Press the button again to check whether it went through.`,`error`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:d3(e.id)}),r.invalidateQueries({queryKey:B.projects})])}}),l=P({mutationFn:t=>fme(n,e.id,t),onSuccess:(t,n)=>{i(n?`Kept as is: ${e.title}. It is off Needs you; editing the project brings it back.`:`${e.title} is back on Needs you.`,`success`,n?{label:`Undo`,run:()=>l.mutate(!1)}:void 0)},onError:t=>{i(`${e.title} wasn't kept as is: ${t.message} Press Keep as is again.`,`error`)},onSettled:()=>r.invalidateQueries({queryKey:B.projects})}),u=s===void 0?void 0:pme[s.stage];return bx({id:`home.approve.${e.id}`,title:u??`Open the held run`,group:`Needs you`,context:e.title,keywords:[`approve`,`review`,`waiting`],run:()=>{s===void 0?a({to:`/projects/$projectId`,params:{projectId:e.id}}):c.mutate(s)}}),(0,h.jsx)(x3,{lead:(0,h.jsx)(y3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:s===void 0?`Waiting for you`:`Waiting for you · ${mme[s.stage]}`}),title:S3(e),detail:s===void 0?`Its next step is held. Open the project to review it and continue the run.`:`Everything before this step is done. Approve to let the run go on, or open the project to look first.`,action:s===void 0||u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`}),(0,h.jsx)(R,{variant:`quiet`,disabled:l.isPending,disabledReason:`Saving…`,onClick:()=>l.mutate(!0),children:`Keep as is`})]}):(0,h.jsx)(R,{variant:t?`primary`:`secondary`,disabled:c.isPending,disabledReason:`Approving…`,onClick:()=>c.mutate(s),children:c.isPending?`Approving…`:u})})}function gme({schedule:e,primary:t}){let n=e.topics.held;return(0,h.jsx)(x3,{lead:(0,h.jsx)(`div`,{className:`sl-media__frame flex items-center justify-center bg-sunken text-info`,children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-7`})}),status:(0,h.jsx)(_S,{tone:`info`,children:`${String(n)} new ${n===1?`topic`:`topics`}`}),title:e.name,detail:`Slopify suggested ${n===1?`a topic`:`${String(n)} topics`} for this schedule. Queue the ones you want and reject the rest.`,action:(0,h.jsx)(fS,{to:`/calendar`,variant:t?`primary`:`secondary`,className:fU,children:`Review topics`})})}function _me({project:e,primary:t}){return(0,h.jsx)(x3,{lead:(0,h.jsx)(y3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}),title:S3(e),detail:`You paused this run. Nothing more happens until you open it and press Continue the run.`,action:(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`})})}function vme({project:e,primary:t}){let{api:n}=z(),r=N({queryKey:B.project(e.id),queryFn:()=>jo(n,e.id)}),i=r.data?.stages.find(e=>e.state===`failed`),a=Oy(),o=async e=>{let t=await q1(e);a(t?`Copied ${e}. Run it in a terminal on the computer running Slopify and sign in, then open the project and press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e} in a terminal, sign in, then open the project and press Check again.`,t?`success`:`error`)},s=i===void 0||r.data===void 0?void 0:_3(i,r.data.project),c=BP(i?.failureReason)??`The run stopped with an error.`,l=i===void 0?``:` · ${nF[i.kind]}`,u=t?`primary`:`secondary`,d=s?.kind===`provider-settings`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},variant:u,children:s.label}):s?.kind===`free-space`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`storage`},variant:u,children:s.label}):s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:u,onClick:()=>void o(s.command),children:`Copy sign-in command`}),(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},children:`Open to retry`})]}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:u,children:s?.label??`Open to retry`});return(0,h.jsx)(x3,{lead:(0,h.jsx)(y3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`failed`,children:`Failed${l}`}),title:S3(e),detail:s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[c,` Run `,(0,h.jsx)(`code`,{className:`sl-code`,children:s.command}),` in a terminal to sign in, then press Check again on the project to retry the step.`]}):c,action:d})}function C3(e){return(e.status===`done`||e.status===`partial`||e.status===`pending`&&e.setAside===!0)&&e.config.sources.video!==`off`&&e.uploadedAt===null}function yme({project:e}){let{api:t}=z(),n=_(),r=Oy(),i=P({mutationFn:n=>v3(t,e.id,n),onSuccess:(t,n)=>{r(n?`Marked uploaded: ${e.title}. It is off Ready to upload; Projects still lists it.`:`${e.title} is back on Ready to upload.`,`success`)},onError:t=>{r(`${e.title} wasn't marked uploaded: ${t.message} Press Mark uploaded again.`,`error`)},onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});return bx({id:`home.uploaded.${e.id}`,title:`Mark uploaded`,group:`Ready to upload`,context:e.title,keywords:[`youtube`,`published`,`done`],run:()=>i.mutate(!0)}),(0,h.jsxs)(`li`,{className:`sl-home-ready ${dU}`,children:[(0,h.jsx)(y3,{projectId:e.id}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:`${e.format} · finished ${ku(e.updatedAt)}${e.status===`partial`?` · a step failed`:``}`}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(h2,{projectId:e.id,ready:!0,size:`small`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i.isPending,disabledReason:`Saving…`,onClick:()=>i.mutate(!0),children:`Mark uploaded`})]})]})]})}function w3(e){return e.status===`pending`&&e.progress===0}var bme=2;function xme({running:e,queued:t}){let n=e>3;if(!n&&t.length===0)return null;let r=t.slice(0,bme).map(e=>e.title.trim()||`Untitled project`),i=t.length-r.length;return(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n?(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/projects`,search:{show:`running`},children:`See all ${String(e)} running`})}):null,t.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-ink`,children:`Queued, waiting to start (${String(t.length)}): `}),r.join(`, `),i>0?` and ${String(i)} more`:``]}),(0,h.jsx)(pS,{to:`/projects`,search:{show:`queued`},children:`See queued`})]})]})}function T3(e,t){if(e.state!==`running`)return;let n=e.startedAt===null?NaN:Date.parse(e.startedAt),r=Number.isFinite(n)?Math.max(0,(t-n)/1e3):void 0,i=e.progressCurrent??0,a=e.progressTotal??0;if(r!==void 0&&a>0&&i>0)return i>=a?{basis:`progress`,seconds:0}:{basis:`progress`,seconds:Math.round(r/i*(a-i))};let o=e.typicalSeconds;if(o===void 0||!Number.isFinite(o)||o<=0)return{basis:`unknown`};let s=o-(r??0);return s>0?{basis:`history`,seconds:Math.round(s)}:{basis:`overdue`}}function E3(e){if(e.basis===`unknown`)return`time left unknown`;if(e.basis===`overdue`)return`taking longer than usual`;let t=e.seconds??0;if(t<=0)return`finishing up`;if(t<60)return`under a minute left`;let n=Math.round(t/60);if(n<60)return`about ${String(n)} min left`;let r=Math.floor(n/60),i=n%60;return i===0?`about ${String(r)} h left`:`about ${String(r)} h ${String(i)} min left`}function D3(e){let t=e.role.replaceAll(`_`,`-`);return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment!==void 0?`${t}-${e.meta.segment}`:e.role===`short_video`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}`:e.role===`short_image`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}-${String(e.meta.index??1)}`:e.role===`thumbnail`&&e.meta.index!==void 0&&e.meta.index>1?`${t}-${String(e.meta.index)}`:e.role===`instructions`?`${e.stageKind}-${t}`:(e.role===`image`||e.role===`animated_image`)&&e.meta.index!==void 0?`${t}-${String(e.meta.index)}`:t}function O3({steps:e,label:t,dense:n=!1,className:r}){return(0,h.jsx)(`ol`,{"aria-label":t,className:L(`sl-steps m-0 list-none p-0`,n&&`sl-steps--dense`,r),children:e.map(e=>(0,h.jsxs)(`li`,{className:`sl-step`,"data-tone":e.tone,children:[(0,h.jsx)(gS,{tone:e.tone}),(0,h.jsxs)(`span`,{className:`sl-step__name`,children:[e.name,(0,h.jsx)(`span`,{className:`sr-only`,children:`, ${e.state}`})]}),(0,h.jsx)(`span`,{className:`sl-step__time`,children:e.time??`—`}),e.detail===void 0?null:(0,h.jsx)(`span`,{className:`sl-step__detail`,children:e.detail})]},e.id))})}function k3(e){let{api:t}=z();return N({...Xy(t,e),enabled:!1,select:e=>e.revisionId??null}).data??null}var A3=(e,t=null)=>[`live-writing`,e,t];function Sme(e,t){let n=e=>e.callId===t.callId&&e.revisionId===t.revisionId&&e.workId===t.workId,r=e.find(n),i=(t.reset?t.text:`${r?.text??``}${t.text}`).slice(-65536),a={...t.revisionId===void 0?{}:{revisionId:t.revisionId},...t.workId===void 0?{}:{workId:t.workId},...t.workPieceId===void 0?{}:{workPieceId:t.workPieceId},stage:t.stage,callId:t.callId,...t.label===void 0?{}:{label:t.label},text:i};return(r?e.map(e=>n(e)?a:e):[...e,a]).slice(-24)}function j3({projectId:e,stage:t,className:n=`mx-5 mt-5`}){let r=(N({queryKey:A3(e,k3(e)),queryFn:()=>[],enabled:!1}).data??[]).filter(e=>e.stage===t),[i,a]=(0,m.useState)(),o=r.find(e=>e.callId===i)??r.at(-1),[s,c]=(0,m.useState)(!0),l=(0,m.useRef)(null);return(0,m.useEffect)(()=>{o?.text&&s&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},[s,o?.text]),r.length===0&&t!==`research`&&t!==`article`?null:(0,h.jsxs)(`div`,{className:L(`border-y border-line`,n),children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-line py-3`,...Ob,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-accent-ink`,children:`Live writing`}),(0,h.jsx)(V,{id:`project.live.writing`})]}),r.length>1?(0,h.jsx)(TV,{"aria-label":`Live writing task`,value:o?.callId??``,onChange:e=>a(e.target.value),className:`max-w-[280px]`,children:r.map((e,t)=>(0,h.jsxs)(`option`,{value:e.callId,children:[e.label??`Writing`,` · `,t+1]},e.callId))}):null,(0,h.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Follow output`]})]}),(0,h.jsx)(`section`,{ref:l,"aria-label":`Live writing preview`,tabIndex:0,className:`max-h-[360px] min-h-32 overflow-auto whitespace-pre-wrap break-words py-4 font-sans text-small leading-relaxed text-ink-2`,children:o?.text||`Waiting for the provider's first text…`}),(0,h.jsx)(`p`,{className:`border-t border-line py-2 text-label text-ink-3`,children:`Live preview. The complete output is saved when this stage finishes.`})]})}var Cme=q({id:W(),projectId:W(),revisionId:W(),itemKey:W(),stage:J(Ck),itemFingerprint:W(),reviewFingerprint:W(),passed:GD(),reasons:K(W()),outcome:J([`passed`,`flagged`,`redo`]),attempt:G(),action:J([`overruled`,`redone`]).nullable(),actionAt:W().nullable(),redoState:J([`pending`,`started`,`failed`]).nullable(),redoError:W().nullable(),createdAt:W(),current:GD(),outputId:W().nullable(),verdicts:G()}),M3=e=>[`reviews`,e],wme=q({title:W(),detail:W().optional()});async function Tme(e,t){let n=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews`);if(!n.ok)throw po(n,void 0);return So(q({reviews:K(Cme)}),await n.json()).reviews}async function Eme(e,t,n,r,i){let a=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews/${encodeURIComponent(n)}/${r}`,{method:`POST`,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}});if(a.ok)return{ok:!0};let o;try{o=await a.json()}catch{throw po(a,void 0)}let s=wme.safeParse(o);if(!s.success||![400,404,409,503].includes(a.status))throw po(a,void 0);return{ok:!1,message:s.data.detail??s.data.title}}var Dme=200;function N3(e,t=null){let{api:n,openEvents:r}=z(),i=_();(0,m.useEffect)(()=>{i.setQueryData(B.article(e,t),``),i.setQueryData(A3(e,t),[]);let a=()=>i.getQueryData(B.project(e))?.revisionId??null,o=kB(()=>{i.invalidateQueries({queryKey:B.project(e)}),i.invalidateQueries({queryKey:B.projects}),i.invalidateQueries({queryKey:d3(e)}),i.invalidateQueries({queryKey:M3(e)})},Dme),s=AS(r,Hs(n,`projects/${e}`),{refetch:o.ask,accept:e=>e.type===`project.updated`||e.type===`project.state`&&e.revisionId===void 0||(e.revisionId??null)===a()||(o.ask(),!1),previewWriting:t=>{i.setQueryData(A3(e,a()),e=>Sme(e??[],t))},narrationPiece:()=>{i.invalidateQueries({queryKey:Py(e,a())})},appendArticle:t=>{i.setQueryData(B.article(e,a()),e=>`${e??``}${t}`)},patch:t=>{if(t.type===`stage.state`&&t.state===`running`&&(i.setQueryData(A3(e,a()),e=>(e??[]).filter(e=>e.stage!==t.stage||e.workId!==t.workId||e.revisionId!==t.revisionId)),t.stage===`article`&&i.setQueryData(B.article(e,a()),``)),t.type!==`project.state`&&t.workId!==void 0){o.ask();return}i.setQueryData(B.project(e),e=>DB(e,t))}});return()=>{s(),o.stop()}},[n,r,i,e,t])}var Ome={pending:`off`,running:`running`,done:`done`,provided:`done`,failed:`failed`,canceled:`off`,skipped:`off`},kme={pending:`Not started`,running:`Running`,done:`Done`,provided:`Provided`,failed:`Failed`,canceled:`Canceled`,skipped:`Skipped`};function Ame(e,t,n){if(e===null)return;let r=(t===null?n:Date.parse(t))-Date.parse(e);if(!Number.isFinite(r)||r<0)return;let i=Math.round(r/1e3);if(i<60)return`${String(i)} s`;let a=Math.round(i/60);if(a<60)return`${String(a)} min`;let o=Math.floor(a/60);return`${String(o)} h ${String(a%60)} min`}function jme(e,t){let n=T3(e,t);if(n===void 0)return;let r=lF(e);return r===void 0?`${e.progressTotal!==null&&e.progressTotal>0?`${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)} · `:``}${E3(n)}`:n.basis===`unknown`?uF(r):`${uF(r)} · ${E3(n)}`}function Mme({project:e,now:t}){let{api:n}=z();N3(e.id);let[r,i]=(0,m.useState)(null),a=N(Xy(n,e.id)),o=(a.data?.stages??[]).filter(e=>e.source!==`off`&&e.state!==`skipped`),s=(a.data?.outputs??[]).filter(e=>e.role===`image`).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),c=o.find(e=>e.kind===`images`&&e.state===`running`),l=o.find(e=>e.state===`running`),u=YH(e.limitWaits),d=s.slice(c===void 0?-4:-3),f=o.map(n=>({id:n.kind,name:iF(n.kind,e.config),tone:Ome[n.state],state:kme[n.state],time:Ame(n.startedAt,n.finishedAt,t),detail:jme(n,t)}));return(0,h.jsxs)(`li`,{className:`sl-home-run ${dU}`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),e.status===`paused`?(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}):u===void 0?(0,h.jsx)(_S,{tone:`running`,children:l===void 0?`Running`:`${iF(l.kind,e.config)}`}):(0,h.jsx)(_S,{tone:`waiting`,children:u})]}),d.length===0&&c===void 0?null:(0,h.jsxs)(B0,{list:!0,density:`compact`,label:`Images of ${e.title}`,children:[d.map((t,r)=>(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,onOpen:()=>i(r)})},t.id)),c===void 0?null:(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{alt:`The next image`,generating:`Drawing · ${String(s.length)} so far`})})]}),(0,h.jsx)(V0,{items:d.map(t=>({src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,...t.meta.prompt===void 0?{}:{caption:t.meta.prompt}})),index:r,onIndex:i,onClose:()=>i(null)}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Images ${String(c.progressCurrent??s.length)} of ${String(c.progressTotal??`?`)}`})]}),(0,h.jsx)(O3,{steps:f,label:`Steps of ${e.title}`})]})}var P3=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2});function Nme(e){return`spent${e.apiEquivalent===null?``:` · ~${P3.format(e.apiEquivalent)} via API`}${e.unpriced===0?``:` · ${String(e.unpriced)} ${e.unpriced===1?`call`:`calls`} without a price`}`}function Pme({channelId:e}){let{api:t}=z(),n=N(dme(t,ume().toISOString(),e));if(n.error!==null)return(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`This week's numbers didn't load: ${n.error.message} Reload the page to try again.`});let r=n.data;return(0,h.jsxs)(G2,{className:`sl-home-stats`,children:[(0,h.jsx)(K2,{value:r===void 0?`—`:String(r.videos),label:`videos made`}),(0,h.jsx)(K2,{value:r===void 0?`—`:P3.format(r.cost),label:r===void 0?`spent`:Nme(r)}),(r?.plans??[]).filter(e=>e.weeklyPercent!==null).map(e=>{let t=Math.round(e.weeklyPercent??0);return(0,h.jsx)(K2,{value:`${String(t)}%`,label:`weekly ${e.name} limit`,children:(0,h.jsx)(q2,{value:t/100,label:`Weekly ${e.name} limit`,valueText:`${String(t)}% of your weekly ${e.name} limit`,tone:t>=80?`waiting`:`accent`})},e.account)})]})}var Fme=864e5,Ime=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`}),F3=4,I3=!1,L3=!1;function Lme(){let{api:e}=z(),t=gx(),n=N(Yy(e)),r=N(EH(e)),i=N(Hq(e)),[a]=(0,m.useState)(()=>{let e=new Date;return e.setHours(0,0,0,0),{from:new Date().toISOString(),to:new Date(e.valueOf()+8*Fme).toISOString()}}),o=N(KH(e,a.from,a.to)),s=N({queryKey:My,queryFn:()=>Iy(e)}),c=Zi();(0,m.useEffect)(()=>{s.data?.show===!0&&!I3&&(I3=!0,c({to:`/welcome`}))},[s.data?.show,c]),(0,m.useEffect)(()=>{s.data?.settle===!0&&!L3&&(L3=!0,Ly(e).catch(()=>{L3=!1}))},[s.data?.settle,e]);let[l,u]=(0,m.useState)(()=>Date.now());(0,m.useEffect)(()=>{let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[]);let d=(0,m.useMemo)(()=>new Map((i.data??[]).map(e=>[e.id,e.channelId])),[i.data]),f=(n.data?.projects??[]).filter(e=>t.includes(e.channelId)),p=f.filter(e=>e.status===`running`),g=f.filter(w3),_=f.filter(e=>e.status===`paused`),v=f.filter(b3),y=f.filter(e=>e.status===`failed`),b=new Set(Object.values(s.data?.samples??{}).filter(e=>e!==null)),x=f.filter(e=>C3(e)&&!b.has(e.id)),S=(r.data??[]).filter(e=>e.deletedAt===null&&e.topicGeneration.mode===`hold`&&e.topics.held>0&&t.includes(d.get(e.templateId))),C=(o.data?.runs??[]).filter(e=>t.includes(d.get(e.templateId))),w=[...v.map(e=>({kind:`waiting`,project:e})),..._.map(e=>({kind:`paused`,project:e})),...S.map(e=>({kind:`held`,schedule:e})),...y.slice(0,F3).map(e=>({kind:`failed`,project:e}))],T=n.isPending;return(0,h.jsxs)(`div`,{"data-tour":`home`,children:[(0,h.jsx)(kq,{display:!0,crumb:Ime.format(new Date),title:t.channel?.name??`Home`,meta:t.channelId===null?`Every channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(fS,{to:`/play`,variant:`secondary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]}),(0,h.jsxs)(fS,{to:`/calendar`,variant:`quiet`,children:[(0,h.jsx)(sc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open calendar`]})]})}),(0,h.jsxs)(`div`,{className:`mb-5 flex items-end gap-1 md:hidden`,...Ob,children:[(0,h.jsx)(_x,{className:`min-w-0 flex-1`}),(0,h.jsx)(V,{id:`home.channel`,className:`mb-1`})]}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-5 text-danger`,children:`Your projects didn't load: ${n.error.message} Check that Slopify is still running, then reload the page.`}),(0,h.jsxs)(e0,{split:`main-side`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(H,{title:`Needs you`,info:`home.needs-you`,meta:T?`Loading…`:w.length===0?`Nothing is waiting for a decision`:`${String(w.length)} ${w.length===1?`thing is`:`things are`} waiting for you`}),w.length===0?null:(0,h.jsx)(`ul`,{"aria-label":`Waiting for you`,className:`m-0 flex list-none flex-col gap-3 p-0`,children:w.map((e,t)=>e.kind===`waiting`?(0,h.jsx)(hme,{project:e.project,primary:t===0},e.project.id):e.kind===`paused`?(0,h.jsx)(_me,{project:e.project,primary:t===0},e.project.id):e.kind===`held`?(0,h.jsx)(gme,{schedule:e.schedule,primary:t===0},e.schedule.id):(0,h.jsx)(vme,{project:e.project,primary:t===0},e.project.id))})]}),(0,h.jsxs)(`section`,{id:`running`,"aria-label":`Running now`,children:[(0,h.jsx)(H,{title:`Running now`,info:`home.running`,meta:p.length===0?`Nothing is running`:`${String(p.length)} ${p.length===1?`video`:`videos`}`}),p.length===0?T||g.length>0?null:(0,h.jsx)(a0,{title:`Start the next video`,children:`Pick a template and a topic on Play, or let a schedule start one.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:p.slice(0,3).map(e=>(0,h.jsx)(Mme,{project:e,now:l},e.id))}),(0,h.jsx)(xme,{running:p.length,queued:g})]})]}),(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Coming up`,children:[(0,h.jsx)(H,{title:`Coming up`,info:`home.coming-up`,meta:`Next 7 days`,children:(0,h.jsx)(pS,{to:`/calendar`,children:`Calendar`})}),o.error===null?C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading…`:`No scheduled runs this week. Plan some on the calendar.`}):(0,h.jsx)(ime,{runs:C.slice(0,6)}):(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The calendar didn't load: ${o.error.message} Reload the page to try again.`})]}),(0,h.jsxs)(`section`,{"aria-label":`Ready to upload`,children:[(0,h.jsx)(H,{title:`Ready to upload`,info:`home.ready`,meta:x.length===0?`Finished videos you haven't marked uploaded show here`:`${String(x.length)} finished and not marked uploaded`}),x.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:x.slice(0,F3).map(e=>(0,h.jsx)(yme,{project:e},e.id))})]}),(0,h.jsxs)(`section`,{"aria-label":`This week`,children:[(0,h.jsx)(H,{title:`This week`,info:`home.this-week`,meta:`Since Monday`}),(0,h.jsx)(Pme,{channelId:t.channelId})]})]})]})]})}function R3({className:e,...t}){return(0,h.jsx)(`input`,{"data-slot":`input`,className:L(`h-8 w-full min-w-0 rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,`placeholder:text-ink-3 aria-invalid:border-danger`,e),...t})}var Rme={written:``,spoken:``,wholeWord:!0,caseSensitive:!1};function zme(){let{api:e}=z(),t=_(),n=N(ab(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)({}),[s,c]=(0,m.useState)(),l=(0,m.useRef)(0),u=(0,m.useId)(),d=e=>e.map(e=>(l.current+=1,{...e,key:l.current}));(0,m.useEffect)(()=>{r===void 0&&n.data!==void 0&&i(d(n.data.aliases))});let f=r??[],p=P({mutationFn:t=>Bs(e,t),onSuccess:async e=>{if(!e.ok){let t={};for(let n of e.fields){let e=/^aliases\.(\d+)/u.exec(n.field)?.[1];e!==void 0&&(t[Number(e)]=n.message)}o(t),c({text:`Not saved: ${e.fields.map(e=>e.message).join(` `)}`,tone:`error`});return}o({}),i(d(e.value.aliases)),c({text:`Saved. New projects use these aliases; a project you already started keeps its copy until you refresh it in Edit project.`,tone:`success`}),await t.invalidateQueries({queryKey:B.narrationAliases})},onError:e=>c({text:`Couldn't save the aliases: ${e.message}`,tone:`error`})});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B4,{action:(0,h.jsxs)(R,{type:`button`,onClick:()=>{l.current+=1,i([...f,{...Rme,key:l.current}]),c(void 0)},disabled:r===void 0,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add alias`]}),children:(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Words the narrator says differently, like Dr. as Doctor.`,(0,h.jsx)(V,{id:`library.aliases`})]})}),n.error===null?null:(0,h.jsxs)(SI,{tone:`danger`,title:`Couldn't load the aliases`,className:`mb-6`,children:[n.error.message,` Reload the page to try again.`]}),(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsx)(t0,{label:`Aliases`,children:r===void 0?null:f.length===0?(0,h.jsx)(a0,{title:`No aliases yet`,children:`Use Add alias to say a word differently from how it is written.`}):(0,h.jsx)(Bme,{rows:f,errors:a,idPrefix:u,update:(e,t)=>{i(f.map(n=>n.key===e?{...n,...t}:n)),c(void 0)},remove:e=>{i(f.filter(t=>t.key!==e)),o({}),c(void 0)}})}),(0,h.jsx)(t0,{as:`aside`,label:`How aliases are used`,children:(0,h.jsxs)(`section`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(H,{title:`How they are used`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`The narrator reads the alias instead of the written word. The article, the captions and the PDF keep the written word.`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`A project takes a copy of this list when it starts and uses it while Use narration aliases is on. A project you already started keeps its copy until you refresh it in Edit project.`}),(0,h.jsx)(`p`,{className:`m-0`,children:`Whole word skips matches inside longer words; Match case only matches the exact capitals.`})]})})]}),(0,h.jsx)($1,{status:(0,h.jsx)(Q1,{tone:s?.tone??`info`,children:s?.text}),children:(0,h.jsx)(R,{type:`button`,variant:`primary`,disabled:r===void 0||p.isPending,onClick:()=>p.mutate(f.map(({written:e,spoken:t,wholeWord:n,caseSensitive:r})=>({written:e,spoken:t,wholeWord:n,caseSensitive:r}))),children:p.isPending?`Saving…`:`Save aliases`})})]})}function Bme({rows:e,errors:t,idPrefix:n,update:r,remove:i}){return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-4 gap-y-1 pb-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Written`,(0,h.jsx)(V,{id:`library.aliases.written`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Say it as`,(0,h.jsx)(V,{id:`library.aliases.spoken`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Whole word`,(0,h.jsx)(V,{id:`library.aliases.whole-word`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Match case`,(0,h.jsx)(V,{id:`library.aliases.match-case`})]})]}),(0,h.jsx)(pU,{label:`Narration aliases`,children:e.map((e,a)=>{let o=`${n}-${e.key}`,s=t[a],c=e.written.trim(),l=e.spoken.trim();return(0,h.jsx)(mU,{title:`Alias ${String(a+1)}`,meta:c===``||l===``?`Not filled in yet`:`Says ${c} as ${l}${e.wholeWord?` · whole word`:``}${e.caseSensitive?` · match case`:``}`,actions:(0,h.jsx)(wy,{size:`small`,label:`Remove alias ${String(a+1)}`,onClick:()=>i(e.key),children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto_auto] md:items-end`,children:[(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-written`,children:[`Written`,(0,h.jsx)(R3,{id:`${o}-written`,value:e.written,placeholder:`Dr.`,maxLength:200,"aria-invalid":s!==void 0,"aria-describedby":s===void 0?void 0:`${o}-error`,onChange:t=>r(e.key,{written:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-spoken`,children:[`Say it as`,(0,h.jsx)(R3,{id:`${o}-spoken`,value:e.spoken,placeholder:`Doctor`,maxLength:500,"aria-invalid":s!==void 0,onChange:t=>r(e.key,{spoken:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.wholeWord,onChange:t=>r(e.key,{wholeWord:t.target.checked})}),`Whole word`]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.caseSensitive,onChange:t=>r(e.key,{caseSensitive:t.target.checked})}),`Match case`]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${o}-error`,className:`m-0 text-small text-danger md:col-span-4`,children:s})]})},e.key)})})]})}function z3(e){return dq(e).names}function Vme(e,t){let n=z3(e),r=Object.create(null);for(let[e,i]of Object.entries(t))r[e]=n.includes(e)?``:i;return r}function Hme(e){return{...e,form:{...e.form,values:Vme(e.form.title,e.form.values)},variants:[]}}function B3({onDefaults:e}){let{api:t}=z(),n=_(),r=N({queryKey:H1.firstRun,queryFn:()=>fde(t),retry:!1,staleTime:1/0}),i=r.data?.defaults;(0,m.useEffect)(()=>{i!==void 0&&(vN(i),e?.(i))},[i,e]);let a=P({mutationFn:()=>pde(t),onSuccess:()=>n.invalidateQueries({queryKey:H1.firstRun})}),o=r.data;if(o===void 0||!o.firstRun||o.message===null)return null;let s=o.detected.filter(e=>e.usable);return(0,h.jsxs)(SI,{title:o.message,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:a.isPending,onClick:()=>a.mutate(),children:`Got it`}),children:[o.detail===null?null:(0,h.jsx)(`p`,{className:`m-0`,children:o.detail}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0`,children:[`Found:`,` `,s.map(e=>`${e.displayName}${e.version===void 0?``:` ${e.version}`}`).join(`, `)]}),a.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:a.error.message}):null]})}function V3(){let{api:e}=z(),{document:t}=rP(),n=N(Hq(e)),r=t.templateSource,i=n.data?.find(e=>e.id===r?.id);return t.channelId??(i===void 0?`00000000-0000-4000-8000-000000000001`:o0(i))}function H3(){let{api:e}=z();return N(Qb(e,V3())).data?.cast??[]}function Ume({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),{document:i}=n,a=V3(),o=r.data?.find(e=>e.id===a),s=i.form.useBrandKit!==!1,c=e=>{n.edit(e),n.invalidateReview(!0)};return(0,h.jsxs)(`div`,{className:`sl-fields items-end`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,children:(0,h.jsxs)(TV,{"data-play-field":`channelId`,value:a,disabled:e,onChange:e=>c({...i,channelId:e.target.value}),children:[r.data===void 0?(0,h.jsx)(`option`,{value:a,children:`Loading channels…`}):null,(r.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsx)(kb,{label:`Use the channel's brand kit`,tip:`play.brand-kit`,checked:s,disabled:e,className:`min-h-[38px]`,onChange:e=>{let{useBrandKit:t,...n}=i.form;c({...i,form:e?n:{...n,useBrandKit:!1}})}}),o?(0,h.jsxs)(`p`,{className:`sl-fields__wide m-0 text-small text-ink-3`,children:[(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:o.id},className:`underline`,children:[`Edit `,o.name]}),s?``:` · its cast is still used`]}):null]})}function U3(){let{api:e}=z(),{document:t}=rP(),n=N(Zb(e)),r=V3(),i=n.data?.find(e=>e.id===r);return t.form.language??i?.brand.language??`en`}function Wme({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),i=V3(),a=r.data?.find(e=>e.id===i),{document:o}=n;return(0,h.jsx)(`div`,{children:(0,h.jsx)(k2,{value:o.form.language,inherited:{label:`Channel's language`,language:a?.brand.language},disabled:e,onChange:e=>{let{language:t,...r}=o.form;n.edit({...o,form:e===void 0?r:{...r,language:e}}),n.invalidateReview(!0)}})})}var W3=[{stage:`audio`,label:`Audio`},{stage:`images`,label:`Images`},{stage:`video`,label:`Video / export`}];function Gme(e,t){if(e===`reviews`||e.startsWith(`reviews.`))return{section:`review`,field:e};if(e!==`checkpoints`&&!e.startsWith(`checkpoints.`))return;let n=e.slice(12),r=/^\d+$/.test(n)?t.checkpoints?.[Number(n)]:n;return{section:`review`,field:W3.some(e=>e.stage===r)?`checkpoints.${r}`:`checkpoints`}}function Kme({problem:e}){let t=rP(),{document:n,review:r}=t,{form:i}=n,a=(0,m.useId)(),o=i.checkpoints??[];return(0,h.jsxs)(`fieldset`,{"data-play-field":`checkpoints`,tabIndex:-1,"aria-invalid":e(`checkpoints`)!==void 0,disabled:r.starting||r.uncertain,className:`min-w-0 rounded-media border border-line px-3 pt-1 pb-2`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`flex items-center gap-1 px-1 font-semibold`,children:[`Review checkpoints`,(0,h.jsx)(V,{id:`play.checkpoints`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-6`,children:W3.map(({stage:r,label:s})=>{let c=o.includes(r),l=r===`video`?i.sources.video!==`off`&&i.sources.images!==`off`||i.sources.audio!==`off`:i.sources[r]===`generate`,u=e(`checkpoints.${r}`),d=`${a}-${r}`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:d,className:`flex min-h-10 items-center gap-3 max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:d,type:`checkbox`,"data-play-field":`checkpoints.${r}`,"aria-invalid":u!==void 0,"aria-describedby":`${d}-detail`,checked:c,disabled:!l&&!c,className:`size-4 accent-accent`,onChange:e=>{let a=e.target.checked?[...o,r]:o.filter(e=>e!==r);t.edit({...n,form:{...i,checkpoints:a}}),t.invalidateReview(!0)}}),`Before `,s]}),(0,h.jsx)(`p`,{id:`${d}-detail`,className:u||c&&!l?`pl-7 text-small text-danger`:`sr-only`,children:u??(l?`Approval required before this step and its dependents run.`:c?`This step is unavailable. Remove its checkpoint or enable the step.`:r===`video`?`Enable Video or Audio to review before export.`:`Choose Generate for ${s} to add this checkpoint.`)})]},r)})}),e(`checkpoints`)?(0,h.jsx)(`p`,{className:`text-small text-danger`,children:e(`checkpoints`)}):null]})}function G3({id:e,value:t,disabled:n,className:r,field:i,onChange:a}){let{api:o}=z(),s=N(ib(o)).data?.themes??[],c=t?.custom,l=c===void 0?void 0:s.find(e=>e.id===c.id),u=c!==void 0&&(l===void 0||l.name!==c.name||JSON.stringify(l.values)!==JSON.stringify(c.values)),d=c===void 0&&JS(t)===`dicemaster`,f=c===void 0?`builtin:${JS(t)}`:u?`kept`:`custom:${c.id}`;return(0,h.jsxs)(DV,{id:e,"data-play-field":i,className:r,disabled:n,value:f,onChange:e=>{let n=e.target.value;if(n===`kept`)return;if(n.startsWith(`builtin:`)){let e=WS.find(e=>`builtin:${e}`===n);e!==void 0&&a({theme:e});return}let r=s.find(e=>`custom:${e.id}`===n);r!==void 0&&a({theme:JS(t),custom:{id:r.id,name:r.name,values:r.values}})},children:[(0,h.jsxs)(`optgroup`,{label:`Built in`,children:[WS.map(e=>(0,h.jsx)(`option`,{value:`builtin:${e}`,children:qS[e]},e)),d?(0,h.jsx)(`option`,{value:`builtin:${GS}`,children:`${qS[GS]} (retired, this project's look)`}):null]}),s.length===0&&!u?null:(0,h.jsxs)(`optgroup`,{label:`Your themes`,children:[u?(0,h.jsx)(`option`,{value:`kept`,children:`${c.name} (this project's copy)`}):null,s.map(e=>(0,h.jsx)(`option`,{value:`custom:${e.id}`,children:u&&l?.id===e.id?`${e.name} (current version)`:e.name},e.id))]})]})}function K3({label:e,field:t,hideLabel:n=!1,value:r,options:i,className:a,tip:o,onPick:s}){let c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:L(`inline-flex items-center gap-3`,a),...o===void 0?{}:Ob,children:[(0,h.jsx)(X4,{id:c,className:n?`sr-only`:`shrink-0`,children:e}),(0,h.jsx)(Z4,{type:`single`,value:r,"aria-labelledby":c,onValueChange:e=>{let t=i.find(t=>t.value===e);t!==void 0&&t.disabled!==!0&&s(t.value)},children:i.map(e=>(0,h.jsx)(Q4,{value:e.value,"data-play-field":e.value===r?t:void 0,disabled:e.disabled===!0,children:e.label},e.value))}),o===void 0?null:(0,h.jsx)(V,{id:o,label:e,className:`-ml-1`})]})}function q3({value:e,onPick:t,rawCounts:n}){let r=e.words??500,i=e.characters??3e3,a=e.mode===`words`||e.mode===`characters`,o=e.mode===`characters`,s=o?e.characters:e.words;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(K3,{field:`chunking.mode`,label:`Chunking`,tip:`play.chunking`,className:`min-w-0 max-w-full flex-wrap [&_[data-slot=toggle-group]]:max-w-full [&_[data-slot=toggle-group]]:flex-wrap`,value:e.mode,options:[{value:`whole`,label:`Whole`},{value:`paragraph`,label:`Paragraph`},{value:`words`,label:`Every ${String(n?.words??r)} words`},{value:`characters`,label:`Every ${String(n?.characters??i)} characters`}],onPick:e=>{if(n){n.onChange(e,e===`characters`?n.characters:n.words);return}t(e===`words`?{mode:e,words:r}:e===`characters`?{mode:e,characters:i}:{mode:e})}}),a?(0,h.jsx)(PV,{label:o?`Characters`:`Words`,tip:`play.chunking.count`,problem:void 0,children:({id:r})=>(0,h.jsx)(CV,{id:r,"data-play-field":o?`chunking.characters`:`chunking.words`,type:n?`text`:`number`,min:1,max:o?1e6:1e4,inputMode:`numeric`,className:`sl-input--number`,value:n?o?n.characters:n.words:s===void 0?``:String(s),onChange:r=>{if(n){n.onChange(e.mode,r.target.value);return}let i=Number.parseInt(r.target.value,10),a=Number.isFinite(i)&&i>0;t(o?a?{mode:`characters`,characters:Math.min(i,1e6)}:{mode:`characters`}:a?{mode:`words`,words:Math.min(i,1e4)}:{mode:`words`})}})}):null]})}var J3=1;function Y3({prompts:e,picked:t,problem:n,onPick:r,rawNumbers:i}){let a=(0,m.useId)(),o=t.reduce((e,t)=>e+t.number,0),s=t.filter(t=>!e.some(e=>e.name===t.name)),c=[...e.map(e=>({name:e.name,missing:!1})),...s.map(e=>({name:e.name,missing:!0}))];return c.length===0?(0,h.jsx)(`p`,{className:`sl-fields__wide basis-full text-small text-ink-3`,children:`No image prompts saved. Write one on Prompts.`}):(0,h.jsxs)(`div`,{className:`sl-fields__wide flex w-full basis-full flex-col gap-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{id:a,className:`engraved text-ink-3`,children:`Image prompts`}),(0,h.jsx)(V,{id:`play.image-prompts`,className:`-my-1`})]}),(0,h.jsx)(`ul`,{"aria-labelledby":a,className:`m-0 grid w-full list-none grid-cols-[repeat(auto-fill,minmax(min(100%,15rem),1fr))] gap-x-6 gap-y-2 p-0`,children:c.map(e=>{let a=t.findIndex(t=>t.name===e.name),o=a===-1?void 0:t[a];return(0,h.jsxs)(`li`,{children:[e.missing?(0,h.jsx)(`span`,{className:`block text-label text-danger`,children:`Missing template · untick to remove`}):null,(0,h.jsx)(qme,{name:e.name,number:o?.number,rawNumber:i?{value:i.values.find(t=>t.name===e.name)?.number??``,onChange:t=>i.onChange(e.name,t)}:void 0,problem:a===-1?void 0:n(`imagePrompts.${String(a)}.number`),onTick:n=>{r(n?[...t,{name:e.name,number:J3}]:t.filter(t=>t.name!==e.name))},onNumber:n=>{r(t.map(t=>t.name===e.name?{name:t.name,number:n}:t))}})]},e.name)})}),t.length===0?null:(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:Number.isFinite(o)?`${String(o)} of 60 images`:`Complete image counts to see the total`})]})}function qme({name:e,number:t,problem:n,onTick:r,onNumber:i,rawNumber:a}){let o=(0,m.useId)(),s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex w-full min-w-0 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:o,"data-play-field":`imagePrompts`,type:`checkbox`,checked:t!==void 0,className:`size-[14px] shrink-0 accent-accent`,onChange:e=>{r(e.target.checked)}}),(0,h.jsx)(`label`,{htmlFor:o,title:e,className:L(`min-w-0 flex-1 truncate`,t===void 0?`text-ink-3`:`text-ink`),children:e}),(0,h.jsx)(X4,{htmlFor:s,className:`sr-only`,children:`Number for ${e}`}),(0,h.jsx)(CV,{id:s,"data-play-field":`imagePrompts.${e}.number`,type:a?`text`:`number`,min:J3,max:20,inputMode:`numeric`,disabled:t===void 0,"aria-invalid":n!==void 0,"aria-describedby":n===void 0?void 0:c,className:`sl-input--number`,value:a?.value??(t===void 0||t===0?``:String(t)),onChange:e=>{if(a){a.onChange(e.target.value);return}let t=Number.parseInt(e.target.value,10);i(Number.isFinite(t)?t:0)}}),n===void 0?null:(0,h.jsx)(`span`,{id:c,className:`text-label text-danger`,children:n})]})}var Jme=`text-small text-ink-2 file:mr-3 file:h-8 file:rounded-control file:border file:border-line-strong file:bg-raised file:px-3 file:text-ink`;function X3({label:e,field:t,value:n,placeholder:r,problem:i,tip:a,onChange:o}){let s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`div`,{...a===void 0?{}:Ob,children:[(0,h.jsxs)(`span`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:s,children:e}),a===void 0?null:(0,h.jsx)(V,{id:a,label:e,className:`-my-1`})]}),(0,h.jsx)(wV,{id:s,"data-play-field":t,rows:6,value:n,placeholder:r,"aria-invalid":i!==void 0,"aria-describedby":i===void 0?void 0:c,onChange:e=>{o(e.target.value)}}),i===void 0?null:(0,h.jsx)(`p`,{id:c,className:`mt-1 text-label text-danger`,children:i})]})}function Z3({label:e,field:t,accept:n,multiple:r=!1,disabled:i=!1,uploads:a,problem:o,numbered:s=!1,onPick:c,onRemove:l,onReattach:u}){let d=(0,m.useId)(),f=(0,m.useId)();return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(X4,{htmlFor:d,className:`mb-1`,children:e}),(0,h.jsx)(`input`,{id:d,"data-play-field":t,type:`file`,accept:n,multiple:r,disabled:i,"aria-invalid":o!==void 0,"aria-describedby":o===void 0?void 0:f,className:Jme,onChange:e=>{c([...e.target.files??[]]),e.target.value=``}}),o===void 0?null:(0,h.jsx)(`p`,{id:f,className:`mt-1 text-label text-danger`,children:o}),a.length===0?null:(0,h.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,children:a.map((e,t)=>(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3`,children:[s?(0,h.jsx)(`span`,{className:`engraved w-6 text-ink-3`,children:String(t+1)}):null,(0,h.jsx)(Yme,{upload:e}),e.error!==void 0&&u?(0,h.jsxs)(`label`,{className:`text-small text-ink-2`,children:[`Reattach`,(0,h.jsx)(`input`,{"aria-label":`Reattach ${e.name}`,className:`max-w-full`,type:`file`,accept:n,onChange:t=>{let n=t.target.files?.[0];t.target.value=``,n&&u(e.key,n)}})]}):null,l===void 0?null:(0,h.jsx)(R,{variant:`quiet`,className:`ml-auto`,"aria-label":`Remove ${e.name}`,onClick:()=>{l(e.key)},children:`Remove`})]},e.key))})]})}function Yme({upload:e}){return(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-3 text-small [overflow-wrap:anywhere]`,children:[(0,h.jsx)(`span`,{className:e.error===void 0?`text-ink`:`text-danger`,children:e.name}),e.error===void 0?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:e.file===void 0?`Copying`:`Staged`}):(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.error})]})}var Q3=`col-span-3 min-w-0 sl-fields`,$3=`col-span-3 min-w-0`;function e6({kind:e,name:t,dim:n,titled:r=!0,children:i}){return(0,h.jsxs)(`section`,{"data-tour":`play-${e}`,className:`grid grid-cols-[24px_1fr_auto] items-center gap-x-2 gap-y-4 border-b border-line py-4 [&>div:empty]:hidden`,children:[r?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(sS,{kind:e,className:n?`text-ink-3`:`text-ink-2`}),(0,h.jsx)(`h3`,{className:L(`m-0 text-title-3`,n?`text-ink-3`:void 0),children:t})]}):(0,h.jsx)(`span`,{className:`sl-field__label col-span-2`,children:`Source`}),i]})}var Xme={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`};function t6({kind:e,form:t,update:n}){return(0,h.jsx)(K3,{field:`sources.${e}`,label:`${e} source`,hideLabel:!0,tip:Xme[e],className:`max-[700px]:col-span-3 max-[700px]:justify-self-start [&_[data-slot=toggle-group]]:flex-wrap`,value:t.sources[e],options:FN(e).filter(n=>e!==`thumbnail`||n.value!==`prompt_by_llm`||t.sources.article!==`off`).map(n=>({...n,disabled:e===`video`&&n.value===`generate`&&t.sources.images===`off`})),onPick:r=>{if(e===`article`&&r===`off`){n(Zme(t));return}n({sources:{...t.sources,[e]:r,...e===`images`&&r===`off`?{video:`off`}:{}}})}})}function n6(e,t){return e.filter(e=>e.kind===t).map(e=>({value:e.name,label:e.name}))}function Zme(e){return{sources:{...e.sources,article:`off`,research:`off`,audio:`off`,document:`off`,...e.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}},subtitles:{...e.subtitles,mode:`off`},youtubeDescription:!1,...e.shorts===void 0?{}:{shorts:{...e.shorts,enabled:!1}}}}function Qme(e){let t=this;t.compiler=n;function n(n){return yle(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}var r6=QR().use(vR).use(Qme).freeze(),i6=`[ˈˌ]?[abdefghijklmnoprstuvwxzæðŋθɑɒɔəɚɛɜɝɡɪɹʃʊʌʒʔɫɾ][\\u0303\\u031a\\u0325\\u0329\\u032a\\u032c\\u032f\\u035c\\u0361ʰʲʷ]*[ːˑ]?`,$me=RegExp(`^(?:${i6})+(?:\\.(?:${i6})+)*$`,`u`),a6=`[ˈˌ]?[a-zæçðøħŋœɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɪɫɬɭɮɯɰɱɲɳɴɵɶɸɹɺɻɽɾʀʁʂʃʄʈʉʊʋʌʍʎʏʐʑʒʔʕʙʛʜʝʟʡʢβθχ][\\u0300-\\u036fʰʱʲʷʼˠˤ˞]*[ːˑ]?`,ehe=RegExp(`^(?:${a6})+(?:\\.(?:${a6})+)*$`,`u`);function o6(e){return e.type===`break`?`
278
+ `:e.value??e.children?.map(o6).join(``)??``}function s6(e){if(e.type===`heading`){let t=o6(e).trim();return/^pronunciation glossary:?\s*$/iu.test(t)?[]:[t]}return e.type===`table`?(e.children??[]).slice(1).map(e=>{let t=e.children??[];if(t.length<2)return o6(e);let[n,r]=t.slice(0,2).map(e=>o6(e).trim());return`${n}: ${r!==void 0&&r!==``&&!r.includes(`/`)?`/${r}/`:r}`}):e.type===`paragraph`?o6(e).split(/\r?\n/u):e.type===`root`||e.type===`list`||e.type===`listItem`?(e.children??[]).flatMap(s6):[`(unsupported glossary block)`]}function the(e){return Array.from(e,e=>{let t=e.toLowerCase(),n=t.toUpperCase().toLowerCase();if(n===e)return e;let r=RegExp(`^${e.replace(/[|\\{}()[\]^$+*?.]/gu,`\\$&`)}$`,`iu`);return r.test(n)?n:r.test(t)?t:e}).join(``)}function c6(e,t){let n=t===void 0||t===`en`,r=n?$me:ehe,i=n?`standard-English IPA`:`IPA`,a=s6(r6().use(pB).parse(e)),o=new Map,s=[];for(let[e,t]of a.entries()){let a=t=>{s.push({row:e+1,reason:t})},c=t.trim();if(c===``||/^pronunciation glossary:?\s*$/iu.test(c))continue;let l=/^([^:]+):\s*(.+)$/u.exec(c),u=l?.[1]?.trim().replace(/\s+/gu,` `),d=l?.[2];if(u===void 0||d===void 0||!/[\p{L}\p{N}]/u.test(u)||/[/[\]<>\p{Cc}]/u.test(u)){a(`use Term: /IPA/ or a Term | IPA table`);continue}let f=/^(\/[^/]+\/(?:\s+\/[^/]+\/)*)(?:\s+[^/]+)?$/u.exec(d);if(f?.[1]===void 0){a(`use slash-delimited ${i}`);continue}let p=Array.from(f[1].matchAll(/\/([^/]+)\//gu)).flatMap(e=>(e[1]??``).trim().split(/\s+/u));if(p.length===0||p.some(e=>!r.test(e))){a(n?`use standard-English IPA only, not ARPAbet, delivery tags or non-English sounds; give a foreign name an English approximation`:`use IPA, not ARPAbet or delivery tags`);continue}if(u.split(` `).length!==p.length){a(`supply one IPA word for each written word`);continue}let m=the(u),h=o.get(m);if(h!==void 0&&h.ipa.join(` `)!==p.join(` `)){a(`an earlier entry already gives this term a different pronunciation`);continue}h===void 0&&o.set(m,{term:u,ipa:p})}return s.length===0?{ok:!0,entries:[...o.values()]}:{ok:!0,entries:[...o.values()],skipped:s}}function nhe(e,t){return e.flatMap(e=>{if(!e.pronunciations?.trim())return[];let n=c6(e.pronunciations,t),r=n.ok?n.skipped??[]:[];return r.length===0?[]:[{speaker:e.name.trim()||`A speaker`,skipped:r}]})}function rhe(e,t){let n=t?.turns.find(t=>t.speaker===e.id)?.text??ihe(e);if(n.length<=200)return n;let r=n.slice(0,200),i=Math.max(r.lastIndexOf(`. `),r.lastIndexOf(`? `),r.lastIndexOf(`! `));return i>60?r.slice(0,i+1):`${r.slice(0,r.lastIndexOf(` `))}…`}function ihe(e){let t=e.name.trim()||`your speaker`;switch(e.role){case`narrator`:return`The night was quiet, and the old house held its breath. I'm ${t}, and I'll be telling this story.`;case`host`:return`Hi everyone, I'm ${t}, and welcome back to the show. Today's topic is a good one.`;case`guest`:return`Thanks for having me. I'm ${t}, and I've been looking forward to this conversation.`;case`character`:return`You really thought I wouldn't find out? My name is ${t}, and I always find out.`}}function ahe(e){return e.flatMap(e=>e.host===!0&&e.voice!==void 0?[l6(e,`host`)]:[])}function ohe(e){let t=e.toLowerCase();return/^[a-z0-9-]{1,55}$/.test(t)?`cast-${t}`:`cast-h${she(e)}`}function she(e){let t=3735928559,n=1103547991;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,2654435761),n=Math.imul(n^i,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(4294967296*(2097151&n)+(t>>>0)).toString(36)}function l6(e,t){let n=e.voice;return{id:ohe(e.id),name:e.name.slice(0,40),role:t,voice:n===void 0?{provider:``,model:``,voice:``}:{provider:n.provider,model:n.model,voice:n.voice},...n?.pace===void 0||n.pace===1?{}:{pace:n.pace},...n?.pronunciations?.trim()?{pronunciations:n.pronunciations}:{},castId:e.id,...che(e)}}function che(e){let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null)?.sha256;return t==null?{}:{portrait:t}}var lhe=/^#{1,6}\s+(.+?)\s*#*\s*$/,uhe=/^\*{0,2}([^:*\n]{1,60}?)\*{0,2}\s*:\s*\*{0,2}\s*(.*)$/;function u6(e,t,n=!1){let r=new Map(t.map(e=>[e.name.trim().toLowerCase(),e])),i=t.map(e=>e.name.trim()).join(`, `),a=[],o=[],s=!1;for(let[t,n]of e.replace(/\r\n?/g,`
279
279
  `).split(`
280
- `).entries()){let e=n.trim(),c=t+1;if(e===``){s=!1;continue}let l=che.exec(e);if(l!==null){o.push({title:d6(l[1]??``),firstTurn:a.length+1}),s=!1;continue}if(/^([-*_=~])\1{2,}$/.test(e)){s=!1;continue}let u=lhe.exec(e),d=u===null?void 0:r.get((u[1]??``).trim().toLowerCase());if(u!==null&&d!==void 0){a.push({speaker:d.id,lines:[u[2]??``],section:o.length-1}),s=!0;continue}let f=a.at(-1);if(s&&f!==void 0){f.lines.push(e);continue}return{ok:!1,reason:u===null?`Line ${String(c)} of the script is not a turn. Start every turn with a speaker's name and a colon (${i}), one turn per paragraph.`:`Line ${String(c)} of the script is spoken by "${(u[1]??``).trim()}", who is not one of the speakers (${i}). Use only these names, or add the speaker under Speakers (Play → Narration, or Edit project → Providers).`}}let c=[];for(let e of a){let t=d6(e.lines.join(` `));t!==``&&c.push({index:c.length+1,speaker:e.speaker,text:t,section:e.section,...n?{markdown:e.lines.join(`
281
- `)}:{}})}if(c.length===0)return{ok:!1,reason:`The script has no spoken turns. Write each turn as a speaker's name, a colon and their words (${i}).`};let l=[],u=new Map;for(let[e,t]of o.entries()){let n=c.find(t=>t.section===e);n!==void 0&&t.title!==``&&(u.set(e,l.length),l.push({title:t.title,firstTurn:n.index}))}return{ok:!0,script:{turns:c.map(e=>({...e,section:u.get(e.section)??-1})),sections:l}}}function d6(e){return e.replace(/\[[^\]]*\]\([^)]*\)/g,e=>e.slice(1,e.indexOf(`]`))).replace(/\[[^\]]*\]/g,` `).replace(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g,`$2`).replace(/`/g,``).replace(/\s+/g,` `).trim()}var uhe={narrator:`Narrator`,host:`Host`,guest:`Guest`,character:`Character`};function f6({value:e,onChange:t,providers:n,voices:r,script:i,problem:a,cast:o=[],language:s}){let c=(0,m.useMemo)(()=>{if(e===void 0||i===void 0||i.trim()===``)return;let t=u6(i,e.speakers);return t.ok?t.script:void 0},[i,e]),l=n=>{if(n===``){t(void 0);return}let r=EA.find(e=>e===n);r!==void 0&&t(e===void 0?zA(r,ihe(o)):{...e,format:r,source:r===`audiobook`?e.source:`script`})},u=n=>{e!==void 0&&t({...e,...n})},d=o.filter(t=>t.voice!==void 0&&!(e?.speakers??[]).some(e=>e.castId===t.id)),f=(t,n)=>{e!==void 0&&u({speakers:e.speakers.map((e,r)=>r===t?n:e)})};return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-3`,"data-play-field":`voices`,children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(FV,{field:`voices.format`,label:`Format`,tip:`play.speakers.format`,value:e?.format??``,placeholder:`Narration (one voice)`,options:EA.map(e=>({value:e,label:DA[e]})),problem:a?.(`voices.format`),onPick:l}),e?.format===`audiobook`?(0,h.jsx)(FV,{field:`voices.source`,label:`Script`,tip:`play.speakers.script`,value:e.source,placeholder:`Pick where the script comes from`,options:[{value:`script`,label:`Write a script (Script prompt)`},{value:`attribute`,label:`Split the article into speakers`}],problem:a?.(`voices.source`),onPick:e=>u({source:e===`attribute`?`attribute`:`script`})}):null]}),e===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`One voice reads the article. Pick a format for an audiobook, podcast, radio drama or interview with several speakers.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.source===`script`?"The article prompt must be a Script prompt: the text model writes speaker turns, one `Name: words` paragraph each.":`The article is written or pasted as usual; the text model then hands its narration and dialogue to the speakers.`}),a?.(`voices.speakers`)===void 0?null:(0,h.jsx)(`p`,{className:`text-label text-danger`,children:a(`voices.speakers`)}),(0,h.jsx)(`ol`,{"aria-label":`Speakers`,className:`divide-y divide-line border-y border-line`,children:e.speakers.map((t,i)=>(0,h.jsx)(mhe,{index:i,speaker:t,line:nhe(t,c),providers:n,voices:r,language:s,problem:a,onChange:e=>f(i,e),onRemove:e.speakers.length>1?()=>u({speakers:e.speakers.filter((e,t)=>t!==i)}):void 0},t.id))}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsx)(R,{type:`button`,disabled:e.speakers.length>=10,onClick:()=>u({speakers:[...e.speakers,phe(e.speakers)]}),children:`Add speaker`}),(0,h.jsx)(FV,{label:`Add from the cast`,tip:`play.speakers.add-from-cast`,value:``,placeholder:d.length===0?`No cast member has a voice yet`:`Pick one of ${String(d.length)}`,options:d.map(e=>({value:e.id,label:e.name})),disabled:d.length===0||e.speakers.length>=10,problem:void 0,onPick:t=>{let n=d.find(e=>e.id===t);n!==void 0&&u({speakers:[...e.speakers,l6(n,fhe(e))]})}}),(0,h.jsx)(FV,{field:`voices.turnGapSeconds`,label:`Gap between turns`,tip:`play.speakers.turn-gap`,value:String(e.turnGapSeconds),placeholder:`Pick a gap`,options:jA.map(e=>({value:String(e),label:`${e} s`})),problem:a?.(`voices.turnGapSeconds`),onPick:e=>u({turnGapSeconds:Number(e)})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{label:`Speaker names on captions`,tip:`play.speakers.name-tags`,checked:e.nameTags,onChange:e=>u({nameTags:e})}),(0,h.jsx)(kb,{label:`One request for consecutive turns where the voice provider can (ElevenLabs v3, Gemini)`,tip:`play.speakers.native-dialogue`,checked:e.nativeDialogue,onChange:e=>u({nativeDialogue:e})}),(0,h.jsx)(kb,{label:`Also make MP3 and M4B files with chapter markers`,tip:`play.speakers.audio-files`,checked:e.audioFiles,onChange:e=>u({audioFiles:e})})]}),e.format===`audiobook`?(0,h.jsx)(dhe,{value:e,onChange:t,problem:a}):null,e.format===`podcast`||e.format===`interview`?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The speaker panel (a tile per speaker, the one talking lit, their name below) is drawn with the captions: set Captions to Burn in under Style to see it in the video.`}):null]})]})}function dhe({value:e,onChange:t,problem:n}){let r=e.book,i=n=>t({...e,...n});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(kb,{label:`A chapter of a book`,tip:`play.speakers.book`,checked:r!==void 0,onChange:n=>{if(n)i({book:{title:``,chapter:1}});else{let{book:n,...r}=e;t(r)}}}),r===void 0?null:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-[minmax(0,1fr)_160px]`,children:[(0,h.jsx)(xV,{label:`Book title`,tip:`play.speakers.book-title`,error:n?.(`voices.book.title`),children:(0,h.jsx)(CV,{value:r.title,maxLength:200,onChange:e=>i({book:{...r,title:e.target.value}})})}),(0,h.jsx)(xV,{label:`Chapter`,tip:`play.speakers.book-chapter`,error:n?.(`voices.book.chapter`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:FA,step:1,value:r.chapter===0?``:String(r.chapter),onChange:e=>i({book:{...r,chapter:Number(e.target.value)||0}})})})]})]})}function fhe(e){return e.format===`podcast`?`host`:e.format===`interview`?e.speakers.some(e=>e.role===`host`)?`guest`:`host`:e.speakers.some(e=>e.role===`narrator`)?`character`:`narrator`}function phe(e){let t=e.length+1;for(;e.some(e=>e.id===`speaker-${String(t)}`);)t+=1;return{id:`speaker-${String(t)}`,name:`Speaker ${String(t)}`,role:`character`,voice:{provider:``,model:``,voice:``}}}function mhe({index:e,speaker:t,line:n,providers:r,voices:i,language:a,problem:o,onChange:s,onRemove:c}){let l=`voices.speakers.${String(e)}`,u=t.voice,d=i.filter(e=>e.provider===u.provider),f=F2(d,a,u.voice||void 0),p=a===void 0?d:f.listed,g=t.name.trim()||`this speaker`,_=(0,m.useMemo)(()=>the([t],a??`und`)[0]?.skipped??[],[t,a]);return(0,h.jsxs)(`li`,{className:`grid grid-cols-1 gap-3 py-3 min-[700px]:grid-cols-2`,"data-play-field":l,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-end gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`mb-2 size-3 shrink-0 rounded-full`,style:{background:`var(--color-speaker-${String(e%6+1)})`}}),(0,h.jsx)(xV,{label:`Speaker name`,tip:`play.speaker.name`,error:o?.(`${l}.name`),className:`min-w-0 flex-1`,children:(0,h.jsx)(CV,{value:t.name,maxLength:40,onChange:e=>s({...t,name:e.target.value})})})]}),(0,h.jsx)(FV,{label:`Role`,tip:`play.speaker.role`,value:t.role,placeholder:`Pick a role`,options:OA.map(e=>({value:e,label:uhe[e]})),problem:void 0,onPick:e=>{let n=OA.find(t=>t===e);n!==void 0&&s({...t,role:n})}}),(0,h.jsx)(RV,{field:`${l}.voice`,label:`Voice provider`,tip:`play.speaker.provider`,family:`tts`,providers:r,value:u.provider,problem:o?.(`${l}.voice`),onPick:e=>s({...t,voice:{provider:e,model:``,voice:``}})}),(0,h.jsx)(zV,{label:`Voice model`,tip:`play.speaker.model`,provider:u.provider,value:u.model,problem:void 0,onPick:e=>s({...t,voice:{...u,model:e}})}),(0,h.jsx)(FV,{field:`${l}.voice.voice`,label:`Voice`,tip:`play.speaker.voice`,value:u.voice,placeholder:p.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:p.map(e=>({value:e.voiceId,label:e.name})),problem:o?.(`${l}.voice.voice`),onPick:e=>s({...t,voice:{...u,voice:e}})}),a===void 0?null:(0,h.jsx)(I2,{language:a,voice:d.find(e=>e.voiceId===u.voice),hidden:f.hidden,showAll:f.showAll,onShowAll:f.setShowAll}),(0,h.jsx)(FV,{field:`${l}.pace`,label:`Pace`,tip:`play.speaker.pace`,value:String(t.pace??1),placeholder:`Pick a pace`,options:AA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:o?.(`${l}.pace`),onPick:e=>{let{pace:n,...r}=t;s(Number(e)===1?r:{...r,pace:Number(e)})}}),(0,h.jsxs)(`details`,{className:`col-span-full text-small`,...Ob,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-ink-2`,children:[`Pronunciations for `,t.name.trim()||`this speaker`,t.pronunciations?.trim()?` · set`:``,(0,h.jsx)(V,{id:`play.speaker.pronunciations`})]}),(0,h.jsx)(wV,{rows:3,"aria-label":`Pronunciations for ${t.name.trim()||`this speaker`}`,value:t.pronunciations??``,placeholder:`Arda: /ˈɑɹdə/`,onChange:e=>{let{pronunciations:n,...r}=t;s(e.target.value===``?r:{...r,pronunciations:e.target.value})}})]}),_.length===0?null:(0,h.jsxs)(SI,{tone:`waiting`,className:`col-span-full`,title:`${String(_.length)} ${_.length===1?`pronunciation`:`pronunciations`} for ${g} ${_.length===1?`is`:`are`} skipped`,children:[(0,h.jsx)(`ul`,{children:_.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsxs)(`p`,{children:[`Those words are read as ordinary text; the other entries are used. Fix them in Pronunciations for `,g,` above: one `,(0,h.jsx)(`code`,{children:`Term: /IPA/`}),` per line.`]})]}),(0,h.jsxs)(`div`,{className:`col-span-full flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(ghe,{speaker:t,line:n}),(0,h.jsx)(`span`,{className:`flex-1`}),c===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:c,children:[`Remove `,t.name.trim()||`speaker`]})]})]})}var hhe=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:4});function ghe({speaker:e,line:t}){let{api:n}=z(),{provider:r,model:i,voice:a}=e.voice,o=r!==``&&i!==``&&a!==``,s=N({queryKey:[`audition-quote`,r,i,t],queryFn:()=>Us(n,[{speaker:e.name.trim()||`Speaker`,provider:r,model:i,text:t}]),enabled:o,staleTime:6e4}),[c,l]=(0,m.useState)(void 0);(0,m.useEffect)(()=>()=>{c!==void 0&&URL.revokeObjectURL(c)},[c]);let u=P({mutationFn:()=>Ws(n,{provider:r,model:i,voice:a,text:t}),onSuccess:e=>{let t=URL.createObjectURL(e);l(t),new Audio(t).play().catch(()=>{})}}),d=s.data?.estimate,f=d==null?void 0:d.unknown>0?`price unknown`:`about ${hhe.format(d.high)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:!o||u.isPending,onClick:()=>u.mutate(),title:`Reads: ${t}`,children:u.isPending?`Speaking…`:`Audition${f===void 0?``:` · ${f}`}`}),(0,h.jsx)(V,{id:`play.speaker.audition`})]}),(0,h.jsx)(`span`,{className:`min-h-5 text-label text-ink-2`,"aria-live":`polite`,children:o?u.error===null?c===void 0?`Reads their first line: “${t.length>60?`${t.slice(0,60)}…`:t}”`:`Playing the audition.`:u.error.message:`Pick a provider, model and voice to audition.`})]})}function _he(e){return e===void 0?`Narration`:DA[e]}function p6({value:e,skipCode:t,onChange:n,tip:r=`play.describe-figures`}){let i=(0,m.useId)(),a=e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.describeFigures`,checked:a,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:e.currentTarget.checked,skipCode:t===!0})}),`Describe tables and figures in the narration`]}),(0,h.jsx)(V,{id:r})]}),a?(0,h.jsxs)(`span`,{className:`flex items-center gap-1 pl-7`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-code`,className:`flex min-h-10 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-code`,type:`checkbox`,"data-play-field":`audio.skipCode`,checked:t===!0,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:!0,skipCode:e.currentTarget.checked})}),`Leave code out`]}),(0,h.jsx)(V,{id:`play.skip-code`})]}):null]})}function m6({value:e,onChange:t,tip:n=`play.show-figures`}){let r=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`showFigures`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Show tables and figures on screen`]}),(0,h.jsx)(V,{id:n})]})}function h6({value:e,onChange:t,note:n}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`audio.useNarrationAliases`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Use narration aliases`]}),(0,h.jsx)(V,{id:`play.narration-aliases`})]}),n===void 0?null:(0,h.jsx)(`div`,{className:`pl-7`,children:n})]})}function g6({value:e,prompts:t,supported:n,error:r,libraryLinks:i=!0,onChange:a}){let o=(0,m.useId)(),s=t.filter(e=>e.kind===`narration`),c=s.find(t=>t.name===e),l=r??(e!==``&&!n?`Choose Inworld TTS-2 or turn preparation Off.`:void 0);return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:o,className:`text-small font-semibold`,children:`Narration Preparation`}),(0,h.jsx)(V,{id:`play.narration-preparation`})]}),(0,h.jsxs)(DV,{id:o,"data-play-field":`narrationPrompt`,value:e,"aria-describedby":l?`${o}-error`:void 0,"aria-invalid":l!==void 0||void 0,onChange:e=>a(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),e!==``&&c===void 0?(0,h.jsxs)(`option`,{value:e,children:[e,` (saved selection)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`text-small text-danger`,children:l}):null,i?(0,h.jsxs)(`div`,{className:`flex gap-4 text-small`,children:[(0,h.jsx)(ha,{to:`/prompts/new`,search:{kind:`narration`},children:`Create prompt`}),c?(0,h.jsx)(ha,{to:`/prompts/$promptId`,params:{promptId:c.id},children:`View prompt`}):null]}):null]})}function _6({value:e,supported:t,onChange:n,shared:r}){let i=(0,m.useId)(),a=t&&e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.usePronunciationGlossary`,checked:e===!0,disabled:!t,"aria-describedby":t?void 0:`${i}-support`,className:`size-4 accent-accent`,onChange:e=>n(e.currentTarget.checked)}),`Use Pronunciation Glossary`]}),(0,h.jsx)(V,{id:`play.pronunciation-glossary`})]}),r===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-1 pl-7`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-shared`,className:`flex min-h-8 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-shared`,type:`checkbox`,"data-play-field":`audio.shareGlossary`,checked:r.value===!0,disabled:!a,className:`size-4 accent-accent`,onChange:e=>r.onChange(e.currentTarget.checked)}),`Also use pronunciations from my other projects`]}),(0,h.jsx)(V,{id:`play.share-glossary`})]}),r.note===void 0?null:r.note]}),t?null:(0,h.jsx)(`p`,{id:`${i}-support`,className:`text-label text-ink-3`,children:`Unavailable for this provider or model. Your saved preference is retained.`})]})}var v6={source:`off`,prompt:``,thumbnail:!0},vhe=[{value:`prompt`,label:`From a prompt`},{value:`provide`,label:`Upload`}];function y6({value:e,prompts:t,problem:n,upload:r,prompt:i,onChange:a}){let o=(0,m.useId)(),s=e.source===`off`,c=t.filter(e=>e.kind===`image`).map(e=>({value:e.name,label:e.name}));return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsx)(`div`,{className:`min-w-0`,children:(0,h.jsx)(FV,{field:`reference.source`,label:`Establishing image`,tip:`play.reference`,value:s?``:e.source,placeholder:`Off`,options:vhe,problem:n?.(`reference.source`),onPick:t=>a({...e,source:t===`prompt`||t===`provide`?t:`off`})})}),e.source===`provide`?(0,h.jsx)(`div`,{className:`min-w-0`,children:r}):i??(0,h.jsx)(FV,{field:`reference.prompt`,label:`Establishing prompt`,tip:`play.reference.prompt`,value:e.prompt,placeholder:s?`Off`:`Pick an image prompt`,options:c,disabled:s,problem:n?.(`reference.prompt`),onPick:t=>a({...e,prompt:t})}),(0,h.jsxs)(`div`,{className:`col-span-full flex min-h-9 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:o,className:`flex cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{id:o,type:`checkbox`,"data-play-field":`reference.thumbnail`,checked:e.thumbnail,disabled:s,onChange:t=>a({...e,thumbnail:t.target.checked})}),`Draw the thumbnail from it too`]}),(0,h.jsx)(V,{id:`play.reference.thumbnail`})]})]})}function b6({choice:e,onChange:t,field:n=`llm.thinking`,label:r=`Thinking`,tip:i=`play.llm.thinking`,problem:a}){let{api:o}=z(),s=N(AV(o,e.provider)).data?.models.find(t=>t.id===e.model)?.thinkingModes??[];if(!s.length&&!e.thinking)return null;let c=r===`Thinking`?`thinking level`:r.toLowerCase();return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(FV,{field:n,label:r,tip:i,value:e.thinking??`default`,placeholder:`Model default`,problem:e.thinking&&!s.includes(e.thinking)?`Choose a supported ${c}.`:a,options:[{value:`default`,label:`Model default`},...e.thinking&&!s.includes(e.thinking)?[{value:e.thinking,label:`${e.thinking} (saved level)`}]:[],...s.map(e=>({value:e,label:e===`off`?`Off`:e.charAt(0).toUpperCase()+e.slice(1)}))],onPick:n=>{let r=s.find(e=>e===n),{thinking:i,...a}=e;t(r===void 0?a:{...a,thinking:r})}}),r===`Thinking`&&s.length&&!s.includes(`off`)?(0,h.jsx)(`p`,{className:`mt-1 text-small text-ink-3`,children:`This model does not support turning thinking off.`}):null]})}function yhe({form:e,prompts:t,providers:n,voices:r,problem:i,update:a,onPickFiles:o,onRemoveFile:s,onReattachFile:c,rawCounts:l,advanced:u,cast:d,language:f,titled:p}){let g=r.filter(t=>t.provider===e.audio.provider),_=F2(g,f??`en`,e.audio.voice||void 0),v=f===void 0?g:_.listed,y=e.voices?.speakers.find(e=>e.voice.provider&&e.voice.model&&e.voice.voice)?.voice,b=e.intro!==``||e.outro!==``,x=e.voices!==void 0&&!b&&y!==void 0;(0,m.useEffect)(()=>{if(!x||y===void 0)return;let t=e.audio;(t.provider!==y.provider||t.model!==y.model||t.voice!==y.voice)&&a({audio:{...t,provider:y.provider,model:y.model,voice:y.voice}})},[x,y,e.audio,a]);let S=e.voices!==void 0,C=[e.chunking.mode,e.intro?`intro ${e.intro}`:void 0,e.outro?`outro ${e.outro}`:void 0,e.narrationPrompt?`preparation on`:void 0,e.audio.usePronunciationGlossary?`glossary on`:void 0].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(e6,{kind:`audio`,name:`Audio`,dim:e.sources.audio===`off`,titled:p,children:[(0,h.jsx)(t6,{kind:`audio`,form:e,update:a}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[x?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`audio.provider`,label:S?`Intro and outro TTS`:`TTS`,tip:`play.tts.provider`,family:`tts`,providers:n,value:e.audio.provider,problem:i(`audio`),onPick:t=>{a({audio:{...e.audio,provider:t,model:``,voice:``}})}}),(0,h.jsx)(zV,{field:`audio.model`,label:`TTS model`,tip:`play.tts.model`,provider:e.audio.provider,value:e.audio.model,problem:i(`audio.model`),onPick:t=>a({audio:{...e.audio,model:t}})}),(0,h.jsx)(FV,{field:`audio.voice`,label:S?`Intro and outro voice`:`Voice`,tip:`play.voice`,value:e.audio.voice,placeholder:v.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:v.map(e=>({value:e.voiceId,label:e.name})),problem:i(`audio.voice`),onPick:t=>{a({audio:{...e.audio,voice:t}})}}),f===void 0?null:(0,h.jsx)(I2,{language:f,voice:g.find(t=>t.voiceId===e.audio.voice),hidden:_.hidden,showAll:_.showAll,onShowAll:_.setShowAll}),S?(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`This voice reads only the intro and outro. Each speaker's voice is set under Speakers.`}):null]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Speakers ·`,` `,e.voices===void 0?`Narration, one voice`:`${_he(e.voices.format)}, ${String(e.voices.speakers.length)} ${e.voices.speakers.length===1?`speaker`:`speakers`}`]}),(0,h.jsx)(`div`,{className:`pt-2 pb-3`,children:(0,h.jsx)(f6,{value:e.voices,providers:n,voices:r,script:e.sources.article===`provide`?e.provided.article:void 0,problem:i,cast:d,language:f,onChange:e=>a({voices:e})})})]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Audio Advanced · `,C]}),(0,h.jsxs)(`div`,{className:`sl-fields pt-2 pb-3`,children:[(0,h.jsx)(`div`,{className:`col-span-full`,children:(0,h.jsx)(q3,{...l?{rawCounts:l}:{},value:e.chunking,onPick:e=>{a({chunking:e})}})}),u,(0,h.jsx)(g6,{value:e.narrationPrompt??``,prompts:t,supported:e.audio.provider===`inworld`&&e.audio.model===`inworld-tts-2`,error:i(`narrationPrompt`),onChange:e=>a({narrationPrompt:e})}),(0,h.jsx)(_6,{value:e.audio.usePronunciationGlossary,supported:Sj({sources:e.sources,audio:{...e.audio,usePronunciationGlossary:!0}}),onChange:t=>a({audio:{...e.audio,usePronunciationGlossary:t}}),shared:{value:e.audio.shareGlossary??!0,onChange:t=>a({audio:{...e.audio,shareGlossary:t}})}}),(0,h.jsx)(h6,{value:e.audio.useNarrationAliases,onChange:t=>a({audio:{...e.audio,useNarrationAliases:t}})}),(0,h.jsx)(p6,{value:e.audio.describeFigures,skipCode:e.audio.skipCode,onChange:t=>a({audio:{...e.audio,...t}})})]})]})]}):null}),e.sources.audio===`provide`?(0,h.jsxs)(`div`,{className:$3,children:[(0,h.jsx)(Z3,{field:`provided.audio`,label:`Narration file`,accept:`audio/*`,uploads:e.provided.audio===void 0?[]:[e.provided.audio],problem:i(`provided.audio`),onPick:e=>{o(`audio`,e)},onReattach:c?(e,t)=>c(`audio`,e,t):void 0,onRemove:e=>{s(`audio`,e)}}),(0,h.jsx)(`p`,{className:`mt-2 text-small text-ink-2`,children:`Uploaded narration is used as-is; include any intro and outro in that file.`})]}):null]})}function bhe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawNumbers:c,more:l,titled:u}){return(0,h.jsxs)(e6,{kind:`images`,name:`Images`,dim:e.sources.images===`off`,titled:u,children:[(0,h.jsx)(t6,{kind:`images`,form:e,update:i}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.images===`generate`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}),(0,h.jsx)(Y3,{prompts:n.filter(e=>e.kind===`image`),...c?{rawNumbers:c}:{},picked:e.imagePrompts,problem:r,onPick:e=>{i({imagePrompts:e})}}),(0,h.jsx)(xhe,{form:e,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s?{onReattachFile:s}:{}}),l]}):null}),e.sources.images===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.images`,label:`Slideshow images`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,numbered:!0,uploads:e.provided.images,problem:r(`provided.images`),onPick:e=>{a(`images`,e)},onReattach:s?(e,t)=>s(`images`,e,t):void 0,onRemove:e=>{o(`images`,e)}})}):null]})}function x6({form:e,providers:t,problem:n,update:r}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`images.provider`,label:`Provider`,tip:`play.images.provider`,family:`image`,providers:t,value:e.images.provider,problem:n(`images`),onPick:e=>r({images:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`images.model`,label:`Model`,tip:`play.images.model`,provider:e.images.provider,value:e.images.model,problem:n(`images.model`),onPick:t=>r({images:{...e.images,model:t}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:e.images,problem:n(`images.thinking`),onChange:e=>r({images:e})})]})}function xhe({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsx)(y6,{value:e.reference??v6,prompts:t,problem:n,onChange:e=>r({reference:e}),upload:(0,h.jsx)(Z3,{field:`provided.reference`,label:`Establishing image file`,accept:`image/png,image/jpeg`,uploads:e.provided.reference===void 0?[]:[e.provided.reference],problem:n(`provided.reference`),onPick:e=>{i(`reference`,e)},onReattach:o?(e,t)=>o(`reference`,e,t):void 0,onRemove:e=>{a(`reference`,e)}})})}var S6=5e3,She=[`Write a YouTube description for this video.`,``,`- Summary: a 2-3 sentence hook that says what the viewer gets from watching, in plain words, without clickbait.`,`- Chapters: split the video where the topic changes, 5-12 chapters for a long video and fewer for a short one. Chapter titles are 2-6 words, in title case, and name what that part covers.`,`- Hashtags: 3-5 hashtags about the subject, most specific last.`,`- Tags: 15-25 search terms a viewer might type to find this video, from broad to specific.`].join(`
282
- `),Che=`Built-in`;function C6({enabled:e,prompt:t,prompts:n,narrated:r,problem:i,onChange:a}){let o=(0,m.useId)(),s=n.filter(e=>e.kind===`description`),c=t!==``&&!s.some(e=>e.name===t),l=i?.(`youtubeDescription`)??i?.(`descriptionPrompt`);return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1 self-end`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${o}-switch`,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${o}-switch`,type:`checkbox`,"data-play-field":`youtubeDescription`,checked:e,disabled:!r&&!e,"aria-describedby":l?`${o}-error`:void 0,className:`size-4 accent-accent`,onChange:e=>a({youtubeDescription:e.currentTarget.checked,descriptionPrompt:t})}),`YouTube description`]}),(0,h.jsx)(V,{id:`play.youtube-description`})]}),(0,h.jsx)(WV,{htmlFor:`${o}-prompt`,label:`Description prompt`,tip:`play.description-prompt`,children:(0,h.jsxs)(DV,{id:`${o}-prompt`,"data-play-field":`descriptionPrompt`,value:t,disabled:!e,onChange:t=>a({youtubeDescription:e,descriptionPrompt:t.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:Che}),c?(0,h.jsxs)(`option`,{value:t,children:[t,` (saved choice)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`sl-fields__wide m-0 text-small text-danger`,children:l}):r?null:(0,h.jsx)(`p`,{className:`sl-fields__wide m-0 text-label text-ink-3`,children:`Needs narration.`})]})}function w6({value:e,narrated:t,imageProvider:n,problem:r,onChange:i,fieldPrefix:a=`videoEdit`,language:o}){let s=(0,m.useId)(),c=e??fA,l=e=>i({...c,...e}),{api:u}=z(),d=N(jV(u,n,c.animate!==`off`)),f=e=>r?.(`${a}.${e}`),p=[c.transition===`cut`?void 0:`${_A[c.transition]} ${String(c.transitionSeconds)} s`,c.grade===`none`?void 0:yA[c.grade],c.atmosphere===`none`?void 0:bA[c.atmosphere],c.vignette===`off`?void 0:`Vignette`,c.grain===`off`?void 0:`Grain`,c.chapterCards?`Chapter cards`:void 0,c.animate===`off`?void 0:`Animated images`].filter(e=>e!==void 0),g=[`transition`,`transitionSeconds`,`chapterCards`,`animate`,`animateEvery`,`animateModel`].map(f).filter(e=>e!==void 0),_=d.data?.models??[],v=c.animateModel!==``&&!_.some(e=>e.id===c.animateModel),y=VO(o);return{cuts:(0,h.jsxs)(T6,{id:`${s}-cuts`,label:`Cuts`,tip:`project.video.cuts`,children:[(0,h.jsx)(DV,{id:`${s}-cuts`,"data-play-field":`${a}.cuts`,className:`min-w-0`,value:y===void 0?c.cuts:`interval`,disabled:y!==void 0,"aria-describedby":y===void 0?void 0:`${s}-cuts-note`,onChange:e=>l({cuts:e.target.value}),children:oA.map(e=>(0,h.jsx)(`option`,{value:e,children:gA[e]},e))}),y===void 0?null:(0,h.jsx)(`p`,{id:`${s}-cuts-note`,className:`m-0 basis-full text-small text-ink-3`,children:y})]}),look:(0,h.jsxs)(`details`,{className:`group min-w-0 rounded-control border border-line-strong`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-10 cursor-pointer items-center gap-3 px-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Look`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-ink-3`,children:p.length===0?`Plain cuts, no effects`:p.join(` · `)})]}),(0,h.jsxs)(`div`,{className:`sl-fields border-line-strong border-t p-3`,children:[(0,h.jsxs)(T6,{id:`${s}-transition`,label:`Transition`,tip:`project.video.transition`,children:[(0,h.jsx)(DV,{id:`${s}-transition`,"data-play-field":`${a}.transition`,className:`min-w-0`,value:c.transition,onChange:e=>l({transition:e.target.value}),children:sA.map(e=>(0,h.jsx)(`option`,{value:e,children:_A[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Transition length`,"data-play-field":`${a}.transitionSeconds`,"aria-invalid":f(`transitionSeconds`)!==void 0,className:`w-24 flex-none`,disabled:c.transition===`cut`,value:String(c.transitionSeconds),onChange:e=>l({transitionSeconds:Number(e.target.value)}),children:hA.map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[e,` s`]},e))})]}),(0,h.jsx)(T6,{id:`${s}-grade`,label:`Colour grade`,tip:`project.video.grade`,children:(0,h.jsx)(E6,{id:`${s}-grade`,field:`${a}.grade`,value:c.grade,options:lA,labels:yA,onChange:e=>l({grade:e})})}),(0,h.jsx)(T6,{id:`${s}-vignette`,label:`Vignette`,tip:`project.video.vignette`,children:(0,h.jsx)(E6,{id:`${s}-vignette`,field:`${a}.vignette`,value:c.vignette,options:cA,labels:vA,onChange:e=>l({vignette:e})})}),(0,h.jsx)(T6,{id:`${s}-grain`,label:`Film grain`,tip:`project.video.grain`,children:(0,h.jsx)(E6,{id:`${s}-grain`,field:`${a}.grain`,value:c.grain,options:cA,labels:vA,onChange:e=>l({grain:e})})}),(0,h.jsx)(T6,{id:`${s}-atmosphere`,label:`Atmosphere`,tip:`project.video.atmosphere`,children:(0,h.jsx)(E6,{id:`${s}-atmosphere`,field:`${a}.atmosphere`,value:c.atmosphere,options:uA,labels:bA,onChange:e=>l({atmosphere:e})})}),(0,h.jsx)(T6,{id:`${s}-cards`,label:`Chapter cards`,tip:`project.video.chapter-cards`,children:(0,h.jsx)(`input`,{id:`${s}-cards`,type:`checkbox`,"data-play-field":`${a}.chapterCards`,className:`size-4 accent-accent`,checked:c.chapterCards,disabled:!t&&!c.chapterCards,onChange:e=>l({chapterCards:e.currentTarget.checked})})}),(0,h.jsxs)(T6,{id:`${s}-animate`,label:`Animate images`,tip:`project.video.animate`,wide:!0,children:[(0,h.jsx)(DV,{id:`${s}-animate`,"data-play-field":`${a}.animate`,"aria-invalid":f(`animate`)!==void 0,className:`min-w-0`,value:c.animate,onChange:e=>l({animate:e.target.value}),children:dA.map(e=>(0,h.jsx)(`option`,{value:e,disabled:e===`chapters`&&!t,children:xA[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Animate every how many images`,"data-play-field":`${a}.animateEvery`,"aria-invalid":f(`animateEvery`)!==void 0,className:`w-24 flex-none`,disabled:c.animate!==`every`,value:String(c.animateEvery),onChange:e=>l({animateEvery:Number(e.target.value)}),children:Array.from({length:9},(e,t)=>t+2).map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[`every `,e]},e))}),(0,h.jsxs)(DV,{"aria-label":`Image-to-video model`,"data-play-field":`${a}.animateModel`,"aria-invalid":f(`animateModel`)!==void 0,className:`min-w-0`,disabled:c.animate===`off`,value:c.animateModel,onChange:e=>l({animateModel:e.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a model`}),v?(0,h.jsxs)(`option`,{value:c.animateModel,children:[c.animateModel,` (saved choice)`]}):null,_.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),g.length>0?(0,h.jsx)(`p`,{className:`col-span-full text-small text-danger`,children:g[0]}):c.animate!==`off`&&d.isSuccess&&_.length===0?(0,h.jsx)(`p`,{className:`col-span-full text-label text-ink-3`,children:`This image provider has no image-to-video models. Choose fal.ai or Replicate for images to animate them.`}):null]})]})}}function T6({id:e,label:t,tip:n,wide:r=!1,children:i}){return(0,h.jsxs)(`div`,{className:L(`sl-field`,r&&`sl-fields__wide`),...Ob,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),(0,h.jsx)(V,{id:n,label:t.toLowerCase()})]}),(0,h.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-start gap-2 [&>select]:min-w-0 [&>select]:flex-1`,children:i})]})}function E6({id:e,field:t,value:n,options:r,labels:i,onChange:a}){return(0,h.jsx)(DV,{id:e,"data-play-field":t,className:`min-w-0`,value:n,onChange:e=>a(e.target.value),children:r.map(e=>(0,h.jsx)(`option`,{value:e,children:i[e]},e))})}var whe=rO(`kind`,[q({kind:pO(`upload`),stagedFileId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`output`),outputId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`picture`),sha256:W().regex(/^[a-f0-9]{64}$/)})]),D6=q({format:J(PS),subtitles:q({mode:J(fM),fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/),fontSize:G().finite().min(16).max(120),position:J(pM)}),videoEdit:yM.optional(),previewText:W().max(200).optional(),image:whe.optional(),shorts:q({titleOnScreen:GD(),speed:G().finite().min(1).max(1.25).optional(),title:W().max(100).optional()}).optional(),force:GD().optional()}),The=q({hash:W().regex(/^[a-f0-9]{64}$/),url:W().min(1),cached:GD(),seconds:G().positive()});async function Ehe(e,t,n){let r=await e.fetch(`${e.origin}/api/style-preview`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),...n===void 0?{}:{signal:n}});if(!r.ok)throw await fo(r);let i=So(The,await r.json());return{...i,src:`${e.origin}${i.url}`}}var Dhe=600;function O6({settings:e,label:t,drawnOn:n,poster:r}){let{api:i}=z(),a=N({queryKey:sN,queryFn:()=>cN(i),staleTime:6e4}),{format:o,subtitles:s,videoEdit:c,previewText:l,image:u,shorts:d}=e,f=r??(u?.kind===`picture`?ux(i,u.sha256):void 0),p=u===void 0?``:JSON.stringify(u),g=d===void 0?``:JSON.stringify(d),_=(0,m.useMemo)(()=>JSON.stringify({format:o,subtitles:{mode:s.mode,fontId:s.fontId,fontSize:s.fontSize,position:s.position},...c===void 0?{}:{videoEdit:c},...l===void 0||l.trim()===``?{}:{previewText:l},...p===``?{}:{image:JSON.parse(p)},...g===``?{}:{shorts:JSON.parse(g)}}),[o,s.mode,s.fontId,s.fontSize,s.position,c,l,p,g]),v=(0,m.useMemo)(()=>D6.safeParse(JSON.parse(_)).success,[_]),[y,b]=(0,m.useState)({kind:`idle`}),[x,S]=(0,m.useState)(void 0),C=(0,m.useRef)(void 0),w=(0,m.useCallback)(async e=>{C.current?.abort();let t=new AbortController;C.current=t,b({kind:`pending`});try{let n=await Ehe(i,{...D6.parse(JSON.parse(_)),...e?{force:e}:{}},t.signal);if(C.current!==t)return;S(n.src),b({kind:`ready`,src:n.src})}catch(e){if(C.current!==t||t.signal.aborted)return;b({kind:`failed`,message:e instanceof Error&&e.message!==``?e.message:`The style preview couldn't render. Press Render again.`})}},[i,_]);(0,m.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>{w(!1)},Dhe);return()=>clearTimeout(e)},[w,v]),(0,m.useEffect)(()=>()=>C.current?.abort(),[]);let T=a.data?.fonts.find(e=>e.id===s.fontId)?.name??(s.fontId==="default"?`Barlow`:`Chosen font`),E=d===void 0?s.mode===`burn-in`?`Captions: ${T} ${String(s.fontSize)} · ${Ohe(s.position)}`:s.mode===`files`?`Captions: a separate file, which players show in their own style`:`Captions: off`:[`Captions: ${T}, word by word`,d.titleOnScreen?`Title on screen`:`No title on screen`,d.speed===void 0||d.speed===1?void 0:`${d.speed.toFixed(2)}×`].filter(e=>e!==void 0).join(` · `),D=d===void 0?`Style preview`:`Shorts preview`,O=o===`9:16`||d!==void 0;return(0,h.jsxs)(`section`,{"aria-label":D,className:`min-w-0 space-y-3`,children:[(0,h.jsx)(H,{as:`h3`,title:D,meta:d===void 0?`6 seconds of the sample, rendered with your settings`:`A few seconds of the sample as a short, rendered with your settings`,info:d===void 0?`project.video.style-preview`:`play.shorts.preview`,children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:!v||y.kind===`pending`,disabledReason:v?`Rendering the preview…`:`Fix the caption settings to render the preview.`,onClick:()=>{w(!0)},children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,size:16,strokeWidth:1.75}),`Render again`]})}),x===void 0?null:(0,h.jsx)(R0,{src:x,label:t??D,...f===void 0?{}:{poster:f},portrait:O,className:O?`max-w-[270px]`:`max-w-[480px]`}),y.kind===`pending`?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Rendering the preview…`}):null,y.kind===`failed`?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:y.message}):null,v?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The preview renders again once the caption size is between 16 and 120.`}),(0,h.jsxs)(`p`,{className:`text-small text-ink-2`,children:[E,u===void 0||n===void 0?``:` · Drawn on ${n}`]})]})}function Ohe(e){let t=e.replace(/-/g,` `);return`${t[0]?.toUpperCase()??``}${t.slice(1)}`}function khe({form:e,problem:t,update:n,onPickFiles:r,onRemoveFile:i,onReattachFile:a}){let o=e.provided.ambientBed;return(0,h.jsx)(A2,{value:e.ambientBed,inherit:`The channel's (brand kit)`,sources:Qk,offerNone:!0,problem:e=>t(`ambientBed.${e}`),file:(0,h.jsx)(Z3,{field:`ambientBed.file`,label:`Ambient sound file: an audio file, looped if shorter than the video`,accept:`audio/*`,uploads:o===void 0?[]:[o],problem:t(`ambientBed.file`),onPick:e=>r(`ambientBed`,e),onReattach:a?(e,t)=>a(`ambientBed`,e,t):void 0,onRemove:e=>i(`ambientBed`,e)}),onChange:e=>n({ambientBed:e})})}function k6({value:e,onChange:t,problem:n,switchTip:r=`project.loudness`,switchLabel:i=`Level the volume`}){return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[(0,h.jsx)(kb,{checked:e.enabled,label:i,tip:r,onChange:n=>t({...e,enabled:n})}),e.enabled?(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(j6,{target:`video`,label:`Video volume`,tip:`project.loudness.video`,lufs:e.videoLufs,error:n?.(`videoLufs`),onChange:n=>t({...e,videoLufs:n})}),(0,h.jsx)(j6,{target:`audioFiles`,label:`Audio files volume`,tip:`project.loudness.audio-files`,lufs:e.audioFilesLufs,error:n?.(`audioFilesLufs`),onChange:n=>t({...e,audioFilesLufs:n})})]}):null]})}var Ahe=`Enter a volume between ${M6(-10)} dB and ${M6(4)} dB (${String(ck(-10))}% to ${String(ck(4))}%).`;function A6(e,t){let n=e.trim().replace(`−`,`-`).replace(`,`,`.`);if(n===``)return;let r=Number(n.replace(/(dB|%)$/i,``).trim());if(!Number.isFinite(r)||t===`percent`&&r<=0)return;let i=t===`db`?r:lk(r);if(!(i<-10.25||i>4.25))return uk(i)}function j6({target:e,label:t,tip:n,lufs:r,error:i,onChange:a}){let o=(0,m.useId)(),s=ok(r,e),[c,l]=(0,m.useState)(),u=c===void 0||A6(c.text,c.unit)!==void 0,d=(t,n)=>{l({unit:t,text:n});let r=A6(n,t);r!==void 0&&a(sk(r,e))},f=c?.unit===`db`?c.text:M6(s),p=c?.unit===`percent`?c.text:String(ck(s));return(0,h.jsx)(xV,{label:t,tip:n,help:`0 dB is the recommended ${N6(ik(e))} LUFS; this is ${N6(r)} LUFS. Peaks stay under ${N6(ak(e))} dBTP.`,error:u?i:Ahe,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`loudness.${e===`video`?`videoLufs`:`audioFilesLufs`}`,value:f,onChange:e=>d(`db`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`dB`}),(0,h.jsx)(CV,{id:`${o}-percent`,"aria-label":`${t} as a percentage of the recommended level`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:p,onChange:e=>d(`percent`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`%`})]})})}function M6(e){return e>0?`+${String(e)}`:N6(e)}function N6(e){return String(e).replace(`-`,`−`)}function P6({sentence:e,paragraph:t,problem:n,onChange:r}){let i=`0 to 2 in steps of ${String(yk)}`;return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(xV,{label:`Pause between sentences (seconds)`,tip:`project.pause.sentence`,help:`${i}; ${String(vk)} is the default. 0 leaves the voice's own.`,error:n(`sentencePauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`sentencePauseSeconds`,value:e,onChange:e=>r(`sentencePauseSeconds`,e.target.value)})}),(0,h.jsx)(xV,{label:`Pause between paragraphs (seconds)`,tip:`project.pause.paragraph`,help:`${i}; 0 (the default) keeps the sentence pause.`,error:n(`paragraphPauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`paragraphPauseSeconds`,value:t,onChange:e=>r(`paragraphPauseSeconds`,e.target.value)})})]})}function F6(e){let t=e.trim().replace(`,`,`.`);if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function jhe({form:e,problem:t,update:n}){let{api:r}=z(),i=N(ob(r)).data?.loudness??tk,a=e.loudness;return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[e.sources.audio===`generate`?(0,h.jsx)(P6,{sentence:e.sentencePause??`0.4`,paragraph:e.paragraphPause??`0`,problem:t,onChange:(e,t)=>n(e===`sentencePauseSeconds`?{sentencePause:t}:{paragraphPause:t})}):null,(0,h.jsx)(k6,{value:{enabled:a?.enabled??i.enabled,videoLufs:a?.videoLufs??i.videoLufs,audioFilesLufs:a?.audioFilesLufs??i.audioFilesLufs},problem:e=>t(`loudness.${e}`),onChange:e=>n({loudness:e})})]})}function I6({value:e,onPick:t,disabled:n=!1}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,...Ob,children:[(0,h.jsx)(X4,{id:r,className:`shrink-0`,children:`Thumbnails`}),(0,h.jsxs)(Z4,{type:`single`,value:String(e),"aria-labelledby":r,disabled:n,"data-play-field":`thumbnailCount`,onValueChange:e=>{(e===`1`||e===`3`)&&t(e===`3`?3:1)},children:[(0,h.jsx)(Q4,{value:`1`,children:`1`}),(0,h.jsx)(Q4,{value:`3`,children:`3`})]}),(0,h.jsx)(V,{id:`play.thumbnail-count`})]})}function Mhe({form:e,problem:t,update:n}){return(0,h.jsxs)(e6,{kind:`research`,name:`Research`,dim:e.sources.research===`off`,children:[(0,h.jsx)(t6,{kind:`research`,form:e,update:n}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.research===`generate`?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:`Runs through the LLM, one agent per chapter`}):null}),e.sources.research===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.research`,label:`Research notes`,tip:`play.provided.research`,value:e.provided.research,placeholder:`Paste the notes the article will be written from.`,problem:t(`provided.research`),onChange:t=>{n({provided:{...e.provided,research:t}})}})}):null]})}function Nhe({form:e,prompts:t,problem:n,update:r,titled:i}){return(0,h.jsxs)(e6,{kind:`article`,name:`Article`,dim:!1,titled:i,children:[(0,h.jsx)(t6,{kind:`article`,form:e,update:r}),(0,h.jsx)(`div`,{className:`${$3} grid gap-4`,children:e.sources.article===`generate`?(0,h.jsx)(FV,{field:`articlePrompt`,label:UA(e)?`Script prompt`:`Article prompt`,tip:`play.article-prompt`,value:e.articlePrompt,placeholder:`Pick a prompt`,options:n6(t,l0(e)),problem:n(`articlePrompt`),onPick:e=>{r({articlePrompt:e})}}):null}),e.sources.article===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.article`,label:`Article text`,tip:`play.provided.article`,value:e.provided.article,placeholder:`Paste the article that will be narrated.`,problem:n(`provided.article`),onChange:t=>{r({provided:{...e.provided,article:t}})}})}):null]})}function Phe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s}){let c=e.sources.thumbnail===`from_prompt`||e.sources.thumbnail===`prompt_by_llm`;return(0,h.jsxs)(e6,{kind:`thumbnail`,name:`Thumbnail`,dim:e.sources.thumbnail===`off`,children:[(0,h.jsx)(t6,{kind:`thumbnail`,form:e,update:i}),(0,h.jsxs)(`div`,{className:Q3,children:[c&&e.sources.images!==`generate`?(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}):null,c?(0,h.jsx)(FV,{field:`thumbnailPrompt`,label:`Thumbnail prompt`,tip:`play.thumbnail-prompt`,value:e.thumbnailPrompt,placeholder:`Pick a prompt`,options:n6(n,`thumbnail`),problem:r(`thumbnailPrompt`),onPick:e=>{i({thumbnailPrompt:e})}}):null,c?(0,h.jsx)(I6,{value:e.thumbnailCount===3?3:1,onPick:e=>{i({thumbnailCount:e})}}):null]}),e.sources.thumbnail===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.thumbnail`,label:`Thumbnail image`,accept:`image/png,image/jpeg,image/webp`,uploads:e.provided.thumbnail===void 0?[]:[e.provided.thumbnail],problem:r(`provided.thumbnail`),onPick:e=>{a(`thumbnail`,e)},onReattach:s?(e,t)=>s(`thumbnail`,e,t):void 0,onRemove:e=>{o(`thumbnail`,e)}})}):null]})}function Fhe({form:e,prompts:t,silenceGapSeconds:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawTiming:c,extras:l=!0,language:u,titled:d}){let f=e.sources.video===`generate`?e.sources.audio===`off`?`Silent video · each image shown once`:`Images and narration · ${String(n)} s segment gaps`:e.sources.audio===`off`?`Download each enabled stage separately`:`Combined WAV export with narration and segment gaps`,p=t=>({value:c?c[t]:Number.isFinite(e[t])?String(e[t]):``,onChange:e=>{c?c.onChange(t,e):i({[t]:e.trim()===``?NaN:Number(e)})}}),m=w6({value:e.videoEdit,narrated:e.sources.audio!==`off`,imageProvider:e.images.provider,problem:r,language:u??e.language,onChange:e=>i({videoEdit:e})});return(0,h.jsxs)(e6,{kind:`video`,name:`Export`,dim:e.sources.video===`off`,titled:d,children:[(0,h.jsx)(t6,{kind:`video`,form:e,update:i}),(0,h.jsx)(`span`,{className:Q3,children:(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:f})}),e.sources.video===`generate`||e.sources.audio!==`off`?(0,h.jsxs)(`div`,{className:Q3,children:[e.sources.video===`generate`?(0,h.jsx)(R6,{field:`imageSeconds`,label:`Seconds per image`,tip:`play.image-seconds`,step:1,problem:r(`imageSeconds`),...p(`imageSeconds`)}):null,e.sources.video===`generate`?(0,h.jsx)(R6,{field:`zoomPercent`,label:`Zoom (%)`,tip:`play.zoom`,step:.5,problem:r(`zoomPercent`),...p(`zoomPercent`)}):null,e.sources.video===`generate`?(0,h.jsx)(PV,{label:`Motion`,tip:`play.motion`,problem:void 0,children:({id:t})=>(0,h.jsx)(DV,{id:t,"data-play-field":`motionStyle`,className:`w-full`,value:e.motionStyle,onChange:e=>i({motionStyle:e.target.value}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null,e.sources.video===`generate`?m.cuts:null,e.sources.audio===`off`?null:(0,h.jsx)(R6,{field:`edgeSilenceSeconds`,label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,step:.5,problem:r(`edgeSilenceSeconds`),...p(`edgeSilenceSeconds`)})]}):null,e.sources.video===`generate`?(0,h.jsx)(`div`,{className:$3,children:m.look}):null,e.sources.video===`generate`&&e.sources.audio!==`off`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(khe,{form:e,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s})}):null,e.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(jhe,{form:e,problem:r,update:i})}),l?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(L6,{form:e,prompts:t,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s===void 0?{}:{onReattachFile:s}})}):null,e.sources.images===`off`?(0,h.jsx)(`p`,{className:`${$3} text-small text-ink-2`,children:`Video is Off because Images is Off. Generate or provide images to enable video.`}):null]})}function L6({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[e.sources.audio===`generate`&&e.audio.describeFigures===!0?(0,h.jsx)(m6,{value:e.showFigures,onChange:e=>r({showFigures:e})}):null,e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(C6,{enabled:e.youtubeDescription===!0,prompt:e.descriptionPrompt??``,prompts:t,narrated:e.sources.audio!==`off`,problem:n,onChange:e=>r(e)})}),e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(YV,{value:e.shorts??GV,prompts:t,narrated:e.sources.audio!==`off`,problem:n,musicName:e.provided.shortsMusic?.name,music:(0,h.jsxs)(`div`,{className:`basis-full`,children:[(0,h.jsx)(Z3,{field:`shorts.music`,label:`Background music (optional): an audio file, looped if shorter than a short`,accept:`audio/*`,disabled:!jN(e),uploads:e.provided.shortsMusic===void 0?[]:[e.provided.shortsMusic],problem:n(`shorts.music`),onPick:e=>i(`shortsMusic`,e),onReattach:o?(e,t)=>o(`shortsMusic`,e,t):void 0,onRemove:e=>a(`shortsMusic`,e)}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:`Plays at the volume above under every short and dips while the narrator speaks.`})]}),preview:(0,h.jsx)(O6,{settings:KV(e.shorts??GV,e.subtitles.fontId)}),onChange:e=>r({shorts:e})})})]})}function R6({field:e,label:t,tip:n,placeholder:r,step:i,problem:a,value:o,onChange:s}){return(0,h.jsx)(PV,{label:t,tip:n,problem:a,children:({id:t,describedBy:n})=>(0,h.jsx)(CV,{id:t,"data-play-field":e,type:`text`,inputMode:i<1?`decimal`:`numeric`,className:`sl-input--number`,"aria-invalid":a!==void 0,"aria-describedby":n,placeholder:r,value:o,onChange:e=>s(e.target.value)})})}function Ihe({form:e,update:t}){let n=e.sources.document===`off`;return(0,h.jsxs)(e6,{kind:`document`,name:`Document`,dim:n,children:[(0,h.jsx)(t6,{kind:`document`,form:e,update:t}),(0,h.jsx)(`div`,{className:Q3,children:(0,h.jsx)(PV,{label:`Theme`,tip:`play.document-theme`,problem:void 0,children:({id:r})=>(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(G3,{id:r,field:`document.theme`,className:`w-auto min-w-[120px]`,disabled:n,value:e.document,onChange:e=>{t({document:e})}}),(0,h.jsx)(ha,{to:`/document-themes`,className:`text-small text-accent-ink underline`,children:`Edit themes`})]})})})]})}function Lhe({form:e,providers:t,problem:n,update:r,uses:i,onSettings:a}){let o=[...new Set(i.map(e=>e.label))],s=o.length<=1?o[0]??``:`${o.slice(0,-1).join(`, `)} and ${o.at(-1)??``}`;return(0,h.jsxs)(`section`,{"aria-label":`Text generation`,className:`border-y border-line py-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`Text generation`,meta:`Used for ${s}.`,info:`play.text-generation`,className:`pb-3`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Settings`})}),(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(RV,{field:`llm.provider`,label:`LLM`,tip:`play.llm.provider`,family:`llm`,providers:t,value:e.llm.provider,problem:n(`llm.provider`)??(e.llm.provider===``?n(`llm`):void 0),onPick:e=>r({llm:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`llm.model`,label:`Text model`,tip:`play.llm.model`,provider:e.llm.provider,value:e.llm.model,problem:n(`llm.model`)??(e.llm.provider!==``&&n(`llm`)?`Pick a text model.`:void 0),onPick:t=>r({llm:{...e.llm,model:t}})}),(0,h.jsx)(b6,{choice:e.llm,onChange:e=>r({llm:e})})]})]})}function z6({section:e,entries:t,...n}){let r=IN(n.form,t);return r[0]?.section===e?(0,h.jsx)(Lhe,{...n,uses:r}):null}function Rhe(e){let{form:t,onLibrary:n}=e,r=e.prompts.find(e=>e.kind===l0(t)&&e.name===t.articlePrompt);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Nhe,{...e,titled:!1}),t.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3 py-3`,children:[r?(0,h.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`summary`,{"data-play-field":`articlePrompt.preview`,className:`cursor-pointer py-2 text-small text-accent-ink`,children:`View prompt`}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words py-3 font-sans text-body text-ink-2`,children:r.body})]}):(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.prompts.some(e=>e.kind===l0(t))?`Choose a saved ${l0(t)} prompt.`:`No ${l0(t)} prompts saved. Create a prompt to begin.`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>n(`/prompts`),children:`Create prompt`})]}):(0,h.jsxs)(`p`,{className:`py-3 text-small text-ink-3`,children:[t.provided.article.trim()?t.provided.article.trim().split(/\s+/).length:0,` `,`words · `,t.provided.article.length,` characters`]}),(0,h.jsx)(z6,{...e,section:`article`,onSettings:()=>n(`/settings`)}),t.sources.article===`off`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`No article: for a project of images or a thumbnail made from prompts. Narration, the PDF and anything else that reads the article stay off.`}):t.sources.article===`provide`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`Research is Off because the article is provided.`}):(0,h.jsx)(Mhe,{...e})]})}function zhe(){let{api:e}=z(),t=rP(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=Oy(),u=N({queryKey:[`play-drafts`],queryFn:async()=>{let t=await ZM(e);if(!t.ok)throw Error(t.message);return t.value.drafts}}),d=async()=>{if(!r||s)return;let e=r.id;c(!0),o(null);try{await t.discard({id:r.id,version:r.version}),i(null),await n.cancelQueries({queryKey:[`play-drafts`]}),n.setQueryData([`play-drafts`],t=>t?.filter(t=>t.id!==e))}catch(e){let t=e instanceof Error?e.message:`The draft wasn't discarded. Try again.`;o(t),l(t,`error`)}finally{c(!1)}};return(0,h.jsxs)(`section`,{"aria-label":`Drafts`,className:`flex min-w-0 flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(`p`,{role:`status`,className:L(`engraved min-w-[112px] text-right`,t.status===`saved`?`text-accent-ink`:t.status===`error`||t.status===`conflict`?`text-danger`:`text-ink-3`),children:{unsaved:`Unsaved`,saving:`Saving…`,saved:`Saved`,error:`Couldn't save`,conflict:`Changed elsewhere`}[t.status]}),t.status===`error`?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{!t.view&&t.activeId&&t.edited===0?t.open(t.activeId):t.flush()},children:`Retry`}):null,t.status===`conflict`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{t.activeId&&t.open(t.activeId)},children:`Reload saved draft`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void t.saveAsNew(),children:`Save as a new draft`}),(0,h.jsx)(V,{id:`play.draft-conflict`})]}):null,(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,children:[`Drafts`,(0,h.jsx)(uc,{"aria-hidden":`true`,className:`size-4`})]})}),(0,h.jsxs)(Eb,{align:`end`,className:`w-[340px] p-0`,"aria-label":`Saved drafts`,children:[u.isPending?(0,h.jsx)(`p`,{role:`status`,className:`px-3 py-2`,children:`Loading drafts…`}):null,u.error?(0,h.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:[u.error.message,` `,(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void u.refetch(),children:`Retry`})]}):null,u.data?.length===0?(0,h.jsx)(`p`,{className:`px-3 py-2`,children:`No saved drafts`}):null,a?(0,h.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:a}):null,u.data?.length?(0,h.jsx)(pU,{label:`Saved drafts`,className:`max-h-72 overflow-y-auto border-t-0`,children:u.data.map(e=>(0,h.jsx)(mU,{title:e.title||`Untitled draft`,onSelect:()=>void t.open(e.id),meta:(0,h.jsxs)(`time`,{dateTime:e.updatedAt,children:[`Last edited `,ku(e.updatedAt)]}),actions:(0,h.jsx)(wy,{size:`small`,label:`Discard ${e.title||`Untitled draft`}`,onClick:()=>{i(e),o(null)},children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:e.readable?null:(0,h.jsx)(`p`,{className:`m-0 text-label text-waiting`,children:`Unsupported or corrupt draft. Try opening it to recover, or discard it.`})},e.id))}):null]})]}),(0,h.jsx)(R,{onClick:()=>void t.newDraft(),children:`New draft`}),(0,h.jsx)(V,{id:`play.drafts`}),(0,h.jsx)(jy,{open:r!==null,title:`Discard ${r?.title||`Untitled draft`}?`,consequence:`The draft is removed. This cannot be undone.`,confirmLabel:`Discard draft`,pending:s,onConfirm:()=>void d(),onCancel:()=>{s||i(null)}})]})}function B6(e,t){let n=[...e.querySelectorAll(`[data-play-field]`)].find(e=>e.dataset.playField===t);if(!n||n.hasAttribute(`disabled`))return!1;let r=n.closest(`details`);return r!==null&&!r.open&&(r.open=!0),n.focus(),n.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`instant`}),document.activeElement===n}function Bhe(e,t,n,r=[]){let i=e;if(e===`fontUpload`&&(i=`subtitles.fontUpload`),/^provided\.images\.\d+$/.test(e)&&(i=`provided.images`),e===`subtitles`&&(i=`subtitles.mode`),e===`chunking`&&(i=`chunking.mode`),[`audio`,`llm`,`images`].includes(e)&&(i=`${e}.provider`),e===`provided`){let e=[`audio`,`images`,`thumbnail`].find(e=>t.sources[e]===`provide`&&(e===`images`?t.provided.images:[t.provided[e]]).some(e=>e&&(e.error!==void 0||e.file===void 0))),n=t.provided.shortsMusic;i=e===void 0&&jN(t)&&n!==void 0&&(n.error!==void 0||n.file===void 0)?`shorts.music`:t.reference?.source===`provide`&&t.provided.reference!==void 0&&(t.provided.reference.error!==void 0||t.provided.reference.file===void 0)?`provided.reference`:`provided.${e??`audio`}`;let r=t.provided.ambientBed;e===void 0&&MN(t)&&r!==void 0&&(r.error!==void 0||r.file===void 0)&&(i=`ambientBed.file`)}let a=/^imagePrompts\.(\d+)\.(.+)$/.exec(e);if(a){let e=t.imagePrompts[Number(a[1])];e&&(i=`imagePrompts.${e.name}.${a[2]}`)}e===`imagePrompts`&&(i=t.imagePrompts[0]?`imagePrompts.${t.imagePrompts[0].name}.number`:`imagePrompts`);let o=/^variants\.(\d+)\.(.+)$/.exec(e);o&&(i=`items.${n[Number(o[1])]?.key??o[1]}.${o[2]}`);let s=/^items\.(\d+)\.(.+)$/.exec(e);s&&(i=Number(s[1])===0?s[2]??e:`items.${n[Number(s[1])-1]?.key??s[1]}.${s[2]}`);let c=t=>t.some(t=>e===t||e.startsWith(`${t}.`));return{section:c([`title`,`articlePrompt`,`provided.article`,`provided.research`,`sources.article`,`sources.research`,...(IN(t,r)[0]?.section??`article`)===`article`?[`llm`]:[],`values`])?`content`:c([`format`,`subtitles`,`fontUpload`])?`style`:c(`audio,narrationPrompt,voices,provided.audio,intro,outro,chunking,images,imagePrompts,imageScale,provided.images,thumbnailPrompt,provided.thumbnail,provided.reference,reference,provided,sources,imageSeconds,zoomPercent,motionStyle,edgeSilenceSeconds,document,youtubeDescription,descriptionPrompt,shorts,videoEdit,ambientBed,loudness,sentencePauseSeconds,paragraphPauseSeconds,llm`.split(`,`))?`outputs`:`review`,field:i}}function Vhe({fields:e,values:t,origins:n,topics:r=[],hide:i=[],problem:a,onChange:o}){let s=e.filter(e=>!i.includes(e.name));return s.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-3 text-small text-ink-2`,children:`Each keyword is entered once and fills every place that names it.`}),(0,h.jsx)(_0,{keywords:s.map(e=>({name:e.name,value:Object.hasOwn(t,e.name)?t[e.name]??``:``,feeds:n?.get(e.name)??[],topic:r.includes(e.name)})),problem:a,onChange:o})]}):null}var Hhe={every:`minutes`,value:`2`};function Uhe({document:e,problem:t,onEdit:n}){let r=(0,m.useId)(),{form:i}=e,a=i.imageScale,o=t(`imageScale.value`)??t(`imageScale`),s=a===void 0?void 0:o===void 0?Ghe(e):{text:o,problem:!0},c=t=>{let{imageScale:r,...o}=i;n({...e,form:{...o,...t===void 0?{}:{imageScale:t},...t!==void 0&&a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})};return(0,h.jsxs)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{checked:a!==void 0,label:`More images for long videos`,tip:`play.image-scale`,describedBy:`${r}-line`,onChange:e=>c(e?Hhe:void 0)}),a===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,...Ob,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,tip:`play.image-scale.rate`,value:a.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>c({every:e,value:Whe(a.value,a.every,e)})}),a.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{id:`${r}-value`,"data-play-field":`imageScale.value`,"aria-label":a.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`sl-input--number`,"aria-invalid":s?.problem===!0,"aria-describedby":`${r}-line`,value:a.value,onChange:e=>c({every:a.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:a.every===`minutes`?`minutes`:`images per hour`})]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:s.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:s.text})]})}function Whe(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function Ghe(e){let{form:t}=e,n=t.imageScale;if(n===void 0)return{text:``,problem:!1};let r=Number(n.value.trim()),i=n.every===`minutes`;if(!(n.value.trim()!==``&&(i?r>=.25&&r<=60:r>=1&&r<=240)))return{text:i?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`,problem:!0};let a=i?YO(r):r,o=t.sources.article===`provide`,s=Number(e.expectedWords.trim()),c=o?Math.max(1,qO(t.provided.article)):Number.isInteger(s)&&s>=1&&s<=1e5?s:GO,l=t.imagePrompts.map(e=>({name:e.name,number:Math.max(0,Number.parseInt(e.number,10)||0)})),u=l.reduce((e,t)=>e+t.number,0),d={perHour:a,words:c},f=$O({imagePrompts:l,imageScale:d,sources:t.sources}).reduce((e,t)=>e+t,0),p=`about ${String(Math.max(1,Math.round(JO(c))))} minutes (${c.toLocaleString(`en-US`)} words ${o?`in the article`:`expected, set on Review`})`;if(l.length===0)return{text:`For ${p}: tick an image prompt to see the count.`,problem:!1};let m=ZO(d)>=240?` That is the most a run makes (240); the images repeat after that.`:``;return{text:f>u?`For ${p}: ${String(f)} images, ${String(f-u)} more than the prompts' ${String(u)}.${m}`:`For ${p}: the prompts' ${String(u)} images already cover it.`,problem:!1}}function Khe({document:e,onEdit:t}){let{form:n}=e;return(0,h.jsx)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,form:{...a,...r?{imageScenes:!0}:{}}})}})})}function qhe(e){return e.upload?(0,h.jsx)(V6,{value:e.value,onPick:e.onPick,upload:e.upload}):(0,h.jsx)(Jhe,{...e})}function Jhe({value:e,onPick:t,onUploading:n}){let{api:r}=z(),i=_(),a=P({mutationFn:e=>lN(r,e),onSuccess:({font:e})=>{i.setQueryData(sN,t=>({fonts:[...(t?.fonts??[]).filter(t=>t.id!==e.id),e]})),i.invalidateQueries({queryKey:sN})}}),o=a.isPending,s=(0,m.useRef)(t);s.current=t;let c=(0,m.useRef)(n);return c.current=n,(0,m.useEffect)(()=>{c.current(o)},[o]),(0,m.useEffect)(()=>()=>c.current(!1),[]),(0,h.jsx)(V6,{value:e,onPick:t,upload:{pending:o,error:a.error?.message,pick:e=>a.mutate(e,{onSuccess:({font:e})=>s.current(e.id)})}})}function V6({value:e,onPick:t,upload:n}){let{api:r}=z(),i=(0,m.useId)(),a=(0,m.useId)(),o=N({queryKey:sN,queryFn:()=>cN(r),staleTime:6e4}),s=n.pending,c=o.data?.fonts??[],l=e!=="default"&&!c.some(t=>t.id===e);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:i,children:`Subtitle font`}),(0,h.jsx)(V,{id:`project.subtitles.font`,className:`-my-1`})]}),(0,h.jsxs)(TV,{id:i,"data-play-field":`subtitles.fontId`,value:e,disabled:s,onChange:e=>t(e.target.value),className:`text-small`,children:[c.some(e=>e.id==="default")?null:(0,h.jsx)(`option`,{value:`default`,children:`Default font · bundled`}),l?(0,h.jsxs)(`option`,{value:e,children:[e,` · saved font`]}):null,c.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.source]},e.id))]})]}),(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,children:[(0,h.jsx)(X4,{htmlFor:a,className:`mb-1`,children:`Upload font (.ttf or .otf)`}),(0,h.jsx)(`input`,{id:a,"data-play-field":`subtitles.fontUpload`,type:`file`,accept:`.ttf,.otf,font/ttf,font/otf`,disabled:s,className:`w-full text-small text-ink-2 file:mr-2 file:rounded-control file:border file:border-line-strong file:bg-sunken file:px-2 file:py-1 file:text-ink`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&n.pick(t)}})]})]}),s?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Uploading font…`}):null,n.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:n.error}):null,l&&o.data?(0,h.jsx)(`p`,{role:`alert`,children:`Saved font is unavailable. Choose another font or upload it again.`}):null,o.error?(0,h.jsxs)(`p`,{role:`alert`,className:`text-small text-danger`,children:[`The font list couldn't be loaded. `,o.error.message]}):null]})}function Yhe(e){return e===`9:16`?{width:1080,height:1920}:{width:1920,height:1080}}function Xhe(e,t){switch(e){case`top`:return{y:60,alignment:8,translateY:0};case`upper-middle`:return{y:t/4,alignment:5,translateY:-50};case`center`:return{y:t/2,alignment:5,translateY:-50};case`lower-middle`:return{y:t*3/4,alignment:5,translateY:-50};case`bottom`:return{y:t-60,alignment:2,translateY:-100}}}function Zhe({value:e,format:t,sample:n=`Every story begins with a word.`,backgroundUrl:r,showCaptions:i=!0,maxFrameHeight:a}){let{api:o}=z(),s=uN(o,e.fontId),c=`subtitle-preview-${(0,m.useId)().replace(/[^a-zA-Z0-9]/g,``)}`,[l,u]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(typeof FontFace>`u`||!document.fonts)return;let e=!0,t=new FontFace(c,`url(${JSON.stringify(s)})`);return u(!1),t.load().then(t=>{e&&document.fonts.add(t)}).catch(()=>{e&&u(!0)}),()=>{e=!1,document.fonts.delete(t)}},[c,s]);let d=Yhe(t),f=Xhe(e.position??`bottom`,d.height),p=Number.isFinite(e.fontSize)?Math.max(16,Math.min(120,e.fontSize)):48,g={position:`absolute`,left:`50%`,top:`${f.y/d.height*100}%`,width:`${(d.width-120)/d.width*100}%`,transform:`translate(-50%, ${f.translateY}%)`,fontFamily:`"${c}", sans-serif`,fontSize:`${p/d.width*100}cqw`,lineHeight:1.2,overflowWrap:`anywhere`,WebkitTextStroke:`${2.5/d.width*100}cqw #101010`,paintOrder:`stroke fill`,textShadow:`0 ${100/d.width}cqw ${100/d.width}cqw #000`};return(0,h.jsxs)(`figure`,{className:`min-w-0 self-start`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Style preview`}),(0,h.jsx)(`span`,{children:t})]}),(0,h.jsxs)(`div`,{role:`img`,"aria-label":`Subtitle style preview`,"data-format":t,"data-position":e.position??`bottom`,className:`sl-media__frame mx-auto w-full text-center text-white`,style:{aspectRatio:`${d.width} / ${d.height}`,maxWidth:t===`9:16`?a?`min(240px, calc((${a}) * 9 / 16))`:240:480,containerType:`inline-size`},children:[r?(0,h.jsx)(`img`,{src:r,alt:``,className:`absolute inset-0 h-full w-full object-cover`}):null,i?(0,h.jsx)(`span`,{role:`note`,"aria-label":`Caption sample`,style:g,children:n}):null]}),(0,h.jsxs)(`figcaption`,{className:`mt-2 text-label text-ink-3`,children:[d.width,` × `,d.height,` · Preview at reduced scale.`,l?` Font preview unavailable; showing a fallback.`:``]})]})}function H6({value:e,format:t=`16:9`,audioEnabled:n,videoEnabled:r,disabled:i=!1,onChange:a,onUploading:o,problem:s,session:c,fontUpload:l,showPreview:u=!0,illustratedPositions:d=!1,rawFontSize:f}){let p=(0,m.useId)(),g=(0,m.useId)(),_=(0,m.useId)(),v=(0,m.useId)(),[y,b]=(0,m.useState)(!1),x=s?.(`subtitles.fontId`),S=s?.(`subtitles.fontSize`),C=s?.(`subtitles.mode`)??s?.(`subtitles`);return(0,h.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":`Subtitles`,children:[(0,h.jsxs)(`fieldset`,{disabled:i||!n,className:`flex min-w-0 flex-col gap-3 disabled:opacity-60`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 flex-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:p,children:`Subtitles`}),(0,h.jsx)(V,{id:`project.subtitles.mode`,className:`-my-1`})]}),(0,h.jsxs)(`select`,{id:p,"data-play-field":`subtitles.mode`,value:n?e.mode:`off`,disabled:l?.pending??y,"aria-describedby":_,"aria-invalid":C!==void 0,onChange:t=>a({...e,mode:t.target.value}),className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:[(0,h.jsx)(`option`,{value:`off`,children:`Off`}),(0,h.jsx)(`option`,{value:`files`,children:`Subtitle files (.srt + .vtt)`}),(0,h.jsx)(`option`,{value:`burn-in`,disabled:!r,children:`Burn into video + files`})]})]}),(0,h.jsx)(`span`,{className:`pb-1 text-label text-ink-3`,children:`English · local · no paid API`})]}),e.mode!==`off`&&n?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Timed from your narration on this computer. First use downloads an approximately 95 MB speech model. Review the subtitles before publishing.`}),(0,h.jsxs)(`div`,{className:`grid items-start gap-5`,style:{gridTemplateColumns:`repeat(auto-fit, minmax(min(100%, 240px), 1fr))`},children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(qhe,{...l?{upload:l}:{},value:e.fontId,onPick:t=>c?c.selectFont(t):a({...e,fontId:t}),onUploading:e=>{b(e),o?.(e)}}),(0,h.jsxs)(`div`,{className:d?`w-full`:`max-w-[180px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:g,children:`Subtitle font size`}),(0,h.jsx)(V,{id:`project.subtitles.size`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-5`,children:[d?(0,h.jsx)(`input`,{"aria-label":`Subtitle font size slider`,type:`range`,min:16,max:120,step:1,value:Math.max(16,Math.min(120,Number.isFinite(e.fontSize)?e.fontSize:48)),className:`min-w-0 flex-1 accent-accent`,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})}):null,(0,h.jsx)(CV,{className:d?`w-20`:void 0,id:g,"data-play-field":`subtitles.fontSize`,type:`number`,min:16,max:120,step:1,value:f?.value??e.fontSize,"aria-invalid":!kN(e)||S!==void 0,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})})]}),!kN(e)||S?(0,h.jsx)(`p`,{role:`alert`,className:`mt-1 text-label text-danger`,children:S??`Choose a whole font size from 16 to 120.`}):null]}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:d?void 0:v,id:`${v}-label`,children:`Subtitle position`}),(0,h.jsx)(V,{id:`project.subtitles.position`,className:`-my-1`})]}),d?(0,h.jsx)(Z4,{type:`single`,"aria-labelledby":`${v}-label`,value:e.position??`bottom`,onValueChange:t=>{let n=pM.find(e=>e===t);n&&a({...e,position:n})},className:`grid w-full grid-cols-5 gap-2 overflow-visible border-0`,children:pM.map((t,n)=>(0,h.jsxs)(Q4,{value:t,"aria-label":t,"data-play-field":(e.position??`bottom`)===t?`subtitles.position`:void 0,className:`flex min-w-0 flex-col items-center gap-2 rounded-control border border-line-strong bg-surface px-1 py-3 text-[10px] last:border-r data-[state=on]:border-focus data-[state=on]:text-accent-ink data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`relative block h-11 w-7 rounded-[2px] border border-current`,children:(0,h.jsx)(`span`,{className:`absolute left-1 right-1 h-[3px] bg-current`,style:{top:`${8+n*20}%`}})}),(0,h.jsxs)(`span`,{children:[t[0]?.toUpperCase(),t.slice(1)]})]},t))}):(0,h.jsx)(`select`,{id:v,"data-play-field":`subtitles.position`,value:e.position??`bottom`,onChange:t=>{let n=pM.find(e=>e===t.target.value);n&&a({...e,position:n})},className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:pM.map(e=>(0,h.jsxs)(`option`,{value:e,children:[e[0]?.toUpperCase(),e.slice(1)]},e))})]})]}),u?(0,h.jsx)(Zhe,{value:e,format:t,...c?{sample:c.previewText}:{}}):null]}),c?.fontUpload&&!c.fontUploading?(0,h.jsxs)(`p`,{role:`alert`,children:[`Reattach `,c.fontUpload.name,`, or select a font.`]}):null,x?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}):null,e.mode===`files`?(0,h.jsx)(`p`,{className:`text-label text-ink-3`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]}):null]}),c?.fontUpload&&(e.mode===`off`||!n)?(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:c.fontUploading?`status`:`alert`,className:`text-small text-ink-2`,children:c.fontUploading?`Uploading ${c.fontUpload.name}…`:`Unfinished font upload: ${c.fontUpload.name}`}),l?.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:l.error}):null,(0,h.jsx)(R,{"data-play-field":`subtitles.fontUpload`,disabled:i,onClick:()=>c.selectFont(e.fontId),children:`Keep current font`})]}):null,C?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:C}):null,(0,h.jsx)(`p`,{id:_,className:`text-small text-ink-2`,children:n?r?`Optional: download subtitles separately or keep them visible in the video.`:`Audio exports support separate subtitle files. Enable Video to burn captions into an MP4.`:`Turn Audio on to add subtitles.`})]})}function U6({value:e,onPick:t}){let n=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`w-full`,...Ob,children:[(0,h.jsxs)(`span`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(X4,{id:n,children:`Frame format`}),(0,h.jsx)(V,{id:`play.format`,className:`-my-1`})]}),(0,h.jsx)(Z4,{type:`single`,value:e,"aria-labelledby":n,className:`w-full max-w-[400px] gap-3 overflow-visible border-0`,onValueChange:e=>{(e===`16:9`||e===`9:16`)&&t(e)},children:[`16:9`,`9:16`].map(t=>(0,h.jsxs)(Q4,{value:t,"data-play-field":e===t?`format`:void 0,"aria-label":t,className:`flex h-28 min-w-0 flex-1 items-center justify-center gap-4 rounded-control border border-line-strong bg-surface p-3 last:border-r data-[state=on]:border-focus data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{className:`flex h-12 items-center justify-center`,"aria-hidden":`true`,children:(0,h.jsx)(`span`,{"data-format-shape":t,className:`block rounded-[2px] border-2 border-current`,style:{width:t===`16:9`?64:27,aspectRatio:t===`16:9`?`16 / 9`:`9 / 16`}})}),(0,h.jsxs)(`span`,{className:`text-left`,children:[(0,h.jsx)(`span`,{className:`block text-body font-semibold`,children:t}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:t===`16:9`?`Landscape`:`Portrait`})]})]},t))})]})}function Qhe({problem:e}){let t=rP(),{document:n}=t,{form:r}=n,i=e=>t.edit({...n,form:{...r,subtitles:{...e,fontSize:r.subtitles.fontSize}}});return(0,h.jsxs)(`div`,{"data-tour":`play-subtitles`,className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`See frame and caption changes in the preview as you go.`}),(0,h.jsx)(U6,{value:r.format,onPick:e=>t.edit({...n,form:{...r,format:e}})}),(0,h.jsx)(`div`,{className:`border-t border-line pt-4`,children:(0,h.jsx)(H6,{showPreview:!1,illustratedPositions:!0,fontUpload:t.fontUpload,session:{previewText:n.previewText,fontUploading:t.fontUploading,fontUpload:n.fontUpload,selectFont:t.selectFont,uploadSubtitleFont:t.uploadSubtitleFont},value:{...r.subtitles,fontSize:Number(r.subtitles.fontSize)},rawFontSize:{value:r.subtitles.fontSize,onChange:e=>t.edit({...n,form:{...r,subtitles:{...r.subtitles,fontSize:e}}})},format:r.format,audioEnabled:r.sources.audio!==`off`,videoEnabled:r.sources.video===`generate`&&r.sources.images!==`off`,onChange:i,problem:e})}),(0,h.jsx)(xV,{label:`Preview text`,tip:`play.preview-text`,className:`border-t border-line pt-4`,children:(0,h.jsx)(CV,{value:n.previewText,onChange:e=>t.edit({...n,previewText:e.target.value})})})]})}function $he(e){let t=rP(),n=t.document,r=H3(),i=U3(),{form:a,entries:o,problem:s,update:c}=e;return(0,h.jsx)(yhe,{...e,titled:!1,cast:r,language:i,rawCounts:{...n.form.chunking,onChange:(e,r)=>t.edit({...n,form:{...n.form,chunking:{...n.form.chunking,mode:e,...e===`words`?{words:r}:e===`characters`?{characters:r}:{}}}})},advanced:(0,h.jsxs)(h.Fragment,{children:[[`intro`,`outro`].map(e=>(0,h.jsx)(FV,{field:e,label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,value:a[e],placeholder:`Off`,options:o.filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),problem:s(e),onPick:t=>c({[e]:t})},e)),(0,h.jsx)(`div`,{className:`col-span-full flex flex-wrap gap-2`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:e.onSettings,children:`Settings`})}),(0,h.jsx)(`div`,{className:`col-span-full empty:hidden`,children:(0,h.jsx)(z6,{...e,section:`narration`,onSettings:e.onSettings})})]})})}function ege(e){let t=rP(),n=t.document;return(0,h.jsx)(bhe,{...e,titled:!1,more:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Uhe,{document:n,problem:e.problem,onEdit:t.edit}),n.form.sources.article===`off`?null:(0,h.jsx)(Khe,{document:n,onEdit:t.edit})]}),rawNumbers:{values:n.form.imagePrompts,onChange:(e,r)=>t.edit({...n,form:{...n.form,imagePrompts:n.form.imagePrompts.map(t=>t.name===e?{...t,number:r}:t)}})}})}function tge(e){let t=rP(),n=t.document,r=U3();return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Fhe,{...e,titled:!1,extras:!1,language:r,rawTiming:{imageSeconds:n.form.imageSeconds,zoomPercent:n.form.zoomPercent,edgeSilenceSeconds:n.form.edgeSilenceSeconds,onChange:(e,r)=>t.edit({...n,form:{...n.form,[e]:r}})}}),n.form.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:`sl-fields border-b border-line py-4`,children:(0,h.jsx)(R6,{field:`silenceGapSeconds`,label:`Silence between segments (seconds)`,tip:`play.silence-gap`,placeholder:String(e.silenceGapSeconds),step:.1,problem:e.problem(`silenceGapSeconds`),value:n.form.silenceGapSeconds??``,onChange:e=>{let{silenceGapSeconds:r,...i}=n.form;t.edit({...n,form:e.trim()===``?i:{...i,silenceGapSeconds:e}})}})}),(0,h.jsx)(Qhe,{problem:e.problemOf})]})}function nge(e){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z6,{...e,section:`outputs`,onSettings:e.onSettings}),(0,h.jsx)(Phe,{...e}),(0,h.jsx)(`section`,{className:`border-b border-line py-4`,children:(0,h.jsx)(L6,{form:e.form,prompts:e.prompts,problem:e.problem,update:e.update,onPickFiles:e.onPickFiles,onRemoveFile:e.onRemoveFile,...e.onReattachFile===void 0?{}:{onReattachFile:e.onReattachFile}})}),e.form.sources.article===`off`?null:(0,h.jsx)(Ihe,{...e})]})}function W6(e,t){if(t===void 0||t.length===0||e.trim()===``)return[];let n=[];for(let[r,i]of t.entries()){let t=1/0;for(let n of[i.name,...i.aliases]){let r=rge(e,n);r!==void 0&&r<t&&(t=r)}Number.isFinite(t)&&n.push({member:i,at:t,order:r})}return n.sort((e,t)=>e.at-t.at||e.order-t.order).map(e=>e.member)}function rge(e,t){let n=t.trim().split(/\s+/u).filter(Boolean);if(n.length===0)return;let r=RegExp(`(?<![\\p{L}\\p{N}])${n.map(ige).join(`\\s+`)}(?![\\p{L}\\p{N}])`,`iu`).exec(e);return r===null?void 0:r.index}function ige(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function age(e,t){let n=e.provided.reference?.file;if(e.sources.images===`generate`&&e.reference?.source===`provide`&&n!==void 0)return{image:{kind:`upload`,stagedFileId:n.id},drawnOn:`the establishing image`};let r=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),i=W6([e.title,...Object.values(e.values)].join(` `),r)[0]??r[0],a=i?.images[0];if(i!==void 0&&a!==void 0)return{image:{kind:`picture`,sha256:a},drawnOn:`${i.name}'s picture`}}function oge({selected:e,reviewed:t}){let n=e=>W3.find(t=>t.stage===e)?.label??e;return e?.length?(0,h.jsxs)(`div`,{className:`space-y-3 text-body`,children:[t?.length?t.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`font-medium`,children:[`Run `,e.runIndex+1,` · Before `,n(e.stage)]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.dependents.length?`Also holds: ${e.dependents.map(n).join(`, `)}.`:`No dependent steps.`})]},`${e.runIndex}-${e.checkpointId}`)):(0,h.jsxs)(`p`,{children:[`Selected: `,e.map(e=>`Before ${n(e)}`).join(`, `),`. Refresh review to confirm dependent steps.`]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Approval required on the project page. Starting this run does not approve these checkpoints.`})]}):(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No review checkpoints selected.`})}function sge({estimates:e}){let t=e.reduce((e,t)=>e+t.low,0),n=e.reduce((e,t)=>e+t.high,0),r=e.reduce((e,t)=>e+t.unknown,0),i=e[0]?.rows.map((t,n)=>({...t,low:e.some(e=>e.rows[n]?.low===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.low??0),0),high:e.some(e=>e.rows[n]?.high===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.high??0),0),apiLow:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiLow==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiLow??0),0),apiHigh:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiHigh==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiHigh??0),0)}))??[],a=e.some(e=>e.apiLow!==void 0),o=e.reduce((e,t)=>e+(t.apiLow??0),0),s=e.reduce((e,t)=>e+(t.apiHigh??0),0),c=e.reduce((e,t)=>e+(t.apiUnknown??0),0);return e.length===0?(0,h.jsx)(`div`,{}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-title-2 font-semibold`,children:[r?`Known subtotal: `:`Estimated total: `,G6(t,n)]}),r?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Plus `,r,` stage charge`,r===1?``:`s`,` with unavailable pricing.`]}):null,(0,h.jsxs)(`details`,{className:`rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Cost by stage · `,i.length,` `,i.length===1?`stage`:`stages`]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 pt-1 pb-3`,children:[a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o===0&&s===0?`CLI steps: $0 on your plan · no API price is listed for their models.`:`CLI steps: $0 on your plan · ~${G6(o,s)} via API${c?` (plus ${String(c)} with no API price)`:``}.`}):null,(0,h.jsx)(`ul`,{"aria-label":`Cost by stage`,className:`m-0 list-none divide-y divide-line p-0`,children:i.map(e=>(0,h.jsxs)(`li`,{className:`py-2`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between gap-4 text-small`,children:[(0,h.jsx)(`span`,{children:e.stage}),(0,h.jsx)(`span`,{className:`text-right tabular-nums`,children:e.onPlan===!0?e.apiLow===null||e.apiHigh===null?`$0 on your plan · API price unknown`:`$0 on your plan · ~${G6(e.apiLow,e.apiHigh)} via API`:e.low===null||e.high===null?`Unknown`:G6(e.low,e.high)})]}),(0,h.jsx)(`p`,{className:`m-0 mt-0.5 text-label text-ink-3`,children:e.detail})]},e.stage))}),[...new Set(e.flatMap(e=>e.assumptions))].map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e},e)),(0,h.jsxs)(`p`,{className:`m-0 text-label text-ink-3`,children:[`Catalogue verified `,e[0]?.catalogueDate??`date unavailable`,`. Batch rows show combined costs.`]})]})]})]})}function G6(e,t){let n=e=>e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`;return e===t?n(e):`${n(e)} – ${n(t)}`}function K6(e){let t=TA(SA(e)),n=new Map(TA(fA)),r=t.filter(([e,t])=>e!==`Cuts`&&n.get(e)!==t).map(([e,t])=>e===`Animate images`?`Animated images: ${t} (paid)`:e===`Chapter cards`?`Chapter cards`:e===`Transition`?t:`${e}: ${t}`);return r.length===0?`Plain cuts, no effects`:r.join(` · `)}function cge(e){return e===void 0?{ok:!1,text:`Provider status unavailable`}:e.readiness.kind===`cli`?tF(e.readiness)?{ok:!0,text:e.readiness.version===void 0?`CLI ready`:`CLI ready · ${e.readiness.version}`}:{ok:!1,text:e.readiness.issue??`CLI not found`}:e.readiness.kind===`local`?e.readiness.available?{ok:!0,text:`Built-in voice · ${e.readiness.engine??`ready`}`}:{ok:!1,text:e.readiness.issue??`No speech program found`}:e.readiness.hasKey?{ok:!0,text:`API key saved`}:{ok:!1,text:`API key missing`}}function lge(e,t){let n=e.sources.audio===`generate`,r=[`from_prompt`,`prompt_by_llm`].includes(e.sources.thumbnail);return[...(e.sources.article===`generate`||e.sources.thumbnail===`prompt_by_llm`||pj(e)||jN(e)||n&&[`intro`,`outro`].some(n=>t.some(t=>t.category===n&&t.name===e[n]&&t.mode===`llm`)))&&e.llm?[{field:`llm.provider`,family:`llm`,label:`Text generation`,provider:e.llm.provider,model:e.llm.model}]:[],...n&&e.audio?[{field:`audio.provider`,family:`tts`,label:`Narration`,provider:e.audio.provider,model:e.audio.model,voice:e.audio.voice}]:[],...(e.sources.images===`generate`||r||jN(e)||CA(e))&&e.images?[{field:`images.provider`,family:`image`,label:`Images`,provider:e.images.provider,model:e.images.model}]:[]]}function q6({name:e,children:t}){return(0,h.jsxs)(`section`,{"aria-label":`${e} summary`,className:`min-w-0 border-t border-line pt-5`,children:[(0,h.jsx)(`h3`,{className:`mb-4 font-semibold`,children:e}),t]})}function uge({form:e,entries:t,providers:n,voices:r,textModels:i,audioModels:a,imageModels:o,onReveal:s}){let c=lge(e,t);if(!c.length)return(0,h.jsx)(q6,{name:`Run readiness`,children:(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No generated providers required. Supplied content is ready for processing.`})});let l={llm:i,tts:a,image:o};return(0,h.jsxs)(q6,{name:`Run readiness`,children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`These checks are refreshed with Review and checked again when you start.`}),(0,h.jsx)(`ul`,{className:`divide-y divide-line`,"aria-label":`Run readiness checks`,children:c.map(e=>{let t=n?.find(t=>t.id===e.provider&&t.family===e.family),i=cge(t),a=l[e.family],o=a?.models.find(t=>t.id===e.model),c=a===void 0?{ok:!0,text:`Model checked at Start`}:o!==void 0||a.allowsCustom?{ok:!0,text:`Model available`}:{ok:!1,text:`Model unavailable`},u=e.voice===void 0?void 0:r===void 0?{ok:!1,text:`Voice list unavailable`}:r.some(t=>t.provider===e.provider&&t.voiceId===e.voice)?{ok:!0,text:`Voice saved`}:{ok:!1,text:`Voice missing`},d=[i,c,...u?[u]:[]],f=d.every(e=>e.ok);return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-3 py-3`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,h.jsx)(`span`,{className:f?`text-lime`:`text-danger`,children:f?`Ready`:d.filter(e=>!e.ok).map(e=>e.text).join(` · `)}),f?null:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>s(e.field),children:`Edit ↗`})]},`${e.family}:${e.provider}`)})})]})}function dge({fields:e,onReveal:t,children:n}){let{document:r,review:i}=rP(),{form:a}=r,{api:o}=z(),s=_(),c=s.getQueryData(eb(o).queryKey),l=s.getQueryData(rb(o).queryKey),u=s.getQueryData(tb(o).queryKey),d=s.getQueryData(sN),f=s.getQueryData(OV(a.llm.provider)),p=s.getQueryData(OV(a.audio.provider)),m=s.getQueryData(OV(a.images.provider)),g=a.sources.audio===`generate`,v=[`from_prompt`,`prompt_by_llm`].includes(a.sources.thumbnail),y=a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||pj(a)||jN(a)||g&&[`intro`,`outro`].some(e=>l?.entries.some(t=>t.category===e&&t.name===a[e]&&t.mode===`llm`)),b=e=>c?.providers.find(t=>t.id===e)?.displayName??e,x=(e,n,r)=>(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[90px_minmax(0,1fr)_auto] items-start gap-x-3 py-1 sm:grid-cols-[145px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(`dt`,{className:`break-words py-2 text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`min-w-0 whitespace-pre-wrap break-words py-2`,children:r||`Not selected`}),n?(0,h.jsx)(`dd`,{children:(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit ${e}`,onClick:()=>t(n),children:`Edit ↗`})}):null]},n??e),S=a.chunking.mode===`words`||a.chunking.mode===`characters`?a.chunking.mode:null;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(uge,{form:a,entries:l?.entries??[],providers:c?.providers,voices:u?.voices,textModels:f,audioModels:p,imageModels:m,onReveal:t}),(0,h.jsxs)(q6,{name:`Content`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Project`,`title`,a.title||`Untitled run`),x(`Article`,`sources.article`,PN[a.sources.article]),a.sources.article===`generate`?x(`Article prompt`,`articlePrompt`,a.articlePrompt):x(`Article text`,`provided.article`,`Your article`),a.sources.article===`generate`?x(`Research`,`sources.research`,PN[a.sources.research]):x(`Research`,null,`Off · Article is provided`),a.sources.research===`provide`&&a.sources.article===`generate`?x(`Research text`,`provided.research`,a.provided.research):null,y?(0,h.jsxs)(h.Fragment,{children:[x(`Text provider`,`llm.provider`,b(a.llm.provider)),x(`Text model`,`llm.model`,f?.models.find(e=>e.id===a.llm.model)?.name??a.llm.model),a.llm.thinking||f?.models.find(e=>e.id===a.llm.model)?.thinkingModes?.length?x(`Thinking`,`llm.thinking`,a.llm.thinking??`Model default`):null]}):null,e.map(({name:e})=>x(e,`values.${e}`,a.values[e]??``))]}),n]}),(0,h.jsx)(q6,{name:`Outputs`,children:(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Narration`,`sources.audio`,PN[a.sources.audio]),g?(0,h.jsxs)(h.Fragment,{children:[x(`Audio provider`,`audio.provider`,b(a.audio.provider)),x(`Audio model`,`audio.model`,p?.models.find(e=>e.id===a.audio.model)?.name??a.audio.model),x(`Voice`,`audio.voice`,u?.voices.find(e=>e.provider===a.audio.provider&&e.voiceId===a.audio.voice)?.name??a.audio.voice),x(`Chunking`,S?`chunking.${S}`:`chunking.mode`,S?`Every ${a.chunking[S]||`(not entered)`} ${S}`:a.chunking.mode===`whole`?`Whole text`:`Paragraph`),x(`Intro`,`intro`,a.intro||`Off`),x(`Narration Preparation`,`narrationPrompt`,a.narrationPrompt?`${a.narrationPrompt} · One LLM call per narration chunk and entry`:`Off`),x(`Outro`,`outro`,a.outro||`Off`)]}):null,a.sources.audio===`provide`?x(`Narration file`,`provided.audio`,a.provided.audio?.name):null,x(`Images`,`sources.images`,PN[a.sources.images]),a.sources.images===`generate`||v||jN(a)?(0,h.jsxs)(h.Fragment,{children:[x(`Image provider`,`images.provider`,b(a.images.provider)),x(`Image model`,`images.model`,m?.models.find(e=>e.id===a.images.model)?.name??a.images.model),a.images.thinking===void 0?null:x(`Image effort`,`images.thinking`,a.images.thinking)]}):null,a.sources.images===`generate`&&a.reference!==void 0&&a.reference.source!==`off`?x(`Establishing image`,a.reference.source===`prompt`?`reference.prompt`:`provided.reference`,`${a.reference.source===`prompt`?a.reference.prompt||`(no prompt picked)`:a.provided.reference?.name??`(no file attached)`}${a.reference.thumbnail?` · thumbnail too`:``}`):null,a.sources.images===`generate`?a.imagePrompts.length?a.imagePrompts.map((e,t)=>x(e.name,`imagePrompts.${t}.number`,`${e.name} · ${e.number||`(not entered)`} images`)):x(`Image prompts`,`imagePrompts`,`None selected`):null,a.sources.images===`provide`?x(`Image files`,`provided.images`,a.provided.images.length?(0,h.jsx)(`ol`,{className:`list-inside list-decimal`,children:a.provided.images.map(e=>(0,h.jsx)(`li`,{children:e.name},e.attachmentId))}):`No files selected`):null,x(`Thumbnail`,`sources.thumbnail`,PN[a.sources.thumbnail]),v?x(`Thumbnail prompt`,`thumbnailPrompt`,a.thumbnailPrompt):null,a.sources.thumbnail===`provide`?x(`Thumbnail file`,`provided.thumbnail`,a.provided.thumbnail?.name):null,x(`Video`,`sources.video`,PN[a.sources.video]),a.sources.video===`generate`?x(`Seconds per image`,`imageSeconds`,a.imageSeconds||`(not entered)`):null,a.sources.video===`generate`?x(`Zoom`,`zoomPercent`,a.zoomPercent?`${a.zoomPercent}%`:`(not entered)`):null,a.sources.video===`generate`?x(`Motion`,`motionStyle`,YA[a.motionStyle]):null,a.sources.video===`generate`?x(`Cuts`,`videoEdit.cuts`,gA[SA(a).cuts]):null,a.sources.video===`generate`?x(`Look`,`videoEdit`,K6(a)):null,a.sources.audio===`off`?null:x(`Silence at start and end`,`edgeSilenceSeconds`,a.edgeSilenceSeconds?`${a.edgeSilenceSeconds} s`:`(not entered)`),a.sources.audio===`off`?null:x(`YouTube description`,`youtubeDescription`,a.youtubeDescription===!0?`${a.descriptionPrompt||`Built-in`} prompt · One LLM call after subtitle timing`:`Off`),a.sources.audio===`off`?null:x(`Shorts`,`shorts.enabled`,jN(a)&&a.shorts!==void 0?[`${a.shorts.count} shorts of ${a.shorts.minSeconds}-${a.shorts.maxSeconds} s`,`${a.shorts.prompt||`Built-in`} prompt`,`${a.shorts.imagePrompt||`Built-in`} image style`,...fge(a.shorts,a.provided.shortsMusic?.name),`Vertical images and renders after subtitle timing`].join(` · `):`Off`),x(`Document`,`sources.document`,RS(a.sources,`document`)===`generate`?`PDF · ${XS(a.document)} theme`:PN.off)]})}),(0,h.jsxs)(q6,{name:`Checkpoints`,children:[(0,h.jsx)(oge,{selected:a.checkpoints,reviewed:i.valid?i.receipt?.checkpointSet:void 0}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit checkpoints`,onClick:()=>t(`checkpoints`),children:`Edit checkpoints ↗`})]}),(0,h.jsxs)(q6,{name:`Style`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Frame`,`format`,a.format),a.sources.audio===`off`?x(`Subtitles`,null,`Off · Audio is Off`):x(`Subtitles`,`subtitles.mode`,a.subtitles.mode),a.sources.audio!==`off`&&a.subtitles.mode!==`off`?(0,h.jsxs)(h.Fragment,{children:[x(`Subtitle font`,`subtitles.fontId`,d?.fonts.find(e=>e.id===a.subtitles.fontId)?.name??a.subtitles.fontId),x(`Subtitle size`,`subtitles.fontSize`,`${a.subtitles.fontSize||`(not entered)`} px`),x(`Subtitle position`,`subtitles.position`,a.subtitles.position)]}):null]}),a.sources.audio!==`off`&&a.subtitles.mode===`files`?(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]})]})}function fge(e,t){let n=qk(e),r=n.speed,i=n.musicVolume;return[...n.titleOnScreen===!0?[`Title on screen`]:[],...r!==void 0&&r!==1?[`${r.toFixed(2)}× speed`]:[],...t===void 0?i!==void 0&&i!==15?[`Music at ${String(i)}% once added in Edit project`]:[]:[`Music: ${t} at ${String(i??15)}%`],...n.fullVideoLink===void 0?[]:[`Links ${n.fullVideoLink}`]]}function pge({fields:e,errors:t,onReveal:n,problem:r}){let i=rP(),{document:a,review:o}=i,s=a.form;(0,m.useEffect)(()=>{i.reviewDraft()},[i.reviewDraft]);let c=o.valid?o.receipt?.runs??[]:[];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Everything this run will do, the checkpoints it stops at and the reviews it runs. The estimate and the Play key stay in the right rail.`}),t.length?(0,h.jsx)(`ul`,{"aria-label":`Setup errors`,className:`text-small text-danger`,children:t.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>n(e.field),children:e.message})},`${e.field}-${e.message}`))}):null,(0,h.jsx)(Gme,{problem:r}),(0,h.jsx)(VV,{problem:r}),(0,h.jsx)(dge,{fields:e,onReveal:n,children:(0,h.jsxs)(`details`,{className:`mt-5 border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:s.sources.article===`provide`?`Read the supplied article and resolved prompts`:`Read the resolved prompt`}),c.length?c.map((e,t)=>(0,h.jsxs)(`div`,{className:`mt-4`,children:[(0,h.jsx)(`h4`,{className:`font-medium`,children:e.draft.title}),e.draft.sources.article===`provide`?(0,h.jsx)(`p`,{className:`mt-3 whitespace-pre-wrap break-words text-body`,children:e.draft.provided.article}):null,Object.entries(e.rendered).map(([e,t])=>(0,h.jsxs)(`div`,{className:`mt-3`,children:[(0,h.jsx)(`h5`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-body`,children:t})]},e))]},a.variants[t-1]?.id??i.activeId)):(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Refresh review to read the exact resolved inputs.`})]})})]})}function mge(e,t,n){return[...z3(e).map(e=>(t[e]??``).trim()===``?`${e} is left empty in the template.`:`${e} is left empty in the template (this video's ${e}, "${t[e]}", is not saved).`),...n>0?[`The ${n===1?`other video`:`${String(n)} other videos`} queued here ${n===1?`is`:`are`} not saved.`]:[]]}function hge({open:e,onClose:t}){let{api:n}=z(),r=_(),i=rP(),a=Oy(),o=N(Hq(n)),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),p=(0,m.useRef)(null),{document:g}=i,v=mge(g.form.title,g.form.values,g.variants.length),y=()=>{u(null),t()},b=async()=>{let e=s.trim();if(!(e===``||d)){f(!0),u(null);try{if(!await i.flush()){u(`Your draft wasn't saved, so the template wasn't either. Press Retry beside Drafts, then Save template again.`);return}p.current?.name!==e&&(p.current={name:e,id:crypto.randomUUID()});let s=o.data?.find(e=>e.id===g.templateSource?.id),l=g.channelId??(s?o0(s):void 0),d=Vme(g),f=await Wq(n,{id:p.current.id,name:e,document:l===void 0?d:{...d,channelId:l}});if(!f.ok){p.current=null,u(`The template wasn't saved. ${f.message}`);return}p.current=null,c(``),a(`Template "${e}" saved.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}catch(e){u(`The template wasn't saved. ${e instanceof Error?e.message:`Press Save template again.`}`)}finally{f(!1)}}};return(0,h.jsx)(Ay,{open:e,onOpenChange:e=>{e||y()},title:`Save as template`,description:`Keeps this setup's prompts, voice, images, style, outputs and reviews to start the next video from.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`secondary`,onClick:y,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,disabled:s.trim()===``||d,disabledReason:d?`Saving the template`:`Name the template first`,onClick:()=>void b(),children:`Save template`})]}),children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,value:s,maxLength:120,placeholder:g.form.title.replace(/\{\{[^}]*\}\}/g,``).trim()||`My setup`,onChange:e=>c(e.target.value)})}),v.length?(0,h.jsx)(`ul`,{"aria-label":`Left out of the template`,className:`m-0 flex list-none flex-col gap-1 p-0 text-small text-ink-2`,children:v.map(e=>(0,h.jsx)(`li`,{children:e},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Every keyword keeps its value: the title names none.`}),l?(0,h.jsx)(SI,{tone:`danger`,title:l}):null]})})}var gge=new Set([`a`,`an`,`the`,`of`,`and`,`or`,`in`,`on`,`to`,`for`,`with`,`vs`,`s`]);function J6(e){return e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase().replace(/&/g,` and `).replace(/[^\p{L}\p{N}]+/gu,` `).trim()}function Y6(e){let t=J6(e).split(` `).filter(e=>e!==``&&!gge.has(e)).map(e=>e.length>3&&e.endsWith(`s`)&&!e.endsWith(`ss`)?e.slice(0,-1):e);return new Set(t)}function _ge(e,t){let n=0;for(let r of e)t.has(r)&&(n+=1);return n}function vge(e,t){let n=J6(e);if(n===J6(t))return n!==``;let r=Y6(e),i=Y6(t);if(r.size===0||i.size===0)return!1;let a=_ge(r,i);if(a/(r.size+i.size-a)>=.6)return!0;let o=Math.min(r.size,i.size),s=Math.max(r.size,i.size);return a===o&&o/s>=.5}function yge(e,t,n){let r=e.map(e=>e.trim()).filter(e=>e!==``);if(r.length===0)return;let i=e=>r.some(t=>vge(t,e)),a=t.find(i);if(a!==void 0)return{title:a,where:`project`};let o=n.find(i);return o===void 0?void 0:{title:o,where:`video`}}function bge({topics:e}){let{api:t}=z(),n=rP(),{document:r}=n,i=V3(),a=N(Yy(t)),o=N(V2(t,i)),{form:s}=r,c=mq(s.title,s.values),l=yge(e.length===0?[s.title]:[c,...e.map(e=>s.values[e]??``)],(a.data?.projects??[]).filter(e=>e.channelId===i).map(e=>e.title),(o.data??[]).map(e=>e.title));return l===void 0||n.review.created!==null?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.where===`project`?`This channel already has a video on this: "${l.title}" (in Projects). Start anyway if you want another take.`:`This channel already uploaded "${l.title}" (Channel → Existing videos). Start anyway if you want another take.`})}function xge({rows:e,open:t,onChange:n}){return(0,h.jsx)(`ul`,{"aria-label":`Setup`,className:`m-0 flex list-none flex-col border-t border-line p-0`,children:e.map(e=>{let r=t.has(e.id)&&e.editor!==void 0,i=`play-row-${e.id}`;return(0,h.jsxs)(`li`,{"data-setup-row":e.id,className:`border-b border-line`,children:[(0,h.jsx)(H,{title:e.label,size:`small`,className:`items-center py-3.5`,status:e.problem?(0,h.jsx)(_S,{tone:`failed`,children:`Needs setup`}):void 0,meta:(0,h.jsx)(`span`,{"data-row-summary":!0,className:e.problem&&!r?`block break-words text-danger`:`block truncate text-ink-2`,title:e.problem&&!r?void 0:e.summary,children:r?e.summary:e.problem??e.summary}),children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":e.editor===void 0?void 0:r,"aria-controls":e.editor===void 0?void 0:i,"aria-label":`${r?`Done with`:`Change`} ${e.label.toLowerCase()}`,onClick:()=>n(e.id,!r),children:r?`Done`:`Change`})}),r?(0,h.jsx)(`section`,{id:i,"aria-label":e.label,className:`min-w-0 pb-6`,children:e.editor}):null]},e.id)})})}var X6=[{id:`title`,label:`Title and keywords`,section:`content`},{id:`article`,label:`Article`,section:`content`},{id:`narration`,label:`Narration`,section:`outputs`},{id:`images`,label:`Images`,section:`outputs`},{id:`video`,label:`Video and style`,section:`style`},{id:`outputs`,label:`Outputs`,section:`outputs`},{id:`reviews`,label:`Reviews`,section:`review`},{id:`channel`,label:`Channel`,section:`content`}],Sge=[[`title`,[`title`,`values`]],[`article`,[`sources.article`,`sources.research`,`articlePrompt`,`provided.article`,`provided.research`,`llm`]],[`narration`,[`sources.audio`,`audio`,`voices`,`provided.audio`,`narrationPrompt`,`intro`,`outro`,`chunking`]],[`images`,[`sources.images`,`images`,`imagePrompts`,`provided.images`,`reference`,`provided.reference`]],[`video`,[`sources.video`,`imageSeconds`,`zoomPercent`,`motionStyle`,`edgeSilenceSeconds`,`silenceGapSeconds`,`sentencePauseSeconds`,`paragraphPauseSeconds`,`loudness`,`videoEdit`,`format`,`subtitles`,`fontUpload`]],[`outputs`,[`sources.thumbnail`,`thumbnailPrompt`,`provided.thumbnail`,`thumbnailCount`,`youtubeDescription`,`descriptionPrompt`,`shorts`,`sources.document`,`document`]],[`reviews`,[`checkpoints`,`reviews`]],[`channel`,[`channelId`,`useBrandKit`,`language`]]],Z6=(e,t)=>e.some(e=>t===e||t.startsWith(`${e}.`));function Q6(e,t=`article`){return Z6([`llm`],e)?t:Sge.find(([,t])=>Z6(t,e))?.[0]}function Cge(e){switch(e){case`content`:return[`title`,`article`,`channel`];case`outputs`:return[`narration`,`images`,`video`,`outputs`];case`style`:return[`video`];case`review`:return[`reviews`]}}function $6(e,t,n,r=`article`){return t.find(t=>Q6(t.field,r)===e?e===`title`?t.field===`title`?n.length>0:!n.some(e=>t.field===`values.${e}`):!0:!1)}function wge(e,t,n){let r=e=>e===``?`no provider`:n.providers.find(t=>t.id===e)?.displayName??e,i=e=>e.filter(e=>typeof e==`string`&&e!==``).join(` · `);switch(e){case`title`:return i([n.topics.length?t.title:!1,n.keywords===0?`No keywords`:`${String(n.keywords)} keyword${n.keywords===1?``:`s`}`]);case`article`:return t.sources.article===`off`?`Off: no article`:t.sources.article===`provide`?`Your article`:i([t.articlePrompt||`No prompt picked`,t.llm.provider?`${r(t.llm.provider)} · ${t.llm.model||`no model`}`:!1,t.sources.research===`off`?`research off`:`research: ${PN[t.sources.research].toLowerCase()}`]);case`narration`:{if(t.sources.audio===`off`)return`Off, a silent video`;if(t.sources.audio===`provide`)return t.provided.audio?.name??`Your narration file`;let e=n.voices.find(e=>e.provider===t.audio.provider&&e.voiceId===t.audio.voice);return i([r(t.audio.provider),t.voices===void 0?e?.name??(t.audio.voice||`no voice`):`${DA[t.voices.format]}, ${String(t.voices.speakers.length)} speakers`,t.narrationPrompt?`prepared with ${t.narrationPrompt}`:!1,t.intro?`intro ${t.intro}`:!1,t.outro?`outro ${t.outro}`:!1])}case`images`:{if(t.sources.images===`off`)return`Off`;if(t.sources.images===`provide`)return`${String(t.provided.images.length)} of your images`;let e=t.imagePrompts.map(e=>`${e.name} × ${e.number||`?`}`);return i([e.length?e.join(`, `):`No image prompts picked`,r(t.images.provider),t.images.model,t.reference!==void 0&&t.reference.source!==`off`&&`establishing image`])}case`video`:return i([t.format,t.sources.video===`off`?`no video`:gA[SA(t).cuts].toLowerCase(),t.sources.video!==`off`&&n.look,t.sources.audio!==`off`&&t.subtitles.mode!==`off`?`captions ${n.fontName??t.subtitles.fontId} ${t.subtitles.fontSize} ${t.subtitles.position}`:`no captions`]);case`outputs`:return i([t.sources.thumbnail===`off`?!1:t.sources.thumbnail===`provide`?`your thumbnail`:t.thumbnailCount===3?`3 thumbnails`:`1 thumbnail`,jN(t)&&t.shorts?`${t.shorts.count} shorts`:!1,t.youtubeDescription===!0&&t.sources.audio!==`off`&&`YouTube description`,t.sources.document===`generate`&&`PDF (${XS(t.document)})`])||`Only the video`;case`reviews`:return i([n.checkpoints===0?`No checkpoints`:`${String(n.checkpoints)} checkpoint${n.checkpoints===1?``:`s`}`,n.reviews===0?`no automatic reviews`:`${String(n.reviews)} automatic review${n.reviews===1?``:`s`}`]);case`channel`:return i([n.channel??`Default channel`,n.brandKit?`brand kit on`:`brand kit off`,t.language===void 0?void 0:BO(t.language).name])}}function Tge({review:e,blocker:t,errors:n,pendingUpload:r}){if(e.starting)return;if(e.uncertain)return{text:`Slopify didn't confirm the last start. Press Check Start result to find out before starting again.`};if(t)return{text:t.hint,field:t.field};let i=n[0];if(i)return{text:i.message,field:i.field};if(r)return{text:`Wait for uploads to finish before Start`,field:r};if(e.error)return{text:e.error};if(e.pending||!e.valid)return{text:`Checking your setup and the estimate…`}}function Ege({errors:e,blocker:t,saveProblem:n,onReveal:r,onWholeSetup:i,onSaveTemplate:a,preview:o}){let s=rP(),{document:c,review:l}=s,u=YN(c,s.view),d=l.starting||l.uncertain;(0,m.useEffect)(()=>{s.reviewDraft()},[s.reviewDraft]);let f=!l.valid&&!l.pending&&!l.starting&&!l.uncertain&&l.error===null&&e.length===0&&t===void 0&&!u&&s.activeId!==null;(0,m.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>void s.reviewDraft(),800);return()=>clearTimeout(e)},[f,c,s.reviewDraft]);let p=l.valid&&l.receipt?l.receipt.runs.length:GN(c),g=Tge({review:l,blocker:t,errors:e,pendingUpload:u}),_=l.starting||!l.uncertain&&(!l.valid||l.pending||e.length>0||!!u);return(0,h.jsxs)(h.Fragment,{children:[o,(0,h.jsxs)(`section`,{"aria-label":`Start`,className:`flex min-w-0 flex-col gap-4 border-t border-line pt-5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:p===1?`1 video`:`${String(p)} videos`}),p>1?(0,h.jsx)(kb,{label:`Queue`,tip:`play.batch-queue`,checked:JN(c),disabled:d,onChange:e=>s.edit({...c,queue:e})}):(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`One run`})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Estimated cost`,info:`play.estimate`,size:`small`,className:`pb-0`}),l.valid&&l.receipt?(0,h.jsx)(sge,{estimates:l.receipt.estimates}):(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.pending?`Calculating the estimate…`:`The estimate appears once the setup is complete.`}),(0,h.jsx)(xV,{label:`Expected article words per video`,tip:`play.expected-words`,className:`mt-2`,children:(0,h.jsx)(CV,{"data-play-field":`expectedWords`,type:`number`,min:1,max:1e5,value:c.expectedWords,disabled:d,onChange:e=>s.edit({...c,expectedWords:e.target.value})})})]}),n?(0,h.jsx)(SI,{tone:`danger`,title:n}):null,(0,h.jsxs)(Ty,{"data-tour":`play-start`,disabled:_,"aria-describedby":g?`play-start-reason`:void 0,onClick:()=>{s.startRun()},children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),qN(l,c)]}),(0,h.jsx)(`div`,{id:`play-start-reason`,className:`min-h-5 text-center text-small`,children:g===void 0?(0,h.jsx)(`span`,{className:`text-ink-3`,children:p===1?`Nothing starts until you press it.`:JN(c)?`They run one after another. Nothing starts until you press it.`:`They all run at once. Nothing starts until you press it.`}):g.field===void 0?(0,h.jsx)(`span`,{role:l.error?`alert`:`status`,className:l.error?`text-danger`:`text-ink-2`,children:g.text}):(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center justify-center gap-x-1`,children:[(0,h.jsx)(`span`,{id:`play-start-field`,className:`text-waiting`,children:g.text}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-describedby":`play-start-field`,onClick:()=>r(g.field??``),children:`Go to the field`})]})}),(0,h.jsxs)(Ey,{className:`justify-center`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:l.pending||d||!!u,onClick:()=>{s.reviewDraft()},children:`Refresh review`}),(0,h.jsx)(V,{id:`play.refresh-review`})]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-keyshortcuts":Mx(lP.reviewSetup),onClick:i,children:`Review the whole setup`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Save as template`})]})]})]})}function Dge(e,t,n){let r=e?.prompts??[],i=e?.entries??[];return{prompts:[...r,...t.filter(e=>!r.some(t=>t.kind===e.kind&&t.name.toLowerCase()===e.name.toLowerCase()))],entries:[...i,...n.filter(e=>!i.some(t=>t.category===e.category&&t.name.toLowerCase()===e.name.toLowerCase()))]}}function Oge({topics:e,onError:t}){let{api:n}=z(),r=_(),i=rP(),a=N(Hq(n)),o=N(Zb(n)),[s,c]=(0,m.useState)(!1),l=i.review.starting||i.review.uncertain||i.review.created!==null,u=i.document.templateSource,d=a.data?.find(e=>e.id===u?.id),f=e=>o.data?.find(t=>t.id===e)?.name,p=async o=>{if(t(null),o===``){await i.newDraft();return}let s=a.data?.find(e=>e.id===o);if(s){c(!0);try{if(!await i.flush()){t(`Your draft wasn't saved, so the template wasn't applied. Press Retry beside Drafts, then pick the template again.`);return}let a=Object.fromEntries(e.map(e=>[e,i.document.form.values[e]??``]).filter(([,e])=>e.trim()!==``)),o=await Xq(n,s,crypto.randomUUID());if(!o.ok){t(`The template "${s.name}" wasn't applied. ${o.message}`);return}if(await r.invalidateQueries({queryKey:[`play-drafts`]}),!await i.open(o.value.draft.id)){t(`The draft made from "${s.name}" didn't open. Open it from Drafts.`);return}let c=o.value.draft.document,l=Object.fromEntries(Object.entries(a).filter(([e])=>(c.form.values[e]??``)===``));Object.keys(l).length>0&&i.edit({...c,form:{...c.form,values:{...c.form.values,...l}}})}catch(e){t(e instanceof Error?`The template "${s.name}" wasn't applied. ${e.message}`:`The template "${s.name}" wasn't applied. Pick it again.`)}finally{c(!1)}}},g=a.error?`Templates didn't load. ${a.error.message}`:d?[f(o0(d)),`version ${String(d.version)}`].filter(Boolean).join(` · `):a.data?.length===0?`No templates yet. Set this video up, then Save as template.`:void 0;return(0,h.jsx)(xV,{label:`Template`,tip:`play.template`,help:g,children:(0,h.jsxs)(TV,{"data-play-field":`template`,value:d?.id??``,disabled:s||l,onChange:e=>void p(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:u&&!d?`Template no longer saved`:`No template`}),(a.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})}function kge({topics:e,problem:t}){let n=rP(),{document:r}=n,{form:i}=r,a=e=>{n.edit({...r,form:e}),n.invalidateReview(!0)};if(e.length===0)return(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:t(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,className:`!h-11 text-[17px]`,value:i.title,maxLength:200,placeholder:`What's the video about?`,"aria-invalid":t(`title`)!==void 0,onChange:e=>a({...i,title:e.target.value})})});let o=mq(i.title,i.values);return(0,h.jsx)(`div`,{className:`grid min-w-0 gap-4`,children:e.map((n,r)=>(0,h.jsx)(xV,{label:n,tip:`play.topic`,help:r===e.length-1?(0,h.jsxs)(h.Fragment,{children:[`Title: `,(0,h.jsx)(`b`,{className:`font-semibold text-ink`,children:o})]}):void 0,error:t(`values.${n}`)??(r===e.length-1?t(`title`):void 0),children:(0,h.jsx)(CV,{"data-play-field":`values.${n}`,className:`!h-11 text-[17px]`,value:i.values[n]??``,maxLength:200,spellCheck:!1,"aria-invalid":t(`values.${n}`)!==void 0,onChange:e=>a({...i,values:{...i.values,[n]:e.target.value}})})},n))})}function Age({topics:e,keywordNames:t,origins:n,problem:r,adding:i,onAdding:a,open:o,onOpen:s}){let c=rP(),{document:l}=c,{form:u}=l,[d,f]=(0,m.useState)(``),p=(0,m.useId)(),g=(0,m.useRef)(null),_=c.review.starting||c.review.uncertain,v=l.variants,y=e=>{c.edit({...l,variants:e})},b=e[0],x=e=>b===void 0?e.title:e.values[b]||e.title,S=()=>{let e=d.trim();e===``||v.length>=49||(y([...v,{id:crypto.randomUUID(),title:b===void 0?e:u.title,values:b===void 0?{...u.values}:{...u.values,[b]:e}}]),f(``),g.current?.focus())},C=v.findIndex(e=>e.id===o),w=C===-1?void 0:v[C];return(0,h.jsxs)(`section`,{"aria-label":`More videos from the same setup`,className:`min-w-0`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:`More videos from the same setup`}),(0,h.jsx)(V,{id:`play.more-videos`,className:`-my-1`})]}),(0,h.jsxs)(Ey,{className:`flex-wrap`,children:[v.map((e,n)=>{let i=x(e)||`Video ${String(n+2)}`,a=[`items.${String(n+1)}.title`,...t.map(e=>`items.${String(n+1)}.values.${e}`)].some(e=>r(e)!==void 0);return(0,h.jsx)(yS,{...a?{className:`border-danger`}:{},..._?{}:{onRemove:()=>y(v.filter(t=>t.id!==e.id)),removeLabel:`Remove ${i}`},children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,"data-play-field":`items.${e.id}`,className:`-my-1 -ml-1.5 h-6 px-1.5 text-ink`,"aria-label":`Change the keywords of ${i}`,onClick:()=>s(e.id),children:[i,(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})]})},e.id)}),i?(0,h.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,h.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:b===void 0?`Title of another video`:`${b} of another video`}),(0,h.jsx)(CV,{ref:g,id:p,autoFocus:!0,className:`!h-8 w-48`,value:d,maxLength:200,placeholder:b===void 0?`Another title`:`Another ${b}`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(!1)}}),(0,h.jsx)(R,{type:`submit`,size:`small`,disabled:d.trim()===``,children:`Add`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>a(!1),children:`Done`})]}):(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:_||v.length>=49,disabledReason:_?`Wait for the start to finish`:`One Start queues at most 50 videos`,onClick:()=>a(!0),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add topic`]})]}),(0,h.jsx)(YP,{open:w!==void 0,title:w?`Video ${String(C+2)}: ${x(w)||`untitled`}`:``,width:`narrow`,onClose:()=>s(null),footer:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>s(null),children:`Done`}),children:w?(0,h.jsxs)(`fieldset`,{disabled:_,className:`flex min-w-0 flex-col gap-5 border-0 p-0`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Everything else comes from the setup of the first video.`}),(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:r(`items.${String(C+1)}.title`),children:(0,h.jsx)(CV,{"data-play-field":`items.${w.id}.title`,value:w.title,maxLength:200,onChange:e=>y(v.map(t=>t.id===w.id?{...t,title:e.target.value}:t))})}),(0,h.jsx)(_0,{fieldPrefix:`items.${w.id}.values`,keywords:t.map(t=>({name:t,value:w.values[t]??``,feeds:n.get(t)??[],topic:e.includes(t)})),problem:e=>r(e.replace(`items.${w.id}.`,`items.${String(C+1)}.`)),onChange:(e,t)=>y(v.map(n=>n.id===w.id?{...n,values:{...n.values,[e]:t}}:n))})]}):null})]})}function jge(){let e=Zi();return(0,h.jsx)(Mge,{onCreated:t=>{e({to:`/projects/$projectId`,params:{projectId:t}})}})}function Mge({onCreated:e}){let{api:t}=z(),n=lI(),r=N(eb(t)),i=N(nb(t)),a=N(rb(t)),o=N(tb(t)),s=N(ob(t)),c=N(Zb(t)),l=N(Hq(t)),u=N({queryKey:sN,queryFn:()=>cN(t),staleTime:6e4}),[d,f]=cP(),p=H3(),g=rP(),{document:_}=g,v=Dge(_.librarySnapshot,i.data?.prompts??[],a.data?.entries??[]),y=_.variants.map(({id:e,...t})=>({...t,key:e})),b=g.fontUploading||_.fontUpload!==null,x=g.review.fields,[S,C]=(0,m.useState)(new Set),[w,T]=(0,m.useState)(new Set),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,ee]=(0,m.useState)(!1),[te,ne]=(0,m.useState)(null),j=(0,m.useRef)(null),re=(0,m.useRef)(null),M=(0,m.useRef)(null),ie=Zi(),ae=(0,m.useRef)(g.activeId);(0,m.useLayoutEffect)(()=>{ae.current!==g.activeId&&(ae.current=g.activeId,C(new Set),k(null))},[g.activeId]);let oe=e=>{f(t=>{let n={...t,...e};return{...n,subtitles:ON(n.subtitles,n.sources)}}),g.invalidateReview(!0)},se=s.data?.silenceGapSeconds??3,ce=_.form.silenceGapSeconds?.trim()??``,le={form:d,prompts:v.prompts,entries:v.entries,silenceGapSeconds:ce===``?se:Number(ce)},{fields:ue,result:de,blocker:fe}=Dde(le),pe=h0(le),me=z3(d.title).filter(e=>ue.some(t=>t.name===e)),he=b?{field:`subtitles.fontUpload`,hint:`Wait for the subtitle font upload to finish to play`}:fe;(0,m.useEffect)(()=>{if(!g.review.created)return;let t=g.takeCreated()?.projectIds[0];t&&(n({type:`project-created`,id:t}),e(t))},[g.review.created,g.takeCreated,n,e]);let ge=de.ok?x:[...de.fields,...x],_e=(...e)=>!ge.some(t=>e.some(e=>t.field===e||t.field.startsWith(`${e}.`))),ve=(e,t)=>v.prompts.some(n=>n.kind===e&&n.name===t),ye=e=>e?.file!==void 0&&e.error===void 0;cI({playArticleReady:_e(`sources.article`,`articlePrompt`,`provided.article`)&&(d.sources.article===`provide`||ve(`article`,d.articlePrompt)),playAudioReady:d.sources.audio===`off`||_e(`sources.audio`,`audio`,`provided.audio`)&&(d.sources.audio!==`provide`||ye(d.provided.audio)),playImagesReady:d.sources.images===`off`||_e(`sources.images`,`images`,`imagePrompts`,`provided.images`)&&(d.sources.images===`provide`?d.provided.images.every(ye):d.imagePrompts.every(e=>ve(`image`,e.name))),playVideoReady:_e(`sources.video`),playSubtitlesReady:_e(`subtitles`)&&!b,playOptionsReady:_e(`title`,`format`,`llm`,`intro`,`outro`),playHasKeywords:ue.length>0,playKeywordsReady:_e(`values`),playReady:he===void 0&&!g.review.starting});let be=IN(d,v.entries)[0]?.section??`article`,xe=e=>Wme(e,d)??Bhe(e,d,y,v.entries),Se=e=>{let t=xe(e).field;return ge.find(n=>xe(n.field).field===t&&(x.includes(n)||S.has(e)||S.has(t)))?.message},Ce=e=>{let t=xe(e);C(n=>new Set([...n,e,t.field])),g.navigate(t.field.startsWith(`items.`)?`content`:t.section,t.field)},we=[r,i,a,o,s].every(e=>e.isSuccess||e.isError),Te=(0,m.useRef)(null),Ee=g.generation();(0,m.useEffect)(()=>{if(!we)return;let e=Te.current;Te.current={generation:Ee,id:g.activeId},(e===null||e.generation!==Ee||e.id!==g.activeId&&e.id!==null)&&T(new Set(X6.map(e=>e.id).filter(e=>e!==`reviews`&&$6(e,ge,me,be)!==void 0)))},[we,g.activeId,Ee]);let De=(0,m.useRef)(null);(0,m.useLayoutEffect)(()=>{let e=g.reveal;if(e||(De.current=null),!e||e.sequence===De.current||!j.current)return;let t=e.field,n=t?/^items\.([^.]+)(\.|$)/.exec(t)?.[1]:void 0;if(e.section===`review`){if(De.current=e.sequence,t&&B6(j.current,t))return;M.current?.focus();return}if(n!==void 0&&_.variants.some(e=>e.id===n)){if(O!==n){k(n);return}}else if(!(t&&me.some(e=>t===`values.${e}`))){let n=t?Q6(t,be):void 0,r=(n===void 0?Cge(e.section):[n]).filter(e=>!w.has(e));if((t!==`title`||me.length!==0)&&r.length>0){T(e=>new Set([...e,...r]));return}}De.current=e.sequence,!(t&&B6(j.current,t))&&re.current?.focus()},[g.reveal,w,O]);let Oe=async e=>{await g.flush()&&(e===`/prompts`?await ie({to:`/prompts/new`,search:{kind:`article`}}):await ie({to:e}))},ke=()=>{g.navigate(`review`)},Ae=(e,t)=>{g.invalidateReview(!0),g.attach(e,t)},je=(e,t)=>{f(n=>({...n,provided:e===`images`?{...n.provided,images:n.provided.images.filter(e=>e.key!==t)}:{...n.provided,[e]:void 0}}))},Me=[r,i,a,o,s].find(e=>e.error!==null)?.error?.message,Ne=g.error?`Your draft wasn't saved. ${g.error}`:Me,Pe={form:d,providers:r.data?.providers??[],prompts:v.prompts,voices:o.data?.voices??[],silenceGapSeconds:s.data?.silenceGapSeconds??3,problem:Se,update:oe,onPickFiles:Ae,onRemoveFile:je,onReattachFile:(e,t,n)=>{g.attach(e,[n],t)}},Fe=l.data?.find(e=>e.id===_.templateSource?.id),Ie=_.channelId??(Fe===void 0?`00000000-0000-4000-8000-000000000001`:o0(Fe)),Le=Object.values(_.form.reviews?.stages??{}).filter(e=>e.mode!==`off`).length,Re={providers:r.data?.providers??[],voices:o.data?.voices??[],keywords:ue.length,topics:me,channel:c.data?.find(e=>e.id===Ie)?.name,brandKit:_.form.useBrandKit!==!1,look:K6(_.form),fontName:u.data?.fonts.find(e=>e.id===d.subtitles.fontId)?.name,checkpoints:d.checkpoints?.length??0,reviews:Le},ze={title:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[me.length?(0,h.jsx)(xV,{label:`Title pattern`,tip:`play.title-pattern`,error:Se(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,value:d.title,maxLength:200,"aria-invalid":Se(`title`)!==void 0,onChange:e=>oe({title:e.target.value})})}):null,(0,h.jsx)(Vhe,{fields:ue,origins:pe,topics:me,hide:me,values:d.values,problem:Se,onChange:(e,t)=>oe({values:{...d.values,[e]:t}})}),ue.length===me.length?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:ue.length===0?`No keywords. A prompt or the title that names {{a keyword}} adds one here.`:`The only keywords are the topic, typed at the top.`}):null]}),article:(0,h.jsx)(Rhe,{...Pe,entries:v.entries,onLibrary:e=>{Oe(e)}}),narration:(0,h.jsx)($he,{...Pe,entries:v.entries,onKeyword:Ce,onSettings:()=>{Oe(`/settings`)}}),images:(0,h.jsx)(ege,{...Pe}),video:(0,h.jsx)(tge,{...Pe,problemOf:Se}),outputs:(0,h.jsx)(nge,{...Pe,entries:v.entries,onSettings:()=>{Oe(`/settings`)}}),reviews:void 0,channel:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(Hme,{}),(0,h.jsx)(Ume,{})]})},Be=X6.filter(e=>e.id!==`narration`||d.sources.article!==`off`),Ve=Be.map(e=>({id:e.id,label:e.label,summary:wge(e.id,d,Re),problem:$6(e.id,ge,me,be)?.message,editor:ze[e.id]})),He=(e,t)=>{if(e===`reviews`){ke();return}T(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},Ue=e=>{He(e,!0),requestAnimationFrame(()=>{j.current?.querySelector(`[data-setup-row="${e}"]`)?.scrollIntoView({block:`start`,behavior:`smooth`})})},We=_.variants.length+1,Ge=YN(_,g.view),Ke=!g.review.starting&&(g.review.uncertain||g.review.valid&&!g.review.pending&&ge.length===0&&!Ge);bx({id:`play.start`,title:qN(g.review,_),group:`Play`,context:d.title||`New project`,keywords:[`start`,`queue`,`run`,`play`,`go`],run:()=>{Ke?g.startRun():he?Ce(he.field):ge[0]&&Ce(ge[0].field)}}),bx({id:`play.add-topic`,title:`Add a topic for another video`,group:`Play`,context:`${String(We)} video${We===1?``:`s`}`,keywords:[`more videos`,`variation`,`batch`,`queue`],run:()=>D(!0)}),bx({id:`play.save-template`,title:`Save as template`,group:`Play`,keywords:[`template`,`setup`,`reuse`],run:()=>ee(!0)}),bx({id:`play.review`,title:`Review the whole setup`,group:`Play`,keywords:[`summary`,`checkpoints`,`prompt`],shortcut:lP.reviewSetup,run:ke}),bx({id:`play.template`,title:`Pick a template`,group:`Play`,keywords:[`template`,`setup`],run:()=>{j.current&&B6(j.current,`template`)}});let qe=d.sources.video===`generate`&&d.sources.images!==`off`,Je=age(d,p),Ye=qe?(0,h.jsx)(O6,{drawnOn:Je?.drawnOn,settings:{format:d.format,subtitles:{mode:d.sources.audio===`off`?`off`:d.subtitles.mode,fontId:d.subtitles.fontId,fontSize:Number(_.form.subtitles.fontSize)||d.subtitles.fontSize,position:d.subtitles.position},videoEdit:d.videoEdit,previewText:_.previewText,image:Je?.image}}):null;return(0,h.jsxs)(`div`,{ref:j,onBlurCapture:e=>{let t=e.target.dataset.playField;t&&C(e=>new Set([...e,t]))},"data-play-grid":`true`,className:`min-w-0 max-[767px]:[&_button]:min-h-11 max-[767px]:[&_input:not([type=checkbox])]:min-h-11 max-[767px]:[&_select]:min-h-11 max-[767px]:[&_summary]:min-h-11`,children:[(0,h.jsx)(kq,{crumb:`New project`,title:(0,h.jsx)(`span`,{ref:re,tabIndex:-1,children:`What's the video about?`}),meta:d.title.trim()===``?`Untitled draft`:d.title,actions:(0,h.jsx)(zhe,{})}),(0,h.jsx)(B3,{onDefaults:g.adoptDefaults}),(0,h.jsxs)(Aq,{className:`sl-workspace--play`,aside:(0,h.jsx)(Ege,{errors:ge,blocker:he,saveProblem:Ne,onReveal:Ce,onWholeSetup:ke,onSaveTemplate:()=>ee(!0),preview:Ye}),asideLabel:`Review and start`,children:[(0,h.jsxs)(`div`,{"data-tour":`play-options`,className:`grid min-w-0 grid-cols-1 items-start gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(Oge,{topics:me,onError:ne}),(0,h.jsx)(kge,{topics:me,problem:Se})]}),(0,h.jsx)(bge,{topics:me}),te?(0,h.jsx)(SI,{tone:`danger`,title:te}):null,(0,h.jsx)(Age,{topics:me,keywordNames:ue.map(e=>e.name),origins:pe,problem:Se,adding:E,onAdding:D,open:O,onOpen:k}),(0,h.jsx)(xge,{rows:Ve,open:w,onChange:He})]}),(0,h.jsx)(YP,{open:g.section===`review`,title:`Review`,headingRef:M,onClose:()=>{g.navigate(`content`)},children:(0,h.jsx)(pge,{fields:ue,errors:ge,problem:Se,onReveal:Ce})}),(0,h.jsx)(hge,{open:A,onClose:()=>ee(!1)}),Be.map(e=>(0,h.jsx)(Nge,{id:e.id,label:e.label,onOpen:Ue},e.id))]})}function Nge({id:e,label:t,onOpen:n}){return bx({id:`play.row.${e}`,title:`Change ${t.toLowerCase()}`,group:`Play`,keywords:[`open`,`edit`,`section`,t],run:()=>n(e)}),null}function Pge(){let{api:e}=z(),t=N({queryKey:[`batch-queue`],queryFn:async()=>F(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=N(Yy(e)),r=t.data?.queue.length??0;return(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,disabled:r===0,"aria-label":`Video queue: ${r} remaining`,children:[(0,h.jsx)(Ec,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,r]})]})}),(0,h.jsxs)(Eb,{align:`end`,className:`p-0`,children:[(0,h.jsx)(`p`,{className:`border-b border-line px-3 py-2 text-small text-ink-2`,children:pb(`play.queue`).body}),(0,h.jsx)(Fge,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function Fge({queue:e,projects:t}){return(0,h.jsx)(`ol`,{className:`max-h-40 overflow-y-auto px-4 py-2`,children:e.map((e,n)=>{let r=t?.find(t=>t.id===e.projectId);return(0,h.jsxs)(`li`,{className:`flex justify-between gap-3 py-1 text-small`,children:[(0,h.jsxs)(ha,{className:`truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[n+1,`. `,r?.title??`Video`]}),(0,h.jsx)(`span`,{className:`shrink-0 text-ink-2`,children:r?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`})]},e.projectId)})})}function e8({label:e,className:t,children:n}){return(0,h.jsx)(`nav`,{"aria-label":e,className:L(`sl-rail`,t),children:n})}function Ige({icon:e,meta:t,children:n}){return(0,h.jsxs)(h.Fragment,{children:[e,(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:n}),t===void 0?null:(0,h.jsx)(`span`,{className:`sl-rail__meta`,children:t})]})}function t8({icon:e,meta:t,current:n=!1,onClick:r,className:i,children:a,"data-tour":o}){return(0,h.jsx)(`button`,{type:`button`,"data-tour":o,"aria-current":n?`true`:void 0,onClick:r,className:L(`sl-rail__item w-full border-0 bg-transparent text-left font-[inherit]`,n&&`bg-accent-tint font-semibold text-ink`,i),children:(0,h.jsx)(Ige,{icon:e,meta:t,children:a})})}var n8=/^(?:[-*+]|\d+[.)])\s+/u;function Lge(e){let t=e.split(/\r?\n/u).filter(e=>e.trim()!==``),n=[];for(let e of t.slice(1)){let t=e.trim().replace(n8,``).trim(),r=n.length-1;/^\s/u.test(e)&&!n8.test(e.trim())&&r>=0?n[r]=`${n[r]??``} ${t}`:t!==``&&n.push(t)}return n}var Rge={blockquote:o8,break:Uge,code:s8,definition:s8,delete:o8,emphasis:o8,footnoteReference:s8,footnoteDefinition:s8,heading:Hge,html:s8,image:i8,imageReference:i8,inlineCode:a8,list:o8,listItem:o8,link:o8,linkReference:o8,strong:o8,table:s8,tableCell:s8,text:a8,thematicBreak:s8,toml:s8,yaml:s8},zge={},r8=[];function Bge(e){let t={...Rge},n=e||zge,r=n.keep||r8,i=n.remove||r8,a=-1;for(;++a<i.length;){let e=i[a];typeof e==`string`?t[e]=s8:t[e[0]]=e[1]}let o={};if(r.length===0)o=t;else{let e;for(e in t)r.includes(e)||(o[e]=t[e]);for(a=-1;++a<r.length;)if(e=r[a],!Object.hasOwn(t,e))throw Error("Unknown node type `"+e+"` in `keep`, use a replace tuple with a handle instead: `remove: [['"+e+"', handle]]`")}return function(e){return s(e)};function s(e){let t=e.type,n=e;if(Object.hasOwn(o,t)){let e=o[t];e&&(n=e(n)||void 0)}return n=Array.isArray(n)?c(n):n,n&&`children`in n&&(n.children=c(n.children)),n}function c(e){let t=-1,n=[];for(;++t<e.length;){let r=s(e[t]);Array.isArray(r)?n.push(...c(r)):r&&n.push(r)}return Vge(n)}}function Vge(e){let t=-1,n=[],r;for(;++t<e.length;){let i=e[t];r&&i.type===r.type&&`value`in i&&`value`in r?r.value+=i.value:(n.push(i),r=i)}return n}function i8(e){let t=`title`in e?e.title:``,n=e.alt||t||``;return n?{type:`text`,value:n}:void 0}function a8(e){return{type:`text`,value:e.value}}function Hge(e){return{type:`paragraph`,children:e.children}}function o8(e){return e.children}function Uge(){return{type:`text`,value:`
283
- `}}function s8(){}var Wge=64,c8=new Map;function Gge(e){let t=c8.get(e);if(t!==void 0)return t;let n=Kge(e);for(c8.set(e,n);c8.size>Wge;){let e=c8.keys().next().value;if(e===void 0)break;c8.delete(e)}return n}function Kge(e){let t=r6().use(pB).use(Bge),n=t.runSync(t.parse(e)).children.map(e=>{if(e.type!==`paragraph`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.children.map(e=>{if(e.type!==`text`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.value}).join(``)}).filter(e=>e.trim()!==``);return n.length===0?``:n.join(`
280
+ `).entries()){let e=n.trim(),c=t+1;if(e===``){s=!1;continue}let l=lhe.exec(e);if(l!==null){o.push({title:d6(l[1]??``),firstTurn:a.length+1}),s=!1;continue}if(/^([-*_=~])\1{2,}$/.test(e)){s=!1;continue}let u=uhe.exec(e),d=u===null?void 0:r.get((u[1]??``).trim().toLowerCase());if(u!==null&&d!==void 0){a.push({speaker:d.id,lines:[u[2]??``],section:o.length-1}),s=!0;continue}let f=a.at(-1);if(s&&f!==void 0){f.lines.push(e);continue}return{ok:!1,reason:u===null?`Line ${String(c)} of the script is not a turn. Start every turn with a speaker's name and a colon (${i}), one turn per paragraph.`:`Line ${String(c)} of the script is spoken by "${(u[1]??``).trim()}", who is not one of the speakers (${i}). Use only these names, or add the speaker under Speakers (Play → Narration, or Edit project → Providers).`}}let c=[];for(let e of a){let t=d6(e.lines.join(` `));t!==``&&c.push({index:c.length+1,speaker:e.speaker,text:t,section:e.section,...n?{markdown:e.lines.join(`
281
+ `)}:{}})}if(c.length===0)return{ok:!1,reason:`The script has no spoken turns. Write each turn as a speaker's name, a colon and their words (${i}).`};let l=[],u=new Map;for(let[e,t]of o.entries()){let n=c.find(t=>t.section===e);n!==void 0&&t.title!==``&&(u.set(e,l.length),l.push({title:t.title,firstTurn:n.index}))}return{ok:!0,script:{turns:c.map(e=>({...e,section:u.get(e.section)??-1})),sections:l}}}function d6(e){return e.replace(/\[[^\]]*\]\([^)]*\)/g,e=>e.slice(1,e.indexOf(`]`))).replace(/\[[^\]]*\]/g,` `).replace(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g,`$2`).replace(/`/g,``).replace(/\s+/g,` `).trim()}var dhe={narrator:`Narrator`,host:`Host`,guest:`Guest`,character:`Character`};function f6({value:e,onChange:t,providers:n,voices:r,script:i,problem:a,cast:o=[],language:s}){let c=(0,m.useMemo)(()=>{if(e===void 0||i===void 0||i.trim()===``)return;let t=u6(i,e.speakers);return t.ok?t.script:void 0},[i,e]),l=n=>{if(n===``){t(void 0);return}let r=EA.find(e=>e===n);r!==void 0&&t(e===void 0?zA(r,ahe(o)):{...e,format:r,source:r===`audiobook`?e.source:`script`})},u=n=>{e!==void 0&&t({...e,...n})},d=o.filter(t=>t.voice!==void 0&&!(e?.speakers??[]).some(e=>e.castId===t.id)),f=(t,n)=>{e!==void 0&&u({speakers:e.speakers.map((e,r)=>r===t?n:e)})};return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-3`,"data-play-field":`voices`,children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(FV,{field:`voices.format`,label:`Format`,tip:`play.speakers.format`,value:e?.format??``,placeholder:`Narration (one voice)`,options:EA.map(e=>({value:e,label:DA[e]})),problem:a?.(`voices.format`),onPick:l}),e?.format===`audiobook`?(0,h.jsx)(FV,{field:`voices.source`,label:`Script`,tip:`play.speakers.script`,value:e.source,placeholder:`Pick where the script comes from`,options:[{value:`script`,label:`Write a script (Script prompt)`},{value:`attribute`,label:`Split the article into speakers`}],problem:a?.(`voices.source`),onPick:e=>u({source:e===`attribute`?`attribute`:`script`})}):null]}),e===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`One voice reads the article. Pick a format for an audiobook, podcast, radio drama or interview with several speakers.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.source===`script`?"The article prompt must be a Script prompt: the text model writes speaker turns, one `Name: words` paragraph each.":`The article is written or pasted as usual; the text model then hands its narration and dialogue to the speakers.`}),a?.(`voices.speakers`)===void 0?null:(0,h.jsx)(`p`,{className:`text-label text-danger`,children:a(`voices.speakers`)}),(0,h.jsx)(`ol`,{"aria-label":`Speakers`,className:`divide-y divide-line border-y border-line`,children:e.speakers.map((t,i)=>(0,h.jsx)(hhe,{index:i,speaker:t,line:rhe(t,c),providers:n,voices:r,language:s,problem:a,onChange:e=>f(i,e),onRemove:e.speakers.length>1?()=>u({speakers:e.speakers.filter((e,t)=>t!==i)}):void 0},t.id))}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsx)(R,{type:`button`,disabled:e.speakers.length>=10,onClick:()=>u({speakers:[...e.speakers,mhe(e.speakers)]}),children:`Add speaker`}),(0,h.jsx)(FV,{label:`Add from the cast`,tip:`play.speakers.add-from-cast`,value:``,placeholder:d.length===0?`No cast member has a voice yet`:`Pick one of ${String(d.length)}`,options:d.map(e=>({value:e.id,label:e.name})),disabled:d.length===0||e.speakers.length>=10,problem:void 0,onPick:t=>{let n=d.find(e=>e.id===t);n!==void 0&&u({speakers:[...e.speakers,l6(n,phe(e))]})}}),(0,h.jsx)(FV,{field:`voices.turnGapSeconds`,label:`Gap between turns`,tip:`play.speakers.turn-gap`,value:String(e.turnGapSeconds),placeholder:`Pick a gap`,options:jA.map(e=>({value:String(e),label:`${e} s`})),problem:a?.(`voices.turnGapSeconds`),onPick:e=>u({turnGapSeconds:Number(e)})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{label:`Speaker names on captions`,tip:`play.speakers.name-tags`,checked:e.nameTags,onChange:e=>u({nameTags:e})}),(0,h.jsx)(kb,{label:`One request for consecutive turns where the voice provider can (ElevenLabs v3, Gemini)`,tip:`play.speakers.native-dialogue`,checked:e.nativeDialogue,onChange:e=>u({nativeDialogue:e})}),(0,h.jsx)(kb,{label:`Also make MP3 and M4B files with chapter markers`,tip:`play.speakers.audio-files`,checked:e.audioFiles,onChange:e=>u({audioFiles:e})})]}),e.format===`audiobook`?(0,h.jsx)(fhe,{value:e,onChange:t,problem:a}):null,e.format===`podcast`||e.format===`interview`?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The speaker panel (a tile per speaker, the one talking lit, their name below) is drawn with the captions: set Captions to Burn in under Style to see it in the video.`}):null]})]})}function fhe({value:e,onChange:t,problem:n}){let r=e.book,i=n=>t({...e,...n});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(kb,{label:`A chapter of a book`,tip:`play.speakers.book`,checked:r!==void 0,onChange:n=>{if(n)i({book:{title:``,chapter:1}});else{let{book:n,...r}=e;t(r)}}}),r===void 0?null:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-[minmax(0,1fr)_160px]`,children:[(0,h.jsx)(xV,{label:`Book title`,tip:`play.speakers.book-title`,error:n?.(`voices.book.title`),children:(0,h.jsx)(CV,{value:r.title,maxLength:200,onChange:e=>i({book:{...r,title:e.target.value}})})}),(0,h.jsx)(xV,{label:`Chapter`,tip:`play.speakers.book-chapter`,error:n?.(`voices.book.chapter`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:FA,step:1,value:r.chapter===0?``:String(r.chapter),onChange:e=>i({book:{...r,chapter:Number(e.target.value)||0}})})})]})]})}function phe(e){return e.format===`podcast`?`host`:e.format===`interview`?e.speakers.some(e=>e.role===`host`)?`guest`:`host`:e.speakers.some(e=>e.role===`narrator`)?`character`:`narrator`}function mhe(e){let t=e.length+1;for(;e.some(e=>e.id===`speaker-${String(t)}`);)t+=1;return{id:`speaker-${String(t)}`,name:`Speaker ${String(t)}`,role:`character`,voice:{provider:``,model:``,voice:``}}}function hhe({index:e,speaker:t,line:n,providers:r,voices:i,language:a,problem:o,onChange:s,onRemove:c}){let l=`voices.speakers.${String(e)}`,u=t.voice,d=i.filter(e=>e.provider===u.provider),f=F2(d,a,u.voice||void 0),p=a===void 0?d:f.listed,g=t.name.trim()||`this speaker`,_=(0,m.useMemo)(()=>nhe([t],a??`und`)[0]?.skipped??[],[t,a]);return(0,h.jsxs)(`li`,{className:`grid grid-cols-1 gap-3 py-3 min-[700px]:grid-cols-2`,"data-play-field":l,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-end gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`mb-2 size-3 shrink-0 rounded-full`,style:{background:`var(--color-speaker-${String(e%6+1)})`}}),(0,h.jsx)(xV,{label:`Speaker name`,tip:`play.speaker.name`,error:o?.(`${l}.name`),className:`min-w-0 flex-1`,children:(0,h.jsx)(CV,{value:t.name,maxLength:40,onChange:e=>s({...t,name:e.target.value})})})]}),(0,h.jsx)(FV,{label:`Role`,tip:`play.speaker.role`,value:t.role,placeholder:`Pick a role`,options:OA.map(e=>({value:e,label:dhe[e]})),problem:void 0,onPick:e=>{let n=OA.find(t=>t===e);n!==void 0&&s({...t,role:n})}}),(0,h.jsx)(RV,{field:`${l}.voice`,label:`Voice provider`,tip:`play.speaker.provider`,family:`tts`,providers:r,value:u.provider,problem:o?.(`${l}.voice`),onPick:e=>s({...t,voice:{provider:e,model:``,voice:``}})}),(0,h.jsx)(zV,{label:`Voice model`,tip:`play.speaker.model`,provider:u.provider,value:u.model,problem:void 0,onPick:e=>s({...t,voice:{...u,model:e}})}),(0,h.jsx)(FV,{field:`${l}.voice.voice`,label:`Voice`,tip:`play.speaker.voice`,value:u.voice,placeholder:p.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:p.map(e=>({value:e.voiceId,label:e.name})),problem:o?.(`${l}.voice.voice`),onPick:e=>s({...t,voice:{...u,voice:e}})}),a===void 0?null:(0,h.jsx)(I2,{language:a,voice:d.find(e=>e.voiceId===u.voice),hidden:f.hidden,showAll:f.showAll,onShowAll:f.setShowAll}),(0,h.jsx)(FV,{field:`${l}.pace`,label:`Pace`,tip:`play.speaker.pace`,value:String(t.pace??1),placeholder:`Pick a pace`,options:AA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:o?.(`${l}.pace`),onPick:e=>{let{pace:n,...r}=t;s(Number(e)===1?r:{...r,pace:Number(e)})}}),(0,h.jsxs)(`details`,{className:`col-span-full text-small`,...Ob,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-ink-2`,children:[`Pronunciations for `,t.name.trim()||`this speaker`,t.pronunciations?.trim()?` · set`:``,(0,h.jsx)(V,{id:`play.speaker.pronunciations`})]}),(0,h.jsx)(wV,{rows:3,"aria-label":`Pronunciations for ${t.name.trim()||`this speaker`}`,value:t.pronunciations??``,placeholder:`Arda: /ˈɑɹdə/`,onChange:e=>{let{pronunciations:n,...r}=t;s(e.target.value===``?r:{...r,pronunciations:e.target.value})}})]}),_.length===0?null:(0,h.jsxs)(SI,{tone:`waiting`,className:`col-span-full`,title:`${String(_.length)} ${_.length===1?`pronunciation`:`pronunciations`} for ${g} ${_.length===1?`is`:`are`} skipped`,children:[(0,h.jsx)(`ul`,{children:_.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsxs)(`p`,{children:[`Those words are read as ordinary text; the other entries are used. Fix them in Pronunciations for `,g,` above: one `,(0,h.jsx)(`code`,{children:`Term: /IPA/`}),` per line.`]})]}),(0,h.jsxs)(`div`,{className:`col-span-full flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(_he,{speaker:t,line:n}),(0,h.jsx)(`span`,{className:`flex-1`}),c===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:c,children:[`Remove `,t.name.trim()||`speaker`]})]})]})}var ghe=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:4});function _he({speaker:e,line:t}){let{api:n}=z(),{provider:r,model:i,voice:a}=e.voice,o=r!==``&&i!==``&&a!==``,s=N({queryKey:[`audition-quote`,r,i,t],queryFn:()=>Us(n,[{speaker:e.name.trim()||`Speaker`,provider:r,model:i,text:t}]),enabled:o,staleTime:6e4}),[c,l]=(0,m.useState)(void 0);(0,m.useEffect)(()=>()=>{c!==void 0&&URL.revokeObjectURL(c)},[c]);let u=P({mutationFn:()=>Ws(n,{provider:r,model:i,voice:a,text:t}),onSuccess:e=>{let t=URL.createObjectURL(e);l(t),new Audio(t).play().catch(()=>{})}}),d=s.data?.estimate,f=d==null?void 0:d.unknown>0?`price unknown`:`about ${ghe.format(d.high)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:!o||u.isPending,onClick:()=>u.mutate(),title:`Reads: ${t}`,children:u.isPending?`Speaking…`:`Audition${f===void 0?``:` · ${f}`}`}),(0,h.jsx)(V,{id:`play.speaker.audition`})]}),(0,h.jsx)(`span`,{className:`min-h-5 text-label text-ink-2`,"aria-live":`polite`,children:o?u.error===null?c===void 0?`Reads their first line: “${t.length>60?`${t.slice(0,60)}…`:t}”`:`Playing the audition.`:u.error.message:`Pick a provider, model and voice to audition.`})]})}function vhe(e){return e===void 0?`Narration`:DA[e]}function p6({value:e,skipCode:t,onChange:n,tip:r=`play.describe-figures`}){let i=(0,m.useId)(),a=e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.describeFigures`,checked:a,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:e.currentTarget.checked,skipCode:t===!0})}),`Describe tables and figures in the narration`]}),(0,h.jsx)(V,{id:r})]}),a?(0,h.jsxs)(`span`,{className:`flex items-center gap-1 pl-7`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-code`,className:`flex min-h-10 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-code`,type:`checkbox`,"data-play-field":`audio.skipCode`,checked:t===!0,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:!0,skipCode:e.currentTarget.checked})}),`Leave code out`]}),(0,h.jsx)(V,{id:`play.skip-code`})]}):null]})}function m6({value:e,onChange:t,tip:n=`play.show-figures`}){let r=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`showFigures`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Show tables and figures on screen`]}),(0,h.jsx)(V,{id:n})]})}function h6({value:e,onChange:t,note:n}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`audio.useNarrationAliases`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Use narration aliases`]}),(0,h.jsx)(V,{id:`play.narration-aliases`})]}),n===void 0?null:(0,h.jsx)(`div`,{className:`pl-7`,children:n})]})}function g6({value:e,prompts:t,supported:n,error:r,libraryLinks:i=!0,onChange:a}){let o=(0,m.useId)(),s=t.filter(e=>e.kind===`narration`),c=s.find(t=>t.name===e),l=r??(e!==``&&!n?`Choose Inworld TTS-2 or turn preparation Off.`:void 0);return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:o,className:`text-small font-semibold`,children:`Narration Preparation`}),(0,h.jsx)(V,{id:`play.narration-preparation`})]}),(0,h.jsxs)(DV,{id:o,"data-play-field":`narrationPrompt`,value:e,"aria-describedby":l?`${o}-error`:void 0,"aria-invalid":l!==void 0||void 0,onChange:e=>a(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),e!==``&&c===void 0?(0,h.jsxs)(`option`,{value:e,children:[e,` (saved selection)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`text-small text-danger`,children:l}):null,i?(0,h.jsxs)(`div`,{className:`flex gap-4 text-small`,children:[(0,h.jsx)(ha,{to:`/prompts/new`,search:{kind:`narration`},children:`Create prompt`}),c?(0,h.jsx)(ha,{to:`/prompts/$promptId`,params:{promptId:c.id},children:`View prompt`}):null]}):null]})}function _6({value:e,supported:t,onChange:n,shared:r}){let i=(0,m.useId)(),a=t&&e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.usePronunciationGlossary`,checked:e===!0,disabled:!t,"aria-describedby":t?void 0:`${i}-support`,className:`size-4 accent-accent`,onChange:e=>n(e.currentTarget.checked)}),`Use Pronunciation Glossary`]}),(0,h.jsx)(V,{id:`play.pronunciation-glossary`})]}),r===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-1 pl-7`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-shared`,className:`flex min-h-8 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-shared`,type:`checkbox`,"data-play-field":`audio.shareGlossary`,checked:r.value===!0,disabled:!a,className:`size-4 accent-accent`,onChange:e=>r.onChange(e.currentTarget.checked)}),`Also use pronunciations from my other projects`]}),(0,h.jsx)(V,{id:`play.share-glossary`})]}),r.note===void 0?null:r.note]}),t?null:(0,h.jsx)(`p`,{id:`${i}-support`,className:`text-label text-ink-3`,children:`Unavailable for this provider or model. Your saved preference is retained.`})]})}var v6={source:`off`,prompt:``,thumbnail:!0},yhe=[{value:`prompt`,label:`From a prompt`},{value:`provide`,label:`Upload`}];function y6({value:e,prompts:t,problem:n,upload:r,prompt:i,onChange:a}){let o=(0,m.useId)(),s=e.source===`off`,c=t.filter(e=>e.kind===`image`).map(e=>({value:e.name,label:e.name}));return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsx)(`div`,{className:`min-w-0`,children:(0,h.jsx)(FV,{field:`reference.source`,label:`Establishing image`,tip:`play.reference`,value:s?``:e.source,placeholder:`Off`,options:yhe,problem:n?.(`reference.source`),onPick:t=>a({...e,source:t===`prompt`||t===`provide`?t:`off`})})}),e.source===`provide`?(0,h.jsx)(`div`,{className:`min-w-0`,children:r}):i??(0,h.jsx)(FV,{field:`reference.prompt`,label:`Establishing prompt`,tip:`play.reference.prompt`,value:e.prompt,placeholder:s?`Off`:`Pick an image prompt`,options:c,disabled:s,problem:n?.(`reference.prompt`),onPick:t=>a({...e,prompt:t})}),(0,h.jsxs)(`div`,{className:`col-span-full flex min-h-9 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:o,className:`flex cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{id:o,type:`checkbox`,"data-play-field":`reference.thumbnail`,checked:e.thumbnail,disabled:s,onChange:t=>a({...e,thumbnail:t.target.checked})}),`Draw the thumbnail from it too`]}),(0,h.jsx)(V,{id:`play.reference.thumbnail`})]})]})}function b6({choice:e,onChange:t,field:n=`llm.thinking`,label:r=`Thinking`,tip:i=`play.llm.thinking`,problem:a}){let{api:o}=z(),s=N(AV(o,e.provider)).data?.models.find(t=>t.id===e.model)?.thinkingModes??[];if(!s.length&&!e.thinking)return null;let c=r===`Thinking`?`thinking level`:r.toLowerCase();return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(FV,{field:n,label:r,tip:i,value:e.thinking??`default`,placeholder:`Model default`,problem:e.thinking&&!s.includes(e.thinking)?`Choose a supported ${c}.`:a,options:[{value:`default`,label:`Model default`},...e.thinking&&!s.includes(e.thinking)?[{value:e.thinking,label:`${e.thinking} (saved level)`}]:[],...s.map(e=>({value:e,label:e===`off`?`Off`:e.charAt(0).toUpperCase()+e.slice(1)}))],onPick:n=>{let r=s.find(e=>e===n),{thinking:i,...a}=e;t(r===void 0?a:{...a,thinking:r})}}),r===`Thinking`&&s.length&&!s.includes(`off`)?(0,h.jsx)(`p`,{className:`mt-1 text-small text-ink-3`,children:`This model does not support turning thinking off.`}):null]})}function bhe({form:e,prompts:t,providers:n,voices:r,problem:i,update:a,onPickFiles:o,onRemoveFile:s,onReattachFile:c,rawCounts:l,advanced:u,cast:d,language:f,titled:p}){let g=r.filter(t=>t.provider===e.audio.provider),_=F2(g,f??`en`,e.audio.voice||void 0),v=f===void 0?g:_.listed,y=e.voices?.speakers.find(e=>e.voice.provider&&e.voice.model&&e.voice.voice)?.voice,b=e.intro!==``||e.outro!==``,x=e.voices!==void 0&&!b&&y!==void 0;(0,m.useEffect)(()=>{if(!x||y===void 0)return;let t=e.audio;(t.provider!==y.provider||t.model!==y.model||t.voice!==y.voice)&&a({audio:{...t,provider:y.provider,model:y.model,voice:y.voice}})},[x,y,e.audio,a]);let S=e.voices!==void 0,C=[e.chunking.mode,e.intro?`intro ${e.intro}`:void 0,e.outro?`outro ${e.outro}`:void 0,e.narrationPrompt?`preparation on`:void 0,e.audio.usePronunciationGlossary?`glossary on`:void 0].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(e6,{kind:`audio`,name:`Audio`,dim:e.sources.audio===`off`,titled:p,children:[(0,h.jsx)(t6,{kind:`audio`,form:e,update:a}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[x?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`audio.provider`,label:S?`Intro and outro TTS`:`TTS`,tip:`play.tts.provider`,family:`tts`,providers:n,value:e.audio.provider,problem:i(`audio`),onPick:t=>{a({audio:{...e.audio,provider:t,model:``,voice:``}})}}),(0,h.jsx)(zV,{field:`audio.model`,label:`TTS model`,tip:`play.tts.model`,provider:e.audio.provider,value:e.audio.model,problem:i(`audio.model`),onPick:t=>a({audio:{...e.audio,model:t}})}),(0,h.jsx)(FV,{field:`audio.voice`,label:S?`Intro and outro voice`:`Voice`,tip:`play.voice`,value:e.audio.voice,placeholder:v.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:v.map(e=>({value:e.voiceId,label:e.name})),problem:i(`audio.voice`),onPick:t=>{a({audio:{...e.audio,voice:t}})}}),f===void 0?null:(0,h.jsx)(I2,{language:f,voice:g.find(t=>t.voiceId===e.audio.voice),hidden:_.hidden,showAll:_.showAll,onShowAll:_.setShowAll}),S?(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`This voice reads only the intro and outro. Each speaker's voice is set under Speakers.`}):null]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Speakers ·`,` `,e.voices===void 0?`Narration, one voice`:`${vhe(e.voices.format)}, ${String(e.voices.speakers.length)} ${e.voices.speakers.length===1?`speaker`:`speakers`}`]}),(0,h.jsx)(`div`,{className:`pt-2 pb-3`,children:(0,h.jsx)(f6,{value:e.voices,providers:n,voices:r,script:e.sources.article===`provide`?e.provided.article:void 0,problem:i,cast:d,language:f,onChange:e=>a({voices:e})})})]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Audio Advanced · `,C]}),(0,h.jsxs)(`div`,{className:`sl-fields pt-2 pb-3`,children:[(0,h.jsx)(`div`,{className:`col-span-full`,children:(0,h.jsx)(q3,{...l?{rawCounts:l}:{},value:e.chunking,onPick:e=>{a({chunking:e})}})}),u,(0,h.jsx)(g6,{value:e.narrationPrompt??``,prompts:t,supported:e.audio.provider===`inworld`&&e.audio.model===`inworld-tts-2`,error:i(`narrationPrompt`),onChange:e=>a({narrationPrompt:e})}),(0,h.jsx)(_6,{value:e.audio.usePronunciationGlossary,supported:Sj({sources:e.sources,audio:{...e.audio,usePronunciationGlossary:!0}}),onChange:t=>a({audio:{...e.audio,usePronunciationGlossary:t}}),shared:{value:e.audio.shareGlossary??!0,onChange:t=>a({audio:{...e.audio,shareGlossary:t}})}}),(0,h.jsx)(h6,{value:e.audio.useNarrationAliases,onChange:t=>a({audio:{...e.audio,useNarrationAliases:t}})}),(0,h.jsx)(p6,{value:e.audio.describeFigures,skipCode:e.audio.skipCode,onChange:t=>a({audio:{...e.audio,...t}})})]})]})]}):null}),e.sources.audio===`provide`?(0,h.jsxs)(`div`,{className:$3,children:[(0,h.jsx)(Z3,{field:`provided.audio`,label:`Narration file`,accept:`audio/*`,uploads:e.provided.audio===void 0?[]:[e.provided.audio],problem:i(`provided.audio`),onPick:e=>{o(`audio`,e)},onReattach:c?(e,t)=>c(`audio`,e,t):void 0,onRemove:e=>{s(`audio`,e)}}),(0,h.jsx)(`p`,{className:`mt-2 text-small text-ink-2`,children:`Uploaded narration is used as-is; include any intro and outro in that file.`})]}):null]})}function xhe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawNumbers:c,more:l,titled:u}){return(0,h.jsxs)(e6,{kind:`images`,name:`Images`,dim:e.sources.images===`off`,titled:u,children:[(0,h.jsx)(t6,{kind:`images`,form:e,update:i}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.images===`generate`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}),(0,h.jsx)(Y3,{prompts:n.filter(e=>e.kind===`image`),...c?{rawNumbers:c}:{},picked:e.imagePrompts,problem:r,onPick:e=>{i({imagePrompts:e})}}),(0,h.jsx)(She,{form:e,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s?{onReattachFile:s}:{}}),l]}):null}),e.sources.images===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.images`,label:`Slideshow images`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,numbered:!0,uploads:e.provided.images,problem:r(`provided.images`),onPick:e=>{a(`images`,e)},onReattach:s?(e,t)=>s(`images`,e,t):void 0,onRemove:e=>{o(`images`,e)}})}):null]})}function x6({form:e,providers:t,problem:n,update:r}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`images.provider`,label:`Provider`,tip:`play.images.provider`,family:`image`,providers:t,value:e.images.provider,problem:n(`images`),onPick:e=>r({images:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`images.model`,label:`Model`,tip:`play.images.model`,provider:e.images.provider,value:e.images.model,problem:n(`images.model`),onPick:t=>r({images:{...e.images,model:t}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:e.images,problem:n(`images.thinking`),onChange:e=>r({images:e})})]})}function She({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsx)(y6,{value:e.reference??v6,prompts:t,problem:n,onChange:e=>r({reference:e}),upload:(0,h.jsx)(Z3,{field:`provided.reference`,label:`Establishing image file`,accept:`image/png,image/jpeg`,uploads:e.provided.reference===void 0?[]:[e.provided.reference],problem:n(`provided.reference`),onPick:e=>{i(`reference`,e)},onReattach:o?(e,t)=>o(`reference`,e,t):void 0,onRemove:e=>{a(`reference`,e)}})})}var S6=5e3,Che=[`Write a YouTube description for this video.`,``,`- Summary: a 2-3 sentence hook that says what the viewer gets from watching, in plain words, without clickbait.`,`- Chapters: split the video where the topic changes, 5-12 chapters for a long video and fewer for a short one. Chapter titles are 2-6 words, in title case, and name what that part covers.`,`- Hashtags: 3-5 hashtags about the subject, most specific last.`,`- Tags: 15-25 search terms a viewer might type to find this video, from broad to specific.`].join(`
282
+ `),whe=`Built-in`;function C6({enabled:e,prompt:t,prompts:n,narrated:r,problem:i,onChange:a}){let o=(0,m.useId)(),s=n.filter(e=>e.kind===`description`),c=t!==``&&!s.some(e=>e.name===t),l=i?.(`youtubeDescription`)??i?.(`descriptionPrompt`);return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1 self-end`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${o}-switch`,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${o}-switch`,type:`checkbox`,"data-play-field":`youtubeDescription`,checked:e,disabled:!r&&!e,"aria-describedby":l?`${o}-error`:void 0,className:`size-4 accent-accent`,onChange:e=>a({youtubeDescription:e.currentTarget.checked,descriptionPrompt:t})}),`YouTube description`]}),(0,h.jsx)(V,{id:`play.youtube-description`})]}),(0,h.jsx)(WV,{htmlFor:`${o}-prompt`,label:`Description prompt`,tip:`play.description-prompt`,children:(0,h.jsxs)(DV,{id:`${o}-prompt`,"data-play-field":`descriptionPrompt`,value:t,disabled:!e,onChange:t=>a({youtubeDescription:e,descriptionPrompt:t.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:whe}),c?(0,h.jsxs)(`option`,{value:t,children:[t,` (saved choice)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`sl-fields__wide m-0 text-small text-danger`,children:l}):r?null:(0,h.jsx)(`p`,{className:`sl-fields__wide m-0 text-label text-ink-3`,children:`Needs narration.`})]})}function w6({value:e,narrated:t,imageProvider:n,problem:r,onChange:i,fieldPrefix:a=`videoEdit`,language:o}){let s=(0,m.useId)(),c=e??fA,l=e=>i({...c,...e}),{api:u}=z(),d=N(jV(u,n,c.animate!==`off`)),f=e=>r?.(`${a}.${e}`),p=[c.transition===`cut`?void 0:`${_A[c.transition]} ${String(c.transitionSeconds)} s`,c.grade===`none`?void 0:yA[c.grade],c.atmosphere===`none`?void 0:bA[c.atmosphere],c.vignette===`off`?void 0:`Vignette`,c.grain===`off`?void 0:`Grain`,c.chapterCards?`Chapter cards`:void 0,c.animate===`off`?void 0:`Animated images`].filter(e=>e!==void 0),g=[`transition`,`transitionSeconds`,`chapterCards`,`animate`,`animateEvery`,`animateModel`].map(f).filter(e=>e!==void 0),_=d.data?.models??[],v=c.animateModel!==``&&!_.some(e=>e.id===c.animateModel),y=VO(o);return{cuts:(0,h.jsxs)(T6,{id:`${s}-cuts`,label:`Cuts`,tip:`project.video.cuts`,children:[(0,h.jsx)(DV,{id:`${s}-cuts`,"data-play-field":`${a}.cuts`,className:`min-w-0`,value:y===void 0?c.cuts:`interval`,disabled:y!==void 0,"aria-describedby":y===void 0?void 0:`${s}-cuts-note`,onChange:e=>l({cuts:e.target.value}),children:oA.map(e=>(0,h.jsx)(`option`,{value:e,children:gA[e]},e))}),y===void 0?null:(0,h.jsx)(`p`,{id:`${s}-cuts-note`,className:`m-0 basis-full text-small text-ink-3`,children:y})]}),look:(0,h.jsxs)(`details`,{className:`group min-w-0 rounded-control border border-line-strong`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-10 cursor-pointer items-center gap-3 px-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Look`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-ink-3`,children:p.length===0?`Plain cuts, no effects`:p.join(` · `)})]}),(0,h.jsxs)(`div`,{className:`sl-fields border-line-strong border-t p-3`,children:[(0,h.jsxs)(T6,{id:`${s}-transition`,label:`Transition`,tip:`project.video.transition`,children:[(0,h.jsx)(DV,{id:`${s}-transition`,"data-play-field":`${a}.transition`,className:`min-w-0`,value:c.transition,onChange:e=>l({transition:e.target.value}),children:sA.map(e=>(0,h.jsx)(`option`,{value:e,children:_A[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Transition length`,"data-play-field":`${a}.transitionSeconds`,"aria-invalid":f(`transitionSeconds`)!==void 0,className:`w-24 flex-none`,disabled:c.transition===`cut`,value:String(c.transitionSeconds),onChange:e=>l({transitionSeconds:Number(e.target.value)}),children:hA.map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[e,` s`]},e))})]}),(0,h.jsx)(T6,{id:`${s}-grade`,label:`Colour grade`,tip:`project.video.grade`,children:(0,h.jsx)(E6,{id:`${s}-grade`,field:`${a}.grade`,value:c.grade,options:lA,labels:yA,onChange:e=>l({grade:e})})}),(0,h.jsx)(T6,{id:`${s}-vignette`,label:`Vignette`,tip:`project.video.vignette`,children:(0,h.jsx)(E6,{id:`${s}-vignette`,field:`${a}.vignette`,value:c.vignette,options:cA,labels:vA,onChange:e=>l({vignette:e})})}),(0,h.jsx)(T6,{id:`${s}-grain`,label:`Film grain`,tip:`project.video.grain`,children:(0,h.jsx)(E6,{id:`${s}-grain`,field:`${a}.grain`,value:c.grain,options:cA,labels:vA,onChange:e=>l({grain:e})})}),(0,h.jsx)(T6,{id:`${s}-atmosphere`,label:`Atmosphere`,tip:`project.video.atmosphere`,children:(0,h.jsx)(E6,{id:`${s}-atmosphere`,field:`${a}.atmosphere`,value:c.atmosphere,options:uA,labels:bA,onChange:e=>l({atmosphere:e})})}),(0,h.jsx)(T6,{id:`${s}-cards`,label:`Chapter cards`,tip:`project.video.chapter-cards`,children:(0,h.jsx)(`input`,{id:`${s}-cards`,type:`checkbox`,"data-play-field":`${a}.chapterCards`,className:`size-4 accent-accent`,checked:c.chapterCards,disabled:!t&&!c.chapterCards,onChange:e=>l({chapterCards:e.currentTarget.checked})})}),(0,h.jsxs)(T6,{id:`${s}-animate`,label:`Animate images`,tip:`project.video.animate`,wide:!0,children:[(0,h.jsx)(DV,{id:`${s}-animate`,"data-play-field":`${a}.animate`,"aria-invalid":f(`animate`)!==void 0,className:`min-w-0`,value:c.animate,onChange:e=>l({animate:e.target.value}),children:dA.map(e=>(0,h.jsx)(`option`,{value:e,disabled:e===`chapters`&&!t,children:xA[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Animate every how many images`,"data-play-field":`${a}.animateEvery`,"aria-invalid":f(`animateEvery`)!==void 0,className:`w-24 flex-none`,disabled:c.animate!==`every`,value:String(c.animateEvery),onChange:e=>l({animateEvery:Number(e.target.value)}),children:Array.from({length:9},(e,t)=>t+2).map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[`every `,e]},e))}),(0,h.jsxs)(DV,{"aria-label":`Image-to-video model`,"data-play-field":`${a}.animateModel`,"aria-invalid":f(`animateModel`)!==void 0,className:`min-w-0`,disabled:c.animate===`off`,value:c.animateModel,onChange:e=>l({animateModel:e.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a model`}),v?(0,h.jsxs)(`option`,{value:c.animateModel,children:[c.animateModel,` (saved choice)`]}):null,_.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),g.length>0?(0,h.jsx)(`p`,{className:`col-span-full text-small text-danger`,children:g[0]}):c.animate!==`off`&&d.isSuccess&&_.length===0?(0,h.jsx)(`p`,{className:`col-span-full text-label text-ink-3`,children:`This image provider has no image-to-video models. Choose fal.ai or Replicate for images to animate them.`}):null]})]})}}function T6({id:e,label:t,tip:n,wide:r=!1,children:i}){return(0,h.jsxs)(`div`,{className:L(`sl-field`,r&&`sl-fields__wide`),...Ob,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),(0,h.jsx)(V,{id:n,label:t.toLowerCase()})]}),(0,h.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-start gap-2 [&>select]:min-w-0 [&>select]:flex-1`,children:i})]})}function E6({id:e,field:t,value:n,options:r,labels:i,onChange:a}){return(0,h.jsx)(DV,{id:e,"data-play-field":t,className:`min-w-0`,value:n,onChange:e=>a(e.target.value),children:r.map(e=>(0,h.jsx)(`option`,{value:e,children:i[e]},e))})}var The=rO(`kind`,[q({kind:pO(`upload`),stagedFileId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`output`),outputId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`picture`),sha256:W().regex(/^[a-f0-9]{64}$/)})]),D6=q({format:J(PS),subtitles:q({mode:J(fM),fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/),fontSize:G().finite().min(16).max(120),position:J(pM)}),videoEdit:yM.optional(),previewText:W().max(200).optional(),image:The.optional(),shorts:q({titleOnScreen:GD(),speed:G().finite().min(1).max(1.25).optional(),title:W().max(100).optional()}).optional(),force:GD().optional()}),Ehe=q({hash:W().regex(/^[a-f0-9]{64}$/),url:W().min(1),cached:GD(),seconds:G().positive()});async function Dhe(e,t,n){let r=await e.fetch(`${e.origin}/api/style-preview`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),...n===void 0?{}:{signal:n}});if(!r.ok)throw await fo(r);let i=So(Ehe,await r.json());return{...i,src:`${e.origin}${i.url}`}}var Ohe=600;function O6({settings:e,label:t,drawnOn:n,poster:r}){let{api:i}=z(),a=N({queryKey:sN,queryFn:()=>cN(i),staleTime:6e4}),{format:o,subtitles:s,videoEdit:c,previewText:l,image:u,shorts:d}=e,f=r??(u?.kind===`picture`?ux(i,u.sha256):void 0),p=u===void 0?``:JSON.stringify(u),g=d===void 0?``:JSON.stringify(d),_=(0,m.useMemo)(()=>JSON.stringify({format:o,subtitles:{mode:s.mode,fontId:s.fontId,fontSize:s.fontSize,position:s.position},...c===void 0?{}:{videoEdit:c},...l===void 0||l.trim()===``?{}:{previewText:l},...p===``?{}:{image:JSON.parse(p)},...g===``?{}:{shorts:JSON.parse(g)}}),[o,s.mode,s.fontId,s.fontSize,s.position,c,l,p,g]),v=(0,m.useMemo)(()=>D6.safeParse(JSON.parse(_)).success,[_]),[y,b]=(0,m.useState)({kind:`idle`}),[x,S]=(0,m.useState)(void 0),C=(0,m.useRef)(void 0),w=(0,m.useCallback)(async e=>{C.current?.abort();let t=new AbortController;C.current=t,b({kind:`pending`});try{let n=await Dhe(i,{...D6.parse(JSON.parse(_)),...e?{force:e}:{}},t.signal);if(C.current!==t)return;S(n.src),b({kind:`ready`,src:n.src})}catch(e){if(C.current!==t||t.signal.aborted)return;b({kind:`failed`,message:e instanceof Error&&e.message!==``?e.message:`The style preview couldn't render. Press Render again.`})}},[i,_]);(0,m.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>{w(!1)},Ohe);return()=>clearTimeout(e)},[w,v]),(0,m.useEffect)(()=>()=>C.current?.abort(),[]);let T=a.data?.fonts.find(e=>e.id===s.fontId)?.name??(s.fontId==="default"?`Barlow`:`Chosen font`),E=d===void 0?s.mode===`burn-in`?`Captions: ${T} ${String(s.fontSize)} · ${khe(s.position)}`:s.mode===`files`?`Captions: a separate file, which players show in their own style`:`Captions: off`:[`Captions: ${T}, word by word`,d.titleOnScreen?`Title on screen`:`No title on screen`,d.speed===void 0||d.speed===1?void 0:`${d.speed.toFixed(2)}×`].filter(e=>e!==void 0).join(` · `),D=d===void 0?`Style preview`:`Shorts preview`,O=o===`9:16`||d!==void 0;return(0,h.jsxs)(`section`,{"aria-label":D,className:`min-w-0 space-y-3`,children:[(0,h.jsx)(H,{as:`h3`,title:D,meta:d===void 0?`6 seconds of the sample, rendered with your settings`:`A few seconds of the sample as a short, rendered with your settings`,info:d===void 0?`project.video.style-preview`:`play.shorts.preview`,children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:!v||y.kind===`pending`,disabledReason:v?`Rendering the preview…`:`Fix the caption settings to render the preview.`,onClick:()=>{w(!0)},children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,size:16,strokeWidth:1.75}),`Render again`]})}),x===void 0?null:(0,h.jsx)(R0,{src:x,label:t??D,...f===void 0?{}:{poster:f},portrait:O,className:O?`max-w-[270px]`:`max-w-[480px]`}),y.kind===`pending`?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Rendering the preview…`}):null,y.kind===`failed`?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:y.message}):null,v?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The preview renders again once the caption size is between 16 and 120.`}),(0,h.jsxs)(`p`,{className:`text-small text-ink-2`,children:[E,u===void 0||n===void 0?``:` · Drawn on ${n}`]})]})}function khe(e){let t=e.replace(/-/g,` `);return`${t[0]?.toUpperCase()??``}${t.slice(1)}`}function Ahe({form:e,problem:t,update:n,onPickFiles:r,onRemoveFile:i,onReattachFile:a}){let o=e.provided.ambientBed;return(0,h.jsx)(A2,{value:e.ambientBed,inherit:`The channel's (brand kit)`,sources:Qk,offerNone:!0,problem:e=>t(`ambientBed.${e}`),file:(0,h.jsx)(Z3,{field:`ambientBed.file`,label:`Ambient sound file: an audio file, looped if shorter than the video`,accept:`audio/*`,uploads:o===void 0?[]:[o],problem:t(`ambientBed.file`),onPick:e=>r(`ambientBed`,e),onReattach:a?(e,t)=>a(`ambientBed`,e,t):void 0,onRemove:e=>i(`ambientBed`,e)}),onChange:e=>n({ambientBed:e})})}function k6({value:e,onChange:t,problem:n,switchTip:r=`project.loudness`,switchLabel:i=`Level the volume`}){return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[(0,h.jsx)(kb,{checked:e.enabled,label:i,tip:r,onChange:n=>t({...e,enabled:n})}),e.enabled?(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(j6,{target:`video`,label:`Video volume`,tip:`project.loudness.video`,lufs:e.videoLufs,error:n?.(`videoLufs`),onChange:n=>t({...e,videoLufs:n})}),(0,h.jsx)(j6,{target:`audioFiles`,label:`Audio files volume`,tip:`project.loudness.audio-files`,lufs:e.audioFilesLufs,error:n?.(`audioFilesLufs`),onChange:n=>t({...e,audioFilesLufs:n})})]}):null]})}var jhe=`Enter a volume between ${M6(-10)} dB and ${M6(4)} dB (${String(ck(-10))}% to ${String(ck(4))}%).`;function A6(e,t){let n=e.trim().replace(`−`,`-`).replace(`,`,`.`);if(n===``)return;let r=Number(n.replace(/(dB|%)$/i,``).trim());if(!Number.isFinite(r)||t===`percent`&&r<=0)return;let i=t===`db`?r:lk(r);if(!(i<-10.25||i>4.25))return uk(i)}function j6({target:e,label:t,tip:n,lufs:r,error:i,onChange:a}){let o=(0,m.useId)(),s=ok(r,e),[c,l]=(0,m.useState)(),u=c===void 0||A6(c.text,c.unit)!==void 0,d=(t,n)=>{l({unit:t,text:n});let r=A6(n,t);r!==void 0&&a(sk(r,e))},f=c?.unit===`db`?c.text:M6(s),p=c?.unit===`percent`?c.text:String(ck(s));return(0,h.jsx)(xV,{label:t,tip:n,help:`0 dB is the recommended ${N6(ik(e))} LUFS; this is ${N6(r)} LUFS. Peaks stay under ${N6(ak(e))} dBTP.`,error:u?i:jhe,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`loudness.${e===`video`?`videoLufs`:`audioFilesLufs`}`,value:f,onChange:e=>d(`db`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`dB`}),(0,h.jsx)(CV,{id:`${o}-percent`,"aria-label":`${t} as a percentage of the recommended level`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:p,onChange:e=>d(`percent`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`%`})]})})}function M6(e){return e>0?`+${String(e)}`:N6(e)}function N6(e){return String(e).replace(`-`,`−`)}function P6({sentence:e,paragraph:t,problem:n,onChange:r}){let i=`0 to 2 in steps of ${String(yk)}`;return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(xV,{label:`Pause between sentences (seconds)`,tip:`project.pause.sentence`,help:`${i}; ${String(vk)} is the default. 0 leaves the voice's own.`,error:n(`sentencePauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`sentencePauseSeconds`,value:e,onChange:e=>r(`sentencePauseSeconds`,e.target.value)})}),(0,h.jsx)(xV,{label:`Pause between paragraphs (seconds)`,tip:`project.pause.paragraph`,help:`${i}; 0 (the default) keeps the sentence pause.`,error:n(`paragraphPauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`paragraphPauseSeconds`,value:t,onChange:e=>r(`paragraphPauseSeconds`,e.target.value)})})]})}function F6(e){let t=e.trim().replace(`,`,`.`);if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function Mhe({form:e,problem:t,update:n}){let{api:r}=z(),i=N(ob(r)).data?.loudness??tk,a=e.loudness;return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[e.sources.audio===`generate`?(0,h.jsx)(P6,{sentence:e.sentencePause??`0.4`,paragraph:e.paragraphPause??`0`,problem:t,onChange:(e,t)=>n(e===`sentencePauseSeconds`?{sentencePause:t}:{paragraphPause:t})}):null,(0,h.jsx)(k6,{value:{enabled:a?.enabled??i.enabled,videoLufs:a?.videoLufs??i.videoLufs,audioFilesLufs:a?.audioFilesLufs??i.audioFilesLufs},problem:e=>t(`loudness.${e}`),onChange:e=>n({loudness:e})})]})}function I6({value:e,onPick:t,disabled:n=!1}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,...Ob,children:[(0,h.jsx)(X4,{id:r,className:`shrink-0`,children:`Thumbnails`}),(0,h.jsxs)(Z4,{type:`single`,value:String(e),"aria-labelledby":r,disabled:n,"data-play-field":`thumbnailCount`,onValueChange:e=>{(e===`1`||e===`3`)&&t(e===`3`?3:1)},children:[(0,h.jsx)(Q4,{value:`1`,children:`1`}),(0,h.jsx)(Q4,{value:`3`,children:`3`})]}),(0,h.jsx)(V,{id:`play.thumbnail-count`})]})}function Nhe({form:e,problem:t,update:n}){return(0,h.jsxs)(e6,{kind:`research`,name:`Research`,dim:e.sources.research===`off`,children:[(0,h.jsx)(t6,{kind:`research`,form:e,update:n}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.research===`generate`?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:`Runs through the LLM, one agent per chapter`}):null}),e.sources.research===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.research`,label:`Research notes`,tip:`play.provided.research`,value:e.provided.research,placeholder:`Paste the notes the article will be written from.`,problem:t(`provided.research`),onChange:t=>{n({provided:{...e.provided,research:t}})}})}):null]})}function Phe({form:e,prompts:t,problem:n,update:r,titled:i}){return(0,h.jsxs)(e6,{kind:`article`,name:`Article`,dim:!1,titled:i,children:[(0,h.jsx)(t6,{kind:`article`,form:e,update:r}),(0,h.jsx)(`div`,{className:`${$3} grid gap-4`,children:e.sources.article===`generate`?(0,h.jsx)(FV,{field:`articlePrompt`,label:UA(e)?`Script prompt`:`Article prompt`,tip:`play.article-prompt`,value:e.articlePrompt,placeholder:`Pick a prompt`,options:n6(t,l0(e)),problem:n(`articlePrompt`),onPick:e=>{r({articlePrompt:e})}}):null}),e.sources.article===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.article`,label:`Article text`,tip:`play.provided.article`,value:e.provided.article,placeholder:`Paste the article that will be narrated.`,problem:n(`provided.article`),onChange:t=>{r({provided:{...e.provided,article:t}})}})}):null]})}function Fhe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s}){let c=e.sources.thumbnail===`from_prompt`||e.sources.thumbnail===`prompt_by_llm`;return(0,h.jsxs)(e6,{kind:`thumbnail`,name:`Thumbnail`,dim:e.sources.thumbnail===`off`,children:[(0,h.jsx)(t6,{kind:`thumbnail`,form:e,update:i}),(0,h.jsxs)(`div`,{className:Q3,children:[c&&e.sources.images!==`generate`?(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}):null,c?(0,h.jsx)(FV,{field:`thumbnailPrompt`,label:`Thumbnail prompt`,tip:`play.thumbnail-prompt`,value:e.thumbnailPrompt,placeholder:`Pick a prompt`,options:n6(n,`thumbnail`),problem:r(`thumbnailPrompt`),onPick:e=>{i({thumbnailPrompt:e})}}):null,c?(0,h.jsx)(I6,{value:e.thumbnailCount===3?3:1,onPick:e=>{i({thumbnailCount:e})}}):null]}),e.sources.thumbnail===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.thumbnail`,label:`Thumbnail image`,accept:`image/png,image/jpeg,image/webp`,uploads:e.provided.thumbnail===void 0?[]:[e.provided.thumbnail],problem:r(`provided.thumbnail`),onPick:e=>{a(`thumbnail`,e)},onReattach:s?(e,t)=>s(`thumbnail`,e,t):void 0,onRemove:e=>{o(`thumbnail`,e)}})}):null]})}function Ihe({form:e,prompts:t,silenceGapSeconds:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawTiming:c,extras:l=!0,language:u,titled:d}){let f=e.sources.video===`generate`?e.sources.audio===`off`?`Silent video · each image shown once`:`Images and narration · ${String(n)} s segment gaps`:e.sources.audio===`off`?`Download each enabled stage separately`:`Combined WAV export with narration and segment gaps`,p=t=>({value:c?c[t]:Number.isFinite(e[t])?String(e[t]):``,onChange:e=>{c?c.onChange(t,e):i({[t]:e.trim()===``?NaN:Number(e)})}}),m=w6({value:e.videoEdit,narrated:e.sources.audio!==`off`,imageProvider:e.images.provider,problem:r,language:u??e.language,onChange:e=>i({videoEdit:e})});return(0,h.jsxs)(e6,{kind:`video`,name:`Export`,dim:e.sources.video===`off`,titled:d,children:[(0,h.jsx)(t6,{kind:`video`,form:e,update:i}),(0,h.jsx)(`span`,{className:Q3,children:(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:f})}),e.sources.video===`generate`||e.sources.audio!==`off`?(0,h.jsxs)(`div`,{className:Q3,children:[e.sources.video===`generate`?(0,h.jsx)(R6,{field:`imageSeconds`,label:`Seconds per image`,tip:`play.image-seconds`,step:1,problem:r(`imageSeconds`),...p(`imageSeconds`)}):null,e.sources.video===`generate`?(0,h.jsx)(R6,{field:`zoomPercent`,label:`Zoom (%)`,tip:`play.zoom`,step:.5,problem:r(`zoomPercent`),...p(`zoomPercent`)}):null,e.sources.video===`generate`?(0,h.jsx)(PV,{label:`Motion`,tip:`play.motion`,problem:void 0,children:({id:t})=>(0,h.jsx)(DV,{id:t,"data-play-field":`motionStyle`,className:`w-full`,value:e.motionStyle,onChange:e=>i({motionStyle:e.target.value}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null,e.sources.video===`generate`?m.cuts:null,e.sources.audio===`off`?null:(0,h.jsx)(R6,{field:`edgeSilenceSeconds`,label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,step:.5,problem:r(`edgeSilenceSeconds`),...p(`edgeSilenceSeconds`)})]}):null,e.sources.video===`generate`?(0,h.jsx)(`div`,{className:$3,children:m.look}):null,e.sources.video===`generate`&&e.sources.audio!==`off`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Ahe,{form:e,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s})}):null,e.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Mhe,{form:e,problem:r,update:i})}),l?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(L6,{form:e,prompts:t,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s===void 0?{}:{onReattachFile:s}})}):null,e.sources.images===`off`?(0,h.jsx)(`p`,{className:`${$3} text-small text-ink-2`,children:`Video is Off because Images is Off. Generate or provide images to enable video.`}):null]})}function L6({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[e.sources.audio===`generate`&&e.audio.describeFigures===!0?(0,h.jsx)(m6,{value:e.showFigures,onChange:e=>r({showFigures:e})}):null,e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(C6,{enabled:e.youtubeDescription===!0,prompt:e.descriptionPrompt??``,prompts:t,narrated:e.sources.audio!==`off`,problem:n,onChange:e=>r(e)})}),e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(YV,{value:e.shorts??GV,prompts:t,narrated:e.sources.audio!==`off`,problem:n,musicName:e.provided.shortsMusic?.name,music:(0,h.jsxs)(`div`,{className:`basis-full`,children:[(0,h.jsx)(Z3,{field:`shorts.music`,label:`Background music (optional): an audio file, looped if shorter than a short`,accept:`audio/*`,disabled:!jN(e),uploads:e.provided.shortsMusic===void 0?[]:[e.provided.shortsMusic],problem:n(`shorts.music`),onPick:e=>i(`shortsMusic`,e),onReattach:o?(e,t)=>o(`shortsMusic`,e,t):void 0,onRemove:e=>a(`shortsMusic`,e)}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:`Plays at the volume above under every short and dips while the narrator speaks.`})]}),preview:(0,h.jsx)(O6,{settings:KV(e.shorts??GV,e.subtitles.fontId)}),onChange:e=>r({shorts:e})})})]})}function R6({field:e,label:t,tip:n,placeholder:r,step:i,problem:a,value:o,onChange:s}){return(0,h.jsx)(PV,{label:t,tip:n,problem:a,children:({id:t,describedBy:n})=>(0,h.jsx)(CV,{id:t,"data-play-field":e,type:`text`,inputMode:i<1?`decimal`:`numeric`,className:`sl-input--number`,"aria-invalid":a!==void 0,"aria-describedby":n,placeholder:r,value:o,onChange:e=>s(e.target.value)})})}function Lhe({form:e,update:t}){let n=e.sources.document===`off`;return(0,h.jsxs)(e6,{kind:`document`,name:`Document`,dim:n,children:[(0,h.jsx)(t6,{kind:`document`,form:e,update:t}),(0,h.jsx)(`div`,{className:Q3,children:(0,h.jsx)(PV,{label:`Theme`,tip:`play.document-theme`,problem:void 0,children:({id:r})=>(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(G3,{id:r,field:`document.theme`,className:`w-auto min-w-[120px]`,disabled:n,value:e.document,onChange:e=>{t({document:e})}}),(0,h.jsx)(ha,{to:`/document-themes`,className:`text-small text-accent-ink underline`,children:`Edit themes`})]})})})]})}function Rhe({form:e,providers:t,problem:n,update:r,uses:i,onSettings:a}){let o=[...new Set(i.map(e=>e.label))],s=o.length<=1?o[0]??``:`${o.slice(0,-1).join(`, `)} and ${o.at(-1)??``}`;return(0,h.jsxs)(`section`,{"aria-label":`Text generation`,className:`border-y border-line py-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`Text generation`,meta:`Used for ${s}.`,info:`play.text-generation`,className:`pb-3`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Settings`})}),(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(RV,{field:`llm.provider`,label:`LLM`,tip:`play.llm.provider`,family:`llm`,providers:t,value:e.llm.provider,problem:n(`llm.provider`)??(e.llm.provider===``?n(`llm`):void 0),onPick:e=>r({llm:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`llm.model`,label:`Text model`,tip:`play.llm.model`,provider:e.llm.provider,value:e.llm.model,problem:n(`llm.model`)??(e.llm.provider!==``&&n(`llm`)?`Pick a text model.`:void 0),onPick:t=>r({llm:{...e.llm,model:t}})}),(0,h.jsx)(b6,{choice:e.llm,onChange:e=>r({llm:e})})]})]})}function z6({section:e,entries:t,...n}){let r=IN(n.form,t);return r[0]?.section===e?(0,h.jsx)(Rhe,{...n,uses:r}):null}function zhe(e){let{form:t,onLibrary:n}=e,r=e.prompts.find(e=>e.kind===l0(t)&&e.name===t.articlePrompt);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Phe,{...e,titled:!1}),t.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3 py-3`,children:[r?(0,h.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`summary`,{"data-play-field":`articlePrompt.preview`,className:`cursor-pointer py-2 text-small text-accent-ink`,children:`View prompt`}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words py-3 font-sans text-body text-ink-2`,children:r.body})]}):(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.prompts.some(e=>e.kind===l0(t))?`Choose a saved ${l0(t)} prompt.`:`No ${l0(t)} prompts saved. Create a prompt to begin.`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>n(`/prompts`),children:`Create prompt`})]}):(0,h.jsxs)(`p`,{className:`py-3 text-small text-ink-3`,children:[t.provided.article.trim()?t.provided.article.trim().split(/\s+/).length:0,` `,`words · `,t.provided.article.length,` characters`]}),(0,h.jsx)(z6,{...e,section:`article`,onSettings:()=>n(`/settings`)}),t.sources.article===`off`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`No article: for a project of images or a thumbnail made from prompts. Narration, the PDF and anything else that reads the article stay off.`}):t.sources.article===`provide`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`Research is Off because the article is provided.`}):(0,h.jsx)(Nhe,{...e})]})}function Bhe(){let{api:e}=z(),t=rP(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=Oy(),u=N({queryKey:[`play-drafts`],queryFn:async()=>{let t=await ZM(e);if(!t.ok)throw Error(t.message);return t.value.drafts}}),d=async()=>{if(!r||s)return;let e=r.id;c(!0),o(null);try{await t.discard({id:r.id,version:r.version}),i(null),await n.cancelQueries({queryKey:[`play-drafts`]}),n.setQueryData([`play-drafts`],t=>t?.filter(t=>t.id!==e))}catch(e){let t=e instanceof Error?e.message:`The draft wasn't discarded. Try again.`;o(t),l(t,`error`)}finally{c(!1)}};return(0,h.jsxs)(`section`,{"aria-label":`Drafts`,className:`flex min-w-0 flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(`p`,{role:`status`,className:L(`engraved min-w-[112px] text-right`,t.status===`saved`?`text-accent-ink`:t.status===`error`||t.status===`conflict`?`text-danger`:`text-ink-3`),children:{unsaved:`Unsaved`,saving:`Saving…`,saved:`Saved`,error:`Couldn't save`,conflict:`Changed elsewhere`}[t.status]}),t.status===`error`?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{!t.view&&t.activeId&&t.edited===0?t.open(t.activeId):t.flush()},children:`Retry`}):null,t.status===`conflict`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{t.activeId&&t.open(t.activeId)},children:`Reload saved draft`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void t.saveAsNew(),children:`Save as a new draft`}),(0,h.jsx)(V,{id:`play.draft-conflict`})]}):null,(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,children:[`Drafts`,(0,h.jsx)(uc,{"aria-hidden":`true`,className:`size-4`})]})}),(0,h.jsxs)(Eb,{align:`end`,className:`w-[340px] p-0`,"aria-label":`Saved drafts`,children:[u.isPending?(0,h.jsx)(`p`,{role:`status`,className:`px-3 py-2`,children:`Loading drafts…`}):null,u.error?(0,h.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:[u.error.message,` `,(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void u.refetch(),children:`Retry`})]}):null,u.data?.length===0?(0,h.jsx)(`p`,{className:`px-3 py-2`,children:`No saved drafts`}):null,a?(0,h.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:a}):null,u.data?.length?(0,h.jsx)(pU,{label:`Saved drafts`,className:`max-h-72 overflow-y-auto border-t-0`,children:u.data.map(e=>(0,h.jsx)(mU,{title:e.title||`Untitled draft`,onSelect:()=>void t.open(e.id),meta:(0,h.jsxs)(`time`,{dateTime:e.updatedAt,children:[`Last edited `,ku(e.updatedAt)]}),actions:(0,h.jsx)(wy,{size:`small`,label:`Discard ${e.title||`Untitled draft`}`,onClick:()=>{i(e),o(null)},children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:e.readable?null:(0,h.jsx)(`p`,{className:`m-0 text-label text-waiting`,children:`Unsupported or corrupt draft. Try opening it to recover, or discard it.`})},e.id))}):null]})]}),(0,h.jsx)(R,{onClick:()=>void t.newDraft(),children:`New draft`}),(0,h.jsx)(V,{id:`play.drafts`}),(0,h.jsx)(jy,{open:r!==null,title:`Discard ${r?.title||`Untitled draft`}?`,consequence:`The draft is removed. This cannot be undone.`,confirmLabel:`Discard draft`,pending:s,onConfirm:()=>void d(),onCancel:()=>{s||i(null)}})]})}function B6(e,t){let n=[...e.querySelectorAll(`[data-play-field]`)].find(e=>e.dataset.playField===t);if(!n||n.hasAttribute(`disabled`))return!1;let r=n.closest(`details`);return r!==null&&!r.open&&(r.open=!0),n.focus(),n.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`instant`}),document.activeElement===n}function Vhe(e,t,n,r=[]){let i=e;if(e===`fontUpload`&&(i=`subtitles.fontUpload`),/^provided\.images\.\d+$/.test(e)&&(i=`provided.images`),e===`subtitles`&&(i=`subtitles.mode`),e===`chunking`&&(i=`chunking.mode`),[`audio`,`llm`,`images`].includes(e)&&(i=`${e}.provider`),e===`provided`){let e=[`audio`,`images`,`thumbnail`].find(e=>t.sources[e]===`provide`&&(e===`images`?t.provided.images:[t.provided[e]]).some(e=>e&&(e.error!==void 0||e.file===void 0))),n=t.provided.shortsMusic;i=e===void 0&&jN(t)&&n!==void 0&&(n.error!==void 0||n.file===void 0)?`shorts.music`:t.reference?.source===`provide`&&t.provided.reference!==void 0&&(t.provided.reference.error!==void 0||t.provided.reference.file===void 0)?`provided.reference`:`provided.${e??`audio`}`;let r=t.provided.ambientBed;e===void 0&&MN(t)&&r!==void 0&&(r.error!==void 0||r.file===void 0)&&(i=`ambientBed.file`)}let a=/^imagePrompts\.(\d+)\.(.+)$/.exec(e);if(a){let e=t.imagePrompts[Number(a[1])];e&&(i=`imagePrompts.${e.name}.${a[2]}`)}e===`imagePrompts`&&(i=t.imagePrompts[0]?`imagePrompts.${t.imagePrompts[0].name}.number`:`imagePrompts`);let o=/^variants\.(\d+)\.(.+)$/.exec(e);o&&(i=`items.${n[Number(o[1])]?.key??o[1]}.${o[2]}`);let s=/^items\.(\d+)\.(.+)$/.exec(e);s&&(i=Number(s[1])===0?s[2]??e:`items.${n[Number(s[1])-1]?.key??s[1]}.${s[2]}`);let c=t=>t.some(t=>e===t||e.startsWith(`${t}.`));return{section:c([`title`,`articlePrompt`,`provided.article`,`provided.research`,`sources.article`,`sources.research`,...(IN(t,r)[0]?.section??`article`)===`article`?[`llm`]:[],`values`])?`content`:c([`format`,`subtitles`,`fontUpload`])?`style`:c(`audio,narrationPrompt,voices,provided.audio,intro,outro,chunking,images,imagePrompts,imageScale,provided.images,thumbnailPrompt,provided.thumbnail,provided.reference,reference,provided,sources,imageSeconds,zoomPercent,motionStyle,edgeSilenceSeconds,document,youtubeDescription,descriptionPrompt,shorts,videoEdit,ambientBed,loudness,sentencePauseSeconds,paragraphPauseSeconds,llm`.split(`,`))?`outputs`:`review`,field:i}}function Hhe({fields:e,values:t,origins:n,topics:r=[],hide:i=[],problem:a,onChange:o}){let s=e.filter(e=>!i.includes(e.name));return s.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-3 text-small text-ink-2`,children:`Each keyword is entered once and fills every place that names it.`}),(0,h.jsx)(_0,{keywords:s.map(e=>({name:e.name,value:Object.hasOwn(t,e.name)?t[e.name]??``:``,feeds:n?.get(e.name)??[],topic:r.includes(e.name)})),problem:a,onChange:o})]}):null}var Uhe={every:`minutes`,value:`2`};function Whe({document:e,problem:t,onEdit:n}){let r=(0,m.useId)(),{form:i}=e,a=i.imageScale,o=t(`imageScale.value`)??t(`imageScale`),s=a===void 0?void 0:o===void 0?Khe(e):{text:o,problem:!0},c=t=>{let{imageScale:r,...o}=i;n({...e,form:{...o,...t===void 0?{}:{imageScale:t},...t!==void 0&&a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})};return(0,h.jsxs)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{checked:a!==void 0,label:`More images for long videos`,tip:`play.image-scale`,describedBy:`${r}-line`,onChange:e=>c(e?Uhe:void 0)}),a===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,...Ob,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,tip:`play.image-scale.rate`,value:a.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>c({every:e,value:Ghe(a.value,a.every,e)})}),a.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{id:`${r}-value`,"data-play-field":`imageScale.value`,"aria-label":a.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`sl-input--number`,"aria-invalid":s?.problem===!0,"aria-describedby":`${r}-line`,value:a.value,onChange:e=>c({every:a.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:a.every===`minutes`?`minutes`:`images per hour`})]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:s.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:s.text})]})}function Ghe(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function Khe(e){let{form:t}=e,n=t.imageScale;if(n===void 0)return{text:``,problem:!1};let r=Number(n.value.trim()),i=n.every===`minutes`;if(!(n.value.trim()!==``&&(i?r>=.25&&r<=60:r>=1&&r<=240)))return{text:i?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`,problem:!0};let a=i?YO(r):r,o=t.sources.article===`provide`,s=Number(e.expectedWords.trim()),c=o?Math.max(1,qO(t.provided.article)):Number.isInteger(s)&&s>=1&&s<=1e5?s:GO,l=t.imagePrompts.map(e=>({name:e.name,number:Math.max(0,Number.parseInt(e.number,10)||0)})),u=l.reduce((e,t)=>e+t.number,0),d={perHour:a,words:c},f=$O({imagePrompts:l,imageScale:d,sources:t.sources}).reduce((e,t)=>e+t,0),p=`about ${String(Math.max(1,Math.round(JO(c))))} minutes (${c.toLocaleString(`en-US`)} words ${o?`in the article`:`expected, set on Review`})`;if(l.length===0)return{text:`For ${p}: tick an image prompt to see the count.`,problem:!1};let m=ZO(d)>=240?` That is the most a run makes (240); the images repeat after that.`:``;return{text:f>u?`For ${p}: ${String(f)} images, ${String(f-u)} more than the prompts' ${String(u)}.${m}`:`For ${p}: the prompts' ${String(u)} images already cover it.`,problem:!1}}function qhe({document:e,onEdit:t}){let{form:n}=e;return(0,h.jsx)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,form:{...a,...r?{imageScenes:!0}:{}}})}})})}function Jhe(e){return e.upload?(0,h.jsx)(V6,{value:e.value,onPick:e.onPick,upload:e.upload}):(0,h.jsx)(Yhe,{...e})}function Yhe({value:e,onPick:t,onUploading:n}){let{api:r}=z(),i=_(),a=P({mutationFn:e=>lN(r,e),onSuccess:({font:e})=>{i.setQueryData(sN,t=>({fonts:[...(t?.fonts??[]).filter(t=>t.id!==e.id),e]})),i.invalidateQueries({queryKey:sN})}}),o=a.isPending,s=(0,m.useRef)(t);s.current=t;let c=(0,m.useRef)(n);return c.current=n,(0,m.useEffect)(()=>{c.current(o)},[o]),(0,m.useEffect)(()=>()=>c.current(!1),[]),(0,h.jsx)(V6,{value:e,onPick:t,upload:{pending:o,error:a.error?.message,pick:e=>a.mutate(e,{onSuccess:({font:e})=>s.current(e.id)})}})}function V6({value:e,onPick:t,upload:n}){let{api:r}=z(),i=(0,m.useId)(),a=(0,m.useId)(),o=N({queryKey:sN,queryFn:()=>cN(r),staleTime:6e4}),s=n.pending,c=o.data?.fonts??[],l=e!=="default"&&!c.some(t=>t.id===e);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:i,children:`Subtitle font`}),(0,h.jsx)(V,{id:`project.subtitles.font`,className:`-my-1`})]}),(0,h.jsxs)(TV,{id:i,"data-play-field":`subtitles.fontId`,value:e,disabled:s,onChange:e=>t(e.target.value),className:`text-small`,children:[c.some(e=>e.id==="default")?null:(0,h.jsx)(`option`,{value:`default`,children:`Default font · bundled`}),l?(0,h.jsxs)(`option`,{value:e,children:[e,` · saved font`]}):null,c.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.source]},e.id))]})]}),(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,children:[(0,h.jsx)(X4,{htmlFor:a,className:`mb-1`,children:`Upload font (.ttf or .otf)`}),(0,h.jsx)(`input`,{id:a,"data-play-field":`subtitles.fontUpload`,type:`file`,accept:`.ttf,.otf,font/ttf,font/otf`,disabled:s,className:`w-full text-small text-ink-2 file:mr-2 file:rounded-control file:border file:border-line-strong file:bg-sunken file:px-2 file:py-1 file:text-ink`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&n.pick(t)}})]})]}),s?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Uploading font…`}):null,n.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:n.error}):null,l&&o.data?(0,h.jsx)(`p`,{role:`alert`,children:`Saved font is unavailable. Choose another font or upload it again.`}):null,o.error?(0,h.jsxs)(`p`,{role:`alert`,className:`text-small text-danger`,children:[`The font list couldn't be loaded. `,o.error.message]}):null]})}function Xhe(e){return e===`9:16`?{width:1080,height:1920}:{width:1920,height:1080}}function Zhe(e,t){switch(e){case`top`:return{y:60,alignment:8,translateY:0};case`upper-middle`:return{y:t/4,alignment:5,translateY:-50};case`center`:return{y:t/2,alignment:5,translateY:-50};case`lower-middle`:return{y:t*3/4,alignment:5,translateY:-50};case`bottom`:return{y:t-60,alignment:2,translateY:-100}}}function Qhe({value:e,format:t,sample:n=`Every story begins with a word.`,backgroundUrl:r,showCaptions:i=!0,maxFrameHeight:a}){let{api:o}=z(),s=uN(o,e.fontId),c=`subtitle-preview-${(0,m.useId)().replace(/[^a-zA-Z0-9]/g,``)}`,[l,u]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(typeof FontFace>`u`||!document.fonts)return;let e=!0,t=new FontFace(c,`url(${JSON.stringify(s)})`);return u(!1),t.load().then(t=>{e&&document.fonts.add(t)}).catch(()=>{e&&u(!0)}),()=>{e=!1,document.fonts.delete(t)}},[c,s]);let d=Xhe(t),f=Zhe(e.position??`bottom`,d.height),p=Number.isFinite(e.fontSize)?Math.max(16,Math.min(120,e.fontSize)):48,g={position:`absolute`,left:`50%`,top:`${f.y/d.height*100}%`,width:`${(d.width-120)/d.width*100}%`,transform:`translate(-50%, ${f.translateY}%)`,fontFamily:`"${c}", sans-serif`,fontSize:`${p/d.width*100}cqw`,lineHeight:1.2,overflowWrap:`anywhere`,WebkitTextStroke:`${2.5/d.width*100}cqw #101010`,paintOrder:`stroke fill`,textShadow:`0 ${100/d.width}cqw ${100/d.width}cqw #000`};return(0,h.jsxs)(`figure`,{className:`min-w-0 self-start`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Style preview`}),(0,h.jsx)(`span`,{children:t})]}),(0,h.jsxs)(`div`,{role:`img`,"aria-label":`Subtitle style preview`,"data-format":t,"data-position":e.position??`bottom`,className:`sl-media__frame mx-auto w-full text-center text-white`,style:{aspectRatio:`${d.width} / ${d.height}`,maxWidth:t===`9:16`?a?`min(240px, calc((${a}) * 9 / 16))`:240:480,containerType:`inline-size`},children:[r?(0,h.jsx)(`img`,{src:r,alt:``,className:`absolute inset-0 h-full w-full object-cover`}):null,i?(0,h.jsx)(`span`,{role:`note`,"aria-label":`Caption sample`,style:g,children:n}):null]}),(0,h.jsxs)(`figcaption`,{className:`mt-2 text-label text-ink-3`,children:[d.width,` × `,d.height,` · Preview at reduced scale.`,l?` Font preview unavailable; showing a fallback.`:``]})]})}function H6({value:e,format:t=`16:9`,audioEnabled:n,videoEnabled:r,disabled:i=!1,onChange:a,onUploading:o,problem:s,session:c,fontUpload:l,showPreview:u=!0,illustratedPositions:d=!1,rawFontSize:f}){let p=(0,m.useId)(),g=(0,m.useId)(),_=(0,m.useId)(),v=(0,m.useId)(),[y,b]=(0,m.useState)(!1),x=s?.(`subtitles.fontId`),S=s?.(`subtitles.fontSize`),C=s?.(`subtitles.mode`)??s?.(`subtitles`);return(0,h.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":`Subtitles`,children:[(0,h.jsxs)(`fieldset`,{disabled:i||!n,className:`flex min-w-0 flex-col gap-3 disabled:opacity-60`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 flex-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:p,children:`Subtitles`}),(0,h.jsx)(V,{id:`project.subtitles.mode`,className:`-my-1`})]}),(0,h.jsxs)(`select`,{id:p,"data-play-field":`subtitles.mode`,value:n?e.mode:`off`,disabled:l?.pending??y,"aria-describedby":_,"aria-invalid":C!==void 0,onChange:t=>a({...e,mode:t.target.value}),className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:[(0,h.jsx)(`option`,{value:`off`,children:`Off`}),(0,h.jsx)(`option`,{value:`files`,children:`Subtitle files (.srt + .vtt)`}),(0,h.jsx)(`option`,{value:`burn-in`,disabled:!r,children:`Burn into video + files`})]})]}),(0,h.jsx)(`span`,{className:`pb-1 text-label text-ink-3`,children:`English · local · no paid API`})]}),e.mode!==`off`&&n?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Timed from your narration on this computer. First use downloads an approximately 95 MB speech model. Review the subtitles before publishing.`}),(0,h.jsxs)(`div`,{className:`grid items-start gap-5`,style:{gridTemplateColumns:`repeat(auto-fit, minmax(min(100%, 240px), 1fr))`},children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(Jhe,{...l?{upload:l}:{},value:e.fontId,onPick:t=>c?c.selectFont(t):a({...e,fontId:t}),onUploading:e=>{b(e),o?.(e)}}),(0,h.jsxs)(`div`,{className:d?`w-full`:`max-w-[180px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:g,children:`Subtitle font size`}),(0,h.jsx)(V,{id:`project.subtitles.size`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-5`,children:[d?(0,h.jsx)(`input`,{"aria-label":`Subtitle font size slider`,type:`range`,min:16,max:120,step:1,value:Math.max(16,Math.min(120,Number.isFinite(e.fontSize)?e.fontSize:48)),className:`min-w-0 flex-1 accent-accent`,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})}):null,(0,h.jsx)(CV,{className:d?`w-20`:void 0,id:g,"data-play-field":`subtitles.fontSize`,type:`number`,min:16,max:120,step:1,value:f?.value??e.fontSize,"aria-invalid":!kN(e)||S!==void 0,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})})]}),!kN(e)||S?(0,h.jsx)(`p`,{role:`alert`,className:`mt-1 text-label text-danger`,children:S??`Choose a whole font size from 16 to 120.`}):null]}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:d?void 0:v,id:`${v}-label`,children:`Subtitle position`}),(0,h.jsx)(V,{id:`project.subtitles.position`,className:`-my-1`})]}),d?(0,h.jsx)(Z4,{type:`single`,"aria-labelledby":`${v}-label`,value:e.position??`bottom`,onValueChange:t=>{let n=pM.find(e=>e===t);n&&a({...e,position:n})},className:`grid w-full grid-cols-5 gap-2 overflow-visible border-0`,children:pM.map((t,n)=>(0,h.jsxs)(Q4,{value:t,"aria-label":t,"data-play-field":(e.position??`bottom`)===t?`subtitles.position`:void 0,className:`flex min-w-0 flex-col items-center gap-2 rounded-control border border-line-strong bg-surface px-1 py-3 text-[10px] last:border-r data-[state=on]:border-focus data-[state=on]:text-accent-ink data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`relative block h-11 w-7 rounded-[2px] border border-current`,children:(0,h.jsx)(`span`,{className:`absolute left-1 right-1 h-[3px] bg-current`,style:{top:`${8+n*20}%`}})}),(0,h.jsxs)(`span`,{children:[t[0]?.toUpperCase(),t.slice(1)]})]},t))}):(0,h.jsx)(`select`,{id:v,"data-play-field":`subtitles.position`,value:e.position??`bottom`,onChange:t=>{let n=pM.find(e=>e===t.target.value);n&&a({...e,position:n})},className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:pM.map(e=>(0,h.jsxs)(`option`,{value:e,children:[e[0]?.toUpperCase(),e.slice(1)]},e))})]})]}),u?(0,h.jsx)(Qhe,{value:e,format:t,...c?{sample:c.previewText}:{}}):null]}),c?.fontUpload&&!c.fontUploading?(0,h.jsxs)(`p`,{role:`alert`,children:[`Reattach `,c.fontUpload.name,`, or select a font.`]}):null,x?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}):null,e.mode===`files`?(0,h.jsx)(`p`,{className:`text-label text-ink-3`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]}):null]}),c?.fontUpload&&(e.mode===`off`||!n)?(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:c.fontUploading?`status`:`alert`,className:`text-small text-ink-2`,children:c.fontUploading?`Uploading ${c.fontUpload.name}…`:`Unfinished font upload: ${c.fontUpload.name}`}),l?.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:l.error}):null,(0,h.jsx)(R,{"data-play-field":`subtitles.fontUpload`,disabled:i,onClick:()=>c.selectFont(e.fontId),children:`Keep current font`})]}):null,C?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:C}):null,(0,h.jsx)(`p`,{id:_,className:`text-small text-ink-2`,children:n?r?`Optional: download subtitles separately or keep them visible in the video.`:`Audio exports support separate subtitle files. Enable Video to burn captions into an MP4.`:`Turn Audio on to add subtitles.`})]})}function U6({value:e,onPick:t}){let n=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`w-full`,...Ob,children:[(0,h.jsxs)(`span`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(X4,{id:n,children:`Frame format`}),(0,h.jsx)(V,{id:`play.format`,className:`-my-1`})]}),(0,h.jsx)(Z4,{type:`single`,value:e,"aria-labelledby":n,className:`w-full max-w-[400px] gap-3 overflow-visible border-0`,onValueChange:e=>{(e===`16:9`||e===`9:16`)&&t(e)},children:[`16:9`,`9:16`].map(t=>(0,h.jsxs)(Q4,{value:t,"data-play-field":e===t?`format`:void 0,"aria-label":t,className:`flex h-28 min-w-0 flex-1 items-center justify-center gap-4 rounded-control border border-line-strong bg-surface p-3 last:border-r data-[state=on]:border-focus data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{className:`flex h-12 items-center justify-center`,"aria-hidden":`true`,children:(0,h.jsx)(`span`,{"data-format-shape":t,className:`block rounded-[2px] border-2 border-current`,style:{width:t===`16:9`?64:27,aspectRatio:t===`16:9`?`16 / 9`:`9 / 16`}})}),(0,h.jsxs)(`span`,{className:`text-left`,children:[(0,h.jsx)(`span`,{className:`block text-body font-semibold`,children:t}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:t===`16:9`?`Landscape`:`Portrait`})]})]},t))})]})}function $he({problem:e}){let t=rP(),{document:n}=t,{form:r}=n,i=e=>t.edit({...n,form:{...r,subtitles:{...e,fontSize:r.subtitles.fontSize}}});return(0,h.jsxs)(`div`,{"data-tour":`play-subtitles`,className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`See frame and caption changes in the preview as you go.`}),(0,h.jsx)(U6,{value:r.format,onPick:e=>t.edit({...n,form:{...r,format:e}})}),(0,h.jsx)(`div`,{className:`border-t border-line pt-4`,children:(0,h.jsx)(H6,{showPreview:!1,illustratedPositions:!0,fontUpload:t.fontUpload,session:{previewText:n.previewText,fontUploading:t.fontUploading,fontUpload:n.fontUpload,selectFont:t.selectFont,uploadSubtitleFont:t.uploadSubtitleFont},value:{...r.subtitles,fontSize:Number(r.subtitles.fontSize)},rawFontSize:{value:r.subtitles.fontSize,onChange:e=>t.edit({...n,form:{...r,subtitles:{...r.subtitles,fontSize:e}}})},format:r.format,audioEnabled:r.sources.audio!==`off`,videoEnabled:r.sources.video===`generate`&&r.sources.images!==`off`,onChange:i,problem:e})}),(0,h.jsx)(xV,{label:`Preview text`,tip:`play.preview-text`,className:`border-t border-line pt-4`,children:(0,h.jsx)(CV,{value:n.previewText,onChange:e=>t.edit({...n,previewText:e.target.value})})})]})}function ege(e){let t=rP(),n=t.document,r=H3(),i=U3(),{form:a,entries:o,problem:s,update:c}=e;return(0,h.jsx)(bhe,{...e,titled:!1,cast:r,language:i,rawCounts:{...n.form.chunking,onChange:(e,r)=>t.edit({...n,form:{...n.form,chunking:{...n.form.chunking,mode:e,...e===`words`?{words:r}:e===`characters`?{characters:r}:{}}}})},advanced:(0,h.jsxs)(h.Fragment,{children:[[`intro`,`outro`].map(e=>(0,h.jsx)(FV,{field:e,label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,value:a[e],placeholder:`Off`,options:o.filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),problem:s(e),onPick:t=>c({[e]:t})},e)),(0,h.jsx)(`div`,{className:`col-span-full flex flex-wrap gap-2`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:e.onSettings,children:`Settings`})}),(0,h.jsx)(`div`,{className:`col-span-full empty:hidden`,children:(0,h.jsx)(z6,{...e,section:`narration`,onSettings:e.onSettings})})]})})}function tge(e){let t=rP(),n=t.document;return(0,h.jsx)(xhe,{...e,titled:!1,more:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Whe,{document:n,problem:e.problem,onEdit:t.edit}),n.form.sources.article===`off`?null:(0,h.jsx)(qhe,{document:n,onEdit:t.edit})]}),rawNumbers:{values:n.form.imagePrompts,onChange:(e,r)=>t.edit({...n,form:{...n.form,imagePrompts:n.form.imagePrompts.map(t=>t.name===e?{...t,number:r}:t)}})}})}function nge(e){let t=rP(),n=t.document,r=U3();return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Ihe,{...e,titled:!1,extras:!1,language:r,rawTiming:{imageSeconds:n.form.imageSeconds,zoomPercent:n.form.zoomPercent,edgeSilenceSeconds:n.form.edgeSilenceSeconds,onChange:(e,r)=>t.edit({...n,form:{...n.form,[e]:r}})}}),n.form.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:`sl-fields border-b border-line py-4`,children:(0,h.jsx)(R6,{field:`silenceGapSeconds`,label:`Silence between segments (seconds)`,tip:`play.silence-gap`,placeholder:String(e.silenceGapSeconds),step:.1,problem:e.problem(`silenceGapSeconds`),value:n.form.silenceGapSeconds??``,onChange:e=>{let{silenceGapSeconds:r,...i}=n.form;t.edit({...n,form:e.trim()===``?i:{...i,silenceGapSeconds:e}})}})}),(0,h.jsx)($he,{problem:e.problemOf})]})}function rge(e){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z6,{...e,section:`outputs`,onSettings:e.onSettings}),(0,h.jsx)(Fhe,{...e}),(0,h.jsx)(`section`,{className:`border-b border-line py-4`,children:(0,h.jsx)(L6,{form:e.form,prompts:e.prompts,problem:e.problem,update:e.update,onPickFiles:e.onPickFiles,onRemoveFile:e.onRemoveFile,...e.onReattachFile===void 0?{}:{onReattachFile:e.onReattachFile}})}),e.form.sources.article===`off`?null:(0,h.jsx)(Lhe,{...e})]})}function W6(e,t){if(t===void 0||t.length===0||e.trim()===``)return[];let n=[];for(let[r,i]of t.entries()){let t=1/0;for(let n of[i.name,...i.aliases]){let r=ige(e,n);r!==void 0&&r<t&&(t=r)}Number.isFinite(t)&&n.push({member:i,at:t,order:r})}return n.sort((e,t)=>e.at-t.at||e.order-t.order).map(e=>e.member)}function ige(e,t){let n=t.trim().split(/\s+/u).filter(Boolean);if(n.length===0)return;let r=RegExp(`(?<![\\p{L}\\p{N}])${n.map(age).join(`\\s+`)}(?![\\p{L}\\p{N}])`,`iu`).exec(e);return r===null?void 0:r.index}function age(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function oge(e,t){let n=e.provided.reference?.file;if(e.sources.images===`generate`&&e.reference?.source===`provide`&&n!==void 0)return{image:{kind:`upload`,stagedFileId:n.id},drawnOn:`the establishing image`};let r=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),i=W6([e.title,...Object.values(e.values)].join(` `),r)[0]??r[0],a=i?.images[0];if(i!==void 0&&a!==void 0)return{image:{kind:`picture`,sha256:a},drawnOn:`${i.name}'s picture`}}function sge({selected:e,reviewed:t}){let n=e=>W3.find(t=>t.stage===e)?.label??e;return e?.length?(0,h.jsxs)(`div`,{className:`space-y-3 text-body`,children:[t?.length?t.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`font-medium`,children:[`Run `,e.runIndex+1,` · Before `,n(e.stage)]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.dependents.length?`Also holds: ${e.dependents.map(n).join(`, `)}.`:`No dependent steps.`})]},`${e.runIndex}-${e.checkpointId}`)):(0,h.jsxs)(`p`,{children:[`Selected: `,e.map(e=>`Before ${n(e)}`).join(`, `),`. Refresh review to confirm dependent steps.`]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Approval required on the project page. Starting this run does not approve these checkpoints.`})]}):(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No review checkpoints selected.`})}function cge({estimates:e}){let t=e.reduce((e,t)=>e+t.low,0),n=e.reduce((e,t)=>e+t.high,0),r=e.reduce((e,t)=>e+t.unknown,0),i=e[0]?.rows.map((t,n)=>({...t,low:e.some(e=>e.rows[n]?.low===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.low??0),0),high:e.some(e=>e.rows[n]?.high===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.high??0),0),apiLow:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiLow==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiLow??0),0),apiHigh:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiHigh==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiHigh??0),0)}))??[],a=e.some(e=>e.apiLow!==void 0),o=e.reduce((e,t)=>e+(t.apiLow??0),0),s=e.reduce((e,t)=>e+(t.apiHigh??0),0),c=e.reduce((e,t)=>e+(t.apiUnknown??0),0);return e.length===0?(0,h.jsx)(`div`,{}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-title-2 font-semibold`,children:[r?`Known subtotal: `:`Estimated total: `,G6(t,n)]}),r?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Plus `,r,` stage charge`,r===1?``:`s`,` with unavailable pricing.`]}):null,(0,h.jsxs)(`details`,{className:`rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Cost by stage · `,i.length,` `,i.length===1?`stage`:`stages`]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 pt-1 pb-3`,children:[a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o===0&&s===0?`CLI steps: $0 on your plan · no API price is listed for their models.`:`CLI steps: $0 on your plan · ~${G6(o,s)} via API${c?` (plus ${String(c)} with no API price)`:``}.`}):null,(0,h.jsx)(`ul`,{"aria-label":`Cost by stage`,className:`m-0 list-none divide-y divide-line p-0`,children:i.map(e=>(0,h.jsxs)(`li`,{className:`py-2`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between gap-4 text-small`,children:[(0,h.jsx)(`span`,{children:e.stage}),(0,h.jsx)(`span`,{className:`text-right tabular-nums`,children:e.onPlan===!0?e.apiLow===null||e.apiHigh===null?`$0 on your plan · API price unknown`:`$0 on your plan · ~${G6(e.apiLow,e.apiHigh)} via API`:e.low===null||e.high===null?`Unknown`:G6(e.low,e.high)})]}),(0,h.jsx)(`p`,{className:`m-0 mt-0.5 text-label text-ink-3`,children:e.detail})]},e.stage))}),[...new Set(e.flatMap(e=>e.assumptions))].map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e},e)),(0,h.jsxs)(`p`,{className:`m-0 text-label text-ink-3`,children:[`Catalogue verified `,e[0]?.catalogueDate??`date unavailable`,`. Batch rows show combined costs.`]})]})]})]})}function G6(e,t){let n=e=>e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`;return e===t?n(e):`${n(e)} – ${n(t)}`}function K6(e){let t=TA(SA(e)),n=new Map(TA(fA)),r=t.filter(([e,t])=>e!==`Cuts`&&n.get(e)!==t).map(([e,t])=>e===`Animate images`?`Animated images: ${t} (paid)`:e===`Chapter cards`?`Chapter cards`:e===`Transition`?t:`${e}: ${t}`);return r.length===0?`Plain cuts, no effects`:r.join(` · `)}function lge(e){return e===void 0?{ok:!1,text:`Provider status unavailable`}:e.readiness.kind===`cli`?tF(e.readiness)?{ok:!0,text:e.readiness.version===void 0?`CLI ready`:`CLI ready · ${e.readiness.version}`}:{ok:!1,text:e.readiness.issue??`CLI not found`}:e.readiness.kind===`local`?e.readiness.available?{ok:!0,text:`Built-in voice · ${e.readiness.engine??`ready`}`}:{ok:!1,text:e.readiness.issue??`No speech program found`}:e.readiness.hasKey?{ok:!0,text:`API key saved`}:{ok:!1,text:`API key missing`}}function uge(e,t){let n=e.sources.audio===`generate`,r=[`from_prompt`,`prompt_by_llm`].includes(e.sources.thumbnail);return[...(e.sources.article===`generate`||e.sources.thumbnail===`prompt_by_llm`||pj(e)||jN(e)||n&&[`intro`,`outro`].some(n=>t.some(t=>t.category===n&&t.name===e[n]&&t.mode===`llm`)))&&e.llm?[{field:`llm.provider`,family:`llm`,label:`Text generation`,provider:e.llm.provider,model:e.llm.model}]:[],...n&&e.audio?[{field:`audio.provider`,family:`tts`,label:`Narration`,provider:e.audio.provider,model:e.audio.model,voice:e.audio.voice}]:[],...(e.sources.images===`generate`||r||jN(e)||CA(e))&&e.images?[{field:`images.provider`,family:`image`,label:`Images`,provider:e.images.provider,model:e.images.model}]:[]]}function q6({name:e,children:t}){return(0,h.jsxs)(`section`,{"aria-label":`${e} summary`,className:`min-w-0 border-t border-line pt-5`,children:[(0,h.jsx)(`h3`,{className:`mb-4 font-semibold`,children:e}),t]})}function dge({form:e,entries:t,providers:n,voices:r,textModels:i,audioModels:a,imageModels:o,onReveal:s}){let c=uge(e,t);if(!c.length)return(0,h.jsx)(q6,{name:`Run readiness`,children:(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No generated providers required. Supplied content is ready for processing.`})});let l={llm:i,tts:a,image:o};return(0,h.jsxs)(q6,{name:`Run readiness`,children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`These checks are refreshed with Review and checked again when you start.`}),(0,h.jsx)(`ul`,{className:`divide-y divide-line`,"aria-label":`Run readiness checks`,children:c.map(e=>{let t=n?.find(t=>t.id===e.provider&&t.family===e.family),i=lge(t),a=l[e.family],o=a?.models.find(t=>t.id===e.model),c=a===void 0?{ok:!0,text:`Model checked at Start`}:o!==void 0||a.allowsCustom?{ok:!0,text:`Model available`}:{ok:!1,text:`Model unavailable`},u=e.voice===void 0?void 0:r===void 0?{ok:!1,text:`Voice list unavailable`}:r.some(t=>t.provider===e.provider&&t.voiceId===e.voice)?{ok:!0,text:`Voice saved`}:{ok:!1,text:`Voice missing`},d=[i,c,...u?[u]:[]],f=d.every(e=>e.ok);return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-3 py-3`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,h.jsx)(`span`,{className:f?`text-lime`:`text-danger`,children:f?`Ready`:d.filter(e=>!e.ok).map(e=>e.text).join(` · `)}),f?null:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>s(e.field),children:`Edit ↗`})]},`${e.family}:${e.provider}`)})})]})}function fge({fields:e,onReveal:t,children:n}){let{document:r,review:i}=rP(),{form:a}=r,{api:o}=z(),s=_(),c=s.getQueryData(eb(o).queryKey),l=s.getQueryData(rb(o).queryKey),u=s.getQueryData(tb(o).queryKey),d=s.getQueryData(sN),f=s.getQueryData(OV(a.llm.provider)),p=s.getQueryData(OV(a.audio.provider)),m=s.getQueryData(OV(a.images.provider)),g=a.sources.audio===`generate`,v=[`from_prompt`,`prompt_by_llm`].includes(a.sources.thumbnail),y=a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||pj(a)||jN(a)||g&&[`intro`,`outro`].some(e=>l?.entries.some(t=>t.category===e&&t.name===a[e]&&t.mode===`llm`)),b=e=>c?.providers.find(t=>t.id===e)?.displayName??e,x=(e,n,r)=>(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[90px_minmax(0,1fr)_auto] items-start gap-x-3 py-1 sm:grid-cols-[145px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(`dt`,{className:`break-words py-2 text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`min-w-0 whitespace-pre-wrap break-words py-2`,children:r||`Not selected`}),n?(0,h.jsx)(`dd`,{children:(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit ${e}`,onClick:()=>t(n),children:`Edit ↗`})}):null]},n??e),S=a.chunking.mode===`words`||a.chunking.mode===`characters`?a.chunking.mode:null;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(dge,{form:a,entries:l?.entries??[],providers:c?.providers,voices:u?.voices,textModels:f,audioModels:p,imageModels:m,onReveal:t}),(0,h.jsxs)(q6,{name:`Content`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Project`,`title`,a.title||`Untitled run`),x(`Article`,`sources.article`,PN[a.sources.article]),a.sources.article===`generate`?x(`Article prompt`,`articlePrompt`,a.articlePrompt):x(`Article text`,`provided.article`,`Your article`),a.sources.article===`generate`?x(`Research`,`sources.research`,PN[a.sources.research]):x(`Research`,null,`Off · Article is provided`),a.sources.research===`provide`&&a.sources.article===`generate`?x(`Research text`,`provided.research`,a.provided.research):null,y?(0,h.jsxs)(h.Fragment,{children:[x(`Text provider`,`llm.provider`,b(a.llm.provider)),x(`Text model`,`llm.model`,f?.models.find(e=>e.id===a.llm.model)?.name??a.llm.model),a.llm.thinking||f?.models.find(e=>e.id===a.llm.model)?.thinkingModes?.length?x(`Thinking`,`llm.thinking`,a.llm.thinking??`Model default`):null]}):null,e.map(({name:e})=>x(e,`values.${e}`,a.values[e]??``))]}),n]}),(0,h.jsx)(q6,{name:`Outputs`,children:(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Narration`,`sources.audio`,PN[a.sources.audio]),g?(0,h.jsxs)(h.Fragment,{children:[x(`Audio provider`,`audio.provider`,b(a.audio.provider)),x(`Audio model`,`audio.model`,p?.models.find(e=>e.id===a.audio.model)?.name??a.audio.model),x(`Voice`,`audio.voice`,u?.voices.find(e=>e.provider===a.audio.provider&&e.voiceId===a.audio.voice)?.name??a.audio.voice),x(`Chunking`,S?`chunking.${S}`:`chunking.mode`,S?`Every ${a.chunking[S]||`(not entered)`} ${S}`:a.chunking.mode===`whole`?`Whole text`:`Paragraph`),x(`Intro`,`intro`,a.intro||`Off`),x(`Narration Preparation`,`narrationPrompt`,a.narrationPrompt?`${a.narrationPrompt} · One LLM call per narration chunk and entry`:`Off`),x(`Outro`,`outro`,a.outro||`Off`)]}):null,a.sources.audio===`provide`?x(`Narration file`,`provided.audio`,a.provided.audio?.name):null,x(`Images`,`sources.images`,PN[a.sources.images]),a.sources.images===`generate`||v||jN(a)?(0,h.jsxs)(h.Fragment,{children:[x(`Image provider`,`images.provider`,b(a.images.provider)),x(`Image model`,`images.model`,m?.models.find(e=>e.id===a.images.model)?.name??a.images.model),a.images.thinking===void 0?null:x(`Image effort`,`images.thinking`,a.images.thinking)]}):null,a.sources.images===`generate`&&a.reference!==void 0&&a.reference.source!==`off`?x(`Establishing image`,a.reference.source===`prompt`?`reference.prompt`:`provided.reference`,`${a.reference.source===`prompt`?a.reference.prompt||`(no prompt picked)`:a.provided.reference?.name??`(no file attached)`}${a.reference.thumbnail?` · thumbnail too`:``}`):null,a.sources.images===`generate`?a.imagePrompts.length?a.imagePrompts.map((e,t)=>x(e.name,`imagePrompts.${t}.number`,`${e.name} · ${e.number||`(not entered)`} images`)):x(`Image prompts`,`imagePrompts`,`None selected`):null,a.sources.images===`provide`?x(`Image files`,`provided.images`,a.provided.images.length?(0,h.jsx)(`ol`,{className:`list-inside list-decimal`,children:a.provided.images.map(e=>(0,h.jsx)(`li`,{children:e.name},e.attachmentId))}):`No files selected`):null,x(`Thumbnail`,`sources.thumbnail`,PN[a.sources.thumbnail]),v?x(`Thumbnail prompt`,`thumbnailPrompt`,a.thumbnailPrompt):null,a.sources.thumbnail===`provide`?x(`Thumbnail file`,`provided.thumbnail`,a.provided.thumbnail?.name):null,x(`Video`,`sources.video`,PN[a.sources.video]),a.sources.video===`generate`?x(`Seconds per image`,`imageSeconds`,a.imageSeconds||`(not entered)`):null,a.sources.video===`generate`?x(`Zoom`,`zoomPercent`,a.zoomPercent?`${a.zoomPercent}%`:`(not entered)`):null,a.sources.video===`generate`?x(`Motion`,`motionStyle`,YA[a.motionStyle]):null,a.sources.video===`generate`?x(`Cuts`,`videoEdit.cuts`,gA[SA(a).cuts]):null,a.sources.video===`generate`?x(`Look`,`videoEdit`,K6(a)):null,a.sources.audio===`off`?null:x(`Silence at start and end`,`edgeSilenceSeconds`,a.edgeSilenceSeconds?`${a.edgeSilenceSeconds} s`:`(not entered)`),a.sources.audio===`off`?null:x(`YouTube description`,`youtubeDescription`,a.youtubeDescription===!0?`${a.descriptionPrompt||`Built-in`} prompt · One LLM call after subtitle timing`:`Off`),a.sources.audio===`off`?null:x(`Shorts`,`shorts.enabled`,jN(a)&&a.shorts!==void 0?[`${a.shorts.count} shorts of ${a.shorts.minSeconds}-${a.shorts.maxSeconds} s`,`${a.shorts.prompt||`Built-in`} prompt`,`${a.shorts.imagePrompt||`Built-in`} image style`,...pge(a.shorts,a.provided.shortsMusic?.name),`Vertical images and renders after subtitle timing`].join(` · `):`Off`),x(`Document`,`sources.document`,RS(a.sources,`document`)===`generate`?`PDF · ${XS(a.document)} theme`:PN.off)]})}),(0,h.jsxs)(q6,{name:`Checkpoints`,children:[(0,h.jsx)(sge,{selected:a.checkpoints,reviewed:i.valid?i.receipt?.checkpointSet:void 0}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit checkpoints`,onClick:()=>t(`checkpoints`),children:`Edit checkpoints ↗`})]}),(0,h.jsxs)(q6,{name:`Style`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Frame`,`format`,a.format),a.sources.audio===`off`?x(`Subtitles`,null,`Off · Audio is Off`):x(`Subtitles`,`subtitles.mode`,a.subtitles.mode),a.sources.audio!==`off`&&a.subtitles.mode!==`off`?(0,h.jsxs)(h.Fragment,{children:[x(`Subtitle font`,`subtitles.fontId`,d?.fonts.find(e=>e.id===a.subtitles.fontId)?.name??a.subtitles.fontId),x(`Subtitle size`,`subtitles.fontSize`,`${a.subtitles.fontSize||`(not entered)`} px`),x(`Subtitle position`,`subtitles.position`,a.subtitles.position)]}):null]}),a.sources.audio!==`off`&&a.subtitles.mode===`files`?(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]})]})}function pge(e,t){let n=qk(e),r=n.speed,i=n.musicVolume;return[...n.titleOnScreen===!0?[`Title on screen`]:[],...r!==void 0&&r!==1?[`${r.toFixed(2)}× speed`]:[],...t===void 0?i!==void 0&&i!==15?[`Music at ${String(i)}% once added in Edit project`]:[]:[`Music: ${t} at ${String(i??15)}%`],...n.fullVideoLink===void 0?[]:[`Links ${n.fullVideoLink}`]]}function mge({fields:e,errors:t,onReveal:n,problem:r}){let i=rP(),{document:a,review:o}=i,s=a.form;(0,m.useEffect)(()=>{i.reviewDraft()},[i.reviewDraft]);let c=o.valid?o.receipt?.runs??[]:[];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Everything this run will do, the checkpoints it stops at and the reviews it runs. The estimate and the Play key stay in the right rail.`}),t.length?(0,h.jsx)(`ul`,{"aria-label":`Setup errors`,className:`text-small text-danger`,children:t.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>n(e.field),children:e.message})},`${e.field}-${e.message}`))}):null,(0,h.jsx)(Kme,{problem:r}),(0,h.jsx)(VV,{problem:r}),(0,h.jsx)(fge,{fields:e,onReveal:n,children:(0,h.jsxs)(`details`,{className:`mt-5 border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:s.sources.article===`provide`?`Read the supplied article and resolved prompts`:`Read the resolved prompt`}),c.length?c.map((e,t)=>(0,h.jsxs)(`div`,{className:`mt-4`,children:[(0,h.jsx)(`h4`,{className:`font-medium`,children:e.draft.title}),e.draft.sources.article===`provide`?(0,h.jsx)(`p`,{className:`mt-3 whitespace-pre-wrap break-words text-body`,children:e.draft.provided.article}):null,Object.entries(e.rendered).map(([e,t])=>(0,h.jsxs)(`div`,{className:`mt-3`,children:[(0,h.jsx)(`h5`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-body`,children:t})]},e))]},a.variants[t-1]?.id??i.activeId)):(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Refresh review to read the exact resolved inputs.`})]})})]})}function hge(e,t,n){return[...z3(e).map(e=>(t[e]??``).trim()===``?`${e} is left empty in the template.`:`${e} is left empty in the template (this video's ${e}, "${t[e]}", is not saved).`),...n>0?[`The ${n===1?`other video`:`${String(n)} other videos`} queued here ${n===1?`is`:`are`} not saved.`]:[]]}function gge({open:e,onClose:t}){let{api:n}=z(),r=_(),i=rP(),a=Oy(),o=N(Hq(n)),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),p=(0,m.useRef)(null),{document:g}=i,v=hge(g.form.title,g.form.values,g.variants.length),y=()=>{u(null),t()},b=async()=>{let e=s.trim();if(!(e===``||d)){f(!0),u(null);try{if(!await i.flush()){u(`Your draft wasn't saved, so the template wasn't either. Press Retry beside Drafts, then Save template again.`);return}p.current?.name!==e&&(p.current={name:e,id:crypto.randomUUID()});let s=o.data?.find(e=>e.id===g.templateSource?.id),l=g.channelId??(s?o0(s):void 0),d=Hme(g),f=await Wq(n,{id:p.current.id,name:e,document:l===void 0?d:{...d,channelId:l}});if(!f.ok){p.current=null,u(`The template wasn't saved. ${f.message}`);return}p.current=null,c(``),a(`Template "${e}" saved.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}catch(e){u(`The template wasn't saved. ${e instanceof Error?e.message:`Press Save template again.`}`)}finally{f(!1)}}};return(0,h.jsx)(Ay,{open:e,onOpenChange:e=>{e||y()},title:`Save as template`,description:`Keeps this setup's prompts, voice, images, style, outputs and reviews to start the next video from.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`secondary`,onClick:y,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,disabled:s.trim()===``||d,disabledReason:d?`Saving the template`:`Name the template first`,onClick:()=>void b(),children:`Save template`})]}),children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,value:s,maxLength:120,placeholder:g.form.title.replace(/\{\{[^}]*\}\}/g,``).trim()||`My setup`,onChange:e=>c(e.target.value)})}),v.length?(0,h.jsx)(`ul`,{"aria-label":`Left out of the template`,className:`m-0 flex list-none flex-col gap-1 p-0 text-small text-ink-2`,children:v.map(e=>(0,h.jsx)(`li`,{children:e},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Every keyword keeps its value: the title names none.`}),l?(0,h.jsx)(SI,{tone:`danger`,title:l}):null]})})}var _ge=new Set([`a`,`an`,`the`,`of`,`and`,`or`,`in`,`on`,`to`,`for`,`with`,`vs`,`s`]);function J6(e){return e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase().replace(/&/g,` and `).replace(/[^\p{L}\p{N}]+/gu,` `).trim()}function Y6(e){let t=J6(e).split(` `).filter(e=>e!==``&&!_ge.has(e)).map(e=>e.length>3&&e.endsWith(`s`)&&!e.endsWith(`ss`)?e.slice(0,-1):e);return new Set(t)}function vge(e,t){let n=0;for(let r of e)t.has(r)&&(n+=1);return n}function yge(e,t){let n=J6(e);if(n===J6(t))return n!==``;let r=Y6(e),i=Y6(t);if(r.size===0||i.size===0)return!1;let a=vge(r,i);if(a/(r.size+i.size-a)>=.6)return!0;let o=Math.min(r.size,i.size),s=Math.max(r.size,i.size);return a===o&&o/s>=.5}function bge(e,t,n){let r=e.map(e=>e.trim()).filter(e=>e!==``);if(r.length===0)return;let i=e=>r.some(t=>yge(t,e)),a=t.find(i);if(a!==void 0)return{title:a,where:`project`};let o=n.find(i);return o===void 0?void 0:{title:o,where:`video`}}function xge({topics:e}){let{api:t}=z(),n=rP(),{document:r}=n,i=V3(),a=N(Yy(t)),o=N(V2(t,i)),{form:s}=r,c=mq(s.title,s.values),l=bge(e.length===0?[s.title]:[c,...e.map(e=>s.values[e]??``)],(a.data?.projects??[]).filter(e=>e.channelId===i).map(e=>e.title),(o.data??[]).map(e=>e.title));return l===void 0||n.review.created!==null?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.where===`project`?`This channel already has a video on this: "${l.title}" (in Projects). Start anyway if you want another take.`:`This channel already uploaded "${l.title}" (Channel → Existing videos). Start anyway if you want another take.`})}function Sge({rows:e,open:t,onChange:n}){return(0,h.jsx)(`ul`,{"aria-label":`Setup`,className:`m-0 flex list-none flex-col border-t border-line p-0`,children:e.map(e=>{let r=t.has(e.id)&&e.editor!==void 0,i=`play-row-${e.id}`;return(0,h.jsxs)(`li`,{"data-setup-row":e.id,className:`border-b border-line`,children:[(0,h.jsx)(H,{title:e.label,size:`small`,className:`items-center py-3.5`,status:e.problem?(0,h.jsx)(_S,{tone:`failed`,children:`Needs setup`}):void 0,meta:(0,h.jsx)(`span`,{"data-row-summary":!0,className:e.problem&&!r?`block break-words text-danger`:`block truncate text-ink-2`,title:e.problem&&!r?void 0:e.summary,children:r?e.summary:e.problem??e.summary}),children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":e.editor===void 0?void 0:r,"aria-controls":e.editor===void 0?void 0:i,"aria-label":`${r?`Done with`:`Change`} ${e.label.toLowerCase()}`,onClick:()=>n(e.id,!r),children:r?`Done`:`Change`})}),r?(0,h.jsx)(`section`,{id:i,"aria-label":e.label,className:`min-w-0 pb-6`,children:e.editor}):null]},e.id)})})}var X6=[{id:`title`,label:`Title and keywords`,section:`content`},{id:`article`,label:`Article`,section:`content`},{id:`narration`,label:`Narration`,section:`outputs`},{id:`images`,label:`Images`,section:`outputs`},{id:`video`,label:`Video and style`,section:`style`},{id:`outputs`,label:`Outputs`,section:`outputs`},{id:`reviews`,label:`Reviews`,section:`review`},{id:`channel`,label:`Channel`,section:`content`}],Cge=[[`title`,[`title`,`values`]],[`article`,[`sources.article`,`sources.research`,`articlePrompt`,`provided.article`,`provided.research`,`llm`]],[`narration`,[`sources.audio`,`audio`,`voices`,`provided.audio`,`narrationPrompt`,`intro`,`outro`,`chunking`]],[`images`,[`sources.images`,`images`,`imagePrompts`,`provided.images`,`reference`,`provided.reference`]],[`video`,[`sources.video`,`imageSeconds`,`zoomPercent`,`motionStyle`,`edgeSilenceSeconds`,`silenceGapSeconds`,`sentencePauseSeconds`,`paragraphPauseSeconds`,`loudness`,`videoEdit`,`format`,`subtitles`,`fontUpload`]],[`outputs`,[`sources.thumbnail`,`thumbnailPrompt`,`provided.thumbnail`,`thumbnailCount`,`youtubeDescription`,`descriptionPrompt`,`shorts`,`sources.document`,`document`]],[`reviews`,[`checkpoints`,`reviews`]],[`channel`,[`channelId`,`useBrandKit`,`language`]]],Z6=(e,t)=>e.some(e=>t===e||t.startsWith(`${e}.`));function Q6(e,t=`article`){return Z6([`llm`],e)?t:Cge.find(([,t])=>Z6(t,e))?.[0]}function wge(e){switch(e){case`content`:return[`title`,`article`,`channel`];case`outputs`:return[`narration`,`images`,`video`,`outputs`];case`style`:return[`video`];case`review`:return[`reviews`]}}function $6(e,t,n,r=`article`){return t.find(t=>Q6(t.field,r)===e?e===`title`?t.field===`title`?n.length>0:!n.some(e=>t.field===`values.${e}`):!0:!1)}function Tge(e,t,n){let r=e=>e===``?`no provider`:n.providers.find(t=>t.id===e)?.displayName??e,i=e=>e.filter(e=>typeof e==`string`&&e!==``).join(` · `);switch(e){case`title`:return i([n.topics.length?t.title:!1,n.keywords===0?`No keywords`:`${String(n.keywords)} keyword${n.keywords===1?``:`s`}`]);case`article`:return t.sources.article===`off`?`Off: no article`:t.sources.article===`provide`?`Your article`:i([t.articlePrompt||`No prompt picked`,t.llm.provider?`${r(t.llm.provider)} · ${t.llm.model||`no model`}`:!1,t.sources.research===`off`?`research off`:`research: ${PN[t.sources.research].toLowerCase()}`]);case`narration`:{if(t.sources.audio===`off`)return`Off, a silent video`;if(t.sources.audio===`provide`)return t.provided.audio?.name??`Your narration file`;let e=n.voices.find(e=>e.provider===t.audio.provider&&e.voiceId===t.audio.voice);return i([r(t.audio.provider),t.voices===void 0?e?.name??(t.audio.voice||`no voice`):`${DA[t.voices.format]}, ${String(t.voices.speakers.length)} speakers`,t.narrationPrompt?`prepared with ${t.narrationPrompt}`:!1,t.intro?`intro ${t.intro}`:!1,t.outro?`outro ${t.outro}`:!1])}case`images`:{if(t.sources.images===`off`)return`Off`;if(t.sources.images===`provide`)return`${String(t.provided.images.length)} of your images`;let e=t.imagePrompts.map(e=>`${e.name} × ${e.number||`?`}`);return i([e.length?e.join(`, `):`No image prompts picked`,r(t.images.provider),t.images.model,t.reference!==void 0&&t.reference.source!==`off`&&`establishing image`])}case`video`:return i([t.format,t.sources.video===`off`?`no video`:gA[SA(t).cuts].toLowerCase(),t.sources.video!==`off`&&n.look,t.sources.audio!==`off`&&t.subtitles.mode!==`off`?`captions ${n.fontName??t.subtitles.fontId} ${t.subtitles.fontSize} ${t.subtitles.position}`:`no captions`]);case`outputs`:return i([t.sources.thumbnail===`off`?!1:t.sources.thumbnail===`provide`?`your thumbnail`:t.thumbnailCount===3?`3 thumbnails`:`1 thumbnail`,jN(t)&&t.shorts?`${t.shorts.count} shorts`:!1,t.youtubeDescription===!0&&t.sources.audio!==`off`&&`YouTube description`,t.sources.document===`generate`&&`PDF (${XS(t.document)})`])||`Only the video`;case`reviews`:return i([n.checkpoints===0?`No checkpoints`:`${String(n.checkpoints)} checkpoint${n.checkpoints===1?``:`s`}`,n.reviews===0?`no automatic reviews`:`${String(n.reviews)} automatic review${n.reviews===1?``:`s`}`]);case`channel`:return i([n.channel??`Default channel`,n.brandKit?`brand kit on`:`brand kit off`,t.language===void 0?void 0:BO(t.language).name])}}function Ege({review:e,blocker:t,errors:n,pendingUpload:r}){if(e.starting)return;if(e.uncertain)return{text:`Slopify didn't confirm the last start. Press Check Start result to find out before starting again.`};if(t)return{text:t.hint,field:t.field};let i=n[0];if(i)return{text:i.message,field:i.field};if(r)return{text:`Wait for uploads to finish before Start`,field:r};if(e.error)return{text:e.error};if(e.pending||!e.valid)return{text:`Checking your setup and the estimate…`}}function Dge({errors:e,blocker:t,saveProblem:n,onReveal:r,onWholeSetup:i,onSaveTemplate:a,preview:o}){let s=rP(),{document:c,review:l}=s,u=YN(c,s.view),d=l.starting||l.uncertain;(0,m.useEffect)(()=>{s.reviewDraft()},[s.reviewDraft]);let f=!l.valid&&!l.pending&&!l.starting&&!l.uncertain&&l.error===null&&e.length===0&&t===void 0&&!u&&s.activeId!==null;(0,m.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>void s.reviewDraft(),800);return()=>clearTimeout(e)},[f,c,s.reviewDraft]);let p=l.valid&&l.receipt?l.receipt.runs.length:GN(c),g=Ege({review:l,blocker:t,errors:e,pendingUpload:u}),_=l.starting||!l.uncertain&&(!l.valid||l.pending||e.length>0||!!u);return(0,h.jsxs)(h.Fragment,{children:[o,(0,h.jsxs)(`section`,{"aria-label":`Start`,className:`flex min-w-0 flex-col gap-4 border-t border-line pt-5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:p===1?`1 video`:`${String(p)} videos`}),p>1?(0,h.jsx)(kb,{label:`Queue`,tip:`play.batch-queue`,checked:JN(c),disabled:d,onChange:e=>s.edit({...c,queue:e})}):(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`One run`})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Estimated cost`,info:`play.estimate`,size:`small`,className:`pb-0`}),l.valid&&l.receipt?(0,h.jsx)(cge,{estimates:l.receipt.estimates}):(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.pending?`Calculating the estimate…`:`The estimate appears once the setup is complete.`}),(0,h.jsx)(xV,{label:`Expected article words per video`,tip:`play.expected-words`,className:`mt-2`,children:(0,h.jsx)(CV,{"data-play-field":`expectedWords`,type:`number`,min:1,max:1e5,value:c.expectedWords,disabled:d,onChange:e=>s.edit({...c,expectedWords:e.target.value})})})]}),n?(0,h.jsx)(SI,{tone:`danger`,title:n}):null,(0,h.jsxs)(Ty,{"data-tour":`play-start`,disabled:_,"aria-describedby":g?`play-start-reason`:void 0,onClick:()=>{s.startRun()},children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),qN(l,c)]}),(0,h.jsx)(`div`,{id:`play-start-reason`,className:`min-h-5 text-center text-small`,children:g===void 0?(0,h.jsx)(`span`,{className:`text-ink-3`,children:p===1?`Nothing starts until you press it.`:JN(c)?`They run one after another. Nothing starts until you press it.`:`They all run at once. Nothing starts until you press it.`}):g.field===void 0?(0,h.jsx)(`span`,{role:l.error?`alert`:`status`,className:l.error?`text-danger`:`text-ink-2`,children:g.text}):(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center justify-center gap-x-1`,children:[(0,h.jsx)(`span`,{id:`play-start-field`,className:`text-waiting`,children:g.text}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-describedby":`play-start-field`,onClick:()=>r(g.field??``),children:`Go to the field`})]})}),(0,h.jsxs)(Ey,{className:`justify-center`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:l.pending||d||!!u,onClick:()=>{s.reviewDraft()},children:`Refresh review`}),(0,h.jsx)(V,{id:`play.refresh-review`})]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-keyshortcuts":Mx(lP.reviewSetup),onClick:i,children:`Review the whole setup`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Save as template`})]})]})]})}function Oge(e,t,n){let r=e?.prompts??[],i=e?.entries??[];return{prompts:[...r,...t.filter(e=>!r.some(t=>t.kind===e.kind&&t.name.toLowerCase()===e.name.toLowerCase()))],entries:[...i,...n.filter(e=>!i.some(t=>t.category===e.category&&t.name.toLowerCase()===e.name.toLowerCase()))]}}function kge({topics:e,onError:t}){let{api:n}=z(),r=_(),i=rP(),a=N(Hq(n)),o=N(Zb(n)),[s,c]=(0,m.useState)(!1),l=i.review.starting||i.review.uncertain||i.review.created!==null,u=i.document.templateSource,d=a.data?.find(e=>e.id===u?.id),f=e=>o.data?.find(t=>t.id===e)?.name,p=async o=>{if(t(null),o===``){await i.newDraft();return}let s=a.data?.find(e=>e.id===o);if(s){c(!0);try{if(!await i.flush()){t(`Your draft wasn't saved, so the template wasn't applied. Press Retry beside Drafts, then pick the template again.`);return}let a=Object.fromEntries(e.map(e=>[e,i.document.form.values[e]??``]).filter(([,e])=>e.trim()!==``)),o=await Xq(n,s,crypto.randomUUID());if(!o.ok){t(`The template "${s.name}" wasn't applied. ${o.message}`);return}if(await r.invalidateQueries({queryKey:[`play-drafts`]}),!await i.open(o.value.draft.id)){t(`The draft made from "${s.name}" didn't open. Open it from Drafts.`);return}let c=o.value.draft.document,l=Object.fromEntries(Object.entries(a).filter(([e])=>(c.form.values[e]??``)===``));Object.keys(l).length>0&&i.edit({...c,form:{...c.form,values:{...c.form.values,...l}}})}catch(e){t(e instanceof Error?`The template "${s.name}" wasn't applied. ${e.message}`:`The template "${s.name}" wasn't applied. Pick it again.`)}finally{c(!1)}}},g=a.error?`Templates didn't load. ${a.error.message}`:d?[f(o0(d)),`version ${String(d.version)}`].filter(Boolean).join(` · `):a.data?.length===0?`No templates yet. Set this video up, then Save as template.`:void 0;return(0,h.jsx)(xV,{label:`Template`,tip:`play.template`,help:g,children:(0,h.jsxs)(TV,{"data-play-field":`template`,value:d?.id??``,disabled:s||l,onChange:e=>void p(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:u&&!d?`Template no longer saved`:`No template`}),(a.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})}function Age({topics:e,problem:t}){let n=rP(),{document:r}=n,{form:i}=r,a=e=>{n.edit({...r,form:e}),n.invalidateReview(!0)};if(e.length===0)return(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:t(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,className:`!h-11 text-[17px]`,value:i.title,maxLength:200,placeholder:`What's the video about?`,"aria-invalid":t(`title`)!==void 0,onChange:e=>a({...i,title:e.target.value})})});let o=mq(i.title,i.values);return(0,h.jsx)(`div`,{className:`grid min-w-0 gap-4`,children:e.map((n,r)=>(0,h.jsx)(xV,{label:n,tip:`play.topic`,help:r===e.length-1?(0,h.jsxs)(h.Fragment,{children:[`Title: `,(0,h.jsx)(`b`,{className:`font-semibold text-ink`,children:o})]}):void 0,error:t(`values.${n}`)??(r===e.length-1?t(`title`):void 0),children:(0,h.jsx)(CV,{"data-play-field":`values.${n}`,className:`!h-11 text-[17px]`,value:i.values[n]??``,maxLength:200,spellCheck:!1,"aria-invalid":t(`values.${n}`)!==void 0,onChange:e=>a({...i,values:{...i.values,[n]:e.target.value}})})},n))})}function jge({topics:e,keywordNames:t,origins:n,problem:r,adding:i,onAdding:a,open:o,onOpen:s}){let c=rP(),{document:l}=c,{form:u}=l,[d,f]=(0,m.useState)(``),p=(0,m.useId)(),g=(0,m.useRef)(null),_=c.review.starting||c.review.uncertain,v=l.variants,y=e=>{c.edit({...l,variants:e})},b=e[0],x=e=>b===void 0?e.title:e.values[b]||e.title,S=()=>{let e=d.trim();e===``||v.length>=49||(y([...v,{id:crypto.randomUUID(),title:b===void 0?e:u.title,values:b===void 0?{...u.values}:{...u.values,[b]:e}}]),f(``),g.current?.focus())},C=v.findIndex(e=>e.id===o),w=C===-1?void 0:v[C];return(0,h.jsxs)(`section`,{"aria-label":`More videos from the same setup`,className:`min-w-0`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:`More videos from the same setup`}),(0,h.jsx)(V,{id:`play.more-videos`,className:`-my-1`})]}),(0,h.jsxs)(Ey,{className:`flex-wrap`,children:[v.map((e,n)=>{let i=x(e)||`Video ${String(n+2)}`,a=[`items.${String(n+1)}.title`,...t.map(e=>`items.${String(n+1)}.values.${e}`)].some(e=>r(e)!==void 0);return(0,h.jsx)(yS,{...a?{className:`border-danger`}:{},..._?{}:{onRemove:()=>y(v.filter(t=>t.id!==e.id)),removeLabel:`Remove ${i}`},children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,"data-play-field":`items.${e.id}`,className:`-my-1 -ml-1.5 h-6 px-1.5 text-ink`,"aria-label":`Change the keywords of ${i}`,onClick:()=>s(e.id),children:[i,(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})]})},e.id)}),i?(0,h.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,h.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:b===void 0?`Title of another video`:`${b} of another video`}),(0,h.jsx)(CV,{ref:g,id:p,autoFocus:!0,className:`!h-8 w-48`,value:d,maxLength:200,placeholder:b===void 0?`Another title`:`Another ${b}`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(!1)}}),(0,h.jsx)(R,{type:`submit`,size:`small`,disabled:d.trim()===``,children:`Add`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>a(!1),children:`Done`})]}):(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:_||v.length>=49,disabledReason:_?`Wait for the start to finish`:`One Start queues at most 50 videos`,onClick:()=>a(!0),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add topic`]})]}),(0,h.jsx)(YP,{open:w!==void 0,title:w?`Video ${String(C+2)}: ${x(w)||`untitled`}`:``,width:`narrow`,onClose:()=>s(null),footer:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>s(null),children:`Done`}),children:w?(0,h.jsxs)(`fieldset`,{disabled:_,className:`flex min-w-0 flex-col gap-5 border-0 p-0`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Everything else comes from the setup of the first video.`}),(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:r(`items.${String(C+1)}.title`),children:(0,h.jsx)(CV,{"data-play-field":`items.${w.id}.title`,value:w.title,maxLength:200,onChange:e=>y(v.map(t=>t.id===w.id?{...t,title:e.target.value}:t))})}),(0,h.jsx)(_0,{fieldPrefix:`items.${w.id}.values`,keywords:t.map(t=>({name:t,value:w.values[t]??``,feeds:n.get(t)??[],topic:e.includes(t)})),problem:e=>r(e.replace(`items.${w.id}.`,`items.${String(C+1)}.`)),onChange:(e,t)=>y(v.map(n=>n.id===w.id?{...n,values:{...n.values,[e]:t}}:n))})]}):null})]})}function Mge(){let e=Zi();return(0,h.jsx)(Nge,{onCreated:t=>{e({to:`/projects/$projectId`,params:{projectId:t}})}})}function Nge({onCreated:e}){let{api:t}=z(),n=lI(),r=N(eb(t)),i=N(nb(t)),a=N(rb(t)),o=N(tb(t)),s=N(ob(t)),c=N(Zb(t)),l=N(Hq(t)),u=N({queryKey:sN,queryFn:()=>cN(t),staleTime:6e4}),[d,f]=cP(),p=H3(),g=rP(),{document:_}=g,v=Oge(_.librarySnapshot,i.data?.prompts??[],a.data?.entries??[]),y=_.variants.map(({id:e,...t})=>({...t,key:e})),b=g.fontUploading||_.fontUpload!==null,x=g.review.fields,[S,C]=(0,m.useState)(new Set),[w,T]=(0,m.useState)(new Set),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,ee]=(0,m.useState)(!1),[te,ne]=(0,m.useState)(null),j=(0,m.useRef)(null),re=(0,m.useRef)(null),M=(0,m.useRef)(null),ie=Zi(),ae=(0,m.useRef)(g.activeId);(0,m.useLayoutEffect)(()=>{ae.current!==g.activeId&&(ae.current=g.activeId,C(new Set),k(null))},[g.activeId]);let oe=e=>{f(t=>{let n={...t,...e};return{...n,subtitles:ON(n.subtitles,n.sources)}}),g.invalidateReview(!0)},se=s.data?.silenceGapSeconds??3,ce=_.form.silenceGapSeconds?.trim()??``,le={form:d,prompts:v.prompts,entries:v.entries,silenceGapSeconds:ce===``?se:Number(ce)},{fields:ue,result:de,blocker:fe}=Dde(le),pe=h0(le),me=z3(d.title).filter(e=>ue.some(t=>t.name===e)),he=b?{field:`subtitles.fontUpload`,hint:`Wait for the subtitle font upload to finish to play`}:fe;(0,m.useEffect)(()=>{if(!g.review.created)return;let t=g.takeCreated()?.projectIds[0];t&&(n({type:`project-created`,id:t}),e(t))},[g.review.created,g.takeCreated,n,e]);let ge=de.ok?x:[...de.fields,...x],_e=(...e)=>!ge.some(t=>e.some(e=>t.field===e||t.field.startsWith(`${e}.`))),ve=(e,t)=>v.prompts.some(n=>n.kind===e&&n.name===t),ye=e=>e?.file!==void 0&&e.error===void 0;cI({playArticleReady:_e(`sources.article`,`articlePrompt`,`provided.article`)&&(d.sources.article===`provide`||ve(`article`,d.articlePrompt)),playAudioReady:d.sources.audio===`off`||_e(`sources.audio`,`audio`,`provided.audio`)&&(d.sources.audio!==`provide`||ye(d.provided.audio)),playImagesReady:d.sources.images===`off`||_e(`sources.images`,`images`,`imagePrompts`,`provided.images`)&&(d.sources.images===`provide`?d.provided.images.every(ye):d.imagePrompts.every(e=>ve(`image`,e.name))),playVideoReady:_e(`sources.video`),playSubtitlesReady:_e(`subtitles`)&&!b,playOptionsReady:_e(`title`,`format`,`llm`,`intro`,`outro`),playHasKeywords:ue.length>0,playKeywordsReady:_e(`values`),playReady:he===void 0&&!g.review.starting});let be=IN(d,v.entries)[0]?.section??`article`,xe=e=>Gme(e,d)??Vhe(e,d,y,v.entries),Se=e=>{let t=xe(e).field;return ge.find(n=>xe(n.field).field===t&&(x.includes(n)||S.has(e)||S.has(t)))?.message},Ce=e=>{let t=xe(e);C(n=>new Set([...n,e,t.field])),g.navigate(t.field.startsWith(`items.`)?`content`:t.section,t.field)},we=[r,i,a,o,s].every(e=>e.isSuccess||e.isError),Te=(0,m.useRef)(null),Ee=g.generation();(0,m.useEffect)(()=>{if(!we)return;let e=Te.current;Te.current={generation:Ee,id:g.activeId},(e===null||e.generation!==Ee||e.id!==g.activeId&&e.id!==null)&&T(new Set(X6.map(e=>e.id).filter(e=>e!==`reviews`&&$6(e,ge,me,be)!==void 0)))},[we,g.activeId,Ee]);let De=(0,m.useRef)(null);(0,m.useLayoutEffect)(()=>{let e=g.reveal;if(e||(De.current=null),!e||e.sequence===De.current||!j.current)return;let t=e.field,n=t?/^items\.([^.]+)(\.|$)/.exec(t)?.[1]:void 0;if(e.section===`review`){if(De.current=e.sequence,t&&B6(j.current,t))return;M.current?.focus();return}if(n!==void 0&&_.variants.some(e=>e.id===n)){if(O!==n){k(n);return}}else if(!(t&&me.some(e=>t===`values.${e}`))){let n=t?Q6(t,be):void 0,r=(n===void 0?wge(e.section):[n]).filter(e=>!w.has(e));if((t!==`title`||me.length!==0)&&r.length>0){T(e=>new Set([...e,...r]));return}}De.current=e.sequence,!(t&&B6(j.current,t))&&re.current?.focus()},[g.reveal,w,O]);let Oe=async e=>{await g.flush()&&(e===`/prompts`?await ie({to:`/prompts/new`,search:{kind:`article`}}):await ie({to:e}))},ke=()=>{g.navigate(`review`)},Ae=(e,t)=>{g.invalidateReview(!0),g.attach(e,t)},je=(e,t)=>{f(n=>({...n,provided:e===`images`?{...n.provided,images:n.provided.images.filter(e=>e.key!==t)}:{...n.provided,[e]:void 0}}))},Me=[r,i,a,o,s].find(e=>e.error!==null)?.error?.message,Ne=g.error?`Your draft wasn't saved. ${g.error}`:Me,Pe={form:d,providers:r.data?.providers??[],prompts:v.prompts,voices:o.data?.voices??[],silenceGapSeconds:s.data?.silenceGapSeconds??3,problem:Se,update:oe,onPickFiles:Ae,onRemoveFile:je,onReattachFile:(e,t,n)=>{g.attach(e,[n],t)}},Fe=l.data?.find(e=>e.id===_.templateSource?.id),Ie=_.channelId??(Fe===void 0?`00000000-0000-4000-8000-000000000001`:o0(Fe)),Le=Object.values(_.form.reviews?.stages??{}).filter(e=>e.mode!==`off`).length,Re={providers:r.data?.providers??[],voices:o.data?.voices??[],keywords:ue.length,topics:me,channel:c.data?.find(e=>e.id===Ie)?.name,brandKit:_.form.useBrandKit!==!1,look:K6(_.form),fontName:u.data?.fonts.find(e=>e.id===d.subtitles.fontId)?.name,checkpoints:d.checkpoints?.length??0,reviews:Le},ze={title:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[me.length?(0,h.jsx)(xV,{label:`Title pattern`,tip:`play.title-pattern`,error:Se(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,value:d.title,maxLength:200,"aria-invalid":Se(`title`)!==void 0,onChange:e=>oe({title:e.target.value})})}):null,(0,h.jsx)(Hhe,{fields:ue,origins:pe,topics:me,hide:me,values:d.values,problem:Se,onChange:(e,t)=>oe({values:{...d.values,[e]:t}})}),ue.length===me.length?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:ue.length===0?`No keywords. A prompt or the title that names {{a keyword}} adds one here.`:`The only keywords are the topic, typed at the top.`}):null]}),article:(0,h.jsx)(zhe,{...Pe,entries:v.entries,onLibrary:e=>{Oe(e)}}),narration:(0,h.jsx)(ege,{...Pe,entries:v.entries,onKeyword:Ce,onSettings:()=>{Oe(`/settings`)}}),images:(0,h.jsx)(tge,{...Pe}),video:(0,h.jsx)(nge,{...Pe,problemOf:Se}),outputs:(0,h.jsx)(rge,{...Pe,entries:v.entries,onSettings:()=>{Oe(`/settings`)}}),reviews:void 0,channel:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(Ume,{}),(0,h.jsx)(Wme,{})]})},Be=X6.filter(e=>e.id!==`narration`||d.sources.article!==`off`),Ve=Be.map(e=>({id:e.id,label:e.label,summary:Tge(e.id,d,Re),problem:$6(e.id,ge,me,be)?.message,editor:ze[e.id]})),He=(e,t)=>{if(e===`reviews`){ke();return}T(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},Ue=e=>{He(e,!0),requestAnimationFrame(()=>{j.current?.querySelector(`[data-setup-row="${e}"]`)?.scrollIntoView({block:`start`,behavior:`smooth`})})},We=_.variants.length+1,Ge=YN(_,g.view),Ke=!g.review.starting&&(g.review.uncertain||g.review.valid&&!g.review.pending&&ge.length===0&&!Ge);bx({id:`play.start`,title:qN(g.review,_),group:`Play`,context:d.title||`New project`,keywords:[`start`,`queue`,`run`,`play`,`go`],run:()=>{Ke?g.startRun():he?Ce(he.field):ge[0]&&Ce(ge[0].field)}}),bx({id:`play.add-topic`,title:`Add a topic for another video`,group:`Play`,context:`${String(We)} video${We===1?``:`s`}`,keywords:[`more videos`,`variation`,`batch`,`queue`],run:()=>D(!0)}),bx({id:`play.save-template`,title:`Save as template`,group:`Play`,keywords:[`template`,`setup`,`reuse`],run:()=>ee(!0)}),bx({id:`play.review`,title:`Review the whole setup`,group:`Play`,keywords:[`summary`,`checkpoints`,`prompt`],shortcut:lP.reviewSetup,run:ke}),bx({id:`play.template`,title:`Pick a template`,group:`Play`,keywords:[`template`,`setup`],run:()=>{j.current&&B6(j.current,`template`)}});let qe=d.sources.video===`generate`&&d.sources.images!==`off`,Je=oge(d,p),Ye=qe?(0,h.jsx)(O6,{drawnOn:Je?.drawnOn,settings:{format:d.format,subtitles:{mode:d.sources.audio===`off`?`off`:d.subtitles.mode,fontId:d.subtitles.fontId,fontSize:Number(_.form.subtitles.fontSize)||d.subtitles.fontSize,position:d.subtitles.position},videoEdit:d.videoEdit,previewText:_.previewText,image:Je?.image}}):null;return(0,h.jsxs)(`div`,{ref:j,onBlurCapture:e=>{let t=e.target.dataset.playField;t&&C(e=>new Set([...e,t]))},"data-play-grid":`true`,className:`min-w-0 max-[767px]:[&_button]:min-h-11 max-[767px]:[&_input:not([type=checkbox])]:min-h-11 max-[767px]:[&_select]:min-h-11 max-[767px]:[&_summary]:min-h-11`,children:[(0,h.jsx)(kq,{crumb:`New project`,title:(0,h.jsx)(`span`,{ref:re,tabIndex:-1,children:`What's the video about?`}),meta:d.title.trim()===``?`Untitled draft`:d.title,actions:(0,h.jsx)(Bhe,{})}),(0,h.jsx)(B3,{onDefaults:g.adoptDefaults}),(0,h.jsxs)(Aq,{className:`sl-workspace--play`,aside:(0,h.jsx)(Dge,{errors:ge,blocker:he,saveProblem:Ne,onReveal:Ce,onWholeSetup:ke,onSaveTemplate:()=>ee(!0),preview:Ye}),asideLabel:`Review and start`,children:[(0,h.jsxs)(`div`,{"data-tour":`play-options`,className:`grid min-w-0 grid-cols-1 items-start gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(kge,{topics:me,onError:ne}),(0,h.jsx)(Age,{topics:me,problem:Se})]}),(0,h.jsx)(xge,{topics:me}),te?(0,h.jsx)(SI,{tone:`danger`,title:te}):null,(0,h.jsx)(jge,{topics:me,keywordNames:ue.map(e=>e.name),origins:pe,problem:Se,adding:E,onAdding:D,open:O,onOpen:k}),(0,h.jsx)(Sge,{rows:Ve,open:w,onChange:He})]}),(0,h.jsx)(YP,{open:g.section===`review`,title:`Review`,headingRef:M,onClose:()=>{g.navigate(`content`)},children:(0,h.jsx)(mge,{fields:ue,errors:ge,problem:Se,onReveal:Ce})}),(0,h.jsx)(gge,{open:A,onClose:()=>ee(!1)}),Be.map(e=>(0,h.jsx)(Pge,{id:e.id,label:e.label,onOpen:Ue},e.id))]})}function Pge({id:e,label:t,onOpen:n}){return bx({id:`play.row.${e}`,title:`Change ${t.toLowerCase()}`,group:`Play`,keywords:[`open`,`edit`,`section`,t],run:()=>n(e)}),null}function Fge(){let{api:e}=z(),t=N({queryKey:[`batch-queue`],queryFn:async()=>F(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=N(Yy(e)),r=t.data?.queue.length??0;return(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,disabled:r===0,"aria-label":`Video queue: ${r} remaining`,children:[(0,h.jsx)(Ec,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,r]})]})}),(0,h.jsxs)(Eb,{align:`end`,className:`p-0`,children:[(0,h.jsx)(`p`,{className:`border-b border-line px-3 py-2 text-small text-ink-2`,children:pb(`play.queue`).body}),(0,h.jsx)(Ige,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function Ige({queue:e,projects:t}){return(0,h.jsx)(`ol`,{className:`max-h-40 overflow-y-auto px-4 py-2`,children:e.map((e,n)=>{let r=t?.find(t=>t.id===e.projectId);return(0,h.jsxs)(`li`,{className:`flex justify-between gap-3 py-1 text-small`,children:[(0,h.jsxs)(ha,{className:`truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[n+1,`. `,r?.title??`Video`]}),(0,h.jsx)(`span`,{className:`shrink-0 text-ink-2`,children:r?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`})]},e.projectId)})})}function e8({label:e,className:t,children:n}){return(0,h.jsx)(`nav`,{"aria-label":e,className:L(`sl-rail`,t),children:n})}function Lge({icon:e,meta:t,children:n}){return(0,h.jsxs)(h.Fragment,{children:[e,(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:n}),t===void 0?null:(0,h.jsx)(`span`,{className:`sl-rail__meta`,children:t})]})}function t8({icon:e,meta:t,current:n=!1,onClick:r,className:i,children:a,"data-tour":o}){return(0,h.jsx)(`button`,{type:`button`,"data-tour":o,"aria-current":n?`true`:void 0,onClick:r,className:L(`sl-rail__item w-full border-0 bg-transparent text-left font-[inherit]`,n&&`bg-accent-tint font-semibold text-ink`,i),children:(0,h.jsx)(Lge,{icon:e,meta:t,children:a})})}var n8=/^(?:[-*+]|\d+[.)])\s+/u;function Rge(e){let t=e.split(/\r?\n/u).filter(e=>e.trim()!==``),n=[];for(let e of t.slice(1)){let t=e.trim().replace(n8,``).trim(),r=n.length-1;/^\s/u.test(e)&&!n8.test(e.trim())&&r>=0?n[r]=`${n[r]??``} ${t}`:t!==``&&n.push(t)}return n}var zge={blockquote:o8,break:Wge,code:s8,definition:s8,delete:o8,emphasis:o8,footnoteReference:s8,footnoteDefinition:s8,heading:Uge,html:s8,image:i8,imageReference:i8,inlineCode:a8,list:o8,listItem:o8,link:o8,linkReference:o8,strong:o8,table:s8,tableCell:s8,text:a8,thematicBreak:s8,toml:s8,yaml:s8},Bge={},r8=[];function Vge(e){let t={...zge},n=e||Bge,r=n.keep||r8,i=n.remove||r8,a=-1;for(;++a<i.length;){let e=i[a];typeof e==`string`?t[e]=s8:t[e[0]]=e[1]}let o={};if(r.length===0)o=t;else{let e;for(e in t)r.includes(e)||(o[e]=t[e]);for(a=-1;++a<r.length;)if(e=r[a],!Object.hasOwn(t,e))throw Error("Unknown node type `"+e+"` in `keep`, use a replace tuple with a handle instead: `remove: [['"+e+"', handle]]`")}return function(e){return s(e)};function s(e){let t=e.type,n=e;if(Object.hasOwn(o,t)){let e=o[t];e&&(n=e(n)||void 0)}return n=Array.isArray(n)?c(n):n,n&&`children`in n&&(n.children=c(n.children)),n}function c(e){let t=-1,n=[];for(;++t<e.length;){let r=s(e[t]);Array.isArray(r)?n.push(...c(r)):r&&n.push(r)}return Hge(n)}}function Hge(e){let t=-1,n=[],r;for(;++t<e.length;){let i=e[t];r&&i.type===r.type&&`value`in i&&`value`in r?r.value+=i.value:(n.push(i),r=i)}return n}function i8(e){let t=`title`in e?e.title:``,n=e.alt||t||``;return n?{type:`text`,value:n}:void 0}function a8(e){return{type:`text`,value:e.value}}function Uge(e){return{type:`paragraph`,children:e.children}}function o8(e){return e.children}function Wge(){return{type:`text`,value:`
283
+ `}}function s8(){}var Gge=64,c8=new Map;function Kge(e){let t=c8.get(e);if(t!==void 0)return t;let n=qge(e);for(c8.set(e,n);c8.size>Gge;){let e=c8.keys().next().value;if(e===void 0)break;c8.delete(e)}return n}function qge(e){let t=r6().use(pB).use(Vge),n=t.runSync(t.parse(e)).children.map(e=>{if(e.type!==`paragraph`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.children.map(e=>{if(e.type!==`text`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.value}).join(``)}).filter(e=>e.trim()!==``);return n.length===0?``:n.join(`
284
284
 
285
285
  `)+`
286
- `}var l8={"sources consulted":`sources`,"pronunciation glossary":`glossary`},qge=16,u8=new Map;function d8(e){let t=u8.get(e);if(t!==void 0)return t;let n=Jge(e);for(u8.set(e,n);u8.size>qge;){let e=u8.keys().next().value;if(e===void 0)break;u8.delete(e)}return n}function Jge(e){let t=Yge(e),n=t[0];if(n===void 0)return{body:e,sources:``,glossary:``};let r={sources:``,glossary:``};for(let[n,i]of t.entries())r[i.part]+=e.slice(i.at,t[n+1]?.at??e.length);return{body:e.slice(0,n.at),sources:r.sources,glossary:r.glossary}}function Yge(e){let t=r6().use(pB).parse(e),n=[];for(let r of t.children){if(r.type!==`heading`&&r.type!==`paragraph`)continue;let t=r.position?.start.offset,i=r.position?.end.offset;if(t===void 0||i===void 0)continue;let a=Qge(e.slice(t,i));a!==void 0&&n.push({part:a,at:t})}return n}var Xge=Object.keys(l8).map(e=>e.replace(/[^a-z]/g,``));function Zge(e){let t=e.toLowerCase().replace(/[^a-z]/g,``);return Xge.some(e=>{let n=0;for(let r of t)r===e[n]&&(n+=1);return n>=e.length})}function Qge(e){return Zge(e)?l8[Gge(e).trim().toLowerCase().replace(/:$/,``)]:void 0}function $ge({script:e,voices:t}){let n=(0,m.useMemo)(()=>u6(e,t.speakers),[e,t.speakers]);if(!n.ok)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`This script can't be narrated yet: `,n.reason,` Fix it in Edit project → Article.`]});let r=new Map(t.speakers.map((e,t)=>[e.id,t])),i=new Map(t.speakers.map(e=>[e.id,e.name.trim()]));return(0,h.jsx)(`ol`,{"aria-label":`Script`,className:`space-y-3`,children:n.script.turns.map(e=>{let t=n.script.sections.find(t=>t.firstTurn===e.index),a=`var(--color-speaker-${String((r.get(e.speaker)??0)%6+1)})`;return(0,h.jsxs)(`li`,{className:`space-y-2`,children:[t===void 0?null:(0,h.jsx)(`h3`,{className:`pt-2 text-title-3 font-semibold text-ink`,children:t.title}),(0,h.jsxs)(`div`,{className:`border-l-4 pl-3`,style:{borderColor:a},children:[(0,h.jsx)(`p`,{className:`text-label font-semibold text-ink-2`,children:i.get(e.speaker)??e.speaker}),(0,h.jsx)(`p`,{className:`text-body text-ink`,children:e.text})]})]},e.index)})})}function f8(e,t){return e.filter(e=>e.stageKind===t.kind)}function p8(e,t){return e.find(e=>e.role===t)}var m8=Lv,h8=Rv;function g8({className:e,sideOffset:t=4,align:n=`end`,...r}){return(0,h.jsx)(zv,{children:(0,h.jsx)(Bv,{"data-slot":`menu-content`,sideOffset:t,align:n,className:L(`z-50 min-w-[180px] overflow-hidden rounded-control border border-line bg-raised p-1`,`shadow-[var(--shadow-pop)]`,e),...r})})}function _8({className:e,...t}){return(0,h.jsx)(Vv,{"data-slot":`menu-item`,className:L(`flex cursor-default items-center gap-2 rounded-control px-[10px] py-[6px] text-small text-ink`,`outline-hidden select-none focus:bg-sunken data-highlighted:bg-sunken`,`data-disabled:text-ink-3`,e),...t})}function e_e({className:e}){return(0,h.jsx)(Hv,{className:L(`my-1 h-px bg-line`,e)})}var v8=(0,m.createContext)(null);function t_e({projectId:e,revisionId:t,children:n}){let{api:r}=z(),i=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved version yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);let i=n.value.view;if(i.revision.id!==t||i.revision.projectId!==e)throw Error(`The project changed while its files were loading. Reload the page.`);return i}});return(0,h.jsxs)(v8,{value:{projectId:e,revisionId:t,view:i.data},children:[i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:i.error.message}),n]})}function y8(){return(0,m.useContext)(v8)?.view}function b8(e){let t=(0,m.useContext)(v8),{api:n}=z();return S8(n,t,e)}function x8(e){let t=(0,m.useContext)(v8),{api:n}=z(),r=new Map;for(let i of e){let e=S8(n,t,i);e!==void 0&&r.set(i.id,e)}return r}function S8(e,t,n){if(n===void 0||t!==null&&t.projectId!==n.projectId)return;if(t===null||t.revisionId===null)return{url:Ko(e,n.projectId,D3(n)),cacheKey:B.file(n.projectId,n.id),folder:null};let r=t.view?.outputs.find(e=>e.selected&&e.available&&e.output.id===n.id);return r===void 0?void 0:C8(e,t.projectId,t.revisionId,r)}function n_e(e,t){let n=(0,m.useContext)(v8),{api:r}=z();if(n!==null&&n.projectId!==e)return;if(n===null||n.revisionId===null)return{url:Ko(r,e,t),cacheKey:B.file(e,t),folder:null};let i=n.view?.outputs.find(e=>e.selected&&e.available&&(t===`images.zip`?e.output.role===`image`||e.output.role===`thumbnail`:D3(e.output)===t));if(i===void 0)return;let a=C8(r,e,n.revisionId,i);return t===`images.zip`?{...a,url:s2(r,e,n.revisionId,`images.zip`),cacheKey:B.revisionFile(e,n.revisionId,`images.zip`)}:a}function C8(e,t,n,r){return{url:s2(e,t,n,r.recordId),cacheKey:B.revisionFile(t,n,r.recordId),folder:{revisionId:n,recordId:r.recordId}}}function w8({children:e,className:t}){return(0,h.jsx)(`div`,{className:L(`flex min-w-0 flex-col gap-5`,t),children:e})}function T8({children:e}){return(0,h.jsx)(`span`,{className:`sl-kicker`,children:e})}var r_e={h1:({children:e})=>(0,h.jsx)(E8,{size:`text-title-2`,children:e}),h2:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h3:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h4:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h5:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h6:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),p:({children:e})=>(0,h.jsx)(`p`,{className:`m-0`,children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),ul:({children:e})=>(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5`,children:e}),ol:({children:e})=>(0,h.jsx)(`ol`,{className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:e}),li:({children:e})=>(0,h.jsx)(`li`,{className:`m-0`,children:e}),a:({children:e,href:t})=>(0,h.jsx)(`a`,{href:t,className:`rounded-control text-accent-ink underline underline-offset-[3px]`,target:`_blank`,rel:`noreferrer`,children:e}),code:({children:e})=>(0,h.jsx)(`code`,{className:`rounded-control bg-sunken px-1 py-0.5 font-mono text-small`,children:e}),pre:({children:e})=>(0,h.jsx)(`pre`,{className:`m-0 overflow-x-auto rounded-control bg-sunken p-3 font-mono text-small`,children:e}),blockquote:({children:e})=>(0,h.jsx)(`blockquote`,{className:`m-0 flex flex-col gap-2 border-l-2 border-line-strong pl-3 text-ink-2`,children:e}),hr:()=>(0,h.jsx)(`hr`,{className:`my-2 border-line`}),table:({children:e})=>(0,h.jsx)(`table`,{className:`w-full border-collapse text-left text-small`,children:e}),th:({children:e})=>(0,h.jsx)(`th`,{className:`sl-kicker border-b border-line py-2 pr-4 text-left`,children:e}),td:({children:e})=>(0,h.jsx)(`td`,{className:`border-b border-line py-2 pr-4 align-top`,children:e})},i_e={p:({children:e})=>(0,h.jsx)(h.Fragment,{children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),a:({children:e})=>(0,h.jsx)(h.Fragment,{children:e})};function E8({size:e,children:t}){return(0,h.jsx)(`h3`,{className:L(`mt-2 font-bold tracking-[-0.01em]`,e),children:t})}function D8({markdown:e}){return(0,h.jsx)(`div`,{className:`flex max-w-[68ch] flex-col gap-2 text-pretty text-body text-ink`,children:(0,h.jsx)(sz,{remarkPlugins:[pB],components:r_e,children:e})})}function a_e({markdown:e}){return(0,h.jsx)(sz,{remarkPlugins:[pB],components:i_e,children:e})}var o_e=/^#{1,6}[ \t]+(.*?)[ \t]*#*[ \t]*(?:\r?\n|$)/;function s_e(e){let t=e.replace(/^[\s]*\n/,``),n=o_e.exec(t);return n===null?{title:void 0,body:e.trim()}:{title:n[1]??``,body:t.slice(n[0].length).trim()}}function c_e({projectId:e,asset:t,label:n=`Download`,variant:r=`primary`}){let i=n_e(e,t);return i===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]}),(0,h.jsx)(u2,{projectId:e,asset:t,folder:i.folder})]})}function l_e(e){return e.flatMap(e=>e.output===void 0?[]:[e.output])}function O8({files:e,label:t=`Download`,variant:n=`primary`}){let r=e.filter(e=>e.output!==void 0),[i]=r;return i===void 0?null:r.length===1?(0,h.jsx)(u_e,{output:i.output,label:t,file:i.label,variant:n}):(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsxs)(R,{variant:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t,(0,h.jsx)(uc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(g8,{children:r.map(e=>(0,h.jsx)(d_e,{output:e.output,label:e.label},e.output.id))})]})}function u_e({output:e,label:t,file:n,variant:r}){let i=b8(e);return i===void 0?null:(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,title:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t]})}function d_e({output:e,label:t}){let n=b8(e);return n===void 0?null:(0,h.jsx)(_8,{asChild:!0,children:(0,h.jsxs)(`a`,{href:n.url,download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),t]})})}function k8({output:e}){let t=b8(e);return e===void 0||t===void 0?null:(0,h.jsx)(u2,{projectId:e.projectId,asset:D3(e),folder:t.folder})}function A8({files:e,label:t=`Download`,variant:n=`primary`,children:r}){let i=l_e(e);return i.length===0&&r===void 0?null:(0,h.jsxs)(Ey,{children:[(0,h.jsx)(O8,{files:e,label:t,variant:n}),(0,h.jsx)(k8,{output:i[0]}),r]})}function j8({children:e}){return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:e})}function M8(e){let{api:t}=z(),n=b8(e);return N({queryKey:n?.cacheKey??B.revisionFile(``,``,`unavailable`),queryFn:async()=>n===void 0?``:lo(await t.fetch(n.url)),enabled:n!==void 0,staleTime:1/0})}function f_e({output:e,as:t=`prose`}){let n=M8(e);return n.error===null?n.data===void 0?(0,h.jsx)(`span`,{className:`h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):t===`prose`?(0,h.jsx)(D8,{markdown:n.data}):(0,h.jsx)(`pre`,{className:`m-0 max-w-[68ch] overflow-x-auto whitespace-pre-wrap font-sans text-small text-ink-2`,children:n.data}):(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:n.error.message})}function N8({output:e}){let[t,n]=(0,m.useState)(!1);return e===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":t,onClick:()=>{n(!t)},children:t?`Hide instructions`:`Show instructions`}),t?(0,h.jsx)(`div`,{className:`w-full basis-full`,children:(0,h.jsx)(f_e,{output:e,as:`plain`})}):null]})}function p_e({projectId:e,stage:t,notes:n,onCopy:r}){let i=t.state===`running`,a=M8(n);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[i?(0,h.jsx)(j3,{projectId:e,stage:`research`,className:``}):null,i&&n===void 0?null:a.error===null?(0,h.jsx)(CB,{markdown:a.data??``,label:`Research notes`,regionLabel:`Research notes`,anchorPrefix:`research-`,what:`research notes`,onCopy:r,copyAll:!1,children:n===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:m_e(t)}):(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}):(0,h.jsx)(`p`,{className:`text-body text-danger`,children:a.error.message})]})}function m_e(e){switch(e.state){case`failed`:case`canceled`:return`Research stopped before any notes were saved. Try the research again with the next action beside it.`;case`pending`:return`The research runs first; its notes appear here when it finishes.`;default:return`No notes were written.`}}var h_e=[{segment:`intro`,name:`Intro`},{segment:`body`,name:`Body`},{segment:`outro`,name:`Outro`}];function P8(e){let t=/\.([a-z0-9]+)$/i.exec(e.path);return t===null?``:` (.${(t[1]??``).toLowerCase()})`}function g_e(e,t=[],n){return[...__e(e,t),...n===void 0?[]:[{output:n,label:`Script by speaker${P8(n)}`}]]}function __e(e,t){return h_e.flatMap(({segment:n,name:r})=>{let i=t=>e.find(e=>e.role===t&&e.meta.segment===n),a=t.find(e=>e.segment===n)?.output,o=i(`narration_txt`),s=i(`tts_script`);return[...a===void 0?[]:[{output:a,label:`${r} narration${P8(a)}`}],...o===void 0?[]:[{output:o,label:`${r} clean narration${P8(o)}`}],...s===void 0?[]:[{output:s,label:`${r} TTS script${P8(s)}`}]]})}function v_e(e){return e.some(e=>e.role===`narration_txt`||e.role===`tts_script`)}function F8(e){let{api:t}=z();return(N({queryKey:M3(e),queryFn:()=>wme(t,e)}).data??[]).filter(e=>e.current)}function I8(e,t){return e.find(e=>t.itemKey===void 0?t.outputId!==void 0&&e.outputId===t.outputId:e.itemKey===t.itemKey)}function y_e(e){return e.passed?e.attempt>1?{label:`Redone after review`,tone:`info`}:{label:`Review passed`,tone:`neutral`}:e.action===`overruled`?{label:`Accepted by you`,tone:`neutral`}:e.action===`redone`?{label:`Being made again`,tone:`running`}:e.redoState===`pending`?{label:`Waiting to be made again`,tone:`running`}:e.redoState===`started`?{label:`Being made again`,tone:`running`}:{label:`Flagged by review`,tone:`info`}}function b_e({review:e}){let t=y_e(e);return(0,h.jsx)(vS,{tone:t.tone,children:t.label})}function L8({review:e}){return(0,h.jsx)(b_e,{review:e})}function R8({review:e}){return(0,h.jsxs)(h.Fragment,{children:[e.reasons.length===0?(0,h.jsx)(`p`,{className:`m-0`,children:`The reviewer found nothing to fix.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-4`,children:e.reasons.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:e.outcome===`flagged`&&!e.passed&&e.attempt>1?`Kept after ${String(e.attempt)} tries: the redo limit was reached.`:`Try ${String(e.attempt)}.`}),e.redoState===`failed`&&e.redoError?(0,h.jsx)(`p`,{className:`m-0 text-danger`,children:e.redoError}):null]})}function z8({review:e,projectId:t,busy:n}){let{api:r}=z(),i=_(),[a,o]=(0,m.useState)(null),s=P({mutationFn:async n=>{let a=i.getQueryData(B.project(t))?.revisionId;return Tme(r,t,e.id,n,n===`redo`&&a?{baseRevisionId:a,idempotencyKey:crypto.randomUUID()}:void 0)},onSuccess:async e=>{o(e.ok?null:e.message),await i.invalidateQueries({queryKey:M3(t)}),await i.invalidateQueries({queryKey:B.project(t)})},onError:e=>o(e.message)});if(e.passed||e.action!==null)return null;let c=e.redoState===`pending`,l=c||e.redoState===`started`;return(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n&&!c||e.redoState===`started`||s.isPending,disabledReason:e.redoState===`started`?`Slopify is already making this item again; wait for the new version`:`Wait until the work on this project is done`,onClick:()=>s.mutate(`overrule`),children:`Overrule`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n||l||s.isPending,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.mutate(`redo`),children:`Redo`}),a?(0,h.jsx)(`span`,{role:`alert`,className:`basis-full text-small text-danger`,children:a}):null]})}function B8({review:e,projectId:t,busy:n}){return e===void 0?null:(0,h.jsxs)(`section`,{"aria-label":`${Tk[e.stage]} review`,className:`flex min-w-0 flex-col gap-1 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsx)(z8,{review:e,projectId:t,busy:n})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-1 text-ink-2`,children:(0,h.jsx)(R8,{review:e})})]})}function V8({review:e}){return e===void 0||e.passed&&e.attempt<=1?null:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{type:`button`,"aria-label":`About this review`,className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Cc,{"aria-hidden":`true`,className:`size-[15px]`})}),(0,h.jsx)(Eb,{className:`space-y-2 leading-[1.45]`,children:(0,h.jsx)(R8,{review:e})})]})]})}function x_e(e){let t=[e.stage,e.companion].filter(e=>e!==void 0);for(let e of[`failed`,`canceled`,`running`]){let n=t.find(t=>t.state===e);if(n!==void 0)return n}return e.stage.state===`skipped`&&e.companion!==void 0?e.companion:e.stage}var H8=e=>e.state!==`pending`&&e.state!==`skipped`;function S_e(e){return e.replace(/^\s*[^\n]*\n?/u,``).trim()}function C_e({stage:e,companion:t,project:n,outputs:r,busy:i}){let a=F8(n.id),o=k3(n.id),s=f8(r,e),c=t?.kind===`research`?t:void 0,l=c===void 0?[]:f8(r,c),u=p8(l,`notes`),d=M8(u),f=p8(s,`article_md`)??p8(s,`article_txt`),p=p8(s,`sources`),g=p8(s,`glossary`),_=HA(n.config)?n.config.voices:void 0,v=p8(s,`script_md`),y=M8(v),b=M8(f),x=N({queryKey:A3(n.id,o),queryFn:()=>[],enabled:!1}).data?.some(e=>e.stage===`article`)===!0,S=N({queryKey:B.article(n.id,o),queryFn:()=>``,enabled:!1}),C=b.data??``,w=e.state===`running`,T=s_e(w?S.data??``:C),E=T.title??n.title,D=(0,m.useMemo)(()=>w?{body:T.body,sources:``,glossary:``}:d8(T.body),[w,T.body]),O=(0,m.useMemo)(()=>Lge(D.sources),[D.sources]),k=S_e(D.glossary),A=(0,m.useMemo)(()=>{if(D.glossary.trim()===``)return[];let e=c6(D.glossary);return e.ok?e.skipped??[]:[]},[D.glossary]),ee=_===void 0||w?``:_.source===`script`?d8(C).body:y.data??``,te=[{id:`article`,label:_?.source===`script`?`Script text`:`Article`},...ee.trim()===``?[]:[{id:`script`,label:`Speakers`}],...c===void 0?[]:[{id:`research`,label:`Research`}],...O.length>0?[{id:`sources`,label:`Sources`,badge:String(O.length)}]:[],...k===``?[]:[{id:`pronunciation`,label:`Pronunciation`}]],ne=c!==void 0&&x_e({kind:`article`,stage:e,companion:c})===c,[j,re]=(0,m.useState)(),M=j??(ne?`research`:`article`),ie=te.some(e=>e.id===M)?M:`article`,ae=(0,m.useId)().replace(/:/gu,``),[oe,se]=(0,m.useState)(),ce={article:`${T.title===void 0?``:`# ${T.title}\n\n`}${D.body.trim()}\n`,script:`${ee.trim()}\n`,research:`${(d.data??``).trim()}\n`,sources:`${O.map(e=>`- ${e}`).join(`
287
- `)}\n`,pronunciation:`${k}\n`},le={article:`article`,script:`script`,research:`research notes`,sources:`sources`,pronunciation:`pronunciation table`},ue=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>se({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),de=e=>ue(ce[e],le[e]);return(0,h.jsxs)(w8,{children:[(0,h.jsx)(B8,{review:I8(a,{itemKey:`article:body`}),projectId:n.id,busy:i}),(0,h.jsxs)(A8,{files:[...f===void 0?[]:[{output:f,label:`Article${P8(f)}`}],...p===void 0?[]:[{output:p,label:`Sources${P8(p)}`}],...g===void 0?[]:[{output:g,label:`Pronunciation glossary${P8(g)}`}],...u===void 0?[]:[{output:u,label:`Research notes${P8(u)}`}],...v===void 0?[]:[{output:v,label:`Script by speaker${P8(v)}`}]],children:[(ie===`research`?c?.state===`running`||d.data===void 0:w||C===``)?null:(0,h.jsxs)(R,{variant:`secondary`,onClick:()=>de(ie),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy `,le[ie]]}),ie===`research`&&c!==void 0?(0,h.jsx)(N8,{output:p8(l,`instructions`)}):(0,h.jsx)(N8,{output:p8(s,`instructions`)}),(0,h.jsx)(Q1,{tone:oe?.tone??`info`,children:oe?.text})]}),b.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:b.error.message}),te.length>1?(0,h.jsx)(r0,{items:te,value:ie,onChange:e=>{re(e),se(void 0)},label:`Article parts`,idPrefix:ae}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3 font-semibold text-ink`,children:(0,h.jsx)(a_e,{markdown:E})}),D.body.trim()===``?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:w_e(D.body)})]}),(0,h.jsx)(i0,{idPrefix:ae,id:`article`,active:ie===`article`,children:w?(0,h.jsx)(`section`,{"aria-label":`Article content`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:x?(0,h.jsx)(j3,{projectId:n.id,stage:`article`,className:``}):(0,h.jsx)(D8,{markdown:D.body})}):(0,h.jsx)(CB,{markdown:D.body,label:`Article`,regionLabel:`Article content`,anchorPrefix:`article-`,what:`article`,onCopy:ue,copyAll:!1,children:H8(e)&&f!==void 0&&b.data===void 0?(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:H8(e)?`No article was saved.`:c===void 0?`The article will be written when its inputs are ready.`:`The article is written once the research has finished.`})})}),_===void 0||ee.trim()===``?null:(0,h.jsx)(i0,{idPrefix:ae,id:`script`,active:ie===`script`,children:(0,h.jsx)(`section`,{"aria-label":`Script by speaker`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:(0,h.jsx)($ge,{script:ee,voices:_})})}),c===void 0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`research`,active:ie===`research`,children:(0,h.jsx)(p_e,{projectId:n.id,stage:c,notes:u,onCopy:ue})}),O.length===0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`sources`,active:ie===`sources`,children:(0,h.jsx)(CB,{markdown:O.map((e,t)=>`${String(t+1)}. ${e}`).join(`
288
- `),label:`Sources`,regionLabel:`Sources`,anchorPrefix:`sources-`,what:`sources`,onCopy:ue,copyAll:!1})}),k===``?null:(0,h.jsxs)(i0,{idPrefix:ae,id:`pronunciation`,active:ie===`pronunciation`,children:[A.length===0?null:(0,h.jsxs)(SI,{className:`mb-3`,title:`${A.length===1?`1 entry is`:`${A.length} entries are`} skipped by the narration and read as ordinary text`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:A.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsx)(`p`,{className:`m-0 mt-1`,children:`The other entries are used. To fix these, edit the Pronunciation Glossary at the end of the article in Edit settings → Article.`})]}),(0,h.jsx)(`div`,{className:`sl-stage-scroll pr-3`,children:(0,h.jsx)(D8,{markdown:k})})]})]})}var U8=new Intl.NumberFormat(`en`);function w_e(e){let t=e.replace(/\]\([^)]*\)/g,`]`).replace(/[#*_>`[\]]/g,``).replace(/[ \t]+/g,` `).trim(),n=t.split(/\s+/).filter(e=>/[\p{L}\p{N}]/u.test(e)).length,r=t.replace(/\s*\n\s*/g,` `).length;return`${U8.format(n)} ${n===1?`word`:`words`} · ${U8.format(r)} characters`}function W8({className:e,label:t,children:n}){return(0,h.jsx)(`dl`,{"aria-label":t,className:L(`m-0 grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[max-content_minmax(0,1fr)] sm:gap-y-3`,e),children:n})}function G8({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2 max-sm:mt-2 max-sm:first:mt-0`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function K8({src:e,label:t,marks:n=[],waveform:r,compact:i=!1,preload:a=`metadata`,onError:o,ref:s,className:c}){let l=A0(),u=l.media;return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`${t} controls`,"data-slot":`audio-player`,"data-state":l.playing?`playing`:`paused`,className:L(`sl-audio`,i&&`sl-audio--compact`,r!==void 0&&r.length>0&&`sl-audio--wave`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.key===` `&&e.target.closest(`button`)!==null)return;let t=l.keyAction(e.key);t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||l.setMenu(!1)},children:[(0,h.jsx)(`audio`,{ref:O0(u,s),src:e,preload:a,"aria-label":t,onError:o,...l.events}),(0,h.jsx)(N0,{controls:l,className:`sl-audio__key`}),(0,h.jsx)(P0,{controls:l}),(0,h.jsx)(F0,{controls:l,chapters:n,waveform:r}),(0,h.jsx)(I0,{controls:l}),(0,h.jsx)(L0,{controls:l})]})}function q8({projectId:e,revisionId:t}){let n=k3(e),r=t===void 0?n:t,{api:i}=z(),a=N({queryKey:B.audioPreview(e,r),queryFn:async()=>F(await i.client.projects[`:projectId`][`audio-preview`].$get({param:{projectId:e}})),refetchInterval:1e3,staleTime:0,gcTime:0,retry:!1}),o=(a.data?.revisionId??null)===r?a.data?.previews??[]:[];return(0,h.jsxs)(`section`,{"aria-label":`Live narration`,className:`grid gap-3 border-y border-line py-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-ink`,children:`Listen while it generates`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Play any part. Each preview starts from its beginning.`})]}),a.error===null?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Live preview is temporarily unavailable. Finished audio will still appear here.`}),o.length===0&&a.error===null?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Waiting for the first audio bytes…`}):null,(0,h.jsx)(`div`,{className:`grid max-h-[420px] gap-3 overflow-y-auto`,children:o.map(t=>(0,h.jsx)(T_e,{preview:t,url:`${i.origin}/api/projects/${encodeURIComponent(e)}/audio-preview/${t.id}`},t.id))})]})}function T_e({preview:e,url:t}){let[n,r]=(0,m.useState)(!1),i=(e.state===`streaming`||e.state===`ready`)&&e.bytes>0,a=e.state===`ready`?`Ready`:e.state===`streaming`?`Generating`:`Preview stopped`;return(0,h.jsxs)(`div`,{className:`grid gap-2 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:e.label}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:a})]}),i&&!n?(0,h.jsx)(E_e,{label:e.label,url:t,onError:()=>r(!0)}):(0,h.jsx)(`p`,{className:`text-ink-2`,children:e.state===`streaming`&&!n?`Waiting for audio…`:`This preview has stopped. The finished narration will be available when generation completes.`})]})}function E_e({label:e,url:t,onError:n}){let r=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=r.current;return()=>{e!==null&&(e.pause(),e.removeAttribute(`src`),e.load())}},[]),(0,h.jsx)(K8,{ref:r,compact:!0,preload:`none`,label:`Live ${e} narration`,src:t,onError:n,className:`max-w-[620px]`})}function D_e({outputs:e}){let t=(0,m.useId)(),n=t=>e.find(e=>e.role===`narration_txt`&&e.meta.segment===t),r=M8(n(`intro`)).data,i=M8(n(`body`)).data,a=M8(n(`outro`)).data,[o,s]=(0,m.useState)(),c=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>s({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),l=[[`Intro`,r],[`Body`,i],[`Outro`,a]].filter(([,e])=>e!==void 0&&e.trim()!==``);if(!e.some(e=>e.role===`narration_txt`))return null;let u=l.length===1?(l[0]?.[1]??``).trim():l.map(([e,t])=>`## ${e}\n\n${(t??``).trim()}`).join(`
286
+ `}var l8={"sources consulted":`sources`,"pronunciation glossary":`glossary`},Jge=16,u8=new Map;function d8(e){let t=u8.get(e);if(t!==void 0)return t;let n=Yge(e);for(u8.set(e,n);u8.size>Jge;){let e=u8.keys().next().value;if(e===void 0)break;u8.delete(e)}return n}function Yge(e){let t=Xge(e),n=t[0];if(n===void 0)return{body:e,sources:``,glossary:``};let r={sources:``,glossary:``};for(let[n,i]of t.entries())r[i.part]+=e.slice(i.at,t[n+1]?.at??e.length);return{body:e.slice(0,n.at),sources:r.sources,glossary:r.glossary}}function Xge(e){let t=r6().use(pB).parse(e),n=[];for(let r of t.children){if(r.type!==`heading`&&r.type!==`paragraph`)continue;let t=r.position?.start.offset,i=r.position?.end.offset;if(t===void 0||i===void 0)continue;let a=$ge(e.slice(t,i));a!==void 0&&n.push({part:a,at:t})}return n}var Zge=Object.keys(l8).map(e=>e.replace(/[^a-z]/g,``));function Qge(e){let t=e.toLowerCase().replace(/[^a-z]/g,``);return Zge.some(e=>{let n=0;for(let r of t)r===e[n]&&(n+=1);return n>=e.length})}function $ge(e){return Qge(e)?l8[Kge(e).trim().toLowerCase().replace(/:$/,``)]:void 0}function e_e({script:e,voices:t}){let n=(0,m.useMemo)(()=>u6(e,t.speakers),[e,t.speakers]);if(!n.ok)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`This script can't be narrated yet: `,n.reason,` Fix it in Edit project → Article.`]});let r=new Map(t.speakers.map((e,t)=>[e.id,t])),i=new Map(t.speakers.map(e=>[e.id,e.name.trim()]));return(0,h.jsx)(`ol`,{"aria-label":`Script`,className:`space-y-3`,children:n.script.turns.map(e=>{let t=n.script.sections.find(t=>t.firstTurn===e.index),a=`var(--color-speaker-${String((r.get(e.speaker)??0)%6+1)})`;return(0,h.jsxs)(`li`,{className:`space-y-2`,children:[t===void 0?null:(0,h.jsx)(`h3`,{className:`pt-2 text-title-3 font-semibold text-ink`,children:t.title}),(0,h.jsxs)(`div`,{className:`border-l-4 pl-3`,style:{borderColor:a},children:[(0,h.jsx)(`p`,{className:`text-label font-semibold text-ink-2`,children:i.get(e.speaker)??e.speaker}),(0,h.jsx)(`p`,{className:`text-body text-ink`,children:e.text})]})]},e.index)})})}function f8(e,t){return e.filter(e=>e.stageKind===t.kind)}function p8(e,t){return e.find(e=>e.role===t)}var m8=Lv,h8=Rv;function g8({className:e,sideOffset:t=4,align:n=`end`,...r}){return(0,h.jsx)(zv,{children:(0,h.jsx)(Bv,{"data-slot":`menu-content`,sideOffset:t,align:n,className:L(`z-50 min-w-[180px] overflow-hidden rounded-control border border-line bg-raised p-1`,`shadow-[var(--shadow-pop)]`,e),...r})})}function _8({className:e,...t}){return(0,h.jsx)(Vv,{"data-slot":`menu-item`,className:L(`flex cursor-default items-center gap-2 rounded-control px-[10px] py-[6px] text-small text-ink`,`outline-hidden select-none focus:bg-sunken data-highlighted:bg-sunken`,`data-disabled:text-ink-3`,e),...t})}function t_e({className:e}){return(0,h.jsx)(Hv,{className:L(`my-1 h-px bg-line`,e)})}var v8=(0,m.createContext)(null);function n_e({projectId:e,revisionId:t,children:n}){let{api:r}=z(),i=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved version yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);let i=n.value.view;if(i.revision.id!==t||i.revision.projectId!==e)throw Error(`The project changed while its files were loading. Reload the page.`);return i}});return(0,h.jsxs)(v8,{value:{projectId:e,revisionId:t,view:i.data},children:[i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:i.error.message}),n]})}function y8(){return(0,m.useContext)(v8)?.view}function b8(e){let t=(0,m.useContext)(v8),{api:n}=z();return S8(n,t,e)}function x8(e){let t=(0,m.useContext)(v8),{api:n}=z(),r=new Map;for(let i of e){let e=S8(n,t,i);e!==void 0&&r.set(i.id,e)}return r}function S8(e,t,n){if(n===void 0||t!==null&&t.projectId!==n.projectId)return;if(t===null||t.revisionId===null)return{url:Ko(e,n.projectId,D3(n)),cacheKey:B.file(n.projectId,n.id),folder:null};let r=t.view?.outputs.find(e=>e.selected&&e.available&&e.output.id===n.id);return r===void 0?void 0:C8(e,t.projectId,t.revisionId,r)}function r_e(e,t){let n=(0,m.useContext)(v8),{api:r}=z();if(n!==null&&n.projectId!==e)return;if(n===null||n.revisionId===null)return{url:Ko(r,e,t),cacheKey:B.file(e,t),folder:null};let i=n.view?.outputs.find(e=>e.selected&&e.available&&(t===`images.zip`?e.output.role===`image`||e.output.role===`thumbnail`:D3(e.output)===t));if(i===void 0)return;let a=C8(r,e,n.revisionId,i);return t===`images.zip`?{...a,url:s2(r,e,n.revisionId,`images.zip`),cacheKey:B.revisionFile(e,n.revisionId,`images.zip`)}:a}function C8(e,t,n,r){return{url:s2(e,t,n,r.recordId),cacheKey:B.revisionFile(t,n,r.recordId),folder:{revisionId:n,recordId:r.recordId}}}function w8({children:e,className:t}){return(0,h.jsx)(`div`,{className:L(`flex min-w-0 flex-col gap-5`,t),children:e})}function T8({children:e}){return(0,h.jsx)(`span`,{className:`sl-kicker`,children:e})}var i_e={h1:({children:e})=>(0,h.jsx)(E8,{size:`text-title-2`,children:e}),h2:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h3:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h4:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h5:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h6:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),p:({children:e})=>(0,h.jsx)(`p`,{className:`m-0`,children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),ul:({children:e})=>(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5`,children:e}),ol:({children:e})=>(0,h.jsx)(`ol`,{className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:e}),li:({children:e})=>(0,h.jsx)(`li`,{className:`m-0`,children:e}),a:({children:e,href:t})=>(0,h.jsx)(`a`,{href:t,className:`rounded-control text-accent-ink underline underline-offset-[3px]`,target:`_blank`,rel:`noreferrer`,children:e}),code:({children:e})=>(0,h.jsx)(`code`,{className:`rounded-control bg-sunken px-1 py-0.5 font-mono text-small`,children:e}),pre:({children:e})=>(0,h.jsx)(`pre`,{className:`m-0 overflow-x-auto rounded-control bg-sunken p-3 font-mono text-small`,children:e}),blockquote:({children:e})=>(0,h.jsx)(`blockquote`,{className:`m-0 flex flex-col gap-2 border-l-2 border-line-strong pl-3 text-ink-2`,children:e}),hr:()=>(0,h.jsx)(`hr`,{className:`my-2 border-line`}),table:({children:e})=>(0,h.jsx)(`table`,{className:`w-full border-collapse text-left text-small`,children:e}),th:({children:e})=>(0,h.jsx)(`th`,{className:`sl-kicker border-b border-line py-2 pr-4 text-left`,children:e}),td:({children:e})=>(0,h.jsx)(`td`,{className:`border-b border-line py-2 pr-4 align-top`,children:e})},a_e={p:({children:e})=>(0,h.jsx)(h.Fragment,{children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),a:({children:e})=>(0,h.jsx)(h.Fragment,{children:e})};function E8({size:e,children:t}){return(0,h.jsx)(`h3`,{className:L(`mt-2 font-bold tracking-[-0.01em]`,e),children:t})}function D8({markdown:e}){return(0,h.jsx)(`div`,{className:`flex max-w-[68ch] flex-col gap-2 text-pretty text-body text-ink`,children:(0,h.jsx)(sz,{remarkPlugins:[pB],components:i_e,children:e})})}function o_e({markdown:e}){return(0,h.jsx)(sz,{remarkPlugins:[pB],components:a_e,children:e})}var s_e=/^#{1,6}[ \t]+(.*?)[ \t]*#*[ \t]*(?:\r?\n|$)/;function c_e(e){let t=e.replace(/^[\s]*\n/,``),n=s_e.exec(t);return n===null?{title:void 0,body:e.trim()}:{title:n[1]??``,body:t.slice(n[0].length).trim()}}function l_e({projectId:e,asset:t,label:n=`Download`,variant:r=`primary`}){let i=r_e(e,t);return i===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]}),(0,h.jsx)(u2,{projectId:e,asset:t,folder:i.folder})]})}function u_e(e){return e.flatMap(e=>e.output===void 0?[]:[e.output])}function O8({files:e,label:t=`Download`,variant:n=`primary`}){let r=e.filter(e=>e.output!==void 0),[i]=r;return i===void 0?null:r.length===1?(0,h.jsx)(d_e,{output:i.output,label:t,file:i.label,variant:n}):(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsxs)(R,{variant:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t,(0,h.jsx)(uc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(g8,{children:r.map(e=>(0,h.jsx)(f_e,{output:e.output,label:e.label},e.output.id))})]})}function d_e({output:e,label:t,file:n,variant:r}){let i=b8(e);return i===void 0?null:(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,title:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t]})}function f_e({output:e,label:t}){let n=b8(e);return n===void 0?null:(0,h.jsx)(_8,{asChild:!0,children:(0,h.jsxs)(`a`,{href:n.url,download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),t]})})}function k8({output:e}){let t=b8(e);return e===void 0||t===void 0?null:(0,h.jsx)(u2,{projectId:e.projectId,asset:D3(e),folder:t.folder})}function A8({files:e,label:t=`Download`,variant:n=`primary`,children:r}){let i=u_e(e);return i.length===0&&r===void 0?null:(0,h.jsxs)(Ey,{children:[(0,h.jsx)(O8,{files:e,label:t,variant:n}),(0,h.jsx)(k8,{output:i[0]}),r]})}function j8({children:e}){return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:e})}function M8(e){let{api:t}=z(),n=b8(e);return N({queryKey:n?.cacheKey??B.revisionFile(``,``,`unavailable`),queryFn:async()=>n===void 0?``:lo(await t.fetch(n.url)),enabled:n!==void 0,staleTime:1/0})}function p_e({output:e,as:t=`prose`}){let n=M8(e);return n.error===null?n.data===void 0?(0,h.jsx)(`span`,{className:`h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):t===`prose`?(0,h.jsx)(D8,{markdown:n.data}):(0,h.jsx)(`pre`,{className:`m-0 max-w-[68ch] overflow-x-auto whitespace-pre-wrap font-sans text-small text-ink-2`,children:n.data}):(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:n.error.message})}function N8({output:e}){let[t,n]=(0,m.useState)(!1);return e===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":t,onClick:()=>{n(!t)},children:t?`Hide instructions`:`Show instructions`}),t?(0,h.jsx)(`div`,{className:`w-full basis-full`,children:(0,h.jsx)(p_e,{output:e,as:`plain`})}):null]})}function m_e({projectId:e,stage:t,notes:n,onCopy:r}){let i=t.state===`running`,a=M8(n);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[i?(0,h.jsx)(j3,{projectId:e,stage:`research`,className:``}):null,i&&n===void 0?null:a.error===null?(0,h.jsx)(CB,{markdown:a.data??``,label:`Research notes`,regionLabel:`Research notes`,anchorPrefix:`research-`,what:`research notes`,onCopy:r,copyAll:!1,children:n===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:h_e(t)}):(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}):(0,h.jsx)(`p`,{className:`text-body text-danger`,children:a.error.message})]})}function h_e(e){switch(e.state){case`failed`:case`canceled`:return`Research stopped before any notes were saved. Try the research again with the next action beside it.`;case`pending`:return`The research runs first; its notes appear here when it finishes.`;default:return`No notes were written.`}}var g_e=[{segment:`intro`,name:`Intro`},{segment:`body`,name:`Body`},{segment:`outro`,name:`Outro`}];function P8(e){let t=/\.([a-z0-9]+)$/i.exec(e.path);return t===null?``:` (.${(t[1]??``).toLowerCase()})`}function __e(e,t=[],n){return[...v_e(e,t),...n===void 0?[]:[{output:n,label:`Script by speaker${P8(n)}`}]]}function v_e(e,t){return g_e.flatMap(({segment:n,name:r})=>{let i=t=>e.find(e=>e.role===t&&e.meta.segment===n),a=t.find(e=>e.segment===n)?.output,o=i(`narration_txt`),s=i(`tts_script`);return[...a===void 0?[]:[{output:a,label:`${r} narration${P8(a)}`}],...o===void 0?[]:[{output:o,label:`${r} clean narration${P8(o)}`}],...s===void 0?[]:[{output:s,label:`${r} TTS script${P8(s)}`}]]})}function y_e(e){return e.some(e=>e.role===`narration_txt`||e.role===`tts_script`)}function F8(e){let{api:t}=z();return(N({queryKey:M3(e),queryFn:()=>Tme(t,e)}).data??[]).filter(e=>e.current)}function I8(e,t){return e.find(e=>t.itemKey===void 0?t.outputId!==void 0&&e.outputId===t.outputId:e.itemKey===t.itemKey)}function b_e(e){return e.passed?e.attempt>1?{label:`Redone after review`,tone:`info`}:{label:`Review passed`,tone:`neutral`}:e.action===`overruled`?{label:`Accepted by you`,tone:`neutral`}:e.action===`redone`?{label:`Being made again`,tone:`running`}:e.redoState===`pending`?{label:`Waiting to be made again`,tone:`running`}:e.redoState===`started`?{label:`Being made again`,tone:`running`}:{label:`Flagged by review`,tone:`info`}}function x_e({review:e}){let t=b_e(e);return(0,h.jsx)(vS,{tone:t.tone,children:t.label})}function L8({review:e}){return(0,h.jsx)(x_e,{review:e})}function R8({review:e}){return(0,h.jsxs)(h.Fragment,{children:[e.reasons.length===0?(0,h.jsx)(`p`,{className:`m-0`,children:`The reviewer found nothing to fix.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-4`,children:e.reasons.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:e.outcome===`flagged`&&!e.passed&&e.attempt>1?`Kept after ${String(e.attempt)} tries: the redo limit was reached.`:`Try ${String(e.attempt)}.`}),e.redoState===`failed`&&e.redoError?(0,h.jsx)(`p`,{className:`m-0 text-danger`,children:e.redoError}):null]})}function z8({review:e,projectId:t,busy:n}){let{api:r}=z(),i=_(),[a,o]=(0,m.useState)(null),s=P({mutationFn:async n=>{let a=i.getQueryData(B.project(t))?.revisionId;return Eme(r,t,e.id,n,n===`redo`&&a?{baseRevisionId:a,idempotencyKey:crypto.randomUUID()}:void 0)},onSuccess:async e=>{o(e.ok?null:e.message),await i.invalidateQueries({queryKey:M3(t)}),await i.invalidateQueries({queryKey:B.project(t)})},onError:e=>o(e.message)});if(e.passed||e.action!==null)return null;let c=e.redoState===`pending`,l=c||e.redoState===`started`;return(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n&&!c||e.redoState===`started`||s.isPending,disabledReason:e.redoState===`started`?`Slopify is already making this item again; wait for the new version`:`Wait until the work on this project is done`,onClick:()=>s.mutate(`overrule`),children:`Overrule`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n||l||s.isPending,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.mutate(`redo`),children:`Redo`}),a?(0,h.jsx)(`span`,{role:`alert`,className:`basis-full text-small text-danger`,children:a}):null]})}function B8({review:e,projectId:t,busy:n}){return e===void 0?null:(0,h.jsxs)(`section`,{"aria-label":`${Tk[e.stage]} review`,className:`flex min-w-0 flex-col gap-1 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsx)(z8,{review:e,projectId:t,busy:n})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-1 text-ink-2`,children:(0,h.jsx)(R8,{review:e})})]})}function V8({review:e}){return e===void 0||e.passed&&e.attempt<=1?null:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{type:`button`,"aria-label":`About this review`,className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Cc,{"aria-hidden":`true`,className:`size-[15px]`})}),(0,h.jsx)(Eb,{className:`space-y-2 leading-[1.45]`,children:(0,h.jsx)(R8,{review:e})})]})]})}function S_e(e){let t=[e.stage,e.companion].filter(e=>e!==void 0);for(let e of[`failed`,`canceled`,`running`]){let n=t.find(t=>t.state===e);if(n!==void 0)return n}return e.stage.state===`skipped`&&e.companion!==void 0?e.companion:e.stage}var H8=e=>e.state!==`pending`&&e.state!==`skipped`;function C_e(e){return e.replace(/^\s*[^\n]*\n?/u,``).trim()}function w_e({stage:e,companion:t,project:n,outputs:r,busy:i}){let a=F8(n.id),o=k3(n.id),s=f8(r,e),c=t?.kind===`research`?t:void 0,l=c===void 0?[]:f8(r,c),u=p8(l,`notes`),d=M8(u),f=p8(s,`article_md`)??p8(s,`article_txt`),p=p8(s,`sources`),g=p8(s,`glossary`),_=HA(n.config)?n.config.voices:void 0,v=p8(s,`script_md`),y=M8(v),b=M8(f),x=N({queryKey:A3(n.id,o),queryFn:()=>[],enabled:!1}).data?.some(e=>e.stage===`article`)===!0,S=N({queryKey:B.article(n.id,o),queryFn:()=>``,enabled:!1}),C=b.data??``,w=e.state===`running`,T=c_e(w?S.data??``:C),E=T.title??n.title,D=(0,m.useMemo)(()=>w?{body:T.body,sources:``,glossary:``}:d8(T.body),[w,T.body]),O=(0,m.useMemo)(()=>Rge(D.sources),[D.sources]),k=C_e(D.glossary),A=(0,m.useMemo)(()=>{if(D.glossary.trim()===``)return[];let e=c6(D.glossary);return e.ok?e.skipped??[]:[]},[D.glossary]),ee=_===void 0||w?``:_.source===`script`?d8(C).body:y.data??``,te=[{id:`article`,label:_?.source===`script`?`Script text`:`Article`},...ee.trim()===``?[]:[{id:`script`,label:`Speakers`}],...c===void 0?[]:[{id:`research`,label:`Research`}],...O.length>0?[{id:`sources`,label:`Sources`,badge:String(O.length)}]:[],...k===``?[]:[{id:`pronunciation`,label:`Pronunciation`}]],ne=c!==void 0&&S_e({kind:`article`,stage:e,companion:c})===c,[j,re]=(0,m.useState)(),M=j??(ne?`research`:`article`),ie=te.some(e=>e.id===M)?M:`article`,ae=(0,m.useId)().replace(/:/gu,``),[oe,se]=(0,m.useState)(),ce={article:`${T.title===void 0?``:`# ${T.title}\n\n`}${D.body.trim()}\n`,script:`${ee.trim()}\n`,research:`${(d.data??``).trim()}\n`,sources:`${O.map(e=>`- ${e}`).join(`
287
+ `)}\n`,pronunciation:`${k}\n`},le={article:`article`,script:`script`,research:`research notes`,sources:`sources`,pronunciation:`pronunciation table`},ue=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>se({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),de=e=>ue(ce[e],le[e]);return(0,h.jsxs)(w8,{children:[(0,h.jsx)(B8,{review:I8(a,{itemKey:`article:body`}),projectId:n.id,busy:i}),(0,h.jsxs)(A8,{files:[...f===void 0?[]:[{output:f,label:`Article${P8(f)}`}],...p===void 0?[]:[{output:p,label:`Sources${P8(p)}`}],...g===void 0?[]:[{output:g,label:`Pronunciation glossary${P8(g)}`}],...u===void 0?[]:[{output:u,label:`Research notes${P8(u)}`}],...v===void 0?[]:[{output:v,label:`Script by speaker${P8(v)}`}]],children:[(ie===`research`?c?.state===`running`||d.data===void 0:w||C===``)?null:(0,h.jsxs)(R,{variant:`secondary`,onClick:()=>de(ie),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy `,le[ie]]}),ie===`research`&&c!==void 0?(0,h.jsx)(N8,{output:p8(l,`instructions`)}):(0,h.jsx)(N8,{output:p8(s,`instructions`)}),(0,h.jsx)(Q1,{tone:oe?.tone??`info`,children:oe?.text})]}),b.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:b.error.message}),te.length>1?(0,h.jsx)(r0,{items:te,value:ie,onChange:e=>{re(e),se(void 0)},label:`Article parts`,idPrefix:ae}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3 font-semibold text-ink`,children:(0,h.jsx)(o_e,{markdown:E})}),D.body.trim()===``?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:T_e(D.body)})]}),(0,h.jsx)(i0,{idPrefix:ae,id:`article`,active:ie===`article`,children:w?(0,h.jsx)(`section`,{"aria-label":`Article content`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:x?(0,h.jsx)(j3,{projectId:n.id,stage:`article`,className:``}):(0,h.jsx)(D8,{markdown:D.body})}):(0,h.jsx)(CB,{markdown:D.body,label:`Article`,regionLabel:`Article content`,anchorPrefix:`article-`,what:`article`,onCopy:ue,copyAll:!1,children:H8(e)&&f!==void 0&&b.data===void 0?(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:H8(e)?`No article was saved.`:c===void 0?`The article will be written when its inputs are ready.`:`The article is written once the research has finished.`})})}),_===void 0||ee.trim()===``?null:(0,h.jsx)(i0,{idPrefix:ae,id:`script`,active:ie===`script`,children:(0,h.jsx)(`section`,{"aria-label":`Script by speaker`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:(0,h.jsx)(e_e,{script:ee,voices:_})})}),c===void 0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`research`,active:ie===`research`,children:(0,h.jsx)(m_e,{projectId:n.id,stage:c,notes:u,onCopy:ue})}),O.length===0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`sources`,active:ie===`sources`,children:(0,h.jsx)(CB,{markdown:O.map((e,t)=>`${String(t+1)}. ${e}`).join(`
288
+ `),label:`Sources`,regionLabel:`Sources`,anchorPrefix:`sources-`,what:`sources`,onCopy:ue,copyAll:!1})}),k===``?null:(0,h.jsxs)(i0,{idPrefix:ae,id:`pronunciation`,active:ie===`pronunciation`,children:[A.length===0?null:(0,h.jsxs)(SI,{className:`mb-3`,title:`${A.length===1?`1 entry is`:`${A.length} entries are`} skipped by the narration and read as ordinary text`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:A.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsx)(`p`,{className:`m-0 mt-1`,children:`The other entries are used. To fix these, edit the Pronunciation Glossary at the end of the article in Edit settings → Article.`})]}),(0,h.jsx)(`div`,{className:`sl-stage-scroll pr-3`,children:(0,h.jsx)(D8,{markdown:k})})]})]})}var U8=new Intl.NumberFormat(`en`);function T_e(e){let t=e.replace(/\]\([^)]*\)/g,`]`).replace(/[#*_>`[\]]/g,``).replace(/[ \t]+/g,` `).trim(),n=t.split(/\s+/).filter(e=>/[\p{L}\p{N}]/u.test(e)).length,r=t.replace(/\s*\n\s*/g,` `).length;return`${U8.format(n)} ${n===1?`word`:`words`} · ${U8.format(r)} characters`}function W8({className:e,label:t,children:n}){return(0,h.jsx)(`dl`,{"aria-label":t,className:L(`m-0 grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[max-content_minmax(0,1fr)] sm:gap-y-3`,e),children:n})}function G8({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2 max-sm:mt-2 max-sm:first:mt-0`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function K8({src:e,label:t,marks:n=[],waveform:r,compact:i=!1,preload:a=`metadata`,onError:o,ref:s,className:c}){let l=A0(),u=l.media;return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`${t} controls`,"data-slot":`audio-player`,"data-state":l.playing?`playing`:`paused`,className:L(`sl-audio`,i&&`sl-audio--compact`,r!==void 0&&r.length>0&&`sl-audio--wave`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.key===` `&&e.target.closest(`button`)!==null)return;let t=l.keyAction(e.key);t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||l.setMenu(!1)},children:[(0,h.jsx)(`audio`,{ref:O0(u,s),src:e,preload:a,"aria-label":t,onError:o,...l.events}),(0,h.jsx)(N0,{controls:l,className:`sl-audio__key`}),(0,h.jsx)(P0,{controls:l}),(0,h.jsx)(F0,{controls:l,chapters:n,waveform:r}),(0,h.jsx)(I0,{controls:l}),(0,h.jsx)(L0,{controls:l})]})}function q8({projectId:e,revisionId:t}){let n=k3(e),r=t===void 0?n:t,{api:i}=z(),a=N({queryKey:B.audioPreview(e,r),queryFn:async()=>F(await i.client.projects[`:projectId`][`audio-preview`].$get({param:{projectId:e}})),refetchInterval:1e3,staleTime:0,gcTime:0,retry:!1}),o=(a.data?.revisionId??null)===r?a.data?.previews??[]:[];return(0,h.jsxs)(`section`,{"aria-label":`Live narration`,className:`grid gap-3 border-y border-line py-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-ink`,children:`Listen while it generates`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Play any part. Each preview starts from its beginning.`})]}),a.error===null?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Live preview is temporarily unavailable. Finished audio will still appear here.`}),o.length===0&&a.error===null?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Waiting for the first audio bytes…`}):null,(0,h.jsx)(`div`,{className:`grid max-h-[420px] gap-3 overflow-y-auto`,children:o.map(t=>(0,h.jsx)(E_e,{preview:t,url:`${i.origin}/api/projects/${encodeURIComponent(e)}/audio-preview/${t.id}`},t.id))})]})}function E_e({preview:e,url:t}){let[n,r]=(0,m.useState)(!1),i=(e.state===`streaming`||e.state===`ready`)&&e.bytes>0,a=e.state===`ready`?`Ready`:e.state===`streaming`?`Generating`:`Preview stopped`;return(0,h.jsxs)(`div`,{className:`grid gap-2 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:e.label}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:a})]}),i&&!n?(0,h.jsx)(D_e,{label:e.label,url:t,onError:()=>r(!0)}):(0,h.jsx)(`p`,{className:`text-ink-2`,children:e.state===`streaming`&&!n?`Waiting for audio…`:`This preview has stopped. The finished narration will be available when generation completes.`})]})}function D_e({label:e,url:t,onError:n}){let r=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=r.current;return()=>{e!==null&&(e.pause(),e.removeAttribute(`src`),e.load())}},[]),(0,h.jsx)(K8,{ref:r,compact:!0,preload:`none`,label:`Live ${e} narration`,src:t,onError:n,className:`max-w-[620px]`})}function O_e({outputs:e}){let t=(0,m.useId)(),n=t=>e.find(e=>e.role===`narration_txt`&&e.meta.segment===t),r=M8(n(`intro`)).data,i=M8(n(`body`)).data,a=M8(n(`outro`)).data,[o,s]=(0,m.useState)(),c=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>s({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),l=[[`Intro`,r],[`Body`,i],[`Outro`,a]].filter(([,e])=>e!==void 0&&e.trim()!==``);if(!e.some(e=>e.role===`narration_txt`))return null;let u=l.length===1?(l[0]?.[1]??``).trim():l.map(([e,t])=>`## ${e}\n\n${(t??``).trim()}`).join(`
289
289
 
290
- `);return(0,h.jsxs)(`section`,{"aria-labelledby":`${t}-title`,className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`h3`,{id:`${t}-title`,className:`sl-kicker text-ink-3`,children:`Narration text`}),(0,h.jsx)(CB,{markdown:u,label:`Narration text`,regionLabel:`Narration text`,anchorPrefix:`narration-`,what:`narration text`,onCopy:c,children:(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}),(0,h.jsx)(Q1,{tone:o?.tone??`info`,children:o?.text})]})}var J8=(0,m.createContext)(!1),Y8=(0,m.createContext)(void 0),X8=(0,m.createContext)(void 0);function Z8(e){let t=y8();return e===void 0?!1:t?.outputs.some(t=>t.output.id===e.id&&t.state===`outdated`)??!1}function Q8(e,t,n){let[r,i]=(0,m.useState)(),a=(0,m.use)(J8),o=(0,m.use)(Y8),s=(0,m.use)(X8),c=y8(),l=e===void 0?void 0:c?.outputs.find(t=>t.output.id===e.id)?.workKey,u=a&&l!==void 0;return{act:t=>{if(e===void 0)return;if(!u||l===void 0||t===`regenerate-image`){i(t);return}if(!l.startsWith(`image:`))return;let n=l.slice(6);o?.({section:`images`,change:e=>({...e,content:{...e.content,imageOrder:e.content.imageOrder.filter(e=>e!==n),imageDefinitions:Object.fromEntries(Object.entries(e.content.imageDefinitions).filter(([e])=>e!==n))},regenerate:(e.regenerate??[]).filter(e=>e!==l)})})},asking:r,confirm:()=>{let n=r;i(void 0),n!==void 0&&e!==void 0&&(u&&l!==void 0&&n===`regenerate-image`?s?.([l]):t.run({kind:n,outputId:e.id}))},dismiss:()=>i(void 0),unavailable:e===void 0||n||t.pending||u&&(o===void 0||s===void 0),viaEdit:u,now:u,ready:!a||c!==void 0}}function O_e(e,t){let[n,r]=(0,m.useState)(!1),i=(0,m.use)(J8),a=(0,m.use)(X8),o=y8();if(!i||o===void 0)return;let s=new Set(e.map(e=>e.id)),c=o.outputs.flatMap(e=>s.has(e.output.id)&&e.workKey.startsWith(`image:`)?[e.workKey]:[]);if(c.length!==0)return{count:c.length,asking:n,act:()=>r(!0),confirm:()=>{r(!1),a?.(c)},dismiss:()=>r(!1),unavailable:t||a===void 0}}var k_e=200,A_e=q({seconds:G(),peaks:K(G())});function j_e(e){if(e===void 0)return;let t;try{t=new URL(e,window.location.href)}catch{return}if(t.pathname.startsWith(`/files/`))return t.searchParams.set(`waveform`,String(k_e)),t.toString()}function M_e(e){let{api:t}=z(),n=j_e(e);return N({queryKey:[`waveform`,n],enabled:n!==void 0,staleTime:1/0,retry:!1,queryFn:async()=>{if(n===void 0)return[];let e=await t.fetch(n);if(!e.ok)throw po(e,void 0);let{peaks:r}=So(A_e,await e.json()),i=Math.max(0,...r);return i===0?[]:r.map(e=>e/i)}}).data}function $8(e){return(0,h.jsx)(K8,{...e,waveform:M_e(e.src)})}var e5=[{role:`audio_intro`,segment:`intro`,name:`Intro`},{role:`audio_body`,segment:`body`,name:`Body`},{role:`audio_outro`,segment:`outro`,name:`Outro`}];function N_e({stage:e,project:t,outputs:n,busy:r}){let{api:i}=z(),a=N(tb(i)),o=F8(t.id),s=f8(n,e),c=s.filter(e=>e.role===`audio_levelled`),l=e5.flatMap(e=>{let t=p8(s,e.role),n=c.find(t=>t.meta.segment===e.segment)??t;return n===void 0?[]:[{...e,output:n,...t===void 0||t===n?{}:{plain:t}}]}),u=e5.flatMap(e=>{let t=c.find(t=>t.meta.segment===e.segment)?.meta.loudness;return t===void 0?[]:[{name:e.name,report:t}]}),d=l.find(e=>e.output.meta.voice!==void 0)?.output.meta,f=l.length>0?d?.voice:t.config.audio?.voice,p=l.length>0?d?.provider:t.config.audio?.provider,m=a.data?.voices.find(e=>e.voiceId===f&&e.provider===p)?.name??f;return(0,h.jsxs)(w8,{children:[e.state===`running`?(0,h.jsx)(q8,{projectId:t.id}):null,l.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No narration has landed yet.`}):l.map(e=>(0,h.jsx)(P_e,{name:e.name,output:e.output,...e.plain===void 0?{}:{plain:e.plain}},e.role)),(0,h.jsx)(A8,{files:g_e(s,l,n.find(e=>e.role===`script_md`))}),u.length===0?null:(0,h.jsx)(j8,{children:u.map(({name:e,report:t})=>u.length===1?mk(t):`${e}: ${mk(t)}`).join(` `)}),(0,h.jsxs)(W8,{label:`How it was recorded`,children:[m===void 0?null:(0,h.jsx)(G8,{label:`Voice`,children:m}),(0,h.jsx)(G8,{label:`Chunking`,children:F_e(I_e(t.config.chunking))}),v_e(s)?(0,h.jsx)(G8,{label:`Text files`,children:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Clean narration is the spoken text used for captions. The TTS script adds delivery cues, with a blank line between requests. Uploaded audio has no TTS request.`})}):null]}),(0,h.jsx)(B8,{review:I8(o,{itemKey:`narration`}),projectId:t.id,busy:r}),(0,h.jsx)(D_e,{outputs:s})]})}function P_e({name:e,output:t,plain:n}){let r=b8(t),i=Z8(t),a=Z8(n)||n===void 0?void 0:n,o=b8(i?a:void 0);return(0,h.jsxs)(`div`,{className:`grid grid-cols-[64px_minmax(0,1fr)] items-center gap-3 text-small`,children:[(0,h.jsx)(T8,{children:e}),(0,h.jsx)($8,{label:`${e} narration`,src:r?.url,className:`max-w-[640px]`}),i?(0,h.jsx)(`p`,{className:`col-start-2 m-0 text-small text-ink-2`,children:a===void 0?`Outdated: this is the narration from before your last change. The new one is made when the run carries on: press Continue the run, or Remake at the top of the page.`:`Outdated: this is the levelled narration from before your last change. The new narration is below as it was spoken; it is levelled when the run carries on: press Continue the run, or Remake at the top of the page.`}):null,i&&a!==void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(T8,{children:`New`}),(0,h.jsx)($8,{label:`${e} narration, new, before levelling`,src:o?.url,className:`max-w-[640px]`})]}):null]})}function F_e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function I_e(e){return e===void 0||e.mode===`whole`?`the whole text as one request`:e.mode===`paragraph`?`one request per paragraph`:e.mode===`characters`?`every ${String(e.characters??3e3)} characters`:`every ${String(e.words??500)} words`}function L_e({stage:e,project:t,outputs:n}){let r=p8(f8(n,e),`document_pdf`),i=b8(r),a=XS(t.config.document);return(0,h.jsxs)(w8,{children:[r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The PDF will be saved when rendering finishes.`:`No PDF has been saved yet.`}):(0,h.jsx)(A8,{files:[{output:r,label:`PDF`}],label:`Download PDF`,children:i?.folder?(0,h.jsxs)(mS,{href:`${i.url}?inline=1`,target:`_blank`,rel:`noopener`,variant:`secondary`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open PDF`]}):null}),(0,h.jsx)(W8,{label:`PDF details`,children:(0,h.jsx)(G8,{label:`Theme`,children:a})})]})}var R_e={research:`Generates fresh research and affected article, narration, entries, thumbnail and exports; previous outputs stay in History.`,article:`Generates a fresh article and affected narration, entries, thumbnail and exports; previous outputs stay in History.`,audio:`Regenerates narration and affected exports, keeping compatible cue preparation; previous outputs stay in History.`,images:`Regenerates generated images and affected video, keeping supplied images and narration; previous outputs stay in History.`,thumbnail:`Regenerates the thumbnail without changing the main video; previous outputs stay in History.`,video:`Rebuilds local exports from saved media without regenerating narration or images; previous outputs stay in History.`,document:`Renders the PDF again from the saved article and title without regenerating anything else; previous outputs stay in History.`};function t5(e){switch(e.kind){case`cancel`:return{title:`Cancel this run?`,consequence:`Stops every running stage; finished outputs are kept.`,verb:`Cancel run`,dismiss:`Keep running`};case`rerun`:return{title:`Re-run this stage?`,consequence:R_e[e.stage],verb:`Re-run`,dismiss:`Cancel`};case`delete-image`:return{title:`Delete this image?`,consequence:`Removes the image and re-renders video when enabled.`,verb:`Delete`,dismiss:`Cancel`};case`regenerate-image`:return{title:`Regenerate this image?`,consequence:e.now?`Makes a new image now, one paid image call. The video keeps the current one until you remake it; the old image stays in History.`:`Replaces the image with a new one and re-renders video when enabled.`,verb:`Regenerate`,dismiss:`Cancel`};case`save-article`:return{title:`Save the edited article?`,consequence:`Replaces the article, then updates the enabled narration and final export.`,verb:`Save & update outputs`,dismiss:`Cancel`};case`discard-article`:return{title:`Discard these edits?`,consequence:`The article goes back to the text on disk.`,verb:`Discard`,dismiss:`Keep editing`}}}function z_e(e,t){let{config:n,content:r,fingerprints:i}=e.revision;switch(t){case`research`:return n.sources.research===`generate`;case`article`:return n.sources.article===`generate`&&!r.articleEdited;case`audio`:return n.sources.audio===`generate`&&Object.keys(i).some(e=>!/^audio:(body:.+|intro|outro):[0-9]+$/.test(e)&&!/^audio:(body|intro|outro):future$/.test(e)?!1:!Object.entries(r.narrationOverrides).some(([t,n])=>n.kind===`asset`&&(e===t||e.startsWith(`${t}:`))));case`images`:return n.sources.images!==`off`&&r.imageOrder.some(e=>r.imageDefinitions[e]?.source===`generate`);case`thumbnail`:return n.sources.thumbnail===`from_prompt`||n.sources.thumbnail===`prompt_by_llm`;case`video`:return n.sources.video!==`off`||n.sources.audio!==`off`;case`document`:return RS(n.sources,`document`)===`generate`}}function n5(e){switch(e){case`research`:case`article`:return`article`;case`audio`:return`narration`;case`images`:case`thumbnail`:return`images`;case`video`:return`video`;case`document`:return`document`}}var r5={research:`Research`,article:`Article`,audio:`Narration`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`PDF`},i5=e=>/^[A-Z]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1);function B_e(e){let{project:t,stages:n}=e,r=t.config,i=e=>e===`video`&&rF(r)===`audio`?`Audio export`:r5[e];if(e.sample)return{situation:`sample`,tone:`info`,status:`Sample project`,title:`This is the sample project, finished and free to explore.`,why:`It is read-only. Your own copy can be edited and made again.`,action:{label:`Make my own copy`,intent:{kind:`copy-sample`}}};if(t.status===`paused`){let t=G_e(e.outdated);return{situation:`paused`,tone:`waiting`,status:`Paused`,title:`The run is paused.`,why:t===void 0?`Everything made so far is kept. Continuing picks up where it stopped.`:`Everything made so far is kept. Still to make: ${t}. They stay outdated until you continue.`,action:{label:`Continue the run`,intent:{kind:`resume`}}}}let a=n.find(e=>e.state===`failed`&&e.retryAt===void 0);if(a!==void 0){let t=i(a.kind),n=e.fixOf(a),r={label:`Try ${i5(a5(t))} again`,intent:{kind:`retry`,stage:a.kind}},o={situation:`failed`,tone:`failed`,status:`Failed`,section:n5(a.kind),...a.failureReason===null?{}:{detail:a.failureReason}};switch(n?.kind){case`sign-in`:return{...o,title:`${n.label.replace(/^Sign in to /,``)} is signed out, so ${i5(a5(t))} stopped.`,why:`Copy the sign-in command (${n.command}), run it in a terminal on the computer running Slopify and sign in, then press Check again. Once ${n.label.replace(/^Sign in to /,``)} is signed in, Slopify tries ${i5(a5(t))} again.`,action:{label:`Copy sign-in command`,intent:{kind:`sign-in`,stage:a.kind,fix:n}}};case`refused`:return{...o,title:`A content filter refused a prompt, so ${i5(a5(t))} stopped.`,why:n.soften?`Softening rewrites each refused prompt without what the filter flagged, then draws it again.`:`Change the prompt in the project settings, then try again.`,action:n.soften?{label:n.label,intent:{kind:`soften`,stage:a.kind}}:{label:`Edit the prompt`,intent:{kind:`edit`}}};case`switch-model`:return{...o,title:`The model for ${i5(a5(t))} is no longer offered.`,why:`Pick another model in the project settings, then try again.`,action:{label:`Switch model`,intent:{kind:`edit`}}};case`provider-settings`:return{...o,title:`The provider did not accept its key, so ${i5(a5(t))} stopped.`,why:`Check the key in Settings, then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`providers`}}};case`free-space`:return{...o,title:`The disk is full, so ${i5(a5(t))} stopped.`,why:`Storage in Settings shows what can go. Then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`storage`}}};case void 0:return{...o,title:`${t} stopped with an error.`,why:`Trying again keeps everything already made.`,action:r}}}let o=e.held[0];if(o!==void 0){let e=i(o.stage);return{situation:`held`,tone:`waiting`,status:`Waiting for you`,title:`The ${i5(e)} ${U_e(e)} ready for your review.`,why:o.dependents.length===0?`Approving marks it reviewed.`:`Approving lets ${o5(o.dependents.map(e=>i5(a5(i(e)))))} run. Nothing after it runs until you do.`,action:{label:V_e(o,i),intent:{kind:`approve`,gate:o}},section:n5(o.stage)}}let s=n.find(e=>e.state===`failed`&&e.retryAt!==void 0),c=e.waits[0];if(c!==void 0||s!==void 0){if(c!==void 0){let t=XH(e.waits);return{situation:`waiting`,tone:`waiting`,status:`Waiting for limits`,title:`${YH(e.waits,e.clock)??``}.`,why:`Nothing to do: the run carries on by itself when they reset, and work that does not need ${t} keeps going.`,section:n5(c.stage)}}if(s!==void 0)return{situation:`waiting`,tone:`waiting`,status:`Waiting to try again`,title:`${i(s.kind)} will try again by itself at ${e.clock(s.retryAt??``)}.`,why:`Nothing to do: the run carries on when it does.`,section:n5(s.kind),...s.failureReason===null?{}:{detail:s.failureReason}}}let l=n.find(e=>e.state===`running`);if(t.status===`running`||l!==void 0)return{situation:`running`,tone:`running`,status:`Running`,title:l===void 0?`The run is starting.`:`Making the ${i5(i(l.kind))}${H_e(l)}.`,why:`Pausing lets the current call finish and keeps everything made so far.`,action:{label:`Pause`,intent:{kind:`pause`}},...l===void 0?{}:{section:n5(l.kind)}};if(e.resumable||t.status===`canceled`||t.status===`failed`&&a===void 0)return{situation:`stopped`,tone:`off`,status:t.status===`canceled`?`Canceled`:`Stopped`,title:`The run stopped before it finished.`,why:`Continuing makes only what is missing; everything made so far is kept.`,action:{label:`Continue the run`,intent:{kind:`resume`}}};if(t.status===`pending`)return{situation:`queued`,tone:`off`,status:`Queued`,title:`Waiting for its turn.`,why:`It starts by itself when the videos ahead of it are done.`};let u=W_e(e.outdated);if(u!==void 0)return{situation:`outdated`,tone:`info`,status:`Outdated`,title:u.count===1||u.singular?`The ${u.noun} ${u.noun.endsWith(`s`)?`are`:`is`} outdated after your edit.`:`${String(u.count)} ${u.plural} are outdated after your edit.`,why:`They keep their current version until you remake them. Nothing else is made again.`,action:{label:u.count===1||u.singular?`Remake the outdated ${u.noun}`:`Remake ${String(u.count)} outdated ${u.plural}`,intent:{kind:`remake`,workKeys:u.workKeys}},section:u.section};if(t.status===`done`&&r.mode===`short`)return{situation:`done`,tone:`done`,status:`Done`,title:`The short is ready.`,why:`Play opens set up for a long video on the same topic, with the same starter pack and providers. Nothing starts until you press Play.`,action:{label:`Make the full video on this topic`,intent:{kind:`full-video`}}};if((t.status===`done`||t.status===`partial`)&&e.uploadReady)return{situation:`done`,tone:`done`,status:`Done`,title:`The video is ready.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}}function V_e(e,t){if(e.dependents.includes(`video`))return`Approve and render the video`;if(e.dependents.includes(`images`))return`Approve and make the images`;if(e.dependents.includes(`audio`))return`Approve and record the narration`;let n=e.dependents[0];return n===void 0?`Approve the ${i5(t(e.stage))}`:`Approve and make the ${i5(t(n))}`}function H_e(e){let t=lF(e);return t===void 0?e.progressTotal===null||e.progressTotal<=0?``:` · ${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)}`:` · ${t}`}function a5(e){return/s$/i.test(e)?e:`the ${i5(e)}`}function U_e(e){return/s$/i.test(e)?`are`:`is`}function o5(e){return e.length<=1?e[0]??``:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`}var s5=[{id:`article`,noun:`article`,plural:`article files`,singular:!0,section:`article`,roles:[`notes`,`sources`,`article_md`,`article_txt`,`script_md`],counted:[`article_md`]},{id:`narration`,noun:`narration`,plural:`narration parts`,singular:!0,section:`narration`,roles:[`narration_txt`,`tts_script`,`glossary`,`audio_body`,`audio_intro`,`audio_outro`,`audio_levelled`],counted:[`audio_body`]},{id:`reference`,noun:`establishing image`,plural:`establishing images`,singular:!0,section:`images`,roles:[`reference`],counted:[`reference`]},{id:`images`,noun:`image`,plural:`images`,singular:!1,section:`images`,roles:[`image`],counted:[`image`]},{id:`animated`,noun:`animated image`,plural:`animated images`,singular:!1,section:`images`,roles:[`animated_image`],counted:[`animated_image`]},{id:`thumbnails`,noun:`thumbnail`,plural:`thumbnails`,singular:!1,section:`images`,roles:[`thumbnail`],counted:[`thumbnail`]},{id:`video`,noun:`video`,plural:`video files`,singular:!0,section:`video`,roles:[`video`,`audio_export`,`audio_mp3`,`audio_m4b`,`render_params`,`subtitles_srt`,`subtitles_vtt`,`subtitle_words`,`subtitle_ass`,`subtitle_font`],counted:[`video`,`audio_export`]},{id:`shorts`,noun:`short`,plural:`shorts`,singular:!1,section:`shorts`,roles:[`shorts`,`short_image`,`short_video`],counted:[`short_video`]},{id:`youtube`,noun:`YouTube description`,plural:`YouTube descriptions`,singular:!0,section:`youtube`,roles:[`youtube_description`,`youtube_tags`,`youtube_pinned_comment`,`youtube_titles`],counted:[`youtube_description`]},{id:`document`,noun:`PDF`,plural:`PDFs`,singular:!0,section:`document`,roles:[`document_pdf`],counted:[`document_pdf`]}];function W_e(e){for(let t of s5){let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)continue;let r=n.filter(e=>t.counted.includes(e.role)).length;return{noun:t.noun,plural:t.plural,singular:t.singular,count:Math.max(1,r),workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section}}}function G_e(e){let t=s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[t.singular?`the ${t.noun}`:r===1?`1 ${t.noun}`:`${String(r)} ${t.plural}`]});return t.length===0?void 0:o5(t)}function K_e(e){return s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[{label:r===1||t.singular?`Remake the outdated ${t.noun}`:`Remake ${String(r)} outdated ${t.plural}`,workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section,count:r}]})}function q_e({tone:e,status:t,title:n,why:r,action:i,className:a}){return(0,h.jsxs)(`section`,{"aria-label":`Next action`,className:L(`sl-next`,a),children:[(0,h.jsx)(_S,{tone:e,children:t}),(0,h.jsx)(`p`,{className:`sl-next__title`,children:n}),r===void 0?null:(0,h.jsx)(`p`,{className:`sl-next__why`,children:r}),i===void 0?null:(0,h.jsx)(`div`,{className:`flex flex-col [&>*]:w-full`,children:i})]})}function J_e({project:e,stages:t,resumable:n,sample:r,gates:i,outdated:a,waits:o,uploadReady:s,actions:c,controller:l,openSection:u,openUpload:d}){let{api:f}=z(),p=_(),h=Zi(),[g,v]=(0,m.useState)(),y=(0,m.useRef)(new Map),b=B_e({project:e,stages:t,resumable:n,sample:r,held:i.filter(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint).map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),outdated:a,waits:o,uploadReady:s,fixOf:t=>_3(t,e),clock:fF}),x=P({mutationFn:()=>Wy(f,e.id),onSuccess:async({projectId:e})=>{await p.invalidateQueries({queryKey:B.projects}),await h({to:`/projects/$projectId`,params:{projectId:e}})},onError:e=>v(`${bo(e.message)} The copy was not made. Press Make my own copy to try again.`)}),S=(0,m.useRef)(null),C=nP(),w=P({mutationFn:async()=>{if(C===null)throw Error(`Play isn't available on this page. Reload the page`);if(C.review.starting||C.review.uncertain||C.review.created!==null)throw Error(`Play is starting a run from its open draft. Wait for it to start`);if(!await C.flush())throw Error(`The draft open in Play couldn't be saved. Open Play, save or discard it`);S.current??=crypto.randomUUID();let{draft:t}=await By(f,{projectId:e.id,draftId:S.current});if(await p.invalidateQueries({queryKey:[`play-drafts`]}),!await C.open(t.id))throw Error(`The full video's draft was made but didn't open. Open Play and pick it`);S.current=null,await h({to:`/play`})},onError:e=>v(`${bo(e.message)} Then press Make the full video on this topic again.`)}),T=P({mutationFn:async t=>{let n=i.find(e=>e.checkpointId===t.checkpointId);if(n===void 0)throw Error(`The review changed before it was approved. Reload the page.`);let r=`${n.checkpointId}:${n.fingerprint}`,a=y.current.get(r)??crypto.randomUUID();y.current.set(r,a);let o=await h3(f,e.id,n.checkpointId,{revisionId:n.revisionId,fingerprint:n.fingerprint,idempotencyKey:a});if(y.current.delete(r),!o.ok)throw Error(o.message)},onSettled:async()=>{await p.invalidateQueries({queryKey:d3(e.id)}),await p.invalidateQueries({queryKey:B.project(e.id)}),p.invalidateQueries({queryKey:B.projects})},onError:e=>v(`${bo(e.message)} Press the approve button again to check whether it went through.`)});return{next:b,run:e=>{switch(v(void 0),e.kind){case`copy-sample`:x.mutate();return;case`resume`:case`pause`:c.run({kind:e.kind});return;case`retry`:case`soften`:c.run({kind:e.kind,stage:e.stage});return;case`sign-in`:q1(e.fix.command).then(t=>v(t?`Copied ${e.fix.command}. Run it in a terminal on the computer running Slopify, sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.fix.command} in a terminal, sign in, then press Check again.`));return;case`approve`:T.mutate(e.gate);return;case`remake`:l.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0});return;case`edit`:u(`settings`);return;case`open-settings`:h({to:`/settings`,search:{section:e.section}});return;case`prepare-upload`:d();return;case`full-video`:w.mutate();return}},pending:x.isPending||w.isPending||T.isPending||c.pending||l.pending,message:g}}function Y_e(e){switch(e.kind){case`copy-sample`:return`Copying…`;case`resume`:return`Continuing…`;case`pause`:return`Pausing…`;case`approve`:return`Approving…`;case`remake`:return`Starting the remake…`;case`retry`:return`Trying again…`;case`soften`:return`Softening…`;case`full-video`:return`Opening Play…`;default:return}}function c5({state:e,variant:t,className:n}){let[r,i]=(0,m.useState)(!1),a=e.next?.action;if(a===void 0)return null;let o=a.intent;if(o.kind===`sign-in`)return(0,h.jsx)(J1,{fix:o.fix,variant:t,retry:{run:()=>e.run({kind:`retry`,stage:o.stage}),busy:e.pending}});if(o.kind===`open-settings`)return(0,h.jsx)(fS,{to:`/settings`,search:{section:o.section},variant:t,...n===void 0?{}:{className:n},children:a.label});let s=e.pending?Y_e(o)??a.label:a.label;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:t,className:n,disabled:e.pending,disabledReason:`Working on the last press`,"aria-keyshortcuts":t===`primary`?Mx(lP.nextAction):void 0,onClick:()=>o.kind===`soften`?i(!0):e.run(o),children:s}),o.kind===`soften`?(0,h.jsx)(jy,{open:r,tone:`primary`,title:`Soften the refused prompt and try again?`,consequence:`Your project's AI model rewrites each refused prompt without what a content filter could flag, keeping the scene and style. The image is then drawn again from the new wording, which it keeps as its prompt. The AI call and the new image are charged like any other.`,confirmLabel:`Soften and retry`,cancelLabel:`Keep the prompt`,pending:e.pending,onConfirm:()=>{i(!1),e.run(o)},onCancel:()=>i(!1)}):null]})}function X_e({state:e,feedback:t}){let n=e.next;return n===void 0&&t===void 0&&e.message===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n===void 0?null:(0,h.jsx)(q_e,{tone:n.tone,status:n.status,title:n.title,...n.why===void 0?{}:{why:n.why},...n.action===void 0?{}:{action:(0,h.jsx)(c5,{state:e,variant:`primary`})}}),e.message===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e.message}),t]})}var Z_e={sample:void 0,paused:void 0,stopped:void 0,queued:void 0,running:void 0,failed:`danger`,held:`waiting`,waiting:`waiting`,outdated:`info`,done:void 0};function Q_e({state:e,section:t}){let n=e.next;if(n===void 0||n.section!==t)return null;let r=Z_e[n.situation];return r===void 0?null:(0,h.jsx)(SI,{className:`max-[1180px]:hidden`,tone:r,title:n.title,...n.action===void 0?{}:{actions:(0,h.jsx)(c5,{state:e,variant:`secondary`})},children:n.why===void 0&&n.detail===void 0?void 0:(0,h.jsxs)(h.Fragment,{children:[n.why===void 0?null:(0,h.jsx)(`span`,{className:`block`,children:n.why}),n.detail===void 0?null:(0,h.jsxs)(`details`,{className:`mt-1`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:n.detail})]})]})})}var $_e={research:`Research again`,article:`Write the article again`,audio:`Record the narration again`,images:`Make all images again`,thumbnail:`Make the thumbnails again`,video:`Render the video again`,document:`Render the PDF again`};function l5(e,t){return e===`video`&&t.config.sources.video===`off`?`Export the audio again`:$_e[e]}function u5({id:e,title:t,kicker:n,stages:r,project:i,outputs:a,actions:o,next:s,active:c,meta:l,head:u=!0,extra:d,resumable:f=!1,children:p}){let m=r[0],g=r.some(e=>o.refusal?.stage===e.kind)?o.refusal?.message:void 0,_=r.filter(t=>t.state===`failed`&&t.retryAt===void 0&&(s.next?.situation!==`failed`||s.next.section!==e)),v=r.find(e=>e.state===`running`),y=v===void 0?void 0:dF(v),b=l??(m===void 0?void 0:r.filter(e=>e.state!==`skipped`).map(e=>e===m?cF(e,a,i,f):`${r5[e.kind]}: ${cF(e,a,i,f)}`).join(` · `));return(0,h.jsxs)(`section`,{hidden:!c,"aria-label":t,"data-tour":m===void 0?void 0:`project-${m.kind}`,className:`flex min-w-0 flex-col gap-5`,children:[u?(0,h.jsxs)(H,{row:!0,title:t,...n===void 0?{}:{kicker:n},...b===void 0||b===``?{}:{meta:b},children:[d,(0,h.jsx)(f5,{stages:r,project:i,actions:o})]}):null,y===void 0||v===void 0?null:(0,h.jsx)(q2,{value:y,label:`${r5[v.kind]} progress`,valueText:cF(v,a,i,f)}),(0,h.jsx)(Q_e,{state:s,section:e}),_.map(e=>(0,h.jsx)(SI,{tone:`danger`,title:`${r5[e.kind]} stopped with an error.`,children:e.failureReason===null?void 0:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.failureReason})]})},e.id)),g===void 0?null:(0,h.jsx)(SI,{tone:`danger`,title:g,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:o.dismissRefusal,children:`Dismiss`})}),m?.state===`running`&&m.kind!==`article`&&m.kind!==`images`&&m.kind!==`video`&&m.kind!==`document`?(0,h.jsx)(j3,{projectId:i.id,stage:m.kind}):null,p]})}function d5({stage:e,project:t,name:n}){return e===void 0||e.state===`skipped`?(0,h.jsx)(a0,{title:`${n} is off for this run.`,children:`Switch it on in the project settings to make it.`}):(0,h.jsx)(a0,{title:`No ${n.toLowerCase()} yet.`,children:t.status===`paused`?`It is made once you continue the run.`:`It starts when the steps before it are done. Finished work elsewhere can be looked at meanwhile.`})}function f5({stages:e,project:t,actions:n}){let r=(0,m.useContext)(J8),i=y8(),[a,o]=(0,m.useState)(),s=e.filter(e=>e.state!==`skipped`&&e.state!==`pending`&&(!r||i!==void 0&&z_e(i,e.kind)));if(s.length===0)return null;let c=n.pending||t.status===`running`||e.some(e=>e.state===`running`),l=a===void 0?void 0:t5({kind:`rerun`,stage:a});return(0,h.jsxs)(h.Fragment,{children:[s.map(e=>(0,h.jsxs)(R,{size:`small`,disabled:c,disabledReason:`Wait until the work on this project is done`,onClick:()=>o(e.kind),children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),l5(e.kind,t)]},e.id)),(0,h.jsx)(jy,{open:a!==void 0,title:a===void 0?``:`${l5(a,t)}?`,consequence:l?.consequence??``,confirmLabel:a===void 0?``:l5(a,t),cancelLabel:`Keep what is there`,pending:n.pending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&n.run({kind:`rerun`,stage:e})},onCancel:()=>o(void 0)})]})}function eve({stage:e,project:t,outputs:n,actions:r,busy:i}){let a=f8(n,e),o=F8(t.id),s=VS(t.config),c=Array.from({length:s},(e,t)=>t+1).map(e=>({variant:e,output:a.find(t=>t.role===`thumbnail`&&(t.meta.index??1)===e)})),l=c.flatMap(e=>e.output===void 0?[]:[e.output]),u=x8(l),[d,f]=(0,m.useState)(null),p=l.filter(e=>u.has(e.id)),g=p.map(e=>({src:u.get(e.id)?.url??``,alt:`Thumbnail ${String(e.meta.index??1)}`})),_=t.format===`9:16`,v=({variant:n,output:a})=>(0,h.jsx)(tve,{variant:n,count:s,output:a,review:I8(o,{outputId:a?.id}),stage:e,project:t,actions:r,busy:i,onOpen:()=>f(a===void 0?null:nve(p,a))},n);return(0,h.jsxs)(`section`,{"aria-label":s===1?`Thumbnail`:`Thumbnails`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:s===1?`Thumbnail`:`Thumbnails`,meta:s===1?`The picture YouTube shows before the video plays`:`${String(s)} variants for YouTube's Test & compare`,children:[(0,h.jsx)(O8,{variant:`secondary`,files:l.map(e=>({output:e,label:s===1?`Thumbnail`:`Thumbnail ${String(e.meta.index??1)}`}))}),(0,h.jsx)(k8,{output:l[0]}),(0,h.jsx)(f5,{stages:[e],project:t,actions:r})]}),c.length===1?(0,h.jsx)(`div`,{className:_?`max-w-[280px]`:`max-w-[480px]`,children:c.map(v)}):(0,h.jsx)(B0,{list:!0,label:`Thumbnail variants`,children:c.map(e=>(0,h.jsx)(`li`,{className:`min-w-0`,children:v(e)},e.variant))}),(0,h.jsx)(V0,{items:g,index:d,onIndex:f,onClose:()=>f(null),actions:(e,t)=>{let n=p[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:s===1?`the thumbnail`:`thumbnail ${String(n.meta.index??1)}`,actions:r,busy:i},n.id)}})]})}function tve({variant:e,count:t,output:n,review:r,stage:i,project:a,actions:o,busy:s,onOpen:c}){let l=b8(n),u=Q8(n,o,s),d=t===1?`the thumbnail`:`thumbnail ${String(e)}`;bx({id:`project.thumbnail.${String(e)}`,title:t===1?`Regenerate the thumbnail`:`Regenerate thumbnail ${String(e)}`,group:`This project`,context:a.title,keywords:[`thumbnail`,`redraw`,`remake`],run:()=>u.act(`regenerate-image`)});let f=r!==void 0&&!r.passed&&r.action===null,p=String.fromCharCode(64+e),m=u.asking===void 0||n===void 0?void 0:t5({kind:u.asking,outputId:n.id,now:u.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:t===1?`Thumbnail for ${a.title}`:`Thumbnail ${String(e)} for ${a.title}`,aspect:p5(a.format),...l===void 0?{}:{src:l.url},...n===void 0&&i.state===`running`?{generating:`Making the thumbnail`}:{},title:t===1?`Thumbnail`:p,...n===void 0?{meta:rve(i)}:{},onOpen:c,openLabel:`Open ${d} full size`,...r===void 0?{}:{badge:(0,h.jsx)(V8,{review:r})},actionsShown:f,...n===void 0?{}:{actions:(0,h.jsxs)(h.Fragment,{children:[f&&r!==void 0?(0,h.jsx)(z8,{review:r,projectId:a.id,busy:s}):null,(0,h.jsxs)(R,{size:`small`,disabled:u.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>u.act(`regenerate-image`),"aria-label":`Regenerate ${d}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),l===void 0?null:(0,h.jsx)(v5,{href:l.url,label:`Download ${d}`})]})}}),(0,h.jsx)(jy,{open:u.asking!==void 0,tone:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:`Regenerate the thumbnail`,cancelLabel:`Keep it`,pending:o.pending,onConfirm:u.confirm,onCancel:u.dismiss})]})}function nve(e,t){let n=e.indexOf(t);return n===-1?null:n}function rve(e){switch(e.state){case`running`:return`Being made`;case`failed`:case`canceled`:return`Not made`;default:return`Not made yet`}}function ive(e,t){let n=e.filter(e=>e.role===`image`),r=new Map;for(let e of n){let t=e.meta.promptName??`Images`;r.set(t,[...r.get(t)??[],e])}let i=t.filter(e=>r.has(e)),a=[...r.keys()].filter(e=>!i.includes(e)).sort();return[...i,...a].flatMap(e=>{let t=r.get(e);return t===void 0?[]:[{name:e,images:[...t].sort(ave)}]})}function ave(e,t){return(e.meta.index??0)-(t.meta.index??0)}function ove(e,t,n,r,i){let a=Oy(),[o,s]=(0,m.useState)(),c=(r,i)=>{let o=r===`image`?t:n,c=r===`image`?`image`:`on-screen card`;if(i===void 0){a(`Type the ${c}'s number with the command, for example "regenerate ${c} 3".`);return}let l=o.find(e=>e.meta.index===i);if(l===void 0){let t=o.flatMap(e=>e.meta.index===void 0?[]:[e.meta.index]);a(t.length===0?`${e.title} has no ${c}s yet, so there is no ${c} ${String(i)} to regenerate. They appear under Images once the run makes them.`:`${e.title} has no ${c} ${String(i)}: its ${c}s are numbered ${String(Math.min(...t))} to ${String(Math.max(...t))}. Type one of those, or press Regenerate on the ${c} in Images.`,`error`);return}s(e=>({image:l,name:`${c[0]?.toUpperCase()??``}${c.slice(1)} ${String(i)}`,nonce:(e?.nonce??0)+1}))};return bx({id:`project.image.regenerate`,title:`Regenerate an image`,numbered:e=>`Regenerate image ${String(e)}`,group:`This project`,context:e.title,keywords:[`image`,`picture`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`image`,e)}),bx({id:`project.card.regenerate`,title:`Regenerate an on-screen card`,numbered:e=>`Regenerate on-screen card ${String(e)}`,group:`This project`,context:e.title,keywords:[`card`,`figure`,`table`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`card`,e)}),Yx(Wx.regenerateImage(e.id),e=>c(`image`,e)),o===void 0?null:(0,h.jsx)(sve,{request:o,actions:r,busy:i},o.nonce)}function sve({request:e,actions:t,busy:n}){let r=Oy(),i=Q8(e.image,t,n),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a.current&&i.ready&&(a.current=!0,i.unavailable?r(`${e.name} can't be regenerated while work on this project is running. Wait until it finishes, then run the command again or press Regenerate on it in Images.`,`error`):i.act(`regenerate-image`))},[i,r,e.name]);let o=i.asking===void 0?void 0:t5({kind:i.asking,outputId:e.image.id,now:i.now});return(0,h.jsx)(jy,{open:i.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate the image`,cancelLabel:`Keep it`,pending:t.pending,onConfirm:i.confirm,onCancel:i.dismiss})}function p5(e){return e===`9:16`?`portrait`:`landscape`}function cve({stage:e,companion:t,project:n,outputs:r,actions:i,busy:a}){let o=F8(n.id),s=f8(r,e),c=ive(s,n.config.imagePrompts?.map(e=>e.name)??[]),l=c.flatMap(e=>e.images),u=s.filter(e=>e.role===`figure_card`&&(e.meta.format??n.format)===n.format).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),d=[...l,...u],f=ove(n,l,u,i,a),p=O_e(l,a),g=x8(d),[_,v]=(0,m.useState)(null),y=d.filter(e=>g.has(e.id)),b=y.map(e=>({src:g.get(e.id)?.url??``,alt:e.role===`figure_card`?`On-screen card ${String(e.meta.index??``)}`:e.meta.prompt??`Image ${String(e.meta.index??``)}`,...m5(e)?{kind:`video`}:{},caption:e.role===`figure_card`?`Shown while the narration describes it`:e.meta.prompt??e.meta.promptName??`Slideshow image`})),x=n.config.reference===void 0?null:(0,h.jsx)(lve,{image:p8(s,`reference`),format:n.format,generated:n.config.reference.source===`prompt`,affected:l.length,actions:i,busy:a}),S=t?.kind===`thumbnail`?(0,h.jsx)(eve,{stage:t,project:n,outputs:r,actions:i,busy:a}):null,C=e.state===`running`&&e.progressTotal!==null?Math.max(0,e.progressTotal-l.length):0,w=o.filter(e=>l.some(t=>t.id===e.outputId)),T=w.filter(e=>e.passed&&e.attempt>1).length,E=w.filter(e=>!e.passed&&e.action===null).length,D=[l.length===0?void 0:`${String(l.length)} in the video`,w.length===0?void 0:`reviewed`,T===0?void 0:`${String(T)} redone after review`,E===0?void 0:`${String(E)} flagged`].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(h.Fragment,{children:[f,x,x===null||S===null&&e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),S,S===null||e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),e.state===`skipped`?null:(0,h.jsxs)(`section`,{"aria-label":`Slideshow images`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:`Images`,...D===``?{}:{meta:D},children:[p===void 0?null:(0,h.jsxs)(R,{size:`small`,disabled:p.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:p.act,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate all`]}),p===void 0?null:(0,h.jsx)(jy,{open:p.asking,tone:`primary`,title:`Regenerate all ${String(p.count)} images?`,consequence:`Makes ${String(p.count)} new images now, one paid image call each. The video keeps the current ones until you remake it; the old images stay in History.`,confirmLabel:`Regenerate them`,cancelLabel:`Keep them`,pending:i.pending,onConfirm:p.confirm,onCancel:p.dismiss}),(0,h.jsx)(c_e,{projectId:n.id,asset:`images.zip`,label:`Download all`}),(0,h.jsx)(f5,{stages:[e],project:n,actions:i})]}),c.length===0&&C===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`pending`?`The images are made once the narration is timed.`:`No images have landed yet.`}):null,c.map((e,t)=>(0,h.jsx)(y5,{name:e.name,count:e.images.length,showName:c.length>1,trailing:t===c.length-1&&C>0?Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the next image`:`Waiting its turn`},t)):null,children:t=>e.images.slice(0,t).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:I8(o,{outputId:e.id}),format:n.format,actions:i,busy:a,onOpen:()=>v(g5(y,e))},e.id))},e.name)),u.length===0?null:(0,h.jsx)(y5,{name:`From the article`,count:u.length,showName:!0,children:e=>u.slice(0,e).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:void 0,format:n.format,actions:i,busy:a,card:!0,onOpen:()=>v(g5(y,e))},e.id))}),c.length===0&&C>0?(0,h.jsx)(B0,{label:`Images being made`,children:Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the first image`:`Waiting its turn`},t))}):null,(0,h.jsx)(V0,{items:b,index:_,onIndex:v,onClose:()=>v(null),actions:(e,t)=>{let n=y[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:n.role===`figure_card`?`on-screen card${h5(n)}`:`image${h5(n)}`,actions:i,busy:a},n.id)}})]})]})}var m5=e=>/\.(mp4|mov|m4v|webm|mkv)$/i.test(e.path),h5=e=>e.meta.index===void 0?``:` ${String(e.meta.index)}`;function g5(e,t){let n=e.indexOf(t);return n===-1?null:n}function _5({output:e,name:t,actions:n,busy:r}){let i=b8(e),a=Q8(e,n,r),o=a.asking===void 0?void 0:t5({kind:a.asking,outputId:e.id,now:a.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(R,{size:`small`,disabled:a.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>a.act(`regenerate-image`),"aria-label":`Regenerate ${t}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),i===void 0?null:(0,h.jsx)(v5,{href:i.url,label:`Download ${t}`}),(0,h.jsx)(jy,{open:a.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate it`,cancelLabel:`Keep it`,pending:n.pending,onConfirm:a.confirm,onCancel:a.dismiss})]})}function v5({href:e,label:t,text:n}){return(0,h.jsxs)(mS,{href:e,download:!0,"aria-label":t,title:t,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]})}function lve({image:e,format:t,generated:n,affected:r,actions:i,busy:a}){let o=b8(e),s=Q8(e,i,a),[c,l]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Establishing image`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{kicker:`Reference · not in the video`,title:`Establishing image`,meta:`Every image follows it for the look, palette and style`,children:e!==void 0&&n?(0,h.jsx)(R,{disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.act(`regenerate-image`),children:`Make the establishing image again`}):null}),(0,h.jsx)(z0,{className:`w-full max-w-[360px]`,alt:e?.meta.prompt??`Establishing image`,aspect:p5(t),...o===void 0?{}:{src:o.url},title:`Establishing image`,...e===void 0?{meta:`Not made yet`}:{},onOpen:()=>l(0),openLabel:`Open the establishing image full size`,...e===void 0||o===void 0?{}:{actions:(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`,text:`Download`})}}),n&&r>0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Making it again marks ${String(r)} image${r===1?``:`s`} outdated. They keep their current version until you remake them.`}):null,(0,h.jsx)(V0,{items:o===void 0?[]:[{src:o.url,alt:`Establishing image`,caption:e?.meta.prompt??`The reference every image follows`}],index:c,onIndex:l,onClose:()=>l(null),actions:()=>o===void 0?null:(0,h.jsxs)(h.Fragment,{children:[n?(0,h.jsxs)(R,{size:`small`,disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>{l(null),s.act(`regenerate-image`)},"aria-label":`Make the establishing image again`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}):null,(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`})]})}),(0,h.jsx)(jy,{open:s.asking!==void 0,tone:`primary`,title:`Make the establishing image again?`,consequence:`A new establishing image replaces this one${r>0?`, and the ${String(r)} images drawn from it become outdated until you remake them`:``}. The old one stays in History.`,confirmLabel:`Make it again`,cancelLabel:`Keep this one`,pending:i.pending,onConfirm:s.confirm,onCancel:s.dismiss})]})}function y5({name:e,count:t,showName:n,trailing:r,children:i}){let[a,o]=(0,m.useState)(!1),s=t>12&&!a;return(0,h.jsxs)(`section`,{"aria-label":`${e} × ${String(t)}`,className:`flex flex-col gap-3`,children:[n?(0,h.jsx)(`h3`,{className:`sl-kicker m-0`,children:`${e} × ${String(t)}`}):null,(0,h.jsxs)(B0,{children:[i(s?12:t),r]}),t>12?(0,h.jsx)(R,{variant:`quiet`,"aria-expanded":a,className:`self-start`,onClick:()=>o(e=>!e),children:a?`Show fewer`:`Show all ${String(t)} images`}):null]})}function b5({image:e,projectId:t,review:n,format:r,actions:i,busy:a,card:o=!1,onOpen:s}){let c=b8(e),l=h5(e),u=o?`on-screen card${l}`:`image${l}`,d=Q8(e,i,a),f=Z8(e),p=n!==void 0&&!n.passed&&n.action===null,m=d.asking===void 0?void 0:t5({kind:d.asking,outputId:e.id,now:d.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:o?`On-screen card${l}`:e.meta.prompt??`Slideshow ${u}`,kind:m5(e)?`video`:`image`,aspect:p5(r),...c===void 0?{}:{src:c.url},title:o?`Card${l}`:e.meta.prompt??`Image${l}`,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`},onOpen:s,openLabel:`Open ${u} full size`,...n===void 0&&!f?{}:{badge:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap gap-1`,children:[f?(0,h.jsx)(vS,{tone:`info`,children:`Outdated`}):null,n===void 0?null:(0,h.jsx)(V8,{review:n})]})},actionsShown:p,actions:(0,h.jsxs)(h.Fragment,{children:[p&&n!==void 0?(0,h.jsx)(z8,{review:n,projectId:t,busy:a}):null,(0,h.jsxs)(R,{size:`small`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`regenerate-image`),"aria-label":`Regenerate ${u}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),c===void 0?null:(0,h.jsx)(v5,{href:c.url,label:`Download ${u}`}),o?null:(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`delete-image`),"aria-label":`Delete ${u}`,title:`Delete ${u}`,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})}),(0,h.jsx)(jy,{open:d.asking!==void 0,tone:d.asking===`delete-image`?`destructive`:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:d.asking===`delete-image`?`Delete the image`:`Regenerate the image`,cancelLabel:`Keep it`,pending:i.pending,onConfirm:d.confirm,onCancel:d.dismiss})]})}function x5(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function S5(e){let t=/^(?:(\d+):)?(\d{1,2}):(\d{2})$/.exec(e.trim());if(t===null)return;let n=Number(t[1]??`0`),r=Number(t[2]),i=Number(t[3]);if(!(i>59||t[1]!==void 0&&r>59))return n*3600+r*60+i}function uve(e){let t=e.trim(),n=/^(\S+)\s+(.+)$/u.exec(t);if(n===null)return;let r=S5(n[1]??``),i=(n[2]??``).trim();return r===void 0||i===``?void 0:{start:r,title:i}}function C5(e,t){let n=e.replace(/\r\n?/gu,`
290
+ `);return(0,h.jsxs)(`section`,{"aria-labelledby":`${t}-title`,className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`h3`,{id:`${t}-title`,className:`sl-kicker text-ink-3`,children:`Narration text`}),(0,h.jsx)(CB,{markdown:u,label:`Narration text`,regionLabel:`Narration text`,anchorPrefix:`narration-`,what:`narration text`,onCopy:c,children:(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}),(0,h.jsx)(Q1,{tone:o?.tone??`info`,children:o?.text})]})}var J8=(0,m.createContext)(!1),Y8=(0,m.createContext)(void 0),X8=(0,m.createContext)(void 0);function Z8(e){let t=y8();return e===void 0?!1:t?.outputs.some(t=>t.output.id===e.id&&t.state===`outdated`)??!1}function Q8(e,t,n){let[r,i]=(0,m.useState)(),a=(0,m.use)(J8),o=(0,m.use)(Y8),s=(0,m.use)(X8),c=y8(),l=e===void 0?void 0:c?.outputs.find(t=>t.output.id===e.id)?.workKey,u=a&&l!==void 0;return{act:t=>{if(e===void 0)return;if(!u||l===void 0||t===`regenerate-image`){i(t);return}if(!l.startsWith(`image:`))return;let n=l.slice(6);o?.({section:`images`,change:e=>({...e,content:{...e.content,imageOrder:e.content.imageOrder.filter(e=>e!==n),imageDefinitions:Object.fromEntries(Object.entries(e.content.imageDefinitions).filter(([e])=>e!==n))},regenerate:(e.regenerate??[]).filter(e=>e!==l)})})},asking:r,confirm:()=>{let n=r;i(void 0),n!==void 0&&e!==void 0&&(u&&l!==void 0&&n===`regenerate-image`?s?.([l]):t.run({kind:n,outputId:e.id}))},dismiss:()=>i(void 0),unavailable:e===void 0||n||t.pending||u&&(o===void 0||s===void 0),viaEdit:u,now:u,ready:!a||c!==void 0}}function k_e(e,t){let[n,r]=(0,m.useState)(!1),i=(0,m.use)(J8),a=(0,m.use)(X8),o=y8();if(!i||o===void 0)return;let s=new Set(e.map(e=>e.id)),c=o.outputs.flatMap(e=>s.has(e.output.id)&&e.workKey.startsWith(`image:`)?[e.workKey]:[]);if(c.length!==0)return{count:c.length,asking:n,act:()=>r(!0),confirm:()=>{r(!1),a?.(c)},dismiss:()=>r(!1),unavailable:t||a===void 0}}var A_e=200,j_e=q({seconds:G(),peaks:K(G())});function M_e(e){if(e===void 0)return;let t;try{t=new URL(e,window.location.href)}catch{return}if(t.pathname.startsWith(`/files/`))return t.searchParams.set(`waveform`,String(A_e)),t.toString()}function N_e(e){let{api:t}=z(),n=M_e(e);return N({queryKey:[`waveform`,n],enabled:n!==void 0,staleTime:1/0,retry:!1,queryFn:async()=>{if(n===void 0)return[];let e=await t.fetch(n);if(!e.ok)throw po(e,void 0);let{peaks:r}=So(j_e,await e.json()),i=Math.max(0,...r);return i===0?[]:r.map(e=>e/i)}}).data}function $8(e){return(0,h.jsx)(K8,{...e,waveform:N_e(e.src)})}var e5=[{role:`audio_intro`,segment:`intro`,name:`Intro`},{role:`audio_body`,segment:`body`,name:`Body`},{role:`audio_outro`,segment:`outro`,name:`Outro`}];function P_e({stage:e,project:t,outputs:n,busy:r}){let{api:i}=z(),a=N(tb(i)),o=F8(t.id),s=f8(n,e),c=s.filter(e=>e.role===`audio_levelled`),l=e5.flatMap(e=>{let t=p8(s,e.role),n=c.find(t=>t.meta.segment===e.segment)??t;return n===void 0?[]:[{...e,output:n,...t===void 0||t===n?{}:{plain:t}}]}),u=e5.flatMap(e=>{let t=c.find(t=>t.meta.segment===e.segment)?.meta.loudness;return t===void 0?[]:[{name:e.name,report:t}]}),d=l.find(e=>e.output.meta.voice!==void 0)?.output.meta,f=l.length>0?d?.voice:t.config.audio?.voice,p=l.length>0?d?.provider:t.config.audio?.provider,m=a.data?.voices.find(e=>e.voiceId===f&&e.provider===p)?.name??f;return(0,h.jsxs)(w8,{children:[e.state===`running`?(0,h.jsx)(q8,{projectId:t.id}):null,l.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No narration has landed yet.`}):l.map(e=>(0,h.jsx)(F_e,{name:e.name,output:e.output,...e.plain===void 0?{}:{plain:e.plain}},e.role)),(0,h.jsx)(A8,{files:__e(s,l,n.find(e=>e.role===`script_md`))}),u.length===0?null:(0,h.jsx)(j8,{children:u.map(({name:e,report:t})=>u.length===1?mk(t):`${e}: ${mk(t)}`).join(` `)}),(0,h.jsxs)(W8,{label:`How it was recorded`,children:[m===void 0?null:(0,h.jsx)(G8,{label:`Voice`,children:m}),(0,h.jsx)(G8,{label:`Chunking`,children:I_e(L_e(t.config.chunking))}),y_e(s)?(0,h.jsx)(G8,{label:`Text files`,children:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Clean narration is the spoken text used for captions. The TTS script adds delivery cues, with a blank line between requests. Uploaded audio has no TTS request.`})}):null]}),(0,h.jsx)(B8,{review:I8(o,{itemKey:`narration`}),projectId:t.id,busy:r}),(0,h.jsx)(O_e,{outputs:s})]})}function F_e({name:e,output:t,plain:n}){let r=b8(t),i=Z8(t),a=Z8(n)||n===void 0?void 0:n,o=b8(i?a:void 0);return(0,h.jsxs)(`div`,{className:`grid grid-cols-[64px_minmax(0,1fr)] items-center gap-3 text-small`,children:[(0,h.jsx)(T8,{children:e}),(0,h.jsx)($8,{label:`${e} narration`,src:r?.url,className:`max-w-[640px]`}),i?(0,h.jsx)(`p`,{className:`col-start-2 m-0 text-small text-ink-2`,children:a===void 0?`Outdated: this is the narration from before your last change. The new one is made when the run carries on: press Continue the run, or Remake at the top of the page.`:`Outdated: this is the levelled narration from before your last change. The new narration is below as it was spoken; it is levelled when the run carries on: press Continue the run, or Remake at the top of the page.`}):null,i&&a!==void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(T8,{children:`New`}),(0,h.jsx)($8,{label:`${e} narration, new, before levelling`,src:o?.url,className:`max-w-[640px]`})]}):null]})}function I_e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function L_e(e){return e===void 0||e.mode===`whole`?`the whole text as one request`:e.mode===`paragraph`?`one request per paragraph`:e.mode===`characters`?`every ${String(e.characters??3e3)} characters`:`every ${String(e.words??500)} words`}function R_e({stage:e,project:t,outputs:n}){let r=p8(f8(n,e),`document_pdf`),i=b8(r),a=XS(t.config.document);return(0,h.jsxs)(w8,{children:[r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The PDF will be saved when rendering finishes.`:`No PDF has been saved yet.`}):(0,h.jsx)(A8,{files:[{output:r,label:`PDF`}],label:`Download PDF`,children:i?.folder?(0,h.jsxs)(mS,{href:`${i.url}?inline=1`,target:`_blank`,rel:`noopener`,variant:`secondary`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open PDF`]}):null}),(0,h.jsx)(W8,{label:`PDF details`,children:(0,h.jsx)(G8,{label:`Theme`,children:a})})]})}var z_e={research:`Generates fresh research and affected article, narration, entries, thumbnail and exports; previous outputs stay in History.`,article:`Generates a fresh article and affected narration, entries, thumbnail and exports; previous outputs stay in History.`,audio:`Regenerates narration and affected exports, keeping compatible cue preparation; previous outputs stay in History.`,images:`Regenerates generated images and affected video, keeping supplied images and narration; previous outputs stay in History.`,thumbnail:`Regenerates the thumbnail without changing the main video; previous outputs stay in History.`,video:`Rebuilds local exports from saved media without regenerating narration or images; previous outputs stay in History.`,document:`Renders the PDF again from the saved article and title without regenerating anything else; previous outputs stay in History.`};function t5(e){switch(e.kind){case`cancel`:return{title:`Cancel this run?`,consequence:`Stops every running stage; finished outputs are kept.`,verb:`Cancel run`,dismiss:`Keep running`};case`rerun`:return{title:`Re-run this stage?`,consequence:z_e[e.stage],verb:`Re-run`,dismiss:`Cancel`};case`delete-image`:return{title:`Delete this image?`,consequence:`Removes the image and re-renders video when enabled.`,verb:`Delete`,dismiss:`Cancel`};case`regenerate-image`:return e.thumbnail?{title:`Regenerate this thumbnail?`,consequence:`Makes a new thumbnail, one paid image call. The video and shorts are not touched; the PDF's cover follows the first thumbnail. The old one stays in History.`,verb:`Regenerate`,dismiss:`Cancel`}:{title:`Regenerate this image?`,consequence:e.now?`Makes a new image now, one paid image call. The video keeps the current one until you remake it; the old image stays in History.`:`Replaces the image with a new one and re-renders video when enabled.`,verb:`Regenerate`,dismiss:`Cancel`};case`save-article`:return{title:`Save the edited article?`,consequence:`Replaces the article, then updates the enabled narration and final export.`,verb:`Save & update outputs`,dismiss:`Cancel`};case`discard-article`:return{title:`Discard these edits?`,consequence:`The article goes back to the text on disk.`,verb:`Discard`,dismiss:`Keep editing`}}}function B_e(e,t){let{config:n,content:r,fingerprints:i}=e.revision;switch(t){case`research`:return n.sources.research===`generate`;case`article`:return n.sources.article===`generate`&&!r.articleEdited;case`audio`:return n.sources.audio===`generate`&&Object.keys(i).some(e=>!/^audio:(body:.+|intro|outro):[0-9]+$/.test(e)&&!/^audio:(body|intro|outro):future$/.test(e)?!1:!Object.entries(r.narrationOverrides).some(([t,n])=>n.kind===`asset`&&(e===t||e.startsWith(`${t}:`))));case`images`:return n.sources.images!==`off`&&r.imageOrder.some(e=>r.imageDefinitions[e]?.source===`generate`);case`thumbnail`:return n.sources.thumbnail===`from_prompt`||n.sources.thumbnail===`prompt_by_llm`;case`video`:return n.sources.video!==`off`||n.sources.audio!==`off`;case`document`:return RS(n.sources,`document`)===`generate`}}function n5(e){switch(e){case`research`:case`article`:return`article`;case`audio`:return`narration`;case`images`:case`thumbnail`:return`images`;case`video`:return`video`;case`document`:return`document`}}var r5={research:`Research`,article:`Article`,audio:`Narration`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`PDF`},i5=e=>/^[A-Z]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1);function V_e(e){let{project:t,stages:n}=e,r=t.config,i=e=>e===`video`&&rF(r)===`audio`?`Audio export`:r5[e];if(e.sample)return{situation:`sample`,tone:`info`,status:`Sample project`,title:`This is the sample project, finished and free to explore.`,why:`It is read-only. Your own copy can be edited and made again.`,action:{label:`Make my own copy`,intent:{kind:`copy-sample`}}};if(t.status===`paused`){let t=K_e(e.outdated);return{situation:`paused`,tone:`waiting`,status:`Paused`,title:`The run is paused.`,why:t===void 0?`Everything made so far is kept. Continuing picks up where it stopped.`:`Everything made so far is kept. Still to make: ${t}. They stay outdated until you continue.`,action:{label:`Continue the run`,intent:{kind:`resume`}}}}let a=n.find(e=>e.state===`failed`&&e.retryAt===void 0);if(a!==void 0){let t=i(a.kind),n=e.fixOf(a),r={label:`Try ${i5(a5(t))} again`,intent:{kind:`retry`,stage:a.kind}},o={situation:`failed`,tone:`failed`,status:`Failed`,section:n5(a.kind),...a.failureReason===null?{}:{detail:a.failureReason}};switch(n?.kind){case`sign-in`:return{...o,title:`${n.label.replace(/^Sign in to /,``)} is signed out, so ${i5(a5(t))} stopped.`,why:`Copy the sign-in command (${n.command}), run it in a terminal on the computer running Slopify and sign in, then press Check again. Once ${n.label.replace(/^Sign in to /,``)} is signed in, Slopify tries ${i5(a5(t))} again.`,action:{label:`Copy sign-in command`,intent:{kind:`sign-in`,stage:a.kind,fix:n}}};case`refused`:return{...o,title:`A content filter refused a prompt, so ${i5(a5(t))} stopped.`,why:n.soften?`Softening rewrites each refused prompt without what the filter flagged, then draws it again.`:`Change the prompt in the project settings, then try again.`,action:n.soften?{label:n.label,intent:{kind:`soften`,stage:a.kind}}:{label:`Edit the prompt`,intent:{kind:`edit`}}};case`switch-model`:return{...o,title:`The model for ${i5(a5(t))} is no longer offered.`,why:`Pick another model in the project settings, then try again.`,action:{label:`Switch model`,intent:{kind:`edit`}}};case`provider-settings`:return{...o,title:`The provider did not accept its key, so ${i5(a5(t))} stopped.`,why:`Check the key in Settings, then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`providers`}}};case`free-space`:return{...o,title:`The disk is full, so ${i5(a5(t))} stopped.`,why:`Storage in Settings shows what can go. Then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`storage`}}};case void 0:return{...o,title:`${t} stopped with an error.`,why:`Trying again keeps everything already made.`,action:r}}}let o=e.held[0];if(o!==void 0){let e=i(o.stage);return{situation:`held`,tone:`waiting`,status:`Waiting for you`,title:`The ${i5(e)} ${W_e(e)} ready for your review.`,why:o.dependents.length===0?`Approving marks it reviewed.`:`Approving lets ${o5(o.dependents.map(e=>i5(a5(i(e)))))} run. Nothing after it runs until you do.`,action:{label:H_e(o,i),intent:{kind:`approve`,gate:o}},section:n5(o.stage)}}let s=n.find(e=>e.state===`failed`&&e.retryAt!==void 0),c=e.waits[0];if(c!==void 0||s!==void 0){if(c!==void 0){let t=XH(e.waits);return{situation:`waiting`,tone:`waiting`,status:`Waiting for limits`,title:`${YH(e.waits,e.clock)??``}.`,why:`Nothing to do: the run carries on by itself when they reset, and work that does not need ${t} keeps going.`,section:n5(c.stage)}}if(s!==void 0)return{situation:`waiting`,tone:`waiting`,status:`Waiting to try again`,title:`${i(s.kind)} will try again by itself at ${e.clock(s.retryAt??``)}.`,why:`Nothing to do: the run carries on when it does.`,section:n5(s.kind),...s.failureReason===null?{}:{detail:s.failureReason}}}let l=n.find(e=>e.state===`running`);if(t.status===`running`||l!==void 0)return{situation:`running`,tone:`running`,status:`Running`,title:l===void 0?`The run is starting.`:`Making the ${i5(i(l.kind))}${U_e(l)}.`,why:`Pausing lets the current call finish and keeps everything made so far.`,action:{label:`Pause`,intent:{kind:`pause`}},...l===void 0?{}:{section:n5(l.kind)}};if(e.resumable||t.status===`canceled`||t.status===`failed`&&a===void 0)return{situation:`stopped`,tone:`off`,status:t.status===`canceled`?`Canceled`:`Stopped`,title:`The run stopped before it finished.`,why:`Continuing makes only what is missing; everything made so far is kept.`,action:{label:`Continue the run`,intent:{kind:`resume`}}};if(t.status===`pending`)return{situation:`queued`,tone:`off`,status:`Queued`,title:`Waiting for its turn.`,why:`It starts by itself when the videos ahead of it are done.`};let u=G_e(e.outdated);if(u!==void 0)return{situation:`outdated`,tone:`info`,status:`Outdated`,title:u.count===1||u.singular?`The ${u.noun} ${u.noun.endsWith(`s`)?`are`:`is`} outdated after your edit.`:`${String(u.count)} ${u.plural} are outdated after your edit.`,why:`They keep their current version until you remake them. Nothing else is made again.`,action:{label:u.count===1||u.singular?`Remake the outdated ${u.noun}`:`Remake ${String(u.count)} outdated ${u.plural}`,intent:{kind:`remake`,workKeys:u.workKeys}},section:u.section};if(t.status===`done`&&r.mode===`short`)return{situation:`done`,tone:`done`,status:`Done`,title:`The short is ready.`,why:`Play opens set up for a long video on the same topic, with the same starter pack and providers. Nothing starts until you press Play.`,action:{label:`Make the full video on this topic`,intent:{kind:`full-video`}}};if((t.status===`done`||t.status===`partial`)&&e.uploadReady)return{situation:`done`,tone:`done`,status:`Done`,title:`The video is ready.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}}function H_e(e,t){if(e.dependents.includes(`video`))return`Approve and render the video`;if(e.dependents.includes(`images`))return`Approve and make the images`;if(e.dependents.includes(`audio`))return`Approve and record the narration`;let n=e.dependents[0];return n===void 0?`Approve the ${i5(t(e.stage))}`:`Approve and make the ${i5(t(n))}`}function U_e(e){let t=lF(e);return t===void 0?e.progressTotal===null||e.progressTotal<=0?``:` · ${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)}`:` · ${t}`}function a5(e){return/s$/i.test(e)?e:`the ${i5(e)}`}function W_e(e){return/s$/i.test(e)?`are`:`is`}function o5(e){return e.length<=1?e[0]??``:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`}var s5=[{id:`article`,noun:`article`,plural:`article files`,singular:!0,section:`article`,roles:[`notes`,`sources`,`article_md`,`article_txt`,`script_md`],counted:[`article_md`]},{id:`narration`,noun:`narration`,plural:`narration parts`,singular:!0,section:`narration`,roles:[`narration_txt`,`tts_script`,`glossary`,`audio_body`,`audio_intro`,`audio_outro`,`audio_levelled`],counted:[`audio_body`]},{id:`reference`,noun:`establishing image`,plural:`establishing images`,singular:!0,section:`images`,roles:[`reference`],counted:[`reference`]},{id:`images`,noun:`image`,plural:`images`,singular:!1,section:`images`,roles:[`image`],counted:[`image`]},{id:`animated`,noun:`animated image`,plural:`animated images`,singular:!1,section:`images`,roles:[`animated_image`],counted:[`animated_image`]},{id:`thumbnails`,noun:`thumbnail`,plural:`thumbnails`,singular:!1,section:`images`,roles:[`thumbnail`],counted:[`thumbnail`]},{id:`video`,noun:`video`,plural:`video files`,singular:!0,section:`video`,roles:[`video`,`audio_export`,`audio_mp3`,`audio_m4b`,`render_params`,`subtitles_srt`,`subtitles_vtt`,`subtitle_words`,`subtitle_ass`,`subtitle_font`],counted:[`video`,`audio_export`]},{id:`shorts`,noun:`short`,plural:`shorts`,singular:!1,section:`shorts`,roles:[`shorts`,`short_image`,`short_video`],counted:[`short_video`]},{id:`youtube`,noun:`YouTube description`,plural:`YouTube descriptions`,singular:!0,section:`youtube`,roles:[`youtube_description`,`youtube_tags`,`youtube_pinned_comment`,`youtube_titles`],counted:[`youtube_description`]},{id:`document`,noun:`PDF`,plural:`PDFs`,singular:!0,section:`document`,roles:[`document_pdf`],counted:[`document_pdf`]}];function G_e(e){for(let t of s5){let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)continue;let r=n.filter(e=>t.counted.includes(e.role)).length;return{noun:t.noun,plural:t.plural,singular:t.singular,count:Math.max(1,r),workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section}}}function K_e(e){let t=s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[t.singular?`the ${t.noun}`:r===1?`1 ${t.noun}`:`${String(r)} ${t.plural}`]});return t.length===0?void 0:o5(t)}function q_e(e){return s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[{label:r===1||t.singular?`Remake the outdated ${t.noun}`:`Remake ${String(r)} outdated ${t.plural}`,workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section,count:r}]})}function J_e({tone:e,status:t,title:n,why:r,action:i,className:a}){return(0,h.jsxs)(`section`,{"aria-label":`Next action`,className:L(`sl-next`,a),children:[(0,h.jsx)(_S,{tone:e,children:t}),(0,h.jsx)(`p`,{className:`sl-next__title`,children:n}),r===void 0?null:(0,h.jsx)(`p`,{className:`sl-next__why`,children:r}),i===void 0?null:(0,h.jsx)(`div`,{className:`flex flex-col [&>*]:w-full`,children:i})]})}function Y_e({project:e,stages:t,resumable:n,sample:r,gates:i,outdated:a,waits:o,uploadReady:s,actions:c,controller:l,openSection:u,openUpload:d}){let{api:f}=z(),p=_(),h=Zi(),[g,v]=(0,m.useState)(),y=(0,m.useRef)(new Map),b=V_e({project:e,stages:t,resumable:n,sample:r,held:i.filter(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint).map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),outdated:a,waits:o,uploadReady:s,fixOf:t=>_3(t,e),clock:fF}),x=P({mutationFn:()=>Wy(f,e.id),onSuccess:async({projectId:e})=>{await p.invalidateQueries({queryKey:B.projects}),await h({to:`/projects/$projectId`,params:{projectId:e}})},onError:e=>v(`${bo(e.message)} The copy was not made. Press Make my own copy to try again.`)}),S=(0,m.useRef)(null),C=nP(),w=P({mutationFn:async()=>{if(C===null)throw Error(`Play isn't available on this page. Reload the page`);if(C.review.starting||C.review.uncertain||C.review.created!==null)throw Error(`Play is starting a run from its open draft. Wait for it to start`);if(!await C.flush())throw Error(`The draft open in Play couldn't be saved. Open Play, save or discard it`);S.current??=crypto.randomUUID();let{draft:t}=await By(f,{projectId:e.id,draftId:S.current});if(await p.invalidateQueries({queryKey:[`play-drafts`]}),!await C.open(t.id))throw Error(`The full video's draft was made but didn't open. Open Play and pick it`);S.current=null,await h({to:`/play`})},onError:e=>v(`${bo(e.message)} Then press Make the full video on this topic again.`)}),T=P({mutationFn:async t=>{let n=i.find(e=>e.checkpointId===t.checkpointId);if(n===void 0)throw Error(`The review changed before it was approved. Reload the page.`);let r=`${n.checkpointId}:${n.fingerprint}`,a=y.current.get(r)??crypto.randomUUID();y.current.set(r,a);let o=await h3(f,e.id,n.checkpointId,{revisionId:n.revisionId,fingerprint:n.fingerprint,idempotencyKey:a});if(y.current.delete(r),!o.ok)throw Error(o.message)},onSettled:async()=>{await p.invalidateQueries({queryKey:d3(e.id)}),await p.invalidateQueries({queryKey:B.project(e.id)}),p.invalidateQueries({queryKey:B.projects})},onError:e=>v(`${bo(e.message)} Press the approve button again to check whether it went through.`)});return{next:b,run:e=>{switch(v(void 0),e.kind){case`copy-sample`:x.mutate();return;case`resume`:case`pause`:c.run({kind:e.kind});return;case`retry`:case`soften`:c.run({kind:e.kind,stage:e.stage});return;case`sign-in`:q1(e.fix.command).then(t=>v(t?`Copied ${e.fix.command}. Run it in a terminal on the computer running Slopify, sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.fix.command} in a terminal, sign in, then press Check again.`));return;case`approve`:T.mutate(e.gate);return;case`remake`:l.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0});return;case`edit`:u(`settings`);return;case`open-settings`:h({to:`/settings`,search:{section:e.section}});return;case`prepare-upload`:d();return;case`full-video`:w.mutate();return}},pending:x.isPending||w.isPending||T.isPending||c.pending||l.pending,message:g}}function X_e(e){switch(e.kind){case`copy-sample`:return`Copying…`;case`resume`:return`Continuing…`;case`pause`:return`Pausing…`;case`approve`:return`Approving…`;case`remake`:return`Starting the remake…`;case`retry`:return`Trying again…`;case`soften`:return`Softening…`;case`full-video`:return`Opening Play…`;default:return}}function c5({state:e,variant:t,className:n}){let[r,i]=(0,m.useState)(!1),a=e.next?.action;if(a===void 0)return null;let o=a.intent;if(o.kind===`sign-in`)return(0,h.jsx)(J1,{fix:o.fix,variant:t,retry:{run:()=>e.run({kind:`retry`,stage:o.stage}),busy:e.pending}});if(o.kind===`open-settings`)return(0,h.jsx)(fS,{to:`/settings`,search:{section:o.section},variant:t,...n===void 0?{}:{className:n},children:a.label});let s=e.pending?X_e(o)??a.label:a.label;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:t,className:n,disabled:e.pending,disabledReason:`Working on the last press`,"aria-keyshortcuts":t===`primary`?Mx(lP.nextAction):void 0,onClick:()=>o.kind===`soften`?i(!0):e.run(o),children:s}),o.kind===`soften`?(0,h.jsx)(jy,{open:r,tone:`primary`,title:`Soften the refused prompt and try again?`,consequence:`Your project's AI model rewrites each refused prompt without what a content filter could flag, keeping the scene and style. The image is then drawn again from the new wording, which it keeps as its prompt. The AI call and the new image are charged like any other.`,confirmLabel:`Soften and retry`,cancelLabel:`Keep the prompt`,pending:e.pending,onConfirm:()=>{i(!1),e.run(o)},onCancel:()=>i(!1)}):null]})}function Z_e({state:e,feedback:t}){let n=e.next;return n===void 0&&t===void 0&&e.message===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n===void 0?null:(0,h.jsx)(J_e,{tone:n.tone,status:n.status,title:n.title,...n.why===void 0?{}:{why:n.why},...n.action===void 0?{}:{action:(0,h.jsx)(c5,{state:e,variant:`primary`})}}),e.message===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e.message}),t]})}var Q_e={sample:void 0,paused:void 0,stopped:void 0,queued:void 0,running:void 0,failed:`danger`,held:`waiting`,waiting:`waiting`,outdated:`info`,done:void 0};function $_e({state:e,section:t}){let n=e.next;if(n===void 0||n.section!==t)return null;let r=Q_e[n.situation];return r===void 0?null:(0,h.jsx)(SI,{className:`max-[1180px]:hidden`,tone:r,title:n.title,...n.action===void 0?{}:{actions:(0,h.jsx)(c5,{state:e,variant:`secondary`})},children:n.why===void 0&&n.detail===void 0?void 0:(0,h.jsxs)(h.Fragment,{children:[n.why===void 0?null:(0,h.jsx)(`span`,{className:`block`,children:n.why}),n.detail===void 0?null:(0,h.jsxs)(`details`,{className:`mt-1`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:n.detail})]})]})})}var eve={research:`Research again`,article:`Write the article again`,audio:`Record the narration again`,images:`Make all images again`,thumbnail:`Make the thumbnails again`,video:`Render the video again`,document:`Render the PDF again`};function l5(e,t){return e===`video`&&t.config.sources.video===`off`?`Export the audio again`:eve[e]}function u5({id:e,title:t,kicker:n,stages:r,project:i,outputs:a,actions:o,next:s,active:c,meta:l,head:u=!0,extra:d,resumable:f=!1,children:p}){let m=r[0],g=r.some(e=>o.refusal?.stage===e.kind)?o.refusal?.message:void 0,_=r.filter(t=>t.state===`failed`&&t.retryAt===void 0&&(s.next?.situation!==`failed`||s.next.section!==e)),v=r.find(e=>e.state===`running`),y=v===void 0?void 0:dF(v),b=l??(m===void 0?void 0:r.filter(e=>e.state!==`skipped`).map(e=>e===m?cF(e,a,i,f):`${r5[e.kind]}: ${cF(e,a,i,f)}`).join(` · `));return(0,h.jsxs)(`section`,{hidden:!c,"aria-label":t,"data-tour":m===void 0?void 0:`project-${m.kind}`,className:`flex min-w-0 flex-col gap-5`,children:[u?(0,h.jsxs)(H,{row:!0,title:t,...n===void 0?{}:{kicker:n},...b===void 0||b===``?{}:{meta:b},children:[d,(0,h.jsx)(f5,{stages:r,project:i,actions:o})]}):null,y===void 0||v===void 0?null:(0,h.jsx)(q2,{value:y,label:`${r5[v.kind]} progress`,valueText:cF(v,a,i,f)}),(0,h.jsx)($_e,{state:s,section:e}),_.map(e=>(0,h.jsx)(SI,{tone:`danger`,title:`${r5[e.kind]} stopped with an error.`,children:e.failureReason===null?void 0:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.failureReason})]})},e.id)),g===void 0?null:(0,h.jsx)(SI,{tone:`danger`,title:g,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:o.dismissRefusal,children:`Dismiss`})}),m?.state===`running`&&m.kind!==`article`&&m.kind!==`images`&&m.kind!==`video`&&m.kind!==`document`?(0,h.jsx)(j3,{projectId:i.id,stage:m.kind}):null,p]})}function d5({stage:e,project:t,name:n}){return e===void 0||e.state===`skipped`?(0,h.jsx)(a0,{title:`${n} is off for this run.`,children:`Switch it on in the project settings to make it.`}):(0,h.jsx)(a0,{title:`No ${n.toLowerCase()} yet.`,children:t.status===`paused`?`It is made once you continue the run.`:`It starts when the steps before it are done. Finished work elsewhere can be looked at meanwhile.`})}function f5({stages:e,project:t,actions:n}){let r=(0,m.useContext)(J8),i=y8(),[a,o]=(0,m.useState)(),s=e.filter(e=>e.state!==`skipped`&&e.state!==`pending`&&(!r||i!==void 0&&B_e(i,e.kind)));if(s.length===0)return null;let c=n.pending||t.status===`running`||e.some(e=>e.state===`running`),l=a===void 0?void 0:t5({kind:`rerun`,stage:a});return(0,h.jsxs)(h.Fragment,{children:[s.map(e=>(0,h.jsxs)(R,{size:`small`,disabled:c,disabledReason:`Wait until the work on this project is done`,onClick:()=>o(e.kind),children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),l5(e.kind,t)]},e.id)),(0,h.jsx)(jy,{open:a!==void 0,title:a===void 0?``:`${l5(a,t)}?`,consequence:l?.consequence??``,confirmLabel:a===void 0?``:l5(a,t),cancelLabel:`Keep what is there`,pending:n.pending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&n.run({kind:`rerun`,stage:e})},onCancel:()=>o(void 0)})]})}function tve({stage:e,project:t,outputs:n,actions:r,busy:i}){let a=f8(n,e),o=F8(t.id),s=VS(t.config),c=Array.from({length:s},(e,t)=>t+1).map(e=>({variant:e,output:a.find(t=>t.role===`thumbnail`&&(t.meta.index??1)===e)})),l=c.flatMap(e=>e.output===void 0?[]:[e.output]),u=x8(l),[d,f]=(0,m.useState)(null),p=l.filter(e=>u.has(e.id)),g=p.map(e=>({src:u.get(e.id)?.url??``,alt:`Thumbnail ${String(e.meta.index??1)}`})),_=t.format===`9:16`,v=({variant:n,output:a})=>(0,h.jsx)(nve,{variant:n,count:s,output:a,review:I8(o,{outputId:a?.id}),stage:e,project:t,actions:r,busy:i,onOpen:()=>f(a===void 0?null:rve(p,a))},n);return(0,h.jsxs)(`section`,{"aria-label":s===1?`Thumbnail`:`Thumbnails`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:s===1?`Thumbnail`:`Thumbnails`,meta:s===1?`The picture YouTube shows before the video plays`:`${String(s)} variants for YouTube's Test & compare`,children:[(0,h.jsx)(O8,{variant:`secondary`,files:l.map(e=>({output:e,label:s===1?`Thumbnail`:`Thumbnail ${String(e.meta.index??1)}`}))}),(0,h.jsx)(k8,{output:l[0]}),(0,h.jsx)(f5,{stages:[e],project:t,actions:r})]}),c.length===1?(0,h.jsx)(`div`,{className:_?`max-w-[280px]`:`max-w-[480px]`,children:c.map(v)}):(0,h.jsx)(B0,{list:!0,label:`Thumbnail variants`,children:c.map(e=>(0,h.jsx)(`li`,{className:`min-w-0`,children:v(e)},e.variant))}),(0,h.jsx)(V0,{items:g,index:d,onIndex:f,onClose:()=>f(null),actions:(e,t)=>{let n=p[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:s===1?`the thumbnail`:`thumbnail ${String(n.meta.index??1)}`,actions:r,busy:i},n.id)}})]})}function nve({variant:e,count:t,output:n,review:r,stage:i,project:a,actions:o,busy:s,onOpen:c}){let l=b8(n),u=Q8(n,o,s),d=t===1?`the thumbnail`:`thumbnail ${String(e)}`;bx({id:`project.thumbnail.${String(e)}`,title:t===1?`Regenerate the thumbnail`:`Regenerate thumbnail ${String(e)}`,group:`This project`,context:a.title,keywords:[`thumbnail`,`redraw`,`remake`],run:()=>u.act(`regenerate-image`)});let f=r!==void 0&&!r.passed&&r.action===null,p=String.fromCharCode(64+e),m=u.asking===void 0||n===void 0?void 0:t5({kind:u.asking,outputId:n.id,now:u.now,thumbnail:!0});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:t===1?`Thumbnail for ${a.title}`:`Thumbnail ${String(e)} for ${a.title}`,aspect:p5(a.format),...l===void 0?{}:{src:l.url},...n===void 0&&i.state===`running`?{generating:`Making the thumbnail`}:{},title:t===1?`Thumbnail`:p,...n===void 0?{meta:ive(i)}:{},onOpen:c,openLabel:`Open ${d} full size`,...r===void 0?{}:{badge:(0,h.jsx)(V8,{review:r})},actionsShown:f,...n===void 0?{}:{actions:(0,h.jsxs)(h.Fragment,{children:[f&&r!==void 0?(0,h.jsx)(z8,{review:r,projectId:a.id,busy:s}):null,(0,h.jsxs)(R,{size:`small`,disabled:u.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>u.act(`regenerate-image`),"aria-label":`Regenerate ${d}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),l===void 0?null:(0,h.jsx)(v5,{href:l.url,label:`Download ${d}`})]})}}),(0,h.jsx)(jy,{open:u.asking!==void 0,tone:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:`Regenerate the thumbnail`,cancelLabel:`Keep it`,pending:o.pending,onConfirm:u.confirm,onCancel:u.dismiss})]})}function rve(e,t){let n=e.indexOf(t);return n===-1?null:n}function ive(e){switch(e.state){case`running`:return`Being made`;case`failed`:case`canceled`:return`Not made`;default:return`Not made yet`}}function ave(e,t){let n=e.filter(e=>e.role===`image`),r=new Map;for(let e of n){let t=e.meta.promptName??`Images`;r.set(t,[...r.get(t)??[],e])}let i=t.filter(e=>r.has(e)),a=[...r.keys()].filter(e=>!i.includes(e)).sort();return[...i,...a].flatMap(e=>{let t=r.get(e);return t===void 0?[]:[{name:e,images:[...t].sort(ove)}]})}function ove(e,t){return(e.meta.index??0)-(t.meta.index??0)}function sve(e,t,n,r,i){let a=Oy(),[o,s]=(0,m.useState)(),c=(r,i)=>{let o=r===`image`?t:n,c=r===`image`?`image`:`on-screen card`;if(i===void 0){a(`Type the ${c}'s number with the command, for example "regenerate ${c} 3".`);return}let l=o.find(e=>e.meta.index===i);if(l===void 0){let t=o.flatMap(e=>e.meta.index===void 0?[]:[e.meta.index]);a(t.length===0?`${e.title} has no ${c}s yet, so there is no ${c} ${String(i)} to regenerate. They appear under Images once the run makes them.`:`${e.title} has no ${c} ${String(i)}: its ${c}s are numbered ${String(Math.min(...t))} to ${String(Math.max(...t))}. Type one of those, or press Regenerate on the ${c} in Images.`,`error`);return}s(e=>({image:l,name:`${c[0]?.toUpperCase()??``}${c.slice(1)} ${String(i)}`,nonce:(e?.nonce??0)+1}))};return bx({id:`project.image.regenerate`,title:`Regenerate an image`,numbered:e=>`Regenerate image ${String(e)}`,group:`This project`,context:e.title,keywords:[`image`,`picture`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`image`,e)}),bx({id:`project.card.regenerate`,title:`Regenerate an on-screen card`,numbered:e=>`Regenerate on-screen card ${String(e)}`,group:`This project`,context:e.title,keywords:[`card`,`figure`,`table`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`card`,e)}),Yx(Wx.regenerateImage(e.id),e=>c(`image`,e)),o===void 0?null:(0,h.jsx)(cve,{request:o,actions:r,busy:i},o.nonce)}function cve({request:e,actions:t,busy:n}){let r=Oy(),i=Q8(e.image,t,n),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a.current&&i.ready&&(a.current=!0,i.unavailable?r(`${e.name} can't be regenerated while work on this project is running. Wait until it finishes, then run the command again or press Regenerate on it in Images.`,`error`):i.act(`regenerate-image`))},[i,r,e.name]);let o=i.asking===void 0?void 0:t5({kind:i.asking,outputId:e.image.id,now:i.now});return(0,h.jsx)(jy,{open:i.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate the image`,cancelLabel:`Keep it`,pending:t.pending,onConfirm:i.confirm,onCancel:i.dismiss})}function p5(e){return e===`9:16`?`portrait`:`landscape`}function lve({stage:e,companion:t,project:n,outputs:r,actions:i,busy:a}){let o=F8(n.id),s=f8(r,e),c=ave(s,n.config.imagePrompts?.map(e=>e.name)??[]),l=c.flatMap(e=>e.images),u=s.filter(e=>e.role===`figure_card`&&(e.meta.format??n.format)===n.format).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),d=[...l,...u],f=sve(n,l,u,i,a),p=k_e(l,a),g=x8(d),[_,v]=(0,m.useState)(null),y=d.filter(e=>g.has(e.id)),b=y.map(e=>({src:g.get(e.id)?.url??``,alt:e.role===`figure_card`?`On-screen card ${String(e.meta.index??``)}`:e.meta.prompt??`Image ${String(e.meta.index??``)}`,...m5(e)?{kind:`video`}:{},caption:e.role===`figure_card`?`Shown while the narration describes it`:e.meta.prompt??e.meta.promptName??`Slideshow image`})),x=n.config.reference===void 0?null:(0,h.jsx)(uve,{image:p8(s,`reference`),format:n.format,generated:n.config.reference.source===`prompt`,affected:l.length,actions:i,busy:a}),S=t?.kind===`thumbnail`?(0,h.jsx)(tve,{stage:t,project:n,outputs:r,actions:i,busy:a}):null,C=e.state===`running`&&e.progressTotal!==null?Math.max(0,e.progressTotal-l.length):0,w=o.filter(e=>l.some(t=>t.id===e.outputId)),T=w.filter(e=>e.passed&&e.attempt>1).length,E=w.filter(e=>!e.passed&&e.action===null).length,D=[l.length===0?void 0:`${String(l.length)} in the video`,w.length===0?void 0:`reviewed`,T===0?void 0:`${String(T)} redone after review`,E===0?void 0:`${String(E)} flagged`].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(h.Fragment,{children:[f,x,x===null||S===null&&e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),S,S===null||e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),e.state===`skipped`?null:(0,h.jsxs)(`section`,{"aria-label":`Slideshow images`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:`Images`,...D===``?{}:{meta:D},children:[p===void 0?null:(0,h.jsxs)(R,{size:`small`,disabled:p.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:p.act,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate all`]}),p===void 0?null:(0,h.jsx)(jy,{open:p.asking,tone:`primary`,title:`Regenerate all ${String(p.count)} images?`,consequence:`Makes ${String(p.count)} new images now, one paid image call each. The video keeps the current ones until you remake it; the old images stay in History.`,confirmLabel:`Regenerate them`,cancelLabel:`Keep them`,pending:i.pending,onConfirm:p.confirm,onCancel:p.dismiss}),(0,h.jsx)(l_e,{projectId:n.id,asset:`images.zip`,label:`Download all`}),(0,h.jsx)(f5,{stages:[e],project:n,actions:i})]}),c.length===0&&C===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`pending`?`The images are made once the narration is timed.`:`No images have landed yet.`}):null,c.map((e,t)=>(0,h.jsx)(y5,{name:e.name,count:e.images.length,showName:c.length>1,trailing:t===c.length-1&&C>0?Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the next image`:`Waiting its turn`},t)):null,children:t=>e.images.slice(0,t).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:I8(o,{outputId:e.id}),format:n.format,actions:i,busy:a,onOpen:()=>v(g5(y,e))},e.id))},e.name)),u.length===0?null:(0,h.jsx)(y5,{name:`From the article`,count:u.length,showName:!0,children:e=>u.slice(0,e).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:void 0,format:n.format,actions:i,busy:a,card:!0,onOpen:()=>v(g5(y,e))},e.id))}),c.length===0&&C>0?(0,h.jsx)(B0,{label:`Images being made`,children:Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the first image`:`Waiting its turn`},t))}):null,(0,h.jsx)(V0,{items:b,index:_,onIndex:v,onClose:()=>v(null),actions:(e,t)=>{let n=y[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:n.role===`figure_card`?`on-screen card${h5(n)}`:`image${h5(n)}`,actions:i,busy:a},n.id)}})]})]})}var m5=e=>/\.(mp4|mov|m4v|webm|mkv)$/i.test(e.path),h5=e=>e.meta.index===void 0?``:` ${String(e.meta.index)}`;function g5(e,t){let n=e.indexOf(t);return n===-1?null:n}function _5({output:e,name:t,actions:n,busy:r}){let i=b8(e),a=Q8(e,n,r),o=a.asking===void 0?void 0:t5({kind:a.asking,outputId:e.id,now:a.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(R,{size:`small`,disabled:a.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>a.act(`regenerate-image`),"aria-label":`Regenerate ${t}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),i===void 0?null:(0,h.jsx)(v5,{href:i.url,label:`Download ${t}`}),(0,h.jsx)(jy,{open:a.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate it`,cancelLabel:`Keep it`,pending:n.pending,onConfirm:a.confirm,onCancel:a.dismiss})]})}function v5({href:e,label:t,text:n}){return(0,h.jsxs)(mS,{href:e,download:!0,"aria-label":t,title:t,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]})}function uve({image:e,format:t,generated:n,affected:r,actions:i,busy:a}){let o=b8(e),s=Q8(e,i,a),[c,l]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Establishing image`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{kicker:`Reference · not in the video`,title:`Establishing image`,meta:`Every image follows it for the look, palette and style`,children:e!==void 0&&n?(0,h.jsx)(R,{disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.act(`regenerate-image`),children:`Make the establishing image again`}):null}),(0,h.jsx)(z0,{className:`w-full max-w-[360px]`,alt:e?.meta.prompt??`Establishing image`,aspect:p5(t),...o===void 0?{}:{src:o.url},title:`Establishing image`,...e===void 0?{meta:`Not made yet`}:{},onOpen:()=>l(0),openLabel:`Open the establishing image full size`,...e===void 0||o===void 0?{}:{actions:(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`,text:`Download`})}}),n&&r>0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Making it again marks ${String(r)} image${r===1?``:`s`} outdated. They keep their current version until you remake them.`}):null,(0,h.jsx)(V0,{items:o===void 0?[]:[{src:o.url,alt:`Establishing image`,caption:e?.meta.prompt??`The reference every image follows`}],index:c,onIndex:l,onClose:()=>l(null),actions:()=>o===void 0?null:(0,h.jsxs)(h.Fragment,{children:[n?(0,h.jsxs)(R,{size:`small`,disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>{l(null),s.act(`regenerate-image`)},"aria-label":`Make the establishing image again`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}):null,(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`})]})}),(0,h.jsx)(jy,{open:s.asking!==void 0,tone:`primary`,title:`Make the establishing image again?`,consequence:`A new establishing image replaces this one${r>0?`, and the ${String(r)} images drawn from it become outdated until you remake them`:``}. The old one stays in History.`,confirmLabel:`Make it again`,cancelLabel:`Keep this one`,pending:i.pending,onConfirm:s.confirm,onCancel:s.dismiss})]})}function y5({name:e,count:t,showName:n,trailing:r,children:i}){let[a,o]=(0,m.useState)(!1),s=t>12&&!a;return(0,h.jsxs)(`section`,{"aria-label":`${e} × ${String(t)}`,className:`flex flex-col gap-3`,children:[n?(0,h.jsx)(`h3`,{className:`sl-kicker m-0`,children:`${e} × ${String(t)}`}):null,(0,h.jsxs)(B0,{children:[i(s?12:t),r]}),t>12?(0,h.jsx)(R,{variant:`quiet`,"aria-expanded":a,className:`self-start`,onClick:()=>o(e=>!e),children:a?`Show fewer`:`Show all ${String(t)} images`}):null]})}function b5({image:e,projectId:t,review:n,format:r,actions:i,busy:a,card:o=!1,onOpen:s}){let c=b8(e),l=h5(e),u=o?`on-screen card${l}`:`image${l}`,d=Q8(e,i,a),f=Z8(e),p=n!==void 0&&!n.passed&&n.action===null,m=d.asking===void 0?void 0:t5({kind:d.asking,outputId:e.id,now:d.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:o?`On-screen card${l}`:e.meta.prompt??`Slideshow ${u}`,kind:m5(e)?`video`:`image`,aspect:p5(r),...c===void 0?{}:{src:c.url},title:o?`Card${l}`:e.meta.prompt??`Image${l}`,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`},onOpen:s,openLabel:`Open ${u} full size`,...n===void 0&&!f?{}:{badge:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap gap-1`,children:[f?(0,h.jsx)(vS,{tone:`info`,children:`Outdated`}):null,n===void 0?null:(0,h.jsx)(V8,{review:n})]})},actionsShown:p,actions:(0,h.jsxs)(h.Fragment,{children:[p&&n!==void 0?(0,h.jsx)(z8,{review:n,projectId:t,busy:a}):null,(0,h.jsxs)(R,{size:`small`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`regenerate-image`),"aria-label":`Regenerate ${u}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),c===void 0?null:(0,h.jsx)(v5,{href:c.url,label:`Download ${u}`}),o?null:(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`delete-image`),"aria-label":`Delete ${u}`,title:`Delete ${u}`,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})}),(0,h.jsx)(jy,{open:d.asking!==void 0,tone:d.asking===`delete-image`?`destructive`:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:d.asking===`delete-image`?`Delete the image`:`Regenerate the image`,cancelLabel:`Keep it`,pending:i.pending,onConfirm:d.confirm,onCancel:d.dismiss})]})}function x5(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function S5(e){let t=/^(?:(\d+):)?(\d{1,2}):(\d{2})$/.exec(e.trim());if(t===null)return;let n=Number(t[1]??`0`),r=Number(t[2]),i=Number(t[3]);if(!(i>59||t[1]!==void 0&&r>59))return n*3600+r*60+i}function dve(e){let t=e.trim(),n=/^(\S+)\s+(.+)$/u.exec(t);if(n===null)return;let r=S5(n[1]??``),i=(n[2]??``).trim();return r===void 0||i===``?void 0:{start:r,title:i}}function C5(e,t){let n=e.replace(/\r\n?/gu,`
291
291
  `).split(`
292
- `),r=[],i=[];for(let[e,t]of n.entries()){let n=uve(t);n!==void 0&&(r.push(e),i.push(n))}if(i.length===0)return{text:e,adjustments:[]};let a=[],o=e=>`"${e.title}"`,s=[...i].sort((e,t)=>e.start-t.start);s.some((e,t)=>e!==i[t])&&a.push(`put the chapters in time order`);let c=[];for(let e of s){let t=c.at(-1);t!==void 0&&t.start===e.start?a.push(`merged ${o(e)} (0 s) into ${o(t)}`):c.push(e)}s=c;let l=t!==void 0&&Number.isFinite(t)&&t>0?t:void 0;if(l!==void 0){let e=s.filter((e,t)=>t>0&&e.start>=l);for(let t of e)a.push(`removed ${o(t)} (${x5(t.start)}), which starts after the video ends at ${x5(l)}`);s=s.filter(t=>!e.includes(t))}let u=s[0];u!==void 0&&u.start!==0&&(a.push(`moved the first, ${o(u)}, from ${x5(u.start)} to 0:00`),s=[{start:0,title:u.title},...s.slice(1)]);let d=e=>{let t=s[e+1],n=s[e]?.start??0;return t===void 0?l===void 0?1/0:l-n:t.start-n},f=e=>`${String(Math.max(0,Math.floor(e)))} s`;for(;s.length>1;){let e=s.findIndex((e,t)=>d(t)<10);if(e===-1)break;let t=s[e];if(t===void 0)break;let n=f(d(e));if(e===0){let e=s[1];if(e===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(e)}`),s=[{start:0,title:e.title},...s.slice(2)]}else{let r=s[e-1];if(r===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(r)}`),s=s.filter((t,n)=>n!==e)}}if(s.length<3&&(a.push(`left the chapter list out, since YouTube needs at least 3 chapters of 10 s or more and only ${String(s.length)} ${s.length===1?`is`:`are`} left`),s=[]),a.length===0)return{text:e,adjustments:a};let p=new Map(r.map((e,t)=>[e,s[t]]));return{text:n.flatMap((e,t)=>{if(!p.has(t))return[e];let n=p.get(t);return n===void 0?[]:[`${x5(n.start)} ${n.title}`]}).join(`
293
- `).trim(),adjustments:a}}function dve(e){return e.length===0?void 0:`Chapters adjusted for YouTube: ${e.join(`; `)}.`}function w5(e,t,n={}){let r=e.replace(/\r\n?/gu,`
292
+ `),r=[],i=[];for(let[e,t]of n.entries()){let n=dve(t);n!==void 0&&(r.push(e),i.push(n))}if(i.length===0)return{text:e,adjustments:[]};let a=[],o=e=>`"${e.title}"`,s=[...i].sort((e,t)=>e.start-t.start);s.some((e,t)=>e!==i[t])&&a.push(`put the chapters in time order`);let c=[];for(let e of s){let t=c.at(-1);t!==void 0&&t.start===e.start?a.push(`merged ${o(e)} (0 s) into ${o(t)}`):c.push(e)}s=c;let l=t!==void 0&&Number.isFinite(t)&&t>0?t:void 0;if(l!==void 0){let e=s.filter((e,t)=>t>0&&e.start>=l);for(let t of e)a.push(`removed ${o(t)} (${x5(t.start)}), which starts after the video ends at ${x5(l)}`);s=s.filter(t=>!e.includes(t))}let u=s[0];u!==void 0&&u.start!==0&&(a.push(`moved the first, ${o(u)}, from ${x5(u.start)} to 0:00`),s=[{start:0,title:u.title},...s.slice(1)]);let d=e=>{let t=s[e+1],n=s[e]?.start??0;return t===void 0?l===void 0?1/0:l-n:t.start-n},f=e=>`${String(Math.max(0,Math.floor(e)))} s`;for(;s.length>1;){let e=s.findIndex((e,t)=>d(t)<10);if(e===-1)break;let t=s[e];if(t===void 0)break;let n=f(d(e));if(e===0){let e=s[1];if(e===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(e)}`),s=[{start:0,title:e.title},...s.slice(2)]}else{let r=s[e-1];if(r===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(r)}`),s=s.filter((t,n)=>n!==e)}}if(s.length<3&&(a.push(`left the chapter list out, since YouTube needs at least 3 chapters of 10 s or more and only ${String(s.length)} ${s.length===1?`is`:`are`} left`),s=[]),a.length===0)return{text:e,adjustments:a};let p=new Map(r.map((e,t)=>[e,s[t]]));return{text:n.flatMap((e,t)=>{if(!p.has(t))return[e];let n=p.get(t);return n===void 0?[]:[`${x5(n.start)} ${n.title}`]}).join(`
293
+ `).trim(),adjustments:a}}function fve(e){return e.length===0?void 0:`Chapters adjusted for YouTube: ${e.join(`; `)}.`}function w5(e,t,n={}){let r=e.replace(/\r\n?/gu,`
294
294
  `).split(`
295
- `);for(;r.length>0&&r.at(-1)?.trim()===``;)r.pop();let i=``,a=r.at(-1)?.trim()??``;for(a!==``&&a.split(/\s+/u).every(e=>/^#[\p{L}\p{N}_]+$/u.test(e))&&(i=a,r.pop());r.length>0&&r.at(-1)?.trim()===``;)r.pop();let o=[];for(;r.length>0&&fve(r.at(-1)??``);)o.unshift((r.pop()??``).trim());return{summary:r.join(`
295
+ `);for(;r.length>0&&r.at(-1)?.trim()===``;)r.pop();let i=``,a=r.at(-1)?.trim()??``;for(a!==``&&a.split(/\s+/u).every(e=>/^#[\p{L}\p{N}_]+$/u.test(e))&&(i=a,r.pop());r.length>0&&r.at(-1)?.trim()===``;)r.pop();let o=[];for(;r.length>0&&pve(r.at(-1)??``);)o.unshift((r.pop()??``).trim());return{summary:r.join(`
296
296
  `).trim(),chapters:o.join(`
297
- `),hashtags:i,tags:t.trim(),pinnedComment:(n.pinnedComment??``).trim(),titles:(n.titles??``).trim()}}function fve(e){let[t=``,...n]=e.trim().split(/\s+/u);return S5(t)!==void 0&&n.length>0}function pve(e){return[e.summary.trim(),e.chapters.trim(),e.hashtags.trim()].filter(e=>e!==``).join(`
297
+ `),hashtags:i,tags:t.trim(),pinnedComment:(n.pinnedComment??``).trim(),titles:(n.titles??``).trim()}}function pve(e){let[t=``,...n]=e.trim().split(/\s+/u);return S5(t)!==void 0&&n.length>0}function mve(e){return[e.summary.trim(),e.chapters.trim(),e.hashtags.trim()].filter(e=>e!==``).join(`
298
298
 
299
- `)}function mve(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function T5(e,t){let n=n=>mve(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function E5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}var hve=q({number:G().int().positive(),first:G().int().positive(),last:G().int().positive(),start:G().finite().nonnegative(),end:G().finite().positive(),title:W(),description:W(),hashtags:K(W()),why:W(),text:W(),seed:W().nullable().optional()}),gve=.25,_ve=.4;function D5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(gve,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(_ve,(s-a.end)/2)));return{start:O5(c),end:O5(l)}}q({first:tO([G(),W()]),last:tO([G(),W()]),title:W(),description:W(),hashtags:K(W()),why:W().optional()});function O5(e){return Math.round(e*1e3)/1e3}var vve=q({shorts:K(hve),durationSeconds:G().finite().nonnegative().optional(),sentences:K(q({start:G().finite().nonnegative(),end:G().finite().nonnegative(),text:W()})).optional()});function yve(e){if(e!=null)try{let t=vve.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function bve(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=D5(o,n,r,xve(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function xve(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function k5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:mq(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:mq(n,e.config.values)]))}}}}function Sve(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:ON(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function A5(e,t,n){return k5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function Cve(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function j5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=z(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await Vo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await Cve(r.signal);let e=(await Po(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Ho(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(xV,{label:e,id:s,children:(0,h.jsx)(CV,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(R,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var M5=`shorts:pick`,N5=e=>`shorts:${String(e)}`;function P5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],M5])]}}function F5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],N5(t)])]}}function wve(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=yve(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function Tve({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Lk,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Jk(o)}),l=[...n,...I5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...I5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(M5)===!0,f=wve(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(YV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(Eve,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(O6,{settings:KV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?kve(n,e):A5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=qk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(Dve,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function Eve({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(j5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function Dve({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:D5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(V,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==M5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>o(P5(e)),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(Ove,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(N5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):bve(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?F5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==N5(t.number))})},t.number))})]})}function Ove({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(xV,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(TV,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(V,{id:`project.shorts.remake`})]})]})]})}function I5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function kve(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return k5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var Ave=q({shorts:K(q({number:G(),first:G().optional(),last:G().optional(),start:G(),end:G(),title:W(),description:W(),hashtags:K(W())}))});function jve({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=f8(n,e),a=p8(i,`shorts`),o=z5(i),s=F8(t.id),[c,l]=(0,m.useState)(),u=L5(i,`short_video`,o),d=t.config.shorts,f=(0,m.use)(J8),p=(0,m.use)(Y8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let g=f&&p!==void 0&&d?.enabled===!0,_=e=>{let t=Uk(e,d?.fullVideoLink),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(A8,{files:o.map(e=>({output:u.find(t=>R5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:g&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...Ob,children:[(0,h.jsx)(R,{onClick:()=>p({section:`shorts`,change:P5}),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(B0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(Mve,{clip:n,projectId:t.id,review:I8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>R5(e,n)),stills:L5(i,`short_image`,o).filter(e=>R5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:d?.fullVideoLink,wanted:Kk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:Fve(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>_(n),...g?{onRemake:()=>p({section:`shorts`,change:e=>F5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(Q1,{tone:c?.tone??`info`,children:c?.text})]})}function Mve({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=b8(r),g=b8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(R0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(z0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:_F(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(Nve,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(B8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Ey,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(hS,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(wy,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(m8,{children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{align:`start`,children:(0,h.jsxs)(_8,{onSelect:d,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function Nve({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(vS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function L5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>R5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function R5(e,t){return e.meta.short===t.number}function z5(e){return Pve(M8(p8(e,`shorts`)).data)}function Pve(e){if(e===void 0)return[];try{let t=Ave.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function Fve(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function Ive({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=z(),a=Oy(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=p8(f8(n,e),o?`audio_export`:`video`),c=f8(n,e),l=p8(c,`subtitles_srt`),u=p8(c,`subtitles_vtt`),d=p8(c,`youtube_description`),f=p8(c,`youtube_tags`),p=p8(c,`audio_mp3`),m=p8(c,`audio_m4b`),g=L5(c,`short_video`,z5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=b8(s),v=b8(Lve(n)),y=Rve(t.id,d,f,s?.durationMs??null),b=b8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=vF(e.progressCurrent??0,e.progressTotal??0);return bx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await c2(i,{projectId:t.id,asset:D3(s),folder:_?.folder??null});e.opened||a(`${l2} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(w8,{children:r}):(0,h.jsxs)(w8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:aF(e,t.config)?`Preparing subtitles · ${String(vF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:uF(lF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)($8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(R0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,className:t.format===`9:16`?`max-w-[360px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(A8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(j8,{children:[_F(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:hk(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||VO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:VO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function Lve(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function Rve(e,t,n,r){let{api:i}=z(),a=M8(t).data,o=M8(n).data,s=N({queryKey:B.youtubeEdits(e),queryFn:()=>Es(i,e),enabled:t!==void 0});return a===void 0?[]:zve(E5(T5(w5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function zve(e,t){return C5(e,t).text.split(`
300
- `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:S5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function Bve(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(C_e,{...e});case`audio`:return(0,h.jsx)(N_e,{...e});case`images`:return(0,h.jsx)(cve,{...e});case`video`:return(0,h.jsx)(Ive,{...e});case`document`:return(0,h.jsx)(L_e,{...e});case`research`:case`thumbnail`:return null}}q({summary:W(),chapters:K(q({start:tO([W(),G()]),title:W()})),hashtags:K(W()),tags:K(W()),pinnedComment:W(),titles:K(W())});function B5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function Vve({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=z(),a=_(),o=f8(n,e),s=p8(o,`youtube_description`),c=p8(o,`youtube_tags`),l=p8(o,`youtube_pinned_comment`),u=p8(o,`youtube_titles`),d=M8(s).data,f=M8(c).data,p=M8(l).data,g=M8(u).data,v=(0,m.use)(X8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=N({queryKey:B.youtubeEdits(t.id),queryFn:()=>Es(i,t.id)}),T=N({queryKey:B.projectChannelLinks(t.id),queryFn:()=>Ts(i,t.id)}),[E,D]=(0,m.useState)(),O=Oy(),k=e=>a.setQueryData(B.youtubeEdits(t.id),e),A=P({mutationFn:e=>Ds(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),ee=(0,m.useRef)({});if(bx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:lP.copyDescription,run:()=>ee.current.description===void 0?O(`The description has not been written yet.`,`info`):ee.current.description()}),bx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>ee.current.tags===void 0?O(`The tags have not been written yet.`,`info`):ee.current.tags()}),bx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>ee.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):ee.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let te=d===void 0?void 0:w5(d,f??``,{pinnedComment:p,titles:g}),ne=T5(te,w.data?.fields??{}),j=E5(ne),re=Nj(T.data?.links??[],w.data?.links??[]),M=p8(o,`video`),ie=C5(j.chapters,M?.durationMs===null||M?.durationMs===void 0?void 0:M.durationMs/1e3),ae=dve(ie.adjustments),oe=Fj(pve({...j,chapters:ie.text}),re),se=Fj(j.tags,re),ce=Fj(j.pinnedComment,re),le=[...oe.unknown,...se.unknown,...ce.unknown].filter((e,t,n)=>n.findIndex(t=>Mj(t)===Mj(e))===t),ue=G5(se.text),de=te!==void 0,fe=ce.text.trim()!==``,pe=j.titles.split(`
301
- `).map(e=>e.trim()).filter(e=>e!==``),me=(e,t)=>{let n=`Couldn't copy the ${t}. Select the text in the YouTube section and copy it.`;if(!navigator.clipboard){D({text:n,tone:`error`}),O(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),O(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),O(n,`error`)})};ee.current=de?{description:()=>me(oe.text,`description`),tags:()=>me(se.text,`tags`),...fe?{pinnedComment:()=>me(ce.text,`pinned comment`)}:{}}:{};let he=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,ge=(e,t)=>(0,h.jsx)(Hve,{label:V5[e],value:ne[e],links:re,disabled:!de||A.isPending,multiline:e!==`hashtags`,placeholder:de&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again above to have one written, or Edit to write your own.`:de&&e===`titles`?`Written before other titles existed. Use Write again above to have two written, or Edit to write your own, one per line.`:he,render:t,onSave:t=>A.mutate({field:e,edit:{text:t,base:te?.[e]??``},done:`Saved your ${V5[e].toLowerCase()}.`}),onUseGenerated:()=>A.mutate({field:e,edit:null,done:`The ${V5[e].toLowerCase()} follows the generated text again.`}),onKeepMine:(t,n)=>A.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${V5[e].toLowerCase()}.`})},e);return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`@container flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sr-only`,children:`YouTube`}),(0,h.jsxs)(`div`,{className:`flex min-w-0 max-w-[80ch] flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:de?()=>me(oe.text,`description`):void 0,keyshortcuts:Mx(lP.copyDescription),count:de?`${String(oe.text.length)} / ${String(S6)} characters`:void 0,over:oe.text.length>S6,main:!0,again:de&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`summary`),ge(`chapters`,()=>ie.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(W5,{text:ie.text,links:re})),ae===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:ae}),ge(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:de?()=>me(se.text,`tags`):void 0,count:de?`${String(B5(ue))} / 500 characters`:void 0,over:B5(ue)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:ge(`tags`,e=>(0,h.jsx)(Uve,{text:e,links:re}))}),(0,h.jsx)(U5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:de&&fe?()=>me(ce.text,`pinned comment`):void 0,count:de&&fe?`${String(ce.text.length)} / 500 characters`:void 0,over:ce.text.length>500}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`pinnedComment`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Post it under the video once it is published, then choose Pin in the comment's menu.`})]}),(0,h.jsx)(U5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:de&&pe.length>0?()=>me(pe.join(`
302
- `),`other titles`):void 0,count:de&&pe.length>0?`${String(pe.length+1)} titles to test`:void 0,over:pe.some(e=>e.length>100)}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`titles`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`For YouTube's A/B Testing beside the title, with this project's own title "${t.title}". One per line.`})]})]})]}),le.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${le.map(e=>`{{${e}}}`).join(`, `)}, so it stays as typed. Add it under Channel links on `,T.data===void 0?`the channel's Brand tab`:(0,h.jsx)(ha,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${le.some(e=>Mj(e)===Mj(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(Wve,{projectId:t.id,edits:w.data,onSaved:e=>{k(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(Q1,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(jy,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags and pinned comment. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function U5({id:e,label:t,copy:n,count:r,over:i,keyshortcuts:a,main:o=!1,again:s,open:c,onToggle:l}){return(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-3 border-b border-line pb-2`,children:[(0,h.jsx)(`h4`,{id:e,className:`m-0 text-title-3 font-semibold text-ink`,children:l===void 0?t:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,"aria-expanded":c===!0,onClick:l,className:`-ml-2 h-auto px-2 py-1 text-title-3 font-semibold text-ink`,children:[(0,h.jsx)(fc,{"aria-hidden":`true`,strokeWidth:1.75,className:L(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:L(`text-small tabular-nums`,i?`text-danger`:`text-ink-3`),children:i?`${r}, over YouTube's limit`:r}),(0,h.jsx)(`span`,{className:`flex-1`}),s===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`secondary`,onClick:s,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(R,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function Hve({label:e,value:t,links:n,disabled:r,multiline:i,placeholder:a,render:o,onSave:s,onUseGenerated:c,onKeepMine:l}){let u=(0,m.useId)(),[d,f]=(0,m.useState)(),[p,g]=(0,m.useState)(!1),_=d!==void 0,v=e.toLowerCase(),y=e in H5?H5[e]:void 0;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h5`,{id:`${u}-label`,className:`sl-kicker text-ink-3`,children:e}),y===void 0?null:(0,h.jsx)(V,{id:y,label:v,className:`-my-1`})]}),t.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),t.edited&&!_?(0,h.jsx)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r,"aria-label":`Use the generated ${v}`,onClick:c,children:`Use generated`}):null,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r||_,"aria-label":`Edit ${v}`,onClick:()=>f(t.text),children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),t.pending===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-l-2 border-waiting pl-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`p`,{className:`text-small text-ink`,children:`New generated version available.`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Use the new generated ${v}`,onClick:c,children:`Use it`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Keep my ${v}`,onClick:()=>l(t.text,t.pending??``),children:`Keep mine`}),(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-expanded":p,"aria-label":`${p?`Hide`:`View`} the ${v} diff`,onClick:()=>g(e=>!e),children:p?`Hide diff`:`View diff`})]}),p?(0,h.jsx)(w4,{before:t.text,after:t.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),_?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${u}-edit`,className:`sr-only`,children:e}),i?(0,h.jsx)(wV,{id:`${u}-edit`,rows:e===`Chapters`?8:5,value:d,onChange:e=>f(e.currentTarget.value)}):(0,h.jsx)(CV,{id:`${u}-edit`,value:d,onChange:e=>f(e.currentTarget.value)}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(R,{type:`button`,variant:`primary`,disabled:r,onClick:()=>{s(d),f(void 0)},children:[`Save `,v]}),(0,h.jsx)(R,{type:`button`,variant:`secondary`,onClick:()=>f(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${u}-label`,className:L(`min-w-0 whitespace-pre-wrap break-words text-small`,t.text===``?`text-ink-3`:`text-ink`),children:t.text===``?a:o===void 0?(0,h.jsx)(W5,{text:t.text,links:n}):o(t.text)})]})}function W5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:Pj(e,t).map(e=>{let t=String(n);return n+=e.kind===`text`?e.text.length:e.raw.length,e.kind===`text`?(0,h.jsx)(`span`,{children:e.text},t):e.url===void 0?(0,h.jsx)(`mark`,{title:`No link named ${e.name}`,className:`rounded-[2px] bg-waiting/25 px-0.5 text-ink`,children:e.raw},t):(0,h.jsx)(`span`,{title:e.raw,className:`underline decoration-dotted underline-offset-[3px]`,children:e.url},t)})})}function G5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function Uve({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:G5(e).map((e,n)=>(0,h.jsx)(`li`,{className:`rounded-full border border-line bg-raised px-2 py-0.5 text-small text-ink`,children:(0,h.jsx)(W5,{text:e,links:t})},n))})}function Wve({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=z(),a=(0,m.useId)(),o=t?.links.find(e=>Mj(e.name)===Mj(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=P({mutationFn:()=>{let n=(t?.links??[]).filter(e=>Mj(e.name)!==Mj(kj));return Os(i,e,l.trim()===``?n:[...n,{name:kj,url:l.trim()}])},onSuccess:e=>{c(void 0),n(e)},onError:e=>r(e.message)});return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[260px] flex-1 flex-col gap-1 sm:max-w-[520px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{className:`sl-field__label`,htmlFor:a,children:`Previous video for this project`}),(0,h.jsx)(V,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(CV,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(R,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var K5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function Gve({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=z(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(!1),g=(0,m.useRef)(!0),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=JSON.stringify([t,n.map(e=>[e.stage,e.checkpointId]).toSorted()]),b=s!==null&&s.baseIdentity!==y,x=s?.stages??n.map(e=>e.stage),S=K5.some(({stage:e})=>x.includes(e)!==n.some(t=>t.stage===e)),C=b||d!==null&&d.kind!==`success`,w=b?{kind:`refused`,message:`Checkpoint choices changed elsewhere. Press Reload checkpoint choices before saving, then make your change again.`}:d;(0,m.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,m.useEffect)(()=>{(d||b)&&_.current?.focus()},[d,b]);async function T(){if(!(p.current||!S||C)){p.current=!0,u(!0);try{let n=await cme(o,e,{revisionId:t,stages:x});if(!g.current)return;n.ok?n.value.revisionId===t?(a(n.value),c(null),f({kind:`success`,message:`Checkpoint choices saved.`})):f({kind:`refused`,message:`The project was edited elsewhere. Press Reload checkpoint choices to see its current choices.`}):f({kind:`refused`,message:n.message})}catch(e){g.current&&f({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the change`)} It may or may not have saved. Press Reload checkpoint choices before changing anything else.`})}finally{p.current=!1,g.current&&u(!1)}}}async function E(){if(!p.current){p.current=!0,u(!0);try{let e=await i();g.current&&e&&(c(null),f(null),v.current?.focus())}finally{p.current=!1,g.current&&u(!1)}}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(`fieldset`,{ref:v,tabIndex:-1,className:`space-y-2`,...Ob,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(V,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),K5.map(({stage:e,name:t})=>{let n=r.find(t=>t.kind===e),i=n?.state===`pending`&&(e===`video`?n.source!==`off`||r.some(e=>e.kind===`audio`&&e.source!==`off`&&e.state!==`skipped`):(n.source??`generate`)===`generate`);return(0,h.jsxs)(`label`,{className:`flex min-h-10 items-center gap-3`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),disabled:!i||l||C,onChange:t=>{c({baseIdentity:s?.baseIdentity??y,stages:t.target.checked?[...x,e]:x.filter(t=>t!==e)}),f(null)}}),`Before `,t]},e)})]}),w?(0,h.jsx)(`p`,{ref:_,tabIndex:-1,role:w.kind===`success`?`status`:`alert`,children:w.message}):null,(0,h.jsx)(R,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(R,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var q5=e=>e.charAt(0).toUpperCase()+e.slice(1);function Kve(e){return e.revisionId===null?null:(0,h.jsx)(qve,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function qve({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=z(),o=_(),s=N({queryKey:f3(e,t),queryFn:()=>m3(a,e),retry:!1}),c=s.data,l=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t?e.data.value:void 0},u=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t};return s.isPending?null:s.error||c?.ok===!1?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:s.error?.message??(c?.ok===!1?c.message:`Checkpoints couldn't be loaded. Press Reload checkpoints.`)}),(0,h.jsx)(R,{onClick:()=>void u(),children:`Reload checkpoints`})]}):c?.ok?c.value.revisionId===t?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col gap-5`,children:[(0,h.jsx)(H,{title:`Review checkpoints`,size:`small`,className:`pb-0`}),n?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`The project is paused. Continue the run before approving held work.`}):null,(0,h.jsx)(Gve,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(f3(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:B.project(e)}),o.invalidateQueries({queryKey:B.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(Jve,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,...a.checkpointId===i?{inRail:!0}:{}},`${a.checkpointId}:${a.fingerprint}`))]}):(0,h.jsx)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The project was edited after these checkpoints loaded. Press Reload checkpoints before approving.`})}):null}function Jve({gate:e,disabled:t,reload:n,inRail:r=!1}){let{api:i}=z(),a=_(),o=(0,m.useRef)(null),s=(0,m.useRef)(!1),c=(0,m.useRef)(!0),l=(0,m.useRef)(null),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(null);(0,m.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,m.useEffect)(()=>{f!==null&&l.current?.focus()},[f]);let g=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function v(){if(!(s.current||t||!g||f?.kind===`refused`||f?.kind===`success`)){s.current=!0,d(!0),o.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await h3(i,e.projectId,e.checkpointId,o.current);o.current=null,c.current&&p(t.ok?{kind:`success`,message:t.value.replayed?`Checkpoint already approved.`:`Checkpoint approved. Work will run when its dependencies are ready.`}:{kind:`refused`,message:t.message}),a.invalidateQueries({queryKey:d3(e.projectId)}),a.invalidateQueries({queryKey:B.project(e.projectId)}),a.invalidateQueries({queryKey:B.projects})}catch(e){c.current&&p({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{s.current=!1,c.current&&d(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`${q5(e.stage)} checkpoint`,className:`pb-0`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`released`&&e.approvedAt!==null?`Authorized for this revision. Work can run when dependencies are ready and the project is resumed.`:e.state===`satisfied`?`Checkpoint satisfied. Its reviewed work is complete.`:e.state===`invalidated`||e.fingerprint!==e.currentFingerprint?`Inputs changed. Review the current revision before approving.`:g?`${q5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Reviewed revision: `,e.revisionId]}),e.dependents.length?(0,h.jsx)(`ul`,{"aria-label":`Dependent work`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:e.dependents.map(e=>(0,h.jsx)(`li`,{className:`sl-chip`,children:q5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),f?(0,h.jsx)(`p`,{ref:l,tabIndex:-1,role:f.kind===`success`?`status`:`alert`,className:f.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:f.message}):null,g&&r&&f===null?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Its approval is the project's next action, in the right rail.`}):g?(0,h.jsx)(R,{className:`self-start`,disabled:t||u||f?.kind===`refused`||f?.kind===`success`,onClick:()=>void v(),children:u?`Approving…`:f?.kind===`transport`?`Retry approval`:`Approve ${q5(e.stage)} checkpoint`}):null,f?.kind===`refused`?(0,h.jsx)(R,{className:`self-start`,onClick:async()=>{await n()&&p(null)},children:`Reload checkpoints`}):null]})}function Yve({projects:e,queryKey:t}){let{api:n}=z(),r=_(),i=Oy(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=P({mutationFn:e=>Bo(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t.title}" (${String(e.files)} working file${e.files===1?``:`s`}).`,`success`)},onError:e=>c(e.message),onSettled:()=>r.invalidateQueries({queryKey:t})}),u=e.toSorted((e,t)=>t.bytes-e.bytes);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-2 flex items-center gap-1 text-small text-ink-2`,children:[`Keep outputs only frees a finished project's working files.`,(0,h.jsx)(V,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(pU,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(mU,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[Y5(e.bytes),` · outputs `,Y5(e.outputsBytes),` · working files `,Y5(e.workingBytes)]}),actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:!e.finished||e.removableBytes===0||l.isPending,title:e.finished?e.removableBytes===0?`No working files left to remove.`:`Frees ${Y5(e.removableBytes)}.`:`Available once the project has finished.`,onClick:()=>o(e),children:l.isPending&&l.variables?.id===e.id?`Removing…`:`Keep outputs only`})},e.id))}),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:s}),(0,h.jsx)(jy,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:J5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function J5(e,t){return`This removes ${String(e)} working file(s) and frees ${Y5(t)}: the images, narration parts, subtitle timing and render settings the project was made from. The video, shorts, thumbnail, article, description and document stay, and so does anything you uploaded. If you change this project later (edit an image, a caption style or the narration, or re-render), Slopify has to make those files again first, which takes time and uses provider credits.`}function Y5(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var X5=e=>[`storage`,`project`,e];function Xve({projectId:e,title:t,status:n,sample:r}){let{api:i}=z(),a=_(),o=Oy(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=N({queryKey:[...X5(e),n],queryFn:()=>zo(i,e),enabled:l&&!r}),d=P({mutationFn:()=>Bo(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t}". The outputs are all still here.`,`success`),onError:e=>o(`The working files of "${t}" weren't removed: ${e.message}`,`error`),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:X5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:B.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=Y5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{as:`h3`,title:`Free space`,meta:`Outputs ${Y5(f.outputsBytes)} · working files ${Y5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Free ${p}: keep the outputs, drop the working files`,disabled:d.isPending,disabledReason:`Removing the working files…`,onClick:()=>c(!0),children:d.isPending?`Removing…`:`Free ${p}`})}),(0,h.jsx)(jy,{open:s,title:`Free ${p} from "${t}"?`,consequence:J5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function Zve({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=eye(e.status);return(0,h.jsx)(kq,{crumb:(0,h.jsxs)(ha,{to:`/projects`,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(dc,{"aria-hidden":`true`,strokeWidth:1.75}),`Projects`]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[tye(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:s.tone,children:[s.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`Project: ${s.word}`})]}),a!==void 0&&Qve(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(V,{id:`project.next-chapter`}),a.error===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`max-w-[320px] text-small text-danger`,children:a.error})]}):null,(0,h.jsxs)(R,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{label:`More project actions`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{children:i.map(e=>(0,h.jsx)($ve,{item:e},e.id))})]})]})})}function Qve(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function $ve({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(e_e,{}):null,(0,h.jsx)(_8,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function eye(e){switch(e){case`running`:return{tone:`running`,word:`Running`};case`paused`:return{tone:`waiting`,word:`Paused`};case`failed`:return{tone:`failed`,word:`Failed`};case`partial`:return{tone:`waiting`,word:`Done with problems`};case`done`:return{tone:`done`,word:`Done`};case`canceled`:return{tone:`off`,word:`Canceled`};case`pending`:return{tone:`off`,word:`Queued`}}}function tye(e,t){let n=e.config.articlePrompt,r=t===void 0||t.some(e=>e.name===n),i=n===void 0||n===``?void 0:r?n:`${n} (deleted)`,a=e.config.voices?.book;return[a===void 0?void 0:LA(a),i,e.format,`started ${ku(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function nye({projectId:e}){let{api:t}=z(),n=N(Zy(t,e));return n.error===null?n.data===void 0?(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading run cost`,className:`flex flex-col gap-8`,children:[(0,h.jsx)(`span`,{className:`h-16 max-w-3xl rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`})]}):(0,h.jsx)(sye,{cost:n.data}):(0,h.jsx)(SI,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var rye=new Set([`done`,`partial`,`failed`,`canceled`]);function iye({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=r?.current===!0&&!rye.has(t),[a,o]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),!i||r===null)return null;let s=o7(r.workingMs+(r.running?Math.max(0,a-n):0));return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(zc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3.5 shrink-0`}),r.running?`Working for ${s}`:`${s} of work so far`]})]})}var aye=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:nF[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:o7(e.wallMs)}],oye=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:uye(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>t7.format(e.calls)}];function Z5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function sye({cost:e}){if(e.calls===0&&e.byStage.length===0)return(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Nothing has been spent yet. The cost of each provider call appears here as the run makes it.`});let t=e.byModel.some(e=>e.onPlan),n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({plan:e,window:t})):[]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{"aria-label":`Run cost summary`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(G2,{children:[(0,h.jsx)(K2,{value:a7(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(K2,{value:`~${a7(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${Z5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${n7.format(t.usedPercent)}%`;return(0,h.jsx)(K2,{value:r,label:`of ${n}`,children:(0,h.jsx)(q2,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${n7.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(K2,{value:o7(e.run.workingMs),label:`this run's working time`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 text-small text-ink-2`,children:[e.unpriced>0?(0,h.jsx)(`p`,{className:`m-0`,children:`Plus ${i7(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:cye(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:lye(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(H,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by stage`,columns:aye,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(H,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by model`,columns:oye,rows:e.byModel,rowKey:e=>`${e.provider}/${e.model}/${e.kind}`})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In total: ${e7(e.totals)||`no reported usage`} · ${o7(e.totals.wallMs)} working, over every run.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Priced from the model catalogue${e.catalogueDate===null?``:` of ${e.catalogueDate}`} when each call finished. Retries that failed are not charged here; taxes and included credits are not counted.`})]})]})}function cye(e){let t=e.apiEquivalent??0;if(t===0&&e.apiUnpriced>0)return`CLI calls: $0 on your plan · no API price is listed for their models.`;let n=e.apiUnpriced>0?` (plus ${i7(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${a7(t)} via API${n}.`}function lye(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=Z5(t.kind),r=t.usedPercent<1?`under 1%`:`~${n7.format(t.usedPercent)}%`,i=`now at ${n7.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${fye(t.resetsAt)}`}`;return`This run used ${r} of your ${n} ${e.name} limit (${i}).`}).join(` `):`${e.name} did not report its plan limits for this run, so the share it used is not known.`}function Q5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${a7(e.cost)} + unknown`:a7(e.cost)}function $5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${a7(e.apiEquivalent)}`}function uye(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function e7(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${r7(e.tokensIn)} in / ${r7(e.tokensOut)} out tokens${e.cachedTokens>0?` (${r7(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${r7(e.characters)} characters`),e.images>0&&t.push(i7(e.images,`image`)),e.seconds>0&&t.push(`${t7.format(e.seconds)} s of video`),t.join(` · `)}var t7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),n7=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),dye=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function r7(e){return e<1e4?t7.format(e):dye.format(e)}function i7(e,t){return`${t7.format(e)} ${t}${e===1?``:`s`}`}function a7(e){return e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function o7(e){let t=Math.round(e/1e3);if(t<60)return`${t} s`;let n=Math.floor(t/60);return n<60?`${n} min ${t%60} s`:`${Math.floor(n/60)} h ${n%60} min`}function fye(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function pye({project:e,revisionId:t,stages:n,outputs:r}){let i=r.filter(e=>e.role===`image`).sort((e,t)=>(e.meta.index??0)-(t.meta.index??0)),a=n.find(e=>e.kind===`article`),o=(0,m.use)(g3);return(0,h.jsx)(`div`,{className:`flex min-w-0 flex-col`,children:(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{title:`Article`}),a?.state===`running`?(0,h.jsx)(j3,{projectId:e.id,stage:`article`,className:`mb-6`}):a?.state===`done`?(0,h.jsxs)(`p`,{className:`mb-6 flex flex-wrap items-center gap-3 text-small text-ink-2`,children:[`The article is written.`,o===void 0?null:(0,h.jsx)(R,{variant:`secondary`,size:`small`,onClick:()=>o(`output`),children:`Read it`})]}):(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:a===void 0||a.state===`skipped`?`This project has no article.`:`The article appears here as it is written.`}),(0,h.jsx)(H,{title:`Narration`}),(0,h.jsx)(hye,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(H,{title:`Images`}),i.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The images appear here as each one is drawn.`}):(0,h.jsx)(B0,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(mye,{output:t,aspect:p5(e.format)},t.id))})]})})}function mye({output:e,aspect:t}){let n=b8(e);if(n===void 0)return null;let r=e.meta.index===void 0?``:` ${String(e.meta.index)}`;return(0,h.jsx)(`li`,{className:`min-w-0`,children:(0,h.jsx)(z0,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function hye({projectId:e,revisionId:t,audio:n,outputs:r}){let i=r.find(e=>e.role===`audio_levelled`&&e.meta.segment===`body`)??r.find(e=>e.role===`audio_body`),a=b8(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s7,{projectId:e,revisionId:t}),(0,h.jsx)(q8,{projectId:e})]}):a===void 0?(0,h.jsx)(s7,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)($8,{label:`Body narration`,src:a.url})})}var gye=240;function s7({projectId:e,revisionId:t}){let{api:n}=z(),r=N({queryKey:Py(e,t),queryFn:()=>Ky(n,e),enabled:t!==null}),i=(r.data?.pieces??[]).flatMap(e=>e.peaks),a=(r.data?.pieces??[]).reduce((e,t)=>e+t.seconds,0),o=Math.max(1,Math.ceil(i.length/gye)),s=[];for(let e=0;e<i.length;e+=o)s.push(Math.max(...i.slice(e,e+o)));return(0,h.jsxs)(`div`,{className:`mb-6`,children:[(0,h.jsx)(`div`,{role:`img`,"aria-label":s.length===0?`No narration yet`:`Narration so far: ${o7(a*1e3)}`,className:`flex h-16 items-center gap-px overflow-hidden rounded-control border border-line bg-raised px-2`,children:s.map((e,t)=>(0,h.jsx)(`span`,{className:`w-[3px] shrink-0 rounded-full bg-accent`,style:{height:`${String(Math.max(4,Math.round(e*100)))}%`}},t))}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:r.error?r.error.message:s.length===0?`The waveform grows as each part of the narration is spoken.`:`${o7(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function _ye(e){let t=[],n=[],r=0,i=()=>{let e=n[0],r=n.at(-1);e!==void 0&&r!==void 0&&t.push({start:e.start,end:r.end,text:c7(n.map(e=>e.text)),...e.speaker===void 0?{}:{speaker:e.speaker}}),n=[]};for(let t of e){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<r-.001||t.end<=t.start)throw Error(`The saved caption timing is damaged. Use More → Render the video again in the Video section to time them again, then Try again.`);let e=n[0];e!==void 0&&(t.start-r>.7||t.speaker!==e.speaker||t.end-e.start>5||c7([...n.map(e=>e.text),t.text]).split(`
299
+ `)}function hve(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function T5(e,t){let n=n=>hve(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function E5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}var gve=q({number:G().int().positive(),first:G().int().positive(),last:G().int().positive(),start:G().finite().nonnegative(),end:G().finite().positive(),title:W(),description:W(),hashtags:K(W()),why:W(),text:W(),seed:W().nullable().optional()}),_ve=.25,vve=.4;function D5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(_ve,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(vve,(s-a.end)/2)));return{start:O5(c),end:O5(l)}}q({first:tO([G(),W()]),last:tO([G(),W()]),title:W(),description:W(),hashtags:K(W()),why:W().optional()});function O5(e){return Math.round(e*1e3)/1e3}var yve=q({shorts:K(gve),durationSeconds:G().finite().nonnegative().optional(),sentences:K(q({start:G().finite().nonnegative(),end:G().finite().nonnegative(),text:W()})).optional()});function bve(e){if(e!=null)try{let t=yve.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function xve(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=D5(o,n,r,Sve(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function Sve(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function k5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:mq(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:mq(n,e.config.values)]))}}}}function Cve(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:ON(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function A5(e,t,n){return k5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function wve(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function j5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=z(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await Vo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await wve(r.signal);let e=(await Po(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Ho(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(xV,{label:e,id:s,children:(0,h.jsx)(CV,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(R,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var M5=`shorts:pick`,N5=e=>`shorts:${String(e)}`;function P5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],M5])]}}function F5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],N5(t)])]}}function Tve(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=bve(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function Eve({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Lk,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Jk(o)}),l=[...n,...I5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...I5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(M5)===!0,f=Tve(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(YV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(Dve,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(O6,{settings:KV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?Ave(n,e):A5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=qk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(Ove,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function Dve({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(j5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function Ove({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:D5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(V,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==M5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>o(P5(e)),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(kve,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(N5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):xve(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?F5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==N5(t.number))})},t.number))})]})}function kve({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(xV,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(TV,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(V,{id:`project.shorts.remake`})]})]})]})}function I5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function Ave(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return k5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var jve=q({shorts:K(q({number:G(),first:G().optional(),last:G().optional(),start:G(),end:G(),title:W(),description:W(),hashtags:K(W())}))});function Mve({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=f8(n,e),a=p8(i,`shorts`),o=z5(i),s=F8(t.id),[c,l]=(0,m.useState)(),u=L5(i,`short_video`,o),d=t.config.shorts,f=(0,m.use)(J8),p=(0,m.use)(Y8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let g=f&&p!==void 0&&d?.enabled===!0,_=e=>{let t=Uk(e,d?.fullVideoLink),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(A8,{files:o.map(e=>({output:u.find(t=>R5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:g&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...Ob,children:[(0,h.jsx)(R,{onClick:()=>p({section:`shorts`,change:P5}),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(B0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(Nve,{clip:n,projectId:t.id,review:I8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>R5(e,n)),stills:L5(i,`short_image`,o).filter(e=>R5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:d?.fullVideoLink,wanted:Kk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:Ive(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>_(n),...g?{onRemake:()=>p({section:`shorts`,change:e=>F5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(Q1,{tone:c?.tone??`info`,children:c?.text})]})}function Nve({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=b8(r),g=b8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(R0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(z0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:_F(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(Pve,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(B8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Ey,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(hS,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(wy,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(m8,{children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{align:`start`,children:(0,h.jsxs)(_8,{onSelect:d,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function Pve({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(vS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function L5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>R5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function R5(e,t){return e.meta.short===t.number}function z5(e){return Fve(M8(p8(e,`shorts`)).data)}function Fve(e){if(e===void 0)return[];try{let t=jve.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function Ive(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function Lve({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=z(),a=Oy(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=p8(f8(n,e),o?`audio_export`:`video`),c=f8(n,e),l=p8(c,`subtitles_srt`),u=p8(c,`subtitles_vtt`),d=p8(c,`youtube_description`),f=p8(c,`youtube_tags`),p=p8(c,`audio_mp3`),m=p8(c,`audio_m4b`),g=L5(c,`short_video`,z5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=b8(s),v=b8(Rve(n)),y=zve(t.id,d,f,s?.durationMs??null),b=b8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=vF(e.progressCurrent??0,e.progressTotal??0);return bx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await c2(i,{projectId:t.id,asset:D3(s),folder:_?.folder??null});e.opened||a(`${l2} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(w8,{children:r}):(0,h.jsxs)(w8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:aF(e,t.config)?`Preparing subtitles · ${String(vF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:uF(lF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)($8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(R0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,className:t.format===`9:16`?`max-w-[360px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(A8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(j8,{children:[_F(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:hk(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||VO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:VO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function Rve(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function zve(e,t,n,r){let{api:i}=z(),a=M8(t).data,o=M8(n).data,s=N({queryKey:B.youtubeEdits(e),queryFn:()=>Es(i,e),enabled:t!==void 0});return a===void 0?[]:Bve(E5(T5(w5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function Bve(e,t){return C5(e,t).text.split(`
300
+ `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:S5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function Vve(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(w_e,{...e});case`audio`:return(0,h.jsx)(P_e,{...e});case`images`:return(0,h.jsx)(lve,{...e});case`video`:return(0,h.jsx)(Lve,{...e});case`document`:return(0,h.jsx)(R_e,{...e});case`research`:case`thumbnail`:return null}}q({summary:W(),chapters:K(q({start:tO([W(),G()]),title:W()})),hashtags:K(W()),tags:K(W()),pinnedComment:W(),titles:K(W())});function B5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function Hve({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=z(),a=_(),o=f8(n,e),s=p8(o,`youtube_description`),c=p8(o,`youtube_tags`),l=p8(o,`youtube_pinned_comment`),u=p8(o,`youtube_titles`),d=M8(s).data,f=M8(c).data,p=M8(l).data,g=M8(u).data,v=(0,m.use)(X8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=N({queryKey:B.youtubeEdits(t.id),queryFn:()=>Es(i,t.id)}),T=N({queryKey:B.projectChannelLinks(t.id),queryFn:()=>Ts(i,t.id)}),[E,D]=(0,m.useState)(),O=Oy(),k=e=>a.setQueryData(B.youtubeEdits(t.id),e),A=P({mutationFn:e=>Ds(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),ee=(0,m.useRef)({});if(bx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:lP.copyDescription,run:()=>ee.current.description===void 0?O(`The description has not been written yet.`,`info`):ee.current.description()}),bx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>ee.current.tags===void 0?O(`The tags have not been written yet.`,`info`):ee.current.tags()}),bx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>ee.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):ee.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let te=d===void 0?void 0:w5(d,f??``,{pinnedComment:p,titles:g}),ne=T5(te,w.data?.fields??{}),j=E5(ne),re=Nj(T.data?.links??[],w.data?.links??[]),M=p8(o,`video`),ie=C5(j.chapters,M?.durationMs===null||M?.durationMs===void 0?void 0:M.durationMs/1e3),ae=fve(ie.adjustments),oe=Fj(mve({...j,chapters:ie.text}),re),se=Fj(j.tags,re),ce=Fj(j.pinnedComment,re),le=[...oe.unknown,...se.unknown,...ce.unknown].filter((e,t,n)=>n.findIndex(t=>Mj(t)===Mj(e))===t),ue=G5(se.text),de=te!==void 0,fe=ce.text.trim()!==``,pe=j.titles.split(`
301
+ `).map(e=>e.trim()).filter(e=>e!==``),me=(e,t)=>{let n=`Couldn't copy the ${t}. Select the text in the YouTube section and copy it.`;if(!navigator.clipboard){D({text:n,tone:`error`}),O(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),O(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),O(n,`error`)})};ee.current=de?{description:()=>me(oe.text,`description`),tags:()=>me(se.text,`tags`),...fe?{pinnedComment:()=>me(ce.text,`pinned comment`)}:{}}:{};let he=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,ge=(e,t)=>(0,h.jsx)(Uve,{label:V5[e],value:ne[e],links:re,disabled:!de||A.isPending,multiline:e!==`hashtags`,placeholder:de&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again above to have one written, or Edit to write your own.`:de&&e===`titles`?`Written before other titles existed. Use Write again above to have two written, or Edit to write your own, one per line.`:he,render:t,onSave:t=>A.mutate({field:e,edit:{text:t,base:te?.[e]??``},done:`Saved your ${V5[e].toLowerCase()}.`}),onUseGenerated:()=>A.mutate({field:e,edit:null,done:`The ${V5[e].toLowerCase()} follows the generated text again.`}),onKeepMine:(t,n)=>A.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${V5[e].toLowerCase()}.`})},e);return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`@container flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sr-only`,children:`YouTube`}),(0,h.jsxs)(`div`,{className:`flex min-w-0 max-w-[80ch] flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:de?()=>me(oe.text,`description`):void 0,keyshortcuts:Mx(lP.copyDescription),count:de?`${String(oe.text.length)} / ${String(S6)} characters`:void 0,over:oe.text.length>S6,main:!0,again:de&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`summary`),ge(`chapters`,()=>ie.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(W5,{text:ie.text,links:re})),ae===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:ae}),ge(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:de?()=>me(se.text,`tags`):void 0,count:de?`${String(B5(ue))} / 500 characters`:void 0,over:B5(ue)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:ge(`tags`,e=>(0,h.jsx)(Wve,{text:e,links:re}))}),(0,h.jsx)(U5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:de&&fe?()=>me(ce.text,`pinned comment`):void 0,count:de&&fe?`${String(ce.text.length)} / 500 characters`:void 0,over:ce.text.length>500}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`pinnedComment`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Post it under the video once it is published, then choose Pin in the comment's menu.`})]}),(0,h.jsx)(U5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:de&&pe.length>0?()=>me(pe.join(`
302
+ `),`other titles`):void 0,count:de&&pe.length>0?`${String(pe.length+1)} titles to test`:void 0,over:pe.some(e=>e.length>100)}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`titles`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`For YouTube's A/B Testing beside the title, with this project's own title "${t.title}". One per line.`})]})]})]}),le.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${le.map(e=>`{{${e}}}`).join(`, `)}, so it stays as typed. Add it under Channel links on `,T.data===void 0?`the channel's Brand tab`:(0,h.jsx)(ha,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${le.some(e=>Mj(e)===Mj(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(Gve,{projectId:t.id,edits:w.data,onSaved:e=>{k(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(Q1,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(jy,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags and pinned comment. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function U5({id:e,label:t,copy:n,count:r,over:i,keyshortcuts:a,main:o=!1,again:s,open:c,onToggle:l}){return(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-3 border-b border-line pb-2`,children:[(0,h.jsx)(`h4`,{id:e,className:`m-0 text-title-3 font-semibold text-ink`,children:l===void 0?t:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,"aria-expanded":c===!0,onClick:l,className:`-ml-2 h-auto px-2 py-1 text-title-3 font-semibold text-ink`,children:[(0,h.jsx)(fc,{"aria-hidden":`true`,strokeWidth:1.75,className:L(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:L(`text-small tabular-nums`,i?`text-danger`:`text-ink-3`),children:i?`${r}, over YouTube's limit`:r}),(0,h.jsx)(`span`,{className:`flex-1`}),s===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`secondary`,onClick:s,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(R,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function Uve({label:e,value:t,links:n,disabled:r,multiline:i,placeholder:a,render:o,onSave:s,onUseGenerated:c,onKeepMine:l}){let u=(0,m.useId)(),[d,f]=(0,m.useState)(),[p,g]=(0,m.useState)(!1),_=d!==void 0,v=e.toLowerCase(),y=e in H5?H5[e]:void 0;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h5`,{id:`${u}-label`,className:`sl-kicker text-ink-3`,children:e}),y===void 0?null:(0,h.jsx)(V,{id:y,label:v,className:`-my-1`})]}),t.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),t.edited&&!_?(0,h.jsx)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r,"aria-label":`Use the generated ${v}`,onClick:c,children:`Use generated`}):null,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r||_,"aria-label":`Edit ${v}`,onClick:()=>f(t.text),children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),t.pending===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-l-2 border-waiting pl-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`p`,{className:`text-small text-ink`,children:`New generated version available.`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Use the new generated ${v}`,onClick:c,children:`Use it`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Keep my ${v}`,onClick:()=>l(t.text,t.pending??``),children:`Keep mine`}),(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-expanded":p,"aria-label":`${p?`Hide`:`View`} the ${v} diff`,onClick:()=>g(e=>!e),children:p?`Hide diff`:`View diff`})]}),p?(0,h.jsx)(w4,{before:t.text,after:t.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),_?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${u}-edit`,className:`sr-only`,children:e}),i?(0,h.jsx)(wV,{id:`${u}-edit`,rows:e===`Chapters`?8:5,value:d,onChange:e=>f(e.currentTarget.value)}):(0,h.jsx)(CV,{id:`${u}-edit`,value:d,onChange:e=>f(e.currentTarget.value)}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(R,{type:`button`,variant:`primary`,disabled:r,onClick:()=>{s(d),f(void 0)},children:[`Save `,v]}),(0,h.jsx)(R,{type:`button`,variant:`secondary`,onClick:()=>f(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${u}-label`,className:L(`min-w-0 whitespace-pre-wrap break-words text-small`,t.text===``?`text-ink-3`:`text-ink`),children:t.text===``?a:o===void 0?(0,h.jsx)(W5,{text:t.text,links:n}):o(t.text)})]})}function W5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:Pj(e,t).map(e=>{let t=String(n);return n+=e.kind===`text`?e.text.length:e.raw.length,e.kind===`text`?(0,h.jsx)(`span`,{children:e.text},t):e.url===void 0?(0,h.jsx)(`mark`,{title:`No link named ${e.name}`,className:`rounded-[2px] bg-waiting/25 px-0.5 text-ink`,children:e.raw},t):(0,h.jsx)(`span`,{title:e.raw,className:`underline decoration-dotted underline-offset-[3px]`,children:e.url},t)})})}function G5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function Wve({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:G5(e).map((e,n)=>(0,h.jsx)(`li`,{className:`rounded-full border border-line bg-raised px-2 py-0.5 text-small text-ink`,children:(0,h.jsx)(W5,{text:e,links:t})},n))})}function Gve({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=z(),a=(0,m.useId)(),o=t?.links.find(e=>Mj(e.name)===Mj(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=P({mutationFn:()=>{let n=(t?.links??[]).filter(e=>Mj(e.name)!==Mj(kj));return Os(i,e,l.trim()===``?n:[...n,{name:kj,url:l.trim()}])},onSuccess:e=>{c(void 0),n(e)},onError:e=>r(e.message)});return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[260px] flex-1 flex-col gap-1 sm:max-w-[520px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{className:`sl-field__label`,htmlFor:a,children:`Previous video for this project`}),(0,h.jsx)(V,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(CV,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(R,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var K5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function Kve({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=z(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(!1),g=(0,m.useRef)(!0),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=JSON.stringify([t,n.map(e=>[e.stage,e.checkpointId]).toSorted()]),b=s!==null&&s.baseIdentity!==y,x=s?.stages??n.map(e=>e.stage),S=K5.some(({stage:e})=>x.includes(e)!==n.some(t=>t.stage===e)),C=b||d!==null&&d.kind!==`success`,w=b?{kind:`refused`,message:`Checkpoint choices changed elsewhere. Press Reload checkpoint choices before saving, then make your change again.`}:d;(0,m.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,m.useEffect)(()=>{(d||b)&&_.current?.focus()},[d,b]);async function T(){if(!(p.current||!S||C)){p.current=!0,u(!0);try{let n=await cme(o,e,{revisionId:t,stages:x});if(!g.current)return;n.ok?n.value.revisionId===t?(a(n.value),c(null),f({kind:`success`,message:`Checkpoint choices saved.`})):f({kind:`refused`,message:`The project was edited elsewhere. Press Reload checkpoint choices to see its current choices.`}):f({kind:`refused`,message:n.message})}catch(e){g.current&&f({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the change`)} It may or may not have saved. Press Reload checkpoint choices before changing anything else.`})}finally{p.current=!1,g.current&&u(!1)}}}async function E(){if(!p.current){p.current=!0,u(!0);try{let e=await i();g.current&&e&&(c(null),f(null),v.current?.focus())}finally{p.current=!1,g.current&&u(!1)}}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(`fieldset`,{ref:v,tabIndex:-1,className:`space-y-2`,...Ob,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(V,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),K5.map(({stage:e,name:t})=>{let n=r.find(t=>t.kind===e),i=n?.state===`pending`&&(e===`video`?n.source!==`off`||r.some(e=>e.kind===`audio`&&e.source!==`off`&&e.state!==`skipped`):(n.source??`generate`)===`generate`);return(0,h.jsxs)(`label`,{className:`flex min-h-10 items-center gap-3`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),disabled:!i||l||C,onChange:t=>{c({baseIdentity:s?.baseIdentity??y,stages:t.target.checked?[...x,e]:x.filter(t=>t!==e)}),f(null)}}),`Before `,t]},e)})]}),w?(0,h.jsx)(`p`,{ref:_,tabIndex:-1,role:w.kind===`success`?`status`:`alert`,children:w.message}):null,(0,h.jsx)(R,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(R,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var q5=e=>e.charAt(0).toUpperCase()+e.slice(1);function qve(e){return e.revisionId===null?null:(0,h.jsx)(Jve,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function Jve({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=z(),o=_(),s=N({queryKey:f3(e,t),queryFn:()=>m3(a,e),retry:!1}),c=s.data,l=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t?e.data.value:void 0},u=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t};return s.isPending?null:s.error||c?.ok===!1?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:s.error?.message??(c?.ok===!1?c.message:`Checkpoints couldn't be loaded. Press Reload checkpoints.`)}),(0,h.jsx)(R,{onClick:()=>void u(),children:`Reload checkpoints`})]}):c?.ok?c.value.revisionId===t?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col gap-5`,children:[(0,h.jsx)(H,{title:`Review checkpoints`,size:`small`,className:`pb-0`}),n?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`The project is paused. Continue the run before approving held work.`}):null,(0,h.jsx)(Kve,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(f3(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:B.project(e)}),o.invalidateQueries({queryKey:B.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(Yve,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,...a.checkpointId===i?{inRail:!0}:{}},`${a.checkpointId}:${a.fingerprint}`))]}):(0,h.jsx)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The project was edited after these checkpoints loaded. Press Reload checkpoints before approving.`})}):null}function Yve({gate:e,disabled:t,reload:n,inRail:r=!1}){let{api:i}=z(),a=_(),o=(0,m.useRef)(null),s=(0,m.useRef)(!1),c=(0,m.useRef)(!0),l=(0,m.useRef)(null),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(null);(0,m.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,m.useEffect)(()=>{f!==null&&l.current?.focus()},[f]);let g=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function v(){if(!(s.current||t||!g||f?.kind===`refused`||f?.kind===`success`)){s.current=!0,d(!0),o.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await h3(i,e.projectId,e.checkpointId,o.current);o.current=null,c.current&&p(t.ok?{kind:`success`,message:t.value.replayed?`Checkpoint already approved.`:`Checkpoint approved. Work will run when its dependencies are ready.`}:{kind:`refused`,message:t.message}),a.invalidateQueries({queryKey:d3(e.projectId)}),a.invalidateQueries({queryKey:B.project(e.projectId)}),a.invalidateQueries({queryKey:B.projects})}catch(e){c.current&&p({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{s.current=!1,c.current&&d(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`${q5(e.stage)} checkpoint`,className:`pb-0`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`released`&&e.approvedAt!==null?`Authorized for this revision. Work can run when dependencies are ready and the project is resumed.`:e.state===`satisfied`?`Checkpoint satisfied. Its reviewed work is complete.`:e.state===`invalidated`||e.fingerprint!==e.currentFingerprint?`Inputs changed. Review the current revision before approving.`:g?`${q5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Reviewed revision: `,e.revisionId]}),e.dependents.length?(0,h.jsx)(`ul`,{"aria-label":`Dependent work`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:e.dependents.map(e=>(0,h.jsx)(`li`,{className:`sl-chip`,children:q5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),f?(0,h.jsx)(`p`,{ref:l,tabIndex:-1,role:f.kind===`success`?`status`:`alert`,className:f.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:f.message}):null,g&&r&&f===null?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Its approval is the project's next action, in the right rail.`}):g?(0,h.jsx)(R,{className:`self-start`,disabled:t||u||f?.kind===`refused`||f?.kind===`success`,onClick:()=>void v(),children:u?`Approving…`:f?.kind===`transport`?`Retry approval`:`Approve ${q5(e.stage)} checkpoint`}):null,f?.kind===`refused`?(0,h.jsx)(R,{className:`self-start`,onClick:async()=>{await n()&&p(null)},children:`Reload checkpoints`}):null]})}function Xve({projects:e,queryKey:t}){let{api:n}=z(),r=_(),i=Oy(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=P({mutationFn:e=>Bo(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t.title}" (${String(e.files)} working file${e.files===1?``:`s`}).`,`success`)},onError:e=>c(e.message),onSettled:()=>r.invalidateQueries({queryKey:t})}),u=e.toSorted((e,t)=>t.bytes-e.bytes);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-2 flex items-center gap-1 text-small text-ink-2`,children:[`Keep outputs only frees a finished project's working files.`,(0,h.jsx)(V,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(pU,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(mU,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[Y5(e.bytes),` · outputs `,Y5(e.outputsBytes),` · working files `,Y5(e.workingBytes)]}),actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:!e.finished||e.removableBytes===0||l.isPending,title:e.finished?e.removableBytes===0?`No working files left to remove.`:`Frees ${Y5(e.removableBytes)}.`:`Available once the project has finished.`,onClick:()=>o(e),children:l.isPending&&l.variables?.id===e.id?`Removing…`:`Keep outputs only`})},e.id))}),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:s}),(0,h.jsx)(jy,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:J5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function J5(e,t){return`This removes ${String(e)} working file(s) and frees ${Y5(t)}: the images, narration parts, subtitle timing and render settings the project was made from. The video, shorts, thumbnail, article, description and document stay, and so does anything you uploaded. If you change this project later (edit an image, a caption style or the narration, or re-render), Slopify has to make those files again first, which takes time and uses provider credits.`}function Y5(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var X5=e=>[`storage`,`project`,e];function Zve({projectId:e,title:t,status:n,sample:r}){let{api:i}=z(),a=_(),o=Oy(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=N({queryKey:[...X5(e),n],queryFn:()=>zo(i,e),enabled:l&&!r}),d=P({mutationFn:()=>Bo(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t}". The outputs are all still here.`,`success`),onError:e=>o(`The working files of "${t}" weren't removed: ${e.message}`,`error`),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:X5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:B.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=Y5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{as:`h3`,title:`Free space`,meta:`Outputs ${Y5(f.outputsBytes)} · working files ${Y5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Free ${p}: keep the outputs, drop the working files`,disabled:d.isPending,disabledReason:`Removing the working files…`,onClick:()=>c(!0),children:d.isPending?`Removing…`:`Free ${p}`})}),(0,h.jsx)(jy,{open:s,title:`Free ${p} from "${t}"?`,consequence:J5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function Qve({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=tye(e.status);return(0,h.jsx)(kq,{crumb:(0,h.jsxs)(ha,{to:`/projects`,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(dc,{"aria-hidden":`true`,strokeWidth:1.75}),`Projects`]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[nye(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:s.tone,children:[s.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`Project: ${s.word}`})]}),a!==void 0&&$ve(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(V,{id:`project.next-chapter`}),a.error===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`max-w-[320px] text-small text-danger`,children:a.error})]}):null,(0,h.jsxs)(R,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{label:`More project actions`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{children:i.map(e=>(0,h.jsx)(eye,{item:e},e.id))})]})]})})}function $ve(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function eye({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(t_e,{}):null,(0,h.jsx)(_8,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function tye(e){switch(e){case`running`:return{tone:`running`,word:`Running`};case`paused`:return{tone:`waiting`,word:`Paused`};case`failed`:return{tone:`failed`,word:`Failed`};case`partial`:return{tone:`waiting`,word:`Done with problems`};case`done`:return{tone:`done`,word:`Done`};case`canceled`:return{tone:`off`,word:`Canceled`};case`pending`:return{tone:`off`,word:`Queued`}}}function nye(e,t){let n=e.config.articlePrompt,r=t===void 0||t.some(e=>e.name===n),i=n===void 0||n===``?void 0:r?n:`${n} (deleted)`,a=e.config.voices?.book;return[a===void 0?void 0:LA(a),i,e.format,`started ${ku(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function rye({projectId:e}){let{api:t}=z(),n=N(Zy(t,e));return n.error===null?n.data===void 0?(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading run cost`,className:`flex flex-col gap-8`,children:[(0,h.jsx)(`span`,{className:`h-16 max-w-3xl rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`})]}):(0,h.jsx)(cye,{cost:n.data}):(0,h.jsx)(SI,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var iye=new Set([`done`,`partial`,`failed`,`canceled`]);function aye({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=r?.current===!0&&!iye.has(t),[a,o]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),!i||r===null)return null;let s=o7(r.workingMs+(r.running?Math.max(0,a-n):0));return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(zc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3.5 shrink-0`}),r.running?`Working for ${s}`:`${s} of work so far`]})]})}var oye=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:nF[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:o7(e.wallMs)}],sye=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:dye(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>t7.format(e.calls)}];function Z5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function cye({cost:e}){if(e.calls===0&&e.byStage.length===0)return(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Nothing has been spent yet. The cost of each provider call appears here as the run makes it.`});let t=e.byModel.some(e=>e.onPlan),n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({plan:e,window:t})):[]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{"aria-label":`Run cost summary`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(G2,{children:[(0,h.jsx)(K2,{value:a7(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(K2,{value:`~${a7(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${Z5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${n7.format(t.usedPercent)}%`;return(0,h.jsx)(K2,{value:r,label:`of ${n}`,children:(0,h.jsx)(q2,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${n7.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(K2,{value:o7(e.run.workingMs),label:`this run's working time`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 text-small text-ink-2`,children:[e.unpriced>0?(0,h.jsx)(`p`,{className:`m-0`,children:`Plus ${i7(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:lye(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:uye(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(H,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by stage`,columns:oye,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(H,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by model`,columns:sye,rows:e.byModel,rowKey:e=>`${e.provider}/${e.model}/${e.kind}`})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In total: ${e7(e.totals)||`no reported usage`} · ${o7(e.totals.wallMs)} working, over every run.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Priced from the model catalogue${e.catalogueDate===null?``:` of ${e.catalogueDate}`} when each call finished. Retries that failed are not charged here; taxes and included credits are not counted.`})]})]})}function lye(e){let t=e.apiEquivalent??0;if(t===0&&e.apiUnpriced>0)return`CLI calls: $0 on your plan · no API price is listed for their models.`;let n=e.apiUnpriced>0?` (plus ${i7(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${a7(t)} via API${n}.`}function uye(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=Z5(t.kind),r=t.usedPercent<1?`under 1%`:`~${n7.format(t.usedPercent)}%`,i=`now at ${n7.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${pye(t.resetsAt)}`}`;return`This run used ${r} of your ${n} ${e.name} limit (${i}).`}).join(` `):`${e.name} did not report its plan limits for this run, so the share it used is not known.`}function Q5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${a7(e.cost)} + unknown`:a7(e.cost)}function $5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${a7(e.apiEquivalent)}`}function dye(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function e7(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${r7(e.tokensIn)} in / ${r7(e.tokensOut)} out tokens${e.cachedTokens>0?` (${r7(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${r7(e.characters)} characters`),e.images>0&&t.push(i7(e.images,`image`)),e.seconds>0&&t.push(`${t7.format(e.seconds)} s of video`),t.join(` · `)}var t7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),n7=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),fye=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function r7(e){return e<1e4?t7.format(e):fye.format(e)}function i7(e,t){return`${t7.format(e)} ${t}${e===1?``:`s`}`}function a7(e){return e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function o7(e){let t=Math.round(e/1e3);if(t<60)return`${t} s`;let n=Math.floor(t/60);return n<60?`${n} min ${t%60} s`:`${Math.floor(n/60)} h ${n%60} min`}function pye(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function mye({project:e,revisionId:t,stages:n,outputs:r}){let i=r.filter(e=>e.role===`image`).sort((e,t)=>(e.meta.index??0)-(t.meta.index??0)),a=n.find(e=>e.kind===`article`),o=(0,m.use)(g3);return(0,h.jsx)(`div`,{className:`flex min-w-0 flex-col`,children:(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{title:`Article`}),a?.state===`running`?(0,h.jsx)(j3,{projectId:e.id,stage:`article`,className:`mb-6`}):a?.state===`done`?(0,h.jsxs)(`p`,{className:`mb-6 flex flex-wrap items-center gap-3 text-small text-ink-2`,children:[`The article is written.`,o===void 0?null:(0,h.jsx)(R,{variant:`secondary`,size:`small`,onClick:()=>o(`output`),children:`Read it`})]}):(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:a===void 0||a.state===`skipped`?`This project has no article.`:`The article appears here as it is written.`}),(0,h.jsx)(H,{title:`Narration`}),(0,h.jsx)(gye,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(H,{title:`Images`}),i.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The images appear here as each one is drawn.`}):(0,h.jsx)(B0,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(hye,{output:t,aspect:p5(e.format)},t.id))})]})})}function hye({output:e,aspect:t}){let n=b8(e);if(n===void 0)return null;let r=e.meta.index===void 0?``:` ${String(e.meta.index)}`;return(0,h.jsx)(`li`,{className:`min-w-0`,children:(0,h.jsx)(z0,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function gye({projectId:e,revisionId:t,audio:n,outputs:r}){let i=r.find(e=>e.role===`audio_levelled`&&e.meta.segment===`body`)??r.find(e=>e.role===`audio_body`),a=b8(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s7,{projectId:e,revisionId:t}),(0,h.jsx)(q8,{projectId:e})]}):a===void 0?(0,h.jsx)(s7,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)($8,{label:`Body narration`,src:a.url})})}var _ye=240;function s7({projectId:e,revisionId:t}){let{api:n}=z(),r=N({queryKey:Py(e,t),queryFn:()=>Ky(n,e),enabled:t!==null}),i=(r.data?.pieces??[]).flatMap(e=>e.peaks),a=(r.data?.pieces??[]).reduce((e,t)=>e+t.seconds,0),o=Math.max(1,Math.ceil(i.length/_ye)),s=[];for(let e=0;e<i.length;e+=o)s.push(Math.max(...i.slice(e,e+o)));return(0,h.jsxs)(`div`,{className:`mb-6`,children:[(0,h.jsx)(`div`,{role:`img`,"aria-label":s.length===0?`No narration yet`:`Narration so far: ${o7(a*1e3)}`,className:`flex h-16 items-center gap-px overflow-hidden rounded-control border border-line bg-raised px-2`,children:s.map((e,t)=>(0,h.jsx)(`span`,{className:`w-[3px] shrink-0 rounded-full bg-accent`,style:{height:`${String(Math.max(4,Math.round(e*100)))}%`}},t))}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:r.error?r.error.message:s.length===0?`The waveform grows as each part of the narration is spoken.`:`${o7(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function vye(e){let t=[],n=[],r=0,i=()=>{let e=n[0],r=n.at(-1);e!==void 0&&r!==void 0&&t.push({start:e.start,end:r.end,text:c7(n.map(e=>e.text)),...e.speaker===void 0?{}:{speaker:e.speaker}}),n=[]};for(let t of e){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<r-.001||t.end<=t.start)throw Error(`The saved caption timing is damaged. Use More → Render the video again in the Video section to time them again, then Try again.`);let e=n[0];e!==void 0&&(t.start-r>.7||t.speaker!==e.speaker||t.end-e.start>5||c7([...n.map(e=>e.text),t.text]).split(`
303
303
  `).length>2)&&i(),n.push({...t,text:t.text.replace(/\s+/g,` `).trim()}),r=t.end,/[.!?]["'’”)]*$/.test(t.text)&&i()}return i(),t}function c7(e){let t=[],n=``;for(let r of e)n!==``&&n.length+r.length+1>42&&(t.push(n),n=``),n=n===``?r:`${n} ${r}`;return n!==``&&t.push(n),t.join(`
304
- `)}function vye({cues:e,duration:t,onChange:n,onPending:r}){let i=(0,m.useId)(),[a,o]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[s,c]=(0,m.useState)(),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(r);d.current=r,(0,m.useEffect)(()=>{d.current(l)},[l]),(0,m.useEffect)(()=>()=>d.current(!1),[]);function f(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){c(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,o]of a.entries()){let a=o.start.trim()===``?NaN:Number(o.start),s=o.end.trim()===``?NaN:Number(o.end);if(r.has(o.id)){c(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(o.id),!Number.isFinite(a)||a<0||a<i){c(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=a||s>t){c(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(o.text.trim()===``){c(`Caption ${n+1}: enter caption text.`);return}e.push({id:o.id,text:o.text,start:a,end:s,...o.speaker===void 0?{}:{speaker:o.speaker}}),i=s}n(e),c(void 0),u(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(V,{id:`project.captions.editor`})]}),a.map((e,t)=>(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Caption `,t+1]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(wV,{id:`${i}-${e.id}-text`,value:e.text,onChange:n=>{u(!0),o(a.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{u(!0),o(a.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{u(!0),o(a.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:s}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:f,children:`Apply caption edits to draft`}),(0,h.jsx)(V,{id:`project.captions.apply`})]}),l?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function l7(e){return`imagePrompts.${String(e)}`}function u7(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function yye(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function bye(e){let{from:t,to:n,content:r}=e,i=n.map(e=>t.findIndex(t=>t.name===e.name)),a=[],o={},s={};for(let[e,t]of Object.entries(r.promptTemplates))u7(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))u7(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=l7(t),l=i[t]??-1;if(l>=0){let t=l7(l);Object.hasOwn(r.promptTemplates,t)&&(o[n]=r.promptTemplates[t]??null);let i=e.rendered[t];i!==void 0&&(s[n]=i);continue}let u=e.body(c.name);if(u===void 0){a.push({field:`imagePrompts.${String(t)}.name`,message:`The image prompt "${c.name}" is not in the Library any more. Untick it under Images, or add it back on Library → Prompts.`});continue}o[n]=u,s[n]=mq(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=u7(r.imageDefinitions[e]?.templateKey);n===void 0||n>=t.length||c.set(n,[...c.get(n)??[],e])}let l={},u=[],d=[],f=(e,t)=>{let n=l7(e),r=o[n];return t===void 0?{source:`generate`,assetId:null,prompt:s[n]??null,templateKey:r==null?null:n}:{...t,source:`generate`,assetId:null,templateKey:t.templateKey??null}},p=(t,n,r)=>Array.from({length:Math.max(0,n)},()=>{let n=e.key();return l[n]=f(t,r),u.push(n),n}),m=[];for(let e of r.imageOrder){let a=r.imageDefinitions[e];if(a===void 0)continue;let o=u7(a.templateKey);if(o===void 0||o>=t.length){l[e]=a,m.push(e);continue}let s=i.indexOf(o);if(s===-1){d.push(e);continue}let u=c.get(o)??[],f=t[o]?.number!==n[s]?.number,h=f?n[s]?.number??0:u.length,g=u.indexOf(e);if(g>=h){d.push(e);continue}let _=a.templateKey===l7(s)?a:{...a,templateKey:l7(s)};l[e]=_,m.push(e),f&&g===Math.min(u.length,h)-1&&m.push(...p(s,h-u.length,_))}for(let[e,r]of n.entries()){let n=i[e]??-1,a=n>=0?c.get(n)??[]:[];n>=0&&(a.length>0||t[n]?.number===r.number)||m.push(...p(e,r.number,void 0))}return{ok:!0,content:{...r,imageOrder:m,imageDefinitions:l,promptTemplates:o},rendered:s,added:u,removed:d}}function xye({edit:e,saved:t,prompts:n,problem:r,onChange:i}){let{config:a}=e;if(a.sources.images!==`generate`)return null;let o=n.filter(e=>e.kind===`image`);return(0,h.jsxs)(`section`,{"aria-label":`Image prompts`,className:`space-y-3`,children:[(0,h.jsx)(Y3,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(Sye,{edit:e,saved:t,prompts:o,problem:r})]})}function Sye({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(yye(t,i))return a===void 0?null:(0,h.jsx)(d7,{children:a});let o=0,s=bye({from:t,to:i,content:e.content,rendered:e.config.rendered,values:e.config.values,body:e=>n.find(t=>t.name===e)?.body,key:()=>`planned-${String(++o)}`});if(!s.ok)return(0,h.jsx)(d7,{children:s.fields.map(e=>e.message).join(` `)});let c=e=>`${String(e)} ${e===1?`image`:`images`}`,l=[...s.added.length>0?[`adds ${c(s.added.length)} to make`]:[],...s.removed.length>0?[`removes ${c(s.removed.length)}`]:[]];return(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsx)(d7,{children:a}),(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.length===0?`Saving keeps every image as it is.`:`Saving ${l.join(` and `)}. The other images are kept; the new ones are made when you remake outdated outputs.`})]})}function d7({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function Cye({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:iA(r)),o=r?.source===`upload`?[...Zk,`upload`]:Zk,s=i===void 0?[]:[...Eye(i)];return(0,h.jsx)(A2,{value:i,inherit:`None`,sources:o,offerNone:!1,problem:e=>t(`ambientBed.${e}`)??s.find(t=>t.field===e)?.message,onChange:t=>{a(t);let r=aA(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function wye({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...tk,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(k6,{value:i,problem:e=>t(`loudness.${e}`),onChange:t=>{a(t);let{loudness:r,...i}=e.config;n({...e,config:t.enabled?{...i,loudness:{videoLufs:t.videoLufs,audioFilesLufs:t.audioFilesLufs}}:i})}})}function Tye({edit:e,problem:t,onChange:n}){let[r,i]=(0,m.useState)(()=>({sentencePauseSeconds:String(e.config.sentencePauseSeconds??0),paragraphPauseSeconds:String(e.config.paragraphPauseSeconds??0)}));if(e.config.sources.audio!==`generate`)return null;let a=e=>{let t=F6(r[e]);return t===void 0?`Enter a number of seconds.`:bk(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(P6,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=F6(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function Eye(e){let t=aA(e);return t===void 0?[]:nA(t)}function Dye({edit:e,problem:t,onChange:n}){let r=(0,m.useId)(),{config:i}=e,a=i.imageScale,[o,s]=(0,m.useState)(()=>a===void 0?void 0:XO(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(qO(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=f7(t);l!==void 0&&n({...e,config:{...o,imageScale:{perHour:l,words:c},...a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})},u=i.imagePrompts.reduce((e,t)=>e+t.number,0),d=a===void 0?u:$O(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:f7(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(JO(c))))} minutes of narration: ${String(d)} images${d>u?`, ${String(d-u)} more than the prompts' ${String(u)}`:`, which the prompts' Numbers already cover`}.`},g=t(`imageScale`)??void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:[(0,h.jsx)(kb,{checked:o!==void 0,label:`More images for long videos`,describedBy:`${r}-line`,tip:`play.image-scale`,onChange:e=>l(e?{every:`minutes`,value:`2`}:void 0)}),o===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,value:o.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>l({every:e,value:Oye(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{"aria-label":o.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`w-[72px] tabular-nums`,"aria-invalid":p?.problem===!0,"aria-describedby":`${r}-line`,value:o.value,onChange:e=>l({every:o.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:o.every===`minutes`?`minutes`:`images per hour`})]}),g===void 0&&p===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:g!==void 0||p?.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:g??p?.text})]})}function f7(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?YO(t):void 0:t>=1&&t<=240?t:void 0}function Oye(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function kye({edit:e,onChange:t}){let{config:n}=e;return n.sources.images!==`generate`||n.sources.article===`off`?null:(0,h.jsx)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,config:{...a,...r?{imageScenes:!0}:{}}})}})})}function Aye({edit:e,view:t,imageKey:n,index:r}){let{api:i}=z(),a=e.content.imageDefinitions[n];if(a===void 0)return null;let o=t?.outputs.filter(e=>e.output.stageKind===`images`&&e.output.role===`image`)??[],s=o.find(e=>e.selected&&e.workKey===`image:${n}`),c=e.uploads?.some(e=>e.destination.kind===`image`&&e.destination.imageKey===n)??!1,l=a.source===`generate`||c||s?.assetId===a.assetId?s:o.find(e=>e.assetId===a.assetId&&e.available),u=l?.available===!0,d=!u&&(l!==void 0||a.source===`provide`&&a.assetId!==null),f=e.regenerate?.includes(`image:${n}`)===!0,p=c?u?`Replacement ready to save; previous image shown until Save`:`Replacement ready to save; preview available after Save`:f?`Made again after you press Save changes; the current image stays until then`:d?`Image file unavailable`:u?a.source===`provide`&&l!==s?`Provided image selected`:l.state===`review`?`Image retained; review required`:l.state===`outdated`?`Outdated image retained until rebuilt`:`Current image retained`:`No completed image yet`,m=u&&/\.(mp4|mov|m4v|webm|mkv)$/i.test(l.output.path);return(0,h.jsxs)(h.Fragment,{children:[!u||t===void 0?null:m?(0,h.jsx)(R0,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(z0,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}function p7(e,t,n){let r=t+n,i=e[t],a=e[r];if(i===void 0||a===void 0)return e;let o=[...e];return o[t]=a,o[r]=i,o}function jye({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),{content:c}=e,l=KO(e.config),u=(0,m.useRef)(e);u.current=e;function d(e){let n=e.content.imageOrder.flatMap(t=>{let n=e.content.imageDefinitions[t];return n===void 0?[]:[n]}),r=e.content.imageOrder.length===0||e.config.sources.images===`off`?`off`:n.some(e=>e.source===`generate`)?`generate`:`provide`,i={...e,config:{...e.config,sources:{...e.config.sources,images:r,...r===`off`?{video:`off`}:{}}}};u.current=i,t(i)}function f(e,t){let n=i?.()??u.current,r=n.content.imageDefinitions[e];if(r===void 0)return;let a=r.templateKey??`image:${e}`;s(t=>({...t,[e]:(t[e]??0)+1})),d(A5({...n,...n.uploads===void 0?{}:{uploads:n.uploads.filter(t=>t.destination.kind!==`image`||t.destination.imageKey!==e)},content:{...n.content,imageDefinitions:{...n.content.imageDefinitions,[e]:{...r,templateKey:a}}}},a,t))}function p(e){let t=i?.()??u.current,n=t.content,r=crypto.randomUUID();d({...t,config:{...t.config,sources:{...t.config.sources,images:t.config.sources.images===`off`?`provide`:t.config.sources.images}},content:{...n,imageOrder:[...n.imageOrder,r],imageDefinitions:{...n.imageDefinitions,[r]:{source:`provide`,assetId:null,prompt:null}}},uploads:[...t.uploads??[],{stagedFileId:e.id,destination:{kind:`image`,imageKey:r}}]})}return(0,h.jsxs)(`section`,{"aria-label":`Edit images`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Images`}),(0,h.jsx)(V,{id:`project.images.editor`})]}),c.imageOrder.map((t,s)=>{let l=c.imageDefinitions[t];return l===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(Aye,{edit:e,view:r,imageKey:t,index:s}),l.source===`generate`?(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${t}-prompt`,children:[`Prompt for image `,s+1]}),(0,h.jsx)(V,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${t}-prompt`,value:l.templateKey===void 0||l.templateKey===null?l.prompt??``:c.promptTemplates[l.templateKey]??l.prompt??``,onChange:e=>f(t,e.target.value)})]}):null,l.source===`generate`&&l.templateKey==null?(0,h.jsxs)(R,{type:`button`,onClick:()=>f(t,l.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(j5,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??u.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&d({...n,regenerate:(n.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:[...(n.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t),{stagedFileId:e.id,destination:{kind:`image`,imageKey:t}}],content:{...r,imageDefinitions:{...r.imageDefinitions,[t]:{...a,source:`provide`,prompt:null,templateKey:null}}}})}},`${t}:${o[t]??0}:${e.config.sources.images===`off`}`),(0,h.jsxs)(R,{type:`button`,disabled:s===0,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(R,{type:`button`,disabled:s===c.imageOrder.length-1,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(R,{type:`button`,onClick:()=>{let n=c.imageOrder.filter(e=>e!==t);d({...e,config:n.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...c,imageOrder:n,imageDefinitions:Object.fromEntries(Object.entries(c.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t)})},children:[`Delete image `,s+1,c.imageOrder.length===1?` and turn Images and Video Off`:``]}),l.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(V,{id:`project.images.regenerate`})]}):null]},t)}),(0,h.jsx)(R,{type:`button`,disabled:c.imageOrder.length>=l,onClick:()=>{if(c.imageOrder.length>=l)return;let t=crypto.randomUUID();d({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...c,imageOrder:[...c.imageOrder,t],promptTemplates:{...c.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...c.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),c.imageOrder.length>=l?(0,h.jsxs)(`p`,{children:[`At most `,l,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(j5,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:p},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(j5,{label:`Add a video clip`,kind:`images`,accept:`video/mp4,video/quicktime,video/webm,video/x-matroska,.mp4,.mov,.m4v,.webm,.mkv`,onPending:e=>n(`clip:new`,e),onReady:p},`new-clip:${e.config.sources.images===`off`}`)]})]})}var Mye=q({logicalKey:W().min(1),logicalText:W(),segment:J([`body`,`intro`,`outro`]),text:W()});function Nye(e,t){if(t==null)return e;let n=[...t.intro??[],...t.body??[],...t.outro??[]];return n.length===0?e:n.flatMap(t=>e.filter(e=>e.key===t))}function Pye(e){let t=new Map,n=new Set,r=0;for(let i of e.pieces){if(!i.selected||i.stageKind!==`audio`||i.piece.kind!==`chunk`)continue;let e;try{e=i.piece.payload===null?null:JSON.parse(i.piece.payload)}catch{r++;continue}let a=Mye.safeParse(e);if(!a.success){r++;continue}let{logicalKey:o,logicalText:s}=a.data;if(n.has(o)){r++;continue}let c=t.get(o);if(c!==void 0&&c.text!==s){r+=c.parts+1,t.delete(o),n.add(o);continue}t.set(o,{key:o,text:s,parts:(c?.parts??0)+1})}return{groups:[...t.values()],unmapped:r}}function Fye({view:e,edit:t,onChange:n,onPending:r,getEdit:i}){let a=(0,m.useId)(),{api:o}=z(),s=N({queryKey:[`narration-chunks`,e.revision.projectId,e.revision.id],queryFn:async()=>{let t=await Sfe(o,e.revision.projectId,e.revision.id);return t.ok?t.value.chunks:null},staleTime:1/0}),c=Pye(e),l=Nye(c.groups,s.data),u=c.unmapped,d=(0,m.useRef)(t);d.current=t;let[f,p]=(0,m.useState)({});function g(e){d.current=e,n(e)}return(0,h.jsxs)(`section`,{"aria-label":`Edit narration`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Narration`}),(0,h.jsx)(V,{id:`project.narration.editor`})]}),t.config.chunking?.mode===`whole`||t.config.chunking===void 0?(0,h.jsx)(`p`,{children:`This narration uses one whole request. Editing its text rebuilds the whole narration request.`}):null,u===0?null:(0,h.jsx)(`p`,{children:`Some older audio cannot be matched reliably to its narration text. Replace the provided narration or rebuild from the article to edit those chunks.`}),l.map((e,n)=>{let o=t.content.narrationOverrides[e.key];return(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Narration chunk `,n+1]}),(0,h.jsxs)(`p`,{children:[e.parts,` audio `,e.parts===1?`part`:`parts`,` in this narration chunk.`]}),(0,h.jsxs)(`div`,{className:`text-small`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.key}-text`,children:[`Text for narration chunk `,n+1]}),(0,h.jsx)(V,{id:`project.narration.chunk-text`,label:`text for narration chunk ${String(n+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${e.key}-text`,value:o?.kind===`text`?o.text:e.text,onChange:n=>{p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,...t.uploads===void 0?{}:{uploads:t.uploads.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key)},content:{...t.content,narrationOverrides:{...t.content.narrationOverrides,[e.key]:{kind:`text`,text:n.target.value}}}})}})]}),(0,h.jsx)(j5,{label:`Replace narration chunk ${n+1}`,kind:`audio`,onPending:t=>r(`narration:${e.key}`,t),onReady:t=>{let n=i?.()??d.current;g({...n,regenerate:(n.regenerate??[]).filter(t=>t!==e.key),uploads:[...(n.uploads??[]).filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),{stagedFileId:t.id,destination:{kind:`narration`,key:e.key}}]})}},`${e.key}:${f[e.key]??0}`),t.regenerate?.includes(e.key)?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Narration chunk `,n+1,` will be regenerated after you save and press Remake.`,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:()=>{let t=i?.()??d.current;g({...t,regenerate:(t.regenerate??[]).filter(t=>t!==e.key)})},children:[`Keep narration chunk `,n+1]})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(R,{type:`button`,onClick:()=>{let t=i?.()??d.current,n={...t.content.narrationOverrides};n[e.key]?.kind===`asset`&&delete n[e.key],p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,content:{...t.content,narrationOverrides:n},uploads:t.uploads?.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),regenerate:[...new Set([...t.regenerate??[],e.key])]})},children:[`Regenerate narration chunk `,n+1,` after review`]}),(0,h.jsx)(V,{id:`project.narration.regenerate`})]})]},e.key)})]})}function Iye(e){let{config:t,fingerprints:n}=e.revision;if(t.sources.audio===`off`)return;let r=t.sources.audio===`provide`?[{key:`audio:provided`,role:`audio_body`}]:[...t.intro===void 0?[]:[{key:`audio:intro`,role:`audio_intro`}],{key:`audio:body:concat`,role:`audio_body`},...t.outro===void 0?[]:[{key:`audio:outro`,role:`audio_outro`}]],i=e.outputs.filter(e=>e.selected&&e.state===`ready`&&e.available&&e.fingerprint===n[e.workKey]),a=r.map(({key:e,role:t})=>i.find(n=>n.workKey===e&&n.output.role===t));if(a.some(e=>e===void 0))return;let o=a.map(e=>e?.output.durationMs);if(o.every(m7))return o.reduce((e,t)=>e+t,0)/1e3+Math.max(0,r.length-1)*t.silenceGapSeconds+2*t.edgeSilenceSeconds;let s=i.find(e=>(e.output.role===`audio_export`||e.output.role===`video`)&&m7(e.output.durationMs))?.output.durationMs;return m7(s)?s/1e3:void 0}function m7(e){return e!=null&&Number.isFinite(e)&&e>0}function Lye({edit:e,prompts:t,problem:n,onChange:r,onPending:i,getEdit:a}){let{config:o}=e;if(o.sources.images!==`generate`)return null;let s=o.reference,c=s===void 0?v6:{source:s.source,prompt:s.prompt??``,thumbnail:s.thumbnail!==!1},l=e=>({...e,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`provided`||e.destination.stage!==`reference`)});return(0,h.jsx)(`section`,{"aria-label":`Establishing image`,className:`space-y-3`,children:(0,h.jsx)(y6,{value:c,prompts:t,problem:n,onChange:n=>{let{reference:i,...a}=o;if(n.source===`off`){r(l({...e,config:a}));return}let s={source:n.source,...n.source===`prompt`?{prompt:n.prompt}:{},...n.thumbnail?{}:{thumbnail:!1}},u=n.source===`prompt`&&n.prompt!==c.prompt?t.find(e=>e.kind===`image`&&e.name===n.prompt):void 0,d={...e,config:{...a,reference:s}},f=u===void 0?d:A5(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(j5,{label:e.content.provided.reference===void 0?`Upload the establishing image`:`Replace the establishing image`,kind:`images`,accept:`image/png,image/jpeg`,onPending:i,onReady:t=>{let n=l(a?.()??e);n.config.reference?.source===`provide`&&r({...n,uploads:[...n.uploads??[],{stagedFileId:t.id,destination:{kind:`provided`,stage:`reference`}}]})}})})})}var Rye=q({words:K(q({text:W().trim().min(1),start:G().finite().nonnegative(),end:G().finite().positive(),confidence:G().optional(),speaker:W().min(1).optional()})).min(1)});function h7(e){let{config:t,content:n}=e;return JSON.stringify({source:t.sources.audio,audio:n.provided.audio,uploads:e.uploads?.filter(e=>e.destination.kind===`narration`||e.destination.kind===`provided`&&e.destination.stage===`audio`)??[],edge:t.edgeSilenceSeconds,...t.sources.audio===`generate`?{choice:t.audio,chunking:t.chunking,article:n.articleMarkdown??t.provided.article,articleSource:t.sources.article,renderedArticle:t.rendered.article,intro:t.intro,outro:t.outro,renderedIntro:t.rendered.intro,renderedOutro:t.rendered.outro,gap:t.silenceGapSeconds,overrides:n.narrationOverrides,regenerate:e.regenerate?.filter(e=>/^(audio:|article:|entry:)/.test(e))??[]}:{}})}function zye({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=z(),s=N(nb(o)).data?.prompts??[],c=h7(t),l=t.config.sources.audio!==`off`&&c===h7({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?Iye(e):void 0,f=d!==void 0&&u!==void 0&&u!==``,p=(0,m.useRef)({edit:t,onChange:r,revisionId:e.revision.id,identity:c});p.current={edit:t,onChange:r,revisionId:e.revision.id,identity:c};let g=(0,m.useRef)(i);g.current=i;let[_,v]=(0,m.useState)(new Set),[y,b]=(0,m.useState)(),x=(0,m.useRef)(void 0),S=(0,m.useRef)(!0),C=(0,m.useCallback)((e,t)=>{S.current&&v(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,m.useEffect)(()=>{g.current(_.size>0)},[_]),(0,m.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&x.current?.abort()}},[e.revision.id,c]);function w(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:h7(e)},t(e)}async function T(){if(x.current!==void 0)return;let t=new AbortController;x.current=t;let n=p.current;C(`captions:load`,!0),b(void 0);try{let r=e.outputs.find(e=>e.selected&&e.state===`ready`&&e.output.role===`subtitle_words`&&e.available);if(!f||d===void 0||u===void 0||r===void 0)throw Error(`Captions can't be edited until the current narration has finished and its subtitle timing is ready.`);let i=await o.fetch(s2(o,e.revision.projectId,e.revision.id,r.recordId),{signal:t.signal});if(!i.ok)throw Error(`The subtitle timing file couldn't be read. Reload the page and try again; if it still fails, use More → make it again in its section on Audio.`);let a=Rye.parse(await i.json()),s=0;for(let e of a.words){if(e.start<s||e.end<=e.start||e.end>d)throw Error(`The saved subtitle timing doesn't match the current narration. Use More → make it again in its section on Audio to rebuild it.`);s=e.end}let c=_ye(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!S.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;w({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){S.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{x.current===t&&(x.current=void 0),C(`captions:load`,!1)}}let E=t.content.subtitleCues,D=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!D(`images`),className:`space-y-6`,children:[(0,h.jsx)(xye,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(Dye,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(kye,{edit:t,onChange:w}),(0,h.jsx)(Lye,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:w,onPending:e=>C(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(I6,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;w({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(j5,{label:`Replace provided ${e}`,kind:e,onPending:t=>C(`provided:${e}`,t),onReady:t=>{let n=p.current;n.edit.config.sources[e]===`provide`&&w({...n.edit,uploads:[...(n.edit.uploads??[]).filter(t=>t.destination.kind!==`provided`||t.destination.stage!==e),{stagedFileId:t.id,destination:{kind:`provided`,stage:e}}]})}},e):null),(0,h.jsx)(jye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!D(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(Fye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!D(`captions`),className:`space-y-5`,children:[f?null:(0,h.jsx)(`p`,{children:`Captions can be edited once the current narration has finished and its subtitle timing is ready.`}),E===void 0?(0,h.jsx)(R,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void T(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[E.audioFingerprint===u?null:(0,h.jsx)(`p`,{children:`These caption edits belong to an earlier narration. Review their text and timing against the current narration, then apply your corrections and save the project.`}),f&&d!==void 0?(0,h.jsx)(vye,{cues:E.cues,duration:d,onPending:e=>C(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&w({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(R,{type:`button`,onClick:()=>w({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function Bye({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(k2,{value:e.config.language,error:t,onChange:t=>{let{language:r,...i}=e.config;n({...e,config:t===void 0||t===`en`?i:{...i,language:t}})}})})}function Vye({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=z(),a=N(Zb(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:Wb,c=s(o.channelId),l=a.data?.find(e=>e.id===c),u=o.useBrandKit!==!1,d=c!==s(t.channelId),f=u!==(t.useBrandKit!==!1);return(0,h.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(TV,{value:c,onChange:t=>r({...e,config:{...o,channelId:t.target.value}}),children:[a.data===void 0?(0,h.jsx)(`option`,{value:c,children:`Loading channels…`}):null,(a.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col justify-end gap-1`,children:[(0,h.jsx)(kb,{checked:u,label:`Use the channel's brand kit`,tip:`play.brand-kit`,onChange:t=>{let{useBrandKit:n,...i}=o;r({...e,config:t?i:{...i,useBrandKit:!1}})}}),u?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Its cast is still used.`})]}),a.error===null?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-danger md:col-span-2`,children:[`The channels couldn't be loaded: `,a.error.message,`. Reload the page to pick a channel.`]}),d||f?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:[d?`Saving moves the project to this channel and takes its cast as it is now. `:``,u?`The brand kit fills the caption font and colours, title style, end screen, intro, outro and document theme where they are at their default or were set by the old kit.`:`What the old brand kit had set is taken off.`]}):null]})}function Hye(e,t,n){let r=e.outputs.find(e=>e.selected&&e.available&&e.output.role===`reference`);if(t.config.reference!==void 0&&r!==void 0)return{image:{kind:`output`,outputId:r.output.id},drawnOn:`the establishing image`};let i=n.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),a=W6([t.config.title,...Object.values(t.config.values??{})].join(` `),i)[0]??i[0],o=a?.images[0];if(a!==void 0&&o!==void 0)return{image:{kind:`picture`,sha256:o},drawnOn:`${a.name}'s picture`}}function Uye({edit:e,view:t,prompts:n,error:r,onChange:i}){let a=(0,m.useRef)(e.config.narrationPrompt);if(e.config.sources.audio!==`generate`)return null;let o=t.revision.config.narrationPrompt,s=t.revision.content.promptTemplates.narration??t.revision.config.rendered.narration,c=o&&s!==void 0&&!n.some(e=>e.kind===`narration`&&e.name===o)?[...n,{id:`saved-narration`,kind:`narration`,name:o,body:s,slots:[],updatedAt:t.revision.createdAt}]:n;return(0,h.jsx)(g6,{value:e.config.narrationPrompt??``,prompts:c,libraryLinks:!1,supported:e.config.audio?.provider===`inworld`&&e.config.audio.model===`inworld-tts-2`,error:r,onChange:t=>{let n=e.config.narrationPrompt||a.current;t===``&&(a.current=e.config.narrationPrompt);let r=c.find(e=>e.kind===`narration`&&e.name===t),o=r===void 0||t===n?e:A5(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function Wye({edit:e,saved:t=e.config.imagePrompts,prompts:n,entries:r,onChange:i}){let a=(0,m.useId)(),o=[...new Set([...Object.keys(e.config.rendered),...Object.keys(e.content.promptTemplates),...e.config.sources.article===`generate`?[`article`]:[],...uj(e.config)?[`narration`]:[],...pj(e.config)&&e.config.descriptionPrompt?[`description`]:[],..._j(e.config)&&e.config.shorts?.prompt?[`shorts`]:[],..._j(e.config)&&e.config.shorts?.imagePrompt?[`shortsImage`]:[],...[`from_prompt`,`prompt_by_llm`].includes(e.config.sources.thumbnail)?[`thumbnailPrompt`]:[],...hj(e.config)&&e.config.reference?.source===`prompt`?[`referencePrompt`]:[],...e.config.intro===void 0?[]:[`intro`],...e.config.outro===void 0?[]:[`outro`]])].filter(n=>{let r=y7(n);if(r===void 0)return!0;let i=t[r]?.name;return i===void 0||e.config.imagePrompts.some(e=>e.name===i)}),s=e.config.imagePrompts.filter(e=>!t.some(t=>t.name===e.name)),c=e=>qye(e,t),l=[...new Set([...Object.keys(e.config.values),...Object.values(e.content.promptTemplates).flatMap(e=>e===null?[]:dq(e).names)])].filter(e=>!fq.includes(e)),u=t=>[...dq(e.config.title).names.includes(t)?[`Project title`]:[],...Object.entries(e.content.promptTemplates).flatMap(([e,n])=>n!==null&&dq(n).names.includes(t)?[c(e)]:[])],d=dq(e.config.title).names;return(0,h.jsxs)(`section`,{"aria-label":`Prompt snapshots`,className:`space-y-6`,children:[o.map(o=>{let s=c(o),l=e.content.promptTemplates[o]??null,u=o===`intro`||o===`outro`?r.filter(e=>e.category===o):n.filter(t=>t.kind===(o===`article`?UA(e.config)?`script`:`article`:o===`narration`?`narration`:o===`description`?`description`:o===`shorts`?`shorts`:o===`thumbnailPrompt`?`thumbnail`:`image`));return(0,h.jsxs)(`div`,{className:`min-w-0 space-y-4 border-t border-line pt-6 first:border-t-0 first:pt-0`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:s}),l===null?(0,h.jsx)(SI,{tone:`info`,title:`Original template unavailable`,actions:(0,h.jsx)(R,{"aria-label":`Use saved wording as template for ${s}`,onClick:()=>i(A5(e,o,e.config.rendered[o]??``)),children:`Use saved wording as template`}),children:`The saved prompt below stays as it is until you choose or write a template.`}):null,(0,h.jsx)(Kye,{label:s,raw:l,library:Gye(e,o,u,t),onUse:t=>i(A5(e,o,t))}),(0,h.jsx)(xV,{label:`Use saved template for ${s}`,id:`${a}-library-${o}`,tip:`project.prompts.template`,children:(0,h.jsxs)(TV,{value:``,onChange:t=>{let n=u.find(e=>e.id===t.target.value);if(n===void 0)return;let r=A5(e,o,n.body),a=`category`in n?{...r.config,[n.category]:{name:n.name,mode:n.mode}}:o===`article`?{...r.config,articlePrompt:n.name}:o===`narration`?{...r.config,narrationPrompt:n.name}:o===`description`?{...r.config,descriptionPrompt:n.name}:(o===`shorts`||o===`shortsImage`)&&r.config.shorts!==void 0?{...r.config,shorts:{...r.config.shorts,[o===`shorts`?`prompt`:`imagePrompt`]:n.name}}:o===`thumbnailPrompt`?{...r.config,thumbnailPrompt:n.name}:o===`referencePrompt`&&r.config.reference!==void 0?{...r.config,reference:{...r.config.reference,prompt:n.name}}:r.config;i({...r,config:a})},children:[(0,h.jsx)(`option`,{value:``,children:`Choose a saved template`}),u.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,h.jsx)(xV,{label:`Raw prompt for ${s}`,id:`${a}-raw-${o}`,tip:`project.prompts.raw`,children:(0,h.jsx)(wV,{rows:4,value:l??``,onChange:t=>i(A5(e,o,t.target.value))})}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`text-small text-ink-2`,children:`Saved rendered prompt`}),(0,h.jsx)(`pre`,{className:`m-0 mt-2 whitespace-pre-wrap break-words text-small`,children:e.config.rendered[o]??``})]})]},o)}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s.map(e=>`"${e.name}"`).join(`, `),` `,s.length===1?`uses its`:`use their`,` Library wording. Save, then change it here.`]}),l.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`space-y-3 pt-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:`Keywords`}),(0,h.jsx)(_0,{fieldPrefix:`config.values`,keywords:l.map(t=>({name:t,value:e.config.values[t]??``,feeds:u(t),topic:d.includes(t)})),onChange:(t,n)=>i(k5({...e,config:{...e.config,values:{...e.config.values,[t]:n}}}))})]}):null]})}function Gye(e,t,n,r){let{config:i}=e,a=y7(t);if(t===`intro`||t===`outro`){let e=i[t]?.name;return e===void 0||e===``?void 0:n.find(t=>`category`in t&&t.name===e)}let o=t===`article`?i.articlePrompt:t===`narration`?i.narrationPrompt:t===`description`?i.descriptionPrompt:t===`shorts`?i.shorts?.prompt:t===`shortsImage`?i.shorts?.imagePrompt:t===`thumbnailPrompt`?i.thumbnailPrompt:t===`referencePrompt`?i.reference?.prompt:a===void 0?void 0:r[a]?.name;if(o!==void 0&&o!==``)return n.find(e=>!(`category`in e)&&e.name===o)}var g7=`slopify.library-kept`;function _7(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t*33^e.charCodeAt(n))>>>0;return t.toString(36)}function v7(){try{let e=window.localStorage.getItem(g7),t=e===null?[]:JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Kye({label:e,raw:t,library:n,onUse:r}){let i=n===void 0||t===null?``:`${e}:${_7(t)}:${_7(n.body)}`,[a,o]=(0,m.useState)(()=>v7().includes(i));return n===void 0||t===null||n.body===t||a?null:(0,h.jsx)(SI,{tone:`info`,title:`The Library's "${n.name}" has changed since this project copied it`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{"aria-label":`Use the Library version for ${e}`,onClick:()=>{r(n.body)},children:`Use the Library version`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Keep this project's version for ${e}`,onClick:()=>{try{window.localStorage.setItem(g7,JSON.stringify([...v7().filter(e=>e!==i),i].slice(-200)))}catch{}o(!0)},children:`Keep this project's version`})]}),children:`The project uses its own copy below until you choose. Using the Library version marks what it wrote as outdated, to remake when you are ready.`})}function y7(e){let t=/^imagePrompts\.(\d+)$/.exec(e);return t?.[1]===void 0?void 0:Number(t[1])}function qye(e,t){if(e===`article`)return`Article`;if(e===`narration`)return`Narration Preparation`;if(e===`description`)return`YouTube description`;if(e===`shorts`)return`Shorts`;if(e===`shortsImage`)return`Shorts image style`;if(e===`thumbnailPrompt`)return`Thumbnail`;if(e===`referencePrompt`)return`Establishing image`;if(e===`intro`)return`Intro`;if(e===`outro`)return`Outro`;let n=y7(e);if(n!==void 0){let e=t[n]?.name;return e===void 0||e===``?`Image prompt ${String(n+1)}`:`Image prompt "${e}"`}return e.replace(/[._-]/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`)}function Jye(e,t,n){let{api:r}=z(),[i,a]=(0,m.useState)({busy:!1}),{config:o}=t,s=o.audio,c=async()=>{if(s!==void 0){a({busy:!0});try{let i=await Rs(r,e),{sharedGlossary:c,...l}=o;n({...t,config:{...l,audio:{...s,shareGlossary:!0},...i.entries.length===0?{}:{sharedGlossary:i.entries}}}),a({busy:!1,projects:i.projects})}catch(e){a({busy:!1,error:e instanceof Error?e.message:String(e)})}}},l=()=>{if(s===void 0)return;let{sharedGlossary:e,...r}=o;n({...t,config:{...r,audio:{...s,shareGlossary:!1}}})},u=o.sharedGlossary?.length??0,d=s?.shareGlossary===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[i.error===void 0?u===0?`No pronunciations from other projects are copied yet.`:`${String(u)} ${u===1?`term`:`terms`} copied from ${i.projects===void 0?`your other projects`:`${String(i.projects)} other ${i.projects===1?`project`:`projects`}`}.`:`Couldn't read your other projects' pronunciations: ${i.error}`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:i.busy,onClick:()=>void c(),children:i.busy?`Copying…`:`Update from other projects`}),(0,h.jsx)(V,{id:`project.edit.update-glossary`})]}):void 0;return{value:s?.shareGlossary===!0,onChange:e=>{e?c():l()},note:d}}function Yye(e,t){let{api:n}=z(),[r,i]=(0,m.useState)({busy:!1}),{config:a}=e,o=a.audio,s=async()=>{if(o!==void 0){i({busy:!0});try{let{aliases:r}=await zs(n),{narrationAliases:s,...c}=a;t({...e,config:{...c,audio:{...o,useNarrationAliases:!0},...r.length===0?{}:{narrationAliases:r}}}),i({busy:!1})}catch(e){i({busy:!1,error:e instanceof Error?e.message:String(e)})}}},c=a.narrationAliases?.length??0;return{value:o?.useNarrationAliases===!0,onChange:n=>{if(o!==void 0){if(n)s();else{let{narrationAliases:n,...r}=a;t({...e,config:{...r,audio:{...o,useNarrationAliases:!1}}})}}},note:o?.useNarrationAliases===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[r.error===void 0?c===0?`No aliases are copied yet. Add some in Library → Aliases.`:`${String(c)} ${c===1?`alias`:`aliases`} copied from Library → Aliases.`:`Couldn't read Library → Aliases: ${r.error} Try Update from Library again.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r.busy,onClick:()=>void s(),children:r.busy?`Copying…`:`Update from Library`}),(0,h.jsx)(V,{id:`project.edit.update-aliases`})]}):void 0}}function Xye({projectId:e,edit:t,providers:n,voices:r,onChange:i}){let{config:a}=t,o=a.llm??{provider:``,model:``},s=a.audio??{provider:``,model:``,voice:``},c=Jye(e,t,i),l=Yye(t,i),{api:u}=z(),d=N(Qb(u,a.channelId??`00000000-0000-4000-8000-000000000001`)),f=a.images??{provider:``,model:``},p=uj(a)||a.sources.audio===`generate`&&a.audio?.describeFigures===!0||a.sources.research===`generate`||a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||HA(a)&&a.voices?.source===`attribute`||a.sources.audio===`generate`&&(a.intro?.mode===`llm`||a.outro?.mode===`llm`),m=a.sources.images===`generate`||a.sources.thumbnail===`from_prompt`||a.sources.thumbnail===`prompt_by_llm`,g=r.filter(e=>e.provider===s.provider).map(e=>({value:e.voiceId,label:e.name}));return(0,h.jsxs)(`section`,{"aria-label":`Generation providers`,className:`grid min-w-0 gap-3 sm:grid-cols-2`,children:[p?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Text provider`,tip:`play.llm.provider`,family:`llm`,providers:n,value:o.provider,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Text model`,tip:`play.llm.model`,provider:o.provider,value:o.model,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{...o,model:e}}})}),(0,h.jsx)(b6,{choice:o,onChange:e=>i({...t,config:{...a,llm:e}})})]}):null,a.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[a.voices!==void 0&&a.intro===void 0&&a.outro===void 0?null:(0,h.jsxs)(h.Fragment,{children:[a.voices===void 0?null:(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`The voice below reads only the intro and outro. Each speaker's voice is set under Speakers.`}),(0,h.jsx)(RV,{label:a.voices===void 0?`Narration provider`:`Intro and outro provider`,tip:`play.tts.provider`,family:`tts`,providers:n,value:s.provider,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,provider:e,model:``,voice:``}}})}),(0,h.jsx)(zV,{label:a.voices===void 0?`Narration model`:`Intro and outro model`,tip:`play.tts.model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,model:e}}})}),(0,h.jsx)(FV,{label:a.voices===void 0?`Narration voice`:`Intro and outro voice`,tip:`play.voice`,value:s.voice,problem:void 0,placeholder:`Choose a saved voice`,options:s.voice!==``&&!g.some(e=>e.value===s.voice)?[{value:s.voice,label:`${s.voice} (saved voice)`},...g]:g,onPick:e=>i({...t,config:{...a,audio:{...s,voice:e}}})})]}),(0,h.jsx)(q3,{value:a.chunking??{mode:`whole`},onPick:e=>i({...t,config:{...a,chunking:e}})}),(0,h.jsx)(_6,{shared:c,value:s.usePronunciationGlossary,supported:Sj({sources:a.sources,audio:{...s,usePronunciationGlossary:!0}}),onChange:e=>i({...t,config:{...a,audio:{...s,usePronunciationGlossary:e}}})}),(0,h.jsx)(h6,{...l}),(0,h.jsx)(p6,{tip:`project.edit.describe-figures`,value:s.describeFigures,skipCode:s.skipCode,onChange:({describeFigures:e,skipCode:n})=>{let{describeFigures:r,skipCode:o,...c}=s;i({...t,config:{...a,audio:{...c,...e?{describeFigures:e}:{},...e&&n?{skipCode:n}:{}}}})}}),(0,h.jsxs)(`section`,{"aria-label":`Speakers`,className:`col-span-full border-t border-line pt-3`,children:[(0,h.jsx)(`h3`,{className:`mb-2 text-small font-semibold`,children:`Speakers`}),(0,h.jsx)(f6,{value:a.voices,cast:d.data?.cast??[],language:a.language,providers:n,voices:r,script:t.content.articleMarkdown??void 0,onChange:e=>{let{voices:n,...r}=a;i({...t,config:e===void 0?r:{...r,voices:e}})}})]})]}):null,m?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Image provider`,tip:`play.images.provider`,family:`image`,providers:n,value:f.provider,problem:void 0,onPick:e=>i({...t,config:{...a,images:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Image model`,tip:`play.images.model`,provider:f.provider,value:f.model,problem:void 0,onPick:e=>i({...t,config:{...a,images:{...f,model:e}}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:f,onChange:e=>i({...t,config:{...a,images:e}})})]}):null]})}function Zye({edit:e,providers:t,prompts:n,problem:r,onChange:i}){let{config:a}=e,o=a.reviews===void 0?HV:jk(a.reviews),[s,c]=(0,m.useState)(o),l=a.shorts?.enabled===!0&&a.sources.audio!==`off`,u=e=>Nk({sources:a.sources,shorts:l?{enabled:!0}:void 0},e),d=Mk(s,u).retriesProblem;return(0,h.jsx)(UV,{value:s,providers:t,prompts:n,makes:u,problem:e=>e===`reviews.retries`&&d!==void 0?d:r(e),onChange:t=>{c(t);let{settings:r}=Mk(t,u),o={...e.content.promptTemplates},s={...a.rendered};for(let e of Ck){let t=Ak(e),i=r?.stages[e]?.prompt??``,c=n.find(e=>e.kind===`review`&&e.name===i);if(i===``){let{[t]:e,...n}=o,{[t]:r,...i}=s;o=n,s=i}else c!==void 0&&i!==(a.reviews?.stages[e]?.prompt??``)&&(o={...o,[t]:c.body})}let{reviews:l,...d}=a;i(k5({...e,config:{...d,rendered:s,...r===void 0?{}:{reviews:r}},content:{...e.content,promptTemplates:o}}))}})}function Qye({edit:e,view:t,prompts:n,problem:r,onChange:i}){let a=t.revision.config.descriptionPrompt,o=t.revision.content.promptTemplates.description??t.revision.config.rendered.description,s=a&&o!==void 0&&!n.some(e=>e.kind===`description`&&e.name===a)?[...n,{id:`saved-description`,kind:`description`,name:a,body:o,slots:[],updatedAt:t.revision.createdAt}]:n,c=t.outputs.some(e=>e.selected&&e.workKey===b7&&e.state===`ready`),l=e.regenerate?.includes(b7)===!0;return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(C6,{enabled:e.config.youtubeDescription===!0,prompt:e.config.descriptionPrompt??``,prompts:s,narrated:e.config.sources.audio!==`off`,problem:r,onChange:({youtubeDescription:t,descriptionPrompt:n})=>{let r=s.find(e=>e.kind===`description`&&e.name===n),a=n===(e.config.descriptionPrompt??``)?e:r===void 0?$ye(e):A5(e,`description`,r.body),{descriptionPrompt:o,...c}=a.config;i({...a,config:{...c,youtubeDescription:t,...n===``?{}:{descriptionPrompt:n}}})}}),c&&e.config.youtubeDescription===!0?l?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The YouTube description will be written again after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>{i({...e,regenerate:(e.regenerate??[]).filter(e=>e!==b7)})},children:`Keep the current description`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>{i({...e,regenerate:[...new Set([...e.regenerate??[],b7])]})},children:`Write the description again after review`}),(0,h.jsx)(V,{id:`project.edit.rewrite-description`})]}):null]})}var b7=`youtube:description`;function $ye(e){let{description:t,...n}=e.content.promptTemplates,{description:r,...i}=e.config.rendered;return k5({config:{...e.config,rendered:i},content:{...e.content,promptTemplates:n}})}var ebe={research:`Research source`,article:`Article source`,audio:`Audio source`,images:`Images source`,thumbnail:`Thumbnail source`,video:`Video source`,document:`Document source`},tbe={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`},nbe=`\0kept:`;function x7({title:e,children:t,columns:n=!0}){return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:e}),(0,h.jsx)(`div`,{className:L(`grid min-w-0 gap-4`,n&&`md:grid-cols-2`),children:t})]})}function rbe(e){let{view:t,edit:n,onChange:r,onPending:i,fields:a}=e,o=(0,m.useId)(),[s,c]=(0,m.useState)(e.focus?.section??`inputs`);(0,m.useEffect)(()=>{e.focus!==void 0&&c(e.focus.section)},[e.focus]);let[l,u]=(0,m.useState)({font:!1,content:!1,music:!1});(0,m.useEffect)(()=>{i(l.font||l.content||l.music)},[i,l]);let d=(0,m.useCallback)(e=>{u(t=>t.font===e?t:{...t,font:e})},[]),f=(0,m.useCallback)(e=>{u(t=>t.content===e?t:{...t,content:e})},[]),p=(0,m.useCallback)(e=>{u(t=>t.music===e?t:{...t,music:e})},[]),{api:g}=z(),_=N(eb(g)),v=N(tb(g)),y=N(nb(g)),b=N(rb(g)),{config:x}=n,S=Hye(t,n,N(Qb(g,x.channelId??`00000000-0000-4000-8000-000000000001`)).data?.cast??[]),C=S?.image.kind===`output`?t.outputs.find(e=>e.selected&&e.available&&S.image.kind===`output`&&e.output.id===S.image.outputId):void 0,w=C===void 0?void 0:s2(g,t.revision.projectId,t.revision.id,C.recordId),T=e=>a.find(t=>t.field===e||t.field===`config.${e}`||t.field===`edit.config.${e}`)?.message,E=w6({value:x.videoEdit,narrated:x.sources.audio!==`off`,imageProvider:x.images?.provider??``,problem:T,language:x.language,onChange:e=>r({...n,config:{...x,videoEdit:e}})}),D=[{id:`inputs`,label:`Inputs`},...x.sources.article===`off`?[]:[{id:`article`,label:`Article`,...n.content.articleEdited?{badge:`edited`}:{}}],{id:`providers`,label:`Providers`},{id:`prompts`,label:`Prompts`},{id:`reviews`,label:`Reviews`,...x.reviews===void 0?{}:{badge:`on`}},...x.sources.audio!==`off`||x.shorts?.enabled===!0?[{id:`shorts`,label:`Shorts`,...x.shorts?.enabled?{badge:`on`}:{}}]:[],...x.sources.article===`off`?[]:[{id:`subtitles`,label:`Subtitles`}],{id:`images`,label:`Images`,badge:String(n.content.imageOrder.length)},...x.sources.audio===`generate`?[{id:`narration`,label:`Narration`}]:[],...x.sources.article===`off`?[]:[{id:`captions`,label:`Captions`,...n.content.subtitleCues===void 0?{}:{badge:String(n.content.subtitleCues.cues.length)}}]],O=D.some(e=>e.id===s)?s:`inputs`,k=e=>L(`min-w-0 space-y-6`,O===e?void 0:`hidden`),A=e=>Number.isFinite(e)?e:``,ee=x.sources.video!==`off`;return(0,h.jsxs)(`div`,{className:`grid min-w-0 gap-8 md:grid-cols-[180px_minmax(0,1fr)]`,children:[(0,h.jsx)(`nav`,{"aria-label":`Edit sections`,className:`min-w-0 md:sticky md:top-16 md:self-start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none gap-1 overflow-x-auto p-0 [scrollbar-width:none] md:flex-col`,children:D.map(e=>(0,h.jsx)(`li`,{className:`shrink-0`,children:(0,h.jsx)(t8,{current:e.id===O,onClick:()=>c(e.id),meta:e.badge,className:`whitespace-nowrap`,children:e.label})},e.id))})}),(0,h.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[Object.entries({providers:_.error,voices:v.error,prompts:y.error,entries:b.error}).flatMap(([e,t])=>t===null?[]:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:t.message},e)]),a.length===0?null:(0,h.jsx)(`ul`,{role:`alert`,className:`m-0 space-y-1 pl-5 text-small text-danger`,children:a.map(e=>(0,h.jsx)(`li`,{children:e.message},`${e.field}-${e.message}`))}),(0,h.jsxs)(`section`,{"aria-label":`Inputs`,hidden:O!==`inputs`,className:k(`inputs`),children:[(0,h.jsxs)(x7,{title:`Project`,children:[(0,h.jsx)(xV,{label:`Project title`,error:T(`title`),className:`md:col-span-2`,children:(0,h.jsx)(CV,{value:x.title,maxLength:200,onChange:e=>r({...n,config:{...x,title:e.target.value}})})}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(U6,{value:x.format,onPick:e=>r({...n,config:{...x,format:e}})})})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Channel`,columns:!1,children:(0,h.jsx)(Vye,{edit:n,saved:t.revision.config,problem:T,onChange:r})}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Stages`,children:[FS.filter(e=>x.sources.article!==`off`||e!==`research`&&e!==`audio`&&e!==`document`).map(e=>(0,h.jsx)(xV,{label:ebe[e],tip:tbe[e],error:T(`sources.${e}`),children:(0,h.jsx)(TV,{value:RS(x.sources,e),onChange:i=>{let a=FN(e).find(e=>e.value===i.target.value);if(a===void 0)return;let o=Sve(n,e,a.value);r(e===`article`&&a.value===`provide`&&!n.content.articleEdited?{...o,content:{...o.content,articleMarkdown:t.articleMarkdown??n.content.articleMarkdown}}:o)},children:FN(e).filter(t=>e!==`thumbnail`||t.value!==`prompt_by_llm`||x.sources.article!==`off`).map(t=>(0,h.jsx)(`option`,{value:t.value,disabled:e===`video`&&t.value===`generate`&&x.sources.images===`off`,children:t.label},t.value))})},e)),x.sources.images===`off`?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:`Images are Off. Video is also Off in these changes.`}):null,(0,h.jsx)(xV,{label:`Document theme`,id:`${o}-document-theme`,tip:`play.document-theme`,children:(0,h.jsx)(G3,{id:`${o}-document-theme`,disabled:RS(x.sources,`document`)===`off`,value:x.document,onChange:e=>{r({...n,config:{...x,document:e}})}})})]}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Timing`,children:[(0,h.jsx)(xV,{label:`Silence gap (seconds)`,tip:`play.silence-gap`,error:T(`silenceGapSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.1,value:A(x.silenceGapSeconds),onChange:e=>r({...n,config:{...x,silenceGapSeconds:Number(e.target.value)}})})}),x.sources.audio===`off`?null:(0,h.jsx)(xV,{label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,error:T(`edgeSilenceSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.5,value:A(x.edgeSilenceSeconds),onChange:e=>r({...n,config:{...x,edgeSilenceSeconds:Number(e.target.value)}})})}),ee?(0,h.jsx)(xV,{label:`Seconds per image`,tip:`play.image-seconds`,error:T(`imageSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:600,step:1,value:A(x.imageSeconds),onChange:e=>r({...n,config:{...x,imageSeconds:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Zoom (%)`,tip:`play.zoom`,error:T(`zoomPercent`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:50,step:.5,value:A(x.zoomPercent),onChange:e=>r({...n,config:{...x,zoomPercent:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Motion`,tip:`play.motion`,children:(0,h.jsx)(TV,{value:x.motionStyle,onChange:e=>r({...n,config:{...x,motionStyle:e.target.value}}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null]}),ee?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Cuts and look`,columns:!1,children:[E.cuts,E.look,x.sources.audio===`generate`&&x.audio?.describeFigures===!0?(0,h.jsx)(m6,{tip:`project.edit.show-figures`,value:x.showFigures,onChange:e=>{let{showFigures:t,...i}=x;r({...n,config:e?{...i,showFigures:!0}:i})}}):null]}),x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Ambient sound`,columns:!1,children:(0,h.jsx)(Cye,{edit:n,problem:T,onChange:r})})]})]}):null,x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Pauses and volume`,columns:!1,children:[(0,h.jsx)(Tye,{edit:n,problem:T,onChange:r}),(0,h.jsx)(wye,{edit:n,problem:T,onChange:r})]})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Intro and outro`,children:[`intro`,`outro`].map(e=>{let i=x[e]?.name,a=t.revision.content.promptTemplates[e],o=b.data?.entries.find(t=>t.category===e&&t.name===i),s=i!==void 0&&o!==void 0&&typeof a==`string`&&t.revision.config[e]?.name===i&&a!==o.body,c=n.content.promptTemplates[e],l=`${nbe}${i??``}`,u=i===void 0?``:s&&c!==o?.body?l:i;return(0,h.jsx)(xV,{label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,children:(0,h.jsxs)(TV,{value:u,onChange:i=>{if(i.target.value===l&&typeof a==`string`){r(k5({...n,config:{...x,[e]:t.revision.config[e]},content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:a}}}));return}let o=b.data?.entries.find(t=>t.category===e&&t.name===i.target.value),s={...x};o===void 0?delete s[e]:s[e]={name:o.name,mode:o.mode},r(k5({...n,config:s,content:o===void 0?n.content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:o.body}}}))},children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),i!==void 0&&!b.data?.entries.some(t=>t.category===e&&t.name===i)?(0,h.jsxs)(`option`,{value:i,children:[i,` (saved entry)`]}):null,s?(0,h.jsxs)(`option`,{value:l,children:[i,` · this project's version`]}):null,b.data?.entries.filter(t=>t.category===e).map(e=>(0,h.jsx)(`option`,{value:e.name,children:s&&e.name===i?`${e.name} · Library version (newer)`:e.name},e.id))]})},e)})}),x.sources.research===`provide`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Research`,columns:!1,children:(0,h.jsx)(xV,{label:`Research notes`,tip:`play.provided.research`,error:T(`provided.research`),children:(0,h.jsx)(wV,{rows:6,value:x.provided.research??``,onChange:e=>r({...n,config:{...x,provided:{...x.provided,research:e.target.value}}})})})})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Article`,hidden:O!==`article`,className:k(`article`),children:[(0,h.jsx)(xV,{label:`Article text`,tip:`project.edit.article-text`,error:T(`content.articleMarkdown`)??T(`provided.article`),help:n.content.articleEdited?`Your edited article is kept when other settings change. Regenerating it replaces it after the rebuild review.`:void 0,children:(0,h.jsx)(wV,{rows:12,maxLength:5e5,value:(n.content.articleEdited?n.content.articleMarkdown:t.articleMarkdown)??n.content.articleMarkdown??x.provided.article??``,onChange:e=>r({...n,content:{...n.content,articleMarkdown:e.target.value,articleEdited:!0}})})}),x.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:()=>r({...n,regenerate:[...new Set([...n.regenerate??[],`article:body`])]}),children:`Regenerate article after review`}),(0,h.jsx)(V,{id:`project.edit.regenerate-article`})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Providers`,hidden:O!==`providers`,className:k(`providers`),children:[(0,h.jsx)(Bye,{edit:n,error:T(`language`),onChange:r}),(0,h.jsx)(Xye,{projectId:t.revision.projectId,edit:n,providers:_.data?.providers??[],voices:v.data?.voices??[],onChange:r}),(0,h.jsx)(Uye,{edit:n,view:t,prompts:y.data?.prompts??[],error:T(`narrationPrompt`),onChange:r})]}),(0,h.jsxs)(`section`,{"aria-label":`Prompts`,hidden:O!==`prompts`,className:k(`prompts`),children:[(0,h.jsx)(Qye,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r}),(0,h.jsx)(Wye,{edit:n,saved:t.revision.config.imagePrompts,prompts:y.data?.prompts??[],entries:b.data?.entries??[],onChange:r})]}),(0,h.jsx)(`section`,{"aria-label":`Reviews`,hidden:O!==`reviews`,className:k(`reviews`),children:(0,h.jsx)(Zye,{edit:n,providers:_.data?.providers??[],prompts:y.data?.prompts??[],problem:T,onChange:r})}),(0,h.jsx)(`section`,{"aria-label":`Shorts`,hidden:O!==`shorts`,className:k(`shorts`),children:(0,h.jsx)(Tve,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r,onPending:p})}),(0,h.jsxs)(`section`,{"aria-label":`Subtitles`,hidden:O!==`subtitles`,className:k(`subtitles`),children:[(0,h.jsx)(`div`,{"data-tour":`project-subtitles`,children:(0,h.jsx)(H6,{value:x.subtitles??hM,format:x.format,audioEnabled:x.sources.audio!==`off`,videoEnabled:ee,onChange:e=>r({...n,config:{...x,subtitles:ON(e,x.sources)}}),onUploading:d,problem:T})}),O!==`subtitles`||!ee?null:(0,h.jsx)(O6,{drawnOn:S?.drawnOn,poster:w,settings:{format:x.format,subtitles:{mode:(x.subtitles??hM).mode,fontId:(x.subtitles??hM).fontId,fontSize:(x.subtitles??hM).fontSize,position:(x.subtitles??hM).position??`bottom`},videoEdit:x.videoEdit,image:S?.image}})]}),e.renderContent?.({view:t,edit:n,fields:a,onChange:r,onPending:f,section:O})]})]})}var S7={notes:`Research notes`,article_md:`Article (Markdown)`,article_txt:`Article text`,narration_txt:`Clean Narration`,tts_script:`TTS Script`,sources:`Research sources`,glossary:`Glossary`,audio_body:`Narration`,audio_intro:`Intro narration`,audio_outro:`Outro narration`,audio_export:`Audio export`,image:`Image`,thumbnail:`Thumbnail`,video:`Video`,render_params:`Export settings`,subtitles_srt:`Subtitles (SRT)`,subtitles_vtt:`Subtitles (VTT)`,subtitle_words:`Subtitle timing`,subtitle_ass:`Styled subtitles`,subtitle_font:`Subtitle font`,instructions:`Generation instructions`,document_pdf:`Document (PDF)`,youtube_description:`YouTube description`,youtube_tags:`YouTube tags`,youtube_pinned_comment:`Pinned comment`,youtube_titles:`Other titles`,shorts:`Shorts list`,short_image:`Short image`,short_video:`Short`,animated_image:`Animated image`,figure_card:`On-screen card`,reference:`Establishing image (reference)`,script_md:`Script (speaker split)`,audio_mp3:`Audio (MP3 with chapters)`,audio_m4b:`Audiobook (M4B with chapters)`,audio_levelled:`Levelled narration`};function C7(e){return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment?`${e.meta.segment===`body`?`Body`:e.meta.segment===`intro`?`Intro`:`Outro`} ${S7[e.role]}`:e.role===`short_video`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)}`:e.role===`short_image`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)} image ${String(e.meta.index??1)}`:e.role===`figure_card`&&typeof e.meta.index==`number`?`On-screen card ${String(e.meta.index)}`:e.role===`animated_image`&&typeof e.meta.index==`number`?`Animated image ${String(e.meta.index)}`:e.role===`image`&&typeof e.meta.index==`number`?`Image ${e.meta.index}`:S7[e.role]}function ibe(e){if(e.startsWith(`image:`))return`Image`;if(e.startsWith(`animate:`))return S7.animated_image;if(/^shorts:\d+:render$/.test(e))return S7.short_video;if(/^shorts:\d+:image:\d+$/.test(e))return S7.short_image;if(e===`document:pdf`)return S7.document_pdf;let t=e.split(`:`).at(-1);return Object.entries(S7).find(([e])=>e===t)?.[1]??`Saved output`}function w7({preview:e,pending:t,feedback:n,onStart:r,onCancel:i}){let a=ube(e),[o,s]=(0,m.useState)([]),[c,l]=(0,m.useState)(!1),u=(0,m.useId)(),d=e.work.filter(e=>e.disposition===`blocked`),f=e.providedReuseRequired.filter(e=>!o.includes(e)),p=e.work.filter(e=>e.disposition===`generate`||e.disposition===`local`||e.disposition===`review`).length,g=p===1?`Remake 1 output`:`Remake ${String(p)} outputs`,_=[...d.length===0?[]:[`${d.length===1?`1 item is`:`${d.length} items are`} unavailable (reasons above)`],...f.map(e=>`tick “Keep the provided content for ${a(e)}”`),...e.costs.unknown===0||c?[]:[`tick “I understand that ${e.costs.unknown} cost estimates are unknown”`]],v=_.length===0,y=obe.map(t=>({disposition:t,count:e.work.filter(e=>e.disposition===t).length})).filter(e=>e.count>0),b=e.costs.rows.some(e=>e.onPlan===!0),x=e.costs.apiLow,S=e.costs.apiHigh;return(0,h.jsxs)(`section`,{"aria-label":`Review affected rebuild`,className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-6 gap-y-3 sm:grid-cols-3`,children:[y.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:k7[e.disposition]}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:e.count})]},e.disposition)),(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:e.costs.unknown>0?`known cost`:`cost`}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:O7(e.costs.low,e.costs.high)})]})]}),b?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`CLI work: $0 on your plan${x===void 0||S===void 0?``:` · ~${O7(x,S)} via API`}.`}):null,d.length===0?null:(0,h.jsx)(SI,{tone:`danger`,title:`${d.length===1?`1 item can’t`:`${d.length} items can’t`} run, so this rebuild can’t start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:sbe(d,a).map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.what,`:`]}),` `,e.reason]},e.reason))})}),e.wholeRequestNotice===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.wholeRequestNotice}),e.warnings.map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e},e)),(0,h.jsxs)(`div`,{className:`flex flex-col divide-y divide-line border-y border-line`,children:[e.review?.inputChanges.length?(0,h.jsx)(T7,{summary:`Changed inputs (${String(e.review.inputChanges.length)})`,children:(0,h.jsx)(`dl`,{className:`m-0 flex flex-col gap-3`,children:e.review.inputChanges.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`dt`,{className:`font-semibold`,children:e.label}),(0,h.jsxs)(`dd`,{className:`m-0 grid gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(E7,{label:`Before`,text:e.before}),(0,h.jsx)(E7,{label:`After`,text:e.after})]})]},e.label))})}):null,(0,h.jsxs)(T7,{summary:`Work items (${e.work.length}): ${y.map(e=>`${e.count} ${k7[e.disposition]}`).join(`, `)||`none`}`,children:[e.changedInputs.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 mb-3 flex flex-col gap-1 pl-5`,children:e.changedInputs.map(e=>(0,h.jsxs)(`li`,{children:[a(e.path),`:`,` `,e.after===null?`Removed`:e.before===null?`New output`:`Inputs changed`]},e.path))}),(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-2 pl-5`,children:e.work.map(t=>(0,h.jsxs)(`li`,{children:[a(t.key),`: `,k7[t.disposition],`. `,t.reason,t.inflight?` An already submitted request may still be billed.`:``,e.review?.requests.filter(e=>e.key===t.key).map(e=>(0,h.jsxs)(`div`,{children:[e.settings===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.settings}),e.text===null?null:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:`View request text`}),(0,h.jsx)(`pre`,{className:`m-0 max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.text})]})]},e.key))]},t.key))}),(0,h.jsxs)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:[`Retained outputs:`,` `,e.retained.map(e=>ibe(e.slot)).join(`, `)||`None`]})]}),e.costs.rows.length===0?null:(0,h.jsx)(T7,{summary:`Cost by step`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:e.costs.rows.map(e=>(0,h.jsxs)(`li`,{children:[a(e.stage),`: `,abe(e),`. `,e.detail]},`${e.stage}-${e.detail}`))})})]}),n,(0,h.jsxs)(`div`,{className:`sticky bottom-[-16px] -mx-4 flex flex-col gap-3 border-t border-line bg-raised px-4 py-3`,children:[e.providedReuseRequired.length===0&&e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small`,children:[e.providedReuseRequired.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:o.includes(e),onChange:t=>s(t.target.checked?[...o,e]:o.filter(t=>t!==e))}),(0,h.jsxs)(`span`,{children:[`Keep the provided content for `,a(e)]})]}),(0,h.jsx)(V,{id:`project.rebuild.keep-provided`,className:`-my-1`})]},e)),e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:c,onChange:e=>l(e.target.checked)}),(0,h.jsxs)(`span`,{children:[`I understand that `,e.costs.unknown,` cost estimates are unknown.`]})]}),(0,h.jsx)(V,{id:`project.rebuild.unknown-costs`,className:`-my-1`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:t||!v,"aria-describedby":v?void 0:u,onClick:()=>r({acknowledgeUnknownCosts:c,confirmedProvidedWorkKeys:o}),children:t?`Starting the remake…`:g}),(0,h.jsx)(R,{disabled:t,onClick:i,children:`Keep things as they are`}),v||t?null:(0,h.jsx)(`p`,{id:u,className:`m-0 min-w-0 text-small text-ink-2`,children:`${g} is off until: ${_.join(`; `)}.`})]})]})]})}function T7({summary:e,children:t}){return(0,h.jsxs)(`details`,{className:`py-3 text-small`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold text-ink`,children:e}),(0,h.jsx)(`div`,{className:`mt-3`,children:t})]})}function E7({label:e,text:t}){return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`pre`,{className:`m-0 max-h-40 overflow-auto whitespace-pre-wrap break-words text-small`,children:t??`Not set`})]})}var D7=e=>e===null?`Unknown`:e===0?`$0`:new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:e>0&&e<.01?4:2}).format(e);function O7(e,t){return e===t?D7(e):`${D7(e)}–${D7(t)}`}function abe(e){return e.onPlan===!0?`$0 on plan${e.apiLow===void 0||e.apiLow===null||e.apiHigh===void 0?``:` · ~${O7(e.apiLow,e.apiHigh??null)} via API`}`:O7(e.low,e.high)}var obe=[`generate`,`local`,`review`,`reuse`,`blocked`];function sbe(e,t){let n=new Map;for(let t of e){let e=t.reason.trim()||`No reason was given.`;n.set(e,[...n.get(e)??[],t.key])}return[...n].map(([e,n])=>({reason:e,what:n.length===1?t(n[0]??``):`${n.length} ${new Set(n.map(A7)).size===1?cbe(A7(n[0]??``)):`items`}`}))}function cbe(e){return/s$/u.test(e)?e:`${e.charAt(0).toLowerCase()}${e.slice(1)}s`}var k7={reuse:`kept as they are`,generate:`to make`,local:`built on this computer`,review:`to confirm`,blocked:`can't run`},lbe={"export:wav":`Audio export (WAV)`,"export:video":`Video export`,"subtitles:timing":`Subtitle timing`,"subtitles:cues":`Caption text and timing`,"subtitles:files":`Subtitle files`,"article:body":`Article`,"audio:provided":`Provided narration`,"audio:body:concat":`Combined narration`,"audio:intro":`Combined intro narration`,"audio:outro":`Combined outro narration`,"research:planner":`Research plan`,"research:notes":`Research notes`,"entry:intro:text":`Intro text`,"entry:outro:text":`Outro text`};function A7(e){let t=lbe[e];return t===void 0?{image:`Image request`,images:`Images`,audio:`Narration request`,article:`Article`,research:`Research`,thumbnail:`Thumbnail`,subtitles:`Subtitles`,video:`Video export`,export:`Export`,entry:`Intro or outro`}[e.split(`:`)[0]??``]??`Output`:t}function ube(e){let t=new Map,n=new Map;for(let t of e.work){let e=A7(t.key);n.set(e,(n.get(e)??0)+1)}let r=new Map;for(let i of e.work){let e=A7(i.key),a=(r.get(e)??0)+1;r.set(e,a),t.set(i.key,(n.get(e)??0)>1?`${e} ${a}`:e)}for(let n of e.review?.requests??[])t.set(n.key,n.label);return e=>t.get(e)??A7(e)}var dbe={llm:`Text generation`,image:`Images`,images:`Images`,tts:`Audio`,audio:`Audio`};function j7({error:e,refusal:t}){let n=(0,m.useRef)(null);return(0,m.useEffect)(()=>{(e!==void 0||t!==void 0)&&n.current?.focus()},[e,t]),e===void 0&&t===void 0?null:(0,h.jsxs)(`div`,{ref:n,role:`alert`,tabIndex:-1,"data-tone":`danger`,className:`sl-callout sl-callout--danger outline-none`,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),(0,h.jsx)(`p`,{className:`sl-callout__title m-0`,children:e??(t?.reason===`readiness`?t.fields.length>0?`This can't start yet. Fix the items below, then try again.`:`Slopify couldn't check your providers. Open Settings → Providers, make sure each one you use is set up, then try again.`:t?.message)}),t?.fields.length?(0,h.jsx)(`ul`,{className:`sl-callout__body m-0 list-disc pl-5`,children:t.fields.map(({field:e,message:t})=>(0,h.jsxs)(`li`,{children:[dbe[e.split(`.`)[0]??``]??`Project`,`: `,t]},`${e}:${t}`))}):null]})}var fbe=q({text:W().optional(),logicalText:W().optional(),title:W().optional(),notes:W().optional(),outline:K(W()).optional(),prompt:W().optional()});function pbe(e){if(e===null)return`No text was recorded for this part.`;try{let t=fbe.safeParse(JSON.parse(e));if(!t.success)return`Recorded text cannot be decoded.`;let{logicalText:n,text:r,title:i,notes:a,outline:o,prompt:s}=t.data;return[n,r,a?.trim()?[i,a].filter(e=>e?.trim()).join(`
304
+ `)}function yye({cues:e,duration:t,onChange:n,onPending:r}){let i=(0,m.useId)(),[a,o]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[s,c]=(0,m.useState)(),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(r);d.current=r,(0,m.useEffect)(()=>{d.current(l)},[l]),(0,m.useEffect)(()=>()=>d.current(!1),[]);function f(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){c(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,o]of a.entries()){let a=o.start.trim()===``?NaN:Number(o.start),s=o.end.trim()===``?NaN:Number(o.end);if(r.has(o.id)){c(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(o.id),!Number.isFinite(a)||a<0||a<i){c(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=a||s>t){c(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(o.text.trim()===``){c(`Caption ${n+1}: enter caption text.`);return}e.push({id:o.id,text:o.text,start:a,end:s,...o.speaker===void 0?{}:{speaker:o.speaker}}),i=s}n(e),c(void 0),u(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(V,{id:`project.captions.editor`})]}),a.map((e,t)=>(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Caption `,t+1]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(wV,{id:`${i}-${e.id}-text`,value:e.text,onChange:n=>{u(!0),o(a.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{u(!0),o(a.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{u(!0),o(a.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:s}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:f,children:`Apply caption edits to draft`}),(0,h.jsx)(V,{id:`project.captions.apply`})]}),l?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function l7(e){return`imagePrompts.${String(e)}`}function u7(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function bye(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function xye(e){let{from:t,to:n,content:r}=e,i=n.map(e=>t.findIndex(t=>t.name===e.name)),a=[],o={},s={};for(let[e,t]of Object.entries(r.promptTemplates))u7(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))u7(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=l7(t),l=i[t]??-1;if(l>=0){let t=l7(l);Object.hasOwn(r.promptTemplates,t)&&(o[n]=r.promptTemplates[t]??null);let i=e.rendered[t];i!==void 0&&(s[n]=i);continue}let u=e.body(c.name);if(u===void 0){a.push({field:`imagePrompts.${String(t)}.name`,message:`The image prompt "${c.name}" is not in the Library any more. Untick it under Images, or add it back on Library → Prompts.`});continue}o[n]=u,s[n]=mq(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=u7(r.imageDefinitions[e]?.templateKey);n===void 0||n>=t.length||c.set(n,[...c.get(n)??[],e])}let l={},u=[],d=[],f=(e,t)=>{let n=l7(e),r=o[n];return t===void 0?{source:`generate`,assetId:null,prompt:s[n]??null,templateKey:r==null?null:n}:{...t,source:`generate`,assetId:null,templateKey:t.templateKey??null}},p=(t,n,r)=>Array.from({length:Math.max(0,n)},()=>{let n=e.key();return l[n]=f(t,r),u.push(n),n}),m=[];for(let e of r.imageOrder){let a=r.imageDefinitions[e];if(a===void 0)continue;let o=u7(a.templateKey);if(o===void 0||o>=t.length){l[e]=a,m.push(e);continue}let s=i.indexOf(o);if(s===-1){d.push(e);continue}let u=c.get(o)??[],f=t[o]?.number!==n[s]?.number,h=f?n[s]?.number??0:u.length,g=u.indexOf(e);if(g>=h){d.push(e);continue}let _=a.templateKey===l7(s)?a:{...a,templateKey:l7(s)};l[e]=_,m.push(e),f&&g===Math.min(u.length,h)-1&&m.push(...p(s,h-u.length,_))}for(let[e,r]of n.entries()){let n=i[e]??-1,a=n>=0?c.get(n)??[]:[];n>=0&&(a.length>0||t[n]?.number===r.number)||m.push(...p(e,r.number,void 0))}return{ok:!0,content:{...r,imageOrder:m,imageDefinitions:l,promptTemplates:o},rendered:s,added:u,removed:d}}function Sye({edit:e,saved:t,prompts:n,problem:r,onChange:i}){let{config:a}=e;if(a.sources.images!==`generate`)return null;let o=n.filter(e=>e.kind===`image`);return(0,h.jsxs)(`section`,{"aria-label":`Image prompts`,className:`space-y-3`,children:[(0,h.jsx)(Y3,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(Cye,{edit:e,saved:t,prompts:o,problem:r})]})}function Cye({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(bye(t,i))return a===void 0?null:(0,h.jsx)(d7,{children:a});let o=0,s=xye({from:t,to:i,content:e.content,rendered:e.config.rendered,values:e.config.values,body:e=>n.find(t=>t.name===e)?.body,key:()=>`planned-${String(++o)}`});if(!s.ok)return(0,h.jsx)(d7,{children:s.fields.map(e=>e.message).join(` `)});let c=e=>`${String(e)} ${e===1?`image`:`images`}`,l=[...s.added.length>0?[`adds ${c(s.added.length)} to make`]:[],...s.removed.length>0?[`removes ${c(s.removed.length)}`]:[]];return(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsx)(d7,{children:a}),(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.length===0?`Saving keeps every image as it is.`:`Saving ${l.join(` and `)}. The other images are kept; the new ones are made when you remake outdated outputs.`})]})}function d7({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function wye({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:iA(r)),o=r?.source===`upload`?[...Zk,`upload`]:Zk,s=i===void 0?[]:[...Dye(i)];return(0,h.jsx)(A2,{value:i,inherit:`None`,sources:o,offerNone:!1,problem:e=>t(`ambientBed.${e}`)??s.find(t=>t.field===e)?.message,onChange:t=>{a(t);let r=aA(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function Tye({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...tk,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(k6,{value:i,problem:e=>t(`loudness.${e}`),onChange:t=>{a(t);let{loudness:r,...i}=e.config;n({...e,config:t.enabled?{...i,loudness:{videoLufs:t.videoLufs,audioFilesLufs:t.audioFilesLufs}}:i})}})}function Eye({edit:e,problem:t,onChange:n}){let[r,i]=(0,m.useState)(()=>({sentencePauseSeconds:String(e.config.sentencePauseSeconds??0),paragraphPauseSeconds:String(e.config.paragraphPauseSeconds??0)}));if(e.config.sources.audio!==`generate`)return null;let a=e=>{let t=F6(r[e]);return t===void 0?`Enter a number of seconds.`:bk(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(P6,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=F6(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function Dye(e){let t=aA(e);return t===void 0?[]:nA(t)}function Oye({edit:e,problem:t,onChange:n}){let r=(0,m.useId)(),{config:i}=e,a=i.imageScale,[o,s]=(0,m.useState)(()=>a===void 0?void 0:XO(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(qO(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=f7(t);l!==void 0&&n({...e,config:{...o,imageScale:{perHour:l,words:c},...a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})},u=i.imagePrompts.reduce((e,t)=>e+t.number,0),d=a===void 0?u:$O(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:f7(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(JO(c))))} minutes of narration: ${String(d)} images${d>u?`, ${String(d-u)} more than the prompts' ${String(u)}`:`, which the prompts' Numbers already cover`}.`},g=t(`imageScale`)??void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:[(0,h.jsx)(kb,{checked:o!==void 0,label:`More images for long videos`,describedBy:`${r}-line`,tip:`play.image-scale`,onChange:e=>l(e?{every:`minutes`,value:`2`}:void 0)}),o===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,value:o.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>l({every:e,value:kye(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{"aria-label":o.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`w-[72px] tabular-nums`,"aria-invalid":p?.problem===!0,"aria-describedby":`${r}-line`,value:o.value,onChange:e=>l({every:o.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:o.every===`minutes`?`minutes`:`images per hour`})]}),g===void 0&&p===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:g!==void 0||p?.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:g??p?.text})]})}function f7(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?YO(t):void 0:t>=1&&t<=240?t:void 0}function kye(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function Aye({edit:e,onChange:t}){let{config:n}=e;return n.sources.images!==`generate`||n.sources.article===`off`?null:(0,h.jsx)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,config:{...a,...r?{imageScenes:!0}:{}}})}})})}function jye({edit:e,view:t,imageKey:n,index:r}){let{api:i}=z(),a=e.content.imageDefinitions[n];if(a===void 0)return null;let o=t?.outputs.filter(e=>e.output.stageKind===`images`&&e.output.role===`image`)??[],s=o.find(e=>e.selected&&e.workKey===`image:${n}`),c=e.uploads?.some(e=>e.destination.kind===`image`&&e.destination.imageKey===n)??!1,l=a.source===`generate`||c||s?.assetId===a.assetId?s:o.find(e=>e.assetId===a.assetId&&e.available),u=l?.available===!0,d=!u&&(l!==void 0||a.source===`provide`&&a.assetId!==null),f=e.regenerate?.includes(`image:${n}`)===!0,p=c?u?`Replacement ready to save; previous image shown until Save`:`Replacement ready to save; preview available after Save`:f?`Made again after you press Save changes; the current image stays until then`:d?`Image file unavailable`:u?a.source===`provide`&&l!==s?`Provided image selected`:l.state===`review`?`Image retained; review required`:l.state===`outdated`?`Outdated image retained until rebuilt`:`Current image retained`:`No completed image yet`,m=u&&/\.(mp4|mov|m4v|webm|mkv)$/i.test(l.output.path);return(0,h.jsxs)(h.Fragment,{children:[!u||t===void 0?null:m?(0,h.jsx)(R0,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(z0,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}function p7(e,t,n){let r=t+n,i=e[t],a=e[r];if(i===void 0||a===void 0)return e;let o=[...e];return o[t]=a,o[r]=i,o}function Mye({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),{content:c}=e,l=KO(e.config),u=(0,m.useRef)(e);u.current=e;function d(e){let n=e.content.imageOrder.flatMap(t=>{let n=e.content.imageDefinitions[t];return n===void 0?[]:[n]}),r=e.content.imageOrder.length===0||e.config.sources.images===`off`?`off`:n.some(e=>e.source===`generate`)?`generate`:`provide`,i={...e,config:{...e.config,sources:{...e.config.sources,images:r,...r===`off`?{video:`off`}:{}}}};u.current=i,t(i)}function f(e,t){let n=i?.()??u.current,r=n.content.imageDefinitions[e];if(r===void 0)return;let a=r.templateKey??`image:${e}`;s(t=>({...t,[e]:(t[e]??0)+1})),d(A5({...n,...n.uploads===void 0?{}:{uploads:n.uploads.filter(t=>t.destination.kind!==`image`||t.destination.imageKey!==e)},content:{...n.content,imageDefinitions:{...n.content.imageDefinitions,[e]:{...r,templateKey:a}}}},a,t))}function p(e){let t=i?.()??u.current,n=t.content,r=crypto.randomUUID();d({...t,config:{...t.config,sources:{...t.config.sources,images:t.config.sources.images===`off`?`provide`:t.config.sources.images}},content:{...n,imageOrder:[...n.imageOrder,r],imageDefinitions:{...n.imageDefinitions,[r]:{source:`provide`,assetId:null,prompt:null}}},uploads:[...t.uploads??[],{stagedFileId:e.id,destination:{kind:`image`,imageKey:r}}]})}return(0,h.jsxs)(`section`,{"aria-label":`Edit images`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Images`}),(0,h.jsx)(V,{id:`project.images.editor`})]}),c.imageOrder.map((t,s)=>{let l=c.imageDefinitions[t];return l===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(jye,{edit:e,view:r,imageKey:t,index:s}),l.source===`generate`?(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${t}-prompt`,children:[`Prompt for image `,s+1]}),(0,h.jsx)(V,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${t}-prompt`,value:l.templateKey===void 0||l.templateKey===null?l.prompt??``:c.promptTemplates[l.templateKey]??l.prompt??``,onChange:e=>f(t,e.target.value)})]}):null,l.source===`generate`&&l.templateKey==null?(0,h.jsxs)(R,{type:`button`,onClick:()=>f(t,l.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(j5,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??u.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&d({...n,regenerate:(n.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:[...(n.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t),{stagedFileId:e.id,destination:{kind:`image`,imageKey:t}}],content:{...r,imageDefinitions:{...r.imageDefinitions,[t]:{...a,source:`provide`,prompt:null,templateKey:null}}}})}},`${t}:${o[t]??0}:${e.config.sources.images===`off`}`),(0,h.jsxs)(R,{type:`button`,disabled:s===0,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(R,{type:`button`,disabled:s===c.imageOrder.length-1,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(R,{type:`button`,onClick:()=>{let n=c.imageOrder.filter(e=>e!==t);d({...e,config:n.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...c,imageOrder:n,imageDefinitions:Object.fromEntries(Object.entries(c.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t)})},children:[`Delete image `,s+1,c.imageOrder.length===1?` and turn Images and Video Off`:``]}),l.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(V,{id:`project.images.regenerate`})]}):null]},t)}),(0,h.jsx)(R,{type:`button`,disabled:c.imageOrder.length>=l,onClick:()=>{if(c.imageOrder.length>=l)return;let t=crypto.randomUUID();d({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...c,imageOrder:[...c.imageOrder,t],promptTemplates:{...c.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...c.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),c.imageOrder.length>=l?(0,h.jsxs)(`p`,{children:[`At most `,l,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(j5,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:p},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(j5,{label:`Add a video clip`,kind:`images`,accept:`video/mp4,video/quicktime,video/webm,video/x-matroska,.mp4,.mov,.m4v,.webm,.mkv`,onPending:e=>n(`clip:new`,e),onReady:p},`new-clip:${e.config.sources.images===`off`}`)]})]})}var Nye=q({logicalKey:W().min(1),logicalText:W(),segment:J([`body`,`intro`,`outro`]),text:W()});function Pye(e,t){if(t==null)return e;let n=[...t.intro??[],...t.body??[],...t.outro??[]];return n.length===0?e:n.flatMap(t=>e.filter(e=>e.key===t))}function Fye(e){let t=new Map,n=new Set,r=0;for(let i of e.pieces){if(!i.selected||i.stageKind!==`audio`||i.piece.kind!==`chunk`)continue;let e;try{e=i.piece.payload===null?null:JSON.parse(i.piece.payload)}catch{r++;continue}let a=Nye.safeParse(e);if(!a.success){r++;continue}let{logicalKey:o,logicalText:s}=a.data;if(n.has(o)){r++;continue}let c=t.get(o);if(c!==void 0&&c.text!==s){r+=c.parts+1,t.delete(o),n.add(o);continue}t.set(o,{key:o,text:s,parts:(c?.parts??0)+1})}return{groups:[...t.values()],unmapped:r}}function Iye({view:e,edit:t,onChange:n,onPending:r,getEdit:i}){let a=(0,m.useId)(),{api:o}=z(),s=N({queryKey:[`narration-chunks`,e.revision.projectId,e.revision.id],queryFn:async()=>{let t=await Sfe(o,e.revision.projectId,e.revision.id);return t.ok?t.value.chunks:null},staleTime:1/0}),c=Fye(e),l=Pye(c.groups,s.data),u=c.unmapped,d=(0,m.useRef)(t);d.current=t;let[f,p]=(0,m.useState)({});function g(e){d.current=e,n(e)}return(0,h.jsxs)(`section`,{"aria-label":`Edit narration`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Narration`}),(0,h.jsx)(V,{id:`project.narration.editor`})]}),t.config.chunking?.mode===`whole`||t.config.chunking===void 0?(0,h.jsx)(`p`,{children:`This narration uses one whole request. Editing its text rebuilds the whole narration request.`}):null,u===0?null:(0,h.jsx)(`p`,{children:`Some older audio cannot be matched reliably to its narration text. Replace the provided narration or rebuild from the article to edit those chunks.`}),l.map((e,n)=>{let o=t.content.narrationOverrides[e.key];return(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Narration chunk `,n+1]}),(0,h.jsxs)(`p`,{children:[e.parts,` audio `,e.parts===1?`part`:`parts`,` in this narration chunk.`]}),(0,h.jsxs)(`div`,{className:`text-small`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.key}-text`,children:[`Text for narration chunk `,n+1]}),(0,h.jsx)(V,{id:`project.narration.chunk-text`,label:`text for narration chunk ${String(n+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${e.key}-text`,value:o?.kind===`text`?o.text:e.text,onChange:n=>{p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,...t.uploads===void 0?{}:{uploads:t.uploads.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key)},content:{...t.content,narrationOverrides:{...t.content.narrationOverrides,[e.key]:{kind:`text`,text:n.target.value}}}})}})]}),(0,h.jsx)(j5,{label:`Replace narration chunk ${n+1}`,kind:`audio`,onPending:t=>r(`narration:${e.key}`,t),onReady:t=>{let n=i?.()??d.current;g({...n,regenerate:(n.regenerate??[]).filter(t=>t!==e.key),uploads:[...(n.uploads??[]).filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),{stagedFileId:t.id,destination:{kind:`narration`,key:e.key}}]})}},`${e.key}:${f[e.key]??0}`),t.regenerate?.includes(e.key)?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Narration chunk `,n+1,` will be regenerated after you save and press Remake.`,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:()=>{let t=i?.()??d.current;g({...t,regenerate:(t.regenerate??[]).filter(t=>t!==e.key)})},children:[`Keep narration chunk `,n+1]})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(R,{type:`button`,onClick:()=>{let t=i?.()??d.current,n={...t.content.narrationOverrides};n[e.key]?.kind===`asset`&&delete n[e.key],p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,content:{...t.content,narrationOverrides:n},uploads:t.uploads?.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),regenerate:[...new Set([...t.regenerate??[],e.key])]})},children:[`Regenerate narration chunk `,n+1,` after review`]}),(0,h.jsx)(V,{id:`project.narration.regenerate`})]})]},e.key)})]})}function Lye(e){let{config:t,fingerprints:n}=e.revision;if(t.sources.audio===`off`)return;let r=t.sources.audio===`provide`?[{key:`audio:provided`,role:`audio_body`}]:[...t.intro===void 0?[]:[{key:`audio:intro`,role:`audio_intro`}],{key:`audio:body:concat`,role:`audio_body`},...t.outro===void 0?[]:[{key:`audio:outro`,role:`audio_outro`}]],i=e.outputs.filter(e=>e.selected&&e.state===`ready`&&e.available&&e.fingerprint===n[e.workKey]),a=r.map(({key:e,role:t})=>i.find(n=>n.workKey===e&&n.output.role===t));if(a.some(e=>e===void 0))return;let o=a.map(e=>e?.output.durationMs);if(o.every(m7))return o.reduce((e,t)=>e+t,0)/1e3+Math.max(0,r.length-1)*t.silenceGapSeconds+2*t.edgeSilenceSeconds;let s=i.find(e=>(e.output.role===`audio_export`||e.output.role===`video`)&&m7(e.output.durationMs))?.output.durationMs;return m7(s)?s/1e3:void 0}function m7(e){return e!=null&&Number.isFinite(e)&&e>0}function Rye({edit:e,prompts:t,problem:n,onChange:r,onPending:i,getEdit:a}){let{config:o}=e;if(o.sources.images!==`generate`)return null;let s=o.reference,c=s===void 0?v6:{source:s.source,prompt:s.prompt??``,thumbnail:s.thumbnail!==!1},l=e=>({...e,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`provided`||e.destination.stage!==`reference`)});return(0,h.jsx)(`section`,{"aria-label":`Establishing image`,className:`space-y-3`,children:(0,h.jsx)(y6,{value:c,prompts:t,problem:n,onChange:n=>{let{reference:i,...a}=o;if(n.source===`off`){r(l({...e,config:a}));return}let s={source:n.source,...n.source===`prompt`?{prompt:n.prompt}:{},...n.thumbnail?{}:{thumbnail:!1}},u=n.source===`prompt`&&n.prompt!==c.prompt?t.find(e=>e.kind===`image`&&e.name===n.prompt):void 0,d={...e,config:{...a,reference:s}},f=u===void 0?d:A5(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(j5,{label:e.content.provided.reference===void 0?`Upload the establishing image`:`Replace the establishing image`,kind:`images`,accept:`image/png,image/jpeg`,onPending:i,onReady:t=>{let n=l(a?.()??e);n.config.reference?.source===`provide`&&r({...n,uploads:[...n.uploads??[],{stagedFileId:t.id,destination:{kind:`provided`,stage:`reference`}}]})}})})})}var zye=q({words:K(q({text:W().trim().min(1),start:G().finite().nonnegative(),end:G().finite().positive(),confidence:G().optional(),speaker:W().min(1).optional()})).min(1)});function h7(e){let{config:t,content:n}=e;return JSON.stringify({source:t.sources.audio,audio:n.provided.audio,uploads:e.uploads?.filter(e=>e.destination.kind===`narration`||e.destination.kind===`provided`&&e.destination.stage===`audio`)??[],edge:t.edgeSilenceSeconds,...t.sources.audio===`generate`?{choice:t.audio,chunking:t.chunking,article:n.articleMarkdown??t.provided.article,articleSource:t.sources.article,renderedArticle:t.rendered.article,intro:t.intro,outro:t.outro,renderedIntro:t.rendered.intro,renderedOutro:t.rendered.outro,gap:t.silenceGapSeconds,overrides:n.narrationOverrides,regenerate:e.regenerate?.filter(e=>/^(audio:|article:|entry:)/.test(e))??[]}:{}})}function Bye({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=z(),s=N(nb(o)).data?.prompts??[],c=h7(t),l=t.config.sources.audio!==`off`&&c===h7({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?Lye(e):void 0,f=d!==void 0&&u!==void 0&&u!==``,p=(0,m.useRef)({edit:t,onChange:r,revisionId:e.revision.id,identity:c});p.current={edit:t,onChange:r,revisionId:e.revision.id,identity:c};let g=(0,m.useRef)(i);g.current=i;let[_,v]=(0,m.useState)(new Set),[y,b]=(0,m.useState)(),x=(0,m.useRef)(void 0),S=(0,m.useRef)(!0),C=(0,m.useCallback)((e,t)=>{S.current&&v(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,m.useEffect)(()=>{g.current(_.size>0)},[_]),(0,m.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&x.current?.abort()}},[e.revision.id,c]);function w(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:h7(e)},t(e)}async function T(){if(x.current!==void 0)return;let t=new AbortController;x.current=t;let n=p.current;C(`captions:load`,!0),b(void 0);try{let r=e.outputs.find(e=>e.selected&&e.state===`ready`&&e.output.role===`subtitle_words`&&e.available);if(!f||d===void 0||u===void 0||r===void 0)throw Error(`Captions can't be edited until the current narration has finished and its subtitle timing is ready.`);let i=await o.fetch(s2(o,e.revision.projectId,e.revision.id,r.recordId),{signal:t.signal});if(!i.ok)throw Error(`The subtitle timing file couldn't be read. Reload the page and try again; if it still fails, use More → make it again in its section on Audio.`);let a=zye.parse(await i.json()),s=0;for(let e of a.words){if(e.start<s||e.end<=e.start||e.end>d)throw Error(`The saved subtitle timing doesn't match the current narration. Use More → make it again in its section on Audio to rebuild it.`);s=e.end}let c=vye(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!S.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;w({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){S.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{x.current===t&&(x.current=void 0),C(`captions:load`,!1)}}let E=t.content.subtitleCues,D=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!D(`images`),className:`space-y-6`,children:[(0,h.jsx)(Sye,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(Oye,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(Aye,{edit:t,onChange:w}),(0,h.jsx)(Rye,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:w,onPending:e=>C(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(I6,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;w({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(j5,{label:`Replace provided ${e}`,kind:e,onPending:t=>C(`provided:${e}`,t),onReady:t=>{let n=p.current;n.edit.config.sources[e]===`provide`&&w({...n.edit,uploads:[...(n.edit.uploads??[]).filter(t=>t.destination.kind!==`provided`||t.destination.stage!==e),{stagedFileId:t.id,destination:{kind:`provided`,stage:e}}]})}},e):null),(0,h.jsx)(Mye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!D(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(Iye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!D(`captions`),className:`space-y-5`,children:[f?null:(0,h.jsx)(`p`,{children:`Captions can be edited once the current narration has finished and its subtitle timing is ready.`}),E===void 0?(0,h.jsx)(R,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void T(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[E.audioFingerprint===u?null:(0,h.jsx)(`p`,{children:`These caption edits belong to an earlier narration. Review their text and timing against the current narration, then apply your corrections and save the project.`}),f&&d!==void 0?(0,h.jsx)(yye,{cues:E.cues,duration:d,onPending:e=>C(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&w({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(R,{type:`button`,onClick:()=>w({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function Vye({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(k2,{value:e.config.language,error:t,onChange:t=>{let{language:r,...i}=e.config;n({...e,config:t===void 0||t===`en`?i:{...i,language:t}})}})})}function Hye({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=z(),a=N(Zb(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:Wb,c=s(o.channelId),l=a.data?.find(e=>e.id===c),u=o.useBrandKit!==!1,d=c!==s(t.channelId),f=u!==(t.useBrandKit!==!1);return(0,h.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(TV,{value:c,onChange:t=>r({...e,config:{...o,channelId:t.target.value}}),children:[a.data===void 0?(0,h.jsx)(`option`,{value:c,children:`Loading channels…`}):null,(a.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col justify-end gap-1`,children:[(0,h.jsx)(kb,{checked:u,label:`Use the channel's brand kit`,tip:`play.brand-kit`,onChange:t=>{let{useBrandKit:n,...i}=o;r({...e,config:t?i:{...i,useBrandKit:!1}})}}),u?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Its cast is still used.`})]}),a.error===null?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-danger md:col-span-2`,children:[`The channels couldn't be loaded: `,a.error.message,`. Reload the page to pick a channel.`]}),d||f?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:[d?`Saving moves the project to this channel and takes its cast as it is now. `:``,u?`The brand kit fills the caption font and colours, title style, end screen, intro, outro and document theme where they are at their default or were set by the old kit.`:`What the old brand kit had set is taken off.`]}):null]})}function Uye(e,t,n){let r=e.outputs.find(e=>e.selected&&e.available&&e.output.role===`reference`);if(t.config.reference!==void 0&&r!==void 0)return{image:{kind:`output`,outputId:r.output.id},drawnOn:`the establishing image`};let i=n.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),a=W6([t.config.title,...Object.values(t.config.values??{})].join(` `),i)[0]??i[0],o=a?.images[0];if(a!==void 0&&o!==void 0)return{image:{kind:`picture`,sha256:o},drawnOn:`${a.name}'s picture`}}function Wye({edit:e,view:t,prompts:n,error:r,onChange:i}){let a=(0,m.useRef)(e.config.narrationPrompt);if(e.config.sources.audio!==`generate`)return null;let o=t.revision.config.narrationPrompt,s=t.revision.content.promptTemplates.narration??t.revision.config.rendered.narration,c=o&&s!==void 0&&!n.some(e=>e.kind===`narration`&&e.name===o)?[...n,{id:`saved-narration`,kind:`narration`,name:o,body:s,slots:[],updatedAt:t.revision.createdAt}]:n;return(0,h.jsx)(g6,{value:e.config.narrationPrompt??``,prompts:c,libraryLinks:!1,supported:e.config.audio?.provider===`inworld`&&e.config.audio.model===`inworld-tts-2`,error:r,onChange:t=>{let n=e.config.narrationPrompt||a.current;t===``&&(a.current=e.config.narrationPrompt);let r=c.find(e=>e.kind===`narration`&&e.name===t),o=r===void 0||t===n?e:A5(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function Gye({edit:e,saved:t=e.config.imagePrompts,prompts:n,entries:r,onChange:i}){let a=(0,m.useId)(),o=[...new Set([...Object.keys(e.config.rendered),...Object.keys(e.content.promptTemplates),...e.config.sources.article===`generate`?[`article`]:[],...uj(e.config)?[`narration`]:[],...pj(e.config)&&e.config.descriptionPrompt?[`description`]:[],..._j(e.config)&&e.config.shorts?.prompt?[`shorts`]:[],..._j(e.config)&&e.config.shorts?.imagePrompt?[`shortsImage`]:[],...[`from_prompt`,`prompt_by_llm`].includes(e.config.sources.thumbnail)?[`thumbnailPrompt`]:[],...hj(e.config)&&e.config.reference?.source===`prompt`?[`referencePrompt`]:[],...e.config.intro===void 0?[]:[`intro`],...e.config.outro===void 0?[]:[`outro`]])].filter(n=>{let r=y7(n);if(r===void 0)return!0;let i=t[r]?.name;return i===void 0||e.config.imagePrompts.some(e=>e.name===i)}),s=e.config.imagePrompts.filter(e=>!t.some(t=>t.name===e.name)),c=e=>Jye(e,t),l=[...new Set([...Object.keys(e.config.values),...Object.values(e.content.promptTemplates).flatMap(e=>e===null?[]:dq(e).names)])].filter(e=>!fq.includes(e)),u=t=>[...dq(e.config.title).names.includes(t)?[`Project title`]:[],...Object.entries(e.content.promptTemplates).flatMap(([e,n])=>n!==null&&dq(n).names.includes(t)?[c(e)]:[])],d=dq(e.config.title).names;return(0,h.jsxs)(`section`,{"aria-label":`Prompt snapshots`,className:`space-y-6`,children:[o.map(o=>{let s=c(o),l=e.content.promptTemplates[o]??null,u=o===`intro`||o===`outro`?r.filter(e=>e.category===o):n.filter(t=>t.kind===(o===`article`?UA(e.config)?`script`:`article`:o===`narration`?`narration`:o===`description`?`description`:o===`shorts`?`shorts`:o===`thumbnailPrompt`?`thumbnail`:`image`));return(0,h.jsxs)(`div`,{className:`min-w-0 space-y-4 border-t border-line pt-6 first:border-t-0 first:pt-0`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:s}),l===null?(0,h.jsx)(SI,{tone:`info`,title:`Original template unavailable`,actions:(0,h.jsx)(R,{"aria-label":`Use saved wording as template for ${s}`,onClick:()=>i(A5(e,o,e.config.rendered[o]??``)),children:`Use saved wording as template`}),children:`The saved prompt below stays as it is until you choose or write a template.`}):null,(0,h.jsx)(qye,{label:s,raw:l,library:Kye(e,o,u,t),onUse:t=>i(A5(e,o,t))}),(0,h.jsx)(xV,{label:`Use saved template for ${s}`,id:`${a}-library-${o}`,tip:`project.prompts.template`,children:(0,h.jsxs)(TV,{value:``,onChange:t=>{let n=u.find(e=>e.id===t.target.value);if(n===void 0)return;let r=A5(e,o,n.body),a=`category`in n?{...r.config,[n.category]:{name:n.name,mode:n.mode}}:o===`article`?{...r.config,articlePrompt:n.name}:o===`narration`?{...r.config,narrationPrompt:n.name}:o===`description`?{...r.config,descriptionPrompt:n.name}:(o===`shorts`||o===`shortsImage`)&&r.config.shorts!==void 0?{...r.config,shorts:{...r.config.shorts,[o===`shorts`?`prompt`:`imagePrompt`]:n.name}}:o===`thumbnailPrompt`?{...r.config,thumbnailPrompt:n.name}:o===`referencePrompt`&&r.config.reference!==void 0?{...r.config,reference:{...r.config.reference,prompt:n.name}}:r.config;i({...r,config:a})},children:[(0,h.jsx)(`option`,{value:``,children:`Choose a saved template`}),u.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,h.jsx)(xV,{label:`Raw prompt for ${s}`,id:`${a}-raw-${o}`,tip:`project.prompts.raw`,children:(0,h.jsx)(wV,{rows:4,value:l??``,onChange:t=>i(A5(e,o,t.target.value))})}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`text-small text-ink-2`,children:`Saved rendered prompt`}),(0,h.jsx)(`pre`,{className:`m-0 mt-2 whitespace-pre-wrap break-words text-small`,children:e.config.rendered[o]??``})]})]},o)}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s.map(e=>`"${e.name}"`).join(`, `),` `,s.length===1?`uses its`:`use their`,` Library wording. Save, then change it here.`]}),l.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`space-y-3 pt-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:`Keywords`}),(0,h.jsx)(_0,{fieldPrefix:`config.values`,keywords:l.map(t=>({name:t,value:e.config.values[t]??``,feeds:u(t),topic:d.includes(t)})),onChange:(t,n)=>i(k5({...e,config:{...e.config,values:{...e.config.values,[t]:n}}}))})]}):null]})}function Kye(e,t,n,r){let{config:i}=e,a=y7(t);if(t===`intro`||t===`outro`){let e=i[t]?.name;return e===void 0||e===``?void 0:n.find(t=>`category`in t&&t.name===e)}let o=t===`article`?i.articlePrompt:t===`narration`?i.narrationPrompt:t===`description`?i.descriptionPrompt:t===`shorts`?i.shorts?.prompt:t===`shortsImage`?i.shorts?.imagePrompt:t===`thumbnailPrompt`?i.thumbnailPrompt:t===`referencePrompt`?i.reference?.prompt:a===void 0?void 0:r[a]?.name;if(o!==void 0&&o!==``)return n.find(e=>!(`category`in e)&&e.name===o)}var g7=`slopify.library-kept`;function _7(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t*33^e.charCodeAt(n))>>>0;return t.toString(36)}function v7(){try{let e=window.localStorage.getItem(g7),t=e===null?[]:JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function qye({label:e,raw:t,library:n,onUse:r}){let i=n===void 0||t===null?``:`${e}:${_7(t)}:${_7(n.body)}`,[a,o]=(0,m.useState)(()=>v7().includes(i));return n===void 0||t===null||n.body===t||a?null:(0,h.jsx)(SI,{tone:`info`,title:`The Library's "${n.name}" has changed since this project copied it`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{"aria-label":`Use the Library version for ${e}`,onClick:()=>{r(n.body)},children:`Use the Library version`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Keep this project's version for ${e}`,onClick:()=>{try{window.localStorage.setItem(g7,JSON.stringify([...v7().filter(e=>e!==i),i].slice(-200)))}catch{}o(!0)},children:`Keep this project's version`})]}),children:`The project uses its own copy below until you choose. Using the Library version marks what it wrote as outdated, to remake when you are ready.`})}function y7(e){let t=/^imagePrompts\.(\d+)$/.exec(e);return t?.[1]===void 0?void 0:Number(t[1])}function Jye(e,t){if(e===`article`)return`Article`;if(e===`narration`)return`Narration Preparation`;if(e===`description`)return`YouTube description`;if(e===`shorts`)return`Shorts`;if(e===`shortsImage`)return`Shorts image style`;if(e===`thumbnailPrompt`)return`Thumbnail`;if(e===`referencePrompt`)return`Establishing image`;if(e===`intro`)return`Intro`;if(e===`outro`)return`Outro`;let n=y7(e);if(n!==void 0){let e=t[n]?.name;return e===void 0||e===``?`Image prompt ${String(n+1)}`:`Image prompt "${e}"`}return e.replace(/[._-]/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`)}function Yye(e,t,n){let{api:r}=z(),[i,a]=(0,m.useState)({busy:!1}),{config:o}=t,s=o.audio,c=async()=>{if(s!==void 0){a({busy:!0});try{let i=await Rs(r,e),{sharedGlossary:c,...l}=o;n({...t,config:{...l,audio:{...s,shareGlossary:!0},...i.entries.length===0?{}:{sharedGlossary:i.entries}}}),a({busy:!1,projects:i.projects})}catch(e){a({busy:!1,error:e instanceof Error?e.message:String(e)})}}},l=()=>{if(s===void 0)return;let{sharedGlossary:e,...r}=o;n({...t,config:{...r,audio:{...s,shareGlossary:!1}}})},u=o.sharedGlossary?.length??0,d=s?.shareGlossary===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[i.error===void 0?u===0?`No pronunciations from other projects are copied yet.`:`${String(u)} ${u===1?`term`:`terms`} copied from ${i.projects===void 0?`your other projects`:`${String(i.projects)} other ${i.projects===1?`project`:`projects`}`}.`:`Couldn't read your other projects' pronunciations: ${i.error}`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:i.busy,onClick:()=>void c(),children:i.busy?`Copying…`:`Update from other projects`}),(0,h.jsx)(V,{id:`project.edit.update-glossary`})]}):void 0;return{value:s?.shareGlossary===!0,onChange:e=>{e?c():l()},note:d}}function Xye(e,t){let{api:n}=z(),[r,i]=(0,m.useState)({busy:!1}),{config:a}=e,o=a.audio,s=async()=>{if(o!==void 0){i({busy:!0});try{let{aliases:r}=await zs(n),{narrationAliases:s,...c}=a;t({...e,config:{...c,audio:{...o,useNarrationAliases:!0},...r.length===0?{}:{narrationAliases:r}}}),i({busy:!1})}catch(e){i({busy:!1,error:e instanceof Error?e.message:String(e)})}}},c=a.narrationAliases?.length??0;return{value:o?.useNarrationAliases===!0,onChange:n=>{if(o!==void 0){if(n)s();else{let{narrationAliases:n,...r}=a;t({...e,config:{...r,audio:{...o,useNarrationAliases:!1}}})}}},note:o?.useNarrationAliases===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[r.error===void 0?c===0?`No aliases are copied yet. Add some in Library → Aliases.`:`${String(c)} ${c===1?`alias`:`aliases`} copied from Library → Aliases.`:`Couldn't read Library → Aliases: ${r.error} Try Update from Library again.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r.busy,onClick:()=>void s(),children:r.busy?`Copying…`:`Update from Library`}),(0,h.jsx)(V,{id:`project.edit.update-aliases`})]}):void 0}}function Zye({projectId:e,edit:t,providers:n,voices:r,onChange:i}){let{config:a}=t,o=a.llm??{provider:``,model:``},s=a.audio??{provider:``,model:``,voice:``},c=Yye(e,t,i),l=Xye(t,i),{api:u}=z(),d=N(Qb(u,a.channelId??`00000000-0000-4000-8000-000000000001`)),f=a.images??{provider:``,model:``},p=uj(a)||a.sources.audio===`generate`&&a.audio?.describeFigures===!0||a.sources.research===`generate`||a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||HA(a)&&a.voices?.source===`attribute`||a.sources.audio===`generate`&&(a.intro?.mode===`llm`||a.outro?.mode===`llm`),m=a.sources.images===`generate`||a.sources.thumbnail===`from_prompt`||a.sources.thumbnail===`prompt_by_llm`,g=r.filter(e=>e.provider===s.provider).map(e=>({value:e.voiceId,label:e.name}));return(0,h.jsxs)(`section`,{"aria-label":`Generation providers`,className:`grid min-w-0 gap-3 sm:grid-cols-2`,children:[p?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Text provider`,tip:`play.llm.provider`,family:`llm`,providers:n,value:o.provider,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Text model`,tip:`play.llm.model`,provider:o.provider,value:o.model,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{...o,model:e}}})}),(0,h.jsx)(b6,{choice:o,onChange:e=>i({...t,config:{...a,llm:e}})})]}):null,a.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[a.voices!==void 0&&a.intro===void 0&&a.outro===void 0?null:(0,h.jsxs)(h.Fragment,{children:[a.voices===void 0?null:(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`The voice below reads only the intro and outro. Each speaker's voice is set under Speakers.`}),(0,h.jsx)(RV,{label:a.voices===void 0?`Narration provider`:`Intro and outro provider`,tip:`play.tts.provider`,family:`tts`,providers:n,value:s.provider,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,provider:e,model:``,voice:``}}})}),(0,h.jsx)(zV,{label:a.voices===void 0?`Narration model`:`Intro and outro model`,tip:`play.tts.model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,model:e}}})}),(0,h.jsx)(FV,{label:a.voices===void 0?`Narration voice`:`Intro and outro voice`,tip:`play.voice`,value:s.voice,problem:void 0,placeholder:`Choose a saved voice`,options:s.voice!==``&&!g.some(e=>e.value===s.voice)?[{value:s.voice,label:`${s.voice} (saved voice)`},...g]:g,onPick:e=>i({...t,config:{...a,audio:{...s,voice:e}}})})]}),(0,h.jsx)(q3,{value:a.chunking??{mode:`whole`},onPick:e=>i({...t,config:{...a,chunking:e}})}),(0,h.jsx)(_6,{shared:c,value:s.usePronunciationGlossary,supported:Sj({sources:a.sources,audio:{...s,usePronunciationGlossary:!0}}),onChange:e=>i({...t,config:{...a,audio:{...s,usePronunciationGlossary:e}}})}),(0,h.jsx)(h6,{...l}),(0,h.jsx)(p6,{tip:`project.edit.describe-figures`,value:s.describeFigures,skipCode:s.skipCode,onChange:({describeFigures:e,skipCode:n})=>{let{describeFigures:r,skipCode:o,...c}=s;i({...t,config:{...a,audio:{...c,...e?{describeFigures:e}:{},...e&&n?{skipCode:n}:{}}}})}}),(0,h.jsxs)(`section`,{"aria-label":`Speakers`,className:`col-span-full border-t border-line pt-3`,children:[(0,h.jsx)(`h3`,{className:`mb-2 text-small font-semibold`,children:`Speakers`}),(0,h.jsx)(f6,{value:a.voices,cast:d.data?.cast??[],language:a.language,providers:n,voices:r,script:t.content.articleMarkdown??void 0,onChange:e=>{let{voices:n,...r}=a;i({...t,config:e===void 0?r:{...r,voices:e}})}})]})]}):null,m?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Image provider`,tip:`play.images.provider`,family:`image`,providers:n,value:f.provider,problem:void 0,onPick:e=>i({...t,config:{...a,images:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Image model`,tip:`play.images.model`,provider:f.provider,value:f.model,problem:void 0,onPick:e=>i({...t,config:{...a,images:{...f,model:e}}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:f,onChange:e=>i({...t,config:{...a,images:e}})})]}):null]})}function Qye({edit:e,providers:t,prompts:n,problem:r,onChange:i}){let{config:a}=e,o=a.reviews===void 0?HV:jk(a.reviews),[s,c]=(0,m.useState)(o),l=a.shorts?.enabled===!0&&a.sources.audio!==`off`,u=e=>Nk({sources:a.sources,shorts:l?{enabled:!0}:void 0},e),d=Mk(s,u).retriesProblem;return(0,h.jsx)(UV,{value:s,providers:t,prompts:n,makes:u,problem:e=>e===`reviews.retries`&&d!==void 0?d:r(e),onChange:t=>{c(t);let{settings:r}=Mk(t,u),o={...e.content.promptTemplates},s={...a.rendered};for(let e of Ck){let t=Ak(e),i=r?.stages[e]?.prompt??``,c=n.find(e=>e.kind===`review`&&e.name===i);if(i===``){let{[t]:e,...n}=o,{[t]:r,...i}=s;o=n,s=i}else c!==void 0&&i!==(a.reviews?.stages[e]?.prompt??``)&&(o={...o,[t]:c.body})}let{reviews:l,...d}=a;i(k5({...e,config:{...d,rendered:s,...r===void 0?{}:{reviews:r}},content:{...e.content,promptTemplates:o}}))}})}function $ye({edit:e,view:t,prompts:n,problem:r,onChange:i}){let a=t.revision.config.descriptionPrompt,o=t.revision.content.promptTemplates.description??t.revision.config.rendered.description,s=a&&o!==void 0&&!n.some(e=>e.kind===`description`&&e.name===a)?[...n,{id:`saved-description`,kind:`description`,name:a,body:o,slots:[],updatedAt:t.revision.createdAt}]:n,c=t.outputs.some(e=>e.selected&&e.workKey===b7&&e.state===`ready`),l=e.regenerate?.includes(b7)===!0;return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(C6,{enabled:e.config.youtubeDescription===!0,prompt:e.config.descriptionPrompt??``,prompts:s,narrated:e.config.sources.audio!==`off`,problem:r,onChange:({youtubeDescription:t,descriptionPrompt:n})=>{let r=s.find(e=>e.kind===`description`&&e.name===n),a=n===(e.config.descriptionPrompt??``)?e:r===void 0?ebe(e):A5(e,`description`,r.body),{descriptionPrompt:o,...c}=a.config;i({...a,config:{...c,youtubeDescription:t,...n===``?{}:{descriptionPrompt:n}}})}}),c&&e.config.youtubeDescription===!0?l?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The YouTube description will be written again after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>{i({...e,regenerate:(e.regenerate??[]).filter(e=>e!==b7)})},children:`Keep the current description`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>{i({...e,regenerate:[...new Set([...e.regenerate??[],b7])]})},children:`Write the description again after review`}),(0,h.jsx)(V,{id:`project.edit.rewrite-description`})]}):null]})}var b7=`youtube:description`;function ebe(e){let{description:t,...n}=e.content.promptTemplates,{description:r,...i}=e.config.rendered;return k5({config:{...e.config,rendered:i},content:{...e.content,promptTemplates:n}})}var tbe={research:`Research source`,article:`Article source`,audio:`Audio source`,images:`Images source`,thumbnail:`Thumbnail source`,video:`Video source`,document:`Document source`},nbe={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`},rbe=`\0kept:`;function x7({title:e,children:t,columns:n=!0}){return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:e}),(0,h.jsx)(`div`,{className:L(`grid min-w-0 gap-4`,n&&`md:grid-cols-2`),children:t})]})}function ibe(e){let{view:t,edit:n,onChange:r,onPending:i,fields:a}=e,o=(0,m.useId)(),[s,c]=(0,m.useState)(e.focus?.section??`inputs`);(0,m.useEffect)(()=>{e.focus!==void 0&&c(e.focus.section)},[e.focus]);let[l,u]=(0,m.useState)({font:!1,content:!1,music:!1});(0,m.useEffect)(()=>{i(l.font||l.content||l.music)},[i,l]);let d=(0,m.useCallback)(e=>{u(t=>t.font===e?t:{...t,font:e})},[]),f=(0,m.useCallback)(e=>{u(t=>t.content===e?t:{...t,content:e})},[]),p=(0,m.useCallback)(e=>{u(t=>t.music===e?t:{...t,music:e})},[]),{api:g}=z(),_=N(eb(g)),v=N(tb(g)),y=N(nb(g)),b=N(rb(g)),{config:x}=n,S=Uye(t,n,N(Qb(g,x.channelId??`00000000-0000-4000-8000-000000000001`)).data?.cast??[]),C=S?.image.kind===`output`?t.outputs.find(e=>e.selected&&e.available&&S.image.kind===`output`&&e.output.id===S.image.outputId):void 0,w=C===void 0?void 0:s2(g,t.revision.projectId,t.revision.id,C.recordId),T=e=>a.find(t=>t.field===e||t.field===`config.${e}`||t.field===`edit.config.${e}`)?.message,E=w6({value:x.videoEdit,narrated:x.sources.audio!==`off`,imageProvider:x.images?.provider??``,problem:T,language:x.language,onChange:e=>r({...n,config:{...x,videoEdit:e}})}),D=[{id:`inputs`,label:`Inputs`},...x.sources.article===`off`?[]:[{id:`article`,label:`Article`,...n.content.articleEdited?{badge:`edited`}:{}}],{id:`providers`,label:`Providers`},{id:`prompts`,label:`Prompts`},{id:`reviews`,label:`Reviews`,...x.reviews===void 0?{}:{badge:`on`}},...x.sources.audio!==`off`||x.shorts?.enabled===!0?[{id:`shorts`,label:`Shorts`,...x.shorts?.enabled?{badge:`on`}:{}}]:[],...x.sources.article===`off`?[]:[{id:`subtitles`,label:`Subtitles`}],{id:`images`,label:`Images`,badge:String(n.content.imageOrder.length)},...x.sources.audio===`generate`?[{id:`narration`,label:`Narration`}]:[],...x.sources.article===`off`?[]:[{id:`captions`,label:`Captions`,...n.content.subtitleCues===void 0?{}:{badge:String(n.content.subtitleCues.cues.length)}}]],O=D.some(e=>e.id===s)?s:`inputs`,k=e=>L(`min-w-0 space-y-6`,O===e?void 0:`hidden`),A=e=>Number.isFinite(e)?e:``,ee=x.sources.video!==`off`;return(0,h.jsxs)(`div`,{className:`grid min-w-0 gap-8 md:grid-cols-[180px_minmax(0,1fr)]`,children:[(0,h.jsx)(`nav`,{"aria-label":`Edit sections`,className:`min-w-0 md:sticky md:top-16 md:self-start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none gap-1 overflow-x-auto p-0 [scrollbar-width:none] md:flex-col`,children:D.map(e=>(0,h.jsx)(`li`,{className:`shrink-0`,children:(0,h.jsx)(t8,{current:e.id===O,onClick:()=>c(e.id),meta:e.badge,className:`whitespace-nowrap`,children:e.label})},e.id))})}),(0,h.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[Object.entries({providers:_.error,voices:v.error,prompts:y.error,entries:b.error}).flatMap(([e,t])=>t===null?[]:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:t.message},e)]),a.length===0?null:(0,h.jsx)(`ul`,{role:`alert`,className:`m-0 space-y-1 pl-5 text-small text-danger`,children:a.map(e=>(0,h.jsx)(`li`,{children:e.message},`${e.field}-${e.message}`))}),(0,h.jsxs)(`section`,{"aria-label":`Inputs`,hidden:O!==`inputs`,className:k(`inputs`),children:[(0,h.jsxs)(x7,{title:`Project`,children:[(0,h.jsx)(xV,{label:`Project title`,error:T(`title`),className:`md:col-span-2`,children:(0,h.jsx)(CV,{value:x.title,maxLength:200,onChange:e=>r({...n,config:{...x,title:e.target.value}})})}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(U6,{value:x.format,onPick:e=>r({...n,config:{...x,format:e}})})})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Channel`,columns:!1,children:(0,h.jsx)(Hye,{edit:n,saved:t.revision.config,problem:T,onChange:r})}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Stages`,children:[FS.filter(e=>x.sources.article!==`off`||e!==`research`&&e!==`audio`&&e!==`document`).map(e=>(0,h.jsx)(xV,{label:tbe[e],tip:nbe[e],error:T(`sources.${e}`),children:(0,h.jsx)(TV,{value:RS(x.sources,e),onChange:i=>{let a=FN(e).find(e=>e.value===i.target.value);if(a===void 0)return;let o=Cve(n,e,a.value);r(e===`article`&&a.value===`provide`&&!n.content.articleEdited?{...o,content:{...o.content,articleMarkdown:t.articleMarkdown??n.content.articleMarkdown}}:o)},children:FN(e).filter(t=>e!==`thumbnail`||t.value!==`prompt_by_llm`||x.sources.article!==`off`).map(t=>(0,h.jsx)(`option`,{value:t.value,disabled:e===`video`&&t.value===`generate`&&x.sources.images===`off`,children:t.label},t.value))})},e)),x.sources.images===`off`?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:`Images are Off. Video is also Off in these changes.`}):null,(0,h.jsx)(xV,{label:`Document theme`,id:`${o}-document-theme`,tip:`play.document-theme`,children:(0,h.jsx)(G3,{id:`${o}-document-theme`,disabled:RS(x.sources,`document`)===`off`,value:x.document,onChange:e=>{r({...n,config:{...x,document:e}})}})})]}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Timing`,children:[(0,h.jsx)(xV,{label:`Silence gap (seconds)`,tip:`play.silence-gap`,error:T(`silenceGapSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.1,value:A(x.silenceGapSeconds),onChange:e=>r({...n,config:{...x,silenceGapSeconds:Number(e.target.value)}})})}),x.sources.audio===`off`?null:(0,h.jsx)(xV,{label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,error:T(`edgeSilenceSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.5,value:A(x.edgeSilenceSeconds),onChange:e=>r({...n,config:{...x,edgeSilenceSeconds:Number(e.target.value)}})})}),ee?(0,h.jsx)(xV,{label:`Seconds per image`,tip:`play.image-seconds`,error:T(`imageSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:600,step:1,value:A(x.imageSeconds),onChange:e=>r({...n,config:{...x,imageSeconds:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Zoom (%)`,tip:`play.zoom`,error:T(`zoomPercent`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:50,step:.5,value:A(x.zoomPercent),onChange:e=>r({...n,config:{...x,zoomPercent:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Motion`,tip:`play.motion`,children:(0,h.jsx)(TV,{value:x.motionStyle,onChange:e=>r({...n,config:{...x,motionStyle:e.target.value}}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null]}),ee?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Cuts and look`,columns:!1,children:[E.cuts,E.look,x.sources.audio===`generate`&&x.audio?.describeFigures===!0?(0,h.jsx)(m6,{tip:`project.edit.show-figures`,value:x.showFigures,onChange:e=>{let{showFigures:t,...i}=x;r({...n,config:e?{...i,showFigures:!0}:i})}}):null]}),x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Ambient sound`,columns:!1,children:(0,h.jsx)(wye,{edit:n,problem:T,onChange:r})})]})]}):null,x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Pauses and volume`,columns:!1,children:[(0,h.jsx)(Eye,{edit:n,problem:T,onChange:r}),(0,h.jsx)(Tye,{edit:n,problem:T,onChange:r})]})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Intro and outro`,children:[`intro`,`outro`].map(e=>{let i=x[e]?.name,a=t.revision.content.promptTemplates[e],o=b.data?.entries.find(t=>t.category===e&&t.name===i),s=i!==void 0&&o!==void 0&&typeof a==`string`&&t.revision.config[e]?.name===i&&a!==o.body,c=n.content.promptTemplates[e],l=`${rbe}${i??``}`,u=i===void 0?``:s&&c!==o?.body?l:i;return(0,h.jsx)(xV,{label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,children:(0,h.jsxs)(TV,{value:u,onChange:i=>{if(i.target.value===l&&typeof a==`string`){r(k5({...n,config:{...x,[e]:t.revision.config[e]},content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:a}}}));return}let o=b.data?.entries.find(t=>t.category===e&&t.name===i.target.value),s={...x};o===void 0?delete s[e]:s[e]={name:o.name,mode:o.mode},r(k5({...n,config:s,content:o===void 0?n.content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:o.body}}}))},children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),i!==void 0&&!b.data?.entries.some(t=>t.category===e&&t.name===i)?(0,h.jsxs)(`option`,{value:i,children:[i,` (saved entry)`]}):null,s?(0,h.jsxs)(`option`,{value:l,children:[i,` · this project's version`]}):null,b.data?.entries.filter(t=>t.category===e).map(e=>(0,h.jsx)(`option`,{value:e.name,children:s&&e.name===i?`${e.name} · Library version (newer)`:e.name},e.id))]})},e)})}),x.sources.research===`provide`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Research`,columns:!1,children:(0,h.jsx)(xV,{label:`Research notes`,tip:`play.provided.research`,error:T(`provided.research`),children:(0,h.jsx)(wV,{rows:6,value:x.provided.research??``,onChange:e=>r({...n,config:{...x,provided:{...x.provided,research:e.target.value}}})})})})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Article`,hidden:O!==`article`,className:k(`article`),children:[(0,h.jsx)(xV,{label:`Article text`,tip:`project.edit.article-text`,error:T(`content.articleMarkdown`)??T(`provided.article`),help:n.content.articleEdited?`Your edited article is kept when other settings change. Regenerating it replaces it after the rebuild review.`:void 0,children:(0,h.jsx)(wV,{rows:12,maxLength:5e5,value:(n.content.articleEdited?n.content.articleMarkdown:t.articleMarkdown)??n.content.articleMarkdown??x.provided.article??``,onChange:e=>r({...n,content:{...n.content,articleMarkdown:e.target.value,articleEdited:!0}})})}),x.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:()=>r({...n,regenerate:[...new Set([...n.regenerate??[],`article:body`])]}),children:`Regenerate article after review`}),(0,h.jsx)(V,{id:`project.edit.regenerate-article`})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Providers`,hidden:O!==`providers`,className:k(`providers`),children:[(0,h.jsx)(Vye,{edit:n,error:T(`language`),onChange:r}),(0,h.jsx)(Zye,{projectId:t.revision.projectId,edit:n,providers:_.data?.providers??[],voices:v.data?.voices??[],onChange:r}),(0,h.jsx)(Wye,{edit:n,view:t,prompts:y.data?.prompts??[],error:T(`narrationPrompt`),onChange:r})]}),(0,h.jsxs)(`section`,{"aria-label":`Prompts`,hidden:O!==`prompts`,className:k(`prompts`),children:[(0,h.jsx)($ye,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r}),(0,h.jsx)(Gye,{edit:n,saved:t.revision.config.imagePrompts,prompts:y.data?.prompts??[],entries:b.data?.entries??[],onChange:r})]}),(0,h.jsx)(`section`,{"aria-label":`Reviews`,hidden:O!==`reviews`,className:k(`reviews`),children:(0,h.jsx)(Qye,{edit:n,providers:_.data?.providers??[],prompts:y.data?.prompts??[],problem:T,onChange:r})}),(0,h.jsx)(`section`,{"aria-label":`Shorts`,hidden:O!==`shorts`,className:k(`shorts`),children:(0,h.jsx)(Eve,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r,onPending:p})}),(0,h.jsxs)(`section`,{"aria-label":`Subtitles`,hidden:O!==`subtitles`,className:k(`subtitles`),children:[(0,h.jsx)(`div`,{"data-tour":`project-subtitles`,children:(0,h.jsx)(H6,{value:x.subtitles??hM,format:x.format,audioEnabled:x.sources.audio!==`off`,videoEnabled:ee,onChange:e=>r({...n,config:{...x,subtitles:ON(e,x.sources)}}),onUploading:d,problem:T})}),O!==`subtitles`||!ee?null:(0,h.jsx)(O6,{drawnOn:S?.drawnOn,poster:w,settings:{format:x.format,subtitles:{mode:(x.subtitles??hM).mode,fontId:(x.subtitles??hM).fontId,fontSize:(x.subtitles??hM).fontSize,position:(x.subtitles??hM).position??`bottom`},videoEdit:x.videoEdit,image:S?.image}})]}),e.renderContent?.({view:t,edit:n,fields:a,onChange:r,onPending:f,section:O})]})]})}var S7={notes:`Research notes`,article_md:`Article (Markdown)`,article_txt:`Article text`,narration_txt:`Clean Narration`,tts_script:`TTS Script`,sources:`Research sources`,glossary:`Glossary`,audio_body:`Narration`,audio_intro:`Intro narration`,audio_outro:`Outro narration`,audio_export:`Audio export`,image:`Image`,thumbnail:`Thumbnail`,video:`Video`,render_params:`Export settings`,subtitles_srt:`Subtitles (SRT)`,subtitles_vtt:`Subtitles (VTT)`,subtitle_words:`Subtitle timing`,subtitle_ass:`Styled subtitles`,subtitle_font:`Subtitle font`,instructions:`Generation instructions`,document_pdf:`Document (PDF)`,youtube_description:`YouTube description`,youtube_tags:`YouTube tags`,youtube_pinned_comment:`Pinned comment`,youtube_titles:`Other titles`,shorts:`Shorts list`,short_image:`Short image`,short_video:`Short`,animated_image:`Animated image`,figure_card:`On-screen card`,reference:`Establishing image (reference)`,script_md:`Script (speaker split)`,audio_mp3:`Audio (MP3 with chapters)`,audio_m4b:`Audiobook (M4B with chapters)`,audio_levelled:`Levelled narration`};function C7(e){return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment?`${e.meta.segment===`body`?`Body`:e.meta.segment===`intro`?`Intro`:`Outro`} ${S7[e.role]}`:e.role===`short_video`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)}`:e.role===`short_image`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)} image ${String(e.meta.index??1)}`:e.role===`figure_card`&&typeof e.meta.index==`number`?`On-screen card ${String(e.meta.index)}`:e.role===`animated_image`&&typeof e.meta.index==`number`?`Animated image ${String(e.meta.index)}`:e.role===`image`&&typeof e.meta.index==`number`?`Image ${e.meta.index}`:S7[e.role]}function abe(e){if(e.startsWith(`image:`))return`Image`;if(e.startsWith(`animate:`))return S7.animated_image;if(/^shorts:\d+:render$/.test(e))return S7.short_video;if(/^shorts:\d+:image:\d+$/.test(e))return S7.short_image;if(e===`document:pdf`)return S7.document_pdf;let t=e.split(`:`).at(-1);return Object.entries(S7).find(([e])=>e===t)?.[1]??`Saved output`}function obe({preview:e,pending:t,feedback:n,onStart:r,onCancel:i}){let a=fbe(e),[o,s]=(0,m.useState)([]),[c,l]=(0,m.useState)(!1),u=(0,m.useId)(),d=e.work.filter(e=>e.disposition===`blocked`),f=e.providedReuseRequired.filter(e=>!o.includes(e)),p=e.work.filter(e=>e.disposition===`generate`||e.disposition===`local`||e.disposition===`review`).length,g=p===1?`Remake 1 output`:`Remake ${String(p)} outputs`,_=[...d.length===0?[]:[`${d.length===1?`1 item is`:`${d.length} items are`} unavailable (reasons above)`],...f.map(e=>`tick “Keep the provided content for ${a(e)}”`),...e.costs.unknown===0||c?[]:[`tick “I understand that ${e.costs.unknown} cost estimates are unknown”`]],v=_.length===0,y=cbe.map(t=>({disposition:t,count:e.work.filter(e=>e.disposition===t).length})).filter(e=>e.count>0),b=e.costs.rows.some(e=>e.onPlan===!0),x=e.costs.apiLow,S=e.costs.apiHigh;return(0,h.jsxs)(`section`,{"aria-label":`Review affected rebuild`,className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-6 gap-y-3 sm:grid-cols-3`,children:[y.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:O7[e.disposition]}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:e.count})]},e.disposition)),(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:e.costs.unknown>0?`known cost`:`cost`}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:D7(e.costs.low,e.costs.high)})]})]}),b?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`CLI work: $0 on your plan${x===void 0||S===void 0?``:` · ~${D7(x,S)} via API`}.`}):null,d.length===0?null:(0,h.jsx)(SI,{tone:`danger`,title:`${d.length===1?`1 item can’t`:`${d.length} items can’t`} run, so this rebuild can’t start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:lbe(d,a).map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.what,`:`]}),` `,e.reason]},e.reason))})}),e.wholeRequestNotice===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.wholeRequestNotice}),e.warnings.map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e},e)),(0,h.jsxs)(`div`,{className:`flex flex-col divide-y divide-line border-y border-line`,children:[e.review?.inputChanges.length?(0,h.jsx)(w7,{summary:`Changed inputs (${String(e.review.inputChanges.length)})`,children:(0,h.jsx)(`dl`,{className:`m-0 flex flex-col gap-3`,children:e.review.inputChanges.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`dt`,{className:`font-semibold`,children:e.label}),(0,h.jsxs)(`dd`,{className:`m-0 grid gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(T7,{label:`Before`,text:e.before}),(0,h.jsx)(T7,{label:`After`,text:e.after})]})]},e.label))})}):null,(0,h.jsxs)(w7,{summary:`Work items (${e.work.length}): ${y.map(e=>`${e.count} ${O7[e.disposition]}`).join(`, `)||`none`}`,children:[e.changedInputs.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 mb-3 flex flex-col gap-1 pl-5`,children:e.changedInputs.map(e=>(0,h.jsxs)(`li`,{children:[a(e.path),`:`,` `,e.after===null?`Removed`:e.before===null?`New output`:`Inputs changed`]},e.path))}),(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-2 pl-5`,children:e.work.map(t=>(0,h.jsxs)(`li`,{children:[a(t.key),`: `,O7[t.disposition],`. `,t.reason,t.inflight?` An already submitted request may still be billed.`:``,e.review?.requests.filter(e=>e.key===t.key).map(e=>(0,h.jsxs)(`div`,{children:[e.settings===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.settings}),e.text===null?null:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:`View request text`}),(0,h.jsx)(`pre`,{className:`m-0 max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.text})]})]},e.key))]},t.key))}),(0,h.jsxs)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:[`Retained outputs:`,` `,e.retained.map(e=>abe(e.slot)).join(`, `)||`None`]})]}),e.costs.rows.length===0?null:(0,h.jsx)(w7,{summary:`Cost by step`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:e.costs.rows.map(e=>(0,h.jsxs)(`li`,{children:[a(e.stage),`: `,sbe(e),`. `,e.detail]},`${e.stage}-${e.detail}`))})})]}),n,(0,h.jsxs)(`div`,{className:`sticky bottom-[-16px] -mx-4 flex flex-col gap-3 border-t border-line bg-raised px-4 py-3`,children:[e.providedReuseRequired.length===0&&e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small`,children:[e.providedReuseRequired.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:o.includes(e),onChange:t=>s(t.target.checked?[...o,e]:o.filter(t=>t!==e))}),(0,h.jsxs)(`span`,{children:[`Keep the provided content for `,a(e)]})]}),(0,h.jsx)(V,{id:`project.rebuild.keep-provided`,className:`-my-1`})]},e)),e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:c,onChange:e=>l(e.target.checked)}),(0,h.jsxs)(`span`,{children:[`I understand that `,e.costs.unknown,` cost estimates are unknown.`]})]}),(0,h.jsx)(V,{id:`project.rebuild.unknown-costs`,className:`-my-1`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:t||!v,"aria-describedby":v?void 0:u,onClick:()=>r({acknowledgeUnknownCosts:c,confirmedProvidedWorkKeys:o}),children:t?`Starting the remake…`:g}),(0,h.jsx)(R,{disabled:t,onClick:i,children:`Keep things as they are`}),v||t?null:(0,h.jsx)(`p`,{id:u,className:`m-0 min-w-0 text-small text-ink-2`,children:`${g} is off until: ${_.join(`; `)}.`})]})]})]})}function w7({summary:e,children:t}){return(0,h.jsxs)(`details`,{className:`py-3 text-small`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold text-ink`,children:e}),(0,h.jsx)(`div`,{className:`mt-3`,children:t})]})}function T7({label:e,text:t}){return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`pre`,{className:`m-0 max-h-40 overflow-auto whitespace-pre-wrap break-words text-small`,children:t??`Not set`})]})}var E7=e=>e===null?`Unknown`:e===0?`$0`:new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:e>0&&e<.01?4:2}).format(e);function D7(e,t){return e===t?E7(e):`${E7(e)}–${E7(t)}`}function sbe(e){return e.onPlan===!0?`$0 on plan${e.apiLow===void 0||e.apiLow===null||e.apiHigh===void 0?``:` · ~${D7(e.apiLow,e.apiHigh??null)} via API`}`:D7(e.low,e.high)}var cbe=[`generate`,`local`,`review`,`reuse`,`blocked`];function lbe(e,t){let n=new Map;for(let t of e){let e=t.reason.trim()||`No reason was given.`;n.set(e,[...n.get(e)??[],t.key])}return[...n].map(([e,n])=>({reason:e,what:n.length===1?t(n[0]??``):`${n.length} ${new Set(n.map(k7)).size===1?ube(k7(n[0]??``)):`items`}`}))}function ube(e){return/s$/u.test(e)?e:`${e.charAt(0).toLowerCase()}${e.slice(1)}s`}var O7={reuse:`kept as they are`,generate:`to make`,local:`built on this computer`,review:`to confirm`,blocked:`can't run`},dbe={"export:wav":`Audio export (WAV)`,"export:video":`Video export`,"subtitles:timing":`Subtitle timing`,"subtitles:cues":`Caption text and timing`,"subtitles:files":`Subtitle files`,"article:body":`Article`,"audio:provided":`Provided narration`,"audio:body:concat":`Combined narration`,"audio:intro":`Combined intro narration`,"audio:outro":`Combined outro narration`,"research:planner":`Research plan`,"research:notes":`Research notes`,"entry:intro:text":`Intro text`,"entry:outro:text":`Outro text`};function k7(e){let t=dbe[e];return t===void 0?{image:`Image request`,images:`Images`,audio:`Narration request`,article:`Article`,research:`Research`,thumbnail:`Thumbnail`,subtitles:`Subtitles`,video:`Video export`,export:`Export`,entry:`Intro or outro`}[e.split(`:`)[0]??``]??`Output`:t}function fbe(e){let t=new Map,n=new Map;for(let t of e.work){let e=k7(t.key);n.set(e,(n.get(e)??0)+1)}let r=new Map;for(let i of e.work){let e=k7(i.key),a=(r.get(e)??0)+1;r.set(e,a),t.set(i.key,(n.get(e)??0)>1?`${e} ${a}`:e)}for(let n of e.review?.requests??[])t.set(n.key,n.label);return e=>t.get(e)??k7(e)}var pbe={llm:`Text generation`,image:`Images`,images:`Images`,tts:`Audio`,audio:`Audio`};function A7({error:e,refusal:t}){let n=(0,m.useRef)(null);return(0,m.useEffect)(()=>{(e!==void 0||t!==void 0)&&n.current?.focus()},[e,t]),e===void 0&&t===void 0?null:(0,h.jsxs)(`div`,{ref:n,role:`alert`,tabIndex:-1,"data-tone":`danger`,className:`sl-callout sl-callout--danger outline-none`,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),(0,h.jsx)(`p`,{className:`sl-callout__title m-0`,children:e??(t?.reason===`readiness`?t.fields.length>0?`This can't start yet. Fix the items below, then try again.`:`Slopify couldn't check your providers. Open Settings → Providers, make sure each one you use is set up, then try again.`:t?.message)}),t?.fields.length?(0,h.jsx)(`ul`,{className:`sl-callout__body m-0 list-disc pl-5`,children:t.fields.map(({field:e,message:t})=>(0,h.jsxs)(`li`,{children:[pbe[e.split(`.`)[0]??``]??`Project`,`: `,t]},`${e}:${t}`))}):null]})}var mbe=q({text:W().optional(),logicalText:W().optional(),title:W().optional(),notes:W().optional(),outline:K(W()).optional(),prompt:W().optional()});function hbe(e){if(e===null)return`No text was recorded for this part.`;try{let t=mbe.safeParse(JSON.parse(e));if(!t.success)return`Recorded text cannot be decoded.`;let{logicalText:n,text:r,title:i,notes:a,outline:o,prompt:s}=t.data;return[n,r,a?.trim()?[i,a].filter(e=>e?.trim()).join(`
305
305
 
306
306
  `):void 0,o?.filter(e=>e.trim()).map((e,t)=>`${t+1}. ${e}`).join(`
307
- `),s].find(e=>e?.trim())??`No text was recorded for this part.`}catch{return`Recorded text cannot be decoded.`}}function mbe({projectId:e,pending:t,onRestore:n}){let{api:r}=z(),[i,a]=(0,m.useState)(),o=N({queryKey:B.revisions(e),queryFn:async()=>{let t=await xfe(r,e);if(!t.ok)throw Error(t.message);return t.value.revisions}}),s=N({queryKey:B.revision(e,i??``),enabled:i!==void 0,queryFn:async()=>{if(i===void 0)throw Error(`Choose a version from History first.`);let t=await a2(r,e,i);if(!t.ok)throw Error(t.message);return t.value.view}}),c=s.data,l=c?.outputs.find(e=>e.selected&&e.available&&(e.output.role===`image`||e.output.role===`thumbnail`)),u=l??c?.outputs.find(e=>e.available);return(0,h.jsxs)(`section`,{"aria-label":`Project history`,className:`space-y-3`,children:[(0,h.jsx)(H,{title:`Project history`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:o.error.message}),(0,h.jsx)(`ol`,{className:`space-y-2`,children:o.data?.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(R,{type:`button`,onClick:()=>a(e.id),children:[e.title,` · `,e.createdAt,e.current?` · Current`:``]})},e.id))}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:s.error.message}),c===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:c.revision.config.title}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{variant:`primary`,disabled:t,onClick:()=>n(c.revision.id),children:`Restore this revision`}),l===void 0?null:(0,h.jsxs)(mS,{href:Efe(r,e,c.revision.id),download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download all images`]}),u===void 0?null:(0,h.jsx)(u2,{projectId:e,asset:``,folder:{revisionId:c.revision.id,recordId:u.recordId}})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-3 p-0`,children:c.outputs.map(t=>(0,h.jsxs)(`li`,{className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:C7(t.output)}),(0,h.jsxs)(`span`,{className:`text-small text-ink-2`,children:[` · ${t.state}${t.selected?``:` · Earlier result`}`,t.available?``:` · File missing`]})]}),t.available?(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,"aria-label":`Download ${C7(t.output)}`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download`]}):null]}),t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained output`}),t.output.role===`video`?(0,h.jsx)(R0,{className:`max-w-[640px]`,label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):[`audio_export`,`audio_body`,`audio_intro`,`audio_outro`].includes(t.output.role)?(0,h.jsx)($8,{label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):t.output.role===`image`||t.output.role===`thumbnail`?(0,h.jsx)(z0,{className:`max-w-[480px]`,alt:C7(t.output),title:C7(t.output),meta:t.selected?`Current`:`Earlier result`,src:s2(r,e,c.revision.id,t.recordId)}):(0,h.jsx)(`p`,{children:`Use Download to inspect this retained file.`})]}):null]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained narration parts`,children:c.pieces.filter(e=>e.stageKind===`audio`&&e.assetId!==null).map(t=>(0,h.jsxs)(`li`,{children:[`Narration part `,t.piece.idx,t.selected?``:` · Earlier result`,t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained audio part`}),(0,h.jsx)($8,{label:`Narration part ${String(t.piece.idx)}`,src:s2(r,e,c.revision.id,t.recordId)}),(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download narration part`]})]}):(0,h.jsx)(`span`,{children:` · File missing`})]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained text parts`,children:c.pieces.filter(e=>e.assetId===null).map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(`details`,{children:[(0,h.jsxs)(`summary`,{children:[e.stageKind,` part `,e.piece.idx]}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words`,children:pbe(e.piece.payload)})]})},e.recordId))})]})]})}function M7(e,t,n){let r=JSON.stringify(t);return e?.payload===r?e:{payload:r,idempotencyKey:n()}}function hbe(e,t,n={}){let{api:r}=z(),i=_(),a=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved settings to show yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);return n.value.view}}),[o,s]=(0,m.useState)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(),[f,p]=(0,m.useState)(),[h,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(),w=(0,m.useRef)(void 0),T=(0,m.useRef)(void 0),E=(0,m.useRef)(void 0),D=(0,m.useRef)(n.onOpenEdit);D.current=n.onOpenEdit;let O=(0,m.useMemo)(()=>c!==void 0&&(o===void 0||(c.regenerate?.length??0)>0||(c.uploads?.length??0)>0||JSON.stringify(c.config)!==JSON.stringify(o.revision.config)||JSON.stringify(c.content)!==JSON.stringify(o.revision.content)),[c,o]),k=c!==void 0&&o!==void 0&&t!==null&&t!==o.revision.id,A=(0,m.useRef)(!1);async function ee(e){if(!A.current){A.current=!0,g(!0),x(void 0),C(void 0);try{await e()}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1,g(!1)}}}async function te(t){let n=await r2(r,e);if(!n.ok){C(n);return}return C(void 0),s(n.value.view),t&&l({config:structuredClone(n.value.view.revision.config),content:structuredClone(n.value.view.revision.content)}),n.value.view}async function ne(t){let n=await jo(r,e);return i.setQueryData(B.project(e),n),await i.invalidateQueries({queryKey:B.revisions(e)}),!t.current||n.revisionId!==t.revision.id?(C({ok:!1,reason:`conflict`,message:`The project changed again. Your draft is preserved.`,currentRevisionId:n.revisionId,fields:[]}),!1):(s(t),l(void 0),C(void 0),d(void 0),!0)}async function j(){if(v||o===void 0||c===void 0)return;let t={baseRevisionId:o.revision.id,edit:c},n=M7(w.current,t,()=>crypto.randomUUID());w.current=n;let i=await i2(r,e,{...t,idempotencyKey:n.idempotencyKey});if(!i.ok){C(i);return}await ne(i.value.view),w.current=void 0}async function re(t,n=u){if(n===void 0)return;let a={baseRevisionId:n.baseRevisionId,previewId:n.id,...t},o=M7(E.current,a,()=>crypto.randomUUID());E.current=o;let s=await wfe(r,e,{...a,idempotencyKey:o.idempotencyKey});if(!s.ok){C(s),(s.reason===`stale-preview`||s.reason===`conflict`)&&d(void 0);return}E.current=void 0,d(void 0),await i.invalidateQueries({queryKey:B.project(e)})}async function M(t,n){let i=await te(!1);if(i===void 0)return;let a=await Cfe(r,e,{baseRevisionId:i.revision.id,request:t});if(!a.ok){C(a);return}let o=a.value.value;if(E.current=void 0,n&&gbe(o)){await re({acknowledgeUnknownCosts:!1,confirmedProvidedWorkKeys:[]},o);return}d(o)}async function ie(t){let n=o??a.data??await te(!1);if(n===void 0)return;let i={baseRevisionId:n.revision.id,targetRevisionId:t},s=M7(T.current,i,()=>crypto.randomUUID());T.current=s;let c=await bfe(r,e,{...i,idempotencyKey:s.idempotencyKey});if(!c.ok){C(c);return}await ne(c.value.view),T.current=void 0}return{saved:a,view:o,edit:c,preview:u,focus:f,pending:h,uploading:v,error:b,refusal:S,unsaved:O,remoteChanged:k,busy:h||v||c!==void 0||u!==void 0,setEdit:l,setUploading:y,openEditor:()=>void ee(async()=>{await te(!0)}),discard:()=>{l(void 0),C(void 0),y(!1),w.current=void 0},save:()=>void ee(j),reloadDraft:()=>void ee(async()=>{w.current=void 0,y(!1),await te(!0),C(void 0)}),reloadCurrent:()=>void ee(async()=>{T.current=void 0,E.current=void 0,d(void 0),await te(!1),await i.invalidateQueries({queryKey:B.project(e)})}),requestEdit:e=>void ee(async()=>{let t=o,n=c;if(t===void 0||n===void 0){if(t=await te(!1),t===void 0)return;n={config:structuredClone(t.revision.config),content:structuredClone(t.revision.content)}}l(e.change(n,t)),p({section:e.section}),D.current?.()}),regenerateNow:t=>void ee(async()=>{let n=e=>({...e,regenerate:[...new Set([...e.regenerate??[],...t])]});if(c!==void 0&&O){l(n(c)),p({section:`images`}),D.current?.();return}let i=await te(!1);if(i===void 0)return;let a=await i2(r,e,{baseRevisionId:i.revision.id,edit:n({config:structuredClone(i.revision.config),content:structuredClone(i.revision.content)}),idempotencyKey:crypto.randomUUID()});if(!a.ok){C(a);return}await ne(a.value.view)&&await M({kind:`selected`,workKeys:t},!0)}),review:(e,t)=>void ee(()=>M(e,t?.autoStart===!0)),start:e=>void ee(()=>re(e)),closePreview:()=>{h||(d(void 0),E.current=void 0)},restore:e=>void ee(()=>ie(e))}}function gbe(e){return!e.work.some(e=>e.disposition===`blocked`)&&e.providedReuseRequired.length===0&&e.costs.unknown===0}function _be({controller:e,renderEditor:t,active:n=!0,intro:r}){let i=e;return i.view===void 0||i.edit===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r??(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Saved revision`,info:`project.saved-revision`}),i.saved.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.saved.error.message}),i.saved.data===void 0?null:(0,h.jsx)(`ul`,{"aria-label":`Saved output status`,className:`sl-list m-0 list-none p-0`,children:i.saved.data.outputs.filter(e=>e.selected).map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:C7(e.output)}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.available?e.state===`ready`?`Ready`:e.state===`outdated`?`Outdated; the retained version stays until it is remade`:`Provided content needs review`:`Retained file missing`})]},e.recordId))})]}),i.preview===void 0&&n?(0,h.jsx)(j7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{children:[i.refusal?.reason===`conflict`&&n?(0,h.jsx)(R,{disabled:i.pending,onClick:i.reloadCurrent,children:`Reload current revision`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{disabled:i.busy,onClick:()=>i.review({kind:`allAffected`}),variant:`secondary`,children:`Choose what to remake`}),(0,h.jsx)(V,{id:`project.choose-remake`})]}),(0,h.jsx)(R,{variant:`primary`,disabled:i.busy,onClick:i.openEditor,children:`Edit project`})]})]}):(0,h.jsxs)(`form`,{"aria-label":`Edit project`,onSubmit:e=>{e.preventDefault(),i.save()},children:[(0,h.jsx)(`fieldset`,{disabled:i.pending,className:`m-0 min-w-0 border-0 p-0`,children:t({view:i.view,edit:i.edit,fields:i.refusal?.fields??[],onChange:i.setEdit,onPending:i.setUploading,...i.focus===void 0?{}:{focus:i.focus}})}),i.preview===void 0?(0,h.jsx)(j7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:i.remoteChanged?`warning`:`info`,children:i.remoteChanged?`A newer revision is available. Your unsaved changes are kept below.`:i.uploading?`Waiting for uploads to finish…`:void 0}),children:[i.remoteChanged||i.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:i.pending||i.uploading,onClick:i.reloadDraft,children:`Reload current revision and discard my draft`}):null,(0,h.jsx)(R,{variant:`quiet`,disabled:i.pending||i.uploading,onClick:i.discard,children:`Discard changes`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:i.pending||i.uploading,children:`Save changes`})]})]})}function vbe({controller:e,projectId:t,active:n}){let r=e;return n?(0,h.jsxs)(h.Fragment,{children:[r.preview===void 0&&(r.error||r.refusal)?(0,h.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3`,children:[(0,h.jsx)(j7,{error:r.error,refusal:r.refusal}),r.edit===void 0&&r.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:r.pending,onClick:r.reloadCurrent,className:`self-start`,children:`Reload current revision`}):null]}):null,(0,h.jsx)(mbe,{projectId:t,pending:r.busy,onRestore:r.restore})]}):null}function ybe({controller:e}){let t=e;return(0,h.jsx)(YP,{open:t.preview!==void 0,title:`Choose what to remake`,onClose:t.closePreview,children:t.preview===void 0?null:(0,h.jsx)(w7,{preview:t.preview,feedback:(0,h.jsx)(j7,{error:t.error,refusal:t.refusal}),pending:t.pending,onStart:t.start,onCancel:t.closePreview},t.preview.id)})}var bbe=(e,t)=>{if(t)return`waiting`;switch(e.state){case`running`:return`running`;case`done`:case`provided`:return`done`;case`failed`:return e.retryAt===void 0?`failed`:`waiting`;default:return`off`}},xbe=(e,t)=>{if(t)return`Held for you`;switch(e.state){case`running`:return`Running`;case`done`:return`Done`;case`provided`:return`Provided`;case`failed`:return e.retryAt===void 0?`Failed`:`Waiting to try again`;case`canceled`:return`Canceled`;case`skipped`:return`Off`;case`pending`:return`Not started`}};function Sbe(e,t){if(e.startedAt===null)return;let n=Date.parse(e.startedAt),r=e.finishedAt===null?t:Date.parse(e.finishedAt);if(!Number.isFinite(n)||!Number.isFinite(r)||r<n)return;let i=Math.round((r-n)/1e3);if(i<1)return;if(i<60)return`${String(i)} s`;let a=Math.round(i/60);return a<60?`${String(a)} min`:`${String(Math.floor(a/60))} h ${String(a%60)} min`}function Cbe(e,t,n){let r=T3(t,n);return r===void 0?e:e===void 0||e===``?E3(r):`${e} · ${E3(r)}`}function wbe({stages:e,outputs:t,project:n,resumable:r,held:i,now:a}){return e.filter(e=>e.state!==`skipped`).map(e=>{let o=i.some(t=>t.stage===e.kind),s=Sbe(e,a);return{id:e.id,name:e.kind===`video`&&rF(n.config)===`audio`?`Audio export`:r5[e.kind],tone:bbe(e,o),state:xbe(e,o),...s===void 0?{}:{time:s},detail:o?`Held for your review`:Cbe(cF(e,t,n,r),e,a)}})}function Tbe({stages:e}){return(0,h.jsx)(`div`,{className:`sr-only`,children:e.filter(e=>e.state!==`skipped`).map(e=>(0,h.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:`${r5[e.kind]}: ${e.state}`},e.id))})}function Ebe({steps:e}){return(0,h.jsxs)(`section`,{"aria-labelledby":`run-steps-title`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{id:`run-steps-title`,title:`Run`,size:`small`,className:`pb-0`}),(0,h.jsx)(O3,{steps:e,label:`Run steps`,dense:!0})]})}var N7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});function Dbe({cost:e,onOpen:t}){if(e===void 0||e.calls===0&&e.byStage.length===0)return null;let n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({key:`${e.account}/${t.kind}`,name:e.name,window:t.kind===`five_hour`?`5-hour`:t.kind===`weekly`?`weekly`:`current`,used:t.usedPercent,now:t.nowPercent})):[]);return(0,h.jsxs)(`section`,{"aria-labelledby":`cost-so-far-title`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{id:`cost-so-far-title`,title:`Cost so far`,size:`small`,className:`pb-0`,children:t===void 0?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`By stage`})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[(0,h.jsx)(`strong`,{className:`text-ink`,children:a7(e.cost)}),e.unpriced>0?` known, spent`:` spent`,e.apiEquivalent===null?null:` · ~${a7(e.apiEquivalent)} via API`,e.run===null||e.run.running?null:` · ${o7(e.run.workingMs)} of work`]}),n.map(e=>{let t=e.used<1?`under 1%`:`${N7.format(e.used)}%`,n=`${e.window} ${e.name} limit`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`${e.name}: ${t} of your ${e.window} limit`}),(0,h.jsx)(q2,{value:e.used/100,label:`Share of the ${n} this run used`,valueText:`${t} of your ${n}; now at ${N7.format(e.now)}%`,tone:e.now>=80?`waiting`:`accent`})]},e.key)})]})}function Obe({projectId:e,revisionId:t,title:n,open:r,onClose:i}){let{api:a}=z(),o=_(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=Oy(),g=(0,m.useRef)(!1),v=(0,m.useRef)(null);(0,m.useEffect)(()=>{r&&t!==null&&(c({revisionId:t,name:n}),f(null)),r||c(null)},[r,t,n]);async function y(){if(!s||g.current||!s.name.trim())return;g.current=!0,u(!0),f(null);let t=JSON.stringify([e,s.revisionId,s.name.trim()]);v.current?.key!==t&&(v.current={key:t,id:crypto.randomUUID()});try{let t=await qq(a,e,{id:v.current.id,name:s.name.trim(),revisionId:s.revisionId});if(!t.ok){v.current=null,f(t.message);return}v.current=null,i(),p(`Template saved.`,`success`),await o.invalidateQueries({queryKey:Lq})}catch(e){f(e instanceof Error?e.message:`The template wasn't saved. Press Save template to try again.`)}finally{g.current=!1,u(!1)}}return(0,h.jsx)(Ay,{open:r&&s!==null,onOpenChange:e=>{!e&&!g.current&&i()},title:`Save as template`,description:`Save this revision’s setup for a fresh Play draft. This does not rebuild the project.`,children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,required:!0,maxLength:200,disabled:l,value:s?.name??``,onChange:e=>{let t=e.target.value;c(e=>e&&{...e,name:t})}})}),d?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:d}):null,(0,h.jsxs)(`div`,{className:`sl-dialog__foot`,children:[(0,h.jsx)(R,{disabled:l,onClick:i,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:l||!s?.name.trim(),children:`Save template`})]})]})})}var P7=q({baseRevisionId:W().min(1).max(64),idempotencyKey:wD()}).strict(),kbe=rO(`kind`,[q({kind:pO(`resume`)}).strict(),q({kind:pO(`retry`),stage:J(FS)}).strict(),q({kind:pO(`rerun`),stage:J(FS)}).strict(),q({kind:pO(`redo`),item:W().min(1).max(200)}).strict()]);P7.extend({action:kbe}).strict();var Abe=rO(`ok`,[q({ok:pO(!0),value:K0.and(q({warnings:K(W()).readonly()}))}),q({ok:pO(!1),reason:J([`no-project`,`no-revision`,`conflict`,`idempotency-conflict`,`invalid-edit`,`stale-preview`,`invalid-selection`,`review-required`,`cost-ack-required`,`readiness`,`running`,`accepted-job`,`control-changed`]),fields:K(q({field:W(),message:W()})).readonly().optional(),intentRevisionId:W().optional(),currentRevisionId:W().nullable().optional()})]),F7=new Set([400,404,409]);async function jbe(e,t,n){return L7(e,t,`cancel`,n)}async function Mbe(e,t,n){return L7(e,t,`pause`,n)}function Nbe(e,t,n){return R7(e,t,`resume`,n)}function Pbe(e,t,n,r){return R7(e,t,`stages/${n}/retry`,r)}function Fbe(e,t,n,r){return R7(e,t,`stages/${n}/soften`,r)}function Ibe(e,t,n,r){return R7(e,t,`stages/${n}/rerun`,r)}async function Lbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/providers`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function Rbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/subtitles`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function zbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/article`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({markdown:n})}))}async function Bbe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].$delete({param:{id:t,outputId:n}}))}async function Vbe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].regenerate.$post({param:{id:t,outputId:n}}))}async function I7(e){if(e.ok)return{ok:!0,value:await e.json()};let t=await mo(e);if(t!==void 0&&F7.has(e.status))return{ok:!1,message:po(e,t).message};throw po(e,t)}async function L7(e,t,n,r){let i=P7.parse(r);return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}))}async function R7(e,t,n,r){let i=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(P7.parse(r))});if(i.ok){let e=Abe.parse(await i.json());if(!e.ok)throw Error(xo);return{ok:!0,value:e.value,warnings:e.value.warnings}}let a=await mo(i);if(a!==void 0&&F7.has(i.status))return{ok:!1,message:po(i,a).message};throw po(i,a)}function Hbe(e){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(),s=(0,m.useRef)(new Map),c=(0,m.useRef)(!1),l=P({mutationFn:async e=>{let r=e.action;if(![`pause`,`cancel`,`resume`,`retry`,`soften`,`rerun`].includes(r.kind))return B7(t,e.projectId,r);let i=r.kind===`retry`||r.kind===`soften`||r.kind===`rerun`?r.stage:``,a=`${e.projectId}:${r.kind}:${i}`,o=s.current.get(a);if(!o){let r=n.getQueryData(B.project(e.projectId))?.revisionId;if(!r){let n=await r2(t,e.projectId);if(!n.ok)return{ok:!1,message:n.message};r=n.value.view.revision.id}o={baseRevisionId:r,idempotencyKey:crypto.randomUUID()},s.current.set(a,o)}let c=await B7(t,e.projectId,r,o);return s.current.delete(a),c.ok&&await jo(t,e.projectId).then(t=>n.setQueryData(B.project(e.projectId),t),e=>console.warn(`Project refresh after an accepted action failed`,e)),c},onMutate:()=>{i(void 0),o(void 0)},onSuccess:async(e,t)=>{e.ok?(o(`warnings`in e&&e.warnings.length>0?e.warnings.join(` `):void 0),n.invalidateQueries({queryKey:B.projects})):i({message:e.message,stage:z7(t.action)}),await n.invalidateQueries({queryKey:B.project(t.projectId)})},onSettled:()=>{c.current=!1},onError:(e,t)=>{i({message:e.message,stage:z7(t.action)})}});return{run:(t,n)=>{c.current||(c.current=!0,l.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok&&n?.()}}))},pending:l.isPending,performing:l.isPending?l.variables?.action:void 0,refusal:r,dismissRefusal:()=>{i(void 0)},notice:a}}function z7(e){switch(e.kind){case`cancel`:case`pause`:case`resume`:case`providers`:return;case`retry`:case`soften`:case`rerun`:return e.stage;case`subtitles`:return`video`;case`save-article`:return`article`;case`delete-image`:case`regenerate-image`:return`images`}}function B7(e,t,n,r){let i=()=>{if(!r)throw Error(`A saved revision and request identity are required.`);return r};switch(n.kind){case`pause`:return Mbe(e,t,i());case`cancel`:return jbe(e,t,i());case`resume`:return Nbe(e,t,i());case`retry`:return Pbe(e,t,n.stage,i());case`soften`:return Fbe(e,t,n.stage,i());case`rerun`:return Ibe(e,t,n.stage,i());case`providers`:return Lbe(e,t,n.choices);case`subtitles`:return Rbe(e,t,n.subtitles);case`save-article`:return zbe(e,t,n.markdown);case`delete-image`:return Bbe(e,t,n.outputId);case`regenerate-image`:return Vbe(e,t,n.outputId)}}var V7=e=>e.state===`done`||e.state===`provided`;function Ube(e){let t=e.find(e=>e.state===`failed`)??e.find(e=>e.state===`running`);if(t)return t.kind;let n=e.find(e=>e.kind===`video`&&V7(e));if(n)return n.kind;let r=e.find(e=>e.state===`pending`);return r?r.kind:e.find(e=>e.kind===`article`&&V7(e))?.kind??e.find(e=>e.state!==`skipped`)?.kind??`article`}function Wbe({projectId:e,openDraft:t}){return(0,h.jsx)(Gbe,{projectId:e,openDraft:t},e)}var H7=e=>{let t=e.filter(e=>e!==void 0);if(!(t.length===0||t.every(e=>e.state===`skipped`)))return t.some(e=>e.state===`failed`&&e.retryAt===void 0)?`failed`:t.some(e=>e.state===`running`)?`running`:t.some(e=>e.state===`failed`)?`waiting`:t.every(e=>e.state===`done`||e.state===`provided`||e.state===`skipped`)?`done`:`off`};function Gbe({projectId:e,openDraft:t}){let{api:n}=z(),r=Oy(),i=Jbe(e,t),a=N(Xy(n,e)),o=N(nb(n)),s=N(Zy(n,e)),c=Hbe(e),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),y=a.data?.revisionId??null,b=hbe(e,y,{onOpenEdit:()=>u(`settings`)}),x=uI(e),S=(0,m.useRef)(void 0);(0,m.useEffect)(()=>{if(x===void 0){S.current=void 0;return}a.data!==void 0&&S.current!==x&&(S.current=x,x===`download`&&u(rF(a.data.project.config)===`article`?`article`:`video`))},[x,a.data]),N3(e,y);let C=N({queryKey:Ny,queryFn:()=>Vy(n)}),w=Hy(C.data,e),T=N({queryKey:f3(e,y??``),queryFn:()=>m3(n,e),enabled:y!==null,retry:!1}),E=T.data?.ok===!0?T.data.value.checkpoints:[],D=b.saved.data?.outputs.filter(e=>e.selected&&e.state===`outdated`).map(e=>({workKey:e.workKey,role:e.output.role}))??[],O=a.data?.project,k=a.data?.stages??[],A=a.data?.outputs??[],ee=A.some(e=>e.role===`video`),te=e=>u(e),ne=J_e({project:O??Kbe,stages:k,resumable:a.data?.resumable??!1,sample:w,gates:E,outdated:D,waits:s.data?.waits??[],uploadReady:ee,actions:c,controller:b,openSection:te,openUpload:()=>f(!0)}),j=l===`settings`,re=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!j){re.current=!1;return}b.edit!==void 0&&(re.current=!0),!(re.current||b.busy)&&(re.current=!0,b.openEditor())},[j,b]);let M=k.some(e=>e.state===`running`),ie=O?.status===`running`,ae=O?.title??``,oe=ne.next?.action;bx({id:`project.next`,title:oe?.label??`Show the project's next action`,group:`This project`,context:ae,keywords:[`next`,`continue`,`resume`,`approve`,`retry`],shortcut:lP.nextAction,run:()=>{oe===void 0?r(`This project has no next action right now: nothing waits on you.`,`info`):oe.intent.kind===`soften`?r(`Soften and retry asks first: press it in the Next action panel on the right.`):ne.run(oe.intent)}}),Yx(Wx.showImages(e),()=>{let e=a.data?.stages.find(e=>e.kind===`images`);e===void 0||e.state===`skipped`?r(`${ae} makes no slideshow images, so there is no image to regenerate. To add them, open Settings in this project and choose how its images are made.`,`error`):u(`images`)},a.data!==void 0),bx({id:`project.pause`,title:O?.status===`paused`?`Continue the run`:`Pause the run`,group:`This project`,context:ae,keywords:[`pause`,`resume`,`continue`,`stop`],run:()=>c.run({kind:O?.status===`paused`?`resume`:`pause`})}),bx({id:`project.prepare-upload`,title:`Prepare upload`,group:`This project`,context:ae,keywords:[`youtube`,`studio`,`upload`,`publish`],run:()=>{ee?f(!0):r(`Prepare upload opens once the video has been made.`,`info`)}}),bx({id:`project.settings`,title:`Edit project settings`,group:`This project`,context:ae,keywords:[`edit`,`settings`,`prompts`,`providers`,`channel`],run:()=>u(`settings`)}),bx({id:`project.rebuild-review`,title:`Choose what to remake`,group:`This project`,context:ae,keywords:[`rebuild`,`review`,`remake`,`outdated`,`affected`],run:()=>b.review({kind:`allAffected`})}),bx({id:`project.template`,title:`Save as template`,group:`This project`,context:ae,keywords:[`template`,`reuse`],run:()=>g(!0)}),bx({id:`project.cancel`,title:`Cancel the run`,group:`This project`,context:ae,keywords:[`cancel`,`stop`],run:()=>v(!0)});let se=K_e(D);if(bx({id:`project.remake-1`,title:se[0]?.label??`Remake outdated outputs`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`],run:()=>{let e=se[0];e===void 0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0})}}),bx({id:`project.remake-all`,title:`Remake everything outdated`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`,`all`],run:()=>{let e=[...new Set(se.flatMap(e=>e.workKeys))];e.length===0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e},{autoStart:!0})}}),bx({id:`project.copy`,title:`Make my own copy`,group:`This project`,context:ae,keywords:[`sample`,`copy`,`duplicate`],run:()=>w?ne.run({kind:`copy-sample`}):r(`Only the sample project is copied this way.`,`info`)}),a.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The project could not be loaded.`,children:`${a.error.message} Reload the page to try again, or go back to Projects.`});if(a.data===void 0||O===void 0)return(0,h.jsx)(qbe,{});let ce=e=>k.find(t=>t.kind===e),le=ce(`article`),ue=ce(`research`),de=ce(`audio`),fe=ce(`images`),pe=ce(`thumbnail`),me=ce(`video`),he=ce(`document`),ge=O.config,_e=e=>e!==void 0&&e.state!==`skipped`,ve=ge.shorts?.enabled===!0||A.some(e=>e.role===`short_video`||e.role===`shorts`),ye=ge.youtubeDescription===!0||A.some(e=>e.role===`youtube_description`),be=E.filter(e=>e.state===`held`||e.state===`pending-review`),xe=[..._e(le)||_e(ue)?[{id:`article`,label:`Article`,tone:H7([le,ue])}]:[],..._e(de)?[{id:`narration`,label:`Narration`,tone:H7([de])}]:[],..._e(fe)||_e(pe)||ge.reference!==void 0?[{id:`images`,label:`Images`,tone:H7([fe,pe])}]:[],..._e(me)?[{id:`video`,label:rF(ge)===`audio`?`Audio export`:`Video`,tone:H7([me])}]:[],...ve?[{id:`shorts`,label:`Shorts`}]:[],...ye?[{id:`youtube`,label:`YouTube`}]:[],..._e(he)?[{id:`document`,label:`PDF`,tone:H7([he])}]:[],{id:`cost`,label:`Cost`},{id:`live`,label:`Live`}].map(e=>{let t=se.filter(t=>t.section===e.id).reduce((e,t)=>e+t.count,0);return t===0?e:{...e,meta:`${String(t)} outdated`}}),Se=[{id:`settings`,label:`Settings`,...b.unsaved?{meta:`unsaved`}:{}},...y===null?[]:[{id:`checkpoints`,label:`Checkpoints`,...be.length===0?{}:{meta:`${String(be.length)} held`}}],{id:`history`,label:`History`}],Ce=[...xe,...Se],we=ne.next?.situation,Te=ne.next?.section!==void 0&&we!==`done`&&we!==`running`?ne.next.section:we===`done`&&A.some(e=>e.role===`youtube_description`)?`youtube`:n5(Ube(k)),Ee=l!==void 0&&Ce.some(e=>e.id===l)?l:Ce.find(e=>e.id===Te)?.id??xe[0]?.id??`cost`,De=(...e)=>y===null?O.status===`running`||O.status===`paused`||M||c.pending:c.pending||e.some(e=>e?.state===`running`),Oe={project:O,outputs:A,actions:c,next:ne,resumable:a.data.resumable},ke=(e,t)=>e===void 0?null:(0,h.jsx)(Bve,{stage:e,...t===void 0||t.state===`skipped`?{}:{companion:t},project:O,outputs:A,actions:c,busy:De(e,t)}),Ae=(...e)=>A.some(t=>e.some(e=>e!==void 0&&t.stageKind===e.kind)),je=(...e)=>Ae(...e)||e.some(e=>e!==void 0&&[`running`,`done`,`provided`,`failed`,`canceled`].includes(e.state)),Me=[{id:`rebuild`,label:`Choose what to remake…`,run:()=>b.review({kind:`allAffected`}),disabled:b.busy},{id:`template`,label:`Save as template…`,run:()=>g(!0),disabled:y===null||w},{id:`cancel`,label:`Cancel the run…`,run:()=>v(!0),disabled:!ie||c.pending,apart:!0}],Ne=t5({kind:`cancel`}),Pe=c.refusal?.stage===void 0?c.refusal:void 0,Fe=Pe===void 0?c.notice===void 0?b.preview===void 0&&(b.error||b.refusal)&&Ee!==`settings`&&Ee!==`history`?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:b.error??b.refusal?.message}):void 0:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:c.notice}):(0,h.jsx)(SI,{tone:`danger`,title:Pe.message,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,className:`mt-1`,onClick:c.dismissRefusal,children:`Dismiss`})}),Ie=wbe({stages:k,outputs:A,project:O,resumable:a.data.resumable,held:be.map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),now:Date.now()});return(0,h.jsx)(t_e,{projectId:e,revisionId:y,children:(0,h.jsx)(J8,{value:y!==null,children:(0,h.jsx)(g3,{value:e=>u(e===`edit`?`settings`:`article`),children:(0,h.jsx)(Y8,{value:b.pending||b.preview!==void 0?void 0:b.requestEdit,children:(0,h.jsxs)(X8,{value:b.pending||b.preview!==void 0?void 0:b.regenerateNow,children:[(0,h.jsxs)(`div`,{className:`sl-project`,children:[(0,h.jsx)(`div`,{"data-tour":`project-controls`,children:(0,h.jsx)(Zve,{project:O,prompts:o.data?.prompts,editing:Ee===`settings`,onEdit:()=>u(`settings`),more:Me,nextChapter:i,clock:(0,h.jsx)(iye,{cost:s.data,status:O.status,measuredAt:s.dataUpdatedAt})})}),(0,h.jsx)(Tbe,{stages:k}),(0,h.jsxs)(Aq,{sections:(0,h.jsxs)(e8,{label:`Project sections`,children:[xe.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:te},e.id)),(0,h.jsx)(`hr`,{className:`sl-rule my-2`}),Se.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:te},e.id))]}),aside:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(X_e,{state:ne,feedback:Fe}),O===void 0?null:(0,h.jsx)(Xve,{projectId:e,title:O.title,status:O.status,sample:w||C.isPending}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-6 max-[1180px]:hidden`,children:[(0,h.jsx)(Ebe,{steps:Ie}),(0,h.jsx)(Dbe,{cost:s.data,onOpen:()=>te(`cost`)}),(0,h.jsx)(Pge,{})]})]}),children:[(0,h.jsx)(u5,{id:`article`,title:`Article`,stages:[le,ue].filter(U7),active:Ee===`article`,...Oe,children:_e(le)||_e(ue)?ke(le,ue):(0,h.jsx)(d5,{stage:le,project:O,name:`Article`})}),(0,h.jsx)(u5,{id:`narration`,title:`Narration`,stages:[de].filter(U7),active:Ee===`narration`,...Oe,children:je(de)?ke(de):(0,h.jsx)(d5,{stage:de,project:O,name:`Narration`})}),(0,h.jsx)(u5,{id:`images`,title:`Images`,head:!1,stages:[fe,pe].filter(U7),active:Ee===`images`,...Oe,children:ke(fe,pe)}),(0,h.jsx)(u5,{id:`video`,title:rF(ge)===`audio`?`Audio export`:`Video`,stages:[me].filter(U7),active:Ee===`video`,...Oe,children:ke(me)}),me===void 0?null:(0,h.jsx)(u5,{id:`shorts`,title:`Shorts`,stages:[],active:Ee===`shorts`,...Oe,meta:`Vertical clips picked from the video, each with its title and hashtags`,children:(0,h.jsx)(jve,{stage:me,project:O,outputs:A})}),me===void 0?null:(0,h.jsx)(u5,{id:`youtube`,title:`YouTube`,stages:[],active:Ee===`youtube`,...Oe,meta:`The description, chapters, hashtags and tags, as they go into YouTube Studio`,...ee&&ne.next?.action?.intent.kind!==`prepare-upload`?{extra:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>f(!0),children:`Prepare upload`})}:{},children:(0,h.jsx)(Vve,{stage:me,project:O,outputs:A})}),he===void 0?null:(0,h.jsx)(u5,{id:`document`,title:`PDF`,stages:[he],active:Ee===`document`,...Oe,children:je(he)?ke(he):(0,h.jsx)(d5,{stage:he,project:O,name:`PDF`})}),(0,h.jsx)(G7,{id:`cost`,title:`Run cost`,selected:Ee,children:(0,h.jsx)(nye,{projectId:e})}),(0,h.jsx)(G7,{id:`live`,title:`Live`,selected:Ee,children:Ee===`live`?(0,h.jsx)(pye,{project:O,revisionId:y,stages:k,outputs:A}):null}),(0,h.jsx)(G7,{id:`settings`,title:`Settings`,selected:Ee,children:(0,h.jsx)(_be,{controller:b,active:Ee===`settings`,renderEditor:e=>(0,h.jsx)(rbe,{...e,renderContent:e=>(0,h.jsx)(zye,{...e},e.view.revision.id)})})}),y===null?null:(0,h.jsx)(G7,{id:`checkpoints`,title:`Checkpoints`,selected:Ee,children:(0,h.jsx)(Kve,{projectId:e,revisionId:y,paused:O.status===`paused`,stages:k,approvedInRail:ne.next?.action?.intent.kind===`approve`?ne.next.action.intent.gate.checkpointId:void 0})}),(0,h.jsx)(G7,{id:`history`,title:`History`,selected:Ee,children:(0,h.jsx)(vbe,{controller:b,projectId:e,active:Ee===`history`})})]})]}),(0,h.jsx)(ybe,{controller:b}),d?(0,h.jsx)(v2,{projectId:e,onClose:()=>f(!1)}):null,(0,h.jsx)(Obe,{projectId:e,revisionId:y,title:O.title,open:p,onClose:()=>g(!1)}),(0,h.jsx)(jy,{open:_,title:Ne.title,consequence:Ne.consequence,confirmLabel:Ne.verb,cancelLabel:Ne.dismiss,pending:c.pending,onConfirm:()=>{v(!1),c.run({kind:`cancel`})},onCancel:()=>v(!1)})]})})})})})}var U7=e=>e!==void 0;function W7({item:e,selected:t,onSelect:n}){return(0,h.jsx)(t8,{className:`max-md:w-auto`,"data-tour":`project-rail-${e.id}`,current:e.id===t,onClick:()=>n(e.id),...e.tone===void 0?{}:{icon:(0,h.jsx)(gS,{tone:e.tone})},...e.meta===void 0?{}:{meta:e.meta},children:e.label})}function G7({id:e,title:t,selected:n,children:r}){return(0,h.jsxs)(`section`,{hidden:n!==e,"aria-label":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:t}),r]})}var Kbe={id:``,title:``,format:`16:9`,status:`pending`,createdAt:``,config:{sources:{}}};function qbe(){return(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading project`,children:[(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-8 w-80 max-w-full rounded-control bg-sunken`})]}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(`div`,{className:`flex flex-col gap-2`,children:[`a`,`b`,`c`,`d`,`e`].map(e=>(0,h.jsx)(`span`,{className:`h-8 rounded-control bg-sunken`},e))}),aside:(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`}),children:(0,h.jsx)(`span`,{className:`h-[480px] rounded-control bg-sunken`})})]})}function Jbe(e,t){let{api:n}=z(),r=(0,m.useRef)(void 0),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0);if(t!==void 0)return{pending:i,error:o,run:()=>{i||(r.current??=crypto.randomUUID(),a(!0),s(void 0),Yq(n,e,r.current).then(async e=>{if(!e.ok){s(e.message);return}await t(e.value.draft.id)?r.current=void 0:s(`The next chapter's draft was made, but Play could not open it because the draft open there is not saved yet. Open Play, let it save, then press Make the next chapter again.`)}).catch(e=>s(`The next chapter could not be made (${e instanceof Error?e.message:`the connection dropped`}). Press Make the next chapter again.`)).finally(()=>a(!1)))}}}var Ybe=[`all`,`running`,`queued`,`waiting`,`ready`,`failed`];function Xbe(e){return Ybe.find(t=>t===e)}var K7=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`queued`,label:`Queued`},{value:`waiting`,label:`Needs you`},{value:`ready`,label:`Ready to upload`},{value:`failed`,label:`Failed`}];function q7(e,t){switch(t){case`all`:return!0;case`running`:return e.status===`running`||e.status===`paused`;case`queued`:return w3(e);case`waiting`:return y3(e);case`ready`:return C3(e);case`failed`:return e.status===`failed`||e.status===`partial`}}function Zbe(e){let t={running:{tone:`running`,word:`Running`},paused:{tone:`waiting`,word:`Paused`},pending:{tone:`off`,word:`Queued`},failed:{tone:`failed`,word:`Failed`},partial:{tone:`info`,word:`Done with problems`},done:{tone:`done`,word:`Done`},canceled:{tone:`off`,word:`Canceled`}};if(y3(e))return{tone:`waiting`,word:`Waiting for you`};let n=e.status===`running`?YH(e.limitWaits):void 0;return n===void 0?t[e.status]:{tone:`waiting`,word:n}}function Qbe(e){let t=e.config.articlePrompt,n=e.config.voices?.book;return[n===void 0?void 0:LA(n),t===void 0||t===``?void 0:t,e.format].filter(e=>e!==void 0).join(` · `)}function $be({initialFilter:e=`all`}={}){let{api:t}=z(),n=_(),r=Oy(),i=gx(),a=N(Yy(t)),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(e),u=N({queryKey:My,queryFn:()=>Iy(t)}),d=new Set(Object.values(u.data?.samples??{}).filter(e=>e!==null)),[f,p]=(0,m.useState)(``),g=(0,m.useRef)(null),v=xx(g,`projects`),y=P({mutationFn:e=>No(t,e),onSettled:async()=>{s(void 0),await n.invalidateQueries({queryKey:B.projects})}}),b=P({mutationFn:e=>S3(t,e.project.id,e.uploaded),onError:(e,t)=>r(`${t.project.title} wasn't changed: ${e.message} Press the button again.`,`error`),onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});bx({id:`projects.show.waiting`,title:`Show projects that need you`,group:`Projects`,keywords:[`waiting`,`filter`],run:()=>l(`waiting`)}),bx({id:`projects.show.ready`,title:`Show videos ready to upload`,group:`Projects`,keywords:[`upload`,`finished`,`filter`],run:()=>l(`ready`)}),bx({id:`projects.show.failed`,title:`Show failed projects`,group:`Projects`,keywords:[`error`,`filter`],run:()=>l(`failed`)});let x=(a.data?.projects??[]).filter(e=>i.includes(e.channelId)),S=f.trim().toLowerCase(),C=x.filter(e=>q7(e,c)&&(S===``||e.title.toLowerCase().includes(S)));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Projects`,meta:a.data===void 0?void 0:`${String(x.length)} ${x.length===1?`project`:`projects`} · ${i.channel?.name??`every channel`}`,actions:(0,h.jsxs)(fS,{to:`/play`,variant:`primary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]})}),a.data?.projects.length===0?(0,h.jsx)(jB,{}):null,a.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-4 text-danger`,children:a.error.message}),a.data===void 0?a.error===null?(0,h.jsx)(txe,{}):null:a.data.projects.length===0?(0,h.jsx)(a0,{title:`No projects yet`,actions:(0,h.jsx)(fS,{to:`/play`,variant:`primary`,children:`Make your first video`}),children:`Set up a run on Play: pick a template, type a topic and start.`}):(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsxs)(t0,{label:`Project list`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`div`,{className:`relative w-full max-w-[320px]`,children:[(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{type:`search`,ref:g,"aria-label":`Search projects`,"aria-keyshortcuts":Mx(v),placeholder:`Search projects`,value:f,onChange:e=>p(e.target.value),className:`sl-input pl-9`})]}),(0,h.jsx)(Ab,{label:`Show`,value:c,options:K7,onChange:l,className:`max-w-full overflow-x-auto`})]}),C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:x.length===0?`No projects in ${i.channel?.name??`this channel`} yet. Pick All channels in the rail to see the others.`:`No project matches. Clear the search or pick All.`}):(0,h.jsx)(pU,{label:`Projects`,children:C.map(e=>(0,h.jsx)(exe,{project:e,sample:d.has(e.id),onDelete:()=>s(e),onUploaded:t=>b.mutate({project:e,uploaded:t}),busy:b.isPending},e.id))})]}),(0,h.jsxs)(t0,{as:`aside`,label:`Projects at a glance`,children:[(0,h.jsxs)(`section`,{children:[(0,h.jsx)(H,{title:`At a glance`}),(0,h.jsx)(G2,{children:K7.filter(e=>e.value!==`all`).map(e=>(0,h.jsx)(K2,{label:e.label,value:String(x.filter(t=>q7(t,e.value)).length)},e.value))})]}),(0,h.jsxs)(`section`,{"aria-label":`Video queue`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Video queue`,info:`play.queue`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Videos started together, in the order they run, are on the calendar.`}),(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/calendar`,children:`Open calendar`})})]})]})]}),y.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`mt-3 text-small text-danger`,children:y.error.message}),(0,h.jsx)(jy,{open:o!==void 0,title:o===void 0?``:`Delete "${o.title}"?`,consequence:`Moves the project to the trash for 30 days. Restore it or delete it for good in Settings → Trash.`,confirmLabel:`Delete project`,cancelLabel:`Keep it`,pending:y.isPending,onConfirm:()=>{o!==void 0&&y.mutate(o.id)},onCancel:()=>s(void 0)})]})}function exe({project:e,sample:t,onDelete:n,onUploaded:r,busy:i}){let a=Zbe(e),o=e.status===`running`;return(0,h.jsx)(mU,{title:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),t?(0,h.jsx)(vS,{children:`Sample`}):null]}),meta:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:`${Qbe(e)} · started ${ku(e.createdAt)}`}),o?(0,h.jsx)(q2,{value:e.progress,label:`${e.title} progress`,valueText:`${String(Math.round(e.progress*100))}% done`,className:`max-w-[240px]`}):null]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:a.tone,children:[a.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`${e.title}: ${a.word}`})]}),C3(e)?(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!0),children:`Mark uploaded`}):null,C3(e)?(0,h.jsx)(V,{id:`project.mark-uploaded`}):e.uploadedAt===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(vS,{children:`Uploaded`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Mark ${e.title} not uploaded`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!1),children:`Undo`})]}),(0,h.jsx)(wy,{label:`Delete ${e.title}`,size:`small`,disabled:o,disabledReason:`Cancel the run first, then delete it.`,onClick:n,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function txe(){return(0,h.jsx)(`ul`,{"aria-label":`Loading projects`,className:`sl-list m-0 list-none p-0`,children:[0,1,2,3,4,5].map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,"data-slot":`skeleton-row`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-2/5 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[10px] w-1/4 rounded-control bg-sunken`})]}),(0,h.jsx)(`span`,{className:`h-[10px] w-16 rounded-control bg-sunken`})]},e))})}var nxe=`Prepare restrained delivery cues for a documentary narrator. Let the facts carry the scene. Use a measured pace and make only occasional changes where the supplied wording clearly calls for emphasis, reflection or tension. Prefer no cue to an unnecessary cue. Avoid theatrical emotion, invented reactions and routine laughter or sighs. Never rewrite, summarize, translate or add spoken words. Return only the cue annotations required by the supplied format contract.`;function J7({promptId:e,kind:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=lI(),s=N(nb(i)),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=oP(JSON.stringify(e===void 0?[`new`,t,n??null]:[`prompt`,e])),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(void 0),b=v!==void 0,[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),T=s.data?.prompts,E=e??n,D=E===void 0?void 0:T?.find(e=>e.id===E),O=D===void 0?{kind:t,name:``,body:``}:e===void 0?{kind:D.kind,name:`${D.name} copy`,body:D.body}:{kind:D.kind,name:D.name,body:D.body},k=d??v??O,A=P({mutationFn:t=>xs(i,t,e),onSuccess:async(e,t)=>{if(!e.ok){g(e.fields);return}y(e.value),f(e=>e===t?void 0:e),o({type:`prompt-saved`,id:e.value.id,kind:e.value.kind}),await a.invalidateQueries({queryKey:nb(i).queryKey})}}),ee=P({mutationFn:e=>Cs(i,e),onSuccess:async()=>{S(!1),f(void 0),await a.invalidateQueries({queryKey:nb(i).queryKey}),r(k.kind)}}),te=P({mutationFn:({id:e,on:t})=>Ss(i,e,t),onSettled:async()=>{await a.invalidateQueries({queryKey:nb(i).queryKey})}});X2(b,()=>{r(k.kind)});let ne=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},j=t3(k,p),re=n3(j),M=a3(k.body),ie=k.body.trim()===``?[]:r3(j),ae=k.name.trim()===``?[]:i3(j);return cI({promptNamed:k.name.trim()!==``&&ae.length===0,promptBodyReady:k.body.trim()!==``&&ie.length===0,promptHasKeywords:M.length>0&&ie.length===0,promptSaveReady:re===void 0&&!A.isPending&&!b,promptSaving:A.isPending||b,promptIsArticle:k.kind===`article`,promptIsImage:k.kind===`image`}),s.error===null?E!==void 0&&T===void 0?(0,h.jsx)($2,{}):E!==void 0&&D===void 0?(0,h.jsx)(X7,{kind:t,children:`That prompt is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:k.kind},children:`Prompts`})}),title:e===void 0?`New prompt`:`Edit prompt`,meta:`${_V(k.kind)} prompt`}),(0,h.jsxs)(`div`,{"data-tour":`prompt-editor`,className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{"data-tour":`prompt-name`,className:`min-w-[min(100%,240px)] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.prompt.name`,...ae.length===0?{}:{error:ae.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:k.name,onChange:e=>{ne({...k,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Kind`,value:k.kind,options:gV,tip:`library.prompt.kind`,onPick:e=>{ne({...k,kind:e},`name`)}})]}),(0,h.jsxs)(`div`,{"data-tour":`prompt-body`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex min-h-8 items-end justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:rxe[k.kind],label:`${_V(k.kind)} prompt body`,className:`-my-1`})]}),Y7(k.kind)?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=Y7(k.kind);e!==void 0&&(k.body.trim()===``?ne({...k,body:e.body},`body`):w(!0))},children:Y7(k.kind)?.label}),(0,h.jsx)(V,{id:`library.prompt.starter`,label:Y7(k.kind)?.label})]}):null]}),(0,h.jsx)(s3,{id:c,value:k.body,invalid:ie.length>0,describedBy:ie.length===0?void 0:l,onChange:e=>{ne({...k,body:e},`body`)}})]}),k.kind===`image`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e!==void 0&&D?.kind===`image`?(0,h.jsx)(kb,{checked:te.isPending?te.variables.on:D.photorealistic===!0,disabled:te.isPending,onChange:t=>te.mutate({id:e,on:t}),label:`Draws photorealistic pictures`,tip:`library.prompt.photorealistic`}):(0,h.jsxs)(`span`,{className:`flex items-center gap-1 text-small text-ink-2`,children:[`Save this Image prompt first, then choose whether it draws photorealistic pictures.`,(0,h.jsx)(V,{id:`library.prompt.photorealistic`})]}),te.error===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small text-danger`,children:`Couldn't change Draws photorealistic pictures: ${te.error.message} Press the switch again.`})]}):null,(0,h.jsx)(`div`,{"data-tour":`prompt-save`,children:(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{S(!0)},blocked:re,blockedId:u,pending:A.isPending,saved:b,cancel:(0,h.jsx)(fS,{to:`/prompts`,search:{kind:k.kind},onClick:()=>{f(void 0)},variant:`secondary`,children:`Cancel`}),errors:[A.error,ee.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{A.mutate(k)}})})]}),(0,h.jsx)(`div`,{"data-tour":`prompt-slots`,className:m4,children:(0,h.jsx)(Y4,{slots:M,body:k.body,lint:ie,lintId:l})})]}),(0,h.jsx)(jy,{open:C,title:`Replace this prompt body?`,consequence:`The starter replaces the text in this editor. Nothing is saved until you choose Save.`,confirmLabel:`Use starter`,tone:`primary`,onConfirm:()=>{let e=Y7(k.kind);e!==void 0&&ne({...k,body:e.body},`body`),w(!1)},onCancel:()=>w(!1)}),(0,h.jsx)(jy,{open:x,title:`Delete "${k.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:ee.isPending,onConfirm:()=>{e!==void 0&&ee.mutate(e)},onCancel:()=>{S(!1)}})]}):(0,h.jsx)(X7,{kind:k.kind,children:s.error.message})}var rxe={article:`library.prompt.body.article`,image:`library.prompt.body.image`,thumbnail:`library.prompt.body.thumbnail`,narration:`library.prompt.body.narration`,description:`library.prompt.body.description`,shorts:`library.prompt.body.shorts`,review:`library.prompt.body.review`,script:`library.prompt.body.script`};function Y7(e){if(e===`narration`)return{label:`Use Documentary Starter`,body:nxe};if(e===`description`)return{label:`Use Built-in Starter`,body:She};if(e===`shorts`)return{label:`Use Built-in Starter`,body:Gk}}function X7({kind:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:e},children:`Back to Prompts`}),children:t})}function ixe({kind:e,onKind:t,onUseInPlay:n,playBlocked:r}){let{api:i}=z(),a=_(),o=N(nb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=xx(l,`prompts`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=P({mutationFn:e=>Cs(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:B.prompts})}}),x=async(e,t)=>{let n=await xs(i,{kind:e.kind,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:B.prompts}),n.ok?null:q4(n.fields)},S=o.data?.prompts.filter(t=>t.kind===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B4,{action:(0,h.jsx)(oxe,{kind:e}),children:[(0,h.jsx)(CV,{type:`search`,ref:l,"aria-label":`Search prompts`,"aria-keyshortcuts":Mx(u),placeholder:`Search prompts`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsx)(TV,{"aria-label":`Prompt kind`,value:e,className:`w-full sm:w-56`,options:gV,onChange:e=>{let n=gV.find(t=>t.value===e.target.value);n!==void 0&&t(n.value)}}),(0,h.jsx)(V,{id:`library.prompt.kind`})]})]}),o.error===null?null:(0,h.jsx)(R4,{what:`prompts`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(L4,{label:`Prompts`}):null:S.length===0?(0,h.jsxs)(a0,{title:`No ${_V(e).toLowerCase()} prompts yet`,children:[`A prompt is text with `,`{{keywords}}`,`; each keyword becomes a field on Play.`]}):(0,h.jsx)(jq,{className:F4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${_V(e).toLowerCase()} prompts match "${s.trim()}".`}):(0,h.jsx)(pU,{label:`Prompts`,children:w.map(e=>(0,h.jsx)(mU,{className:I4,title:(0,h.jsx)(J4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:axe(e),selected:e.id===T?.id,actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e.kind,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(M4,{item:`prompt`,id:T.id,name:T.name,kicker:`${_V(T.kind)} prompt`,meta:`Updated ${P4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:T.id},size:`small`,children:`Edit prompt`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The prompt wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(O4,{item:`prompt`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(jy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function axe(e){return`${_V(e.kind)} · ${N4(e.slots.length,`keyword`)} · updated ${P4(e.updatedAt)}`}function oxe({kind:e}){return(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e},variant:`primary`,children:`New prompt`})}var sxe={template:`Template`,schedule:`Schedule`,draft:`Draft`,project:`Project`};function Z7(e){let t=[e.added.length>0?`${e.added.length} new`:null,e.priced.length>0?`${e.priced.length} repriced`:null,e.retired.length>0?`${e.retired.length} retired`:null].filter(e=>e!==null);return t.length===0?`No changes`:t.join(`, `)}function cxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:H1.catalogue,queryFn:()=>cde(e),refetchInterval:3e4}),i=N({queryKey:H1.retired,queryFn:()=>G1(e)}),a=async()=>{await Promise.all([t.invalidateQueries({queryKey:[`provider-models`]}),t.invalidateQueries({queryKey:H1.retired})])},o=P({mutationFn:()=>lde(e),onSuccess:async e=>{t.setQueryData(H1.catalogue,e),n(e.sync?.warning??`Model list checked: ${Z7(e.sync?.changes??lxe)}.`,e.sync?.warning?`error`:`success`),await a()}}),s=P({mutationFn:()=>ude(e),onSuccess:async e=>{n(`Catalogue replaced with the published file.`,`success`),t.setQueryData(H1.catalogue,e),await a()}}),c=async()=>{await Promise.all([t.invalidateQueries({queryKey:H1.retired}),t.invalidateQueries({queryKey:Lq}),t.invalidateQueries({queryKey:TH}),t.invalidateQueries({queryKey:[`play-drafts`]}),t.invalidateQueries({queryKey:[`projects`]}),t.invalidateQueries({queryKey:[`project`]})])},l=P({mutationFn:t=>K1(e,t),onSuccess:c}),u=P({mutationFn:()=>dde(e),onSuccess:async e=>{n(e.failed.length===0?`Switched ${e.switched} ${e.switched===1?`use`:`uses`}.`:`Switched ${e.switched}; ${e.failed.length} could not be switched: ${e.failed[0]?.message??``}`,e.failed.length===0?`success`:`error`),await c()}}),d=r.data?.sync,f=i.data??[],p=f.filter(e=>e.blocked===null&&e.replacement!==null),m=o.error?.message??s.error?.message??r.error?.message??r.data?.warning??d?.warning??null;return bx({id:`settings.check-models`,title:`Check for new models`,group:`Settings`,context:`Models`,keywords:[`catalogue`,`prices`,`retired`],run:()=>{!o.isPending&&r.data?.path&&o.mutate()}}),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Model catalogue`,info:`settings.models.catalogue`,children:[(0,h.jsx)(R,{disabled:o.isPending||!r.data?.path,onClick:()=>o.mutate(),children:o.isPending?`Checking…`:`Check now`}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:s.isPending||!r.data?.path,onClick:()=>s.mutate(),children:s.isPending?`Replacing…`:`Replace with published file`}),(0,h.jsx)(V,{id:`settings.models.replace`})]})]}),(0,h.jsxs)(`dl`,{className:`m-0 grid gap-x-6 border-t border-line text-small sm:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Catalogue file`}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 border-b border-line pb-3 break-all font-mono text-ink-2 sm:pt-3`,children:r.data?.path??`Not available`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Verified`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:r.data?.updatedAt??`date unavailable`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Last checked`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:d?.checkedAt?`${new Date(d.checkedAt).toLocaleString()} · ${Z7(d.changes)}`:`Not checked yet`})]}),d!==void 0&&d.changes.retired.length+d.changes.added.length>0?(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1 text-small text-ink-2`,children:[d.changes.added.length>0?(0,h.jsxs)(`span`,{children:[`New: `,d.changes.added.map(e=>e.name).join(`, `)]}):null,d.changes.retired.length>0?(0,h.jsxs)(`span`,{children:[`Retired: `,d.changes.retired.map(e=>e.name).join(`, `)]}):null]}):null,m===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-3 text-body text-danger`,children:m})]}),(0,h.jsxs)(`section`,{"aria-label":`Retired models in use`,children:[(0,h.jsx)(H,{title:`Retired models in use`,info:`settings.models.retired`,children:(0,h.jsx)(R,{variant:`primary`,disabled:u.isPending||p.length===0,onClick:()=>u.mutate(),children:u.isPending?`Switching…`:`Switch all`})}),i.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:i.error.message}):null,l.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:l.error.message}):null,f.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i.isPending?`Looking…`:`Nothing uses a retired model.`}):(0,h.jsx)(`ul`,{"aria-label":`Retired models in use`,className:`sl-list m-0 list-none p-0`,children:f.map(e=>(0,h.jsxs)(`li`,{className:`sl-row max-sm:grid-cols-1`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:sxe[e.kind]}),` `,(0,h.jsx)(`span`,{className:`font-semibold`,children:e.name})]}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s0[e.slot],`: `,e.model,` (`,e.why===`retired`?`retired`:`no longer listed`,`)`]}),e.blocked===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e.blocked})]}),(0,h.jsx)(Ey,{children:(0,h.jsx)(R,{size:`small`,disabled:e.blocked!==null||e.replacement===null||l.isPending,onClick:()=>l.mutate(e),children:e.replacement===null?`No replacement`:`Switch to ${e.replacement.name}`})})]},e.key))})]})]})}var lxe={added:[],retired:[],priced:[]},uxe={ok:`Ready`,warning:`Check`,problem:`Needs fixing`,unused:`Not set up`},dxe={ok:`done`,warning:`waiting`,problem:`failed`,unused:`off`},fxe={ok:`text-ink-2`,warning:`text-waiting`,problem:`text-danger`,skipped:`text-ink-3`};function Q7(){let{api:e}=z();return P({mutationFn:()=>W1(e)})}function pxe(e){let{api:t}=z(),[n,r]=(0,m.useState)({byId:new Map});return{one:P({mutationFn:e=>W1(t,e),onSuccess:t=>{r(n=>{let r=new Map(n.after===e?n.byId:[]);for(let e of t.providers)r.set(e.id,e);return{after:e,byId:r}})}}),latest:t=>n.after===e?n.byId.get(t.id)??t:t}}function mxe({run:e}={}){let t=Q7(),n=e??t,r=n.data,i=pxe(r?.checkedAt),a=r?.providers.filter(e=>e.state!==`unused`).map(i.latest)??[],o=r?.providers.filter(e=>e.state===`unused`)??[];return(0,h.jsxs)(`section`,{"aria-label":`Health check`,children:[(0,h.jsx)(H,{title:`Health check`,info:`settings.health`,children:e===void 0?(0,h.jsx)(R,{disabled:n.isPending,onClick:()=>{n.mutate()},children:n.isPending?`Checking…`:`Check all`}):void 0}),n.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:[`The health check didn't finish: `,n.error.message,` Press Check all to try again.`]}),i.one.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:`The check didn't finish: ${i.one.error.message} Press Check again on the provider to try again.`}),r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:n.isPending?`Checking every provider…`:`Not checked yet.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ul`,{"aria-label":`Health by provider`,className:`sl-list m-0 list-none p-0`,children:a.map(e=>(0,h.jsxs)(`li`,{className:`sl-row grid-cols-1 gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:e.displayName}),(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(_S,{tone:dxe[e.state],children:uxe[e.state]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Check ${e.displayName} again`,disabled:i.one.isPending,onClick:()=>{i.one.mutate(e.id)},children:i.one.isPending&&i.one.variables===e.id?`Checking…`:`Check again`})]})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-1 p-0`,children:e.checks.map(e=>(0,h.jsxs)(`li`,{className:L(`text-small`,fxe[e.state]),children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.label,`:`]}),` `,e.detail]},e.label))})]},e.id))}),(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:o.length===0?`Checked at ${new Date(r.checkedAt).toLocaleTimeString()}.`:`Not set up and not used anywhere: ${o.map(e=>e.displayName).join(`, `)}.`})]})]})}var $7={openrouter:`settings.provider.openrouter`,"claude-code":`settings.provider.claude-code`,codex:`settings.provider.codex`,gemini:`settings.provider.gemini`,elevenlabs:`settings.provider.elevenlabs`,"openai-tts":`settings.provider.openai-tts`,cartesia:`settings.provider.cartesia`,inworld:`settings.provider.inworld`,"system-voice":`settings.provider.system-voice`,"google-tts":`settings.provider.google-tts`,fal:`settings.provider.fal`,replicate:`settings.provider.replicate`,"openai-image":`settings.provider.openai-image`,"google-image":`settings.provider.google-image`,"codex-image":`settings.provider.codex-image`};function e9(e){return tF(e)?{tone:`done`,word:`Ready`}:e.installed?{tone:`waiting`,word:`Needs attention`}:{tone:`off`,word:`Not found`}}function hxe({provider:e,readiness:t,kind:n}){let{api:r}=z(),i=_(),a=(0,m.useId)(),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(!1),u=e.cliPath?.configured??null,d=e.cliPath?.managedOnHost===!0,f=e.id===`claude-code`?`claude`:e.id===`codex-image`?`codex`:e.id,p=e.cliPath?.command??f,g=o??u??``,v=tF(t),y=P({mutationFn:t=>Yo(r,e.id,t),onMutate:()=>l(!1),onSuccess:async e=>{i.setQueryData(B.providers,t=>t?{...t,providers:t.providers.map(t=>t.id===e.id?e:t)}:void 0),s(void 0),l(!0),await i.invalidateQueries({queryKey:B.providers})}});(0,m.useEffect)(()=>{if(!c)return;let e=setTimeout(()=>l(!1),Y2);return()=>clearTimeout(e)},[c]);let[b,x]=(0,m.useState)(!1),S=(0,m.useId)();return(0,h.jsxs)(`section`,{"aria-labelledby":a,"data-ready":v,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:a,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:$7[e.id],label:e.displayName})]}),(0,h.jsxs)(`p`,{className:`sl-section-head__meta`,children:[n,` · command line, no key needed`]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:e9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:gxe(t,u)})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Command`}),(0,h.jsx)(EV,{className:`min-w-0 truncate`,title:p,children:p})]})]}),(0,h.jsxs)(Ey,{children:[d?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-small text-ink-2`,children:[`Managed on host`,(0,h.jsx)(V,{id:`settings.cli.managed-on-host`})]}):(0,h.jsx)(R,{"aria-expanded":b,"aria-controls":S,onClick:()=>x(e=>!e),children:b?`Close path`:`Change path`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:c?(0,h.jsx)(Z2,{}):null})]}),d||!b?null:(0,h.jsx)(`form`,{id:S,onSubmit:e=>{e.preventDefault(),y.isPending||y.mutate(g)},children:(0,h.jsx)(xV,{label:`Executable path`,tip:`settings.cli.path`,help:(0,h.jsxs)(h.Fragment,{children:[`Leave blank to find `,(0,h.jsx)(EV,{children:f}),` on PATH. Use an absolute path without quotes or arguments.`]}),error:y.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{autoComplete:`off`,spellCheck:!1,maxLength:4096,"aria-label":`${e.displayName} Executable path`,className:`min-w-0 flex-1 basis-[220px]`,placeholder:f,value:g,disabled:y.isPending,onChange:e=>{s(e.target.value),l(!1),y.reset()}}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,"aria-label":`Save ${e.displayName} path`,disabled:y.isPending,children:y.isPending?`Checking…`:`Save path`})]})})})]})}function gxe(e,t){return e.issue===void 0?e.installed?e.version===void 0?`Installed`:`Installed, version ${e.version}`:t===null?`Not found on PATH`:`Not found at saved path`:e.issue}var _xe=[`providers`,`system-voice`,`voices`];async function vxe(e){return F(await e.fetch(`${e.origin}/api/providers/system-voice/voices`))}function t9(e=!0){let{api:t}=z();return N({queryKey:_xe,queryFn:()=>vxe(t),enabled:e})}function n9(e){return e.available?{tone:`done`,word:`Ready`}:{tone:`off`,word:`Not found`}}function yxe({provider:e,readiness:t}){let n=(0,m.useId)(),r=t9(t.available).data?.engines??[];return(0,h.jsxs)(`section`,{"aria-labelledby":n,"data-ready":t.available,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:n,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:$7[e.id],label:e.displayName})]}),(0,h.jsx)(`p`,{className:`sl-section-head__meta`,children:`Speech · built into this computer, no key needed`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:n9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:t.available?`Found ${t.engine??`a speech program`}. Narration with it is free; a keyed voice (ElevenLabs, OpenAI) sounds better.`:t.issue??`No speech program was found on this computer.`})]}),r.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 list-none p-0 text-small text-ink-2`,children:r.map(e=>{let t=e.voices.length;return(0,h.jsx)(`li`,{children:`${e.name}: ${t} voice${t===1?``:`s`}`},e.id)})}),t.available?(0,h.jsx)(Ey,{children:(0,h.jsx)(fS,{to:`/settings`,search:{section:`voices`},children:`Add a system voice`})}):null]})}function bxe({value:e,onPick:t}){let n=t9(),r=n.data?.engines??[];return n.data!==void 0&&r.length===0?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:n.data.issue??`No speech program was found on this computer.`}):(0,h.jsxs)(TV,{value:e,onChange:e=>{for(let n of r){let r=n.voices.find(t=>t.id===e.target.value);if(r!==void 0)return t(r)}},children:[(0,h.jsx)(`option`,{value:``,children:n.data===void 0?`Looking for voices…`:`Pick a voice`}),r.map(e=>(0,h.jsx)(`optgroup`,{label:e.name,children:e.voices.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.language===void 0?e.name:`${e.name} (${e.language})`},e.id))},e.id))]})}var r9=[`llm`,`tts`,`image`],i9={llm:`Text`,tts:`Speech`,image:`Images`},xxe=`••••••••••••`;function Sxe(e){return tF(e.readiness)}function Cxe(e){return e.readiness.kind===`cli`?e9(e.readiness):e.readiness.kind===`local`?n9(e.readiness):e.readiness.hasKey?{tone:`done`,word:`Key saved`}:{tone:`off`,word:`No key`}}function wxe(){let{api:e}=z(),t=N(eb(e)),[n,r]=(0,m.useState)(void 0),i=(0,m.useRef)(null),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{n!==void 0&&a.current&&(a.current=!1,typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&i.current?.scrollIntoView?.({block:`start`,behavior:`smooth`}))},[n]);let o=r9.flatMap(e=>(t.data?.providers??[]).filter(t=>t.family===e)),s=o.find(e=>!Sxe(e))??o[0];if(n===void 0&&s!==void 0&&r(s.id),t.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message});if(t.data===void 0)return(0,h.jsx)(Exe,{});let c=o.find(e=>e.id===n)??s,l=o.every(e=>e.readiness.kind!==`keyed`||!e.readiness.hasKey),u=e=>{a.current=!0,r(e)};return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:[l?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Paste a key to make its provider selectable on Play.`}):null,r9.map(e=>(0,h.jsxs)(`section`,{"data-tour":`keys-${e}`,"aria-labelledby":`keys-${e}-title`,className:`grid items-start gap-x-8 gap-y-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{id:`keys-${e}-title`,title:i9[e],size:`small`,className:`pb-2`}),(0,h.jsx)(pU,{label:`${i9[e]} providers`,children:o.filter(t=>t.family===e).map(e=>{let t=Cxe(e);return(0,h.jsx)(mU,{title:e.displayName,meta:e.readiness.kind===`cli`?`Command line`:e.readiness.kind===`local`?`Built in, no key`:`API key`,selected:e.id===c?.id,onSelect:()=>u(e.id),actions:(0,h.jsx)(_S,{tone:t.tone,children:t.word})},e.id)})})]}),c===void 0||c.family!==e?null:(0,h.jsx)(`div`,{ref:i,className:`min-w-0 scroll-mt-4`,children:c.readiness.kind===`cli`?(0,h.jsx)(hxe,{provider:c,readiness:c.readiness,kind:i9[c.family]},c.id):c.readiness.kind===`local`?(0,h.jsx)(yxe,{provider:c,readiness:c.readiness},c.id):(0,h.jsx)(Txe,{provider:c,hasKey:c.readiness.hasKey},c.id)})]},e))]})}function Txe({provider:e,hasKey:t}){let{api:n}=z(),r=_(),i=(0,m.useId)(),a=(0,m.useId)(),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(void 0),C=(0,m.useId)(),w=VF[e.id],T=o.trim(),E=async()=>{b(!0),S(void 0);try{S(await sde(n,e.id,T===``?void 0:T))}catch(e){p(e instanceof Error?e.message:String(e))}finally{b(!1)}},D=async()=>{l(!0),p(void 0);try{await Jo(n,e.id,o),s(``),d(!0),S(void 0),await r.invalidateQueries({queryKey:B.providers})}catch(e){p(e instanceof Error?e.message:String(e))}finally{l(!1)}},O=P({mutationFn:()=>Xo(n,e.id),onSuccess:async()=>{v(!1),p(void 0),await r.invalidateQueries({queryKey:B.providers})},onError:e=>{v(!1),p(e.message)}});(0,m.useEffect)(()=>{if(!u)return;let e=setTimeout(()=>{d(!1)},Y2);return()=>{clearTimeout(e)}},[u]);let k=[t?a:void 0,x===void 0?void 0:C].filter(e=>e!==void 0).join(` `);return(0,h.jsxs)(`section`,{"aria-labelledby":i,"data-ready":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{as:`h3`,size:`default`,id:i,title:t?e.displayName:`Set up ${e.displayName}`,info:$7[e.id],infoLabel:e.displayName,meta:`${i9[e.family]} · ${t?`a key is saved`:`needs an API key`}`,className:`pb-0`}),w===void 0?null:t?(0,h.jsxs)(`details`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Where to get a key`}),(0,h.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:(0,h.jsx)(a9,{guide:w})})]}):(0,h.jsx)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:(0,h.jsx)(a9,{guide:w})}),(0,h.jsx)(xV,{label:`${e.displayName} API key`,tip:`settings.providers.api-key`,help:`Stored on this computer only. Never in backups or exports.`,error:f,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`password`,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 basis-[200px]`,"aria-describedby":k===``?void 0:k,placeholder:t?xxe:`Paste API key`,value:o,onChange:e=>{s(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,"aria-label":`Save ${e.displayName} key`,disabled:o.trim()===``||c,onClick:()=>{D()},children:`Save`})]})}),t?(0,h.jsx)(`span`,{id:a,className:`sr-only`,children:`A key is stored for this provider.`}):null,x===void 0?null:(0,h.jsx)(`p`,{id:C,role:x.ok?`status`:`alert`,className:L(`m-0 text-small`,x.ok?`text-accent-ink`:`text-danger`),children:x.message}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{"aria-label":`Test ${e.displayName} key`,disabled:!t&&T===``||y,disabledReason:`Paste a key first.`,onClick:()=>{E()},children:y?`Testing…`:`Test`}),(0,h.jsx)(V,{id:`settings.providers.test-key`,label:`Test`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Remove ${e.displayName} key`,disabled:!t,onClick:()=>{v(!0)},children:`Remove`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:u?(0,h.jsx)(Z2,{}):null})]}),(0,h.jsx)(jy,{open:g,title:`Remove the ${e.displayName} key?`,consequence:`Projects that used this provider cannot retry until a key is saved.`,confirmLabel:`Remove key`,pending:O.isPending,onConfirm:()=>{O.mutate()},onCancel:()=>{v(!1)}})]})}function a9({guide:e}){let t=(e,t)=>(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`underline`,children:t});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ol`,{className:`m-0 list-decimal space-y-1 pl-5`,children:e.steps.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`Sign up: `,t(e.signUp.url,e.signUp.label),`. Make the key:`,` `,t(e.keyPage.url,e.keyPage.label),`.`,e.billing===void 0?null:(0,h.jsxs)(h.Fragment,{children:[` Credit: `,t(e.billing.url,e.billing.label),`.`]})]}),(0,h.jsx)(`p`,{className:`m-0`,children:e.permissions}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`More in the provider's `,t(e.docs.url,e.docs.label),`. After saving, choose Test.`]})]})}function Exe(){return(0,h.jsxs)(`div`,{className:`grid items-start gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,role:`status`,"aria-label":`Loading providers`,children:[(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:[[`llm`,4],[`tts`,5],[`image`,5]].map(([e,t])=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`span`,{className:`mb-2 block h-3 w-16 rounded-control bg-raised`}),(0,h.jsx)(`div`,{className:`sl-list`,children:Array.from({length:t},(t,n)=>`${e}-${n}`).map(e=>(0,h.jsxs)(`div`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`h-4 w-32 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-4 w-20 rounded-control bg-raised`})]},e))})]},e))}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-6 w-48 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-10 rounded-control bg-raised`})]})]})}function o9(e){return e.split(/[\s,;]+/).map(e=>e.trim().toLowerCase()).filter(e=>e!==``)}function Dxe(e){return e.languages===void 0?`Any (not known)`:e.languages.map(e=>BO(e).code===e?BO(e).name:e).join(`, `)}function Oxe({voice:e}){let{api:t}=z(),n=_(),r=(0,m.useId)(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)((e.languages??[]).join(`, `)),[c,l]=(0,m.useState)(void 0),u=P({mutationFn:()=>hs(t,e.id,o9(o)),onSuccess:async e=>{if(e!==void 0){l(e.message);return}a(!1),l(void 0),await n.invalidateQueries({queryKey:B.voices})}});return i?(0,h.jsxs)(`div`,{className:`grid gap-1`,children:[(0,h.jsx)(CV,{id:r,"aria-label":`Languages of ${e.name}`,value:o,placeholder:`es, de`,"aria-invalid":c!==void 0,onChange:e=>{s(e.target.value),l(void 0)}}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:c}),u.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:u.error.message}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(R,{size:`small`,disabled:u.isPending,onClick:()=>u.mutate(),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{a(!1),l(void 0),s((e.languages??[]).join(`, `))},children:`Cancel`})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:Dxe(e)}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit the languages of ${e.name}`,onClick:()=>a(!0),children:`Edit`})]})}function kxe(){let{api:e}=z(),t=_(),n=N(tb(e)),r=N(eb(e)),[i,a]=(0,m.useState)(void 0),o=P({mutationFn:t=>_s(e,t),onSettled:async()=>{a(void 0),await t.invalidateQueries({queryKey:B.voices})}}),s=P({mutationFn:({id:t,on:n})=>gs(e,t,n),onSettled:async()=>{await t.invalidateQueries({queryKey:B.voices})}}),c=(r.data?.providers??[]).filter(e=>e.family===`tts`);if(n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});let l=n.data?.voices;return(0,h.jsxs)(`div`,{"data-tour":`voices`,className:`flex min-w-0 flex-col gap-10`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 overflow-x-auto`,children:[(0,h.jsxs)(`table`,{className:`sl-table min-w-[640px] table-fixed`,...Ob,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Voices`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:`Name`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[18%] pr-4`,children:`Provider`}),(0,h.jsx)(`th`,{scope:`col`,className:`pr-4`,children:`Voice ID`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Languages`,(0,h.jsx)(V,{id:`play.voices.languages`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[20%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Real person`,(0,h.jsx)(V,{id:`play.voices.real-person`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[96px]`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:l===void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,children:(0,h.jsx)(`span`,{className:`block h-4 w-64 rounded-control bg-raised`})})}):l.length===0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,className:`text-ink-2`,children:`Add a voice ID from your text-to-speech provider. Audio needs one to narrate.`})}):l.map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`truncate pr-4 font-semibold`,children:e.name}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:jxe(c,e.provider)}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:e.voiceId}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(Oxe,{voice:e})}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(kb,{checked:s.isPending&&s.variables.id===e.id?s.variables.on:e.imitatesRealPerson===!0,disabled:s.isPending,onChange:t=>s.mutate({id:e.id,on:t}),label:(0,h.jsx)(`span`,{className:`sr-only`,children:`${e.name} imitates a real person`}),className:`text-small`})}),(0,h.jsx)(`td`,{className:`text-right`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name}`,onClick:()=>{a(e)},children:`Remove`})})]},e.id))})]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:`Couldn't change Real person: ${s.error.message} Press the switch again.`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:o.error.message})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Add a voice`}),(0,h.jsx)(Axe,{tts:c})]}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Remove ${i.name}?`,consequence:`Projects that used this voice keep the audio they made with it.`,confirmLabel:`Remove voice`,pending:o.isPending,onConfirm:()=>{i!==void 0&&o.mutate(i.id)},onCancel:()=>{a(void 0)}})]})}function Axe({tts:e}){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(void 0),[d,f]=(0,m.useState)(void 0),p=l??e[0]?.id,g=P({mutationFn:e=>ms(t,e),onSuccess:async e=>{if(!e.ok){f(e.refusal);return}i(``),o(``),c(``),f(void 0),await n.invalidateQueries({queryKey:B.voices})}}),v=(e,t)=>{t(),d?.field===e&&f(void 0)},y=e=>d?.field===e?d.message:void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`grid items-start gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(xV,{label:`Voice name`,tip:`play.voices.name`,error:y(`name`),children:(0,h.jsx)(CV,{value:r,onChange:e=>{let t=e.target.value;v(`name`,()=>{i(t)})}})}),(0,h.jsx)(xV,{label:`Provider`,tip:`play.voices.provider`,error:y(`provider`),children:(0,h.jsxs)(TV,{value:p??``,onChange:t=>{let n=e.find(e=>e.id===t.target.value);n!==void 0&&v(`provider`,()=>{u(n.id)})},children:[e.length===0?(0,h.jsx)(`option`,{value:``,children:`No speech provider`}):null,e.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.displayName},e.id))]})}),(0,h.jsx)(xV,{label:`Voice ID`,tip:`play.voices.voice-id`,error:y(`voiceId`),...p===`inworld`?{help:`Use an Inworld voice ID, such as Dennis, or one from your workspace.`}:{},children:p===`system-voice`?(0,h.jsx)(bxe,{value:a,onPick:e=>{v(`voiceId`,()=>{o(e.id)}),r.trim()===``&&i(e.name);let t=/^([a-z]{2,3})(?:[-_]|$)/i.exec(e.language??``)?.[1];s.trim()===``&&t!==void 0&&c(t.toLowerCase())}}):p===`google-tts`?(0,h.jsx)(TV,{value:a,options:[{value:``,label:`Pick a Gemini voice`},...UF.map(e=>({value:e.name,label:`${e.name} (${e.style})`}))],onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t),r.trim()===``&&i(t)})}}):(0,h.jsx)(CV,{className:`tabular-nums`,value:a,onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t)})}})}),(0,h.jsx)(xV,{label:`Languages`,tip:`play.voices.languages`,help:`Codes such as es, de.`,error:y(`languages`),children:(0,h.jsx)(CV,{value:s,placeholder:`es, de`,onChange:e=>{let t=e.target.value;v(`languages`,()=>{c(t)})}})}),(0,h.jsx)(R,{variant:`primary`,className:`md:mt-6`,disabled:p===void 0||d!==void 0||g.isPending,onClick:()=>{if(p!==void 0){let e=o9(s);g.mutate({provider:p,name:r,voiceId:a,...e.length===0?{}:{languages:e}})}},children:`Add voice`})]}),g.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:g.error.message})]})}function jxe(e,t){return e.find(e=>e.id===t)?.displayName??t}var s9=[`settings`,`notifications`],Mxe=`The test notification couldn't be shown: this browser only allows notifications from installed apps. Set a Notification URL below instead.`;function Nxe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Browser and phone`,info:`settings.notifications`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(Pxe,{}),(0,h.jsx)(Fxe,{}),(0,h.jsx)(Ixe,{})]})]})}function Pxe(){let e=(0,m.useSyncExternalStore)(vP,gP,()=>!1),[t,n]=(0,m.useState)(hP),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=Oy(),c=e&&t===`granted`;async function l(e){if(i(void 0),!e){_P(!1);return}o(!0);try{let e=await xP();n(e);let t=bP(e);e===`granted`?(_P(!0),gP()||i(`Browser notifications couldn't be turned on because this browser blocks site storage for Slopify. Allow site data for this address in your browser's settings, then turn Browser notifications on again.`)):i(t??`Browser notifications weren't turned on because the permission prompt was dismissed. Turn Browser notifications on again and choose Allow.`)}finally{o(!1)}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Browser notifications`,tip:`settings.notifications.browser`,checked:c,disabled:a,onChange:e=>void l(e)}),(0,h.jsx)(R,{variant:`quiet`,disabled:!c,disabledReason:`Turn Browser notifications on first.`,onClick:()=>{i(void 0);try{CP({projectId:`test`,text:UP},()=>{}),s(`Test notification sent to this browser.`,`success`)}catch{i(Mxe)}},children:`Send test notification`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Works while any Slopify tab is open.`}),r===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:r})]})}function Fxe(){let e=(0,m.useSyncExternalStore)(AP,OP,()=>!0);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Run sounds`,tip:`settings.notifications.sounds`,checked:e,onChange:kP}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`start`),children:`Play start`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`end`),children:`Play end`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`A chime when a run starts and a different one when it finishes, fails or waits for you. Works while any Slopify tab is open; set your computer's volume for how loud.`})]})}function Ixe(){let{api:e}=z(),t=_(),n=Oy(),r=(0,m.useId)(),i=N({queryKey:s9,queryFn:()=>$o(e)}),[a,o]=(0,m.useState)(void 0),s=a??i.data?.url??``,c=GP(s),l=P({mutationFn:t=>ts(e,t),onSuccess:e=>{t.setQueryData(s9,e),o(void 0),n(e.url===null?`Notification URL removed.`:`Notification URL saved.`,`success`)}}),u=P({mutationFn:t=>ns(e,t),onSuccess:()=>{n(`Test notification sent. Check the app or page behind your Notification URL.`,`success`)}}),d=c??l.error?.message??u.error?.message,f=l.isPending||u.isPending||i.data===void 0;return(0,h.jsxs)(xV,{label:`Notification URL`,tip:`settings.notifications.url`,help:`Works with no tab open, for example an ntfy topic on your phone.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`url`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:`https://ntfy.sh/your-topic`,className:`min-w-0 flex-1 basis-[220px]`,value:s,disabled:i.data===void 0,"aria-invalid":c!==void 0,"aria-describedby":d===void 0?void 0:r,onChange:e=>{l.reset(),u.reset(),o(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,disabled:f||c!==void 0||a===void 0,onClick:()=>l.mutate(s),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,disabled:f||c!==void 0||s.trim()===``,onClick:()=>u.mutate(s),children:`Send test notification`})]}),i.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The saved Notification URL couldn't be read: `,i.error.message]}),d===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:d})]})}var c9={library:`The Library of Alexandria`,audiobook:`The Wind in the Willows (audiobook)`,podcast:`The Antikythera Mechanism (podcast)`};function Lxe(){let{api:e}=z(),t=_(),n=N({queryKey:Ny,queryFn:()=>Vy(e)}),r=P({mutationFn:()=>Uy(e),onSettled:async()=>{await t.invalidateQueries({queryKey:Ny}),await t.invalidateQueries({queryKey:My}),await t.invalidateQueries({queryKey:B.projects})}}),i=r.data?.samples??n.data?.samples;return(0,h.jsxs)(`div`,{className:`mt-8`,children:[(0,h.jsx)(H,{title:`Sample projects`,info:`settings.sample.restore`}),(0,h.jsx)(pU,{label:`Sample projects`,children:Object.keys(c9).map(e=>{let t=i?.[e]??null;return(0,h.jsx)(mU,{title:c9[e],meta:t===null?`Not in your projects`:`In your projects`,actions:t===null?void 0:(0,h.jsx)(pS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:`Open`})},e)})}),(0,h.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{disabled:r.isPending,onClick:()=>r.mutate(),children:r.isPending?`Restoring…`:`Restore samples`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Puts all three back as they shipped.`})]}),(0,h.jsx)(Q1,{tone:r.error?`error`:`success`,children:r.error?.message??(r.isSuccess?`The samples are back in Projects.`:void 0)})]})}var Rxe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function zxe(e){let[t,n,r]=e.split(`-`).map(Number),i=Rxe[(n??0)-1];return i===void 0||r===void 0?e:`${String(r)} ${i} ${String(t)}`}function l9(e,t){let n=[e.range===void 0?e.version:`Versions ${e.range}`,`released ${zxe(e.date)}`].filter(e=>e!==void 0).join(`, `),r=n.charAt(0).toUpperCase()+n.slice(1);return e.version===t?`${r}. The version you are running.`:`${r}.`}function Bxe({note:e,onNote:t}){let{api:n}=z(),r=N(fI(n));if(r.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The patch notes did not load`,actions:(0,h.jsx)(R,{onClick:()=>void r.refetch(),children:`Try again`}),children:`${r.error.message} Press Try again, or reload the page.`});if(r.data===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the patch notes…`});let{notes:i,version:a}=r.data,[o,...s]=i;if(o===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:`This version of Slopify has no patch notes.`});let c=e===void 0?void 0:i.find(t=>t.id===e),l=c!==void 0&&c.id!==o.id?c:void 0;return l===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e!==void 0&&c===void 0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`There are no patch notes called "${e}" in this version. The latest are below; older ones are under Earlier versions.`}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:`Latest version`,meta:l9(o,a),info:`settings.patch-notes`}),(0,h.jsx)(wB,{id:o.id})]}),s.length===0?null:(0,h.jsxs)(`details`,{className:`max-w-prose border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`Earlier versions (${String(s.length)})`}),(0,h.jsx)(pU,{label:`Earlier versions`,className:`mt-2`,children:s.map(e=>(0,h.jsx)(mU,{title:e.title,meta:l9(e,a),onSelect:()=>t(e.id),actions:(0,h.jsx)(R,{"aria-label":`Read ${e.title}`,onClick:()=>t(e.id),children:`Read`})},e.id))})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{children:(0,h.jsxs)(R,{variant:`quiet`,onClick:()=>t(void 0),children:[(0,h.jsx)(nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Back to the latest patch notes`]})}),(0,h.jsx)(H,{title:`Earlier version`,meta:l9(l,a)}),(0,h.jsx)(wB,{id:l.id})]})}var u9=[`trash`];async function Vxe(e){return(await F(await e.client.trash.$get())).items}async function Hxe(e,t,n){return(await F(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function Uxe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await fo(r)}var Wxe={project:`Project`,prompt:`Prompt`,entry:`Intro/outro`,template:`Template`,schedule:`Schedule`};function Gxe(e){return e.kind===`entry`&&e.detail!==null?e.detail===`intro`?`Intro`:`Outro`:e.kind===`prompt`&&e.detail!==null?`Prompt · ${e.detail}`:Wxe[e.kind]}function Kxe(e){return e<=0?`removed for good today`:e===1?`1 day left`:`${String(e)} days left`}var qxe=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}),Jxe={project:[B.projects,[`calendar`]],prompt:[B.prompts],entry:[B.entries],template:[Lq],schedule:[TH,[`calendar`]]};function Yxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:u9,queryFn:()=>Vxe(e)}),[i,a]=(0,m.useState)(void 0),o=async e=>{await Promise.all([u9,...Jxe[e.kind]].map(e=>t.invalidateQueries({queryKey:e})))},s=P({mutationFn:t=>Hxe(e,t.kind,t.id),onSuccess:async(e,t)=>{await o(t),n(e.renamedFrom===null?`Restored "${e.name}".`:`Restored as "${e.name}": another item is now called "${e.renamedFrom}".`,`success`),e.kind===`schedule`&&n(`The schedule is paused. Press Resume on Schedules to run it again.`,`info`)},onError:e=>n(e.message,`error`)}),c=P({mutationFn:t=>Uxe(e,t.kind,t.id),onSuccess:async(e,t)=>{a(void 0),await o(t),n(`Deleted "${t.name}" for good.`,`success`)},onError:e=>{a(void 0),n(e.message,`error`)}}),l=r.data??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Trash`,info:`settings.trash`}),r.isPending?(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the trash…`}):r.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:r.error.message}):l.length===0?(0,h.jsx)(a0,{title:`The trash is empty`,children:`Anything you delete stays here for 30 days before it is removed for good.`}):(0,h.jsx)(pU,{label:`Deleted items`,children:l.map(e=>(0,h.jsx)(mU,{title:e.name,meta:`${Gxe(e)} · deleted ${qxe.format(new Date(e.deletedAt))} · ${Kxe(e.daysLeft)}`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>s.mutate(e),children:`Restore`}),(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>a(e),children:`Delete now`})]})},`${e.kind}:${e.id}`))}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Delete "${i.name}" for good?`,consequence:i?.kind===`project`?`The project and every file it produced are removed from disk. This cannot be undone.`:i?.kind===`schedule`?`The schedule leaves the trash and cannot be restored. Its run history stays on Schedules.`:`It is removed for good. This cannot be undone.`,confirmLabel:`Delete for good`,cancelLabel:`Keep it`,pending:c.isPending,onConfirm:()=>{i!==void 0&&c.mutate(i)},onCancel:()=>{c.isPending||a(void 0)}})]})}var Xxe=`https://github.com/GentBajko/slopify`,Zxe=`https://www.patreon.com/cw/GentBajko`,Qxe=`https://buymeacoffee.com/gentbajko`;function $xe(){return[{href:Xxe,label:`GitHub`,detail:`The code, issues and releases.`,glyph:`github`},{href:Zxe,label:`Patreon`,detail:`Monthly support for the project.`,glyph:`patreon`},{href:Qxe,label:`Buy Me a Coffee`,detail:`A one-off thank you.`,glyph:`coffee`},{href:`https://slopify.stream/channel.html`,label:`How I run a channel with it`,detail:`A lore channel run on Slopify, start to finish.`}]}function eSe({onWhatsNew:e}){return(0,h.jsxs)(`div`,{className:`max-w-prose`,children:[(0,h.jsx)(H,{title:`About`}),(0,h.jsx)(`p`,{className:`m-0 mb-3 text-ink-2`,children:`Slopify is free and open source, and runs on your machine with your own keys. If it saves you time, you can support it here.`}),(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1 text-small text-ink-2`,children:[`Updates: the circular-arrows button at the foot of the sidebar (at the top on a phone).`,(0,h.jsx)(V,{id:`settings.updates`})]}),e===void 0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:e,children:`What's new in this version`}),(0,h.jsx)(V,{id:`settings.whats-new`})]}),(0,h.jsx)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:`Made by Gent Bajko. Apache License 2.0: anyone who redistributes Slopify or builds on it keeps this credit.`}),(0,h.jsx)(`ul`,{"aria-label":`Links`,className:`sl-list m-0 list-none p-0`,children:$xe().map(e=>(0,h.jsx)(`li`,{className:`sl-row`,children:(0,h.jsxs)(`div`,{className:`sl-row__lead`,children:[e.glyph===void 0?(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}):(0,h.jsx)(lS,{name:e.glyph,className:`shrink-0 text-ink-2`}),(0,h.jsxs)(`div`,{className:`sl-row__text`,children:[(0,h.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,className:`font-semibold text-ink underline underline-offset-3`,children:e.label}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.detail})]})]})},e.label))})]})}var d9=[`backups`],f9=1,p9=30;function m9(){return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}function tSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=f9&&Number(t)<=p9?void 0:`Keep between ${f9} and ${p9} backups.`}function nSe(e){return{enabled:e.config.enabled,time:e.config.time,keep:String(e.config.keep),folder:e.config.folder??``}}function h9(){let{api:e}=z(),t=_(),n=Oy();return P({mutationFn:()=>ko(e),onSuccess:e=>{t.setQueryData(d9,e),n(`Backup started. Its result shows here when it finishes.`,`success`)}})}function rSe(){let{api:e}=z(),t=_(),n=N({queryKey:d9,queryFn:()=>Do(e),refetchInterval:e=>e.state.data?.running===!0&&2e3}),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Oo(e,t),onSuccess:e=>{t.setQueryData(d9,e),i(void 0),o(!0)}}),c=h9();(0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Y2);return()=>clearTimeout(e)},[a]);let l=n.data,u=r??(l===void 0?void 0:nSe(l)),d=u===void 0?void 0:tSe(u.keep),f=e=>{u!==void 0&&i({...u,...e})};return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Daily backup`,info:`settings.backups`,children:(0,h.jsx)(R,{variant:`primary`,disabled:l===void 0||l.running||c.isPending,onClick:()=>c.mutate(),children:`Back up now`})}),(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-x-4 gap-y-1 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{role:`status`,children:l===void 0?(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`}):iSe(l)}),(0,h.jsx)(`span`,{children:l===void 0?null:aSe(l)})]}),l?.status.detail?l.status.lastResult===`failed`?(0,h.jsx)(SI,{tone:`danger`,title:`Why the last backup stopped`,children:l.status.detail}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:l.status.detail}):null,c.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:c.error.message}):null]}),n.error?(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The backup settings couldn't be read: `,n.error.message]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(kb,{label:`Back up automatically`,tip:`settings.backups.auto`,checked:u?.enabled===!0,disabled:u===void 0,className:`self-start`,onChange:e=>f({enabled:e})}),(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Time of day`,tip:`settings.backups.time`,help:`${m9()} time`,children:(0,h.jsx)(CV,{type:`time`,className:`w-[140px] tabular-nums`,value:u?.time??`03:00`,disabled:u===void 0,onChange:e=>f({time:e.target.value})})}),(0,h.jsx)(xV,{label:`Keep last`,tip:`settings.backups.keep`,help:`Backups kept in the folder.`,error:d,children:(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:f9,max:p9,step:1,className:`w-[88px] tabular-nums`,value:u?.keep??`5`,disabled:u===void 0,onChange:e=>f({keep:e.target.value})})}),(0,h.jsx)(xV,{label:`Folder`,tip:`settings.backups.folder`,className:`md:col-span-2`,...l===void 0?{}:{help:oSe(l)},children:(0,h.jsx)(CV,{value:u?.folder??``,placeholder:l?.defaultFolder??``,disabled:u===void 0,onChange:e=>f({folder:e.target.value})})})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:u===void 0||d!==void 0||s.isPending,onClick:()=>{u!==void 0&&(o(!1),s.mutate({enabled:u.enabled,time:u.time,timeZone:m9(),keep:Number(u.keep.trim()),folder:u.folder.trim()===``?null:u.folder.trim()}))},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 basis-full text-small text-danger`,children:s.error.message})]})]})]})}function g9(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function iSe(e){if(e.running)return`Backing up now…`;let{status:t}=e,n=t.lastSuccessAt===null?`No backup yet.`:`Last backup ${g9(t.lastSuccessAt)}${t.lastSuccessBytes===null?``:`, ${_9(t.lastSuccessBytes)}`}.`;return t.lastResult===`failed`&&t.lastAttemptAt!==null?`${n} The backup at ${g9(t.lastAttemptAt)} failed.`:t.lastResult===`waiting`?`${n} Waiting for projects to finish.`:n}function aSe(e){return e.config.enabled?e.overdue?`Next: shortly.`:e.nextRunAt===null?``:`Next: ${g9(e.nextRunAt)}.`:`Automatic backups are off.`}function oSe(e){let t=`${e.files.length} backup${e.files.length===1?``:`s`} here (${_9(e.files.reduce((e,t)=>e+t.bytes,0))}).`;return e.hostFolder===null?`Inside Slopify's Docker volume, not on your computer. Leave Folder empty to save backups in the Backups folder on your computer. ${t}`:`${e.config.folder===null?`Empty uses the default: `:`On your computer: `}${e.hostFolder}. ${t}`}function _9(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var v9=[`storage-files`];function sSe({usageQueryKey:e}){let{api:t}=z(),n=_(),r=Oy(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(),u=N({queryKey:v9,queryFn:()=>Io(t),refetchInterval:e=>b9(e.state.data)?1e3:!1}),d=P({mutationFn:e=>Lo(t,e),onMutate:()=>l(void 0),onSuccess:e=>{n.setQueryData(v9,e),a(!1)},onError:e=>l(e.message)}),f=P({mutationFn:()=>Ro(t),onSuccess:e=>{e.opened||r(`Your files are in ${e.path}.`,`info`)},onError:e=>r(e.message,`error`)}),p=u.data,g=b9(p),v=p?.move?.phase;if((0,m.useEffect)(()=>{v===`done`&&n.invalidateQueries({queryKey:e})},[v,n,e]),p===void 0)return(0,h.jsx)(`div`,{children:(0,h.jsx)(H,{title:`Your files`,meta:u.error?`Where your files are is unavailable. Reload the page to try again.`:`Loading…`})});if(p.docker)return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Your files`,meta:p.folder??`The Docker project folder isn't set up.`,info:`settings.files.docker`,children:(0,h.jsx)(R,{disabled:p.folder===null||f.isPending,onClick:()=>f.mutate(),children:`Open folder`})}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),p.dockerCommand===null?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[`To move your projects to Documents/Slopify, run this on the computer running Docker (or use `,(0,h.jsx)(EV,{children:`--projects-dir <folder>`}),` for another folder):`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(EV,{className:`min-w-0 break-all`,children:p.dockerCommand}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=p.dockerCommand??``;navigator.clipboard.writeText(e).then(()=>r(`Command copied.`,`success`)).catch(()=>r(`Copying failed: this browser doesn't allow it here. Select the command and copy it yourself.`,`error`))},children:`Copy command`})]})]})]})]});let y=v===`failed`||v===`interrupted`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Your files`,meta:p.folder,info:`settings.files`,children:[p.inDocuments||p.documentsRoot===null?null:(0,h.jsx)(R,{variant:`primary`,disabled:g||d.isPending,onClick:()=>d.mutate(`documents`),children:`Move to Documents/Slopify`}),(0,h.jsx)(R,{disabled:f.isPending,onClick:()=>f.mutate(),children:`Open folder`}),(0,h.jsx)(R,{variant:`quiet`,disabled:g||d.isPending,onClick:()=>{a(e=>!e),l(void 0)},children:`Choose another folder`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),i?(0,h.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),d.mutate(o)},children:[(0,h.jsx)(xV,{label:`New folder`,tip:`settings.files.new-folder`,help:`The full path; it must be empty or new.`,error:c,className:`min-w-0 flex-1 basis-80`,children:(0,h.jsx)(CV,{value:o,placeholder:p.documentsRoot??`/home/you/Videos/Slopify`,onChange:e=>s(e.target.value)})}),(0,h.jsx)(R,{type:`submit`,disabled:o.trim()===``||d.isPending,children:`Move here`})]}):c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:c}),p.move===null?null:g?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[p.move.phase===`copying`?`Copying`:`Checking the copy of`,` your files to`,` `,p.move.target,`: `,p.move.files,` of `,p.move.totalFiles,` files (`,Y5(p.move.bytes),` of `,Y5(p.move.totalBytes),`). Keep Slopify running until it finishes.`]}),(0,h.jsx)(q2,{label:p.move.phase===`copying`?`Files copied`:`Files checked`,value:p.move.totalBytes===0?0:p.move.bytes/p.move.totalBytes})]}):y?(0,h.jsx)(SI,{tone:v===`failed`?`danger`:`waiting`,title:v===`failed`?`Moving your files to ${p.move.target} stopped`:`Moving your files to ${p.move.target} didn't finish`,actions:(0,h.jsx)(R,{disabled:d.isPending,onClick:()=>d.mutate(p.move?.target??``),children:`Continue moving`}),children:p.move.error??`Slopify was stopped before the copy was checked, so it still uses the old folder. Continue moving picks up where it left off.`}):v===`done`&&p.move.oldFolder!==null?(0,h.jsxs)(SI,{tone:`info`,title:`Your files are now in ${p.move.target}`,children:[`Every file was copied and checked. The old folder `,p.move.oldFolder,` still has a copy; once your projects open fine, you can delete it to free the space.`]}):null]})]})}function y9({view:e}){let t=[[`Projects`,e.projects],[`Automatic backups`,e.backups],[`Exports`,e.exports]].filter(e=>e[1]!==null);return(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1`,children:t.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-3`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-all`,children:t})]},e))})}function b9(e){return e?.move?.phase===`copying`||e?.move?.phase===`verifying`}function cSe(){let{api:e}=z(),t=N($y(e));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[t.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message}),t.data===void 0?t.error===null?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(hSe,{cells:5}),(0,h.jsx)(gSe,{})]}):null:(0,h.jsx)(uSe,{usage:t.data})]})}var lSe=[{id:`stage`,header:`Stage`,cell:e=>nF[e.stage]},{id:`model`,header:`Provider · model`,cell:e=>dSe(e)},{id:`in`,header:`Tokens in`,numeric:!0,cell:e=>x9.format(e.tokensIn)},{id:`out`,header:`Tokens out`,numeric:!0,cell:e=>x9.format(e.tokensOut)}];function uSe({usage:e}){let t=Object.values(e.counters).every(e=>e===0);return(0,h.jsxs)(e0,{split:`even`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(G2,{children:mSe(e).map(e=>(0,h.jsx)(K2,{label:e.label,value:e.value},e.label))}),t?(0,h.jsx)(`p`,{className:`m-0 mt-3 text-body text-ink-2`,children:`Numbers appear after your first run.`}):null]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Machine ID ${e.machineId??`not made yet`} · Slopify ${e.appVersion}`})]}),(0,h.jsx)(t0,{children:(0,h.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Tokens by stage`,columns:lSe,rows:e.byStage,rowKey:e=>`${e.stage}/${e.provider}/${e.model??``}`,empty:`No stages have run yet.`,className:`min-w-[480px] [&_td]:pr-4 [&_th]:pr-4`})})})]})}function dSe(e){return e.model===null?e.provider:`${e.provider} · ${e.model}`}var x9=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),fSe=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),pSe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function mSe(e){let t=e.counters;return[{label:`Videos made`,value:x9.format(t.videosMade)},{label:`Hours of audio`,value:fSe.format(t.audioSeconds/3600)},{label:`Images made`,value:x9.format(t.imagesMade)},{label:`Tokens used`,value:t.tokensUsed<1e6?x9.format(t.tokensUsed):pSe.format(t.tokensUsed)},{label:`Projects`,value:x9.format(t.projects)}]}function hSe({cells:e}){return(0,h.jsx)(`div`,{className:`sl-stats`,children:Array.from({length:e},(e,t)=>t).map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-8 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`})]},e))})}function gSe(){return(0,h.jsx)(`div`,{className:`border-t border-line`,children:[0,1,2,3].map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-4 border-b border-line py-3`,children:[(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 max-w-[40%] rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`ml-auto h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`})]},e))})}var S9=[`storage-usage`],_Se=[S9,B.projects,[`project`],B.usage,B.documentThemes,TH,[`play-drafts`],B.settings,B.providers,B.voices,B.prompts,B.entries,B.staging,Lq,sN,[`provider-models`]];async function vSe(e){await Promise.all(_Se.map(t=>e.invalidateQueries({queryKey:t})))}var C9=30,ySe=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function bSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=0&&Number(t)<=C9?void 0:`The silence gap is a whole number of seconds between 0 and ${String(C9)}.`}var w9=[{id:`general`,label:`General`,meta:`How Slopify starts on this computer.`},{id:`providers`,label:`Providers`,meta:`Keys stay on this machine and go only to their provider. Readiness is checked again before each run.`},{id:`voices`,label:`Voices`,meta:`A wrong voice ID shows up when the audio stage uses it.`},{id:`models`,label:`Models`,meta:`New models, prices and retirements, checked once a day.`},{id:`playback`,label:`Playback & appearance`,meta:`How narration is paced and how Slopify looks.`},{id:`notifications`,label:`Notifications`,meta:`When a run finishes, fails, waits for you, or a review needs a decision.`},{id:`channel-links`,label:`Channel links`,meta:`The links a YouTube description's {{Name}} placeholders fill from.`},{id:`studio`,label:`YouTube Studio`,meta:`The playlist upload packs name, and the Studio extension's pairing.`},{id:`storage`,label:`Backup & storage`,meta:`Export everything, import a backup, and see what uses disk space.`},{id:`backups`,label:`Backups`,meta:`A daily copy of everything, in a folder you choose.`},{id:`trash`,label:`Trash`,meta:`Deleted projects, prompts, templates and schedules, kept for 30 days.`},{id:`usage`,label:`Usage`,meta:`This machine only. The same counters, anonymised, feed slopify.stream.`},{id:`patch-notes`,label:`Patch notes`,meta:`What changed in each version of Slopify.`},{id:`about`,label:`About`,meta:`Free and open source, running on your machine with your own keys.`}];function xSe(e){return w9.find(t=>t.id===e)?.id??`providers`}function SSe(e){let t=document.createElement(`a`);t.href=`${e}/api/diagnostics`,t.download=`slopify-diagnostics.json`,document.body.append(t),t.click(),t.remove()}function CSe({section:e=`providers`,note:t,onSection:n=()=>{},onNote:r=()=>{}}){let{api:i}=z(),a=_(),o=Oy(),s=Q7(),c=h9(),l=w9.find(t=>t.id===e)??w9[0];return bx({id:`settings.check-providers`,title:`Check all providers`,group:`Settings`,keywords:[`health`,`keys`,`signed in`],run:()=>{n(`providers`),s.mutate()}}),bx({id:`settings.back-up-now`,title:`Back up now`,group:`Settings`,keywords:[`backup`],run:()=>{n(`backups`),c.mutate(void 0,{onError:e=>{o(`The backup didn't start: ${e.message} Open Settings → Backups to see its state.`,`error`)}})}}),bx({id:`settings.download-diagnostics`,title:`Download diagnostics`,group:`Settings`,keywords:[`support`,`bug report`],run:()=>{SSe(i.origin)}}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:`Settings`,title:l.label,meta:l.meta,actions:(0,h.jsxs)(h.Fragment,{children:[e===`providers`?(0,h.jsx)(R,{disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check all`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(mS,{variant:`secondary`,href:`${i.origin}/api/diagnostics`,download:`slopify-diagnostics.json`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download diagnostics`]}),(0,h.jsx)(V,{id:`settings.diagnostics`})]})]})}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(e8,{label:`Settings sections`,children:w9.map(t=>(0,h.jsx)(t8,{current:t.id===e,onClick:()=>n(t.id),className:`whitespace-nowrap max-md:w-auto`,children:t.label},t.id))}),children:(0,h.jsxs)(`section`,{"aria-label":l.label,className:`flex min-w-0 flex-col gap-10`,children:[e===`providers`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B3,{}),(0,h.jsx)(wxe,{}),(0,h.jsx)(mxe,{run:s})]}):null,e===`general`?(0,h.jsx)(zb,{}):null,e===`voices`?(0,h.jsx)(kxe,{}):null,e===`models`?(0,h.jsx)(cxe,{}):null,e===`playback`?(0,h.jsx)(DSe,{}):null,e===`notifications`?(0,h.jsx)(Nxe,{}):null,e===`channel-links`?(0,h.jsx)(Kfe,{}):null,e===`studio`?(0,h.jsx)(Afe,{}):null,e===`storage`?(0,h.jsx)(sSe,{usageQueryKey:S9}):null,e===`storage`?(0,h.jsx)(wSe,{}):null,e===`storage`?(0,h.jsx)(Lxe,{}):null,e===`backups`?(0,h.jsx)(rSe,{}):null,e===`trash`?(0,h.jsx)(Yxe,{}):null,e===`usage`?(0,h.jsx)(cSe,{}):null,e===`patch-notes`?(0,h.jsx)(Bxe,{note:t,onNote:r}):null,e===`about`?(0,h.jsx)(eSe,{onWhatsNew:()=>{a.fetchQuery(fI(i)).then(e=>r(e.current??void 0),e=>{o(`The patch notes did not open: ${e instanceof Error?e.message:String(e)} Open Settings → Patch notes to try again.`,`error`)})}}):null]})})]})}var T9=`The backup wasn't imported. Check it is a file made with Export everything (.tar) or Export backup (.zip), then try again.`;function wSe(){let{api:e}=z(),t=_(),n=N({queryKey:S9,queryFn:()=>Fo(e),staleTime:3e4}),[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)({phase:`idle`}),[s,c]=(0,m.useState)({phase:`idle`}),[l,u]=(0,m.useState)(null),d=Oy(),[f,p]=(0,m.useState)(null);async function g(){p(null),o({phase:`preparing`});try{let t=await Eo(e);if(!t.ready){o({phase:`idle`}),p(t.detail??`The backup can't be made right now. Try again in a moment.`);return}o({phase:`downloading`,bytes:t.bytes??0,projects:t.projects??0});let n=document.createElement(`a`);n.href=`${e.origin}/api/storage/export`,n.download=``,document.body.append(n),n.click(),n.remove()}catch(e){o({phase:`idle`}),p(e instanceof Error?e.message:`The backup couldn't be prepared. Try again in a moment.`)}}async function v(n){let r=n.name.toLowerCase().endsWith(`.zip`)||n.type===`application/zip`;if(n.size===0||r&&n.size>104857600){p(r?`This file is empty or larger than 100 MB. Choose a .zip made with Export backup, or a .tar made with Export everything.`:`This file is empty. Choose the .tar made with Export everything.`);return}i(!0),p(null),u(null),c({phase:`uploading`,sent:0,total:n.size});try{let i=await e.upload(`${e.origin}/api/storage/import`,n,r?`application/zip`:`application/x-tar`,(e,t)=>{c(e>=t?{phase:`importing`}:{phase:`uploading`,sent:e,total:t})}),a=await i.json();if(!i.ok)throw Error(a.detail??T9);a.projects===void 0?d(`Imported ${a.templates??0} template(s), ${a.fonts??0} uploaded font(s), and ${a.stagedFiles??0} staged file(s).${a.fontFallbacks?` ${a.fontFallbacks} missing legacy font reference(s) now use the default font.`:``}`,`success`):(u(a),d(`Backup imported.`,`success`)),await vSe(t)}catch(e){p(e instanceof Error?e.message:T9)}finally{c({phase:`idle`}),i(!1)}}async function y(){i(!0),p(null);try{let n=await e.fetch(`${e.origin}/api/storage/cleanup`,{method:`POST`}),r=await n.json();if(!n.ok)throw Error(`Clean orphan files didn't finish. Try again in a moment.`);d(`Removed ${r.orphanFiles??0} orphan project file(s) and ${r.stagedFiles??0} stale staged file(s).`,`success`),await t.invalidateQueries({queryKey:S9})}catch(e){p(e instanceof Error?e.message:`Clean orphan files didn't finish. Try again in a moment.`)}finally{i(!1)}}bx({id:`settings.export-everything`,title:`Export everything`,group:`Settings`,context:`Backup & storage`,keywords:[`backup`,`download`],run:()=>{!r&&a.phase!==`preparing`&&g()}});let b=r||a.phase===`preparing`,x=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Export and import`,info:`settings.storage.export`,children:[(0,h.jsx)(R,{disabled:b,onClick:()=>void g(),children:`Export everything`}),(0,h.jsx)(R,{disabled:b,onClick:()=>x.current?.click(),children:`Import a backup`}),(0,h.jsx)(`input`,{ref:x,className:`sr-only`,type:`file`,tabIndex:-1,"aria-label":`Import a backup`,accept:`.tar,application/x-tar,.zip,application/zip`,disabled:b,onChange:e=>{let t=e.target.files?.[0];t&&v(t),e.target.value=``}}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:b,onClick:()=>void y(),children:`Clean orphan files`}),(0,h.jsx)(V,{id:`settings.storage.clean`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Provider keys are never included in a backup. After importing, enter them again in Settings → Providers.`}),a.phase===`preparing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Preparing the backup…`}):null,a.phase===`downloading`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 min-w-0 flex-1 text-ink`,children:[`Downloading `,Y5(a.bytes),` (`,a.projects,` project`,a.projects===1?``:`s`,`). Your browser's downloads show its progress; keep Slopify running until it finishes.`]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>o({phase:`idle`}),children:`Dismiss`})]}):null,s.phase===`uploading`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[`Uploading the backup: `,Y5(s.sent),` of`,` `,Y5(s.total)]}),(0,h.jsx)(q2,{label:`Backup upload`,value:s.total===0?0:s.sent/s.total})]}):null,s.phase===`importing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Checking and importing the backup… large projects can take a minute.`}):null,f?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:f}):null]})]}),l?(0,h.jsx)(ESe,{result:l,onDismiss:()=>u(null)}):null,(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Disk space`,info:`settings.storage.disk`,meta:n.data?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`font-semibold text-ink`,children:[Y5(n.data.data),` stored`]}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[` `,`· `,Y5(Math.max(0,n.data.projects-n.data.trash.bytes)),` project files · `,Y5(n.data.staging),` staged files`,n.data.trash.projects>0?` · ${Y5(n.data.trash.bytes)} in the trash (${TSe(n.data.trash.projects)}), freed when removed for good`:null]})]}):n.error?`Storage usage is unavailable. Reload the page to try again.`:(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`})}),n.data&&n.data.byProject.length>0?(0,h.jsx)(Yve,{projects:n.data.byProject,queryKey:[...S9]}):null]})]})}function TSe(e){return e===1?`1 deleted project`:`${String(e)} deleted projects`}function E9(e,t){if(t===void 0)return null;let n=[t.added>0?`${t.added} added`:null,t.renamed>0?`${t.renamed} added as “(imported)” because the name was taken`:null,t.skipped>0?`${t.skipped} already here`:null].filter(e=>e!==null);return n.length===0?null:`${e}: ${n.join(`, `)}.`}function ESe({result:e,onDismiss:t}){let n=[e.projects.imported.length>0?`Projects: ${e.projects.imported.length} added (${Y5(e.files.bytes)} of files).`:`Projects: none added.`,E9(`Prompts`,e.prompts),E9(`Intros and outros`,e.entries),E9(`Channels`,e.channels),E9(`Cast members`,e.cast),E9(`Episode memories`,e.episodeMemories),E9(`Existing videos`,e.channelVideos),E9(`Document themes`,e.documentThemes),E9(`Templates`,e.templates),E9(`Schedules`,e.schedules),e.schedules.paused>0?`${e.schedules.paused} schedule(s) arrived paused so two installs never run them both; resume them on the Schedules screen.`:null,E9(`Voices`,e.voices),E9(`Play drafts`,e.drafts),e.settings.added+e.settings.kept>0?`Settings: ${e.settings.added} filled in${e.settings.kept>0?`, ${e.settings.kept} kept as this install has them`:``}.`:null,e.fonts>0?`Uploaded fonts: ${e.fonts} added.`:null,e.usage.alreadyImported?`Usage: this backup's history was already added before, so it wasn't counted twice.`:`Usage: ${e.usage.events} recorded event(s) added to the totals.`,`Provider keys are not in backups: enter them in Settings → Providers.`].filter(e=>e!==null);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{as:`h3`,title:`Imported the backup from ${e.backup.createdAt.slice(0,10)}`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`Dismiss`})}),(0,h.jsxs)(`ul`,{"aria-label":`Import result`,className:`m-0 list-disc pl-5 text-small text-ink-2`,children:[n.map(e=>(0,h.jsx)(`li`,{className:`py-0.5`,children:e},e)),e.projects.skipped.map(e=>(0,h.jsxs)(`li`,{className:`py-0.5`,children:[`Skipped “`,e.title,`”: `,e.reason]},e.id))]})]})}function DSe(){let{api:e}=z(),t=_(),n=N(ob(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Qo(e,t),onMutate:e=>{let n=t.getQueryData(B.settings);return t.setQueryData(B.settings,e),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(B.settings,r.previous)},onSuccess:e=>{t.setQueryData(B.settings,e)}});if((0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>{o(!1)},Y2);return()=>{clearTimeout(e)}},[a]),n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});if(n.data===void 0)return(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,role:`status`,"aria-label":`Loading settings`,children:[(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`})]});let c=n.data,l=r??String(c.silenceGapSeconds),u=bSe(l);return(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Silence between segments`,tip:`settings.playback.silence-gap`,help:`Seconds of quiet between narrated segments.`,error:u??s.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:0,max:C9,step:1,className:`w-[88px] tabular-nums`,value:l,"aria-invalid":u!==void 0,onChange:e=>{i(e.target.value)}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`seconds`}),(0,h.jsx)(R,{variant:`primary`,disabled:u!==void 0||s.isPending,onClick:()=>{o(!1),s.mutate({...c,silenceGapSeconds:Number(l.trim())},{onSuccess:()=>{i(void 0),o(!0)}})},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null})]})}),(0,h.jsxs)(`div`,{className:`sl-field`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Appearance`}),(0,h.jsx)(V,{id:`settings.appearance`,className:`-my-1`})]}),(0,h.jsx)(Ab,{label:`Appearance`,value:c.appearance,options:ySe,className:`self-start`,onChange:e=>{s.mutate({...c,appearance:e})}})]}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(k6,{value:c.loudness??tk,switchLabel:`Level the volume for new runs`,switchTip:`settings.loudness`,onChange:e=>{s.mutate({...c,loudness:e})}})})]})}function OSe({open:e,onClose:t,onInstalled:n}){let{api:r}=z(),i=_(),a=N({queryKey:My,queryFn:()=>Iy(r),enabled:e}),o=P({mutationFn:e=>Ry(r,e),onSuccess:()=>n(),onSettled:()=>i.invalidateQueries({queryKey:My})});return(0,h.jsxs)(YP,{open:e,title:`Add a starter pack`,onClose:t,footer:(0,h.jsx)(Q1,{tone:o.error||a.error?`error`:`success`,children:o.error?.message??a.error?.message??(o.data===void 0?void 0:o.data.added?`Added: its prompts are in Prompts and its template is in this list.`:`That pack was already added.`)}),children:[(0,h.jsxs)(`p`,{className:`mb-4 flex items-center gap-1 text-small text-ink-2`,children:[`Prompts, a suggested voice and a template for one kind of channel.`,(0,h.jsx)(V,{id:`welcome.packs`})]}),(0,h.jsxs)(pU,{label:`Starter packs`,className:`[&_.sl-row__meta]:whitespace-normal`,children:[(a.data?.packs??[]).map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:(0,h.jsx)(R,{disabled:e.installed||o.isPending,onClick:()=>o.mutate(e.id),children:e.installed?`Added`:`Add pack`})},e.id)),a.data===void 0?(0,h.jsx)(mU,{title:`Loading packs…`}):null]})]})}function kSe({template:e}){let{api:t}=z(),n=N({queryKey:[...Lq,e.id,e.version],queryFn:async()=>{let n=await Uq(t,e.id);if(!n.ok)throw Error(n.message);return n.value}});if(n.error)return(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The keywords of `,e.name,` didn't load. `,n.error.message,` Press Keywords again.`]});if(!n.data)return(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`Reading the keywords…`});let{form:r,librarySnapshot:i}=n.data.document,a=h0({form:r,prompts:i?.prompts??[],entries:i?.entries??[]}),o=z3(r.title),s=[...new Set([...a.keys(),...Object.keys(r.values)])];return(0,h.jsx)(_0,{keywords:s.map(e=>({name:e,value:r.values[e]??``,feeds:a.get(e)??[],topic:o.includes(e)})),empty:`No keywords: the prompts and the title name none.`})}async function ASe(e,t,n,r){let i=await Gq(e,t.id,{baseVersion:t.version,mutationId:r,...n});if(!i.ok)throw Error(i.message);return i.value}function jSe({template:e}){return e===void 0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`Pick a template to see the keywords it fills.`}):(0,h.jsxs)(`section`,{"aria-label":`Keywords of ${e.name}`,className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:e.name,as:`h3`,info:`templates.edit`,className:`pb-0`}),(0,h.jsx)(kSe,{template:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`To change the settings, press Use in Play, change the draft, then Save a setup.`})]})}function MSe({template:e,onClose:t}){let{api:n}=z(),r=_(),i=Array.from({length:e.version},(t,n)=>e.version-n),a=ot({queries:i.map(t=>({queryKey:[...Lq,e.id,`version`,t],queryFn:async()=>{let r=await Uq(n,e.id,t);if(!r.ok)throw Error(r.message);return r.value},staleTime:1/0}))}),o=a[0]?.data,[s,c]=(0,m.useState)(i[1]??e.version),l=a[i.indexOf(s)]?.data,u=(0,m.useRef)(crypto.randomUUID()),d=Oy(),f=P({mutationFn:t=>ASe(n,e,{name:t.name,document:t.document},u.current),onSuccess:async(n,i)=>{u.current=crypto.randomUUID(),d(`Restored version ${String(i.version)} of ${e.name} as version ${String(n.version)}.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}}),p=a.find(e=>e.error!==null)?.error;return(0,h.jsx)(YP,{open:!0,title:`History of ${e.name}`,onClose:t,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[p?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:`A version couldn't be read: ${p.message} Close History and open it again.`}):null,(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Versions`,as:`h3`,info:`templates.history`}),(0,h.jsx)(pU,{label:`Versions of ${e.name}`,children:i.map((t,n)=>{let r=a[n]?.data;return(0,h.jsx)(mU,{title:`Version ${String(t)}`,selected:t===s,onSelect:()=>c(t),meta:r===void 0?`Loading…`:`${r.name} · ${j4(r.updatedAt)}`,actions:t===e.version?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(R,{size:`small`,"aria-label":`Restore version ${String(t)}`,disabled:r===void 0||f.isPending,disabledReason:r===void 0?`Reading the version`:`Restoring`,onClick:()=>{r!==void 0&&f.mutate(r)},children:`Restore`})},t)})}),(0,h.jsx)(Q1,{tone:`error`,children:f.error===null?void 0:`The version wasn't restored: ${f.error.message}`})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`Compare with the current version`,as:`h3`}),o===void 0||l===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Loading the versions…`}):l.version===o.version?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.version===1?`This is the only version so far.`:`Pick an older version in the list to compare it.`}):(0,h.jsxs)(h.Fragment,{children:[l.name===o.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${l.name}" to "${o.name}".`}),(0,h.jsx)(w4,{before:D9(l),after:D9(o),beforeLabel:`Version ${String(l.version)}`,afterLabel:`Version ${String(o.version)} (current)`})]})]})]})})}function D9(e){return JSON.stringify(e.document,null,1).split(`
307
+ `),s].find(e=>e?.trim())??`No text was recorded for this part.`}catch{return`Recorded text cannot be decoded.`}}function gbe({projectId:e,pending:t,onRestore:n}){let{api:r}=z(),[i,a]=(0,m.useState)(),o=N({queryKey:B.revisions(e),queryFn:async()=>{let t=await xfe(r,e);if(!t.ok)throw Error(t.message);return t.value.revisions}}),s=N({queryKey:B.revision(e,i??``),enabled:i!==void 0,queryFn:async()=>{if(i===void 0)throw Error(`Choose a version from History first.`);let t=await a2(r,e,i);if(!t.ok)throw Error(t.message);return t.value.view}}),c=s.data,l=c?.outputs.find(e=>e.selected&&e.available&&(e.output.role===`image`||e.output.role===`thumbnail`)),u=l??c?.outputs.find(e=>e.available);return(0,h.jsxs)(`section`,{"aria-label":`Project history`,className:`space-y-3`,children:[(0,h.jsx)(H,{title:`Project history`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:o.error.message}),(0,h.jsx)(`ol`,{className:`space-y-2`,children:o.data?.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(R,{type:`button`,onClick:()=>a(e.id),children:[e.title,` · `,e.createdAt,e.current?` · Current`:``]})},e.id))}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:s.error.message}),c===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:c.revision.config.title}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{variant:`primary`,disabled:t,onClick:()=>n(c.revision.id),children:`Restore this revision`}),l===void 0?null:(0,h.jsxs)(mS,{href:Efe(r,e,c.revision.id),download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download all images`]}),u===void 0?null:(0,h.jsx)(u2,{projectId:e,asset:``,folder:{revisionId:c.revision.id,recordId:u.recordId}})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-3 p-0`,children:c.outputs.map(t=>(0,h.jsxs)(`li`,{className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:C7(t.output)}),(0,h.jsxs)(`span`,{className:`text-small text-ink-2`,children:[` · ${t.state}${t.selected?``:` · Earlier result`}`,t.available?``:` · File missing`]})]}),t.available?(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,"aria-label":`Download ${C7(t.output)}`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download`]}):null]}),t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained output`}),t.output.role===`video`?(0,h.jsx)(R0,{className:`max-w-[640px]`,label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):[`audio_export`,`audio_body`,`audio_intro`,`audio_outro`].includes(t.output.role)?(0,h.jsx)($8,{label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):t.output.role===`image`||t.output.role===`thumbnail`?(0,h.jsx)(z0,{className:`max-w-[480px]`,alt:C7(t.output),title:C7(t.output),meta:t.selected?`Current`:`Earlier result`,src:s2(r,e,c.revision.id,t.recordId)}):(0,h.jsx)(`p`,{children:`Use Download to inspect this retained file.`})]}):null]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained narration parts`,children:c.pieces.filter(e=>e.stageKind===`audio`&&e.assetId!==null).map(t=>(0,h.jsxs)(`li`,{children:[`Narration part `,t.piece.idx,t.selected?``:` · Earlier result`,t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained audio part`}),(0,h.jsx)($8,{label:`Narration part ${String(t.piece.idx)}`,src:s2(r,e,c.revision.id,t.recordId)}),(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download narration part`]})]}):(0,h.jsx)(`span`,{children:` · File missing`})]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained text parts`,children:c.pieces.filter(e=>e.assetId===null).map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(`details`,{children:[(0,h.jsxs)(`summary`,{children:[e.stageKind,` part `,e.piece.idx]}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words`,children:hbe(e.piece.payload)})]})},e.recordId))})]})]})}function j7(e,t,n){let r=JSON.stringify(t);return e?.payload===r?e:{payload:r,idempotencyKey:n()}}function _be(e,t,n={}){let{api:r}=z(),i=_(),a=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved settings to show yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);return n.value.view}}),[o,s]=(0,m.useState)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(),[f,p]=(0,m.useState)(),[h,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(),w=(0,m.useRef)(void 0),T=(0,m.useRef)(void 0),E=(0,m.useRef)(void 0),D=(0,m.useRef)(n.onOpenEdit);D.current=n.onOpenEdit;let O=(0,m.useMemo)(()=>c!==void 0&&(o===void 0||(c.regenerate?.length??0)>0||(c.uploads?.length??0)>0||JSON.stringify(c.config)!==JSON.stringify(o.revision.config)||JSON.stringify(c.content)!==JSON.stringify(o.revision.content)),[c,o]),k=c!==void 0&&o!==void 0&&t!==null&&t!==o.revision.id,A=(0,m.useRef)(!1);async function ee(e){if(!A.current){A.current=!0,g(!0),x(void 0),C(void 0);try{await e()}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1,g(!1)}}}async function te(t){let n=await r2(r,e);if(!n.ok){C(n);return}return C(void 0),s(n.value.view),t&&l({config:structuredClone(n.value.view.revision.config),content:structuredClone(n.value.view.revision.content)}),n.value.view}async function ne(t){let n=await jo(r,e);return i.setQueryData(B.project(e),n),await i.invalidateQueries({queryKey:B.revisions(e)}),!t.current||n.revisionId!==t.revision.id?(C({ok:!1,reason:`conflict`,message:`The project changed again. Your draft is preserved.`,currentRevisionId:n.revisionId,fields:[]}),!1):(s(t),l(void 0),C(void 0),d(void 0),!0)}async function j(){if(v||o===void 0||c===void 0)return;let t={baseRevisionId:o.revision.id,edit:c},n=j7(w.current,t,()=>crypto.randomUUID());w.current=n;let i=await i2(r,e,{...t,idempotencyKey:n.idempotencyKey});if(!i.ok){C(i);return}await ne(i.value.view),w.current=void 0}async function re(t,n=u){if(n===void 0)return;let a={baseRevisionId:n.baseRevisionId,previewId:n.id,...t},o=j7(E.current,a,()=>crypto.randomUUID());E.current=o;let s=await wfe(r,e,{...a,idempotencyKey:o.idempotencyKey});if(!s.ok){C(s),(s.reason===`stale-preview`||s.reason===`conflict`)&&d(void 0);return}E.current=void 0,d(void 0),await i.invalidateQueries({queryKey:B.project(e)})}async function M(t,n){let i=await te(!1);if(i===void 0)return;let a=await Cfe(r,e,{baseRevisionId:i.revision.id,request:t});if(!a.ok){C(a);return}let o=a.value.value;if(E.current=void 0,n&&vbe(o)){await re({acknowledgeUnknownCosts:!1,confirmedProvidedWorkKeys:[]},o);return}d(o)}async function ie(t){let n=o??a.data??await te(!1);if(n===void 0)return;let i={baseRevisionId:n.revision.id,targetRevisionId:t},s=j7(T.current,i,()=>crypto.randomUUID());T.current=s;let c=await bfe(r,e,{...i,idempotencyKey:s.idempotencyKey});if(!c.ok){C(c);return}await ne(c.value.view),T.current=void 0}return{saved:a,view:o,edit:c,preview:u,focus:f,pending:h,uploading:v,error:b,refusal:S,unsaved:O,remoteChanged:k,busy:h||v||c!==void 0||u!==void 0,setEdit:l,setUploading:y,openEditor:()=>void ee(async()=>{await te(!0)}),discard:()=>{l(void 0),C(void 0),y(!1),w.current=void 0},save:()=>void ee(j),reloadDraft:()=>void ee(async()=>{w.current=void 0,y(!1),await te(!0),C(void 0)}),reloadCurrent:()=>void ee(async()=>{T.current=void 0,E.current=void 0,d(void 0),await te(!1),await i.invalidateQueries({queryKey:B.project(e)})}),requestEdit:e=>void ee(async()=>{let t=o,n=c;if(t===void 0||n===void 0){if(t=await te(!1),t===void 0)return;n={config:structuredClone(t.revision.config),content:structuredClone(t.revision.content)}}l(e.change(n,t)),p({section:e.section}),D.current?.()}),regenerateNow:t=>void ee(async()=>{let n=e=>({...e,regenerate:[...new Set([...e.regenerate??[],...t])]});if(c!==void 0&&O){l(n(c)),p({section:`images`}),D.current?.();return}let i=await te(!1);if(i===void 0)return;let a=await i2(r,e,{baseRevisionId:i.revision.id,edit:n({config:structuredClone(i.revision.config),content:structuredClone(i.revision.content)}),idempotencyKey:crypto.randomUUID()});if(!a.ok){C(a);return}await ne(a.value.view)&&await M({kind:`selected`,workKeys:t},!0)}),review:(e,t)=>void ee(()=>M(e,t?.autoStart===!0)),start:e=>void ee(()=>re(e)),closePreview:()=>{h||(d(void 0),E.current=void 0)},restore:e=>void ee(()=>ie(e))}}function vbe(e){return!e.work.some(e=>e.disposition===`blocked`)&&e.providedReuseRequired.length===0&&e.costs.unknown===0}function ybe({controller:e,renderEditor:t,active:n=!0,intro:r}){let i=e;return i.view===void 0||i.edit===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r??(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Saved revision`,info:`project.saved-revision`}),i.saved.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.saved.error.message}),i.saved.data===void 0?null:(0,h.jsx)(`ul`,{"aria-label":`Saved output status`,className:`sl-list m-0 list-none p-0`,children:i.saved.data.outputs.filter(e=>e.selected).map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:C7(e.output)}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.available?e.state===`ready`?`Ready`:e.state===`outdated`?`Outdated; the retained version stays until it is remade`:`Provided content needs review`:`Retained file missing`})]},e.recordId))})]}),i.preview===void 0&&n?(0,h.jsx)(A7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{children:[i.refusal?.reason===`conflict`&&n?(0,h.jsx)(R,{disabled:i.pending,onClick:i.reloadCurrent,children:`Reload current revision`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{disabled:i.busy,onClick:()=>i.review({kind:`allAffected`}),variant:`secondary`,children:`Choose what to remake`}),(0,h.jsx)(V,{id:`project.choose-remake`})]}),(0,h.jsx)(R,{variant:`primary`,disabled:i.busy,onClick:i.openEditor,children:`Edit project`})]})]}):(0,h.jsxs)(`form`,{"aria-label":`Edit project`,onSubmit:e=>{e.preventDefault(),i.save()},children:[(0,h.jsx)(`fieldset`,{disabled:i.pending,className:`m-0 min-w-0 border-0 p-0`,children:t({view:i.view,edit:i.edit,fields:i.refusal?.fields??[],onChange:i.setEdit,onPending:i.setUploading,...i.focus===void 0?{}:{focus:i.focus}})}),i.preview===void 0?(0,h.jsx)(A7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:i.remoteChanged?`warning`:`info`,children:i.remoteChanged?`A newer revision is available. Your unsaved changes are kept below.`:i.uploading?`Waiting for uploads to finish…`:void 0}),children:[i.remoteChanged||i.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:i.pending||i.uploading,onClick:i.reloadDraft,children:`Reload current revision and discard my draft`}):null,(0,h.jsx)(R,{variant:`quiet`,disabled:i.pending||i.uploading,onClick:i.discard,children:`Discard changes`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:i.pending||i.uploading,children:`Save changes`})]})]})}function bbe({controller:e,projectId:t,active:n}){let r=e;return n?(0,h.jsxs)(h.Fragment,{children:[r.preview===void 0&&(r.error||r.refusal)?(0,h.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3`,children:[(0,h.jsx)(A7,{error:r.error,refusal:r.refusal}),r.edit===void 0&&r.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:r.pending,onClick:r.reloadCurrent,className:`self-start`,children:`Reload current revision`}):null]}):null,(0,h.jsx)(gbe,{projectId:t,pending:r.busy,onRestore:r.restore})]}):null}function xbe({controller:e}){let t=e;return(0,h.jsx)(YP,{open:t.preview!==void 0,title:`Choose what to remake`,onClose:t.closePreview,children:t.preview===void 0?null:(0,h.jsx)(obe,{preview:t.preview,feedback:(0,h.jsx)(A7,{error:t.error,refusal:t.refusal}),pending:t.pending,onStart:t.start,onCancel:t.closePreview},t.preview.id)})}var Sbe=(e,t)=>{if(t)return`waiting`;switch(e.state){case`running`:return`running`;case`done`:case`provided`:return`done`;case`failed`:return e.retryAt===void 0?`failed`:`waiting`;default:return`off`}},Cbe=(e,t)=>{if(t)return`Held for you`;switch(e.state){case`running`:return`Running`;case`done`:return`Done`;case`provided`:return`Provided`;case`failed`:return e.retryAt===void 0?`Failed`:`Waiting to try again`;case`canceled`:return`Canceled`;case`skipped`:return`Off`;case`pending`:return`Not started`}};function wbe(e,t){if(e.startedAt===null)return;let n=Date.parse(e.startedAt),r=e.finishedAt===null?t:Date.parse(e.finishedAt);if(!Number.isFinite(n)||!Number.isFinite(r)||r<n)return;let i=Math.round((r-n)/1e3);if(i<1)return;if(i<60)return`${String(i)} s`;let a=Math.round(i/60);return a<60?`${String(a)} min`:`${String(Math.floor(a/60))} h ${String(a%60)} min`}function Tbe(e,t,n){let r=T3(t,n);return r===void 0?e:e===void 0||e===``?E3(r):`${e} · ${E3(r)}`}function Ebe({stages:e,outputs:t,project:n,resumable:r,held:i,now:a}){return e.filter(e=>e.state!==`skipped`).map(e=>{let o=i.some(t=>t.stage===e.kind),s=wbe(e,a);return{id:e.id,name:e.kind===`video`&&rF(n.config)===`audio`?`Audio export`:r5[e.kind],tone:Sbe(e,o),state:Cbe(e,o),...s===void 0?{}:{time:s},detail:o?`Held for your review`:Tbe(cF(e,t,n,r),e,a)}})}function Dbe({stages:e}){return(0,h.jsx)(`div`,{className:`sr-only`,children:e.filter(e=>e.state!==`skipped`).map(e=>(0,h.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:`${r5[e.kind]}: ${e.state}`},e.id))})}function Obe({steps:e}){return(0,h.jsxs)(`section`,{"aria-labelledby":`run-steps-title`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{id:`run-steps-title`,title:`Run`,size:`small`,className:`pb-0`}),(0,h.jsx)(O3,{steps:e,label:`Run steps`,dense:!0})]})}var M7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});function kbe({cost:e,onOpen:t}){if(e===void 0||e.calls===0&&e.byStage.length===0)return null;let n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({key:`${e.account}/${t.kind}`,name:e.name,window:t.kind===`five_hour`?`5-hour`:t.kind===`weekly`?`weekly`:`current`,used:t.usedPercent,now:t.nowPercent})):[]);return(0,h.jsxs)(`section`,{"aria-labelledby":`cost-so-far-title`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{id:`cost-so-far-title`,title:`Cost so far`,size:`small`,className:`pb-0`,children:t===void 0?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`By stage`})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[(0,h.jsx)(`strong`,{className:`text-ink`,children:a7(e.cost)}),e.unpriced>0?` known, spent`:` spent`,e.apiEquivalent===null?null:` · ~${a7(e.apiEquivalent)} via API`,e.run===null||e.run.running?null:` · ${o7(e.run.workingMs)} of work`]}),n.map(e=>{let t=e.used<1?`under 1%`:`${M7.format(e.used)}%`,n=`${e.window} ${e.name} limit`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`${e.name}: ${t} of your ${e.window} limit`}),(0,h.jsx)(q2,{value:e.used/100,label:`Share of the ${n} this run used`,valueText:`${t} of your ${n}; now at ${M7.format(e.now)}%`,tone:e.now>=80?`waiting`:`accent`})]},e.key)})]})}function N7({projectId:e,revisionId:t,title:n,open:r,onClose:i}){let{api:a}=z(),o=_(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=Oy(),g=(0,m.useRef)(!1),v=(0,m.useRef)(null);(0,m.useEffect)(()=>{r&&t!==null&&(c({revisionId:t,name:n}),f(null)),r||c(null)},[r,t,n]);async function y(){if(!s||g.current||!s.name.trim())return;g.current=!0,u(!0),f(null);let t=JSON.stringify([e,s.revisionId,s.name.trim()]);v.current?.key!==t&&(v.current={key:t,id:crypto.randomUUID()});try{let t=await qq(a,e,{id:v.current.id,name:s.name.trim(),revisionId:s.revisionId});if(!t.ok){v.current=null,f(t.message);return}v.current=null,i(),p(`Template saved.`,`success`),await o.invalidateQueries({queryKey:Lq})}catch(e){f(e instanceof Error?e.message:`The template wasn't saved. Press Save template to try again.`)}finally{g.current=!1,u(!1)}}return(0,h.jsx)(Ay,{open:r&&s!==null,onOpenChange:e=>{!e&&!g.current&&i()},title:`Save as template`,description:`Save this revision’s setup for a fresh Play draft. This does not rebuild the project.`,children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,required:!0,maxLength:200,disabled:l,value:s?.name??``,onChange:e=>{let t=e.target.value;c(e=>e&&{...e,name:t})}})}),d?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:d}):null,(0,h.jsxs)(`div`,{className:`sl-dialog__foot`,children:[(0,h.jsx)(R,{disabled:l,onClick:i,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:l||!s?.name.trim(),children:`Save template`})]})]})})}var P7=q({baseRevisionId:W().min(1).max(64),idempotencyKey:wD()}).strict(),Abe=rO(`kind`,[q({kind:pO(`resume`)}).strict(),q({kind:pO(`retry`),stage:J(FS)}).strict(),q({kind:pO(`rerun`),stage:J(FS)}).strict(),q({kind:pO(`redo`),item:W().min(1).max(200)}).strict()]);P7.extend({action:Abe}).strict();var jbe=rO(`ok`,[q({ok:pO(!0),value:K0.and(q({warnings:K(W()).readonly()}))}),q({ok:pO(!1),reason:J([`no-project`,`no-revision`,`conflict`,`idempotency-conflict`,`invalid-edit`,`stale-preview`,`invalid-selection`,`review-required`,`cost-ack-required`,`readiness`,`running`,`accepted-job`,`control-changed`]),fields:K(q({field:W(),message:W()})).readonly().optional(),intentRevisionId:W().optional(),currentRevisionId:W().nullable().optional()})]),F7=new Set([400,404,409]);async function Mbe(e,t,n){return L7(e,t,`cancel`,n)}async function Nbe(e,t,n){return L7(e,t,`pause`,n)}function Pbe(e,t,n){return R7(e,t,`resume`,n)}function Fbe(e,t,n,r){return R7(e,t,`stages/${n}/retry`,r)}function Ibe(e,t,n,r){return R7(e,t,`stages/${n}/soften`,r)}function Lbe(e,t,n,r){return R7(e,t,`stages/${n}/rerun`,r)}async function Rbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/providers`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function zbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/subtitles`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function Bbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/article`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({markdown:n})}))}async function Vbe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].$delete({param:{id:t,outputId:n}}))}async function Hbe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].regenerate.$post({param:{id:t,outputId:n}}))}async function I7(e){if(e.ok)return{ok:!0,value:await e.json()};let t=await mo(e);if(t!==void 0&&F7.has(e.status))return{ok:!1,message:po(e,t).message};throw po(e,t)}async function L7(e,t,n,r){let i=P7.parse(r);return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}))}async function R7(e,t,n,r){let i=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(P7.parse(r))});if(i.ok){let e=jbe.parse(await i.json());if(!e.ok)throw Error(xo);return{ok:!0,value:e.value,warnings:e.value.warnings}}let a=await mo(i);if(a!==void 0&&F7.has(i.status))return{ok:!1,message:po(i,a).message};throw po(i,a)}function Ube(e){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(),s=(0,m.useRef)(new Map),c=(0,m.useRef)(!1),l=P({mutationFn:async e=>{let r=e.action;if(![`pause`,`cancel`,`resume`,`retry`,`soften`,`rerun`].includes(r.kind))return B7(t,e.projectId,r);let i=r.kind===`retry`||r.kind===`soften`||r.kind===`rerun`?r.stage:``,a=`${e.projectId}:${r.kind}:${i}`,o=s.current.get(a);if(!o){let r=n.getQueryData(B.project(e.projectId))?.revisionId;if(!r){let n=await r2(t,e.projectId);if(!n.ok)return{ok:!1,message:n.message};r=n.value.view.revision.id}o={baseRevisionId:r,idempotencyKey:crypto.randomUUID()},s.current.set(a,o)}let c=await B7(t,e.projectId,r,o);return s.current.delete(a),c.ok&&await jo(t,e.projectId).then(t=>n.setQueryData(B.project(e.projectId),t),e=>console.warn(`Project refresh after an accepted action failed`,e)),c},onMutate:()=>{i(void 0),o(void 0)},onSuccess:async(e,t)=>{e.ok?(o(`warnings`in e&&e.warnings.length>0?e.warnings.join(` `):void 0),n.invalidateQueries({queryKey:B.projects})):i({message:e.message,stage:z7(t.action)}),await n.invalidateQueries({queryKey:B.project(t.projectId)})},onSettled:()=>{c.current=!1},onError:(e,t)=>{i({message:e.message,stage:z7(t.action)})}});return{run:(t,n)=>{c.current||(c.current=!0,l.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok&&n?.()}}))},pending:l.isPending,performing:l.isPending?l.variables?.action:void 0,refusal:r,dismissRefusal:()=>{i(void 0)},notice:a}}function z7(e){switch(e.kind){case`cancel`:case`pause`:case`resume`:case`providers`:return;case`retry`:case`soften`:case`rerun`:return e.stage;case`subtitles`:return`video`;case`save-article`:return`article`;case`delete-image`:case`regenerate-image`:return`images`}}function B7(e,t,n,r){let i=()=>{if(!r)throw Error(`A saved revision and request identity are required.`);return r};switch(n.kind){case`pause`:return Nbe(e,t,i());case`cancel`:return Mbe(e,t,i());case`resume`:return Pbe(e,t,i());case`retry`:return Fbe(e,t,n.stage,i());case`soften`:return Ibe(e,t,n.stage,i());case`rerun`:return Lbe(e,t,n.stage,i());case`providers`:return Rbe(e,t,n.choices);case`subtitles`:return zbe(e,t,n.subtitles);case`save-article`:return Bbe(e,t,n.markdown);case`delete-image`:return Vbe(e,t,n.outputId);case`regenerate-image`:return Hbe(e,t,n.outputId)}}var V7=e=>e.state===`done`||e.state===`provided`;function Wbe(e){let t=e.find(e=>e.state===`failed`)??e.find(e=>e.state===`running`);if(t)return t.kind;let n=e.find(e=>e.kind===`video`&&V7(e));if(n)return n.kind;let r=e.find(e=>e.state===`pending`);return r?r.kind:e.find(e=>e.kind===`article`&&V7(e))?.kind??e.find(e=>e.state!==`skipped`)?.kind??`article`}function Gbe({projectId:e,openDraft:t}){return(0,h.jsx)(Kbe,{projectId:e,openDraft:t},e)}var H7=e=>{let t=e.filter(e=>e!==void 0);if(!(t.length===0||t.every(e=>e.state===`skipped`)))return t.some(e=>e.state===`failed`&&e.retryAt===void 0)?`failed`:t.some(e=>e.state===`running`)?`running`:t.some(e=>e.state===`failed`)?`waiting`:t.every(e=>e.state===`done`||e.state===`provided`||e.state===`skipped`)?`done`:`off`};function Kbe({projectId:e,openDraft:t}){let{api:n}=z(),r=Oy(),i=Ybe(e,t),a=N(Xy(n,e)),o=N(nb(n)),s=N(Zy(n,e)),c=Ube(e),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),y=a.data?.revisionId??null,b=_be(e,y,{onOpenEdit:()=>u(`settings`)}),x=uI(e),S=(0,m.useRef)(void 0);(0,m.useEffect)(()=>{if(x===void 0){S.current=void 0;return}a.data!==void 0&&S.current!==x&&(S.current=x,x===`download`&&u(rF(a.data.project.config)===`article`?`article`:`video`))},[x,a.data]),N3(e,y);let C=N({queryKey:Ny,queryFn:()=>Vy(n)}),w=Hy(C.data,e),T=N({queryKey:f3(e,y??``),queryFn:()=>m3(n,e),enabled:y!==null,retry:!1}),E=T.data?.ok===!0?T.data.value.checkpoints:[],D=b.saved.data?.outputs.filter(e=>e.selected&&e.state===`outdated`).map(e=>({workKey:e.workKey,role:e.output.role}))??[],O=a.data?.project,k=a.data?.stages??[],A=a.data?.outputs??[],ee=A.some(e=>e.role===`video`),te=e=>u(e),ne=Y_e({project:O??qbe,stages:k,resumable:a.data?.resumable??!1,sample:w,gates:E,outdated:D,waits:s.data?.waits??[],uploadReady:ee,actions:c,controller:b,openSection:te,openUpload:()=>f(!0)}),j=l===`settings`,re=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!j){re.current=!1;return}b.edit!==void 0&&(re.current=!0),!(re.current||b.busy)&&(re.current=!0,b.openEditor())},[j,b]);let M=k.some(e=>e.state===`running`),ie=O?.status===`running`,ae=O?.title??``,oe=ne.next?.action;bx({id:`project.next`,title:oe?.label??`Show the project's next action`,group:`This project`,context:ae,keywords:[`next`,`continue`,`resume`,`approve`,`retry`],shortcut:lP.nextAction,run:()=>{oe===void 0?r(`This project has no next action right now: nothing waits on you.`,`info`):oe.intent.kind===`soften`?r(`Soften and retry asks first: press it in the Next action panel on the right.`):ne.run(oe.intent)}}),Yx(Wx.showImages(e),()=>{let e=a.data?.stages.find(e=>e.kind===`images`);e===void 0||e.state===`skipped`?r(`${ae} makes no slideshow images, so there is no image to regenerate. To add them, open Settings in this project and choose how its images are made.`,`error`):u(`images`)},a.data!==void 0),bx({id:`project.pause`,title:O?.status===`paused`?`Continue the run`:`Pause the run`,group:`This project`,context:ae,keywords:[`pause`,`resume`,`continue`,`stop`],run:()=>c.run({kind:O?.status===`paused`?`resume`:`pause`})}),bx({id:`project.prepare-upload`,title:`Prepare upload`,group:`This project`,context:ae,keywords:[`youtube`,`studio`,`upload`,`publish`],run:()=>{ee?f(!0):r(`Prepare upload opens once the video has been made.`,`info`)}}),bx({id:`project.settings`,title:`Edit project settings`,group:`This project`,context:ae,keywords:[`edit`,`settings`,`prompts`,`providers`,`channel`],run:()=>u(`settings`)}),bx({id:`project.rebuild-review`,title:`Choose what to remake`,group:`This project`,context:ae,keywords:[`rebuild`,`review`,`remake`,`outdated`,`affected`],run:()=>b.review({kind:`allAffected`})}),bx({id:`project.template`,title:`Save as template`,group:`This project`,context:ae,keywords:[`template`,`reuse`],run:()=>g(!0)}),bx({id:`project.cancel`,title:`Cancel the run`,group:`This project`,context:ae,keywords:[`cancel`,`stop`],run:()=>v(!0)});let se=q_e(D);if(bx({id:`project.remake-1`,title:se[0]?.label??`Remake outdated outputs`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`],run:()=>{let e=se[0];e===void 0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0})}}),bx({id:`project.remake-all`,title:`Remake everything outdated`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`,`all`],run:()=>{let e=[...new Set(se.flatMap(e=>e.workKeys))];e.length===0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e},{autoStart:!0})}}),bx({id:`project.copy`,title:`Make my own copy`,group:`This project`,context:ae,keywords:[`sample`,`copy`,`duplicate`],run:()=>w?ne.run({kind:`copy-sample`}):r(`Only the sample project is copied this way.`,`info`)}),a.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The project could not be loaded.`,children:`${a.error.message} Reload the page to try again, or go back to Projects.`});if(a.data===void 0||O===void 0)return(0,h.jsx)(Jbe,{});let ce=e=>k.find(t=>t.kind===e),le=ce(`article`),ue=ce(`research`),de=ce(`audio`),fe=ce(`images`),pe=ce(`thumbnail`),me=ce(`video`),he=ce(`document`),ge=O.config,_e=e=>e!==void 0&&e.state!==`skipped`,ve=ge.shorts?.enabled===!0||A.some(e=>e.role===`short_video`||e.role===`shorts`),ye=ge.youtubeDescription===!0||A.some(e=>e.role===`youtube_description`),be=E.filter(e=>e.state===`held`||e.state===`pending-review`),xe=[..._e(le)||_e(ue)?[{id:`article`,label:`Article`,tone:H7([le,ue])}]:[],..._e(de)?[{id:`narration`,label:`Narration`,tone:H7([de])}]:[],..._e(fe)||_e(pe)||ge.reference!==void 0?[{id:`images`,label:`Images`,tone:H7([fe,pe])}]:[],..._e(me)?[{id:`video`,label:rF(ge)===`audio`?`Audio export`:`Video`,tone:H7([me])}]:[],...ve?[{id:`shorts`,label:`Shorts`}]:[],...ye?[{id:`youtube`,label:`YouTube`}]:[],..._e(he)?[{id:`document`,label:`PDF`,tone:H7([he])}]:[],{id:`cost`,label:`Cost`},{id:`live`,label:`Live`}].map(e=>{let t=se.filter(t=>t.section===e.id).reduce((e,t)=>e+t.count,0);return t===0?e:{...e,meta:`${String(t)} outdated`}}),Se=[{id:`settings`,label:`Settings`,...b.unsaved?{meta:`unsaved`}:{}},...y===null?[]:[{id:`checkpoints`,label:`Checkpoints`,...be.length===0?{}:{meta:`${String(be.length)} held`}}],{id:`history`,label:`History`}],Ce=[...xe,...Se],we=ne.next?.situation,Te=ne.next?.section!==void 0&&we!==`done`&&we!==`running`?ne.next.section:we===`done`&&A.some(e=>e.role===`youtube_description`)?`youtube`:n5(Wbe(k)),Ee=l!==void 0&&Ce.some(e=>e.id===l)?l:Ce.find(e=>e.id===Te)?.id??xe[0]?.id??`cost`,De=(...e)=>y===null?O.status===`running`||O.status===`paused`||M||c.pending:c.pending||e.some(e=>e?.state===`running`),Oe={project:O,outputs:A,actions:c,next:ne,resumable:a.data.resumable},ke=(e,t)=>e===void 0?null:(0,h.jsx)(Vve,{stage:e,...t===void 0||t.state===`skipped`?{}:{companion:t},project:O,outputs:A,actions:c,busy:De(e,t)}),Ae=(...e)=>A.some(t=>e.some(e=>e!==void 0&&t.stageKind===e.kind)),je=(...e)=>Ae(...e)||e.some(e=>e!==void 0&&[`running`,`done`,`provided`,`failed`,`canceled`].includes(e.state)),Me=[{id:`rebuild`,label:`Choose what to remake…`,run:()=>b.review({kind:`allAffected`}),disabled:b.busy},{id:`template`,label:`Save as template…`,run:()=>g(!0),disabled:y===null||w},{id:`cancel`,label:`Cancel the run…`,run:()=>v(!0),disabled:!ie||c.pending,apart:!0}],Ne=t5({kind:`cancel`}),Pe=c.refusal?.stage===void 0?c.refusal:void 0,Fe=Pe===void 0?c.notice===void 0?b.preview===void 0&&(b.error||b.refusal)&&Ee!==`settings`&&Ee!==`history`?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:b.error??b.refusal?.message}):void 0:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:c.notice}):(0,h.jsx)(SI,{tone:`danger`,title:Pe.message,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,className:`mt-1`,onClick:c.dismissRefusal,children:`Dismiss`})}),Ie=Ebe({stages:k,outputs:A,project:O,resumable:a.data.resumable,held:be.map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),now:Date.now()});return(0,h.jsx)(n_e,{projectId:e,revisionId:y,children:(0,h.jsx)(J8,{value:y!==null,children:(0,h.jsx)(g3,{value:e=>u(e===`edit`?`settings`:`article`),children:(0,h.jsx)(Y8,{value:b.pending||b.preview!==void 0?void 0:b.requestEdit,children:(0,h.jsxs)(X8,{value:b.pending||b.preview!==void 0?void 0:b.regenerateNow,children:[(0,h.jsxs)(`div`,{className:`sl-project`,children:[(0,h.jsx)(`div`,{"data-tour":`project-controls`,children:(0,h.jsx)(Qve,{project:O,prompts:o.data?.prompts,editing:Ee===`settings`,onEdit:()=>u(`settings`),more:Me,nextChapter:i,clock:(0,h.jsx)(aye,{cost:s.data,status:O.status,measuredAt:s.dataUpdatedAt})})}),(0,h.jsx)(Dbe,{stages:k}),(0,h.jsxs)(Aq,{sections:(0,h.jsxs)(e8,{label:`Project sections`,children:[xe.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:te},e.id)),(0,h.jsx)(`hr`,{className:`sl-rule my-2`}),Se.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:te},e.id))]}),aside:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Z_e,{state:ne,feedback:Fe}),O===void 0?null:(0,h.jsx)(Zve,{projectId:e,title:O.title,status:O.status,sample:w||C.isPending}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-6 max-[1180px]:hidden`,children:[(0,h.jsx)(Obe,{steps:Ie}),(0,h.jsx)(kbe,{cost:s.data,onOpen:()=>te(`cost`)}),(0,h.jsx)(Fge,{})]})]}),children:[(0,h.jsx)(u5,{id:`article`,title:`Article`,stages:[le,ue].filter(U7),active:Ee===`article`,...Oe,children:_e(le)||_e(ue)?ke(le,ue):(0,h.jsx)(d5,{stage:le,project:O,name:`Article`})}),(0,h.jsx)(u5,{id:`narration`,title:`Narration`,stages:[de].filter(U7),active:Ee===`narration`,...Oe,children:je(de)?ke(de):(0,h.jsx)(d5,{stage:de,project:O,name:`Narration`})}),(0,h.jsx)(u5,{id:`images`,title:`Images`,head:!1,stages:[fe,pe].filter(U7),active:Ee===`images`,...Oe,children:ke(fe,pe)}),(0,h.jsx)(u5,{id:`video`,title:rF(ge)===`audio`?`Audio export`:`Video`,stages:[me].filter(U7),active:Ee===`video`,...Oe,children:ke(me)}),me===void 0?null:(0,h.jsx)(u5,{id:`shorts`,title:`Shorts`,stages:[],active:Ee===`shorts`,...Oe,meta:`Vertical clips picked from the video, each with its title and hashtags`,children:(0,h.jsx)(Mve,{stage:me,project:O,outputs:A})}),me===void 0?null:(0,h.jsx)(u5,{id:`youtube`,title:`YouTube`,stages:[],active:Ee===`youtube`,...Oe,meta:`The description, chapters, hashtags and tags, as they go into YouTube Studio`,...ee&&ne.next?.action?.intent.kind!==`prepare-upload`?{extra:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>f(!0),children:`Prepare upload`})}:{},children:(0,h.jsx)(Hve,{stage:me,project:O,outputs:A})}),he===void 0?null:(0,h.jsx)(u5,{id:`document`,title:`PDF`,stages:[he],active:Ee===`document`,...Oe,children:je(he)?ke(he):(0,h.jsx)(d5,{stage:he,project:O,name:`PDF`})}),(0,h.jsx)(G7,{id:`cost`,title:`Run cost`,selected:Ee,children:(0,h.jsx)(rye,{projectId:e})}),(0,h.jsx)(G7,{id:`live`,title:`Live`,selected:Ee,children:Ee===`live`?(0,h.jsx)(mye,{project:O,revisionId:y,stages:k,outputs:A}):null}),(0,h.jsx)(G7,{id:`settings`,title:`Settings`,selected:Ee,children:(0,h.jsx)(ybe,{controller:b,active:Ee===`settings`,renderEditor:e=>(0,h.jsx)(ibe,{...e,renderContent:e=>(0,h.jsx)(Bye,{...e},e.view.revision.id)})})}),y===null?null:(0,h.jsx)(G7,{id:`checkpoints`,title:`Checkpoints`,selected:Ee,children:(0,h.jsx)(qve,{projectId:e,revisionId:y,paused:O.status===`paused`,stages:k,approvedInRail:ne.next?.action?.intent.kind===`approve`?ne.next.action.intent.gate.checkpointId:void 0})}),(0,h.jsx)(G7,{id:`history`,title:`History`,selected:Ee,children:(0,h.jsx)(bbe,{controller:b,projectId:e,active:Ee===`history`})})]})]}),(0,h.jsx)(xbe,{controller:b}),d?(0,h.jsx)(v2,{projectId:e,onClose:()=>f(!1)}):null,(0,h.jsx)(N7,{projectId:e,revisionId:y,title:O.title,open:p,onClose:()=>g(!1)}),(0,h.jsx)(jy,{open:_,title:Ne.title,consequence:Ne.consequence,confirmLabel:Ne.verb,cancelLabel:Ne.dismiss,pending:c.pending,onConfirm:()=>{v(!1),c.run({kind:`cancel`})},onCancel:()=>v(!1)})]})})})})})}var U7=e=>e!==void 0;function W7({item:e,selected:t,onSelect:n}){return(0,h.jsx)(t8,{className:`max-md:w-auto`,"data-tour":`project-rail-${e.id}`,current:e.id===t,onClick:()=>n(e.id),...e.tone===void 0?{}:{icon:(0,h.jsx)(gS,{tone:e.tone})},...e.meta===void 0?{}:{meta:e.meta},children:e.label})}function G7({id:e,title:t,selected:n,children:r}){return(0,h.jsxs)(`section`,{hidden:n!==e,"aria-label":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:t}),r]})}var qbe={id:``,title:``,format:`16:9`,status:`pending`,createdAt:``,config:{sources:{}}};function Jbe(){return(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading project`,children:[(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-8 w-80 max-w-full rounded-control bg-sunken`})]}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(`div`,{className:`flex flex-col gap-2`,children:[`a`,`b`,`c`,`d`,`e`].map(e=>(0,h.jsx)(`span`,{className:`h-8 rounded-control bg-sunken`},e))}),aside:(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`}),children:(0,h.jsx)(`span`,{className:`h-[480px] rounded-control bg-sunken`})})]})}function Ybe(e,t){let{api:n}=z(),r=(0,m.useRef)(void 0),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0);if(t!==void 0)return{pending:i,error:o,run:()=>{i||(r.current??=crypto.randomUUID(),a(!0),s(void 0),Yq(n,e,r.current).then(async e=>{if(!e.ok){s(e.message);return}await t(e.value.draft.id)?r.current=void 0:s(`The next chapter's draft was made, but Play could not open it because the draft open there is not saved yet. Open Play, let it save, then press Make the next chapter again.`)}).catch(e=>s(`The next chapter could not be made (${e instanceof Error?e.message:`the connection dropped`}). Press Make the next chapter again.`)).finally(()=>a(!1)))}}}var Xbe=[`all`,`running`,`queued`,`waiting`,`ready`,`failed`];function Zbe(e){return Xbe.find(t=>t===e)}var K7=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`queued`,label:`Queued`},{value:`waiting`,label:`Needs you`},{value:`ready`,label:`Ready to upload`},{value:`failed`,label:`Failed`}];function q7(e,t){switch(t){case`all`:return!0;case`running`:return e.status===`running`||e.status===`paused`;case`queued`:return w3(e);case`waiting`:return b3(e);case`ready`:return C3(e);case`failed`:return e.status===`failed`||e.status===`partial`}}function Qbe(e){let t={running:{tone:`running`,word:`Running`},paused:{tone:`waiting`,word:`Paused`},pending:{tone:`off`,word:`Queued`},failed:{tone:`failed`,word:`Failed`},partial:{tone:`info`,word:`Done with problems`},done:{tone:`done`,word:`Done`},canceled:{tone:`off`,word:`Canceled`}};if(b3(e))return{tone:`waiting`,word:`Waiting for you`};if(e.status===`pending`&&e.setAside===!0)return{tone:`done`,word:`Kept as is`};let n=e.status===`running`?YH(e.limitWaits):void 0;return n===void 0?t[e.status]:{tone:`waiting`,word:n}}function $be(e){let t=e.config.articlePrompt,n=e.config.voices?.book;return[n===void 0?void 0:LA(n),t===void 0||t===``?void 0:t,e.format].filter(e=>e!==void 0).join(` · `)}function exe({initialFilter:e=`all`}={}){let{api:t}=z(),n=_(),r=Oy(),i=gx(),a=N(Yy(t)),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(e),u=N({queryKey:My,queryFn:()=>Iy(t)}),d=new Set(Object.values(u.data?.samples??{}).filter(e=>e!==null)),[f,p]=(0,m.useState)(``),g=(0,m.useRef)(null),v=xx(g,`projects`),y=P({mutationFn:e=>No(t,e),onSettled:async()=>{s(void 0),await n.invalidateQueries({queryKey:B.projects})}}),b=P({mutationFn:e=>v3(t,e.project.id,e.uploaded),onError:(e,t)=>r(`${t.project.title} wasn't changed: ${e.message} Press the button again.`,`error`),onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});bx({id:`projects.show.waiting`,title:`Show projects that need you`,group:`Projects`,keywords:[`waiting`,`filter`],run:()=>l(`waiting`)}),bx({id:`projects.show.ready`,title:`Show videos ready to upload`,group:`Projects`,keywords:[`upload`,`finished`,`filter`],run:()=>l(`ready`)}),bx({id:`projects.show.failed`,title:`Show failed projects`,group:`Projects`,keywords:[`error`,`filter`],run:()=>l(`failed`)});let x=(a.data?.projects??[]).filter(e=>i.includes(e.channelId)),S=f.trim().toLowerCase(),C=x.filter(e=>q7(e,c)&&(S===``||e.title.toLowerCase().includes(S)));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Projects`,meta:a.data===void 0?void 0:`${String(x.length)} ${x.length===1?`project`:`projects`} · ${i.channel?.name??`every channel`}`,actions:(0,h.jsxs)(fS,{to:`/play`,variant:`primary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]})}),a.data?.projects.length===0?(0,h.jsx)(jB,{}):null,a.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-4 text-danger`,children:a.error.message}),a.data===void 0?a.error===null?(0,h.jsx)(nxe,{}):null:a.data.projects.length===0?(0,h.jsx)(a0,{title:`No projects yet`,actions:(0,h.jsx)(fS,{to:`/play`,variant:`primary`,children:`Make your first video`}),children:`Set up a run on Play: pick a template, type a topic and start.`}):(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsxs)(t0,{label:`Project list`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`div`,{className:`relative w-full max-w-[320px]`,children:[(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{type:`search`,ref:g,"aria-label":`Search projects`,"aria-keyshortcuts":Mx(v),placeholder:`Search projects`,value:f,onChange:e=>p(e.target.value),className:`sl-input pl-9`})]}),(0,h.jsx)(Ab,{label:`Show`,value:c,options:K7,onChange:l,className:`max-w-full overflow-x-auto`})]}),C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:x.length===0?`No projects in ${i.channel?.name??`this channel`} yet. Pick All channels in the rail to see the others.`:`No project matches. Clear the search or pick All.`}):(0,h.jsx)(pU,{label:`Projects`,children:C.map(e=>(0,h.jsx)(txe,{project:e,sample:d.has(e.id),onDelete:()=>s(e),onUploaded:t=>b.mutate({project:e,uploaded:t}),busy:b.isPending},e.id))})]}),(0,h.jsxs)(t0,{as:`aside`,label:`Projects at a glance`,children:[(0,h.jsxs)(`section`,{children:[(0,h.jsx)(H,{title:`At a glance`}),(0,h.jsx)(G2,{children:K7.filter(e=>e.value!==`all`).map(e=>(0,h.jsx)(K2,{label:e.label,value:String(x.filter(t=>q7(t,e.value)).length)},e.value))})]}),(0,h.jsxs)(`section`,{"aria-label":`Video queue`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Video queue`,info:`play.queue`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Videos started together, in the order they run, are on the calendar.`}),(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/calendar`,children:`Open calendar`})})]})]})]}),y.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`mt-3 text-small text-danger`,children:y.error.message}),(0,h.jsx)(jy,{open:o!==void 0,title:o===void 0?``:`Delete "${o.title}"?`,consequence:`Moves the project to the trash for 30 days. Restore it or delete it for good in Settings → Trash.`,confirmLabel:`Delete project`,cancelLabel:`Keep it`,pending:y.isPending,onConfirm:()=>{o!==void 0&&y.mutate(o.id)},onCancel:()=>s(void 0)})]})}function txe({project:e,sample:t,onDelete:n,onUploaded:r,busy:i}){let a=Qbe(e),o=e.status===`running`;return(0,h.jsx)(mU,{title:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),t?(0,h.jsx)(vS,{children:`Sample`}):null]}),meta:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:`${$be(e)} · started ${ku(e.createdAt)}`}),o?(0,h.jsx)(q2,{value:e.progress,label:`${e.title} progress`,valueText:`${String(Math.round(e.progress*100))}% done`,className:`max-w-[240px]`}):null]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:a.tone,children:[a.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`${e.title}: ${a.word}`})]}),C3(e)?(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!0),children:`Mark uploaded`}):null,C3(e)?(0,h.jsx)(V,{id:`project.mark-uploaded`}):e.uploadedAt===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(vS,{children:`Uploaded`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Mark ${e.title} not uploaded`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!1),children:`Undo`})]}),(0,h.jsx)(wy,{label:`Delete ${e.title}`,size:`small`,disabled:o,disabledReason:`Cancel the run first, then delete it.`,onClick:n,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function nxe(){return(0,h.jsx)(`ul`,{"aria-label":`Loading projects`,className:`sl-list m-0 list-none p-0`,children:[0,1,2,3,4,5].map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,"data-slot":`skeleton-row`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-2/5 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[10px] w-1/4 rounded-control bg-sunken`})]}),(0,h.jsx)(`span`,{className:`h-[10px] w-16 rounded-control bg-sunken`})]},e))})}var rxe=`Prepare restrained delivery cues for a documentary narrator. Let the facts carry the scene. Use a measured pace and make only occasional changes where the supplied wording clearly calls for emphasis, reflection or tension. Prefer no cue to an unnecessary cue. Avoid theatrical emotion, invented reactions and routine laughter or sighs. Never rewrite, summarize, translate or add spoken words. Return only the cue annotations required by the supplied format contract.`;function J7({promptId:e,kind:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=lI(),s=N(nb(i)),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=oP(JSON.stringify(e===void 0?[`new`,t,n??null]:[`prompt`,e])),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(void 0),b=v!==void 0,[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),T=s.data?.prompts,E=e??n,D=E===void 0?void 0:T?.find(e=>e.id===E),O=D===void 0?{kind:t,name:``,body:``}:e===void 0?{kind:D.kind,name:`${D.name} copy`,body:D.body}:{kind:D.kind,name:D.name,body:D.body},k=d??v??O,A=P({mutationFn:t=>xs(i,t,e),onSuccess:async(e,t)=>{if(!e.ok){g(e.fields);return}y(e.value),f(e=>e===t?void 0:e),o({type:`prompt-saved`,id:e.value.id,kind:e.value.kind}),await a.invalidateQueries({queryKey:nb(i).queryKey})}}),ee=P({mutationFn:e=>Cs(i,e),onSuccess:async()=>{S(!1),f(void 0),await a.invalidateQueries({queryKey:nb(i).queryKey}),r(k.kind)}}),te=P({mutationFn:({id:e,on:t})=>Ss(i,e,t),onSettled:async()=>{await a.invalidateQueries({queryKey:nb(i).queryKey})}});X2(b,()=>{r(k.kind)});let ne=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},j=t3(k,p),re=n3(j),M=a3(k.body),ie=k.body.trim()===``?[]:r3(j),ae=k.name.trim()===``?[]:i3(j);return cI({promptNamed:k.name.trim()!==``&&ae.length===0,promptBodyReady:k.body.trim()!==``&&ie.length===0,promptHasKeywords:M.length>0&&ie.length===0,promptSaveReady:re===void 0&&!A.isPending&&!b,promptSaving:A.isPending||b,promptIsArticle:k.kind===`article`,promptIsImage:k.kind===`image`}),s.error===null?E!==void 0&&T===void 0?(0,h.jsx)($2,{}):E!==void 0&&D===void 0?(0,h.jsx)(X7,{kind:t,children:`That prompt is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:k.kind},children:`Prompts`})}),title:e===void 0?`New prompt`:`Edit prompt`,meta:`${_V(k.kind)} prompt`}),(0,h.jsxs)(`div`,{"data-tour":`prompt-editor`,className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{"data-tour":`prompt-name`,className:`min-w-[min(100%,240px)] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.prompt.name`,...ae.length===0?{}:{error:ae.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:k.name,onChange:e=>{ne({...k,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Kind`,value:k.kind,options:gV,tip:`library.prompt.kind`,onPick:e=>{ne({...k,kind:e},`name`)}})]}),(0,h.jsxs)(`div`,{"data-tour":`prompt-body`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex min-h-8 items-end justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:ixe[k.kind],label:`${_V(k.kind)} prompt body`,className:`-my-1`})]}),Y7(k.kind)?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=Y7(k.kind);e!==void 0&&(k.body.trim()===``?ne({...k,body:e.body},`body`):w(!0))},children:Y7(k.kind)?.label}),(0,h.jsx)(V,{id:`library.prompt.starter`,label:Y7(k.kind)?.label})]}):null]}),(0,h.jsx)(s3,{id:c,value:k.body,invalid:ie.length>0,describedBy:ie.length===0?void 0:l,onChange:e=>{ne({...k,body:e},`body`)}})]}),k.kind===`image`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e!==void 0&&D?.kind===`image`?(0,h.jsx)(kb,{checked:te.isPending?te.variables.on:D.photorealistic===!0,disabled:te.isPending,onChange:t=>te.mutate({id:e,on:t}),label:`Draws photorealistic pictures`,tip:`library.prompt.photorealistic`}):(0,h.jsxs)(`span`,{className:`flex items-center gap-1 text-small text-ink-2`,children:[`Save this Image prompt first, then choose whether it draws photorealistic pictures.`,(0,h.jsx)(V,{id:`library.prompt.photorealistic`})]}),te.error===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small text-danger`,children:`Couldn't change Draws photorealistic pictures: ${te.error.message} Press the switch again.`})]}):null,(0,h.jsx)(`div`,{"data-tour":`prompt-save`,children:(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{S(!0)},blocked:re,blockedId:u,pending:A.isPending,saved:b,cancel:(0,h.jsx)(fS,{to:`/prompts`,search:{kind:k.kind},onClick:()=>{f(void 0)},variant:`secondary`,children:`Cancel`}),errors:[A.error,ee.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{A.mutate(k)}})})]}),(0,h.jsx)(`div`,{"data-tour":`prompt-slots`,className:m4,children:(0,h.jsx)(Y4,{slots:M,body:k.body,lint:ie,lintId:l})})]}),(0,h.jsx)(jy,{open:C,title:`Replace this prompt body?`,consequence:`The starter replaces the text in this editor. Nothing is saved until you choose Save.`,confirmLabel:`Use starter`,tone:`primary`,onConfirm:()=>{let e=Y7(k.kind);e!==void 0&&ne({...k,body:e.body},`body`),w(!1)},onCancel:()=>w(!1)}),(0,h.jsx)(jy,{open:x,title:`Delete "${k.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:ee.isPending,onConfirm:()=>{e!==void 0&&ee.mutate(e)},onCancel:()=>{S(!1)}})]}):(0,h.jsx)(X7,{kind:k.kind,children:s.error.message})}var ixe={article:`library.prompt.body.article`,image:`library.prompt.body.image`,thumbnail:`library.prompt.body.thumbnail`,narration:`library.prompt.body.narration`,description:`library.prompt.body.description`,shorts:`library.prompt.body.shorts`,review:`library.prompt.body.review`,script:`library.prompt.body.script`};function Y7(e){if(e===`narration`)return{label:`Use Documentary Starter`,body:rxe};if(e===`description`)return{label:`Use Built-in Starter`,body:Che};if(e===`shorts`)return{label:`Use Built-in Starter`,body:Gk}}function X7({kind:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:e},children:`Back to Prompts`}),children:t})}function axe({kind:e,onKind:t,onUseInPlay:n,playBlocked:r}){let{api:i}=z(),a=_(),o=N(nb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=xx(l,`prompts`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=P({mutationFn:e=>Cs(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:B.prompts})}}),x=async(e,t)=>{let n=await xs(i,{kind:e.kind,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:B.prompts}),n.ok?null:q4(n.fields)},S=o.data?.prompts.filter(t=>t.kind===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B4,{action:(0,h.jsx)(sxe,{kind:e}),children:[(0,h.jsx)(CV,{type:`search`,ref:l,"aria-label":`Search prompts`,"aria-keyshortcuts":Mx(u),placeholder:`Search prompts`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsx)(TV,{"aria-label":`Prompt kind`,value:e,className:`w-full sm:w-56`,options:gV,onChange:e=>{let n=gV.find(t=>t.value===e.target.value);n!==void 0&&t(n.value)}}),(0,h.jsx)(V,{id:`library.prompt.kind`})]})]}),o.error===null?null:(0,h.jsx)(R4,{what:`prompts`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(L4,{label:`Prompts`}):null:S.length===0?(0,h.jsxs)(a0,{title:`No ${_V(e).toLowerCase()} prompts yet`,children:[`A prompt is text with `,`{{keywords}}`,`; each keyword becomes a field on Play.`]}):(0,h.jsx)(jq,{className:F4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${_V(e).toLowerCase()} prompts match "${s.trim()}".`}):(0,h.jsx)(pU,{label:`Prompts`,children:w.map(e=>(0,h.jsx)(mU,{className:I4,title:(0,h.jsx)(J4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:oxe(e),selected:e.id===T?.id,actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e.kind,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(M4,{item:`prompt`,id:T.id,name:T.name,kicker:`${_V(T.kind)} prompt`,meta:`Updated ${P4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:T.id},size:`small`,children:`Edit prompt`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The prompt wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(O4,{item:`prompt`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(jy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function oxe(e){return`${_V(e.kind)} · ${N4(e.slots.length,`keyword`)} · updated ${P4(e.updatedAt)}`}function sxe({kind:e}){return(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e},variant:`primary`,children:`New prompt`})}var cxe={template:`Template`,schedule:`Schedule`,draft:`Draft`,project:`Project`};function Z7(e){let t=[e.added.length>0?`${e.added.length} new`:null,e.priced.length>0?`${e.priced.length} repriced`:null,e.retired.length>0?`${e.retired.length} retired`:null].filter(e=>e!==null);return t.length===0?`No changes`:t.join(`, `)}function lxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:H1.catalogue,queryFn:()=>cde(e),refetchInterval:3e4}),i=N({queryKey:H1.retired,queryFn:()=>G1(e)}),a=async()=>{await Promise.all([t.invalidateQueries({queryKey:[`provider-models`]}),t.invalidateQueries({queryKey:H1.retired})])},o=P({mutationFn:()=>lde(e),onSuccess:async e=>{t.setQueryData(H1.catalogue,e),n(e.sync?.warning??`Model list checked: ${Z7(e.sync?.changes??uxe)}.`,e.sync?.warning?`error`:`success`),await a()}}),s=P({mutationFn:()=>ude(e),onSuccess:async e=>{n(`Catalogue replaced with the published file.`,`success`),t.setQueryData(H1.catalogue,e),await a()}}),c=async()=>{await Promise.all([t.invalidateQueries({queryKey:H1.retired}),t.invalidateQueries({queryKey:Lq}),t.invalidateQueries({queryKey:TH}),t.invalidateQueries({queryKey:[`play-drafts`]}),t.invalidateQueries({queryKey:[`projects`]}),t.invalidateQueries({queryKey:[`project`]})])},l=P({mutationFn:t=>K1(e,t),onSuccess:c}),u=P({mutationFn:()=>dde(e),onSuccess:async e=>{n(e.failed.length===0?`Switched ${e.switched} ${e.switched===1?`use`:`uses`}.`:`Switched ${e.switched}; ${e.failed.length} could not be switched: ${e.failed[0]?.message??``}`,e.failed.length===0?`success`:`error`),await c()}}),d=r.data?.sync,f=i.data??[],p=f.filter(e=>e.blocked===null&&e.replacement!==null),m=o.error?.message??s.error?.message??r.error?.message??r.data?.warning??d?.warning??null;return bx({id:`settings.check-models`,title:`Check for new models`,group:`Settings`,context:`Models`,keywords:[`catalogue`,`prices`,`retired`],run:()=>{!o.isPending&&r.data?.path&&o.mutate()}}),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Model catalogue`,info:`settings.models.catalogue`,children:[(0,h.jsx)(R,{disabled:o.isPending||!r.data?.path,onClick:()=>o.mutate(),children:o.isPending?`Checking…`:`Check now`}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:s.isPending||!r.data?.path,onClick:()=>s.mutate(),children:s.isPending?`Replacing…`:`Replace with published file`}),(0,h.jsx)(V,{id:`settings.models.replace`})]})]}),(0,h.jsxs)(`dl`,{className:`m-0 grid gap-x-6 border-t border-line text-small sm:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Catalogue file`}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 border-b border-line pb-3 break-all font-mono text-ink-2 sm:pt-3`,children:r.data?.path??`Not available`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Verified`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:r.data?.updatedAt??`date unavailable`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Last checked`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:d?.checkedAt?`${new Date(d.checkedAt).toLocaleString()} · ${Z7(d.changes)}`:`Not checked yet`})]}),d!==void 0&&d.changes.retired.length+d.changes.added.length>0?(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1 text-small text-ink-2`,children:[d.changes.added.length>0?(0,h.jsxs)(`span`,{children:[`New: `,d.changes.added.map(e=>e.name).join(`, `)]}):null,d.changes.retired.length>0?(0,h.jsxs)(`span`,{children:[`Retired: `,d.changes.retired.map(e=>e.name).join(`, `)]}):null]}):null,m===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-3 text-body text-danger`,children:m})]}),(0,h.jsxs)(`section`,{"aria-label":`Retired models in use`,children:[(0,h.jsx)(H,{title:`Retired models in use`,info:`settings.models.retired`,children:(0,h.jsx)(R,{variant:`primary`,disabled:u.isPending||p.length===0,onClick:()=>u.mutate(),children:u.isPending?`Switching…`:`Switch all`})}),i.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:i.error.message}):null,l.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:l.error.message}):null,f.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i.isPending?`Looking…`:`Nothing uses a retired model.`}):(0,h.jsx)(`ul`,{"aria-label":`Retired models in use`,className:`sl-list m-0 list-none p-0`,children:f.map(e=>(0,h.jsxs)(`li`,{className:`sl-row max-sm:grid-cols-1`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:cxe[e.kind]}),` `,(0,h.jsx)(`span`,{className:`font-semibold`,children:e.name})]}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s0[e.slot],`: `,e.model,` (`,e.why===`retired`?`retired`:`no longer listed`,`)`]}),e.blocked===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e.blocked})]}),(0,h.jsx)(Ey,{children:(0,h.jsx)(R,{size:`small`,disabled:e.blocked!==null||e.replacement===null||l.isPending,onClick:()=>l.mutate(e),children:e.replacement===null?`No replacement`:`Switch to ${e.replacement.name}`})})]},e.key))})]})]})}var uxe={added:[],retired:[],priced:[]},dxe={ok:`Ready`,warning:`Check`,problem:`Needs fixing`,unused:`Not set up`},fxe={ok:`done`,warning:`waiting`,problem:`failed`,unused:`off`},pxe={ok:`text-ink-2`,warning:`text-waiting`,problem:`text-danger`,skipped:`text-ink-3`};function Q7(){let{api:e}=z();return P({mutationFn:()=>W1(e)})}function mxe(e){let{api:t}=z(),[n,r]=(0,m.useState)({byId:new Map});return{one:P({mutationFn:e=>W1(t,e),onSuccess:t=>{r(n=>{let r=new Map(n.after===e?n.byId:[]);for(let e of t.providers)r.set(e.id,e);return{after:e,byId:r}})}}),latest:t=>n.after===e?n.byId.get(t.id)??t:t}}function hxe({run:e}={}){let t=Q7(),n=e??t,r=n.data,i=mxe(r?.checkedAt),a=r?.providers.filter(e=>e.state!==`unused`).map(i.latest)??[],o=r?.providers.filter(e=>e.state===`unused`)??[];return(0,h.jsxs)(`section`,{"aria-label":`Health check`,children:[(0,h.jsx)(H,{title:`Health check`,info:`settings.health`,children:e===void 0?(0,h.jsx)(R,{disabled:n.isPending,onClick:()=>{n.mutate()},children:n.isPending?`Checking…`:`Check all`}):void 0}),n.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:[`The health check didn't finish: `,n.error.message,` Press Check all to try again.`]}),i.one.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:`The check didn't finish: ${i.one.error.message} Press Check again on the provider to try again.`}),r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:n.isPending?`Checking every provider…`:`Not checked yet.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ul`,{"aria-label":`Health by provider`,className:`sl-list m-0 list-none p-0`,children:a.map(e=>(0,h.jsxs)(`li`,{className:`sl-row grid-cols-1 gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:e.displayName}),(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(_S,{tone:fxe[e.state],children:dxe[e.state]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Check ${e.displayName} again`,disabled:i.one.isPending,onClick:()=>{i.one.mutate(e.id)},children:i.one.isPending&&i.one.variables===e.id?`Checking…`:`Check again`})]})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-1 p-0`,children:e.checks.map(e=>(0,h.jsxs)(`li`,{className:L(`text-small`,pxe[e.state]),children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.label,`:`]}),` `,e.detail]},e.label))})]},e.id))}),(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:o.length===0?`Checked at ${new Date(r.checkedAt).toLocaleTimeString()}.`:`Not set up and not used anywhere: ${o.map(e=>e.displayName).join(`, `)}.`})]})]})}var $7={openrouter:`settings.provider.openrouter`,"claude-code":`settings.provider.claude-code`,codex:`settings.provider.codex`,gemini:`settings.provider.gemini`,elevenlabs:`settings.provider.elevenlabs`,"openai-tts":`settings.provider.openai-tts`,cartesia:`settings.provider.cartesia`,inworld:`settings.provider.inworld`,"system-voice":`settings.provider.system-voice`,"google-tts":`settings.provider.google-tts`,fal:`settings.provider.fal`,replicate:`settings.provider.replicate`,"openai-image":`settings.provider.openai-image`,"google-image":`settings.provider.google-image`,"codex-image":`settings.provider.codex-image`};function e9(e){return tF(e)?{tone:`done`,word:`Ready`}:e.installed?{tone:`waiting`,word:`Needs attention`}:{tone:`off`,word:`Not found`}}function gxe({provider:e,readiness:t,kind:n}){let{api:r}=z(),i=_(),a=(0,m.useId)(),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(!1),u=e.cliPath?.configured??null,d=e.cliPath?.managedOnHost===!0,f=e.id===`claude-code`?`claude`:e.id===`codex-image`?`codex`:e.id,p=e.cliPath?.command??f,g=o??u??``,v=tF(t),y=P({mutationFn:t=>Yo(r,e.id,t),onMutate:()=>l(!1),onSuccess:async e=>{i.setQueryData(B.providers,t=>t?{...t,providers:t.providers.map(t=>t.id===e.id?e:t)}:void 0),s(void 0),l(!0),await i.invalidateQueries({queryKey:B.providers})}});(0,m.useEffect)(()=>{if(!c)return;let e=setTimeout(()=>l(!1),Y2);return()=>clearTimeout(e)},[c]);let[b,x]=(0,m.useState)(!1),S=(0,m.useId)();return(0,h.jsxs)(`section`,{"aria-labelledby":a,"data-ready":v,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:a,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:$7[e.id],label:e.displayName})]}),(0,h.jsxs)(`p`,{className:`sl-section-head__meta`,children:[n,` · command line, no key needed`]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:e9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:_xe(t,u)})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Command`}),(0,h.jsx)(EV,{className:`min-w-0 truncate`,title:p,children:p})]})]}),(0,h.jsxs)(Ey,{children:[d?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-small text-ink-2`,children:[`Managed on host`,(0,h.jsx)(V,{id:`settings.cli.managed-on-host`})]}):(0,h.jsx)(R,{"aria-expanded":b,"aria-controls":S,onClick:()=>x(e=>!e),children:b?`Close path`:`Change path`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:c?(0,h.jsx)(Z2,{}):null})]}),d||!b?null:(0,h.jsx)(`form`,{id:S,onSubmit:e=>{e.preventDefault(),y.isPending||y.mutate(g)},children:(0,h.jsx)(xV,{label:`Executable path`,tip:`settings.cli.path`,help:(0,h.jsxs)(h.Fragment,{children:[`Leave blank to find `,(0,h.jsx)(EV,{children:f}),` on PATH. Use an absolute path without quotes or arguments.`]}),error:y.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{autoComplete:`off`,spellCheck:!1,maxLength:4096,"aria-label":`${e.displayName} Executable path`,className:`min-w-0 flex-1 basis-[220px]`,placeholder:f,value:g,disabled:y.isPending,onChange:e=>{s(e.target.value),l(!1),y.reset()}}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,"aria-label":`Save ${e.displayName} path`,disabled:y.isPending,children:y.isPending?`Checking…`:`Save path`})]})})})]})}function _xe(e,t){return e.issue===void 0?e.installed?e.version===void 0?`Installed`:`Installed, version ${e.version}`:t===null?`Not found on PATH`:`Not found at saved path`:e.issue}var vxe=[`providers`,`system-voice`,`voices`];async function yxe(e){return F(await e.fetch(`${e.origin}/api/providers/system-voice/voices`))}function t9(e=!0){let{api:t}=z();return N({queryKey:vxe,queryFn:()=>yxe(t),enabled:e})}function n9(e){return e.available?{tone:`done`,word:`Ready`}:{tone:`off`,word:`Not found`}}function bxe({provider:e,readiness:t}){let n=(0,m.useId)(),r=t9(t.available).data?.engines??[];return(0,h.jsxs)(`section`,{"aria-labelledby":n,"data-ready":t.available,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:n,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:$7[e.id],label:e.displayName})]}),(0,h.jsx)(`p`,{className:`sl-section-head__meta`,children:`Speech · built into this computer, no key needed`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:n9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:t.available?`Found ${t.engine??`a speech program`}. Narration with it is free; a keyed voice (ElevenLabs, OpenAI) sounds better.`:t.issue??`No speech program was found on this computer.`})]}),r.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 list-none p-0 text-small text-ink-2`,children:r.map(e=>{let t=e.voices.length;return(0,h.jsx)(`li`,{children:`${e.name}: ${t} voice${t===1?``:`s`}`},e.id)})}),t.available?(0,h.jsx)(Ey,{children:(0,h.jsx)(fS,{to:`/settings`,search:{section:`voices`},children:`Add a system voice`})}):null]})}function xxe({value:e,onPick:t}){let n=t9(),r=n.data?.engines??[];return n.data!==void 0&&r.length===0?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:n.data.issue??`No speech program was found on this computer.`}):(0,h.jsxs)(TV,{value:e,onChange:e=>{for(let n of r){let r=n.voices.find(t=>t.id===e.target.value);if(r!==void 0)return t(r)}},children:[(0,h.jsx)(`option`,{value:``,children:n.data===void 0?`Looking for voices…`:`Pick a voice`}),r.map(e=>(0,h.jsx)(`optgroup`,{label:e.name,children:e.voices.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.language===void 0?e.name:`${e.name} (${e.language})`},e.id))},e.id))]})}var r9=[`llm`,`tts`,`image`],i9={llm:`Text`,tts:`Speech`,image:`Images`},Sxe=`••••••••••••`;function Cxe(e){return tF(e.readiness)}function wxe(e){return e.readiness.kind===`cli`?e9(e.readiness):e.readiness.kind===`local`?n9(e.readiness):e.readiness.hasKey?{tone:`done`,word:`Key saved`}:{tone:`off`,word:`No key`}}function Txe(){let{api:e}=z(),t=N(eb(e)),[n,r]=(0,m.useState)(void 0),i=(0,m.useRef)(null),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{n!==void 0&&a.current&&(a.current=!1,typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&i.current?.scrollIntoView?.({block:`start`,behavior:`smooth`}))},[n]);let o=r9.flatMap(e=>(t.data?.providers??[]).filter(t=>t.family===e)),s=o.find(e=>!Cxe(e))??o[0];if(n===void 0&&s!==void 0&&r(s.id),t.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message});if(t.data===void 0)return(0,h.jsx)(Dxe,{});let c=o.find(e=>e.id===n)??s,l=o.every(e=>e.readiness.kind!==`keyed`||!e.readiness.hasKey),u=e=>{a.current=!0,r(e)};return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:[l?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Paste a key to make its provider selectable on Play.`}):null,r9.map(e=>(0,h.jsxs)(`section`,{"data-tour":`keys-${e}`,"aria-labelledby":`keys-${e}-title`,className:`grid items-start gap-x-8 gap-y-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{id:`keys-${e}-title`,title:i9[e],size:`small`,className:`pb-2`}),(0,h.jsx)(pU,{label:`${i9[e]} providers`,children:o.filter(t=>t.family===e).map(e=>{let t=wxe(e);return(0,h.jsx)(mU,{title:e.displayName,meta:e.readiness.kind===`cli`?`Command line`:e.readiness.kind===`local`?`Built in, no key`:`API key`,selected:e.id===c?.id,onSelect:()=>u(e.id),actions:(0,h.jsx)(_S,{tone:t.tone,children:t.word})},e.id)})})]}),c===void 0||c.family!==e?null:(0,h.jsx)(`div`,{ref:i,className:`min-w-0 scroll-mt-4`,children:c.readiness.kind===`cli`?(0,h.jsx)(gxe,{provider:c,readiness:c.readiness,kind:i9[c.family]},c.id):c.readiness.kind===`local`?(0,h.jsx)(bxe,{provider:c,readiness:c.readiness},c.id):(0,h.jsx)(Exe,{provider:c,hasKey:c.readiness.hasKey},c.id)})]},e))]})}function Exe({provider:e,hasKey:t}){let{api:n}=z(),r=_(),i=(0,m.useId)(),a=(0,m.useId)(),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(void 0),C=(0,m.useId)(),w=VF[e.id],T=o.trim(),E=async()=>{b(!0),S(void 0);try{S(await sde(n,e.id,T===``?void 0:T))}catch(e){p(e instanceof Error?e.message:String(e))}finally{b(!1)}},D=async()=>{l(!0),p(void 0);try{await Jo(n,e.id,o),s(``),d(!0),S(void 0),await r.invalidateQueries({queryKey:B.providers})}catch(e){p(e instanceof Error?e.message:String(e))}finally{l(!1)}},O=P({mutationFn:()=>Xo(n,e.id),onSuccess:async()=>{v(!1),p(void 0),await r.invalidateQueries({queryKey:B.providers})},onError:e=>{v(!1),p(e.message)}});(0,m.useEffect)(()=>{if(!u)return;let e=setTimeout(()=>{d(!1)},Y2);return()=>{clearTimeout(e)}},[u]);let k=[t?a:void 0,x===void 0?void 0:C].filter(e=>e!==void 0).join(` `);return(0,h.jsxs)(`section`,{"aria-labelledby":i,"data-ready":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{as:`h3`,size:`default`,id:i,title:t?e.displayName:`Set up ${e.displayName}`,info:$7[e.id],infoLabel:e.displayName,meta:`${i9[e.family]} · ${t?`a key is saved`:`needs an API key`}`,className:`pb-0`}),w===void 0?null:t?(0,h.jsxs)(`details`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Where to get a key`}),(0,h.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:(0,h.jsx)(a9,{guide:w})})]}):(0,h.jsx)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:(0,h.jsx)(a9,{guide:w})}),(0,h.jsx)(xV,{label:`${e.displayName} API key`,tip:`settings.providers.api-key`,help:`Stored on this computer only. Never in backups or exports.`,error:f,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`password`,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 basis-[200px]`,"aria-describedby":k===``?void 0:k,placeholder:t?Sxe:`Paste API key`,value:o,onChange:e=>{s(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,"aria-label":`Save ${e.displayName} key`,disabled:o.trim()===``||c,onClick:()=>{D()},children:`Save`})]})}),t?(0,h.jsx)(`span`,{id:a,className:`sr-only`,children:`A key is stored for this provider.`}):null,x===void 0?null:(0,h.jsx)(`p`,{id:C,role:x.ok?`status`:`alert`,className:L(`m-0 text-small`,x.ok?`text-accent-ink`:`text-danger`),children:x.message}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{"aria-label":`Test ${e.displayName} key`,disabled:!t&&T===``||y,disabledReason:`Paste a key first.`,onClick:()=>{E()},children:y?`Testing…`:`Test`}),(0,h.jsx)(V,{id:`settings.providers.test-key`,label:`Test`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Remove ${e.displayName} key`,disabled:!t,onClick:()=>{v(!0)},children:`Remove`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:u?(0,h.jsx)(Z2,{}):null})]}),(0,h.jsx)(jy,{open:g,title:`Remove the ${e.displayName} key?`,consequence:`Projects that used this provider cannot retry until a key is saved.`,confirmLabel:`Remove key`,pending:O.isPending,onConfirm:()=>{O.mutate()},onCancel:()=>{v(!1)}})]})}function a9({guide:e}){let t=(e,t)=>(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`underline`,children:t});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ol`,{className:`m-0 list-decimal space-y-1 pl-5`,children:e.steps.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`Sign up: `,t(e.signUp.url,e.signUp.label),`. Make the key:`,` `,t(e.keyPage.url,e.keyPage.label),`.`,e.billing===void 0?null:(0,h.jsxs)(h.Fragment,{children:[` Credit: `,t(e.billing.url,e.billing.label),`.`]})]}),(0,h.jsx)(`p`,{className:`m-0`,children:e.permissions}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`More in the provider's `,t(e.docs.url,e.docs.label),`. After saving, choose Test.`]})]})}function Dxe(){return(0,h.jsxs)(`div`,{className:`grid items-start gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,role:`status`,"aria-label":`Loading providers`,children:[(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:[[`llm`,4],[`tts`,5],[`image`,5]].map(([e,t])=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`span`,{className:`mb-2 block h-3 w-16 rounded-control bg-raised`}),(0,h.jsx)(`div`,{className:`sl-list`,children:Array.from({length:t},(t,n)=>`${e}-${n}`).map(e=>(0,h.jsxs)(`div`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`h-4 w-32 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-4 w-20 rounded-control bg-raised`})]},e))})]},e))}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-6 w-48 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-10 rounded-control bg-raised`})]})]})}function o9(e){return e.split(/[\s,;]+/).map(e=>e.trim().toLowerCase()).filter(e=>e!==``)}function Oxe(e){return e.languages===void 0?`Any (not known)`:e.languages.map(e=>BO(e).code===e?BO(e).name:e).join(`, `)}function kxe({voice:e}){let{api:t}=z(),n=_(),r=(0,m.useId)(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)((e.languages??[]).join(`, `)),[c,l]=(0,m.useState)(void 0),u=P({mutationFn:()=>hs(t,e.id,o9(o)),onSuccess:async e=>{if(e!==void 0){l(e.message);return}a(!1),l(void 0),await n.invalidateQueries({queryKey:B.voices})}});return i?(0,h.jsxs)(`div`,{className:`grid gap-1`,children:[(0,h.jsx)(CV,{id:r,"aria-label":`Languages of ${e.name}`,value:o,placeholder:`es, de`,"aria-invalid":c!==void 0,onChange:e=>{s(e.target.value),l(void 0)}}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:c}),u.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:u.error.message}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(R,{size:`small`,disabled:u.isPending,onClick:()=>u.mutate(),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{a(!1),l(void 0),s((e.languages??[]).join(`, `))},children:`Cancel`})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:Oxe(e)}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit the languages of ${e.name}`,onClick:()=>a(!0),children:`Edit`})]})}function Axe(){let{api:e}=z(),t=_(),n=N(tb(e)),r=N(eb(e)),[i,a]=(0,m.useState)(void 0),o=P({mutationFn:t=>_s(e,t),onSettled:async()=>{a(void 0),await t.invalidateQueries({queryKey:B.voices})}}),s=P({mutationFn:({id:t,on:n})=>gs(e,t,n),onSettled:async()=>{await t.invalidateQueries({queryKey:B.voices})}}),c=(r.data?.providers??[]).filter(e=>e.family===`tts`);if(n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});let l=n.data?.voices;return(0,h.jsxs)(`div`,{"data-tour":`voices`,className:`flex min-w-0 flex-col gap-10`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 overflow-x-auto`,children:[(0,h.jsxs)(`table`,{className:`sl-table min-w-[640px] table-fixed`,...Ob,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Voices`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:`Name`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[18%] pr-4`,children:`Provider`}),(0,h.jsx)(`th`,{scope:`col`,className:`pr-4`,children:`Voice ID`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Languages`,(0,h.jsx)(V,{id:`play.voices.languages`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[20%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Real person`,(0,h.jsx)(V,{id:`play.voices.real-person`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[96px]`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:l===void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,children:(0,h.jsx)(`span`,{className:`block h-4 w-64 rounded-control bg-raised`})})}):l.length===0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,className:`text-ink-2`,children:`Add a voice ID from your text-to-speech provider. Audio needs one to narrate.`})}):l.map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`truncate pr-4 font-semibold`,children:e.name}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:Mxe(c,e.provider)}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:e.voiceId}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(kxe,{voice:e})}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(kb,{checked:s.isPending&&s.variables.id===e.id?s.variables.on:e.imitatesRealPerson===!0,disabled:s.isPending,onChange:t=>s.mutate({id:e.id,on:t}),label:(0,h.jsx)(`span`,{className:`sr-only`,children:`${e.name} imitates a real person`}),className:`text-small`})}),(0,h.jsx)(`td`,{className:`text-right`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name}`,onClick:()=>{a(e)},children:`Remove`})})]},e.id))})]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:`Couldn't change Real person: ${s.error.message} Press the switch again.`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:o.error.message})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Add a voice`}),(0,h.jsx)(jxe,{tts:c})]}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Remove ${i.name}?`,consequence:`Projects that used this voice keep the audio they made with it.`,confirmLabel:`Remove voice`,pending:o.isPending,onConfirm:()=>{i!==void 0&&o.mutate(i.id)},onCancel:()=>{a(void 0)}})]})}function jxe({tts:e}){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(void 0),[d,f]=(0,m.useState)(void 0),p=l??e[0]?.id,g=P({mutationFn:e=>ms(t,e),onSuccess:async e=>{if(!e.ok){f(e.refusal);return}i(``),o(``),c(``),f(void 0),await n.invalidateQueries({queryKey:B.voices})}}),v=(e,t)=>{t(),d?.field===e&&f(void 0)},y=e=>d?.field===e?d.message:void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`grid items-start gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(xV,{label:`Voice name`,tip:`play.voices.name`,error:y(`name`),children:(0,h.jsx)(CV,{value:r,onChange:e=>{let t=e.target.value;v(`name`,()=>{i(t)})}})}),(0,h.jsx)(xV,{label:`Provider`,tip:`play.voices.provider`,error:y(`provider`),children:(0,h.jsxs)(TV,{value:p??``,onChange:t=>{let n=e.find(e=>e.id===t.target.value);n!==void 0&&v(`provider`,()=>{u(n.id)})},children:[e.length===0?(0,h.jsx)(`option`,{value:``,children:`No speech provider`}):null,e.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.displayName},e.id))]})}),(0,h.jsx)(xV,{label:`Voice ID`,tip:`play.voices.voice-id`,error:y(`voiceId`),...p===`inworld`?{help:`Use an Inworld voice ID, such as Dennis, or one from your workspace.`}:{},children:p===`system-voice`?(0,h.jsx)(xxe,{value:a,onPick:e=>{v(`voiceId`,()=>{o(e.id)}),r.trim()===``&&i(e.name);let t=/^([a-z]{2,3})(?:[-_]|$)/i.exec(e.language??``)?.[1];s.trim()===``&&t!==void 0&&c(t.toLowerCase())}}):p===`google-tts`?(0,h.jsx)(TV,{value:a,options:[{value:``,label:`Pick a Gemini voice`},...UF.map(e=>({value:e.name,label:`${e.name} (${e.style})`}))],onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t),r.trim()===``&&i(t)})}}):(0,h.jsx)(CV,{className:`tabular-nums`,value:a,onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t)})}})}),(0,h.jsx)(xV,{label:`Languages`,tip:`play.voices.languages`,help:`Codes such as es, de.`,error:y(`languages`),children:(0,h.jsx)(CV,{value:s,placeholder:`es, de`,onChange:e=>{let t=e.target.value;v(`languages`,()=>{c(t)})}})}),(0,h.jsx)(R,{variant:`primary`,className:`md:mt-6`,disabled:p===void 0||d!==void 0||g.isPending,onClick:()=>{if(p!==void 0){let e=o9(s);g.mutate({provider:p,name:r,voiceId:a,...e.length===0?{}:{languages:e}})}},children:`Add voice`})]}),g.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:g.error.message})]})}function Mxe(e,t){return e.find(e=>e.id===t)?.displayName??t}var s9=[`settings`,`notifications`],Nxe=`The test notification couldn't be shown: this browser only allows notifications from installed apps. Set a Notification URL below instead.`;function Pxe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Browser and phone`,info:`settings.notifications`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(Fxe,{}),(0,h.jsx)(Ixe,{}),(0,h.jsx)(Lxe,{})]})]})}function Fxe(){let e=(0,m.useSyncExternalStore)(vP,gP,()=>!1),[t,n]=(0,m.useState)(hP),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=Oy(),c=e&&t===`granted`;async function l(e){if(i(void 0),!e){_P(!1);return}o(!0);try{let e=await xP();n(e);let t=bP(e);e===`granted`?(_P(!0),gP()||i(`Browser notifications couldn't be turned on because this browser blocks site storage for Slopify. Allow site data for this address in your browser's settings, then turn Browser notifications on again.`)):i(t??`Browser notifications weren't turned on because the permission prompt was dismissed. Turn Browser notifications on again and choose Allow.`)}finally{o(!1)}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Browser notifications`,tip:`settings.notifications.browser`,checked:c,disabled:a,onChange:e=>void l(e)}),(0,h.jsx)(R,{variant:`quiet`,disabled:!c,disabledReason:`Turn Browser notifications on first.`,onClick:()=>{i(void 0);try{CP({projectId:`test`,text:UP},()=>{}),s(`Test notification sent to this browser.`,`success`)}catch{i(Nxe)}},children:`Send test notification`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Works while any Slopify tab is open.`}),r===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:r})]})}function Ixe(){let e=(0,m.useSyncExternalStore)(AP,OP,()=>!0);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Run sounds`,tip:`settings.notifications.sounds`,checked:e,onChange:kP}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`start`),children:`Play start`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`end`),children:`Play end`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`A chime when a run starts and a different one when it finishes, fails or waits for you. Works while any Slopify tab is open; set your computer's volume for how loud.`})]})}function Lxe(){let{api:e}=z(),t=_(),n=Oy(),r=(0,m.useId)(),i=N({queryKey:s9,queryFn:()=>$o(e)}),[a,o]=(0,m.useState)(void 0),s=a??i.data?.url??``,c=GP(s),l=P({mutationFn:t=>ts(e,t),onSuccess:e=>{t.setQueryData(s9,e),o(void 0),n(e.url===null?`Notification URL removed.`:`Notification URL saved.`,`success`)}}),u=P({mutationFn:t=>ns(e,t),onSuccess:()=>{n(`Test notification sent. Check the app or page behind your Notification URL.`,`success`)}}),d=c??l.error?.message??u.error?.message,f=l.isPending||u.isPending||i.data===void 0;return(0,h.jsxs)(xV,{label:`Notification URL`,tip:`settings.notifications.url`,help:`Works with no tab open, for example an ntfy topic on your phone.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`url`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:`https://ntfy.sh/your-topic`,className:`min-w-0 flex-1 basis-[220px]`,value:s,disabled:i.data===void 0,"aria-invalid":c!==void 0,"aria-describedby":d===void 0?void 0:r,onChange:e=>{l.reset(),u.reset(),o(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,disabled:f||c!==void 0||a===void 0,onClick:()=>l.mutate(s),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,disabled:f||c!==void 0||s.trim()===``,onClick:()=>u.mutate(s),children:`Send test notification`})]}),i.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The saved Notification URL couldn't be read: `,i.error.message]}),d===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:d})]})}var c9={library:`The Library of Alexandria`,audiobook:`The Wind in the Willows (audiobook)`,podcast:`The Antikythera Mechanism (podcast)`};function Rxe(){let{api:e}=z(),t=_(),n=N({queryKey:Ny,queryFn:()=>Vy(e)}),r=P({mutationFn:()=>Uy(e),onSettled:async()=>{await t.invalidateQueries({queryKey:Ny}),await t.invalidateQueries({queryKey:My}),await t.invalidateQueries({queryKey:B.projects})}}),i=r.data?.samples??n.data?.samples;return(0,h.jsxs)(`div`,{className:`mt-8`,children:[(0,h.jsx)(H,{title:`Sample projects`,info:`settings.sample.restore`}),(0,h.jsx)(pU,{label:`Sample projects`,children:Object.keys(c9).map(e=>{let t=i?.[e]??null;return(0,h.jsx)(mU,{title:c9[e],meta:t===null?`Not in your projects`:`In your projects`,actions:t===null?void 0:(0,h.jsx)(pS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:`Open`})},e)})}),(0,h.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{disabled:r.isPending,onClick:()=>r.mutate(),children:r.isPending?`Restoring…`:`Restore samples`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Puts all three back as they shipped.`})]}),(0,h.jsx)(Q1,{tone:r.error?`error`:`success`,children:r.error?.message??(r.isSuccess?`The samples are back in Projects.`:void 0)})]})}var zxe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function Bxe(e){let[t,n,r]=e.split(`-`).map(Number),i=zxe[(n??0)-1];return i===void 0||r===void 0?e:`${String(r)} ${i} ${String(t)}`}function l9(e,t){let n=[e.range===void 0?e.version:`Versions ${e.range}`,`released ${Bxe(e.date)}`].filter(e=>e!==void 0).join(`, `),r=n.charAt(0).toUpperCase()+n.slice(1);return e.version===t?`${r}. The version you are running.`:`${r}.`}function Vxe({note:e,onNote:t}){let{api:n}=z(),r=N(fI(n));if(r.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The patch notes did not load`,actions:(0,h.jsx)(R,{onClick:()=>void r.refetch(),children:`Try again`}),children:`${r.error.message} Press Try again, or reload the page.`});if(r.data===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the patch notes…`});let{notes:i,version:a}=r.data,[o,...s]=i;if(o===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:`This version of Slopify has no patch notes.`});let c=e===void 0?void 0:i.find(t=>t.id===e),l=c!==void 0&&c.id!==o.id?c:void 0;return l===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e!==void 0&&c===void 0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`There are no patch notes called "${e}" in this version. The latest are below; older ones are under Earlier versions.`}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:`Latest version`,meta:l9(o,a),info:`settings.patch-notes`}),(0,h.jsx)(wB,{id:o.id})]}),s.length===0?null:(0,h.jsxs)(`details`,{className:`max-w-prose border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`Earlier versions (${String(s.length)})`}),(0,h.jsx)(pU,{label:`Earlier versions`,className:`mt-2`,children:s.map(e=>(0,h.jsx)(mU,{title:e.title,meta:l9(e,a),onSelect:()=>t(e.id),actions:(0,h.jsx)(R,{"aria-label":`Read ${e.title}`,onClick:()=>t(e.id),children:`Read`})},e.id))})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{children:(0,h.jsxs)(R,{variant:`quiet`,onClick:()=>t(void 0),children:[(0,h.jsx)(nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Back to the latest patch notes`]})}),(0,h.jsx)(H,{title:`Earlier version`,meta:l9(l,a)}),(0,h.jsx)(wB,{id:l.id})]})}var u9=[`trash`];async function Hxe(e){return(await F(await e.client.trash.$get())).items}async function Uxe(e,t,n){return(await F(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function Wxe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await fo(r)}var Gxe={project:`Project`,prompt:`Prompt`,entry:`Intro/outro`,template:`Template`,schedule:`Schedule`};function Kxe(e){return e.kind===`entry`&&e.detail!==null?e.detail===`intro`?`Intro`:`Outro`:e.kind===`prompt`&&e.detail!==null?`Prompt · ${e.detail}`:Gxe[e.kind]}function qxe(e){return e<=0?`removed for good today`:e===1?`1 day left`:`${String(e)} days left`}var Jxe=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}),Yxe={project:[B.projects,[`calendar`]],prompt:[B.prompts],entry:[B.entries],template:[Lq],schedule:[TH,[`calendar`]]};function Xxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:u9,queryFn:()=>Hxe(e)}),[i,a]=(0,m.useState)(void 0),o=async e=>{await Promise.all([u9,...Yxe[e.kind]].map(e=>t.invalidateQueries({queryKey:e})))},s=P({mutationFn:t=>Uxe(e,t.kind,t.id),onSuccess:async(e,t)=>{await o(t),n(e.renamedFrom===null?`Restored "${e.name}".`:`Restored as "${e.name}": another item is now called "${e.renamedFrom}".`,`success`),e.kind===`schedule`&&n(`The schedule is paused. Press Resume on Schedules to run it again.`,`info`)},onError:e=>n(e.message,`error`)}),c=P({mutationFn:t=>Wxe(e,t.kind,t.id),onSuccess:async(e,t)=>{a(void 0),await o(t),n(`Deleted "${t.name}" for good.`,`success`)},onError:e=>{a(void 0),n(e.message,`error`)}}),l=r.data??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Trash`,info:`settings.trash`}),r.isPending?(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the trash…`}):r.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:r.error.message}):l.length===0?(0,h.jsx)(a0,{title:`The trash is empty`,children:`Anything you delete stays here for 30 days before it is removed for good.`}):(0,h.jsx)(pU,{label:`Deleted items`,children:l.map(e=>(0,h.jsx)(mU,{title:e.name,meta:`${Kxe(e)} · deleted ${Jxe.format(new Date(e.deletedAt))} · ${qxe(e.daysLeft)}`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>s.mutate(e),children:`Restore`}),(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>a(e),children:`Delete now`})]})},`${e.kind}:${e.id}`))}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Delete "${i.name}" for good?`,consequence:i?.kind===`project`?`The project and every file it produced are removed from disk. This cannot be undone.`:i?.kind===`schedule`?`The schedule leaves the trash and cannot be restored. Its run history stays on Schedules.`:`It is removed for good. This cannot be undone.`,confirmLabel:`Delete for good`,cancelLabel:`Keep it`,pending:c.isPending,onConfirm:()=>{i!==void 0&&c.mutate(i)},onCancel:()=>{c.isPending||a(void 0)}})]})}var Zxe=`https://github.com/GentBajko/slopify`,Qxe=`https://www.patreon.com/cw/GentBajko`,$xe=`https://buymeacoffee.com/gentbajko`;function eSe(){return[{href:Zxe,label:`GitHub`,detail:`The code, issues and releases.`,glyph:`github`},{href:Qxe,label:`Patreon`,detail:`Monthly support for the project.`,glyph:`patreon`},{href:$xe,label:`Buy Me a Coffee`,detail:`A one-off thank you.`,glyph:`coffee`},{href:`https://slopify.stream/channel.html`,label:`How I run a channel with it`,detail:`A lore channel run on Slopify, start to finish.`}]}function tSe({onWhatsNew:e}){return(0,h.jsxs)(`div`,{className:`max-w-prose`,children:[(0,h.jsx)(H,{title:`About`}),(0,h.jsx)(`p`,{className:`m-0 mb-3 text-ink-2`,children:`Slopify is free and open source, and runs on your machine with your own keys. If it saves you time, you can support it here.`}),(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1 text-small text-ink-2`,children:[`Updates: the circular-arrows button at the foot of the sidebar (at the top on a phone).`,(0,h.jsx)(V,{id:`settings.updates`})]}),e===void 0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:e,children:`What's new in this version`}),(0,h.jsx)(V,{id:`settings.whats-new`})]}),(0,h.jsx)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:`Made by Gent Bajko. Apache License 2.0: anyone who redistributes Slopify or builds on it keeps this credit.`}),(0,h.jsx)(`ul`,{"aria-label":`Links`,className:`sl-list m-0 list-none p-0`,children:eSe().map(e=>(0,h.jsx)(`li`,{className:`sl-row`,children:(0,h.jsxs)(`div`,{className:`sl-row__lead`,children:[e.glyph===void 0?(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}):(0,h.jsx)(lS,{name:e.glyph,className:`shrink-0 text-ink-2`}),(0,h.jsxs)(`div`,{className:`sl-row__text`,children:[(0,h.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,className:`font-semibold text-ink underline underline-offset-3`,children:e.label}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.detail})]})]})},e.label))})]})}var d9=[`backups`],f9=1,p9=30;function m9(){return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}function nSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=f9&&Number(t)<=p9?void 0:`Keep between ${f9} and ${p9} backups.`}function rSe(e){return{enabled:e.config.enabled,time:e.config.time,keep:String(e.config.keep),folder:e.config.folder??``}}function h9(){let{api:e}=z(),t=_(),n=Oy();return P({mutationFn:()=>ko(e),onSuccess:e=>{t.setQueryData(d9,e),n(`Backup started. Its result shows here when it finishes.`,`success`)}})}function iSe(){let{api:e}=z(),t=_(),n=N({queryKey:d9,queryFn:()=>Do(e),refetchInterval:e=>e.state.data?.running===!0&&2e3}),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Oo(e,t),onSuccess:e=>{t.setQueryData(d9,e),i(void 0),o(!0)}}),c=h9();(0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Y2);return()=>clearTimeout(e)},[a]);let l=n.data,u=r??(l===void 0?void 0:rSe(l)),d=u===void 0?void 0:nSe(u.keep),f=e=>{u!==void 0&&i({...u,...e})};return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Daily backup`,info:`settings.backups`,children:(0,h.jsx)(R,{variant:`primary`,disabled:l===void 0||l.running||c.isPending,onClick:()=>c.mutate(),children:`Back up now`})}),(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-x-4 gap-y-1 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{role:`status`,children:l===void 0?(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`}):aSe(l)}),(0,h.jsx)(`span`,{children:l===void 0?null:oSe(l)})]}),l?.status.detail?l.status.lastResult===`failed`?(0,h.jsx)(SI,{tone:`danger`,title:`Why the last backup stopped`,children:l.status.detail}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:l.status.detail}):null,c.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:c.error.message}):null]}),n.error?(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The backup settings couldn't be read: `,n.error.message]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(kb,{label:`Back up automatically`,tip:`settings.backups.auto`,checked:u?.enabled===!0,disabled:u===void 0,className:`self-start`,onChange:e=>f({enabled:e})}),(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Time of day`,tip:`settings.backups.time`,help:`${m9()} time`,children:(0,h.jsx)(CV,{type:`time`,className:`w-[140px] tabular-nums`,value:u?.time??`03:00`,disabled:u===void 0,onChange:e=>f({time:e.target.value})})}),(0,h.jsx)(xV,{label:`Keep last`,tip:`settings.backups.keep`,help:`Backups kept in the folder.`,error:d,children:(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:f9,max:p9,step:1,className:`w-[88px] tabular-nums`,value:u?.keep??`5`,disabled:u===void 0,onChange:e=>f({keep:e.target.value})})}),(0,h.jsx)(xV,{label:`Folder`,tip:`settings.backups.folder`,className:`md:col-span-2`,...l===void 0?{}:{help:sSe(l)},children:(0,h.jsx)(CV,{value:u?.folder??``,placeholder:l?.defaultFolder??``,disabled:u===void 0,onChange:e=>f({folder:e.target.value})})})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:u===void 0||d!==void 0||s.isPending,onClick:()=>{u!==void 0&&(o(!1),s.mutate({enabled:u.enabled,time:u.time,timeZone:m9(),keep:Number(u.keep.trim()),folder:u.folder.trim()===``?null:u.folder.trim()}))},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 basis-full text-small text-danger`,children:s.error.message})]})]})]})}function g9(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function aSe(e){if(e.running)return`Backing up now…`;let{status:t}=e,n=t.lastSuccessAt===null?`No backup yet.`:`Last backup ${g9(t.lastSuccessAt)}${t.lastSuccessBytes===null?``:`, ${_9(t.lastSuccessBytes)}`}.`;return t.lastResult===`failed`&&t.lastAttemptAt!==null?`${n} The backup at ${g9(t.lastAttemptAt)} failed.`:t.lastResult===`waiting`?`${n} Waiting for projects to finish.`:n}function oSe(e){return e.config.enabled?e.overdue?`Next: shortly.`:e.nextRunAt===null?``:`Next: ${g9(e.nextRunAt)}.`:`Automatic backups are off.`}function sSe(e){let t=`${e.files.length} backup${e.files.length===1?``:`s`} here (${_9(e.files.reduce((e,t)=>e+t.bytes,0))}).`;return e.hostFolder===null?`Inside Slopify's Docker volume, not on your computer. Leave Folder empty to save backups in the Backups folder on your computer. ${t}`:`${e.config.folder===null?`Empty uses the default: `:`On your computer: `}${e.hostFolder}. ${t}`}function _9(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var v9=[`storage-files`];function cSe({usageQueryKey:e}){let{api:t}=z(),n=_(),r=Oy(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(),u=N({queryKey:v9,queryFn:()=>Io(t),refetchInterval:e=>b9(e.state.data)?1e3:!1}),d=P({mutationFn:e=>Lo(t,e),onMutate:()=>l(void 0),onSuccess:e=>{n.setQueryData(v9,e),a(!1)},onError:e=>l(e.message)}),f=P({mutationFn:()=>Ro(t),onSuccess:e=>{e.opened||r(`Your files are in ${e.path}.`,`info`)},onError:e=>r(e.message,`error`)}),p=u.data,g=b9(p),v=p?.move?.phase;if((0,m.useEffect)(()=>{v===`done`&&n.invalidateQueries({queryKey:e})},[v,n,e]),p===void 0)return(0,h.jsx)(`div`,{children:(0,h.jsx)(H,{title:`Your files`,meta:u.error?`Where your files are is unavailable. Reload the page to try again.`:`Loading…`})});if(p.docker)return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Your files`,meta:p.folder??`The Docker project folder isn't set up.`,info:`settings.files.docker`,children:(0,h.jsx)(R,{disabled:p.folder===null||f.isPending,onClick:()=>f.mutate(),children:`Open folder`})}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),p.dockerCommand===null?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[`To move your projects to Documents/Slopify, run this on the computer running Docker (or use `,(0,h.jsx)(EV,{children:`--projects-dir <folder>`}),` for another folder):`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(EV,{className:`min-w-0 break-all`,children:p.dockerCommand}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=p.dockerCommand??``;navigator.clipboard.writeText(e).then(()=>r(`Command copied.`,`success`)).catch(()=>r(`Copying failed: this browser doesn't allow it here. Select the command and copy it yourself.`,`error`))},children:`Copy command`})]})]})]})]});let y=v===`failed`||v===`interrupted`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Your files`,meta:p.folder,info:`settings.files`,children:[p.inDocuments||p.documentsRoot===null?null:(0,h.jsx)(R,{variant:`primary`,disabled:g||d.isPending,onClick:()=>d.mutate(`documents`),children:`Move to Documents/Slopify`}),(0,h.jsx)(R,{disabled:f.isPending,onClick:()=>f.mutate(),children:`Open folder`}),(0,h.jsx)(R,{variant:`quiet`,disabled:g||d.isPending,onClick:()=>{a(e=>!e),l(void 0)},children:`Choose another folder`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),i?(0,h.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),d.mutate(o)},children:[(0,h.jsx)(xV,{label:`New folder`,tip:`settings.files.new-folder`,help:`The full path; it must be empty or new.`,error:c,className:`min-w-0 flex-1 basis-80`,children:(0,h.jsx)(CV,{value:o,placeholder:p.documentsRoot??`/home/you/Videos/Slopify`,onChange:e=>s(e.target.value)})}),(0,h.jsx)(R,{type:`submit`,disabled:o.trim()===``||d.isPending,children:`Move here`})]}):c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:c}),p.move===null?null:g?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[p.move.phase===`copying`?`Copying`:`Checking the copy of`,` your files to`,` `,p.move.target,`: `,p.move.files,` of `,p.move.totalFiles,` files (`,Y5(p.move.bytes),` of `,Y5(p.move.totalBytes),`). Keep Slopify running until it finishes.`]}),(0,h.jsx)(q2,{label:p.move.phase===`copying`?`Files copied`:`Files checked`,value:p.move.totalBytes===0?0:p.move.bytes/p.move.totalBytes})]}):y?(0,h.jsx)(SI,{tone:v===`failed`?`danger`:`waiting`,title:v===`failed`?`Moving your files to ${p.move.target} stopped`:`Moving your files to ${p.move.target} didn't finish`,actions:(0,h.jsx)(R,{disabled:d.isPending,onClick:()=>d.mutate(p.move?.target??``),children:`Continue moving`}),children:p.move.error??`Slopify was stopped before the copy was checked, so it still uses the old folder. Continue moving picks up where it left off.`}):v===`done`&&p.move.oldFolder!==null?(0,h.jsxs)(SI,{tone:`info`,title:`Your files are now in ${p.move.target}`,children:[`Every file was copied and checked. The old folder `,p.move.oldFolder,` still has a copy; once your projects open fine, you can delete it to free the space.`]}):null]})]})}function y9({view:e}){let t=[[`Projects`,e.projects],[`Automatic backups`,e.backups],[`Exports`,e.exports]].filter(e=>e[1]!==null);return(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1`,children:t.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-3`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-all`,children:t})]},e))})}function b9(e){return e?.move?.phase===`copying`||e?.move?.phase===`verifying`}function lSe(){let{api:e}=z(),t=N($y(e));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[t.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message}),t.data===void 0?t.error===null?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(gSe,{cells:5}),(0,h.jsx)(_Se,{})]}):null:(0,h.jsx)(dSe,{usage:t.data})]})}var uSe=[{id:`stage`,header:`Stage`,cell:e=>nF[e.stage]},{id:`model`,header:`Provider · model`,cell:e=>fSe(e)},{id:`in`,header:`Tokens in`,numeric:!0,cell:e=>x9.format(e.tokensIn)},{id:`out`,header:`Tokens out`,numeric:!0,cell:e=>x9.format(e.tokensOut)}];function dSe({usage:e}){let t=Object.values(e.counters).every(e=>e===0);return(0,h.jsxs)(e0,{split:`even`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(G2,{children:hSe(e).map(e=>(0,h.jsx)(K2,{label:e.label,value:e.value},e.label))}),t?(0,h.jsx)(`p`,{className:`m-0 mt-3 text-body text-ink-2`,children:`Numbers appear after your first run.`}):null]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Machine ID ${e.machineId??`not made yet`} · Slopify ${e.appVersion}`})]}),(0,h.jsx)(t0,{children:(0,h.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Tokens by stage`,columns:uSe,rows:e.byStage,rowKey:e=>`${e.stage}/${e.provider}/${e.model??``}`,empty:`No stages have run yet.`,className:`min-w-[480px] [&_td]:pr-4 [&_th]:pr-4`})})})]})}function fSe(e){return e.model===null?e.provider:`${e.provider} · ${e.model}`}var x9=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),pSe=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),mSe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function hSe(e){let t=e.counters;return[{label:`Videos made`,value:x9.format(t.videosMade)},{label:`Hours of audio`,value:pSe.format(t.audioSeconds/3600)},{label:`Images made`,value:x9.format(t.imagesMade)},{label:`Tokens used`,value:t.tokensUsed<1e6?x9.format(t.tokensUsed):mSe.format(t.tokensUsed)},{label:`Projects`,value:x9.format(t.projects)}]}function gSe({cells:e}){return(0,h.jsx)(`div`,{className:`sl-stats`,children:Array.from({length:e},(e,t)=>t).map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-8 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`})]},e))})}function _Se(){return(0,h.jsx)(`div`,{className:`border-t border-line`,children:[0,1,2,3].map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-4 border-b border-line py-3`,children:[(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 max-w-[40%] rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`ml-auto h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`})]},e))})}var S9=[`storage-usage`],vSe=[S9,B.projects,[`project`],B.usage,B.documentThemes,TH,[`play-drafts`],B.settings,B.providers,B.voices,B.prompts,B.entries,B.staging,Lq,sN,[`provider-models`]];async function ySe(e){await Promise.all(vSe.map(t=>e.invalidateQueries({queryKey:t})))}var C9=30,bSe=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function xSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=0&&Number(t)<=C9?void 0:`The silence gap is a whole number of seconds between 0 and ${String(C9)}.`}var w9=[{id:`general`,label:`General`,meta:`How Slopify starts on this computer.`},{id:`providers`,label:`Providers`,meta:`Keys stay on this machine and go only to their provider. Readiness is checked again before each run.`},{id:`voices`,label:`Voices`,meta:`A wrong voice ID shows up when the audio stage uses it.`},{id:`models`,label:`Models`,meta:`New models, prices and retirements, checked once a day.`},{id:`playback`,label:`Playback & appearance`,meta:`How narration is paced and how Slopify looks.`},{id:`notifications`,label:`Notifications`,meta:`When a run finishes, fails, waits for you, or a review needs a decision.`},{id:`channel-links`,label:`Channel links`,meta:`The links a YouTube description's {{Name}} placeholders fill from.`},{id:`studio`,label:`YouTube Studio`,meta:`The playlist upload packs name, and the Studio extension's pairing.`},{id:`storage`,label:`Backup & storage`,meta:`Export everything, import a backup, and see what uses disk space.`},{id:`backups`,label:`Backups`,meta:`A daily copy of everything, in a folder you choose.`},{id:`trash`,label:`Trash`,meta:`Deleted projects, prompts, templates and schedules, kept for 30 days.`},{id:`usage`,label:`Usage`,meta:`This machine only. The same counters, anonymised, feed slopify.stream.`},{id:`patch-notes`,label:`Patch notes`,meta:`What changed in each version of Slopify.`},{id:`about`,label:`About`,meta:`Free and open source, running on your machine with your own keys.`}];function SSe(e){return w9.find(t=>t.id===e)?.id??`providers`}function CSe(e){let t=document.createElement(`a`);t.href=`${e}/api/diagnostics`,t.download=`slopify-diagnostics.json`,document.body.append(t),t.click(),t.remove()}function wSe({section:e=`providers`,note:t,onSection:n=()=>{},onNote:r=()=>{}}){let{api:i}=z(),a=_(),o=Oy(),s=Q7(),c=h9(),l=w9.find(t=>t.id===e)??w9[0];return bx({id:`settings.check-providers`,title:`Check all providers`,group:`Settings`,keywords:[`health`,`keys`,`signed in`],run:()=>{n(`providers`),s.mutate()}}),bx({id:`settings.back-up-now`,title:`Back up now`,group:`Settings`,keywords:[`backup`],run:()=>{n(`backups`),c.mutate(void 0,{onError:e=>{o(`The backup didn't start: ${e.message} Open Settings → Backups to see its state.`,`error`)}})}}),bx({id:`settings.download-diagnostics`,title:`Download diagnostics`,group:`Settings`,keywords:[`support`,`bug report`],run:()=>{CSe(i.origin)}}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:`Settings`,title:l.label,meta:l.meta,actions:(0,h.jsxs)(h.Fragment,{children:[e===`providers`?(0,h.jsx)(R,{disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check all`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(mS,{variant:`secondary`,href:`${i.origin}/api/diagnostics`,download:`slopify-diagnostics.json`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download diagnostics`]}),(0,h.jsx)(V,{id:`settings.diagnostics`})]})]})}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(e8,{label:`Settings sections`,children:w9.map(t=>(0,h.jsx)(t8,{current:t.id===e,onClick:()=>n(t.id),className:`whitespace-nowrap max-md:w-auto`,children:t.label},t.id))}),children:(0,h.jsxs)(`section`,{"aria-label":l.label,className:`flex min-w-0 flex-col gap-10`,children:[e===`providers`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B3,{}),(0,h.jsx)(Txe,{}),(0,h.jsx)(hxe,{run:s})]}):null,e===`general`?(0,h.jsx)(zb,{}):null,e===`voices`?(0,h.jsx)(Axe,{}):null,e===`models`?(0,h.jsx)(lxe,{}):null,e===`playback`?(0,h.jsx)(OSe,{}):null,e===`notifications`?(0,h.jsx)(Pxe,{}):null,e===`channel-links`?(0,h.jsx)(Kfe,{}):null,e===`studio`?(0,h.jsx)(Afe,{}):null,e===`storage`?(0,h.jsx)(cSe,{usageQueryKey:S9}):null,e===`storage`?(0,h.jsx)(TSe,{}):null,e===`storage`?(0,h.jsx)(Rxe,{}):null,e===`backups`?(0,h.jsx)(iSe,{}):null,e===`trash`?(0,h.jsx)(Xxe,{}):null,e===`usage`?(0,h.jsx)(lSe,{}):null,e===`patch-notes`?(0,h.jsx)(Vxe,{note:t,onNote:r}):null,e===`about`?(0,h.jsx)(tSe,{onWhatsNew:()=>{a.fetchQuery(fI(i)).then(e=>r(e.current??void 0),e=>{o(`The patch notes did not open: ${e instanceof Error?e.message:String(e)} Open Settings → Patch notes to try again.`,`error`)})}}):null]})})]})}var T9=`The backup wasn't imported. Check it is a file made with Export everything (.tar) or Export backup (.zip), then try again.`;function TSe(){let{api:e}=z(),t=_(),n=N({queryKey:S9,queryFn:()=>Fo(e),staleTime:3e4}),[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)({phase:`idle`}),[s,c]=(0,m.useState)({phase:`idle`}),[l,u]=(0,m.useState)(null),d=Oy(),[f,p]=(0,m.useState)(null);async function g(){p(null),o({phase:`preparing`});try{let t=await Eo(e);if(!t.ready){o({phase:`idle`}),p(t.detail??`The backup can't be made right now. Try again in a moment.`);return}o({phase:`downloading`,bytes:t.bytes??0,projects:t.projects??0});let n=document.createElement(`a`);n.href=`${e.origin}/api/storage/export`,n.download=``,document.body.append(n),n.click(),n.remove()}catch(e){o({phase:`idle`}),p(e instanceof Error?e.message:`The backup couldn't be prepared. Try again in a moment.`)}}async function v(n){let r=n.name.toLowerCase().endsWith(`.zip`)||n.type===`application/zip`;if(n.size===0||r&&n.size>104857600){p(r?`This file is empty or larger than 100 MB. Choose a .zip made with Export backup, or a .tar made with Export everything.`:`This file is empty. Choose the .tar made with Export everything.`);return}i(!0),p(null),u(null),c({phase:`uploading`,sent:0,total:n.size});try{let i=await e.upload(`${e.origin}/api/storage/import`,n,r?`application/zip`:`application/x-tar`,(e,t)=>{c(e>=t?{phase:`importing`}:{phase:`uploading`,sent:e,total:t})}),a=await i.json();if(!i.ok)throw Error(a.detail??T9);a.projects===void 0?d(`Imported ${a.templates??0} template(s), ${a.fonts??0} uploaded font(s), and ${a.stagedFiles??0} staged file(s).${a.fontFallbacks?` ${a.fontFallbacks} missing legacy font reference(s) now use the default font.`:``}`,`success`):(u(a),d(`Backup imported.`,`success`)),await ySe(t)}catch(e){p(e instanceof Error?e.message:T9)}finally{c({phase:`idle`}),i(!1)}}async function y(){i(!0),p(null);try{let n=await e.fetch(`${e.origin}/api/storage/cleanup`,{method:`POST`}),r=await n.json();if(!n.ok)throw Error(`Clean orphan files didn't finish. Try again in a moment.`);d(`Removed ${r.orphanFiles??0} orphan project file(s) and ${r.stagedFiles??0} stale staged file(s).`,`success`),await t.invalidateQueries({queryKey:S9})}catch(e){p(e instanceof Error?e.message:`Clean orphan files didn't finish. Try again in a moment.`)}finally{i(!1)}}bx({id:`settings.export-everything`,title:`Export everything`,group:`Settings`,context:`Backup & storage`,keywords:[`backup`,`download`],run:()=>{!r&&a.phase!==`preparing`&&g()}});let b=r||a.phase===`preparing`,x=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Export and import`,info:`settings.storage.export`,children:[(0,h.jsx)(R,{disabled:b,onClick:()=>void g(),children:`Export everything`}),(0,h.jsx)(R,{disabled:b,onClick:()=>x.current?.click(),children:`Import a backup`}),(0,h.jsx)(`input`,{ref:x,className:`sr-only`,type:`file`,tabIndex:-1,"aria-label":`Import a backup`,accept:`.tar,application/x-tar,.zip,application/zip`,disabled:b,onChange:e=>{let t=e.target.files?.[0];t&&v(t),e.target.value=``}}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:b,onClick:()=>void y(),children:`Clean orphan files`}),(0,h.jsx)(V,{id:`settings.storage.clean`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Provider keys are never included in a backup. After importing, enter them again in Settings → Providers.`}),a.phase===`preparing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Preparing the backup…`}):null,a.phase===`downloading`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 min-w-0 flex-1 text-ink`,children:[`Downloading `,Y5(a.bytes),` (`,a.projects,` project`,a.projects===1?``:`s`,`). Your browser's downloads show its progress; keep Slopify running until it finishes.`]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>o({phase:`idle`}),children:`Dismiss`})]}):null,s.phase===`uploading`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[`Uploading the backup: `,Y5(s.sent),` of`,` `,Y5(s.total)]}),(0,h.jsx)(q2,{label:`Backup upload`,value:s.total===0?0:s.sent/s.total})]}):null,s.phase===`importing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Checking and importing the backup… large projects can take a minute.`}):null,f?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:f}):null]})]}),l?(0,h.jsx)(DSe,{result:l,onDismiss:()=>u(null)}):null,(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Disk space`,info:`settings.storage.disk`,meta:n.data?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`font-semibold text-ink`,children:[Y5(n.data.data),` stored`]}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[` `,`· `,Y5(Math.max(0,n.data.projects-n.data.trash.bytes)),` project files · `,Y5(n.data.staging),` staged files`,n.data.trash.projects>0?` · ${Y5(n.data.trash.bytes)} in the trash (${ESe(n.data.trash.projects)}), freed when removed for good`:null]})]}):n.error?`Storage usage is unavailable. Reload the page to try again.`:(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`})}),n.data&&n.data.byProject.length>0?(0,h.jsx)(Xve,{projects:n.data.byProject,queryKey:[...S9]}):null]})]})}function ESe(e){return e===1?`1 deleted project`:`${String(e)} deleted projects`}function E9(e,t){if(t===void 0)return null;let n=[t.added>0?`${t.added} added`:null,t.renamed>0?`${t.renamed} added as “(imported)” because the name was taken`:null,t.skipped>0?`${t.skipped} already here`:null].filter(e=>e!==null);return n.length===0?null:`${e}: ${n.join(`, `)}.`}function DSe({result:e,onDismiss:t}){let n=[e.projects.imported.length>0?`Projects: ${e.projects.imported.length} added (${Y5(e.files.bytes)} of files).`:`Projects: none added.`,E9(`Prompts`,e.prompts),E9(`Intros and outros`,e.entries),E9(`Channels`,e.channels),E9(`Cast members`,e.cast),E9(`Episode memories`,e.episodeMemories),E9(`Existing videos`,e.channelVideos),E9(`Document themes`,e.documentThemes),E9(`Templates`,e.templates),E9(`Schedules`,e.schedules),e.schedules.paused>0?`${e.schedules.paused} schedule(s) arrived paused so two installs never run them both; resume them on the Schedules screen.`:null,E9(`Voices`,e.voices),E9(`Play drafts`,e.drafts),e.settings.added+e.settings.kept>0?`Settings: ${e.settings.added} filled in${e.settings.kept>0?`, ${e.settings.kept} kept as this install has them`:``}.`:null,e.fonts>0?`Uploaded fonts: ${e.fonts} added.`:null,e.usage.alreadyImported?`Usage: this backup's history was already added before, so it wasn't counted twice.`:`Usage: ${e.usage.events} recorded event(s) added to the totals.`,`Provider keys are not in backups: enter them in Settings → Providers.`].filter(e=>e!==null);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{as:`h3`,title:`Imported the backup from ${e.backup.createdAt.slice(0,10)}`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`Dismiss`})}),(0,h.jsxs)(`ul`,{"aria-label":`Import result`,className:`m-0 list-disc pl-5 text-small text-ink-2`,children:[n.map(e=>(0,h.jsx)(`li`,{className:`py-0.5`,children:e},e)),e.projects.skipped.map(e=>(0,h.jsxs)(`li`,{className:`py-0.5`,children:[`Skipped “`,e.title,`”: `,e.reason]},e.id))]})]})}function OSe(){let{api:e}=z(),t=_(),n=N(ob(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Qo(e,t),onMutate:e=>{let n=t.getQueryData(B.settings);return t.setQueryData(B.settings,e),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(B.settings,r.previous)},onSuccess:e=>{t.setQueryData(B.settings,e)}});if((0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>{o(!1)},Y2);return()=>{clearTimeout(e)}},[a]),n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});if(n.data===void 0)return(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,role:`status`,"aria-label":`Loading settings`,children:[(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`})]});let c=n.data,l=r??String(c.silenceGapSeconds),u=xSe(l);return(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Silence between segments`,tip:`settings.playback.silence-gap`,help:`Seconds of quiet between narrated segments.`,error:u??s.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:0,max:C9,step:1,className:`w-[88px] tabular-nums`,value:l,"aria-invalid":u!==void 0,onChange:e=>{i(e.target.value)}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`seconds`}),(0,h.jsx)(R,{variant:`primary`,disabled:u!==void 0||s.isPending,onClick:()=>{o(!1),s.mutate({...c,silenceGapSeconds:Number(l.trim())},{onSuccess:()=>{i(void 0),o(!0)}})},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null})]})}),(0,h.jsxs)(`div`,{className:`sl-field`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Appearance`}),(0,h.jsx)(V,{id:`settings.appearance`,className:`-my-1`})]}),(0,h.jsx)(Ab,{label:`Appearance`,value:c.appearance,options:bSe,className:`self-start`,onChange:e=>{s.mutate({...c,appearance:e})}})]}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(k6,{value:c.loudness??tk,switchLabel:`Level the volume for new runs`,switchTip:`settings.loudness`,onChange:e=>{s.mutate({...c,loudness:e})}})})]})}function kSe({open:e,onClose:t,onInstalled:n}){let{api:r}=z(),i=_(),a=N({queryKey:My,queryFn:()=>Iy(r),enabled:e}),o=P({mutationFn:e=>Ry(r,e),onSuccess:()=>n(),onSettled:()=>i.invalidateQueries({queryKey:My})});return(0,h.jsxs)(YP,{open:e,title:`Add a starter pack`,onClose:t,footer:(0,h.jsx)(Q1,{tone:o.error||a.error?`error`:`success`,children:o.error?.message??a.error?.message??(o.data===void 0?void 0:o.data.added?`Added: its prompts are in Prompts and its template is in this list.`:`That pack was already added.`)}),children:[(0,h.jsxs)(`p`,{className:`mb-4 flex items-center gap-1 text-small text-ink-2`,children:[`Prompts, a suggested voice and a template for one kind of channel.`,(0,h.jsx)(V,{id:`welcome.packs`})]}),(0,h.jsxs)(pU,{label:`Starter packs`,className:`[&_.sl-row__meta]:whitespace-normal`,children:[(a.data?.packs??[]).map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:(0,h.jsx)(R,{disabled:e.installed||o.isPending,onClick:()=>o.mutate(e.id),children:e.installed?`Added`:`Add pack`})},e.id)),a.data===void 0?(0,h.jsx)(mU,{title:`Loading packs…`}):null]})]})}function ASe({template:e}){let{api:t}=z(),n=N({queryKey:[...Lq,e.id,e.version],queryFn:async()=>{let n=await Uq(t,e.id);if(!n.ok)throw Error(n.message);return n.value}});if(n.error)return(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The keywords of `,e.name,` didn't load. `,n.error.message,` Press Keywords again.`]});if(!n.data)return(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`Reading the keywords…`});let{form:r,librarySnapshot:i}=n.data.document,a=h0({form:r,prompts:i?.prompts??[],entries:i?.entries??[]}),o=z3(r.title),s=[...new Set([...a.keys(),...Object.keys(r.values)])];return(0,h.jsx)(_0,{keywords:s.map(e=>({name:e,value:r.values[e]??``,feeds:a.get(e)??[],topic:o.includes(e)})),empty:`No keywords: the prompts and the title name none.`})}async function jSe(e,t,n,r){let i=await Gq(e,t.id,{baseVersion:t.version,mutationId:r,...n});if(!i.ok)throw Error(i.message);return i.value}function MSe({template:e}){return e===void 0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`Pick a template to see the keywords it fills.`}):(0,h.jsxs)(`section`,{"aria-label":`Keywords of ${e.name}`,className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:e.name,as:`h3`,info:`templates.edit`,className:`pb-0`}),(0,h.jsx)(ASe,{template:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`To change the settings, press Use in Play, change the draft, then Save a setup.`})]})}function NSe({template:e,onClose:t}){let{api:n}=z(),r=_(),i=Array.from({length:e.version},(t,n)=>e.version-n),a=ot({queries:i.map(t=>({queryKey:[...Lq,e.id,`version`,t],queryFn:async()=>{let r=await Uq(n,e.id,t);if(!r.ok)throw Error(r.message);return r.value},staleTime:1/0}))}),o=a[0]?.data,[s,c]=(0,m.useState)(i[1]??e.version),l=a[i.indexOf(s)]?.data,u=(0,m.useRef)(crypto.randomUUID()),d=Oy(),f=P({mutationFn:t=>jSe(n,e,{name:t.name,document:t.document},u.current),onSuccess:async(n,i)=>{u.current=crypto.randomUUID(),d(`Restored version ${String(i.version)} of ${e.name} as version ${String(n.version)}.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}}),p=a.find(e=>e.error!==null)?.error;return(0,h.jsx)(YP,{open:!0,title:`History of ${e.name}`,onClose:t,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[p?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:`A version couldn't be read: ${p.message} Close History and open it again.`}):null,(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Versions`,as:`h3`,info:`templates.history`}),(0,h.jsx)(pU,{label:`Versions of ${e.name}`,children:i.map((t,n)=>{let r=a[n]?.data;return(0,h.jsx)(mU,{title:`Version ${String(t)}`,selected:t===s,onSelect:()=>c(t),meta:r===void 0?`Loading…`:`${r.name} · ${j4(r.updatedAt)}`,actions:t===e.version?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(R,{size:`small`,"aria-label":`Restore version ${String(t)}`,disabled:r===void 0||f.isPending,disabledReason:r===void 0?`Reading the version`:`Restoring`,onClick:()=>{r!==void 0&&f.mutate(r)},children:`Restore`})},t)})}),(0,h.jsx)(Q1,{tone:`error`,children:f.error===null?void 0:`The version wasn't restored: ${f.error.message}`})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`Compare with the current version`,as:`h3`}),o===void 0||l===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Loading the versions…`}):l.version===o.version?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.version===1?`This is the only version so far.`:`Pick an older version in the list to compare it.`}):(0,h.jsxs)(h.Fragment,{children:[l.name===o.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${l.name}" to "${o.name}".`}),(0,h.jsx)(w4,{before:D9(l),after:D9(o),beforeLabel:`Version ${String(l.version)}`,afterLabel:`Version ${String(o.version)} (current)`})]})]})]})})}function D9(e){return JSON.stringify(e.document,null,1).split(`
308
308
  `).map(e=>e.trim()).filter(e=>!/^[[\]{}],?$/u.test(e)).join(`
309
- `)}function NSe({onApplied:e,beforeApply:t,getGeneration:n,blocked:r=!1}){let{api:i}=z(),a=_(),o=N(Hq(i)),s=N(Zb(i)),[c,l]=(0,m.useState)(``),u=o.data?.filter(e=>c===``||o0(e)===c),d=e=>s.data?.find(t=>t.id===o0(e))?.name,f=N({queryKey:[`play-drafts`],queryFn:async()=>{let e=await ZM(i);if(!e.ok)throw Error(e.message);return e.value.drafts}}),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),E=Oy(),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!1),[ee,te]=(0,m.useState)(null),[ne,j]=(0,m.useState)(null),[re,M]=(0,m.useState)(null),ie=(0,m.useRef)(new Map),ae=(0,m.useRef)(!1),oe=(0,m.useRef)(null),se=(0,m.useRef)(new Map),ce=(0,m.useRef)(!0);(0,m.useEffect)(()=>(ce.current=!0,()=>{ce.current=!1}),[]);async function le(e){if(!ae.current){ae.current=!0,C(!0),T(null);try{await e()}catch(e){T(e instanceof Error?e.message:`That didn't finish. Try again.`)}finally{ae.current=!1,C(!1)}}}async function ue(){let e=await $M(i,p);if(!e.ok)throw Error(e.message);let t=JSON.stringify([p,e.value.draft.version,v.trim(),b]);oe.current?.key!==t&&(oe.current={key:t,id:crypto.randomUUID()});let n=e.value.draft.document,r=o.data?.find(e=>e.id===n.templateSource?.id),s=b||n.channelId||(r?o0(r):void 0),c=await Wq(i,{id:oe.current.id,name:v.trim(),document:s===void 0?n:{...n,channelId:s}});if(!c.ok)throw oe.current=null,Error(c.message);oe.current=null,y(``),O(!1),E(`Template saved.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function de(o){let s=n?.();if(r||t&&!await t())throw Error(`Save or discard the draft open in Play first, then apply the template again.`);if(!ce.current||s!==void 0&&s!==n?.())return;let c=`${o.id}:${o.version}`,l=se.current.get(c);l||(l=crypto.randomUUID(),se.current.set(c,l));let u=await Xq(i,o,l);if(!u.ok)throw se.current.delete(c),Error(u.message);if(!(!ce.current||s!==void 0&&s!==n?.())&&(await a.invalidateQueries({queryKey:[`play-drafts`]}),!(!ce.current||s!==void 0&&s!==n?.()))){if(await e(u.value.draft.id,()=>ce.current)!==!1)se.current.delete(c);else throw Error(`The template's draft was created but didn't open. Press Use in Play again to open it.`)}}async function fe(e){let t=`${e.id}:${e.version}`,n=ie.current.get(t);n||(n=crypto.randomUUID(),ie.current.set(t,n));let r=await Uq(i,e.id);if(!r.ok)throw Error(r.message);let o=await Wq(i,{id:n,name:`${e.name} copy`,document:r.value.document});if(!o.ok)throw Error(o.message);ie.current.delete(t),E(`Duplicated as ${o.value.name}.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function pe(){if(!ee)return;let e=ee.id,t=await Jq(i,ee);if(!t.ok)throw Error(t.message);te(null),await a.cancelQueries({queryKey:Lq}),a.setQueryData(Lq,t=>t?.filter(t=>t.id!==e)),E(`Template moved to the trash. Restore it in Settings → Trash within 30 days.`,`success`),await a.invalidateQueries({queryKey:Lq})}bx({id:`library.save-template`,title:`Save a setup as a template`,group:`Library`,keywords:[`template`,`new template`,`play draft`],run:()=>O(!0)});let me=w&&!ee?{tone:`error`,text:w}:r?{tone:`warning`,text:`A run is still starting in Play. Wait for it to finish (or press Check Start result there), then apply a template.`}:o.error?{tone:`error`,text:o.error.message}:o.isPending?{tone:`info`,text:`Loading templates…`}:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(OSe,{open:k,onClose:()=>A(!1),onInstalled:()=>void a.invalidateQueries({queryKey:Hq(i).queryKey})}),(0,h.jsxs)(B4,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,onClick:()=>A(!0),"aria-expanded":k,children:`Add pack`}),(0,h.jsx)(V,{id:`welcome.packs`,label:`Add pack`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`primary`,onClick:()=>O(!0),"aria-expanded":D,children:`Save a setup`}),(0,h.jsx)(V,{id:`templates.save`,label:`Save a setup`})]})]}),children:[(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsxs)(TV,{"aria-label":`Show templates of`,value:c,className:`w-full sm:w-56`,onChange:e=>l(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsx)(V,{id:`templates.show-channel`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Reuse a Play setup and its checkpoint choices. Use in Play creates a fresh draft to review.`,(0,h.jsx)(V,{id:`templates.apply`,label:`Use in Play`})]})]}),(0,h.jsxs)(`div`,{className:`mb-2 flex min-h-8 flex-wrap items-center gap-3`,children:[(0,h.jsx)(Q1,{tone:me?.tone??`info`,children:me?.text}),o.error?(0,h.jsx)(R,{size:`small`,onClick:()=>void o.refetch(),children:`Reload templates`}):null,(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:S||o.isFetching,onClick:()=>void o.refetch(),children:`Refresh templates`})]}),o.data?.length===0?(0,h.jsx)(a0,{title:`No templates yet`,children:`Use Save a setup to keep a Play draft for reuse.`}):null,o.data?.length&&u?.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No templates in this channel.`}):null,o.isPending&&!o.error?(0,h.jsx)(L4,{label:`Project templates`}):null,u?.length?(0,h.jsx)(jq,{className:F4,list:(0,h.jsx)(pU,{label:`Project templates`,children:u.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(mU,{className:`max-md:grid-cols-1`,title:(0,h.jsx)(J4,{name:e.name,maxLength:120,onSelect:()=>j(e.id),onRename:async t=>{let n=await Kq(i,e.id,t);return await a.invalidateQueries({queryKey:Lq}),n}}),selected:e.id===ne,meta:(0,h.jsxs)(h.Fragment,{children:[d(e)===void 0?``:`${d(e)} · `,`Version `,e.version,` · updated`,` `,(0,h.jsx)(`time`,{dateTime:e.updatedAt,children:e.updatedAt.slice(0,10)})]}),actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,onClick:()=>j(e.id),children:`Edit`}),duplicate:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:S,disabledReason:`Working on the last press`,onClick:()=>void le(()=>fe(e)),children:`Duplicate`}),play:{run:()=>void le(()=>de(e)),blocked:r?`A run is still starting in Play. Wait for it, then use the template.`:S?`Working on the last press`:void 0},onHistory:()=>M(e),onDelete:()=>{te(e),T(null)}})}),(0,h.jsx)(c0,{kind:`template`,id:e.id,name:e.name})]},e.id))}),detail:(0,h.jsx)(jSe,{template:u.find(e=>e.id===ne)})}):null,(0,h.jsxs)(YP,{open:D,title:`Save a setup`,width:`narrow`,onClose:()=>O(!1),footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:w?`error`:`info`,children:w??(S?`Saving…`:void 0)}),(0,h.jsx)(R,{type:`submit`,form:`save-template-form`,variant:`primary`,disabled:S||!p||!v.trim(),children:`Save template`})]}),children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[`Choose a saved Play draft, or`,` `,(0,h.jsx)(ha,{to:`/play`,className:`text-accent-ink underline`,children:`open Play`}),` `,`to prepare one.`]}),(0,h.jsx)(`p`,{className:`mb-4 text-small text-ink-2`,children:`A template keeps the settings, not one video's topic.`}),(0,h.jsxs)(`form`,{id:`save-template-form`,"aria-label":`Save a setup`,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),p&&v.trim()&&le(ue)},children:[(0,h.jsx)(xV,{label:`Saved Play draft`,tip:`templates.save.draft`,help:f.isPending?`Loading saved drafts…`:f.data?.length===0?`No saved drafts yet.`:void 0,children:(0,h.jsxs)(TV,{value:p,required:!0,disabled:S,onChange:e=>g(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a draft`}),f.data?.filter(e=>e.readable).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.title||`Untitled draft`},e.id))]})}),f.error?(0,h.jsx)(SI,{tone:`danger`,title:`The saved drafts couldn't be loaded.`,actions:(0,h.jsx)(R,{size:`small`,onClick:()=>void f.refetch(),children:`Reload drafts`}),children:f.error.message}):null,(0,h.jsx)(xV,{label:`Template name`,id:`template-name`,tip:`templates.save.name`,children:(0,h.jsx)(CV,{value:v,required:!0,maxLength:120,disabled:S,onChange:e=>y(e.target.value)})}),(0,h.jsx)(xV,{label:`Channel`,id:`template-channel`,tip:`templates.save.channel`,children:(0,h.jsxs)(TV,{value:b,disabled:S,onChange:e=>x(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`The draft's channel`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]})]}),re===null?null:(0,h.jsx)(MSe,{template:re,onClose:()=>M(null)},`${re.id}:${String(re.version)}`),(0,h.jsx)(jy,{open:ee!==null,title:`Delete ${ee?.name??`template`}?`,consequence:w??`Moves it to the trash for 30 days (Settings → Trash). Existing projects and drafts keep their setup.`,confirmLabel:`Delete template`,pending:S,onConfirm:()=>void le(pe),onCancel:()=>{S||te(null)}})]})}function PSe({page:e,anchor:t,words:n}){let{api:r}=z(),i=N(NB(r)),a=N(PB(r,e)),o=Zi(),[s,c]=(0,m.useState)(n??``);(0,m.useEffect)(()=>{c(n??``)},[n]);let l=(0,m.useRef)(null),u=(0,m.useMemo)(()=>new Set((i.data?.pages??[]).map(e=>e.id)),[i.data]),d=i.data?.pages.find(t=>t.id===e)?.title??e.replace(/-/g,` `),f=(0,m.useMemo)(()=>yb(a.data??``),[a.data]),p=(0,m.useMemo)(()=>a.data===void 0?``:vb(f.body,u,e),[a.data,f.body,u,e]);(0,m.useEffect)(()=>{if(p===``)return;let e=l.current;if(e===null)return;let n=t===void 0?void 0:xb(e,t,f.title===void 0?[]:[f.title]);n===void 0?window.scrollTo?.({top:0}):n.scrollIntoView?.({block:`start`})},[p,t,f.title]);let g=i.data?.groups.find(t=>t.pages.some(t=>t.id===e));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Help`}),(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`›`}),(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:i.data?.home.id??`Home`},children:`Tutorials`})]}),title:d,meta:g===void 0?`Guides to every screen of Slopify, for the version you are running.`:g.title}),(0,h.jsx)(Aq,{className:`sl-workspace--tutorials`,sections:(0,h.jsx)(FSe,{index:i.data,page:e,onOpenHit:(e,t)=>{o({to:`/help/tutorials/$page`,params:{page:e.page},search:{q:t},...e.anchor===``?{}:{hash:e.anchor}})}}),children:a.error===null?(0,h.jsxs)(`div`,{ref:l,onClick:e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey)return;let t=e.target.closest(`a`),n=t?.getAttribute(`href`);if(t===null||n==null)return;let r=bb(n);if(r!==void 0){e.preventDefault(),o({to:`/help/tutorials/$page`,params:{page:r.page},...r.anchor===void 0?{}:{hash:r.anchor}});return}/^https?:/.test(n)&&(e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`))},children:[(0,h.jsx)(CB,{markdown:p,label:`Tutorial`,what:`tutorial`,query:s,onQuery:c,anchorPrefix:`tutorial-`,children:(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the tutorial…`})}),i.data?.footer?(0,h.jsx)(`p`,{className:`mt-8 border-t border-line pt-4 text-small text-ink-3`,children:i.data.footer.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`)}):null]}):(0,h.jsx)(SI,{tone:`danger`,title:`This tutorial did not load`,actions:(0,h.jsx)(R,{onClick:()=>void a.refetch(),variant:`secondary`,children:`Try again`}),children:`${a.error.message} Press Try again, or pick another page on the left.`})})]})}function FSe({index:e,page:t,onOpenHit:n}){let{api:r}=z(),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),c=(0,m.useRef)(null),l=(0,m.useId)();xx(c,`the tutorials`),(0,m.useEffect)(()=>{let e=setTimeout(()=>s(i.trim()),200);return()=>clearTimeout(e)},[i]);let u=N(FB(r,o));return(0,h.jsxs)(`nav`,{"aria-label":`Tutorials`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(`label`,{htmlFor:l,className:`sr-only`,children:`Search all tutorials`}),(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{ref:c,id:l,type:`search`,value:i,placeholder:`Search all tutorials`,onChange:e=>a(e.target.value),onKeyDown:e=>{let t=u.data?.hits[0];e.key===`Enter`&&t!==void 0&&(e.preventDefault(),n(t,o))},className:`sl-input pl-9`})]}),o===``?e===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the tutorials…`}):(0,h.jsxs)(`div`,{className:`sl-tutorials-nav flex flex-col gap-4`,children:[(0,h.jsx)(O9,{id:e.home.id,title:e.home.title,current:t}),e.groups.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,h.jsx)(`div`,{className:`sl-kicker px-2.5 pb-1`,children:e.title}),e.pages.map(e=>(0,h.jsx)(O9,{id:e.id,title:e.title,current:t},e.id))]},e.title))]}):(0,h.jsx)(ISe,{query:o,hits:u.data?.hits,error:u.error?.message})]})}function O9({id:e,title:t,current:n}){return(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:e},"aria-current":e===n?`page`:void 0,className:`sl-tutorials-nav__link`,children:t})}function ISe({query:e,hits:t,error:n}){return n===void 0?t===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Searching…`}):t.length===0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`No tutorial mentions "${e}". Try fewer or other words.`}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{role:`status`,className:`m-0 px-2.5 text-small text-ink-3`,children:t.length===1?`1 section`:`${String(t.length)} sections`}),(0,h.jsx)(`ul`,{"aria-label":`Search results`,className:`m-0 flex list-none flex-col gap-1 p-0`,children:t.map(t=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(ha,{to:`/help/tutorials/$page`,params:{page:t.page},search:{q:e},...t.anchor===``?{}:{hash:t.anchor},className:`sl-tutorials-hit`,children:[(0,h.jsx)(`span`,{className:`block font-semibold text-ink`,children:t.heading===void 0?t.pageTitle:t.heading}),t.heading===void 0?null:(0,h.jsx)(`span`,{className:`block text-label text-ink-3`,children:t.pageTitle}),(0,h.jsx)(`span`,{className:`mt-0.5 block text-small text-ink-2`,children:t.snippet})]})},`${t.page}#${t.anchor}`))})]}):(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The search didn't run: ${n} Change the words or reload the page.`})}var LSe=[{id:`library`,name:`The Library of Alexandria`,summary:`A narrated video with its two shorts, article, PDF, description and images.`,action:`Explore the sample`},{id:`audiobook`,name:`The Wind in the Willows`,summary:`An audiobook: a narrator and two character voices, captions tagged with who speaks, MP3 and M4B with chapters.`,action:`See an audiobook`},{id:`podcast`,name:`The Antikythera Mechanism`,summary:`A two-host podcast with the speaker panel, name tags and portraits, and its MP3 and M4B.`,action:`Hear a podcast`}],k9=[{id:`found`,label:`1 · What you have`},{id:`style`,label:`2 · Pick a style`},{id:`make`,label:`3 · Make your first short`}];function RSe(e){return e.length<=2?e.join(` or `):`${e.slice(0,-1).join(`, `)} or ${e.at(-1)??``}`}function zSe(e){return e===void 0?{ready:!1,text:`Looking for a voice…`}:e.keyed===null?e.system.available?{ready:!0,text:`Narration uses your computer's built-in voice${e.system.engine===null?``:` (${e.system.engine})`}; add an ElevenLabs or OpenAI key later for a better one.`}:{ready:!1,text:e.system.issue??`No voice can narrate yet. Add an ElevenLabs or OpenAI key in Settings → Providers.`}:{ready:!0,text:`Narration uses your ${e.keyed} voice key.`}}function BSe(){let{api:e}=z(),t=_(),n=Zi(),r=N({queryKey:My,queryFn:()=>Iy(e)}),[i,a]=(0,m.useState)(`found`),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(void 0),f=(0,m.useRef)(void 0),p=P({mutationFn:()=>Ly(e),onSuccess:async()=>{await t.invalidateQueries({queryKey:My}),await n({to:`/`})}}),g=P({mutationFn:t=>Ry(e,t),onSettled:()=>t.invalidateQueries({queryKey:My})}),v=P({mutationFn:()=>(f.current??=crypto.randomUUID(),zy(e,{topic:o,requestId:f.current,...c===``?{}:{packId:c}})),onSuccess:async({projectId:e})=>{f.current=void 0,d(e),await t.invalidateQueries({queryKey:B.projects}),await t.invalidateQueries({queryKey:B.voices})}}),y=e=>{e.preventDefault(),o.trim()!==``&&v.mutate()},b=r.data,x=b?.clis.filter(e=>e.ready)??[],S=zSe(b?.voice),C=c===``?`General`:b?.packs.find(e=>e.id===c)?.name??c,w=v.error?{tone:`error`,text:v.error.message}:g.error?{tone:`error`,text:g.error.message}:p.error?{tone:`error`,text:p.error.message}:v.isPending?{tone:`info`,text:`Starting your short…`}:void 0,T=k9.findIndex(e=>e.id===i),E=k9[T+1],D=k9[T-1];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Welcome to Slopify`,meta:`Make a video from a topic, with the tools already on this computer.`,actions:(0,h.jsx)(R,{variant:`quiet`,disabled:p.isPending,onClick:()=>p.mutate(),children:u===void 0?`Skip`:`Done`})}),r.error?(0,h.jsx)(SI,{tone:`danger`,title:`Could not read what this computer has`,className:`mb-6`,children:r.error.message}):null,(0,h.jsx)(r0,{items:k9.map(e=>({id:e.id,label:e.label})),value:i,onChange:a,label:`First-run steps`,idPrefix:`welcome`,className:`mb-6`}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`found`,active:i===`found`,children:[(0,h.jsx)(H,{title:`Found on this computer`,info:`welcome.found`}),(0,h.jsxs)(pU,{label:`Tools found on this computer`,className:`mb-4`,children:[(b?.clis??[]).map(e=>(0,h.jsx)(mU,{title:e.name,actions:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.ready?`Ready${e.version===null?``:` · ${e.version}`}${e.draws?` · writes and draws`:` · writes`}`:e.installed?e.issue??`Installed, not usable yet`:`Not found`})},e.id)),b===void 0?(0,h.jsx)(mU,{title:`Looking for installed tools…`}):null]}),b!==void 0&&x.length>0?(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:`You can make a video now: no API keys are needed for ${RSe([`the text`,...x.some(e=>e.draws)?[`the images`]:[],...S.ready&&b.voice.keyed===null?[`the narration`]:[]])}.`}):null,b!==void 0&&x.length===0?(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`Nothing on this computer can write the script yet.`,actions:(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},children:`Open Settings → Providers`}),children:`Install Claude Code, Codex or Gemini CLI and sign in to it, then press Check again; or add an OpenRouter key in Settings → Providers.`}):null,(0,h.jsx)(H,{title:`Narration voice`,info:`welcome.voice`}),b===void 0?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6`,children:(0,h.jsx)(mU,{title:`Looking for a voice…`})}):(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`style`,active:i===`style`,children:[(0,h.jsx)(H,{title:`Pick a style`,info:`welcome.pack`}),(0,h.jsx)(pU,{label:`Styles`,className:`mb-3 [&_.sl-row__meta]:whitespace-normal`,children:[{id:``,name:`General`,summary:`A neutral explainer style.`,installed:!1,library:!1},...(b?.packs??[]).map(e=>({...e,library:!0}))].map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,selected:c===e.id,actions:(0,h.jsxs)(h.Fragment,{children:[e.library?(0,h.jsx)(R,{variant:`quiet`,disabled:e.installed||g.isPending,"aria-label":e.installed?`${e.name} is in your library`:`Add ${e.name} to library`,onClick:()=>g.mutate(e.id),children:e.installed?`In your library`:`Add to library`}):null,(0,h.jsx)(R,{variant:c===e.id?`primary`:`secondary`,"aria-pressed":c===e.id,"aria-label":`Use ${e.name}`,onClick:()=>l(e.id),children:c===e.id?`Picked`:`Use this style`})]})},e.id===``?`general`:e.id))}),(0,h.jsxs)(`p`,{className:`mb-6 flex items-center gap-1 text-small text-ink-2`,...Ob,children:[`Add to library keeps a pack's prompts and Play template for later videos.`,(0,h.jsx)(V,{id:`welcome.packs`,className:`-my-1`})]})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`make`,active:i===`make`,children:[u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Make a 60-second short`,info:`welcome.short`}),(0,h.jsxs)(`p`,{className:`mb-3 text-small text-ink-2`,children:[`Style: ${C}. `,S.text]}),S.ready||b===void 0?null:(0,h.jsx)(`div`,{className:`mb-4`,children:(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})}),(0,h.jsxs)(`form`,{onSubmit:y,className:`mb-6 flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[240px] flex-1 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:`welcome-topic`,className:`text-label text-ink-2`,children:`Topic`}),(0,h.jsx)(V,{id:`welcome.topic`,className:`-my-1`})]}),(0,h.jsx)(R3,{id:`welcome-topic`,value:o,maxLength:200,placeholder:`Why the sea glows at night`,onChange:e=>s(e.target.value)})]}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:o.trim()===``||v.isPending,disabledReason:`Type a topic first.`,children:`Make a 60-second short`})]})]}):(0,h.jsx)(SI,{tone:`info`,className:`mb-6`,title:`Your short is being made.`,actions:(0,h.jsx)(fS,{variant:`primary`,to:`/projects/$projectId`,params:{projectId:u},children:`Watch it being made`}),children:`It usually takes about five minutes. The live view shows each step as it runs; while you wait, look at a sample or set Slopify to start when you log in.`}),(0,h.jsx)(H,{title:`While you wait: the samples`,info:`welcome.samples`}),(0,h.jsx)(pU,{label:`Samples`,className:`mb-6 [&_.sl-row__meta]:whitespace-normal`,children:LSe.map(e=>{let t=b?.samples[e.id]??null;return(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:t===null?(0,h.jsx)(pS,{to:`/settings`,search:{section:`storage`},children:`Restore samples in Settings`}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:e.action})},e.id)})}),(0,h.jsx)(Vb,{})]}),(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:w?.tone??`info`,children:w?.text}),children:[(0,h.jsx)(pS,{to:`/play`,children:`Set up a long video instead`}),D===void 0?null:(0,h.jsx)(R,{onClick:()=>a(D.id),children:`Back`}),E===void 0?null:(0,h.jsx)(R,{variant:`primary`,onClick:()=>a(E.id),children:`Next: ${E.label.replace(/^\d · /,``)}`})]})]})}function A9({voice:e,checking:t,onCheck:n}){return e.ready?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6 [&_.sl-row__title]:whitespace-normal`,children:(0,h.jsx)(mU,{lead:(0,h.jsx)(gS,{tone:`done`}),title:e.text,actions:(0,h.jsx)(fS,{variant:`quiet`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`})})}):(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`No voice can narrate the short yet.`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(fS,{variant:`primary`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`}),(0,h.jsx)(R,{disabled:t,onClick:n,children:t?`Checking…`:`Check again`})]}),children:e.text})}var j9=ba({component:eV}),VSe=va({getParentRoute:()=>j9,path:`/`,component:Ime}),M9=va({getParentRoute:()=>j9,path:`projects`,validateSearch:e=>{let t=Xbe(e.show);return t===void 0?{}:{show:t}},component:HSe});function HSe(){let{show:e}=M9.useSearch();return(0,h.jsx)($be,{initialFilter:e??`all`},e??`all`)}var USe=va({getParentRoute:()=>j9,path:`welcome`,component:BSe}),WSe=va({getParentRoute:()=>j9,path:`play`,component:jge}),N9=va({getParentRoute:()=>j9,id:`_library`,component:Wpe}),GSe=va({getParentRoute:()=>j9,path:`library`,beforeLoad:()=>{throw dn({to:`/prompts`,search:{kind:`article`}})}}),KSe=va({getParentRoute:()=>j9,path:`channels`,component:xpe}),P9=va({getParentRoute:()=>j9,path:`channels/$channelId`,validateSearch:e=>e.tab===void 0?{}:{tab:ype(e.tab)},component:qSe});function qSe(){let{channelId:e}=P9.useParams(),{tab:t}=P9.useSearch(),n=Zi();return(0,h.jsx)(bpe,{channelId:e,tab:t??`brand`,onTab:t=>{n({to:`/channels/$channelId`,params:{channelId:e},search:{tab:t},replace:!0})}},e)}var JSe=va({getParentRoute:()=>N9,path:`templates`,component:$Se}),YSe=/^[0-9A-Za-z-]{1,64}$/;function F9(e){return Ife(e.tab)===`schedules`?typeof e.schedule==`string`&&YSe.test(e.schedule)?{tab:`schedules`,schedule:e.schedule}:{tab:`schedules`}:{}}var I9=va({getParentRoute:()=>j9,path:`calendar`,validateSearch:F9,component:QSe}),XSe=va({getParentRoute:()=>j9,path:`schedules`,beforeLoad:()=>{throw dn({to:`/calendar`,search:{tab:`schedules`},replace:!0})}}),ZSe=va({getParentRoute:()=>j9,path:`schedules/$scheduleId`,beforeLoad:({params:e})=>{throw dn({to:`/calendar`,search:F9({tab:`schedules`,schedule:e.scheduleId}),replace:!0})}});function QSe(){let e=F9(I9.useSearch()),t=Zi();return(0,h.jsx)(Rfe,{tab:e.tab??`weeks`,schedule:e.schedule,onTab:e=>{t({to:`/calendar`,search:e===`schedules`?{tab:`schedules`}:{},replace:!0})},onSchedule:e=>{t({to:`/calendar`,search:{tab:`schedules`,schedule:e},replace:!0})}})}function $Se(){let e=rP(),t=Zi();return(0,h.jsx)(NSe,{getGeneration:e.generation,blocked:e.review.starting||e.review.uncertain||e.review.created!==null,beforeApply:e.flush,onApplied:async(n,r)=>!r()||!await e.open(n,r)||!r()?!1:(await t({to:`/play`}),r())})}var L9=va({getParentRoute:()=>j9,path:`projects/$projectId`,component:cCe}),R9=va({getParentRoute:()=>N9,path:`prompts`,validateSearch:e=>({kind:vV(e.kind)}),component:lCe}),z9=va({getParentRoute:()=>j9,path:`prompts/new`,validateSearch:e=>{let t=vV(e.kind);return typeof e.from==`string`?{kind:t,from:e.from}:{kind:t}},component:uCe}),B9=va({getParentRoute:()=>j9,path:`prompts/$promptId`,component:dCe}),V9=va({getParentRoute:()=>N9,path:`entries`,validateSearch:e=>({category:hV(e.category)}),component:fCe}),H9=va({getParentRoute:()=>j9,path:`entries/new`,validateSearch:e=>{let t=hV(e.category);return typeof e.from==`string`?{category:t,from:e.from}:{category:t}},component:pCe}),U9=va({getParentRoute:()=>j9,path:`entries/$entryId`,component:mCe}),eCe=va({getParentRoute:()=>N9,path:`narration-aliases`,component:Rme}),tCe=va({getParentRoute:()=>N9,path:`document-themes`,component:Kpe}),W9=va({getParentRoute:()=>j9,path:`document-themes/new`,validateSearch:e=>typeof e.from==`string`?{from:e.from}:{},component:hCe}),G9=va({getParentRoute:()=>j9,path:`document-themes/$themeId`,component:gCe});function nCe(e){let t=e.section===void 0?void 0:xSe(e.section),n=t===`patch-notes`&&typeof e.note==`string`&&/^[0-9A-Za-z][0-9A-Za-z.-]{0,63}$/.test(e.note)?e.note:void 0;return{...t===void 0?{}:{section:t},...n===void 0?{}:{note:n}}}var K9=va({getParentRoute:()=>j9,path:`settings`,validateSearch:nCe,component:sCe}),q9=va({getParentRoute:()=>j9,path:`help/tutorials/$page`,validateSearch:e=>typeof e.q==`string`&&e.q.trim()!==``?{q:e.q.slice(0,200)}:{},component:rCe});function rCe(){let{page:e}=q9.useParams(),{q:t}=q9.useSearch(),n=Ha({select:e=>e.hash});return(0,h.jsx)(PSe,{page:e,anchor:n===``?void 0:n,words:t})}var iCe=va({getParentRoute:()=>j9,path:`help`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),aCe=va({getParentRoute:()=>j9,path:`help/tutorials`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),oCe=va({getParentRoute:()=>j9,path:`usage`,beforeLoad:()=>{throw dn({to:`/settings`,search:{section:`usage`}})}});function sCe(){let{section:e,note:t}=K9.useSearch(),n=Zi();return(0,h.jsx)(CSe,{section:e??`providers`,note:t,onSection:e=>{n({to:`/settings`,search:{section:e},replace:!0})},onNote:e=>{n({to:`/settings`,search:{section:`patch-notes`,...e===void 0?{}:{note:e}}})}})}function cCe(){let{projectId:e}=L9.useParams(),t=rP(),n=Zi();return(0,h.jsx)(Wbe,{projectId:e,openDraft:async e=>!await t.flush()||!await t.open(e)?!1:(await n({to:`/play`}),!0)},e)}function lCe(){let{kind:e}=R9.useSearch(),t=Zi(),n=J9();return(0,h.jsx)(ixe,{kind:e,onKind:e=>{t({to:`/prompts`,search:{kind:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function J9(){let e=rP(),t=Zi();return{blocked:e.review.starting||e.review.uncertain||e.review.created!==null?`Play is starting a run from its draft. Wait for it to start, then try again.`:void 0,use:n=>{let r=ZV(e.document,n);e.edit(r.document),t({to:`/play`}).then(()=>e.navigate(r.section,r.field))}}}function uCe(){let{kind:e,from:t}=z9.useSearch(),n=Y9();return(0,h.jsx)(J7,{promptId:void 0,kind:e,from:t,onLeave:n},`${e}:${t??`new`}`)}function dCe(){let{promptId:e}=B9.useParams(),t=Y9();return(0,h.jsx)(J7,{promptId:e,kind:`article`,from:void 0,onLeave:t},e)}function Y9(){let e=Zi();return t=>{e({to:`/prompts`,search:{kind:t}})}}function fCe(){let{category:e}=V9.useSearch(),t=Zi(),n=J9();return(0,h.jsx)(qpe,{category:e,onCategory:e=>{t({to:`/entries`,search:{category:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function pCe(){let{category:e,from:t}=H9.useSearch(),n=Z9();return(0,h.jsx)(c3,{entryId:void 0,category:e,from:t,onLeave:n})}function mCe(){let{entryId:e}=U9.useParams(),t=Z9();return(0,h.jsx)(c3,{entryId:e,category:`intro`,from:void 0,onLeave:t})}function hCe(){let{from:e}=W9.useSearch(),t=X9();return(0,h.jsx)(_4,{themeId:void 0,from:e,onLeave:t})}function gCe(){let{themeId:e}=G9.useParams(),t=X9();return(0,h.jsx)(_4,{themeId:e,from:void 0,onLeave:t})}function X9(){let e=Zi();return()=>{e({to:`/document-themes`})}}function Z9(){let e=Zi();return t=>{e({to:`/entries`,search:{category:t}})}}var _Ce=j9.addChildren({homeRoute:VSe,projectsRoute:M9,welcomeRoute:USe,playRoute:WSe,libraryRoute:N9.addChildren({promptsRoute:R9,entriesRoute:V9,templatesRoute:JSe,documentThemesRoute:tCe,narrationAliasesRoute:eCe}),schedulesRoute:XSe,scheduleRoute:ZSe,calendarRoute:I9,libraryIndexRoute:GSe,channelsRoute:KSe,channelRoute:P9,projectRoute:L9,newPromptRoute:z9,promptRoute:B9,newEntryRoute:H9,entryRoute:U9,newDocumentThemeRoute:W9,documentThemeRoute:G9,settingsRoute:K9,usageRoute:oCe,helpRoute:iCe,tutorialsIndexRoute:aCe,tutorialsRoute:q9});function vCe(){return La({routeTree:_Ce})}function yCe(){let e,t,n=new Set;return{observe:r=>{if(e===void 0){e=r;for(let e of n)e();return}if(r!==e&&r!==t){t=r;for(let e of n)e()}},staleAt:()=>t,loadedAt:()=>e,subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function bCe(e,t){return async(n,r)=>{let i=await e(n,r),a=i.headers.get(`X-Slopify-Version`);return a!==null&&t.observe(a),i}}function xCe(){let e=new Map;return{observe:t=>{if(t.type===`stage.state`){let n=e.get(t.projectId);if(n){for(let[e,r]of n)r.stage===t.stage&&r.revisionId===t.revisionId&&r.workId===t.workId&&n.delete(e);n.size===0&&e.delete(t.projectId)}return}if(t.type!==`llm.preview`)return;let n=e.get(t.projectId)??new Map,r=JSON.stringify([t.revisionId,t.workId,t.callId]),i=n.get(r),a=(t.reset?t.text:`${i?.text??``}${t.text}`).slice(-65536);for(n.delete(r),n.set(r,{...t,text:a,reset:!0});n.size>8;){let e=n.keys().next().value;e!==void 0&&n.delete(e)}for(e.delete(t.projectId),e.set(t.projectId,n);e.size>16;){let t=e.keys().next().value;t!==void 0&&e.delete(t)}},snapshot:t=>[...e.get(t)?.values()??[]],snapshotAll:()=>[...e.values()].flatMap(e=>[...e.values()])}}var Q9=/\/events\/projects\/([^/?#]+)/,SCe=/\/events\/global(?:[?#]|$)/,CCe=[`running.count`,`staging.progress`,`staging.failed`,`schedule.topics`,`stage.state`,`stage.progress`,`article.delta`,`llm.preview`,`image.landed`,`narration.piece`,`project.state`,`project.updated`,`review.flagged`];function wCe(e){let t=new Set,n=xCe(),r,i=!1,a=(e,t,n)=>{for(let r of e.listeners.get(t)??[])r({data:n})},o=o=>{if(r!==void 0)return;let s=e(o);r=s,s.addEventListener(`open`,()=>{i=!0;for(let e of[...t])for(let t of e.opens)t()});for(let e of CCe)s.addEventListener(e,r=>{let i;try{let t=JSON.parse(r.data);typeof t.projectId==`string`&&(i=t.projectId),(e===`llm.preview`||e===`stage.state`)&&n.observe(t)}catch{return}for(let n of[...t])(n.projectId===void 0||n.projectId===i)&&a(n,e,r.data)})};return s=>{let c=Q9.exec(s)?.[1];if(c===void 0&&!SCe.test(s))return e(s);o(c===void 0?s:s.replace(Q9,`/events/global`));let l={projectId:c===void 0?void 0:decodeURIComponent(c),listeners:new Map,opens:new Set};return t.add(l),i&&queueMicrotask(()=>{if(t.has(l)){for(let e of l.opens)e();if(l.projectId!==void 0)for(let e of n.snapshot(l.projectId))a(l,`llm.preview`,JSON.stringify(e))}}),{addEventListener:(e,t)=>{if(e===`open`){l.opens.add(t);return}let n=l.listeners.get(e)??new Set;n.add(t),l.listeners.set(e,n)},close:()=>{t.delete(l),t.size===0&&r!==void 0&&(r.close(),r=void 0,i=!1)}}}}function TCe(e){let t=yCe(),n={api:Co(window.location.origin,bCe(window.fetch.bind(window),t),To(e=>{let n=e.headers.get(`X-Slopify-Version`);n!==null&&t.observe(n)})),openEvents:wCe(e=>new EventSource(e)),version:t};(0,co.createRoot)(e).render((0,h.jsx)(m.StrictMode,{children:(0,h.jsx)(v,{client:new Je,children:(0,h.jsx)(ste,{deps:n,children:(0,h.jsx)(Ba,{router:vCe()})})})}))}var $9=document.getElementById(`root`);if($9===null)throw Error(`index.html carries no #root element for the app to mount on`);TCe($9);export{t4 as t};
309
+ `)}function PSe({onApplied:e,beforeApply:t,getGeneration:n,blocked:r=!1}){let{api:i}=z(),a=_(),o=N(Hq(i)),s=N(Zb(i)),[c,l]=(0,m.useState)(``),u=o.data?.filter(e=>c===``||o0(e)===c),d=e=>s.data?.find(t=>t.id===o0(e))?.name,f=N({queryKey:[`play-drafts`],queryFn:async()=>{let e=await ZM(i);if(!e.ok)throw Error(e.message);return e.value.drafts}}),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),E=Oy(),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!1),[ee,te]=(0,m.useState)(null),[ne,j]=(0,m.useState)(null),[re,M]=(0,m.useState)(null),ie=(0,m.useRef)(new Map),ae=(0,m.useRef)(!1),oe=(0,m.useRef)(null),se=(0,m.useRef)(new Map),ce=(0,m.useRef)(!0);(0,m.useEffect)(()=>(ce.current=!0,()=>{ce.current=!1}),[]);async function le(e){if(!ae.current){ae.current=!0,C(!0),T(null);try{await e()}catch(e){T(e instanceof Error?e.message:`That didn't finish. Try again.`)}finally{ae.current=!1,C(!1)}}}async function ue(){let e=await $M(i,p);if(!e.ok)throw Error(e.message);let t=JSON.stringify([p,e.value.draft.version,v.trim(),b]);oe.current?.key!==t&&(oe.current={key:t,id:crypto.randomUUID()});let n=e.value.draft.document,r=o.data?.find(e=>e.id===n.templateSource?.id),s=b||n.channelId||(r?o0(r):void 0),c=await Wq(i,{id:oe.current.id,name:v.trim(),document:s===void 0?n:{...n,channelId:s}});if(!c.ok)throw oe.current=null,Error(c.message);oe.current=null,y(``),O(!1),E(`Template saved.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function de(o){let s=n?.();if(r||t&&!await t())throw Error(`Save or discard the draft open in Play first, then apply the template again.`);if(!ce.current||s!==void 0&&s!==n?.())return;let c=`${o.id}:${o.version}`,l=se.current.get(c);l||(l=crypto.randomUUID(),se.current.set(c,l));let u=await Xq(i,o,l);if(!u.ok)throw se.current.delete(c),Error(u.message);if(!(!ce.current||s!==void 0&&s!==n?.())&&(await a.invalidateQueries({queryKey:[`play-drafts`]}),!(!ce.current||s!==void 0&&s!==n?.()))){if(await e(u.value.draft.id,()=>ce.current)!==!1)se.current.delete(c);else throw Error(`The template's draft was created but didn't open. Press Use in Play again to open it.`)}}async function fe(e){let t=`${e.id}:${e.version}`,n=ie.current.get(t);n||(n=crypto.randomUUID(),ie.current.set(t,n));let r=await Uq(i,e.id);if(!r.ok)throw Error(r.message);let o=await Wq(i,{id:n,name:`${e.name} copy`,document:r.value.document});if(!o.ok)throw Error(o.message);ie.current.delete(t),E(`Duplicated as ${o.value.name}.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function pe(){if(!ee)return;let e=ee.id,t=await Jq(i,ee);if(!t.ok)throw Error(t.message);te(null),await a.cancelQueries({queryKey:Lq}),a.setQueryData(Lq,t=>t?.filter(t=>t.id!==e)),E(`Template moved to the trash. Restore it in Settings → Trash within 30 days.`,`success`),await a.invalidateQueries({queryKey:Lq})}bx({id:`library.save-template`,title:`Save a setup as a template`,group:`Library`,keywords:[`template`,`new template`,`play draft`],run:()=>O(!0)});let me=w&&!ee?{tone:`error`,text:w}:r?{tone:`warning`,text:`A run is still starting in Play. Wait for it to finish (or press Check Start result there), then apply a template.`}:o.error?{tone:`error`,text:o.error.message}:o.isPending?{tone:`info`,text:`Loading templates…`}:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kSe,{open:k,onClose:()=>A(!1),onInstalled:()=>void a.invalidateQueries({queryKey:Hq(i).queryKey})}),(0,h.jsxs)(B4,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,onClick:()=>A(!0),"aria-expanded":k,children:`Add pack`}),(0,h.jsx)(V,{id:`welcome.packs`,label:`Add pack`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`primary`,onClick:()=>O(!0),"aria-expanded":D,children:`Save a setup`}),(0,h.jsx)(V,{id:`templates.save`,label:`Save a setup`})]})]}),children:[(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsxs)(TV,{"aria-label":`Show templates of`,value:c,className:`w-full sm:w-56`,onChange:e=>l(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsx)(V,{id:`templates.show-channel`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Reuse a Play setup and its checkpoint choices. Use in Play creates a fresh draft to review.`,(0,h.jsx)(V,{id:`templates.apply`,label:`Use in Play`})]})]}),(0,h.jsxs)(`div`,{className:`mb-2 flex min-h-8 flex-wrap items-center gap-3`,children:[(0,h.jsx)(Q1,{tone:me?.tone??`info`,children:me?.text}),o.error?(0,h.jsx)(R,{size:`small`,onClick:()=>void o.refetch(),children:`Reload templates`}):null,(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:S||o.isFetching,onClick:()=>void o.refetch(),children:`Refresh templates`})]}),o.data?.length===0?(0,h.jsx)(a0,{title:`No templates yet`,children:`Use Save a setup to keep a Play draft for reuse.`}):null,o.data?.length&&u?.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No templates in this channel.`}):null,o.isPending&&!o.error?(0,h.jsx)(L4,{label:`Project templates`}):null,u?.length?(0,h.jsx)(jq,{className:F4,list:(0,h.jsx)(pU,{label:`Project templates`,children:u.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(mU,{className:`max-md:grid-cols-1`,title:(0,h.jsx)(J4,{name:e.name,maxLength:120,onSelect:()=>j(e.id),onRename:async t=>{let n=await Kq(i,e.id,t);return await a.invalidateQueries({queryKey:Lq}),n}}),selected:e.id===ne,meta:(0,h.jsxs)(h.Fragment,{children:[d(e)===void 0?``:`${d(e)} · `,`Version `,e.version,` · updated`,` `,(0,h.jsx)(`time`,{dateTime:e.updatedAt,children:e.updatedAt.slice(0,10)})]}),actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,onClick:()=>j(e.id),children:`Edit`}),duplicate:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:S,disabledReason:`Working on the last press`,onClick:()=>void le(()=>fe(e)),children:`Duplicate`}),play:{run:()=>void le(()=>de(e)),blocked:r?`A run is still starting in Play. Wait for it, then use the template.`:S?`Working on the last press`:void 0},onHistory:()=>M(e),onDelete:()=>{te(e),T(null)}})}),(0,h.jsx)(c0,{kind:`template`,id:e.id,name:e.name})]},e.id))}),detail:(0,h.jsx)(MSe,{template:u.find(e=>e.id===ne)})}):null,(0,h.jsxs)(YP,{open:D,title:`Save a setup`,width:`narrow`,onClose:()=>O(!1),footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:w?`error`:`info`,children:w??(S?`Saving…`:void 0)}),(0,h.jsx)(R,{type:`submit`,form:`save-template-form`,variant:`primary`,disabled:S||!p||!v.trim(),children:`Save template`})]}),children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[`Choose a saved Play draft, or`,` `,(0,h.jsx)(ha,{to:`/play`,className:`text-accent-ink underline`,children:`open Play`}),` `,`to prepare one.`]}),(0,h.jsx)(`p`,{className:`mb-4 text-small text-ink-2`,children:`A template keeps the settings, not one video's topic.`}),(0,h.jsxs)(`form`,{id:`save-template-form`,"aria-label":`Save a setup`,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),p&&v.trim()&&le(ue)},children:[(0,h.jsx)(xV,{label:`Saved Play draft`,tip:`templates.save.draft`,help:f.isPending?`Loading saved drafts…`:f.data?.length===0?`No saved drafts yet.`:void 0,children:(0,h.jsxs)(TV,{value:p,required:!0,disabled:S,onChange:e=>g(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a draft`}),f.data?.filter(e=>e.readable).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.title||`Untitled draft`},e.id))]})}),f.error?(0,h.jsx)(SI,{tone:`danger`,title:`The saved drafts couldn't be loaded.`,actions:(0,h.jsx)(R,{size:`small`,onClick:()=>void f.refetch(),children:`Reload drafts`}),children:f.error.message}):null,(0,h.jsx)(xV,{label:`Template name`,id:`template-name`,tip:`templates.save.name`,children:(0,h.jsx)(CV,{value:v,required:!0,maxLength:120,disabled:S,onChange:e=>y(e.target.value)})}),(0,h.jsx)(xV,{label:`Channel`,id:`template-channel`,tip:`templates.save.channel`,children:(0,h.jsxs)(TV,{value:b,disabled:S,onChange:e=>x(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`The draft's channel`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]})]}),re===null?null:(0,h.jsx)(NSe,{template:re,onClose:()=>M(null)},`${re.id}:${String(re.version)}`),(0,h.jsx)(jy,{open:ee!==null,title:`Delete ${ee?.name??`template`}?`,consequence:w??`Moves it to the trash for 30 days (Settings → Trash). Existing projects and drafts keep their setup.`,confirmLabel:`Delete template`,pending:S,onConfirm:()=>void le(pe),onCancel:()=>{S||te(null)}})]})}function FSe({page:e,anchor:t,words:n}){let{api:r}=z(),i=N(NB(r)),a=N(PB(r,e)),o=Zi(),[s,c]=(0,m.useState)(n??``);(0,m.useEffect)(()=>{c(n??``)},[n]);let l=(0,m.useRef)(null),u=(0,m.useMemo)(()=>new Set((i.data?.pages??[]).map(e=>e.id)),[i.data]),d=i.data?.pages.find(t=>t.id===e)?.title??e.replace(/-/g,` `),f=(0,m.useMemo)(()=>yb(a.data??``),[a.data]),p=(0,m.useMemo)(()=>a.data===void 0?``:vb(f.body,u,e),[a.data,f.body,u,e]);(0,m.useEffect)(()=>{if(p===``)return;let e=l.current;if(e===null)return;let n=t===void 0?void 0:xb(e,t,f.title===void 0?[]:[f.title]);n===void 0?window.scrollTo?.({top:0}):n.scrollIntoView?.({block:`start`})},[p,t,f.title]);let g=i.data?.groups.find(t=>t.pages.some(t=>t.id===e));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Help`}),(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`›`}),(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:i.data?.home.id??`Home`},children:`Tutorials`})]}),title:d,meta:g===void 0?`Guides to every screen of Slopify, for the version you are running.`:g.title}),(0,h.jsx)(Aq,{className:`sl-workspace--tutorials`,sections:(0,h.jsx)(ISe,{index:i.data,page:e,onOpenHit:(e,t)=>{o({to:`/help/tutorials/$page`,params:{page:e.page},search:{q:t},...e.anchor===``?{}:{hash:e.anchor}})}}),children:a.error===null?(0,h.jsxs)(`div`,{ref:l,onClick:e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey)return;let t=e.target.closest(`a`),n=t?.getAttribute(`href`);if(t===null||n==null)return;let r=bb(n);if(r!==void 0){e.preventDefault(),o({to:`/help/tutorials/$page`,params:{page:r.page},...r.anchor===void 0?{}:{hash:r.anchor}});return}/^https?:/.test(n)&&(e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`))},children:[(0,h.jsx)(CB,{markdown:p,label:`Tutorial`,what:`tutorial`,query:s,onQuery:c,anchorPrefix:`tutorial-`,children:(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the tutorial…`})}),i.data?.footer?(0,h.jsx)(`p`,{className:`mt-8 border-t border-line pt-4 text-small text-ink-3`,children:i.data.footer.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`)}):null]}):(0,h.jsx)(SI,{tone:`danger`,title:`This tutorial did not load`,actions:(0,h.jsx)(R,{onClick:()=>void a.refetch(),variant:`secondary`,children:`Try again`}),children:`${a.error.message} Press Try again, or pick another page on the left.`})})]})}function ISe({index:e,page:t,onOpenHit:n}){let{api:r}=z(),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),c=(0,m.useRef)(null),l=(0,m.useId)();xx(c,`the tutorials`),(0,m.useEffect)(()=>{let e=setTimeout(()=>s(i.trim()),200);return()=>clearTimeout(e)},[i]);let u=N(FB(r,o));return(0,h.jsxs)(`nav`,{"aria-label":`Tutorials`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(`label`,{htmlFor:l,className:`sr-only`,children:`Search all tutorials`}),(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{ref:c,id:l,type:`search`,value:i,placeholder:`Search all tutorials`,onChange:e=>a(e.target.value),onKeyDown:e=>{let t=u.data?.hits[0];e.key===`Enter`&&t!==void 0&&(e.preventDefault(),n(t,o))},className:`sl-input pl-9`})]}),o===``?e===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the tutorials…`}):(0,h.jsxs)(`div`,{className:`sl-tutorials-nav flex flex-col gap-4`,children:[(0,h.jsx)(O9,{id:e.home.id,title:e.home.title,current:t}),e.groups.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,h.jsx)(`div`,{className:`sl-kicker px-2.5 pb-1`,children:e.title}),e.pages.map(e=>(0,h.jsx)(O9,{id:e.id,title:e.title,current:t},e.id))]},e.title))]}):(0,h.jsx)(LSe,{query:o,hits:u.data?.hits,error:u.error?.message})]})}function O9({id:e,title:t,current:n}){return(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:e},"aria-current":e===n?`page`:void 0,className:`sl-tutorials-nav__link`,children:t})}function LSe({query:e,hits:t,error:n}){return n===void 0?t===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Searching…`}):t.length===0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`No tutorial mentions "${e}". Try fewer or other words.`}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{role:`status`,className:`m-0 px-2.5 text-small text-ink-3`,children:t.length===1?`1 section`:`${String(t.length)} sections`}),(0,h.jsx)(`ul`,{"aria-label":`Search results`,className:`m-0 flex list-none flex-col gap-1 p-0`,children:t.map(t=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(ha,{to:`/help/tutorials/$page`,params:{page:t.page},search:{q:e},...t.anchor===``?{}:{hash:t.anchor},className:`sl-tutorials-hit`,children:[(0,h.jsx)(`span`,{className:`block font-semibold text-ink`,children:t.heading===void 0?t.pageTitle:t.heading}),t.heading===void 0?null:(0,h.jsx)(`span`,{className:`block text-label text-ink-3`,children:t.pageTitle}),(0,h.jsx)(`span`,{className:`mt-0.5 block text-small text-ink-2`,children:t.snippet})]})},`${t.page}#${t.anchor}`))})]}):(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The search didn't run: ${n} Change the words or reload the page.`})}var RSe=[{id:`library`,name:`The Library of Alexandria`,summary:`A narrated video with its two shorts, article, PDF, description and images.`,action:`Explore the sample`},{id:`audiobook`,name:`The Wind in the Willows`,summary:`An audiobook: a narrator and two character voices, captions tagged with who speaks, MP3 and M4B with chapters.`,action:`See an audiobook`},{id:`podcast`,name:`The Antikythera Mechanism`,summary:`A two-host podcast with the speaker panel, name tags and portraits, and its MP3 and M4B.`,action:`Hear a podcast`}],k9=[{id:`found`,label:`1 · What you have`},{id:`style`,label:`2 · Pick a style`},{id:`make`,label:`3 · Make your first short`}];function zSe(e){return e.length<=2?e.join(` or `):`${e.slice(0,-1).join(`, `)} or ${e.at(-1)??``}`}function BSe(e){return e===void 0?{ready:!1,text:`Looking for a voice…`}:e.keyed===null?e.system.available?{ready:!0,text:`Narration uses your computer's built-in voice${e.system.engine===null?``:` (${e.system.engine})`}; add an ElevenLabs or OpenAI key later for a better one.`}:{ready:!1,text:e.system.issue??`No voice can narrate yet. Add an ElevenLabs or OpenAI key in Settings → Providers.`}:{ready:!0,text:`Narration uses your ${e.keyed} voice key.`}}function VSe(){let{api:e}=z(),t=_(),n=Zi(),r=N({queryKey:My,queryFn:()=>Iy(e)}),[i,a]=(0,m.useState)(`found`),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(void 0),f=(0,m.useRef)(void 0),p=P({mutationFn:()=>Ly(e),onSuccess:async()=>{await t.invalidateQueries({queryKey:My}),await n({to:`/`})}}),g=P({mutationFn:t=>Ry(e,t),onSettled:()=>t.invalidateQueries({queryKey:My})}),v=P({mutationFn:()=>(f.current??=crypto.randomUUID(),zy(e,{topic:o,requestId:f.current,...c===``?{}:{packId:c}})),onSuccess:async({projectId:e})=>{f.current=void 0,d(e),await t.invalidateQueries({queryKey:B.projects}),await t.invalidateQueries({queryKey:B.voices})}}),y=e=>{e.preventDefault(),o.trim()!==``&&v.mutate()},b=r.data,x=b?.clis.filter(e=>e.ready)??[],S=BSe(b?.voice),C=c===``?`General`:b?.packs.find(e=>e.id===c)?.name??c,w=v.error?{tone:`error`,text:v.error.message}:g.error?{tone:`error`,text:g.error.message}:p.error?{tone:`error`,text:p.error.message}:v.isPending?{tone:`info`,text:`Starting your short…`}:void 0,T=k9.findIndex(e=>e.id===i),E=k9[T+1],D=k9[T-1];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Welcome to Slopify`,meta:`Make a video from a topic, with the tools already on this computer.`,actions:(0,h.jsx)(R,{variant:`quiet`,disabled:p.isPending,onClick:()=>p.mutate(),children:u===void 0?`Skip`:`Done`})}),r.error?(0,h.jsx)(SI,{tone:`danger`,title:`Could not read what this computer has`,className:`mb-6`,children:r.error.message}):null,(0,h.jsx)(r0,{items:k9.map(e=>({id:e.id,label:e.label})),value:i,onChange:a,label:`First-run steps`,idPrefix:`welcome`,className:`mb-6`}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`found`,active:i===`found`,children:[(0,h.jsx)(H,{title:`Found on this computer`,info:`welcome.found`}),(0,h.jsxs)(pU,{label:`Tools found on this computer`,className:`mb-4`,children:[(b?.clis??[]).map(e=>(0,h.jsx)(mU,{title:e.name,actions:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.ready?`Ready${e.version===null?``:` · ${e.version}`}${e.draws?` · writes and draws`:` · writes`}`:e.installed?e.issue??`Installed, not usable yet`:`Not found`})},e.id)),b===void 0?(0,h.jsx)(mU,{title:`Looking for installed tools…`}):null]}),b!==void 0&&x.length>0?(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:`You can make a video now: no API keys are needed for ${zSe([`the text`,...x.some(e=>e.draws)?[`the images`]:[],...S.ready&&b.voice.keyed===null?[`the narration`]:[]])}.`}):null,b!==void 0&&x.length===0?(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`Nothing on this computer can write the script yet.`,actions:(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},children:`Open Settings → Providers`}),children:`Install Claude Code, Codex or Gemini CLI and sign in to it, then press Check again; or add an OpenRouter key in Settings → Providers.`}):null,(0,h.jsx)(H,{title:`Narration voice`,info:`welcome.voice`}),b===void 0?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6`,children:(0,h.jsx)(mU,{title:`Looking for a voice…`})}):(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`style`,active:i===`style`,children:[(0,h.jsx)(H,{title:`Pick a style`,info:`welcome.pack`}),(0,h.jsx)(pU,{label:`Styles`,className:`mb-3 [&_.sl-row__meta]:whitespace-normal`,children:[{id:``,name:`General`,summary:`A neutral explainer style.`,installed:!1,library:!1},...(b?.packs??[]).map(e=>({...e,library:!0}))].map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,selected:c===e.id,actions:(0,h.jsxs)(h.Fragment,{children:[e.library?(0,h.jsx)(R,{variant:`quiet`,disabled:e.installed||g.isPending,"aria-label":e.installed?`${e.name} is in your library`:`Add ${e.name} to library`,onClick:()=>g.mutate(e.id),children:e.installed?`In your library`:`Add to library`}):null,(0,h.jsx)(R,{variant:c===e.id?`primary`:`secondary`,"aria-pressed":c===e.id,"aria-label":`Use ${e.name}`,onClick:()=>l(e.id),children:c===e.id?`Picked`:`Use this style`})]})},e.id===``?`general`:e.id))}),(0,h.jsxs)(`p`,{className:`mb-6 flex items-center gap-1 text-small text-ink-2`,...Ob,children:[`Add to library keeps a pack's prompts and Play template for later videos.`,(0,h.jsx)(V,{id:`welcome.packs`,className:`-my-1`})]})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`make`,active:i===`make`,children:[u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Make a 60-second short`,info:`welcome.short`}),(0,h.jsxs)(`p`,{className:`mb-3 text-small text-ink-2`,children:[`Style: ${C}. `,S.text]}),S.ready||b===void 0?null:(0,h.jsx)(`div`,{className:`mb-4`,children:(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})}),(0,h.jsxs)(`form`,{onSubmit:y,className:`mb-6 flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[240px] flex-1 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:`welcome-topic`,className:`text-label text-ink-2`,children:`Topic`}),(0,h.jsx)(V,{id:`welcome.topic`,className:`-my-1`})]}),(0,h.jsx)(R3,{id:`welcome-topic`,value:o,maxLength:200,placeholder:`Why the sea glows at night`,onChange:e=>s(e.target.value)})]}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:o.trim()===``||v.isPending,disabledReason:`Type a topic first.`,children:`Make a 60-second short`})]})]}):(0,h.jsx)(SI,{tone:`info`,className:`mb-6`,title:`Your short is being made.`,actions:(0,h.jsx)(fS,{variant:`primary`,to:`/projects/$projectId`,params:{projectId:u},children:`Watch it being made`}),children:`It usually takes about five minutes. The live view shows each step as it runs; while you wait, look at a sample or set Slopify to start when you log in.`}),(0,h.jsx)(H,{title:`While you wait: the samples`,info:`welcome.samples`}),(0,h.jsx)(pU,{label:`Samples`,className:`mb-6 [&_.sl-row__meta]:whitespace-normal`,children:RSe.map(e=>{let t=b?.samples[e.id]??null;return(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:t===null?(0,h.jsx)(pS,{to:`/settings`,search:{section:`storage`},children:`Restore samples in Settings`}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:e.action})},e.id)})}),(0,h.jsx)(Vb,{})]}),(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:w?.tone??`info`,children:w?.text}),children:[(0,h.jsx)(pS,{to:`/play`,children:`Set up a long video instead`}),D===void 0?null:(0,h.jsx)(R,{onClick:()=>a(D.id),children:`Back`}),E===void 0?null:(0,h.jsx)(R,{variant:`primary`,onClick:()=>a(E.id),children:`Next: ${E.label.replace(/^\d · /,``)}`})]})]})}function A9({voice:e,checking:t,onCheck:n}){return e.ready?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6 [&_.sl-row__title]:whitespace-normal`,children:(0,h.jsx)(mU,{lead:(0,h.jsx)(gS,{tone:`done`}),title:e.text,actions:(0,h.jsx)(fS,{variant:`quiet`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`})})}):(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`No voice can narrate the short yet.`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(fS,{variant:`primary`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`}),(0,h.jsx)(R,{disabled:t,onClick:n,children:t?`Checking…`:`Check again`})]}),children:e.text})}var j9=ba({component:eV}),HSe=va({getParentRoute:()=>j9,path:`/`,component:Lme}),M9=va({getParentRoute:()=>j9,path:`projects`,validateSearch:e=>{let t=Zbe(e.show);return t===void 0?{}:{show:t}},component:USe});function USe(){let{show:e}=M9.useSearch();return(0,h.jsx)(exe,{initialFilter:e??`all`},e??`all`)}var WSe=va({getParentRoute:()=>j9,path:`welcome`,component:VSe}),GSe=va({getParentRoute:()=>j9,path:`play`,component:Mge}),N9=va({getParentRoute:()=>j9,id:`_library`,component:Wpe}),KSe=va({getParentRoute:()=>j9,path:`library`,beforeLoad:()=>{throw dn({to:`/prompts`,search:{kind:`article`}})}}),qSe=va({getParentRoute:()=>j9,path:`channels`,component:xpe}),P9=va({getParentRoute:()=>j9,path:`channels/$channelId`,validateSearch:e=>e.tab===void 0?{}:{tab:ype(e.tab)},component:JSe});function JSe(){let{channelId:e}=P9.useParams(),{tab:t}=P9.useSearch(),n=Zi();return(0,h.jsx)(bpe,{channelId:e,tab:t??`brand`,onTab:t=>{n({to:`/channels/$channelId`,params:{channelId:e},search:{tab:t},replace:!0})}},e)}var YSe=va({getParentRoute:()=>N9,path:`templates`,component:eCe}),XSe=/^[0-9A-Za-z-]{1,64}$/;function F9(e){return Ife(e.tab)===`schedules`?typeof e.schedule==`string`&&XSe.test(e.schedule)?{tab:`schedules`,schedule:e.schedule}:{tab:`schedules`}:{}}var I9=va({getParentRoute:()=>j9,path:`calendar`,validateSearch:F9,component:$Se}),ZSe=va({getParentRoute:()=>j9,path:`schedules`,beforeLoad:()=>{throw dn({to:`/calendar`,search:{tab:`schedules`},replace:!0})}}),QSe=va({getParentRoute:()=>j9,path:`schedules/$scheduleId`,beforeLoad:({params:e})=>{throw dn({to:`/calendar`,search:F9({tab:`schedules`,schedule:e.scheduleId}),replace:!0})}});function $Se(){let e=F9(I9.useSearch()),t=Zi();return(0,h.jsx)(Rfe,{tab:e.tab??`weeks`,schedule:e.schedule,onTab:e=>{t({to:`/calendar`,search:e===`schedules`?{tab:`schedules`}:{},replace:!0})},onSchedule:e=>{t({to:`/calendar`,search:{tab:`schedules`,schedule:e},replace:!0})}})}function eCe(){let e=rP(),t=Zi();return(0,h.jsx)(PSe,{getGeneration:e.generation,blocked:e.review.starting||e.review.uncertain||e.review.created!==null,beforeApply:e.flush,onApplied:async(n,r)=>!r()||!await e.open(n,r)||!r()?!1:(await t({to:`/play`}),r())})}var L9=va({getParentRoute:()=>j9,path:`projects/$projectId`,component:lCe}),R9=va({getParentRoute:()=>N9,path:`prompts`,validateSearch:e=>({kind:vV(e.kind)}),component:uCe}),z9=va({getParentRoute:()=>j9,path:`prompts/new`,validateSearch:e=>{let t=vV(e.kind);return typeof e.from==`string`?{kind:t,from:e.from}:{kind:t}},component:dCe}),B9=va({getParentRoute:()=>j9,path:`prompts/$promptId`,component:fCe}),V9=va({getParentRoute:()=>N9,path:`entries`,validateSearch:e=>({category:hV(e.category)}),component:pCe}),H9=va({getParentRoute:()=>j9,path:`entries/new`,validateSearch:e=>{let t=hV(e.category);return typeof e.from==`string`?{category:t,from:e.from}:{category:t}},component:mCe}),U9=va({getParentRoute:()=>j9,path:`entries/$entryId`,component:hCe}),tCe=va({getParentRoute:()=>N9,path:`narration-aliases`,component:zme}),nCe=va({getParentRoute:()=>N9,path:`document-themes`,component:Kpe}),W9=va({getParentRoute:()=>j9,path:`document-themes/new`,validateSearch:e=>typeof e.from==`string`?{from:e.from}:{},component:gCe}),G9=va({getParentRoute:()=>j9,path:`document-themes/$themeId`,component:_Ce});function rCe(e){let t=e.section===void 0?void 0:SSe(e.section),n=t===`patch-notes`&&typeof e.note==`string`&&/^[0-9A-Za-z][0-9A-Za-z.-]{0,63}$/.test(e.note)?e.note:void 0;return{...t===void 0?{}:{section:t},...n===void 0?{}:{note:n}}}var K9=va({getParentRoute:()=>j9,path:`settings`,validateSearch:rCe,component:cCe}),q9=va({getParentRoute:()=>j9,path:`help/tutorials/$page`,validateSearch:e=>typeof e.q==`string`&&e.q.trim()!==``?{q:e.q.slice(0,200)}:{},component:iCe});function iCe(){let{page:e}=q9.useParams(),{q:t}=q9.useSearch(),n=Ha({select:e=>e.hash});return(0,h.jsx)(FSe,{page:e,anchor:n===``?void 0:n,words:t})}var aCe=va({getParentRoute:()=>j9,path:`help`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),oCe=va({getParentRoute:()=>j9,path:`help/tutorials`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),sCe=va({getParentRoute:()=>j9,path:`usage`,beforeLoad:()=>{throw dn({to:`/settings`,search:{section:`usage`}})}});function cCe(){let{section:e,note:t}=K9.useSearch(),n=Zi();return(0,h.jsx)(wSe,{section:e??`providers`,note:t,onSection:e=>{n({to:`/settings`,search:{section:e},replace:!0})},onNote:e=>{n({to:`/settings`,search:{section:`patch-notes`,...e===void 0?{}:{note:e}}})}})}function lCe(){let{projectId:e}=L9.useParams(),t=rP(),n=Zi();return(0,h.jsx)(Gbe,{projectId:e,openDraft:async e=>!await t.flush()||!await t.open(e)?!1:(await n({to:`/play`}),!0)},e)}function uCe(){let{kind:e}=R9.useSearch(),t=Zi(),n=J9();return(0,h.jsx)(axe,{kind:e,onKind:e=>{t({to:`/prompts`,search:{kind:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function J9(){let e=rP(),t=Zi();return{blocked:e.review.starting||e.review.uncertain||e.review.created!==null?`Play is starting a run from its draft. Wait for it to start, then try again.`:void 0,use:n=>{let r=ZV(e.document,n);e.edit(r.document),t({to:`/play`}).then(()=>e.navigate(r.section,r.field))}}}function dCe(){let{kind:e,from:t}=z9.useSearch(),n=Y9();return(0,h.jsx)(J7,{promptId:void 0,kind:e,from:t,onLeave:n},`${e}:${t??`new`}`)}function fCe(){let{promptId:e}=B9.useParams(),t=Y9();return(0,h.jsx)(J7,{promptId:e,kind:`article`,from:void 0,onLeave:t},e)}function Y9(){let e=Zi();return t=>{e({to:`/prompts`,search:{kind:t}})}}function pCe(){let{category:e}=V9.useSearch(),t=Zi(),n=J9();return(0,h.jsx)(qpe,{category:e,onCategory:e=>{t({to:`/entries`,search:{category:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function mCe(){let{category:e,from:t}=H9.useSearch(),n=Z9();return(0,h.jsx)(c3,{entryId:void 0,category:e,from:t,onLeave:n})}function hCe(){let{entryId:e}=U9.useParams(),t=Z9();return(0,h.jsx)(c3,{entryId:e,category:`intro`,from:void 0,onLeave:t})}function gCe(){let{from:e}=W9.useSearch(),t=X9();return(0,h.jsx)(_4,{themeId:void 0,from:e,onLeave:t})}function _Ce(){let{themeId:e}=G9.useParams(),t=X9();return(0,h.jsx)(_4,{themeId:e,from:void 0,onLeave:t})}function X9(){let e=Zi();return()=>{e({to:`/document-themes`})}}function Z9(){let e=Zi();return t=>{e({to:`/entries`,search:{category:t}})}}var vCe=j9.addChildren({homeRoute:HSe,projectsRoute:M9,welcomeRoute:WSe,playRoute:GSe,libraryRoute:N9.addChildren({promptsRoute:R9,entriesRoute:V9,templatesRoute:YSe,documentThemesRoute:nCe,narrationAliasesRoute:tCe}),schedulesRoute:ZSe,scheduleRoute:QSe,calendarRoute:I9,libraryIndexRoute:KSe,channelsRoute:qSe,channelRoute:P9,projectRoute:L9,newPromptRoute:z9,promptRoute:B9,newEntryRoute:H9,entryRoute:U9,newDocumentThemeRoute:W9,documentThemeRoute:G9,settingsRoute:K9,usageRoute:sCe,helpRoute:aCe,tutorialsIndexRoute:oCe,tutorialsRoute:q9});function yCe(){return La({routeTree:vCe})}function bCe(){let e,t,n=new Set;return{observe:r=>{if(e===void 0){e=r;for(let e of n)e();return}if(r!==e&&r!==t){t=r;for(let e of n)e()}},staleAt:()=>t,loadedAt:()=>e,subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function xCe(e,t){return async(n,r)=>{let i=await e(n,r),a=i.headers.get(`X-Slopify-Version`);return a!==null&&t.observe(a),i}}function SCe(){let e=new Map;return{observe:t=>{if(t.type===`stage.state`){let n=e.get(t.projectId);if(n){for(let[e,r]of n)r.stage===t.stage&&r.revisionId===t.revisionId&&r.workId===t.workId&&n.delete(e);n.size===0&&e.delete(t.projectId)}return}if(t.type!==`llm.preview`)return;let n=e.get(t.projectId)??new Map,r=JSON.stringify([t.revisionId,t.workId,t.callId]),i=n.get(r),a=(t.reset?t.text:`${i?.text??``}${t.text}`).slice(-65536);for(n.delete(r),n.set(r,{...t,text:a,reset:!0});n.size>8;){let e=n.keys().next().value;e!==void 0&&n.delete(e)}for(e.delete(t.projectId),e.set(t.projectId,n);e.size>16;){let t=e.keys().next().value;t!==void 0&&e.delete(t)}},snapshot:t=>[...e.get(t)?.values()??[]],snapshotAll:()=>[...e.values()].flatMap(e=>[...e.values()])}}var Q9=/\/events\/projects\/([^/?#]+)/,CCe=/\/events\/global(?:[?#]|$)/,wCe=[`running.count`,`staging.progress`,`staging.failed`,`schedule.topics`,`stage.state`,`stage.progress`,`article.delta`,`llm.preview`,`image.landed`,`narration.piece`,`project.state`,`project.updated`,`review.flagged`];function TCe(e){let t=new Set,n=SCe(),r,i=!1,a=(e,t,n)=>{for(let r of e.listeners.get(t)??[])r({data:n})},o=o=>{if(r!==void 0)return;let s=e(o);r=s,s.addEventListener(`open`,()=>{i=!0;for(let e of[...t])for(let t of e.opens)t()});for(let e of wCe)s.addEventListener(e,r=>{let i;try{let t=JSON.parse(r.data);typeof t.projectId==`string`&&(i=t.projectId),(e===`llm.preview`||e===`stage.state`)&&n.observe(t)}catch{return}for(let n of[...t])(n.projectId===void 0||n.projectId===i)&&a(n,e,r.data)})};return s=>{let c=Q9.exec(s)?.[1];if(c===void 0&&!CCe.test(s))return e(s);o(c===void 0?s:s.replace(Q9,`/events/global`));let l={projectId:c===void 0?void 0:decodeURIComponent(c),listeners:new Map,opens:new Set};return t.add(l),i&&queueMicrotask(()=>{if(t.has(l)){for(let e of l.opens)e();if(l.projectId!==void 0)for(let e of n.snapshot(l.projectId))a(l,`llm.preview`,JSON.stringify(e))}}),{addEventListener:(e,t)=>{if(e===`open`){l.opens.add(t);return}let n=l.listeners.get(e)??new Set;n.add(t),l.listeners.set(e,n)},close:()=>{t.delete(l),t.size===0&&r!==void 0&&(r.close(),r=void 0,i=!1)}}}}function ECe(e){let t=bCe(),n={api:Co(window.location.origin,xCe(window.fetch.bind(window),t),To(e=>{let n=e.headers.get(`X-Slopify-Version`);n!==null&&t.observe(n)})),openEvents:TCe(e=>new EventSource(e)),version:t};(0,co.createRoot)(e).render((0,h.jsx)(m.StrictMode,{children:(0,h.jsx)(v,{client:new Je,children:(0,h.jsx)(ste,{deps:n,children:(0,h.jsx)(Ba,{router:yCe()})})})}))}var $9=document.getElementById(`root`);if($9===null)throw Error(`index.html carries no #root element for the app to mount on`);ECe($9);export{t4 as t};