PageSourceSearch

https://paper2gal.com/assets/index-CAJdU2ur.js

js paper2gal.com collected 2026-10-09 22:39:25 UTC 12,220 bytes, 3 lines download raw bytes

1import{e as L,a as O,b as C,d as N,f as T,g as B,h as R,i as D}from"./gameScript-BiTWJXKG.js";import{j as Se,c as Ie,k as xe,l as Ae,m as Fe,o as ke,n as Oe,p as Ne,s as Je}from"./gameScript-BiTWJXKG.js";import"./katex-math-BxKHCrdI.js";import"./main-Dck1T9BT.js";import"./react-vendor-CHQL15iE.js";import"./lucide-BFLOpGdB.js";import"./pdfjs-ji3DqnKJ.js";import"./markdown-W-rE_H7s.js";function g(n){return n.replace(/,(\s*[}\]])/g,"$1")}function k(n){const e=String(n||"");let t="";const s=[];let r=!1,l=!1,i="";const a=o=>o==="{"||o==="["||o==='"'||o==="-"||/[0-9tfn]/i.test(o),c=o=>o==="}"||o==="]"||o==='"'||/[0-9eE]/.test(o);for(let o=0;o<e.length;o+=1){const u=e[o];if(r){t+=u,l?l=!1:u==="\\"?l=!0:u==='"'&&(r=!1,i='"');continue}if(/\s/.test(u)){t+=u;continue}if(s[s.length-1]==="array"&&a(u)&&c(i)){const h=t.trimEnd(),d=h[h.length-1]||"";d!==","&&d!=="["&&(t=h+","+t.slice(h.length))}if(t+=u,u==='"'){r=!0,i=u;continue}u==="{"?s.push("object"):u==="["?s.push("array"):(u==="}"&&s[s.length-1]==="object"||u==="]"&&s[s.length-1]==="array")&&s.pop(),i=u}return t}function x(n){let e=n.trim();e.endsWith("\\")&&(e=e.slice(0,-1));let t=!1,s=!1;for(let i=0;i<e.length;i++){const a=e[i];if(s){s=!1;continue}if(a==="\\"){s=!0;continue}a==='"'&&(t=!t)}if(t){const i=Math.max(e.lastIndexOf(","),e.lastIndexOf("["),e.lastIndexOf("{"));i>=0&&(e=e.slice(0,i))}let r=0,l=0;t=!1,s=!1;for(let i=0;i<e.length;i++){const a=e[i];if(s){s=!1;continue}if(a==="\\"){s=!0;continue}if(a==='"'){t=!t;continue}t||(a==="{"?r++:a==="}"?r--:a==="["?l++:a==="]"&&l--)}for(;l>0;)e+="]",l--;for(;r>0;)e+="}",r--;try{return JSON.parse(e),e}catch{return null}}function q(n){const e=String(n||"");let t="",s=!1,r=!1;const l=i=>{for(let a=i;a<e.length;a+=1)if(!/\s/.test(e[a]))return e[a];return""};for(let i=0;i<e.length;i+=1){const a=e[i];if(!s){t+=a,a==='"'&&(s=!0,r=!1);continue}if(r){t+=a,r=!1;continue}if(a==="\\"){t+=a,r=!0;continue}if(a==='"'){const c=l(i+1);c===":"||c===","||c==="}"||c==="]"||c===""?(t+=a,s=!1):t+='\\"';continue}t+=a}return t}function b(n){const e=q(n);if(e===n)return null;try{return JSON.parse(e)}catch{const t=g(e);try{return JSON.parse(t)}catch{const s=x(t);if(s)return JSON.parse(s)}}return null}function W(n){try{return{ok:!0,value:JSON.parse(n)}}catch{}const e=b(n);if(e!==null)return{ok:!0,value:e};const t=g(n);if(t!==n){try{return{ok:!0,value:JSON.parse(t)}}catch{}const s=b(t);if(s!==null)return{ok:!0,value:s}}return{ok:!1}}function Q(n){const e=[/^(?:Here is|Below is|以下是|这是)\s+(?:the\s+)?JSON[::]?\s*/i,/^(?:Sure|Okay|Ok|好的|当然)[,,!!.]?\s*/i],t=[/\s*(?:Note|注意|Reminder|提醒)[::].*$/i,/\s*Hope (?:this|that) (?:helps|works).*$/i];let s=n;for(const r of e)s=s.replace(r,"");for(const r of t)s=s.replace(r,"");return s.trim()}function pe(n){const{cleanedText:e}=L(n);let t=e.trim();t.startsWith("```json")?t=t.replace(/^```json\s*/i,"").replace(/\s*```$/,""):t.startsWith("```")&&(t=t.replace(/^```\s*/i,"").replace(/\s*```$/,"")),t=Q(t),t=O(t);const s=W(t);if(s.ok)return s.value;const r=x(t);if(r)return JSON.parse(r);const l=C(t);if(l)t=l;else{const f=N(t),m=T(t);f&&m?t=t.indexOf(f)<=t.indexOf(m)?f:m:f?t=f:m&&(t=m)}try{return JSON.parse(t)}catch{}const i=b(t);if(i!==null)return i;const a=g(t);if(a!==t){try{return JSON.parse(a)}catch{}const f=b(a);if(f!==null)return f}const c=g(k(t));if(c!==t&&c!==a)try{return JSON.parse(c)}catch{}const o=t.replace(/\\(u[0-9a-fA-F]{4}|["\\/bfnrt]|[^])/g,(f,m)=>m.length>1&&m.startsWith("u")||['"',"\\","/","b","f","n","r","t"].includes(m)?f:"\\\\"+m);try{return JSON.parse(o)}catch{}const u=b(o);if(u!==null)return u;const p=g(k(o));if(p!==o)try{return JSON.parse(p)}catch{}const h=x(c);if(h)return JSON.parse(h);const d=O(e.trim()),w=W(d);if(w.ok)return w.value;const A=C(d);if(A&&A!==t)try{return JSON.parse(A)}catch{}const $=N(d),S=T(d);let y=null;if($&&S?y=d.indexOf($)<=d.indexOf(S)?$:S:y=$||S,y&&y!==t)try{return JSON.parse(y)}catch{}const _=g(k(d)),F=x(_);if(F&&F!==h)try{return JSON.parse(F)}catch{}const I=new Error("模型返回了非 JSON 格式的数据。");throw I.rawJsonText=n,I.cleanedJsonText=t,I.errorLayerHint="ai_api",I}const v=/\\(?:alpha|argmax|argmin|bar|begin|beta|cdot|cos|delta|dot|epsilon|end|exp|frac|gamma|geq|hat|infty|int|lambda|left|leq|lim|ln|log|mathbb|mathcal|mathbf|mathrm|mu|nabla|neq|omega|operatorname|overline|partial|phi|prod|psi|qquad|quad|right|sigma|sin|softmax|sqrt|sum|tan|text|theta|tilde|times|underline|vec)\b/,E=/(\$\$[\s\S]*?\$\$|\\\[[\s\S]*?\\\]|\$[\s\S]*?\$|\\\([\s\S]*?\\\))/g,Z=/(^|[::((]\s*)([A-Za-z][A-Za-z0-9_{}\\^]*(?:\s*=\s*)[A-Za-z0-9_{}\\^+\-*/=().,\s<>|]+?)(?=\s*([。!?!?;;,,\n]|$))/g;function G(n){return n.replace(/\\\\([a-zA-Z]+)/g,(e,t)=>`\\${t}
1`).replace(/\\\\([\[\]\(\)])/g,(e,t)=>`\\${t}`)}function H(n){return n.replace(/\f(?=rac\b)/g,"\\f").replace(/\r(?=ight\b)/g,"\\r").replace(/\n(?=(?:abla|eq)\b)/g,"\\n").replace(/\t(?=(?:ext|heta|ilde|imes)\b)/g,"\\t").replace(/\u0008(?=(?:ar|egin|eta)\b)/g,"\\b")}function U(n,e){let t=0;for(let s=e-1;s>=0&&n[s]==="\\";s--)t++;return t%2===1}function V(n){const e=[];for(let t=0;t<n.length;t++)n[t]!=="$"||U(n,t)||n[t-1]==="$"||n[t+1]==="$"||e.push(t);return e}function X(n){const e=V(n);if(e.length%2===0)return n;const t=e[e.length-1],s=n.slice(t+1);if(!v.test(s))return n;const r=s.match(/^(.*?)([。!?.!?])?(\s*)$/);if(!r)return n;const l=r[1]||"";return l.trim()?`${n.slice(0,t+1)}${l}$${r[2]||""}${r[3]||""}`:n}function K(n){const e=n.trim();return!e||e.includes("$")?!1:v.test(e)?/^[\\A-Za-z0-9_{}^+\-*/=(),.[\]\s<>|:]+$/.test(e):z(e)}function Y(n){return n.split(`
2`).map(e=>{var l,i;if(!K(e))return e;const t=((l=e.match(/^\s*/))==null?void 0:l[0])||"",s=((i=e.match(/\s*$/))==null?void 0:i[0])||"",r=e.trim();return`${t}$${r}$${s}`}).join(`
3`)}function P(n){return n.startsWith("$$")&&n.endsWith("$$")||n.startsWith("\\[")&&n.endsWith("\\]")||n.startsWith("$")&&n.endsWith("$")&&n.length>1||n.startsWith("\\(")&&n.endsWith("\\)")}function ee(n){return n.replace(/((?:^|[::\n])[^。!?.!?;;\n]*=[^。!?.!?;;\n]*?)\s+(?:undefined|null)(?=\s*(?:[。!?.!?;;]|$))/gi,"$1").replace(/([。!?.!?;;])\s+(?:undefined|null)(?=\s*$)/gi,"$1")}function j(n){return n.trim().replace(/\b([A-Za-z])\s+dot\s*\*/gi,"\\dot{$1} ").replace(/\b([A-Za-z])_dot\b/gi,"\\dot{$1}").replace(/\b([A-Za-z])\s+dot\b/gi,"\\dot{$1}").replace(/\s*\*\s*/g," ").replace(/\s+/g," ").trim()}function z(n){const e=n.trim();if(!e||e.includes("$")||/^https?:\/\//i.test(e)||!e.includes("=")||!/[A-Za-z]/.test(e))return!1;if(!/[+\-*/^_()]|\d|\bdot\b/i.test(e.replace(/=/g,""))){const t=e.match(/[A-Za-z]+/g)||[];if(t.length===0||t.some(s=>s.length>3))return!1}return/[\u4e00-\u9fff\u3040-\u30ff\u0400-\u04ff]/.test(e)?!1:/^[A-Za-z0-9_{}\\^+\-*/=().,\s<>|]+$/.test(e)}function te(n){return n.split(E).map(e=>!e||P(e)?e:e.replace(Z,(t,s,r)=>z(r)?`${s}$${j(r)}$`:t)).join("")}function ne(n){return n.split(E).map(e=>{if(!e||!P(e))return e;const t=e.startsWith("$$")&&e.endsWith("$$"),s=e.startsWith("\\[")&&e.endsWith("\\]"),r=e.startsWith("\\(")&&e.endsWith("\\)"),l=t?"$$":s?"\\[":r?"\\(":"$",i=t?"$$":s?"\\]":r?"\\)":"$",a=e.slice(l.length,-i.length).trim();return!/\bdot\b|\s\*\s/i.test(a)||!z(a)?e:`${l}${j(a)}${i}`}).join("")}function J(n){let e=H(n);return e=ee(e),e=G(e),e=X(e),e=Y(e),e=te(e),e=ne(e),e}const re=n=>n==="append"||n==="clear"||n==="replace"?n:void 0,se=(n="zh-CN")=>{const e=String(n||"").trim().toLowerCase();return e.startsWith("en")||e==="english"?{title:"Story Q&A",summary:"Temporary in-story question"}:e.startsWith("ja")||e.includes("japanese")?{title:"その場で質問",summary:"一時的な質問"}:e.startsWith("ru")||e.includes("russian")?{title:"Вопрос по сюжету",summary:"Временный вопрос"}:{title:"举手问答",summary:"临时问答"}},M=n=>Array.isArray(n)?n.map(e=>{if(!e||typeof e!="object")return null;const t=e;return typeof t.text!="string"||!t.text.trim()?null:{speaker:typeof t.speaker=="string"&&t.speaker.trim()?t.speaker.trim():"旁白",text:J(t.text.trim()),emotion:B(t.emotion),isImportant:typeof t.isImportant=="boolean"?t.isImportant:void 0,blackboard:J(D(t.blackboard))||void 0,blackboardMode:re(t.blackboardMode??R(t.blackboard))}}).filter(Boolean).slice(0,8):[];function he(n,e="zh-CN"){const t=se(e),{cleanedText:s}=L(n);let r=s.trim();r.startsWith("```json")?r=r.replace(/^```json\s*/i,"").replace(/\s*```$/,""):r.startsWith("```")&&(r=r.replace(/^```\s*/i,"").replace(/\s*```$/,"")),r=O(r);const l=N(r);l&&(r=l);const i=JSON.parse(r),a=M(i.steps),c=a.length>0?[]:M(i.frames),o=a.length>0||c.length>0?[]:typeof i.answer=="string"||Array.isArray(i.answer)?(Array.isArray(i.answer)?i.answer:[i.answer]).filter(p=>typeof p=="string"&&p.trim().length>0).map(p=>({speaker:"旁白",text:J(p.trim()),emotion:B("THINKING")})).slice(0,8):[],u=a.length>0?a:c.length>0?c:o;if(u.length>0)return{title:typeof i.title=="string"&&i.title.trim()?i.title.trim():t.title,summary:typeof i.summary=="string"&&i.summary.trim()?i.summary.trim():t.summary,steps:u};throw new Error("模型返回的问答必须包含有效的 steps 数组。")}function ie(n){return{...n,choices:Array.isArray(n.choices)?n.choices.map(e=>({...e})):void 0}}function ge(n,e={}){if(!Array.isArray(n)||n.length===0)return n;const t=n.map(ie),s=new Set(t.map(r=>r.id).filter(r=>typeof r=="number"));for(const r of t){if(!Array.isArray(r.choices)||r.choices.length===0)continue;const l=r.choices.map(o=>o==null?void 0:o.nextFrameId).filter(o=>typeof o=="number"&&s.has(o));if(l.length===0)continue;const i=new Set(l),a=t.filter(o=>i.has(o.id)&&(typeof o.nextFrameId!="number"||!s.has(o.nextFrameId)||i.has(o.nextFrameId)));if(a.length===0)continue;const c=a.map(o=>o.nextFrameId).find(o=>typeof o=="number"&&s.has(o)&&!i.has(o));if(typeof c=="number")for(const o of a)(typeof o.nextFrameId!="number"||i.has(o.nextFrameId))&&(o.nextFrameId=c)}return t}function ae(n){if(!Array.isArray(n))return["frames must be an array"];const e=[],t=new Set;for(const r of n){if(typeof(r==null?void 0:r.id)!="number"||!Number.isFinite(r.id)){e.push(`frame has invali
3d id: ${String(r==null?void 0:r.id)}`);continue}t.has(r.id)&&e.push(`duplicate frame id: ${r.id}`),t.add(r.id)}const s=new Map(n.map(r=>[r.id,r]));for(const r of n)if(!(!r||typeof r.id!="number")&&(typeof r.nextFrameId=="number"&&!t.has(r.nextFrameId)&&e.push(`frame ${r.id}.nextFrameId points to missing frame ${r.nextFrameId}`),Array.isArray(r.choices)&&r.choices.forEach((l,i)=>{(typeof(l==null?void 0:l.nextFrameId)!="number"||!t.has(l.nextFrameId))&&e.push(`frame ${r.id}.choices[${i}].nextFrameId points to missing frame ${String(l==null?void 0:l.nextFrameId)}`)}),r.socialChoiceId&&Array.isArray(r.choices))){const l=new Set;for(const i of r.choices){const a=s.get(i.nextFrameId),c=typeof(a==null?void 0:a.nextFrameId)=="number"?s.get(a.nextFrameId):void 0;if((a==null?void 0:a.speakerRole)!=="player"||a.socialChoiceId!==r.socialChoiceId||a.socialChoiceOptionId!==i.optionId){e.push(`social choice ${r.socialChoiceId} option ${String(i.optionId)} must target its player frame`);continue}if(!c||c.speakerRole==="player"||c.socialChoiceId!==r.socialChoiceId||c.socialChoiceOptionId!==i.optionId){e.push(`social choice ${r.socialChoiceId} option ${String(i.optionId)} must target its character response`);continue}typeof c.nextFrameId=="number"&&l.add(c.nextFrameId)}(l.size!==1||[...l].some(i=>!t.has(i)))&&e.push(`social choice ${r.socialChoiceId} branches must converge on one valid merge frame`)}return e}function ye(n){const e=ae(n);if(e.length>0){const t=new Error(`Unresolvable internal links: ${e.join("; ")}`);throw t.branchSafetyIssues=e,t}}export{ye as assertAllInternalLinksResolvable,Se as assertGameScriptHasRequiredFields,Ie as coerceLlmTextContent,xe as compileLinearFlowToFrames,ge as ensureLocalQuizMergeFrame,N as extractFirstBalancedJsonObject,Ae as extractOpenAiCompatMessage,Fe as extractOpenAiCompatMessageText,L as extractThinkTag,ae as getUnresolvableInternalLinks,ke as normalizeGameScriptPayload,O as normalizeLikelyJsonTypos,Oe as normalizeScriptBranches,pe as parseJsonResponse,Ne as parseRawResponseToGameScript,he as parseRawResponseToStoryQuestion,Je as sanitizePaperContentForModel};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.